25 #include "kfiledialog.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>
47 #include <kapplication.h>
48 #include <kcharsets.h>
49 #include <kcmdlineargs.h>
50 #include <kcompletionbox.h>
54 #include <kglobalsettings.h>
55 #include <kiconloader.h>
58 #include <kio/netaccess.h>
59 #include <kio/scheduler.h>
60 #include <kio/kservicetypefactory.h>
62 #include <kmessagebox.h>
63 #include <kmimetype.h>
64 #include <kpopupmenu.h>
65 #include <kprotocolinfo.h>
66 #include <kpushbutton.h>
67 #include <krecentdirs.h>
69 #include <kstandarddirs.h>
70 #include <kstdguiitem.h>
71 #include <kstaticdeleter.h>
73 #include <ktoolbarbutton.h>
75 #include <kurlcombobox.h>
76 #include <kurlcompletion.h>
79 #include "config-kfile.h"
80 #include "kpreviewwidgetbase.h"
82 #include <kdirselectdialog.h>
83 #include <kfileview.h>
84 #include <krecentdocument.h>
85 #include <kfilefiltercombo.h>
86 #include <kdiroperator.h>
87 #include <kimagefilepreview.h>
89 #include <kfilespeedbar.h>
90 #include <kfilebookmarkhandler.h>
97 enum Buttons { HOTLIST_BUTTON,
98 PATH_COMBO, CONFIGURE_BUTTON };
100 template class TQPtrList<KIO::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<KIO::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 KConfig *config = KGlobal::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(kfile_area) <<
"slotOK\n";
341 if ( (
mode() & KFile::Directory) != KFile::Directory ) {
342 if ( locationEdit->currentText().stripWhiteSpace().isEmpty() ) {
343 if ( !items || items->isEmpty() )
346 if ( d->operationMode == Saving )
347 msg = i18n(
"Please specify the filename to save to.");
349 msg = i18n(
"Please select the file to open.");
350 KMessageBox::information(
this, msg);
358 bool multi = (
mode() & KFile::Files) != 0;
359 KFileItemListIterator it( *items );
360 TQString endQuote = TQString::fromLatin1(
"\" ");
361 TQString name, files;
362 while ( it.current() ) {
363 name = (*it)->name();
366 name.append( endQuote );
369 files.append( name );
372 setLocationText( files );
381 if ( items && !locationEdit->lineEdit()->edited() &&
382 !(items->isEmpty() && !dirOnly) ) {
385 d->filenames = TQString::null;
391 if ( !(
mode() & KFile::Files) ) {
392 d->url = items->getFirst()->url();
397 KFileItemListIterator it( *items );
398 while ( it.current() ) {
399 d->urlList.append( (*it)->url() );
405 KURL url = KIO::NetAccess::mostLocalURL(d->url,topLevelWidget());
406 if ( (
mode() & KFile::LocalOnly) == KFile::LocalOnly &&
407 !url.isLocalFile() ) {
409 KMessageBox::sorry( d->mainWidget,
410 i18n(
"You can only select local files."),
411 i18n(
"Remote Files Not Accepted") );
423 if ( (
mode() & KFile::Files) == KFile::Files ) {
424 TQString locationText = locationEdit->currentText();
425 if ( locationText.contains(
'/' )) {
427 KURL u( ops->
url(), KShell::tildeExpand(locationText));
431 selectedURL = ops->
url();
434 selectedURL = ops->
url();
441 appendExtension (selectedURL);
444 if ( !selectedURL.isValid() ) {
445 KMessageBox::sorry( d->mainWidget, i18n(
"%1\ndoes not appear to be a valid URL.\n").arg(d->url.url()), i18n(
"Invalid URL") );
449 KURL url = KIO::NetAccess::mostLocalURL(selectedURL,topLevelWidget());
450 if ( (
mode() & KFile::LocalOnly) == KFile::LocalOnly &&
451 !url.isLocalFile() ) {
452 KMessageBox::sorry( d->mainWidget,
453 i18n(
"You can only select local files."),
454 i18n(
"Remote Files Not Accepted") );
462 if ( (
mode() & KFile::Directory) == KFile::Directory ) {
463 kdDebug(kfile_area) <<
"Directory" << endl;
465 if ( d->url.isLocalFile() ) {
466 if ( locationEdit->currentText().stripWhiteSpace().isEmpty() ) {
467 TQFileInfo info( d->url.path() );
468 if ( info.isDir() ) {
469 d->filenames = TQString::null;
471 d->urlList.append( d->url );
474 else if (!info.exists() && (
mode() & KFile::File) != KFile::File) {
476 if ( ops->
mkdir( d->url.url(), true ))
483 if ( (
mode() & KFile::File) == KFile::File ||
484 (
mode() & KFile::Files) == KFile::Files )
490 if (
mode() & KFile::ExistingOnly )
494 KURL fullURL(d->url, locationEdit->currentText());
495 if ( TQFile::exists( fullURL.path() ) )
498 d->filenames = TQString::null;
508 d->filenames = locationEdit->currentText();
515 d->filenames = TQString::null;
517 d->urlList.append( d->url );
519 if (
mode() & KFile::ExistingOnly )
529 if (!kapp->authorizeURLAction(
"open", KURL(), d->url))
531 TQString msg = KIO::buildErrorString(KIO::ERR_ACCESS_DENIED, d->url.prettyURL());
532 KMessageBox::error( d->mainWidget, msg);
536 KIO::StatJob *job = 0L;
538 d->filenames = KShell::tildeExpand(locationEdit->currentText());
540 if ( (
mode() & KFile::Files) == KFile::Files &&
541 !locationEdit->currentText().contains(
'/' )) {
542 kdDebug(kfile_area) <<
"Files\n";
543 KURL::List list = parseSelectedURLs();
544 for ( KURL::List::ConstIterator it = list.begin();
545 it != list.end(); ++it )
547 if (!kapp->authorizeURLAction(
"open", KURL(), *it))
549 TQString msg = KIO::buildErrorString(KIO::ERR_ACCESS_DENIED, (*it).prettyURL());
550 KMessageBox::error( d->mainWidget, msg);
554 for ( KURL::List::ConstIterator it = list.begin();
555 it != list.end(); ++it )
557 job = KIO::stat( *it, !(*it).isLocalFile() );
558 job->setWindow (topLevelWidget());
559 KIO::Scheduler::scheduleJob( job );
560 d->statJobs.append( job );
561 connect( job, TQT_SIGNAL( result(KIO::Job *) ),
562 TQT_SLOT( slotStatResult( KIO::Job *) ));
567 job = KIO::stat(d->url,!d->url.isLocalFile());
568 job->setWindow (topLevelWidget());
569 d->statJobs.append( job );
570 connect(job, TQT_SIGNAL(result(KIO::Job*)), TQT_SLOT(slotStatResult(KIO::Job*)));
574 static bool isDirectory (
const KIO::UDSEntry &t)
578 for (KIO::UDSEntry::ConstIterator it = t.begin();
582 if ((*it).m_uds == KIO::UDS_FILE_TYPE)
584 isDir = S_ISDIR ((mode_t) ((*it).m_long));
595 void KFileDialog::slotStatResult(KIO::Job* job)
597 kdDebug(kfile_area) <<
"slotStatResult" << endl;
598 KIO::StatJob *sJob =
static_cast<KIO::StatJob *
>( job );
600 if ( !d->statJobs.removeRef( sJob ) ) {
604 int count = d->statJobs.count();
608 if (sJob->error() && count == 0 && !ops->
dirOnlyMode())
614 KIO::UDSEntry t = sJob->statResult();
619 d->filenames = TQString::null;
626 locationEdit->clearEdit();
627 locationEdit->lineEdit()->setEdited(
false );
639 kdDebug(kfile_area) <<
"filename " << sJob->url().url() << endl;
645 void KFileDialog::accept()
647 setResult( TQDialog::Accepted );
649 *lastDirectory = ops->
url();
650 if (!d->fileClass.isEmpty())
654 locationEdit->changeItem( TQString::null, 0 );
657 TQValueListConstIterator<KURL> it = list.begin();
658 for ( ; it != list.end(); ++it ) {
659 const KURL& url = *it;
663 TQString file = url.isLocalFile() ? url.path(-1) : url.prettyURL(-1);
666 for (
int i = 1; i < locationEdit->count(); i++ ) {
667 if ( locationEdit->text( i ) == file ) {
668 locationEdit->removeItem( i-- );
672 locationEdit->insertItem( file, 1 );
675 KConfig *config = KGlobal::config();
676 config->setForceGlobal(
true );
678 config->setForceGlobal(
false );
683 KDialogBase::accept();
685 addToRecentDocuments();
687 if ( (
mode() & KFile::Files) != KFile::Files )
701 if ( (ops->
mode() & KFile::Files) != KFile::Files ) {
707 if ( !locationEdit->hasFocus() ) {
708 setLocationText( i->name() );
724 if ( (ops->
mode() & KFile::Files) != KFile::Files ) {
729 setLocationText( i->name() );
743 if ( locationEdit->hasFocus() )
746 locationEdit->lineEdit()->setEdited(
false );
750 locationEdit->clearEdit();
754 static const TQString &begin = KGlobal::staticQString(
" \"");
755 KFileItemListIterator it ( *list );
757 while ( (item = it.current()) ) {
758 text.append( begin ).append( item->name() ).append(
'\"' );
762 setLocationText( text.stripWhiteSpace() );
765 void KFileDialog::setLocationText(
const TQString& text )
770 disconnect( locationEdit, TQT_SIGNAL( textChanged(
const TQString& ) ),
771 this, TQT_SLOT( slotLocationChanged(
const TQString& ) ) );
772 locationEdit->setCurrentItem( 0 );
773 connect( locationEdit, TQT_SIGNAL( textChanged(
const TQString& ) ),
774 TQT_SLOT( slotLocationChanged(
const TQString& )) );
775 locationEdit->setEditText( text );
778 if ( d->operationMode == Saving && !locationEdit->isVisible())
779 setNonExtSelection();
782 static const char autocompletionWhatsThisText[] = I18N_NOOP(
"<p>While typing in the text area, you may be presented "
783 "with possible matches. "
784 "This feature can be controlled by clicking with the right mouse button "
785 "and selecting a preferred mode from the <b>Text Completion</b> menu.")
"</qt>";
786 void KFileDialog::updateLocationWhatsThis (
void)
788 TQString whatsThisText;
789 if (d->operationMode == KFileDialog::Saving)
791 whatsThisText =
"<qt>" + i18n(
"This is the name to save the file as.") +
792 i18n (autocompletionWhatsThisText);
794 else if (ops->
mode() & KFile::Files)
796 whatsThisText =
"<qt>" + i18n(
"This is the list of files to open. More than "
797 "one file can be specified by listing several "
798 "files, separated by spaces.") +
799 i18n (autocompletionWhatsThisText);
803 whatsThisText =
"<qt>" + i18n(
"This is the name of the file to open.") +
804 i18n (autocompletionWhatsThisText);
807 TQWhatsThis::add(d->locationLabel, whatsThisText);
808 TQWhatsThis::add(locationEdit, whatsThisText);
814 d =
new KFileDialogPrivate();
817 d->keepLocation =
false;
818 d->operationMode = Opening;
819 d->bookmarkHandler = 0;
820 d->hasDefaultFilter =
false;
822 d->mainWidget =
new TQWidget(
this,
"KFileDialog::mainWidget");
823 setMainWidget( d->mainWidget );
824 d->okButton =
new KPushButton( KStdGuiItem::ok(), d->mainWidget );
825 d->okButton->setDefault(
true );
826 d->cancelButton =
new KPushButton(KStdGuiItem::cancel(), d->mainWidget);
827 connect( d->okButton, TQT_SIGNAL( clicked() ), TQT_SLOT( slotOk() ));
828 connect( d->cancelButton, TQT_SIGNAL( clicked() ), TQT_SLOT( slotCancel() ));
829 d->customWidget = widget;
830 d->autoSelectExtCheckBox = 0;
831 d->autoSelectExtChecked =
false;
834 TQtMsgHandler oldHandler = tqInstallMsgHandler( silenceQToolBar );
835 toolbar =
new KToolBar( d->mainWidget,
"KFileDialog::toolbar",
true);
836 toolbar->setFlat(
true);
837 tqInstallMsgHandler( oldHandler );
839 d->pathCombo =
new KURLComboBox( KURLComboBox::Directories,
true,
840 toolbar,
"path combo" );
841 TQToolTip::add( d->pathCombo, i18n(
"Current location") );
842 TQWhatsThis::add( d->pathCombo,
"<qt>" + i18n(
"This is the currently listed location. "
843 "The drop-down list also lists commonly used locations. "
844 "This includes standard locations, such as your home folder, as well as "
845 "locations that have been visited recently.") + i18n (autocompletionWhatsThisText));
848 u.setPath( TQDir::rootDirPath() );
849 TQString text = i18n(
"Root Folder: %1").arg( u.path() );
850 d->pathCombo->addDefaultURL( u,
851 KMimeType::pixmapForURL( u, 0, KIcon::Small ),
854 u.setPath( TQDir::homeDirPath() );
855 text = i18n(
"Home Folder: %1").arg( u.path( +1 ) );
856 d->pathCombo->addDefaultURL( u, KMimeType::pixmapForURL( u, 0, KIcon::Small ),
860 docPath.setPath( KGlobalSettings::documentPath() );
861 if ( (u.path(+1) != docPath.path(+1)) &&
862 TQDir(docPath.path(+1)).exists() )
864 text = i18n(
"Documents: %1").arg( docPath.path( +1 ) );
865 d->pathCombo->addDefaultURL( docPath,
866 KMimeType::pixmapForURL( docPath, 0, KIcon::Small ),
870 u.setPath( KGlobalSettings::desktopPath() );
871 text = i18n(
"Desktop: %1").arg( u.path( +1 ) );
872 d->pathCombo->addDefaultURL( u,
873 KMimeType::pixmapForURL( u, 0, KIcon::Small ),
877 d->selection = d->url.url();
880 if ( d->url.isLocalFile() )
882 if ( !TQFile::exists( d->url.path() ) )
884 d->url = d->url.upURL();
885 TQDir dir( d->url.path() );
886 while ( !dir.exists() )
888 d->url = d->url.upURL();
889 dir.setPath( d->url.path() );
894 ops =
new KDirOperator(d->url, d->mainWidget,
"KFileDialog::ops");
896 connect(ops, TQT_SIGNAL(urlEntered(
const KURL&)),
897 TQT_SLOT(urlEntered(
const KURL&)));
900 connect(ops, TQT_SIGNAL(
fileSelected(
const KFileItem *)),
902 connect(ops, TQT_SIGNAL(finishedLoading()),
903 TQT_SLOT(slotLoadingFinished()));
905 ops->
setupMenu(KDirOperator::SortActions |
906 KDirOperator::FileActions |
907 KDirOperator::ViewActions);
911 coll->action(
"up" )->plug( toolbar );
912 coll->action(
"up" )->setWhatsThis(i18n(
"<qt>Click this button to enter the parent folder.<p>"
913 "For instance, if the current location is file:/home/%1 clicking this "
914 "button will take you to file:/home.</qt>").arg( KUser().loginName() ));
915 coll->action(
"back" )->plug( toolbar );
916 coll->action(
"back" )->setWhatsThis(i18n(
"Click this button to move backwards one step in the browsing history."));
917 coll->action(
"forward" )->plug( toolbar );
918 coll->action(
"forward" )->setWhatsThis(i18n(
"Click this button to move forward one step in the browsing history."));
919 coll->action(
"reload" )->plug( toolbar );
920 coll->action(
"reload" )->setWhatsThis(i18n(
"Click this button to reload the contents of the current location."));
921 coll->action(
"mkdir" )->setShortcut(Key_F10);
922 coll->action(
"mkdir" )->plug( toolbar );
923 coll->action(
"mkdir" )->setWhatsThis(i18n(
"Click this button to create a new folder."));
925 KToggleAction *showSidebarAction =
926 new KToggleAction(i18n(
"Show Quick Access Navigation Panel"), Key_F9, coll,
"toggleSpeedbar");
927 showSidebarAction->setCheckedState(i18n(
"Hide Quick Access Navigation Panel"));
928 connect( showSidebarAction, TQT_SIGNAL( toggled(
bool ) ),
931 KToggleAction *showBookmarksAction =
932 new KToggleAction(i18n(
"Show Bookmarks"), 0, coll,
"toggleBookmarks");
933 showBookmarksAction->setCheckedState(i18n(
"Hide Bookmarks"));
934 connect( showBookmarksAction, TQT_SIGNAL( toggled(
bool ) ),
937 KActionMenu *menu =
new KActionMenu( i18n(
"Configure"),
"configure", TQT_TQOBJECT(
this),
"extra menu" );
938 menu->setWhatsThis(i18n(
"<qt>This is the configuration menu for the file dialog. "
939 "Various options can be accessed from this menu including: <ul>"
940 "<li>how files are sorted in the list</li>"
941 "<li>types of view, including icon and list</li>"
942 "<li>showing of hidden files</li>"
943 "<li>the Quick Access navigation panel</li>"
944 "<li>file previews</li>"
945 "<li>separating folders from files</li></ul></qt>"));
946 menu->insert( coll->action(
"sorting menu" ));
947 menu->insert( coll->action(
"separator" ));
948 coll->action(
"short view" )->setShortcut(Key_F6);
949 menu->insert( coll->action(
"short view" ));
950 coll->action(
"detailed view" )->setShortcut(Key_F7);
951 menu->insert( coll->action(
"detailed view" ));
952 menu->insert( coll->action(
"separator" ));
953 coll->action(
"show hidden" )->setShortcut(Key_F8);
954 menu->insert( coll->action(
"show hidden" ));
955 menu->insert( showSidebarAction );
956 menu->insert( showBookmarksAction );
957 coll->action(
"preview" )->setShortcut(Key_F11);
958 menu->insert( coll->action(
"preview" ));
959 coll->action(
"separate dirs" )->setShortcut(Key_F12);
960 menu->insert( coll->action(
"separate dirs" ));
962 menu->setDelayed(
false );
963 connect( menu->popupMenu(), TQT_SIGNAL( aboutToShow() ),
964 ops, TQT_SLOT( updateSelectionDependentActions() ));
965 menu->plug( toolbar );
968 KToolBarSeparator* spacerWidget =
new KToolBarSeparator(Qt::Horizontal,
false ,
970 d->m_pathComboIndex = toolbar->insertWidget(-1, -1, spacerWidget);
971 toolbar->insertWidget(PATH_COMBO, 0, d->pathCombo);
974 toolbar->setItemAutoSized (PATH_COMBO);
975 toolbar->setIconText(KToolBar::IconOnly);
976 toolbar->setBarPos(KToolBar::Top);
977 toolbar->setMovingEnabled(
false);
978 toolbar->adjustSize();
980 KURLCompletion *pathCompletionObj =
new KURLCompletion( KURLCompletion::DirCompletion );
981 d->pathCombo->setCompletionObject( pathCompletionObj );
982 d->pathCombo->setAutoDeleteCompletionObject(
true );
984 connect( d->pathCombo, TQT_SIGNAL( urlActivated(
const KURL& )),
985 this, TQT_SLOT( enterURL(
const KURL& ) ));
986 connect( d->pathCombo, TQT_SIGNAL( returnPressed(
const TQString& )),
987 this, TQT_SLOT( enterURL(
const TQString& ) ));
989 TQString whatsThisText;
992 d->locationLabel =
new TQLabel(i18n(
"&Location:"), d->mainWidget);
993 locationEdit =
new KURLComboBox(KURLComboBox::Files,
true,
994 d->mainWidget,
"LocationEdit");
995 connect( locationEdit, TQT_SIGNAL( textChanged(
const TQString& ) ),
996 TQT_SLOT( slotLocationChanged(
const TQString& )) );
998 updateLocationWhatsThis ();
999 d->locationLabel->setBuddy(locationEdit);
1001 locationEdit->setFocus();
1002 KURLCompletion *fileCompletionObj =
new KURLCompletion( KURLCompletion::FileCompletion );
1003 TQString dir = d->url.url(+1);
1004 pathCompletionObj->setDir( dir );
1005 fileCompletionObj->setDir( dir );
1006 locationEdit->setCompletionObject( fileCompletionObj );
1007 locationEdit->setAutoDeleteCompletionObject(
true );
1008 connect( fileCompletionObj, TQT_SIGNAL( match(
const TQString& ) ),
1009 TQT_SLOT( fileCompletion(
const TQString& )) );
1011 connect( locationEdit, TQT_SIGNAL( returnPressed() ),
1012 this, TQT_SLOT( slotOk()));
1013 connect(locationEdit, TQT_SIGNAL( activated(
const TQString& )),
1014 this, TQT_SLOT( locationActivated(
const TQString& ) ));
1017 whatsThisText = i18n(
"<qt>This is the filter to apply to the file list. "
1018 "File names that do not match the filter will not be shown.<p>"
1019 "You may select from one of the preset filters in the "
1020 "drop down menu, or you may enter a custom filter "
1021 "directly into the text area.<p>"
1022 "Wildcards such as * and ? are allowed.</qt>");
1023 d->filterLabel =
new TQLabel(i18n(
"&Filter:"), d->mainWidget);
1024 TQWhatsThis::add(d->filterLabel, whatsThisText);
1025 filterWidget =
new KFileFilterCombo(d->mainWidget,
1026 "KFileDialog::filterwidget");
1027 TQWhatsThis::add(filterWidget, whatsThisText);
1029 d->filterLabel->setBuddy(filterWidget);
1030 connect(filterWidget, TQT_SIGNAL(
filterChanged()), TQT_SLOT(slotFilterChanged()));
1034 d->autoSelectExtCheckBox =
new TQCheckBox (d->mainWidget);
1035 connect(d->autoSelectExtCheckBox, TQT_SIGNAL(clicked()), TQT_SLOT(slotAutoSelectExtClicked()));
1039 KConfig* config = KGlobal::config();
1049 void KFileDialog::initSpeedbar()
1051 d->urlBar =
new KFileSpeedBar( d->mainWidget,
"url bar" );
1052 connect( d->urlBar, TQT_SIGNAL( activated(
const KURL& )),
1053 TQT_SLOT( enterURL(
const KURL& )) );
1059 d->urlBar->setCurrentItem( d->url );
1061 d->urlBarLayout->insertWidget( 0, d->urlBar );
1066 delete d->boxLayout;
1068 d->boxLayout =
new TQVBoxLayout( d->mainWidget, 0, KDialog::spacingHint());
1069 d->boxLayout->addWidget(toolbar, AlignTop);
1071 d->urlBarLayout =
new TQHBoxLayout( d->boxLayout );
1072 TQVBoxLayout *vbox =
new TQVBoxLayout( d->urlBarLayout );
1074 vbox->addWidget(ops, 4);
1075 vbox->addSpacing(3);
1077 TQGridLayout* lafBox=
new TQGridLayout(2, 3, KDialog::spacingHint());
1079 lafBox->addWidget(d->locationLabel, 0, 0, Qt::AlignVCenter);
1080 lafBox->addWidget(locationEdit, 0, 1, Qt::AlignVCenter);
1081 lafBox->addWidget(d->okButton, 0, 2, Qt::AlignVCenter);
1083 lafBox->addWidget(d->filterLabel, 1, 0, Qt::AlignVCenter);
1084 lafBox->addWidget(filterWidget, 1, 1, Qt::AlignVCenter);
1085 lafBox->addWidget(d->cancelButton, 1, 2, Qt::AlignVCenter);
1087 lafBox->setColStretch(1, 4);
1089 vbox->addLayout(TQT_TQLAYOUT(lafBox), 0);
1090 vbox->addSpacing(3);
1093 vbox->addWidget (d->autoSelectExtCheckBox);
1094 vbox->addSpacing (3);
1096 setTabOrder(ops, d->autoSelectExtCheckBox);
1097 setTabOrder (d->autoSelectExtCheckBox, locationEdit);
1098 setTabOrder(locationEdit, filterWidget);
1099 setTabOrder(filterWidget, d->okButton);
1100 setTabOrder(d->okButton, d->cancelButton);
1101 setTabOrder(d->cancelButton, d->pathCombo);
1102 setTabOrder(d->pathCombo, ops);
1105 if ( d->customWidget != 0 )
1110 d->customWidget->reparent( d->mainWidget, TQPoint() );
1112 vbox->addWidget( d->customWidget );
1113 vbox->addSpacing(3);
1120 setTabOrder(d->cancelButton, d->customWidget);
1121 setTabOrder(d->customWidget, d->pathCombo);
1125 setTabOrder(d->cancelButton, d->pathCombo);
1128 setTabOrder(d->pathCombo, ops);
1131 void KFileDialog::slotFilterChanged()
1133 TQString filter = filterWidget->currentFilter();
1136 if ( filter.find(
'/' ) > -1 ) {
1137 TQStringList types = TQStringList::split(
" ", filter );
1138 types.prepend(
"inode/directory" );
1154 d->selection = TQString::null;
1155 ops->
setURL( url, clearforward);
1159 void KFileDialog::urlEntered(
const KURL& url)
1161 TQString filename = locationEdit->currentText();
1162 d->selection = TQString::null;
1164 if ( d->pathCombo->count() != 0 ) {
1165 d->pathCombo->setURL( url );
1168 if (url.protocol()==
"beagle" && url.path()==
"/") {
1169 d->pathCombo->setEditText(
"beagle:/<"+i18n(
"search term")+
">");
1170 d->pathCombo->lineEdit()->setSelection(8,255);
1171 d->pathCombo->setFocus();
1174 locationEdit->blockSignals(
true );
1175 locationEdit->setCurrentItem( 0 );
1176 if ( d->keepLocation )
1177 locationEdit->setEditText( filename );
1179 locationEdit->blockSignals(
false );
1181 TQString dir = url.url(+1);
1182 static_cast<KURLCompletion*
>( d->pathCombo->completionObject() )->setDir( dir );
1183 static_cast<KURLCompletion*
>( locationEdit->completionObject() )->setDir( dir );
1186 d->urlBar->setCurrentItem( url );
1189 void KFileDialog::locationActivated(
const TQString& url )
1196 if (!locationEdit->lineEdit()->edited())
1200 void KFileDialog::enterURL(
const KURL& url)
1205 void KFileDialog::enterURL(
const TQString& url )
1207 setURL( KURL::fromPathOrURL( KURLCompletion::replacedPath( url,
true,
true )) );
1221 kdDebug(kfile_area) <<
"setSelection " << url << endl;
1223 if (url.isEmpty()) {
1224 d->selection = TQString::null;
1230 kdWarning() << url <<
" is not a correct argument for setSelection!" << endl;
1234 if (!KProtocolInfo::supportsListing(u)) {
1235 locationEdit->lineEdit()->setEdited(
true );
1242 KFileItem i(KFileItem::Unknown, KFileItem::Unknown, u,
true );
1244 if ( i.isDir() && u.isLocalFile() && TQFile::exists( u.path() ) ) {
1252 TQString filename = u.url();
1253 int sep = filename.findRev(
'/');
1255 if ( KProtocolInfo::supportsListing( u )) {
1257 dir.setQuery( TQString::null );
1258 dir.setFileName( TQString::null );
1264 filename = u.fileName();
1265 kdDebug(kfile_area) <<
"filename " << filename << endl;
1266 d->selection = filename;
1267 setLocationText( filename );
1276 locationEdit->lineEdit()->setEdited(
true );
1279 d->url = ops->
url();
1280 d->url.addPath(filename);
1284 void KFileDialog::slotLoadingFinished()
1286 if ( !d->selection.isNull() )
1297 void KFileDialog::fileCompletion(
const TQString& match )
1299 if ( match.isEmpty() && ops->
view() )
1305 void KFileDialog::slotLocationChanged(
const TQString& text )
1307 if ( text.isEmpty() && ops->
view() )
1315 kdWarning() <<
"KFileDialog::updateStatusLine is deprecated! The status line no longer exists. Do not try and use it!" << endl;
1319 const TQString& filter,
1320 TQWidget *parent,
const TQString& caption)
1322 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1325 dlg.
setMode( KFile::File | KFile::LocalOnly );
1326 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1335 const TQString& filter,
1336 WId parent_id,
const TQString& caption)
1338 TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
1339 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1341 if( parent == NULL && parent_id != 0 )
1342 XSetTransientForHint( qt_xdisplay(), dlg.winId(), parent_id );
1349 dlg.
setMode( KFile::File | KFile::LocalOnly );
1350 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1359 const TQString& filter,
1361 const TQString& caption)
1363 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1366 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1367 dlg.
setMode(KFile::Files | KFile::LocalOnly);
1375 TQWidget *parent,
const TQString& caption)
1377 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1380 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1389 const TQString& filter,
1391 const TQString& caption)
1393 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1396 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1406 const TQString& caption)
1413 const TQString& caption)
1416 return TQFileDialog::getExistingDirectory(startDir, parent,
"getExistingDirectory",
1417 caption,
true,
true);
1421 if ( url.isValid() )
1424 return TQString::null;
1429 const TQString& caption)
1431 TQStringList mimetypes = KImageIO::mimeTypes( KImageIO::Reading );
1433 mimetypes.join(
" "),
1434 parent,
"filedialog",
true);
1436 dlg.setCaption( caption.isNull() ? i18n(
"Open") : caption );
1437 dlg.setMode( KFile::File );
1440 dlg.setPreviewWidget( ip );
1443 return dlg.selectedURL();
1448 if ( result() == TQDialog::Accepted )
1457 if ( result() == TQDialog::Accepted ) {
1458 if ( (ops->
mode() & KFile::Files) == KFile::Files )
1459 list = parseSelectedURLs();
1461 list.append( d->url );
1467 KURL::List& KFileDialog::parseSelectedURLs()
const
1469 if ( d->filenames.isEmpty() ) {
1474 if ( d->filenames.contains(
'/' )) {
1475 static const TQString &prot = KGlobal::staticQString(
":/");
1477 if ( d->filenames.find( prot ) != -1 )
1480 u.setPath( d->filenames );
1483 d->urlList.append( u );
1485 KMessageBox::error( d->mainWidget,
1486 i18n(
"The chosen filenames do not\n"
1487 "appear to be valid."),
1488 i18n(
"Invalid Filenames") );
1492 d->urlList =
tokenize( d->filenames );
1494 d->filenames = TQString::null;
1504 KURL u( ops->
url() );
1507 int count = line.contains(
'"' );
1509 u.setFileName( line );
1516 if ( (count % 2) == 1 ) {
1518 KMessageBox::sorry(that, i18n(
"The requested filenames\n"
1520 "do not appear to be valid;\n"
1521 "make sure every filename is enclosed in double quotes.").arg(line),
1522 i18n(
"Filename Error"));
1527 int index1 = -1, index2 = -1;
1529 index1 = line.find(
'"', start );
1530 index2 = line.find(
'"', index1 + 1 );
1536 name = line.mid( index1 + 1, index2 - index1 - 1 );
1537 u.setFileName( name );
1549 if ( result() == TQDialog::Accepted )
1551 KURL url = KIO::NetAccess::mostLocalURL(d->url,topLevelWidget());
1552 if (url.isLocalFile())
1555 KMessageBox::sorry( d->mainWidget,
1556 i18n(
"You can only select local files."),
1557 i18n(
"Remote Files Not Accepted") );
1560 return TQString::null;
1568 if ( result() == TQDialog::Accepted ) {
1569 if ( (ops->
mode() & KFile::Files) == KFile::Files ) {
1570 KURL::List urls = parseSelectedURLs();
1571 TQValueListConstIterator<KURL> it = urls.begin();
1572 while ( it != urls.end() ) {
1573 url = KIO::NetAccess::mostLocalURL(*it,topLevelWidget());
1574 if ( url.isLocalFile() )
1575 list.append( url.path() );
1581 if ( d->url.isLocalFile() )
1582 list.append( d->url.path() );
1596 const TQString& caption)
1598 bool specialDir = dir.at(0) ==
':';
1599 KFileDialog dlg( specialDir ? dir : TQString::null, filter, parent,
"filedialog",
true);
1604 dlg.setCaption(caption.isNull() ? i18n(
"Save As") : caption);
1609 if (!filename.isEmpty())
1617 const TQString& caption)
1619 bool specialDir = dir.at(0) ==
':';
1620 TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
1621 KFileDialog dlg( specialDir ? dir : TQString::null, filter, parent,
"filedialog",
true);
1623 if( parent == NULL && parent_id != 0 )
1624 XSetTransientForHint(qt_xdisplay(), dlg.winId(), parent_id);
1633 dlg.setCaption(caption.isNull() ? i18n(
"Save As") : caption);
1638 if (!filename.isEmpty())
1645 TQWidget *parent,
const TQString& caption)
1647 bool specialDir = dir.at(0) ==
':';
1648 KFileDialog dlg(specialDir ? dir : TQString::null, filter, parent,
"filedialog",
true);
1652 dlg.setCaption(caption.isNull() ? i18n(
"Save As") : caption);
1664 void KFileDialog::show()
1666 if ( !d->hasView ) {
1672 KDialogBase::show();
1679 filterWidget->setDefaultFilter( i18n(
"*|All Folders") );
1682 filterWidget->setDefaultFilter( i18n(
"*|All Files") );
1690 setMode(static_cast<KFile::Mode>( m ));
1704 TQString oldGroup = kc->group();
1705 if ( !group.isEmpty() )
1706 kc->setGroup( group );
1711 combo->
setURLs( kc->readPathListEntry( RecentURLs ), KURLComboBox::RemoveTop );
1712 combo->
setMaxItems( kc->readNumEntry( RecentURLsNumber,
1713 DefaultRecentURLsNumber ) );
1715 autoDirectoryFollowing = kc->readBoolEntry( AutoDirectoryFollowing,
1716 DefaultDirectoryFollowing );
1718 KGlobalSettings::Completion cm = (KGlobalSettings::Completion)
1719 kc->readNumEntry( PathComboCompletionMode,
1720 KGlobalSettings::completionMode() );
1721 if ( cm != KGlobalSettings::completionMode() )
1722 combo->setCompletionMode( cm );
1724 cm = (KGlobalSettings::Completion)
1725 kc->readNumEntry( LocationComboCompletionMode,
1726 KGlobalSettings::completionMode() );
1727 if ( cm != KGlobalSettings::completionMode() )
1728 locationEdit->setCompletionMode( cm );
1737 d->autoSelectExtChecked = kc->readBoolEntry (AutoSelectExtChecked, DefaultAutoSelectExtChecked);
1740 int w1 = minimumSize().width();
1741 int w2 = toolbar->sizeHint().width() + 10;
1743 setMinimumWidth(w2);
1745 TQSize size = configDialogSize( group );
1747 kc->setGroup( oldGroup );
1755 TQString oldGroup = kc->group();
1756 if ( !group.isEmpty() )
1757 kc->setGroup( group );
1759 kc->writePathEntry( RecentURLs, d->pathCombo->urls() );
1760 saveDialogSize( group,
true );
1761 kc->writeEntry( PathComboCompletionMode, static_cast<int>(d->pathCombo->completionMode()) );
1762 kc->writeEntry( LocationComboCompletionMode, static_cast<int>(locationEdit->completionMode()) );
1763 kc->writeEntry( ShowSpeedbar, d->urlBar && !d->urlBar->isHidden() );
1764 kc->writeEntry( ShowBookmarks, d->bookmarkHandler != 0 );
1765 kc->writeEntry( AutoSelectExtChecked, d->autoSelectExtChecked );
1768 kc->setGroup( oldGroup );
1774 TQString oldGroup = kc->group();
1775 kc->setGroup( ConfigGroup );
1777 locationEdit->
setMaxItems( kc->readNumEntry( RecentFilesNumber,
1778 DefaultRecentURLsNumber ) );
1779 locationEdit->
setURLs( kc->readPathListEntry( RecentFiles ),
1780 KURLComboBox::RemoveBottom );
1781 locationEdit->insertItem( TQString::null, 0 );
1782 locationEdit->setCurrentItem( 0 );
1784 kc->setGroup( oldGroup );
1789 TQString oldGroup = kc->group();
1790 kc->setGroup( ConfigGroup );
1792 kc->writePathEntry( RecentFiles, locationEdit->urls() );
1794 kc->setGroup( oldGroup );
1804 return d->cancelButton;
1812 void KFileDialog::slotCancel()
1815 KDialogBase::slotCancel();
1817 KConfig *config = KGlobal::config();
1818 config->setForceGlobal(
true );
1820 config->setForceGlobal(
false );
1825 d->keepLocation = keep;
1830 return d->keepLocation;
1835 d->operationMode =
mode;
1836 d->keepLocation = (mode == Saving);
1837 filterWidget->setEditable( !d->hasDefaultFilter || mode != Saving );
1838 if ( mode == Opening )
1839 d->okButton->setGuiItem( KGuiItem( i18n(
"&Open"),
"fileopen") );
1840 else if ( mode == Saving ) {
1841 d->okButton->setGuiItem( KStdGuiItem::save() );
1842 setNonExtSelection();
1845 d->okButton->setGuiItem( KStdGuiItem::ok() );
1846 updateLocationWhatsThis ();
1852 return d->operationMode;
1855 void KFileDialog::slotAutoSelectExtClicked()
1857 kdDebug (kfile_area) <<
"slotAutoSelectExtClicked(): "
1858 << d->autoSelectExtCheckBox->isChecked () << endl;
1861 d->autoSelectExtChecked = d->autoSelectExtCheckBox->isChecked ();
1864 updateLocationEditExtension (d->extension );
1867 static TQString getExtensionFromPatternList (
const TQStringList &patternList)
1870 kdDebug (kfile_area) <<
"\tgetExtension " << patternList << endl;
1872 TQStringList::ConstIterator patternListEnd = patternList.end ();
1873 for (TQStringList::ConstIterator it = patternList.begin ();
1874 it != patternListEnd;
1877 kdDebug (kfile_area) <<
"\t\ttry: \'" << (*it) <<
"\'" << endl;
1886 if ((*it).startsWith (
"*.") &&
1887 (*it).length () > 2 &&
1888 (*it).find (
'*', 2) < 0 && (*it).find (
'?', 2) < 0)
1890 ret = (*it).mid (1);
1898 static TQString stripUndisplayable (
const TQString &
string)
1900 TQString ret = string;
1911 return d->extension;
1916 if (!d->autoSelectExtCheckBox)
return;
1925 kdDebug (kfile_area) <<
"Figure out an extension: " << endl;
1926 TQString lastExtension = d->extension;
1927 d->extension = TQString::null;
1937 if (!filter.isEmpty ())
1940 if (filter.find (
'/') < 0)
1942 d->extension = getExtensionFromPatternList (TQStringList::split (
" ", filter)).lower ();
1943 kdDebug (kfile_area) <<
"\tsetFilter-style: pattern ext=\'"
1944 << d->extension <<
"\'" << endl;
1949 KMimeType::Ptr mime = KMimeType::mimeType (filter);
1952 TQString nativeExtension = mime->property (
"X-KDE-NativeExtension").toString ();
1953 if (nativeExtension.at (0) ==
'.')
1955 d->extension = nativeExtension.lower ();
1956 kdDebug (kfile_area) <<
"\tsetMimeFilter-style: native ext=\'"
1957 << d->extension <<
"\'" << endl;
1961 if (d->extension.isEmpty ())
1963 d->extension = getExtensionFromPatternList (mime->patterns ()).lower ();
1964 kdDebug (kfile_area) <<
"\tsetMimeFilter-style: pattern ext=\'"
1965 << d->extension <<
"\'" << endl;
1975 TQString whatsThisExtension;
1976 if (!d->extension.isEmpty ())
1979 d->autoSelectExtCheckBox->setText (i18n (
"Automatically select filename e&xtension (%1)").arg (d->extension));
1980 whatsThisExtension = i18n (
"the extension <b>%1</b>").arg (d->extension);
1982 d->autoSelectExtCheckBox->setEnabled (
true);
1983 d->autoSelectExtCheckBox->setChecked (d->autoSelectExtChecked);
1988 d->autoSelectExtCheckBox->setText (i18n (
"Automatically select filename e&xtension"));
1989 whatsThisExtension = i18n (
"a suitable extension");
1991 d->autoSelectExtCheckBox->setChecked (
false);
1992 d->autoSelectExtCheckBox->setEnabled (
false);
1995 const TQString locationLabelText = stripUndisplayable (d->locationLabel->text ());
1996 const TQString filterLabelText = stripUndisplayable (d->filterLabel->text ());
1997 TQWhatsThis::add (d->autoSelectExtCheckBox,
2000 "This option enables some convenient features for "
2001 "saving files with extensions:<br>"
2003 "<li>Any extension specified in the <b>%1</b> text "
2004 "area will be updated if you change the file type "
2007 "<li>If no extension is specified in the <b>%2</b> "
2008 "text area when you click "
2009 "<b>Save</b>, %3 will be added to the end of the "
2010 "filename (if the filename does not already exist). "
2011 "This extension is based on the file type that you "
2012 "have chosen to save in.<br>"
2014 "If you do not want KDE to supply an extension for the "
2015 "filename, you can either turn this option off or you "
2016 "can suppress it by adding a period (.) to the end of "
2017 "the filename (the period will be automatically "
2021 "If unsure, keep this option enabled as it makes your "
2022 "files more manageable."
2024 .arg (locationLabelText)
2025 .arg (locationLabelText)
2026 .arg (whatsThisExtension)
2030 d->autoSelectExtCheckBox->show ();
2034 updateLocationEditExtension (lastExtension);
2039 d->autoSelectExtCheckBox->setChecked (
false);
2040 d->autoSelectExtCheckBox->hide ();
2047 void KFileDialog::updateLocationEditExtension (
const TQString &lastExtension)
2049 if (!d->autoSelectExtCheckBox->isChecked () || d->extension.isEmpty ())
2052 TQString urlStr = locationEdit->currentText ();
2053 if (urlStr.isEmpty ())
2057 kdDebug (kfile_area) <<
"updateLocationEditExtension (" << url <<
")" << endl;
2059 const int fileNameOffset = urlStr.findRev (
'/') + 1;
2060 TQString fileName = urlStr.mid (fileNameOffset);
2062 const int dot = fileName.findRev (
'.');
2063 const int len = fileName.length ();
2071 if (KIO::NetAccess::stat (url, t, topLevelWidget()))
2073 kdDebug (kfile_area) <<
"\tfile exists" << endl;
2075 if (isDirectory (t))
2077 kdDebug (kfile_area) <<
"\tisDir - won't alter extension" << endl;
2090 if (lastExtension.length () && fileName.endsWith (lastExtension))
2091 fileName.truncate (len - lastExtension.length ());
2094 fileName.truncate (dot);
2097 const TQString newText = urlStr.left (fileNameOffset) + fileName + d->extension;
2098 if ( newText != locationEdit->currentText() )
2100 locationEdit->setCurrentText (urlStr.left (fileNameOffset) + fileName + d->extension);
2101 locationEdit->lineEdit()->setEdited (
true);
2108 void KFileDialog::updateFilter ()
2111 const TQString urlStr = locationEdit->currentText ();
2112 if (urlStr.isEmpty ())
2115 KMimeType::Ptr mime = KMimeType::findByPath(urlStr, 0,
true);
2116 if (mime && mime->name() != KMimeType::defaultMimeType()) {
2117 if (filterWidget->currentFilter() != mime->name() &&
2118 filterWidget->filters.findIndex(mime->name()) != -1) {
2119 filterWidget->setCurrentFilter(mime->name());
2126 void KFileDialog::appendExtension (KURL &url)
2128 if (!d->autoSelectExtCheckBox->isChecked () || d->extension.isEmpty ())
2131 TQString fileName = url.fileName ();
2132 if (fileName.isEmpty ())
2135 kdDebug (kfile_area) <<
"appendExtension(" << url <<
")" << endl;
2137 const int len = fileName.length ();
2138 const int dot = fileName.findRev (
'.');
2140 const bool suppressExtension = (dot == len - 1);
2141 const bool unspecifiedExtension = (dot <= 0);
2144 if (!(suppressExtension || unspecifiedExtension))
2149 if (KIO::NetAccess::stat (url, t, topLevelWidget()))
2151 kdDebug (kfile_area) <<
"\tfile exists - won't append extension" << endl;
2156 if (suppressExtension)
2168 kdDebug (kfile_area) <<
"\tstrip trailing dot" << endl;
2169 url.setFileName (fileName.left (len - 1));
2172 else if (unspecifiedExtension)
2174 kdDebug (kfile_area) <<
"\tappending extension \'" << d->extension <<
"\'..." << endl;
2175 url.setFileName (fileName + d->extension);
2176 kdDebug (kfile_area) <<
"\tsaving as \'" << url <<
"\'" << endl;
2182 void KFileDialog::addToRecentDocuments()
2184 int m = ops->
mode();
2186 if ( m & KFile::LocalOnly ) {
2188 TQStringList::ConstIterator it = files.begin();
2189 for ( ; it != files.end(); ++it )
2195 KURL::List::ConstIterator it = urls.begin();
2196 for ( ; it != urls.end(); ++it ) {
2197 if ( (*it).isValid() )
2210 if ( e->key() == Key_Escape )
2213 d->cancelButton->animateClick();
2216 KDialogBase::keyPressEvent( e );
2231 homeURL.setPath( TQDir::homeDirPath() );
2234 if ( homeURL.equals( urlItem->
url(), true ) )
2240 urlItem =
static_cast<KURLBarItem*
>( urlItem->next() );
2252 static_cast<KToggleAction *
>(
actionCollection()->action(
"toggleSpeedbar"))->setChecked( show );
2259 if (d->bookmarkHandler)
2264 d->bookmarkHandler =
new KFileBookmarkHandler(
this );
2265 connect( d->bookmarkHandler, TQT_SIGNAL( openURL(
const TQString& )),
2266 TQT_SLOT( enterURL(
const TQString& )));
2268 toolbar->insertButton(TQString::fromLatin1(
"bookmark"),
2269 (
int)HOTLIST_BUTTON,
true,
2270 i18n(
"Bookmarks"), 5);
2271 toolbar->getButton(HOTLIST_BUTTON)->setPopup(d->bookmarkHandler->menu(),
2273 TQWhatsThis::add(toolbar->getButton(HOTLIST_BUTTON),
2274 i18n(
"<qt>This button allows you to bookmark specific locations. "
2275 "Click on this button to open the bookmark menu where you may add, "
2276 "edit or select a bookmark.<p>"
2277 "These bookmarks are specific to the file dialog, but otherwise operate "
2278 "like bookmarks elsewhere in KDE.</qt>"));
2280 else if (d->bookmarkHandler)
2282 delete d->bookmarkHandler;
2283 d->bookmarkHandler = 0;
2284 toolbar->removeItem(HOTLIST_BUTTON);
2287 static_cast<KToggleAction *
>(
actionCollection()->action(
"toggleBookmarks"))->setChecked( show );
2292 return d->m_pathComboIndex;
2296 void KFileDialog::initStatic()
2298 if ( lastDirectory )
2301 lastDirectory = ldd.setObject(lastDirectory,
new KURL());
2306 TQString& recentDirClass )
2310 recentDirClass = TQString::null;
2313 bool useDefaultStartDir = startDir.isEmpty();
2314 if ( !useDefaultStartDir )
2316 if (startDir[0] ==
':')
2318 recentDirClass = startDir;
2323 ret = KCmdLineArgs::makeURL( TQFile::encodeName(startDir) );
2325 if ( !KProtocolInfo::supportsListing( ret ) )
2326 useDefaultStartDir =
true;
2330 if ( useDefaultStartDir )
2332 if (lastDirectory->isEmpty()) {
2333 lastDirectory->setPath(KGlobalSettings::documentPath());
2335 home.setPath( TQDir::homeDirPath() );
2340 if ( lastDirectory->path(+1) == home.path(+1) ||
2341 TQDir::currentDirPath() != TQDir::homeDirPath() ||
2342 !TQDir(lastDirectory->path(+1)).exists() )
2343 lastDirectory->setPath(TQDir::currentDirPath());
2345 ret = *lastDirectory;
2351 void KFileDialog::setStartDir(
const KURL& directory )
2354 if ( directory.isValid() )
2355 *lastDirectory = directory;
2358 void KFileDialog::setNonExtSelection()
2361 TQString pattern, filename = locationEdit->currentText().stripWhiteSpace();
2362 KServiceTypeFactory::self()->findFromPattern( filename, &pattern );
2364 if ( !pattern.isEmpty() && pattern.at( 0 ) ==
'*' && pattern.find(
'*' , 1 ) == -1 )
2365 locationEdit->lineEdit()->setSelection( 0, filename.length() - pattern.stripWhiteSpace().length()+1 );
2368 int lastDot = filename.findRev(
'.' );
2370 locationEdit->lineEdit()->setSelection( 0, lastDot );
2374 void KFileDialog::virtual_hook(
int id,
void* data )
2375 { KDialogBase::virtual_hook(
id, data ); }
2378 #include "kfiledialog.moc"