24 #include <tqapplication.h>
28 #include <tqpushbutton.h>
29 #include <tqpopupmenu.h>
34 #include <tdeaction.h>
35 #include <tdeapplication.h>
38 #include <kdialogbase.h>
39 #include <kdirlister.h>
40 #include <kinputdialog.h>
41 #include <tdelocale.h>
42 #include <tdemessagebox.h>
43 #include <tdepopupmenu.h>
44 #include <kprogress.h>
45 #include <kstdaction.h>
46 #include <tdeio/job.h>
47 #include <tdeio/jobclasses.h>
48 #include <tdeio/netaccess.h>
49 #include <tdeio/previewjob.h>
50 #include <tdeio/renamedlg.h>
51 #include <kpropertiesdialog.h>
52 #include <kservicetypefactory.h>
53 #include <tdestdaccel.h>
56 #include "config-tdefile.h"
57 #include "kcombiview.h"
58 #include "tdediroperator.h"
59 #include "tdefiledetailview.h"
60 #include "tdefileiconview.h"
61 #include "tdefilepreview.h"
62 #include "tdefileview.h"
63 #include "tdefileitem.h"
64 #include "tdefilemetapreview.h"
67 template class TQPtrStack<KURL>;
68 template class TQDict<KFileItem>;
71 class KDirOperator::KDirOperatorPrivate
74 KDirOperatorPrivate() {
75 onlyDoubleClickSelectsFiles =
false;
76 progressDelayTimer = 0L;
77 dirHighlighting =
false;
82 ~KDirOperatorPrivate() {
83 delete progressDelayTimer;
88 bool onlyDoubleClickSelectsFiles;
89 TQTimer *progressDelayTimer;
90 TDEActionSeparator *viewActionSeparator;
98 TQWidget *parent,
const char* _name)
99 : TQWidget(parent, _name),
105 myMode = KFile::File;
106 m_viewKind = KFile::Simple;
107 mySorting =
static_cast<TQDir::SortSpec
>(TQDir::Name | TQDir::DirsFirst);
108 d =
new KDirOperatorPrivate;
110 if (_url.isEmpty()) {
111 TQString strPath = TQDir::currentDirPath();
114 currUrl.setProtocol(TQString::fromLatin1(
"file"));
115 currUrl.setPath(strPath);
119 if ( currUrl.protocol().isEmpty() )
120 currUrl.setProtocol(TQString::fromLatin1(
"file"));
122 currUrl.addPath(
"/");
127 connect(&myCompletion, TQ_SIGNAL(match(
const TQString&)),
130 progress =
new KProgress(
this,
"progress");
131 progress->adjustSize();
132 progress->move(2, height() - progress->height() -2);
134 d->progressDelayTimer =
new TQTimer(
this,
"progress delay timer" );
135 connect( d->progressDelayTimer, TQ_SIGNAL( timeout() ),
136 TQ_SLOT( slotShowProgress() ));
138 myCompleteListDirty =
false;
140 backStack.setAutoDelete(
true );
141 forwardStack.setAutoDelete(
true );
147 setFocusPolicy(TQWidget::WheelFocus);
156 m_fileView->writeConfig( d->config, d->configGroup );
178 TQApplication::restoreOverrideCursor();
182 void KDirOperator::insertViewDependentActions()
190 if ( (viewActionMenu->popupMenu()->count() == 0) ||
193 if (viewActionCollection)
195 disconnect( viewActionCollection, TQ_SIGNAL( inserted( TDEAction * )),
196 this, TQ_SLOT( slotViewActionAdded( TDEAction * )));
197 disconnect( viewActionCollection, TQ_SIGNAL( removed( TDEAction * )),
198 this, TQ_SLOT( slotViewActionRemoved( TDEAction * )));
201 viewActionMenu->popupMenu()->clear();
205 viewActionMenu->insert( myActionCollection->action(
"short view" ) );
206 viewActionMenu->insert( myActionCollection->action(
"detailed view" ) );
207 viewActionMenu->insert( actionSeparator );
208 viewActionMenu->insert( showHiddenAction );
210 viewActionMenu->insert( separateDirsAction );
215 if (!viewActionCollection)
218 if ( !viewActionCollection->isEmpty() )
220 viewActionMenu->insert( d->viewActionSeparator );
223 TQStringList groups = viewActionCollection->groups();
224 groups.prepend( TQString::null );
225 TQStringList::ConstIterator git = groups.begin();
226 TDEActionPtrList list;
228 for ( ; git != groups.end(); ++git )
230 if ( git != groups.begin() )
231 viewActionMenu->insert( sep );
233 list = viewActionCollection->actions( *git );
234 TDEActionPtrList::ConstIterator it = list.begin();
235 for ( ; it != list.end(); ++it )
236 viewActionMenu->insert( *it );
240 connect( viewActionCollection, TQ_SIGNAL( inserted( TDEAction * )),
241 TQ_SLOT( slotViewActionAdded( TDEAction * )));
242 connect( viewActionCollection, TQ_SIGNAL( removed( TDEAction * )),
243 TQ_SLOT( slotViewActionRemoved( TDEAction * )));
252 actionMenu->popup( pos );
257 bool hasSelection = m_fileView && m_fileView->
selectedItems() &&
259 myActionCollection->action(
"trash" )->setEnabled( hasSelection );
260 myActionCollection->action(
"delete" )->setEnabled( hasSelection );
261 myActionCollection->action(
"properties" )->setEnabled( hasSelection );
267 m_viewKind = (m_viewKind | KFile::PreviewContents);
269 m_viewKind = (m_viewKind & ~
KFile::PreviewContents);
274 TDEToggleAction *preview =
static_cast<TDEToggleAction*
>(myActionCollection->action(
"preview"));
275 preview->setEnabled( w != 0L );
276 preview->setChecked( w != 0L );
277 setView(
static_cast<KFile::FileView
>(m_viewKind) );
282 return m_fileView ? m_fileView->
numDirs() : 0;
287 return m_fileView ? m_fileView->
numFiles() : 0;
290 void KDirOperator::slotDetailedView()
292 KFile::FileView
view =
static_cast<KFile::FileView
>( (m_viewKind & ~
KFile::Simple) | KFile::Detail );
296 void KDirOperator::slotSimpleView()
298 KFile::FileView
view =
static_cast<KFile::FileView
>( (m_viewKind & ~
KFile::Detail) | KFile::Simple );
302 void KDirOperator::slotToggleHidden(
bool show )
304 dir->setShowingDotFiles( show );
310 void KDirOperator::slotSeparateDirs()
312 if (separateDirsAction->isChecked())
314 KFile::FileView
view =
static_cast<KFile::FileView
>( m_viewKind | KFile::SeparateDirs );
319 KFile::FileView
view =
static_cast<KFile::FileView
>( m_viewKind & ~
KFile::SeparateDirs );
324 void KDirOperator::slotDefaultPreview()
326 m_viewKind = m_viewKind | KFile::PreviewContents;
328 myPreview =
new KFileMetaPreview(
this );
329 (
static_cast<TDEToggleAction*
>( myActionCollection->action(
"preview") ))->setChecked(
true);
332 setView(
static_cast<KFile::FileView
>(m_viewKind) );
335 void KDirOperator::slotSortByName()
339 mySorting = m_fileView->
sorting();
340 caseInsensitiveAction->setEnabled(
true );
343 void KDirOperator::slotSortBySize()
347 mySorting = m_fileView->
sorting();
348 caseInsensitiveAction->setEnabled(
false );
351 void KDirOperator::slotSortByDate()
355 mySorting = m_fileView->
sorting();
356 caseInsensitiveAction->setEnabled(
false );
359 void KDirOperator::slotSortReversed()
362 m_fileView->sortReversed();
365 void KDirOperator::slotToggleDirsFirst()
368 if ( !KFile::isSortDirsFirst(
sorting ) )
369 m_fileView->
setSorting(
static_cast<TQDir::SortSpec
>(
sorting | TQDir::DirsFirst ));
371 m_fileView->
setSorting(
static_cast<TQDir::SortSpec
>(
sorting & ~TQDir::DirsFirst));
372 mySorting = m_fileView->
sorting();
375 void KDirOperator::slotToggleIgnoreCase()
378 if ( !KFile::isSortCaseInsensitive(
sorting ) )
379 m_fileView->
setSorting(
static_cast<TQDir::SortSpec
>(
sorting | TQDir::IgnoreCase ));
381 m_fileView->
setSorting(
static_cast<TQDir::SortSpec
>(
sorting & ~TQDir::IgnoreCase));
382 mySorting = m_fileView->
sorting();
388 TQString where =
url().pathOrURL();
389 TQString name = i18n(
"New Folder" );
390 if (
url().isLocalFile() && TQFileInfo(
url().path(+1) + name ).exists() )
391 name = TDEIO::RenameDlg::suggestName(
url(), name );
393 TQString dir = KInputDialog::getText( i18n(
"New Folder" ),
394 i18n(
"Create new folder in:\n%1" ).arg( where ),
397 mkdir( TDEIO::encodeFileName( dir ),
true );
406 bool writeOk =
false;
410 TQStringList dirs = TQStringList::split( TQDir::separator(), directory );
411 TQStringList::ConstIterator it = dirs.begin();
413 for ( ; it != dirs.end(); ++it )
416 exists = TDEIO::NetAccess::exists(
url,
false, 0 );
417 writeOk = !exists && TDEIO::NetAccess::mkdir(
url, topLevelWidget() );
422 KMessageBox::sorry(
viewWidget(), i18n(
"A file or folder named %1 already exists.").arg(
url.pathOrURL()));
423 enterDirectory =
false;
425 else if ( !writeOk ) {
426 KMessageBox::sorry(
viewWidget(), i18n(
"You do not have permission to "
427 "create that folder." ));
429 else if ( enterDirectory ) {
437 bool ask,
bool showProgress )
439 return del( items,
this, ask, showProgress );
444 bool ask,
bool showProgress )
446 if ( items.isEmpty() ) {
447 KMessageBox::information( parent,
448 i18n(
"You did not select a file to delete."),
449 i18n(
"Nothing to Delete") );
455 KFileItemListIterator it( items );
457 for ( ; it.current(); ++it ) {
458 KURL
url = (*it)->url();
460 if (
url.isLocalFile() )
461 files.append(
url.path() );
463 files.append(
url.prettyURL() );
469 if ( items.count() == 1 ) {
470 ret = KMessageBox::warningContinueCancel( parent,
471 i18n(
"<qt>Do you really want to delete\n <b>'%1'</b>?</qt>" )
472 .arg( files.first() ),
474 KStdGuiItem::del(),
"AskForDelete" );
477 ret = KMessageBox::warningContinueCancelList( parent,
478 i18n(
"Do you really want to delete this item?",
"Do you really want to delete these %n items?", items.count() ),
480 i18n(
"Delete Files"),
481 KStdGuiItem::del(),
"AskForDelete" );
482 doIt = (ret == KMessageBox::Continue);
486 TDEIO::DeleteJob *job = TDEIO::del( urls,
false, showProgress );
487 job->setWindow (topLevelWidget());
488 job->setAutoErrorHandlingEnabled(
true, parent );
507 bool ask,
bool showProgress )
509 if ( items.isEmpty() ) {
510 KMessageBox::information( parent,
511 i18n(
"You did not select a file to trash."),
512 i18n(
"Nothing to Trash") );
518 KFileItemListIterator it( items );
520 for ( ; it.current(); ++it ) {
521 KURL
url = (*it)->url();
523 if (
url.isLocalFile() )
524 files.append(
url.path() );
526 files.append(
url.prettyURL() );
532 if ( items.count() == 1 ) {
533 ret = KMessageBox::warningContinueCancel( parent,
534 i18n(
"<qt>Do you really want to trash\n <b>'%1'</b>?</qt>" )
535 .arg( files.first() ),
537 KGuiItem(i18n(
"to trash",
"&Trash"),
"edittrash"),
"AskForTrash" );
540 ret = KMessageBox::warningContinueCancelList( parent,
541 i18n(
"translators: not called for n == 1",
"Do you really want to trash these %n items?", items.count() ),
544 KGuiItem(i18n(
"to trash",
"&Trash"),
"edittrash"),
"AskForTrash" );
545 doIt = (ret == KMessageBox::Continue);
549 TDEIO::CopyJob *job = TDEIO::trash( urls, showProgress );
550 job->setWindow (topLevelWidget());
551 job->setAutoErrorHandlingEnabled(
true, parent );
563 if ( reason == TDEAction::PopupMenuActivation && ( state & ShiftButton ) ) {
570 trash( *list,
this );
576 pendingMimeTypes.clear();
577 myCompletion.clear();
578 myDirCompletion.clear();
579 myCompleteListDirty =
true;
583 void KDirOperator::checkPath(
const TQString &,
bool )
587 TQString text = _txt;
590 text = text.stripWhiteSpace();
593 if (text.find(
':') < 0 && text[0] !=
'/')
594 text.insert(0, currUrl);
598 if (!selection.isNull()) {
599 int position = text.findRev(
'/');
600 ASSERT(position >= 0);
601 TQString filename = text.mid(position + 1, text.length());
602 if (filename != selection)
603 selection = TQString::null;
607 bool filenameEntered =
false;
609 if (u.isLocalFile()) {
611 KFileItem i(
"", u.path());
616 if (acceptOnlyExisting && !i.isFile())
617 warning(
"you entered an invalid URL");
619 filenameEntered =
true;
624 if (filenameEntered) {
626 emit fileSelected(filename_);
628 TQApplication::restoreOverrideCursor();
633 kdDebug(tdefile_area) <<
"TODO KDirOperator::checkPath()" << endl;
640 if ( !_newurl.isValid() )
641 newurl.setPath( TQDir::homeDirPath() );
645 TQString pathstr = newurl.path(+1);
646 newurl.setPath(pathstr);
649 if ( newurl.equals( currUrl,
true ) )
652 if ( !isReadable( newurl ) ) {
654 newurl.cd(TQString::fromLatin1(
".."));
655 if ( !isReadable( newurl ) ) {
658 i18n(
"The specified folder does not exist "
659 "or was not readable."));
666 backStack.push(
new KURL(currUrl));
667 forwardStack.clear();
670 d->lastURL = currUrl.url(-1);
674 emit urlEntered(newurl);
677 forwardAction->setEnabled( !forwardStack.isEmpty() );
678 backAction->setEnabled( !backStack.isEmpty() );
679 upAction->setEnabled( !
isRoot() );
694 openURL( currUrl,
false,
true );
698 bool KDirOperator::openURL(
const KURL& url,
bool keep,
bool reload )
700 bool result = dir->openURL(
url, keep, reload );
713 pendingMimeTypes.clear();
715 myCompletion.clear();
716 myDirCompletion.clear();
719 TQApplication::restoreOverrideCursor();
722 TQApplication::setOverrideCursor( TQt::waitCursor );
724 if ( !isReadable( currUrl )) {
726 i18n(
"The specified folder does not exist "
727 "or was not readable."));
728 if (backStack.isEmpty())
735 void KDirOperator::slotRedirected(
const KURL& newURL )
738 pendingMimeTypes.clear();
739 myCompletion.clear();
740 myDirCompletion.clear();
741 myCompleteListDirty =
true;
742 emit urlEntered( newURL );
748 if ( backStack.isEmpty() )
751 forwardStack.push(
new KURL(currUrl) );
753 KURL *s = backStack.pop();
762 if ( forwardStack.isEmpty() )
765 backStack.push(
new KURL(currUrl));
767 KURL *s = forwardStack.pop();
780 tmp.cd(TQString::fromLatin1(
".."));
787 u.setPath( TQDir::homeDirPath() );
793 dir->setNameFilter( TQString::null );
794 dir->clearMimeFilter();
800 dir->setNameFilter(filter);
806 dir->setMimeFilter( mimetypes );
812 TDEToggleAction *previewAction =
static_cast<TDEToggleAction*
>( myActionCollection->action(
"preview" ));
814 bool hasPreviewSupport =
false;
815 TDEConfig *kc = TDEGlobal::config();
816 TDEConfigGroupSaver cs( kc, ConfigGroup );
817 if ( kc->readBoolEntry(
"Show Default Preview",
true ) )
818 hasPreviewSupport = checkPreviewInternal();
820 previewAction->setEnabled( hasPreviewSupport );
821 return hasPreviewSupport;
824 bool KDirOperator::checkPreviewInternal()
const
826 TQStringList supported = TDEIO::PreviewJob::supportedMimeTypes();
828 if (
dirOnlyMode() && supported.findIndex(
"inode/directory" ) == -1 )
831 TQStringList mimeTypes = dir->mimeFilters();
832 TQStringList
nameFilter = TQStringList::split(
" ", dir->nameFilter() );
834 if ( mimeTypes.isEmpty() &&
nameFilter.isEmpty() && !supported.isEmpty() )
838 r.setWildcard(
true );
840 if ( !mimeTypes.isEmpty() ) {
841 TQStringList::Iterator it = supported.begin();
843 for ( ; it != supported.end(); ++it ) {
846 TQStringList result = mimeTypes.grep( r );
847 if ( !result.isEmpty() ) {
855 KServiceTypeFactory *fac = KServiceTypeFactory::self();
856 TQStringList::Iterator it1 =
nameFilter.begin();
858 if ( (*it1) ==
"*" ) {
862 KMimeType *mt = fac->findFromPattern( *it1 );
865 TQString mime = mt->name();
870 TQStringList::Iterator it2 = supported.begin();
871 for ( ; it2 != supported.end(); ++it2 ) {
872 r.setPattern( *it2 );
873 if ( r.search( mime ) != -1 ) {
887 bool separateDirs = KFile::isSeparateDirs(
view );
890 if ( separateDirs || preview ) {
894 combi =
new KCombiView( parent,
"combi view" );
899 if ( KFile::isSimpleView(
view ) )
918 else if ( KFile::isDetailView(
view ) && !preview ) {
928 new_view->
widget()->setAcceptDrops(acceptDrops());
935 m_fileView->
widget()->setAcceptDrops(b);
936 TQWidget::setAcceptDrops(b);
941 d->dropOptions = options;
948 bool separateDirs = KFile::isSeparateDirs(
view );
951 if (
view == KFile::Default) {
952 if ( KFile::isDetailView( (KFile::FileView) defaultView ) )
953 view = KFile::Detail;
955 view = KFile::Simple;
957 separateDirs = KFile::isSeparateDirs(
static_cast<KFile::FileView
>(defaultView) );
959 KFile::isPreviewContents(
static_cast<KFile::FileView
>(defaultView) ) )
960 && myActionCollection->action(
"preview")->isEnabled();
963 m_viewKind = defaultView;
964 slotDefaultPreview();
967 else if ( !separateDirs )
968 separateDirsAction->setChecked(
true);
972 if ( (
mode() & KFile::File) == 0 &&
973 (
mode() & KFile::Files) == 0 ) {
974 separateDirs =
false;
975 separateDirsAction->setEnabled(
false );
978 m_viewKind =
static_cast<int>(
view) | (separateDirs ? KFile::SeparateDirs : 0);
979 view =
static_cast<KFile::FileView
>(m_viewKind);
992 void KDirOperator::connectView(
KFileView *view)
995 pendingMimeTypes.clear();
999 view->setViewMode(KFileView::Directories);
1001 view->setViewMode(KFileView::All);
1003 if ( myMode & KFile::Files )
1004 view->setSelectionMode( KFile::Extended );
1006 view->setSelectionMode( KFile::Single );
1012 m_fileView->writeConfig( d->config, d->configGroup );
1013 view->readConfig( d->config, d->configGroup );
1021 if ( m_fileView->
widget()->hasFocus() )
1025 if ( oldCurrentItem ) {
1031 const KFileItemList *oldSelected = m_fileView->
selectedItems();
1032 if ( !oldSelected->isEmpty() ) {
1033 KFileItemListIterator it( *oldSelected );
1034 for ( ; it.current(); ++it )
1038 m_fileView->
widget()->hide();
1045 view->readConfig( d->config, d->configGroup );
1050 viewActionCollection = 0L;
1053 connect(sig, TQ_SIGNAL(
activatedMenu(
const KFileItem *,
const TQPoint& ) ),
1054 this, TQ_SLOT(
activatedMenu(
const KFileItem *,
const TQPoint& )));
1055 connect(sig, TQ_SIGNAL( dirActivated(
const KFileItem *) ),
1056 this, TQ_SLOT(
selectDir(
const KFileItem*) ) );
1057 connect(sig, TQ_SIGNAL( fileSelected(
const KFileItem *) ),
1058 this, TQ_SLOT(
selectFile(
const KFileItem*) ) );
1061 connect(sig, TQ_SIGNAL( sortingChanged( TQDir::SortSpec ) ),
1062 this, TQ_SLOT( slotViewSortingChanged( TQDir::SortSpec )));
1063 connect(sig, TQ_SIGNAL(
dropped(
const KFileItem *, TQDropEvent*,
const KURL::List&) ),
1064 this, TQ_SIGNAL(
dropped(
const KFileItem *, TQDropEvent*,
const KURL::List&)) );
1066 if ( reverseAction->isChecked() != m_fileView->
isReversed() )
1070 m_fileView->
widget()->resize(size());
1071 m_fileView->
widget()->show();
1074 TQApplication::setOverrideCursor( TQt::waitCursor );
1096 setView(
static_cast<KFile::FileView
>(m_viewKind) );
1101 if (
view == m_fileView ) {
1115 if ( lister == dir )
1121 dir->setAutoUpdate(
true );
1123 TQWidget* mainWidget = topLevelWidget();
1124 dir->setMainWindow (mainWidget);
1125 kdDebug (tdefile_area) <<
"mainWidget=" << mainWidget << endl;
1127 connect( dir, TQ_SIGNAL( percent(
int )),
1128 TQ_SLOT( slotProgress(
int ) ));
1129 connect( dir, TQ_SIGNAL(started(
const KURL& )), TQ_SLOT(slotStarted()));
1130 connect( dir, TQ_SIGNAL(newItems(
const KFileItemList &)),
1132 connect( dir, TQ_SIGNAL(completed()), TQ_SLOT(slotIOFinished()));
1133 connect( dir, TQ_SIGNAL(canceled()), TQ_SLOT(slotCanceled()));
1134 connect( dir, TQ_SIGNAL(deleteItem(KFileItem *)),
1136 connect( dir, TQ_SIGNAL(redirection(
const KURL& )),
1137 TQ_SLOT( slotRedirected(
const KURL& )));
1138 connect( dir, TQ_SIGNAL( clear() ), TQ_SLOT( slotClearView() ));
1139 connect( dir, TQ_SIGNAL( refreshItems(
const KFileItemList& ) ),
1140 TQ_SLOT( slotRefreshItems(
const KFileItemList& ) ) );
1145 if ( newone.isEmpty() || !m_fileView )
1148 myCompleteListDirty =
true;
1150 emit updateInformation(m_fileView->
numDirs(), m_fileView->
numFiles());
1153 KFileItemListIterator it( newone );
1155 while ( (item = it.current()) ) {
1157 if ( d->dirHighlighting && item->isDir() &&
1158 item->url().url(-1) == d->lastURL ) {
1166 TQTimer::singleShot(200,
this, TQ_SLOT(
resetCursor()));
1171 setURL(item->url(),
true);
1176 pendingMimeTypes.removeRef( item );
1179 m_fileView->
removeItem(
static_cast<KFileItem *
>( item ));
1180 emit updateInformation(m_fileView->
numDirs(), m_fileView->
numFiles());
1186 TQApplication::restoreOverrideCursor();
1188 emit fileSelected( item );
1194 const KFileItem *item = 0L;
1196 if ( !filename.isNull() )
1197 item =
static_cast<KFileItem *
>(dir->findByName( filename ));
1210 if (
string.isEmpty() ) {
1212 return TQString::null;
1216 return myCompletion.makeCompletion(
string );
1221 if (
string.isEmpty() ) {
1223 return TQString::null;
1227 return myDirCompletion.makeCompletion(
string );
1235 if ( myCompleteListDirty ) {
1236 KFileItemListIterator it( *(m_fileView->
items()) );
1237 for( ; it.current(); ++it ) {
1238 KFileItem *item = it.current();
1240 myCompletion.addItem( item->name() );
1241 if ( item->isDir() )
1242 myDirCompletion.addItem( item->name() );
1244 myCompleteListDirty =
false;
1251 emit completion( match );
1256 myActionCollection =
new TDEActionCollection( topLevelWidget(),
this,
"KDirOperator::myActionCollection" );
1258 actionMenu =
new TDEActionMenu( i18n(
"Menu"), myActionCollection,
"popupMenu" );
1259 upAction = KStdAction::up(
this, TQ_SLOT(
cdUp() ), myActionCollection,
"up" );
1260 upAction->setText( i18n(
"Parent Folder") );
1261 backAction = KStdAction::back(
this, TQ_SLOT(
back() ), myActionCollection,
"back" );
1262 forwardAction = KStdAction::forward(
this, TQ_SLOT(
forward()), myActionCollection,
"forward" );
1263 homeAction = KStdAction::home(
this, TQ_SLOT(
home() ), myActionCollection,
"home" );
1264 homeAction->setText(i18n(
"Home Folder"));
1265 reloadAction = KStdAction::redisplay(
this, TQ_SLOT(
rereadDir()), myActionCollection,
"reload" );
1266 actionSeparator =
new TDEActionSeparator( myActionCollection,
"separator" );
1267 d->viewActionSeparator =
new TDEActionSeparator( myActionCollection,
1268 "viewActionSeparator" );
1269 mkdirAction =
new TDEAction( i18n(
"New Folder..."), 0,
1270 this, TQ_SLOT(
mkdir() ), myActionCollection,
"mkdir" );
1271 TDEAction*
trash =
new TDEAction( i18n(
"Move to Trash" ),
"edittrash", Key_Delete, myActionCollection,
"trash" );
1272 connect(
trash, TQ_SIGNAL( activated( TDEAction::ActivationReason, TQt::ButtonState ) ),
1273 this, TQ_SLOT(
trashSelected( TDEAction::ActivationReason, TQt::ButtonState ) ) );
1274 new TDEAction( i18n(
"Delete" ),
"edit-delete", SHIFT+Key_Delete,
this,
1276 mkdirAction->setIcon( TQString::fromLatin1(
"folder-new") );
1277 reloadAction->setText( i18n(
"Reload") );
1278 reloadAction->setShortcut( TDEStdAccel::shortcut( TDEStdAccel::Reload ));
1282 sortActionMenu =
new TDEActionMenu( i18n(
"Sorting"), myActionCollection,
"sorting menu");
1283 byNameAction =
new TDERadioAction( i18n(
"By Name"), 0,
1284 this, TQ_SLOT( slotSortByName() ),
1285 myActionCollection,
"by name" );
1286 byDateAction =
new TDERadioAction( i18n(
"By Date"), 0,
1287 this, TQ_SLOT( slotSortByDate() ),
1288 myActionCollection,
"by date" );
1289 bySizeAction =
new TDERadioAction( i18n(
"By Size"), 0,
1290 this, TQ_SLOT( slotSortBySize() ),
1291 myActionCollection,
"by size" );
1292 reverseAction =
new TDEToggleAction( i18n(
"Reverse"), 0,
1293 this, TQ_SLOT( slotSortReversed() ),
1294 myActionCollection,
"reversed" );
1296 TQString sortGroup = TQString::fromLatin1(
"sort");
1297 byNameAction->setExclusiveGroup( sortGroup );
1298 byDateAction->setExclusiveGroup( sortGroup );
1299 bySizeAction->setExclusiveGroup( sortGroup );
1302 dirsFirstAction =
new TDEToggleAction( i18n(
"Folders First"), 0,
1303 myActionCollection,
"dirs first");
1304 caseInsensitiveAction =
new TDEToggleAction(i18n(
"Case Insensitive"), 0,
1305 myActionCollection,
"case insensitive" );
1307 connect( dirsFirstAction, TQ_SIGNAL( toggled(
bool ) ),
1308 TQ_SLOT( slotToggleDirsFirst() ));
1309 connect( caseInsensitiveAction, TQ_SIGNAL( toggled(
bool ) ),
1310 TQ_SLOT( slotToggleIgnoreCase() ));
1315 viewActionMenu =
new TDEActionMenu( i18n(
"&View"), myActionCollection,
"view menu" );
1316 connect( viewActionMenu->popupMenu(), TQ_SIGNAL( aboutToShow() ),
1317 TQ_SLOT( insertViewDependentActions() ));
1319 shortAction =
new TDERadioAction( i18n(
"Short View"),
"view_multicolumn",
1320 TDEShortcut(), myActionCollection,
"short view" );
1321 detailedAction =
new TDERadioAction( i18n(
"Detailed View"),
"view_detailed",
1322 TDEShortcut(), myActionCollection,
"detailed view" );
1324 showHiddenAction =
new TDEToggleAction( i18n(
"Show Hidden Files"), TDEShortcut(),
1325 myActionCollection,
"show hidden" );
1327 separateDirsAction =
new TDEToggleAction( i18n(
"Separate Folders"), TDEShortcut(),
1329 TQ_SLOT(slotSeparateDirs()),
1330 myActionCollection,
"separate dirs" );
1331 TDEToggleAction *previewAction =
new TDEToggleAction(i18n(
"Show Preview"),
1332 "thumbnail", TDEShortcut(),
1335 previewAction->setCheckedState(i18n(
"Hide Preview"));
1336 connect( previewAction, TQ_SIGNAL( toggled(
bool )),
1337 TQ_SLOT( togglePreview(
bool )));
1340 TQString viewGroup = TQString::fromLatin1(
"view");
1341 shortAction->setExclusiveGroup( viewGroup );
1342 detailedAction->setExclusiveGroup( viewGroup );
1344 connect( shortAction, TQ_SIGNAL( activated() ),
1345 TQ_SLOT( slotSimpleView() ));
1346 connect( detailedAction, TQ_SIGNAL( activated() ),
1347 TQ_SLOT( slotDetailedView() ));
1348 connect( showHiddenAction, TQ_SIGNAL( toggled(
bool ) ),
1349 TQ_SLOT( slotToggleHidden(
bool ) ));
1351 new TDEAction( i18n(
"Properties"), TDEShortcut(ALT+Key_Return),
this,
1352 TQ_SLOT(slotProperties()), myActionCollection,
"properties" );
1363 sortActionMenu->popupMenu()->clear();
1364 sortActionMenu->insert( byNameAction );
1365 sortActionMenu->insert( byDateAction );
1366 sortActionMenu->insert( bySizeAction );
1367 sortActionMenu->insert( actionSeparator );
1368 sortActionMenu->insert( reverseAction );
1369 sortActionMenu->insert( dirsFirstAction );
1370 sortActionMenu->insert( caseInsensitiveAction );
1373 actionMenu->popupMenu()->clear();
1374 if (whichActions & NavActions)
1376 actionMenu->insert( upAction );
1377 actionMenu->insert( backAction );
1378 actionMenu->insert( forwardAction );
1379 actionMenu->insert( homeAction );
1380 actionMenu->insert( actionSeparator );
1383 if (whichActions & FileActions)
1385 actionMenu->insert( mkdirAction );
1386 if (currUrl.isLocalFile() && !(TDEApplication::keyboardMouseState() & TQt::ShiftButton))
1387 actionMenu->insert( myActionCollection->action(
"trash" ) );
1388 TDEConfig *globalconfig = TDEGlobal::config();
1389 TDEConfigGroupSaver cs( globalconfig, TQString::fromLatin1(
"KDE") );
1390 if (!currUrl.isLocalFile() || (TDEApplication::keyboardMouseState() & TQt::ShiftButton) ||
1391 globalconfig->readBoolEntry(
"ShowDeleteCommand",
false))
1392 actionMenu->insert( myActionCollection->action(
"delete" ) );
1393 actionMenu->insert( actionSeparator );
1396 if (whichActions & SortActions)
1398 actionMenu->insert( sortActionMenu );
1399 actionMenu->insert( actionSeparator );
1402 if (whichActions & ViewActions)
1404 actionMenu->insert( viewActionMenu );
1405 actionMenu->insert( actionSeparator );
1408 if (whichActions & FileActions)
1410 actionMenu->insert( myActionCollection->action(
"properties" ) );
1416 if ( KFile::isSortByName( mySorting ) )
1417 byNameAction->setChecked(
true );
1418 else if ( KFile::isSortByDate( mySorting ) )
1419 byDateAction->setChecked(
true );
1420 else if ( KFile::isSortBySize( mySorting ) )
1421 bySizeAction->setChecked(
true );
1423 dirsFirstAction->setChecked( KFile::isSortDirsFirst( mySorting ) );
1424 caseInsensitiveAction->setChecked( KFile::isSortCaseInsensitive(mySorting) );
1425 caseInsensitiveAction->setEnabled( KFile::isSortByName( mySorting ) );
1428 reverseAction->setChecked( m_fileView->
isReversed() );
1433 KFile::FileView fv =
static_cast<KFile::FileView
>( m_viewKind );
1435 separateDirsAction->setChecked( KFile::isSeparateDirs( fv ) &&
1436 separateDirsAction->isEnabled() );
1438 shortAction->setChecked( KFile::isSimpleView( fv ));
1439 detailedAction->setChecked( KFile::isDetailView( fv ));
1446 TQString oldGroup = kc->group();
1447 if ( !group.isEmpty() )
1448 kc->setGroup( group );
1453 TQString viewStyle = kc->readEntry( TQString::fromLatin1(
"View Style"),
1454 TQString::fromLatin1(
"Simple") );
1455 if ( viewStyle == TQString::fromLatin1(
"Detail") )
1456 defaultView |= KFile::Detail;
1458 defaultView |= KFile::Simple;
1459 if ( kc->readBoolEntry( TQString::fromLatin1(
"Separate Directories"),
1460 DefaultMixDirsAndFiles ) )
1461 defaultView |= KFile::SeparateDirs;
1462 if ( kc->readBoolEntry(TQString::fromLatin1(
"Show Preview"),
false))
1463 defaultView |= KFile::PreviewContents;
1465 if ( kc->readBoolEntry( TQString::fromLatin1(
"Sort case insensitively"),
1466 DefaultCaseInsensitive ) )
1468 if ( kc->readBoolEntry( TQString::fromLatin1(
"Sort directories first"),
1469 DefaultDirsFirst ) )
1473 TQString name = TQString::fromLatin1(
"Name");
1474 TQString sortBy = kc->readEntry( TQString::fromLatin1(
"Sort by"), name );
1475 if ( sortBy == name )
1477 else if ( sortBy == TQString::fromLatin1(
"Size") )
1479 else if ( sortBy == TQString::fromLatin1(
"Date") )
1482 mySorting =
static_cast<TQDir::SortSpec
>(
sorting );
1486 if ( kc->readBoolEntry( TQString::fromLatin1(
"Show hidden files"),
1487 DefaultShowHidden ) ) {
1488 showHiddenAction->setChecked(
true );
1489 dir->setShowingDotFiles(
true );
1491 if ( kc->readBoolEntry( TQString::fromLatin1(
"Sort reversed"),
1492 DefaultSortReversed ) )
1493 reverseAction->setChecked(
true );
1495 kc->setGroup( oldGroup );
1503 const TQString oldGroup = kc->group();
1505 if ( !group.isEmpty() )
1506 kc->setGroup( group );
1508 TQString sortBy = TQString::fromLatin1(
"Name");
1509 if ( KFile::isSortBySize( mySorting ) )
1510 sortBy = TQString::fromLatin1(
"Size");
1511 else if ( KFile::isSortByDate( mySorting ) )
1512 sortBy = TQString::fromLatin1(
"Date");
1513 kc->writeEntry( TQString::fromLatin1(
"Sort by"), sortBy );
1515 kc->writeEntry( TQString::fromLatin1(
"Sort reversed"),
1516 reverseAction->isChecked() );
1517 kc->writeEntry( TQString::fromLatin1(
"Sort case insensitively"),
1518 caseInsensitiveAction->isChecked() );
1519 kc->writeEntry( TQString::fromLatin1(
"Sort directories first"),
1520 dirsFirstAction->isChecked() );
1524 bool appSpecificPreview =
false;
1526 TQWidget *preview =
const_cast<TQWidget*
>( myPreview );
1527 KFileMetaPreview *tmp =
dynamic_cast<KFileMetaPreview*
>( preview );
1528 appSpecificPreview = (tmp == 0L);
1531 if ( !appSpecificPreview ) {
1532 if ( separateDirsAction->isEnabled() )
1533 kc->writeEntry( TQString::fromLatin1(
"Separate Directories"),
1534 separateDirsAction->isChecked() );
1536 TDEToggleAction *previewAction =
static_cast<TDEToggleAction*
>(myActionCollection->action(
"preview"));
1537 if ( previewAction->isEnabled() ) {
1538 bool hasPreview = previewAction->isChecked();
1539 kc->writeEntry( TQString::fromLatin1(
"Show Preview"), hasPreview );
1543 kc->writeEntry( TQString::fromLatin1(
"Show hidden files"),
1544 showHiddenAction->isChecked() );
1546 KFile::FileView fv =
static_cast<KFile::FileView
>( m_viewKind );
1548 if ( KFile::isDetailView( fv ) )
1549 style = TQString::fromLatin1(
"Detail");
1550 else if ( KFile::isSimpleView( fv ) )
1551 style = TQString::fromLatin1(
"Simple");
1552 kc->writeEntry( TQString::fromLatin1(
"View Style"), style );
1554 kc->setGroup( oldGroup );
1558 void KDirOperator::resizeEvent( TQResizeEvent * )
1561 m_fileView->
widget()->resize( size() );
1563 if ( progress->parent() ==
this )
1564 progress->move(2, height() - progress->height() -2);
1569 d->onlyDoubleClickSelectsFiles = enable;
1576 return d->onlyDoubleClickSelectsFiles;
1579 void KDirOperator::slotStarted()
1581 progress->setProgress( 0 );
1583 d->progressDelayTimer->start( 1000,
true );
1586 void KDirOperator::slotShowProgress()
1590 TQApplication::flushX();
1593 void KDirOperator::slotProgress(
int percent )
1595 progress->setProgress( percent );
1597 if ( progress->isVisible() )
1598 TQApplication::flushX();
1602 void KDirOperator::slotIOFinished()
1604 d->progressDelayTimer->stop();
1605 slotProgress( 100 );
1607 emit finishedLoading();
1614 void KDirOperator::slotCanceled()
1616 emit finishedLoading();
1631 backAction->setEnabled(
false );
1632 forwardStack.clear();
1633 forwardAction->setEnabled(
false );
1636 void KDirOperator::slotViewActionAdded( TDEAction *action )
1638 if ( viewActionMenu->popupMenu()->count() == 5 )
1639 viewActionMenu->insert( d->viewActionSeparator );
1641 viewActionMenu->insert( action );
1644 void KDirOperator::slotViewActionRemoved( TDEAction *action )
1646 viewActionMenu->remove( action );
1648 if ( viewActionMenu->popupMenu()->count() == 6 )
1649 viewActionMenu->remove( d->viewActionSeparator );
1652 void KDirOperator::slotViewSortingChanged( TQDir::SortSpec sort )
1660 d->dirHighlighting = enable;
1665 return d->dirHighlighting;
1668 void KDirOperator::slotProperties()
1672 if ( !list->isEmpty() )
1677 void KDirOperator::slotClearView()
1685 bool KDirOperator::isReadable(
const KURL& url )
1687 if ( !
url.isLocalFile() )
1690 KDE_struct_stat buf;
1691 TQString ts =
url.path(+1);
1692 bool readable = ( KDE_stat( TQFile::encodeName( ts ), &buf) == 0 );
1695 test = opendir( TQFile::encodeName( ts ));
1696 readable = (test != 0);
1703 void KDirOperator::togglePreview(
bool on )
1706 slotDefaultPreview();
1708 setView( (KFile::FileView) (m_viewKind & ~(KFile::PreviewContents|KFile::PreviewInfo)) );
1711 void KDirOperator::slotRefreshItems(
const KFileItemList& items )
1716 KFileItemListIterator it( items );
1717 for ( ; it.current(); ++it )
1724 d->configGroup = group;
1734 return d->configGroup;
1737 void KDirOperator::virtual_hook(
int,
void* )
1740 #include "tdediroperator.moc"
This view is designed to combine two KFileViews into one widget, to show directories on the left side...
void setRight(KFileView *view)
Sets the view to be shown in the right.
void setDropOptions(int options)
Sets the options for dropping files.
virtual void setAcceptDrops(bool b)
Reimplemented - allow dropping of files if b is true.
virtual KFileView * createView(TQWidget *parent, KFile::FileView view)
A view factory for creating predefined fileviews.
void itemDeleted(KFileItem *)
Removes the given KFileItem item from the view (usually called from KDirLister).
const TQString & nameFilter() const
void dropped(const KFileItem *item, TQDropEvent *event, const KURL::List &urls)
Emitted when files are dropped.
void setPreviewWidget(const TQWidget *w)
Sets a preview-widget to be shown next to the file-view.
void rereadDir()
Re-reads the current url.
void setupActions()
Sets up all the actions.
KProgress * progressBar() const
void updateSortActions()
Updates the sorting-related actions to comply with the current sorting.
TDEIO::CopyJob * trash(const KFileItemList &items, TQWidget *parent, bool ask=true, bool showProgress=true)
Starts and returns a TDEIO::CopyJob to trash the given items.
void setMimeFilter(const TQStringList &mimetypes)
Sets a list of mimetypes as filter.
void updateSelectionDependentActions()
Enables/disables actions that are selection dependent.
void close()
Stops loading immediately.
KDirOperator(const KURL &urlName=KURL(), TQWidget *parent=0, const char *name=0)
Constructs the KDirOperator with no initial view.
TQWidget * viewWidget() const
Returns the widget of the current view.
TQString viewConfigGroup() const
Returns the group name used for saving and restoring view's configuration.
void prepareCompletionObjects()
Synchronizes the completion objects with the entries of the currently listed url.
void updateViewActions()
Updates the view-related actions to comply with the current KFile::FileView.
void forward()
Goes one step forward in the history and opens that url.
void setViewConfig(TDEConfig *config, const TQString &group)
Sets the config object and the to be used group in KDirOperator.
void back()
Goes one step back in the history and opens that url.
TDEConfig * viewConfig()
Returns the TDEConfig object used for saving and restoring view's configuration.
void setSorting(TQDir::SortSpec)
Sets the way to sort files and directories.
TQString makeCompletion(const TQString &)
Tries to complete the given string (only completes files).
void clearHistory()
Clears the forward and backward history.
void cdUp()
Goes one directory up from the current url.
bool onlyDoubleClickSelectsFiles() const
void clearFilter()
Clears both the namefilter and mimetype filter, so that all files and directories will be shown.
void selectFile(const KFileItem *item)
Emits fileSelected( item )
TQString makeDirCompletion(const TQString &)
Tries to complete the given string (only completes directores).
void setDirLister(KDirLister *lister)
Sets a custom KDirLister to list directories.
void selectDir(const KFileItem *item)
Enters the directory specified by the given item.
void updateDir()
to update the view after changing the settings
void resetCursor()
Restores the normal cursor after showing the busy-cursor.
void mkdir()
Opens a dialog to create a new directory.
TDEIO::DeleteJob * del(const KFileItemList &items, bool ask=true, bool showProgress=true)
Starts and returns a TDEIO::DeleteJob to delete the given items.
void deleteSelected()
Deletes the currently selected files/directories.
void setOnlyDoubleClickSelectsFiles(bool enable)
This is a KFileDialog specific hack: we want to select directories with single click,...
bool dirHighlighting() const
void fileHighlighted(const KFileItem *item)
Emitted when a file is highlighted or generally the selection changes in multiselection mode.
void setNameFilter(const TQString &filter)
Sets a filter like "*.cpp *.h *.o".
void setupMenu()
Sets up the context-menu with all the necessary actions.
virtual void writeConfig(TDEConfig *, const TQString &group=TQString::null)
Saves the current settings like sorting, simple or detailed view.
void setMode(KFile::Mode m)
Sets the listing/selection mode for the views, an OR'ed combination of.
TDEActionCollection * actionCollection() const
an accessor to a collection of all available Actions.
void setView(KFileView *view)
Sets a new KFileView to be used for showing and browsing files.
virtual void readConfig(TDEConfig *, const TQString &group=TQString::null)
Reads the default settings for a view, i.e.
void home()
Enters the home directory.
TQDir::SortSpec sorting() const
virtual void activatedMenu(const KFileItem *, const TQPoint &pos)
Called upon right-click to activate the popupmenu.
void pathChanged()
Called after setURL() to load the directory, update the history, etc.
void setURL(const KURL &url, bool clearforward)
Sets a new url to list.
virtual ~KDirOperator()
Destroys the KDirOperator.
void slotCompletionMatch(const TQString &match)
Tries to make the given match as current item in the view and emits completion( match )
void insertNewFiles(const KFileItemList &newone)
Adds a new list of KFileItems to the view (coming from KDirLister)
void setCurrentItem(const TQString &filename)
Clears the current selection and attempts to set filename the current file.
void trashSelected(TDEAction::ActivationReason, TQt::ButtonState)
Trashes the currently selected files/directories.
void setEnableDirHighlighting(bool enable)
When going up in the directory hierarchy, KDirOperator can highlight the directory that was just left...
void viewChanged(KFileView *newView)
Emitted whenever the current fileview is changed, either by an explicit call to setView() or by the u...
void highlightFile(const KFileItem *i)
Emits fileHighlighted( i )
bool checkPreviewSupport()
Checks if there support from TDEIO::PreviewJob for the currently shown files, taking mimeFilter() and...
A list-view capable of showing KFileItem'.
An icon-view capable of showing KFileItem's.
internal class to make easier to use signals possible
This class defines an interface to all file views.
virtual void clearSelection()=0
Clears any selection, unhighlights everything.
void setViewName(const TQString &name)
Sets the name of the view, which could be displayed somewhere.
virtual void listingCompleted()
This hook is called when all items of the currently listed directory are listed and inserted into the...
const KFileItemList * items() const
void setCurrentItem(const TQString &filename)
Sets filename the current item in the view, if available.
bool isReversed() const
Tells whether the current items are in reversed order (shortcut to sorting() & TQDir::Reversed).
void setOnlyDoubleClickSelectsFiles(bool enable)
This is a KFileDialog specific hack: we want to select directories with single click,...
const KFileItemList * selectedItems() const
TQDir::SortSpec sorting() const
Returns the sorting order of the internal list.
virtual void updateView(bool f=true)
does a repaint of the view.
virtual TQWidget * widget()=0
a pure virtual function to get a TQWidget, that can be added to other widgets.
void setDropOptions(int options)
Specify DND options.
virtual KFileItem * currentFileItem() const =0
virtual void removeItem(const KFileItem *item)
Removes an item from the list; has to be implemented by the view.
virtual void ensureItemVisible(const KFileItem *i)=0
pure virtual function, that should be implemented to make item i visible, i.e.
virtual void setSorting(TQDir::SortSpec sort)
Sets the sorting order of the view.
virtual TDEActionCollection * actionCollection() const
virtual void clear()
Clears the view and all item lists.
void addItemList(const KFileItemList &list)
inserts a list of items.
virtual void setSelected(const KFileItem *, bool enable)=0
Tells the view that it should highlight the item.
virtual void clearView()=0
pure virtual function, that should be implemented to clear the view.
KFile is a class which provides a namespace for some enumerated values associated with the tdefile li...
Mode
Modes of operation for the dialog.
static bool isPreviewInfo(const FileView &view)
The main properties dialog class.