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 "dolphinmainwindow.h"
26 #include "dolphinapplication.h"
27 #include "dolphinnewmenu.h"
28 #include "dolphinsettings.h"
29 #include "dolphinsettingsdialog.h"
30 #include "dolphinstatusbar.h"
31 #include "dolphinapplication.h"
32 #include "urlnavigator.h"
33 #include "dolphinsettings.h"
34 #include "bookmarkssidebarpage.h"
35 #include "infosidebarpage.h"
36 #include "generalsettings.h"
37 #include "viewpropertiesdialog.h"
38 #include "viewproperties.h"
41 #include <kactioncollection.h>
42 #include <kbookmarkmanager.h>
44 #include <kdesktopfile.h>
45 #include <kdeversion.h>
46 #include <kfiledialog.h>
49 #include <kiconloader.h>
50 #include <kio/netaccess.h>
51 #include <kio/deletejob.h>
52 #include <kio/renamedialog.h>
53 #include <kinputdialog.h>
56 #include <kmessagebox.h>
57 #include <konqmimedata.h>
58 #include <kpropertiesdialog.h>
59 #include <kprotocolinfo.h>
60 #include <ktoggleaction.h>
63 #include <kstandarddirs.h>
64 #include <kstatusbar.h>
65 #include <kstandardaction.h>
68 #include <QCloseEvent>
71 #include <QDockWidget>
73 DolphinMainWindow::DolphinMainWindow() :
79 setObjectName("Dolphin");
80 m_view
[PrimaryIdx
] = 0;
81 m_view
[SecondaryIdx
] = 0;
83 KonqUndoManager::incRef();
85 KonqUndoManager
* undoManager
= KonqUndoManager::self();
86 undoManager
->setUiInterface(new UndoUiInterface(this));
88 connect(undoManager
, SIGNAL(undoAvailable(bool)),
89 this, SLOT(slotUndoAvailable(bool)));
90 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
91 this, SLOT(slotUndoTextChanged(const QString
&)));
94 DolphinMainWindow::~DolphinMainWindow()
96 KonqUndoManager::decRef();
97 DolphinApplication::app()->removeMainWindow(this);
100 void DolphinMainWindow::setActiveView(DolphinView
* view
)
102 assert((view
== m_view
[PrimaryIdx
]) || (view
== m_view
[SecondaryIdx
]));
103 if (m_activeView
== view
) {
114 setCaption(m_activeView
->url().fileName());
116 emit
activeViewChanged();
119 void DolphinMainWindow::dropUrls(const KUrl::List
& urls
,
120 const KUrl
& destination
)
122 Qt::DropAction action
= Qt::CopyAction
;
124 Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
125 const bool shiftPressed
= modifier
& Qt::ShiftModifier
;
126 const bool controlPressed
= modifier
& Qt::ControlModifier
;
127 if (shiftPressed
&& controlPressed
) {
128 // shortcut for 'Link Here' is used
129 action
= Qt::LinkAction
;
131 else if (shiftPressed
) {
132 // shortcut for 'Move Here' is used
133 action
= Qt::MoveAction
;
135 else if (controlPressed
) {
136 // shortcut for 'Copy Here' is used
137 action
= Qt::CopyAction
;
140 // open a context menu which offers the following actions:
148 QString seq
= QKeySequence(Qt::ShiftModifier
).toString();
149 seq
.chop(1); // chop superfluous '+'
150 QAction
* moveAction
= popup
.addAction(KIcon("goto"),
151 i18n("&Move Here") + "\t" + seq
);
153 seq
= QKeySequence(Qt::ControlModifier
).toString();
155 QAction
* copyAction
= popup
.addAction(KIcon("editcopy"),
156 i18n("&Copy Here") + "\t" + seq
);
158 seq
= QKeySequence(Qt::ControlModifier
+ Qt::ShiftModifier
).toString();
160 QAction
* linkAction
= popup
.addAction(KIcon("www"),
161 i18n("&Link Here") + "\t" + seq
);
163 popup
.addSeparator();
164 QAction
* cancelAction
= popup
.addAction(KIcon("stop"), i18n("Cancel"));
166 QAction
* activatedAction
= popup
.exec(QCursor::pos());
167 if (activatedAction
== moveAction
) {
168 action
= Qt::MoveAction
;
170 else if (activatedAction
== copyAction
) {
171 action
= Qt::CopyAction
;
173 else if (activatedAction
== linkAction
) {
174 action
= Qt::LinkAction
;
176 else if (activatedAction
== cancelAction
) {
183 moveUrls(urls
, destination
);
187 copyUrls(urls
, destination
);
191 linkUrls(urls
, destination
);
199 void DolphinMainWindow::refreshViews()
201 const bool split
= DolphinSettings::instance().generalSettings()->splitView();
202 const bool isPrimaryViewActive
= (m_activeView
== m_view
[PrimaryIdx
]);
204 for (int i
= PrimaryIdx
; i
<= SecondaryIdx
; ++i
) {
205 if (m_view
[i
] != 0) {
206 url
= m_view
[i
]->url();
208 // delete view instance...
210 m_view
[i
]->deleteLater();
214 if (split
|| (i
== PrimaryIdx
)) {
215 // ... and recreate it
216 ViewProperties
props(url
);
217 m_view
[i
] = new DolphinView(this,
221 props
.showHiddenFiles());
222 connectViewSignals(i
);
227 m_activeView
= isPrimaryViewActive
? m_view
[PrimaryIdx
] : m_view
[SecondaryIdx
];
228 assert(m_activeView
!= 0);
231 emit
activeViewChanged();
234 void DolphinMainWindow::slotViewModeChanged()
239 void DolphinMainWindow::slotShowHiddenFilesChanged()
241 KToggleAction
* showHiddenFilesAction
=
242 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
243 showHiddenFilesAction
->setChecked(m_activeView
->showHiddenFiles());
246 void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting
)
250 case DolphinView::SortByName
:
251 action
= actionCollection()->action("by_name");
253 case DolphinView::SortBySize
:
254 action
= actionCollection()->action("by_size");
256 case DolphinView::SortByDate
:
257 action
= actionCollection()->action("by_date");
264 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
265 toggleAction
->setChecked(true);
269 void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order
)
271 KToggleAction
* descending
= static_cast<KToggleAction
*>(actionCollection()->action("descending"));
272 const bool sortDescending
= (order
== Qt::Descending
);
273 descending
->setChecked(sortDescending
);
276 void DolphinMainWindow::slotSelectionChanged()
280 assert(m_view
[PrimaryIdx
] != 0);
281 int selectedUrlsCount
= m_view
[PrimaryIdx
]->selectedUrls().count();
282 if (m_view
[SecondaryIdx
] != 0) {
283 selectedUrlsCount
+= m_view
[SecondaryIdx
]->selectedUrls().count();
286 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
287 compareFilesAction
->setEnabled(selectedUrlsCount
== 2);
289 m_activeView
->updateStatusBar();
291 emit
selectionChanged();
294 void DolphinMainWindow::slotHistoryChanged()
299 void DolphinMainWindow::slotUrlChanged(const KUrl
& url
)
303 setCaption(url
.fileName());
306 void DolphinMainWindow::updateFilterBarAction(bool show
)
308 KToggleAction
* showFilterBarAction
=
309 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
310 showFilterBarAction
->setChecked(show
);
313 void DolphinMainWindow::openNewMainWindow()
315 DolphinApplication::app()->createMainWindow()->show();
318 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
320 DolphinSettings
& settings
= DolphinSettings::instance();
321 GeneralSettings
* generalSettings
= settings
.generalSettings();
322 generalSettings
->setFirstRun(false);
326 // TODO: I assume there will be a generic way in KDE 4 to store the docks
327 // of the main window. In the meantime they are stored manually:
328 QString filename
= KStandardDirs::locateLocal("data", KGlobal::mainComponent().componentName());
329 filename
.append("/panels_layout");
330 QFile
file(filename
);
331 if (file
.open(QIODevice::WriteOnly
)) {
332 QByteArray data
= saveState();
337 KMainWindow::closeEvent(event
);
340 void DolphinMainWindow::saveProperties(KConfig
* config
)
342 config
->setGroup("Primary view");
343 config
->writeEntry("Url", m_view
[PrimaryIdx
]->url().url());
344 config
->writeEntry("Editable Url", m_view
[PrimaryIdx
]->isUrlEditable());
345 if (m_view
[SecondaryIdx
] != 0) {
346 config
->setGroup("Secondary view");
347 config
->writeEntry("Url", m_view
[SecondaryIdx
]->url().url());
348 config
->writeEntry("Editable Url", m_view
[SecondaryIdx
]->isUrlEditable());
352 void DolphinMainWindow::readProperties(KConfig
* config
)
354 config
->setGroup("Primary view");
355 m_view
[PrimaryIdx
]->setUrl(config
->readEntry("Url"));
356 m_view
[PrimaryIdx
]->setUrlEditable(config
->readEntry("Editable Url", false));
357 if (config
->hasGroup("Secondary view")) {
358 config
->setGroup("Secondary view");
359 if (m_view
[SecondaryIdx
] == 0) {
362 m_view
[SecondaryIdx
]->setUrl(config
->readEntry("Url"));
363 m_view
[SecondaryIdx
]->setUrlEditable(config
->readEntry("Editable Url", false));
365 else if (m_view
[SecondaryIdx
] != 0) {
370 void DolphinMainWindow::updateNewMenu()
372 m_newMenu
->slotCheckUpToDate();
373 m_newMenu
->setPopupFiles(activeView()->url());
376 void DolphinMainWindow::rename()
379 m_activeView
->renameSelectedItems();
382 void DolphinMainWindow::moveToTrash()
385 const KUrl::List selectedUrls
= m_activeView
->selectedUrls();
386 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls
);
387 m_undoOperations
.append(KonqOperations::TRASH
);
390 void DolphinMainWindow::deleteItems()
394 KUrl::List list
= m_activeView
->selectedUrls();
395 const uint itemCount
= list
.count();
396 assert(itemCount
>= 1);
400 text
= i18n("Do you really want to delete the %1 selected items?",itemCount
);
403 const KUrl
& url
= list
.first();
404 text
= i18n("Do you really want to delete '%1'?",url
.fileName());
407 const bool del
= KMessageBox::warningContinueCancel(this,
410 KGuiItem(i18n("Delete"), KIcon("editdelete"))
411 ) == KMessageBox::Continue
;
413 KIO::Job
* job
= KIO::del(list
);
414 connect(job
, SIGNAL(result(KJob
*)),
415 this, SLOT(slotHandleJobError(KJob
*)));
416 connect(job
, SIGNAL(result(KJob
*)),
417 this, SLOT(slotDeleteFileFinished(KJob
*)));
421 void DolphinMainWindow::properties()
423 const KFileItemList list
= m_activeView
->selectedItems();
424 new KPropertiesDialog(list
, this);
427 void DolphinMainWindow::quit()
432 void DolphinMainWindow::slotHandleJobError(KJob
* job
)
434 if (job
->error() != 0) {
435 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
436 statusBar
->setMessage(job
->errorString(),
437 DolphinStatusBar::Error
);
441 void DolphinMainWindow::slotDeleteFileFinished(KJob
* job
)
443 if (job
->error() == 0) {
444 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
445 statusBar
->setMessage(i18n("Delete operation completed."),
446 DolphinStatusBar::OperationCompleted
);
450 void DolphinMainWindow::slotUndoAvailable(bool available
)
452 QAction
* undoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo
));
453 if (undoAction
!= 0) {
454 undoAction
->setEnabled(available
);
457 if (available
&& (m_undoOperations
.count() > 0)) {
458 const KonqOperations::Operation op
= m_undoOperations
.takeFirst();
459 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
461 case KonqOperations::COPY
:
462 statusBar
->setMessage(i18n("Copy operation completed."),
463 DolphinStatusBar::OperationCompleted
);
465 case KonqOperations::MOVE
:
466 statusBar
->setMessage(i18n("Move operation completed."),
467 DolphinStatusBar::OperationCompleted
);
469 case KonqOperations::LINK
:
470 statusBar
->setMessage(i18n("Link operation completed."),
471 DolphinStatusBar::OperationCompleted
);
473 case KonqOperations::TRASH
:
474 statusBar
->setMessage(i18n("Move to trash operation completed."),
475 DolphinStatusBar::OperationCompleted
);
484 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
486 QAction
* undoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo
));
487 if (undoAction
!= 0) {
488 undoAction
->setText(text
);
492 void DolphinMainWindow::undo()
495 KonqUndoManager::self()->undo();
498 void DolphinMainWindow::cut()
500 QMimeData
* mimeData
= new QMimeData();
501 const KUrl::List kdeUrls
= m_activeView
->selectedUrls();
502 const KUrl::List mostLocalUrls
;
503 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
504 QApplication::clipboard()->setMimeData(mimeData
);
507 void DolphinMainWindow::copy()
509 QMimeData
* mimeData
= new QMimeData();
510 const KUrl::List kdeUrls
= m_activeView
->selectedUrls();
511 const KUrl::List mostLocalUrls
;
512 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
514 QApplication::clipboard()->setMimeData(mimeData
);
517 void DolphinMainWindow::paste()
519 QClipboard
* clipboard
= QApplication::clipboard();
520 const QMimeData
* mimeData
= clipboard
->mimeData();
524 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
526 // per default the pasting is done into the current Url of the view
527 KUrl
destUrl(m_activeView
->url());
529 // check whether the pasting should be done into a selected directory
530 KUrl::List selectedUrls
= m_activeView
->selectedUrls();
531 if (selectedUrls
.count() == 1) {
532 const KFileItem
fileItem(S_IFDIR
,
534 selectedUrls
.first(),
536 if (fileItem
.isDir()) {
537 // only one item is selected which is a directory, hence paste
538 // into this directory
539 destUrl
= selectedUrls
.first();
543 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
544 moveUrls(sourceUrls
, destUrl
);
548 copyUrls(sourceUrls
, destUrl
);
552 void DolphinMainWindow::updatePasteAction()
554 QAction
* pasteAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste
));
555 if (pasteAction
== 0) {
559 QString
text(i18n("Paste"));
560 QClipboard
* clipboard
= QApplication::clipboard();
561 const QMimeData
* mimeData
= clipboard
->mimeData();
563 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
564 if (!urls
.isEmpty()) {
565 pasteAction
->setEnabled(true);
567 const int count
= urls
.count();
569 pasteAction
->setText(i18n("Paste 1 File"));
572 pasteAction
->setText(i18n("Paste %1 Files").arg(count
));
576 pasteAction
->setEnabled(false);
577 pasteAction
->setText(i18n("Paste"));
580 if (pasteAction
->isEnabled()) {
581 KUrl::List urls
= m_activeView
->selectedUrls();
582 const uint count
= urls
.count();
584 // pasting should not be allowed when more than one file
586 pasteAction
->setEnabled(false);
588 else if (count
== 1) {
589 // Only one file is selected. Pasting is only allowed if this
590 // file is a directory.
591 // TODO: this doesn't work with remote protocols; instead we need a
592 // m_activeView->selectedFileItems() to get the real KFileItems
593 const KFileItem
fileItem(S_IFDIR
,
597 pasteAction
->setEnabled(fileItem
.isDir());
602 void DolphinMainWindow::selectAll()
605 m_activeView
->selectAll();
608 void DolphinMainWindow::invertSelection()
611 m_activeView
->invertSelection();
613 void DolphinMainWindow::setIconsView()
615 m_activeView
->setMode(DolphinView::IconsView
);
618 void DolphinMainWindow::setDetailsView()
620 m_activeView
->setMode(DolphinView::DetailsView
);
623 void DolphinMainWindow::sortByName()
625 m_activeView
->setSorting(DolphinView::SortByName
);
628 void DolphinMainWindow::sortBySize()
630 m_activeView
->setSorting(DolphinView::SortBySize
);
633 void DolphinMainWindow::sortByDate()
635 m_activeView
->setSorting(DolphinView::SortByDate
);
638 void DolphinMainWindow::toggleSortOrder()
640 const Qt::SortOrder order
= (m_activeView
->sortOrder() == Qt::Ascending
) ?
643 m_activeView
->setSortOrder(order
);
646 void DolphinMainWindow::toggleSplitView()
648 if (m_view
[SecondaryIdx
] == 0) {
649 const int newWidth
= (m_view
[PrimaryIdx
]->width() - m_splitter
->handleWidth()) / 2;
650 // create a secondary view
651 m_view
[SecondaryIdx
] = new DolphinView(this,
653 m_view
[PrimaryIdx
]->url(),
654 m_view
[PrimaryIdx
]->mode(),
655 m_view
[PrimaryIdx
]->showHiddenFiles());
656 connectViewSignals(SecondaryIdx
);
657 m_splitter
->addWidget(m_view
[SecondaryIdx
]);
658 m_splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
659 m_view
[SecondaryIdx
]->show();
662 // remove secondary view
663 if (m_activeView
== m_view
[PrimaryIdx
]) {
664 m_view
[SecondaryIdx
]->close();
665 m_view
[SecondaryIdx
]->deleteLater();
666 m_view
[SecondaryIdx
] = 0;
667 setActiveView(m_view
[PrimaryIdx
]);
670 // The secondary view is active, hence from the users point of view
671 // the content of the secondary view should be moved to the primary view.
672 // From an implementation point of view it is more efficient to close
673 // the primary view and exchange the internal pointers afterwards.
674 m_view
[PrimaryIdx
]->close();
675 delete m_view
[PrimaryIdx
];
676 m_view
[PrimaryIdx
] = m_view
[SecondaryIdx
];
677 m_view
[SecondaryIdx
] = 0;
678 setActiveView(m_view
[PrimaryIdx
]);
683 void DolphinMainWindow::reloadView()
686 m_activeView
->reload();
689 void DolphinMainWindow::stopLoading()
693 void DolphinMainWindow::togglePreview()
697 const KToggleAction
* showPreviewAction
=
698 static_cast<KToggleAction
*>(actionCollection()->action("show_preview"));
699 const bool show
= showPreviewAction
->isChecked();
700 m_activeView
->setShowPreview(show
);
703 void DolphinMainWindow::toggleShowHiddenFiles()
707 const KToggleAction
* showHiddenFilesAction
=
708 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
709 const bool show
= showHiddenFilesAction
->isChecked();
710 m_activeView
->setShowHiddenFiles(show
);
713 void DolphinMainWindow::showFilterBar()
715 const KToggleAction
* showFilterBarAction
=
716 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
717 const bool show
= showFilterBarAction
->isChecked();
718 m_activeView
->showFilterBar(show
);
721 void DolphinMainWindow::zoomIn()
723 m_activeView
->zoomIn();
727 void DolphinMainWindow::zoomOut()
729 m_activeView
->zoomOut();
733 void DolphinMainWindow::toggleEditLocation()
737 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
739 bool editOrBrowse
= action
->isChecked();
740 m_activeView
->setUrlEditable(editOrBrowse
);
743 void DolphinMainWindow::editLocation()
745 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
746 action
->setChecked(true);
747 m_activeView
->setUrlEditable(true);
750 void DolphinMainWindow::adjustViewProperties()
753 ViewPropertiesDialog
dlg(m_activeView
);
757 void DolphinMainWindow::goBack()
760 m_activeView
->goBack();
763 void DolphinMainWindow::goForward()
766 m_activeView
->goForward();
769 void DolphinMainWindow::goUp()
772 m_activeView
->goUp();
775 void DolphinMainWindow::goHome()
778 m_activeView
->goHome();
781 void DolphinMainWindow::openTerminal()
783 QString
command("konsole --workdir \"");
784 command
.append(m_activeView
->url().path());
785 command
.append('\"');
787 KRun::runCommand(command
, "Konsole", "konsole");
790 void DolphinMainWindow::findFile()
792 KRun::run("kfind", m_activeView
->url());
795 void DolphinMainWindow::compareFiles()
797 // The method is only invoked if exactly 2 files have
798 // been selected. The selected files may be:
799 // - both in the primary view
800 // - both in the secondary view
801 // - one in the primary view and the other in the secondary
803 assert(m_view
[PrimaryIdx
] != 0);
807 KUrl::List urls
= m_view
[PrimaryIdx
]->selectedUrls();
809 switch (urls
.count()) {
811 assert(m_view
[SecondaryIdx
] != 0);
812 urls
= m_view
[SecondaryIdx
]->selectedUrls();
813 assert(urls
.count() == 2);
821 assert(m_view
[SecondaryIdx
] != 0);
822 urls
= m_view
[SecondaryIdx
]->selectedUrls();
823 assert(urls
.count() == 1);
835 // may not happen: compareFiles may only get invoked if 2
836 // files are selected
841 QString
command("kompare -c \"");
842 command
.append(urlA
.pathOrUrl());
843 command
.append("\" \"");
844 command
.append(urlB
.pathOrUrl());
845 command
.append('\"');
846 KRun::runCommand(command
, "Kompare", "kompare");
850 void DolphinMainWindow::editSettings()
852 // TODO: make a static method for opening the settings dialog
853 DolphinSettingsDialog
dlg(this);
857 void DolphinMainWindow::init()
859 // Check whether Dolphin runs the first time. If yes then
860 // a proper default window size is given at the end of DolphinMainWindow::init().
861 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
862 const bool firstRun
= generalSettings
->firstRun();
864 setAcceptDrops(true);
866 m_splitter
= new QSplitter(this);
868 DolphinSettings
& settings
= DolphinSettings::instance();
870 KBookmarkManager
* manager
= settings
.bookmarkManager();
871 assert(manager
!= 0);
872 KBookmarkGroup root
= manager
->root();
873 if (root
.first().isNull()) {
874 root
.addBookmark(manager
, i18n("Home"), settings
.generalSettings()->homeUrl(), "folder_home");
875 root
.addBookmark(manager
, i18n("Storage Media"), KUrl("media:/"), "blockdevice");
876 root
.addBookmark(manager
, i18n("Network"), KUrl("remote:/"), "network_local");
877 root
.addBookmark(manager
, i18n("Root"), KUrl("/"), "folder_red");
878 root
.addBookmark(manager
, i18n("Trash"), KUrl("trash:/"), "trashcan_full");
883 const KUrl
& homeUrl
= root
.first().url();
884 setCaption(homeUrl
.fileName());
885 ViewProperties
props(homeUrl
);
886 m_view
[PrimaryIdx
] = new DolphinView(this,
890 props
.showHiddenFiles());
891 connectViewSignals(PrimaryIdx
);
892 m_view
[PrimaryIdx
]->show();
894 m_activeView
= m_view
[PrimaryIdx
];
896 setCentralWidget(m_splitter
);
899 setupGUI(Keys
|Save
|Create
|ToolBar
);
902 stateChanged("new_file");
903 setAutoSaveSettings();
905 QClipboard
* clipboard
= QApplication::clipboard();
906 connect(clipboard
, SIGNAL(dataChanged()),
907 this, SLOT(updatePasteAction()));
914 // assure a proper default size if Dolphin runs the first time
919 void DolphinMainWindow::loadSettings()
921 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
923 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
924 if (settings
->splitView()) {
925 splitAction
->setChecked(true);
931 // TODO: I assume there will be a generic way in KDE 4 to restore the docks
932 // of the main window. In the meantime they are restored manually (see also
933 // DolphinMainWindow::closeEvent() for more details):
934 QString filename
= KStandardDirs::locateLocal("data", KGlobal::mainComponent().componentName()); filename
.append("/panels_layout");
935 QFile
file(filename
);
936 if (file
.open(QIODevice::ReadOnly
)) {
937 QByteArray data
= file
.readAll();
943 void DolphinMainWindow::setupActions()
946 m_newMenu
= new DolphinNewMenu(this);
947 KMenu
* menu
= m_newMenu
->menu();
948 menu
->setTitle(i18n("Create New..."));
949 menu
->setIcon(SmallIcon("filenew"));
950 connect(menu
, SIGNAL(aboutToShow()),
951 this, SLOT(updateNewMenu()));
953 QAction
* action
= actionCollection()->addAction("new_window");
954 action
->setIcon(KIcon("window_new"));
955 action
->setText(i18n("New &Window"));
956 connect(action
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
958 QAction
* rename
= actionCollection()->addAction("rename");
959 rename
->setText(i18n("Rename"));
960 rename
->setShortcut(Qt::Key_F2
);
961 connect(rename
, SIGNAL(triggered()), this, SLOT(rename()));
963 QAction
* moveToTrash
= actionCollection()->addAction("move_to_trash");
964 moveToTrash
->setText(i18n("Move to Trash"));
965 moveToTrash
->setIcon(KIcon("edittrash"));
966 moveToTrash
->setShortcut(QKeySequence::Delete
);
967 connect(moveToTrash
, SIGNAL(triggered()), this, SLOT(moveToTrash()));
969 QAction
* deleteAction
= actionCollection()->addAction("delete");
970 deleteAction
->setText(i18n("Delete"));
971 deleteAction
->setShortcut(Qt::ALT
| Qt::Key_Delete
);
972 deleteAction
->setIcon(KIcon("editdelete"));
973 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(deleteItems()));
975 QAction
* properties
= actionCollection()->addAction("properties");
976 properties
->setText(i18n("Propert&ies"));
977 properties
->setShortcut(Qt::Key_Alt
| Qt::Key_Return
);
978 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
980 KStandardAction::quit(this, SLOT(quit()), actionCollection());
983 KStandardAction::undo(this,
987 KStandardAction::cut(this, SLOT(cut()), actionCollection());
988 KStandardAction::copy(this, SLOT(copy()), actionCollection());
989 KStandardAction::paste(this, SLOT(paste()), actionCollection());
991 QAction
* selectAll
= actionCollection()->addAction("select_all");
992 selectAll
->setText(i18n("Select All"));
993 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
994 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
996 QAction
* invertSelection
= actionCollection()->addAction("invert_selection");
997 invertSelection
->setText(i18n("Invert Selection"));
998 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
999 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1001 // setup 'View' menu
1002 KStandardAction::zoomIn(this,
1004 actionCollection());
1006 KStandardAction::zoomOut(this,
1008 actionCollection());
1010 KToggleAction
* iconsView
= actionCollection()->add
<KToggleAction
>("icons");
1011 iconsView
->setText(i18n("Icons"));
1012 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
1013 iconsView
->setIcon(KIcon("view_icon"));
1014 connect(iconsView
, SIGNAL(triggered()), this, SLOT(setIconsView()));
1016 KToggleAction
* detailsView
= actionCollection()->add
<KToggleAction
>("details");
1017 detailsView
->setText(i18n("Details"));
1018 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
1019 detailsView
->setIcon(KIcon("view_text"));
1020 connect(detailsView
, SIGNAL(triggered()), this, SLOT(setDetailsView()));
1022 QActionGroup
* viewModeGroup
= new QActionGroup(this);
1023 viewModeGroup
->addAction(iconsView
);
1024 viewModeGroup
->addAction(detailsView
);
1026 KToggleAction
* sortByName
= actionCollection()->add
<KToggleAction
>("by_name");
1027 sortByName
->setText(i18n("By Name"));
1028 connect(sortByName
, SIGNAL(triggered()), this, SLOT(sortByName()));
1030 KToggleAction
* sortBySize
= actionCollection()->add
<KToggleAction
>("by_size");
1031 sortBySize
->setText(i18n("By Size"));
1032 connect(sortBySize
, SIGNAL(triggered()), this, SLOT(sortBySize()));
1034 KToggleAction
* sortByDate
= actionCollection()->add
<KToggleAction
>("by_date");
1035 sortByDate
->setText(i18n("By Date"));
1036 connect(sortByDate
, SIGNAL(triggered()), this, SLOT(sortByDate()));
1038 QActionGroup
* sortGroup
= new QActionGroup(this);
1039 sortGroup
->addAction(sortByName
);
1040 sortGroup
->addAction(sortBySize
);
1041 sortGroup
->addAction(sortByDate
);
1043 KToggleAction
* sortDescending
= actionCollection()->add
<KToggleAction
>("descending");
1044 sortDescending
->setText(i18n("Descending"));
1045 connect(sortDescending
, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
1047 KToggleAction
* showPreview
= actionCollection()->add
<KToggleAction
>("show_preview");
1048 showPreview
->setText(i18n("Show Preview"));
1049 connect(showPreview
, SIGNAL(triggered()), this, SLOT(togglePreview()));
1051 KToggleAction
* showHiddenFiles
= actionCollection()->add
<KToggleAction
>("show_hidden_files");
1052 showHiddenFiles
->setText(i18n("Show Hidden Files"));
1053 //showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_ KDE4-TODO: what Qt-Key represents '.'?
1054 connect(showHiddenFiles
, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles()));
1056 KToggleAction
* split
= actionCollection()->add
<KToggleAction
>("split_view");
1057 split
->setText(i18n("Split View"));
1058 split
->setShortcut(Qt::Key_F10
);
1059 split
->setIcon(KIcon("view_left_right"));
1060 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1062 QAction
* reload
= actionCollection()->addAction("reload");
1063 reload
->setText(i18n("Reload"));
1064 reload
->setShortcut(Qt::Key_F5
);
1065 reload
->setIcon(KIcon("reload"));
1066 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1068 QAction
* stop
= actionCollection()->addAction("stop");
1069 stop
->setText(i18n("Stop"));
1070 stop
->setIcon(KIcon("stop"));
1071 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1073 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1074 showFullLocation
->setText(i18n("Show Full Location"));
1075 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1076 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1078 KToggleAction
* editLocation
= actionCollection()->add
<KToggleAction
>("edit_location");
1079 editLocation
->setText(i18n("Edit Location"));
1080 editLocation
->setShortcut(Qt::Key_F6
);
1081 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
1083 QAction
* adjustViewProps
= actionCollection()->addAction("view_properties");
1084 adjustViewProps
->setText(i18n("Adjust View Properties..."));
1085 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1088 KStandardAction::back(this, SLOT(goBack()), actionCollection());
1089 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1090 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1091 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1093 // setup 'Tools' menu
1094 QAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1095 openTerminal
->setText(i18n("Open Terminal"));
1096 openTerminal
->setShortcut(Qt::Key_F4
);
1097 openTerminal
->setIcon(KIcon("konsole"));
1098 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1100 QAction
* findFile
= actionCollection()->addAction("find_file");
1101 findFile
->setText(i18n("Find File..."));
1102 findFile
->setShortcut(Qt::Key_F
);
1103 findFile
->setIcon(KIcon("filefind"));
1104 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
1106 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1107 showFilterBar
->setText(i18n("Show Filter Bar"));
1108 showFilterBar
->setShortcut(Qt::Key_Slash
);
1109 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1111 QAction
* compareFiles
= actionCollection()->addAction("compare_files");
1112 compareFiles
->setText(i18n("Compare Files"));
1113 compareFiles
->setIcon(KIcon("kompare"));
1114 compareFiles
->setEnabled(false);
1115 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1117 // setup 'Settings' menu
1118 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1121 void DolphinMainWindow::setupDockWidgets()
1123 QDockWidget
* shortcutsDock
= new QDockWidget(i18n("Bookmarks"));
1124 shortcutsDock
->setObjectName("bookmarksDock");
1125 shortcutsDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1126 shortcutsDock
->setWidget(new BookmarksSidebarPage(this));
1128 shortcutsDock
->toggleViewAction()->setText(i18n("Show Bookmarks Panel"));
1129 actionCollection()->addAction("show_bookmarks_panel", shortcutsDock
->toggleViewAction());
1131 addDockWidget(Qt::LeftDockWidgetArea
, shortcutsDock
);
1133 QDockWidget
* infoDock
= new QDockWidget(i18n("Information"));
1134 infoDock
->setObjectName("infoDock");
1135 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1136 infoDock
->setWidget(new InfoSidebarPage(this));
1138 infoDock
->toggleViewAction()->setText(i18n("Show Information Panel"));
1139 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1141 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1144 void DolphinMainWindow::updateHistory()
1147 const QLinkedList
<UrlNavigator::HistoryElem
> list
= m_activeView
->urlHistory(index
);
1149 QAction
* backAction
= actionCollection()->action("go_back");
1150 if (backAction
!= 0) {
1151 backAction
->setEnabled(index
< static_cast<int>(list
.count()) - 1);
1154 QAction
* forwardAction
= actionCollection()->action("go_forward");
1155 if (forwardAction
!= 0) {
1156 forwardAction
->setEnabled(index
> 0);
1160 void DolphinMainWindow::updateEditActions()
1162 const KFileItemList list
= m_activeView
->selectedItems();
1163 if (list
.isEmpty()) {
1164 stateChanged("has_no_selection");
1167 stateChanged("has_selection");
1169 QAction
* renameAction
= actionCollection()->action("rename");
1170 if (renameAction
!= 0) {
1171 renameAction
->setEnabled(list
.count() >= 1);
1174 bool enableMoveToTrash
= true;
1176 KFileItemList::const_iterator it
= list
.begin();
1177 const KFileItemList::const_iterator end
= list
.end();
1179 KFileItem
* item
= *it
;
1180 const KUrl
& url
= item
->url();
1181 // only enable the 'Move to Trash' action for local files
1182 if (!url
.isLocalFile()) {
1183 enableMoveToTrash
= false;
1188 QAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
1189 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1191 updatePasteAction();
1194 void DolphinMainWindow::updateViewActions()
1196 QAction
* zoomInAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomIn
));
1197 if (zoomInAction
!= 0) {
1198 zoomInAction
->setEnabled(m_activeView
->isZoomInPossible());
1201 QAction
* zoomOutAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomOut
));
1202 if (zoomOutAction
!= 0) {
1203 zoomOutAction
->setEnabled(m_activeView
->isZoomOutPossible());
1206 QAction
* action
= 0;
1207 switch (m_activeView
->mode()) {
1208 case DolphinView::IconsView
:
1209 action
= actionCollection()->action("icons");
1211 case DolphinView::DetailsView
:
1212 action
= actionCollection()->action("details");
1219 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
1220 toggleAction
->setChecked(true);
1223 slotSortingChanged(m_activeView
->sorting());
1224 slotSortOrderChanged(m_activeView
->sortOrder());
1226 KToggleAction
* showFilterBarAction
=
1227 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
1228 showFilterBarAction
->setChecked(m_activeView
->isFilterBarVisible());
1230 KToggleAction
* showHiddenFilesAction
=
1231 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
1232 showHiddenFilesAction
->setChecked(m_activeView
->showHiddenFiles());
1234 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1235 splitAction
->setChecked(m_view
[SecondaryIdx
] != 0);
1238 void DolphinMainWindow::updateGoActions()
1240 QAction
* goUpAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Up
));
1241 const KUrl
& currentUrl
= m_activeView
->url();
1242 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1245 void DolphinMainWindow::copyUrls(const KUrl::List
& source
, const KUrl
& dest
)
1247 KonqOperations::copy(this, KonqOperations::COPY
, source
, dest
);
1248 m_undoOperations
.append(KonqOperations::COPY
);
1251 void DolphinMainWindow::moveUrls(const KUrl::List
& source
, const KUrl
& dest
)
1253 KonqOperations::copy(this, KonqOperations::MOVE
, source
, dest
);
1254 m_undoOperations
.append(KonqOperations::MOVE
);
1257 void DolphinMainWindow::linkUrls(const KUrl::List
& source
, const KUrl
& dest
)
1259 KonqOperations::copy(this, KonqOperations::LINK
, source
, dest
);
1260 m_undoOperations
.append(KonqOperations::LINK
);
1263 void DolphinMainWindow::clearStatusBar()
1265 m_activeView
->statusBar()->clear();
1268 void DolphinMainWindow::connectViewSignals(int viewIndex
)
1270 DolphinView
* view
= m_view
[viewIndex
];
1271 connect(view
, SIGNAL(modeChanged()),
1272 this, SLOT(slotViewModeChanged()));
1273 connect(view
, SIGNAL(showHiddenFilesChanged()),
1274 this, SLOT(slotShowHiddenFilesChanged()));
1275 connect(view
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
1276 this, SLOT(slotSortingChanged(DolphinView::Sorting
)));
1277 connect(view
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
1278 this, SLOT(slotSortOrderChanged(Qt::SortOrder
)));
1279 connect(view
, SIGNAL(selectionChanged()),
1280 this, SLOT(slotSelectionChanged()));
1281 connect(view
, SIGNAL(showFilterBarChanged(bool)),
1282 this, SLOT(updateFilterBarAction(bool)));
1284 const UrlNavigator
* navigator
= view
->urlNavigator();
1285 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1286 this, SLOT(slotUrlChanged(const KUrl
&)));
1287 connect(navigator
, SIGNAL(historyChanged()),
1288 this, SLOT(slotHistoryChanged()));
1292 DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow
* mainWin
) :
1293 KonqUndoManager::UiInterface(mainWin
),
1296 assert(m_mainWin
!= 0);
1299 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1303 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1305 DolphinStatusBar
* statusBar
= m_mainWin
->activeView()->statusBar();
1306 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1309 #include "dolphinmainwindow.moc"