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