]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
8a7cda1dd2a523947755546fd2f55ea1d0152c10
[dolphin.git] / src / dolphinmainwindow.cpp
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> *
5 * *
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. *
10 * *
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. *
15 * *
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 ***************************************************************************/
21
22 #include "dolphinmainwindow.h"
23 #include "dolphinviewactionhandler.h"
24
25 #include <config-nepomuk.h>
26
27 #include "dolphinapplication.h"
28 #include "dolphinnewmenu.h"
29 #include "settings/dolphinsettings.h"
30 #include "settings/dolphinsettingsdialog.h"
31 #include "dolphinsearchbox.h"
32 #include "dolphinstatusbar.h"
33 #include "dolphinviewcontainer.h"
34 #include "panels/folders/folderspanel.h"
35 #include "panels/places/placespanel.h"
36 #include "panels/information/informationpanel.h"
37 #include "panels/information/metadatawidget.h"
38 #include "mainwindowadaptor.h"
39 #include "viewproperties.h"
40
41 #ifndef Q_OS_WIN
42 #include "panels/terminal/terminalpanel.h"
43 #endif
44
45 #include "dolphin_generalsettings.h"
46 #include "dolphin_iconsmodesettings.h"
47 #include "draganddrophelper.h"
48
49 #include <kaction.h>
50 #include <kactioncollection.h>
51 #include <kconfig.h>
52 #include <kdesktopfile.h>
53 #include <kdeversion.h>
54 #include <kfiledialog.h>
55 #include <kfileplacesmodel.h>
56 #include <kglobal.h>
57 #include <klineedit.h>
58 #include <ktoolbar.h>
59 #include <kicon.h>
60 #include <kiconloader.h>
61 #include <kio/netaccess.h>
62 #include <kinputdialog.h>
63 #include <klocale.h>
64 #include <kprotocolmanager.h>
65 #include <kmenu.h>
66 #include <kmenubar.h>
67 #include <kmessagebox.h>
68 #include <konq_fileitemcapabilities.h>
69 #include <konqmimedata.h>
70 #include <kprotocolinfo.h>
71 #include <krun.h>
72 #include <kshell.h>
73 #include <kstandarddirs.h>
74 #include <kstatusbar.h>
75 #include <kstandardaction.h>
76 #include <ktabbar.h>
77 #include <ktoggleaction.h>
78 #include <kurlnavigator.h>
79 #include <kurl.h>
80 #include <kurlcombobox.h>
81
82 #include <QDBusMessage>
83 #include <QKeyEvent>
84 #include <QClipboard>
85 #include <QLineEdit>
86 #include <QSplitter>
87 #include <QDockWidget>
88
89 /*
90 * Remembers the tab configuration if a tab has been closed.
91 * Each closed tab can be restored by the menu
92 * "Go -> Recently Closed Tabs".
93 */
94 struct ClosedTab
95 {
96 KUrl primaryUrl;
97 KUrl secondaryUrl;
98 bool isSplit;
99 };
100 Q_DECLARE_METATYPE(ClosedTab)
101
102 DolphinMainWindow::DolphinMainWindow(int id) :
103 KXmlGuiWindow(0),
104 m_newMenu(0),
105 m_showMenuBar(0),
106 m_tabBar(0),
107 m_activeViewContainer(0),
108 m_centralWidgetLayout(0),
109 m_searchBox(0),
110 m_id(id),
111 m_tabIndex(0),
112 m_viewTab(),
113 m_actionHandler(0),
114 m_settingsDialog(0)
115 {
116 setObjectName("Dolphin#");
117
118 m_viewTab.append(ViewTab());
119
120 new MainWindowAdaptor(this);
121 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id), this);
122
123 KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
124 undoManager->setUiInterface(new UndoUiInterface());
125
126 connect(undoManager, SIGNAL(undoAvailable(bool)),
127 this, SLOT(slotUndoAvailable(bool)));
128 connect(undoManager, SIGNAL(undoTextChanged(const QString&)),
129 this, SLOT(slotUndoTextChanged(const QString&)));
130 connect(undoManager, SIGNAL(jobRecordingStarted(CommandType)),
131 this, SLOT(clearStatusBar()));
132 connect(undoManager, SIGNAL(jobRecordingFinished(CommandType)),
133 this, SLOT(showCommand(CommandType)));
134 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString&)),
135 this, SLOT(showErrorMessage(const QString&)));
136 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString&)),
137 this, SLOT(showErrorMessage(const QString&)));
138 }
139
140 DolphinMainWindow::~DolphinMainWindow()
141 {
142 DolphinApplication::app()->removeMainWindow(this);
143 }
144
145 void DolphinMainWindow::toggleViews()
146 {
147 if (m_viewTab[m_tabIndex].primaryView == 0) {
148 return;
149 }
150
151 // move secondary view from the last position of the splitter
152 // to the first position
153 m_viewTab[m_tabIndex].splitter->insertWidget(0, m_viewTab[m_tabIndex].secondaryView);
154
155 DolphinViewContainer* container = m_viewTab[m_tabIndex].primaryView;
156 m_viewTab[m_tabIndex].primaryView = m_viewTab[m_tabIndex].secondaryView;
157 m_viewTab[m_tabIndex].secondaryView = container;
158 }
159
160 void DolphinMainWindow::showCommand(CommandType command)
161 {
162 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
163 switch (command) {
164 case KIO::FileUndoManager::Copy:
165 statusBar->setMessage(i18nc("@info:status", "Copy operation completed."),
166 DolphinStatusBar::OperationCompleted);
167 break;
168 case KIO::FileUndoManager::Move:
169 statusBar->setMessage(i18nc("@info:status", "Move operation completed."),
170 DolphinStatusBar::OperationCompleted);
171 break;
172 case KIO::FileUndoManager::Link:
173 statusBar->setMessage(i18nc("@info:status", "Link operation completed."),
174 DolphinStatusBar::OperationCompleted);
175 break;
176 case KIO::FileUndoManager::Trash:
177 statusBar->setMessage(i18nc("@info:status", "Move to trash operation completed."),
178 DolphinStatusBar::OperationCompleted);
179 break;
180 case KIO::FileUndoManager::Rename:
181 statusBar->setMessage(i18nc("@info:status", "Renaming operation completed."),
182 DolphinStatusBar::OperationCompleted);
183 break;
184
185 case KIO::FileUndoManager::Mkdir:
186 statusBar->setMessage(i18nc("@info:status", "Created folder."),
187 DolphinStatusBar::OperationCompleted);
188 break;
189
190 default:
191 break;
192 }
193 }
194
195 void DolphinMainWindow::refreshViews()
196 {
197 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
198
199 // remember the current active view, as because of
200 // the refreshing the active view might change to
201 // the secondary view
202 DolphinViewContainer* activeViewContainer = m_activeViewContainer;
203
204 const int tabCount = m_viewTab.count();
205 for (int i = 0; i < tabCount; ++i) {
206 m_viewTab[i].primaryView->refresh();
207 if (m_viewTab[i].secondaryView != 0) {
208 m_viewTab[i].secondaryView->refresh();
209 }
210 }
211
212 setActiveViewContainer(activeViewContainer);
213 }
214
215 void DolphinMainWindow::pasteIntoFolder()
216 {
217 m_activeViewContainer->view()->pasteIntoFolder();
218 }
219
220 void DolphinMainWindow::changeUrl(const KUrl& url)
221 {
222 if (!KProtocolManager::supportsListing(url)) {
223 // The URL navigator only checks for validity, not
224 // if the URL can be listed. An error message is
225 // shown due to DolphinViewContainer::restoreView().
226 return;
227 }
228
229 DolphinViewContainer* view = activeViewContainer();
230 if (view != 0) {
231 view->setUrl(url);
232 updateEditActions();
233 updateViewActions();
234 updateGoActions();
235 setCaption(url.fileName());
236 if (m_viewTab.count() > 1) {
237 m_tabBar->setTabText(m_tabIndex, tabName(url));
238 }
239 emit urlChanged(url);
240 }
241 }
242
243 void DolphinMainWindow::changeSelection(const KFileItemList& selection)
244 {
245 activeViewContainer()->view()->changeSelection(selection);
246 }
247
248 void DolphinMainWindow::slotEditableStateChanged(bool editable)
249 {
250 KToggleAction* editableLocationAction =
251 static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
252 editableLocationAction->setChecked(editable);
253 }
254
255 void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
256 {
257 updateEditActions();
258
259 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
260 int selectedUrlsCount = m_viewTab[m_tabIndex].primaryView->view()->selectedItemsCount();
261 if (m_viewTab[m_tabIndex].secondaryView != 0) {
262 selectedUrlsCount += m_viewTab[m_tabIndex].secondaryView->view()->selectedItemsCount();
263 }
264
265 QAction* compareFilesAction = actionCollection()->action("compare_files");
266 if (selectedUrlsCount == 2) {
267 compareFilesAction->setEnabled(isKompareInstalled());
268 } else {
269 compareFilesAction->setEnabled(false);
270 }
271
272 #if defined(QUICK_VIEW)
273 const bool activeViewHasSelection = (activeViewContainer()->view()->selectedItemsCount() > 0);
274 actionCollection()->action("quick_view")->setEnabled(activeViewHasSelection);
275 #endif
276
277 m_activeViewContainer->updateStatusBar();
278
279 emit selectionChanged(selection);
280 }
281
282 void DolphinMainWindow::slotWheelMoved(int wheelDelta)
283 {
284 if (wheelDelta > 0) {
285 activatePrevTab();
286 } else {
287 activateNextTab();
288 }
289 }
290
291 void DolphinMainWindow::slotRequestItemInfo(const KFileItem& item)
292 {
293 emit requestItemInfo(item);
294 }
295
296 void DolphinMainWindow::updateHistory()
297 {
298 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
299 const int index = urlNavigator->historyIndex();
300
301 QAction* backAction = actionCollection()->action("go_back");
302 if (backAction != 0) {
303 backAction->setEnabled(index < urlNavigator->historySize() - 1);
304 }
305
306 QAction* forwardAction = actionCollection()->action("go_forward");
307 if (forwardAction != 0) {
308 forwardAction->setEnabled(index > 0);
309 }
310 }
311
312 void DolphinMainWindow::updateFilterBarAction(bool show)
313 {
314 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
315 showFilterBarAction->setChecked(show);
316 }
317
318 void DolphinMainWindow::openNewMainWindow()
319 {
320 DolphinApplication::app()->createMainWindow()->show();
321 }
322
323 void DolphinMainWindow::openNewTab()
324 {
325 openNewTab(m_activeViewContainer->url());
326 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
327
328 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
329 if (navigator->isUrlEditable()) {
330 // if a new tab is opened and the URL is editable, assure that
331 // the user can edit the URL without manually setting the focus
332 navigator->setFocus();
333 }
334 }
335
336 void DolphinMainWindow::openNewTab(const KUrl& url)
337 {
338 if (m_viewTab.count() == 1) {
339 // Only one view is open currently and hence no tab is shown at
340 // all. Before creating a tab for 'url', provide a tab for the current URL.
341 m_tabBar->addTab(KIcon("folder"), tabName(m_activeViewContainer->url()));
342 m_tabBar->blockSignals(false);
343 }
344
345 m_tabBar->addTab(KIcon("folder"), tabName(url));
346
347 ViewTab viewTab;
348 viewTab.splitter = new QSplitter(this);
349 viewTab.primaryView = new DolphinViewContainer(this, viewTab.splitter, url);
350 viewTab.primaryView->setActive(false);
351 connectViewSignals(viewTab.primaryView);
352 viewTab.primaryView->view()->reload();
353
354 m_viewTab.append(viewTab);
355
356 actionCollection()->action("close_tab")->setEnabled(true);
357
358 // provide a split view, if the startup settings are set this way
359 const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
360 if (generalSettings->splitView()) {
361 const int tabIndex = m_viewTab.count() - 1;
362 createSecondaryView(tabIndex);
363 m_viewTab[tabIndex].secondaryView->setActive(true);
364 m_viewTab[tabIndex].isPrimaryViewActive = false;
365 }
366 }
367
368 void DolphinMainWindow::activateNextTab()
369 {
370 if (m_viewTab.count() == 1 || m_tabBar->count() < 2) {
371 return;
372 }
373
374 const int tabIndex = (m_tabBar->currentIndex() + 1) % m_tabBar->count();
375 m_tabBar->setCurrentIndex(tabIndex);
376 }
377
378 void DolphinMainWindow::activatePrevTab()
379 {
380 if (m_viewTab.count() == 1 || m_tabBar->count() < 2) {
381 return;
382 }
383
384 int tabIndex = m_tabBar->currentIndex() - 1;
385 if (tabIndex == -1) {
386 tabIndex = m_tabBar->count() - 1;
387 }
388 m_tabBar->setCurrentIndex(tabIndex);
389 }
390
391 void DolphinMainWindow::openInNewTab()
392 {
393 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
394 if ((list.count() == 1) && list[0].isDir()) {
395 openNewTab(m_activeViewContainer->view()->selectedUrls()[0]);
396 }
397 }
398
399 void DolphinMainWindow::openInNewWindow()
400 {
401 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
402 if ((list.count() == 1) && list[0].isDir()) {
403 DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
404 window->changeUrl(m_activeViewContainer->view()->selectedUrls()[0]);
405 window->show();
406 }
407 }
408
409 void DolphinMainWindow::toggleActiveView()
410 {
411 if (m_viewTab[m_tabIndex].secondaryView == 0) {
412 // only one view is available
413 return;
414 }
415
416 Q_ASSERT(m_activeViewContainer != 0);
417 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
418
419 DolphinViewContainer* left = m_viewTab[m_tabIndex].primaryView;
420 DolphinViewContainer* right = m_viewTab[m_tabIndex].secondaryView;
421 setActiveViewContainer(m_activeViewContainer == right ? left : right);
422 }
423
424 void DolphinMainWindow::closeEvent(QCloseEvent* event)
425 {
426 DolphinSettings& settings = DolphinSettings::instance();
427 GeneralSettings* generalSettings = settings.generalSettings();
428 generalSettings->setFirstRun(false);
429
430 settings.save();
431
432 KXmlGuiWindow::closeEvent(event);
433 }
434
435 void DolphinMainWindow::saveProperties(KConfigGroup& group)
436 {
437 // TODO: remember tabs
438 DolphinViewContainer* cont = m_viewTab[m_tabIndex].primaryView;
439 group.writeEntry("Primary Url", cont->url().url());
440 group.writeEntry("Primary Editable Url", cont->isUrlEditable());
441
442 cont = m_viewTab[m_tabIndex].secondaryView;
443 if (cont != 0) {
444 group.writeEntry("Secondary Url", cont->url().url());
445 group.writeEntry("Secondary Editable Url", cont->isUrlEditable());
446 }
447 }
448
449 void DolphinMainWindow::readProperties(const KConfigGroup& group)
450 {
451 // TODO: read tabs
452 DolphinViewContainer* cont = m_viewTab[m_tabIndex].primaryView;
453
454 cont->setUrl(group.readEntry("Primary Url"));
455 bool editable = group.readEntry("Primary Editable Url", false);
456 cont->urlNavigator()->setUrlEditable(editable);
457
458 cont = m_viewTab[m_tabIndex].secondaryView;
459 const QString secondaryUrl = group.readEntry("Secondary Url");
460 if (!secondaryUrl.isEmpty()) {
461 if (cont == 0) {
462 // a secondary view should be shown, but no one is available
463 // currently -> create a new view
464 toggleSplitView();
465 cont = m_viewTab[m_tabIndex].secondaryView;
466 Q_ASSERT(cont != 0);
467 }
468
469 cont->setUrl(secondaryUrl);
470 bool editable = group.readEntry("Secondary Editable Url", false);
471 cont->urlNavigator()->setUrlEditable(editable);
472 } else if (cont != 0) {
473 // no secondary view should be shown, but the default setting shows
474 // one already -> close the view
475 toggleSplitView();
476 }
477 }
478
479 void DolphinMainWindow::updateNewMenu()
480 {
481 m_newMenu->slotCheckUpToDate();
482 m_newMenu->setPopupFiles(activeViewContainer()->url());
483 }
484
485 void DolphinMainWindow::quit()
486 {
487 close();
488 }
489
490 void DolphinMainWindow::showErrorMessage(const QString& message)
491 {
492 if (!message.isEmpty()) {
493 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
494 statusBar->setMessage(message, DolphinStatusBar::Error);
495 }
496 }
497
498 void DolphinMainWindow::slotUndoAvailable(bool available)
499 {
500 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
501 if (undoAction != 0) {
502 undoAction->setEnabled(available);
503 }
504 }
505
506 void DolphinMainWindow::restoreClosedTab(QAction* action)
507 {
508 //The Clear Recently Closed Tabs List QAction, has it's data set to true, so we can detect it in here, as it's an exception.
509 if (action->data().toBool() == true) {
510 // Lets preserve the separator, and the clear action within this menu.
511 QList<QAction*> actionlist = m_recentTabsMenu->menu()->actions();
512 for (int i = 2; i < actionlist.size(); i++) {
513 m_recentTabsMenu->menu()->removeAction(actionlist.at(i));
514 }
515 } else {
516 const ClosedTab closedTab = action->data().value<ClosedTab>();
517
518 openNewTab(closedTab.primaryUrl);
519 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
520
521 if (closedTab.isSplit) {
522 //Create secondary view.
523 toggleSplitView();
524 m_viewTab[m_tabIndex].secondaryView->setUrl(closedTab.secondaryUrl);
525 }
526
527 m_recentTabsMenu->removeAction(action);
528 }
529
530 if (m_recentTabsMenu->menu()->actions().count() == 2) {
531 m_recentTabsMenu->setEnabled(false);
532 }
533 }
534
535 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
536 {
537 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
538 if (undoAction != 0) {
539 undoAction->setText(text);
540 }
541 }
542
543 void DolphinMainWindow::undo()
544 {
545 clearStatusBar();
546 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
547 KIO::FileUndoManager::self()->undo();
548 }
549
550 void DolphinMainWindow::cut()
551 {
552 m_activeViewContainer->view()->cutSelectedItems();
553 }
554
555 void DolphinMainWindow::copy()
556 {
557 m_activeViewContainer->view()->copySelectedItems();
558 }
559
560 void DolphinMainWindow::paste()
561 {
562 m_activeViewContainer->view()->paste();
563 }
564
565 void DolphinMainWindow::updatePasteAction()
566 {
567 QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
568 QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
569 pasteAction->setEnabled(pasteInfo.first);
570 pasteAction->setText(pasteInfo.second);
571 }
572
573 void DolphinMainWindow::selectAll()
574 {
575 clearStatusBar();
576
577 // if the URL navigator is editable and focused, select the whole
578 // URL instead of all items of the view
579
580 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
581 QLineEdit* lineEdit = urlNavigator->editor()->lineEdit();
582 const bool selectUrl = urlNavigator->isUrlEditable() &&
583 lineEdit->hasFocus();
584 if (selectUrl) {
585 lineEdit->selectAll();
586 } else {
587 m_activeViewContainer->view()->selectAll();
588 }
589 }
590
591 void DolphinMainWindow::invertSelection()
592 {
593 clearStatusBar();
594 m_activeViewContainer->view()->invertSelection();
595 }
596
597 void DolphinMainWindow::toggleSplitView()
598 {
599 if (m_viewTab[m_tabIndex].secondaryView == 0) {
600 createSecondaryView(m_tabIndex);
601 setActiveViewContainer(m_viewTab[m_tabIndex].secondaryView);
602 } else if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
603 // remove secondary view
604 m_viewTab[m_tabIndex].secondaryView->close();
605 m_viewTab[m_tabIndex].secondaryView->deleteLater();
606 m_viewTab[m_tabIndex].secondaryView = 0;
607
608 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
609 } else {
610 // The primary view is active and should be closed. Hence from a users point of view
611 // the content of the secondary view should be moved to the primary view.
612 // From an implementation point of view it is more efficient to close
613 // the primary view and exchange the internal pointers afterwards.
614
615 m_viewTab[m_tabIndex].primaryView->close();
616 m_viewTab[m_tabIndex].primaryView->deleteLater();
617 m_viewTab[m_tabIndex].primaryView = m_viewTab[m_tabIndex].secondaryView;
618 m_viewTab[m_tabIndex].secondaryView = 0;
619
620 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
621 }
622
623 updateViewActions();
624 }
625
626 void DolphinMainWindow::reloadView()
627 {
628 clearStatusBar();
629 m_activeViewContainer->view()->reload();
630 }
631
632 void DolphinMainWindow::stopLoading()
633 {
634 }
635
636 void DolphinMainWindow::toggleFilterBarVisibility(bool show)
637 {
638 m_activeViewContainer->showFilterBar(show);
639 }
640
641 void DolphinMainWindow::toggleEditLocation()
642 {
643 clearStatusBar();
644
645 QAction* action = actionCollection()->action("editable_location");
646 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
647 urlNavigator->setUrlEditable(action->isChecked());
648 }
649
650 void DolphinMainWindow::replaceLocation()
651 {
652 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
653 navigator->setUrlEditable(true);
654 navigator->setFocus();
655
656 // select the whole text of the combo box editor
657 QLineEdit* lineEdit = navigator->editor()->lineEdit();
658 const QString text = lineEdit->text();
659 lineEdit->setSelection(0, text.length());
660 }
661
662 void DolphinMainWindow::goBack()
663 {
664 clearStatusBar();
665 m_activeViewContainer->urlNavigator()->goBack();
666 }
667
668 void DolphinMainWindow::goForward()
669 {
670 clearStatusBar();
671 m_activeViewContainer->urlNavigator()->goForward();
672 }
673
674 void DolphinMainWindow::goUp()
675 {
676 clearStatusBar();
677 m_activeViewContainer->urlNavigator()->goUp();
678 }
679
680 void DolphinMainWindow::goHome()
681 {
682 clearStatusBar();
683 m_activeViewContainer->urlNavigator()->goHome();
684 }
685
686 void DolphinMainWindow::compareFiles()
687 {
688 // The method is only invoked if exactly 2 files have
689 // been selected. The selected files may be:
690 // - both in the primary view
691 // - both in the secondary view
692 // - one in the primary view and the other in the secondary
693 // view
694 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
695
696 KUrl urlA;
697 KUrl urlB;
698 KUrl::List urls = m_viewTab[m_tabIndex].primaryView->view()->selectedUrls();
699
700 switch (urls.count()) {
701 case 0: {
702 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView != 0);
703 urls = m_viewTab[m_tabIndex].secondaryView->view()->selectedUrls();
704 Q_ASSERT(urls.count() == 2);
705 urlA = urls[0];
706 urlB = urls[1];
707 break;
708 }
709
710 case 1: {
711 urlA = urls[0];
712 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView != 0);
713 urls = m_viewTab[m_tabIndex].secondaryView->view()->selectedUrls();
714 Q_ASSERT(urls.count() == 1);
715 urlB = urls[0];
716 break;
717 }
718
719 case 2: {
720 urlA = urls[0];
721 urlB = urls[1];
722 break;
723 }
724
725 default: {
726 // may not happen: compareFiles may only get invoked if 2
727 // files are selected
728 Q_ASSERT(false);
729 }
730 }
731
732 QString command("kompare -c \"");
733 command.append(urlA.pathOrUrl());
734 command.append("\" \"");
735 command.append(urlB.pathOrUrl());
736 command.append('\"');
737 KRun::runCommand(command, "Kompare", "kompare", this);
738 }
739
740 void DolphinMainWindow::quickView()
741 {
742 const KUrl::List urls = activeViewContainer()->view()->selectedUrls();
743 Q_ASSERT(urls.count() > 0);
744
745 QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.plasma", "/Previewer", "", "openFile");
746 foreach (const KUrl& url, urls) {
747 msg.setArguments(QList<QVariant>() << url.prettyUrl());
748 QDBusConnection::sessionBus().send(msg);
749 }
750 }
751
752 void DolphinMainWindow::toggleShowMenuBar()
753 {
754 const bool visible = menuBar()->isVisible();
755 menuBar()->setVisible(!visible);
756 }
757
758 void DolphinMainWindow::editSettings()
759 {
760 if (m_settingsDialog == 0) {
761 const KUrl& url = activeViewContainer()->url();
762 m_settingsDialog = new DolphinSettingsDialog(url, this);
763 m_settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
764 m_settingsDialog->show();
765 } else {
766 m_settingsDialog->raise();
767 }
768 }
769
770 void DolphinMainWindow::setActiveTab(int index)
771 {
772 Q_ASSERT(index >= 0);
773 Q_ASSERT(index < m_viewTab.count());
774 if (index == m_tabIndex) {
775 return;
776 }
777
778 // hide current tab content
779 ViewTab& hiddenTab = m_viewTab[m_tabIndex];
780 hiddenTab.isPrimaryViewActive = hiddenTab.primaryView->isActive();
781 hiddenTab.primaryView->setActive(false);
782 if (hiddenTab.secondaryView != 0) {
783 hiddenTab.secondaryView->setActive(false);
784 }
785 QSplitter* splitter = m_viewTab[m_tabIndex].splitter;
786 splitter->hide();
787 m_centralWidgetLayout->removeWidget(splitter);
788
789 // show active tab content
790 m_tabIndex = index;
791
792 ViewTab& viewTab = m_viewTab[index];
793 m_centralWidgetLayout->addWidget(viewTab.splitter);
794 viewTab.primaryView->show();
795 if (viewTab.secondaryView != 0) {
796 viewTab.secondaryView->show();
797 }
798 viewTab.splitter->show();
799
800 setActiveViewContainer(viewTab.isPrimaryViewActive ? viewTab.primaryView :
801 viewTab.secondaryView);
802 }
803
804 void DolphinMainWindow::closeTab()
805 {
806 closeTab(m_tabBar->currentIndex());
807 }
808
809 void DolphinMainWindow::closeTab(int index)
810 {
811 Q_ASSERT(index >= 0);
812 Q_ASSERT(index < m_viewTab.count());
813 if (m_viewTab.count() == 1) {
814 // the last tab may never get closed
815 return;
816 }
817
818 if (index == m_tabIndex) {
819 // The tab that should be closed is the active tab. Activate the
820 // previous tab before closing the tab.
821 m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1);
822 }
823 rememberClosedTab(index);
824 //Delete this tab.
825 m_viewTab[index].primaryView->deleteLater();
826 if (m_viewTab[index].secondaryView != 0) {
827 m_viewTab[index].secondaryView->deleteLater();
828 }
829 m_viewTab[index].splitter->deleteLater();
830 m_viewTab.erase(m_viewTab.begin() + index);
831
832 m_tabBar->blockSignals(true);
833 m_tabBar->removeTab(index);
834
835 if (m_tabIndex > index) {
836 m_tabIndex--;
837 Q_ASSERT(m_tabIndex >= 0);
838 }
839
840 // if only one tab is left, also remove the tab entry so that
841 // closing the last tab is not possible
842 if (m_viewTab.count() == 1) {
843 m_tabBar->removeTab(0);
844 actionCollection()->action("close_tab")->setEnabled(false);
845 } else {
846 m_tabBar->blockSignals(false);
847 }
848 }
849
850 void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos)
851 {
852 KMenu menu(this);
853
854 QAction* newTabAction = menu.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
855 newTabAction->setShortcut(actionCollection()->action("new_tab")->shortcut());
856
857 QAction* closeOtherTabsAction = menu.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
858
859 QAction* closeTabAction = menu.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
860 closeTabAction->setShortcut(actionCollection()->action("close_tab")->shortcut());
861
862 QAction* selectedAction = menu.exec(pos);
863 if (selectedAction == newTabAction) {
864 const ViewTab& tab = m_viewTab[index];
865 Q_ASSERT(tab.primaryView != 0);
866 const KUrl url = (tab.secondaryView != 0) && tab.secondaryView->isActive() ?
867 tab.secondaryView->url() : tab.primaryView->url();
868 openNewTab(url);
869 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
870 } else if (selectedAction == closeOtherTabsAction) {
871 const int count = m_tabBar->count();
872 for (int i = 0; i < index; ++i) {
873 closeTab(0);
874 }
875 for (int i = index + 1; i < count; ++i) {
876 closeTab(1);
877 }
878 } else if (selectedAction == closeTabAction) {
879 closeTab(index);
880 }
881 }
882
883 void DolphinMainWindow::handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons)
884 {
885 if (buttons & Qt::MidButton) {
886 openNewTab(url);
887 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
888 } else {
889 changeUrl(url);
890 }
891 }
892
893 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& canDecode)
894 {
895 canDecode = KUrl::List::canDecode(event->mimeData());
896 }
897
898 void DolphinMainWindow::searchItems(const KUrl& url)
899 {
900 m_activeViewContainer->setUrl(url);
901 }
902
903
904 void DolphinMainWindow::init()
905 {
906 DolphinSettings& settings = DolphinSettings::instance();
907
908 // Check whether Dolphin runs the first time. If yes then
909 // a proper default window size is given at the end of DolphinMainWindow::init().
910 GeneralSettings* generalSettings = settings.generalSettings();
911 const bool firstRun = generalSettings->firstRun();
912 if (firstRun) {
913 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
914 }
915
916 setAcceptDrops(true);
917
918 m_viewTab[m_tabIndex].splitter = new QSplitter(this);
919
920 setupActions();
921
922 const KUrl& homeUrl = generalSettings->homeUrl();
923 setCaption(homeUrl.fileName());
924 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
925 connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
926 ViewProperties props(homeUrl);
927 m_viewTab[m_tabIndex].primaryView = new DolphinViewContainer(this,
928 m_viewTab[m_tabIndex].splitter,
929 homeUrl);
930
931 m_activeViewContainer = m_viewTab[m_tabIndex].primaryView;
932 connectViewSignals(m_activeViewContainer);
933 DolphinView* view = m_activeViewContainer->view();
934 view->reload();
935 m_activeViewContainer->show();
936 m_actionHandler->setCurrentView(view);
937
938 m_tabBar = new KTabBar(this);
939 m_tabBar->setMovable(true);
940 m_tabBar->setTabsClosable(true);
941 connect(m_tabBar, SIGNAL(currentChanged(int)),
942 this, SLOT(setActiveTab(int)));
943 connect(m_tabBar, SIGNAL(closeRequest(int)),
944 this, SLOT(closeTab(int)));
945 connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)),
946 this, SLOT(openTabContextMenu(int, const QPoint&)));
947 connect(m_tabBar, SIGNAL(newTabRequest()),
948 this, SLOT(openNewTab()));
949 connect(m_tabBar, SIGNAL(testCanDecode(const QDragMoveEvent*, bool&)),
950 this, SLOT(slotTestCanDecode(const QDragMoveEvent*, bool&)));
951 connect(m_tabBar, SIGNAL(wheelDelta(int)),
952 this, SLOT(slotWheelMoved(int)));
953 connect(m_tabBar, SIGNAL(mouseMiddleClick(int)),
954 this, SLOT(closeTab(int)));
955
956 m_tabBar->blockSignals(true); // signals get unblocked after at least 2 tabs are open
957
958 QWidget* centralWidget = new QWidget(this);
959 m_centralWidgetLayout = new QVBoxLayout(centralWidget);
960 m_centralWidgetLayout->setSpacing(0);
961 m_centralWidgetLayout->setMargin(0);
962 m_centralWidgetLayout->addWidget(m_tabBar);
963 m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter);
964
965 setCentralWidget(centralWidget);
966 setupDockWidgets();
967 emit urlChanged(homeUrl);
968
969 setupGUI(Keys | Save | Create | ToolBar);
970
971 m_searchBox->setParent(toolBar("searchToolBar"));
972 m_searchBox->show();
973
974 stateChanged("new_file");
975
976 QClipboard* clipboard = QApplication::clipboard();
977 connect(clipboard, SIGNAL(dataChanged()),
978 this, SLOT(updatePasteAction()));
979 updatePasteAction();
980 updateGoActions();
981
982 if (generalSettings->splitView()) {
983 toggleSplitView();
984 }
985 updateViewActions();
986
987 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
988 showFilterBarAction->setChecked(generalSettings->filterBar());
989
990 if (firstRun) {
991 // assure a proper default size if Dolphin runs the first time
992 resize(750, 500);
993 }
994
995 m_showMenuBar->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
996 }
997
998 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
999 {
1000 Q_ASSERT(viewContainer != 0);
1001 Q_ASSERT((viewContainer == m_viewTab[m_tabIndex].primaryView) ||
1002 (viewContainer == m_viewTab[m_tabIndex].secondaryView));
1003 if (m_activeViewContainer == viewContainer) {
1004 return;
1005 }
1006
1007 m_activeViewContainer->setActive(false);
1008 m_activeViewContainer = viewContainer;
1009
1010 // Activating the view container might trigger a recursive setActiveViewContainer() call
1011 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1012 // disconnect the activated() signal in this case:
1013 disconnect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1014 m_activeViewContainer->setActive(true);
1015 connect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1016
1017 m_actionHandler->setCurrentView(viewContainer->view());
1018
1019 updateHistory();
1020 updateEditActions();
1021 updateViewActions();
1022 updateGoActions();
1023
1024 const KUrl& url = m_activeViewContainer->url();
1025 setCaption(url.fileName());
1026 if (m_viewTab.count() > 1) {
1027 m_tabBar->setTabText(m_tabIndex, tabName(url));
1028 }
1029
1030 emit urlChanged(url);
1031 }
1032
1033 void DolphinMainWindow::setupActions()
1034 {
1035 // setup 'File' menu
1036 m_newMenu = new DolphinNewMenu(this, this);
1037 KMenu* menu = m_newMenu->menu();
1038 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1039 menu->setIcon(KIcon("document-new"));
1040 connect(menu, SIGNAL(aboutToShow()),
1041 this, SLOT(updateNewMenu()));
1042
1043 KAction* newWindow = actionCollection()->addAction("new_window");
1044 newWindow->setIcon(KIcon("window-new"));
1045 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1046 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
1047 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1048
1049 KAction* newTab = actionCollection()->addAction("new_tab");
1050 newTab->setIcon(KIcon("tab-new"));
1051 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1052 newTab->setShortcut(KShortcut(Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N));
1053 connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab()));
1054
1055 KAction* closeTab = actionCollection()->addAction("close_tab");
1056 closeTab->setIcon(KIcon("tab-close"));
1057 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1058 closeTab->setShortcut(Qt::CTRL | Qt::Key_W);
1059 closeTab->setEnabled(false);
1060 connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
1061
1062 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1063
1064 // setup 'Edit' menu
1065 KStandardAction::undo(this,
1066 SLOT(undo()),
1067 actionCollection());
1068
1069 // need to remove shift+del from cut action, else the shortcut for deletejob
1070 // doesn't work
1071 KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
1072 KShortcut cutShortcut = cut->shortcut();
1073 cutShortcut.remove(Qt::SHIFT + Qt::Key_Delete, KShortcut::KeepEmpty);
1074 cut->setShortcut(cutShortcut);
1075 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1076 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1077
1078 KAction* selectAll = actionCollection()->addAction("select_all");
1079 selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
1080 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
1081 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
1082
1083 KAction* invertSelection = actionCollection()->addAction("invert_selection");
1084 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1085 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1086 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
1087
1088 // setup 'View' menu
1089 // (note that most of it is set up in DolphinViewActionHandler)
1090
1091 KAction* split = actionCollection()->addAction("split_view");
1092 split->setShortcut(Qt::Key_F3);
1093 updateSplitAction();
1094 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1095
1096 KAction* reload = actionCollection()->addAction("reload");
1097 reload->setText(i18nc("@action:inmenu View", "Reload"));
1098 reload->setShortcut(Qt::Key_F5);
1099 reload->setIcon(KIcon("view-refresh"));
1100 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
1101
1102 KAction* stop = actionCollection()->addAction("stop");
1103 stop->setText(i18nc("@action:inmenu View", "Stop"));
1104 stop->setIcon(KIcon("process-stop"));
1105 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
1106
1107 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
1108 showFullLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1109 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
1110 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1111
1112 KAction* replaceLocation = actionCollection()->addAction("replace_location");
1113 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1114 replaceLocation->setShortcut(Qt::Key_F6);
1115 connect(replaceLocation, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1116
1117 // setup 'Go' menu
1118 KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
1119 KShortcut backShortcut = backAction->shortcut();
1120 backShortcut.setAlternate(Qt::Key_Backspace);
1121 backAction->setShortcut(backShortcut);
1122
1123 m_recentTabsMenu = new KActionMenu(i18n("&Recently Closed Tabs"), this);
1124 m_recentTabsMenu->setIcon(KIcon("edit-undo"));
1125 actionCollection()->addAction("closed_tabs", m_recentTabsMenu);
1126 connect(m_recentTabsMenu->menu(), SIGNAL(triggered(QAction *)),
1127 this, SLOT(restoreClosedTab(QAction *)));
1128
1129 QAction* action = new QAction("&Empty Recently Closed Tabs", m_recentTabsMenu);
1130 action->setIcon(KIcon("edit-clear-list"));
1131 action->setData(QVariant::fromValue(true));
1132 m_recentTabsMenu->addAction(action);
1133 m_recentTabsMenu->addSeparator();
1134 m_recentTabsMenu->setEnabled(false);
1135
1136 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1137 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1138 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1139
1140 // setup 'Tools' menu
1141 KToggleAction* showSearchBar = actionCollection()->add<KToggleAction>("show_search_bar");
1142 showSearchBar->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1143 showSearchBar->setShortcut(Qt::CTRL | Qt::Key_S);
1144 connect(showSearchBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1145
1146 KToggleAction* showFilterBar = actionCollection()->add<KToggleAction>("show_filter_bar");
1147 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1148 showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
1149 connect(showFilterBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1150
1151 KAction* compareFiles = actionCollection()->addAction("compare_files");
1152 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1153 compareFiles->setIcon(KIcon("kompare"));
1154 compareFiles->setEnabled(false);
1155 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1156
1157 // disabled Quick View
1158 #if defined(QUICK_VIEW)
1159 KAction* quickView = actionCollection()->addAction("quick_view");
1160 quickView->setText(i18nc("@action:inmenu Tools", "Quick View"));
1161 quickView->setIcon(KIcon("view-preview"));
1162 quickView->setShortcut(Qt::CTRL + Qt::Key_Return);
1163 quickView->setEnabled(false);
1164 connect(quickView, SIGNAL(triggered()), this, SLOT(quickView()));
1165 #endif
1166
1167 // setup 'Settings' menu
1168 m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1169 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1170
1171 // not in menu actions
1172 KAction* activateNextTab = actionCollection()->addAction("activate_next_tab");
1173 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1174 connect(activateNextTab, SIGNAL(triggered()), SLOT(activateNextTab()));
1175 activateNextTab->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1176 KStandardShortcut::tabNext());
1177
1178 KAction* activatePrevTab = actionCollection()->addAction("activate_prev_tab");
1179 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1180 connect(activatePrevTab, SIGNAL(triggered()), SLOT(activatePrevTab()));
1181 activatePrevTab->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1182 KStandardShortcut::tabPrev());
1183
1184 // for context menu
1185 KAction* openInNewTab = actionCollection()->addAction("open_in_new_tab");
1186 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
1187 openInNewTab->setIcon(KIcon("tab-new"));
1188 connect(openInNewTab, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1189
1190 KAction* openInNewWindow = actionCollection()->addAction("open_in_new_window");
1191 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
1192 openInNewWindow->setIcon(KIcon("window-new"));
1193 connect(openInNewWindow, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1194
1195 // 'Search' toolbar
1196 m_searchBox = new DolphinSearchBox(this);
1197 connect(m_searchBox, SIGNAL(search(KUrl)), this, SLOT(searchItems(KUrl)));
1198
1199 KAction* search = new KAction(this);
1200 actionCollection()->addAction("search_bar", search);
1201 search->setText(i18nc("@action:inmenu", "Search Bar"));
1202 search->setDefaultWidget(m_searchBox);
1203 search->setShortcutConfigurable(false);
1204 }
1205
1206 void DolphinMainWindow::setupDockWidgets()
1207 {
1208 // setup "Information"
1209 QDockWidget* infoDock = new QDockWidget(i18nc("@title:window", "Information"));
1210 infoDock->setObjectName("infoDock");
1211 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1212 Panel* infoPanel = new InformationPanel(infoDock);
1213 infoDock->setWidget(infoPanel);
1214
1215 QAction* infoAction = infoDock->toggleViewAction();
1216 infoAction->setText(i18nc("@title:window", "Information"));
1217 infoAction->setShortcut(Qt::Key_F11);
1218 infoAction->setIcon(KIcon("dialog-information"));
1219 actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction());
1220
1221 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1222 connect(this, SIGNAL(urlChanged(KUrl)),
1223 infoPanel, SLOT(setUrl(KUrl)));
1224 connect(this, SIGNAL(selectionChanged(KFileItemList)),
1225 infoPanel, SLOT(setSelection(KFileItemList)));
1226 connect(this, SIGNAL(requestItemInfo(KFileItem)),
1227 infoPanel, SLOT(requestDelayedItemInfo(KFileItem)));
1228
1229 // setup "Folders"
1230 QDockWidget* foldersDock = new QDockWidget(i18nc("@title:window", "Folders"));
1231 foldersDock->setObjectName("foldersDock");
1232 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1233 FoldersPanel* foldersPanel = new FoldersPanel(foldersDock);
1234 foldersDock->setWidget(foldersPanel);
1235
1236 QAction* foldersAction = foldersDock->toggleViewAction();
1237 foldersAction->setText(i18nc("@title:window", "Folders"));
1238 foldersAction->setShortcut(Qt::Key_F7);
1239 foldersAction->setIcon(KIcon("folder"));
1240 actionCollection()->addAction("show_folders_panel", foldersDock->toggleViewAction());
1241
1242 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
1243 connect(this, SIGNAL(urlChanged(KUrl)),
1244 foldersPanel, SLOT(setUrl(KUrl)));
1245 connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
1246 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1247 connect(foldersPanel, SIGNAL(changeSelection(KFileItemList)),
1248 this, SLOT(changeSelection(KFileItemList)));
1249
1250 // setup "Terminal"
1251 #ifndef Q_OS_WIN
1252 QDockWidget* terminalDock = new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1253 terminalDock->setObjectName("terminalDock");
1254 terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1255 Panel* terminalPanel = new TerminalPanel(terminalDock);
1256 terminalDock->setWidget(terminalPanel);
1257
1258 connect(terminalPanel, SIGNAL(hideTerminalPanel()), terminalDock, SLOT(hide()));
1259
1260 QAction* terminalAction = terminalDock->toggleViewAction();
1261 terminalAction->setText(i18nc("@title:window Shell terminal", "Terminal"));
1262 terminalAction->setShortcut(Qt::Key_F4);
1263 terminalAction->setIcon(KIcon("terminal"));
1264 actionCollection()->addAction("show_terminal_panel", terminalDock->toggleViewAction());
1265
1266 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
1267 connect(this, SIGNAL(urlChanged(KUrl)),
1268 terminalPanel, SLOT(setUrl(KUrl)));
1269 #endif
1270
1271 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
1272 if (firstRun) {
1273 foldersDock->hide();
1274 #ifndef Q_OS_WIN
1275 terminalDock->hide();
1276 #endif
1277 }
1278
1279 QDockWidget* placesDock = new QDockWidget(i18nc("@title:window", "Places"));
1280 placesDock->setObjectName("placesDock");
1281 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1282
1283 PlacesPanel* placesPanel = new PlacesPanel(placesDock);
1284 placesDock->setWidget(placesPanel);
1285 placesPanel->setModel(DolphinSettings::instance().placesModel());
1286 placesPanel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1287
1288 QAction* placesAction = placesDock->toggleViewAction();
1289 placesAction->setText(i18nc("@title:window", "Places"));
1290 placesAction->setShortcut(Qt::Key_F9);
1291 placesAction->setIcon(KIcon("bookmarks"));
1292 actionCollection()->addAction("show_places_panel", placesDock->toggleViewAction());
1293
1294 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1295 connect(placesPanel, SIGNAL(urlChanged(KUrl, Qt::MouseButtons)),
1296 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1297 connect(this, SIGNAL(urlChanged(KUrl)),
1298 placesPanel, SLOT(setUrl(KUrl)));
1299 }
1300
1301 void DolphinMainWindow::updateEditActions()
1302 {
1303 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
1304 if (list.isEmpty()) {
1305 stateChanged("has_no_selection");
1306 } else {
1307 stateChanged("has_selection");
1308
1309 KActionCollection* col = actionCollection();
1310 QAction* renameAction = col->action("rename");
1311 QAction* moveToTrashAction = col->action("move_to_trash");
1312 QAction* deleteAction = col->action("delete");
1313 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
1314 QAction* deleteWithTrashShortcut = col->action("delete_shortcut"); // see DolphinViewActionHandler
1315
1316 KonqFileItemCapabilities capabilities(list);
1317 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
1318
1319 renameAction->setEnabled(capabilities.supportsMoving());
1320 moveToTrashAction->setEnabled(enableMoveToTrash);
1321 deleteAction->setEnabled(capabilities.supportsDeleting());
1322 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
1323 cutAction->setEnabled(capabilities.supportsMoving());
1324 }
1325 updatePasteAction();
1326 }
1327
1328 void DolphinMainWindow::updateViewActions()
1329 {
1330 m_actionHandler->updateViewActions();
1331
1332 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1333 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
1334
1335 updateSplitAction();
1336
1337 QAction* editableLocactionAction = actionCollection()->action("editable_location");
1338 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
1339 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
1340 }
1341
1342 void DolphinMainWindow::updateGoActions()
1343 {
1344 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
1345 const KUrl& currentUrl = m_activeViewContainer->url();
1346 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1347 }
1348
1349 void DolphinMainWindow::rememberClosedTab(int index)
1350 {
1351 KMenu* tabsMenu = m_recentTabsMenu->menu();
1352
1353 const QString primaryPath = m_viewTab[index].primaryView->url().path();
1354 const QString iconName = KMimeType::iconNameForUrl(primaryPath);
1355
1356 QAction* action = new QAction(primaryPath, tabsMenu);
1357
1358 ClosedTab closedTab;
1359 closedTab.primaryUrl = m_viewTab[index].primaryView->url();
1360
1361 if (m_viewTab[index].secondaryView != 0) {
1362 closedTab.secondaryUrl = m_viewTab[index].secondaryView->url();
1363 closedTab.isSplit = true;
1364 } else {
1365 closedTab.isSplit = false;
1366 }
1367
1368 action->setData(QVariant::fromValue(closedTab));
1369 action->setIcon(KIcon(iconName));
1370
1371 //Add our action after the separator and the clear list actions
1372 if (tabsMenu->actions().size() == 2) {
1373 tabsMenu->addAction(action);
1374 } else {
1375
1376 tabsMenu->insertAction(tabsMenu->actions().at(2), action);
1377 }
1378 actionCollection()->action("closed_tabs")->setEnabled(true);
1379 }
1380
1381 void DolphinMainWindow::clearStatusBar()
1382 {
1383 m_activeViewContainer->statusBar()->clear();
1384 }
1385
1386 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
1387 {
1388 connect(container, SIGNAL(showFilterBarChanged(bool)),
1389 this, SLOT(updateFilterBarAction(bool)));
1390
1391 DolphinView* view = container->view();
1392 connect(view, SIGNAL(selectionChanged(KFileItemList)),
1393 this, SLOT(slotSelectionChanged(KFileItemList)));
1394 connect(view, SIGNAL(requestItemInfo(KFileItem)),
1395 this, SLOT(slotRequestItemInfo(KFileItem)));
1396 connect(view, SIGNAL(activated()),
1397 this, SLOT(toggleActiveView()));
1398 connect(view, SIGNAL(tabRequested(const KUrl&)),
1399 this, SLOT(openNewTab(const KUrl&)));
1400
1401 const KUrlNavigator* navigator = container->urlNavigator();
1402 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1403 this, SLOT(changeUrl(const KUrl&)));
1404 connect(navigator, SIGNAL(historyChanged()),
1405 this, SLOT(updateHistory()));
1406 connect(navigator, SIGNAL(editableStateChanged(bool)),
1407 this, SLOT(slotEditableStateChanged(bool)));
1408 }
1409
1410 void DolphinMainWindow::updateSplitAction()
1411 {
1412 QAction* splitAction = actionCollection()->action("split_view");
1413 if (m_viewTab[m_tabIndex].secondaryView != 0) {
1414 if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
1415 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
1416 splitAction->setIcon(KIcon("view-right-close"));
1417 } else {
1418 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
1419 splitAction->setIcon(KIcon("view-left-close"));
1420 }
1421 } else {
1422 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
1423 splitAction->setIcon(KIcon("view-right-new"));
1424 }
1425 }
1426
1427 QString DolphinMainWindow::tabName(const KUrl& url) const
1428 {
1429 QString name;
1430 if (url.equals(KUrl("file:///"))) {
1431 name = "/";
1432 } else {
1433 name = url.fileName();
1434 if (name.isEmpty()) {
1435 name = url.protocol();
1436 } else {
1437 // Make sure that a '&' inside the directory name is displayed correctly
1438 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1439 name.replace('&', "&&");
1440 }
1441 }
1442 return name;
1443 }
1444
1445 bool DolphinMainWindow::isKompareInstalled() const
1446 {
1447 static bool initialized = false;
1448 static bool installed = false;
1449 if (!initialized) {
1450 // TODO: maybe replace this approach later by using a menu
1451 // plugin like kdiff3plugin.cpp
1452 installed = !KGlobal::dirs()->findExe("kompare").isEmpty();
1453 initialized = true;
1454 }
1455 return installed;
1456 }
1457
1458 void DolphinMainWindow::createSecondaryView(int tabIndex)
1459 {
1460 QSplitter* splitter = m_viewTab[tabIndex].splitter;
1461 const int newWidth = (m_viewTab[tabIndex].primaryView->width() - splitter->handleWidth()) / 2;
1462
1463 const DolphinView* view = m_viewTab[tabIndex].primaryView->view();
1464 m_viewTab[tabIndex].secondaryView = new DolphinViewContainer(this, 0, view->rootUrl());
1465 splitter->addWidget(m_viewTab[tabIndex].secondaryView);
1466 splitter->setSizes(QList<int>() << newWidth << newWidth);
1467 connectViewSignals(m_viewTab[tabIndex].secondaryView);
1468 m_viewTab[tabIndex].secondaryView->view()->reload();
1469 m_viewTab[tabIndex].secondaryView->setActive(false);
1470 m_viewTab[tabIndex].secondaryView->show();
1471 }
1472
1473 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1474 KIO::FileUndoManager::UiInterface()
1475 {
1476 }
1477
1478 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1479 {
1480 }
1481
1482 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1483 {
1484 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
1485 if (mainWin) {
1486 DolphinStatusBar* statusBar = mainWin->activeViewContainer()->statusBar();
1487 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1488 } else {
1489 KIO::FileUndoManager::UiInterface::jobError(job);
1490 }
1491 }
1492
1493 #include "dolphinmainwindow.moc"