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