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