24 #include "tdefiledialog.h"
30 #include <tqptrcollection.h>
31 #include <tqcheckbox.h>
32 #include <tqcombobox.h>
35 #include <tqlineedit.h>
36 #include <tqptrlist.h>
38 #include <tqtextcodec.h>
39 #include <tqtooltip.h>
41 #include <tqwhatsthis.h>
42 #include <tqfiledialog.h>
45 #include <tdeaction.h>
46 #include <tdeapplication.h>
47 #include <kcharsets.h>
48 #include <tdecmdlineargs.h>
49 #include <tdecompletionbox.h>
50 #include <tdeconfig.h>
52 #include <tdeglobal.h>
53 #include <tdeglobalsettings.h>
54 #include <kiconloader.h>
56 #include <tdeio/job.h>
57 #include <tdeio/netaccess.h>
58 #include <tdeio/scheduler.h>
59 #include <tdeio/kservicetypefactory.h>
60 #include <tdelocale.h>
61 #include <tdemessagebox.h>
62 #include <kmimetype.h>
63 #include <tdepopupmenu.h>
64 #include <kprotocolinfo.h>
65 #include <kpushbutton.h>
66 #include <tderecentdirs.h>
68 #include <kstandarddirs.h>
69 #include <kstdguiitem.h>
70 #include <kstaticdeleter.h>
71 #include <tdetoolbar.h>
72 #include <tdetoolbarbutton.h>
74 #include <kurlcombobox.h>
75 #include <kurlcompletion.h>
78 #include "config-tdefile.h"
79 #include "kpreviewwidgetbase.h"
81 #include <kdirselectdialog.h>
82 #include <tdefileview.h>
83 #include <tderecentdocument.h>
84 #include <tdefilefiltercombo.h>
85 #include <tdediroperator.h>
86 #include <kimagefilepreview.h>
88 #include <tdefilespeedbar.h>
89 #include <tdefilebookmarkhandler.h>
96 enum Buttons { HOTLIST_BUTTON,
97 PATH_COMBO, CONFIGURE_BUTTON };
99 template class TQPtrList<TDEIO::StatJob>;
102 static void silenceQToolBar(TQtMsgType,
const char *)
107 struct KFileDialogPrivate
120 TQBoxLayout *boxLayout;
121 TQWidget *mainWidget;
123 TQLabel *locationLabel;
126 TQLabel *filterLabel;
128 KPushButton *okButton, *cancelButton;
129 KFileSpeedBar *urlBar;
130 TQHBoxLayout *urlBarLayout;
131 TQWidget *customWidget;
134 TQCheckBox *autoSelectExtCheckBox;
135 bool autoSelectExtChecked;
138 TQPtrList<TDEIO::StatJob> statJobs;
142 TQStringList mimetypes;
146 bool keepLocation :1;
152 bool hasDefaultFilter :1;
158 KFileBookmarkHandler *bookmarkHandler;
161 int m_pathComboIndex;
164 KURL *KFileDialog::lastDirectory;
166 static KStaticDeleter<KURL> ldd;
169 TQWidget *parent,
const char* name,
bool modal)
170 : KDialogBase( parent, name, modal, TQString::null, 0 )
172 init( startDir, filter, 0 );
176 TQWidget *parent,
const char* name,
bool modal, TQWidget* widget)
177 : KDialogBase( parent, name, modal, TQString::null, 0 )
179 init( startDir, filter, widget );
187 TDEConfig *config = TDEGlobal::config();
190 d->urlBar->save( config );
194 delete d->bookmarkHandler;
201 d->locationLabel->setText(text);
206 int pos = filter.find(
'/');
211 if (pos > 0 && filter[pos - 1] !=
'\\') {
212 TQStringList filters = TQStringList::split(
" ", filter );
220 TQString copy (filter);
221 for (pos = 0; (pos = copy.find(
"\\/", pos)) != -1; ++pos)
225 filterWidget->setFilter(copy);
227 d->hasDefaultFilter =
false;
228 filterWidget->setEditable(
true );
235 return filterWidget->currentFilter();
240 const KMimeType::List &types,
241 const KMimeType::Ptr &defaultType)
243 d->mimetypes.clear();
244 d->filterLabel->setText(label);
246 KMimeType::List::ConstIterator it;
247 for( it = types.begin(); it != types.end(); ++it)
248 d->mimetypes.append( (*it)->name() );
254 const TQString& defaultType )
256 d->mimetypes = mimeTypes;
257 filterWidget->setMimeFilter( mimeTypes, defaultType );
259 TQStringList types = TQStringList::split(
" ", filterWidget->currentFilter());
260 types.append( TQString::fromLatin1(
"inode/directory" ));
263 d->hasDefaultFilter = !defaultType.isEmpty();
264 filterWidget->setEditable( !d->hasDefaultFilter ||
265 d->operationMode != Saving );
272 d->mimetypes.clear();
273 filterWidget->setFilter( TQString::null );
275 d->hasDefaultFilter =
false;
276 filterWidget->setEditable(
true );
283 int i = filterWidget->currentItem();
284 if (filterWidget->showsAllTypes())
287 if ((i >= 0) && (i < (
int) d->mimetypes.count()))
288 return d->mimetypes[i];
289 return TQString::null;
311 TQString url = KShell::tildeExpand(_url);
314 if ( KURL::isRelativeURL(url) )
316 if (!url.isEmpty() && !TQDir::isRelativePath(url) )
332 void KFileDialog::slotOk()
334 kdDebug(tdefile_area) <<
"slotOK\n";
336 if (locationEdit->lineEdit()->edited())
338 enterURL(d->pathCombo->lineEdit()->text());
344 if ( (
mode() & KFile::Directory) != KFile::Directory ) {
345 if ( locationEdit->currentText().stripWhiteSpace().isEmpty() ) {
346 if ( !items || items->isEmpty() )
349 if ( d->operationMode == Saving )
350 msg = i18n(
"Please specify the filename to save to.");
352 msg = i18n(
"Please select the file to open.");
353 KMessageBox::information(
this, msg);
361 bool multi = (
mode() & KFile::Files) != 0;
362 KFileItemListIterator it( *items );
363 TQString endQuote = TQString::fromLatin1(
"\" ");
364 TQString name, files;
365 while ( it.current() ) {
366 name = (*it)->name();
369 name.append( endQuote );
372 files.append( name );
375 setLocationText( files );
384 if ( items && !locationEdit->lineEdit()->edited() &&
385 !(items->isEmpty() && !dirOnly) ) {
388 d->filenames = TQString::null;
394 if ( !(
mode() & KFile::Files) ) {
395 d->url = items->getFirst()->url();
400 KFileItemListIterator it( *items );
401 while ( it.current() ) {
402 d->urlList.append( (*it)->url() );
408 KURL url = TDEIO::NetAccess::mostLocalURL(d->url,topLevelWidget());
409 if ( (
mode() & KFile::LocalOnly) == KFile::LocalOnly &&
410 !url.isLocalFile() ) {
412 KMessageBox::sorry( d->mainWidget,
413 i18n(
"You can only select local files."),
414 i18n(
"Remote Files Not Accepted") );
426 if ( (
mode() & KFile::Files) == KFile::Files ) {
427 TQString locationText = locationEdit->currentText();
428 if ( locationText.contains(
'/' )) {
430 KURL u( ops->
url(), KShell::tildeExpand(locationText));
448 KMessageBox::sorry( d->mainWidget, i18n(
"%1\ndoes not appear to be a valid URL.\n").arg(d->url.url()), i18n(
"Invalid URL") );
452 KURL url = TDEIO::NetAccess::mostLocalURL(
selectedURL,topLevelWidget());
453 if ( (
mode() & KFile::LocalOnly) == KFile::LocalOnly &&
454 !url.isLocalFile() ) {
455 KMessageBox::sorry( d->mainWidget,
456 i18n(
"You can only select local files."),
457 i18n(
"Remote Files Not Accepted") );
465 if ( (
mode() & KFile::Directory) == KFile::Directory ) {
466 kdDebug(tdefile_area) <<
"Directory" << endl;
468 if ( d->url.isLocalFile() ) {
469 if ( locationEdit->currentText().stripWhiteSpace().isEmpty() ) {
470 TQFileInfo info( d->url.path() );
471 if ( info.isDir() ) {
472 d->filenames = TQString::null;
474 d->urlList.append( d->url );
477 else if (!info.exists() && (
mode() & KFile::File) != KFile::File) {
479 if ( ops->
mkdir( d->url.url(),
true ))
486 if ( (
mode() & KFile::File) == KFile::File ||
487 (
mode() & KFile::Files) == KFile::Files )
493 if (
mode() & KFile::ExistingOnly )
497 KURL fullURL(d->url, locationEdit->currentText());
498 if ( TQFile::exists( fullURL.path() ) )
501 d->filenames = TQString::null;
511 d->filenames = locationEdit->currentText();
518 d->filenames = TQString::null;
520 d->urlList.append( d->url );
522 if (
mode() & KFile::ExistingOnly )
532 if (!kapp->authorizeURLAction(
"open", KURL(), d->url))
534 TQString msg = TDEIO::buildErrorString(TDEIO::ERR_ACCESS_DENIED, d->url.prettyURL());
535 KMessageBox::error( d->mainWidget, msg);
539 TDEIO::StatJob *job = 0L;
541 d->filenames = KShell::tildeExpand(locationEdit->currentText());
543 if ( (
mode() & KFile::Files) == KFile::Files &&
544 !locationEdit->currentText().contains(
'/' )) {
545 kdDebug(tdefile_area) <<
"Files\n";
546 KURL::List list = parseSelectedURLs();
547 for ( KURL::List::ConstIterator it = list.begin();
548 it != list.end(); ++it )
550 if (!kapp->authorizeURLAction(
"open", KURL(), *it))
552 TQString msg = TDEIO::buildErrorString(TDEIO::ERR_ACCESS_DENIED, (*it).prettyURL());
553 KMessageBox::error( d->mainWidget, msg);
557 for ( KURL::List::ConstIterator it = list.begin();
558 it != list.end(); ++it )
560 job = TDEIO::stat( *it, !(*it).isLocalFile() );
561 job->setWindow (topLevelWidget());
562 TDEIO::Scheduler::scheduleJob( job );
563 d->statJobs.append( job );
564 connect( job, TQ_SIGNAL( result(TDEIO::Job *) ),
565 TQ_SLOT( slotStatResult( TDEIO::Job *) ));
570 job = TDEIO::stat(d->url,!d->url.isLocalFile());
571 job->setWindow (topLevelWidget());
572 d->statJobs.append( job );
573 connect(job, TQ_SIGNAL(result(TDEIO::Job*)), TQ_SLOT(slotStatResult(TDEIO::Job*)));
577 static bool isDirectory (
const TDEIO::UDSEntry &t)
581 for (TDEIO::UDSEntry::ConstIterator it = t.begin();
585 if ((*it).m_uds == TDEIO::UDS_FILE_TYPE)
587 isDir = S_ISDIR ((mode_t) ((*it).m_long));
598 void KFileDialog::slotStatResult(TDEIO::Job* job)
600 kdDebug(tdefile_area) <<
"slotStatResult" << endl;
601 TDEIO::StatJob *sJob =
static_cast<TDEIO::StatJob *
>( job );
603 if ( !d->statJobs.removeRef( sJob ) ) {
607 int count = d->statJobs.count();
611 if (sJob->error() && count == 0 && !ops->
dirOnlyMode())
617 TDEIO::UDSEntry t = sJob->statResult();
622 d->filenames = TQString::null;
629 locationEdit->clearEdit();
630 locationEdit->lineEdit()->setEdited(
false );
642 kdDebug(tdefile_area) <<
"filename " << sJob->url().url() << endl;
648 void KFileDialog::accept()
650 setResult( TQDialog::Accepted );
652 *lastDirectory = ops->
url();
653 if (!d->fileClass.isEmpty())
657 locationEdit->changeItem( TQString::null, 0 );
660 TQValueListConstIterator<KURL> it = list.begin();
661 for ( ; it != list.end(); ++it ) {
662 const KURL& url = *it;
666 TQString file = url.isLocalFile() ? url.path(-1) : url.prettyURL(-1);
669 for (
int i = 1; i < locationEdit->count(); i++ ) {
670 if ( locationEdit->text( i ) == file ) {
671 locationEdit->removeItem( i-- );
675 locationEdit->insertItem( file, 1 );
678 TDEConfig *config = TDEGlobal::config();
679 config->setForceGlobal(
true );
681 config->setForceGlobal(
false );
686 KDialogBase::accept();
688 addToRecentDocuments();
690 if ( (
mode() & KFile::Files) != KFile::Files )
704 if ( (ops->
mode() & KFile::Files) != KFile::Files ) {
710 if ( !locationEdit->hasFocus() ) {
711 setLocationText( i->name() );
727 if ( (ops->
mode() & KFile::Files) != KFile::Files ) {
732 setLocationText( i->name() );
746 if ( locationEdit->hasFocus() )
749 locationEdit->lineEdit()->setEdited(
false );
753 locationEdit->clearEdit();
757 static const TQString &begin = TDEGlobal::staticQString(
" \"");
758 KFileItemListIterator it ( *list );
760 while ( (item = it.current()) ) {
761 text.append( begin ).append( item->name() ).append(
'\"' );
765 setLocationText( text.stripWhiteSpace() );
768 void KFileDialog::setLocationText(
const TQString& text )
773 disconnect( locationEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
774 this, TQ_SLOT( slotLocationChanged(
const TQString& ) ) );
775 locationEdit->setCurrentItem( 0 );
776 connect( locationEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
777 TQ_SLOT( slotLocationChanged(
const TQString& )) );
778 locationEdit->setEditText( text );
781 if ( d->operationMode == Saving && !locationEdit->isVisible())
782 setNonExtSelection();
785 static const char autocompletionWhatsThisText[] = I18N_NOOP(
"<p>While typing in the text area, you may be presented "
786 "with possible matches. "
787 "This feature can be controlled by clicking with the right mouse button "
788 "and selecting a preferred mode from the <b>Text Completion</b> menu.")
"</qt>";
789 void KFileDialog::updateLocationWhatsThis (
void)
791 TQString whatsThisText;
792 if (d->operationMode == KFileDialog::Saving)
794 whatsThisText =
"<qt>" + i18n(
"This is the name to save the file as.") +
795 i18n (autocompletionWhatsThisText);
797 else if (ops->
mode() & KFile::Files)
799 whatsThisText =
"<qt>" + i18n(
"This is the list of files to open. More than "
800 "one file can be specified by listing several "
801 "files, separated by spaces.") +
802 i18n (autocompletionWhatsThisText);
806 whatsThisText =
"<qt>" + i18n(
"This is the name of the file to open.") +
807 i18n (autocompletionWhatsThisText);
810 TQWhatsThis::add(d->locationLabel, whatsThisText);
811 TQWhatsThis::add(locationEdit, whatsThisText);
817 d =
new KFileDialogPrivate();
820 d->keepLocation =
false;
821 d->operationMode = Opening;
822 d->bookmarkHandler = 0;
823 d->hasDefaultFilter =
false;
825 d->mainWidget =
new TQWidget(
this,
"KFileDialog::mainWidget");
826 setMainWidget( d->mainWidget );
827 d->okButton =
new KPushButton( KStdGuiItem::ok(), d->mainWidget );
828 d->okButton->setDefault(
true );
829 d->cancelButton =
new KPushButton(KStdGuiItem::cancel(), d->mainWidget);
830 connect( d->okButton, TQ_SIGNAL( clicked() ), TQ_SLOT( slotOk() ));
831 connect( d->cancelButton, TQ_SIGNAL( clicked() ), TQ_SLOT( slotCancel() ));
832 d->customWidget = widget;
833 d->autoSelectExtCheckBox = 0;
834 d->autoSelectExtChecked =
false;
837 TQtMsgHandler oldHandler = qInstallMsgHandler( silenceQToolBar );
838 toolbar =
new TDEToolBar( d->mainWidget,
"KFileDialog::toolbar",
true);
839 toolbar->setFlat(
true);
840 qInstallMsgHandler( oldHandler );
842 d->pathCombo =
new KURLComboBox( KURLComboBox::Directories,
true,
843 toolbar,
"path combo" );
844 TQToolTip::add( d->pathCombo, i18n(
"Current location") );
845 TQWhatsThis::add( d->pathCombo,
"<qt>" + i18n(
"This is the currently listed location. "
846 "The drop-down list also lists commonly used locations. "
847 "This includes standard locations, such as your home folder, as well as "
848 "locations that have been visited recently.") + i18n (autocompletionWhatsThisText));
851 u.setPath( TQDir::rootDirPath() );
852 TQString text = i18n(
"Root Folder: %1").arg( u.path() );
853 d->pathCombo->addDefaultURL( u,
854 KMimeType::pixmapForURL( u, 0, TDEIcon::Small ),
857 u.setPath( TQDir::homeDirPath() );
858 text = i18n(
"Home Folder: %1").arg( u.path( +1 ) );
859 d->pathCombo->addDefaultURL( u, KMimeType::pixmapForURL( u, 0, TDEIcon::Small ),
863 docPath.setPath( TDEGlobalSettings::documentPath() );
864 if ( (u.path(+1) != docPath.path(+1)) &&
865 TQDir(docPath.path(+1)).exists() )
867 text = i18n(
"Documents: %1").arg( docPath.path( +1 ) );
868 d->pathCombo->addDefaultURL( docPath,
869 KMimeType::pixmapForURL( docPath, 0, TDEIcon::Small ),
873 u.setPath( TDEGlobalSettings::desktopPath() );
874 text = i18n(
"Desktop: %1").arg( u.path( +1 ) );
875 d->pathCombo->addDefaultURL( u,
876 KMimeType::pixmapForURL( u, 0, TDEIcon::Small ),
880 d->selection = d->url.url();
883 if ( d->url.isLocalFile() )
885 if ( !TQFile::exists( d->url.path() ) )
887 d->url = d->url.upURL();
888 TQDir dir( d->url.path() );
889 while ( !dir.exists() )
891 d->url = d->url.upURL();
892 dir.setPath( d->url.path() );
897 ops =
new KDirOperator(d->url, d->mainWidget,
"KFileDialog::ops");
899 connect(ops, TQ_SIGNAL(urlEntered(
const KURL&)),
900 TQ_SLOT(urlEntered(
const KURL&)));
903 connect(ops, TQ_SIGNAL(
fileSelected(
const KFileItem *)),
905 connect(ops, TQ_SIGNAL(finishedLoading()),
906 TQ_SLOT(slotLoadingFinished()));
908 ops->
setupMenu(KDirOperator::SortActions |
909 KDirOperator::FileActions |
910 KDirOperator::ViewActions);
914 coll->action(
"up" )->plug( toolbar );
915 coll->action(
"up" )->setWhatsThis(i18n(
"<qt>Click this button to enter the parent folder.<p>"
916 "For instance, if the current location is file:/home/%1 clicking this "
917 "button will take you to file:/home.</qt>").arg( KUser().loginName() ));
918 coll->action(
"back" )->plug( toolbar );
919 coll->action(
"back" )->setWhatsThis(i18n(
"Click this button to move backwards one step in the browsing history."));
920 coll->action(
"forward" )->plug( toolbar );
921 coll->action(
"forward" )->setWhatsThis(i18n(
"Click this button to move forward one step in the browsing history."));
922 coll->action(
"reload" )->plug( toolbar );
923 coll->action(
"reload" )->setWhatsThis(i18n(
"Click this button to reload the contents of the current location."));
924 coll->action(
"mkdir" )->setShortcut(Key_F10);
925 coll->action(
"mkdir" )->plug( toolbar );
926 coll->action(
"mkdir" )->setWhatsThis(i18n(
"Click this button to create a new folder."));
928 TDEToggleAction *showSidebarAction =
929 new TDEToggleAction(i18n(
"Show Quick Access Navigation Panel"), Key_F9, coll,
"toggleSpeedbar");
930 showSidebarAction->setCheckedState(i18n(
"Hide Quick Access Navigation Panel"));
931 connect( showSidebarAction, TQ_SIGNAL( toggled(
bool ) ),
934 TDEToggleAction *showBookmarksAction =
935 new TDEToggleAction(i18n(
"Show Bookmarks"), 0, coll,
"toggleBookmarks");
936 showBookmarksAction->setCheckedState(i18n(
"Hide Bookmarks"));
937 connect( showBookmarksAction, TQ_SIGNAL( toggled(
bool ) ),
940 TDEActionMenu *menu =
new TDEActionMenu( i18n(
"Configure"),
"configure",
this,
"extra menu" );
941 menu->setWhatsThis(i18n(
"<qt>This is the configuration menu for the file dialog. "
942 "Various options can be accessed from this menu including: <ul>"
943 "<li>how files are sorted in the list</li>"
944 "<li>types of view, including icon and list</li>"
945 "<li>showing of hidden files</li>"
946 "<li>the Quick Access navigation panel</li>"
947 "<li>file previews</li>"
948 "<li>separating folders from files</li></ul></qt>"));
949 menu->insert( coll->action(
"sorting menu" ));
950 menu->insert( coll->action(
"separator" ));
951 coll->action(
"short view" )->setShortcut(Key_F6);
952 menu->insert( coll->action(
"short view" ));
953 coll->action(
"detailed view" )->setShortcut(Key_F7);
954 menu->insert( coll->action(
"detailed view" ));
955 menu->insert( coll->action(
"separator" ));
956 coll->action(
"show hidden" )->setShortcut(Key_F8);
957 menu->insert( coll->action(
"show hidden" ));
958 menu->insert( showSidebarAction );
959 menu->insert( showBookmarksAction );
960 coll->action(
"preview" )->setShortcut(Key_F11);
961 menu->insert( coll->action(
"preview" ));
962 coll->action(
"separate dirs" )->setShortcut(Key_F12);
963 menu->insert( coll->action(
"separate dirs" ));
965 menu->setDelayed(
false );
966 connect( menu->popupMenu(), TQ_SIGNAL( aboutToShow() ),
967 ops, TQ_SLOT( updateSelectionDependentActions() ));
968 menu->plug( toolbar );
971 TDEToolBarSeparator* spacerWidget =
new TDEToolBarSeparator(TQt::Horizontal,
false ,
973 d->m_pathComboIndex = toolbar->insertWidget(-1, -1, spacerWidget);
974 toolbar->insertWidget(PATH_COMBO, 0, d->pathCombo);
977 toolbar->setItemAutoSized (PATH_COMBO);
978 toolbar->setIconText(TDEToolBar::IconOnly);
979 toolbar->setBarPos(TDEToolBar::Top);
980 toolbar->setMovingEnabled(
false);
981 toolbar->adjustSize();
983 KURLCompletion *pathCompletionObj =
new KURLCompletion( KURLCompletion::DirCompletion );
984 d->pathCombo->setCompletionObject( pathCompletionObj );
985 d->pathCombo->setAutoDeleteCompletionObject(
true );
987 connect( d->pathCombo, TQ_SIGNAL( urlActivated(
const KURL& )),
988 this, TQ_SLOT( enterURL(
const KURL& ) ));
989 connect( d->pathCombo, TQ_SIGNAL( returnPressed(
const TQString& )),
990 this, TQ_SLOT( enterURL(
const TQString& ) ));
991 connect( d->pathCombo, TQ_SIGNAL( activated(
const TQString& )),
992 this, TQ_SLOT( enterURL(
const TQString& ) ));
994 TQString whatsThisText;
997 d->locationLabel =
new TQLabel(i18n(
"&Location:"), d->mainWidget);
998 locationEdit =
new KURLComboBox(KURLComboBox::Files,
true,
999 d->mainWidget,
"LocationEdit");
1000 locationEdit->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed));
1001 connect( locationEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
1002 TQ_SLOT( slotLocationChanged(
const TQString& )) );
1004 updateLocationWhatsThis ();
1005 d->locationLabel->setBuddy(locationEdit);
1007 locationEdit->setFocus();
1008 KURLCompletion *fileCompletionObj =
new KURLCompletion( KURLCompletion::FileCompletion );
1009 TQString dir = d->url.url(+1);
1010 pathCompletionObj->setDir( dir );
1011 fileCompletionObj->setDir( dir );
1012 locationEdit->setCompletionObject( fileCompletionObj );
1013 locationEdit->setAutoDeleteCompletionObject(
true );
1014 connect( fileCompletionObj, TQ_SIGNAL( match(
const TQString& ) ),
1015 TQ_SLOT( fileCompletion(
const TQString& )) );
1017 connect( locationEdit, TQ_SIGNAL( returnPressed() ),
1018 this, TQ_SLOT( slotOk()));
1019 connect(locationEdit, TQ_SIGNAL( activated(
const TQString& )),
1020 this, TQ_SLOT( locationActivated(
const TQString& ) ));
1023 whatsThisText = i18n(
"<qt>This is the filter to apply to the file list. "
1024 "File names that do not match the filter will not be shown.<p>"
1025 "You may select from one of the preset filters in the "
1026 "drop down menu, or you may enter a custom filter "
1027 "directly into the text area.<p>"
1028 "Wildcards such as * and ? are allowed.</qt>");
1029 d->filterLabel =
new TQLabel(i18n(
"&Filter:"), d->mainWidget);
1030 TQWhatsThis::add(d->filterLabel, whatsThisText);
1031 filterWidget =
new KFileFilterCombo(d->mainWidget,
1032 "KFileDialog::filterwidget");
1033 filterWidget->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed));
1034 TQWhatsThis::add(filterWidget, whatsThisText);
1036 d->filterLabel->setBuddy(filterWidget);
1037 connect(filterWidget, TQ_SIGNAL(
filterChanged()), TQ_SLOT(slotFilterChanged()));
1041 d->autoSelectExtCheckBox =
new TQCheckBox (d->mainWidget);
1042 connect(d->autoSelectExtCheckBox, TQ_SIGNAL(clicked()), TQ_SLOT(slotAutoSelectExtClicked()));
1046 TDEConfig* config = TDEGlobal::config();
1056 void KFileDialog::initSpeedbar()
1058 d->urlBar =
new KFileSpeedBar( d->mainWidget,
"url bar" );
1059 connect( d->urlBar, TQ_SIGNAL( activated(
const KURL& )),
1060 TQ_SLOT( enterURL(
const KURL& )) );
1066 d->urlBar->setCurrentItem( d->url );
1068 d->urlBarLayout->insertWidget( 0, d->urlBar );
1073 delete d->boxLayout;
1075 d->boxLayout =
new TQVBoxLayout( d->mainWidget, 0, KDialog::spacingHint());
1076 d->boxLayout->addWidget(toolbar, AlignTop);
1078 d->urlBarLayout =
new TQHBoxLayout( d->boxLayout );
1079 TQVBoxLayout *vbox =
new TQVBoxLayout( d->urlBarLayout );
1081 vbox->addWidget(ops, 4);
1082 vbox->addSpacing(3);
1084 TQGridLayout* lafBox=
new TQGridLayout(2, 3, KDialog::spacingHint());
1086 lafBox->addWidget(d->locationLabel, 0, 0, TQt::AlignVCenter);
1087 lafBox->addWidget(locationEdit, 0, 1, TQt::AlignVCenter);
1088 lafBox->addWidget(d->okButton, 0, 2, TQt::AlignVCenter);
1090 lafBox->addWidget(d->filterLabel, 1, 0, TQt::AlignVCenter);
1091 lafBox->addWidget(filterWidget, 1, 1, TQt::AlignVCenter);
1092 lafBox->addWidget(d->cancelButton, 1, 2, TQt::AlignVCenter);
1094 lafBox->setColStretch(1, 4);
1096 vbox->addLayout(lafBox, 0);
1097 vbox->addSpacing(3);
1100 vbox->addWidget (d->autoSelectExtCheckBox);
1101 vbox->addSpacing (3);
1103 setTabOrder(ops, d->autoSelectExtCheckBox);
1104 setTabOrder (d->autoSelectExtCheckBox, locationEdit);
1105 setTabOrder(locationEdit, filterWidget);
1106 setTabOrder(filterWidget, d->okButton);
1107 setTabOrder(d->okButton, d->cancelButton);
1108 setTabOrder(d->cancelButton, d->pathCombo);
1109 setTabOrder(d->pathCombo, ops);
1112 if ( d->customWidget != 0 )
1117 d->customWidget->reparent( d->mainWidget, TQPoint() );
1119 vbox->addWidget( d->customWidget );
1120 vbox->addSpacing(3);
1127 setTabOrder(d->cancelButton, d->customWidget);
1128 setTabOrder(d->customWidget, d->pathCombo);
1132 setTabOrder(d->cancelButton, d->pathCombo);
1135 setTabOrder(d->pathCombo, ops);
1138 void KFileDialog::slotFilterChanged()
1140 TQString filter = filterWidget->currentFilter();
1143 if ( filter.find(
'/' ) > -1 ) {
1144 TQStringList types = TQStringList::split(
" ", filter );
1145 types.prepend(
"inode/directory" );
1161 d->selection = TQString::null;
1162 ops->
setURL( url, clearforward);
1166 void KFileDialog::urlEntered(
const KURL& url)
1168 TQString filename = locationEdit->currentText();
1169 d->selection = TQString::null;
1171 if ( d->pathCombo->count() != 0 ) {
1172 d->pathCombo->setURL( url );
1175 locationEdit->blockSignals(
true );
1176 locationEdit->setCurrentItem( 0 );
1177 if ( d->keepLocation )
1178 locationEdit->setEditText( filename );
1180 locationEdit->blockSignals(
false );
1182 TQString dir = url.url(+1);
1183 static_cast<KURLCompletion*
>( d->pathCombo->completionObject() )->setDir( dir );
1184 static_cast<KURLCompletion*
>( locationEdit->completionObject() )->setDir( dir );
1187 d->urlBar->setCurrentItem( url );
1190 void KFileDialog::locationActivated(
const TQString& url )
1197 if (!locationEdit->lineEdit()->edited())
1201 void KFileDialog::enterURL(
const KURL& url)
1206 void KFileDialog::enterURL(
const TQString& url )
1208 setURL( KURL::fromPathOrURL( KURLCompletion::replacedPath( url,
true,
true )) );
1222 kdDebug(tdefile_area) <<
"setSelection " << url << endl;
1224 if (url.isEmpty()) {
1225 d->selection = TQString::null;
1231 kdWarning() << url <<
" is not a correct argument for setSelection!" << endl;
1235 if (!KProtocolInfo::supportsListing(u)) {
1236 locationEdit->lineEdit()->setEdited(
true );
1243 KFileItem i(KFileItem::Unknown, KFileItem::Unknown, u,
true );
1245 if ( i.isDir() && u.isLocalFile() && TQFile::exists( u.path() ) ) {
1253 TQString filename = u.url();
1254 int sep = filename.findRev(
'/');
1256 if ( KProtocolInfo::supportsListing( u )) {
1258 dir.setQuery( TQString::null );
1259 dir.setFileName( TQString::null );
1265 filename = u.fileName();
1266 kdDebug(tdefile_area) <<
"filename " << filename << endl;
1267 d->selection = filename;
1268 setLocationText( filename );
1277 locationEdit->lineEdit()->setEdited(
true );
1280 d->url = ops->
url();
1281 d->url.addPath(filename);
1285 void KFileDialog::slotLoadingFinished()
1287 if ( !d->selection.isNull() )
1298 void KFileDialog::fileCompletion(
const TQString& match )
1300 if ( match.isEmpty() && ops->
view() )
1306 void KFileDialog::slotLocationChanged(
const TQString& text )
1308 if ( text.isEmpty() && ops->
view() )
1316 kdWarning() <<
"KFileDialog::updateStatusLine is deprecated! The status line no longer exists. Do not try and use it!" << endl;
1320 const TQString& filter,
1321 TQWidget *parent,
const TQString& caption)
1323 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1326 dlg.
setMode( KFile::File | KFile::LocalOnly );
1327 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1336 const TQString& filter,
1337 WId parent_id,
const TQString& caption)
1339 TQWidget* parent = TQWidget::find( parent_id );
1340 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1342 if( parent == NULL && parent_id != 0 )
1343 XSetTransientForHint( tqt_xdisplay(), dlg.winId(), parent_id );
1350 dlg.
setMode( KFile::File | KFile::LocalOnly );
1351 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1360 const TQString& filter,
1362 const TQString& caption)
1364 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1367 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1368 dlg.
setMode(KFile::Files | KFile::LocalOnly);
1376 TQWidget *parent,
const TQString& caption)
1378 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1381 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1390 const TQString& filter,
1392 const TQString& caption)
1394 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1397 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1407 const TQString& caption)
1414 const TQString& caption)
1417 return TQFileDialog::getExistingDirectory(startDir, parent,
"getExistingDirectory",
1418 caption,
true,
true);
1422 if ( url.isValid() )
1425 return TQString::null;
1430 const TQString& caption)
1432 TQStringList mimetypes = KImageIO::mimeTypes( KImageIO::Reading );
1434 mimetypes.join(
" "),
1435 parent,
"filedialog",
true);
1437 dlg.setCaption( caption.isNull() ? i18n(
"Open") : caption );
1449 if ( result() == TQDialog::Accepted )
1458 if ( result() == TQDialog::Accepted ) {
1459 if ( (ops->
mode() & KFile::Files) == KFile::Files )
1460 list = parseSelectedURLs();
1462 list.append( d->url );
1468 KURL::List& KFileDialog::parseSelectedURLs()
const
1470 if ( d->filenames.isEmpty() ) {
1475 if ( d->filenames.contains(
'/' )) {
1476 static const TQString &prot = TDEGlobal::staticQString(
":/");
1478 if ( d->filenames.find( prot ) != -1 )
1481 u.setPath( d->filenames );
1484 d->urlList.append( u );
1486 KMessageBox::error( d->mainWidget,
1487 i18n(
"The chosen filenames do not\n"
1488 "appear to be valid."),
1489 i18n(
"Invalid Filenames") );
1493 d->urlList =
tokenize( d->filenames );
1495 d->filenames = TQString::null;
1505 KURL u( ops->
url() );
1508 int count = line.contains(
'"' );
1510 u.setFileName( line );
1517 if ( (count % 2) == 1 ) {
1519 KMessageBox::sorry(that, i18n(
"The requested filenames\n"
1521 "do not appear to be valid;\n"
1522 "make sure every filename is enclosed in double quotes.").arg(line),
1523 i18n(
"Filename Error"));
1528 int index1 = -1, index2 = -1;
1530 index1 = line.find(
'"', start );
1531 index2 = line.find(
'"', index1 + 1 );
1537 name = line.mid( index1 + 1, index2 - index1 - 1 );
1538 u.setFileName( name );
1550 if ( result() == TQDialog::Accepted )
1552 KURL url = TDEIO::NetAccess::mostLocalURL(d->url,topLevelWidget());
1553 if (url.isLocalFile())
1556 KMessageBox::sorry( d->mainWidget,
1557 i18n(
"You can only select local files."),
1558 i18n(
"Remote Files Not Accepted") );
1561 return TQString::null;
1569 if ( result() == TQDialog::Accepted ) {
1570 if ( (ops->
mode() & KFile::Files) == KFile::Files ) {
1571 KURL::List urls = parseSelectedURLs();
1572 TQValueListConstIterator<KURL> it = urls.begin();
1573 while ( it != urls.end() ) {
1574 url = TDEIO::NetAccess::mostLocalURL(*it,topLevelWidget());
1575 if ( url.isLocalFile() )
1576 list.append( url.path() );
1582 if ( d->url.isLocalFile() )
1583 list.append( d->url.path() );
1597 const TQString& caption)
1599 bool specialDir = dir.at(0) ==
':';
1600 KFileDialog dlg( specialDir ? dir : TQString::null, filter, parent,
"filedialog",
true);
1605 dlg.setCaption(caption.isNull() ? i18n(
"Save As") : caption);
1610 if (!filename.isEmpty())
1618 const TQString& caption)
1620 bool specialDir = dir.at(0) ==
':';
1621 TQWidget* parent = TQWidget::find( parent_id );
1622 KFileDialog dlg( specialDir ? dir : TQString::null, filter, parent,
"filedialog",
true);
1624 if( parent == NULL && parent_id != 0 )
1625 XSetTransientForHint(tqt_xdisplay(), dlg.winId(), parent_id);
1634 dlg.setCaption(caption.isNull() ? i18n(
"Save As") : caption);
1639 if (!filename.isEmpty())
1646 TQWidget *parent,
const TQString& caption)
1648 bool specialDir = dir.at(0) ==
':';
1649 KFileDialog dlg(specialDir ? dir : TQString::null, filter, parent,
"filedialog",
true);
1653 dlg.setCaption(caption.isNull() ? i18n(
"Save As") : caption);
1665 void KFileDialog::show()
1667 if ( !d->hasView ) {
1673 KDialogBase::show();
1680 filterWidget->setDefaultFilter( i18n(
"*|All Folders") );
1683 filterWidget->setDefaultFilter( i18n(
"*|All Files") );
1705 TQString oldGroup = kc->group();
1706 if ( !group.isEmpty() )
1707 kc->setGroup( group );
1712 combo->
setURLs( kc->readPathListEntry( RecentURLs ), KURLComboBox::RemoveTop );
1713 combo->
setMaxItems( kc->readNumEntry( RecentURLsNumber,
1714 DefaultRecentURLsNumber ) );
1716 autoDirectoryFollowing = kc->readBoolEntry( AutoDirectoryFollowing,
1717 DefaultDirectoryFollowing );
1719 TDEGlobalSettings::Completion cm = (TDEGlobalSettings::Completion)
1720 kc->readNumEntry( PathComboCompletionMode,
1721 TDEGlobalSettings::completionMode() );
1722 if ( cm != TDEGlobalSettings::completionMode() )
1723 combo->setCompletionMode( cm );
1725 cm = (TDEGlobalSettings::Completion)
1726 kc->readNumEntry( LocationComboCompletionMode,
1727 TDEGlobalSettings::completionMode() );
1728 if ( cm != TDEGlobalSettings::completionMode() )
1729 locationEdit->setCompletionMode( cm );
1738 d->autoSelectExtChecked = kc->readBoolEntry (AutoSelectExtChecked, DefaultAutoSelectExtChecked);
1741 int w1 = minimumSize().width();
1742 int w2 = toolbar->sizeHint().width() + 10;
1744 setMinimumWidth(w2);
1746 TQSize size = configDialogSize( group );
1748 kc->setGroup( oldGroup );
1756 TQString oldGroup = kc->group();
1757 if ( !group.isEmpty() )
1758 kc->setGroup( group );
1760 kc->writePathEntry( RecentURLs, d->pathCombo->urls() );
1761 saveDialogSize( group,
true );
1762 kc->writeEntry( PathComboCompletionMode,
static_cast<int>(d->pathCombo->completionMode()) );
1763 kc->writeEntry( LocationComboCompletionMode,
static_cast<int>(locationEdit->completionMode()) );
1764 kc->writeEntry( ShowSpeedbar, d->urlBar && !d->urlBar->isHidden() );
1765 kc->writeEntry( ShowBookmarks, d->bookmarkHandler != 0 );
1766 kc->writeEntry( AutoSelectExtChecked, d->autoSelectExtChecked );
1769 kc->setGroup( oldGroup );
1775 TQString oldGroup = kc->group();
1776 kc->setGroup( ConfigGroup );
1778 locationEdit->
setMaxItems( kc->readNumEntry( RecentFilesNumber,
1779 DefaultRecentURLsNumber ) );
1780 locationEdit->
setURLs( kc->readPathListEntry( RecentFiles ),
1781 KURLComboBox::RemoveBottom );
1782 locationEdit->insertItem( TQString::null, 0 );
1783 locationEdit->setCurrentItem( 0 );
1785 kc->setGroup( oldGroup );
1790 TQString oldGroup = kc->group();
1791 kc->setGroup( ConfigGroup );
1793 kc->writePathEntry( RecentFiles, locationEdit->
urls() );
1795 kc->setGroup( oldGroup );
1805 return d->cancelButton;
1813 void KFileDialog::slotCancel()
1816 KDialogBase::slotCancel();
1818 TDEConfig *config = TDEGlobal::config();
1819 config->setForceGlobal(
true );
1821 config->setForceGlobal(
false );
1826 d->keepLocation = keep;
1831 return d->keepLocation;
1836 d->operationMode =
mode;
1837 d->keepLocation = (
mode == Saving);
1838 filterWidget->setEditable( !d->hasDefaultFilter ||
mode != Saving );
1839 if (
mode == Opening )
1840 d->okButton->setGuiItem( KGuiItem( i18n(
"&Open"),
"document-open") );
1841 else if (
mode == Saving ) {
1842 d->okButton->setGuiItem( KStdGuiItem::save() );
1843 setNonExtSelection();
1846 d->okButton->setGuiItem( KStdGuiItem::ok() );
1847 updateLocationWhatsThis ();
1853 return d->operationMode;
1856 void KFileDialog::slotAutoSelectExtClicked()
1858 kdDebug (tdefile_area) <<
"slotAutoSelectExtClicked(): "
1859 << d->autoSelectExtCheckBox->isChecked () << endl;
1862 d->autoSelectExtChecked = d->autoSelectExtCheckBox->isChecked ();
1865 updateLocationEditExtension (d->extension );
1868 static TQString getExtensionFromPatternList (
const TQStringList &patternList)
1871 kdDebug (tdefile_area) <<
"\tgetExtension " << patternList << endl;
1873 TQStringList::ConstIterator patternListEnd = patternList.end ();
1874 for (TQStringList::ConstIterator it = patternList.begin ();
1875 it != patternListEnd;
1878 kdDebug (tdefile_area) <<
"\t\ttry: \'" << (*it) <<
"\'" << endl;
1887 if ((*it).startsWith (
"*.") &&
1888 (*it).length () > 2 &&
1889 (*it).find (
'*', 2) < 0 && (*it).find (
'?', 2) < 0)
1891 ret = (*it).mid (1);
1899 static TQString stripUndisplayable (
const TQString &
string)
1901 TQString ret = string;
1912 return d->extension;
1917 if (!d->autoSelectExtCheckBox)
return;
1926 kdDebug (tdefile_area) <<
"Figure out an extension: " << endl;
1927 TQString lastExtension = d->extension;
1928 d->extension = TQString::null;
1938 if (!filter.isEmpty ())
1941 if (filter.find (
'/') < 0)
1943 d->extension = getExtensionFromPatternList (TQStringList::split (
" ", filter)).lower ();
1944 kdDebug (tdefile_area) <<
"\tsetFilter-style: pattern ext=\'"
1945 << d->extension <<
"\'" << endl;
1950 KMimeType::Ptr mime = KMimeType::mimeType (filter);
1953 TQString nativeExtension = mime->property (
"X-TDE-NativeExtension").toString ();
1954 if (nativeExtension.at (0) ==
'.')
1956 d->extension = nativeExtension.lower ();
1957 kdDebug (tdefile_area) <<
"\tsetMimeFilter-style: native ext=\'"
1958 << d->extension <<
"\'" << endl;
1962 if (d->extension.isEmpty ())
1964 d->extension = getExtensionFromPatternList (mime->patterns ()).lower ();
1965 kdDebug (tdefile_area) <<
"\tsetMimeFilter-style: pattern ext=\'"
1966 << d->extension <<
"\'" << endl;
1976 TQString whatsThisExtension;
1977 if (!d->extension.isEmpty ())
1980 d->autoSelectExtCheckBox->setText (i18n (
"Automatically select filename e&xtension (%1)").arg (d->extension));
1981 whatsThisExtension = i18n (
"the extension <b>%1</b>").arg (d->extension);
1983 d->autoSelectExtCheckBox->setEnabled (
true);
1984 d->autoSelectExtCheckBox->setChecked (d->autoSelectExtChecked);
1989 d->autoSelectExtCheckBox->setText (i18n (
"Automatically select filename e&xtension"));
1990 whatsThisExtension = i18n (
"a suitable extension");
1992 d->autoSelectExtCheckBox->setChecked (
false);
1993 d->autoSelectExtCheckBox->setEnabled (
false);
1996 const TQString locationLabelText = stripUndisplayable (d->locationLabel->text ());
1997 const TQString filterLabelText = stripUndisplayable (d->filterLabel->text ());
1998 TQWhatsThis::add (d->autoSelectExtCheckBox,
2001 "This option enables some convenient features for "
2002 "saving files with extensions:<br>"
2004 "<li>Any extension specified in the <b>%1</b> text "
2005 "area will be updated if you change the file type "
2008 "<li>If no extension is specified in the <b>%2</b> "
2009 "text area when you click "
2010 "<b>Save</b>, %3 will be added to the end of the "
2011 "filename (if the filename does not already exist). "
2012 "This extension is based on the file type that you "
2013 "have chosen to save in.<br>"
2015 "If you do not want TDE to supply an extension for the "
2016 "filename, you can either turn this option off or you "
2017 "can suppress it by adding a period (.) to the end of "
2018 "the filename (the period will be automatically "
2022 "If unsure, keep this option enabled as it makes your "
2023 "files more manageable."
2025 .arg (locationLabelText)
2026 .arg (locationLabelText)
2027 .arg (whatsThisExtension)
2031 d->autoSelectExtCheckBox->show ();
2035 updateLocationEditExtension (lastExtension);
2040 d->autoSelectExtCheckBox->setChecked (
false);
2041 d->autoSelectExtCheckBox->hide ();
2048 void KFileDialog::updateLocationEditExtension (
const TQString &lastExtension)
2050 if (!d->autoSelectExtCheckBox->isChecked () || d->extension.isEmpty ())
2053 TQString urlStr = locationEdit->currentText ();
2054 if (urlStr.isEmpty ())
2058 kdDebug (tdefile_area) <<
"updateLocationEditExtension (" << url <<
")" << endl;
2060 const int fileNameOffset = urlStr.findRev (
'/') + 1;
2061 TQString fileName = urlStr.mid (fileNameOffset);
2063 const int dot = fileName.findRev (
'.');
2064 const int len = fileName.length ();
2072 if (TDEIO::NetAccess::stat (url, t, topLevelWidget()))
2074 kdDebug (tdefile_area) <<
"\tfile exists" << endl;
2076 if (isDirectory (t))
2078 kdDebug (tdefile_area) <<
"\tisDir - won't alter extension" << endl;
2091 if (lastExtension.length () && fileName.endsWith (lastExtension))
2092 fileName.truncate (len - lastExtension.length ());
2095 fileName.truncate (dot);
2098 const TQString newText = urlStr.left (fileNameOffset) + fileName + d->extension;
2099 if ( newText != locationEdit->currentText() )
2101 locationEdit->setCurrentText (urlStr.left (fileNameOffset) + fileName + d->extension);
2102 locationEdit->lineEdit()->setEdited (
true);
2109 void KFileDialog::updateFilter ()
2112 const TQString urlStr = locationEdit->currentText ();
2113 if (urlStr.isEmpty ())
2116 KMimeType::Ptr mime = KMimeType::findByPath(urlStr, 0,
true);
2117 if (mime && mime->name() != KMimeType::defaultMimeType()) {
2118 if (filterWidget->currentFilter() != mime->name() &&
2119 filterWidget->filters.findIndex(mime->name()) != -1) {
2120 filterWidget->setCurrentFilter(mime->name());
2127 void KFileDialog::appendExtension (KURL &url)
2129 if (!d->autoSelectExtCheckBox->isChecked () || d->extension.isEmpty ())
2132 TQString fileName = url.fileName ();
2133 if (fileName.isEmpty ())
2136 kdDebug (tdefile_area) <<
"appendExtension(" << url <<
")" << endl;
2138 const int len = fileName.length ();
2139 const int dot = fileName.findRev (
'.');
2141 const bool suppressExtension = (dot == len - 1);
2142 const bool unspecifiedExtension = (dot <= 0);
2145 if (!(suppressExtension || unspecifiedExtension))
2150 if (TDEIO::NetAccess::stat (url, t, topLevelWidget()))
2152 kdDebug (tdefile_area) <<
"\tfile exists - won't append extension" << endl;
2157 if (suppressExtension)
2169 kdDebug (tdefile_area) <<
"\tstrip trailing dot" << endl;
2170 url.setFileName (fileName.left (len - 1));
2173 else if (unspecifiedExtension)
2175 kdDebug (tdefile_area) <<
"\tappending extension \'" << d->extension <<
"\'..." << endl;
2176 url.setFileName (fileName + d->extension);
2177 kdDebug (tdefile_area) <<
"\tsaving as \'" << url <<
"\'" << endl;
2183 void KFileDialog::addToRecentDocuments()
2185 int m = ops->
mode();
2187 if ( m & KFile::LocalOnly ) {
2189 TQStringList::ConstIterator it = files.begin();
2190 for ( ; it != files.end(); ++it )
2196 KURL::List::ConstIterator it = urls.begin();
2197 for ( ; it != urls.end(); ++it ) {
2198 if ( (*it).isValid() )
2211 if ( e->key() == Key_Escape )
2214 d->cancelButton->animateClick();
2217 KDialogBase::keyPressEvent( e );
2232 homeURL.setPath( TQDir::homeDirPath() );
2235 if ( homeURL.equals( urlItem->
url(),
true ) )
2241 urlItem =
static_cast<KURLBarItem*
>( urlItem->next() );
2253 static_cast<TDEToggleAction *
>(
actionCollection()->action(
"toggleSpeedbar"))->setChecked( show );
2260 if (d->bookmarkHandler)
2265 d->bookmarkHandler =
new KFileBookmarkHandler(
this );
2266 connect( d->bookmarkHandler, TQ_SIGNAL( openURL(
const TQString& )),
2267 TQ_SLOT( enterURL(
const TQString& )));
2269 toolbar->insertButton(TQString::fromLatin1(
"bookmark"),
2270 (
int)HOTLIST_BUTTON,
true,
2271 i18n(
"Bookmarks"), 5);
2272 toolbar->getButton(HOTLIST_BUTTON)->setPopup(d->bookmarkHandler->menu(),
2274 TQWhatsThis::add(toolbar->getButton(HOTLIST_BUTTON),
2275 i18n(
"<qt>This button allows you to bookmark specific locations. "
2276 "Click on this button to open the bookmark menu where you may add, "
2277 "edit or select a bookmark.<p>"
2278 "These bookmarks are specific to the file dialog, but otherwise operate "
2279 "like bookmarks elsewhere in TDE.</qt>"));
2281 else if (d->bookmarkHandler)
2283 delete d->bookmarkHandler;
2284 d->bookmarkHandler = 0;
2285 toolbar->removeItem(HOTLIST_BUTTON);
2288 static_cast<TDEToggleAction *
>(
actionCollection()->action(
"toggleBookmarks"))->setChecked( show );
2293 return d->m_pathComboIndex;
2297 void KFileDialog::initStatic()
2299 if ( lastDirectory )
2302 lastDirectory = ldd.setObject(lastDirectory,
new KURL());
2307 TQString& recentDirClass )
2311 recentDirClass = TQString::null;
2314 bool useDefaultStartDir = startDir.isEmpty();
2315 if ( !useDefaultStartDir )
2317 if (startDir[0] ==
':')
2319 recentDirClass = startDir;
2324 ret = TDECmdLineArgs::makeURL( TQFile::encodeName(startDir) );
2326 if ( !KProtocolInfo::supportsListing( ret ) )
2327 useDefaultStartDir =
true;
2331 if ( useDefaultStartDir )
2333 if (lastDirectory->isEmpty()) {
2334 lastDirectory->setPath(TDEGlobalSettings::documentPath());
2336 home.setPath( TQDir::homeDirPath() );
2341 if ( lastDirectory->path(+1) == home.path(+1) ||
2342 TQDir::currentDirPath() != TQDir::homeDirPath() ||
2343 !TQDir(lastDirectory->path(+1)).exists() )
2344 lastDirectory->setPath(TQDir::currentDirPath());
2346 ret = *lastDirectory;
2352 void KFileDialog::setStartDir(
const KURL& directory )
2355 if ( directory.isValid() )
2356 *lastDirectory = directory;
2359 void KFileDialog::setNonExtSelection()
2362 TQString pattern, filename = locationEdit->currentText().stripWhiteSpace();
2363 KServiceTypeFactory::self()->findFromPattern( filename, &pattern );
2365 if ( !pattern.isEmpty() && pattern.at( 0 ) ==
'*' && pattern.find(
'*' , 1 ) == -1 )
2366 locationEdit->lineEdit()->setSelection( 0, filename.length() - pattern.stripWhiteSpace().length()+1 );
2369 int lastDot = filename.findRev(
'.' );
2371 locationEdit->lineEdit()->setSelection( 0, lastDot );
2375 void KFileDialog::virtual_hook(
int id,
void* data )
2376 { KDialogBase::virtual_hook(
id, data ); }
2379 #include "tdefiledialog.moc"