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