]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Port patch 1098976 for Konqueror by David Faure to Dolphin: When the user clicks...
[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::tabDropEvent(int tab, QDropEvent* event)
1143 {
1144 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
1145 if (!urls.isEmpty() && tab != -1) {
1146 const ViewTab& viewTab = m_viewTab[tab];
1147 const KUrl destPath = viewTab.isPrimaryViewActive ? viewTab.primaryView->url() : viewTab.secondaryView->url();
1148 DragAndDropHelper::instance().dropUrls(KFileItem(), destPath, event, m_tabBar);
1149 }
1150 }
1151
1152 void DolphinMainWindow::slotCaptionStatFinished(KJob* job)
1153 {
1154 m_captionStatJob = 0;
1155 const KIO::UDSEntry entry = static_cast<KIO::StatJob*>(job)->statResult();
1156 const QString name = entry.stringValue(KIO::UDSEntry::UDS_DISPLAY_NAME);
1157 setCaption(name);
1158 }
1159
1160 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
1161 {
1162 newMenu()->setEnabled(isFolderWritable);
1163 }
1164
1165 void DolphinMainWindow::openContextMenu(const KFileItem& item,
1166 const KUrl& url,
1167 const QList<QAction*>& customActions)
1168 {
1169 DolphinContextMenu contextMenu(this, item, url);
1170 contextMenu.setCustomActions(customActions);
1171 contextMenu.open();
1172 }
1173
1174 void DolphinMainWindow::init()
1175 {
1176 DolphinSettings& settings = DolphinSettings::instance();
1177
1178 // Check whether Dolphin runs the first time. If yes then
1179 // a proper default window size is given at the end of DolphinMainWindow::init().
1180 GeneralSettings* generalSettings = settings.generalSettings();
1181 const bool firstRun = generalSettings->firstRun();
1182 if (firstRun) {
1183 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
1184 }
1185
1186 setAcceptDrops(true);
1187
1188 m_viewTab[m_tabIndex].splitter = new QSplitter(this);
1189 m_viewTab[m_tabIndex].splitter->setChildrenCollapsible(false);
1190
1191 setupActions();
1192
1193 const KUrl& homeUrl = generalSettings->homeUrl();
1194 setUrlAsCaption(homeUrl);
1195 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
1196 connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1197 connect(m_actionHandler, SIGNAL(createDirectory()), SLOT(createDirectory()));
1198 ViewProperties props(homeUrl);
1199 m_viewTab[m_tabIndex].primaryView = new DolphinViewContainer(homeUrl,
1200 m_viewTab[m_tabIndex].splitter);
1201
1202 m_activeViewContainer = m_viewTab[m_tabIndex].primaryView;
1203 connectViewSignals(m_activeViewContainer);
1204 DolphinView* view = m_activeViewContainer->view();
1205 view->reload();
1206 m_activeViewContainer->show();
1207 m_actionHandler->setCurrentView(view);
1208
1209 m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
1210 connect(this, SIGNAL(urlChanged(const KUrl&)),
1211 m_remoteEncoding, SLOT(slotAboutToOpenUrl()));
1212
1213 #ifdef HAVE_NEPOMUK
1214 m_searchOptionsConfigurator = new DolphinSearchOptionsConfigurator(this);
1215 m_searchOptionsConfigurator->hide();
1216 connect(m_searchOptionsConfigurator, SIGNAL(searchOptionsChanged()),
1217 this, SLOT(searchItems()));
1218 connect(this, SIGNAL(urlChanged(KUrl)), m_searchOptionsConfigurator, SLOT(setDirectory(KUrl)));
1219 #endif
1220
1221 m_tabBar = new KTabBar(this);
1222 m_tabBar->setMovable(true);
1223 m_tabBar->setTabsClosable(true);
1224 connect(m_tabBar, SIGNAL(currentChanged(int)),
1225 this, SLOT(setActiveTab(int)));
1226 connect(m_tabBar, SIGNAL(tabCloseRequested(int)),
1227 this, SLOT(closeTab(int)));
1228 connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)),
1229 this, SLOT(openTabContextMenu(int, const QPoint&)));
1230 connect(m_tabBar, SIGNAL(newTabRequest()),
1231 this, SLOT(openNewTab()));
1232 connect(m_tabBar, SIGNAL(testCanDecode(const QDragMoveEvent*, bool&)),
1233 this, SLOT(slotTestCanDecode(const QDragMoveEvent*, bool&)));
1234 connect(m_tabBar, SIGNAL(wheelDelta(int)),
1235 this, SLOT(slotWheelMoved(int)));
1236 connect(m_tabBar, SIGNAL(mouseMiddleClick(int)),
1237 this, SLOT(closeTab(int)));
1238 connect(m_tabBar, SIGNAL(tabMoved(int, int)),
1239 this, SLOT(slotTabMoved(int, int)));
1240 connect(m_tabBar, SIGNAL(receivedDropEvent(int, QDropEvent*)),
1241 this, SLOT(tabDropEvent(int, QDropEvent*)));
1242
1243 m_tabBar->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1244
1245 QWidget* centralWidget = new QWidget(this);
1246 m_centralWidgetLayout = new QVBoxLayout(centralWidget);
1247 m_centralWidgetLayout->setSpacing(0);
1248 m_centralWidgetLayout->setMargin(0);
1249 #ifdef HAVE_NEPOMUK
1250 m_centralWidgetLayout->addWidget(m_searchOptionsConfigurator);
1251 #endif
1252 m_centralWidgetLayout->addWidget(m_tabBar);
1253 m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter, 1);
1254
1255 setCentralWidget(centralWidget);
1256 setupDockWidgets();
1257 emit urlChanged(homeUrl);
1258
1259 setupGUI(Keys | Save | Create | ToolBar);
1260
1261 m_searchBox->setParent(toolBar("searchToolBar"));
1262 m_searchBox->show();
1263 connect(m_searchBox, SIGNAL(requestSearchOptions()),
1264 this, SLOT(showSearchOptions()));
1265 #ifdef HAVE_NEPOMUK
1266 connect(m_searchBox, SIGNAL(searchTextChanged(QString)),
1267 m_searchOptionsConfigurator, SLOT(setCustomSearchQuery(QString)));
1268 #endif
1269
1270 stateChanged("new_file");
1271
1272 QClipboard* clipboard = QApplication::clipboard();
1273 connect(clipboard, SIGNAL(dataChanged()),
1274 this, SLOT(updatePasteAction()));
1275 updatePasteAction();
1276 updateGoActions();
1277
1278 if (generalSettings->splitView()) {
1279 toggleSplitView();
1280 }
1281 updateViewActions();
1282
1283 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1284 showFilterBarAction->setChecked(generalSettings->filterBar());
1285
1286 if (firstRun) {
1287 // assure a proper default size if Dolphin runs the first time
1288 resize(750, 500);
1289 }
1290
1291 m_showMenuBar->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1292 }
1293
1294 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
1295 {
1296 Q_ASSERT(viewContainer != 0);
1297 Q_ASSERT((viewContainer == m_viewTab[m_tabIndex].primaryView) ||
1298 (viewContainer == m_viewTab[m_tabIndex].secondaryView));
1299 if (m_activeViewContainer == viewContainer) {
1300 return;
1301 }
1302
1303 m_activeViewContainer->setActive(false);
1304 m_activeViewContainer = viewContainer;
1305
1306 // Activating the view container might trigger a recursive setActiveViewContainer() call
1307 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1308 // disconnect the activated() signal in this case:
1309 disconnect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1310 m_activeViewContainer->setActive(true);
1311 connect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1312
1313 m_actionHandler->setCurrentView(viewContainer->view());
1314
1315 updateHistory();
1316 updateEditActions();
1317 updateViewActions();
1318 updateGoActions();
1319
1320 const KUrl& url = m_activeViewContainer->url();
1321 setUrlAsCaption(url);
1322 if (m_viewTab.count() > 1 && m_viewTab[m_tabIndex].secondaryView != 0) {
1323 m_tabBar->setTabText(m_tabIndex, tabName(url));
1324 m_tabBar->setTabIcon(m_tabIndex, KIcon(KMimeType::iconNameForUrl(url)));
1325 }
1326
1327 emit urlChanged(url);
1328 }
1329
1330 void DolphinMainWindow::setupActions()
1331 {
1332 // setup 'File' menu
1333 m_newMenu = new DolphinNewMenu(this, this);
1334 KMenu* menu = m_newMenu->menu();
1335 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1336 menu->setIcon(KIcon("document-new"));
1337 connect(menu, SIGNAL(aboutToShow()),
1338 this, SLOT(updateNewMenu()));
1339
1340 KAction* newWindow = actionCollection()->addAction("new_window");
1341 newWindow->setIcon(KIcon("window-new"));
1342 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1343 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
1344 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1345
1346 KAction* newTab = actionCollection()->addAction("new_tab");
1347 newTab->setIcon(KIcon("tab-new"));
1348 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1349 newTab->setShortcut(KShortcut(Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N));
1350 connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab()));
1351
1352 KAction* closeTab = actionCollection()->addAction("close_tab");
1353 closeTab->setIcon(KIcon("tab-close"));
1354 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1355 closeTab->setShortcut(Qt::CTRL | Qt::Key_W);
1356 closeTab->setEnabled(false);
1357 connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
1358
1359 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1360
1361 // setup 'Edit' menu
1362 KStandardAction::undo(this,
1363 SLOT(undo()),
1364 actionCollection());
1365
1366 // need to remove shift+del from cut action, else the shortcut for deletejob
1367 // doesn't work
1368 KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
1369 KShortcut cutShortcut = cut->shortcut();
1370 cutShortcut.remove(Qt::SHIFT + Qt::Key_Delete, KShortcut::KeepEmpty);
1371 cut->setShortcut(cutShortcut);
1372 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1373 KAction* paste = KStandardAction::paste(this, SLOT(paste()), actionCollection());
1374 // The text of the paste-action is modified dynamically by Dolphin
1375 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1376 // due to the long text, the text "Paste" is used:
1377 paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1378
1379 KAction* selectAll = actionCollection()->addAction("select_all");
1380 selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
1381 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
1382 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
1383
1384 KAction* invertSelection = actionCollection()->addAction("invert_selection");
1385 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1386 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1387 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
1388
1389 // setup 'View' menu
1390 // (note that most of it is set up in DolphinViewActionHandler)
1391
1392 KAction* split = actionCollection()->addAction("split_view");
1393 split->setShortcut(Qt::Key_F3);
1394 updateSplitAction();
1395 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1396
1397 KAction* reload = actionCollection()->addAction("reload");
1398 reload->setText(i18nc("@action:inmenu View", "Reload"));
1399 reload->setShortcut(Qt::Key_F5);
1400 reload->setIcon(KIcon("view-refresh"));
1401 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
1402
1403 KAction* stop = actionCollection()->addAction("stop");
1404 stop->setText(i18nc("@action:inmenu View", "Stop"));
1405 stop->setToolTip(i18nc("@info", "Stop loading"));
1406 stop->setIcon(KIcon("process-stop"));
1407 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
1408
1409 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
1410 showFullLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1411 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
1412 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1413
1414 KAction* replaceLocation = actionCollection()->addAction("replace_location");
1415 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1416 replaceLocation->setShortcut(Qt::Key_F6);
1417 connect(replaceLocation, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1418
1419 // setup 'Go' menu
1420 KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
1421 connect(backAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goBack(Qt::MouseButtons)));
1422 KShortcut backShortcut = backAction->shortcut();
1423 backShortcut.setAlternate(Qt::Key_Backspace);
1424 backAction->setShortcut(backShortcut);
1425
1426 m_recentTabsMenu = new KActionMenu(i18n("Recently Closed Tabs"), this);
1427 m_recentTabsMenu->setIcon(KIcon("edit-undo"));
1428 actionCollection()->addAction("closed_tabs", m_recentTabsMenu);
1429 connect(m_recentTabsMenu->menu(), SIGNAL(triggered(QAction *)),
1430 this, SLOT(restoreClosedTab(QAction *)));
1431
1432 QAction* action = new QAction("Empty Recently Closed Tabs", m_recentTabsMenu);
1433 action->setIcon(KIcon("edit-clear-list"));
1434 action->setData(QVariant::fromValue(true));
1435 m_recentTabsMenu->addAction(action);
1436 m_recentTabsMenu->addSeparator();
1437 m_recentTabsMenu->setEnabled(false);
1438
1439 KAction* forwardAction = KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1440 connect(forwardAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goForward(Qt::MouseButtons)));
1441
1442 KAction* upAction = KStandardAction::up(this, SLOT(goUp()), actionCollection());
1443 connect(upAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goUp(Qt::MouseButtons)));
1444
1445 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1446
1447 // setup 'Tools' menu
1448 KToggleAction* showSearchBar = actionCollection()->add<KToggleAction>("show_search_bar");
1449 showSearchBar->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1450 showSearchBar->setShortcut(Qt::CTRL | Qt::Key_S);
1451 connect(showSearchBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1452
1453 KToggleAction* showFilterBar = actionCollection()->add<KToggleAction>("show_filter_bar");
1454 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1455 showFilterBar->setIcon(KIcon("view-filter"));
1456 showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
1457 connect(showFilterBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1458
1459 KAction* compareFiles = actionCollection()->addAction("compare_files");
1460 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1461 compareFiles->setIcon(KIcon("kompare"));
1462 compareFiles->setEnabled(false);
1463 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1464
1465 KAction* openTerminal = actionCollection()->addAction("open_terminal");
1466 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1467 openTerminal->setIcon(KIcon("utilities-terminal"));
1468 openTerminal->setShortcut(Qt::SHIFT | Qt::Key_F4);
1469 connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal()));
1470
1471 // setup 'Settings' menu
1472 m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1473 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1474
1475 // not in menu actions
1476 KAction* activateNextTab = actionCollection()->addAction("activate_next_tab");
1477 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1478 connect(activateNextTab, SIGNAL(triggered()), SLOT(activateNextTab()));
1479 activateNextTab->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1480 KStandardShortcut::tabNext());
1481
1482 KAction* activatePrevTab = actionCollection()->addAction("activate_prev_tab");
1483 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1484 connect(activatePrevTab, SIGNAL(triggered()), SLOT(activatePrevTab()));
1485 activatePrevTab->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1486 KStandardShortcut::tabPrev());
1487
1488 // for context menu
1489 KAction* openInNewTab = actionCollection()->addAction("open_in_new_tab");
1490 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
1491 openInNewTab->setIcon(KIcon("tab-new"));
1492 connect(openInNewTab, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1493
1494 KAction* openInNewWindow = actionCollection()->addAction("open_in_new_window");
1495 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
1496 openInNewWindow->setIcon(KIcon("window-new"));
1497 connect(openInNewWindow, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1498
1499 // 'Search' toolbar
1500 m_searchBox = new DolphinSearchBox(this);
1501 connect(m_searchBox, SIGNAL(search(QString)), this, SLOT(searchItems()));
1502
1503 KAction* search = new KAction(this);
1504 actionCollection()->addAction("search_bar", search);
1505 search->setText(i18nc("@action:inmenu", "Search Bar"));
1506 search->setDefaultWidget(m_searchBox);
1507 search->setShortcutConfigurable(false);
1508 }
1509
1510 void DolphinMainWindow::setupDockWidgets()
1511 {
1512 // setup "Information"
1513 QDockWidget* infoDock = new QDockWidget(i18nc("@title:window", "Information"));
1514 infoDock->setObjectName("infoDock");
1515 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1516 Panel* infoPanel = new InformationPanel(infoDock);
1517 connect(infoPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
1518 infoDock->setWidget(infoPanel);
1519
1520 KAction* infoAction = new KAction(this);
1521 infoAction->setText(i18nc("@title:window", "Information"));
1522 infoAction->setShortcut(Qt::Key_F11);
1523 infoAction->setIcon(KIcon("dialog-information"));
1524 actionCollection()->addAction("show_info_panel", infoAction);
1525 connect(infoAction, SIGNAL(triggered()), infoDock->toggleViewAction(), SLOT(trigger()));
1526
1527 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1528 connect(this, SIGNAL(urlChanged(KUrl)),
1529 infoPanel, SLOT(setUrl(KUrl)));
1530 connect(this, SIGNAL(selectionChanged(KFileItemList)),
1531 infoPanel, SLOT(setSelection(KFileItemList)));
1532 connect(this, SIGNAL(requestItemInfo(KFileItem)),
1533 infoPanel, SLOT(requestDelayedItemInfo(KFileItem)));
1534
1535 // setup "Folders"
1536 QDockWidget* foldersDock = new QDockWidget(i18nc("@title:window", "Folders"));
1537 foldersDock->setObjectName("foldersDock");
1538 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1539 FoldersPanel* foldersPanel = new FoldersPanel(foldersDock);
1540 foldersDock->setWidget(foldersPanel);
1541
1542 KAction* foldersAction = new KAction(this);
1543 foldersAction->setText(i18nc("@title:window", "Folders"));
1544 foldersAction->setShortcut(Qt::Key_F7);
1545 foldersAction->setIcon(KIcon("folder"));
1546 actionCollection()->addAction("show_folders_panel", foldersAction);
1547 connect(foldersAction, SIGNAL(triggered()), foldersDock->toggleViewAction(), SLOT(trigger()));
1548
1549 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
1550 connect(this, SIGNAL(urlChanged(KUrl)),
1551 foldersPanel, SLOT(setUrl(KUrl)));
1552 connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
1553 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1554
1555 // setup "Terminal"
1556 #ifndef Q_OS_WIN
1557 QDockWidget* terminalDock = new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1558 terminalDock->setObjectName("terminalDock");
1559 terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1560 Panel* terminalPanel = new TerminalPanel(terminalDock);
1561 terminalDock->setWidget(terminalPanel);
1562
1563 connect(terminalPanel, SIGNAL(hideTerminalPanel()), terminalDock, SLOT(hide()));
1564
1565 KAction* terminalAction = new KAction(this);
1566 terminalAction->setText(i18nc("@title:window Shell terminal", "Terminal"));
1567 terminalAction->setShortcut(Qt::Key_F4);
1568 terminalAction->setIcon(KIcon("utilities-terminal"));
1569 actionCollection()->addAction("show_terminal_panel", terminalAction);
1570 connect(terminalAction, SIGNAL(triggered()), terminalDock->toggleViewAction(), SLOT(trigger()));
1571
1572 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
1573 connect(this, SIGNAL(urlChanged(KUrl)),
1574 terminalPanel, SLOT(setUrl(KUrl)));
1575 #endif
1576
1577 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
1578 if (firstRun) {
1579 foldersDock->hide();
1580 #ifndef Q_OS_WIN
1581 terminalDock->hide();
1582 #endif
1583 }
1584
1585 // setup "Places"
1586 QDockWidget* placesDock = new QDockWidget(i18nc("@title:window", "Places"));
1587 placesDock->setObjectName("placesDock");
1588 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1589
1590 PlacesPanel* placesPanel = new PlacesPanel(placesDock);
1591 placesDock->setWidget(placesPanel);
1592 placesPanel->setModel(DolphinSettings::instance().placesModel());
1593 placesPanel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1594
1595 KAction* placesAction = new KAction(this);
1596 placesAction->setText(i18nc("@title:window", "Places"));
1597 placesAction->setShortcut(Qt::Key_F9);
1598 placesAction->setIcon(KIcon("bookmarks"));
1599 actionCollection()->addAction("show_places_panel", placesAction);
1600 connect(placesAction, SIGNAL(triggered()), placesDock->toggleViewAction(), SLOT(trigger()));
1601
1602 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1603 connect(placesPanel, SIGNAL(urlChanged(KUrl, Qt::MouseButtons)),
1604 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1605 connect(this, SIGNAL(urlChanged(KUrl)),
1606 placesPanel, SLOT(setUrl(KUrl)));
1607 }
1608
1609 void DolphinMainWindow::updateEditActions()
1610 {
1611 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
1612 if (list.isEmpty()) {
1613 stateChanged("has_no_selection");
1614 } else {
1615 stateChanged("has_selection");
1616
1617 KActionCollection* col = actionCollection();
1618 QAction* renameAction = col->action("rename");
1619 QAction* moveToTrashAction = col->action("move_to_trash");
1620 QAction* deleteAction = col->action("delete");
1621 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
1622 QAction* deleteWithTrashShortcut = col->action("delete_shortcut"); // see DolphinViewActionHandler
1623
1624 KFileItemListProperties capabilities(list);
1625 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
1626
1627 renameAction->setEnabled(capabilities.supportsMoving());
1628 moveToTrashAction->setEnabled(enableMoveToTrash);
1629 deleteAction->setEnabled(capabilities.supportsDeleting());
1630 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
1631 cutAction->setEnabled(capabilities.supportsMoving());
1632 }
1633 updatePasteAction();
1634 }
1635
1636 void DolphinMainWindow::updateViewActions()
1637 {
1638 m_actionHandler->updateViewActions();
1639
1640 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1641 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
1642
1643 updateSplitAction();
1644
1645 QAction* editableLocactionAction = actionCollection()->action("editable_location");
1646 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
1647 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
1648 }
1649
1650 void DolphinMainWindow::updateGoActions()
1651 {
1652 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
1653 const KUrl& currentUrl = m_activeViewContainer->url();
1654 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1655 }
1656
1657 void DolphinMainWindow::rememberClosedTab(int index)
1658 {
1659 KMenu* tabsMenu = m_recentTabsMenu->menu();
1660
1661 const QString primaryPath = m_viewTab[index].primaryView->url().path();
1662 const QString iconName = KMimeType::iconNameForUrl(primaryPath);
1663
1664 QAction* action = new QAction(squeezedText(primaryPath), tabsMenu);
1665
1666 ClosedTab closedTab;
1667 closedTab.primaryUrl = m_viewTab[index].primaryView->url();
1668
1669 if (m_viewTab[index].secondaryView != 0) {
1670 closedTab.secondaryUrl = m_viewTab[index].secondaryView->url();
1671 closedTab.isSplit = true;
1672 } else {
1673 closedTab.isSplit = false;
1674 }
1675
1676 action->setData(QVariant::fromValue(closedTab));
1677 action->setIcon(KIcon(iconName));
1678
1679 // add the closed tab menu entry after the separator and
1680 // "Empty Recently Closed Tabs" entry
1681 if (tabsMenu->actions().size() == 2) {
1682 tabsMenu->addAction(action);
1683 } else {
1684 tabsMenu->insertAction(tabsMenu->actions().at(2), action);
1685 }
1686
1687 // assure that only up to 8 closed tabs are shown in the menu
1688 if (tabsMenu->actions().size() > 8) {
1689 tabsMenu->removeAction(tabsMenu->actions().last());
1690 }
1691 actionCollection()->action("closed_tabs")->setEnabled(true);
1692 KAcceleratorManager::manage(tabsMenu);
1693 }
1694
1695 void DolphinMainWindow::clearStatusBar()
1696 {
1697 m_activeViewContainer->statusBar()->clear();
1698 }
1699
1700 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
1701 {
1702 connect(container, SIGNAL(showFilterBarChanged(bool)),
1703 this, SLOT(updateFilterBarAction(bool)));
1704 connect(container, SIGNAL(writeStateChanged(bool)),
1705 this, SLOT(slotWriteStateChanged(bool)));
1706
1707 DolphinView* view = container->view();
1708 connect(view, SIGNAL(selectionChanged(KFileItemList)),
1709 this, SLOT(slotSelectionChanged(KFileItemList)));
1710 connect(view, SIGNAL(requestItemInfo(KFileItem)),
1711 this, SLOT(slotRequestItemInfo(KFileItem)));
1712 connect(view, SIGNAL(activated()),
1713 this, SLOT(toggleActiveView()));
1714 connect(view, SIGNAL(tabRequested(const KUrl&)),
1715 this, SLOT(openNewTab(const KUrl&)));
1716 connect(view, SIGNAL(requestContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)),
1717 this, SLOT(openContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)));
1718
1719 const KUrlNavigator* navigator = container->urlNavigator();
1720 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1721 this, SLOT(changeUrl(const KUrl&)));
1722 connect(navigator, SIGNAL(historyChanged()),
1723 this, SLOT(updateHistory()));
1724 connect(navigator, SIGNAL(editableStateChanged(bool)),
1725 this, SLOT(slotEditableStateChanged(bool)));
1726 connect(navigator, SIGNAL(tabRequested(const KUrl&)),
1727 this, SLOT(openNewTab(KUrl)));
1728 }
1729
1730 void DolphinMainWindow::updateSplitAction()
1731 {
1732 QAction* splitAction = actionCollection()->action("split_view");
1733 if (m_viewTab[m_tabIndex].secondaryView != 0) {
1734 if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
1735 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
1736 splitAction->setToolTip(i18nc("@info", "Close right view"));
1737 splitAction->setIcon(KIcon("view-right-close"));
1738 } else {
1739 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
1740 splitAction->setToolTip(i18nc("@info", "Close left view"));
1741 splitAction->setIcon(KIcon("view-left-close"));
1742 }
1743 } else {
1744 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
1745 splitAction->setToolTip(i18nc("@info", "Split view"));
1746 splitAction->setIcon(KIcon("view-right-new"));
1747 }
1748 }
1749
1750 QString DolphinMainWindow::tabName(const KUrl& url) const
1751 {
1752 QString name;
1753 if (url.equals(KUrl("file:///"))) {
1754 name = '/';
1755 } else {
1756 name = url.fileName();
1757 if (name.isEmpty()) {
1758 name = url.protocol();
1759 } else {
1760 // Make sure that a '&' inside the directory name is displayed correctly
1761 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1762 name.replace('&', "&&");
1763 }
1764 }
1765 return name;
1766 }
1767
1768 bool DolphinMainWindow::isKompareInstalled() const
1769 {
1770 static bool initialized = false;
1771 static bool installed = false;
1772 if (!initialized) {
1773 // TODO: maybe replace this approach later by using a menu
1774 // plugin like kdiff3plugin.cpp
1775 installed = !KGlobal::dirs()->findExe("kompare").isEmpty();
1776 initialized = true;
1777 }
1778 return installed;
1779 }
1780
1781 void DolphinMainWindow::createSecondaryView(int tabIndex)
1782 {
1783 QSplitter* splitter = m_viewTab[tabIndex].splitter;
1784 const int newWidth = (m_viewTab[tabIndex].primaryView->width() - splitter->handleWidth()) / 2;
1785
1786 const DolphinView* view = m_viewTab[tabIndex].primaryView->view();
1787 m_viewTab[tabIndex].secondaryView = new DolphinViewContainer(view->rootUrl(), 0);
1788 splitter->addWidget(m_viewTab[tabIndex].secondaryView);
1789 splitter->setSizes(QList<int>() << newWidth << newWidth);
1790 connectViewSignals(m_viewTab[tabIndex].secondaryView);
1791 m_viewTab[tabIndex].secondaryView->view()->reload();
1792 m_viewTab[tabIndex].secondaryView->setActive(false);
1793 m_viewTab[tabIndex].secondaryView->show();
1794 }
1795
1796 QString DolphinMainWindow::tabProperty(const QString& property, int tabIndex) const
1797 {
1798 return "Tab " + QString::number(tabIndex) + ' ' + property;
1799 }
1800
1801 void DolphinMainWindow::setUrlAsCaption(const KUrl& url)
1802 {
1803 delete m_captionStatJob;
1804 m_captionStatJob = 0;
1805
1806 if (url.protocol() == QLatin1String("file")) {
1807 QString caption;
1808 if (url.equals(KUrl("file:///"))) {
1809 caption = '/';
1810 } else {
1811 caption = url.fileName();
1812 if (caption.isEmpty()) {
1813 caption = url.protocol();
1814 }
1815 }
1816
1817 setCaption(caption);
1818 } else {
1819 m_captionStatJob = KIO::stat(url, KIO::HideProgressInfo);
1820 connect(m_captionStatJob, SIGNAL(result(KJob*)),
1821 this, SLOT(slotCaptionStatFinished(KJob*)));
1822 }
1823 }
1824
1825 QString DolphinMainWindow::squeezedText(const QString& text) const
1826 {
1827 const QFontMetrics fm = fontMetrics();
1828 return fm.elidedText(text, Qt::ElideMiddle, fm.maxWidth() * 10);
1829 }
1830
1831 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1832 KIO::FileUndoManager::UiInterface()
1833 {
1834 }
1835
1836 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1837 {
1838 }
1839
1840 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1841 {
1842 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
1843 if (mainWin) {
1844 DolphinStatusBar* statusBar = mainWin->activeViewContainer()->statusBar();
1845 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1846 } else {
1847 KIO::FileUndoManager::UiInterface::jobError(job);
1848 }
1849 }
1850
1851 #include "dolphinmainwindow.moc"