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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
22 #include <config-kmetadata.h>
23 #include "dolphinmainwindow.h"
27 #include "dolphinapplication.h"
28 #include "dolphinnewmenu.h"
29 #include "dolphinsettings.h"
30 #include "dolphinsettingsdialog.h"
31 #include "dolphinstatusbar.h"
32 #include "dolphinapplication.h"
33 #include "urlnavigator.h"
34 #include "dolphinsettings.h"
35 #include "bookmarkssidebarpage.h"
36 #include "infosidebarpage.h"
37 #include "dolphin_generalsettings.h"
38 #include "viewpropertiesdialog.h"
39 #include "viewproperties.h"
40 #include "metadataloader.h"
41 #include "mainwindowadaptor.h"
44 #include <kactioncollection.h>
45 #include <kbookmarkmanager.h>
47 #include <kdesktopfile.h>
48 #include <kdeversion.h>
49 #include <kfiledialog.h>
52 #include <kiconloader.h>
53 #include <kio/netaccess.h>
54 #include <kio/deletejob.h>
55 #include <kio/renamedialog.h>
56 #include <kinputdialog.h>
59 #include <kmessagebox.h>
60 #include <konqmimedata.h>
61 #include <kpropertiesdialog.h>
62 #include <kprotocolinfo.h>
63 #include <ktoggleaction.h>
66 #include <kstandarddirs.h>
67 #include <kstatusbar.h>
68 #include <kstandardaction.h>
71 #include <QCloseEvent>
74 #include <QDockWidget>
76 DolphinMainWindow::DolphinMainWindow(int id
) :
83 setObjectName("Dolphin");
84 m_view
[PrimaryIdx
] = 0;
85 m_view
[SecondaryIdx
] = 0;
87 new MainWindowAdaptor(this);
88 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
90 KonqUndoManager::incRef();
92 KonqUndoManager
* undoManager
= KonqUndoManager::self();
93 undoManager
->setUiInterface(new UndoUiInterface(this));
95 connect(undoManager
, SIGNAL(undoAvailable(bool)),
96 this, SLOT(slotUndoAvailable(bool)));
97 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
98 this, SLOT(slotUndoTextChanged(const QString
&)));
101 DolphinMainWindow::~DolphinMainWindow()
103 KonqUndoManager::decRef();
104 DolphinApplication::app()->removeMainWindow(this);
107 void DolphinMainWindow::setActiveView(DolphinView
* view
)
109 assert((view
== m_view
[PrimaryIdx
]) || (view
== m_view
[SecondaryIdx
]));
110 if (m_activeView
== view
) {
121 setCaption(m_activeView
->url().fileName());
123 emit
activeViewChanged();
126 void DolphinMainWindow::dropUrls(const KUrl::List
& urls
,
127 const KUrl
& destination
)
129 Qt::DropAction action
= Qt::CopyAction
;
131 Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
132 const bool shiftPressed
= modifier
& Qt::ShiftModifier
;
133 const bool controlPressed
= modifier
& Qt::ControlModifier
;
134 if (shiftPressed
&& controlPressed
) {
135 // shortcut for 'Link Here' is used
136 action
= Qt::LinkAction
;
138 else if (shiftPressed
) {
139 // shortcut for 'Move Here' is used
140 action
= Qt::MoveAction
;
142 else if (controlPressed
) {
143 // shortcut for 'Copy Here' is used
144 action
= Qt::CopyAction
;
147 // open a context menu which offers the following actions:
155 QString seq
= QKeySequence(Qt::ShiftModifier
).toString();
156 seq
.chop(1); // chop superfluous '+'
157 QAction
* moveAction
= popup
.addAction(KIcon("goto"),
158 i18n("&Move Here") + '\t' + seq
);
160 seq
= QKeySequence(Qt::ControlModifier
).toString();
162 QAction
* copyAction
= popup
.addAction(KIcon("editcopy"),
163 i18n("&Copy Here") + '\t' + seq
);
165 seq
= QKeySequence(Qt::ControlModifier
+ Qt::ShiftModifier
).toString();
167 QAction
* linkAction
= popup
.addAction(KIcon("www"),
168 i18n("&Link Here") + '\t' + seq
);
170 popup
.addSeparator();
171 popup
.addAction(KIcon("stop"), i18n("Cancel"));
173 QAction
* activatedAction
= popup
.exec(QCursor::pos());
174 if (activatedAction
== moveAction
) {
175 action
= Qt::MoveAction
;
177 else if (activatedAction
== copyAction
) {
178 action
= Qt::CopyAction
;
180 else if (activatedAction
== linkAction
) {
181 action
= Qt::LinkAction
;
190 moveUrls(urls
, destination
);
194 copyUrls(urls
, destination
);
198 linkUrls(urls
, destination
);
206 void DolphinMainWindow::refreshViews()
208 const bool split
= DolphinSettings::instance().generalSettings()->splitView();
209 const bool isPrimaryViewActive
= (m_activeView
== m_view
[PrimaryIdx
]);
211 for (int i
= PrimaryIdx
; i
<= SecondaryIdx
; ++i
) {
212 if (m_view
[i
] != 0) {
213 url
= m_view
[i
]->url();
215 // delete view instance...
217 m_view
[i
]->deleteLater();
221 if (split
|| (i
== PrimaryIdx
)) {
222 // ... and recreate it
223 ViewProperties
props(url
);
224 m_view
[i
] = new DolphinView(this,
228 props
.showHiddenFiles());
229 connectViewSignals(i
);
234 m_activeView
= isPrimaryViewActive
? m_view
[PrimaryIdx
] : m_view
[SecondaryIdx
];
235 assert(m_activeView
!= 0);
238 emit
activeViewChanged();
241 void DolphinMainWindow::changeUrl(const QString
& url
)
243 if (activeView() != 0) {
244 activeView()->setUrl(KUrl(url
));
248 void DolphinMainWindow::slotViewModeChanged()
253 void DolphinMainWindow::slowShowPreviewChanged()
255 KToggleAction
* showPreviewAction
=
256 static_cast<KToggleAction
*>(actionCollection()->action("show_preview"));
257 showPreviewAction
->setChecked(m_activeView
->showPreview());
260 void DolphinMainWindow::slotShowHiddenFilesChanged()
262 KToggleAction
* showHiddenFilesAction
=
263 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
264 showHiddenFilesAction
->setChecked(m_activeView
->showHiddenFiles());
267 void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting
)
271 case DolphinView::SortByName
:
272 action
= actionCollection()->action("by_name");
274 case DolphinView::SortBySize
:
275 action
= actionCollection()->action("by_size");
277 case DolphinView::SortByDate
:
278 action
= actionCollection()->action("by_date");
280 case DolphinView::SortByPermissions
:
281 action
= actionCollection()->action("by_permissions");
283 case DolphinView::SortByOwner
:
284 action
= actionCollection()->action("by_owner");
286 case DolphinView::SortByGroup
:
287 action
= actionCollection()->action("by_group");
294 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
295 toggleAction
->setChecked(true);
299 void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order
)
301 KToggleAction
* descending
= static_cast<KToggleAction
*>(actionCollection()->action("descending"));
302 const bool sortDescending
= (order
== Qt::Descending
);
303 descending
->setChecked(sortDescending
);
306 void DolphinMainWindow::slotSelectionChanged()
310 assert(m_view
[PrimaryIdx
] != 0);
311 int selectedUrlsCount
= m_view
[PrimaryIdx
]->selectedUrls().count();
312 if (m_view
[SecondaryIdx
] != 0) {
313 selectedUrlsCount
+= m_view
[SecondaryIdx
]->selectedUrls().count();
316 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
317 compareFilesAction
->setEnabled(selectedUrlsCount
== 2);
319 m_activeView
->updateStatusBar();
321 emit
selectionChanged();
324 void DolphinMainWindow::slotHistoryChanged()
329 void DolphinMainWindow::slotUrlChanged(const KUrl
& url
)
333 setCaption(url
.fileName());
336 void DolphinMainWindow::updateFilterBarAction(bool show
)
338 KToggleAction
* showFilterBarAction
=
339 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
340 showFilterBarAction
->setChecked(show
);
343 void DolphinMainWindow::openNewMainWindow()
345 DolphinApplication::app()->createMainWindow()->show();
348 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
350 DolphinSettings
& settings
= DolphinSettings::instance();
351 GeneralSettings
* generalSettings
= settings
.generalSettings();
352 generalSettings
->setFirstRun(false);
356 // TODO: I assume there will be a generic way in KDE 4 to store the docks
357 // of the main window. In the meantime they are stored manually:
358 QString filename
= KStandardDirs::locateLocal("data", KGlobal::mainComponent().componentName());
359 filename
.append("/panels_layout");
360 QFile
file(filename
);
361 if (file
.open(QIODevice::WriteOnly
)) {
362 QByteArray data
= saveState();
367 KMainWindow::closeEvent(event
);
370 void DolphinMainWindow::saveProperties(KConfig
* config
)
372 KConfigGroup primaryView
= config
->group("Primary view");
373 primaryView
.writeEntry("Url", m_view
[PrimaryIdx
]->url().url());
374 primaryView
.writeEntry("Editable Url", m_view
[PrimaryIdx
]->isUrlEditable());
375 if (m_view
[SecondaryIdx
] != 0) {
376 KConfigGroup secondaryView
= config
->group("Secondary view");
377 secondaryView
.writeEntry("Url", m_view
[SecondaryIdx
]->url().url());
378 secondaryView
.writeEntry("Editable Url", m_view
[SecondaryIdx
]->isUrlEditable());
382 void DolphinMainWindow::readProperties(KConfig
* config
)
384 const KConfigGroup primaryView
= config
->group("Primary view");
385 m_view
[PrimaryIdx
]->setUrl(primaryView
.readEntry("Url"));
386 m_view
[PrimaryIdx
]->setUrlEditable(primaryView
.readEntry("Editable Url", false));
387 if (config
->hasGroup("Secondary view")) {
388 const KConfigGroup secondaryView
= config
->group("Secondary view");
389 if (m_view
[SecondaryIdx
] == 0) {
392 m_view
[SecondaryIdx
]->setUrl(secondaryView
.readEntry("Url"));
393 m_view
[SecondaryIdx
]->setUrlEditable(secondaryView
.readEntry("Editable Url", false));
395 else if (m_view
[SecondaryIdx
] != 0) {
400 void DolphinMainWindow::updateNewMenu()
402 m_newMenu
->slotCheckUpToDate();
403 m_newMenu
->setPopupFiles(activeView()->url());
406 void DolphinMainWindow::rename()
409 m_activeView
->renameSelectedItems();
412 void DolphinMainWindow::moveToTrash()
415 const KUrl::List selectedUrls
= m_activeView
->selectedUrls();
416 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls
);
417 m_undoOperations
.append(KonqOperations::TRASH
);
420 void DolphinMainWindow::deleteItems()
424 KUrl::List list
= m_activeView
->selectedUrls();
425 const uint itemCount
= list
.count();
426 assert(itemCount
>= 1);
430 text
= i18n("Do you really want to delete the %1 selected items?",itemCount
);
433 const KUrl
& url
= list
.first();
434 text
= i18n("Do you really want to delete '%1'?",url
.fileName());
437 const bool del
= KMessageBox::warningContinueCancel(this,
440 KGuiItem(i18n("Delete"), KIcon("editdelete"))
441 ) == KMessageBox::Continue
;
443 KIO::Job
* job
= KIO::del(list
);
444 connect(job
, SIGNAL(result(KJob
*)),
445 this, SLOT(slotHandleJobError(KJob
*)));
446 connect(job
, SIGNAL(result(KJob
*)),
447 this, SLOT(slotDeleteFileFinished(KJob
*)));
451 void DolphinMainWindow::properties()
453 const KFileItemList list
= m_activeView
->selectedItems();
454 new KPropertiesDialog(list
, this);
457 void DolphinMainWindow::quit()
462 void DolphinMainWindow::slotHandleJobError(KJob
* job
)
464 if (job
->error() != 0) {
465 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
466 statusBar
->setMessage(job
->errorString(),
467 DolphinStatusBar::Error
);
471 void DolphinMainWindow::slotDeleteFileFinished(KJob
* job
)
473 if (job
->error() == 0) {
474 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
475 statusBar
->setMessage(i18n("Delete operation completed."),
476 DolphinStatusBar::OperationCompleted
);
480 void DolphinMainWindow::slotUndoAvailable(bool available
)
482 QAction
* undoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo
));
483 if (undoAction
!= 0) {
484 undoAction
->setEnabled(available
);
487 if (available
&& (m_undoOperations
.count() > 0)) {
488 const KonqOperations::Operation op
= m_undoOperations
.takeFirst();
489 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
491 case KonqOperations::COPY
:
492 statusBar
->setMessage(i18n("Copy operation completed."),
493 DolphinStatusBar::OperationCompleted
);
495 case KonqOperations::MOVE
:
496 statusBar
->setMessage(i18n("Move operation completed."),
497 DolphinStatusBar::OperationCompleted
);
499 case KonqOperations::LINK
:
500 statusBar
->setMessage(i18n("Link operation completed."),
501 DolphinStatusBar::OperationCompleted
);
503 case KonqOperations::TRASH
:
504 statusBar
->setMessage(i18n("Move to trash operation completed."),
505 DolphinStatusBar::OperationCompleted
);
514 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
516 QAction
* undoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo
));
517 if (undoAction
!= 0) {
518 undoAction
->setText(text
);
522 void DolphinMainWindow::undo()
525 KonqUndoManager::self()->undo();
528 void DolphinMainWindow::cut()
530 QMimeData
* mimeData
= new QMimeData();
531 const KUrl::List kdeUrls
= m_activeView
->selectedUrls();
532 const KUrl::List mostLocalUrls
;
533 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
534 QApplication::clipboard()->setMimeData(mimeData
);
537 void DolphinMainWindow::copy()
539 QMimeData
* mimeData
= new QMimeData();
540 const KUrl::List kdeUrls
= m_activeView
->selectedUrls();
541 const KUrl::List mostLocalUrls
;
542 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
544 QApplication::clipboard()->setMimeData(mimeData
);
547 void DolphinMainWindow::paste()
549 QClipboard
* clipboard
= QApplication::clipboard();
550 const QMimeData
* mimeData
= clipboard
->mimeData();
554 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
556 // per default the pasting is done into the current Url of the view
557 KUrl
destUrl(m_activeView
->url());
559 // check whether the pasting should be done into a selected directory
560 KUrl::List selectedUrls
= m_activeView
->selectedUrls();
561 if (selectedUrls
.count() == 1) {
562 const KFileItem
fileItem(S_IFDIR
,
564 selectedUrls
.first(),
566 if (fileItem
.isDir()) {
567 // only one item is selected which is a directory, hence paste
568 // into this directory
569 destUrl
= selectedUrls
.first();
573 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
574 moveUrls(sourceUrls
, destUrl
);
578 copyUrls(sourceUrls
, destUrl
);
582 void DolphinMainWindow::updatePasteAction()
584 QAction
* pasteAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste
));
585 if (pasteAction
== 0) {
589 QString
text(i18n("Paste"));
590 QClipboard
* clipboard
= QApplication::clipboard();
591 const QMimeData
* mimeData
= clipboard
->mimeData();
593 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
594 if (!urls
.isEmpty()) {
595 pasteAction
->setEnabled(true);
597 const int count
= urls
.count();
599 pasteAction
->setText(i18n("Paste 1 File"));
602 pasteAction
->setText(i18n("Paste %1 Files", count
));
606 pasteAction
->setEnabled(false);
607 pasteAction
->setText(i18n("Paste"));
610 if (pasteAction
->isEnabled()) {
611 KUrl::List urls
= m_activeView
->selectedUrls();
612 const uint count
= urls
.count();
614 // pasting should not be allowed when more than one file
616 pasteAction
->setEnabled(false);
618 else if (count
== 1) {
619 // Only one file is selected. Pasting is only allowed if this
620 // file is a directory.
621 // TODO: this doesn't work with remote protocols; instead we need a
622 // m_activeView->selectedFileItems() to get the real KFileItems
623 const KFileItem
fileItem(S_IFDIR
,
627 pasteAction
->setEnabled(fileItem
.isDir());
632 void DolphinMainWindow::selectAll()
635 m_activeView
->selectAll();
638 void DolphinMainWindow::invertSelection()
641 m_activeView
->invertSelection();
643 void DolphinMainWindow::setIconsView()
645 m_activeView
->setMode(DolphinView::IconsView
);
648 void DolphinMainWindow::setDetailsView()
650 m_activeView
->setMode(DolphinView::DetailsView
);
653 void DolphinMainWindow::sortByName()
655 m_activeView
->setSorting(DolphinView::SortByName
);
658 void DolphinMainWindow::sortBySize()
660 m_activeView
->setSorting(DolphinView::SortBySize
);
663 void DolphinMainWindow::sortByDate()
665 m_activeView
->setSorting(DolphinView::SortByDate
);
668 void DolphinMainWindow::sortByPermissions()
670 m_activeView
->setSorting(DolphinView::SortByPermissions
);
673 void DolphinMainWindow::sortByOwner()
675 m_activeView
->setSorting(DolphinView::SortByOwner
);
678 void DolphinMainWindow::sortByGroup()
680 m_activeView
->setSorting(DolphinView::SortByGroup
);
683 void DolphinMainWindow::toggleSortOrder()
685 const Qt::SortOrder order
= (m_activeView
->sortOrder() == Qt::Ascending
) ?
688 m_activeView
->setSortOrder(order
);
691 void DolphinMainWindow::toggleSplitView()
693 if (m_view
[SecondaryIdx
] == 0) {
694 const int newWidth
= (m_view
[PrimaryIdx
]->width() - m_splitter
->handleWidth()) / 2;
695 // create a secondary view
696 m_view
[SecondaryIdx
] = new DolphinView(this,
698 m_view
[PrimaryIdx
]->url(),
699 m_view
[PrimaryIdx
]->mode(),
700 m_view
[PrimaryIdx
]->showHiddenFiles());
701 connectViewSignals(SecondaryIdx
);
702 m_splitter
->addWidget(m_view
[SecondaryIdx
]);
703 m_splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
704 m_view
[SecondaryIdx
]->show();
707 // remove secondary view
708 if (m_activeView
== m_view
[PrimaryIdx
]) {
709 m_view
[SecondaryIdx
]->close();
710 m_view
[SecondaryIdx
]->deleteLater();
711 m_view
[SecondaryIdx
] = 0;
712 setActiveView(m_view
[PrimaryIdx
]);
715 // The secondary view is active, hence from the users point of view
716 // the content of the secondary view should be moved to the primary view.
717 // From an implementation point of view it is more efficient to close
718 // the primary view and exchange the internal pointers afterwards.
719 m_view
[PrimaryIdx
]->close();
720 delete m_view
[PrimaryIdx
];
721 m_view
[PrimaryIdx
] = m_view
[SecondaryIdx
];
722 m_view
[SecondaryIdx
] = 0;
723 setActiveView(m_view
[PrimaryIdx
]);
726 emit
activeViewChanged();
729 void DolphinMainWindow::reloadView()
732 m_activeView
->reload();
735 void DolphinMainWindow::stopLoading()
739 void DolphinMainWindow::togglePreview()
743 const KToggleAction
* showPreviewAction
=
744 static_cast<KToggleAction
*>(actionCollection()->action("show_preview"));
745 const bool show
= showPreviewAction
->isChecked();
746 m_activeView
->setShowPreview(show
);
749 void DolphinMainWindow::toggleShowHiddenFiles()
753 const KToggleAction
* showHiddenFilesAction
=
754 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
755 const bool show
= showHiddenFilesAction
->isChecked();
756 m_activeView
->setShowHiddenFiles(show
);
759 void DolphinMainWindow::showFilterBar()
761 const KToggleAction
* showFilterBarAction
=
762 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
763 const bool show
= showFilterBarAction
->isChecked();
764 m_activeView
->showFilterBar(show
);
767 void DolphinMainWindow::zoomIn()
769 m_activeView
->zoomIn();
773 void DolphinMainWindow::zoomOut()
775 m_activeView
->zoomOut();
779 void DolphinMainWindow::toggleEditLocation()
783 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
785 bool editOrBrowse
= action
->isChecked();
786 m_activeView
->setUrlEditable(editOrBrowse
);
789 void DolphinMainWindow::editLocation()
791 m_activeView
->setUrlEditable(true);
794 void DolphinMainWindow::adjustViewProperties()
797 ViewPropertiesDialog
dlg(m_activeView
);
801 void DolphinMainWindow::goBack()
804 m_activeView
->goBack();
807 void DolphinMainWindow::goForward()
810 m_activeView
->goForward();
813 void DolphinMainWindow::goUp()
816 m_activeView
->goUp();
819 void DolphinMainWindow::goHome()
822 m_activeView
->goHome();
825 void DolphinMainWindow::openTerminal()
827 QString
command("konsole --workdir \"");
828 command
.append(m_activeView
->url().path());
829 command
.append('\"');
831 KRun::runCommand(command
, "Konsole", "konsole");
834 void DolphinMainWindow::findFile()
836 KRun::run("kfind", m_activeView
->url());
839 void DolphinMainWindow::compareFiles()
841 // The method is only invoked if exactly 2 files have
842 // been selected. The selected files may be:
843 // - both in the primary view
844 // - both in the secondary view
845 // - one in the primary view and the other in the secondary
847 assert(m_view
[PrimaryIdx
] != 0);
851 KUrl::List urls
= m_view
[PrimaryIdx
]->selectedUrls();
853 switch (urls
.count()) {
855 assert(m_view
[SecondaryIdx
] != 0);
856 urls
= m_view
[SecondaryIdx
]->selectedUrls();
857 assert(urls
.count() == 2);
865 assert(m_view
[SecondaryIdx
] != 0);
866 urls
= m_view
[SecondaryIdx
]->selectedUrls();
867 assert(urls
.count() == 1);
879 // may not happen: compareFiles may only get invoked if 2
880 // files are selected
885 QString
command("kompare -c \"");
886 command
.append(urlA
.pathOrUrl());
887 command
.append("\" \"");
888 command
.append(urlB
.pathOrUrl());
889 command
.append('\"');
890 KRun::runCommand(command
, "Kompare", "kompare");
894 void DolphinMainWindow::editSettings()
896 // TODO: make a static method for opening the settings dialog
897 DolphinSettingsDialog
dlg(this);
901 void DolphinMainWindow::init()
903 // Check whether Dolphin runs the first time. If yes then
904 // a proper default window size is given at the end of DolphinMainWindow::init().
905 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
906 const bool firstRun
= generalSettings
->firstRun();
908 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
911 setAcceptDrops(true);
913 m_splitter
= new QSplitter(this);
915 DolphinSettings
& settings
= DolphinSettings::instance();
917 KBookmarkManager
* manager
= settings
.bookmarkManager();
918 assert(manager
!= 0);
919 KBookmarkGroup root
= manager
->root();
920 if (root
.first().isNull()) {
921 root
.addBookmark(manager
, i18n("Home"), settings
.generalSettings()->homeUrl(), "folder_home");
922 root
.addBookmark(manager
, i18n("Storage Media"), KUrl("media:/"), "blockdevice");
923 root
.addBookmark(manager
, i18n("Network"), KUrl("remote:/"), "network_local");
924 root
.addBookmark(manager
, i18n("Root"), KUrl("/"), "folder_red");
925 root
.addBookmark(manager
, i18n("Trash"), KUrl("trash:/"), "trashcan_full");
930 const KUrl
& homeUrl
= root
.first().url();
931 setCaption(homeUrl
.fileName());
932 ViewProperties
props(homeUrl
);
933 m_view
[PrimaryIdx
] = new DolphinView(this,
937 props
.showHiddenFiles());
938 connectViewSignals(PrimaryIdx
);
939 m_view
[PrimaryIdx
]->show();
941 m_activeView
= m_view
[PrimaryIdx
];
943 setCentralWidget(m_splitter
);
946 setupGUI(Keys
|Save
|Create
|ToolBar
);
949 stateChanged("new_file");
950 setAutoSaveSettings();
952 QClipboard
* clipboard
= QApplication::clipboard();
953 connect(clipboard
, SIGNAL(dataChanged()),
954 this, SLOT(updatePasteAction()));
961 // assure a proper default size if Dolphin runs the first time
964 #ifdef HAVE_KMETADATA
965 if (!DolphinApplication::app()->metadataLoader()->storageUp())
966 activeView()->statusBar()->setMessage(i18n("Failed to contact Nepomuk service, annotation and tagging are disabled."), DolphinStatusBar::Error
);
970 void DolphinMainWindow::loadSettings()
972 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
974 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
975 if (settings
->splitView()) {
976 splitAction
->setChecked(true);
982 // TODO: I assume there will be a generic way in KDE 4 to restore the docks
983 // of the main window. In the meantime they are restored manually (see also
984 // DolphinMainWindow::closeEvent() for more details):
985 QString filename
= KStandardDirs::locateLocal("data", KGlobal::mainComponent().componentName()); filename
.append("/panels_layout");
986 QFile
file(filename
);
987 if (file
.open(QIODevice::ReadOnly
)) {
988 QByteArray data
= file
.readAll();
994 void DolphinMainWindow::setupActions()
997 m_newMenu
= new DolphinNewMenu(this);
998 KMenu
* menu
= m_newMenu
->menu();
999 menu
->setTitle(i18n("Create New..."));
1000 menu
->setIcon(SmallIcon("filenew"));
1001 connect(menu
, SIGNAL(aboutToShow()),
1002 this, SLOT(updateNewMenu()));
1004 QAction
* newWindow
= actionCollection()->addAction("new_window");
1005 newWindow
->setIcon(KIcon("window_new"));
1006 newWindow
->setText(i18n("New &Window"));
1007 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1008 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1010 QAction
* rename
= actionCollection()->addAction("rename");
1011 rename
->setText(i18n("Rename"));
1012 rename
->setShortcut(Qt::Key_F2
);
1013 connect(rename
, SIGNAL(triggered()), this, SLOT(rename()));
1015 QAction
* moveToTrash
= actionCollection()->addAction("move_to_trash");
1016 moveToTrash
->setText(i18n("Move to Trash"));
1017 moveToTrash
->setIcon(KIcon("edittrash"));
1018 moveToTrash
->setShortcut(QKeySequence::Delete
);
1019 connect(moveToTrash
, SIGNAL(triggered()), this, SLOT(moveToTrash()));
1021 QAction
* deleteAction
= actionCollection()->addAction("delete");
1022 deleteAction
->setText(i18n("Delete"));
1023 deleteAction
->setShortcut(Qt::SHIFT
| Qt::Key_Delete
);
1024 deleteAction
->setIcon(KIcon("editdelete"));
1025 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(deleteItems()));
1027 QAction
* properties
= actionCollection()->addAction("properties");
1028 properties
->setText(i18n("Properties"));
1029 properties
->setShortcut(Qt::ALT
| Qt::Key_Return
);
1030 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
1032 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1034 // setup 'Edit' menu
1035 KStandardAction::undo(this,
1037 actionCollection());
1039 KStandardAction::cut(this, SLOT(cut()), actionCollection());
1040 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1041 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1043 QAction
* selectAll
= actionCollection()->addAction("select_all");
1044 selectAll
->setText(i18n("Select All"));
1045 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1046 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1048 QAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1049 invertSelection
->setText(i18n("Invert Selection"));
1050 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1051 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1053 // setup 'View' menu
1054 KStandardAction::zoomIn(this,
1056 actionCollection());
1058 KStandardAction::zoomOut(this,
1060 actionCollection());
1062 KToggleAction
* iconsView
= actionCollection()->add
<KToggleAction
>("icons");
1063 iconsView
->setText(i18n("Icons"));
1064 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
1065 iconsView
->setIcon(KIcon("view_icon"));
1066 connect(iconsView
, SIGNAL(triggered()), this, SLOT(setIconsView()));
1068 KToggleAction
* detailsView
= actionCollection()->add
<KToggleAction
>("details");
1069 detailsView
->setText(i18n("Details"));
1070 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
1071 detailsView
->setIcon(KIcon("view_text"));
1072 connect(detailsView
, SIGNAL(triggered()), this, SLOT(setDetailsView()));
1074 QActionGroup
* viewModeGroup
= new QActionGroup(this);
1075 viewModeGroup
->addAction(iconsView
);
1076 viewModeGroup
->addAction(detailsView
);
1078 KToggleAction
* sortByName
= actionCollection()->add
<KToggleAction
>("by_name");
1079 sortByName
->setText(i18n("By Name"));
1080 connect(sortByName
, SIGNAL(triggered()), this, SLOT(sortByName()));
1082 KToggleAction
* sortBySize
= actionCollection()->add
<KToggleAction
>("by_size");
1083 sortBySize
->setText(i18n("By Size"));
1084 connect(sortBySize
, SIGNAL(triggered()), this, SLOT(sortBySize()));
1086 KToggleAction
* sortByDate
= actionCollection()->add
<KToggleAction
>("by_date");
1087 sortByDate
->setText(i18n("By Date"));
1088 connect(sortByDate
, SIGNAL(triggered()), this, SLOT(sortByDate()));
1090 KToggleAction
* sortByPermissions
= actionCollection()->add
<KToggleAction
>("by_permissions");
1091 sortByPermissions
->setText(i18n("By Permissions"));
1092 connect(sortByPermissions
, SIGNAL(triggered()), this, SLOT(sortByPermissions()));
1094 KToggleAction
* sortByOwner
= actionCollection()->add
<KToggleAction
>("by_owner");
1095 sortByOwner
->setText(i18n("By Owner"));
1096 connect(sortByOwner
, SIGNAL(triggered()), this, SLOT(sortByOwner()));
1098 KToggleAction
* sortByGroup
= actionCollection()->add
<KToggleAction
>("by_group");
1099 sortByGroup
->setText(i18n("By Group"));
1100 connect(sortByGroup
, SIGNAL(triggered()), this, SLOT(sortByGroup()));
1102 QActionGroup
* sortGroup
= new QActionGroup(this);
1103 sortGroup
->addAction(sortByName
);
1104 sortGroup
->addAction(sortBySize
);
1105 sortGroup
->addAction(sortByDate
);
1106 sortGroup
->addAction(sortByPermissions
);
1107 sortGroup
->addAction(sortByOwner
);
1108 sortGroup
->addAction(sortByGroup
);
1110 KToggleAction
* sortDescending
= actionCollection()->add
<KToggleAction
>("descending");
1111 sortDescending
->setText(i18n("Descending"));
1112 connect(sortDescending
, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
1114 KToggleAction
* showPreview
= actionCollection()->add
<KToggleAction
>("show_preview");
1115 showPreview
->setText(i18n("Show Preview"));
1116 connect(showPreview
, SIGNAL(triggered()), this, SLOT(togglePreview()));
1118 KToggleAction
* showHiddenFiles
= actionCollection()->add
<KToggleAction
>("show_hidden_files");
1119 showHiddenFiles
->setText(i18n("Show Hidden Files"));
1120 showHiddenFiles
->setShortcut(Qt::ALT
| Qt::Key_Period
);
1121 connect(showHiddenFiles
, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles()));
1123 KToggleAction
* split
= actionCollection()->add
<KToggleAction
>("split_view");
1124 split
->setText(i18n("Split View"));
1125 split
->setShortcut(Qt::Key_F10
);
1126 split
->setIcon(KIcon("view_left_right"));
1127 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1129 QAction
* reload
= actionCollection()->addAction("reload");
1130 reload
->setText(i18n("Reload"));
1131 reload
->setShortcut(Qt::Key_F5
);
1132 reload
->setIcon(KIcon("reload"));
1133 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1135 QAction
* stop
= actionCollection()->addAction("stop");
1136 stop
->setText(i18n("Stop"));
1137 stop
->setIcon(KIcon("stop"));
1138 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1140 // TODO: the URL navigator must emit a signal if the editable state has been
1141 // changed, so that the corresponding showFullLocation action is updated. Also
1142 // the naming "Show full Location" is currently confusing...
1143 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1144 showFullLocation
->setText(i18n("Show Full Location"));
1145 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1146 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1148 QAction
* editLocation
= actionCollection()->addAction("edit_location");
1149 editLocation
->setText(i18n("Edit Location"));
1150 editLocation
->setShortcut(Qt::Key_F6
);
1151 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
1153 QAction
* adjustViewProps
= actionCollection()->addAction("view_properties");
1154 adjustViewProps
->setText(i18n("Adjust View Properties..."));
1155 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1158 KStandardAction::back(this, SLOT(goBack()), actionCollection());
1159 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1160 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1161 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1163 // setup 'Tools' menu
1164 QAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1165 openTerminal
->setText(i18n("Open Terminal"));
1166 openTerminal
->setShortcut(Qt::Key_F4
);
1167 openTerminal
->setIcon(KIcon("konsole"));
1168 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1170 QAction
* findFile
= actionCollection()->addAction("find_file");
1171 findFile
->setText(i18n("Find File..."));
1172 findFile
->setShortcut(Qt::Key_F
);
1173 findFile
->setIcon(KIcon("filefind"));
1174 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
1176 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1177 showFilterBar
->setText(i18n("Show Filter Bar"));
1178 showFilterBar
->setShortcut(Qt::Key_Slash
);
1179 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1181 QAction
* compareFiles
= actionCollection()->addAction("compare_files");
1182 compareFiles
->setText(i18n("Compare Files"));
1183 compareFiles
->setIcon(KIcon("kompare"));
1184 compareFiles
->setEnabled(false);
1185 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1187 // setup 'Settings' menu
1188 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1191 void DolphinMainWindow::setupDockWidgets()
1193 QDockWidget
* shortcutsDock
= new QDockWidget(i18n("Bookmarks"));
1194 shortcutsDock
->setObjectName("bookmarksDock");
1195 shortcutsDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1196 shortcutsDock
->setWidget(new BookmarksSidebarPage(this));
1198 shortcutsDock
->toggleViewAction()->setText(i18n("Show Bookmarks Panel"));
1199 actionCollection()->addAction("show_bookmarks_panel", shortcutsDock
->toggleViewAction());
1201 addDockWidget(Qt::LeftDockWidgetArea
, shortcutsDock
);
1203 QDockWidget
* infoDock
= new QDockWidget(i18n("Information"));
1204 infoDock
->setObjectName("infoDock");
1205 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1206 infoDock
->setWidget(new InfoSidebarPage(this));
1208 infoDock
->toggleViewAction()->setText(i18n("Show Information Panel"));
1209 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1211 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1214 void DolphinMainWindow::updateHistory()
1217 const QLinkedList
<UrlNavigator::HistoryElem
> list
= m_activeView
->urlHistory(index
);
1219 QAction
* backAction
= actionCollection()->action("go_back");
1220 if (backAction
!= 0) {
1221 backAction
->setEnabled(index
< static_cast<int>(list
.count()) - 1);
1224 QAction
* forwardAction
= actionCollection()->action("go_forward");
1225 if (forwardAction
!= 0) {
1226 forwardAction
->setEnabled(index
> 0);
1230 void DolphinMainWindow::updateEditActions()
1232 const KFileItemList list
= m_activeView
->selectedItems();
1233 if (list
.isEmpty()) {
1234 stateChanged("has_no_selection");
1237 stateChanged("has_selection");
1239 QAction
* renameAction
= actionCollection()->action("rename");
1240 if (renameAction
!= 0) {
1241 renameAction
->setEnabled(list
.count() >= 1);
1244 bool enableMoveToTrash
= true;
1246 KFileItemList::const_iterator it
= list
.begin();
1247 const KFileItemList::const_iterator end
= list
.end();
1249 KFileItem
* item
= *it
;
1250 const KUrl
& url
= item
->url();
1251 // only enable the 'Move to Trash' action for local files
1252 if (!url
.isLocalFile()) {
1253 enableMoveToTrash
= false;
1258 QAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
1259 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1261 updatePasteAction();
1264 void DolphinMainWindow::updateViewActions()
1266 QAction
* zoomInAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomIn
));
1267 if (zoomInAction
!= 0) {
1268 zoomInAction
->setEnabled(m_activeView
->isZoomInPossible());
1271 QAction
* zoomOutAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomOut
));
1272 if (zoomOutAction
!= 0) {
1273 zoomOutAction
->setEnabled(m_activeView
->isZoomOutPossible());
1276 QAction
* action
= 0;
1277 switch (m_activeView
->mode()) {
1278 case DolphinView::IconsView
:
1279 action
= actionCollection()->action("icons");
1281 case DolphinView::DetailsView
:
1282 action
= actionCollection()->action("details");
1289 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
1290 toggleAction
->setChecked(true);
1293 slotSortingChanged(m_activeView
->sorting());
1294 slotSortOrderChanged(m_activeView
->sortOrder());
1296 KToggleAction
* showFilterBarAction
=
1297 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
1298 showFilterBarAction
->setChecked(m_activeView
->isFilterBarVisible());
1300 KToggleAction
* showPreviewAction
=
1301 static_cast<KToggleAction
*>(actionCollection()->action("show_preview"));
1302 showPreviewAction
->setChecked(m_activeView
->showPreview());
1304 KToggleAction
* showHiddenFilesAction
=
1305 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
1306 showHiddenFilesAction
->setChecked(m_activeView
->showHiddenFiles());
1308 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1309 splitAction
->setChecked(m_view
[SecondaryIdx
] != 0);
1311 KToggleAction
* editableLocactionAction
=
1312 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
1313 editableLocactionAction
->setChecked(m_activeView
->isUrlEditable());
1316 void DolphinMainWindow::updateGoActions()
1318 QAction
* goUpAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Up
));
1319 const KUrl
& currentUrl
= m_activeView
->url();
1320 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1323 void DolphinMainWindow::copyUrls(const KUrl::List
& source
, const KUrl
& dest
)
1325 KonqOperations::copy(this, KonqOperations::COPY
, source
, dest
);
1326 m_undoOperations
.append(KonqOperations::COPY
);
1329 void DolphinMainWindow::moveUrls(const KUrl::List
& source
, const KUrl
& dest
)
1331 KonqOperations::copy(this, KonqOperations::MOVE
, source
, dest
);
1332 m_undoOperations
.append(KonqOperations::MOVE
);
1335 void DolphinMainWindow::linkUrls(const KUrl::List
& source
, const KUrl
& dest
)
1337 KonqOperations::copy(this, KonqOperations::LINK
, source
, dest
);
1338 m_undoOperations
.append(KonqOperations::LINK
);
1341 void DolphinMainWindow::clearStatusBar()
1343 m_activeView
->statusBar()->clear();
1346 void DolphinMainWindow::connectViewSignals(int viewIndex
)
1348 DolphinView
* view
= m_view
[viewIndex
];
1349 connect(view
, SIGNAL(modeChanged()),
1350 this, SLOT(slotViewModeChanged()));
1351 connect(view
, SIGNAL(showPreviewChanged()),
1352 this, SLOT(slowShowPreviewChanged()));
1353 connect(view
, SIGNAL(showHiddenFilesChanged()),
1354 this, SLOT(slotShowHiddenFilesChanged()));
1355 connect(view
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
1356 this, SLOT(slotSortingChanged(DolphinView::Sorting
)));
1357 connect(view
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
1358 this, SLOT(slotSortOrderChanged(Qt::SortOrder
)));
1359 connect(view
, SIGNAL(selectionChanged()),
1360 this, SLOT(slotSelectionChanged()));
1361 connect(view
, SIGNAL(showFilterBarChanged(bool)),
1362 this, SLOT(updateFilterBarAction(bool)));
1364 const UrlNavigator
* navigator
= view
->urlNavigator();
1365 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1366 this, SLOT(slotUrlChanged(const KUrl
&)));
1367 connect(navigator
, SIGNAL(historyChanged()),
1368 this, SLOT(slotHistoryChanged()));
1372 DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow
* mainWin
) :
1373 KonqUndoManager::UiInterface(mainWin
),
1376 assert(m_mainWin
!= 0);
1379 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1383 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1385 DolphinStatusBar
* statusBar
= m_mainWin
->activeView()->statusBar();
1386 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1389 #include "dolphinmainwindow.moc"