25 #include "tdefiledialog.h" 31 #include <tqptrcollection.h> 32 #include <tqcheckbox.h> 33 #include <tqcombobox.h> 36 #include <tqlineedit.h> 37 #include <tqptrlist.h> 39 #include <tqtextcodec.h> 40 #include <tqtooltip.h> 42 #include <tqwhatsthis.h> 43 #include <tqfiledialog.h> 46 #include <tdeaction.h> 47 #include <tdeapplication.h> 48 #include <kcharsets.h> 49 #include <tdecmdlineargs.h> 50 #include <tdecompletionbox.h> 51 #include <tdeconfig.h> 53 #include <tdeglobal.h> 54 #include <tdeglobalsettings.h> 55 #include <kiconloader.h> 57 #include <tdeio/job.h> 58 #include <tdeio/netaccess.h> 59 #include <tdeio/scheduler.h> 60 #include <tdeio/kservicetypefactory.h> 61 #include <tdelocale.h> 62 #include <tdemessagebox.h> 63 #include <kmimetype.h> 64 #include <tdepopupmenu.h> 65 #include <kprotocolinfo.h> 66 #include <kpushbutton.h> 67 #include <tderecentdirs.h> 69 #include <kstandarddirs.h> 70 #include <kstdguiitem.h> 71 #include <kstaticdeleter.h> 72 #include <tdetoolbar.h> 73 #include <tdetoolbarbutton.h> 75 #include <kurlcombobox.h> 76 #include <kurlcompletion.h> 79 #include "config-tdefile.h" 80 #include "kpreviewwidgetbase.h" 82 #include <kdirselectdialog.h> 83 #include <tdefileview.h> 84 #include <tderecentdocument.h> 85 #include <tdefilefiltercombo.h> 86 #include <tdediroperator.h> 87 #include <kimagefilepreview.h> 89 #include <tdefilespeedbar.h> 90 #include <tdefilebookmarkhandler.h> 97 enum Buttons { HOTLIST_BUTTON,
98 PATH_COMBO, CONFIGURE_BUTTON };
100 template class TQPtrList<TDEIO::StatJob>;
103 static void silenceQToolBar(TQtMsgType,
const char *)
108 struct KFileDialogPrivate
121 TQBoxLayout *boxLayout;
122 TQWidget *mainWidget;
124 TQLabel *locationLabel;
127 TQLabel *filterLabel;
129 KPushButton *okButton, *cancelButton;
130 KFileSpeedBar *urlBar;
131 TQHBoxLayout *urlBarLayout;
132 TQWidget *customWidget;
135 TQCheckBox *autoSelectExtCheckBox;
136 bool autoSelectExtChecked;
139 TQPtrList<TDEIO::StatJob> statJobs;
143 TQStringList mimetypes;
147 bool keepLocation :1;
153 bool hasDefaultFilter :1;
159 KFileBookmarkHandler *bookmarkHandler;
162 int m_pathComboIndex;
165 KURL *KFileDialog::lastDirectory;
167 static KStaticDeleter<KURL> ldd;
170 TQWidget *parent,
const char* name,
bool modal)
171 : KDialogBase( parent, name, modal, TQString::null, 0 )
173 init( startDir, filter, 0 );
177 TQWidget *parent,
const char* name,
bool modal, TQWidget* widget)
178 : KDialogBase( parent, name, modal, TQString::null, 0 )
180 init( startDir, filter, widget );
188 TDEConfig *config = TDEGlobal::config();
191 d->urlBar->save( config );
195 delete d->bookmarkHandler;
202 d->locationLabel->setText(text);
207 int pos = filter.find(
'/');
212 if (pos > 0 && filter[pos - 1] !=
'\\') {
213 TQStringList filters = TQStringList::split(
" ", filter );
221 TQString copy (filter);
222 for (pos = 0; (pos = copy.find(
"\\/", pos)) != -1; ++pos)
226 filterWidget->setFilter(copy);
228 d->hasDefaultFilter =
false;
229 filterWidget->setEditable(
true );
236 return filterWidget->currentFilter();
241 const KMimeType::List &types,
242 const KMimeType::Ptr &defaultType)
244 d->mimetypes.clear();
245 d->filterLabel->setText(label);
247 KMimeType::List::ConstIterator it;
248 for( it = types.begin(); it != types.end(); ++it)
249 d->mimetypes.append( (*it)->name() );
255 const TQString& defaultType )
257 d->mimetypes = mimeTypes;
258 filterWidget->setMimeFilter( mimeTypes, defaultType );
260 TQStringList types = TQStringList::split(
" ", filterWidget->currentFilter());
261 types.append( TQString::fromLatin1(
"inode/directory" ));
264 d->hasDefaultFilter = !defaultType.isEmpty();
265 filterWidget->setEditable( !d->hasDefaultFilter ||
266 d->operationMode != Saving );
273 d->mimetypes.clear();
274 filterWidget->setFilter( TQString::null );
276 d->hasDefaultFilter =
false;
277 filterWidget->setEditable(
true );
284 int i = filterWidget->currentItem();
285 if (filterWidget->showsAllTypes())
288 if ((i >= 0) && (i < (int) d->mimetypes.count()))
289 return d->mimetypes[i];
290 return TQString::null;
312 TQString url = KShell::tildeExpand(_url);
315 if ( KURL::isRelativeURL(url) )
317 if (!url.isEmpty() && !TQDir::isRelativePath(url) )
333 void KFileDialog::slotOk()
335 kdDebug(tdefile_area) <<
"slotOK\n";
337 if (locationEdit->lineEdit()->edited())
339 enterURL(d->pathCombo->lineEdit()->text());
345 if ( (
mode() & KFile::Directory) != KFile::Directory ) {
346 if ( locationEdit->currentText().stripWhiteSpace().isEmpty() ) {
347 if ( !items || items->isEmpty() )
350 if ( d->operationMode == Saving )
351 msg = i18n(
"Please specify the filename to save to.");
353 msg = i18n(
"Please select the file to open.");
354 KMessageBox::information(
this, msg);
362 bool multi = (
mode() & KFile::Files) != 0;
363 KFileItemListIterator it( *items );
364 TQString endQuote = TQString::fromLatin1(
"\" ");
365 TQString name, files;
366 while ( it.current() ) {
367 name = (*it)->name();
370 name.append( endQuote );
373 files.append( name );
376 setLocationText( files );
385 if ( items && !locationEdit->lineEdit()->edited() &&
386 !(items->isEmpty() && !dirOnly) ) {
389 d->filenames = TQString::null;
395 if ( !(
mode() & KFile::Files) ) {
396 d->url = items->getFirst()->url();
401 KFileItemListIterator it( *items );
402 while ( it.current() ) {
403 d->urlList.append( (*it)->url() );
409 KURL url = TDEIO::NetAccess::mostLocalURL(d->url,topLevelWidget());
410 if ( (
mode() & KFile::LocalOnly) == KFile::LocalOnly &&
411 !url.isLocalFile() ) {
413 KMessageBox::sorry( d->mainWidget,
414 i18n(
"You can only select local files."),
415 i18n(
"Remote Files Not Accepted") );
427 if ( (
mode() & KFile::Files) == KFile::Files ) {
428 TQString locationText = locationEdit->currentText();
429 if ( locationText.contains(
'/' )) {
431 KURL u( ops->
url(), KShell::tildeExpand(locationText));
435 selectedURL = ops->
url();
438 selectedURL = ops->
url();
445 appendExtension (selectedURL);
448 if ( !selectedURL.isValid() ) {
449 KMessageBox::sorry( d->mainWidget, i18n(
"%1\ndoes not appear to be a valid URL.\n").arg(d->url.url()), i18n(
"Invalid URL") );
453 KURL url = TDEIO::NetAccess::mostLocalURL(selectedURL,topLevelWidget());
454 if ( (
mode() & KFile::LocalOnly) == KFile::LocalOnly &&
455 !url.isLocalFile() ) {
456 KMessageBox::sorry( d->mainWidget,
457 i18n(
"You can only select local files."),
458 i18n(
"Remote Files Not Accepted") );
466 if ( (
mode() & KFile::Directory) == KFile::Directory ) {
467 kdDebug(tdefile_area) <<
"Directory" << endl;
469 if ( d->url.isLocalFile() ) {
470 if ( locationEdit->currentText().stripWhiteSpace().isEmpty() ) {
471 TQFileInfo info( d->url.path() );
472 if ( info.isDir() ) {
473 d->filenames = TQString::null;
475 d->urlList.append( d->url );
478 else if (!info.exists() && (
mode() & KFile::File) != KFile::File) {
480 if ( ops->
mkdir( d->url.url(), true ))
487 if ( (
mode() & KFile::File) == KFile::File ||
488 (
mode() & KFile::Files) == KFile::Files )
494 if (
mode() & KFile::ExistingOnly )
498 KURL fullURL(d->url, locationEdit->currentText());
499 if ( TQFile::exists( fullURL.path() ) )
502 d->filenames = TQString::null;
512 d->filenames = locationEdit->currentText();
519 d->filenames = TQString::null;
521 d->urlList.append( d->url );
523 if (
mode() & KFile::ExistingOnly )
533 if (!kapp->authorizeURLAction(
"open", KURL(), d->url))
535 TQString msg = TDEIO::buildErrorString(TDEIO::ERR_ACCESS_DENIED, d->url.prettyURL());
536 KMessageBox::error( d->mainWidget, msg);
540 TDEIO::StatJob *job = 0L;
542 d->filenames = KShell::tildeExpand(locationEdit->currentText());
544 if ( (
mode() & KFile::Files) == KFile::Files &&
545 !locationEdit->currentText().contains(
'/' )) {
546 kdDebug(tdefile_area) <<
"Files\n";
547 KURL::List list = parseSelectedURLs();
548 for ( KURL::List::ConstIterator it = list.begin();
549 it != list.end(); ++it )
551 if (!kapp->authorizeURLAction(
"open", KURL(), *it))
553 TQString msg = TDEIO::buildErrorString(TDEIO::ERR_ACCESS_DENIED, (*it).prettyURL());
554 KMessageBox::error( d->mainWidget, msg);
558 for ( KURL::List::ConstIterator it = list.begin();
559 it != list.end(); ++it )
561 job = TDEIO::stat( *it, !(*it).isLocalFile() );
562 job->setWindow (topLevelWidget());
563 TDEIO::Scheduler::scheduleJob( job );
564 d->statJobs.append( job );
565 connect( job, TQT_SIGNAL( result(TDEIO::Job *) ),
566 TQT_SLOT( slotStatResult( TDEIO::Job *) ));
571 job = TDEIO::stat(d->url,!d->url.isLocalFile());
572 job->setWindow (topLevelWidget());
573 d->statJobs.append( job );
574 connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotStatResult(TDEIO::Job*)));
578 static bool isDirectory (
const TDEIO::UDSEntry &t)
582 for (TDEIO::UDSEntry::ConstIterator it = t.begin();
586 if ((*it).m_uds == TDEIO::UDS_FILE_TYPE)
588 isDir = S_ISDIR ((mode_t) ((*it).m_long));
599 void KFileDialog::slotStatResult(TDEIO::Job* job)
601 kdDebug(tdefile_area) <<
"slotStatResult" << endl;
602 TDEIO::StatJob *sJob =
static_cast<TDEIO::StatJob *
>( job );
604 if ( !d->statJobs.removeRef( sJob ) ) {
608 int count = d->statJobs.count();
612 if (sJob->error() && count == 0 && !ops->
dirOnlyMode())
618 TDEIO::UDSEntry t = sJob->statResult();
623 d->filenames = TQString::null;
630 locationEdit->clearEdit();
631 locationEdit->lineEdit()->setEdited(
false );
643 kdDebug(tdefile_area) <<
"filename " << sJob->url().url() << endl;
649 void KFileDialog::accept()
651 setResult( TQDialog::Accepted );
653 *lastDirectory = ops->
url();
654 if (!d->fileClass.isEmpty())
658 locationEdit->changeItem( TQString::null, 0 );
661 TQValueListConstIterator<KURL> it = list.begin();
662 for ( ; it != list.end(); ++it ) {
663 const KURL& url = *it;
667 TQString file = url.isLocalFile() ? url.path(-1) : url.prettyURL(-1);
670 for (
int i = 1; i < locationEdit->count(); i++ ) {
671 if ( locationEdit->text( i ) == file ) {
672 locationEdit->removeItem( i-- );
676 locationEdit->insertItem( file, 1 );
679 TDEConfig *config = TDEGlobal::config();
680 config->setForceGlobal(
true );
682 config->setForceGlobal(
false );
687 KDialogBase::accept();
689 addToRecentDocuments();
691 if ( (
mode() & KFile::Files) != KFile::Files )
705 if ( (ops->
mode() & KFile::Files) != KFile::Files ) {
711 if ( !locationEdit->hasFocus() ) {
712 setLocationText( i->name() );
728 if ( (ops->
mode() & KFile::Files) != KFile::Files ) {
733 setLocationText( i->name() );
747 if ( locationEdit->hasFocus() )
750 locationEdit->lineEdit()->setEdited(
false );
754 locationEdit->clearEdit();
758 static const TQString &begin = TDEGlobal::staticQString(
" \"");
759 KFileItemListIterator it ( *list );
761 while ( (item = it.current()) ) {
762 text.append( begin ).append( item->name() ).append(
'\"' );
766 setLocationText( text.stripWhiteSpace() );
769 void KFileDialog::setLocationText(
const TQString& text )
774 disconnect( locationEdit, TQT_SIGNAL( textChanged(
const TQString& ) ),
775 this, TQT_SLOT( slotLocationChanged(
const TQString& ) ) );
776 locationEdit->setCurrentItem( 0 );
777 connect( locationEdit, TQT_SIGNAL( textChanged(
const TQString& ) ),
778 TQT_SLOT( slotLocationChanged(
const TQString& )) );
779 locationEdit->setEditText( text );
782 if ( d->operationMode == Saving && !locationEdit->isVisible())
783 setNonExtSelection();
786 static const char autocompletionWhatsThisText[] = I18N_NOOP(
"<p>While typing in the text area, you may be presented " 787 "with possible matches. " 788 "This feature can be controlled by clicking with the right mouse button " 789 "and selecting a preferred mode from the <b>Text Completion</b> menu.")
"</qt>";
790 void KFileDialog::updateLocationWhatsThis (
void)
792 TQString whatsThisText;
793 if (d->operationMode == KFileDialog::Saving)
795 whatsThisText =
"<qt>" + i18n(
"This is the name to save the file as.") +
796 i18n (autocompletionWhatsThisText);
798 else if (ops->
mode() & KFile::Files)
800 whatsThisText =
"<qt>" + i18n(
"This is the list of files to open. More than " 801 "one file can be specified by listing several " 802 "files, separated by spaces.") +
803 i18n (autocompletionWhatsThisText);
807 whatsThisText =
"<qt>" + i18n(
"This is the name of the file to open.") +
808 i18n (autocompletionWhatsThisText);
811 TQWhatsThis::add(d->locationLabel, whatsThisText);
812 TQWhatsThis::add(locationEdit, whatsThisText);
818 d =
new KFileDialogPrivate();
821 d->keepLocation =
false;
822 d->operationMode = Opening;
823 d->bookmarkHandler = 0;
824 d->hasDefaultFilter =
false;
826 d->mainWidget =
new TQWidget(
this,
"KFileDialog::mainWidget");
827 setMainWidget( d->mainWidget );
828 d->okButton =
new KPushButton( KStdGuiItem::ok(), d->mainWidget );
829 d->okButton->setDefault(
true );
830 d->cancelButton =
new KPushButton(KStdGuiItem::cancel(), d->mainWidget);
831 connect( d->okButton, TQT_SIGNAL( clicked() ), TQT_SLOT( slotOk() ));
832 connect( d->cancelButton, TQT_SIGNAL( clicked() ), TQT_SLOT( slotCancel() ));
833 d->customWidget = widget;
834 d->autoSelectExtCheckBox = 0;
835 d->autoSelectExtChecked =
false;
838 TQtMsgHandler oldHandler = tqInstallMsgHandler( silenceQToolBar );
839 toolbar =
new TDEToolBar( d->mainWidget,
"KFileDialog::toolbar",
true);
840 toolbar->setFlat(
true);
841 tqInstallMsgHandler( oldHandler );
843 d->pathCombo =
new KURLComboBox( KURLComboBox::Directories,
true,
844 toolbar,
"path combo" );
845 TQToolTip::add( d->pathCombo, i18n(
"Current location") );
846 TQWhatsThis::add( d->pathCombo,
"<qt>" + i18n(
"This is the currently listed location. " 847 "The drop-down list also lists commonly used locations. " 848 "This includes standard locations, such as your home folder, as well as " 849 "locations that have been visited recently.") + i18n (autocompletionWhatsThisText));
852 u.setPath( TQDir::rootDirPath() );
853 TQString text = i18n(
"Root Folder: %1").arg( u.path() );
854 d->pathCombo->addDefaultURL( u,
855 KMimeType::pixmapForURL( u, 0, TDEIcon::Small ),
858 u.setPath( TQDir::homeDirPath() );
859 text = i18n(
"Home Folder: %1").arg( u.path( +1 ) );
860 d->pathCombo->addDefaultURL( u, KMimeType::pixmapForURL( u, 0, TDEIcon::Small ),
864 docPath.setPath( TDEGlobalSettings::documentPath() );
865 if ( (u.path(+1) != docPath.path(+1)) &&
866 TQDir(docPath.path(+1)).exists() )
868 text = i18n(
"Documents: %1").arg( docPath.path( +1 ) );
869 d->pathCombo->addDefaultURL( docPath,
870 KMimeType::pixmapForURL( docPath, 0, TDEIcon::Small ),
874 u.setPath( TDEGlobalSettings::desktopPath() );
875 text = i18n(
"Desktop: %1").arg( u.path( +1 ) );
876 d->pathCombo->addDefaultURL( u,
877 KMimeType::pixmapForURL( u, 0, TDEIcon::Small ),
881 d->selection = d->url.url();
884 if ( d->url.isLocalFile() )
886 if ( !TQFile::exists( d->url.path() ) )
888 d->url = d->url.upURL();
889 TQDir dir( d->url.path() );
890 while ( !dir.exists() )
892 d->url = d->url.upURL();
893 dir.setPath( d->url.path() );
898 ops =
new KDirOperator(d->url, d->mainWidget,
"KFileDialog::ops");
900 connect(ops, TQT_SIGNAL(urlEntered(
const KURL&)),
901 TQT_SLOT(urlEntered(
const KURL&)));
904 connect(ops, TQT_SIGNAL(
fileSelected(
const KFileItem *)),
906 connect(ops, TQT_SIGNAL(finishedLoading()),
907 TQT_SLOT(slotLoadingFinished()));
909 ops->
setupMenu(KDirOperator::SortActions |
910 KDirOperator::FileActions |
911 KDirOperator::ViewActions);
915 coll->action(
"up" )->plug( toolbar );
916 coll->action(
"up" )->setWhatsThis(i18n(
"<qt>Click this button to enter the parent folder.<p>" 917 "For instance, if the current location is file:/home/%1 clicking this " 918 "button will take you to file:/home.</qt>").arg( KUser().loginName() ));
919 coll->action(
"back" )->plug( toolbar );
920 coll->action(
"back" )->setWhatsThis(i18n(
"Click this button to move backwards one step in the browsing history."));
921 coll->action(
"forward" )->plug( toolbar );
922 coll->action(
"forward" )->setWhatsThis(i18n(
"Click this button to move forward one step in the browsing history."));
923 coll->action(
"reload" )->plug( toolbar );
924 coll->action(
"reload" )->setWhatsThis(i18n(
"Click this button to reload the contents of the current location."));
925 coll->action(
"mkdir" )->setShortcut(Key_F10);
926 coll->action(
"mkdir" )->plug( toolbar );
927 coll->action(
"mkdir" )->setWhatsThis(i18n(
"Click this button to create a new folder."));
929 TDEToggleAction *showSidebarAction =
930 new TDEToggleAction(i18n(
"Show Quick Access Navigation Panel"), Key_F9, coll,
"toggleSpeedbar");
931 showSidebarAction->setCheckedState(i18n(
"Hide Quick Access Navigation Panel"));
932 connect( showSidebarAction, TQT_SIGNAL( toggled(
bool ) ),
935 TDEToggleAction *showBookmarksAction =
936 new TDEToggleAction(i18n(
"Show Bookmarks"), 0, coll,
"toggleBookmarks");
937 showBookmarksAction->setCheckedState(i18n(
"Hide Bookmarks"));
938 connect( showBookmarksAction, TQT_SIGNAL( toggled(
bool ) ),
941 TDEActionMenu *menu =
new TDEActionMenu( i18n(
"Configure"),
"configure", TQT_TQOBJECT(
this),
"extra menu" );
942 menu->setWhatsThis(i18n(
"<qt>This is the configuration menu for the file dialog. " 943 "Various options can be accessed from this menu including: <ul>" 944 "<li>how files are sorted in the list</li>" 945 "<li>types of view, including icon and list</li>" 946 "<li>showing of hidden files</li>" 947 "<li>the Quick Access navigation panel</li>" 948 "<li>file previews</li>" 949 "<li>separating folders from files</li></ul></qt>"));
950 menu->insert( coll->action(
"sorting menu" ));
951 menu->insert( coll->action(
"separator" ));
952 coll->action(
"short view" )->setShortcut(Key_F6);
953 menu->insert( coll->action(
"short view" ));
954 coll->action(
"detailed view" )->setShortcut(Key_F7);
955 menu->insert( coll->action(
"detailed view" ));
956 menu->insert( coll->action(
"separator" ));
957 coll->action(
"show hidden" )->setShortcut(Key_F8);
958 menu->insert( coll->action(
"show hidden" ));
959 menu->insert( showSidebarAction );
960 menu->insert( showBookmarksAction );
961 coll->action(
"preview" )->setShortcut(Key_F11);
962 menu->insert( coll->action(
"preview" ));
963 coll->action(
"separate dirs" )->setShortcut(Key_F12);
964 menu->insert( coll->action(
"separate dirs" ));
966 menu->setDelayed(
false );
967 connect( menu->popupMenu(), TQT_SIGNAL( aboutToShow() ),
968 ops, TQT_SLOT( updateSelectionDependentActions() ));
969 menu->plug( toolbar );
972 TDEToolBarSeparator* spacerWidget =
new TDEToolBarSeparator(Qt::Horizontal,
false ,
974 d->m_pathComboIndex = toolbar->insertWidget(-1, -1, spacerWidget);
975 toolbar->insertWidget(PATH_COMBO, 0, d->pathCombo);
978 toolbar->setItemAutoSized (PATH_COMBO);
979 toolbar->setIconText(TDEToolBar::IconOnly);
980 toolbar->setBarPos(TDEToolBar::Top);
981 toolbar->setMovingEnabled(
false);
982 toolbar->adjustSize();
984 KURLCompletion *pathCompletionObj =
new KURLCompletion( KURLCompletion::DirCompletion );
985 d->pathCombo->setCompletionObject( pathCompletionObj );
986 d->pathCombo->setAutoDeleteCompletionObject(
true );
988 connect( d->pathCombo, TQT_SIGNAL( urlActivated(
const KURL& )),
989 this, TQT_SLOT( enterURL(
const KURL& ) ));
990 connect( d->pathCombo, TQT_SIGNAL( returnPressed(
const TQString& )),
991 this, TQT_SLOT( enterURL(
const TQString& ) ));
992 connect( d->pathCombo, TQT_SIGNAL( activated(
const TQString& )),
993 this, TQT_SLOT( enterURL(
const TQString& ) ));
995 TQString whatsThisText;
998 d->locationLabel =
new TQLabel(i18n(
"&Location:"), d->mainWidget);
999 locationEdit =
new KURLComboBox(KURLComboBox::Files,
true,
1000 d->mainWidget,
"LocationEdit");
1001 locationEdit->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed));
1002 connect( locationEdit, TQT_SIGNAL( textChanged(
const TQString& ) ),
1003 TQT_SLOT( slotLocationChanged(
const TQString& )) );
1005 updateLocationWhatsThis ();
1006 d->locationLabel->setBuddy(locationEdit);
1008 locationEdit->setFocus();
1009 KURLCompletion *fileCompletionObj =
new KURLCompletion( KURLCompletion::FileCompletion );
1010 TQString dir = d->url.url(+1);
1011 pathCompletionObj->setDir( dir );
1012 fileCompletionObj->setDir( dir );
1013 locationEdit->setCompletionObject( fileCompletionObj );
1014 locationEdit->setAutoDeleteCompletionObject(
true );
1015 connect( fileCompletionObj, TQT_SIGNAL( match(
const TQString& ) ),
1016 TQT_SLOT( fileCompletion(
const TQString& )) );
1018 connect( locationEdit, TQT_SIGNAL( returnPressed() ),
1019 this, TQT_SLOT( slotOk()));
1020 connect(locationEdit, TQT_SIGNAL( activated(
const TQString& )),
1021 this, TQT_SLOT( locationActivated(
const TQString& ) ));
1024 whatsThisText = i18n(
"<qt>This is the filter to apply to the file list. " 1025 "File names that do not match the filter will not be shown.<p>" 1026 "You may select from one of the preset filters in the " 1027 "drop down menu, or you may enter a custom filter " 1028 "directly into the text area.<p>" 1029 "Wildcards such as * and ? are allowed.</qt>");
1030 d->filterLabel =
new TQLabel(i18n(
"&Filter:"), d->mainWidget);
1031 TQWhatsThis::add(d->filterLabel, whatsThisText);
1032 filterWidget =
new KFileFilterCombo(d->mainWidget,
1033 "KFileDialog::filterwidget");
1034 filterWidget->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed));
1035 TQWhatsThis::add(filterWidget, whatsThisText);
1037 d->filterLabel->setBuddy(filterWidget);
1038 connect(filterWidget, TQT_SIGNAL(
filterChanged()), TQT_SLOT(slotFilterChanged()));
1042 d->autoSelectExtCheckBox =
new TQCheckBox (d->mainWidget);
1043 connect(d->autoSelectExtCheckBox, TQT_SIGNAL(clicked()), TQT_SLOT(slotAutoSelectExtClicked()));
1047 TDEConfig* config = TDEGlobal::config();
1057 void KFileDialog::initSpeedbar()
1059 d->urlBar =
new KFileSpeedBar( d->mainWidget,
"url bar" );
1060 connect( d->urlBar, TQT_SIGNAL( activated(
const KURL& )),
1061 TQT_SLOT( enterURL(
const KURL& )) );
1067 d->urlBar->setCurrentItem( d->url );
1069 d->urlBarLayout->insertWidget( 0, d->urlBar );
1074 delete d->boxLayout;
1076 d->boxLayout =
new TQVBoxLayout( d->mainWidget, 0, KDialog::spacingHint());
1077 d->boxLayout->addWidget(toolbar, AlignTop);
1079 d->urlBarLayout =
new TQHBoxLayout( d->boxLayout );
1080 TQVBoxLayout *vbox =
new TQVBoxLayout( d->urlBarLayout );
1082 vbox->addWidget(ops, 4);
1083 vbox->addSpacing(3);
1085 TQGridLayout* lafBox=
new TQGridLayout(2, 3, KDialog::spacingHint());
1087 lafBox->addWidget(d->locationLabel, 0, 0, Qt::AlignVCenter);
1088 lafBox->addWidget(locationEdit, 0, 1, Qt::AlignVCenter);
1089 lafBox->addWidget(d->okButton, 0, 2, Qt::AlignVCenter);
1091 lafBox->addWidget(d->filterLabel, 1, 0, Qt::AlignVCenter);
1092 lafBox->addWidget(filterWidget, 1, 1, Qt::AlignVCenter);
1093 lafBox->addWidget(d->cancelButton, 1, 2, Qt::AlignVCenter);
1095 lafBox->setColStretch(1, 4);
1097 vbox->addLayout(TQT_TQLAYOUT(lafBox), 0);
1098 vbox->addSpacing(3);
1101 vbox->addWidget (d->autoSelectExtCheckBox);
1102 vbox->addSpacing (3);
1104 setTabOrder(ops, d->autoSelectExtCheckBox);
1105 setTabOrder (d->autoSelectExtCheckBox, locationEdit);
1106 setTabOrder(locationEdit, filterWidget);
1107 setTabOrder(filterWidget, d->okButton);
1108 setTabOrder(d->okButton, d->cancelButton);
1109 setTabOrder(d->cancelButton, d->pathCombo);
1110 setTabOrder(d->pathCombo, ops);
1113 if ( d->customWidget != 0 )
1118 d->customWidget->reparent( d->mainWidget, TQPoint() );
1120 vbox->addWidget( d->customWidget );
1121 vbox->addSpacing(3);
1128 setTabOrder(d->cancelButton, d->customWidget);
1129 setTabOrder(d->customWidget, d->pathCombo);
1133 setTabOrder(d->cancelButton, d->pathCombo);
1136 setTabOrder(d->pathCombo, ops);
1139 void KFileDialog::slotFilterChanged()
1141 TQString filter = filterWidget->currentFilter();
1144 if ( filter.find(
'/' ) > -1 ) {
1145 TQStringList types = TQStringList::split(
" ", filter );
1146 types.prepend(
"inode/directory" );
1162 d->selection = TQString::null;
1163 ops->
setURL( url, clearforward);
1167 void KFileDialog::urlEntered(
const KURL& url)
1169 TQString filename = locationEdit->currentText();
1170 d->selection = TQString::null;
1172 if ( d->pathCombo->count() != 0 ) {
1173 d->pathCombo->setURL( url );
1176 locationEdit->blockSignals(
true );
1177 locationEdit->setCurrentItem( 0 );
1178 if ( d->keepLocation )
1179 locationEdit->setEditText( filename );
1181 locationEdit->blockSignals(
false );
1183 TQString dir = url.url(+1);
1184 static_cast<KURLCompletion*
>( d->pathCombo->completionObject() )->setDir( dir );
1185 static_cast<KURLCompletion*
>( locationEdit->completionObject() )->setDir( dir );
1188 d->urlBar->setCurrentItem( url );
1191 void KFileDialog::locationActivated(
const TQString& url )
1198 if (!locationEdit->lineEdit()->edited())
1202 void KFileDialog::enterURL(
const KURL& url)
1207 void KFileDialog::enterURL(
const TQString& url )
1209 setURL( KURL::fromPathOrURL( KURLCompletion::replacedPath( url,
true,
true )) );
1223 kdDebug(tdefile_area) <<
"setSelection " << url << endl;
1225 if (url.isEmpty()) {
1226 d->selection = TQString::null;
1232 kdWarning() << url <<
" is not a correct argument for setSelection!" << endl;
1236 if (!KProtocolInfo::supportsListing(u)) {
1237 locationEdit->lineEdit()->setEdited(
true );
1244 KFileItem i(KFileItem::Unknown, KFileItem::Unknown, u,
true );
1246 if ( i.isDir() && u.isLocalFile() && TQFile::exists( u.path() ) ) {
1254 TQString filename = u.url();
1255 int sep = filename.findRev(
'/');
1257 if ( KProtocolInfo::supportsListing( u )) {
1259 dir.setQuery( TQString::null );
1260 dir.setFileName( TQString::null );
1266 filename = u.fileName();
1267 kdDebug(tdefile_area) <<
"filename " << filename << endl;
1268 d->selection = filename;
1269 setLocationText( filename );
1278 locationEdit->lineEdit()->setEdited(
true );
1281 d->url = ops->
url();
1282 d->url.addPath(filename);
1286 void KFileDialog::slotLoadingFinished()
1288 if ( !d->selection.isNull() )
1299 void KFileDialog::fileCompletion(
const TQString& match )
1301 if ( match.isEmpty() && ops->
view() )
1307 void KFileDialog::slotLocationChanged(
const TQString& text )
1309 if ( text.isEmpty() && ops->
view() )
1317 kdWarning() <<
"KFileDialog::updateStatusLine is deprecated! The status line no longer exists. Do not try and use it!" << endl;
1321 const TQString& filter,
1322 TQWidget *parent,
const TQString& caption)
1324 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1327 dlg.
setMode( KFile::File | KFile::LocalOnly );
1328 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1337 const TQString& filter,
1338 WId parent_id,
const TQString& caption)
1340 TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
1341 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1343 if( parent == NULL && parent_id != 0 )
1344 XSetTransientForHint( tqt_xdisplay(), dlg.winId(), parent_id );
1351 dlg.
setMode( KFile::File | KFile::LocalOnly );
1352 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1361 const TQString& filter,
1363 const TQString& caption)
1365 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1368 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1369 dlg.
setMode(KFile::Files | KFile::LocalOnly);
1377 TQWidget *parent,
const TQString& caption)
1379 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1382 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1391 const TQString& filter,
1393 const TQString& caption)
1395 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1398 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1408 const TQString& caption)
1415 const TQString& caption)
1418 return TQFileDialog::getExistingDirectory(startDir, parent,
"getExistingDirectory",
1419 caption,
true,
true);
1423 if ( url.isValid() )
1426 return TQString::null;
1431 const TQString& caption)
1433 TQStringList mimetypes = KImageIO::mimeTypes( KImageIO::Reading );
1435 mimetypes.join(
" "),
1436 parent,
"filedialog",
true);
1438 dlg.setCaption( caption.isNull() ? i18n(
"Open") : caption );
1439 dlg.setMode( KFile::File );
1442 dlg.setPreviewWidget( ip );
1445 return dlg.selectedURL();
1450 if ( result() == TQDialog::Accepted )
1459 if ( result() == TQDialog::Accepted ) {
1460 if ( (ops->
mode() & KFile::Files) == KFile::Files )
1461 list = parseSelectedURLs();
1463 list.append( d->url );
1469 KURL::List& KFileDialog::parseSelectedURLs()
const 1471 if ( d->filenames.isEmpty() ) {
1476 if ( d->filenames.contains(
'/' )) {
1477 static const TQString &prot = TDEGlobal::staticQString(
":/");
1479 if ( d->filenames.find( prot ) != -1 )
1482 u.setPath( d->filenames );
1485 d->urlList.append( u );
1487 KMessageBox::error( d->mainWidget,
1488 i18n(
"The chosen filenames do not\n" 1489 "appear to be valid."),
1490 i18n(
"Invalid Filenames") );
1494 d->urlList =
tokenize( d->filenames );
1496 d->filenames = TQString::null;
1506 KURL u( ops->
url() );
1509 int count = line.contains(
'"' );
1511 u.setFileName( line );
1518 if ( (count % 2) == 1 ) {
1520 KMessageBox::sorry(that, i18n(
"The requested filenames\n" 1522 "do not appear to be valid;\n" 1523 "make sure every filename is enclosed in double quotes.").arg(line),
1524 i18n(
"Filename Error"));
1529 int index1 = -1, index2 = -1;
1531 index1 = line.find(
'"', start );
1532 index2 = line.find(
'"', index1 + 1 );
1538 name = line.mid( index1 + 1, index2 - index1 - 1 );
1539 u.setFileName( name );
1551 if ( result() == TQDialog::Accepted )
1553 KURL url = TDEIO::NetAccess::mostLocalURL(d->url,topLevelWidget());
1554 if (url.isLocalFile())
1557 KMessageBox::sorry( d->mainWidget,
1558 i18n(
"You can only select local files."),
1559 i18n(
"Remote Files Not Accepted") );
1562 return TQString::null;
1570 if ( result() == TQDialog::Accepted ) {
1571 if ( (ops->
mode() & KFile::Files) == KFile::Files ) {
1572 KURL::List urls = parseSelectedURLs();
1573 TQValueListConstIterator<KURL> it = urls.begin();
1574 while ( it != urls.end() ) {
1575 url = TDEIO::NetAccess::mostLocalURL(*it,topLevelWidget());
1576 if ( url.isLocalFile() )
1577 list.append( url.path() );
1583 if ( d->url.isLocalFile() )
1584 list.append( d->url.path() );
1598 const TQString& caption)
1600 bool specialDir = dir.at(0) ==
':';
1601 KFileDialog dlg( specialDir ? dir : TQString::null, filter, parent,
"filedialog",
true);
1606 dlg.setCaption(caption.isNull() ? i18n(
"Save As") : caption);
1611 if (!filename.isEmpty())
1619 const TQString& caption)
1621 bool specialDir = dir.at(0) ==
':';
1622 TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
1623 KFileDialog dlg( specialDir ? dir : TQString::null, filter, parent,
"filedialog",
true);
1625 if( parent == NULL && parent_id != 0 )
1626 XSetTransientForHint(tqt_xdisplay(), dlg.winId(), parent_id);
1635 dlg.setCaption(caption.isNull() ? i18n(
"Save As") : caption);
1640 if (!filename.isEmpty())
1647 TQWidget *parent,
const TQString& caption)
1649 bool specialDir = dir.at(0) ==
':';
1650 KFileDialog dlg(specialDir ? dir : TQString::null, filter, parent,
"filedialog",
true);
1654 dlg.setCaption(caption.isNull() ? i18n(
"Save As") : caption);
1666 void KFileDialog::show()
1668 if ( !d->hasView ) {
1674 KDialogBase::show();
1681 filterWidget->setDefaultFilter( i18n(
"*|All Folders") );
1684 filterWidget->setDefaultFilter( i18n(
"*|All Files") );
1692 setMode(static_cast<KFile::Mode>( m ));
1706 TQString oldGroup = kc->group();
1707 if ( !group.isEmpty() )
1708 kc->setGroup( group );
1713 combo->
setURLs( kc->readPathListEntry( RecentURLs ), KURLComboBox::RemoveTop );
1714 combo->
setMaxItems( kc->readNumEntry( RecentURLsNumber,
1715 DefaultRecentURLsNumber ) );
1717 autoDirectoryFollowing = kc->readBoolEntry( AutoDirectoryFollowing,
1718 DefaultDirectoryFollowing );
1720 TDEGlobalSettings::Completion cm = (TDEGlobalSettings::Completion)
1721 kc->readNumEntry( PathComboCompletionMode,
1722 TDEGlobalSettings::completionMode() );
1723 if ( cm != TDEGlobalSettings::completionMode() )
1724 combo->setCompletionMode( cm );
1726 cm = (TDEGlobalSettings::Completion)
1727 kc->readNumEntry( LocationComboCompletionMode,
1728 TDEGlobalSettings::completionMode() );
1729 if ( cm != TDEGlobalSettings::completionMode() )
1730 locationEdit->setCompletionMode( cm );
1739 d->autoSelectExtChecked = kc->readBoolEntry (AutoSelectExtChecked, DefaultAutoSelectExtChecked);
1742 int w1 = minimumSize().width();
1743 int w2 = toolbar->sizeHint().width() + 10;
1745 setMinimumWidth(w2);
1747 TQSize size = configDialogSize( group );
1749 kc->setGroup( oldGroup );
1757 TQString oldGroup = kc->group();
1758 if ( !group.isEmpty() )
1759 kc->setGroup( group );
1761 kc->writePathEntry( RecentURLs, d->pathCombo->urls() );
1762 saveDialogSize( group,
true );
1763 kc->writeEntry( PathComboCompletionMode, static_cast<int>(d->pathCombo->completionMode()) );
1764 kc->writeEntry( LocationComboCompletionMode, static_cast<int>(locationEdit->completionMode()) );
1765 kc->writeEntry( ShowSpeedbar, d->urlBar && !d->urlBar->isHidden() );
1766 kc->writeEntry( ShowBookmarks, d->bookmarkHandler != 0 );
1767 kc->writeEntry( AutoSelectExtChecked, d->autoSelectExtChecked );
1770 kc->setGroup( oldGroup );
1776 TQString oldGroup = kc->group();
1777 kc->setGroup( ConfigGroup );
1779 locationEdit->
setMaxItems( kc->readNumEntry( RecentFilesNumber,
1780 DefaultRecentURLsNumber ) );
1781 locationEdit->
setURLs( kc->readPathListEntry( RecentFiles ),
1782 KURLComboBox::RemoveBottom );
1783 locationEdit->insertItem( TQString::null, 0 );
1784 locationEdit->setCurrentItem( 0 );
1786 kc->setGroup( oldGroup );
1791 TQString oldGroup = kc->group();
1792 kc->setGroup( ConfigGroup );
1794 kc->writePathEntry( RecentFiles, locationEdit->
urls() );
1796 kc->setGroup( oldGroup );
1806 return d->cancelButton;
1814 void KFileDialog::slotCancel()
1817 KDialogBase::slotCancel();
1819 TDEConfig *config = TDEGlobal::config();
1820 config->setForceGlobal(
true );
1822 config->setForceGlobal(
false );
1827 d->keepLocation = keep;
1832 return d->keepLocation;
1837 d->operationMode =
mode;
1838 d->keepLocation = (mode == Saving);
1839 filterWidget->setEditable( !d->hasDefaultFilter || mode != Saving );
1840 if ( mode == Opening )
1841 d->okButton->setGuiItem( KGuiItem( i18n(
"&Open"),
"document-open") );
1842 else if ( mode == Saving ) {
1843 d->okButton->setGuiItem( KStdGuiItem::save() );
1844 setNonExtSelection();
1847 d->okButton->setGuiItem( KStdGuiItem::ok() );
1848 updateLocationWhatsThis ();
1854 return d->operationMode;
1857 void KFileDialog::slotAutoSelectExtClicked()
1859 kdDebug (tdefile_area) <<
"slotAutoSelectExtClicked(): " 1860 << d->autoSelectExtCheckBox->isChecked () << endl;
1863 d->autoSelectExtChecked = d->autoSelectExtCheckBox->isChecked ();
1866 updateLocationEditExtension (d->extension );
1869 static TQString getExtensionFromPatternList (
const TQStringList &patternList)
1872 kdDebug (tdefile_area) <<
"\tgetExtension " << patternList << endl;
1874 TQStringList::ConstIterator patternListEnd = patternList.end ();
1875 for (TQStringList::ConstIterator it = patternList.begin ();
1876 it != patternListEnd;
1879 kdDebug (tdefile_area) <<
"\t\ttry: \'" << (*it) <<
"\'" << endl;
1888 if ((*it).startsWith (
"*.") &&
1889 (*it).length () > 2 &&
1890 (*it).find (
'*', 2) < 0 && (*it).find (
'?', 2) < 0)
1892 ret = (*it).mid (1);
1900 static TQString stripUndisplayable (
const TQString &
string)
1902 TQString ret = string;
1913 return d->extension;
1918 if (!d->autoSelectExtCheckBox)
return;
1927 kdDebug (tdefile_area) <<
"Figure out an extension: " << endl;
1928 TQString lastExtension = d->extension;
1929 d->extension = TQString::null;
1939 if (!filter.isEmpty ())
1942 if (filter.find (
'/') < 0)
1944 d->extension = getExtensionFromPatternList (TQStringList::split (
" ", filter)).lower ();
1945 kdDebug (tdefile_area) <<
"\tsetFilter-style: pattern ext=\'" 1946 << d->extension <<
"\'" << endl;
1951 KMimeType::Ptr mime = KMimeType::mimeType (filter);
1954 TQString nativeExtension = mime->property (
"X-TDE-NativeExtension").toString ();
1955 if (nativeExtension.at (0) ==
'.')
1957 d->extension = nativeExtension.lower ();
1958 kdDebug (tdefile_area) <<
"\tsetMimeFilter-style: native ext=\'" 1959 << d->extension <<
"\'" << endl;
1963 if (d->extension.isEmpty ())
1965 d->extension = getExtensionFromPatternList (mime->patterns ()).lower ();
1966 kdDebug (tdefile_area) <<
"\tsetMimeFilter-style: pattern ext=\'" 1967 << d->extension <<
"\'" << endl;
1977 TQString whatsThisExtension;
1978 if (!d->extension.isEmpty ())
1981 d->autoSelectExtCheckBox->setText (i18n (
"Automatically select filename e&xtension (%1)").arg (d->extension));
1982 whatsThisExtension = i18n (
"the extension <b>%1</b>").arg (d->extension);
1984 d->autoSelectExtCheckBox->setEnabled (
true);
1985 d->autoSelectExtCheckBox->setChecked (d->autoSelectExtChecked);
1990 d->autoSelectExtCheckBox->setText (i18n (
"Automatically select filename e&xtension"));
1991 whatsThisExtension = i18n (
"a suitable extension");
1993 d->autoSelectExtCheckBox->setChecked (
false);
1994 d->autoSelectExtCheckBox->setEnabled (
false);
1997 const TQString locationLabelText = stripUndisplayable (d->locationLabel->text ());
1998 const TQString filterLabelText = stripUndisplayable (d->filterLabel->text ());
1999 TQWhatsThis::add (d->autoSelectExtCheckBox,
2002 "This option enables some convenient features for " 2003 "saving files with extensions:<br>" 2005 "<li>Any extension specified in the <b>%1</b> text " 2006 "area will be updated if you change the file type " 2009 "<li>If no extension is specified in the <b>%2</b> " 2010 "text area when you click " 2011 "<b>Save</b>, %3 will be added to the end of the " 2012 "filename (if the filename does not already exist). " 2013 "This extension is based on the file type that you " 2014 "have chosen to save in.<br>" 2016 "If you do not want TDE to supply an extension for the " 2017 "filename, you can either turn this option off or you " 2018 "can suppress it by adding a period (.) to the end of " 2019 "the filename (the period will be automatically " 2023 "If unsure, keep this option enabled as it makes your " 2024 "files more manageable." 2026 .arg (locationLabelText)
2027 .arg (locationLabelText)
2028 .arg (whatsThisExtension)
2032 d->autoSelectExtCheckBox->show ();
2036 updateLocationEditExtension (lastExtension);
2041 d->autoSelectExtCheckBox->setChecked (
false);
2042 d->autoSelectExtCheckBox->hide ();
2049 void KFileDialog::updateLocationEditExtension (
const TQString &lastExtension)
2051 if (!d->autoSelectExtCheckBox->isChecked () || d->extension.isEmpty ())
2054 TQString urlStr = locationEdit->currentText ();
2055 if (urlStr.isEmpty ())
2059 kdDebug (tdefile_area) <<
"updateLocationEditExtension (" << url <<
")" << endl;
2061 const int fileNameOffset = urlStr.findRev (
'/') + 1;
2062 TQString fileName = urlStr.mid (fileNameOffset);
2064 const int dot = fileName.findRev (
'.');
2065 const int len = fileName.length ();
2073 if (TDEIO::NetAccess::stat (url, t, topLevelWidget()))
2075 kdDebug (tdefile_area) <<
"\tfile exists" << endl;
2077 if (isDirectory (t))
2079 kdDebug (tdefile_area) <<
"\tisDir - won't alter extension" << endl;
2092 if (lastExtension.length () && fileName.endsWith (lastExtension))
2093 fileName.truncate (len - lastExtension.length ());
2096 fileName.truncate (dot);
2099 const TQString newText = urlStr.left (fileNameOffset) + fileName + d->extension;
2100 if ( newText != locationEdit->currentText() )
2102 locationEdit->setCurrentText (urlStr.left (fileNameOffset) + fileName + d->extension);
2103 locationEdit->lineEdit()->setEdited (
true);
2110 void KFileDialog::updateFilter ()
2113 const TQString urlStr = locationEdit->currentText ();
2114 if (urlStr.isEmpty ())
2117 KMimeType::Ptr mime = KMimeType::findByPath(urlStr, 0,
true);
2118 if (mime && mime->name() != KMimeType::defaultMimeType()) {
2119 if (filterWidget->currentFilter() != mime->name() &&
2120 filterWidget->filters.findIndex(mime->name()) != -1) {
2121 filterWidget->setCurrentFilter(mime->name());
2128 void KFileDialog::appendExtension (KURL &url)
2130 if (!d->autoSelectExtCheckBox->isChecked () || d->extension.isEmpty ())
2133 TQString fileName = url.fileName ();
2134 if (fileName.isEmpty ())
2137 kdDebug (tdefile_area) <<
"appendExtension(" << url <<
")" << endl;
2139 const int len = fileName.length ();
2140 const int dot = fileName.findRev (
'.');
2142 const bool suppressExtension = (dot == len - 1);
2143 const bool unspecifiedExtension = (dot <= 0);
2146 if (!(suppressExtension || unspecifiedExtension))
2151 if (TDEIO::NetAccess::stat (url, t, topLevelWidget()))
2153 kdDebug (tdefile_area) <<
"\tfile exists - won't append extension" << endl;
2158 if (suppressExtension)
2170 kdDebug (tdefile_area) <<
"\tstrip trailing dot" << endl;
2171 url.setFileName (fileName.left (len - 1));
2174 else if (unspecifiedExtension)
2176 kdDebug (tdefile_area) <<
"\tappending extension \'" << d->extension <<
"\'..." << endl;
2177 url.setFileName (fileName + d->extension);
2178 kdDebug (tdefile_area) <<
"\tsaving as \'" << url <<
"\'" << endl;
2184 void KFileDialog::addToRecentDocuments()
2186 int m = ops->
mode();
2188 if ( m & KFile::LocalOnly ) {
2190 TQStringList::ConstIterator it = files.begin();
2191 for ( ; it != files.end(); ++it )
2197 KURL::List::ConstIterator it = urls.begin();
2198 for ( ; it != urls.end(); ++it ) {
2199 if ( (*it).isValid() )
2212 if ( e->key() == Key_Escape )
2215 d->cancelButton->animateClick();
2218 KDialogBase::keyPressEvent( e );
2233 homeURL.setPath( TQDir::homeDirPath() );
2236 if ( homeURL.equals( urlItem->
url(), true ) )
2242 urlItem =
static_cast<KURLBarItem*
>( urlItem->next() );
2254 static_cast<TDEToggleAction *
>(
actionCollection()->action(
"toggleSpeedbar"))->setChecked( show );
2261 if (d->bookmarkHandler)
2266 d->bookmarkHandler =
new KFileBookmarkHandler(
this );
2267 connect( d->bookmarkHandler, TQT_SIGNAL( openURL(
const TQString& )),
2268 TQT_SLOT( enterURL(
const TQString& )));
2270 toolbar->insertButton(TQString::fromLatin1(
"bookmark"),
2271 (
int)HOTLIST_BUTTON,
true,
2272 i18n(
"Bookmarks"), 5);
2273 toolbar->getButton(HOTLIST_BUTTON)->setPopup(d->bookmarkHandler->menu(),
2275 TQWhatsThis::add(toolbar->getButton(HOTLIST_BUTTON),
2276 i18n(
"<qt>This button allows you to bookmark specific locations. " 2277 "Click on this button to open the bookmark menu where you may add, " 2278 "edit or select a bookmark.<p>" 2279 "These bookmarks are specific to the file dialog, but otherwise operate " 2280 "like bookmarks elsewhere in TDE.</qt>"));
2282 else if (d->bookmarkHandler)
2284 delete d->bookmarkHandler;
2285 d->bookmarkHandler = 0;
2286 toolbar->removeItem(HOTLIST_BUTTON);
2289 static_cast<TDEToggleAction *
>(
actionCollection()->action(
"toggleBookmarks"))->setChecked( show );
2294 return d->m_pathComboIndex;
2298 void KFileDialog::initStatic()
2300 if ( lastDirectory )
2303 lastDirectory = ldd.setObject(lastDirectory,
new KURL());
2308 TQString& recentDirClass )
2312 recentDirClass = TQString::null;
2315 bool useDefaultStartDir = startDir.isEmpty();
2316 if ( !useDefaultStartDir )
2318 if (startDir[0] ==
':')
2320 recentDirClass = startDir;
2325 ret = TDECmdLineArgs::makeURL( TQFile::encodeName(startDir) );
2327 if ( !KProtocolInfo::supportsListing( ret ) )
2328 useDefaultStartDir =
true;
2332 if ( useDefaultStartDir )
2334 if (lastDirectory->isEmpty()) {
2335 lastDirectory->setPath(TDEGlobalSettings::documentPath());
2337 home.setPath( TQDir::homeDirPath() );
2342 if ( lastDirectory->path(+1) == home.path(+1) ||
2343 TQDir::currentDirPath() != TQDir::homeDirPath() ||
2344 !TQDir(lastDirectory->path(+1)).exists() )
2345 lastDirectory->setPath(TQDir::currentDirPath());
2347 ret = *lastDirectory;
2353 void KFileDialog::setStartDir(
const KURL& directory )
2356 if ( directory.isValid() )
2357 *lastDirectory = directory;
2360 void KFileDialog::setNonExtSelection()
2363 TQString pattern, filename = locationEdit->currentText().stripWhiteSpace();
2364 KServiceTypeFactory::self()->findFromPattern( filename, &pattern );
2366 if ( !pattern.isEmpty() && pattern.at( 0 ) ==
'*' && pattern.find(
'*' , 1 ) == -1 )
2367 locationEdit->lineEdit()->setSelection( 0, filename.length() - pattern.stripWhiteSpace().length()+1 );
2370 int lastDot = filename.findRev(
'.' );
2372 locationEdit->lineEdit()->setSelection( 0, lastDot );
2376 void KFileDialog::virtual_hook(
int id,
void* data )
2377 { KDialogBase::virtual_hook(
id, data ); }
2380 #include "tdefiledialog.moc" void setMimeFilter(const TQStringList &types, const TQString &defaultType=TQString::null)
Sets the filter up to specify the output type.
static TQString dir(const TQString &fileClass)
Returns the most recently used directory accociated with this file-class.
static KURL getSaveURL(const TQString &startDir=TQString::null, const TQString &filter=TQString::null, TQWidget *parent=0, const TQString &caption=TQString::null)
Creates a modal file dialog and returns the selected filename or an empty string if none was chosen...
This combobox shows a number of recent URLs/directories, as well as some default directories.
virtual void keyPressEvent(TQKeyEvent *e)
Reimplemented to animate the cancel button.
void setFilterMimeType(const TQString &label, const KMimeType::List &types, const KMimeType::Ptr &defaultType) KDE_DEPRECATED
Sets the filter up to specify the output type.
void close()
Stops loading immediately.
void setOnlyDoubleClickSelectsFiles(bool enable)
This is a KFileDialog specific hack: we want to select directories with single click, but not files.
static KURL selectDirectory(const TQString &startDir=TQString::null, bool localOnly=false, TQWidget *parent=0L, const TQString &caption=TQString::null)
Creates a KDirSelectDialog, and returns the result.
void setPreviewWidget(const TQWidget *w) KDE_DEPRECATED
KPushButton * okButton() const
~KFileDialog()
Destructs the file dialog.
void fileHighlighted(const TQString &)
Emitted when the user highlights a file.
virtual void readConfig(TDEConfig *, const TQString &group=TQString::null)
Reads the default settings for a view, i.e.
TQString currentFilter() const
Returns the current filter as entered by the user or one of the predefined set via setFilter()...
void dirCompletion(const TQString &)
void init(const TQString &startDir, const TQString &filter, TQWidget *widget)
Perform basic initialization tasks.
const KFileItemList * selectedItems() const
TQString currentFilterExtension()
Returns the filename extension associated with the currentFilter().
void clearFilter()
Clears any mime- or namefilter.
Mode
Modes of operation for the dialog.
static TQString getSaveFileName(const TQString &startDir=TQString::null, const TQString &filter=TQString::null, TQWidget *parent=0, const TQString &caption=TQString::null)
Creates a modal file dialog and returns the selected filename or an empty string if none was chosen...
static KURL getOpenURL(const TQString &startDir=TQString::null, const TQString &filter=TQString::null, TQWidget *parent=0, const TQString &caption=TQString::null)
Creates a modal file dialog and returns the selected URL or an empty string if none was chosen...
KURL::List selectedURLs() const
void setMaxItems(int)
Sets how many items should be handled and displayed by the combobox.
Provides a user (and developer) friendly way to select files and directories.
TQStringList selectedFiles() const
Returns a list of all selected local files.
void setViewConfig(TDEConfig *config, const TQString &group)
Sets the config object and the to be used group in KDirOperator.
virtual void clearSelection()=0
Clears any selection, unhighlights everything.
bool mkdir(const TQString &directory, bool enterDirectory=true)
Creates the given directory/url.
void setCurrentItem(const TQString &filename)
Clears the current selection and attempts to set filename the current file.
void setURL(const KURL &url, bool clearforward=true)
Sets the directory to view.
void setMode(KFile::Mode m)
Sets the listing/selection mode for the views, an OR'ed combination of.
static void add(const TQString &fileClass, const TQString &directory)
Associates directory with fileClass.
virtual void initGUI()
rebuild geometry management.
const KURL & url() const
returns the url of this item.
static KURL getStartURL(const TQString &startDir, TQString &recentDirClass)
This method implements the logic to determine the user's default directory to be listed.
KFileDialog(const TQString &startDir, const TQString &filter, TQWidget *parent, const char *name, bool modal)
Constructs a file dialog.
OperationMode operationMode() const
void setKeepLocation(bool keep)
Sets whether the filename/url should be kept when changing directories.
This widget works as a network transparent filebrowser.
KURL getCompleteURL(const TQString &)
Returns the absolute version of the URL specified in locationEdit.
KURLBar is a widget that displays icons together with a description.
static void add(const KURL &url)
Add a new item to the Recent Document menu.
void pathComboChanged(const TQString &)
static TQString getOpenFileNameWId(const TQString &startDir, const TQString &filter, WId parent_id, const TQString &caption)
Use this version only if you have no TQWidget available as parent widget.
void updateDir()
to update the view after changing the settings
virtual void updateStatusLine(int dirs, int files)
void fileSelected(const TQString &)
Emitted when the user selects a file.
void setNameFilter(const TQString &filter)
Sets a filter like "*.cpp *.h *.o".
KURL::List tokenize(const TQString &line) const
Parses the string "line" for files.
static KURL::List getOpenURLs(const TQString &startDir=TQString::null, const TQString &filter=TQString::null, TQWidget *parent=0, const TQString &caption=TQString::null)
Creates a modal file dialog and returns the selected URLs or an empty list if none was chosen...
static TQString getExistingDirectory(const TQString &startDir=TQString::null, TQWidget *parent=0, const TQString &caption=TQString::null)
Creates a modal file dialog and returns the selected directory or an empty string if none was chosen...
void setOperationMode(KFileDialog::OperationMode)
Sets the operational mode of the filedialog to Saving, Opening or Other.
TQString selectedFile() const
Returns the full path of the selected file in the local filesystem.
KFile::Mode mode() const
Returns the mode of the filedialog.
virtual void saveRecentFiles(TDEConfig *)
Saves the entries from the location combobox.
TDEActionCollection * actionCollection() const
Image preview widget for the file dialog.
void setURL(const KURL &url)
Sets the current url.
static KURL getImageOpenURL(const TQString &startDir=TQString::null, TQWidget *parent=0, const TQString &caption=TQString::null)
Creates a modal file dialog with an image previewer and returns the selected url or an empty string i...
virtual void writeConfig(TDEConfig *, const TQString &group=TQString::null)
Saves the current configuration.
TQString currentMimeFilter() const
The mimetype for the desired output format.
KMimeType::Ptr currentFilterMimeType()
Returns the mimetype for the desired output format.
OperationMode
Defines some default behavior of the filedialog.
void setURLs(TQStringList urls)
Inserts urls into the combobox below the "default urls" (see addDefaultURL).
void setMimeFilter(const TQStringList &mimetypes)
Sets a list of mimetypes as filter.
void setPreviewWidget(const TQWidget *w)
Sets a preview-widget to be shown next to the file-view.
void toolbarCallback(int)
void selectionChanged()
Emitted when the user hilights one or more files in multiselection mode.
void clearFilter()
Clears both the namefilter and mimetype filter, so that all files and directories will be shown...
void clearHistory()
Clears the forward and backward history.
static KURL getExistingURL(const TQString &startDir=TQString::null, TQWidget *parent=0, const TQString &caption=TQString::null)
Creates a modal file dialog and returns the selected directory or an empty string if none was chosen...
TQStringList urls() const
An item to be used in KURLBar / KURLBarListBox.
void toggleSpeedbar(bool)
void toggleBookmarks(bool show)
void setSelection(const TQString &name)
Sets the file name to preselect to name.
void filterChanged(const TQString &filter)
Emitted when the filter changed, i.e.
void setMode(KFile::Mode m)
Convenient overload of the other setMode(unsigned int) method.
void multiSelectionChanged()
called when an item is highlighted/selected in multiselection mode.
void setLocationLabel(const TQString &text)
Sets the text to be displayed in front of the selection.
void setURL(const KURL &url, bool clearforward)
Sets a new url to list.
void updateAutoSelectExtension()
Updates the currentFilterExtension and the availability of the Automatically Select Extension Checkbo...
void setFilter(const TQString &filter)
Sets the filter to be used to filter.
void setupMenu(int whichActions)
Sets up the action menu.
virtual void readConfig(TDEConfig *, const TQString &group=TQString::null)
Reads configuration and applies it (size, recent directories, ...)
TDEActionCollection * actionCollection() const
an accessor to a collection of all available Actions.
virtual void writeConfig(TDEConfig *, const TQString &group=TQString::null)
Saves the current settings like sorting, simple or detailed view.
bool keepsLocation() const
static TQStringList getOpenFileNames(const TQString &startDir=TQString::null, const TQString &filter=TQString::null, TQWidget *parent=0, const TQString &caption=TQString::null)
Creates a modal file dialog and returns the selected filenames or an empty list if none was chosen...
KPushButton * cancelButton() const
void setView(KFileView *view)
Sets a new KFileView to be used for showing and browsing files.
static TQString getOpenFileName(const TQString &startDir=TQString::null, const TQString &filter=TQString::null, TQWidget *parent=0, const TQString &caption=TQString::null)
Creates a modal file dialog and return the selected filename or an empty string if none was chosen...
static TQString getSaveFileNameWId(const TQString &dir, const TQString &filter, WId parent_id, const TQString &caption)
This function accepts the window id of the parent window, instead of TQWidget*.
virtual void readRecentFiles(TDEConfig *)
Reads the recent used files and inserts them into the location combobox.