]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Make cursor keys always trigger a statusbar update
[dolphin.git] / src / dolphinmainwindow.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
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
24 #include <config-nepomuk.h>
25
26 #include "dolphinapplication.h"
27 #include "dolphindockwidget.h"
28 #include "dolphincontextmenu.h"
29 #include "dolphinnewfilemenu.h"
30 #include "dolphinviewcontainer.h"
31 #include "mainwindowadaptor.h"
32 #ifdef HAVE_NEPOMUK
33 #include "panels/search/searchpanel.h"
34 #include <Nepomuk/ResourceManager>
35 #endif
36 #include "panels/folders/folderspanel.h"
37 #include "panels/places/placespanel.h"
38 #include "panels/information/informationpanel.h"
39 #include "search/dolphinsearchinformation.h"
40 #include "settings/dolphinsettings.h"
41 #include "settings/dolphinsettingsdialog.h"
42 #include "statusbar/dolphinstatusbar.h"
43 #include "views/dolphinviewactionhandler.h"
44 #include "views/dolphinremoteencoding.h"
45 #include "views/draganddrophelper.h"
46 #include "views/viewproperties.h"
47
48 #ifndef Q_OS_WIN
49 #include "panels/terminal/terminalpanel.h"
50 #endif
51
52 #include "dolphin_generalsettings.h"
53 #include "dolphin_iconsmodesettings.h"
54 #include "dolphin_searchsettings.h"
55
56 #include <KAction>
57 #include <KActionCollection>
58 #include <KActionMenu>
59 #include <KConfig>
60 #include <KDesktopFile>
61 #include <kdeversion.h>
62 #include <kdualaction.h>
63 #include <KFileDialog>
64 #include <KFilePlacesModel>
65 #include <KGlobal>
66 #include <KLineEdit>
67 #include <ktoolbar.h>
68 #include <KIcon>
69 #include <KIconLoader>
70 #include <KIO/NetAccess>
71 #include <KInputDialog>
72 #include <KLocale>
73 #include <KProtocolManager>
74 #include <KMenu>
75 #include <KMenuBar>
76 #include <KMessageBox>
77 #include <KFileItemListProperties>
78 #include <konqmimedata.h>
79 #include <KProtocolInfo>
80 #include <KRun>
81 #include <KShell>
82 #include <KStandardDirs>
83 #include <kstatusbar.h>
84 #include <KStandardAction>
85 #include <ktabbar.h>
86 #include <KToggleAction>
87 #include <KUrlNavigator>
88 #include <KUrl>
89 #include <KUrlComboBox>
90 #include <KToolInvocation>
91
92 #include <QDBusMessage>
93 #include <QKeyEvent>
94 #include <QClipboard>
95 #include <QSplitter>
96 #include <kacceleratormanager.h>
97
98 /*
99 * Remembers the tab configuration if a tab has been closed.
100 * Each closed tab can be restored by the menu
101 * "Go -> Recently Closed Tabs".
102 */
103 struct ClosedTab
104 {
105 KUrl primaryUrl;
106 KUrl secondaryUrl;
107 bool isSplit;
108 };
109 Q_DECLARE_METATYPE(ClosedTab)
110
111 DolphinMainWindow::DolphinMainWindow(int id) :
112 KXmlGuiWindow(0),
113 m_newFileMenu(0),
114 m_showMenuBar(0),
115 m_tabBar(0),
116 m_activeViewContainer(0),
117 m_centralWidgetLayout(0),
118 m_id(id),
119 m_tabIndex(0),
120 m_viewTab(),
121 m_actionHandler(0),
122 m_remoteEncoding(0),
123 m_settingsDialog(0),
124 m_lastHandleUrlStatJob(0),
125 m_searchDockIsTemporaryVisible(false)
126 {
127 // Workaround for a X11-issue in combination with KModifierInfo
128 // (see DolphinContextMenu::initializeModifierKeyInfo() for
129 // more information):
130 DolphinContextMenu::initializeModifierKeyInfo();
131
132 setObjectName("Dolphin#");
133
134 m_viewTab.append(ViewTab());
135
136 new MainWindowAdaptor(this);
137 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id), this);
138
139 KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
140 undoManager->setUiInterface(new UndoUiInterface());
141
142 connect(undoManager, SIGNAL(undoAvailable(bool)),
143 this, SLOT(slotUndoAvailable(bool)));
144 connect(undoManager, SIGNAL(undoTextChanged(const QString&)),
145 this, SLOT(slotUndoTextChanged(const QString&)));
146 connect(undoManager, SIGNAL(jobRecordingStarted(CommandType)),
147 this, SLOT(clearStatusBar()));
148 connect(undoManager, SIGNAL(jobRecordingFinished(CommandType)),
149 this, SLOT(showCommand(CommandType)));
150 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString&)),
151 this, SLOT(showErrorMessage(const QString&)));
152 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString&)),
153 this, SLOT(showErrorMessage(const QString&)));
154 }
155
156 DolphinMainWindow::~DolphinMainWindow()
157 {
158 DolphinApplication::app()->removeMainWindow(this);
159 }
160
161 void DolphinMainWindow::openDirectories(const QList<KUrl>& dirs)
162 {
163 if (dirs.isEmpty()) {
164 return;
165 }
166
167 if (dirs.count() == 1) {
168 m_activeViewContainer->setUrl(dirs.first());
169 return;
170 }
171
172 const int oldOpenTabsCount = m_viewTab.count();
173
174 const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
175 const bool hasSplitView = generalSettings->splitView();
176
177 // Open each directory inside a new tab. If the "split view" option has been enabled,
178 // always show two directories within one tab.
179 QList<KUrl>::const_iterator it = dirs.begin();
180 while (it != dirs.end()) {
181 openNewTab(*it);
182 ++it;
183
184 if (hasSplitView && (it != dirs.end())) {
185 const int tabIndex = m_viewTab.count() - 1;
186 m_viewTab[tabIndex].secondaryView->setUrl(*it);
187 ++it;
188 }
189 }
190
191 // remove the previously opened tabs
192 for (int i = 0; i < oldOpenTabsCount; ++i) {
193 closeTab(0);
194 }
195 }
196
197 void DolphinMainWindow::openFiles(const QList<KUrl>& files)
198 {
199 if (files.isEmpty()) {
200 return;
201 }
202
203 // Get all distinct directories from 'files' and open a tab
204 // for each directory. If the "split view" option is enabled, two
205 // directories are shown inside one tab (see openDirectories()).
206 QList<KUrl> dirs;
207 foreach (const KUrl& url, files) {
208 const KUrl dir(url.directory());
209 if (!dirs.contains(dir)) {
210 dirs.append(dir);
211 }
212 }
213
214 openDirectories(dirs);
215
216 // Select the files. Although the files can be split between several
217 // tabs, there is no need to split 'files' accordingly, as
218 // the DolphinView will just ignore invalid selections.
219 const int tabCount = m_viewTab.count();
220 for (int i = 0; i < tabCount; ++i) {
221 m_viewTab[i].primaryView->view()->markUrlsAsSelected(files);
222 if (m_viewTab[i].secondaryView) {
223 m_viewTab[i].secondaryView->view()->markUrlsAsSelected(files);
224 }
225 }
226 }
227
228 void DolphinMainWindow::showCommand(CommandType command)
229 {
230 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
231 switch (command) {
232 case KIO::FileUndoManager::Copy:
233 statusBar->setMessage(i18nc("@info:status", "Successfully copied."),
234 DolphinStatusBar::OperationCompleted);
235 break;
236 case KIO::FileUndoManager::Move:
237 statusBar->setMessage(i18nc("@info:status", "Successfully moved."),
238 DolphinStatusBar::OperationCompleted);
239 break;
240 case KIO::FileUndoManager::Link:
241 statusBar->setMessage(i18nc("@info:status", "Successfully linked."),
242 DolphinStatusBar::OperationCompleted);
243 break;
244 case KIO::FileUndoManager::Trash:
245 statusBar->setMessage(i18nc("@info:status", "Successfully moved to trash."),
246 DolphinStatusBar::OperationCompleted);
247 break;
248 case KIO::FileUndoManager::Rename:
249 statusBar->setMessage(i18nc("@info:status", "Successfully renamed."),
250 DolphinStatusBar::OperationCompleted);
251 break;
252
253 case KIO::FileUndoManager::Mkdir:
254 statusBar->setMessage(i18nc("@info:status", "Created folder."),
255 DolphinStatusBar::OperationCompleted);
256 break;
257
258 default:
259 break;
260 }
261 }
262
263 void DolphinMainWindow::refreshViews()
264 {
265 Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
266
267 // remember the current active view, as because of
268 // the refreshing the active view might change to
269 // the secondary view
270 DolphinViewContainer* activeViewContainer = m_activeViewContainer;
271
272 const int tabCount = m_viewTab.count();
273 for (int i = 0; i < tabCount; ++i) {
274 m_viewTab[i].primaryView->refresh();
275 if (m_viewTab[i].secondaryView) {
276 m_viewTab[i].secondaryView->refresh();
277 }
278 }
279
280 setActiveViewContainer(activeViewContainer);
281
282 const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
283 if (generalSettings->modifiedStartupSettings()) {
284 // The startup settings have been changed by the user (see bug #254947).
285 // Synchronize the split-view setting with the active view:
286 const bool splitView = generalSettings->splitView();
287 const ViewTab& activeTab = m_viewTab[m_tabIndex];
288 const bool toggle = ( splitView && !activeTab.secondaryView)
289 || (!splitView && activeTab.secondaryView);
290 if (toggle) {
291 toggleSplitView();
292 }
293 }
294 }
295
296 void DolphinMainWindow::pasteIntoFolder()
297 {
298 m_activeViewContainer->view()->pasteIntoFolder();
299 }
300
301 void DolphinMainWindow::changeUrl(const KUrl& url)
302 {
303 if (!KProtocolManager::supportsListing(url)) {
304 // The URL navigator only checks for validity, not
305 // if the URL can be listed. An error message is
306 // shown due to DolphinViewContainer::restoreView().
307 return;
308 }
309
310 DolphinViewContainer* view = activeViewContainer();
311 if (view) {
312 view->setUrl(url);
313 updateEditActions();
314 updateViewActions();
315 updateGoActions();
316 setUrlAsCaption(url);
317 if (m_viewTab.count() > 1) {
318 m_tabBar->setTabText(m_tabIndex, squeezedText(tabName(m_activeViewContainer->url())));
319 }
320 const QString iconName = KMimeType::iconNameForUrl(url);
321 m_tabBar->setTabIcon(m_tabIndex, KIcon(iconName));
322 emit urlChanged(url);
323 }
324 }
325
326 void DolphinMainWindow::slotEditableStateChanged(bool editable)
327 {
328 KToggleAction* editableLocationAction =
329 static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
330 editableLocationAction->setChecked(editable);
331 }
332
333 void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
334 {
335 updateEditActions();
336
337 Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
338 int selectedUrlsCount = m_viewTab[m_tabIndex].primaryView->view()->selectedItemsCount();
339 if (m_viewTab[m_tabIndex].secondaryView) {
340 selectedUrlsCount += m_viewTab[m_tabIndex].secondaryView->view()->selectedItemsCount();
341 }
342
343 QAction* compareFilesAction = actionCollection()->action("compare_files");
344 if (selectedUrlsCount == 2) {
345 compareFilesAction->setEnabled(isKompareInstalled());
346 } else {
347 compareFilesAction->setEnabled(false);
348 }
349
350 emit selectionChanged(selection);
351 }
352
353 void DolphinMainWindow::slotRequestItemInfo(const KFileItem& item)
354 {
355 emit requestItemInfo(item);
356 }
357
358 void DolphinMainWindow::updateHistory()
359 {
360 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
361 const int index = urlNavigator->historyIndex();
362
363 QAction* backAction = actionCollection()->action("go_back");
364 backAction->setToolTip(i18nc("@info", "Go back"));
365 if (backAction) {
366 backAction->setEnabled(index < urlNavigator->historySize() - 1);
367 }
368
369 QAction* forwardAction = actionCollection()->action("go_forward");
370 forwardAction->setToolTip(i18nc("@info", "Go forward"));
371 if (forwardAction) {
372 forwardAction->setEnabled(index > 0);
373 }
374 }
375
376 void DolphinMainWindow::updateFilterBarAction(bool show)
377 {
378 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
379 showFilterBarAction->setChecked(show);
380 }
381
382 void DolphinMainWindow::openNewMainWindow()
383 {
384 DolphinApplication::app()->createMainWindow()->show();
385 }
386
387 void DolphinMainWindow::openNewTab()
388 {
389 const bool isUrlEditable = m_activeViewContainer->urlNavigator()->isUrlEditable();
390
391 openNewTab(m_activeViewContainer->url());
392 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
393
394 // The URL navigator of the new tab should have the same editable state
395 // as the current tab
396 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
397 navigator->setUrlEditable(isUrlEditable);
398
399 if (isUrlEditable) {
400 // If a new tab is opened and the URL is editable, assure that
401 // the user can edit the URL without manually setting the focus
402 navigator->setFocus();
403 }
404 }
405
406 void DolphinMainWindow::openNewTab(const KUrl& url)
407 {
408 QWidget* focusWidget = QApplication::focusWidget();
409
410 if (m_viewTab.count() == 1) {
411 // Only one view is open currently and hence no tab is shown at
412 // all. Before creating a tab for 'url', provide a tab for the current URL.
413 const KUrl currentUrl = m_activeViewContainer->url();
414 m_tabBar->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl)),
415 squeezedText(tabName(currentUrl)));
416 m_tabBar->blockSignals(false);
417 }
418
419 m_tabBar->addTab(KIcon(KMimeType::iconNameForUrl(url)),
420 squeezedText(tabName(url)));
421
422 ViewTab viewTab;
423 viewTab.splitter = new QSplitter(this);
424 viewTab.splitter->setChildrenCollapsible(false);
425 viewTab.primaryView = new DolphinViewContainer(url, viewTab.splitter);
426 viewTab.primaryView->setActive(false);
427 connectViewSignals(viewTab.primaryView);
428
429 m_viewTab.append(viewTab);
430
431 actionCollection()->action("close_tab")->setEnabled(true);
432
433 // provide a split view, if the startup settings are set this way
434 const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
435 if (generalSettings->splitView()) {
436 const int tabIndex = m_viewTab.count() - 1;
437 createSecondaryView(tabIndex);
438 m_viewTab[tabIndex].secondaryView->setActive(true);
439 m_viewTab[tabIndex].isPrimaryViewActive = false;
440 }
441
442 if (focusWidget) {
443 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
444 // in background, assure that the previous focused widget gets the focus back.
445 focusWidget->setFocus();
446 }
447 }
448
449 void DolphinMainWindow::activateNextTab()
450 {
451 if ((m_viewTab.count() == 1) || (m_tabBar->count() < 2)) {
452 return;
453 }
454
455 const int tabIndex = (m_tabBar->currentIndex() + 1) % m_tabBar->count();
456 m_tabBar->setCurrentIndex(tabIndex);
457 }
458
459 void DolphinMainWindow::activatePrevTab()
460 {
461 if ((m_viewTab.count() == 1) || (m_tabBar->count() < 2)) {
462 return;
463 }
464
465 int tabIndex = m_tabBar->currentIndex() - 1;
466 if (tabIndex == -1) {
467 tabIndex = m_tabBar->count() - 1;
468 }
469 m_tabBar->setCurrentIndex(tabIndex);
470 }
471
472 void DolphinMainWindow::openInNewTab()
473 {
474 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
475 if (list.isEmpty()) {
476 openNewTab(m_activeViewContainer->url());
477 } else if ((list.count() == 1) && list[0].isDir()) {
478 openNewTab(list[0].url());
479 }
480 }
481
482 void DolphinMainWindow::openInNewWindow()
483 {
484 KUrl newWindowUrl;
485
486 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
487 if (list.isEmpty()) {
488 newWindowUrl = m_activeViewContainer->url();
489 } else if ((list.count() == 1) && list[0].isDir()) {
490 newWindowUrl = list[0].url();
491 }
492
493 if (!newWindowUrl.isEmpty()) {
494 DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
495 window->changeUrl(newWindowUrl);
496 window->show();
497 }
498 }
499
500 void DolphinMainWindow::toggleActiveView()
501 {
502 if (!m_viewTab[m_tabIndex].secondaryView) {
503 // only one view is available
504 return;
505 }
506
507 Q_ASSERT(m_activeViewContainer);
508 Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
509
510 DolphinViewContainer* left = m_viewTab[m_tabIndex].primaryView;
511 DolphinViewContainer* right = m_viewTab[m_tabIndex].secondaryView;
512 setActiveViewContainer(m_activeViewContainer == right ? left : right);
513 }
514
515 void DolphinMainWindow::showEvent(QShowEvent* event)
516 {
517 KXmlGuiWindow::showEvent(event);
518 if (!event->spontaneous()) {
519 m_activeViewContainer->view()->setFocus();
520 }
521 }
522
523 void DolphinMainWindow::closeEvent(QCloseEvent* event)
524 {
525 DolphinSettings& settings = DolphinSettings::instance();
526 GeneralSettings* generalSettings = settings.generalSettings();
527
528 // Find out if Dolphin is closed directly by the user or
529 // by the session manager because the session is closed
530 bool closedByUser = true;
531 DolphinApplication *application = qobject_cast<DolphinApplication*>(qApp);
532 if (application && application->sessionSaving()) {
533 closedByUser = false;
534 }
535
536 if ((m_viewTab.count() > 1) && generalSettings->confirmClosingMultipleTabs() && closedByUser) {
537 // Ask the user if he really wants to quit and close all tabs.
538 // Open a confirmation dialog with 3 buttons:
539 // KDialog::Yes -> Quit
540 // KDialog::No -> Close only the current tab
541 // KDialog::Cancel -> do nothing
542 KDialog *dialog = new KDialog(this, Qt::Dialog);
543 dialog->setCaption(i18nc("@title:window", "Confirmation"));
544 dialog->setButtons(KDialog::Yes | KDialog::No | KDialog::Cancel);
545 dialog->setModal(true);
546 dialog->setButtonGuiItem(KDialog::Yes, KStandardGuiItem::quit());
547 dialog->setButtonGuiItem(KDialog::No, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
548 dialog->setButtonGuiItem(KDialog::Cancel, KStandardGuiItem::cancel());
549 dialog->setDefaultButton(KDialog::Yes);
550
551 bool doNotAskAgainCheckboxResult = false;
552
553 const int result = KMessageBox::createKMessageBox(dialog,
554 QMessageBox::Warning,
555 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
556 QStringList(),
557 i18n("Do not ask again"),
558 &doNotAskAgainCheckboxResult,
559 KMessageBox::Notify);
560
561 if (doNotAskAgainCheckboxResult) {
562 generalSettings->setConfirmClosingMultipleTabs(false);
563 }
564
565 switch (result) {
566 case KDialog::Yes:
567 // Quit
568 break;
569 case KDialog::No:
570 // Close only the current tab
571 closeTab();
572 default:
573 event->ignore();
574 return;
575 }
576 }
577
578 generalSettings->setFirstRun(false);
579
580 settings.save();
581
582 if (m_searchDockIsTemporaryVisible) {
583 QDockWidget* searchDock = findChild<QDockWidget*>("searchDock");
584 if (searchDock) {
585 searchDock->hide();
586 }
587 m_searchDockIsTemporaryVisible = false;
588 }
589
590 KXmlGuiWindow::closeEvent(event);
591 }
592
593 void DolphinMainWindow::saveProperties(KConfigGroup& group)
594 {
595 const int tabCount = m_viewTab.count();
596 group.writeEntry("Tab Count", tabCount);
597 group.writeEntry("Active Tab Index", m_tabBar->currentIndex());
598
599 for (int i = 0; i < tabCount; ++i) {
600 const DolphinViewContainer* cont = m_viewTab[i].primaryView;
601 group.writeEntry(tabProperty("Primary URL", i), cont->url().url());
602 group.writeEntry(tabProperty("Primary Editable", i),
603 cont->urlNavigator()->isUrlEditable());
604
605 cont = m_viewTab[i].secondaryView;
606 if (cont) {
607 group.writeEntry(tabProperty("Secondary URL", i), cont->url().url());
608 group.writeEntry(tabProperty("Secondary Editable", i),
609 cont->urlNavigator()->isUrlEditable());
610 }
611 }
612 }
613
614 void DolphinMainWindow::readProperties(const KConfigGroup& group)
615 {
616 const int tabCount = group.readEntry("Tab Count", 1);
617 for (int i = 0; i < tabCount; ++i) {
618 DolphinViewContainer* cont = m_viewTab[i].primaryView;
619
620 cont->setUrl(group.readEntry(tabProperty("Primary URL", i)));
621 const bool editable = group.readEntry(tabProperty("Primary Editable", i), false);
622 cont->urlNavigator()->setUrlEditable(editable);
623
624 cont = m_viewTab[i].secondaryView;
625 const QString secondaryUrl = group.readEntry(tabProperty("Secondary URL", i));
626 if (!secondaryUrl.isEmpty()) {
627 if (!cont) {
628 // a secondary view should be shown, but no one is available
629 // currently -> create a new view
630 toggleSplitView();
631 cont = m_viewTab[i].secondaryView;
632 Q_ASSERT(cont);
633 }
634
635 cont->setUrl(secondaryUrl);
636 const bool editable = group.readEntry(tabProperty("Secondary Editable", i), false);
637 cont->urlNavigator()->setUrlEditable(editable);
638 } else if (cont) {
639 // no secondary view should be shown, but the default setting shows
640 // one already -> close the view
641 toggleSplitView();
642 }
643
644 // openNewTab() needs to be called only tabCount - 1 times
645 if (i != tabCount - 1) {
646 openNewTab();
647 }
648 }
649
650 const int index = group.readEntry("Active Tab Index", 0);
651 m_tabBar->setCurrentIndex(index);
652 }
653
654 void DolphinMainWindow::updateNewMenu()
655 {
656 m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
657 m_newFileMenu->checkUpToDate();
658 m_newFileMenu->setPopupFiles(activeViewContainer()->url());
659 }
660
661 void DolphinMainWindow::createDirectory()
662 {
663 m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
664 m_newFileMenu->setPopupFiles(activeViewContainer()->url());
665 m_newFileMenu->createDirectory();
666 }
667
668 void DolphinMainWindow::quit()
669 {
670 close();
671 }
672
673 void DolphinMainWindow::showErrorMessage(const QString& message)
674 {
675 if (!message.isEmpty()) {
676 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
677 statusBar->setMessage(message, DolphinStatusBar::Error);
678 }
679 }
680
681 void DolphinMainWindow::slotUndoAvailable(bool available)
682 {
683 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
684 if (undoAction) {
685 undoAction->setEnabled(available);
686 }
687 }
688
689 void DolphinMainWindow::restoreClosedTab(QAction* action)
690 {
691 if (action->data().toBool()) {
692 // clear all actions except the "Empty Recently Closed Tabs"
693 // action and the separator
694 QList<QAction*> actions = m_recentTabsMenu->menu()->actions();
695 const int count = actions.size();
696 for (int i = 2; i < count; ++i) {
697 m_recentTabsMenu->menu()->removeAction(actions.at(i));
698 }
699 } else {
700 const ClosedTab closedTab = action->data().value<ClosedTab>();
701 openNewTab(closedTab.primaryUrl);
702 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
703
704 if (closedTab.isSplit) {
705 // create secondary view
706 toggleSplitView();
707 m_viewTab[m_tabIndex].secondaryView->setUrl(closedTab.secondaryUrl);
708 }
709
710 m_recentTabsMenu->removeAction(action);
711 }
712
713 if (m_recentTabsMenu->menu()->actions().count() == 2) {
714 m_recentTabsMenu->setEnabled(false);
715 }
716 }
717
718 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
719 {
720 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
721 if (undoAction) {
722 undoAction->setText(text);
723 }
724 }
725
726 void DolphinMainWindow::undo()
727 {
728 clearStatusBar();
729 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
730 KIO::FileUndoManager::self()->undo();
731 }
732
733 void DolphinMainWindow::cut()
734 {
735 m_activeViewContainer->view()->cutSelectedItems();
736 }
737
738 void DolphinMainWindow::copy()
739 {
740 m_activeViewContainer->view()->copySelectedItems();
741 }
742
743 void DolphinMainWindow::paste()
744 {
745 m_activeViewContainer->view()->paste();
746 }
747
748 void DolphinMainWindow::find()
749 {
750 m_activeViewContainer->setSearchModeEnabled(true);
751 }
752
753 void DolphinMainWindow::updatePasteAction()
754 {
755 QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
756 QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
757 pasteAction->setEnabled(pasteInfo.first);
758 pasteAction->setText(pasteInfo.second);
759 }
760
761 void DolphinMainWindow::selectAll()
762 {
763 clearStatusBar();
764
765 // if the URL navigator is editable and focused, select the whole
766 // URL instead of all items of the view
767
768 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
769 QLineEdit* lineEdit = urlNavigator->editor()->lineEdit(); // krazy:exclude=qclasses
770 const bool selectUrl = urlNavigator->isUrlEditable() &&
771 lineEdit->hasFocus();
772 if (selectUrl) {
773 lineEdit->selectAll();
774 } else {
775 m_activeViewContainer->view()->selectAll();
776 }
777 }
778
779 void DolphinMainWindow::invertSelection()
780 {
781 clearStatusBar();
782 m_activeViewContainer->view()->invertSelection();
783 }
784
785 void DolphinMainWindow::toggleSplitView()
786 {
787 if (!m_viewTab[m_tabIndex].secondaryView) {
788 createSecondaryView(m_tabIndex);
789 setActiveViewContainer(m_viewTab[m_tabIndex].secondaryView);
790 } else if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
791 // remove secondary view
792 m_viewTab[m_tabIndex].secondaryView->close();
793 m_viewTab[m_tabIndex].secondaryView->deleteLater();
794 m_viewTab[m_tabIndex].secondaryView = 0;
795
796 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
797 } else {
798 // The primary view is active and should be closed. Hence from a users point of view
799 // the content of the secondary view should be moved to the primary view.
800 // From an implementation point of view it is more efficient to close
801 // the primary view and exchange the internal pointers afterwards.
802
803 m_viewTab[m_tabIndex].primaryView->close();
804 m_viewTab[m_tabIndex].primaryView->deleteLater();
805 m_viewTab[m_tabIndex].primaryView = m_viewTab[m_tabIndex].secondaryView;
806 m_viewTab[m_tabIndex].secondaryView = 0;
807
808 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
809 }
810
811 updateViewActions();
812 }
813
814 void DolphinMainWindow::reloadView()
815 {
816 clearStatusBar();
817 m_activeViewContainer->view()->reload();
818 }
819
820 void DolphinMainWindow::stopLoading()
821 {
822 m_activeViewContainer->view()->stopLoading();
823 }
824
825 void DolphinMainWindow::enableStopAction()
826 {
827 actionCollection()->action("stop")->setEnabled(true);
828 }
829
830 void DolphinMainWindow::disableStopAction()
831 {
832 actionCollection()->action("stop")->setEnabled(false);
833 }
834
835 void DolphinMainWindow::showFilterBar()
836 {
837 m_activeViewContainer->setFilterBarVisible(true);
838 }
839
840 void DolphinMainWindow::toggleEditLocation()
841 {
842 clearStatusBar();
843
844 QAction* action = actionCollection()->action("editable_location");
845 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
846 urlNavigator->setUrlEditable(action->isChecked());
847 }
848
849 void DolphinMainWindow::replaceLocation()
850 {
851 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
852 navigator->setUrlEditable(true);
853 navigator->setFocus();
854
855 // select the whole text of the combo box editor
856 QLineEdit* lineEdit = navigator->editor()->lineEdit(); // krazy:exclude=qclasses
857 lineEdit->selectAll();
858 }
859
860 void DolphinMainWindow::togglePanelLockState()
861 {
862 GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
863
864 const bool newLockState = !generalSettings->lockPanels();
865 foreach (QObject* child, children()) {
866 DolphinDockWidget* dock = qobject_cast<DolphinDockWidget*>(child);
867 if (dock) {
868 dock->setLocked(newLockState);
869 }
870 }
871
872 generalSettings->setLockPanels(newLockState);
873 }
874
875 void DolphinMainWindow::goBack()
876 {
877 clearStatusBar();
878
879 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
880 urlNavigator->goBack();
881
882 if (urlNavigator->locationState().isEmpty()) {
883 // An empty location state indicates a redirection URL,
884 // which must be skipped too
885 urlNavigator->goBack();
886 }
887 }
888
889 void DolphinMainWindow::goForward()
890 {
891 clearStatusBar();
892 m_activeViewContainer->urlNavigator()->goForward();
893 }
894
895 void DolphinMainWindow::goUp()
896 {
897 clearStatusBar();
898 m_activeViewContainer->urlNavigator()->goUp();
899 }
900
901 void DolphinMainWindow::goBack(Qt::MouseButtons buttons)
902 {
903 // The default case (left button pressed) is handled in goBack().
904 if (buttons == Qt::MidButton) {
905 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
906 const int index = urlNavigator->historyIndex() + 1;
907 openNewTab(urlNavigator->locationUrl(index));
908 }
909 }
910
911 void DolphinMainWindow::goForward(Qt::MouseButtons buttons)
912 {
913 // The default case (left button pressed) is handled in goForward().
914 if (buttons == Qt::MidButton) {
915 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
916 const int index = urlNavigator->historyIndex() - 1;
917 openNewTab(urlNavigator->locationUrl(index));
918 }
919 }
920
921 void DolphinMainWindow::goUp(Qt::MouseButtons buttons)
922 {
923 // The default case (left button pressed) is handled in goUp().
924 if (buttons == Qt::MidButton) {
925 openNewTab(activeViewContainer()->url().upUrl());
926 }
927 }
928
929 void DolphinMainWindow::goHome()
930 {
931 clearStatusBar();
932 m_activeViewContainer->urlNavigator()->goHome();
933 }
934
935 void DolphinMainWindow::compareFiles()
936 {
937 // The method is only invoked if exactly 2 files have
938 // been selected. The selected files may be:
939 // - both in the primary view
940 // - both in the secondary view
941 // - one in the primary view and the other in the secondary
942 // view
943 Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
944
945 KUrl urlA;
946 KUrl urlB;
947
948 KFileItemList items = m_viewTab[m_tabIndex].primaryView->view()->selectedItems();
949
950 switch (items.count()) {
951 case 0: {
952 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView);
953 items = m_viewTab[m_tabIndex].secondaryView->view()->selectedItems();
954 Q_ASSERT(items.count() == 2);
955 urlA = items[0].url();
956 urlB = items[1].url();
957 break;
958 }
959
960 case 1: {
961 urlA = items[0].url();
962 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView);
963 items = m_viewTab[m_tabIndex].secondaryView->view()->selectedItems();
964 Q_ASSERT(items.count() == 1);
965 urlB = items[0].url();
966 break;
967 }
968
969 case 2: {
970 urlA = items[0].url();
971 urlB = items[1].url();
972 break;
973 }
974
975 default: {
976 // may not happen: compareFiles may only get invoked if 2
977 // files are selected
978 Q_ASSERT(false);
979 }
980 }
981
982 QString command("kompare -c \"");
983 command.append(urlA.pathOrUrl());
984 command.append("\" \"");
985 command.append(urlB.pathOrUrl());
986 command.append('\"');
987 KRun::runCommand(command, "Kompare", "kompare", this);
988 }
989
990 void DolphinMainWindow::toggleShowMenuBar()
991 {
992 const bool visible = menuBar()->isVisible();
993 menuBar()->setVisible(!visible);
994 }
995
996 void DolphinMainWindow::openTerminal()
997 {
998 QString dir(QDir::homePath());
999
1000 // If the given directory is not local, it can still be the URL of an
1001 // ioslave using UDS_LOCAL_PATH which to be converted first.
1002 KUrl url = KIO::NetAccess::mostLocalUrl(m_activeViewContainer->url(), this);
1003
1004 //If the URL is local after the above conversion, set the directory.
1005 if (url.isLocalFile()) {
1006 dir = url.toLocalFile();
1007 }
1008
1009 KToolInvocation::invokeTerminal(QString(), dir);
1010 }
1011
1012 void DolphinMainWindow::editSettings()
1013 {
1014 if (!m_settingsDialog) {
1015 const KUrl url = activeViewContainer()->url();
1016 m_settingsDialog = new DolphinSettingsDialog(url, this);
1017 m_settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
1018 m_settingsDialog->show();
1019 } else {
1020 m_settingsDialog->raise();
1021 }
1022 }
1023
1024 void DolphinMainWindow::setActiveTab(int index)
1025 {
1026 Q_ASSERT(index >= 0);
1027 Q_ASSERT(index < m_viewTab.count());
1028 if (index == m_tabIndex) {
1029 return;
1030 }
1031
1032 // hide current tab content
1033 ViewTab& hiddenTab = m_viewTab[m_tabIndex];
1034 hiddenTab.isPrimaryViewActive = hiddenTab.primaryView->isActive();
1035 hiddenTab.primaryView->setActive(false);
1036 if (hiddenTab.secondaryView) {
1037 hiddenTab.secondaryView->setActive(false);
1038 }
1039 QSplitter* splitter = m_viewTab[m_tabIndex].splitter;
1040 splitter->hide();
1041 m_centralWidgetLayout->removeWidget(splitter);
1042
1043 // show active tab content
1044 m_tabIndex = index;
1045
1046 ViewTab& viewTab = m_viewTab[index];
1047 m_centralWidgetLayout->addWidget(viewTab.splitter, 1);
1048 viewTab.primaryView->show();
1049 if (viewTab.secondaryView) {
1050 viewTab.secondaryView->show();
1051 }
1052 viewTab.splitter->show();
1053
1054 setActiveViewContainer(viewTab.isPrimaryViewActive ? viewTab.primaryView :
1055 viewTab.secondaryView);
1056 }
1057
1058 void DolphinMainWindow::closeTab()
1059 {
1060 closeTab(m_tabBar->currentIndex());
1061 }
1062
1063 void DolphinMainWindow::closeTab(int index)
1064 {
1065 Q_ASSERT(index >= 0);
1066 Q_ASSERT(index < m_viewTab.count());
1067 if (m_viewTab.count() == 1) {
1068 // the last tab may never get closed
1069 return;
1070 }
1071
1072 if (index == m_tabIndex) {
1073 // The tab that should be closed is the active tab. Activate the
1074 // previous tab before closing the tab.
1075 m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1);
1076 }
1077 rememberClosedTab(index);
1078
1079 // delete tab
1080 m_viewTab[index].primaryView->deleteLater();
1081 if (m_viewTab[index].secondaryView) {
1082 m_viewTab[index].secondaryView->deleteLater();
1083 }
1084 m_viewTab[index].splitter->deleteLater();
1085 m_viewTab.erase(m_viewTab.begin() + index);
1086
1087 m_tabBar->blockSignals(true);
1088 m_tabBar->removeTab(index);
1089
1090 if (m_tabIndex > index) {
1091 m_tabIndex--;
1092 Q_ASSERT(m_tabIndex >= 0);
1093 }
1094
1095 // if only one tab is left, also remove the tab entry so that
1096 // closing the last tab is not possible
1097 if (m_viewTab.count() == 1) {
1098 m_tabBar->removeTab(0);
1099 actionCollection()->action("close_tab")->setEnabled(false);
1100 } else {
1101 m_tabBar->blockSignals(false);
1102 }
1103 }
1104
1105 void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos)
1106 {
1107 KMenu menu(this);
1108
1109 QAction* newTabAction = menu.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1110 newTabAction->setShortcut(actionCollection()->action("new_tab")->shortcut());
1111
1112 QAction* detachTabAction = menu.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1113
1114 QAction* closeOtherTabsAction = menu.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1115
1116 QAction* closeTabAction = menu.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1117 closeTabAction->setShortcut(actionCollection()->action("close_tab")->shortcut());
1118 QAction* selectedAction = menu.exec(pos);
1119 if (selectedAction == newTabAction) {
1120 const ViewTab& tab = m_viewTab[index];
1121 Q_ASSERT(tab.primaryView);
1122 const KUrl url = tab.secondaryView && tab.secondaryView->isActive() ?
1123 tab.secondaryView->url() : tab.primaryView->url();
1124 openNewTab(url);
1125 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
1126 } else if (selectedAction == detachTabAction) {
1127 const ViewTab& tab = m_viewTab[index];
1128 Q_ASSERT(tab.primaryView);
1129 const KUrl primaryUrl = tab.primaryView->url();
1130 DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
1131 window->changeUrl(primaryUrl);
1132
1133 if (tab.secondaryView) {
1134 const KUrl secondaryUrl = tab.secondaryView->url();
1135 if (!window->m_viewTab[0].secondaryView) {
1136 window->toggleSplitView();
1137 }
1138 window->m_viewTab[0].secondaryView->setUrl(secondaryUrl);
1139 if (tab.primaryView->isActive()) {
1140 window->m_viewTab[0].primaryView->setActive(true);
1141 } else {
1142 window->m_viewTab[0].secondaryView->setActive(true);
1143 }
1144 }
1145 window->show();
1146 closeTab(index);
1147 } else if (selectedAction == closeOtherTabsAction) {
1148 const int count = m_tabBar->count();
1149 for (int i = 0; i < index; ++i) {
1150 closeTab(0);
1151 }
1152 for (int i = index + 1; i < count; ++i) {
1153 closeTab(1);
1154 }
1155 } else if (selectedAction == closeTabAction) {
1156 closeTab(index);
1157 }
1158 }
1159
1160 void DolphinMainWindow::slotTabMoved(int from, int to)
1161 {
1162 m_viewTab.move(from, to);
1163 m_tabIndex = m_tabBar->currentIndex();
1164 }
1165
1166 void DolphinMainWindow::handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons)
1167 {
1168 if (buttons & Qt::MidButton) {
1169 openNewTab(url);
1170 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
1171 } else {
1172 changeUrl(url);
1173 }
1174 }
1175
1176 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& canDecode)
1177 {
1178 canDecode = KUrl::List::canDecode(event->mimeData());
1179 }
1180
1181 void DolphinMainWindow::handleUrl(const KUrl& url)
1182 {
1183 delete m_lastHandleUrlStatJob;
1184 m_lastHandleUrlStatJob = 0;
1185
1186 if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
1187 activeViewContainer()->setUrl(url);
1188 } else if (KProtocolManager::supportsListing(url)) {
1189 // stat the URL to see if it is a dir or not
1190 m_lastHandleUrlStatJob = KIO::stat(url, KIO::HideProgressInfo);
1191 connect(m_lastHandleUrlStatJob, SIGNAL(result(KJob*)),
1192 this, SLOT(slotHandleUrlStatFinished(KJob*)));
1193
1194 } else {
1195 new KRun(url, this);
1196 }
1197 }
1198
1199 void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job)
1200 {
1201 m_lastHandleUrlStatJob = 0;
1202 const KIO::UDSEntry entry = static_cast<KIO::StatJob*>(job)->statResult();
1203 const KUrl url = static_cast<KIO::StatJob*>(job)->url();
1204 if (entry.isDir()) {
1205 activeViewContainer()->setUrl(url);
1206 } else {
1207 new KRun(url, this);
1208 }
1209 }
1210
1211 void DolphinMainWindow::tabDropEvent(int tab, QDropEvent* event)
1212 {
1213 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
1214 if (!urls.isEmpty() && tab != -1) {
1215 const ViewTab& viewTab = m_viewTab[tab];
1216 const KUrl destPath = viewTab.isPrimaryViewActive ? viewTab.primaryView->url() : viewTab.secondaryView->url();
1217 DragAndDropHelper::instance().dropUrls(KFileItem(), destPath, event, m_tabBar);
1218 }
1219 }
1220
1221 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
1222 {
1223 newFileMenu()->setEnabled(isFolderWritable);
1224 }
1225
1226 void DolphinMainWindow::slotSearchModeChanged(bool enabled)
1227 {
1228 #ifdef HAVE_NEPOMUK
1229 const KUrl url = m_activeViewContainer->url();
1230 const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
1231 if (!searchInfo.isIndexingEnabled() || !searchInfo.isPathIndexed(url)) {
1232 return;
1233 }
1234
1235 QDockWidget* searchDock = findChild<QDockWidget*>("searchDock");
1236 if (!searchDock) {
1237 return;
1238 }
1239
1240 if (enabled) {
1241 if (!searchDock->isVisible()) {
1242 m_searchDockIsTemporaryVisible = true;
1243 }
1244 searchDock->show();
1245 } else {
1246 if (searchDock->isVisible() && m_searchDockIsTemporaryVisible) {
1247 searchDock->hide();
1248 }
1249 m_searchDockIsTemporaryVisible = false;
1250 }
1251
1252 SearchPanel* searchPanel = qobject_cast<SearchPanel*>(searchDock->widget());
1253 if (searchPanel) {
1254 // Per default any search-operation triggered by the Search Panel is done
1255 // "Everywhere".
1256 SearchPanel::SearchMode searchMode = SearchPanel::Everywhere;
1257
1258 if (enabled && (SearchSettings::location() == QLatin1String("FromHere"))) {
1259 // Only if the search-mode is enabled it is visible for the user whether
1260 // a searching is done "Everywhere" or "From Here" (= current directory).
1261 searchMode = SearchPanel::FromCurrentDir;
1262 }
1263 searchPanel->setSearchMode(searchMode);
1264 }
1265 #else
1266 Q_UNUSED(enabled);
1267 #endif
1268 }
1269
1270 void DolphinMainWindow::openContextMenu(const KFileItem& item,
1271 const KUrl& url,
1272 const QList<QAction*>& customActions)
1273 {
1274 QPointer<DolphinContextMenu> contextMenu = new DolphinContextMenu(this, item, url);
1275 contextMenu->setCustomActions(customActions);
1276 const DolphinContextMenu::Command command = contextMenu->open();
1277
1278 switch (command) {
1279 case DolphinContextMenu::OpenParentFolderInNewWindow: {
1280 DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
1281 window->changeUrl(item.url().upUrl());
1282 window->show();
1283 break;
1284 }
1285
1286 case DolphinContextMenu::OpenParentFolderInNewTab:
1287 openNewTab(item.url().upUrl());
1288 break;
1289
1290 case DolphinContextMenu::None:
1291 default:
1292 break;
1293 }
1294
1295 delete contextMenu;
1296 }
1297
1298 void DolphinMainWindow::init()
1299 {
1300 DolphinSettings& settings = DolphinSettings::instance();
1301
1302 // Check whether Dolphin runs the first time. If yes then
1303 // a proper default window size is given at the end of DolphinMainWindow::init().
1304 GeneralSettings* generalSettings = settings.generalSettings();
1305 const bool firstRun = generalSettings->firstRun();
1306 if (firstRun) {
1307 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
1308 }
1309
1310 setAcceptDrops(true);
1311
1312 m_viewTab[m_tabIndex].splitter = new QSplitter(this);
1313 m_viewTab[m_tabIndex].splitter->setChildrenCollapsible(false);
1314
1315 setupActions();
1316
1317 const KUrl homeUrl(generalSettings->homeUrl());
1318 setUrlAsCaption(homeUrl);
1319 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
1320 connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1321 connect(m_actionHandler, SIGNAL(createDirectory()), SLOT(createDirectory()));
1322 ViewProperties props(homeUrl);
1323 m_viewTab[m_tabIndex].primaryView = new DolphinViewContainer(homeUrl,
1324 m_viewTab[m_tabIndex].splitter);
1325
1326 m_activeViewContainer = m_viewTab[m_tabIndex].primaryView;
1327 connectViewSignals(m_activeViewContainer);
1328 DolphinView* view = m_activeViewContainer->view();
1329 m_activeViewContainer->show();
1330 m_actionHandler->setCurrentView(view);
1331
1332 m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
1333 connect(this, SIGNAL(urlChanged(const KUrl&)),
1334 m_remoteEncoding, SLOT(slotAboutToOpenUrl()));
1335
1336 m_tabBar = new KTabBar(this);
1337 m_tabBar->setMovable(true);
1338 m_tabBar->setTabsClosable(true);
1339 connect(m_tabBar, SIGNAL(currentChanged(int)),
1340 this, SLOT(setActiveTab(int)));
1341 connect(m_tabBar, SIGNAL(tabCloseRequested(int)),
1342 this, SLOT(closeTab(int)));
1343 connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)),
1344 this, SLOT(openTabContextMenu(int, const QPoint&)));
1345 connect(m_tabBar, SIGNAL(newTabRequest()),
1346 this, SLOT(openNewTab()));
1347 connect(m_tabBar, SIGNAL(testCanDecode(const QDragMoveEvent*, bool&)),
1348 this, SLOT(slotTestCanDecode(const QDragMoveEvent*, bool&)));
1349 connect(m_tabBar, SIGNAL(mouseMiddleClick(int)),
1350 this, SLOT(closeTab(int)));
1351 connect(m_tabBar, SIGNAL(tabMoved(int, int)),
1352 this, SLOT(slotTabMoved(int, int)));
1353 connect(m_tabBar, SIGNAL(receivedDropEvent(int, QDropEvent*)),
1354 this, SLOT(tabDropEvent(int, QDropEvent*)));
1355
1356 m_tabBar->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1357
1358 QWidget* centralWidget = new QWidget(this);
1359 m_centralWidgetLayout = new QVBoxLayout(centralWidget);
1360 m_centralWidgetLayout->setSpacing(0);
1361 m_centralWidgetLayout->setMargin(0);
1362 m_centralWidgetLayout->addWidget(m_tabBar);
1363 m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter, 1);
1364
1365 setCentralWidget(centralWidget);
1366 setupDockWidgets();
1367 emit urlChanged(homeUrl);
1368
1369 setupGUI(Keys | Save | Create | ToolBar);
1370 stateChanged("new_file");
1371
1372 QClipboard* clipboard = QApplication::clipboard();
1373 connect(clipboard, SIGNAL(dataChanged()),
1374 this, SLOT(updatePasteAction()));
1375
1376 if (generalSettings->splitView()) {
1377 toggleSplitView();
1378 }
1379 updateEditActions();
1380 updateViewActions();
1381 updateGoActions();
1382
1383 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1384 showFilterBarAction->setChecked(generalSettings->filterBar());
1385
1386 if (firstRun) {
1387 // assure a proper default size if Dolphin runs the first time
1388 resize(750, 500);
1389 }
1390
1391 m_showMenuBar->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1392 }
1393
1394 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
1395 {
1396 Q_ASSERT(viewContainer);
1397 Q_ASSERT((viewContainer == m_viewTab[m_tabIndex].primaryView) ||
1398 (viewContainer == m_viewTab[m_tabIndex].secondaryView));
1399 if (m_activeViewContainer == viewContainer) {
1400 return;
1401 }
1402
1403 m_activeViewContainer->setActive(false);
1404 m_activeViewContainer = viewContainer;
1405
1406 // Activating the view container might trigger a recursive setActiveViewContainer() call
1407 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1408 // disconnect the activated() signal in this case:
1409 disconnect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1410 m_activeViewContainer->setActive(true);
1411 connect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1412
1413 m_actionHandler->setCurrentView(viewContainer->view());
1414
1415 updateHistory();
1416 updateEditActions();
1417 updateViewActions();
1418 updateGoActions();
1419
1420 const KUrl url = m_activeViewContainer->url();
1421 setUrlAsCaption(url);
1422 if (m_viewTab.count() > 1) {
1423 m_tabBar->setTabText(m_tabIndex, tabName(url));
1424 m_tabBar->setTabIcon(m_tabIndex, KIcon(KMimeType::iconNameForUrl(url)));
1425 }
1426
1427 emit urlChanged(url);
1428 }
1429
1430 void DolphinMainWindow::setupActions()
1431 {
1432 // setup 'File' menu
1433 m_newFileMenu = new DolphinNewFileMenu(this);
1434 KMenu* menu = m_newFileMenu->menu();
1435 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1436 menu->setIcon(KIcon("document-new"));
1437 connect(menu, SIGNAL(aboutToShow()),
1438 this, SLOT(updateNewMenu()));
1439
1440 KAction* newWindow = actionCollection()->addAction("new_window");
1441 newWindow->setIcon(KIcon("window-new"));
1442 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1443 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
1444 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1445
1446 KAction* newTab = actionCollection()->addAction("new_tab");
1447 newTab->setIcon(KIcon("tab-new"));
1448 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1449 newTab->setShortcut(KShortcut(Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N));
1450 connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab()));
1451
1452 KAction* closeTab = actionCollection()->addAction("close_tab");
1453 closeTab->setIcon(KIcon("tab-close"));
1454 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1455 closeTab->setShortcut(Qt::CTRL | Qt::Key_W);
1456 closeTab->setEnabled(false);
1457 connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
1458
1459 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1460
1461 // setup 'Edit' menu
1462 KStandardAction::undo(this,
1463 SLOT(undo()),
1464 actionCollection());
1465
1466 // need to remove shift+del from cut action, else the shortcut for deletejob
1467 // doesn't work
1468 KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
1469 KShortcut cutShortcut = cut->shortcut();
1470 cutShortcut.remove(Qt::SHIFT | Qt::Key_Delete, KShortcut::KeepEmpty);
1471 cut->setShortcut(cutShortcut);
1472 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1473 KAction* paste = KStandardAction::paste(this, SLOT(paste()), actionCollection());
1474 // The text of the paste-action is modified dynamically by Dolphin
1475 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1476 // due to the long text, the text "Paste" is used:
1477 paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1478
1479 KStandardAction::find(this, SLOT(find()), actionCollection());
1480
1481 KAction* selectAll = actionCollection()->addAction("select_all");
1482 selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
1483 selectAll->setShortcut(Qt::CTRL | Qt::Key_A);
1484 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
1485
1486 KAction* invertSelection = actionCollection()->addAction("invert_selection");
1487 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1488 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1489 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
1490
1491 // setup 'View' menu
1492 // (note that most of it is set up in DolphinViewActionHandler)
1493
1494 KAction* split = actionCollection()->addAction("split_view");
1495 split->setShortcut(Qt::Key_F3);
1496 updateSplitAction();
1497 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1498
1499 KAction* reload = actionCollection()->addAction("reload");
1500 reload->setText(i18nc("@action:inmenu View", "Reload"));
1501 reload->setShortcut(Qt::Key_F5);
1502 reload->setIcon(KIcon("view-refresh"));
1503 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
1504
1505 KAction* stop = actionCollection()->addAction("stop");
1506 stop->setText(i18nc("@action:inmenu View", "Stop"));
1507 stop->setToolTip(i18nc("@info", "Stop loading"));
1508 stop->setIcon(KIcon("process-stop"));
1509 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
1510
1511 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
1512 showFullLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1513 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
1514 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1515
1516 KAction* replaceLocation = actionCollection()->addAction("replace_location");
1517 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1518 replaceLocation->setShortcut(Qt::Key_F6);
1519 connect(replaceLocation, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1520
1521 // setup 'Go' menu
1522 KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
1523 connect(backAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goBack(Qt::MouseButtons)));
1524 KShortcut backShortcut = backAction->shortcut();
1525 backShortcut.setAlternate(Qt::Key_Backspace);
1526 backAction->setShortcut(backShortcut);
1527
1528 m_recentTabsMenu = new KActionMenu(i18n("Recently Closed Tabs"), this);
1529 m_recentTabsMenu->setIcon(KIcon("edit-undo"));
1530 actionCollection()->addAction("closed_tabs", m_recentTabsMenu);
1531 connect(m_recentTabsMenu->menu(), SIGNAL(triggered(QAction *)),
1532 this, SLOT(restoreClosedTab(QAction *)));
1533
1534 QAction* action = new QAction("Empty Recently Closed Tabs", m_recentTabsMenu);
1535 action->setIcon(KIcon("edit-clear-list"));
1536 action->setData(QVariant::fromValue(true));
1537 m_recentTabsMenu->addAction(action);
1538 m_recentTabsMenu->addSeparator();
1539 m_recentTabsMenu->setEnabled(false);
1540
1541 KAction* forwardAction = KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1542 connect(forwardAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goForward(Qt::MouseButtons)));
1543
1544 KAction* upAction = KStandardAction::up(this, SLOT(goUp()), actionCollection());
1545 connect(upAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goUp(Qt::MouseButtons)));
1546
1547 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1548
1549 // setup 'Tools' menu
1550 KAction* showFilterBar = actionCollection()->addAction("show_filter_bar");
1551 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1552 showFilterBar->setIcon(KIcon("view-filter"));
1553 showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
1554 connect(showFilterBar, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1555
1556 KAction* compareFiles = actionCollection()->addAction("compare_files");
1557 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1558 compareFiles->setIcon(KIcon("kompare"));
1559 compareFiles->setEnabled(false);
1560 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1561
1562 KAction* openTerminal = actionCollection()->addAction("open_terminal");
1563 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1564 openTerminal->setIcon(KIcon("utilities-terminal"));
1565 openTerminal->setShortcut(Qt::SHIFT | Qt::Key_F4);
1566 connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal()));
1567
1568 // setup 'Settings' menu
1569 m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1570 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1571
1572 // not in menu actions
1573 QList<QKeySequence> nextTabKeys;
1574 nextTabKeys.append(KStandardShortcut::tabNext().primary());
1575 nextTabKeys.append(QKeySequence(Qt::CTRL | Qt::Key_Tab));
1576
1577 QList<QKeySequence> prevTabKeys;
1578 prevTabKeys.append(KStandardShortcut::tabPrev().primary());
1579 prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab));
1580
1581 KAction* activateNextTab = actionCollection()->addAction("activate_next_tab");
1582 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1583 connect(activateNextTab, SIGNAL(triggered()), SLOT(activateNextTab()));
1584 activateNextTab->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys : nextTabKeys);
1585
1586 KAction* activatePrevTab = actionCollection()->addAction("activate_prev_tab");
1587 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1588 connect(activatePrevTab, SIGNAL(triggered()), SLOT(activatePrevTab()));
1589 activatePrevTab->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys : prevTabKeys);
1590
1591 // for context menu
1592 KAction* openInNewTab = actionCollection()->addAction("open_in_new_tab");
1593 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
1594 openInNewTab->setIcon(KIcon("tab-new"));
1595 connect(openInNewTab, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1596
1597 KAction* openInNewWindow = actionCollection()->addAction("open_in_new_window");
1598 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
1599 openInNewWindow->setIcon(KIcon("window-new"));
1600 connect(openInNewWindow, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1601 }
1602
1603 void DolphinMainWindow::setupDockWidgets()
1604 {
1605 const bool lock = DolphinSettings::instance().generalSettings()->lockPanels();
1606
1607 KDualAction* lockLayoutAction = actionCollection()->add<KDualAction>("lock_panels");
1608 lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1609 lockLayoutAction->setActiveIcon(KIcon("object-unlocked"));
1610 lockLayoutAction->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1611 lockLayoutAction->setInactiveIcon(KIcon("object-locked"));
1612 lockLayoutAction->setActive(lock);
1613 connect(lockLayoutAction, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1614
1615 // Setup "Information"
1616 DolphinDockWidget* infoDock = new DolphinDockWidget(i18nc("@title:window", "Information"));
1617 infoDock->setLocked(lock);
1618 infoDock->setObjectName("infoDock");
1619 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1620 Panel* infoPanel = new InformationPanel(infoDock);
1621 infoPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1622 connect(infoPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
1623 infoDock->setWidget(infoPanel);
1624
1625 QAction* infoAction = infoDock->toggleViewAction();
1626 infoAction->setIcon(KIcon("dialog-information"));
1627 infoAction->setShortcut(Qt::Key_F11);
1628 addActionCloneToCollection(infoAction, "show_information_panel");
1629
1630 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1631 connect(this, SIGNAL(urlChanged(KUrl)),
1632 infoPanel, SLOT(setUrl(KUrl)));
1633 connect(this, SIGNAL(selectionChanged(KFileItemList)),
1634 infoPanel, SLOT(setSelection(KFileItemList)));
1635 connect(this, SIGNAL(requestItemInfo(KFileItem)),
1636 infoPanel, SLOT(requestDelayedItemInfo(KFileItem)));
1637
1638 // Setup "Folders"
1639 DolphinDockWidget* foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders"));
1640 foldersDock->setLocked(lock);
1641 foldersDock->setObjectName("foldersDock");
1642 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1643 FoldersPanel* foldersPanel = new FoldersPanel(foldersDock);
1644 foldersPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1645 foldersDock->setWidget(foldersPanel);
1646
1647 QAction* foldersAction = foldersDock->toggleViewAction();
1648 foldersAction->setShortcut(Qt::Key_F7);
1649 foldersAction->setIcon(KIcon("folder"));
1650 addActionCloneToCollection(foldersAction, "show_folders_panel");
1651
1652 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
1653 connect(this, SIGNAL(urlChanged(KUrl)),
1654 foldersPanel, SLOT(setUrl(KUrl)));
1655 connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
1656 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1657
1658 // Setup "Terminal"
1659 #ifndef Q_OS_WIN
1660 DolphinDockWidget* terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1661 terminalDock->setLocked(lock);
1662 terminalDock->setObjectName("terminalDock");
1663 terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1664 Panel* terminalPanel = new TerminalPanel(terminalDock);
1665 terminalPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1666 terminalDock->setWidget(terminalPanel);
1667
1668 connect(terminalPanel, SIGNAL(hideTerminalPanel()), terminalDock, SLOT(hide()));
1669
1670 QAction* terminalAction = terminalDock->toggleViewAction();
1671 terminalAction->setShortcut(Qt::Key_F4);
1672 terminalAction->setIcon(KIcon("utilities-terminal"));
1673 addActionCloneToCollection(terminalAction, "show_terminal_panel");
1674
1675 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
1676 connect(this, SIGNAL(urlChanged(KUrl)),
1677 terminalPanel, SLOT(setUrl(KUrl)));
1678 #endif
1679
1680 // Setup "Search"
1681 #ifdef HAVE_NEPOMUK
1682 DolphinDockWidget* searchDock = new DolphinDockWidget(i18nc("@title:window", "Search"));
1683 searchDock->setLocked(lock);
1684 searchDock->setObjectName("searchDock");
1685 searchDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1686 Panel* searchPanel = new SearchPanel(searchDock);
1687 searchPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1688 connect(searchPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
1689 searchDock->setWidget(searchPanel);
1690
1691 QAction* searchAction = searchDock->toggleViewAction();
1692 searchAction->setShortcut(Qt::Key_F12);
1693 searchAction->setIcon(KIcon("system-search"));
1694 addActionCloneToCollection(searchAction, "show_search_panel");
1695 addDockWidget(Qt::RightDockWidgetArea, searchDock);
1696 connect(this, SIGNAL(urlChanged(KUrl)),
1697 searchPanel, SLOT(setUrl(KUrl)));
1698 #endif
1699
1700 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
1701 if (firstRun) {
1702 infoDock->hide();
1703 foldersDock->hide();
1704 #ifndef Q_OS_WIN
1705 terminalDock->hide();
1706 #endif
1707 #ifdef HAVE_NEPOMUK
1708 searchDock->hide();
1709 #endif
1710 }
1711
1712 // Setup "Places"
1713 DolphinDockWidget* placesDock = new DolphinDockWidget(i18nc("@title:window", "Places"));
1714 placesDock->setLocked(lock);
1715 placesDock->setObjectName("placesDock");
1716 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1717
1718 PlacesPanel* placesPanel = new PlacesPanel(placesDock);
1719 QAction* separator = new QAction(placesPanel);
1720 separator->setSeparator(true);
1721 QList<QAction*> placesActions;
1722 placesActions.append(separator);
1723 placesActions.append(lockLayoutAction);
1724 placesPanel->addActions(placesActions);
1725 placesPanel->setModel(DolphinSettings::instance().placesModel());
1726 placesPanel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1727 placesDock->setWidget(placesPanel);
1728
1729 QAction* placesAction = placesDock->toggleViewAction();
1730 placesAction->setShortcut(Qt::Key_F9);
1731 placesAction->setIcon(KIcon("bookmarks"));
1732 addActionCloneToCollection(placesAction, "show_places_panel");
1733
1734 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1735 connect(placesPanel, SIGNAL(urlChanged(KUrl, Qt::MouseButtons)),
1736 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1737 connect(this, SIGNAL(urlChanged(KUrl)),
1738 placesPanel, SLOT(setUrl(KUrl)));
1739
1740 // Add actions into the "Panels" menu
1741 KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1742 actionCollection()->addAction("panels", panelsMenu);
1743 panelsMenu->setDelayed(false);
1744 panelsMenu->addAction(placesAction);
1745 panelsMenu->addAction(infoAction);
1746 panelsMenu->addAction(foldersAction);
1747 #ifndef Q_OS_WIN
1748 panelsMenu->addAction(terminalAction);
1749 #endif
1750 #ifdef HAVE_NEPOMUK
1751 panelsMenu->addAction(searchAction);
1752 #endif
1753 panelsMenu->addSeparator();
1754 panelsMenu->addAction(lockLayoutAction);
1755 }
1756
1757 void DolphinMainWindow::updateEditActions()
1758 {
1759 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
1760 if (list.isEmpty()) {
1761 stateChanged("has_no_selection");
1762 } else {
1763 stateChanged("has_selection");
1764
1765 KActionCollection* col = actionCollection();
1766 QAction* renameAction = col->action("rename");
1767 QAction* moveToTrashAction = col->action("move_to_trash");
1768 QAction* deleteAction = col->action("delete");
1769 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
1770 QAction* deleteWithTrashShortcut = col->action("delete_shortcut"); // see DolphinViewActionHandler
1771
1772 KFileItemListProperties capabilities(list);
1773 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
1774
1775 renameAction->setEnabled(capabilities.supportsMoving());
1776 moveToTrashAction->setEnabled(enableMoveToTrash);
1777 deleteAction->setEnabled(capabilities.supportsDeleting());
1778 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
1779 cutAction->setEnabled(capabilities.supportsMoving());
1780 }
1781 updatePasteAction();
1782 }
1783
1784 void DolphinMainWindow::updateViewActions()
1785 {
1786 m_actionHandler->updateViewActions();
1787
1788 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1789 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
1790
1791 updateSplitAction();
1792
1793 QAction* editableLocactionAction = actionCollection()->action("editable_location");
1794 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
1795 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
1796 }
1797
1798 void DolphinMainWindow::updateGoActions()
1799 {
1800 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
1801 const KUrl currentUrl = m_activeViewContainer->url();
1802 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1803 }
1804
1805 void DolphinMainWindow::rememberClosedTab(int index)
1806 {
1807 KMenu* tabsMenu = m_recentTabsMenu->menu();
1808
1809 const QString primaryPath = m_viewTab[index].primaryView->url().path();
1810 const QString iconName = KMimeType::iconNameForUrl(primaryPath);
1811
1812 QAction* action = new QAction(squeezedText(primaryPath), tabsMenu);
1813
1814 ClosedTab closedTab;
1815 closedTab.primaryUrl = m_viewTab[index].primaryView->url();
1816
1817 if (m_viewTab[index].secondaryView) {
1818 closedTab.secondaryUrl = m_viewTab[index].secondaryView->url();
1819 closedTab.isSplit = true;
1820 } else {
1821 closedTab.isSplit = false;
1822 }
1823
1824 action->setData(QVariant::fromValue(closedTab));
1825 action->setIcon(KIcon(iconName));
1826
1827 // add the closed tab menu entry after the separator and
1828 // "Empty Recently Closed Tabs" entry
1829 if (tabsMenu->actions().size() == 2) {
1830 tabsMenu->addAction(action);
1831 } else {
1832 tabsMenu->insertAction(tabsMenu->actions().at(2), action);
1833 }
1834
1835 // assure that only up to 8 closed tabs are shown in the menu
1836 if (tabsMenu->actions().size() > 8) {
1837 tabsMenu->removeAction(tabsMenu->actions().last());
1838 }
1839 actionCollection()->action("closed_tabs")->setEnabled(true);
1840 KAcceleratorManager::manage(tabsMenu);
1841 }
1842
1843 void DolphinMainWindow::clearStatusBar()
1844 {
1845 m_activeViewContainer->statusBar()->clear();
1846 }
1847
1848 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
1849 {
1850 connect(container, SIGNAL(showFilterBarChanged(bool)),
1851 this, SLOT(updateFilterBarAction(bool)));
1852 connect(container, SIGNAL(writeStateChanged(bool)),
1853 this, SLOT(slotWriteStateChanged(bool)));
1854 connect(container, SIGNAL(searchModeChanged(bool)),
1855 this, SLOT(slotSearchModeChanged(bool)));
1856
1857 DolphinView* view = container->view();
1858 connect(view, SIGNAL(selectionChanged(KFileItemList)),
1859 this, SLOT(slotSelectionChanged(KFileItemList)));
1860 connect(view, SIGNAL(requestItemInfo(KFileItem)),
1861 this, SLOT(slotRequestItemInfo(KFileItem)));
1862 connect(view, SIGNAL(activated()),
1863 this, SLOT(toggleActiveView()));
1864 connect(view, SIGNAL(tabRequested(const KUrl&)),
1865 this, SLOT(openNewTab(const KUrl&)));
1866 connect(view, SIGNAL(requestContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)),
1867 this, SLOT(openContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)));
1868 connect(view, SIGNAL(startedPathLoading(KUrl)),
1869 this, SLOT(enableStopAction()));
1870 connect(view, SIGNAL(finishedPathLoading(KUrl)),
1871 this, SLOT(disableStopAction()));
1872
1873 const KUrlNavigator* navigator = container->urlNavigator();
1874 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1875 this, SLOT(changeUrl(const KUrl&)));
1876 connect(navigator, SIGNAL(historyChanged()),
1877 this, SLOT(updateHistory()));
1878 connect(navigator, SIGNAL(editableStateChanged(bool)),
1879 this, SLOT(slotEditableStateChanged(bool)));
1880 connect(navigator, SIGNAL(tabRequested(const KUrl&)),
1881 this, SLOT(openNewTab(KUrl)));
1882 }
1883
1884 void DolphinMainWindow::updateSplitAction()
1885 {
1886 QAction* splitAction = actionCollection()->action("split_view");
1887 if (m_viewTab[m_tabIndex].secondaryView) {
1888 if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
1889 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
1890 splitAction->setToolTip(i18nc("@info", "Close right view"));
1891 splitAction->setIcon(KIcon("view-right-close"));
1892 } else {
1893 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
1894 splitAction->setToolTip(i18nc("@info", "Close left view"));
1895 splitAction->setIcon(KIcon("view-left-close"));
1896 }
1897 } else {
1898 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
1899 splitAction->setToolTip(i18nc("@info", "Split view"));
1900 splitAction->setIcon(KIcon("view-right-new"));
1901 }
1902 }
1903
1904 QString DolphinMainWindow::tabName(const KUrl& url) const
1905 {
1906 QString name;
1907 if (url.equals(KUrl("file:///"))) {
1908 name = '/';
1909 } else {
1910 name = url.fileName();
1911 if (name.isEmpty()) {
1912 name = url.protocol();
1913 } else {
1914 // Make sure that a '&' inside the directory name is displayed correctly
1915 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1916 name.replace('&', "&&");
1917 }
1918 }
1919 return name;
1920 }
1921
1922 bool DolphinMainWindow::isKompareInstalled() const
1923 {
1924 static bool initialized = false;
1925 static bool installed = false;
1926 if (!initialized) {
1927 // TODO: maybe replace this approach later by using a menu
1928 // plugin like kdiff3plugin.cpp
1929 installed = !KGlobal::dirs()->findExe("kompare").isEmpty();
1930 initialized = true;
1931 }
1932 return installed;
1933 }
1934
1935 void DolphinMainWindow::createSecondaryView(int tabIndex)
1936 {
1937 QSplitter* splitter = m_viewTab[tabIndex].splitter;
1938 const int newWidth = (m_viewTab[tabIndex].primaryView->width() - splitter->handleWidth()) / 2;
1939
1940 const DolphinView* view = m_viewTab[tabIndex].primaryView->view();
1941 m_viewTab[tabIndex].secondaryView = new DolphinViewContainer(view->rootUrl(), 0);
1942 splitter->addWidget(m_viewTab[tabIndex].secondaryView);
1943 splitter->setSizes(QList<int>() << newWidth << newWidth);
1944 connectViewSignals(m_viewTab[tabIndex].secondaryView);
1945 m_viewTab[tabIndex].secondaryView->setActive(false);
1946 m_viewTab[tabIndex].secondaryView->show();
1947 }
1948
1949 QString DolphinMainWindow::tabProperty(const QString& property, int tabIndex) const
1950 {
1951 return "Tab " + QString::number(tabIndex) + ' ' + property;
1952 }
1953
1954 void DolphinMainWindow::setUrlAsCaption(const KUrl& url)
1955 {
1956 QString caption;
1957 if (!url.isLocalFile()) {
1958 caption.append(url.protocol() + " - ");
1959 if (url.hasHost()) {
1960 caption.append(url.host() + " - ");
1961 }
1962 }
1963
1964 const QString fileName = url.fileName().isEmpty() ? "/" : url.fileName();
1965 caption.append(fileName);
1966
1967 setCaption(caption);
1968 }
1969
1970 QString DolphinMainWindow::squeezedText(const QString& text) const
1971 {
1972 const QFontMetrics fm = fontMetrics();
1973 return fm.elidedText(text, Qt::ElideMiddle, fm.maxWidth() * 10);
1974 }
1975
1976 void DolphinMainWindow::addActionCloneToCollection(QAction* action, const QString& actionName)
1977 {
1978 KAction* actionClone = actionCollection()->addAction(actionName);
1979 actionClone->setText(action->text());
1980 actionClone->setIcon(action->icon());
1981 connect(actionClone, SIGNAL(triggered()), action, SLOT(trigger()));
1982 }
1983
1984 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1985 KIO::FileUndoManager::UiInterface()
1986 {
1987 }
1988
1989 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1990 {
1991 }
1992
1993 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1994 {
1995 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
1996 if (mainWin) {
1997 DolphinStatusBar* statusBar = mainWin->activeViewContainer()->statusBar();
1998 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1999 } else {
2000 KIO::FileUndoManager::UiInterface::jobError(job);
2001 }
2002 }
2003
2004 #include "dolphinmainwindow.moc"