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