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