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