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