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