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