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