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