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

tdeio/tdefile

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

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
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdefile by doxygen 1.8.13
This website is maintained by Timothy Pearson.