]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
3f3c1a3047eebba50368afc2989752645aef197f
[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
848 // select the whole text of the combo box editor
849 QLineEdit* lineEdit = navigator->editor()->lineEdit(); // krazy:exclude=qclasses
850 lineEdit->selectAll();
851 }
852
853 void DolphinMainWindow::togglePanelLockState()
854 {
855 GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
856
857 const bool newLockState = !generalSettings->lockPanels();
858 foreach (QObject* child, children()) {
859 DolphinDockWidget* dock = qobject_cast<DolphinDockWidget*>(child);
860 if (dock != 0) {
861 dock->setLocked(newLockState);
862 }
863 }
864
865 generalSettings->setLockPanels(newLockState);
866 }
867
868 void DolphinMainWindow::goBack()
869 {
870 clearStatusBar();
871
872 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
873 urlNavigator->goBack();
874
875 if (urlNavigator->locationState().isEmpty()) {
876 // An empty location state indicates a redirection URL,
877 // which must be skipped too
878 urlNavigator->goBack();
879 }
880 }
881
882 void DolphinMainWindow::goForward()
883 {
884 clearStatusBar();
885 m_activeViewContainer->urlNavigator()->goForward();
886 }
887
888 void DolphinMainWindow::goUp()
889 {
890 clearStatusBar();
891 m_activeViewContainer->urlNavigator()->goUp();
892 }
893
894 void DolphinMainWindow::goBack(Qt::MouseButtons buttons)
895 {
896 // The default case (left button pressed) is handled in goBack().
897 if (buttons == Qt::MidButton) {
898 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
899 const int index = urlNavigator->historyIndex() + 1;
900 openNewTab(urlNavigator->locationUrl(index));
901 }
902 }
903
904 void DolphinMainWindow::goForward(Qt::MouseButtons buttons)
905 {
906 // The default case (left button pressed) is handled in goForward().
907 if (buttons == Qt::MidButton) {
908 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
909 const int index = urlNavigator->historyIndex() - 1;
910 openNewTab(urlNavigator->locationUrl(index));
911 }
912 }
913
914 void DolphinMainWindow::goUp(Qt::MouseButtons buttons)
915 {
916 // The default case (left button pressed) is handled in goUp().
917 if (buttons == Qt::MidButton) {
918 openNewTab(activeViewContainer()->url().upUrl());
919 }
920 }
921
922 void DolphinMainWindow::goHome()
923 {
924 clearStatusBar();
925 m_activeViewContainer->urlNavigator()->goHome();
926 }
927
928 void DolphinMainWindow::compareFiles()
929 {
930 // The method is only invoked if exactly 2 files have
931 // been selected. The selected files may be:
932 // - both in the primary view
933 // - both in the secondary view
934 // - one in the primary view and the other in the secondary
935 // view
936 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
937
938 KUrl urlA;
939 KUrl urlB;
940
941 KFileItemList items = m_viewTab[m_tabIndex].primaryView->view()->selectedItems();
942
943 switch (items.count()) {
944 case 0: {
945 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView != 0);
946 items = m_viewTab[m_tabIndex].secondaryView->view()->selectedItems();
947 Q_ASSERT(items.count() == 2);
948 urlA = items[0].url();
949 urlB = items[1].url();
950 break;
951 }
952
953 case 1: {
954 urlA = items[0].url();
955 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView != 0);
956 items = m_viewTab[m_tabIndex].secondaryView->view()->selectedItems();
957 Q_ASSERT(items.count() == 1);
958 urlB = items[0].url();
959 break;
960 }
961
962 case 2: {
963 urlA = items[0].url();
964 urlB = items[1].url();
965 break;
966 }
967
968 default: {
969 // may not happen: compareFiles may only get invoked if 2
970 // files are selected
971 Q_ASSERT(false);
972 }
973 }
974
975 QString command("kompare -c \"");
976 command.append(urlA.pathOrUrl());
977 command.append("\" \"");
978 command.append(urlB.pathOrUrl());
979 command.append('\"');
980 KRun::runCommand(command, "Kompare", "kompare", this);
981 }
982
983 void DolphinMainWindow::toggleShowMenuBar()
984 {
985 const bool visible = menuBar()->isVisible();
986 menuBar()->setVisible(!visible);
987 }
988
989 void DolphinMainWindow::openTerminal()
990 {
991 QString dir(QDir::homePath());
992
993 // If the given directory is not local, it can still be the URL of an
994 // ioslave using UDS_LOCAL_PATH which to be converted first.
995 KUrl url = KIO::NetAccess::mostLocalUrl(m_activeViewContainer->url(), this);
996
997 //If the URL is local after the above conversion, set the directory.
998 if (url.isLocalFile()) {
999 dir = url.toLocalFile();
1000 }
1001
1002 KToolInvocation::invokeTerminal(QString(), dir);
1003 }
1004
1005 void DolphinMainWindow::editSettings()
1006 {
1007 if (m_settingsDialog == 0) {
1008 const KUrl url = activeViewContainer()->url();
1009 m_settingsDialog = new DolphinSettingsDialog(url, this);
1010 m_settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
1011 m_settingsDialog->show();
1012 } else {
1013 m_settingsDialog->raise();
1014 }
1015 }
1016
1017 void DolphinMainWindow::setActiveTab(int index)
1018 {
1019 Q_ASSERT(index >= 0);
1020 Q_ASSERT(index < m_viewTab.count());
1021 if (index == m_tabIndex) {
1022 return;
1023 }
1024
1025 // hide current tab content
1026 ViewTab& hiddenTab = m_viewTab[m_tabIndex];
1027 hiddenTab.isPrimaryViewActive = hiddenTab.primaryView->isActive();
1028 hiddenTab.primaryView->setActive(false);
1029 if (hiddenTab.secondaryView != 0) {
1030 hiddenTab.secondaryView->setActive(false);
1031 }
1032 QSplitter* splitter = m_viewTab[m_tabIndex].splitter;
1033 splitter->hide();
1034 m_centralWidgetLayout->removeWidget(splitter);
1035
1036 // show active tab content
1037 m_tabIndex = index;
1038
1039 ViewTab& viewTab = m_viewTab[index];
1040 m_centralWidgetLayout->addWidget(viewTab.splitter, 1);
1041 viewTab.primaryView->show();
1042 if (viewTab.secondaryView != 0) {
1043 viewTab.secondaryView->show();
1044 }
1045 viewTab.splitter->show();
1046
1047 setActiveViewContainer(viewTab.isPrimaryViewActive ? viewTab.primaryView :
1048 viewTab.secondaryView);
1049 }
1050
1051 void DolphinMainWindow::closeTab()
1052 {
1053 closeTab(m_tabBar->currentIndex());
1054 }
1055
1056 void DolphinMainWindow::closeTab(int index)
1057 {
1058 Q_ASSERT(index >= 0);
1059 Q_ASSERT(index < m_viewTab.count());
1060 if (m_viewTab.count() == 1) {
1061 // the last tab may never get closed
1062 return;
1063 }
1064
1065 if (index == m_tabIndex) {
1066 // The tab that should be closed is the active tab. Activate the
1067 // previous tab before closing the tab.
1068 m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1);
1069 }
1070 rememberClosedTab(index);
1071
1072 // delete tab
1073 m_viewTab[index].primaryView->deleteLater();
1074 if (m_viewTab[index].secondaryView != 0) {
1075 m_viewTab[index].secondaryView->deleteLater();
1076 }
1077 m_viewTab[index].splitter->deleteLater();
1078 m_viewTab.erase(m_viewTab.begin() + index);
1079
1080 m_tabBar->blockSignals(true);
1081 m_tabBar->removeTab(index);
1082
1083 if (m_tabIndex > index) {
1084 m_tabIndex--;
1085 Q_ASSERT(m_tabIndex >= 0);
1086 }
1087
1088 // if only one tab is left, also remove the tab entry so that
1089 // closing the last tab is not possible
1090 if (m_viewTab.count() == 1) {
1091 m_tabBar->removeTab(0);
1092 actionCollection()->action("close_tab")->setEnabled(false);
1093 } else {
1094 m_tabBar->blockSignals(false);
1095 }
1096 }
1097
1098 void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos)
1099 {
1100 KMenu menu(this);
1101
1102 QAction* newTabAction = menu.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1103 newTabAction->setShortcut(actionCollection()->action("new_tab")->shortcut());
1104
1105 QAction* detachTabAction = menu.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1106
1107 QAction* closeOtherTabsAction = menu.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1108
1109 QAction* closeTabAction = menu.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1110 closeTabAction->setShortcut(actionCollection()->action("close_tab")->shortcut());
1111 QAction* selectedAction = menu.exec(pos);
1112 if (selectedAction == newTabAction) {
1113 const ViewTab& tab = m_viewTab[index];
1114 Q_ASSERT(tab.primaryView != 0);
1115 const KUrl url = (tab.secondaryView != 0) && tab.secondaryView->isActive() ?
1116 tab.secondaryView->url() : tab.primaryView->url();
1117 openNewTab(url);
1118 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
1119 } else if (selectedAction == detachTabAction) {
1120 const ViewTab& tab = m_viewTab[index];
1121 Q_ASSERT(tab.primaryView != 0);
1122 const KUrl primaryUrl = tab.primaryView->url();
1123 DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
1124 window->changeUrl(primaryUrl);
1125
1126 if (tab.secondaryView != 0) {
1127 const KUrl secondaryUrl = tab.secondaryView->url();
1128 window->toggleSplitView();
1129 window->m_viewTab[0].secondaryView->setUrl(secondaryUrl);
1130 if (tab.primaryView->isActive()) {
1131 window->m_viewTab[0].primaryView->setActive(true);
1132 } else {
1133 window->m_viewTab[0].secondaryView->setActive(true);
1134 }
1135 }
1136 window->show();
1137 closeTab(index);
1138 } else if (selectedAction == closeOtherTabsAction) {
1139 const int count = m_tabBar->count();
1140 for (int i = 0; i < index; ++i) {
1141 closeTab(0);
1142 }
1143 for (int i = index + 1; i < count; ++i) {
1144 closeTab(1);
1145 }
1146 } else if (selectedAction == closeTabAction) {
1147 closeTab(index);
1148 }
1149 }
1150
1151 void DolphinMainWindow::slotTabMoved(int from, int to)
1152 {
1153 m_viewTab.move(from, to);
1154 m_tabIndex = m_tabBar->currentIndex();
1155 }
1156
1157 void DolphinMainWindow::handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons)
1158 {
1159 if (buttons & Qt::MidButton) {
1160 openNewTab(url);
1161 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
1162 } else {
1163 changeUrl(url);
1164 }
1165 }
1166
1167 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& canDecode)
1168 {
1169 canDecode = KUrl::List::canDecode(event->mimeData());
1170 }
1171
1172 void DolphinMainWindow::handleUrl(const KUrl& url)
1173 {
1174 delete m_lastHandleUrlStatJob;
1175 m_lastHandleUrlStatJob = 0;
1176
1177 if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
1178 activeViewContainer()->setUrl(url);
1179 } else if (KProtocolManager::supportsListing(url)) {
1180 // stat the URL to see if it is a dir or not
1181 m_lastHandleUrlStatJob = KIO::stat(url, KIO::HideProgressInfo);
1182 connect(m_lastHandleUrlStatJob, SIGNAL(result(KJob*)),
1183 this, SLOT(slotHandleUrlStatFinished(KJob*)));
1184
1185 } else {
1186 new KRun(url, this);
1187 }
1188 }
1189
1190 void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job)
1191 {
1192 m_lastHandleUrlStatJob = 0;
1193 const KIO::UDSEntry entry = static_cast<KIO::StatJob*>(job)->statResult();
1194 const KUrl url = static_cast<KIO::StatJob*>(job)->url();
1195 if (entry.isDir()) {
1196 activeViewContainer()->setUrl(url);
1197 } else {
1198 new KRun(url, this);
1199 }
1200 }
1201
1202 void DolphinMainWindow::tabDropEvent(int tab, QDropEvent* event)
1203 {
1204 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
1205 if (!urls.isEmpty() && tab != -1) {
1206 const ViewTab& viewTab = m_viewTab[tab];
1207 const KUrl destPath = viewTab.isPrimaryViewActive ? viewTab.primaryView->url() : viewTab.secondaryView->url();
1208 DragAndDropHelper::instance().dropUrls(KFileItem(), destPath, event, m_tabBar);
1209 }
1210 }
1211
1212 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
1213 {
1214 newFileMenu()->setEnabled(isFolderWritable);
1215 }
1216
1217 void DolphinMainWindow::slotSearchModeChanged(bool enabled)
1218 {
1219 #ifdef HAVE_NEPOMUK
1220 if (Nepomuk::ResourceManager::instance()->init() != 0) {
1221 // Currently the Filter Panel only works with Nepomuk enabled
1222 return;
1223 }
1224
1225 QDockWidget* filterDock = findChild<QDockWidget*>("filterDock");
1226 if ((filterDock == 0) || !filterDock->isEnabled()) {
1227 return;
1228 }
1229
1230 if (enabled) {
1231 if (!filterDock->isVisible()) {
1232 m_filterDockIsTemporaryVisible = true;
1233 }
1234 filterDock->show();
1235 } else {
1236 if (filterDock->isVisible() && m_filterDockIsTemporaryVisible) {
1237 filterDock->hide();
1238 }
1239 m_filterDockIsTemporaryVisible = false;
1240 }
1241 #else
1242 Q_UNUSED(enabled);
1243 #endif
1244 }
1245
1246 void DolphinMainWindow::openContextMenu(const KFileItem& item,
1247 const KUrl& url,
1248 const QList<QAction*>& customActions)
1249 {
1250 QPointer<DolphinContextMenu> contextMenu = new DolphinContextMenu(this, item, url);
1251 contextMenu->setCustomActions(customActions);
1252 const DolphinContextMenu::Command command = contextMenu->open();
1253
1254 switch (command) {
1255 case DolphinContextMenu::OpenParentFolderInNewWindow: {
1256 DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
1257 window->changeUrl(item.url().upUrl());
1258 window->show();
1259 break;
1260 }
1261
1262 case DolphinContextMenu::OpenParentFolderInNewTab:
1263 openNewTab(item.url().upUrl());
1264 break;
1265
1266 case DolphinContextMenu::None:
1267 default:
1268 break;
1269 }
1270
1271 delete contextMenu;
1272 }
1273
1274 void DolphinMainWindow::init()
1275 {
1276 DolphinSettings& settings = DolphinSettings::instance();
1277
1278 // Check whether Dolphin runs the first time. If yes then
1279 // a proper default window size is given at the end of DolphinMainWindow::init().
1280 GeneralSettings* generalSettings = settings.generalSettings();
1281 const bool firstRun = generalSettings->firstRun();
1282 if (firstRun) {
1283 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
1284 }
1285
1286 setAcceptDrops(true);
1287
1288 m_viewTab[m_tabIndex].splitter = new QSplitter(this);
1289 m_viewTab[m_tabIndex].splitter->setChildrenCollapsible(false);
1290
1291 setupActions();
1292
1293 const KUrl homeUrl(generalSettings->homeUrl());
1294 setUrlAsCaption(homeUrl);
1295 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
1296 connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1297 connect(m_actionHandler, SIGNAL(createDirectory()), SLOT(createDirectory()));
1298 ViewProperties props(homeUrl);
1299 m_viewTab[m_tabIndex].primaryView = new DolphinViewContainer(homeUrl,
1300 m_viewTab[m_tabIndex].splitter);
1301
1302 m_activeViewContainer = m_viewTab[m_tabIndex].primaryView;
1303 connectViewSignals(m_activeViewContainer);
1304 DolphinView* view = m_activeViewContainer->view();
1305 view->reload();
1306 m_activeViewContainer->show();
1307 m_actionHandler->setCurrentView(view);
1308
1309 m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
1310 connect(this, SIGNAL(urlChanged(const KUrl&)),
1311 m_remoteEncoding, SLOT(slotAboutToOpenUrl()));
1312
1313 m_tabBar = new KTabBar(this);
1314 m_tabBar->setMovable(true);
1315 m_tabBar->setTabsClosable(true);
1316 connect(m_tabBar, SIGNAL(currentChanged(int)),
1317 this, SLOT(setActiveTab(int)));
1318 connect(m_tabBar, SIGNAL(tabCloseRequested(int)),
1319 this, SLOT(closeTab(int)));
1320 connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)),
1321 this, SLOT(openTabContextMenu(int, const QPoint&)));
1322 connect(m_tabBar, SIGNAL(newTabRequest()),
1323 this, SLOT(openNewTab()));
1324 connect(m_tabBar, SIGNAL(testCanDecode(const QDragMoveEvent*, bool&)),
1325 this, SLOT(slotTestCanDecode(const QDragMoveEvent*, bool&)));
1326 connect(m_tabBar, SIGNAL(mouseMiddleClick(int)),
1327 this, SLOT(closeTab(int)));
1328 connect(m_tabBar, SIGNAL(tabMoved(int, int)),
1329 this, SLOT(slotTabMoved(int, int)));
1330 connect(m_tabBar, SIGNAL(receivedDropEvent(int, QDropEvent*)),
1331 this, SLOT(tabDropEvent(int, QDropEvent*)));
1332
1333 m_tabBar->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1334
1335 QWidget* centralWidget = new QWidget(this);
1336 m_centralWidgetLayout = new QVBoxLayout(centralWidget);
1337 m_centralWidgetLayout->setSpacing(0);
1338 m_centralWidgetLayout->setMargin(0);
1339 m_centralWidgetLayout->addWidget(m_tabBar);
1340 m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter, 1);
1341
1342 setCentralWidget(centralWidget);
1343 setupDockWidgets();
1344 emit urlChanged(homeUrl);
1345
1346 setupGUI(Keys | Save | Create | ToolBar);
1347 stateChanged("new_file");
1348
1349 QClipboard* clipboard = QApplication::clipboard();
1350 connect(clipboard, SIGNAL(dataChanged()),
1351 this, SLOT(updatePasteAction()));
1352
1353 if (generalSettings->splitView()) {
1354 toggleSplitView();
1355 }
1356 updateEditActions();
1357 updateViewActions();
1358 updateGoActions();
1359
1360 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1361 showFilterBarAction->setChecked(generalSettings->filterBar());
1362
1363 if (firstRun) {
1364 // assure a proper default size if Dolphin runs the first time
1365 resize(750, 500);
1366 }
1367
1368 m_showMenuBar->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1369 }
1370
1371 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
1372 {
1373 Q_ASSERT(viewContainer != 0);
1374 Q_ASSERT((viewContainer == m_viewTab[m_tabIndex].primaryView) ||
1375 (viewContainer == m_viewTab[m_tabIndex].secondaryView));
1376 if (m_activeViewContainer == viewContainer) {
1377 return;
1378 }
1379
1380 m_activeViewContainer->setActive(false);
1381 m_activeViewContainer = viewContainer;
1382
1383 // Activating the view container might trigger a recursive setActiveViewContainer() call
1384 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1385 // disconnect the activated() signal in this case:
1386 disconnect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1387 m_activeViewContainer->setActive(true);
1388 connect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1389
1390 m_actionHandler->setCurrentView(viewContainer->view());
1391
1392 updateHistory();
1393 updateEditActions();
1394 updateViewActions();
1395 updateGoActions();
1396
1397 const KUrl url = m_activeViewContainer->url();
1398 setUrlAsCaption(url);
1399 if (m_viewTab.count() > 1) {
1400 m_tabBar->setTabText(m_tabIndex, tabName(url));
1401 m_tabBar->setTabIcon(m_tabIndex, KIcon(KMimeType::iconNameForUrl(url)));
1402 }
1403
1404 emit urlChanged(url);
1405 }
1406
1407 void DolphinMainWindow::setupActions()
1408 {
1409 // setup 'File' menu
1410 m_newFileMenu = new DolphinNewFileMenu(this, this);
1411 KMenu* menu = m_newFileMenu->menu();
1412 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1413 menu->setIcon(KIcon("document-new"));
1414 connect(menu, SIGNAL(aboutToShow()),
1415 this, SLOT(updateNewMenu()));
1416
1417 KAction* newWindow = actionCollection()->addAction("new_window");
1418 newWindow->setIcon(KIcon("window-new"));
1419 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1420 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
1421 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1422
1423 KAction* newTab = actionCollection()->addAction("new_tab");
1424 newTab->setIcon(KIcon("tab-new"));
1425 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1426 newTab->setShortcut(KShortcut(Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N));
1427 connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab()));
1428
1429 KAction* closeTab = actionCollection()->addAction("close_tab");
1430 closeTab->setIcon(KIcon("tab-close"));
1431 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1432 closeTab->setShortcut(Qt::CTRL | Qt::Key_W);
1433 closeTab->setEnabled(false);
1434 connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
1435
1436 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1437
1438 // setup 'Edit' menu
1439 KStandardAction::undo(this,
1440 SLOT(undo()),
1441 actionCollection());
1442
1443 // need to remove shift+del from cut action, else the shortcut for deletejob
1444 // doesn't work
1445 KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
1446 KShortcut cutShortcut = cut->shortcut();
1447 cutShortcut.remove(Qt::SHIFT + Qt::Key_Delete, KShortcut::KeepEmpty);
1448 cut->setShortcut(cutShortcut);
1449 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1450 KAction* paste = KStandardAction::paste(this, SLOT(paste()), actionCollection());
1451 // The text of the paste-action is modified dynamically by Dolphin
1452 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1453 // due to the long text, the text "Paste" is used:
1454 paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1455
1456 KStandardAction::find(this, SLOT(find()), actionCollection());
1457
1458 KAction* selectAll = actionCollection()->addAction("select_all");
1459 selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
1460 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
1461 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
1462
1463 KAction* invertSelection = actionCollection()->addAction("invert_selection");
1464 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1465 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1466 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
1467
1468 // setup 'View' menu
1469 // (note that most of it is set up in DolphinViewActionHandler)
1470
1471 KAction* split = actionCollection()->addAction("split_view");
1472 split->setShortcut(Qt::Key_F3);
1473 updateSplitAction();
1474 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1475
1476 KAction* reload = actionCollection()->addAction("reload");
1477 reload->setText(i18nc("@action:inmenu View", "Reload"));
1478 reload->setShortcut(Qt::Key_F5);
1479 reload->setIcon(KIcon("view-refresh"));
1480 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
1481
1482 KAction* stop = actionCollection()->addAction("stop");
1483 stop->setText(i18nc("@action:inmenu View", "Stop"));
1484 stop->setToolTip(i18nc("@info", "Stop loading"));
1485 stop->setIcon(KIcon("process-stop"));
1486 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
1487
1488 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
1489 showFullLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1490 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
1491 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1492
1493 KAction* replaceLocation = actionCollection()->addAction("replace_location");
1494 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1495 replaceLocation->setShortcut(Qt::Key_F6);
1496 connect(replaceLocation, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1497
1498 // setup 'Go' menu
1499 KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
1500 connect(backAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goBack(Qt::MouseButtons)));
1501 KShortcut backShortcut = backAction->shortcut();
1502 backShortcut.setAlternate(Qt::Key_Backspace);
1503 backAction->setShortcut(backShortcut);
1504
1505 m_recentTabsMenu = new KActionMenu(i18n("Recently Closed Tabs"), this);
1506 m_recentTabsMenu->setIcon(KIcon("edit-undo"));
1507 actionCollection()->addAction("closed_tabs", m_recentTabsMenu);
1508 connect(m_recentTabsMenu->menu(), SIGNAL(triggered(QAction *)),
1509 this, SLOT(restoreClosedTab(QAction *)));
1510
1511 QAction* action = new QAction("Empty Recently Closed Tabs", m_recentTabsMenu);
1512 action->setIcon(KIcon("edit-clear-list"));
1513 action->setData(QVariant::fromValue(true));
1514 m_recentTabsMenu->addAction(action);
1515 m_recentTabsMenu->addSeparator();
1516 m_recentTabsMenu->setEnabled(false);
1517
1518 KAction* forwardAction = KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1519 connect(forwardAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goForward(Qt::MouseButtons)));
1520
1521 KAction* upAction = KStandardAction::up(this, SLOT(goUp()), actionCollection());
1522 connect(upAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goUp(Qt::MouseButtons)));
1523
1524 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1525
1526 // setup 'Tools' menu
1527 KAction* showFilterBar = actionCollection()->addAction("show_filter_bar");
1528 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1529 showFilterBar->setIcon(KIcon("view-filter"));
1530 showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
1531 connect(showFilterBar, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1532
1533 KAction* compareFiles = actionCollection()->addAction("compare_files");
1534 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1535 compareFiles->setIcon(KIcon("kompare"));
1536 compareFiles->setEnabled(false);
1537 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1538
1539 KAction* openTerminal = actionCollection()->addAction("open_terminal");
1540 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1541 openTerminal->setIcon(KIcon("utilities-terminal"));
1542 openTerminal->setShortcut(Qt::SHIFT | Qt::Key_F4);
1543 connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal()));
1544
1545 // setup 'Settings' menu
1546 m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1547 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1548
1549 // not in menu actions
1550 QList<QKeySequence> nextTabKeys;
1551 nextTabKeys.append(KStandardShortcut::tabNext().primary());
1552 nextTabKeys.append(QKeySequence(Qt::CTRL + Qt::Key_Tab));
1553
1554 QList<QKeySequence> prevTabKeys;
1555 prevTabKeys.append(KStandardShortcut::tabPrev().primary());
1556 prevTabKeys.append(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab));
1557
1558 KAction* activateNextTab = actionCollection()->addAction("activate_next_tab");
1559 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1560 connect(activateNextTab, SIGNAL(triggered()), SLOT(activateNextTab()));
1561 activateNextTab->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys : nextTabKeys);
1562
1563 KAction* activatePrevTab = actionCollection()->addAction("activate_prev_tab");
1564 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1565 connect(activatePrevTab, SIGNAL(triggered()), SLOT(activatePrevTab()));
1566 activatePrevTab->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys : prevTabKeys);
1567
1568 // for context menu
1569 KAction* openInNewTab = actionCollection()->addAction("open_in_new_tab");
1570 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
1571 openInNewTab->setIcon(KIcon("tab-new"));
1572 connect(openInNewTab, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1573
1574 KAction* openInNewWindow = actionCollection()->addAction("open_in_new_window");
1575 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
1576 openInNewWindow->setIcon(KIcon("window-new"));
1577 connect(openInNewWindow, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1578 }
1579
1580 void DolphinMainWindow::setupDockWidgets()
1581 {
1582 const bool lock = DolphinSettings::instance().generalSettings()->lockPanels();
1583
1584 KDualAction* lockLayoutAction = actionCollection()->add<KDualAction>("lock_panels");
1585 lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1586 lockLayoutAction->setActiveIcon(KIcon("object-unlocked"));
1587 lockLayoutAction->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1588 lockLayoutAction->setInactiveIcon(KIcon("object-locked"));
1589 lockLayoutAction->setActive(lock);
1590 connect(lockLayoutAction, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1591
1592 // Setup "Information"
1593 DolphinDockWidget* infoDock = new DolphinDockWidget(i18nc("@title:window", "Information"));
1594 infoDock->setLocked(lock);
1595 infoDock->setObjectName("infoDock");
1596 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1597 Panel* infoPanel = new InformationPanel(infoDock);
1598 infoPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1599 connect(infoPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
1600 infoDock->setWidget(infoPanel);
1601
1602 QAction* infoAction = infoDock->toggleViewAction();
1603 infoAction->setIcon(KIcon("dialog-information"));
1604 infoAction->setShortcut(Qt::Key_F11);
1605 addActionCloneToCollection(infoAction, "show_information_panel");
1606
1607 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1608 connect(this, SIGNAL(urlChanged(KUrl)),
1609 infoPanel, SLOT(setUrl(KUrl)));
1610 connect(this, SIGNAL(selectionChanged(KFileItemList)),
1611 infoPanel, SLOT(setSelection(KFileItemList)));
1612 connect(this, SIGNAL(requestItemInfo(KFileItem)),
1613 infoPanel, SLOT(requestDelayedItemInfo(KFileItem)));
1614
1615 // Setup "Folders"
1616 DolphinDockWidget* foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders"));
1617 foldersDock->setLocked(lock);
1618 foldersDock->setObjectName("foldersDock");
1619 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1620 FoldersPanel* foldersPanel = new FoldersPanel(foldersDock);
1621 foldersPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1622 foldersDock->setWidget(foldersPanel);
1623
1624 QAction* foldersAction = foldersDock->toggleViewAction();
1625 foldersAction->setShortcut(Qt::Key_F7);
1626 foldersAction->setIcon(KIcon("folder"));
1627 addActionCloneToCollection(foldersAction, "show_folders_panel");
1628
1629 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
1630 connect(this, SIGNAL(urlChanged(KUrl)),
1631 foldersPanel, SLOT(setUrl(KUrl)));
1632 connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
1633 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1634
1635 // Setup "Terminal"
1636 #ifndef Q_OS_WIN
1637 DolphinDockWidget* terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1638 terminalDock->setLocked(lock);
1639 terminalDock->setObjectName("terminalDock");
1640 terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1641 Panel* terminalPanel = new TerminalPanel(terminalDock);
1642 terminalPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1643 terminalDock->setWidget(terminalPanel);
1644
1645 connect(terminalPanel, SIGNAL(hideTerminalPanel()), terminalDock, SLOT(hide()));
1646
1647 QAction* terminalAction = terminalDock->toggleViewAction();
1648 terminalAction->setShortcut(Qt::Key_F4);
1649 terminalAction->setIcon(KIcon("utilities-terminal"));
1650 addActionCloneToCollection(terminalAction, "show_terminal_panel");
1651
1652 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
1653 connect(this, SIGNAL(urlChanged(KUrl)),
1654 terminalPanel, SLOT(setUrl(KUrl)));
1655 #endif
1656
1657 // Setup "Filter"
1658 #ifdef HAVE_NEPOMUK
1659 DolphinDockWidget* filterDock = new DolphinDockWidget(i18nc("@title:window", "Filter"));
1660 filterDock->setLocked(lock);
1661 filterDock->setObjectName("filterDock");
1662 filterDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1663 Panel* filterPanel = new FilterPanel(filterDock);
1664 filterPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1665 connect(filterPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
1666 filterDock->setWidget(filterPanel);
1667
1668 QAction* filterAction = filterDock->toggleViewAction();
1669 filterAction->setShortcut(Qt::Key_F12);
1670 filterAction->setIcon(KIcon("view-filter"));
1671 addActionCloneToCollection(filterAction, "show_filter_panel");
1672 addDockWidget(Qt::RightDockWidgetArea, filterDock);
1673 connect(this, SIGNAL(urlChanged(KUrl)),
1674 filterPanel, SLOT(setUrl(KUrl)));
1675 #endif
1676
1677 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
1678 if (firstRun) {
1679 infoDock->hide();
1680 foldersDock->hide();
1681 #ifndef Q_OS_WIN
1682 terminalDock->hide();
1683 #endif
1684 #ifdef HAVE_NEPOMUK
1685 filterDock->hide();
1686 #endif
1687 }
1688
1689 // Setup "Places"
1690 DolphinDockWidget* placesDock = new DolphinDockWidget(i18nc("@title:window", "Places"));
1691 placesDock->setLocked(lock);
1692 placesDock->setObjectName("placesDock");
1693 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1694
1695 PlacesPanel* placesPanel = new PlacesPanel(placesDock);
1696 QAction* separator = new QAction(placesPanel);
1697 separator->setSeparator(true);
1698 QList<QAction*> placesActions;
1699 placesActions.append(separator);
1700 placesActions.append(lockLayoutAction);
1701 placesPanel->addActions(placesActions);
1702 placesPanel->setModel(DolphinSettings::instance().placesModel());
1703 placesPanel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1704 placesDock->setWidget(placesPanel);
1705
1706 QAction* placesAction = placesDock->toggleViewAction();
1707 placesAction->setShortcut(Qt::Key_F9);
1708 placesAction->setIcon(KIcon("bookmarks"));
1709 addActionCloneToCollection(placesAction, "show_places_panel");
1710
1711 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1712 connect(placesPanel, SIGNAL(urlChanged(KUrl, Qt::MouseButtons)),
1713 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1714 connect(this, SIGNAL(urlChanged(KUrl)),
1715 placesPanel, SLOT(setUrl(KUrl)));
1716
1717 // Add actions into the "Panels" menu
1718 KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1719 actionCollection()->addAction("panels", panelsMenu);
1720 panelsMenu->setDelayed(false);
1721 panelsMenu->addAction(placesAction);
1722 panelsMenu->addAction(infoAction);
1723 panelsMenu->addAction(foldersAction);
1724 #ifndef Q_OS_WIN
1725 panelsMenu->addAction(terminalAction);
1726 #endif
1727 #ifdef HAVE_NEPOMUK
1728 panelsMenu->addAction(filterAction);
1729 #endif
1730 panelsMenu->addSeparator();
1731 panelsMenu->addAction(lockLayoutAction);
1732 }
1733
1734 void DolphinMainWindow::updateEditActions()
1735 {
1736 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
1737 if (list.isEmpty()) {
1738 stateChanged("has_no_selection");
1739 } else {
1740 stateChanged("has_selection");
1741
1742 KActionCollection* col = actionCollection();
1743 QAction* renameAction = col->action("rename");
1744 QAction* moveToTrashAction = col->action("move_to_trash");
1745 QAction* deleteAction = col->action("delete");
1746 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
1747 QAction* deleteWithTrashShortcut = col->action("delete_shortcut"); // see DolphinViewActionHandler
1748
1749 KFileItemListProperties capabilities(list);
1750 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
1751
1752 renameAction->setEnabled(capabilities.supportsMoving());
1753 moveToTrashAction->setEnabled(enableMoveToTrash);
1754 deleteAction->setEnabled(capabilities.supportsDeleting());
1755 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
1756 cutAction->setEnabled(capabilities.supportsMoving());
1757 }
1758 updatePasteAction();
1759 }
1760
1761 void DolphinMainWindow::updateViewActions()
1762 {
1763 m_actionHandler->updateViewActions();
1764
1765 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1766 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
1767
1768 updateSplitAction();
1769
1770 QAction* editableLocactionAction = actionCollection()->action("editable_location");
1771 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
1772 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
1773 }
1774
1775 void DolphinMainWindow::updateGoActions()
1776 {
1777 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
1778 const KUrl currentUrl = m_activeViewContainer->url();
1779 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1780 }
1781
1782 void DolphinMainWindow::rememberClosedTab(int index)
1783 {
1784 KMenu* tabsMenu = m_recentTabsMenu->menu();
1785
1786 const QString primaryPath = m_viewTab[index].primaryView->url().path();
1787 const QString iconName = KMimeType::iconNameForUrl(primaryPath);
1788
1789 QAction* action = new QAction(squeezedText(primaryPath), tabsMenu);
1790
1791 ClosedTab closedTab;
1792 closedTab.primaryUrl = m_viewTab[index].primaryView->url();
1793
1794 if (m_viewTab[index].secondaryView != 0) {
1795 closedTab.secondaryUrl = m_viewTab[index].secondaryView->url();
1796 closedTab.isSplit = true;
1797 } else {
1798 closedTab.isSplit = false;
1799 }
1800
1801 action->setData(QVariant::fromValue(closedTab));
1802 action->setIcon(KIcon(iconName));
1803
1804 // add the closed tab menu entry after the separator and
1805 // "Empty Recently Closed Tabs" entry
1806 if (tabsMenu->actions().size() == 2) {
1807 tabsMenu->addAction(action);
1808 } else {
1809 tabsMenu->insertAction(tabsMenu->actions().at(2), action);
1810 }
1811
1812 // assure that only up to 8 closed tabs are shown in the menu
1813 if (tabsMenu->actions().size() > 8) {
1814 tabsMenu->removeAction(tabsMenu->actions().last());
1815 }
1816 actionCollection()->action("closed_tabs")->setEnabled(true);
1817 KAcceleratorManager::manage(tabsMenu);
1818 }
1819
1820 void DolphinMainWindow::clearStatusBar()
1821 {
1822 m_activeViewContainer->statusBar()->clear();
1823 }
1824
1825 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
1826 {
1827 connect(container, SIGNAL(showFilterBarChanged(bool)),
1828 this, SLOT(updateFilterBarAction(bool)));
1829 connect(container, SIGNAL(writeStateChanged(bool)),
1830 this, SLOT(slotWriteStateChanged(bool)));
1831 connect(container, SIGNAL(searchModeChanged(bool)),
1832 this, SLOT(slotSearchModeChanged(bool)));
1833
1834 DolphinView* view = container->view();
1835 connect(view, SIGNAL(selectionChanged(KFileItemList)),
1836 this, SLOT(slotSelectionChanged(KFileItemList)));
1837 connect(view, SIGNAL(requestItemInfo(KFileItem)),
1838 this, SLOT(slotRequestItemInfo(KFileItem)));
1839 connect(view, SIGNAL(activated()),
1840 this, SLOT(toggleActiveView()));
1841 connect(view, SIGNAL(tabRequested(const KUrl&)),
1842 this, SLOT(openNewTab(const KUrl&)));
1843 connect(view, SIGNAL(requestContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)),
1844 this, SLOT(openContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)));
1845 connect(view, SIGNAL(startedPathLoading(KUrl)),
1846 this, SLOT(enableStopAction()));
1847 connect(view, SIGNAL(finishedPathLoading(KUrl)),
1848 this, SLOT(disableStopAction()));
1849
1850 const KUrlNavigator* navigator = container->urlNavigator();
1851 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1852 this, SLOT(changeUrl(const KUrl&)));
1853 connect(navigator, SIGNAL(historyChanged()),
1854 this, SLOT(updateHistory()));
1855 connect(navigator, SIGNAL(editableStateChanged(bool)),
1856 this, SLOT(slotEditableStateChanged(bool)));
1857 connect(navigator, SIGNAL(tabRequested(const KUrl&)),
1858 this, SLOT(openNewTab(KUrl)));
1859 }
1860
1861 void DolphinMainWindow::updateSplitAction()
1862 {
1863 QAction* splitAction = actionCollection()->action("split_view");
1864 if (m_viewTab[m_tabIndex].secondaryView != 0) {
1865 if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
1866 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
1867 splitAction->setToolTip(i18nc("@info", "Close right view"));
1868 splitAction->setIcon(KIcon("view-right-close"));
1869 } else {
1870 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
1871 splitAction->setToolTip(i18nc("@info", "Close left view"));
1872 splitAction->setIcon(KIcon("view-left-close"));
1873 }
1874 } else {
1875 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
1876 splitAction->setToolTip(i18nc("@info", "Split view"));
1877 splitAction->setIcon(KIcon("view-right-new"));
1878 }
1879 }
1880
1881 QString DolphinMainWindow::tabName(const KUrl& url) const
1882 {
1883 QString name;
1884 if (url.equals(KUrl("file:///"))) {
1885 name = '/';
1886 } else {
1887 name = url.fileName();
1888 if (name.isEmpty()) {
1889 name = url.protocol();
1890 } else {
1891 // Make sure that a '&' inside the directory name is displayed correctly
1892 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1893 name.replace('&', "&&");
1894 }
1895 }
1896 return name;
1897 }
1898
1899 bool DolphinMainWindow::isKompareInstalled() const
1900 {
1901 static bool initialized = false;
1902 static bool installed = false;
1903 if (!initialized) {
1904 // TODO: maybe replace this approach later by using a menu
1905 // plugin like kdiff3plugin.cpp
1906 installed = !KGlobal::dirs()->findExe("kompare").isEmpty();
1907 initialized = true;
1908 }
1909 return installed;
1910 }
1911
1912 void DolphinMainWindow::createSecondaryView(int tabIndex)
1913 {
1914 QSplitter* splitter = m_viewTab[tabIndex].splitter;
1915 const int newWidth = (m_viewTab[tabIndex].primaryView->width() - splitter->handleWidth()) / 2;
1916
1917 const DolphinView* view = m_viewTab[tabIndex].primaryView->view();
1918 m_viewTab[tabIndex].secondaryView = new DolphinViewContainer(view->rootUrl(), 0);
1919 splitter->addWidget(m_viewTab[tabIndex].secondaryView);
1920 splitter->setSizes(QList<int>() << newWidth << newWidth);
1921 connectViewSignals(m_viewTab[tabIndex].secondaryView);
1922 m_viewTab[tabIndex].secondaryView->view()->reload();
1923 m_viewTab[tabIndex].secondaryView->setActive(false);
1924 m_viewTab[tabIndex].secondaryView->show();
1925 }
1926
1927 QString DolphinMainWindow::tabProperty(const QString& property, int tabIndex) const
1928 {
1929 return "Tab " + QString::number(tabIndex) + ' ' + property;
1930 }
1931
1932 void DolphinMainWindow::setUrlAsCaption(const KUrl& url)
1933 {
1934 QString caption;
1935 if (!url.isLocalFile()) {
1936 caption.append(url.protocol() + " - ");
1937 if (url.hasHost()) {
1938 caption.append(url.host() + " - ");
1939 }
1940 }
1941
1942 const QString fileName = url.fileName().isEmpty() ? "/" : url.fileName();
1943 caption.append(fileName);
1944
1945 setCaption(caption);
1946 }
1947
1948 QString DolphinMainWindow::squeezedText(const QString& text) const
1949 {
1950 const QFontMetrics fm = fontMetrics();
1951 return fm.elidedText(text, Qt::ElideMiddle, fm.maxWidth() * 10);
1952 }
1953
1954 void DolphinMainWindow::addActionCloneToCollection(QAction* action, const QString& actionName)
1955 {
1956 KAction* actionClone = actionCollection()->addAction(actionName);
1957 actionClone->setText(action->text());
1958 actionClone->setIcon(action->icon());
1959 connect(actionClone, SIGNAL(triggered()), action, SLOT(trigger()));
1960 }
1961
1962 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1963 KIO::FileUndoManager::UiInterface()
1964 {
1965 }
1966
1967 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1968 {
1969 }
1970
1971 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1972 {
1973 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
1974 if (mainWin) {
1975 DolphinStatusBar* statusBar = mainWin->activeViewContainer()->statusBar();
1976 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1977 } else {
1978 KIO::FileUndoManager::UiInterface::jobError(job);
1979 }
1980 }
1981
1982 #include "dolphinmainwindow.moc"