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