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, TQT_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, TQT_SIGNAL( timeout() ),
136 TQT_SLOT( slotShowProgress() ));
138 myCompleteListDirty =
false;
140 backStack.setAutoDelete(
true );
141 forwardStack.setAutoDelete(
true );
147 setFocusPolicy(TQ_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, TQT_SIGNAL( inserted( TDEAction * )),
196 this, TQT_SLOT( slotViewActionAdded( TDEAction * )));
197 disconnect( viewActionCollection, TQT_SIGNAL( removed( TDEAction * )),
198 this, TQT_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, TQT_SIGNAL( inserted( TDEAction * )),
241 TQT_SLOT( slotViewActionAdded( TDEAction * )));
242 connect( viewActionCollection, TQT_SIGNAL( removed( TDEAction * )),
243 TQT_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( tqwaitCursor );
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, TQT_SIGNAL(
activatedMenu(
const KFileItem *,
const TQPoint& ) ),
1054 this, TQT_SLOT(
activatedMenu(
const KFileItem *,
const TQPoint& )));
1055 connect(sig, TQT_SIGNAL( dirActivated(
const KFileItem *) ),
1056 this, TQT_SLOT(
selectDir(
const KFileItem*) ) );
1057 connect(sig, TQT_SIGNAL( fileSelected(
const KFileItem *) ),
1058 this, TQT_SLOT(
selectFile(
const KFileItem*) ) );
1061 connect(sig, TQT_SIGNAL( sortingChanged( TQDir::SortSpec ) ),
1062 this, TQT_SLOT( slotViewSortingChanged( TQDir::SortSpec )));
1063 connect(sig, TQT_SIGNAL(
dropped(
const KFileItem *, TQDropEvent*,
const KURL::List&) ),
1064 this, TQT_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( tqwaitCursor );
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, TQT_SIGNAL( percent(
int )),
1128 TQT_SLOT( slotProgress(
int ) ));
1129 connect( dir, TQT_SIGNAL(started(
const KURL& )), TQT_SLOT(slotStarted()));
1130 connect( dir, TQT_SIGNAL(newItems(
const KFileItemList &)),
1132 connect( dir, TQT_SIGNAL(completed()), TQT_SLOT(slotIOFinished()));
1133 connect( dir, TQT_SIGNAL(canceled()), TQT_SLOT(slotCanceled()));
1134 connect( dir, TQT_SIGNAL(deleteItem(KFileItem *)),
1136 connect( dir, TQT_SIGNAL(redirection(
const KURL& )),
1137 TQT_SLOT( slotRedirected(
const KURL& )));
1138 connect( dir, TQT_SIGNAL( clear() ), TQT_SLOT( slotClearView() ));
1139 connect( dir, TQT_SIGNAL( refreshItems(
const KFileItemList& ) ),
1140 TQT_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, TQT_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(), TQT_TQOBJECT(
this),
"KDirOperator::myActionCollection" );
1258 actionMenu =
new TDEActionMenu( i18n(
"Menu"), myActionCollection,
"popupMenu" );
1259 upAction = KStdAction::up( TQT_TQOBJECT(
this), TQT_SLOT(
cdUp() ), myActionCollection,
"up" );
1260 upAction->setText( i18n(
"Parent Folder") );
1261 backAction = KStdAction::back( TQT_TQOBJECT(
this), TQT_SLOT(
back() ), myActionCollection,
"back" );
1262 forwardAction = KStdAction::forward( TQT_TQOBJECT(
this), TQT_SLOT(
forward()), myActionCollection,
"forward" );
1263 homeAction = KStdAction::home( TQT_TQOBJECT(
this), TQT_SLOT(
home() ), myActionCollection,
"home" );
1264 homeAction->setText(i18n(
"Home Folder"));
1265 reloadAction = KStdAction::redisplay( TQT_TQOBJECT(
this), TQT_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 TQT_TQOBJECT(
this), TQT_SLOT(
mkdir() ), myActionCollection,
"mkdir" );
1271 TDEAction*
trash =
new TDEAction( i18n(
"Move to Trash" ),
"edittrash", Key_Delete, myActionCollection,
"trash" );
1272 connect(
trash, TQT_SIGNAL( activated( TDEAction::ActivationReason, TQt::ButtonState ) ),
1273 this, TQT_SLOT(
trashSelected( TDEAction::ActivationReason, TQt::ButtonState ) ) );
1274 new TDEAction( i18n(
"Delete" ),
"edit-delete", SHIFT+Key_Delete, TQT_TQOBJECT(
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 TQT_TQOBJECT(
this), TQT_SLOT( slotSortByName() ),
1285 myActionCollection,
"by name" );
1286 byDateAction =
new TDERadioAction( i18n(
"By Date"), 0,
1287 TQT_TQOBJECT(
this), TQT_SLOT( slotSortByDate() ),
1288 myActionCollection,
"by date" );
1289 bySizeAction =
new TDERadioAction( i18n(
"By Size"), 0,
1290 TQT_TQOBJECT(
this), TQT_SLOT( slotSortBySize() ),
1291 myActionCollection,
"by size" );
1292 reverseAction =
new TDEToggleAction( i18n(
"Reverse"), 0,
1293 TQT_TQOBJECT(
this), TQT_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, TQT_SIGNAL( toggled(
bool ) ),
1308 TQT_SLOT( slotToggleDirsFirst() ));
1309 connect( caseInsensitiveAction, TQT_SIGNAL( toggled(
bool ) ),
1310 TQT_SLOT( slotToggleIgnoreCase() ));
1315 viewActionMenu =
new TDEActionMenu( i18n(
"&View"), myActionCollection,
"view menu" );
1316 connect( viewActionMenu->popupMenu(), TQT_SIGNAL( aboutToShow() ),
1317 TQT_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 TQT_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, TQT_SIGNAL( toggled(
bool )),
1337 TQT_SLOT( togglePreview(
bool )));
1340 TQString viewGroup = TQString::fromLatin1(
"view");
1341 shortAction->setExclusiveGroup( viewGroup );
1342 detailedAction->setExclusiveGroup( viewGroup );
1344 connect( shortAction, TQT_SIGNAL( activated() ),
1345 TQT_SLOT( slotSimpleView() ));
1346 connect( detailedAction, TQT_SIGNAL( activated() ),
1347 TQT_SLOT( slotDetailedView() ));
1348 connect( showHiddenAction, TQT_SIGNAL( toggled(
bool ) ),
1349 TQT_SLOT( slotToggleHidden(
bool ) ));
1351 new TDEAction( i18n(
"Properties"), TDEShortcut(ALT+Key_Return), TQT_TQOBJECT(
this),
1352 TQT_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 ( TQT_BASE_OBJECT(progress->parent()) == TQT_BASE_OBJECT(
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"