1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
26 #include <kactioncollection.h>
27 #include <ktoggleaction.h>
28 #include <kbookmarkmanager.h>
30 #include <kpropertiesdialog.h>
32 #include <kiconloader.h>
33 #include <kdeversion.h>
34 #include <kstatusbar.h>
35 #include <kio/netaccess.h>
36 #include <kfiledialog.h>
39 #include <kstdaccel.h>
41 #include <kstdaction.h>
43 #include <kio/renamedlg.h>
44 #include <kinputdialog.h>
46 #include <kdesktopfile.h>
47 #include <kstandarddirs.h>
48 #include <kprotocolinfo.h>
49 #include <kmessagebox.h>
51 #include <kstandarddirs.h>
55 #include <qclipboard.h>
56 #include <q3dragobject.h>
58 #include <Q3ValueList>
59 #include <QCloseEvent>
62 #include "urlnavigator.h"
63 #include "viewpropertiesdialog.h"
64 #include "viewproperties.h"
65 #include "dolphinsettings.h"
66 #include "dolphinsettingsdialog.h"
67 #include "dolphinstatusbar.h"
68 #include "undomanager.h"
69 #include "progressindicator.h"
70 #include "dolphinsettings.h"
72 #include "sidebarsettings.h"
73 #include "generalsettings.h"
75 Dolphin
& Dolphin::mainWin()
77 static Dolphin
* instance
= 0;
79 instance
= new Dolphin();
89 void Dolphin::setActiveView(DolphinView
* view
)
91 assert((view
== m_view
[PrimaryIdx
]) || (view
== m_view
[SecondaryIdx
]));
92 if (m_activeView
== view
) {
103 setCaption(m_activeView
->url().fileName());
105 emit
activeViewChanged();
108 void Dolphin::dropUrls(const KUrl::List
& urls
,
109 const KUrl
& destination
)
111 int selectedIndex
= -1;
114 const ButtonState keyboardState = KApplication::keyboardMouseState();
115 const bool shiftPressed = (keyboardState & ShiftButton) > 0;
116 const bool controlPressed = (keyboardState & ControlButton) > 0;
120 if (shiftPressed && controlPressed) {
121 // shortcut for 'Linke Here' is used
124 else if (controlPressed) {
125 // shortcut for 'Copy Here' is used
128 else if (shiftPressed) {
129 // shortcut for 'Move Here' is used
133 // no shortcut is used, hence open a popup menu
136 popup
.insertItem(SmallIcon("goto"), i18n("&Move Here") + "\t" /* KDE4-TODO: + KKey::modFlagLabel(KKey::SHIFT)*/, 0);
137 popup
.insertItem(SmallIcon("editcopy"), i18n( "&Copy Here" ) /* KDE4-TODO + "\t" + KKey::modFlagLabel(KKey::CTRL)*/, 1);
138 popup
.insertItem(i18n("&Link Here") /* KDE4-TODO + "\t" + KKey::modFlagLabel((KKey::ModFlag)(KKey::CTRL|KKey::SHIFT)) */, 2);
139 popup
.insertSeparator();
140 popup
.insertItem(SmallIcon("stop"), i18n("Cancel"), 3);
141 popup
.setAccel(i18n("Escape"), 3);
143 /* KDE4-TODO: selectedIndex = popup.exec(QCursor::pos()); */
144 popup
.exec(QCursor::pos());
145 selectedIndex
= 0; // KD4-TODO: use QAction instead of switch below
146 // See libkonq/konq_operations.cc: KonqOperations::doDropFileCopy() (and doDrop, the main method)
149 if (selectedIndex
< 0) {
153 switch (selectedIndex
) {
155 // 'Move Here' has been selected
156 updateViewProperties(urls
);
157 moveUrls(urls
, destination
);
162 // 'Copy Here' has been selected
163 updateViewProperties(urls
);
164 copyUrls(urls
, destination
);
169 // 'Link Here' has been selected
170 KIO::Job
* job
= KIO::link(urls
, destination
);
171 addPendingUndoJob(job
, DolphinCommand::Link
, urls
, destination
);
176 // 'Cancel' has been selected
181 void Dolphin::refreshViews()
183 const bool split
= DolphinSettings::instance().generalSettings()->splitView();
184 const bool isPrimaryViewActive
= (m_activeView
== m_view
[PrimaryIdx
]);
186 for (int i
= PrimaryIdx
; i
<= SecondaryIdx
; ++i
) {
187 if (m_view
[i
] != 0) {
188 url
= m_view
[i
]->url();
190 // delete view instance...
192 m_view
[i
]->deleteLater();
196 if (split
|| (i
== PrimaryIdx
)) {
197 // ... and recreate it
198 ViewProperties
props(url
);
199 m_view
[i
] = new DolphinView(m_splitter
,
202 props
.isShowHiddenFilesEnabled());
207 m_activeView
= isPrimaryViewActive
? m_view
[PrimaryIdx
] : m_view
[SecondaryIdx
];
208 assert(m_activeView
!= 0);
211 emit
activeViewChanged();
214 void Dolphin::slotHistoryChanged()
219 void Dolphin::slotUrlChanged(const KUrl
& url
)
223 setCaption(url
.fileName());
226 void Dolphin::slotUrlChangeRequest(const KUrl
& url
)
229 m_activeView
->setUrl(url
);
232 void Dolphin::slotViewModeChanged()
237 void Dolphin::slotShowHiddenFilesChanged()
239 KToggleAction
* showHiddenFilesAction
=
240 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
241 showHiddenFilesAction
->setChecked(m_activeView
->isShowHiddenFilesEnabled());
244 void Dolphin::slotShowFilterBarChanged()
246 KToggleAction
* showFilterBarAction
=
247 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
248 showFilterBarAction
->setChecked(m_activeView
->isFilterBarVisible());
251 void Dolphin::slotSortingChanged(DolphinView::Sorting sorting
)
255 case DolphinView::SortByName
:
256 action
= actionCollection()->action("by_name");
258 case DolphinView::SortBySize
:
259 action
= actionCollection()->action("by_size");
261 case DolphinView::SortByDate
:
262 action
= actionCollection()->action("by_date");
269 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
270 toggleAction
->setChecked(true);
274 void Dolphin::slotSortOrderChanged(Qt::SortOrder order
)
276 KToggleAction
* descending
= static_cast<KToggleAction
*>(actionCollection()->action("descending"));
277 const bool sortDescending
= (order
== Qt::Descending
);
278 descending
->setChecked(sortDescending
);
281 void Dolphin::slotSelectionChanged()
285 assert(m_view
[PrimaryIdx
] != 0);
286 int selectedUrlsCount
= m_view
[PrimaryIdx
]->selectedUrls().count();
287 if (m_view
[SecondaryIdx
] != 0) {
288 selectedUrlsCount
+= m_view
[SecondaryIdx
]->selectedUrls().count();
291 KAction
* compareFilesAction
= actionCollection()->action("compare_files");
292 compareFilesAction
->setEnabled(selectedUrlsCount
== 2);
294 m_activeView
->updateStatusBar();
296 emit
selectionChanged();
299 void Dolphin::closeEvent(QCloseEvent
* event
)
302 //KConfig* config = KGlobal::config();
303 //config->setGroup("General");
304 //config->writeEntry("First Run", false);
306 DolphinSettings
& settings
= DolphinSettings::instance();
307 GeneralSettings
* generalSettings
= settings
.generalSettings();
308 generalSettings
->setFirstRun(false);
310 SidebarSettings
* sidebarSettings
= settings
.sidebarSettings();
311 const bool isSidebarVisible
= (m_sidebar
!= 0);
312 sidebarSettings
->setVisible(isSidebarVisible
);
313 if (isSidebarVisible
) {
314 sidebarSettings
->setWidth(m_sidebar
->width());
319 KMainWindow::closeEvent(event
);
322 void Dolphin::saveProperties(KConfig
* config
)
324 config
->setGroup("Primary view");
325 config
->writeEntry("Url", m_view
[PrimaryIdx
]->url().url());
326 config
->writeEntry("Editable Url", m_view
[PrimaryIdx
]->isUrlEditable());
327 if (m_view
[SecondaryIdx
] != 0) {
328 config
->setGroup("Secondary view");
329 config
->writeEntry("Url", m_view
[SecondaryIdx
]->url().url());
330 config
->writeEntry("Editable Url", m_view
[SecondaryIdx
]->isUrlEditable());
334 void Dolphin::readProperties(KConfig
* config
)
336 config
->setGroup("Primary view");
337 m_view
[PrimaryIdx
]->setUrl(config
->readEntry("Url"));
338 m_view
[PrimaryIdx
]->setUrlEditable(config
->readBoolEntry("Editable Url"));
339 if (config
->hasGroup("Secondary view")) {
340 config
->setGroup("Secondary view");
341 if (m_view
[SecondaryIdx
] == 0) {
344 m_view
[SecondaryIdx
]->setUrl(config
->readEntry("Url"));
345 m_view
[SecondaryIdx
]->setUrlEditable(config
->readBoolEntry("Editable Url"));
347 else if (m_view
[SecondaryIdx
] != 0) {
352 void Dolphin::createFolder()
354 // Parts of the following code have been taken
355 // from the class KonqPopupMenu located in
356 // libqonq/konq_popupmenu.h of Konqueror.
357 // (Copyright (C) 2000 David Faure <faure@kde.org>,
358 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
362 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
363 const KUrl
baseUrl(m_activeView
->url());
365 QString
name(i18n("New Folder"));
366 baseUrl
.path(KUrl::AddTrailingSlash
);
369 if (baseUrl
.isLocalFile() && QFileInfo(baseUrl
.path(KUrl::AddTrailingSlash
) + name
).exists()) {
370 name
= KIO::RenameDlg::suggestName(baseUrl
, i18n("New Folder"));
374 name
= KInputDialog::getText(i18n("New Folder"),
375 i18n("Enter folder name:" ),
381 // the user has pressed 'Cancel'
385 assert(!name
.isEmpty());
388 if ((name
[0] == '/') || (name
[0] == '~')) {
389 url
.setPath(KShell::tildeExpand(name
));
392 name
= KIO::encodeFileName(name
);
396 ok
= KIO::NetAccess::mkdir(url
, this);
398 // TODO: provide message type hint
400 statusBar
->setMessage(i18n("Created folder %1.",url
.path()),
401 DolphinStatusBar::OperationCompleted
);
403 DolphinCommand
command(DolphinCommand::CreateFolder
, KUrl::List(), url
);
404 UndoManager::instance().addCommand(command
);
407 // Creating of the folder has been failed. Check whether the creating
408 // has been failed because a folder with the same name exists...
409 if (KIO::NetAccess::exists(url
, true, this)) {
410 statusBar
->setMessage(i18n("A folder named %1 already exists.",url
.path()),
411 DolphinStatusBar::Error
);
414 statusBar
->setMessage(i18n("Creating of folder %1 failed.",url
.path()),
415 DolphinStatusBar::Error
);
421 void Dolphin::createFile()
423 // Parts of the following code have been taken
424 // from the class KonqPopupMenu located in
425 // libqonq/konq_popupmenu.h of Konqueror.
426 // (Copyright (C) 2000 David Faure <faure@kde.org>,
427 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
431 // TODO: const Entry& entry = m_createFileTemplates[QString(sender->name())];
432 // should be enough. Anyway: the implemantation of [] does a linear search internally too.
433 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
434 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
436 const QString
senderName(sender()->name());
438 CreateFileEntry entry
;
439 while (!found
&& (it
!= end
)) {
440 if ((*it
).index() == senderName
) {
441 entry
= (*it
).value();
449 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
450 if (!found
|| !QFile::exists(entry
.templatePath
)) {
451 statusBar
->setMessage(i18n("Could not create file."), DolphinStatusBar::Error
);
455 // Get the source path of the template which should be copied.
456 // The source path is part of the Url entry of the desktop file.
457 const int pos
= entry
.templatePath
.findRev('/');
458 QString
sourcePath(entry
.templatePath
.left(pos
+ 1));
459 sourcePath
+= KDesktopFile(entry
.templatePath
, true).readPathEntry("Url");
461 QString
name(i18n(entry
.name
.ascii()));
462 // Most entry names end with "..." (e. g. "HTML File..."), which is ok for
463 // menus but no good choice for a new file name -> remove the dots...
464 name
.replace("...", QString::null
);
466 // add the file extension to the name
467 name
.append(sourcePath
.right(sourcePath
.length() - sourcePath
.findRev('.')));
469 // Check whether a file with the current name already exists. If yes suggest automatically
470 // a unique file name (e. g. "HTML File" will be replaced by "HTML File_1").
471 const KUrl
viewUrl(m_activeView
->url());
472 const bool fileExists
= viewUrl
.isLocalFile() &&
473 QFileInfo(viewUrl
.path(KUrl::AddTrailingSlash
) + KIO::encodeFileName(name
)).exists();
475 name
= KIO::RenameDlg::suggestName(viewUrl
, name
);
478 // let the user change the suggested file name
480 name
= KInputDialog::getText(entry
.name
,
486 // the user has pressed 'Cancel'
490 // before copying the template to the destination path check whether a file
491 // with the given name already exists
492 const QString
destPath(viewUrl
.pathOrUrl() + "/" + KIO::encodeFileName(name
));
493 const KUrl
destUrl(destPath
);
494 if (KIO::NetAccess::exists(destUrl
, false, this)) {
495 statusBar
->setMessage(i18n("A file named %1 already exists.",name
),
496 DolphinStatusBar::Error
);
500 // copy the template to the destination path
501 const KUrl
sourceUrl(sourcePath
);
502 KIO::CopyJob
* job
= KIO::copyAs(sourceUrl
, destUrl
);
503 job
->setDefaultPermissions(true);
504 if (KIO::NetAccess::synchronousRun(job
, this)) {
505 statusBar
->setMessage(i18n("Created file %1.",name
),
506 DolphinStatusBar::OperationCompleted
);
509 list
.append(sourceUrl
);
510 DolphinCommand
command(DolphinCommand::CreateFile
, list
, destUrl
);
511 UndoManager::instance().addCommand(command
);
515 statusBar
->setMessage(i18n("Creating of file %1 failed.",name
),
516 DolphinStatusBar::Error
);
520 void Dolphin::rename()
523 m_activeView
->renameSelectedItems();
526 void Dolphin::moveToTrash()
529 KUrl::List selectedUrls
= m_activeView
->selectedUrls();
530 KIO::Job
* job
= KIO::trash(selectedUrls
);
531 addPendingUndoJob(job
, DolphinCommand::Trash
, selectedUrls
, m_activeView
->url());
534 void Dolphin::deleteItems()
538 KUrl::List list
= m_activeView
->selectedUrls();
539 const uint itemCount
= list
.count();
540 assert(itemCount
>= 1);
544 text
= i18n("Do you really want to delete the %1 selected items?",itemCount
);
547 const KUrl
& url
= list
.first();
548 text
= i18n("Do you really want to delete '%1'?",url
.fileName());
551 const bool del
= KMessageBox::warningContinueCancel(this,
554 KGuiItem(i18n("Delete"), SmallIcon("editdelete"))
555 ) == KMessageBox::Continue
;
557 KIO::Job
* job
= KIO::del(list
);
558 connect(job
, SIGNAL(result(KIO::Job
*)),
559 this, SLOT(slotHandleJobError(KIO::Job
*)));
560 connect(job
, SIGNAL(result(KIO::Job
*)),
561 this, SLOT(slotDeleteFileFinished(KIO::Job
*)));
565 void Dolphin::properties()
567 const KFileItemList
* sourceList
= m_activeView
->selectedItems();
568 if (sourceList
== 0) {
573 KFileItemList::const_iterator it
= sourceList
->begin();
574 const KFileItemList::const_iterator end
= sourceList
->end();
581 new KPropertiesDialog(list
, this);
589 void Dolphin::slotHandleJobError(KIO::Job
* job
)
591 if (job
->error() != 0) {
592 m_activeView
->statusBar()->setMessage(job
->errorString(),
593 DolphinStatusBar::Error
);
597 void Dolphin::slotDeleteFileFinished(KIO::Job
* job
)
599 if (job
->error() == 0) {
600 m_activeView
->statusBar()->setMessage(i18n("Delete operation completed."),
601 DolphinStatusBar::OperationCompleted
);
603 // TODO: In opposite to the 'Move to Trash' operation in the class KFileIconView
604 // no rearranging of the item position is done when a file has been deleted.
605 // This is bypassed by reloading the view, but it might be worth to investigate
606 // deeper for the root of this issue.
607 m_activeView
->reload();
611 void Dolphin::slotUndoAvailable(bool available
)
613 KAction
* undoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Undo
));
614 if (undoAction
!= 0) {
615 undoAction
->setEnabled(available
);
619 void Dolphin::slotUndoTextChanged(const QString
& text
)
621 KAction
* undoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Undo
));
622 if (undoAction
!= 0) {
623 undoAction
->setText(text
);
627 void Dolphin::slotRedoAvailable(bool available
)
629 KAction
* redoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Redo
));
630 if (redoAction
!= 0) {
631 redoAction
->setEnabled(available
);
635 void Dolphin::slotRedoTextChanged(const QString
& text
)
637 KAction
* redoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Redo
));
638 if (redoAction
!= 0) {
639 redoAction
->setText(text
);
645 // TODO: this boolean doesn't work between instances of dolphin or with konqueror or with other
646 // apps. The "application/x-kde-cutselection" mimetype should be used instead, see KonqMimeData
648 m_clipboardContainsCutData
= true;
649 /* KDE4-TODO: Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(),
651 QApplication::clipboard()->setData(data);*/
656 m_clipboardContainsCutData
= false;
658 Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(),
660 QApplication::clipboard()->setData(data);*/
663 void Dolphin::paste()
665 /* KDE4-TODO: - see KonqOperations::doPaste
666 QClipboard* clipboard = QApplication::clipboard();
667 QMimeSource* data = clipboard->data();
668 if (!KUrlDrag::canDecode(data)) {
674 KUrl::List sourceUrls;
675 KUrlDrag::decode(data, sourceUrls);
677 // per default the pasting is done into the current Url of the view
678 KUrl destUrl(m_activeView->url());
680 // check whether the pasting should be done into a selected directory
681 KUrl::List selectedUrls = m_activeView->selectedUrls();
682 if (selectedUrls.count() == 1) {
683 const KFileItem fileItem(S_IFDIR,
685 selectedUrls.first(),
687 if (fileItem.isDir()) {
688 // only one item is selected which is a directory, hence paste
689 // into this directory
690 destUrl = selectedUrls.first();
695 updateViewProperties(sourceUrls);
696 if (m_clipboardContainsCutData) {
697 moveUrls(sourceUrls, destUrl);
698 m_clipboardContainsCutData = false;
702 copyUrls(sourceUrls, destUrl);
706 void Dolphin::updatePasteAction()
708 KAction
* pasteAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Paste
));
709 if (pasteAction
== 0) {
713 QString
text(i18n("Paste"));
714 QClipboard
* clipboard
= QApplication::clipboard();
715 QMimeSource
* data
= clipboard
->data();
717 if (KUrlDrag::canDecode(data)) {
718 pasteAction->setEnabled(true);
721 KUrlDrag::decode(data, urls);
722 const int count = urls.count();
724 pasteAction->setText(i18n("Paste 1 File"));
727 pasteAction->setText(i18n("Paste %1 Files").arg(count));
731 pasteAction
->setEnabled(false);
732 pasteAction
->setText(i18n("Paste"));
735 if (pasteAction
->isEnabled()) {
736 KUrl::List urls
= m_activeView
->selectedUrls();
737 const uint count
= urls
.count();
739 // pasting should not be allowed when more than one file
741 pasteAction
->setEnabled(false);
743 else if (count
== 1) {
744 // Only one file is selected. Pasting is only allowed if this
745 // file is a directory.
746 // TODO: this doesn't work with remote protocols; instead we need a
747 // m_activeView->selectedFileItems() to get the real KFileItems
748 const KFileItem
fileItem(S_IFDIR
,
752 pasteAction
->setEnabled(fileItem
.isDir());
757 void Dolphin::selectAll()
760 m_activeView
->selectAll();
763 void Dolphin::invertSelection()
766 m_activeView
->invertSelection();
768 void Dolphin::setIconsView()
770 m_activeView
->setMode(DolphinView::IconsView
);
773 void Dolphin::setDetailsView()
775 m_activeView
->setMode(DolphinView::DetailsView
);
778 void Dolphin::setPreviewsView()
780 m_activeView
->setMode(DolphinView::PreviewsView
);
783 void Dolphin::sortByName()
785 m_activeView
->setSorting(DolphinView::SortByName
);
788 void Dolphin::sortBySize()
790 m_activeView
->setSorting(DolphinView::SortBySize
);
793 void Dolphin::sortByDate()
795 m_activeView
->setSorting(DolphinView::SortByDate
);
798 void Dolphin::toggleSortOrder()
800 const Qt::SortOrder order
= (m_activeView
->sortOrder() == Qt::Ascending
) ?
803 m_activeView
->setSortOrder(order
);
806 void Dolphin::toggleSplitView()
808 if (m_view
[SecondaryIdx
] == 0) {
809 // create a secondary view
810 m_view
[SecondaryIdx
] = new DolphinView(m_splitter
,
811 m_view
[PrimaryIdx
]->url(),
812 m_view
[PrimaryIdx
]->mode(),
813 m_view
[PrimaryIdx
]->isShowHiddenFilesEnabled());
814 m_view
[SecondaryIdx
]->show();
817 // remove secondary view
818 if (m_activeView
== m_view
[PrimaryIdx
]) {
819 m_view
[SecondaryIdx
]->close();
820 m_view
[SecondaryIdx
]->deleteLater();
821 m_view
[SecondaryIdx
] = 0;
822 setActiveView(m_view
[PrimaryIdx
]);
825 // The secondary view is active, hence from the users point of view
826 // the content of the secondary view should be moved to the primary view.
827 // From an implementation point of view it is more efficient to close
828 // the primary view and exchange the internal pointers afterwards.
829 m_view
[PrimaryIdx
]->close();
830 m_view
[PrimaryIdx
]->deleteLater();
831 m_view
[PrimaryIdx
] = m_view
[SecondaryIdx
];
832 m_view
[SecondaryIdx
] = 0;
833 setActiveView(m_view
[PrimaryIdx
]);
838 void Dolphin::reloadView()
841 m_activeView
->reload();
844 void Dolphin::stopLoading()
848 void Dolphin::showHiddenFiles()
852 const KToggleAction
* showHiddenFilesAction
=
853 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
854 const bool show
= showHiddenFilesAction
->isChecked();
855 m_activeView
->setShowHiddenFilesEnabled(show
);
858 void Dolphin::showFilterBar()
860 const KToggleAction
* showFilterBarAction
=
861 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
862 const bool show
= showFilterBarAction
->isChecked();
863 m_activeView
->slotShowFilterBar(show
);
866 void Dolphin::zoomIn()
868 m_activeView
->zoomIn();
872 void Dolphin::zoomOut()
874 m_activeView
->zoomOut();
878 void Dolphin::toggleEditLocation()
882 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
884 bool editOrBrowse
= action
->isChecked();
885 // action->setChecked(action->setChecked);
886 m_activeView
->setUrlEditable(editOrBrowse
);
889 void Dolphin::editLocation()
891 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
892 action
->setChecked(true);
893 m_activeView
->setUrlEditable(true);
896 void Dolphin::adjustViewProperties()
899 ViewPropertiesDialog
dlg(m_activeView
);
903 void Dolphin::goBack()
906 m_activeView
->goBack();
909 void Dolphin::goForward()
912 m_activeView
->goForward();
918 m_activeView
->goUp();
921 void Dolphin::goHome()
924 m_activeView
->goHome();
927 void Dolphin::openTerminal()
929 QString
command("konsole --workdir \"");
930 command
.append(m_activeView
->url().path());
931 command
.append('\"');
933 KRun::runCommand(command
, "Konsole", "konsole");
936 void Dolphin::findFile()
938 KRun::run("kfind", m_activeView
->url());
941 void Dolphin::compareFiles()
943 // The method is only invoked if exactly 2 files have
944 // been selected. The selected files may be:
945 // - both in the primary view
946 // - both in the secondary view
947 // - one in the primary view and the other in the secondary
949 assert(m_view
[PrimaryIdx
] != 0);
953 KUrl::List urls
= m_view
[PrimaryIdx
]->selectedUrls();
955 switch (urls
.count()) {
957 assert(m_view
[SecondaryIdx
] != 0);
958 urls
= m_view
[SecondaryIdx
]->selectedUrls();
959 assert(urls
.count() == 2);
967 assert(m_view
[SecondaryIdx
] != 0);
968 urls
= m_view
[SecondaryIdx
]->selectedUrls();
969 assert(urls
.count() == 1);
981 // may not happen: compareFiles may only get invoked if 2
982 // files are selected
987 QString
command("kompare -c \"");
988 command
.append(urlA
.pathOrUrl());
989 command
.append("\" \"");
990 command
.append(urlB
.pathOrUrl());
991 command
.append('\"');
992 KRun::runCommand(command
, "Kompare", "kompare");
996 void Dolphin::editSettings()
998 // TODO: make a static method for opening the settings dialog
999 DolphinSettingsDialog dlg
;
1003 void Dolphin::addUndoOperation(KIO::Job
* job
)
1005 if (job
->error() != 0) {
1006 slotHandleJobError(job
);
1009 const int id
= job
->progressId();
1011 // set iterator to the executed command with the current id...
1012 Q3ValueList
<UndoInfo
>::Iterator it
= m_pendingUndoJobs
.begin();
1013 const Q3ValueList
<UndoInfo
>::Iterator end
= m_pendingUndoJobs
.end();
1015 while (!found
&& (it
!= end
)) {
1016 if ((*it
).id
== id
) {
1025 DolphinCommand command
= (*it
).command
;
1026 if (command
.type() == DolphinCommand::Trash
) {
1027 // To be able to perform an undo for the 'Move to Trash' operation
1028 // all source Urls must be updated with the trash Url. E. g. when moving
1029 // a file "test.txt" and a second file "test.txt" to the trash,
1030 // then the filenames in the trash are "0-test.txt" and "1-test.txt".
1031 QMap
<QString
, QString
> metaData
= job
->metaData();
1032 KUrl::List newSourceUrls
;
1034 KUrl::List sourceUrls
= command
.source();
1035 KUrl::List::Iterator sourceIt
= sourceUrls
.begin();
1036 const KUrl::List::Iterator sourceEnd
= sourceUrls
.end();
1038 while (sourceIt
!= sourceEnd
) {
1039 QMap
<QString
, QString
>::ConstIterator metaIt
= metaData
.find("trashUrl-" + (*sourceIt
).path());
1040 if (metaIt
!= metaData
.end()) {
1041 newSourceUrls
.append(KUrl(metaIt
.data()));
1045 command
.setSource(newSourceUrls
);
1048 UndoManager::instance().addCommand(command
);
1049 m_pendingUndoJobs
.erase(it
);
1051 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
1052 switch (command
.type()) {
1053 case DolphinCommand::Copy
:
1054 statusBar
->setMessage(i18n("Copy operation completed."),
1055 DolphinStatusBar::OperationCompleted
);
1057 case DolphinCommand::Move
:
1058 statusBar
->setMessage(i18n("Move operation completed."),
1059 DolphinStatusBar::OperationCompleted
);
1061 case DolphinCommand::Trash
:
1062 statusBar
->setMessage(i18n("Move to trash operation completed."),
1063 DolphinStatusBar::OperationCompleted
);
1072 void Dolphin::toggleSidebar()
1074 if (m_sidebar
== 0) {
1081 KToggleAction
* sidebarAction
= static_cast<KToggleAction
*>(actionCollection()->action("sidebar"));
1082 sidebarAction
->setChecked(m_sidebar
!= 0);
1085 void Dolphin::closeSidebar()
1087 if (m_sidebar
== 0) {
1088 // the sidebar has already been closed
1092 // store width of sidebar and remember that the sidebar has been closed
1093 SidebarSettings
* settings
= DolphinSettings::instance().sidebarSettings();
1094 settings
->setVisible(false);
1095 settings
->setWidth(m_sidebar
->width());
1097 m_sidebar
->deleteLater();
1101 Dolphin::Dolphin() :
1102 KMainWindow(0, "Dolphin"),
1106 m_clipboardContainsCutData(false)
1108 m_view
[PrimaryIdx
] = 0;
1109 m_view
[SecondaryIdx
] = 0;
1111 m_fileGroupActions
.setAutoDelete(true);
1113 // TODO: the following members are not used yet. See documentation
1114 // of Dolphin::linkGroupActions() and Dolphin::linkToDeviceActions()
1115 // in the header file for details.
1116 //m_linkGroupActions.setAutoDelete(true);
1117 //m_linkToDeviceActions.setAutoDelete(true);
1120 void Dolphin::init()
1122 // Check whether Dolphin runs the first time. If yes then
1123 // a proper default window size is given at the end of Dolphin::init().
1124 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
1125 const bool firstRun
= generalSettings
->firstRun();
1127 setAcceptDrops(true);
1129 m_splitter
= new QSplitter(this);
1131 DolphinSettings
& settings
= DolphinSettings::instance();
1133 KBookmarkManager
* manager
= settings
.bookmarkManager();
1134 assert(manager
!= 0);
1135 KBookmarkGroup root
= manager
->root();
1136 if (root
.first().isNull()) {
1137 root
.addBookmark(manager
, i18n("Home"), settings
.generalSettings()->homeUrl(), "folder_home");
1138 root
.addBookmark(manager
, i18n("Storage Media"), KUrl("media:/"), "blockdevice");
1139 root
.addBookmark(manager
, i18n("Network"), KUrl("remote:/"), "network_local");
1140 root
.addBookmark(manager
, i18n("Root"), KUrl("/"), "folder_red");
1141 root
.addBookmark(manager
, i18n("Trash"), KUrl("trash:/"), "trashcan_full");
1145 setupGUI(Keys
|Save
|Create
|ToolBar
);
1147 const KUrl
& homeUrl
= root
.first().url();
1148 setCaption(homeUrl
.fileName());
1149 ViewProperties
props(homeUrl
);
1150 m_view
[PrimaryIdx
] = new DolphinView(m_splitter
,
1153 props
.isShowHiddenFilesEnabled());
1155 m_activeView
= m_view
[PrimaryIdx
];
1157 setCentralWidget(m_splitter
);
1160 SidebarSettings
* sidebarSettings
= settings
.sidebarSettings();
1161 assert(sidebarSettings
!= 0);
1162 if (sidebarSettings
->visible()) {
1168 stateChanged("new_file");
1169 setAutoSaveSettings();
1171 QClipboard
* clipboard
= QApplication::clipboard();
1172 connect(clipboard
, SIGNAL(dataChanged()),
1173 this, SLOT(updatePasteAction()));
1174 updatePasteAction();
1177 setupCreateNewMenuActions();
1182 // assure a proper default size if Dolphin runs the first time
1187 void Dolphin::loadSettings()
1189 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
1191 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1192 if (settings
->splitView()) {
1193 splitAction
->setChecked(true);
1197 updateViewActions();
1200 void Dolphin::setupActions()
1202 // setup 'File' menu
1203 KAction
* createFolder
= new KAction(i18n("Folder..."), actionCollection(), "create_folder");
1204 createFolder
->setIcon(KIcon("folder"));
1205 createFolder
->setShortcut(Qt::Key_N
);
1206 connect(createFolder
, SIGNAL(triggered()), this, SLOT(createFolder()));
1208 KAction
* rename
= new KAction(i18n("Rename"), actionCollection(), "rename");
1209 rename
->setShortcut(Qt::Key_F2
);
1210 connect(rename
, SIGNAL(triggered()), this, SLOT(rename()));
1212 KAction
* moveToTrash
= new KAction(i18n("Move to Trash"), actionCollection(), "move_to_trash");
1213 moveToTrash
->setIcon(KIcon("edittrash"));
1214 moveToTrash
->setShortcut(QKeySequence::Delete
);
1215 connect(moveToTrash
, SIGNAL(triggered()), this, SLOT(moveToTrash()));
1217 KAction
* deleteAction
= new KAction(i18n("Delete"), actionCollection(), "delete");
1218 deleteAction
->setShortcut(Qt::ALT
| Qt::Key_Delete
);
1219 deleteAction
->setIcon(KIcon("editdelete"));
1220 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(deleteItems()));
1222 KAction
* properties
= new KAction(i18n("Propert&ies"), actionCollection(), "properties");
1223 properties
->setShortcut(Qt::Key_Alt
| Qt::Key_Return
);
1224 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
1226 KStdAction::quit(this, SLOT(quit()), actionCollection());
1228 // setup 'Edit' menu
1229 UndoManager
& undoManager
= UndoManager::instance();
1230 KStdAction::undo(&undoManager
,
1232 actionCollection());
1233 connect(&undoManager
, SIGNAL(undoAvailable(bool)),
1234 this, SLOT(slotUndoAvailable(bool)));
1235 connect(&undoManager
, SIGNAL(undoTextChanged(const QString
&)),
1236 this, SLOT(slotUndoTextChanged(const QString
&)));
1238 KStdAction::redo(&undoManager
,
1240 actionCollection());
1241 connect(&undoManager
, SIGNAL(redoAvailable(bool)),
1242 this, SLOT(slotRedoAvailable(bool)));
1243 connect(&undoManager
, SIGNAL(redoTextChanged(const QString
&)),
1244 this, SLOT(slotRedoTextChanged(const QString
&)));
1246 KStdAction::cut(this, SLOT(cut()), actionCollection());
1247 KStdAction::copy(this, SLOT(copy()), actionCollection());
1248 KStdAction::paste(this, SLOT(paste()), actionCollection());
1250 KAction
* selectAll
= new KAction(i18n("Select All"), actionCollection(), "select_all");
1251 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1252 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1254 KAction
* invertSelection
= new KAction(i18n("Invert Selection"), actionCollection(), "invert_selection");
1255 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1256 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1258 // setup 'View' menu
1259 KStdAction::zoomIn(this,
1261 actionCollection());
1263 KStdAction::zoomOut(this,
1265 actionCollection());
1267 KToggleAction
* iconsView
= new KToggleAction(i18n("Icons"), actionCollection(), "icons");
1268 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
1269 iconsView
->setIcon(KIcon("view_icon"));
1270 connect(iconsView
, SIGNAL(triggered()), this, SLOT(setIconsView()));
1272 KToggleAction
* detailsView
= new KToggleAction(i18n("Details"), actionCollection(), "details");
1273 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
1274 detailsView
->setIcon(KIcon("view_text"));
1275 connect(detailsView
, SIGNAL(triggered()), this, SLOT(setDetailsView()));
1277 KToggleAction
* previewsView
= new KToggleAction(i18n("Previews"), actionCollection(), "previews");
1278 previewsView
->setShortcut(Qt::CTRL
| Qt::Key_3
);
1279 previewsView
->setIcon(KIcon("gvdirpart"));
1280 connect(previewsView
, SIGNAL(triggered()), this, SLOT(setPreviewsView()));
1282 QActionGroup
* viewModeGroup
= new QActionGroup(this);
1283 viewModeGroup
->addAction(iconsView
);
1284 viewModeGroup
->addAction(detailsView
);
1285 viewModeGroup
->addAction(previewsView
);
1287 KToggleAction
* sortByName
= new KToggleAction(i18n("By Name"), actionCollection(), "by_name");
1288 connect(sortByName
, SIGNAL(triggered()), this, SLOT(sortByName()));
1290 KToggleAction
* sortBySize
= new KToggleAction(i18n("By Size"), actionCollection(), "by_size");
1291 connect(sortBySize
, SIGNAL(triggered()), this, SLOT(sortBySize()));
1293 KToggleAction
* sortByDate
= new KToggleAction(i18n("By Date"), actionCollection(), "by_date");
1294 connect(sortByDate
, SIGNAL(triggered()), this, SLOT(sortByDate()));
1296 QActionGroup
* sortGroup
= new QActionGroup(this);
1297 sortGroup
->addAction(sortByName
);
1298 sortGroup
->addAction(sortBySize
);
1299 sortGroup
->addAction(sortByDate
);
1301 KToggleAction
* sortDescending
= new KToggleAction(i18n("Descending"), actionCollection(), "descending");
1302 connect(sortDescending
, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
1304 KToggleAction
* showHiddenFiles
= new KToggleAction(i18n("Show Hidden Files"), actionCollection(), "show_hidden_files");
1305 //showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_ KDE4-TODO: what Qt-Key represents '.'?
1306 connect(showHiddenFiles
, SIGNAL(triggered()), this, SLOT(showHiddenFiles()));
1308 KToggleAction
* split
= new KToggleAction(i18n("Split View"), actionCollection(), "split_view");
1309 split
->setShortcut(Qt::Key_F10
);
1310 split
->setIcon(KIcon("view_left_right"));
1311 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1313 KAction
* reload
= new KAction(i18n("Reload"), "F5", actionCollection(), "reload");
1314 reload
->setShortcut(Qt::Key_F5
);
1315 reload
->setIcon(KIcon("reload"));
1316 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1318 KAction
* stop
= new KAction(i18n("Stop"), actionCollection(), "stop");
1319 stop
->setIcon(KIcon("stop"));
1320 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1322 KToggleAction
* showFullLocation
= new KToggleAction(i18n("Show Full Location"), actionCollection(), "editable_location");
1323 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1324 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1326 KToggleAction
* editLocation
= new KToggleAction(i18n("Edit Location"), actionCollection(), "edit_location");
1327 editLocation
->setShortcut(Qt::Key_F6
);
1328 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
1330 KToggleAction
* sidebar
= new KToggleAction(i18n("Sidebar"), actionCollection(), "sidebar");
1331 sidebar
->setShortcut(Qt::Key_F9
);
1332 connect(sidebar
, SIGNAL(triggered()), this, SLOT(toggleSidebar()));
1334 KAction
* adjustViewProps
= new KAction(i18n("Adjust View Properties..."), actionCollection(), "view_properties");
1335 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1338 KStdAction::back(this, SLOT(goBack()), actionCollection());
1339 KStdAction::forward(this, SLOT(goForward()), actionCollection());
1340 KStdAction::up(this, SLOT(goUp()), actionCollection());
1341 KStdAction::home(this, SLOT(goHome()), actionCollection());
1343 // setup 'Tools' menu
1344 KAction
* openTerminal
= new KAction(i18n("Open Terminal"), actionCollection(), "open_terminal");
1345 openTerminal
->setShortcut(Qt::Key_F4
);
1346 openTerminal
->setIcon(KIcon("konsole"));
1347 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1349 KAction
* findFile
= new KAction(i18n("Find File..."), actionCollection(), "find_file");
1350 findFile
->setShortcut(Qt::Key_F
);
1351 findFile
->setIcon(KIcon("filefind"));
1352 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
1354 KToggleAction
* showFilterBar
= new KToggleAction(i18n("Show Filter Bar"), actionCollection(), "show_filter_bar");
1355 showFilterBar
->setShortcut(Qt::Key_Slash
);
1356 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1358 KAction
* compareFiles
= new KAction(i18n("Compare Files"), actionCollection(), "compare_files");
1359 compareFiles
->setIcon(KIcon("kompare"));
1360 compareFiles
->setEnabled(false);
1361 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1363 // setup 'Settings' menu
1364 KStdAction::preferences(this, SLOT(editSettings()), actionCollection());
1367 void Dolphin::setupCreateNewMenuActions()
1369 // Parts of the following code have been taken
1370 // from the class KNewMenu located in
1371 // libqonq/knewmenu.h of Konqueror.
1372 // Copyright (C) 1998, 1999 David Faure <faure@kde.org>
1373 // 2003 Sven Leiber <s.leiber@web.de>
1375 QStringList files
= actionCollection()->instance()->dirs()->findAllResources("templates");
1376 for (QStringList::Iterator it
= files
.begin() ; it
!= files
.end(); ++it
) {
1377 if ((*it
)[0] != '.' ) {
1378 KSimpleConfig
config(*it
, true);
1379 config
.setDesktopGroup();
1381 // tricky solution to ensure that TextFile is at the beginning
1382 // because this filetype is the most used (according kde-core discussion)
1383 const QString
name(config
.readEntry("Name"));
1386 const QString
path(config
.readPathEntry("Url"));
1387 if (!path
.endsWith("emptydir")) {
1388 if (path
.endsWith("TextFile.txt")) {
1391 else if (!KDesktopFile::isDesktopFile(path
)) {
1394 else if (path
.endsWith("Url.desktop")){
1397 else if (path
.endsWith("Program.desktop")){
1404 const QString
icon(config
.readEntry("Icon"));
1405 const QString
comment(config
.readEntry("Comment"));
1406 const QString
type(config
.readEntry("Type"));
1408 const QString
filePath(*it
);
1411 if (type
== "Link") {
1412 CreateFileEntry entry
;
1415 entry
.comment
= comment
;
1416 entry
.templatePath
= filePath
;
1417 m_createFileTemplates
.insert(key
, entry
);
1422 m_createFileTemplates
.sort();
1424 unplugActionList("create_actions");
1425 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
1426 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
1427 /* KDE4-TODO: don't port this code; use KNewMenu instead
1429 CreateFileEntry entry = (*it).value();
1430 KAction* action = new KAction(entry.name);
1431 action->setIcon(entry.icon);
1432 action->setName((*it).index());
1433 connect(action, SIGNAL(activated()),
1434 this, SLOT(createFile()));
1436 const QChar section = ((*it).index()[0]);
1440 m_fileGroupActions.append(action);
1446 // TODO: not used yet. See documentation of Dolphin::linkGroupActions()
1447 // and Dolphin::linkToDeviceActions() in the header file for details.
1448 //m_linkGroupActions.append(action);
1453 // TODO: not used yet. See documentation of Dolphin::linkGroupActions()
1454 // and Dolphin::linkToDeviceActions() in the header file for details.
1455 //m_linkToDeviceActions.append(action);
1464 plugActionList("create_file_group", m_fileGroupActions);
1465 //plugActionList("create_link_group", m_linkGroupActions);
1466 //plugActionList("link_to_device", m_linkToDeviceActions);*/
1469 void Dolphin::updateHistory()
1472 const Q3ValueList
<UrlNavigator::HistoryElem
> list
= m_activeView
->urlHistory(index
);
1474 KAction
* backAction
= actionCollection()->action("go_back");
1475 if (backAction
!= 0) {
1476 backAction
->setEnabled(index
< static_cast<int>(list
.count()) - 1);
1479 KAction
* forwardAction
= actionCollection()->action("go_forward");
1480 if (forwardAction
!= 0) {
1481 forwardAction
->setEnabled(index
> 0);
1485 void Dolphin::updateEditActions()
1487 const KFileItemList
* list
= m_activeView
->selectedItems();
1488 if ((list
== 0) || (*list
).isEmpty()) {
1489 stateChanged("has_no_selection");
1492 stateChanged("has_selection");
1494 KAction
* renameAction
= actionCollection()->action("rename");
1495 if (renameAction
!= 0) {
1496 renameAction
->setEnabled(list
->count() >= 1);
1499 bool enableMoveToTrash
= true;
1501 KFileItemList::const_iterator it
= list
->begin();
1502 const KFileItemList::const_iterator end
= list
->end();
1504 KFileItem
* item
= *it
;
1505 const KUrl
& url
= item
->url();
1506 // only enable the 'Move to Trash' action for local files
1507 if (!url
.isLocalFile()) {
1508 enableMoveToTrash
= false;
1513 KAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
1514 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1516 updatePasteAction();
1519 void Dolphin::updateViewActions()
1521 KAction
* zoomInAction
= actionCollection()->action(KStdAction::stdName(KStdAction::ZoomIn
));
1522 if (zoomInAction
!= 0) {
1523 zoomInAction
->setEnabled(m_activeView
->isZoomInPossible());
1526 KAction
* zoomOutAction
= actionCollection()->action(KStdAction::stdName(KStdAction::ZoomOut
));
1527 if (zoomOutAction
!= 0) {
1528 zoomOutAction
->setEnabled(m_activeView
->isZoomOutPossible());
1531 KAction
* action
= 0;
1532 switch (m_activeView
->mode()) {
1533 case DolphinView::IconsView
:
1534 action
= actionCollection()->action("icons");
1536 case DolphinView::DetailsView
:
1537 action
= actionCollection()->action("details");
1539 case DolphinView::PreviewsView
:
1540 action
= actionCollection()->action("previews");
1547 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
1548 toggleAction
->setChecked(true);
1551 slotSortingChanged(m_activeView
->sorting());
1552 slotSortOrderChanged(m_activeView
->sortOrder());
1554 KToggleAction
* showFilterBarAction
=
1555 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
1556 showFilterBarAction
->setChecked(m_activeView
->isFilterBarVisible());
1558 KToggleAction
* showHiddenFilesAction
=
1559 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
1560 showHiddenFilesAction
->setChecked(m_activeView
->isShowHiddenFilesEnabled());
1562 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1563 splitAction
->setChecked(m_view
[SecondaryIdx
] != 0);
1565 KToggleAction
* sidebarAction
= static_cast<KToggleAction
*>(actionCollection()->action("sidebar"));
1566 sidebarAction
->setChecked(m_sidebar
!= 0);
1569 void Dolphin::updateGoActions()
1571 KAction
* goUpAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Up
));
1572 const KUrl
& currentUrl
= m_activeView
->url();
1573 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1576 void Dolphin::updateViewProperties(const KUrl::List
& urls
)
1578 if (urls
.isEmpty()) {
1582 // Updating the view properties might take up to several seconds
1583 // when dragging several thousand Urls. Writing a KIO slave for this
1584 // use case is not worth the effort, but at least the main widget
1585 // must be disabled and a progress should be shown.
1586 ProgressIndicator
progressIndicator(i18n("Updating view properties..."),
1590 KUrl::List::ConstIterator end
= urls
.end();
1591 for(KUrl::List::ConstIterator it
= urls
.begin(); it
!= end
; ++it
) {
1592 progressIndicator
.execOperation();
1594 ViewProperties
props(*it
);
1599 void Dolphin::copyUrls(const KUrl::List
& source
, const KUrl
& dest
)
1601 KIO::Job
* job
= KIO::copy(source
, dest
);
1602 addPendingUndoJob(job
, DolphinCommand::Copy
, source
, dest
);
1605 void Dolphin::moveUrls(const KUrl::List
& source
, const KUrl
& dest
)
1607 KIO::Job
* job
= KIO::move(source
, dest
);
1608 addPendingUndoJob(job
, DolphinCommand::Move
, source
, dest
);
1611 void Dolphin::addPendingUndoJob(KIO::Job
* job
,
1612 DolphinCommand::Type commandType
,
1613 const KUrl::List
& source
,
1616 connect(job
, SIGNAL(result(KIO::Job
*)),
1617 this, SLOT(addUndoOperation(KIO::Job
*)));
1620 undoInfo
.id
= job
->progressId();
1621 undoInfo
.command
= DolphinCommand(commandType
, source
, dest
);
1622 m_pendingUndoJobs
.append(undoInfo
);
1625 void Dolphin::clearStatusBar()
1627 m_activeView
->statusBar()->clear();
1630 void Dolphin::openSidebar()
1632 if (m_sidebar
!= 0) {
1633 // the sidebar is already open
1637 m_sidebar
= new Sidebar(m_splitter
);
1640 connect(m_sidebar
, SIGNAL(urlChanged(const KUrl
&)),
1641 this, SLOT(slotUrlChangeRequest(const KUrl
&)));
1642 m_splitter
->setCollapsible(m_sidebar
, false);
1643 m_splitter
->setResizeMode(m_sidebar
, QSplitter::KeepSize
);
1644 m_splitter
->moveToFirst(m_sidebar
);
1646 SidebarSettings
* settings
= DolphinSettings::instance().sidebarSettings();
1647 settings
->setVisible(true);
1650 #include "dolphin.moc"