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";
340 TQDir savedir = TQDir(d->pathCombo->lineEdit()->text());
341 if (!savedir.exists())
343 KMessageBox::information(
this, i18n(
"The selected folder does not exists. Please select an existing one."));
346 if (ops->
url().path(1) != KURL(savedir.absPath()).path(1))
348 setURL(savedir.absPath());
355 if ( (
mode() & KFile::Directory) != KFile::Directory ) {
356 if ( locationEdit->currentText().stripWhiteSpace().isEmpty() ) {
357 if ( !items || items->isEmpty() )
360 if ( d->operationMode == Saving )
361 msg = i18n(
"Please specify the filename to save to.");
363 msg = i18n(
"Please select the file to open.");
364 KMessageBox::information(
this, msg);
372 bool multi = (
mode() & KFile::Files) != 0;
373 KFileItemListIterator it( *items );
374 TQString endQuote = TQString::fromLatin1(
"\" ");
375 TQString name, files;
376 while ( it.current() ) {
377 name = (*it)->name();
380 name.append( endQuote );
383 files.append( name );
386 setLocationText( files );
395 if ( items && !locationEdit->lineEdit()->edited() &&
396 !(items->isEmpty() && !dirOnly) ) {
399 d->filenames = TQString::null;
405 if ( !(
mode() & KFile::Files) ) {
406 d->url = items->getFirst()->url();
411 KFileItemListIterator it( *items );
412 while ( it.current() ) {
413 d->urlList.append( (*it)->url() );
419 KURL url = TDEIO::NetAccess::mostLocalURL(d->url,topLevelWidget());
420 if ( (
mode() & KFile::LocalOnly) == KFile::LocalOnly &&
421 !url.isLocalFile() ) {
423 KMessageBox::sorry( d->mainWidget,
424 i18n(
"You can only select local files."),
425 i18n(
"Remote Files Not Accepted") );
437 if ( (
mode() & KFile::Files) == KFile::Files ) {
438 TQString locationText = locationEdit->currentText();
439 if ( locationText.contains(
'/' )) {
441 KURL u( ops->
url(), KShell::tildeExpand(locationText));
445 selectedURL = ops->
url();
448 selectedURL = ops->
url();
455 appendExtension (selectedURL);
458 if ( !selectedURL.isValid() ) {
459 KMessageBox::sorry( d->mainWidget, i18n(
"%1\ndoes not appear to be a valid URL.\n").arg(d->url.url()), i18n(
"Invalid URL") );
463 KURL url = TDEIO::NetAccess::mostLocalURL(selectedURL,topLevelWidget());
464 if ( (
mode() & KFile::LocalOnly) == KFile::LocalOnly &&
465 !url.isLocalFile() ) {
466 KMessageBox::sorry( d->mainWidget,
467 i18n(
"You can only select local files."),
468 i18n(
"Remote Files Not Accepted") );
476 if ( (
mode() & KFile::Directory) == KFile::Directory ) {
477 kdDebug(tdefile_area) <<
"Directory" << endl;
479 if ( d->url.isLocalFile() ) {
480 if ( locationEdit->currentText().stripWhiteSpace().isEmpty() ) {
481 TQFileInfo info( d->url.path() );
482 if ( info.isDir() ) {
483 d->filenames = TQString::null;
485 d->urlList.append( d->url );
488 else if (!info.exists() && (
mode() & KFile::File) != KFile::File) {
490 if ( ops->
mkdir( d->url.url(), true ))
497 if ( (
mode() & KFile::File) == KFile::File ||
498 (
mode() & KFile::Files) == KFile::Files )
504 if (
mode() & KFile::ExistingOnly )
508 KURL fullURL(d->url, locationEdit->currentText());
509 if ( TQFile::exists( fullURL.path() ) )
512 d->filenames = TQString::null;
522 d->filenames = locationEdit->currentText();
529 d->filenames = TQString::null;
531 d->urlList.append( d->url );
533 if (
mode() & KFile::ExistingOnly )
543 if (!kapp->authorizeURLAction(
"open", KURL(), d->url))
545 TQString msg = TDEIO::buildErrorString(TDEIO::ERR_ACCESS_DENIED, d->url.prettyURL());
546 KMessageBox::error( d->mainWidget, msg);
550 TDEIO::StatJob *job = 0L;
552 d->filenames = KShell::tildeExpand(locationEdit->currentText());
554 if ( (
mode() & KFile::Files) == KFile::Files &&
555 !locationEdit->currentText().contains(
'/' )) {
556 kdDebug(tdefile_area) <<
"Files\n";
557 KURL::List list = parseSelectedURLs();
558 for ( KURL::List::ConstIterator it = list.begin();
559 it != list.end(); ++it )
561 if (!kapp->authorizeURLAction(
"open", KURL(), *it))
563 TQString msg = TDEIO::buildErrorString(TDEIO::ERR_ACCESS_DENIED, (*it).prettyURL());
564 KMessageBox::error( d->mainWidget, msg);
568 for ( KURL::List::ConstIterator it = list.begin();
569 it != list.end(); ++it )
571 job = TDEIO::stat( *it, !(*it).isLocalFile() );
572 job->setWindow (topLevelWidget());
573 TDEIO::Scheduler::scheduleJob( job );
574 d->statJobs.append( job );
575 connect( job, TQT_SIGNAL( result(TDEIO::Job *) ),
576 TQT_SLOT( slotStatResult( TDEIO::Job *) ));
581 job = TDEIO::stat(d->url,!d->url.isLocalFile());
582 job->setWindow (topLevelWidget());
583 d->statJobs.append( job );
584 connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotStatResult(TDEIO::Job*)));
588 static bool isDirectory (
const TDEIO::UDSEntry &t)
592 for (TDEIO::UDSEntry::ConstIterator it = t.begin();
596 if ((*it).m_uds == TDEIO::UDS_FILE_TYPE)
598 isDir = S_ISDIR ((mode_t) ((*it).m_long));
609 void KFileDialog::slotStatResult(TDEIO::Job* job)
611 kdDebug(tdefile_area) <<
"slotStatResult" << endl;
612 TDEIO::StatJob *sJob =
static_cast<TDEIO::StatJob *
>( job );
614 if ( !d->statJobs.removeRef( sJob ) ) {
618 int count = d->statJobs.count();
622 if (sJob->error() && count == 0 && !ops->
dirOnlyMode())
628 TDEIO::UDSEntry t = sJob->statResult();
633 d->filenames = TQString::null;
640 locationEdit->clearEdit();
641 locationEdit->lineEdit()->setEdited(
false );
653 kdDebug(tdefile_area) <<
"filename " << sJob->url().url() << endl;
659 void KFileDialog::accept()
661 setResult( TQDialog::Accepted );
663 *lastDirectory = ops->
url();
664 if (!d->fileClass.isEmpty())
668 locationEdit->changeItem( TQString::null, 0 );
671 TQValueListConstIterator<KURL> it = list.begin();
672 for ( ; it != list.end(); ++it ) {
673 const KURL& url = *it;
677 TQString file = url.isLocalFile() ? url.path(-1) : url.prettyURL(-1);
680 for (
int i = 1; i < locationEdit->count(); i++ ) {
681 if ( locationEdit->text( i ) == file ) {
682 locationEdit->removeItem( i-- );
686 locationEdit->insertItem( file, 1 );
689 TDEConfig *config = TDEGlobal::config();
690 config->setForceGlobal(
true );
692 config->setForceGlobal(
false );
697 KDialogBase::accept();
699 addToRecentDocuments();
701 if ( (
mode() & KFile::Files) != KFile::Files )
715 if ( (ops->
mode() & KFile::Files) != KFile::Files ) {
721 if ( !locationEdit->hasFocus() ) {
722 setLocationText( i->name() );
738 if ( (ops->
mode() & KFile::Files) != KFile::Files ) {
743 setLocationText( i->name() );
757 if ( locationEdit->hasFocus() )
760 locationEdit->lineEdit()->setEdited(
false );
764 locationEdit->clearEdit();
768 static const TQString &begin = TDEGlobal::staticQString(
" \"");
769 KFileItemListIterator it ( *list );
771 while ( (item = it.current()) ) {
772 text.append( begin ).append( item->name() ).append(
'\"' );
776 setLocationText( text.stripWhiteSpace() );
779 void KFileDialog::setLocationText(
const TQString& text )
784 disconnect( locationEdit, TQT_SIGNAL( textChanged(
const TQString& ) ),
785 this, TQT_SLOT( slotLocationChanged(
const TQString& ) ) );
786 locationEdit->setCurrentItem( 0 );
787 connect( locationEdit, TQT_SIGNAL( textChanged(
const TQString& ) ),
788 TQT_SLOT( slotLocationChanged(
const TQString& )) );
789 locationEdit->setEditText( text );
792 if ( d->operationMode == Saving && !locationEdit->isVisible())
793 setNonExtSelection();
796 static const char autocompletionWhatsThisText[] = I18N_NOOP(
"<p>While typing in the text area, you may be presented " 797 "with possible matches. " 798 "This feature can be controlled by clicking with the right mouse button " 799 "and selecting a preferred mode from the <b>Text Completion</b> menu.")
"</qt>";
800 void KFileDialog::updateLocationWhatsThis (
void)
802 TQString whatsThisText;
803 if (d->operationMode == KFileDialog::Saving)
805 whatsThisText =
"<qt>" + i18n(
"This is the name to save the file as.") +
806 i18n (autocompletionWhatsThisText);
808 else if (ops->
mode() & KFile::Files)
810 whatsThisText =
"<qt>" + i18n(
"This is the list of files to open. More than " 811 "one file can be specified by listing several " 812 "files, separated by spaces.") +
813 i18n (autocompletionWhatsThisText);
817 whatsThisText =
"<qt>" + i18n(
"This is the name of the file to open.") +
818 i18n (autocompletionWhatsThisText);
821 TQWhatsThis::add(d->locationLabel, whatsThisText);
822 TQWhatsThis::add(locationEdit, whatsThisText);
828 d =
new KFileDialogPrivate();
831 d->keepLocation =
false;
832 d->operationMode = Opening;
833 d->bookmarkHandler = 0;
834 d->hasDefaultFilter =
false;
836 d->mainWidget =
new TQWidget(
this,
"KFileDialog::mainWidget");
837 setMainWidget( d->mainWidget );
838 d->okButton =
new KPushButton( KStdGuiItem::ok(), d->mainWidget );
839 d->okButton->setDefault(
true );
840 d->cancelButton =
new KPushButton(KStdGuiItem::cancel(), d->mainWidget);
841 connect( d->okButton, TQT_SIGNAL( clicked() ), TQT_SLOT( slotOk() ));
842 connect( d->cancelButton, TQT_SIGNAL( clicked() ), TQT_SLOT( slotCancel() ));
843 d->customWidget = widget;
844 d->autoSelectExtCheckBox = 0;
845 d->autoSelectExtChecked =
false;
848 TQtMsgHandler oldHandler = tqInstallMsgHandler( silenceQToolBar );
849 toolbar =
new TDEToolBar( d->mainWidget,
"KFileDialog::toolbar",
true);
850 toolbar->setFlat(
true);
851 tqInstallMsgHandler( oldHandler );
853 d->pathCombo =
new KURLComboBox( KURLComboBox::Directories,
true,
854 toolbar,
"path combo" );
855 TQToolTip::add( d->pathCombo, i18n(
"Current location") );
856 TQWhatsThis::add( d->pathCombo,
"<qt>" + i18n(
"This is the currently listed location. " 857 "The drop-down list also lists commonly used locations. " 858 "This includes standard locations, such as your home folder, as well as " 859 "locations that have been visited recently.") + i18n (autocompletionWhatsThisText));
862 u.setPath( TQDir::rootDirPath() );
863 TQString text = i18n(
"Root Folder: %1").arg( u.path() );
864 d->pathCombo->addDefaultURL( u,
865 KMimeType::pixmapForURL( u, 0, TDEIcon::Small ),
868 u.setPath( TQDir::homeDirPath() );
869 text = i18n(
"Home Folder: %1").arg( u.path( +1 ) );
870 d->pathCombo->addDefaultURL( u, KMimeType::pixmapForURL( u, 0, TDEIcon::Small ),
874 docPath.setPath( TDEGlobalSettings::documentPath() );
875 if ( (u.path(+1) != docPath.path(+1)) &&
876 TQDir(docPath.path(+1)).exists() )
878 text = i18n(
"Documents: %1").arg( docPath.path( +1 ) );
879 d->pathCombo->addDefaultURL( docPath,
880 KMimeType::pixmapForURL( docPath, 0, TDEIcon::Small ),
884 u.setPath( TDEGlobalSettings::desktopPath() );
885 text = i18n(
"Desktop: %1").arg( u.path( +1 ) );
886 d->pathCombo->addDefaultURL( u,
887 KMimeType::pixmapForURL( u, 0, TDEIcon::Small ),
891 d->selection = d->url.url();
894 if ( d->url.isLocalFile() )
896 if ( !TQFile::exists( d->url.path() ) )
898 d->url = d->url.upURL();
899 TQDir dir( d->url.path() );
900 while ( !dir.exists() )
902 d->url = d->url.upURL();
903 dir.setPath( d->url.path() );
908 ops =
new KDirOperator(d->url, d->mainWidget,
"KFileDialog::ops");
910 connect(ops, TQT_SIGNAL(urlEntered(
const KURL&)),
911 TQT_SLOT(urlEntered(
const KURL&)));
914 connect(ops, TQT_SIGNAL(
fileSelected(
const KFileItem *)),
916 connect(ops, TQT_SIGNAL(finishedLoading()),
917 TQT_SLOT(slotLoadingFinished()));
919 ops->
setupMenu(KDirOperator::SortActions |
920 KDirOperator::FileActions |
921 KDirOperator::ViewActions);
925 coll->action(
"up" )->plug( toolbar );
926 coll->action(
"up" )->setWhatsThis(i18n(
"<qt>Click this button to enter the parent folder.<p>" 927 "For instance, if the current location is file:/home/%1 clicking this " 928 "button will take you to file:/home.</qt>").arg( KUser().loginName() ));
929 coll->action(
"back" )->plug( toolbar );
930 coll->action(
"back" )->setWhatsThis(i18n(
"Click this button to move backwards one step in the browsing history."));
931 coll->action(
"forward" )->plug( toolbar );
932 coll->action(
"forward" )->setWhatsThis(i18n(
"Click this button to move forward one step in the browsing history."));
933 coll->action(
"reload" )->plug( toolbar );
934 coll->action(
"reload" )->setWhatsThis(i18n(
"Click this button to reload the contents of the current location."));
935 coll->action(
"mkdir" )->setShortcut(Key_F10);
936 coll->action(
"mkdir" )->plug( toolbar );
937 coll->action(
"mkdir" )->setWhatsThis(i18n(
"Click this button to create a new folder."));
939 TDEToggleAction *showSidebarAction =
940 new TDEToggleAction(i18n(
"Show Quick Access Navigation Panel"), Key_F9, coll,
"toggleSpeedbar");
941 showSidebarAction->setCheckedState(i18n(
"Hide Quick Access Navigation Panel"));
942 connect( showSidebarAction, TQT_SIGNAL( toggled(
bool ) ),
945 TDEToggleAction *showBookmarksAction =
946 new TDEToggleAction(i18n(
"Show Bookmarks"), 0, coll,
"toggleBookmarks");
947 showBookmarksAction->setCheckedState(i18n(
"Hide Bookmarks"));
948 connect( showBookmarksAction, TQT_SIGNAL( toggled(
bool ) ),
951 TDEActionMenu *menu =
new TDEActionMenu( i18n(
"Configure"),
"configure", TQT_TQOBJECT(
this),
"extra menu" );
952 menu->setWhatsThis(i18n(
"<qt>This is the configuration menu for the file dialog. " 953 "Various options can be accessed from this menu including: <ul>" 954 "<li>how files are sorted in the list</li>" 955 "<li>types of view, including icon and list</li>" 956 "<li>showing of hidden files</li>" 957 "<li>the Quick Access navigation panel</li>" 958 "<li>file previews</li>" 959 "<li>separating folders from files</li></ul></qt>"));
960 menu->insert( coll->action(
"sorting menu" ));
961 menu->insert( coll->action(
"separator" ));
962 coll->action(
"short view" )->setShortcut(Key_F6);
963 menu->insert( coll->action(
"short view" ));
964 coll->action(
"detailed view" )->setShortcut(Key_F7);
965 menu->insert( coll->action(
"detailed view" ));
966 menu->insert( coll->action(
"separator" ));
967 coll->action(
"show hidden" )->setShortcut(Key_F8);
968 menu->insert( coll->action(
"show hidden" ));
969 menu->insert( showSidebarAction );
970 menu->insert( showBookmarksAction );
971 coll->action(
"preview" )->setShortcut(Key_F11);
972 menu->insert( coll->action(
"preview" ));
973 coll->action(
"separate dirs" )->setShortcut(Key_F12);
974 menu->insert( coll->action(
"separate dirs" ));
976 menu->setDelayed(
false );
977 connect( menu->popupMenu(), TQT_SIGNAL( aboutToShow() ),
978 ops, TQT_SLOT( updateSelectionDependentActions() ));
979 menu->plug( toolbar );
982 TDEToolBarSeparator* spacerWidget =
new TDEToolBarSeparator(Qt::Horizontal,
false ,
984 d->m_pathComboIndex = toolbar->insertWidget(-1, -1, spacerWidget);
985 toolbar->insertWidget(PATH_COMBO, 0, d->pathCombo);
988 toolbar->setItemAutoSized (PATH_COMBO);
989 toolbar->setIconText(TDEToolBar::IconOnly);
990 toolbar->setBarPos(TDEToolBar::Top);
991 toolbar->setMovingEnabled(
false);
992 toolbar->adjustSize();
994 KURLCompletion *pathCompletionObj =
new KURLCompletion( KURLCompletion::DirCompletion );
995 d->pathCombo->setCompletionObject( pathCompletionObj );
996 d->pathCombo->setAutoDeleteCompletionObject(
true );
998 connect( d->pathCombo, TQT_SIGNAL( urlActivated(
const KURL& )),
999 this, TQT_SLOT( enterURL(
const KURL& ) ));
1000 connect( d->pathCombo, TQT_SIGNAL( returnPressed(
const TQString& )),
1001 this, TQT_SLOT( enterURL(
const TQString& ) ));
1002 connect( d->pathCombo, TQT_SIGNAL( activated(
const TQString& )),
1003 this, TQT_SLOT( enterURL(
const TQString& ) ));
1005 TQString whatsThisText;
1008 d->locationLabel =
new TQLabel(i18n(
"&Location:"), d->mainWidget);
1009 locationEdit =
new KURLComboBox(KURLComboBox::Files,
true,
1010 d->mainWidget,
"LocationEdit");
1011 locationEdit->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed));
1012 connect( locationEdit, TQT_SIGNAL( textChanged(
const TQString& ) ),
1013 TQT_SLOT( slotLocationChanged(
const TQString& )) );
1015 updateLocationWhatsThis ();
1016 d->locationLabel->setBuddy(locationEdit);
1018 locationEdit->setFocus();
1019 KURLCompletion *fileCompletionObj =
new KURLCompletion( KURLCompletion::FileCompletion );
1020 TQString dir = d->url.url(+1);
1021 pathCompletionObj->setDir( dir );
1022 fileCompletionObj->setDir( dir );
1023 locationEdit->setCompletionObject( fileCompletionObj );
1024 locationEdit->setAutoDeleteCompletionObject(
true );
1025 connect( fileCompletionObj, TQT_SIGNAL( match(
const TQString& ) ),
1026 TQT_SLOT( fileCompletion(
const TQString& )) );
1028 connect( locationEdit, TQT_SIGNAL( returnPressed() ),
1029 this, TQT_SLOT( slotOk()));
1030 connect(locationEdit, TQT_SIGNAL( activated(
const TQString& )),
1031 this, TQT_SLOT( locationActivated(
const TQString& ) ));
1034 whatsThisText = i18n(
"<qt>This is the filter to apply to the file list. " 1035 "File names that do not match the filter will not be shown.<p>" 1036 "You may select from one of the preset filters in the " 1037 "drop down menu, or you may enter a custom filter " 1038 "directly into the text area.<p>" 1039 "Wildcards such as * and ? are allowed.</qt>");
1040 d->filterLabel =
new TQLabel(i18n(
"&Filter:"), d->mainWidget);
1041 TQWhatsThis::add(d->filterLabel, whatsThisText);
1042 filterWidget =
new KFileFilterCombo(d->mainWidget,
1043 "KFileDialog::filterwidget");
1044 filterWidget->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed));
1045 TQWhatsThis::add(filterWidget, whatsThisText);
1047 d->filterLabel->setBuddy(filterWidget);
1048 connect(filterWidget, TQT_SIGNAL(
filterChanged()), TQT_SLOT(slotFilterChanged()));
1052 d->autoSelectExtCheckBox =
new TQCheckBox (d->mainWidget);
1053 connect(d->autoSelectExtCheckBox, TQT_SIGNAL(clicked()), TQT_SLOT(slotAutoSelectExtClicked()));
1057 TDEConfig* config = TDEGlobal::config();
1067 void KFileDialog::initSpeedbar()
1069 d->urlBar =
new KFileSpeedBar( d->mainWidget,
"url bar" );
1070 connect( d->urlBar, TQT_SIGNAL( activated(
const KURL& )),
1071 TQT_SLOT( enterURL(
const KURL& )) );
1077 d->urlBar->setCurrentItem( d->url );
1079 d->urlBarLayout->insertWidget( 0, d->urlBar );
1084 delete d->boxLayout;
1086 d->boxLayout =
new TQVBoxLayout( d->mainWidget, 0, KDialog::spacingHint());
1087 d->boxLayout->addWidget(toolbar, AlignTop);
1089 d->urlBarLayout =
new TQHBoxLayout( d->boxLayout );
1090 TQVBoxLayout *vbox =
new TQVBoxLayout( d->urlBarLayout );
1092 vbox->addWidget(ops, 4);
1093 vbox->addSpacing(3);
1095 TQGridLayout* lafBox=
new TQGridLayout(2, 3, KDialog::spacingHint());
1097 lafBox->addWidget(d->locationLabel, 0, 0, Qt::AlignVCenter);
1098 lafBox->addWidget(locationEdit, 0, 1, Qt::AlignVCenter);
1099 lafBox->addWidget(d->okButton, 0, 2, Qt::AlignVCenter);
1101 lafBox->addWidget(d->filterLabel, 1, 0, Qt::AlignVCenter);
1102 lafBox->addWidget(filterWidget, 1, 1, Qt::AlignVCenter);
1103 lafBox->addWidget(d->cancelButton, 1, 2, Qt::AlignVCenter);
1105 lafBox->setColStretch(1, 4);
1107 vbox->addLayout(TQT_TQLAYOUT(lafBox), 0);
1108 vbox->addSpacing(3);
1111 vbox->addWidget (d->autoSelectExtCheckBox);
1112 vbox->addSpacing (3);
1114 setTabOrder(ops, d->autoSelectExtCheckBox);
1115 setTabOrder (d->autoSelectExtCheckBox, locationEdit);
1116 setTabOrder(locationEdit, filterWidget);
1117 setTabOrder(filterWidget, d->okButton);
1118 setTabOrder(d->okButton, d->cancelButton);
1119 setTabOrder(d->cancelButton, d->pathCombo);
1120 setTabOrder(d->pathCombo, ops);
1123 if ( d->customWidget != 0 )
1128 d->customWidget->reparent( d->mainWidget, TQPoint() );
1130 vbox->addWidget( d->customWidget );
1131 vbox->addSpacing(3);
1138 setTabOrder(d->cancelButton, d->customWidget);
1139 setTabOrder(d->customWidget, d->pathCombo);
1143 setTabOrder(d->cancelButton, d->pathCombo);
1146 setTabOrder(d->pathCombo, ops);
1149 void KFileDialog::slotFilterChanged()
1151 TQString filter = filterWidget->currentFilter();
1154 if ( filter.find(
'/' ) > -1 ) {
1155 TQStringList types = TQStringList::split(
" ", filter );
1156 types.prepend(
"inode/directory" );
1172 d->selection = TQString::null;
1173 ops->
setURL( url, clearforward);
1177 void KFileDialog::urlEntered(
const KURL& url)
1179 TQString filename = locationEdit->currentText();
1180 d->selection = TQString::null;
1182 if ( d->pathCombo->count() != 0 ) {
1183 d->pathCombo->setURL( url );
1186 if (url.protocol()==
"beagle" && url.path()==
"/") {
1187 d->pathCombo->setEditText(
"beagle:/<"+i18n(
"search term")+
">");
1188 d->pathCombo->lineEdit()->setSelection(8,255);
1189 d->pathCombo->setFocus();
1192 locationEdit->blockSignals(
true );
1193 locationEdit->setCurrentItem( 0 );
1194 if ( d->keepLocation )
1195 locationEdit->setEditText( filename );
1197 locationEdit->blockSignals(
false );
1199 TQString dir = url.url(+1);
1200 static_cast<KURLCompletion*
>( d->pathCombo->completionObject() )->setDir( dir );
1201 static_cast<KURLCompletion*
>( locationEdit->completionObject() )->setDir( dir );
1204 d->urlBar->setCurrentItem( url );
1207 void KFileDialog::locationActivated(
const TQString& url )
1214 if (!locationEdit->lineEdit()->edited())
1218 void KFileDialog::enterURL(
const KURL& url)
1223 void KFileDialog::enterURL(
const TQString& url )
1225 setURL( KURL::fromPathOrURL( KURLCompletion::replacedPath( url,
true,
true )) );
1239 kdDebug(tdefile_area) <<
"setSelection " << url << endl;
1241 if (url.isEmpty()) {
1242 d->selection = TQString::null;
1248 kdWarning() << url <<
" is not a correct argument for setSelection!" << endl;
1252 if (!KProtocolInfo::supportsListing(u)) {
1253 locationEdit->lineEdit()->setEdited(
true );
1260 KFileItem i(KFileItem::Unknown, KFileItem::Unknown, u,
true );
1262 if ( i.isDir() && u.isLocalFile() && TQFile::exists( u.path() ) ) {
1270 TQString filename = u.url();
1271 int sep = filename.findRev(
'/');
1273 if ( KProtocolInfo::supportsListing( u )) {
1275 dir.setQuery( TQString::null );
1276 dir.setFileName( TQString::null );
1282 filename = u.fileName();
1283 kdDebug(tdefile_area) <<
"filename " << filename << endl;
1284 d->selection = filename;
1285 setLocationText( filename );
1294 locationEdit->lineEdit()->setEdited(
true );
1297 d->url = ops->
url();
1298 d->url.addPath(filename);
1302 void KFileDialog::slotLoadingFinished()
1304 if ( !d->selection.isNull() )
1315 void KFileDialog::fileCompletion(
const TQString& match )
1317 if ( match.isEmpty() && ops->
view() )
1323 void KFileDialog::slotLocationChanged(
const TQString& text )
1325 if ( text.isEmpty() && ops->
view() )
1333 kdWarning() <<
"KFileDialog::updateStatusLine is deprecated! The status line no longer exists. Do not try and use it!" << endl;
1337 const TQString& filter,
1338 TQWidget *parent,
const TQString& caption)
1340 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1343 dlg.
setMode( KFile::File | KFile::LocalOnly );
1344 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1353 const TQString& filter,
1354 WId parent_id,
const TQString& caption)
1356 TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
1357 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1359 if( parent == NULL && parent_id != 0 )
1360 XSetTransientForHint( tqt_xdisplay(), dlg.winId(), parent_id );
1367 dlg.
setMode( KFile::File | KFile::LocalOnly );
1368 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1377 const TQString& filter,
1379 const TQString& caption)
1381 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1384 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1385 dlg.
setMode(KFile::Files | KFile::LocalOnly);
1393 TQWidget *parent,
const TQString& caption)
1395 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1398 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1407 const TQString& filter,
1409 const TQString& caption)
1411 KFileDialog dlg(startDir, filter, parent,
"filedialog",
true);
1414 dlg.setCaption(caption.isNull() ? i18n(
"Open") : caption);
1424 const TQString& caption)
1431 const TQString& caption)
1434 return TQFileDialog::getExistingDirectory(startDir, parent,
"getExistingDirectory",
1435 caption,
true,
true);
1439 if ( url.isValid() )
1442 return TQString::null;
1447 const TQString& caption)
1449 TQStringList mimetypes = KImageIO::mimeTypes( KImageIO::Reading );
1451 mimetypes.join(
" "),
1452 parent,
"filedialog",
true);
1454 dlg.setCaption( caption.isNull() ? i18n(
"Open") : caption );
1455 dlg.setMode( KFile::File );
1458 dlg.setPreviewWidget( ip );
1461 return dlg.selectedURL();
1466 if ( result() == TQDialog::Accepted )
1475 if ( result() == TQDialog::Accepted ) {
1476 if ( (ops->
mode() & KFile::Files) == KFile::Files )
1477 list = parseSelectedURLs();
1479 list.append( d->url );
1485 KURL::List& KFileDialog::parseSelectedURLs()
const 1487 if ( d->filenames.isEmpty() ) {
1492 if ( d->filenames.contains(
'/' )) {
1493 static const TQString &prot = TDEGlobal::staticQString(
":/");
1495 if ( d->filenames.find( prot ) != -1 )
1498 u.setPath( d->filenames );
1501 d->urlList.append( u );
1503 KMessageBox::error( d->mainWidget,
1504 i18n(
"The chosen filenames do not\n" 1505 "appear to be valid."),
1506 i18n(
"Invalid Filenames") );
1510 d->urlList =
tokenize( d->filenames );
1512 d->filenames = TQString::null;
1522 KURL u( ops->
url() );
1525 int count = line.contains(
'"' );
1527 u.setFileName( line );
1534 if ( (count % 2) == 1 ) {
1536 KMessageBox::sorry(that, i18n(
"The requested filenames\n" 1538 "do not appear to be valid;\n" 1539 "make sure every filename is enclosed in double quotes.").arg(line),
1540 i18n(
"Filename Error"));
1545 int index1 = -1, index2 = -1;
1547 index1 = line.find(
'"', start );
1548 index2 = line.find(
'"', index1 + 1 );
1554 name = line.mid( index1 + 1, index2 - index1 - 1 );
1555 u.setFileName( name );
1567 if ( result() == TQDialog::Accepted )
1569 KURL url = TDEIO::NetAccess::mostLocalURL(d->url,topLevelWidget());
1570 if (url.isLocalFile())
1573 KMessageBox::sorry( d->mainWidget,
1574 i18n(
"You can only select local files."),
1575 i18n(
"Remote Files Not Accepted") );
1578 return TQString::null;
1586 if ( result() == TQDialog::Accepted ) {
1587 if ( (ops->
mode() & KFile::Files) == KFile::Files ) {
1588 KURL::List urls = parseSelectedURLs();
1589 TQValueListConstIterator<KURL> it = urls.begin();
1590 while ( it != urls.end() ) {
1591 url = TDEIO::NetAccess::mostLocalURL(*it,topLevelWidget());
1592 if ( url.isLocalFile() )
1593 list.append( url.path() );
1599 if ( d->url.isLocalFile() )
1600 list.append( d->url.path() );
1614 const TQString& caption)
1616 bool specialDir = dir.at(0) ==
':';
1617 KFileDialog dlg( specialDir ? dir : TQString::null, filter, parent,
"filedialog",
true);
1622 dlg.setCaption(caption.isNull() ? i18n(
"Save As") : caption);
1627 if (!filename.isEmpty())
1635 const TQString& caption)
1637 bool specialDir = dir.at(0) ==
':';
1638 TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
1639 KFileDialog dlg( specialDir ? dir : TQString::null, filter, parent,
"filedialog",
true);
1641 if( parent == NULL && parent_id != 0 )
1642 XSetTransientForHint(tqt_xdisplay(), dlg.winId(), parent_id);
1651 dlg.setCaption(caption.isNull() ? i18n(
"Save As") : caption);
1656 if (!filename.isEmpty())
1663 TQWidget *parent,
const TQString& caption)
1665 bool specialDir = dir.at(0) ==
':';
1666 KFileDialog dlg(specialDir ? dir : TQString::null, filter, parent,
"filedialog",
true);
1670 dlg.setCaption(caption.isNull() ? i18n(
"Save As") : caption);
1682 void KFileDialog::show()
1684 if ( !d->hasView ) {
1690 KDialogBase::show();
1697 filterWidget->setDefaultFilter( i18n(
"*|All Folders") );
1700 filterWidget->setDefaultFilter( i18n(
"*|All Files") );
1708 setMode(static_cast<KFile::Mode>( m ));
1722 TQString oldGroup = kc->group();
1723 if ( !group.isEmpty() )
1724 kc->setGroup( group );
1729 combo->
setURLs( kc->readPathListEntry( RecentURLs ), KURLComboBox::RemoveTop );
1730 combo->
setMaxItems( kc->readNumEntry( RecentURLsNumber,
1731 DefaultRecentURLsNumber ) );
1733 autoDirectoryFollowing = kc->readBoolEntry( AutoDirectoryFollowing,
1734 DefaultDirectoryFollowing );
1736 TDEGlobalSettings::Completion cm = (TDEGlobalSettings::Completion)
1737 kc->readNumEntry( PathComboCompletionMode,
1738 TDEGlobalSettings::completionMode() );
1739 if ( cm != TDEGlobalSettings::completionMode() )
1740 combo->setCompletionMode( cm );
1742 cm = (TDEGlobalSettings::Completion)
1743 kc->readNumEntry( LocationComboCompletionMode,
1744 TDEGlobalSettings::completionMode() );
1745 if ( cm != TDEGlobalSettings::completionMode() )
1746 locationEdit->setCompletionMode( cm );
1755 d->autoSelectExtChecked = kc->readBoolEntry (AutoSelectExtChecked, DefaultAutoSelectExtChecked);
1758 int w1 = minimumSize().width();
1759 int w2 = toolbar->sizeHint().width() + 10;
1761 setMinimumWidth(w2);
1763 TQSize size = configDialogSize( group );
1765 kc->setGroup( oldGroup );
1773 TQString oldGroup = kc->group();
1774 if ( !group.isEmpty() )
1775 kc->setGroup( group );
1777 kc->writePathEntry( RecentURLs, d->pathCombo->urls() );
1778 saveDialogSize( group,
true );
1779 kc->writeEntry( PathComboCompletionMode, static_cast<int>(d->pathCombo->completionMode()) );
1780 kc->writeEntry( LocationComboCompletionMode, static_cast<int>(locationEdit->completionMode()) );
1781 kc->writeEntry( ShowSpeedbar, d->urlBar && !d->urlBar->isHidden() );
1782 kc->writeEntry( ShowBookmarks, d->bookmarkHandler != 0 );
1783 kc->writeEntry( AutoSelectExtChecked, d->autoSelectExtChecked );
1786 kc->setGroup( oldGroup );
1792 TQString oldGroup = kc->group();
1793 kc->setGroup( ConfigGroup );
1795 locationEdit->
setMaxItems( kc->readNumEntry( RecentFilesNumber,
1796 DefaultRecentURLsNumber ) );
1797 locationEdit->
setURLs( kc->readPathListEntry( RecentFiles ),
1798 KURLComboBox::RemoveBottom );
1799 locationEdit->insertItem( TQString::null, 0 );
1800 locationEdit->setCurrentItem( 0 );
1802 kc->setGroup( oldGroup );
1807 TQString oldGroup = kc->group();
1808 kc->setGroup( ConfigGroup );
1810 kc->writePathEntry( RecentFiles, locationEdit->
urls() );
1812 kc->setGroup( oldGroup );
1822 return d->cancelButton;
1830 void KFileDialog::slotCancel()
1833 KDialogBase::slotCancel();
1835 TDEConfig *config = TDEGlobal::config();
1836 config->setForceGlobal(
true );
1838 config->setForceGlobal(
false );
1843 d->keepLocation = keep;
1848 return d->keepLocation;
1853 d->operationMode =
mode;
1854 d->keepLocation = (mode == Saving);
1855 filterWidget->setEditable( !d->hasDefaultFilter || mode != Saving );
1856 if ( mode == Opening )
1857 d->okButton->setGuiItem( KGuiItem( i18n(
"&Open"),
"document-open") );
1858 else if ( mode == Saving ) {
1859 d->okButton->setGuiItem( KStdGuiItem::save() );
1860 setNonExtSelection();
1863 d->okButton->setGuiItem( KStdGuiItem::ok() );
1864 updateLocationWhatsThis ();
1870 return d->operationMode;
1873 void KFileDialog::slotAutoSelectExtClicked()
1875 kdDebug (tdefile_area) <<
"slotAutoSelectExtClicked(): " 1876 << d->autoSelectExtCheckBox->isChecked () << endl;
1879 d->autoSelectExtChecked = d->autoSelectExtCheckBox->isChecked ();
1882 updateLocationEditExtension (d->extension );
1885 static TQString getExtensionFromPatternList (
const TQStringList &patternList)
1888 kdDebug (tdefile_area) <<
"\tgetExtension " << patternList << endl;
1890 TQStringList::ConstIterator patternListEnd = patternList.end ();
1891 for (TQStringList::ConstIterator it = patternList.begin ();
1892 it != patternListEnd;
1895 kdDebug (tdefile_area) <<
"\t\ttry: \'" << (*it) <<
"\'" << endl;
1904 if ((*it).startsWith (
"*.") &&
1905 (*it).length () > 2 &&
1906 (*it).find (
'*', 2) < 0 && (*it).find (
'?', 2) < 0)
1908 ret = (*it).mid (1);
1916 static TQString stripUndisplayable (
const TQString &
string)
1918 TQString ret = string;
1929 return d->extension;
1934 if (!d->autoSelectExtCheckBox)
return;
1943 kdDebug (tdefile_area) <<
"Figure out an extension: " << endl;
1944 TQString lastExtension = d->extension;
1945 d->extension = TQString::null;
1955 if (!filter.isEmpty ())
1958 if (filter.find (
'/') < 0)
1960 d->extension = getExtensionFromPatternList (TQStringList::split (
" ", filter)).lower ();
1961 kdDebug (tdefile_area) <<
"\tsetFilter-style: pattern ext=\'" 1962 << d->extension <<
"\'" << endl;
1967 KMimeType::Ptr mime = KMimeType::mimeType (filter);
1970 TQString nativeExtension = mime->property (
"X-TDE-NativeExtension").toString ();
1971 if (nativeExtension.at (0) ==
'.')
1973 d->extension = nativeExtension.lower ();
1974 kdDebug (tdefile_area) <<
"\tsetMimeFilter-style: native ext=\'" 1975 << d->extension <<
"\'" << endl;
1979 if (d->extension.isEmpty ())
1981 d->extension = getExtensionFromPatternList (mime->patterns ()).lower ();
1982 kdDebug (tdefile_area) <<
"\tsetMimeFilter-style: pattern ext=\'" 1983 << d->extension <<
"\'" << endl;
1993 TQString whatsThisExtension;
1994 if (!d->extension.isEmpty ())
1997 d->autoSelectExtCheckBox->setText (i18n (
"Automatically select filename e&xtension (%1)").arg (d->extension));
1998 whatsThisExtension = i18n (
"the extension <b>%1</b>").arg (d->extension);
2000 d->autoSelectExtCheckBox->setEnabled (
true);
2001 d->autoSelectExtCheckBox->setChecked (d->autoSelectExtChecked);
2006 d->autoSelectExtCheckBox->setText (i18n (
"Automatically select filename e&xtension"));
2007 whatsThisExtension = i18n (
"a suitable extension");
2009 d->autoSelectExtCheckBox->setChecked (
false);
2010 d->autoSelectExtCheckBox->setEnabled (
false);
2013 const TQString locationLabelText = stripUndisplayable (d->locationLabel->text ());
2014 const TQString filterLabelText = stripUndisplayable (d->filterLabel->text ());
2015 TQWhatsThis::add (d->autoSelectExtCheckBox,
2018 "This option enables some convenient features for " 2019 "saving files with extensions:<br>" 2021 "<li>Any extension specified in the <b>%1</b> text " 2022 "area will be updated if you change the file type " 2025 "<li>If no extension is specified in the <b>%2</b> " 2026 "text area when you click " 2027 "<b>Save</b>, %3 will be added to the end of the " 2028 "filename (if the filename does not already exist). " 2029 "This extension is based on the file type that you " 2030 "have chosen to save in.<br>" 2032 "If you do not want TDE to supply an extension for the " 2033 "filename, you can either turn this option off or you " 2034 "can suppress it by adding a period (.) to the end of " 2035 "the filename (the period will be automatically " 2039 "If unsure, keep this option enabled as it makes your " 2040 "files more manageable." 2042 .arg (locationLabelText)
2043 .arg (locationLabelText)
2044 .arg (whatsThisExtension)
2048 d->autoSelectExtCheckBox->show ();
2052 updateLocationEditExtension (lastExtension);
2057 d->autoSelectExtCheckBox->setChecked (
false);
2058 d->autoSelectExtCheckBox->hide ();
2065 void KFileDialog::updateLocationEditExtension (
const TQString &lastExtension)
2067 if (!d->autoSelectExtCheckBox->isChecked () || d->extension.isEmpty ())
2070 TQString urlStr = locationEdit->currentText ();
2071 if (urlStr.isEmpty ())
2075 kdDebug (tdefile_area) <<
"updateLocationEditExtension (" << url <<
")" << endl;
2077 const int fileNameOffset = urlStr.findRev (
'/') + 1;
2078 TQString fileName = urlStr.mid (fileNameOffset);
2080 const int dot = fileName.findRev (
'.');
2081 const int len = fileName.length ();
2089 if (TDEIO::NetAccess::stat (url, t, topLevelWidget()))
2091 kdDebug (tdefile_area) <<
"\tfile exists" << endl;
2093 if (isDirectory (t))
2095 kdDebug (tdefile_area) <<
"\tisDir - won't alter extension" << endl;
2108 if (lastExtension.length () && fileName.endsWith (lastExtension))
2109 fileName.truncate (len - lastExtension.length ());
2112 fileName.truncate (dot);
2115 const TQString newText = urlStr.left (fileNameOffset) + fileName + d->extension;
2116 if ( newText != locationEdit->currentText() )
2118 locationEdit->setCurrentText (urlStr.left (fileNameOffset) + fileName + d->extension);
2119 locationEdit->lineEdit()->setEdited (
true);
2126 void KFileDialog::updateFilter ()
2129 const TQString urlStr = locationEdit->currentText ();
2130 if (urlStr.isEmpty ())
2133 KMimeType::Ptr mime = KMimeType::findByPath(urlStr, 0,
true);
2134 if (mime && mime->name() != KMimeType::defaultMimeType()) {
2135 if (filterWidget->currentFilter() != mime->name() &&
2136 filterWidget->filters.findIndex(mime->name()) != -1) {
2137 filterWidget->setCurrentFilter(mime->name());
2144 void KFileDialog::appendExtension (KURL &url)
2146 if (!d->autoSelectExtCheckBox->isChecked () || d->extension.isEmpty ())
2149 TQString fileName = url.fileName ();
2150 if (fileName.isEmpty ())
2153 kdDebug (tdefile_area) <<
"appendExtension(" << url <<
")" << endl;
2155 const int len = fileName.length ();
2156 const int dot = fileName.findRev (
'.');
2158 const bool suppressExtension = (dot == len - 1);
2159 const bool unspecifiedExtension = (dot <= 0);
2162 if (!(suppressExtension || unspecifiedExtension))
2167 if (TDEIO::NetAccess::stat (url, t, topLevelWidget()))
2169 kdDebug (tdefile_area) <<
"\tfile exists - won't append extension" << endl;
2174 if (suppressExtension)
2186 kdDebug (tdefile_area) <<
"\tstrip trailing dot" << endl;
2187 url.setFileName (fileName.left (len - 1));
2190 else if (unspecifiedExtension)
2192 kdDebug (tdefile_area) <<
"\tappending extension \'" << d->extension <<
"\'..." << endl;
2193 url.setFileName (fileName + d->extension);
2194 kdDebug (tdefile_area) <<
"\tsaving as \'" << url <<
"\'" << endl;
2200 void KFileDialog::addToRecentDocuments()
2202 int m = ops->
mode();
2204 if ( m & KFile::LocalOnly ) {
2206 TQStringList::ConstIterator it = files.begin();
2207 for ( ; it != files.end(); ++it )
2213 KURL::List::ConstIterator it = urls.begin();
2214 for ( ; it != urls.end(); ++it ) {
2215 if ( (*it).isValid() )
2228 if ( e->key() == Key_Escape )
2231 d->cancelButton->animateClick();
2234 KDialogBase::keyPressEvent( e );
2249 homeURL.setPath( TQDir::homeDirPath() );
2252 if ( homeURL.equals( urlItem->
url(), true ) )
2258 urlItem =
static_cast<KURLBarItem*
>( urlItem->next() );
2270 static_cast<TDEToggleAction *
>(
actionCollection()->action(
"toggleSpeedbar"))->setChecked( show );
2277 if (d->bookmarkHandler)
2282 d->bookmarkHandler =
new KFileBookmarkHandler(
this );
2283 connect( d->bookmarkHandler, TQT_SIGNAL( openURL(
const TQString& )),
2284 TQT_SLOT( enterURL(
const TQString& )));
2286 toolbar->insertButton(TQString::fromLatin1(
"bookmark"),
2287 (
int)HOTLIST_BUTTON,
true,
2288 i18n(
"Bookmarks"), 5);
2289 toolbar->getButton(HOTLIST_BUTTON)->setPopup(d->bookmarkHandler->menu(),
2291 TQWhatsThis::add(toolbar->getButton(HOTLIST_BUTTON),
2292 i18n(
"<qt>This button allows you to bookmark specific locations. " 2293 "Click on this button to open the bookmark menu where you may add, " 2294 "edit or select a bookmark.<p>" 2295 "These bookmarks are specific to the file dialog, but otherwise operate " 2296 "like bookmarks elsewhere in TDE.</qt>"));
2298 else if (d->bookmarkHandler)
2300 delete d->bookmarkHandler;
2301 d->bookmarkHandler = 0;
2302 toolbar->removeItem(HOTLIST_BUTTON);
2305 static_cast<TDEToggleAction *
>(
actionCollection()->action(
"toggleBookmarks"))->setChecked( show );
2310 return d->m_pathComboIndex;
2314 void KFileDialog::initStatic()
2316 if ( lastDirectory )
2319 lastDirectory = ldd.setObject(lastDirectory,
new KURL());
2324 TQString& recentDirClass )
2328 recentDirClass = TQString::null;
2331 bool useDefaultStartDir = startDir.isEmpty();
2332 if ( !useDefaultStartDir )
2334 if (startDir[0] ==
':')
2336 recentDirClass = startDir;
2341 ret = TDECmdLineArgs::makeURL( TQFile::encodeName(startDir) );
2343 if ( !KProtocolInfo::supportsListing( ret ) )
2344 useDefaultStartDir =
true;
2348 if ( useDefaultStartDir )
2350 if (lastDirectory->isEmpty()) {
2351 lastDirectory->setPath(TDEGlobalSettings::documentPath());
2353 home.setPath( TQDir::homeDirPath() );
2358 if ( lastDirectory->path(+1) == home.path(+1) ||
2359 TQDir::currentDirPath() != TQDir::homeDirPath() ||
2360 !TQDir(lastDirectory->path(+1)).exists() )
2361 lastDirectory->setPath(TQDir::currentDirPath());
2363 ret = *lastDirectory;
2369 void KFileDialog::setStartDir(
const KURL& directory )
2372 if ( directory.isValid() )
2373 *lastDirectory = directory;
2376 void KFileDialog::setNonExtSelection()
2379 TQString pattern, filename = locationEdit->currentText().stripWhiteSpace();
2380 KServiceTypeFactory::self()->findFromPattern( filename, &pattern );
2382 if ( !pattern.isEmpty() && pattern.at( 0 ) ==
'*' && pattern.find(
'*' , 1 ) == -1 )
2383 locationEdit->lineEdit()->setSelection( 0, filename.length() - pattern.stripWhiteSpace().length()+1 );
2386 int lastDot = filename.findRev(
'.' );
2388 locationEdit->lineEdit()->setSelection( 0, lastDot );
2392 void KFileDialog::virtual_hook(
int id,
void* data )
2393 { KDialogBase::virtual_hook(
id, data ); }
2396 #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...
TQString currentMimeFilter() const
The mimetype for the desired output format.
This combobox shows a number of recent URLs/directories, as well as some default directories.
const KURL & url() const
returns the url of this item.
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.
KFile::Mode mode() const
Returns the mode of the filedialog.
const KFileItemList * selectedItems() const
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.
TQStringList urls() const
void setPreviewWidget(const TQWidget *w) KDE_DEPRECATED
~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.
void dirCompletion(const TQString &)
void init(const TQString &startDir, const TQString &filter, TQWidget *widget)
Perform basic initialization tasks.
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...
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.
KURL::List tokenize(const TQString &line) const
Parses the string "line" for files.
KPushButton * okButton() const
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.
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.
bool keepsLocation() 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".
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.
virtual void saveRecentFiles(TDEConfig *)
Saves the entries from the location combobox.
KURL::List selectedURLs() 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.
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.
TQString selectedFile() const
Returns the full path of the selected file in the local filesystem.
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...
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.
TQStringList selectedFiles() const
Returns a list of all selected local files.
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.
TQString currentFilter() const
Returns the current filter as entered by the user or one of the predefined set via setFilter()...
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.
OperationMode operationMode() const
virtual void readConfig(TDEConfig *, const TQString &group=TQString::null)
Reads configuration and applies it (size, recent directories, ...)
TDEActionCollection * actionCollection() const
virtual void writeConfig(TDEConfig *, const TQString &group=TQString::null)
Saves the current settings like sorting, simple or detailed view.
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...
TDEActionCollection * actionCollection() const
an accessor to a collection of all available Actions.
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...
KPushButton * cancelButton() const
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.