]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Fix i18n context info: "@action:inmenu File" -> "... View"
[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->setButtonGuiItem(KDialog::Yes, KStandardGuiItem::quit());
540 dialog->setButtonGuiItem(KDialog::No, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
541 dialog->setButtonGuiItem(KDialog::Cancel, KStandardGuiItem::cancel());
542 dialog->setDefaultButton(KDialog::Yes);
543
544 bool doNotAskAgainCheckboxResult = false;
545
546 const int result = KMessageBox::createKMessageBox(dialog,
547 QMessageBox::Warning,
548 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
549 QStringList(),
550 i18n("Do not ask again"),
551 &doNotAskAgainCheckboxResult,
552 KMessageBox::Notify);
553
554 if (doNotAskAgainCheckboxResult) {
555 generalSettings->setConfirmClosingMultipleTabs(false);
556 }
557
558 switch (result) {
559 case KDialog::Yes:
560 // Quit
561 break;
562 case KDialog::No:
563 // Close only the current tab
564 closeTab();
565 default:
566 event->ignore();
567 return;
568 }
569 }
570
571 generalSettings->setFirstRun(false);
572
573 settings.save();
574
575 KXmlGuiWindow::closeEvent(event);
576 }
577
578 void DolphinMainWindow::saveProperties(KConfigGroup& group)
579 {
580 const int tabCount = m_viewTab.count();
581 group.writeEntry("Tab Count", tabCount);
582 group.writeEntry("Active Tab Index", m_tabBar->currentIndex());
583
584 for (int i = 0; i < tabCount; ++i) {
585 const DolphinViewContainer* cont = m_viewTab[i].primaryView;
586 group.writeEntry(tabProperty("Primary URL", i), cont->url().url());
587 group.writeEntry(tabProperty("Primary Editable", i),
588 cont->urlNavigator()->isUrlEditable());
589
590 cont = m_viewTab[i].secondaryView;
591 if (cont != 0) {
592 group.writeEntry(tabProperty("Secondary URL", i), cont->url().url());
593 group.writeEntry(tabProperty("Secondary Editable", i),
594 cont->urlNavigator()->isUrlEditable());
595 }
596 }
597 }
598
599 void DolphinMainWindow::readProperties(const KConfigGroup& group)
600 {
601 const int tabCount = group.readEntry("Tab Count", 1);
602 for (int i = 0; i < tabCount; ++i) {
603 DolphinViewContainer* cont = m_viewTab[i].primaryView;
604
605 cont->setUrl(group.readEntry(tabProperty("Primary URL", i)));
606 const bool editable = group.readEntry(tabProperty("Primary Editable", i), false);
607 cont->urlNavigator()->setUrlEditable(editable);
608
609 cont = m_viewTab[i].secondaryView;
610 const QString secondaryUrl = group.readEntry(tabProperty("Secondary URL", i));
611 if (!secondaryUrl.isEmpty()) {
612 if (cont == 0) {
613 // a secondary view should be shown, but no one is available
614 // currently -> create a new view
615 toggleSplitView();
616 cont = m_viewTab[i].secondaryView;
617 Q_ASSERT(cont != 0);
618 }
619
620 cont->setUrl(secondaryUrl);
621 const bool editable = group.readEntry(tabProperty("Secondary Editable", i), false);
622 cont->urlNavigator()->setUrlEditable(editable);
623 } else if (cont != 0) {
624 // no secondary view should be shown, but the default setting shows
625 // one already -> close the view
626 toggleSplitView();
627 }
628
629 // openNewTab() needs to be called only tabCount - 1 times
630 if (i != tabCount - 1) {
631 openNewTab();
632 }
633 }
634
635 const int index = group.readEntry("Active Tab Index", 0);
636 m_tabBar->setCurrentIndex(index);
637 }
638
639 void DolphinMainWindow::updateNewMenu()
640 {
641 m_newMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
642 m_newMenu->checkUpToDate();
643 m_newMenu->setPopupFiles(activeViewContainer()->url());
644 }
645
646 void DolphinMainWindow::createDirectory()
647 {
648 m_newMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
649 m_newMenu->setPopupFiles(activeViewContainer()->url());
650 m_newMenu->createDirectory();
651 }
652
653 void DolphinMainWindow::quit()
654 {
655 close();
656 }
657
658 void DolphinMainWindow::showErrorMessage(const QString& message)
659 {
660 if (!message.isEmpty()) {
661 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
662 statusBar->setMessage(message, DolphinStatusBar::Error);
663 }
664 }
665
666 void DolphinMainWindow::slotUndoAvailable(bool available)
667 {
668 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
669 if (undoAction != 0) {
670 undoAction->setEnabled(available);
671 }
672 }
673
674 void DolphinMainWindow::restoreClosedTab(QAction* action)
675 {
676 if (action->data().toBool()) {
677 // clear all actions except the "Empty Recently Closed Tabs"
678 // action and the separator
679 QList<QAction*> actions = m_recentTabsMenu->menu()->actions();
680 const int count = actions.size();
681 for (int i = 2; i < count; ++i) {
682 m_recentTabsMenu->menu()->removeAction(actions.at(i));
683 }
684 } else {
685 const ClosedTab closedTab = action->data().value<ClosedTab>();
686 openNewTab(closedTab.primaryUrl);
687 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
688
689 if (closedTab.isSplit) {
690 // create secondary view
691 toggleSplitView();
692 m_viewTab[m_tabIndex].secondaryView->setUrl(closedTab.secondaryUrl);
693 }
694
695 m_recentTabsMenu->removeAction(action);
696 }
697
698 if (m_recentTabsMenu->menu()->actions().count() == 2) {
699 m_recentTabsMenu->setEnabled(false);
700 }
701 }
702
703 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
704 {
705 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
706 if (undoAction != 0) {
707 undoAction->setText(text);
708 }
709 }
710
711 void DolphinMainWindow::undo()
712 {
713 clearStatusBar();
714 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
715 KIO::FileUndoManager::self()->undo();
716 }
717
718 void DolphinMainWindow::cut()
719 {
720 m_activeViewContainer->view()->cutSelectedItems();
721 }
722
723 void DolphinMainWindow::copy()
724 {
725 m_activeViewContainer->view()->copySelectedItems();
726 }
727
728 void DolphinMainWindow::paste()
729 {
730 m_activeViewContainer->view()->paste();
731 }
732
733 void DolphinMainWindow::updatePasteAction()
734 {
735 QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
736 QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
737 pasteAction->setEnabled(pasteInfo.first);
738 pasteAction->setText(pasteInfo.second);
739 }
740
741 void DolphinMainWindow::selectAll()
742 {
743 clearStatusBar();
744
745 // if the URL navigator is editable and focused, select the whole
746 // URL instead of all items of the view
747
748 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
749 QLineEdit* lineEdit = urlNavigator->editor()->lineEdit(); // krazy:exclude=qclasses
750 const bool selectUrl = urlNavigator->isUrlEditable() &&
751 lineEdit->hasFocus();
752 if (selectUrl) {
753 lineEdit->selectAll();
754 } else {
755 m_activeViewContainer->view()->selectAll();
756 }
757 }
758
759 void DolphinMainWindow::invertSelection()
760 {
761 clearStatusBar();
762 m_activeViewContainer->view()->invertSelection();
763 }
764
765 void DolphinMainWindow::toggleSplitView()
766 {
767 if (m_viewTab[m_tabIndex].secondaryView == 0) {
768 createSecondaryView(m_tabIndex);
769 setActiveViewContainer(m_viewTab[m_tabIndex].secondaryView);
770 } else if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
771 // remove secondary view
772 m_viewTab[m_tabIndex].secondaryView->close();
773 m_viewTab[m_tabIndex].secondaryView->deleteLater();
774 m_viewTab[m_tabIndex].secondaryView = 0;
775
776 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
777 } else {
778 // The primary view is active and should be closed. Hence from a users point of view
779 // the content of the secondary view should be moved to the primary view.
780 // From an implementation point of view it is more efficient to close
781 // the primary view and exchange the internal pointers afterwards.
782
783 m_viewTab[m_tabIndex].primaryView->close();
784 m_viewTab[m_tabIndex].primaryView->deleteLater();
785 m_viewTab[m_tabIndex].primaryView = m_viewTab[m_tabIndex].secondaryView;
786 m_viewTab[m_tabIndex].secondaryView = 0;
787
788 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
789 }
790
791 updateViewActions();
792 }
793
794 void DolphinMainWindow::reloadView()
795 {
796 clearStatusBar();
797 m_activeViewContainer->view()->reload();
798 }
799
800 void DolphinMainWindow::stopLoading()
801 {
802 }
803
804 void DolphinMainWindow::toggleFilterBarVisibility(bool show)
805 {
806 m_activeViewContainer->showFilterBar(show);
807 }
808
809 void DolphinMainWindow::toggleEditLocation()
810 {
811 clearStatusBar();
812
813 QAction* action = actionCollection()->action("editable_location");
814 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
815 urlNavigator->setUrlEditable(action->isChecked());
816 }
817
818 void DolphinMainWindow::replaceLocation()
819 {
820 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
821 navigator->setUrlEditable(true);
822 navigator->setFocus();
823
824 // select the whole text of the combo box editor
825 QLineEdit* lineEdit = navigator->editor()->lineEdit(); // krazy:exclude=qclasses
826 const QString text = lineEdit->text();
827 lineEdit->setSelection(0, text.length());
828 }
829
830 void DolphinMainWindow::goBack()
831 {
832 clearStatusBar();
833 m_activeViewContainer->urlNavigator()->goBack();
834 }
835
836 void DolphinMainWindow::goForward()
837 {
838 clearStatusBar();
839 m_activeViewContainer->urlNavigator()->goForward();
840 }
841
842 void DolphinMainWindow::goUp()
843 {
844 clearStatusBar();
845 m_activeViewContainer->urlNavigator()->goUp();
846 }
847
848 void DolphinMainWindow::goBack(Qt::MouseButtons buttons)
849 {
850 // The default case (left button pressed) is handled in goBack().
851 if (buttons == Qt::MidButton) {
852 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
853 const int index = urlNavigator->historyIndex() + 1;
854 openNewTab(urlNavigator->locationUrl(index));
855 }
856 }
857
858 void DolphinMainWindow::goForward(Qt::MouseButtons buttons)
859 {
860 // The default case (left button pressed) is handled in goForward().
861 if (buttons == Qt::MidButton) {
862 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
863 const int index = urlNavigator->historyIndex() - 1;
864 openNewTab(urlNavigator->locationUrl(index));
865 }
866 }
867
868 void DolphinMainWindow::goUp(Qt::MouseButtons buttons)
869 {
870 // The default case (left button pressed) is handled in goUp().
871 if (buttons == Qt::MidButton) {
872 openNewTab(activeViewContainer()->url().upUrl());
873 }
874 }
875
876 void DolphinMainWindow::goHome()
877 {
878 clearStatusBar();
879 m_activeViewContainer->urlNavigator()->goHome();
880 }
881
882 void DolphinMainWindow::compareFiles()
883 {
884 // The method is only invoked if exactly 2 files have
885 // been selected. The selected files may be:
886 // - both in the primary view
887 // - both in the secondary view
888 // - one in the primary view and the other in the secondary
889 // view
890 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
891
892 KUrl urlA;
893 KUrl urlB;
894 KUrl::List urls = m_viewTab[m_tabIndex].primaryView->view()->selectedUrls();
895
896 switch (urls.count()) {
897 case 0: {
898 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView != 0);
899 urls = m_viewTab[m_tabIndex].secondaryView->view()->selectedUrls();
900 Q_ASSERT(urls.count() == 2);
901 urlA = urls[0];
902 urlB = urls[1];
903 break;
904 }
905
906 case 1: {
907 urlA = urls[0];
908 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView != 0);
909 urls = m_viewTab[m_tabIndex].secondaryView->view()->selectedUrls();
910 Q_ASSERT(urls.count() == 1);
911 urlB = urls[0];
912 break;
913 }
914
915 case 2: {
916 urlA = urls[0];
917 urlB = urls[1];
918 break;
919 }
920
921 default: {
922 // may not happen: compareFiles may only get invoked if 2
923 // files are selected
924 Q_ASSERT(false);
925 }
926 }
927
928 QString command("kompare -c \"");
929 command.append(urlA.pathOrUrl());
930 command.append("\" \"");
931 command.append(urlB.pathOrUrl());
932 command.append('\"');
933 KRun::runCommand(command, "Kompare", "kompare", this);
934 }
935
936 void DolphinMainWindow::toggleShowMenuBar()
937 {
938 const bool visible = menuBar()->isVisible();
939 menuBar()->setVisible(!visible);
940 }
941
942 void DolphinMainWindow::openTerminal()
943 {
944 QString dir(QDir::homePath());
945
946 // If the given directory is not local, it can still be the URL of an
947 // ioslave using UDS_LOCAL_PATH which to be converted first.
948 KUrl url = KIO::NetAccess::mostLocalUrl(m_activeViewContainer->url(), this);
949
950 //If the URL is local after the above conversion, set the directory.
951 if (url.isLocalFile()) {
952 dir = url.toLocalFile();
953 }
954
955 KToolInvocation::invokeTerminal(QString(), dir);
956 }
957
958 void DolphinMainWindow::editSettings()
959 {
960 if (m_settingsDialog == 0) {
961 const KUrl& url = activeViewContainer()->url();
962 m_settingsDialog = new DolphinSettingsDialog(url, this);
963 m_settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
964 m_settingsDialog->show();
965 } else {
966 m_settingsDialog->raise();
967 }
968 }
969
970 void DolphinMainWindow::setActiveTab(int index)
971 {
972 Q_ASSERT(index >= 0);
973 Q_ASSERT(index < m_viewTab.count());
974 if (index == m_tabIndex) {
975 return;
976 }
977
978 // hide current tab content
979 ViewTab& hiddenTab = m_viewTab[m_tabIndex];
980 hiddenTab.isPrimaryViewActive = hiddenTab.primaryView->isActive();
981 hiddenTab.primaryView->setActive(false);
982 if (hiddenTab.secondaryView != 0) {
983 hiddenTab.secondaryView->setActive(false);
984 }
985 QSplitter* splitter = m_viewTab[m_tabIndex].splitter;
986 splitter->hide();
987 m_centralWidgetLayout->removeWidget(splitter);
988
989 // show active tab content
990 m_tabIndex = index;
991
992 ViewTab& viewTab = m_viewTab[index];
993 m_centralWidgetLayout->addWidget(viewTab.splitter, 1);
994 viewTab.primaryView->show();
995 if (viewTab.secondaryView != 0) {
996 viewTab.secondaryView->show();
997 }
998 viewTab.splitter->show();
999
1000 setActiveViewContainer(viewTab.isPrimaryViewActive ? viewTab.primaryView :
1001 viewTab.secondaryView);
1002 }
1003
1004 void DolphinMainWindow::closeTab()
1005 {
1006 closeTab(m_tabBar->currentIndex());
1007 }
1008
1009 void DolphinMainWindow::closeTab(int index)
1010 {
1011 Q_ASSERT(index >= 0);
1012 Q_ASSERT(index < m_viewTab.count());
1013 if (m_viewTab.count() == 1) {
1014 // the last tab may never get closed
1015 return;
1016 }
1017
1018 if (index == m_tabIndex) {
1019 // The tab that should be closed is the active tab. Activate the
1020 // previous tab before closing the tab.
1021 m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1);
1022 }
1023 rememberClosedTab(index);
1024
1025 // delete tab
1026 m_viewTab[index].primaryView->deleteLater();
1027 if (m_viewTab[index].secondaryView != 0) {
1028 m_viewTab[index].secondaryView->deleteLater();
1029 }
1030 m_viewTab[index].splitter->deleteLater();
1031 m_viewTab.erase(m_viewTab.begin() + index);
1032
1033 m_tabBar->blockSignals(true);
1034 m_tabBar->removeTab(index);
1035
1036 if (m_tabIndex > index) {
1037 m_tabIndex--;
1038 Q_ASSERT(m_tabIndex >= 0);
1039 }
1040
1041 // if only one tab is left, also remove the tab entry so that
1042 // closing the last tab is not possible
1043 if (m_viewTab.count() == 1) {
1044 m_tabBar->removeTab(0);
1045 actionCollection()->action("close_tab")->setEnabled(false);
1046 } else {
1047 m_tabBar->blockSignals(false);
1048 }
1049 }
1050
1051 void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos)
1052 {
1053 KMenu menu(this);
1054
1055 QAction* newTabAction = menu.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1056 newTabAction->setShortcut(actionCollection()->action("new_tab")->shortcut());
1057
1058 QAction* detachTabAction = menu.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1059
1060 QAction* closeOtherTabsAction = menu.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1061
1062 QAction* closeTabAction = menu.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1063 closeTabAction->setShortcut(actionCollection()->action("close_tab")->shortcut());
1064 QAction* selectedAction = menu.exec(pos);
1065 if (selectedAction == newTabAction) {
1066 const ViewTab& tab = m_viewTab[index];
1067 Q_ASSERT(tab.primaryView != 0);
1068 const KUrl url = (tab.secondaryView != 0) && tab.secondaryView->isActive() ?
1069 tab.secondaryView->url() : tab.primaryView->url();
1070 openNewTab(url);
1071 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
1072 } else if (selectedAction == detachTabAction) {
1073 const ViewTab& tab = m_viewTab[index];
1074 Q_ASSERT(tab.primaryView != 0);
1075 const KUrl primaryUrl = tab.primaryView->url();
1076 DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
1077 window->changeUrl(primaryUrl);
1078
1079 if (tab.secondaryView != 0) {
1080 const KUrl secondaryUrl = tab.secondaryView->url();
1081 window->toggleSplitView();
1082 window->m_viewTab[0].secondaryView->setUrl(secondaryUrl);
1083 if (tab.primaryView->isActive()) {
1084 window->m_viewTab[0].primaryView->setActive(true);
1085 } else {
1086 window->m_viewTab[0].secondaryView->setActive(true);
1087 }
1088 }
1089 window->show();
1090 closeTab(index);
1091 } else if (selectedAction == closeOtherTabsAction) {
1092 const int count = m_tabBar->count();
1093 for (int i = 0; i < index; ++i) {
1094 closeTab(0);
1095 }
1096 for (int i = index + 1; i < count; ++i) {
1097 closeTab(1);
1098 }
1099 } else if (selectedAction == closeTabAction) {
1100 closeTab(index);
1101 }
1102 }
1103
1104 void DolphinMainWindow::slotTabMoved(int from, int to)
1105 {
1106 m_viewTab.move(from, to);
1107 m_tabIndex = m_tabBar->currentIndex();
1108 }
1109
1110 void DolphinMainWindow::handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons)
1111 {
1112 if (buttons & Qt::MidButton) {
1113 openNewTab(url);
1114 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
1115 } else {
1116 changeUrl(url);
1117 }
1118 }
1119
1120 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& canDecode)
1121 {
1122 canDecode = KUrl::List::canDecode(event->mimeData());
1123 }
1124
1125 void DolphinMainWindow::searchItems()
1126 {
1127 #ifdef HAVE_NEPOMUK
1128 const KUrl nepomukSearchUrl = m_searchOptionsConfigurator->nepomukSearchUrl();
1129 m_activeViewContainer->setUrl(nepomukSearchUrl);
1130 #endif
1131 }
1132
1133 void DolphinMainWindow::showSearchOptions()
1134 {
1135 #ifdef HAVE_NEPOMUK
1136 m_searchOptionsConfigurator->show();
1137 #endif
1138 }
1139
1140 void DolphinMainWindow::handleUrl(const KUrl& url)
1141 {
1142 delete m_lastHandleUrlStatJob;
1143 m_lastHandleUrlStatJob = 0;
1144
1145 if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
1146 activeViewContainer()->setUrl(url);
1147 } else if (KProtocolManager::supportsListing(url)) {
1148 // stat the URL to see if it is a dir or not
1149 m_lastHandleUrlStatJob = KIO::stat(url, KIO::HideProgressInfo);
1150 connect(m_lastHandleUrlStatJob, SIGNAL(result(KJob*)),
1151 this, SLOT(slotHandleUrlStatFinished(KJob*)));
1152
1153 } else {
1154 new KRun(url, this);
1155 }
1156 }
1157
1158 void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job)
1159 {
1160 m_lastHandleUrlStatJob = 0;
1161 const KIO::UDSEntry entry = static_cast<KIO::StatJob*>(job)->statResult();
1162 const KUrl url = static_cast<KIO::StatJob*>(job)->url();
1163 if ( entry.isDir() ) {
1164 activeViewContainer()->setUrl(url);
1165 } else {
1166 new KRun(url, this);
1167 }
1168 }
1169
1170 void DolphinMainWindow::tabDropEvent(int tab, QDropEvent* event)
1171 {
1172 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
1173 if (!urls.isEmpty() && tab != -1) {
1174 const ViewTab& viewTab = m_viewTab[tab];
1175 const KUrl destPath = viewTab.isPrimaryViewActive ? viewTab.primaryView->url() : viewTab.secondaryView->url();
1176 DragAndDropHelper::instance().dropUrls(KFileItem(), destPath, event, m_tabBar);
1177 }
1178 }
1179
1180 void DolphinMainWindow::slotCaptionStatFinished(KJob* job)
1181 {
1182 m_captionStatJob = 0;
1183 const KIO::UDSEntry entry = static_cast<KIO::StatJob*>(job)->statResult();
1184 const QString name = entry.stringValue(KIO::UDSEntry::UDS_DISPLAY_NAME);
1185 setCaption(name);
1186 }
1187
1188 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
1189 {
1190 newMenu()->setEnabled(isFolderWritable);
1191 }
1192
1193 void DolphinMainWindow::openContextMenu(const KFileItem& item,
1194 const KUrl& url,
1195 const QList<QAction*>& customActions)
1196 {
1197 DolphinContextMenu contextMenu(this, item, url);
1198 contextMenu.setCustomActions(customActions);
1199 contextMenu.open();
1200 }
1201
1202 void DolphinMainWindow::init()
1203 {
1204 DolphinSettings& settings = DolphinSettings::instance();
1205
1206 // Check whether Dolphin runs the first time. If yes then
1207 // a proper default window size is given at the end of DolphinMainWindow::init().
1208 GeneralSettings* generalSettings = settings.generalSettings();
1209 const bool firstRun = generalSettings->firstRun();
1210 if (firstRun) {
1211 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
1212 }
1213
1214 setAcceptDrops(true);
1215
1216 m_viewTab[m_tabIndex].splitter = new QSplitter(this);
1217 m_viewTab[m_tabIndex].splitter->setChildrenCollapsible(false);
1218
1219 setupActions();
1220
1221 const KUrl& homeUrl = generalSettings->homeUrl();
1222 setUrlAsCaption(homeUrl);
1223 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
1224 connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1225 connect(m_actionHandler, SIGNAL(createDirectory()), SLOT(createDirectory()));
1226 ViewProperties props(homeUrl);
1227 m_viewTab[m_tabIndex].primaryView = new DolphinViewContainer(homeUrl,
1228 m_viewTab[m_tabIndex].splitter);
1229
1230 m_activeViewContainer = m_viewTab[m_tabIndex].primaryView;
1231 connectViewSignals(m_activeViewContainer);
1232 DolphinView* view = m_activeViewContainer->view();
1233 view->reload();
1234 m_activeViewContainer->show();
1235 m_actionHandler->setCurrentView(view);
1236
1237 m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
1238 connect(this, SIGNAL(urlChanged(const KUrl&)),
1239 m_remoteEncoding, SLOT(slotAboutToOpenUrl()));
1240
1241 #ifdef HAVE_NEPOMUK
1242 m_searchOptionsConfigurator = new DolphinSearchOptionsConfigurator(this);
1243 m_searchOptionsConfigurator->hide();
1244 connect(m_searchOptionsConfigurator, SIGNAL(searchOptionsChanged()),
1245 this, SLOT(searchItems()));
1246 connect(this, SIGNAL(urlChanged(KUrl)), m_searchOptionsConfigurator, SLOT(setDirectory(KUrl)));
1247 #endif
1248
1249 m_tabBar = new KTabBar(this);
1250 m_tabBar->setMovable(true);
1251 m_tabBar->setTabsClosable(true);
1252 connect(m_tabBar, SIGNAL(currentChanged(int)),
1253 this, SLOT(setActiveTab(int)));
1254 connect(m_tabBar, SIGNAL(tabCloseRequested(int)),
1255 this, SLOT(closeTab(int)));
1256 connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)),
1257 this, SLOT(openTabContextMenu(int, const QPoint&)));
1258 connect(m_tabBar, SIGNAL(newTabRequest()),
1259 this, SLOT(openNewTab()));
1260 connect(m_tabBar, SIGNAL(testCanDecode(const QDragMoveEvent*, bool&)),
1261 this, SLOT(slotTestCanDecode(const QDragMoveEvent*, bool&)));
1262 connect(m_tabBar, SIGNAL(wheelDelta(int)),
1263 this, SLOT(slotWheelMoved(int)));
1264 connect(m_tabBar, SIGNAL(mouseMiddleClick(int)),
1265 this, SLOT(closeTab(int)));
1266 connect(m_tabBar, SIGNAL(tabMoved(int, int)),
1267 this, SLOT(slotTabMoved(int, int)));
1268 connect(m_tabBar, SIGNAL(receivedDropEvent(int, QDropEvent*)),
1269 this, SLOT(tabDropEvent(int, QDropEvent*)));
1270
1271 m_tabBar->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1272
1273 QWidget* centralWidget = new QWidget(this);
1274 m_centralWidgetLayout = new QVBoxLayout(centralWidget);
1275 m_centralWidgetLayout->setSpacing(0);
1276 m_centralWidgetLayout->setMargin(0);
1277 #ifdef HAVE_NEPOMUK
1278 m_centralWidgetLayout->addWidget(m_searchOptionsConfigurator);
1279 #endif
1280 m_centralWidgetLayout->addWidget(m_tabBar);
1281 m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter, 1);
1282
1283 setCentralWidget(centralWidget);
1284 setupDockWidgets();
1285 emit urlChanged(homeUrl);
1286
1287 setupGUI(Keys | Save | Create | ToolBar);
1288
1289 m_searchBox->setParent(toolBar("searchToolBar"));
1290 m_searchBox->show();
1291 connect(m_searchBox, SIGNAL(requestSearchOptions()),
1292 this, SLOT(showSearchOptions()));
1293 #ifdef HAVE_NEPOMUK
1294 connect(m_searchBox, SIGNAL(searchTextChanged(QString)),
1295 m_searchOptionsConfigurator, SLOT(setCustomSearchQuery(QString)));
1296 #endif
1297
1298 stateChanged("new_file");
1299
1300 QClipboard* clipboard = QApplication::clipboard();
1301 connect(clipboard, SIGNAL(dataChanged()),
1302 this, SLOT(updatePasteAction()));
1303
1304 if (generalSettings->splitView()) {
1305 toggleSplitView();
1306 }
1307 updateEditActions();
1308 updateViewActions();
1309 updateGoActions();
1310
1311 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1312 showFilterBarAction->setChecked(generalSettings->filterBar());
1313
1314 if (firstRun) {
1315 // assure a proper default size if Dolphin runs the first time
1316 resize(750, 500);
1317 }
1318
1319 m_showMenuBar->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1320 }
1321
1322 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
1323 {
1324 Q_ASSERT(viewContainer != 0);
1325 Q_ASSERT((viewContainer == m_viewTab[m_tabIndex].primaryView) ||
1326 (viewContainer == m_viewTab[m_tabIndex].secondaryView));
1327 if (m_activeViewContainer == viewContainer) {
1328 return;
1329 }
1330
1331 m_activeViewContainer->setActive(false);
1332 m_activeViewContainer = viewContainer;
1333
1334 // Activating the view container might trigger a recursive setActiveViewContainer() call
1335 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1336 // disconnect the activated() signal in this case:
1337 disconnect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1338 m_activeViewContainer->setActive(true);
1339 connect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1340
1341 m_actionHandler->setCurrentView(viewContainer->view());
1342
1343 updateHistory();
1344 updateEditActions();
1345 updateViewActions();
1346 updateGoActions();
1347
1348 const KUrl& url = m_activeViewContainer->url();
1349 setUrlAsCaption(url);
1350 if (m_viewTab.count() > 1 && m_viewTab[m_tabIndex].secondaryView != 0) {
1351 m_tabBar->setTabText(m_tabIndex, tabName(url));
1352 m_tabBar->setTabIcon(m_tabIndex, KIcon(KMimeType::iconNameForUrl(url)));
1353 }
1354
1355 emit urlChanged(url);
1356 }
1357
1358 void DolphinMainWindow::setupActions()
1359 {
1360 // setup 'File' menu
1361 m_newMenu = new DolphinNewMenu(this, this);
1362 KMenu* menu = m_newMenu->menu();
1363 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1364 menu->setIcon(KIcon("document-new"));
1365 connect(menu, SIGNAL(aboutToShow()),
1366 this, SLOT(updateNewMenu()));
1367
1368 KAction* newWindow = actionCollection()->addAction("new_window");
1369 newWindow->setIcon(KIcon("window-new"));
1370 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1371 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
1372 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1373
1374 KAction* newTab = actionCollection()->addAction("new_tab");
1375 newTab->setIcon(KIcon("tab-new"));
1376 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1377 newTab->setShortcut(KShortcut(Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N));
1378 connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab()));
1379
1380 KAction* closeTab = actionCollection()->addAction("close_tab");
1381 closeTab->setIcon(KIcon("tab-close"));
1382 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1383 closeTab->setShortcut(Qt::CTRL | Qt::Key_W);
1384 closeTab->setEnabled(false);
1385 connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
1386
1387 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1388
1389 // setup 'Edit' menu
1390 KStandardAction::undo(this,
1391 SLOT(undo()),
1392 actionCollection());
1393
1394 // need to remove shift+del from cut action, else the shortcut for deletejob
1395 // doesn't work
1396 KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
1397 KShortcut cutShortcut = cut->shortcut();
1398 cutShortcut.remove(Qt::SHIFT + Qt::Key_Delete, KShortcut::KeepEmpty);
1399 cut->setShortcut(cutShortcut);
1400 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1401 KAction* paste = KStandardAction::paste(this, SLOT(paste()), actionCollection());
1402 // The text of the paste-action is modified dynamically by Dolphin
1403 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1404 // due to the long text, the text "Paste" is used:
1405 paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1406
1407 KAction* selectAll = actionCollection()->addAction("select_all");
1408 selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
1409 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
1410 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
1411
1412 KAction* invertSelection = actionCollection()->addAction("invert_selection");
1413 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1414 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1415 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
1416
1417 // setup 'View' menu
1418 // (note that most of it is set up in DolphinViewActionHandler)
1419
1420 KAction* split = actionCollection()->addAction("split_view");
1421 split->setShortcut(Qt::Key_F3);
1422 updateSplitAction();
1423 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1424
1425 KAction* reload = actionCollection()->addAction("reload");
1426 reload->setText(i18nc("@action:inmenu View", "Reload"));
1427 reload->setShortcut(Qt::Key_F5);
1428 reload->setIcon(KIcon("view-refresh"));
1429 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
1430
1431 KAction* stop = actionCollection()->addAction("stop");
1432 stop->setText(i18nc("@action:inmenu View", "Stop"));
1433 stop->setToolTip(i18nc("@info", "Stop loading"));
1434 stop->setIcon(KIcon("process-stop"));
1435 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
1436
1437 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
1438 showFullLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1439 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
1440 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1441
1442 KAction* replaceLocation = actionCollection()->addAction("replace_location");
1443 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1444 replaceLocation->setShortcut(Qt::Key_F6);
1445 connect(replaceLocation, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1446
1447 // setup 'Go' menu
1448 KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
1449 connect(backAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goBack(Qt::MouseButtons)));
1450 KShortcut backShortcut = backAction->shortcut();
1451 backShortcut.setAlternate(Qt::Key_Backspace);
1452 backAction->setShortcut(backShortcut);
1453
1454 m_recentTabsMenu = new KActionMenu(i18n("Recently Closed Tabs"), this);
1455 m_recentTabsMenu->setIcon(KIcon("edit-undo"));
1456 actionCollection()->addAction("closed_tabs", m_recentTabsMenu);
1457 connect(m_recentTabsMenu->menu(), SIGNAL(triggered(QAction *)),
1458 this, SLOT(restoreClosedTab(QAction *)));
1459
1460 QAction* action = new QAction("Empty Recently Closed Tabs", m_recentTabsMenu);
1461 action->setIcon(KIcon("edit-clear-list"));
1462 action->setData(QVariant::fromValue(true));
1463 m_recentTabsMenu->addAction(action);
1464 m_recentTabsMenu->addSeparator();
1465 m_recentTabsMenu->setEnabled(false);
1466
1467 KAction* forwardAction = KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1468 connect(forwardAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goForward(Qt::MouseButtons)));
1469
1470 KAction* upAction = KStandardAction::up(this, SLOT(goUp()), actionCollection());
1471 connect(upAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goUp(Qt::MouseButtons)));
1472
1473 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1474
1475 // setup 'Tools' menu
1476 KToggleAction* showSearchBar = actionCollection()->add<KToggleAction>("show_search_bar");
1477 showSearchBar->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1478 showSearchBar->setShortcut(Qt::CTRL | Qt::Key_S);
1479 connect(showSearchBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1480
1481 KToggleAction* showFilterBar = actionCollection()->add<KToggleAction>("show_filter_bar");
1482 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1483 showFilterBar->setIcon(KIcon("view-filter"));
1484 showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
1485 connect(showFilterBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1486
1487 KAction* compareFiles = actionCollection()->addAction("compare_files");
1488 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1489 compareFiles->setIcon(KIcon("kompare"));
1490 compareFiles->setEnabled(false);
1491 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1492
1493 KAction* openTerminal = actionCollection()->addAction("open_terminal");
1494 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1495 openTerminal->setIcon(KIcon("utilities-terminal"));
1496 openTerminal->setShortcut(Qt::SHIFT | Qt::Key_F4);
1497 connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal()));
1498
1499 // setup 'Settings' menu
1500 m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1501 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1502
1503 // not in menu actions
1504 QList<QKeySequence> nextTabKeys;
1505 nextTabKeys.append(KStandardShortcut::tabNext().primary());
1506 nextTabKeys.append(QKeySequence(Qt::CTRL + Qt::Key_Tab));
1507
1508 QList<QKeySequence> prevTabKeys;
1509 prevTabKeys.append(KStandardShortcut::tabPrev().primary());
1510 prevTabKeys.append(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab));
1511
1512 KAction* activateNextTab = actionCollection()->addAction("activate_next_tab");
1513 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1514 connect(activateNextTab, SIGNAL(triggered()), SLOT(activateNextTab()));
1515 activateNextTab->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys : nextTabKeys);
1516
1517 KAction* activatePrevTab = actionCollection()->addAction("activate_prev_tab");
1518 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1519 connect(activatePrevTab, SIGNAL(triggered()), SLOT(activatePrevTab()));
1520 activatePrevTab->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys : prevTabKeys);
1521
1522 // for context menu
1523 KAction* openInNewTab = actionCollection()->addAction("open_in_new_tab");
1524 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
1525 openInNewTab->setIcon(KIcon("tab-new"));
1526 connect(openInNewTab, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1527
1528 KAction* openInNewWindow = actionCollection()->addAction("open_in_new_window");
1529 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
1530 openInNewWindow->setIcon(KIcon("window-new"));
1531 connect(openInNewWindow, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1532
1533 // 'Search' toolbar
1534 m_searchBox = new DolphinSearchBox(this);
1535 connect(m_searchBox, SIGNAL(search(QString)), this, SLOT(searchItems()));
1536
1537 KAction* search = new KAction(this);
1538 actionCollection()->addAction("search_bar", search);
1539 search->setText(i18nc("@action:inmenu", "Search Bar"));
1540 search->setDefaultWidget(m_searchBox);
1541 search->setShortcutConfigurable(false);
1542 }
1543
1544 void DolphinMainWindow::setupDockWidgets()
1545 {
1546 // setup "Information"
1547 QDockWidget* infoDock = new QDockWidget(i18nc("@title:window", "Information"));
1548 infoDock->setObjectName("infoDock");
1549 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1550 Panel* infoPanel = new InformationPanel(infoDock);
1551 connect(infoPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
1552 infoDock->setWidget(infoPanel);
1553
1554 QAction* infoAction = infoDock->toggleViewAction();
1555 infoAction->setIcon(KIcon("dialog-information"));
1556 infoAction->setShortcut(Qt::Key_F11);
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 QAction* foldersAction = foldersDock->toggleViewAction();
1574 foldersAction->setShortcut(Qt::Key_F7);
1575 foldersAction->setIcon(KIcon("folder"));
1576
1577 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
1578 connect(this, SIGNAL(urlChanged(KUrl)),
1579 foldersPanel, SLOT(setUrl(KUrl)));
1580 connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
1581 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1582
1583 // setup "Terminal"
1584 #ifndef Q_OS_WIN
1585 QDockWidget* terminalDock = new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1586 terminalDock->setObjectName("terminalDock");
1587 terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1588 Panel* terminalPanel = new TerminalPanel(terminalDock);
1589 terminalDock->setWidget(terminalPanel);
1590
1591 connect(terminalPanel, SIGNAL(hideTerminalPanel()), terminalDock, SLOT(hide()));
1592
1593 QAction* terminalAction = terminalDock->toggleViewAction();
1594 terminalAction->setShortcut(Qt::Key_F4);
1595 terminalAction->setIcon(KIcon("utilities-terminal"));
1596
1597 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
1598 connect(this, SIGNAL(urlChanged(KUrl)),
1599 terminalPanel, SLOT(setUrl(KUrl)));
1600 #endif
1601
1602 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
1603 if (firstRun) {
1604 foldersDock->hide();
1605 #ifndef Q_OS_WIN
1606 terminalDock->hide();
1607 #endif
1608 }
1609
1610 // setup "Places"
1611 QDockWidget* placesDock = new QDockWidget(i18nc("@title:window", "Places"));
1612 placesDock->setObjectName("placesDock");
1613 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1614
1615 PlacesPanel* placesPanel = new PlacesPanel(placesDock);
1616 placesDock->setWidget(placesPanel);
1617 placesPanel->setModel(DolphinSettings::instance().placesModel());
1618 placesPanel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1619
1620 QAction* placesAction = placesDock->toggleViewAction();
1621 placesAction->setShortcut(Qt::Key_F9);
1622 placesAction->setIcon(KIcon("bookmarks"));
1623
1624 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1625 connect(placesPanel, SIGNAL(urlChanged(KUrl, Qt::MouseButtons)),
1626 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1627 connect(this, SIGNAL(urlChanged(KUrl)),
1628 placesPanel, SLOT(setUrl(KUrl)));
1629
1630 KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1631 actionCollection()->addAction("panels", panelsMenu);
1632 panelsMenu->setDelayed(false);
1633 panelsMenu->addAction(placesAction);
1634 panelsMenu->addAction(infoAction);
1635 panelsMenu->addAction(foldersAction);
1636 #ifndef Q_OS_WIN
1637 panelsMenu->addAction(terminalAction);
1638 #endif
1639 }
1640
1641 void DolphinMainWindow::updateEditActions()
1642 {
1643 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
1644 if (list.isEmpty()) {
1645 stateChanged("has_no_selection");
1646 } else {
1647 stateChanged("has_selection");
1648
1649 KActionCollection* col = actionCollection();
1650 QAction* renameAction = col->action("rename");
1651 QAction* moveToTrashAction = col->action("move_to_trash");
1652 QAction* deleteAction = col->action("delete");
1653 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
1654 QAction* deleteWithTrashShortcut = col->action("delete_shortcut"); // see DolphinViewActionHandler
1655
1656 KFileItemListProperties capabilities(list);
1657 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
1658
1659 renameAction->setEnabled(capabilities.supportsMoving());
1660 moveToTrashAction->setEnabled(enableMoveToTrash);
1661 deleteAction->setEnabled(capabilities.supportsDeleting());
1662 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
1663 cutAction->setEnabled(capabilities.supportsMoving());
1664 }
1665 updatePasteAction();
1666 }
1667
1668 void DolphinMainWindow::updateViewActions()
1669 {
1670 m_actionHandler->updateViewActions();
1671
1672 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1673 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
1674
1675 updateSplitAction();
1676
1677 QAction* editableLocactionAction = actionCollection()->action("editable_location");
1678 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
1679 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
1680 }
1681
1682 void DolphinMainWindow::updateGoActions()
1683 {
1684 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
1685 const KUrl& currentUrl = m_activeViewContainer->url();
1686 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1687 }
1688
1689 void DolphinMainWindow::rememberClosedTab(int index)
1690 {
1691 KMenu* tabsMenu = m_recentTabsMenu->menu();
1692
1693 const QString primaryPath = m_viewTab[index].primaryView->url().path();
1694 const QString iconName = KMimeType::iconNameForUrl(primaryPath);
1695
1696 QAction* action = new QAction(squeezedText(primaryPath), tabsMenu);
1697
1698 ClosedTab closedTab;
1699 closedTab.primaryUrl = m_viewTab[index].primaryView->url();
1700
1701 if (m_viewTab[index].secondaryView != 0) {
1702 closedTab.secondaryUrl = m_viewTab[index].secondaryView->url();
1703 closedTab.isSplit = true;
1704 } else {
1705 closedTab.isSplit = false;
1706 }
1707
1708 action->setData(QVariant::fromValue(closedTab));
1709 action->setIcon(KIcon(iconName));
1710
1711 // add the closed tab menu entry after the separator and
1712 // "Empty Recently Closed Tabs" entry
1713 if (tabsMenu->actions().size() == 2) {
1714 tabsMenu->addAction(action);
1715 } else {
1716 tabsMenu->insertAction(tabsMenu->actions().at(2), action);
1717 }
1718
1719 // assure that only up to 8 closed tabs are shown in the menu
1720 if (tabsMenu->actions().size() > 8) {
1721 tabsMenu->removeAction(tabsMenu->actions().last());
1722 }
1723 actionCollection()->action("closed_tabs")->setEnabled(true);
1724 KAcceleratorManager::manage(tabsMenu);
1725 }
1726
1727 void DolphinMainWindow::clearStatusBar()
1728 {
1729 m_activeViewContainer->statusBar()->clear();
1730 }
1731
1732 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
1733 {
1734 connect(container, SIGNAL(showFilterBarChanged(bool)),
1735 this, SLOT(updateFilterBarAction(bool)));
1736 connect(container, SIGNAL(writeStateChanged(bool)),
1737 this, SLOT(slotWriteStateChanged(bool)));
1738
1739 DolphinView* view = container->view();
1740 connect(view, SIGNAL(selectionChanged(KFileItemList)),
1741 this, SLOT(slotSelectionChanged(KFileItemList)));
1742 connect(view, SIGNAL(requestItemInfo(KFileItem)),
1743 this, SLOT(slotRequestItemInfo(KFileItem)));
1744 connect(view, SIGNAL(activated()),
1745 this, SLOT(toggleActiveView()));
1746 connect(view, SIGNAL(tabRequested(const KUrl&)),
1747 this, SLOT(openNewTab(const KUrl&)));
1748 connect(view, SIGNAL(requestContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)),
1749 this, SLOT(openContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)));
1750
1751 const KUrlNavigator* navigator = container->urlNavigator();
1752 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1753 this, SLOT(changeUrl(const KUrl&)));
1754 connect(navigator, SIGNAL(historyChanged()),
1755 this, SLOT(updateHistory()));
1756 connect(navigator, SIGNAL(editableStateChanged(bool)),
1757 this, SLOT(slotEditableStateChanged(bool)));
1758 connect(navigator, SIGNAL(tabRequested(const KUrl&)),
1759 this, SLOT(openNewTab(KUrl)));
1760 }
1761
1762 void DolphinMainWindow::updateSplitAction()
1763 {
1764 QAction* splitAction = actionCollection()->action("split_view");
1765 if (m_viewTab[m_tabIndex].secondaryView != 0) {
1766 if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
1767 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
1768 splitAction->setToolTip(i18nc("@info", "Close right view"));
1769 splitAction->setIcon(KIcon("view-right-close"));
1770 } else {
1771 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
1772 splitAction->setToolTip(i18nc("@info", "Close left view"));
1773 splitAction->setIcon(KIcon("view-left-close"));
1774 }
1775 } else {
1776 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
1777 splitAction->setToolTip(i18nc("@info", "Split view"));
1778 splitAction->setIcon(KIcon("view-right-new"));
1779 }
1780 }
1781
1782 QString DolphinMainWindow::tabName(const KUrl& url) const
1783 {
1784 QString name;
1785 if (url.equals(KUrl("file:///"))) {
1786 name = '/';
1787 } else {
1788 name = url.fileName();
1789 if (name.isEmpty()) {
1790 name = url.protocol();
1791 } else {
1792 // Make sure that a '&' inside the directory name is displayed correctly
1793 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1794 name.replace('&', "&&");
1795 }
1796 }
1797 return name;
1798 }
1799
1800 bool DolphinMainWindow::isKompareInstalled() const
1801 {
1802 static bool initialized = false;
1803 static bool installed = false;
1804 if (!initialized) {
1805 // TODO: maybe replace this approach later by using a menu
1806 // plugin like kdiff3plugin.cpp
1807 installed = !KGlobal::dirs()->findExe("kompare").isEmpty();
1808 initialized = true;
1809 }
1810 return installed;
1811 }
1812
1813 void DolphinMainWindow::createSecondaryView(int tabIndex)
1814 {
1815 QSplitter* splitter = m_viewTab[tabIndex].splitter;
1816 const int newWidth = (m_viewTab[tabIndex].primaryView->width() - splitter->handleWidth()) / 2;
1817
1818 const DolphinView* view = m_viewTab[tabIndex].primaryView->view();
1819 m_viewTab[tabIndex].secondaryView = new DolphinViewContainer(view->rootUrl(), 0);
1820 splitter->addWidget(m_viewTab[tabIndex].secondaryView);
1821 splitter->setSizes(QList<int>() << newWidth << newWidth);
1822 connectViewSignals(m_viewTab[tabIndex].secondaryView);
1823 m_viewTab[tabIndex].secondaryView->view()->reload();
1824 m_viewTab[tabIndex].secondaryView->setActive(false);
1825 m_viewTab[tabIndex].secondaryView->show();
1826 }
1827
1828 QString DolphinMainWindow::tabProperty(const QString& property, int tabIndex) const
1829 {
1830 return "Tab " + QString::number(tabIndex) + ' ' + property;
1831 }
1832
1833 void DolphinMainWindow::setUrlAsCaption(const KUrl& url)
1834 {
1835 delete m_captionStatJob;
1836 m_captionStatJob = 0;
1837
1838 if (url.protocol() == QLatin1String("file")) {
1839 QString caption;
1840 if (url.equals(KUrl("file:///"))) {
1841 caption = '/';
1842 } else {
1843 caption = url.fileName();
1844 if (caption.isEmpty()) {
1845 caption = url.protocol();
1846 }
1847 }
1848
1849 setCaption(caption);
1850 } else {
1851 m_captionStatJob = KIO::stat(url, KIO::HideProgressInfo);
1852 connect(m_captionStatJob, SIGNAL(result(KJob*)),
1853 this, SLOT(slotCaptionStatFinished(KJob*)));
1854 }
1855 }
1856
1857 QString DolphinMainWindow::squeezedText(const QString& text) const
1858 {
1859 const QFontMetrics fm = fontMetrics();
1860 return fm.elidedText(text, Qt::ElideMiddle, fm.maxWidth() * 10);
1861 }
1862
1863 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1864 KIO::FileUndoManager::UiInterface()
1865 {
1866 }
1867
1868 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1869 {
1870 }
1871
1872 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1873 {
1874 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
1875 if (mainWin) {
1876 DolphinStatusBar* statusBar = mainWin->activeViewContainer()->statusBar();
1877 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1878 } else {
1879 KIO::FileUndoManager::UiInterface::jobError(job);
1880 }
1881 }
1882
1883 #include "dolphinmainwindow.moc"