• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdefile
 

tdeio/tdefile

  • tdeio
  • tdefile
tdefiledialog.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 1997, 1998 Richard Moore <rich@kde.org>
3  1998 Stephan Kulow <coolo@kde.org>
4  1998 Daniel Grana <grana@ie.iwi.unibe.ch>
5  1999,2000,2001,2002,2003 Carsten Pfeiffer <pfeiffer@kde.org>
6  2003 Clarence Dang <dang@kde.org>
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 */
23 
24 #include "tdefiledialog.h"
25 
26 #include <unistd.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 
30 #include <tqptrcollection.h>
31 #include <tqcheckbox.h>
32 #include <tqcombobox.h>
33 #include <tqlabel.h>
34 #include <tqlayout.h>
35 #include <tqlineedit.h>
36 #include <tqptrlist.h>
37 #include <tqpixmap.h>
38 #include <tqtextcodec.h>
39 #include <tqtooltip.h>
40 #include <tqtimer.h>
41 #include <tqwhatsthis.h>
42 #include <tqfiledialog.h>
43 
44 #include <tdeaccel.h>
45 #include <tdeaction.h>
46 #include <tdeapplication.h>
47 #include <kcharsets.h>
48 #include <tdecmdlineargs.h>
49 #include <tdecompletionbox.h>
50 #include <tdeconfig.h>
51 #include <kdebug.h>
52 #include <tdeglobal.h>
53 #include <tdeglobalsettings.h>
54 #include <kiconloader.h>
55 #include <kimageio.h>
56 #include <tdeio/job.h>
57 #include <tdeio/netaccess.h>
58 #include <tdeio/scheduler.h>
59 #include <tdeio/kservicetypefactory.h>
60 #include <tdelocale.h>
61 #include <tdemessagebox.h>
62 #include <kmimetype.h>
63 #include <tdepopupmenu.h>
64 #include <kprotocolinfo.h>
65 #include <kpushbutton.h>
66 #include <tderecentdirs.h>
67 #include <kshell.h>
68 #include <kstandarddirs.h>
69 #include <kstdguiitem.h>
70 #include <kstaticdeleter.h>
71 #include <tdetoolbar.h>
72 #include <tdetoolbarbutton.h>
73 #include <kurl.h>
74 #include <kurlcombobox.h>
75 #include <kurlcompletion.h>
76 #include <kuser.h>
77 
78 #include "config-tdefile.h"
79 #include "kpreviewwidgetbase.h"
80 
81 #include <kdirselectdialog.h>
82 #include <tdefileview.h>
83 #include <tderecentdocument.h>
84 #include <tdefilefiltercombo.h>
85 #include <tdediroperator.h>
86 #include <kimagefilepreview.h>
87 
88 #include <tdefilespeedbar.h>
89 #include <tdefilebookmarkhandler.h>
90 
91 #ifdef Q_WS_X11
92 #include <X11/Xlib.h>
93 #include <fixx11h.h>
94 #endif
95 
96 enum Buttons { HOTLIST_BUTTON,
97  PATH_COMBO, CONFIGURE_BUTTON };
98 
99 template class TQPtrList<TDEIO::StatJob>;
100 
101 namespace {
102  static void silenceQToolBar(TQtMsgType, const char *)
103  {
104  }
105 }
106 
107 struct KFileDialogPrivate
108 {
109  // the last selected url
110  KURL url;
111 
112  // the selected filenames in multiselection mode -- FIXME
113  TQString filenames;
114 
115  // the name of the filename set by setSelection
116  TQString selection;
117 
118  // now following all kind of widgets, that I need to rebuild
119  // the geometry management
120  TQBoxLayout *boxLayout;
121  TQWidget *mainWidget;
122 
123  TQLabel *locationLabel;
124 
125  // @deprecated remove in KDE4
126  TQLabel *filterLabel;
127  KURLComboBox *pathCombo;
128  KPushButton *okButton, *cancelButton;
129  KFileSpeedBar *urlBar;
130  TQHBoxLayout *urlBarLayout;
131  TQWidget *customWidget;
132 
133  // Automatically Select Extension stuff
134  TQCheckBox *autoSelectExtCheckBox;
135  bool autoSelectExtChecked; // whether or not the _user_ has checked the above box
136  TQString extension; // current extension for this filter
137 
138  TQPtrList<TDEIO::StatJob> statJobs;
139 
140  KURL::List urlList; //the list of selected urls
141 
142  TQStringList mimetypes; //the list of possible mimetypes to save as
143 
144  // indicates if the location edit should be kept or cleared when changing
145  // directories
146  bool keepLocation :1;
147 
148  // the KDirOperators view is set in KFileDialog::show(), so to avoid
149  // setting it again and again, we have this nice little boolean :)
150  bool hasView :1;
151 
152  bool hasDefaultFilter :1; // necessary for the operationMode
153  KFileDialog::OperationMode operationMode;
154 
155  // The file class used for TDERecentDirs
156  TQString fileClass;
157 
158  KFileBookmarkHandler *bookmarkHandler;
159 
160  // the ID of the path drop down so subclasses can place their custom widgets properly
161  int m_pathComboIndex;
162 };
163 
164 KURL *KFileDialog::lastDirectory; // to set the start path
165 
166 static KStaticDeleter<KURL> ldd;
167 
168 KFileDialog::KFileDialog(const TQString& startDir, const TQString& filter,
169  TQWidget *parent, const char* name, bool modal)
170  : KDialogBase( parent, name, modal, TQString::null, 0 )
171 {
172  init( startDir, filter, 0 );
173 }
174 
175 KFileDialog::KFileDialog(const TQString& startDir, const TQString& filter,
176  TQWidget *parent, const char* name, bool modal, TQWidget* widget)
177  : KDialogBase( parent, name, modal, TQString::null, 0 )
178 {
179  init( startDir, filter, widget );
180 }
181 
182 
183 KFileDialog::~KFileDialog()
184 {
185  hide();
186 
187  TDEConfig *config = TDEGlobal::config();
188 
189  if (d->urlBar)
190  d->urlBar->save( config );
191 
192  config->sync();
193 
194  delete d->bookmarkHandler; // Should be deleted before ops!
195  delete ops;
196  delete d;
197 }
198 
199 void KFileDialog::setLocationLabel(const TQString& text)
200 {
201  d->locationLabel->setText(text);
202 }
203 
204 void KFileDialog::setFilter(const TQString& filter)
205 {
206  int pos = filter.find('/');
207 
208  // Check for an un-escaped '/', if found
209  // interpret as a MIME filter.
210 
211  if (pos > 0 && filter[pos - 1] != '\\') {
212  TQStringList filters = TQStringList::split( " ", filter );
213  setMimeFilter( filters );
214  return;
215  }
216 
217  // Strip the escape characters from
218  // escaped '/' characters.
219 
220  TQString copy (filter);
221  for (pos = 0; (pos = copy.find("\\/", pos)) != -1; ++pos)
222  copy.remove(pos, 1);
223 
224  ops->clearFilter();
225  filterWidget->setFilter(copy);
226  ops->setNameFilter(filterWidget->currentFilter());
227  d->hasDefaultFilter = false;
228  filterWidget->setEditable( true );
229 
230  updateAutoSelectExtension ();
231 }
232 
233 TQString KFileDialog::currentFilter() const
234 {
235  return filterWidget->currentFilter();
236 }
237 
238 // deprecated
239 void KFileDialog::setFilterMimeType(const TQString &label,
240  const KMimeType::List &types,
241  const KMimeType::Ptr &defaultType)
242 {
243  d->mimetypes.clear();
244  d->filterLabel->setText(label);
245 
246  KMimeType::List::ConstIterator it;
247  for( it = types.begin(); it != types.end(); ++it)
248  d->mimetypes.append( (*it)->name() );
249 
250  setMimeFilter( d->mimetypes, defaultType->name() );
251 }
252 
253 void KFileDialog::setMimeFilter( const TQStringList& mimeTypes,
254  const TQString& defaultType )
255 {
256  d->mimetypes = mimeTypes;
257  filterWidget->setMimeFilter( mimeTypes, defaultType );
258 
259  TQStringList types = TQStringList::split(" ", filterWidget->currentFilter());
260  types.append( TQString::fromLatin1( "inode/directory" ));
261  ops->clearFilter();
262  ops->setMimeFilter( types );
263  d->hasDefaultFilter = !defaultType.isEmpty();
264  filterWidget->setEditable( !d->hasDefaultFilter ||
265  d->operationMode != Saving );
266 
267  updateAutoSelectExtension ();
268 }
269 
270 void KFileDialog::clearFilter()
271 {
272  d->mimetypes.clear();
273  filterWidget->setFilter( TQString::null );
274  ops->clearFilter();
275  d->hasDefaultFilter = false;
276  filterWidget->setEditable( true );
277 
278  updateAutoSelectExtension ();
279 }
280 
281 TQString KFileDialog::currentMimeFilter() const
282 {
283  int i = filterWidget->currentItem();
284  if (filterWidget->showsAllTypes())
285  i--;
286 
287  if ((i >= 0) && (i < (int) d->mimetypes.count()))
288  return d->mimetypes[i];
289  return TQString::null; // The "all types" item has no mimetype
290 }
291 
292 KMimeType::Ptr KFileDialog::currentFilterMimeType()
293 {
294  return KMimeType::mimeType( currentMimeFilter() );
295 }
296 
297 void KFileDialog::setPreviewWidget(const TQWidget *w) {
298  ops->setPreviewWidget(w);
299  ops->clearHistory();
300  d->hasView = true;
301 }
302 
303 void KFileDialog::setPreviewWidget(const KPreviewWidgetBase *w) {
304  ops->setPreviewWidget(w);
305  ops->clearHistory();
306  d->hasView = true;
307 }
308 
309 KURL KFileDialog::getCompleteURL(const TQString &_url)
310 {
311  TQString url = KShell::tildeExpand(_url);
312  KURL u;
313 
314  if ( KURL::isRelativeURL(url) ) // only a full URL isn't relative. Even /path is.
315  {
316  if (!url.isEmpty() && !TQDir::isRelativePath(url) ) // absolute path
317  u.setPath( url );
318  else
319  {
320  u = ops->url();
321  u.addPath( url ); // works for filenames and relative paths
322  u.cleanPath(); // fix "dir/.."
323  }
324  }
325  else // complete URL
326  u = url;
327 
328  return u;
329 }
330 
331 // FIXME: check for "existing" flag here?
332 void KFileDialog::slotOk()
333 {
334  kdDebug(tdefile_area) << "slotOK\n";
335 
336  if (locationEdit->lineEdit()->edited())
337  {
338  enterURL(d->pathCombo->lineEdit()->text());
339  }
340  // a list of all selected files/directories (if any)
341  // can only be used if the user didn't type any filenames/urls himself
342  const KFileItemList *items = ops->selectedItems();
343 
344  if ( (mode() & KFile::Directory) != KFile::Directory ) {
345  if ( locationEdit->currentText().stripWhiteSpace().isEmpty() ) {
346  if ( !items || items->isEmpty() )
347  {
348  TQString msg;
349  if ( d->operationMode == Saving )
350  msg = i18n("Please specify the filename to save to.");
351  else
352  msg = i18n("Please select the file to open.");
353  KMessageBox::information(this, msg);
354  return;
355  }
356 
357  // weird case: the location edit is empty, but there are
358  // highlighted files
359  else {
360 
361  bool multi = (mode() & KFile::Files) != 0;
362  KFileItemListIterator it( *items );
363  TQString endQuote = TQString::fromLatin1("\" ");
364  TQString name, files;
365  while ( it.current() ) {
366  name = (*it)->name();
367  if ( multi ) {
368  name.prepend( '"' );
369  name.append( endQuote );
370  }
371 
372  files.append( name );
373  ++it;
374  }
375  setLocationText( files );
376  return;
377  }
378  }
379  }
380 
381  bool dirOnly = ops->dirOnlyMode();
382 
383  // we can use our tdefileitems, no need to parse anything
384  if ( items && !locationEdit->lineEdit()->edited() &&
385  !(items->isEmpty() && !dirOnly) ) {
386 
387  d->urlList.clear();
388  d->filenames = TQString::null;
389 
390  if ( dirOnly ) {
391  d->url = ops->url();
392  }
393  else {
394  if ( !(mode() & KFile::Files) ) {// single selection
395  d->url = items->getFirst()->url();
396  }
397 
398  else { // multi (dirs and/or files)
399  d->url = ops->url();
400  KFileItemListIterator it( *items );
401  while ( it.current() ) {
402  d->urlList.append( (*it)->url() );
403  ++it;
404  }
405  }
406  }
407 
408  KURL url = TDEIO::NetAccess::mostLocalURL(d->url,topLevelWidget());
409  if ( (mode() & KFile::LocalOnly) == KFile::LocalOnly &&
410  !url.isLocalFile() ) {
411 // ### after message freeze, add message for directories!
412  KMessageBox::sorry( d->mainWidget,
413  i18n("You can only select local files."),
414  i18n("Remote Files Not Accepted") );
415  return;
416  }
417 
418  d->url = url;
419  accept();
420  return;
421  }
422 
423 
424  KURL selectedURL;
425 
426  if ( (mode() & KFile::Files) == KFile::Files ) {// multiselection mode
427  TQString locationText = locationEdit->currentText();
428  if ( locationText.contains( '/' )) {
429  // relative path? -> prepend the current directory
430  KURL u( ops->url(), KShell::tildeExpand(locationText));
431  if ( u.isValid() )
432  selectedURL = u;
433  else
434  selectedURL = ops->url();
435  }
436  else // simple filename -> just use the current URL
437  selectedURL = ops->url();
438  }
439 
440  else {
441  selectedURL = getCompleteURL(locationEdit->currentText());
442 
443  // appendExtension() may change selectedURL
444  appendExtension (selectedURL);
445  }
446 
447  if ( !selectedURL.isValid() ) {
448  KMessageBox::sorry( d->mainWidget, i18n("%1\ndoes not appear to be a valid URL.\n").arg(d->url.url()), i18n("Invalid URL") );
449  return;
450  }
451 
452  KURL url = TDEIO::NetAccess::mostLocalURL(selectedURL,topLevelWidget());
453  if ( (mode() & KFile::LocalOnly) == KFile::LocalOnly &&
454  !url.isLocalFile() ) {
455  KMessageBox::sorry( d->mainWidget,
456  i18n("You can only select local files."),
457  i18n("Remote Files Not Accepted") );
458  return;
459  }
460 
461  d->url = url;
462 
463  // d->url is a correct URL now
464 
465  if ( (mode() & KFile::Directory) == KFile::Directory ) {
466  kdDebug(tdefile_area) << "Directory" << endl;
467  bool done = true;
468  if ( d->url.isLocalFile() ) {
469  if ( locationEdit->currentText().stripWhiteSpace().isEmpty() ) {
470  TQFileInfo info( d->url.path() );
471  if ( info.isDir() ) {
472  d->filenames = TQString::null;
473  d->urlList.clear();
474  d->urlList.append( d->url );
475  accept();
476  }
477  else if (!info.exists() && (mode() & KFile::File) != KFile::File) {
478  // directory doesn't exist, create and enter it
479  if ( ops->mkdir( d->url.url(), true ))
480  return;
481  else
482  accept();
483  }
484  else { // d->url is not a directory,
485  // maybe we are in File(s) | Directory mode
486  if ( (mode() & KFile::File) == KFile::File ||
487  (mode() & KFile::Files) == KFile::Files )
488  done = false;
489  }
490  }
491  else // Directory mode, with file[s]/dir[s] selected
492  {
493  if ( mode() & KFile::ExistingOnly )
494  {
495  if ( ops->dirOnlyMode() )
496  {
497  KURL fullURL(d->url, locationEdit->currentText());
498  if ( TQFile::exists( fullURL.path() ) )
499  {
500  d->url = fullURL;
501  d->filenames = TQString::null;
502  d->urlList.clear();
503  accept();
504  return;
505  }
506  else // doesn't exist -> reject
507  return;
508  }
509  }
510 
511  d->filenames = locationEdit->currentText();
512  accept(); // what can we do?
513  }
514 
515  }
516  else { // FIXME: remote directory, should we allow that?
517 // tqDebug( "**** Selected remote directory: %s", d->url.url().latin1());
518  d->filenames = TQString::null;
519  d->urlList.clear();
520  d->urlList.append( d->url );
521 
522  if ( mode() & KFile::ExistingOnly )
523  done = false;
524  else
525  accept();
526  }
527 
528  if ( done )
529  return;
530  }
531 
532  if (!kapp->authorizeURLAction("open", KURL(), d->url))
533  {
534  TQString msg = TDEIO::buildErrorString(TDEIO::ERR_ACCESS_DENIED, d->url.prettyURL());
535  KMessageBox::error( d->mainWidget, msg);
536  return;
537  }
538 
539  TDEIO::StatJob *job = 0L;
540  d->statJobs.clear();
541  d->filenames = KShell::tildeExpand(locationEdit->currentText());
542 
543  if ( (mode() & KFile::Files) == KFile::Files &&
544  !locationEdit->currentText().contains( '/' )) {
545  kdDebug(tdefile_area) << "Files\n";
546  KURL::List list = parseSelectedURLs();
547  for ( KURL::List::ConstIterator it = list.begin();
548  it != list.end(); ++it )
549  {
550  if (!kapp->authorizeURLAction("open", KURL(), *it))
551  {
552  TQString msg = TDEIO::buildErrorString(TDEIO::ERR_ACCESS_DENIED, (*it).prettyURL());
553  KMessageBox::error( d->mainWidget, msg);
554  return;
555  }
556  }
557  for ( KURL::List::ConstIterator it = list.begin();
558  it != list.end(); ++it )
559  {
560  job = TDEIO::stat( *it, !(*it).isLocalFile() );
561  job->setWindow (topLevelWidget());
562  TDEIO::Scheduler::scheduleJob( job );
563  d->statJobs.append( job );
564  connect( job, TQT_SIGNAL( result(TDEIO::Job *) ),
565  TQT_SLOT( slotStatResult( TDEIO::Job *) ));
566  }
567  return;
568  }
569 
570  job = TDEIO::stat(d->url,!d->url.isLocalFile());
571  job->setWindow (topLevelWidget());
572  d->statJobs.append( job );
573  connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotStatResult(TDEIO::Job*)));
574 }
575 
576 
577 static bool isDirectory (const TDEIO::UDSEntry &t)
578 {
579  bool isDir = false;
580 
581  for (TDEIO::UDSEntry::ConstIterator it = t.begin();
582  it != t.end();
583  it++)
584  {
585  if ((*it).m_uds == TDEIO::UDS_FILE_TYPE)
586  {
587  isDir = S_ISDIR ((mode_t) ((*it).m_long));
588  break;
589  }
590  }
591 
592  return isDir;
593 }
594 
595 // FIXME : count all errors and show messagebox when d->statJobs.count() == 0
596 // in case of an error, we cancel the whole operation (clear d->statJobs and
597 // don't call accept)
598 void KFileDialog::slotStatResult(TDEIO::Job* job)
599 {
600  kdDebug(tdefile_area) << "slotStatResult" << endl;
601  TDEIO::StatJob *sJob = static_cast<TDEIO::StatJob *>( job );
602 
603  if ( !d->statJobs.removeRef( sJob ) ) {
604  return;
605  }
606 
607  int count = d->statJobs.count();
608 
609  // errors mean in general, the location is no directory ;/
610  // Can we be sure that it is exististant at all? (pfeiffer)
611  if (sJob->error() && count == 0 && !ops->dirOnlyMode())
612  {
613  accept();
614  return;
615  }
616 
617  TDEIO::UDSEntry t = sJob->statResult();
618  if (isDirectory (t))
619  {
620  if ( ops->dirOnlyMode() )
621  {
622  d->filenames = TQString::null;
623  d->urlList.clear();
624  accept();
625  }
626  else // in File[s] mode, directory means error -> cd into it
627  {
628  if ( count == 0 ) {
629  locationEdit->clearEdit();
630  locationEdit->lineEdit()->setEdited( false );
631  setURL( sJob->url() );
632  }
633  }
634  d->statJobs.clear();
635  return;
636  }
637  else if ( ops->dirOnlyMode() )
638  {
639  return; // ### error message?
640  }
641 
642  kdDebug(tdefile_area) << "filename " << sJob->url().url() << endl;
643 
644  if ( count == 0 )
645  accept();
646 }
647 
648 void KFileDialog::accept()
649 {
650  setResult( TQDialog::Accepted ); // parseSelectedURLs() checks that
651 
652  *lastDirectory = ops->url();
653  if (!d->fileClass.isEmpty())
654  TDERecentDirs::add(d->fileClass, ops->url().url());
655 
656  // clear the topmost item, we insert it as full path later on as item 1
657  locationEdit->changeItem( TQString::null, 0 );
658 
659  KURL::List list = selectedURLs();
660  TQValueListConstIterator<KURL> it = list.begin();
661  for ( ; it != list.end(); ++it ) {
662  const KURL& url = *it;
663  // we strip the last slash (-1) because KURLComboBox does that as well
664  // when operating in file-mode. If we wouldn't , dupe-finding wouldn't
665  // work.
666  TQString file = url.isLocalFile() ? url.path(-1) : url.prettyURL(-1);
667 
668  // remove dupes
669  for ( int i = 1; i < locationEdit->count(); i++ ) {
670  if ( locationEdit->text( i ) == file ) {
671  locationEdit->removeItem( i-- );
672  break;
673  }
674  }
675  locationEdit->insertItem( file, 1 );
676  }
677 
678  TDEConfig *config = TDEGlobal::config();
679  config->setForceGlobal( true );
680  writeConfig( config, ConfigGroup );
681  config->setForceGlobal( false );
682 
683  saveRecentFiles( config );
684  config->sync();
685 
686  KDialogBase::accept();
687 
688  addToRecentDocuments();
689 
690  if ( (mode() & KFile::Files) != KFile::Files ) // single selection
691  emit fileSelected(d->url.url());
692 
693  ops->close();
694  emit okClicked();
695 }
696 
697 
698 void KFileDialog::fileHighlighted(const KFileItem *i)
699 {
700  if (i && i->isDir())
701  return;
702 
703 
704  if ( (ops->mode() & KFile::Files) != KFile::Files ) {
705  if ( !i )
706  return;
707 
708  d->url = i->url();
709 
710  if ( !locationEdit->hasFocus() ) { // don't disturb while editing
711  setLocationText( i->name() );
712  }
713  emit fileHighlighted(d->url.url());
714  }
715 
716  else {
717  multiSelectionChanged();
718  emit selectionChanged();
719  }
720 }
721 
722 void KFileDialog::fileSelected(const KFileItem *i)
723 {
724  if (i && i->isDir())
725  return;
726 
727  if ( (ops->mode() & KFile::Files) != KFile::Files ) {
728  if ( !i )
729  return;
730 
731  d->url = i->url();
732  setLocationText( i->name() );
733  }
734  else {
735  multiSelectionChanged();
736  emit selectionChanged();
737  }
738  slotOk();
739 }
740 
741 
742 // I know it's slow to always iterate thru the whole filelist
743 // (ops->selectedItems()), but what can we do?
744 void KFileDialog::multiSelectionChanged()
745 {
746  if ( locationEdit->hasFocus() ) // don't disturb
747  return;
748 
749  locationEdit->lineEdit()->setEdited( false );
750  KFileItem *item;
751  const KFileItemList *list = ops->selectedItems();
752  if ( !list ) {
753  locationEdit->clearEdit();
754  return;
755  }
756 
757  static const TQString &begin = TDEGlobal::staticQString(" \"");
758  KFileItemListIterator it ( *list );
759  TQString text;
760  while ( (item = it.current()) ) {
761  text.append( begin ).append( item->name() ).append( '\"' );
762  ++it;
763  }
764 
765  setLocationText( text.stripWhiteSpace() );
766 }
767 
768 void KFileDialog::setLocationText( const TQString& text )
769 {
770  // setCurrentItem() will cause textChanged() being emitted,
771  // so slotLocationChanged() will be called. Make sure we don't clear
772  // the KDirOperator's view-selection in there
773  disconnect( locationEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
774  this, TQT_SLOT( slotLocationChanged( const TQString& ) ) );
775  locationEdit->setCurrentItem( 0 );
776  connect( locationEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
777  TQT_SLOT( slotLocationChanged( const TQString& )) );
778  locationEdit->setEditText( text );
779 
780  // don't change selection when user has clicked on an item
781  if ( d->operationMode == Saving && !locationEdit->isVisible())
782  setNonExtSelection();
783 }
784 
785 static const char autocompletionWhatsThisText[] = I18N_NOOP("<p>While typing in the text area, you may be presented "
786  "with possible matches. "
787  "This feature can be controlled by clicking with the right mouse button "
788  "and selecting a preferred mode from the <b>Text Completion</b> menu.") "</qt>";
789 void KFileDialog::updateLocationWhatsThis (void)
790 {
791  TQString whatsThisText;
792  if (d->operationMode == KFileDialog::Saving)
793  {
794  whatsThisText = "<qt>" + i18n("This is the name to save the file as.") +
795  i18n (autocompletionWhatsThisText);
796  }
797  else if (ops->mode() & KFile::Files)
798  {
799  whatsThisText = "<qt>" + i18n("This is the list of files to open. More than "
800  "one file can be specified by listing several "
801  "files, separated by spaces.") +
802  i18n (autocompletionWhatsThisText);
803  }
804  else
805  {
806  whatsThisText = "<qt>" + i18n("This is the name of the file to open.") +
807  i18n (autocompletionWhatsThisText);
808  }
809 
810  TQWhatsThis::add(d->locationLabel, whatsThisText);
811  TQWhatsThis::add(locationEdit, whatsThisText);
812 }
813 
814 void KFileDialog::init(const TQString& startDir, const TQString& filter, TQWidget* widget)
815 {
816  initStatic();
817  d = new KFileDialogPrivate();
818 
819  d->boxLayout = 0;
820  d->keepLocation = false;
821  d->operationMode = Opening;
822  d->bookmarkHandler = 0;
823  d->hasDefaultFilter = false;
824  d->hasView = false;
825  d->mainWidget = new TQWidget( this, "KFileDialog::mainWidget");
826  setMainWidget( d->mainWidget );
827  d->okButton = new KPushButton( KStdGuiItem::ok(), d->mainWidget );
828  d->okButton->setDefault( true );
829  d->cancelButton = new KPushButton(KStdGuiItem::cancel(), d->mainWidget);
830  connect( d->okButton, TQT_SIGNAL( clicked() ), TQT_SLOT( slotOk() ));
831  connect( d->cancelButton, TQT_SIGNAL( clicked() ), TQT_SLOT( slotCancel() ));
832  d->customWidget = widget;
833  d->autoSelectExtCheckBox = 0; // delayed loading
834  d->autoSelectExtChecked = false;
835  d->urlBar = 0; // delayed loading
836 
837  TQtMsgHandler oldHandler = tqInstallMsgHandler( silenceQToolBar );
838  toolbar = new TDEToolBar( d->mainWidget, "KFileDialog::toolbar", true);
839  toolbar->setFlat(true);
840  tqInstallMsgHandler( oldHandler );
841 
842  d->pathCombo = new KURLComboBox( KURLComboBox::Directories, true,
843  toolbar, "path combo" );
844  TQToolTip::add( d->pathCombo, i18n("Current location") );
845  TQWhatsThis::add( d->pathCombo, "<qt>" + i18n("This is the currently listed location. "
846  "The drop-down list also lists commonly used locations. "
847  "This includes standard locations, such as your home folder, as well as "
848  "locations that have been visited recently.") + i18n (autocompletionWhatsThisText));
849 
850  KURL u;
851  u.setPath( TQDir::rootDirPath() );
852  TQString text = i18n("Root Folder: %1").arg( u.path() );
853  d->pathCombo->addDefaultURL( u,
854  KMimeType::pixmapForURL( u, 0, TDEIcon::Small ),
855  text );
856 
857  u.setPath( TQDir::homeDirPath() );
858  text = i18n("Home Folder: %1").arg( u.path( +1 ) );
859  d->pathCombo->addDefaultURL( u, KMimeType::pixmapForURL( u, 0, TDEIcon::Small ),
860  text );
861 
862  KURL docPath;
863  docPath.setPath( TDEGlobalSettings::documentPath() );
864  if ( (u.path(+1) != docPath.path(+1)) &&
865  TQDir(docPath.path(+1)).exists() )
866  {
867  text = i18n("Documents: %1").arg( docPath.path( +1 ) );
868  d->pathCombo->addDefaultURL( docPath,
869  KMimeType::pixmapForURL( docPath, 0, TDEIcon::Small ),
870  text );
871  }
872 
873  u.setPath( TDEGlobalSettings::desktopPath() );
874  text = i18n("Desktop: %1").arg( u.path( +1 ) );
875  d->pathCombo->addDefaultURL( u,
876  KMimeType::pixmapForURL( u, 0, TDEIcon::Small ),
877  text );
878 
879  d->url = getStartURL( startDir, d->fileClass );
880  d->selection = d->url.url();
881 
882  // If local, check it exists. If not, go up until it exists.
883  if ( d->url.isLocalFile() )
884  {
885  if ( !TQFile::exists( d->url.path() ) )
886  {
887  d->url = d->url.upURL();
888  TQDir dir( d->url.path() );
889  while ( !dir.exists() )
890  {
891  d->url = d->url.upURL();
892  dir.setPath( d->url.path() );
893  }
894  }
895  }
896 
897  ops = new KDirOperator(d->url, d->mainWidget, "KFileDialog::ops");
898  ops->setOnlyDoubleClickSelectsFiles( true );
899  connect(ops, TQT_SIGNAL(urlEntered(const KURL&)),
900  TQT_SLOT(urlEntered(const KURL&)));
901  connect(ops, TQT_SIGNAL(fileHighlighted(const KFileItem *)),
902  TQT_SLOT(fileHighlighted(const KFileItem *)));
903  connect(ops, TQT_SIGNAL(fileSelected(const KFileItem *)),
904  TQT_SLOT(fileSelected(const KFileItem *)));
905  connect(ops, TQT_SIGNAL(finishedLoading()),
906  TQT_SLOT(slotLoadingFinished()));
907 
908  ops->setupMenu(KDirOperator::SortActions |
909  KDirOperator::FileActions |
910  KDirOperator::ViewActions);
911  TDEActionCollection *coll = ops->actionCollection();
912 
913  // plug nav items into the toolbar
914  coll->action( "up" )->plug( toolbar );
915  coll->action( "up" )->setWhatsThis(i18n("<qt>Click this button to enter the parent folder.<p>"
916  "For instance, if the current location is file:/home/%1 clicking this "
917  "button will take you to file:/home.</qt>").arg( KUser().loginName() ));
918  coll->action( "back" )->plug( toolbar );
919  coll->action( "back" )->setWhatsThis(i18n("Click this button to move backwards one step in the browsing history."));
920  coll->action( "forward" )->plug( toolbar );
921  coll->action( "forward" )->setWhatsThis(i18n("Click this button to move forward one step in the browsing history."));
922  coll->action( "reload" )->plug( toolbar );
923  coll->action( "reload" )->setWhatsThis(i18n("Click this button to reload the contents of the current location."));
924  coll->action( "mkdir" )->setShortcut(Key_F10);
925  coll->action( "mkdir" )->plug( toolbar );
926  coll->action( "mkdir" )->setWhatsThis(i18n("Click this button to create a new folder."));
927 
928  TDEToggleAction *showSidebarAction =
929  new TDEToggleAction(i18n("Show Quick Access Navigation Panel"), Key_F9, coll,"toggleSpeedbar");
930  showSidebarAction->setCheckedState(i18n("Hide Quick Access Navigation Panel"));
931  connect( showSidebarAction, TQT_SIGNAL( toggled( bool ) ),
932  TQT_SLOT( toggleSpeedbar( bool )) );
933 
934  TDEToggleAction *showBookmarksAction =
935  new TDEToggleAction(i18n("Show Bookmarks"), 0, coll, "toggleBookmarks");
936  showBookmarksAction->setCheckedState(i18n("Hide Bookmarks"));
937  connect( showBookmarksAction, TQT_SIGNAL( toggled( bool ) ),
938  TQT_SLOT( toggleBookmarks( bool )) );
939 
940  TDEActionMenu *menu = new TDEActionMenu( i18n("Configure"), "configure", TQT_TQOBJECT(this), "extra menu" );
941  menu->setWhatsThis(i18n("<qt>This is the configuration menu for the file dialog. "
942  "Various options can be accessed from this menu including: <ul>"
943  "<li>how files are sorted in the list</li>"
944  "<li>types of view, including icon and list</li>"
945  "<li>showing of hidden files</li>"
946  "<li>the Quick Access navigation panel</li>"
947  "<li>file previews</li>"
948  "<li>separating folders from files</li></ul></qt>"));
949  menu->insert( coll->action( "sorting menu" ));
950  menu->insert( coll->action( "separator" ));
951  coll->action( "short view" )->setShortcut(Key_F6);
952  menu->insert( coll->action( "short view" ));
953  coll->action( "detailed view" )->setShortcut(Key_F7);
954  menu->insert( coll->action( "detailed view" ));
955  menu->insert( coll->action( "separator" ));
956  coll->action( "show hidden" )->setShortcut(Key_F8);
957  menu->insert( coll->action( "show hidden" ));
958  menu->insert( showSidebarAction );
959  menu->insert( showBookmarksAction );
960  coll->action( "preview" )->setShortcut(Key_F11);
961  menu->insert( coll->action( "preview" ));
962  coll->action( "separate dirs" )->setShortcut(Key_F12);
963  menu->insert( coll->action( "separate dirs" ));
964 
965  menu->setDelayed( false );
966  connect( menu->popupMenu(), TQT_SIGNAL( aboutToShow() ),
967  ops, TQT_SLOT( updateSelectionDependentActions() ));
968  menu->plug( toolbar );
969 
970  //Insert a separator.
971  TDEToolBarSeparator* spacerWidget = new TDEToolBarSeparator(Qt::Horizontal, false /*no line*/,
972  toolbar);
973  d->m_pathComboIndex = toolbar->insertWidget(-1, -1, spacerWidget);
974  toolbar->insertWidget(PATH_COMBO, 0, d->pathCombo);
975 
976 
977  toolbar->setItemAutoSized (PATH_COMBO);
978  toolbar->setIconText(TDEToolBar::IconOnly);
979  toolbar->setBarPos(TDEToolBar::Top);
980  toolbar->setMovingEnabled(false);
981  toolbar->adjustSize();
982 
983  KURLCompletion *pathCompletionObj = new KURLCompletion( KURLCompletion::DirCompletion );
984  d->pathCombo->setCompletionObject( pathCompletionObj );
985  d->pathCombo->setAutoDeleteCompletionObject( true );
986 
987  connect( d->pathCombo, TQT_SIGNAL( urlActivated( const KURL& )),
988  this, TQT_SLOT( enterURL( const KURL& ) ));
989  connect( d->pathCombo, TQT_SIGNAL( returnPressed( const TQString& )),
990  this, TQT_SLOT( enterURL( const TQString& ) ));
991  connect( d->pathCombo, TQT_SIGNAL( activated( const TQString& )),
992  this, TQT_SLOT( enterURL( const TQString& ) ));
993 
994  TQString whatsThisText;
995 
996  // the Location label/edit
997  d->locationLabel = new TQLabel(i18n("&Location:"), d->mainWidget);
998  locationEdit = new KURLComboBox(KURLComboBox::Files, true,
999  d->mainWidget, "LocationEdit");
1000  locationEdit->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed));
1001  connect( locationEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
1002  TQT_SLOT( slotLocationChanged( const TQString& )) );
1003 
1004  updateLocationWhatsThis ();
1005  d->locationLabel->setBuddy(locationEdit);
1006 
1007  locationEdit->setFocus();
1008  KURLCompletion *fileCompletionObj = new KURLCompletion( KURLCompletion::FileCompletion );
1009  TQString dir = d->url.url(+1);
1010  pathCompletionObj->setDir( dir );
1011  fileCompletionObj->setDir( dir );
1012  locationEdit->setCompletionObject( fileCompletionObj );
1013  locationEdit->setAutoDeleteCompletionObject( true );
1014  connect( fileCompletionObj, TQT_SIGNAL( match( const TQString& ) ),
1015  TQT_SLOT( fileCompletion( const TQString& )) );
1016 
1017  connect( locationEdit, TQT_SIGNAL( returnPressed() ),
1018  this, TQT_SLOT( slotOk()));
1019  connect(locationEdit, TQT_SIGNAL( activated( const TQString& )),
1020  this, TQT_SLOT( locationActivated( const TQString& ) ));
1021 
1022  // the Filter label/edit
1023  whatsThisText = i18n("<qt>This is the filter to apply to the file list. "
1024  "File names that do not match the filter will not be shown.<p>"
1025  "You may select from one of the preset filters in the "
1026  "drop down menu, or you may enter a custom filter "
1027  "directly into the text area.<p>"
1028  "Wildcards such as * and ? are allowed.</qt>");
1029  d->filterLabel = new TQLabel(i18n("&Filter:"), d->mainWidget);
1030  TQWhatsThis::add(d->filterLabel, whatsThisText);
1031  filterWidget = new KFileFilterCombo(d->mainWidget,
1032  "KFileDialog::filterwidget");
1033  filterWidget->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed));
1034  TQWhatsThis::add(filterWidget, whatsThisText);
1035  setFilter(filter);
1036  d->filterLabel->setBuddy(filterWidget);
1037  connect(filterWidget, TQT_SIGNAL(filterChanged()), TQT_SLOT(slotFilterChanged()));
1038 
1039  // the Automatically Select Extension checkbox
1040  // (the text, visibility etc. is set in updateAutoSelectExtension(), which is called by readConfig())
1041  d->autoSelectExtCheckBox = new TQCheckBox (d->mainWidget);
1042  connect(d->autoSelectExtCheckBox, TQT_SIGNAL(clicked()), TQT_SLOT(slotAutoSelectExtClicked()));
1043 
1044  initGUI(); // activate GM
1045 
1046  TDEConfig* config = TDEGlobal::config();
1047  readRecentFiles( config );
1048 
1049  adjustSize();
1050 
1051  ops->setViewConfig( config, ConfigGroup );
1052  readConfig( config, ConfigGroup );
1053  setSelection(d->selection);
1054 }
1055 
1056 void KFileDialog::initSpeedbar()
1057 {
1058  d->urlBar = new KFileSpeedBar( d->mainWidget, "url bar" );
1059  connect( d->urlBar, TQT_SIGNAL( activated( const KURL& )),
1060  TQT_SLOT( enterURL( const KURL& )) );
1061 
1062  // need to set the current url of the urlbar manually (not via urlEntered()
1063  // here, because the initial url of KDirOperator might be the same as the
1064  // one that will be set later (and then urlEntered() won't be emitted).
1065  // ### REMOVE THIS when KDirOperator's initial URL (in the c'tor) is gone.
1066  d->urlBar->setCurrentItem( d->url );
1067 
1068  d->urlBarLayout->insertWidget( 0, d->urlBar );
1069 }
1070 
1071 void KFileDialog::initGUI()
1072 {
1073  delete d->boxLayout; // deletes all sub layouts
1074 
1075  d->boxLayout = new TQVBoxLayout( d->mainWidget, 0, KDialog::spacingHint());
1076  d->boxLayout->addWidget(toolbar, AlignTop);
1077 
1078  d->urlBarLayout = new TQHBoxLayout( d->boxLayout ); // needed for the urlBar that may appear
1079  TQVBoxLayout *vbox = new TQVBoxLayout( d->urlBarLayout );
1080 
1081  vbox->addWidget(ops, 4);
1082  vbox->addSpacing(3);
1083 
1084  TQGridLayout* lafBox= new TQGridLayout(2, 3, KDialog::spacingHint());
1085 
1086  lafBox->addWidget(d->locationLabel, 0, 0, Qt::AlignVCenter);
1087  lafBox->addWidget(locationEdit, 0, 1, Qt::AlignVCenter);
1088  lafBox->addWidget(d->okButton, 0, 2, Qt::AlignVCenter);
1089 
1090  lafBox->addWidget(d->filterLabel, 1, 0, Qt::AlignVCenter);
1091  lafBox->addWidget(filterWidget, 1, 1, Qt::AlignVCenter);
1092  lafBox->addWidget(d->cancelButton, 1, 2, Qt::AlignVCenter);
1093 
1094  lafBox->setColStretch(1, 4);
1095 
1096  vbox->addLayout(TQT_TQLAYOUT(lafBox), 0);
1097  vbox->addSpacing(3);
1098 
1099  // add the Automatically Select Extension checkbox
1100  vbox->addWidget (d->autoSelectExtCheckBox);
1101  vbox->addSpacing (3);
1102 
1103  setTabOrder(ops, d->autoSelectExtCheckBox);
1104  setTabOrder (d->autoSelectExtCheckBox, locationEdit);
1105  setTabOrder(locationEdit, filterWidget);
1106  setTabOrder(filterWidget, d->okButton);
1107  setTabOrder(d->okButton, d->cancelButton);
1108  setTabOrder(d->cancelButton, d->pathCombo);
1109  setTabOrder(d->pathCombo, ops);
1110 
1111  // If a custom widget was specified...
1112  if ( d->customWidget != 0 )
1113  {
1114  // ...add it to the dialog, below the filter list box.
1115 
1116  // Change the parent so that this widget is a child of the main widget
1117  d->customWidget->reparent( d->mainWidget, TQPoint() );
1118 
1119  vbox->addWidget( d->customWidget );
1120  vbox->addSpacing(3);
1121 
1122  // FIXME: This should adjust the tab orders so that the custom widget
1123  // comes after the Cancel button. The code appears to do this, but the result
1124  // somehow screws up the tab order of the file path combo box. Not a major
1125  // problem, but ideally the tab order with a custom widget should be
1126  // the same as the order without one.
1127  setTabOrder(d->cancelButton, d->customWidget);
1128  setTabOrder(d->customWidget, d->pathCombo);
1129  }
1130  else
1131  {
1132  setTabOrder(d->cancelButton, d->pathCombo);
1133  }
1134 
1135  setTabOrder(d->pathCombo, ops);
1136 }
1137 
1138 void KFileDialog::slotFilterChanged()
1139 {
1140  TQString filter = filterWidget->currentFilter();
1141  ops->clearFilter();
1142 
1143  if ( filter.find( '/' ) > -1 ) {
1144  TQStringList types = TQStringList::split( " ", filter );
1145  types.prepend( "inode/directory" );
1146  ops->setMimeFilter( types );
1147  }
1148  else
1149  ops->setNameFilter( filter );
1150 
1151  ops->updateDir();
1152 
1153  updateAutoSelectExtension ();
1154 
1155  emit filterChanged( filter );
1156 }
1157 
1158 
1159 void KFileDialog::setURL(const KURL& url, bool clearforward)
1160 {
1161  d->selection = TQString::null;
1162  ops->setURL( url, clearforward);
1163 }
1164 
1165 // Protected
1166 void KFileDialog::urlEntered(const KURL& url)
1167 {
1168  TQString filename = locationEdit->currentText();
1169  d->selection = TQString::null;
1170 
1171  if ( d->pathCombo->count() != 0 ) { // little hack
1172  d->pathCombo->setURL( url );
1173  }
1174 
1175  locationEdit->blockSignals( true );
1176  locationEdit->setCurrentItem( 0 );
1177  if ( d->keepLocation )
1178  locationEdit->setEditText( filename );
1179 
1180  locationEdit->blockSignals( false );
1181 
1182  TQString dir = url.url(+1);
1183  static_cast<KURLCompletion*>( d->pathCombo->completionObject() )->setDir( dir );
1184  static_cast<KURLCompletion*>( locationEdit->completionObject() )->setDir( dir );
1185 
1186  if ( d->urlBar )
1187  d->urlBar->setCurrentItem( url );
1188 }
1189 
1190 void KFileDialog::locationActivated( const TQString& url )
1191 {
1192  // This guard prevents any URL _typed_ by the user from being interpreted
1193  // twice (by returnPressed/slotOk and here, activated/locationActivated)
1194  // after the user presses Enter. Without this, _both_ setSelection and
1195  // slotOk would "u.addPath( url )" ...so instead we leave it up to just
1196  // slotOk....
1197  if (!locationEdit->lineEdit()->edited())
1198  setSelection( url );
1199 }
1200 
1201 void KFileDialog::enterURL( const KURL& url)
1202 {
1203  setURL( url );
1204 }
1205 
1206 void KFileDialog::enterURL( const TQString& url )
1207 {
1208  setURL( KURL::fromPathOrURL( KURLCompletion::replacedPath( url, true, true )) );
1209 }
1210 
1211 void KFileDialog::toolbarCallback(int) // SLOT
1212 {
1213  /*
1214  * yes, nothing uses this anymore.
1215  * it used to be used to show the configure dialog
1216  */
1217 }
1218 
1219 
1220 void KFileDialog::setSelection(const TQString& url)
1221 {
1222  kdDebug(tdefile_area) << "setSelection " << url << endl;
1223 
1224  if (url.isEmpty()) {
1225  d->selection = TQString::null;
1226  return;
1227  }
1228 
1229  KURL u = getCompleteURL(url);
1230  if (!u.isValid()) { // if it still is
1231  kdWarning() << url << " is not a correct argument for setSelection!" << endl;
1232  return;
1233  }
1234 
1235  if (!KProtocolInfo::supportsListing(u)) {
1236  locationEdit->lineEdit()->setEdited( true );
1237  return;
1238  }
1239 
1240  /* we strip the first / from the path to avoid file://usr which means
1241  * / on host usr
1242  */
1243  KFileItem i(KFileItem::Unknown, KFileItem::Unknown, u, true );
1244  // KFileItem i(u.path());
1245  if ( i.isDir() && u.isLocalFile() && TQFile::exists( u.path() ) ) {
1246  // trust isDir() only if the file is
1247  // local (we cannot stat non-local urls) and if it exists!
1248  // (as KFileItem does not check if the file exists or not
1249  // -> the statbuffer is undefined -> isDir() is unreliable) (Simon)
1250  setURL(u, true);
1251  }
1252  else {
1253  TQString filename = u.url();
1254  int sep = filename.findRev('/');
1255  if (sep >= 0) { // there is a / in it
1256  if ( KProtocolInfo::supportsListing( u )) {
1257  KURL dir(u);
1258  dir.setQuery( TQString::null );
1259  dir.setFileName( TQString::null );
1260  setURL(dir, true );
1261  }
1262 
1263  // filename must be decoded, or "name with space" would become
1264  // "name%20with%20space", so we use KURL::fileName()
1265  filename = u.fileName();
1266  kdDebug(tdefile_area) << "filename " << filename << endl;
1267  d->selection = filename;
1268  setLocationText( filename );
1269 
1270  // tell the line edit that it has been edited
1271  // otherwise we won't know this was set by the user
1272  // and it will be ignored if there has been an
1273  // auto completion. this caused bugs where automcompletion
1274  // would start, the user would pick something from the
1275  // history and then hit Ok only to get the autocompleted
1276  // selection. OOOPS.
1277  locationEdit->lineEdit()->setEdited( true );
1278  }
1279 
1280  d->url = ops->url();
1281  d->url.addPath(filename);
1282  }
1283 }
1284 
1285 void KFileDialog::slotLoadingFinished()
1286 {
1287  if ( !d->selection.isNull() )
1288  ops->setCurrentItem( d->selection );
1289 }
1290 
1291 // ### remove in KDE4
1292 void KFileDialog::pathComboChanged( const TQString& )
1293 {
1294 }
1295 void KFileDialog::dirCompletion( const TQString& ) // SLOT
1296 {
1297 }
1298 void KFileDialog::fileCompletion( const TQString& match )
1299 {
1300  if ( match.isEmpty() && ops->view() )
1301  ops->view()->clearSelection();
1302  else
1303  ops->setCurrentItem( match );
1304 }
1305 
1306 void KFileDialog::slotLocationChanged( const TQString& text )
1307 {
1308  if ( text.isEmpty() && ops->view() )
1309  ops->view()->clearSelection();
1310 
1311  updateFilter();
1312 }
1313 
1314 void KFileDialog::updateStatusLine(int /* dirs */, int /* files */)
1315 {
1316  kdWarning() << "KFileDialog::updateStatusLine is deprecated! The status line no longer exists. Do not try and use it!" << endl;
1317 }
1318 
1319 TQString KFileDialog::getOpenFileName(const TQString& startDir,
1320  const TQString& filter,
1321  TQWidget *parent, const TQString& caption)
1322 {
1323  KFileDialog dlg(startDir, filter, parent, "filedialog", true);
1324  dlg.setOperationMode( Opening );
1325 
1326  dlg.setMode( KFile::File | KFile::LocalOnly );
1327  dlg.setCaption(caption.isNull() ? i18n("Open") : caption);
1328 
1329  dlg.ops->clearHistory();
1330  dlg.exec();
1331 
1332  return dlg.selectedFile();
1333 }
1334 
1335 TQString KFileDialog::getOpenFileNameWId(const TQString& startDir,
1336  const TQString& filter,
1337  WId parent_id, const TQString& caption)
1338 {
1339  TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
1340  KFileDialog dlg(startDir, filter, parent, "filedialog", true);
1341 #ifdef Q_WS_X11
1342  if( parent == NULL && parent_id != 0 )
1343  XSetTransientForHint( tqt_xdisplay(), dlg.winId(), parent_id );
1344 #else
1345  // TODO
1346 #endif
1347 
1348  dlg.setOperationMode( KFileDialog::Opening );
1349 
1350  dlg.setMode( KFile::File | KFile::LocalOnly );
1351  dlg.setCaption(caption.isNull() ? i18n("Open") : caption);
1352 
1353  dlg.ops->clearHistory();
1354  dlg.exec();
1355 
1356  return dlg.selectedFile();
1357 }
1358 
1359 TQStringList KFileDialog::getOpenFileNames(const TQString& startDir,
1360  const TQString& filter,
1361  TQWidget *parent,
1362  const TQString& caption)
1363 {
1364  KFileDialog dlg(startDir, filter, parent, "filedialog", true);
1365  dlg.setOperationMode( Opening );
1366 
1367  dlg.setCaption(caption.isNull() ? i18n("Open") : caption);
1368  dlg.setMode(KFile::Files | KFile::LocalOnly);
1369  dlg.ops->clearHistory();
1370  dlg.exec();
1371 
1372  return dlg.selectedFiles();
1373 }
1374 
1375 KURL KFileDialog::getOpenURL(const TQString& startDir, const TQString& filter,
1376  TQWidget *parent, const TQString& caption)
1377 {
1378  KFileDialog dlg(startDir, filter, parent, "filedialog", true);
1379  dlg.setOperationMode( Opening );
1380 
1381  dlg.setCaption(caption.isNull() ? i18n("Open") : caption);
1382  dlg.setMode( KFile::File );
1383  dlg.ops->clearHistory();
1384  dlg.exec();
1385 
1386  return dlg.selectedURL();
1387 }
1388 
1389 KURL::List KFileDialog::getOpenURLs(const TQString& startDir,
1390  const TQString& filter,
1391  TQWidget *parent,
1392  const TQString& caption)
1393 {
1394  KFileDialog dlg(startDir, filter, parent, "filedialog", true);
1395  dlg.setOperationMode( Opening );
1396 
1397  dlg.setCaption(caption.isNull() ? i18n("Open") : caption);
1398  dlg.setMode(KFile::Files);
1399  dlg.ops->clearHistory();
1400  dlg.exec();
1401 
1402  return dlg.selectedURLs();
1403 }
1404 
1405 KURL KFileDialog::getExistingURL(const TQString& startDir,
1406  TQWidget *parent,
1407  const TQString& caption)
1408 {
1409  return KDirSelectDialog::selectDirectory(startDir, false, parent, caption);
1410 }
1411 
1412 TQString KFileDialog::getExistingDirectory(const TQString& startDir,
1413  TQWidget *parent,
1414  const TQString& caption)
1415 {
1416 #ifdef Q_WS_WIN
1417  return TQFileDialog::getExistingDirectory(startDir, parent, "getExistingDirectory",
1418  caption, true, true);
1419 #else
1420  KURL url = KDirSelectDialog::selectDirectory(startDir, true, parent,
1421  caption);
1422  if ( url.isValid() )
1423  return url.path();
1424 
1425  return TQString::null;
1426 #endif
1427 }
1428 
1429 KURL KFileDialog::getImageOpenURL( const TQString& startDir, TQWidget *parent,
1430  const TQString& caption)
1431 {
1432  TQStringList mimetypes = KImageIO::mimeTypes( KImageIO::Reading );
1433  KFileDialog dlg(startDir,
1434  mimetypes.join(" "),
1435  parent, "filedialog", true);
1436  dlg.setOperationMode( Opening );
1437  dlg.setCaption( caption.isNull() ? i18n("Open") : caption );
1438  dlg.setMode( KFile::File );
1439 
1440  KImageFilePreview *ip = new KImageFilePreview( &dlg );
1441  dlg.setPreviewWidget( ip );
1442  dlg.exec();
1443 
1444  return dlg.selectedURL();
1445 }
1446 
1447 KURL KFileDialog::selectedURL() const
1448 {
1449  if ( result() == TQDialog::Accepted )
1450  return d->url;
1451  else
1452  return KURL();
1453 }
1454 
1455 KURL::List KFileDialog::selectedURLs() const
1456 {
1457  KURL::List list;
1458  if ( result() == TQDialog::Accepted ) {
1459  if ( (ops->mode() & KFile::Files) == KFile::Files )
1460  list = parseSelectedURLs();
1461  else
1462  list.append( d->url );
1463  }
1464  return list;
1465 }
1466 
1467 
1468 KURL::List& KFileDialog::parseSelectedURLs() const
1469 {
1470  if ( d->filenames.isEmpty() ) {
1471  return d->urlList;
1472  }
1473 
1474  d->urlList.clear();
1475  if ( d->filenames.contains( '/' )) { // assume _one_ absolute filename
1476  static const TQString &prot = TDEGlobal::staticQString(":/");
1477  KURL u;
1478  if ( d->filenames.find( prot ) != -1 )
1479  u = d->filenames;
1480  else
1481  u.setPath( d->filenames );
1482 
1483  if ( u.isValid() )
1484  d->urlList.append( u );
1485  else
1486  KMessageBox::error( d->mainWidget,
1487  i18n("The chosen filenames do not\n"
1488  "appear to be valid."),
1489  i18n("Invalid Filenames") );
1490  }
1491 
1492  else
1493  d->urlList = tokenize( d->filenames );
1494 
1495  d->filenames = TQString::null; // indicate that we parsed that one
1496 
1497  return d->urlList;
1498 }
1499 
1500 
1501 // FIXME: current implementation drawback: a filename can't contain quotes
1502 KURL::List KFileDialog::tokenize( const TQString& line ) const
1503 {
1504  KURL::List urls;
1505  KURL u( ops->url() );
1506  TQString name;
1507 
1508  int count = line.contains( '"' );
1509  if ( count == 0 ) { // no " " -> assume one single file
1510  u.setFileName( line );
1511  if ( u.isValid() )
1512  urls.append( u );
1513 
1514  return urls;
1515  }
1516 
1517  if ( (count % 2) == 1 ) { // odd number of " -> error
1518  TQWidget *that = const_cast<KFileDialog *>(this);
1519  KMessageBox::sorry(that, i18n("The requested filenames\n"
1520  "%1\n"
1521  "do not appear to be valid;\n"
1522  "make sure every filename is enclosed in double quotes.").arg(line),
1523  i18n("Filename Error"));
1524  return urls;
1525  }
1526 
1527  int start = 0;
1528  int index1 = -1, index2 = -1;
1529  while ( true ) {
1530  index1 = line.find( '"', start );
1531  index2 = line.find( '"', index1 + 1 );
1532 
1533  if ( index1 < 0 )
1534  break;
1535 
1536  // get everything between the " "
1537  name = line.mid( index1 + 1, index2 - index1 - 1 );
1538  u.setFileName( name );
1539  if ( u.isValid() )
1540  urls.append( u );
1541 
1542  start = index2 + 1;
1543  }
1544  return urls;
1545 }
1546 
1547 
1548 TQString KFileDialog::selectedFile() const
1549 {
1550  if ( result() == TQDialog::Accepted )
1551  {
1552  KURL url = TDEIO::NetAccess::mostLocalURL(d->url,topLevelWidget());
1553  if (url.isLocalFile())
1554  return url.path();
1555  else {
1556  KMessageBox::sorry( d->mainWidget,
1557  i18n("You can only select local files."),
1558  i18n("Remote Files Not Accepted") );
1559  }
1560  }
1561  return TQString::null;
1562 }
1563 
1564 TQStringList KFileDialog::selectedFiles() const
1565 {
1566  TQStringList list;
1567  KURL url;
1568 
1569  if ( result() == TQDialog::Accepted ) {
1570  if ( (ops->mode() & KFile::Files) == KFile::Files ) {
1571  KURL::List urls = parseSelectedURLs();
1572  TQValueListConstIterator<KURL> it = urls.begin();
1573  while ( it != urls.end() ) {
1574  url = TDEIO::NetAccess::mostLocalURL(*it,topLevelWidget());
1575  if ( url.isLocalFile() )
1576  list.append( url.path() );
1577  ++it;
1578  }
1579  }
1580 
1581  else { // single-selection mode
1582  if ( d->url.isLocalFile() )
1583  list.append( d->url.path() );
1584  }
1585  }
1586 
1587  return list;
1588 }
1589 
1590 KURL KFileDialog::baseURL() const
1591 {
1592  return ops->url();
1593 }
1594 
1595 TQString KFileDialog::getSaveFileName(const TQString& dir, const TQString& filter,
1596  TQWidget *parent,
1597  const TQString& caption)
1598 {
1599  bool specialDir = dir.at(0) == ':';
1600  KFileDialog dlg( specialDir ? dir : TQString::null, filter, parent, "filedialog", true);
1601  if ( !specialDir )
1602  dlg.setSelection( dir ); // may also be a filename
1603 
1604  dlg.setOperationMode( Saving );
1605  dlg.setCaption(caption.isNull() ? i18n("Save As") : caption);
1606 
1607  dlg.exec();
1608 
1609  TQString filename = dlg.selectedFile();
1610  if (!filename.isEmpty())
1611  TDERecentDocument::add(filename);
1612 
1613  return filename;
1614 }
1615 
1616 TQString KFileDialog::getSaveFileNameWId(const TQString& dir, const TQString& filter,
1617  WId parent_id,
1618  const TQString& caption)
1619 {
1620  bool specialDir = dir.at(0) == ':';
1621  TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
1622  KFileDialog dlg( specialDir ? dir : TQString::null, filter, parent, "filedialog", true);
1623 #ifdef Q_WS_X11
1624  if( parent == NULL && parent_id != 0 )
1625  XSetTransientForHint(tqt_xdisplay(), dlg.winId(), parent_id);
1626 #else
1627  // TODO
1628 #endif
1629 
1630  if ( !specialDir )
1631  dlg.setSelection( dir ); // may also be a filename
1632 
1633  dlg.setOperationMode( KFileDialog::Saving);
1634  dlg.setCaption(caption.isNull() ? i18n("Save As") : caption);
1635 
1636  dlg.exec();
1637 
1638  TQString filename = dlg.selectedFile();
1639  if (!filename.isEmpty())
1640  TDERecentDocument::add(filename);
1641 
1642  return filename;
1643 }
1644 
1645 KURL KFileDialog::getSaveURL(const TQString& dir, const TQString& filter,
1646  TQWidget *parent, const TQString& caption)
1647 {
1648  bool specialDir = dir.at(0) == ':';
1649  KFileDialog dlg(specialDir ? dir : TQString::null, filter, parent, "filedialog", true);
1650  if ( !specialDir )
1651  dlg.setSelection( dir ); // may also be a filename
1652 
1653  dlg.setCaption(caption.isNull() ? i18n("Save As") : caption);
1654  dlg.setOperationMode( Saving );
1655 
1656  dlg.exec();
1657 
1658  KURL url = dlg.selectedURL();
1659  if (url.isValid())
1660  TDERecentDocument::add( url );
1661 
1662  return url;
1663 }
1664 
1665 void KFileDialog::show()
1666 {
1667  if ( !d->hasView ) { // delayed view-creation
1668  ops->setView(KFile::Default);
1669  ops->clearHistory();
1670  d->hasView = true;
1671  }
1672 
1673  KDialogBase::show();
1674 }
1675 
1676 void KFileDialog::setMode( KFile::Mode m )
1677 {
1678  ops->setMode(m);
1679  if ( ops->dirOnlyMode() ) {
1680  filterWidget->setDefaultFilter( i18n("*|All Folders") );
1681  }
1682  else {
1683  filterWidget->setDefaultFilter( i18n("*|All Files") );
1684  }
1685 
1686  updateAutoSelectExtension ();
1687 }
1688 
1689 void KFileDialog::setMode( unsigned int m )
1690 {
1691  setMode(static_cast<KFile::Mode>( m ));
1692 }
1693 
1694 KFile::Mode KFileDialog::mode() const
1695 {
1696  return ops->mode();
1697 }
1698 
1699 
1700 void KFileDialog::readConfig( TDEConfig *kc, const TQString& group )
1701 {
1702  if ( !kc )
1703  return;
1704 
1705  TQString oldGroup = kc->group();
1706  if ( !group.isEmpty() )
1707  kc->setGroup( group );
1708 
1709  ops->readConfig( kc, group );
1710 
1711  KURLComboBox *combo = d->pathCombo;
1712  combo->setURLs( kc->readPathListEntry( RecentURLs ), KURLComboBox::RemoveTop );
1713  combo->setMaxItems( kc->readNumEntry( RecentURLsNumber,
1714  DefaultRecentURLsNumber ) );
1715  combo->setURL( ops->url() );
1716  autoDirectoryFollowing = kc->readBoolEntry( AutoDirectoryFollowing,
1717  DefaultDirectoryFollowing );
1718 
1719  TDEGlobalSettings::Completion cm = (TDEGlobalSettings::Completion)
1720  kc->readNumEntry( PathComboCompletionMode,
1721  TDEGlobalSettings::completionMode() );
1722  if ( cm != TDEGlobalSettings::completionMode() )
1723  combo->setCompletionMode( cm );
1724 
1725  cm = (TDEGlobalSettings::Completion)
1726  kc->readNumEntry( LocationComboCompletionMode,
1727  TDEGlobalSettings::completionMode() );
1728  if ( cm != TDEGlobalSettings::completionMode() )
1729  locationEdit->setCompletionMode( cm );
1730 
1731  // show or don't show the speedbar
1732  toggleSpeedbar( kc->readBoolEntry(ShowSpeedbar, true) );
1733 
1734  // show or don't show the bookmarks
1735  toggleBookmarks( kc->readBoolEntry(ShowBookmarks, false) );
1736 
1737  // does the user want Automatically Select Extension?
1738  d->autoSelectExtChecked = kc->readBoolEntry (AutoSelectExtChecked, DefaultAutoSelectExtChecked);
1739  updateAutoSelectExtension ();
1740 
1741  int w1 = minimumSize().width();
1742  int w2 = toolbar->sizeHint().width() + 10;
1743  if (w1 < w2)
1744  setMinimumWidth(w2);
1745 
1746  TQSize size = configDialogSize( group );
1747  resize( size );
1748  kc->setGroup( oldGroup );
1749 }
1750 
1751 void KFileDialog::writeConfig( TDEConfig *kc, const TQString& group )
1752 {
1753  if ( !kc )
1754  return;
1755 
1756  TQString oldGroup = kc->group();
1757  if ( !group.isEmpty() )
1758  kc->setGroup( group );
1759 
1760  kc->writePathEntry( RecentURLs, d->pathCombo->urls() );
1761  saveDialogSize( group, true );
1762  kc->writeEntry( PathComboCompletionMode, static_cast<int>(d->pathCombo->completionMode()) );
1763  kc->writeEntry( LocationComboCompletionMode, static_cast<int>(locationEdit->completionMode()) );
1764  kc->writeEntry( ShowSpeedbar, d->urlBar && !d->urlBar->isHidden() );
1765  kc->writeEntry( ShowBookmarks, d->bookmarkHandler != 0 );
1766  kc->writeEntry( AutoSelectExtChecked, d->autoSelectExtChecked );
1767 
1768  ops->writeConfig( kc, group );
1769  kc->setGroup( oldGroup );
1770 }
1771 
1772 
1773 void KFileDialog::readRecentFiles( TDEConfig *kc )
1774 {
1775  TQString oldGroup = kc->group();
1776  kc->setGroup( ConfigGroup );
1777 
1778  locationEdit->setMaxItems( kc->readNumEntry( RecentFilesNumber,
1779  DefaultRecentURLsNumber ) );
1780  locationEdit->setURLs( kc->readPathListEntry( RecentFiles ),
1781  KURLComboBox::RemoveBottom );
1782  locationEdit->insertItem( TQString::null, 0 ); // dummy item without pixmap
1783  locationEdit->setCurrentItem( 0 );
1784 
1785  kc->setGroup( oldGroup );
1786 }
1787 
1788 void KFileDialog::saveRecentFiles( TDEConfig *kc )
1789 {
1790  TQString oldGroup = kc->group();
1791  kc->setGroup( ConfigGroup );
1792 
1793  kc->writePathEntry( RecentFiles, locationEdit->urls() );
1794 
1795  kc->setGroup( oldGroup );
1796 }
1797 
1798 KPushButton * KFileDialog::okButton() const
1799 {
1800  return d->okButton;
1801 }
1802 
1803 KPushButton * KFileDialog::cancelButton() const
1804 {
1805  return d->cancelButton;
1806 }
1807 
1808 KURLBar * KFileDialog::speedBar()
1809 {
1810  return d->urlBar;
1811 }
1812 
1813 void KFileDialog::slotCancel()
1814 {
1815  ops->close();
1816  KDialogBase::slotCancel();
1817 
1818  TDEConfig *config = TDEGlobal::config();
1819  config->setForceGlobal( true );
1820  writeConfig( config, ConfigGroup );
1821  config->setForceGlobal( false );
1822 }
1823 
1824 void KFileDialog::setKeepLocation( bool keep )
1825 {
1826  d->keepLocation = keep;
1827 }
1828 
1829 bool KFileDialog::keepsLocation() const
1830 {
1831  return d->keepLocation;
1832 }
1833 
1834 void KFileDialog::setOperationMode( OperationMode mode )
1835 {
1836  d->operationMode = mode;
1837  d->keepLocation = (mode == Saving);
1838  filterWidget->setEditable( !d->hasDefaultFilter || mode != Saving );
1839  if ( mode == Opening )
1840  d->okButton->setGuiItem( KGuiItem( i18n("&Open"), "document-open") );
1841  else if ( mode == Saving ) {
1842  d->okButton->setGuiItem( KStdGuiItem::save() );
1843  setNonExtSelection();
1844  }
1845  else
1846  d->okButton->setGuiItem( KStdGuiItem::ok() );
1847  updateLocationWhatsThis ();
1848  updateAutoSelectExtension ();
1849 }
1850 
1851 KFileDialog::OperationMode KFileDialog::operationMode() const
1852 {
1853  return d->operationMode;
1854 }
1855 
1856 void KFileDialog::slotAutoSelectExtClicked()
1857 {
1858  kdDebug (tdefile_area) << "slotAutoSelectExtClicked(): "
1859  << d->autoSelectExtCheckBox->isChecked () << endl;
1860 
1861  // whether the _user_ wants it on/off
1862  d->autoSelectExtChecked = d->autoSelectExtCheckBox->isChecked ();
1863 
1864  // update the current filename's extension
1865  updateLocationEditExtension (d->extension /* extension hasn't changed */);
1866 }
1867 
1868 static TQString getExtensionFromPatternList (const TQStringList &patternList)
1869 {
1870  TQString ret;
1871  kdDebug (tdefile_area) << "\tgetExtension " << patternList << endl;
1872 
1873  TQStringList::ConstIterator patternListEnd = patternList.end ();
1874  for (TQStringList::ConstIterator it = patternList.begin ();
1875  it != patternListEnd;
1876  it++)
1877  {
1878  kdDebug (tdefile_area) << "\t\ttry: \'" << (*it) << "\'" << endl;
1879 
1880  // is this pattern like "*.BMP" rather than useless things like:
1881  //
1882  // README
1883  // *.
1884  // *.*
1885  // *.JP*G
1886  // *.JP?
1887  if ((*it).startsWith ("*.") &&
1888  (*it).length () > 2 &&
1889  (*it).find ('*', 2) < 0 && (*it).find ('?', 2) < 0)
1890  {
1891  ret = (*it).mid (1);
1892  break;
1893  }
1894  }
1895 
1896  return ret;
1897 }
1898 
1899 static TQString stripUndisplayable (const TQString &string)
1900 {
1901  TQString ret = string;
1902 
1903  ret.remove (':');
1904  ret.remove ('&');
1905 
1906  return ret;
1907 }
1908 
1909 
1910 TQString KFileDialog::currentFilterExtension (void)
1911 {
1912  return d->extension;
1913 }
1914 
1915 void KFileDialog::updateAutoSelectExtension (void)
1916 {
1917  if (!d->autoSelectExtCheckBox) return;
1918 
1919  //
1920  // Figure out an extension for the Automatically Select Extension thing
1921  // (some Windows users apparently don't know what to do when confronted
1922  // with a text file called "COPYING" but do know what to do with
1923  // COPYING.txt ...)
1924  //
1925 
1926  kdDebug (tdefile_area) << "Figure out an extension: " << endl;
1927  TQString lastExtension = d->extension;
1928  d->extension = TQString::null;
1929 
1930  // Automatically Select Extension is only valid if the user is _saving_ a _file_
1931  if ((operationMode () == Saving) && (mode () & KFile::File))
1932  {
1933  //
1934  // Get an extension from the filter
1935  //
1936 
1937  TQString filter = currentFilter ();
1938  if (!filter.isEmpty ())
1939  {
1940  // e.g. "*.cpp"
1941  if (filter.find ('/') < 0)
1942  {
1943  d->extension = getExtensionFromPatternList (TQStringList::split (" ", filter)).lower ();
1944  kdDebug (tdefile_area) << "\tsetFilter-style: pattern ext=\'"
1945  << d->extension << "\'" << endl;
1946  }
1947  // e.g. "text/html"
1948  else
1949  {
1950  KMimeType::Ptr mime = KMimeType::mimeType (filter);
1951 
1952  // first try X-TDE-NativeExtension
1953  TQString nativeExtension = mime->property ("X-TDE-NativeExtension").toString ();
1954  if (nativeExtension.at (0) == '.')
1955  {
1956  d->extension = nativeExtension.lower ();
1957  kdDebug (tdefile_area) << "\tsetMimeFilter-style: native ext=\'"
1958  << d->extension << "\'" << endl;
1959  }
1960 
1961  // no X-TDE-NativeExtension
1962  if (d->extension.isEmpty ())
1963  {
1964  d->extension = getExtensionFromPatternList (mime->patterns ()).lower ();
1965  kdDebug (tdefile_area) << "\tsetMimeFilter-style: pattern ext=\'"
1966  << d->extension << "\'" << endl;
1967  }
1968  }
1969  }
1970 
1971 
1972  //
1973  // GUI: checkbox
1974  //
1975 
1976  TQString whatsThisExtension;
1977  if (!d->extension.isEmpty ())
1978  {
1979  // remember: sync any changes to the string with below
1980  d->autoSelectExtCheckBox->setText (i18n ("Automatically select filename e&xtension (%1)").arg (d->extension));
1981  whatsThisExtension = i18n ("the extension <b>%1</b>").arg (d->extension);
1982 
1983  d->autoSelectExtCheckBox->setEnabled (true);
1984  d->autoSelectExtCheckBox->setChecked (d->autoSelectExtChecked);
1985  }
1986  else
1987  {
1988  // remember: sync any changes to the string with above
1989  d->autoSelectExtCheckBox->setText (i18n ("Automatically select filename e&xtension"));
1990  whatsThisExtension = i18n ("a suitable extension");
1991 
1992  d->autoSelectExtCheckBox->setChecked (false);
1993  d->autoSelectExtCheckBox->setEnabled (false);
1994  }
1995 
1996  const TQString locationLabelText = stripUndisplayable (d->locationLabel->text ());
1997  const TQString filterLabelText = stripUndisplayable (d->filterLabel->text ());
1998  TQWhatsThis::add (d->autoSelectExtCheckBox,
1999  "<qt>" +
2000  i18n (
2001  "This option enables some convenient features for "
2002  "saving files with extensions:<br>"
2003  "<ol>"
2004  "<li>Any extension specified in the <b>%1</b> text "
2005  "area will be updated if you change the file type "
2006  "to save in.<br>"
2007  "<br></li>"
2008  "<li>If no extension is specified in the <b>%2</b> "
2009  "text area when you click "
2010  "<b>Save</b>, %3 will be added to the end of the "
2011  "filename (if the filename does not already exist). "
2012  "This extension is based on the file type that you "
2013  "have chosen to save in.<br>"
2014  "<br>"
2015  "If you do not want TDE to supply an extension for the "
2016  "filename, you can either turn this option off or you "
2017  "can suppress it by adding a period (.) to the end of "
2018  "the filename (the period will be automatically "
2019  "removed)."
2020  "</li>"
2021  "</ol>"
2022  "If unsure, keep this option enabled as it makes your "
2023  "files more manageable."
2024  )
2025  .arg (locationLabelText)
2026  .arg (locationLabelText)
2027  .arg (whatsThisExtension)
2028  + "</qt>"
2029  );
2030 
2031  d->autoSelectExtCheckBox->show ();
2032 
2033 
2034  // update the current filename's extension
2035  updateLocationEditExtension (lastExtension);
2036  }
2037  // Automatically Select Extension not valid
2038  else
2039  {
2040  d->autoSelectExtCheckBox->setChecked (false);
2041  d->autoSelectExtCheckBox->hide ();
2042  }
2043 }
2044 
2045 // Updates the extension of the filename specified in locationEdit if the
2046 // Automatically Select Extension feature is enabled.
2047 // (this prevents you from accidently saving "file.kwd" as RTF, for example)
2048 void KFileDialog::updateLocationEditExtension (const TQString &lastExtension)
2049 {
2050  if (!d->autoSelectExtCheckBox->isChecked () || d->extension.isEmpty ())
2051  return;
2052 
2053  TQString urlStr = locationEdit->currentText ();
2054  if (urlStr.isEmpty ())
2055  return;
2056 
2057  KURL url = getCompleteURL (urlStr);
2058  kdDebug (tdefile_area) << "updateLocationEditExtension (" << url << ")" << endl;
2059 
2060  const int fileNameOffset = urlStr.findRev ('/') + 1;
2061  TQString fileName = urlStr.mid (fileNameOffset);
2062 
2063  const int dot = fileName.findRev ('.');
2064  const int len = fileName.length ();
2065  if (dot > 0 && // has an extension already and it's not a hidden file
2066  // like ".hidden" (but we do accept ".hidden.ext")
2067  dot != len - 1 // and not deliberately suppressing extension
2068  )
2069  {
2070  // exists?
2071  TDEIO::UDSEntry t;
2072  if (TDEIO::NetAccess::stat (url, t, topLevelWidget()))
2073  {
2074  kdDebug (tdefile_area) << "\tfile exists" << endl;
2075 
2076  if (isDirectory (t))
2077  {
2078  kdDebug (tdefile_area) << "\tisDir - won't alter extension" << endl;
2079  return;
2080  }
2081 
2082  // --- fall through ---
2083  }
2084 
2085 
2086  //
2087  // try to get rid of the current extension
2088  //
2089 
2090  // catch "double extensions" like ".tar.gz"
2091  if (lastExtension.length () && fileName.endsWith (lastExtension))
2092  fileName.truncate (len - lastExtension.length ());
2093  // can only handle "single extensions"
2094  else
2095  fileName.truncate (dot);
2096 
2097  // add extension
2098  const TQString newText = urlStr.left (fileNameOffset) + fileName + d->extension;
2099  if ( newText != locationEdit->currentText() )
2100  {
2101  locationEdit->setCurrentText (urlStr.left (fileNameOffset) + fileName + d->extension);
2102  locationEdit->lineEdit()->setEdited (true);
2103  }
2104  }
2105 }
2106 
2107 // Updates the filter if the extension of the filename specified in locationEdit is changed
2108 // (this prevents you from accidently saving "file.kwd" as RTF, for example)
2109 void KFileDialog::updateFilter ()
2110 {
2111  if ((operationMode() == Saving) && (mode() & KFile::File) ) {
2112  const TQString urlStr = locationEdit->currentText ();
2113  if (urlStr.isEmpty ())
2114  return;
2115 
2116  KMimeType::Ptr mime = KMimeType::findByPath(urlStr, 0, true);
2117  if (mime && mime->name() != KMimeType::defaultMimeType()) {
2118  if (filterWidget->currentFilter() != mime->name() &&
2119  filterWidget->filters.findIndex(mime->name()) != -1) {
2120  filterWidget->setCurrentFilter(mime->name());
2121  }
2122  }
2123  }
2124 }
2125 
2126 // applies only to a file that doesn't already exist
2127 void KFileDialog::appendExtension (KURL &url)
2128 {
2129  if (!d->autoSelectExtCheckBox->isChecked () || d->extension.isEmpty ())
2130  return;
2131 
2132  TQString fileName = url.fileName ();
2133  if (fileName.isEmpty ())
2134  return;
2135 
2136  kdDebug (tdefile_area) << "appendExtension(" << url << ")" << endl;
2137 
2138  const int len = fileName.length ();
2139  const int dot = fileName.findRev ('.');
2140 
2141  const bool suppressExtension = (dot == len - 1);
2142  const bool unspecifiedExtension = (dot <= 0);
2143 
2144  // don't TDEIO::NetAccess::Stat if unnecessary
2145  if (!(suppressExtension || unspecifiedExtension))
2146  return;
2147 
2148  // exists?
2149  TDEIO::UDSEntry t;
2150  if (TDEIO::NetAccess::stat (url, t, topLevelWidget()))
2151  {
2152  kdDebug (tdefile_area) << "\tfile exists - won't append extension" << endl;
2153  return;
2154  }
2155 
2156  // suppress automatically append extension?
2157  if (suppressExtension)
2158  {
2159  //
2160  // Strip trailing dot
2161  // This allows lazy people to have autoSelectExtCheckBox->isChecked
2162  // but don't want a file extension to be appended
2163  // e.g. "README." will make a file called "README"
2164  //
2165  // If you really want a name like "README.", then type "README.."
2166  // and the trailing dot will be removed (or just stop being lazy and
2167  // turn off this feature so that you can type "README.")
2168  //
2169  kdDebug (tdefile_area) << "\tstrip trailing dot" << endl;
2170  url.setFileName (fileName.left (len - 1));
2171  }
2172  // evilmatically append extension :) if the user hasn't specified one
2173  else if (unspecifiedExtension)
2174  {
2175  kdDebug (tdefile_area) << "\tappending extension \'" << d->extension << "\'..." << endl;
2176  url.setFileName (fileName + d->extension);
2177  kdDebug (tdefile_area) << "\tsaving as \'" << url << "\'" << endl;
2178  }
2179 }
2180 
2181 
2182 // adds the selected files/urls to 'recent documents'
2183 void KFileDialog::addToRecentDocuments()
2184 {
2185  int m = ops->mode();
2186 
2187  if ( m & KFile::LocalOnly ) {
2188  TQStringList files = selectedFiles();
2189  TQStringList::ConstIterator it = files.begin();
2190  for ( ; it != files.end(); ++it )
2191  TDERecentDocument::add( *it );
2192  }
2193 
2194  else { // urls
2195  KURL::List urls = selectedURLs();
2196  KURL::List::ConstIterator it = urls.begin();
2197  for ( ; it != urls.end(); ++it ) {
2198  if ( (*it).isValid() )
2199  TDERecentDocument::add( *it );
2200  }
2201  }
2202 }
2203 
2204 TDEActionCollection * KFileDialog::actionCollection() const
2205 {
2206  return ops->actionCollection();
2207 }
2208 
2209 void KFileDialog::keyPressEvent( TQKeyEvent *e )
2210 {
2211  if ( e->key() == Key_Escape )
2212  {
2213  e->accept();
2214  d->cancelButton->animateClick();
2215  }
2216  else
2217  KDialogBase::keyPressEvent( e );
2218 }
2219 
2220 void KFileDialog::toggleSpeedbar( bool show )
2221 {
2222  if ( show )
2223  {
2224  if ( !d->urlBar )
2225  initSpeedbar();
2226 
2227  d->urlBar->show();
2228 
2229  // check to see if they have a home item defined, if not show the home button
2230  KURLBarItem *urlItem = static_cast<KURLBarItem*>( d->urlBar->listBox()->firstItem() );
2231  KURL homeURL;
2232  homeURL.setPath( TQDir::homeDirPath() );
2233  while ( urlItem )
2234  {
2235  if ( homeURL.equals( urlItem->url(), true ) )
2236  {
2237  ops->actionCollection()->action( "home" )->unplug( toolbar );
2238  break;
2239  }
2240 
2241  urlItem = static_cast<KURLBarItem*>( urlItem->next() );
2242  }
2243  }
2244  else
2245  {
2246  if (d->urlBar)
2247  d->urlBar->hide();
2248 
2249  if ( !ops->actionCollection()->action( "home" )->isPlugged( toolbar ) )
2250  ops->actionCollection()->action( "home" )->plug( toolbar, 3 );
2251  }
2252 
2253  static_cast<TDEToggleAction *>(actionCollection()->action("toggleSpeedbar"))->setChecked( show );
2254 }
2255 
2256 void KFileDialog::toggleBookmarks(bool show)
2257 {
2258  if (show)
2259  {
2260  if (d->bookmarkHandler)
2261  {
2262  return;
2263  }
2264 
2265  d->bookmarkHandler = new KFileBookmarkHandler( this );
2266  connect( d->bookmarkHandler, TQT_SIGNAL( openURL( const TQString& )),
2267  TQT_SLOT( enterURL( const TQString& )));
2268 
2269  toolbar->insertButton(TQString::fromLatin1("bookmark"),
2270  (int)HOTLIST_BUTTON, true,
2271  i18n("Bookmarks"), 5);
2272  toolbar->getButton(HOTLIST_BUTTON)->setPopup(d->bookmarkHandler->menu(),
2273  true);
2274  TQWhatsThis::add(toolbar->getButton(HOTLIST_BUTTON),
2275  i18n("<qt>This button allows you to bookmark specific locations. "
2276  "Click on this button to open the bookmark menu where you may add, "
2277  "edit or select a bookmark.<p>"
2278  "These bookmarks are specific to the file dialog, but otherwise operate "
2279  "like bookmarks elsewhere in TDE.</qt>"));
2280  }
2281  else if (d->bookmarkHandler)
2282  {
2283  delete d->bookmarkHandler;
2284  d->bookmarkHandler = 0;
2285  toolbar->removeItem(HOTLIST_BUTTON);
2286  }
2287 
2288  static_cast<TDEToggleAction *>(actionCollection()->action("toggleBookmarks"))->setChecked( show );
2289 }
2290 
2291 int KFileDialog::pathComboIndex()
2292 {
2293  return d->m_pathComboIndex;
2294 }
2295 
2296 // static
2297 void KFileDialog::initStatic()
2298 {
2299  if ( lastDirectory )
2300  return;
2301 
2302  lastDirectory = ldd.setObject(lastDirectory, new KURL());
2303 }
2304 
2305 // static
2306 KURL KFileDialog::getStartURL( const TQString& startDir,
2307  TQString& recentDirClass )
2308 {
2309  initStatic();
2310 
2311  recentDirClass = TQString::null;
2312  KURL ret;
2313 
2314  bool useDefaultStartDir = startDir.isEmpty();
2315  if ( !useDefaultStartDir )
2316  {
2317  if (startDir[0] == ':')
2318  {
2319  recentDirClass = startDir;
2320  ret = KURL::fromPathOrURL( TDERecentDirs::dir(recentDirClass) );
2321  }
2322  else
2323  {
2324  ret = TDECmdLineArgs::makeURL( TQFile::encodeName(startDir) );
2325  // If we won't be able to list it (e.g. http), then use default
2326  if ( !KProtocolInfo::supportsListing( ret ) )
2327  useDefaultStartDir = true;
2328  }
2329  }
2330 
2331  if ( useDefaultStartDir )
2332  {
2333  if (lastDirectory->isEmpty()) {
2334  lastDirectory->setPath(TDEGlobalSettings::documentPath());
2335  KURL home;
2336  home.setPath( TQDir::homeDirPath() );
2337  // if there is no docpath set (== home dir), we prefer the current
2338  // directory over it. We also prefer the homedir when our CWD is
2339  // different from our homedirectory or when the document dir
2340  // does not exist
2341  if ( lastDirectory->path(+1) == home.path(+1) ||
2342  TQDir::currentDirPath() != TQDir::homeDirPath() ||
2343  !TQDir(lastDirectory->path(+1)).exists() )
2344  lastDirectory->setPath(TQDir::currentDirPath());
2345  }
2346  ret = *lastDirectory;
2347  }
2348 
2349  return ret;
2350 }
2351 
2352 void KFileDialog::setStartDir( const KURL& directory )
2353 {
2354  initStatic();
2355  if ( directory.isValid() )
2356  *lastDirectory = directory;
2357 }
2358 
2359 void KFileDialog::setNonExtSelection()
2360 {
2361  // Enhanced rename: Don't highlight the file extension.
2362  TQString pattern, filename = locationEdit->currentText().stripWhiteSpace();
2363  KServiceTypeFactory::self()->findFromPattern( filename, &pattern );
2364 
2365  if ( !pattern.isEmpty() && pattern.at( 0 ) == '*' && pattern.find( '*' , 1 ) == -1 )
2366  locationEdit->lineEdit()->setSelection( 0, filename.length() - pattern.stripWhiteSpace().length()+1 );
2367  else
2368  {
2369  int lastDot = filename.findRev( '.' );
2370  if ( lastDot > 0 )
2371  locationEdit->lineEdit()->setSelection( 0, lastDot );
2372  }
2373 }
2374 
2375 void KFileDialog::virtual_hook( int id, void* data )
2376 { KDialogBase::virtual_hook( id, data ); }
2377 
2378 
2379 #include "tdefiledialog.moc"
KFileDialog::setMimeFilter
void setMimeFilter(const TQStringList &types, const TQString &defaultType=TQString::null)
Sets the filter up to specify the output type.
Definition: tdefiledialog.cpp:253
TDERecentDirs::dir
static TQString dir(const TQString &fileClass)
Returns the most recently used directory accociated with this file-class.
Definition: tderecentdirs.cpp:80
KFileDialog::getSaveURL
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...
Definition: tdefiledialog.cpp:1645
KFileDialog::currentMimeFilter
TQString currentMimeFilter() const
The mimetype for the desired output format.
Definition: tdefiledialog.cpp:281
KURLComboBox
This combobox shows a number of recent URLs/directories, as well as some default directories.
Definition: kurlcombobox.h:41
KURLBarItem::url
const KURL & url() const
returns the url of this item.
Definition: kurlbar.h:127
KFileDialog::keyPressEvent
virtual void keyPressEvent(TQKeyEvent *e)
Reimplemented to animate the cancel button.
Definition: tdefiledialog.cpp:2209
KFileDialog::setFilterMimeType
void setFilterMimeType(const TQString &label, const KMimeType::List &types, const KMimeType::Ptr &defaultType) KDE_DEPRECATED
Sets the filter up to specify the output type.
Definition: tdefiledialog.cpp:239
KDirOperator::close
void close()
Stops loading immediately.
Definition: tdediroperator.cpp:573
KDirOperator::setOnlyDoubleClickSelectsFiles
void setOnlyDoubleClickSelectsFiles(bool enable)
This is a KFileDialog specific hack: we want to select directories with single click, but not files.
Definition: tdediroperator.cpp:1567
KFileDialog::mode
KFile::Mode mode() const
Returns the mode of the filedialog.
Definition: tdefiledialog.cpp:1694
KDirOperator::selectedItems
const KFileItemList * selectedItems() const
Definition: tdediroperator.h:297
KDirOperator::view
KFileView * view() const
Definition: tdediroperator.h:226
KDirSelectDialog::selectDirectory
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.
Definition: kdirselectdialog.cpp:461
KURLComboBox::urls
TQStringList urls() const
Definition: kurlcombobox.cpp:81
KFileDialog::setPreviewWidget
void setPreviewWidget(const TQWidget *w) KDE_DEPRECATED
Definition: tdefiledialog.cpp:297
KFileDialog::~KFileDialog
~KFileDialog()
Destructs the file dialog.
Definition: tdefiledialog.cpp:183
KFileDialog::fileHighlighted
void fileHighlighted(const TQString &)
Emitted when the user highlights a file.
KDirOperator::readConfig
virtual void readConfig(TDEConfig *, const TQString &group=TQString::null)
Reads the default settings for a view, i.e.
Definition: tdediroperator.cpp:1442
KFileDialog::pathComboIndex
int pathComboIndex()
Definition: tdefiledialog.cpp:2291
KFileDialog::speedBar
KURLBar * speedBar()
Definition: tdefiledialog.cpp:1808
KFileDialog::dirCompletion
void dirCompletion(const TQString &)
Definition: tdefiledialog.cpp:1295
KFileDialog::init
void init(const TQString &startDir, const TQString &filter, TQWidget *widget)
Perform basic initialization tasks.
Definition: tdefiledialog.cpp:814
KFileDialog::currentFilterExtension
TQString currentFilterExtension()
Returns the filename extension associated with the currentFilter().
Definition: tdefiledialog.cpp:1910
KFileDialog::clearFilter
void clearFilter()
Clears any mime- or namefilter.
Definition: tdefiledialog.cpp:270
KFile::Mode
Mode
Modes of operation for the dialog.
Definition: tdefile.h:42
KFileDialog::getSaveFileName
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...
Definition: tdefiledialog.cpp:1595
KFileDialog::getOpenURL
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...
Definition: tdefiledialog.cpp:1375
KURLComboBox::setMaxItems
void setMaxItems(int)
Sets how many items should be handled and displayed by the combobox.
Definition: kurlcombobox.cpp:287
KFileDialog
Provides a user (and developer) friendly way to select files and directories.
Definition: tdefiledialog.h:76
KFileDialog::tokenize
KURL::List tokenize(const TQString &line) const
Parses the string "line" for files.
Definition: tdefiledialog.cpp:1502
KFileDialog::okButton
KPushButton * okButton() const
Definition: tdefiledialog.cpp:1798
KDirOperator::setViewConfig
void setViewConfig(TDEConfig *config, const TQString &group)
Sets the config object and the to be used group in KDirOperator.
Definition: tdediroperator.cpp:1721
KFileView::clearSelection
virtual void clearSelection()=0
Clears any selection, unhighlights everything.
KDirOperator::mkdir
bool mkdir(const TQString &directory, bool enterDirectory=true)
Creates the given directory/url.
Definition: tdediroperator.cpp:400
KDirOperator::setCurrentItem
void setCurrentItem(const TQString &filename)
Clears the current selection and attempts to set filename the current file.
Definition: tdediroperator.cpp:1191
KFileDialog::setURL
void setURL(const KURL &url, bool clearforward=true)
Sets the directory to view.
Definition: tdefiledialog.cpp:1159
KFileDialog::baseURL
KURL baseURL() const
Definition: tdefiledialog.cpp:1590
KDirOperator::setMode
void setMode(KFile::Mode m)
Sets the listing/selection mode for the views, an OR'ed combination of.
Definition: tdediroperator.cpp:1086
TDERecentDirs::add
static void add(const TQString &fileClass, const TQString &directory)
Associates directory with fileClass.
Definition: tderecentdirs.cpp:86
KFileDialog::initGUI
virtual void initGUI()
rebuild geometry management.
Definition: tdefiledialog.cpp:1071
KFileDialog::getStartURL
static KURL getStartURL(const TQString &startDir, TQString &recentDirClass)
This method implements the logic to determine the user's default directory to be listed.
Definition: tdefiledialog.cpp:2306
KFileDialog::KFileDialog
KFileDialog(const TQString &startDir, const TQString &filter, TQWidget *parent, const char *name, bool modal)
Constructs a file dialog.
Definition: tdefiledialog.cpp:168
KFileDialog::keepsLocation
bool keepsLocation() const
Definition: tdefiledialog.cpp:1829
KFileDialog::setKeepLocation
void setKeepLocation(bool keep)
Sets whether the filename/url should be kept when changing directories.
Definition: tdefiledialog.cpp:1824
KDirOperator
This widget works as a network transparent filebrowser.
Definition: tdediroperator.h:96
KFileDialog::selectedURL
KURL selectedURL() const
Definition: tdefiledialog.cpp:1447
KFileDialog::getCompleteURL
KURL getCompleteURL(const TQString &)
Returns the absolute version of the URL specified in locationEdit.
Definition: tdefiledialog.cpp:309
KURLBar
KURLBar is a widget that displays icons together with a description.
Definition: kurlbar.h:230
TDERecentDocument::add
static void add(const KURL &url)
Add a new item to the Recent Document menu.
Definition: tderecentdocument.cpp:75
KFileDialog::pathComboChanged
void pathComboChanged(const TQString &)
Definition: tdefiledialog.cpp:1292
KFileDialog::getOpenFileNameWId
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.
Definition: tdefiledialog.cpp:1335
KDirOperator::updateDir
void updateDir()
to update the view after changing the settings
Definition: tdediroperator.cpp:684
KFileDialog::updateStatusLine
virtual void updateStatusLine(int dirs, int files)
Definition: tdefiledialog.cpp:1314
KFileDialog::fileSelected
void fileSelected(const TQString &)
Emitted when the user selects a file.
KDirOperator::setNameFilter
void setNameFilter(const TQString &filter)
Sets a filter like "*.cpp *.h *.o".
Definition: tdediroperator.cpp:798
KFileDialog::getOpenURLs
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...
Definition: tdefiledialog.cpp:1389
KFileDialog::getExistingDirectory
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...
Definition: tdefiledialog.cpp:1412
KFileDialog::setOperationMode
void setOperationMode(KFileDialog::OperationMode)
Sets the operational mode of the filedialog to Saving, Opening or Other.
Definition: tdefiledialog.cpp:1834
KFileDialog::saveRecentFiles
virtual void saveRecentFiles(TDEConfig *)
Saves the entries from the location combobox.
Definition: tdefiledialog.cpp:1788
KFileDialog::selectedURLs
KURL::List selectedURLs() const
Definition: tdefiledialog.cpp:1455
KImageFilePreview
Image preview widget for the file dialog.
Definition: kimagefilepreview.h:31
KURLComboBox::setURL
void setURL(const KURL &url)
Sets the current url.
Definition: kurlcombobox.cpp:205
KFileDialog::getImageOpenURL
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...
Definition: tdefiledialog.cpp:1429
KFileDialog::writeConfig
virtual void writeConfig(TDEConfig *, const TQString &group=TQString::null)
Saves the current configuration.
Definition: tdefiledialog.cpp:1751
KFileDialog::currentFilterMimeType
KMimeType::Ptr currentFilterMimeType()
Returns the mimetype for the desired output format.
Definition: tdefiledialog.cpp:292
KFileDialog::OperationMode
OperationMode
Defines some default behavior of the filedialog.
Definition: tdefiledialog.h:93
KURLComboBox::setURLs
void setURLs(TQStringList urls)
Inserts urls into the combobox below the "default urls" (see addDefaultURL).
Definition: kurlcombobox.cpp:137
KDirOperator::setMimeFilter
void setMimeFilter(const TQStringList &mimetypes)
Sets a list of mimetypes as filter.
Definition: tdediroperator.cpp:804
KFileDialog::selectedFile
TQString selectedFile() const
Returns the full path of the selected file in the local filesystem.
Definition: tdefiledialog.cpp:1548
KDirOperator::setPreviewWidget
void setPreviewWidget(const TQWidget *w)
Sets a preview-widget to be shown next to the file-view.
Definition: tdediroperator.cpp:264
KFileDialog::toolbarCallback
void toolbarCallback(int)
Definition: tdefiledialog.cpp:1211
KFileDialog::selectionChanged
void selectionChanged()
Emitted when the user hilights one or more files in multiselection mode.
KDirOperator::clearFilter
void clearFilter()
Clears both the namefilter and mimetype filter, so that all files and directories will be shown...
Definition: tdediroperator.cpp:791
KDirOperator::clearHistory
void clearHistory()
Clears the forward and backward history.
Definition: tdediroperator.cpp:1628
KFileDialog::getExistingURL
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...
Definition: tdefiledialog.cpp:1405
KURLBarItem
An item to be used in KURLBar / KURLBarListBox.
Definition: kurlbar.h:42
KFileDialog::toggleSpeedbar
void toggleSpeedbar(bool)
Definition: tdefiledialog.cpp:2220
KFileDialog::toggleBookmarks
void toggleBookmarks(bool show)
Definition: tdefiledialog.cpp:2256
KFileDialog::setSelection
void setSelection(const TQString &name)
Sets the file name to preselect to name.
Definition: tdefiledialog.cpp:1220
KFileDialog::filterChanged
void filterChanged(const TQString &filter)
Emitted when the filter changed, i.e.
KDirOperator::dirOnlyMode
bool dirOnlyMode() const
Definition: tdediroperator.h:537
KPreviewWidgetBase
Abstract baseclass for all preview widgets which shall be used via KFileDialog::setPreviewWidget(cons...
Definition: kpreviewwidgetbase.h:44
KDirOperator::mode
KFile::Mode mode() const
Definition: tdediroperator.cpp:1081
KFileDialog::selectedFiles
TQStringList selectedFiles() const
Returns a list of all selected local files.
Definition: tdefiledialog.cpp:1564
KFileDialog::setMode
void setMode(KFile::Mode m)
Convenient overload of the other setMode(unsigned int) method.
Definition: tdefiledialog.cpp:1676
KFileDialog::multiSelectionChanged
void multiSelectionChanged()
called when an item is highlighted/selected in multiselection mode.
Definition: tdefiledialog.cpp:744
KFileDialog::setLocationLabel
void setLocationLabel(const TQString &text)
Sets the text to be displayed in front of the selection.
Definition: tdefiledialog.cpp:199
KDirOperator::setURL
void setURL(const KURL &url, bool clearforward)
Sets a new url to list.
Definition: tdediroperator.cpp:636
KFileDialog::currentFilter
TQString currentFilter() const
Returns the current filter as entered by the user or one of the predefined set via setFilter()...
Definition: tdefiledialog.cpp:233
KFileDialog::updateAutoSelectExtension
void updateAutoSelectExtension()
Updates the currentFilterExtension and the availability of the Automatically Select Extension Checkbo...
Definition: tdefiledialog.cpp:1915
KFileDialog::setFilter
void setFilter(const TQString &filter)
Sets the filter to be used to filter.
Definition: tdefiledialog.cpp:204
KDirOperator::setupMenu
void setupMenu(int whichActions)
Sets up the action menu.
Definition: tdediroperator.cpp:1360
KFileDialog::operationMode
OperationMode operationMode() const
Definition: tdefiledialog.cpp:1851
KFileDialog::readConfig
virtual void readConfig(TDEConfig *, const TQString &group=TQString::null)
Reads configuration and applies it (size, recent directories, ...)
Definition: tdefiledialog.cpp:1700
KFileDialog::actionCollection
TDEActionCollection * actionCollection() const
Definition: tdefiledialog.cpp:2204
KDirOperator::writeConfig
virtual void writeConfig(TDEConfig *, const TQString &group=TQString::null)
Saves the current settings like sorting, simple or detailed view.
Definition: tdediroperator.cpp:1498
KFileDialog::getOpenFileNames
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...
Definition: tdefiledialog.cpp:1359
KDirOperator::url
KURL url() const
Definition: tdediroperator.cpp:772
KDirOperator::actionCollection
TDEActionCollection * actionCollection() const
an accessor to a collection of all available Actions.
Definition: tdediroperator.h:389
KDirOperator::setView
void setView(KFileView *view)
Sets a new KFileView to be used for showing and browsing files.
Definition: tdediroperator.cpp:1099
KFileDialog::getOpenFileName
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...
Definition: tdefiledialog.cpp:1319
KFileDialog::cancelButton
KPushButton * cancelButton() const
Definition: tdefiledialog.cpp:1803
KFileDialog::getSaveFileNameWId
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*.
Definition: tdefiledialog.cpp:1616
KFileDialog::readRecentFiles
virtual void readRecentFiles(TDEConfig *)
Reads the recent used files and inserts them into the location combobox.
Definition: tdefiledialog.cpp:1773

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdefile by doxygen 1.8.8
This website is maintained by Timothy Pearson.