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