+}
+
+void DolphinMainWindow::toggleShowMenuBar()
+{
+ const bool visible = menuBar()->isVisible();
+ menuBar()->setVisible(!visible);
+ if (visible) {
+ createToolBarMenuButton();
+ } else {
+ deleteToolBarMenuButton();
+ }
+}
+
+void DolphinMainWindow::openTerminal()
+{
+ QString dir(QDir::homePath());
+
+ // If the given directory is not local, it can still be the URL of an
+ // ioslave using UDS_LOCAL_PATH which to be converted first.
+ KUrl url = KIO::NetAccess::mostLocalUrl(m_activeViewContainer->url(), this);
+
+ //If the URL is local after the above conversion, set the directory.
+ if (url.isLocalFile()) {
+ dir = url.toLocalFile();
+ }
+
+ KToolInvocation::invokeTerminal(QString(), dir);
+}
+
+void DolphinMainWindow::editSettings()
+{
+ if (!m_settingsDialog) {
+ const KUrl url = activeViewContainer()->url();
+ DolphinSettingsDialog* settingsDialog = new DolphinSettingsDialog(url, this);
+ connect(settingsDialog, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
+ settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
+ settingsDialog->show();
+ m_settingsDialog = settingsDialog;
+ } else {
+ m_settingsDialog.data()->raise();
+ }
+}
+
+void DolphinMainWindow::setActiveTab(int index)
+{
+ Q_ASSERT(index >= 0);
+ Q_ASSERT(index < m_viewTab.count());
+ if (index == m_tabIndex) {
+ return;
+ }
+
+ // hide current tab content
+ ViewTab& hiddenTab = m_viewTab[m_tabIndex];
+ hiddenTab.isPrimaryViewActive = hiddenTab.primaryView->isActive();
+ hiddenTab.primaryView->setActive(false);
+ if (hiddenTab.secondaryView) {
+ hiddenTab.secondaryView->setActive(false);
+ }
+ QSplitter* splitter = m_viewTab[m_tabIndex].splitter;
+ splitter->hide();
+ m_centralWidgetLayout->removeWidget(splitter);
+
+ // show active tab content
+ m_tabIndex = index;
+
+ ViewTab& viewTab = m_viewTab[index];
+ m_centralWidgetLayout->addWidget(viewTab.splitter, 1);
+ viewTab.primaryView->show();
+ if (viewTab.secondaryView) {
+ viewTab.secondaryView->show();
+ }
+ viewTab.splitter->show();
+
+ if (!viewTab.wasActive) {
+ viewTab.wasActive = true;
+
+ // If the tab has not been activated yet the size of the KItemListView is
+ // undefined and results in an unwanted animation. To prevent this a
+ // reloading of the directory gets triggered.
+ viewTab.primaryView->view()->reload();
+ if (viewTab.secondaryView) {
+ viewTab.secondaryView->view()->reload();
+ }
+ }
+
+ setActiveViewContainer(viewTab.isPrimaryViewActive ? viewTab.primaryView :
+ viewTab.secondaryView);
+}
+
+void DolphinMainWindow::closeTab()
+{
+ closeTab(m_tabBar->currentIndex());
+}
+
+void DolphinMainWindow::closeTab(int index)
+{
+ Q_ASSERT(index >= 0);
+ Q_ASSERT(index < m_viewTab.count());
+ if (m_viewTab.count() == 1) {
+ // the last tab may never get closed
+ return;
+ }
+
+ if (index == m_tabIndex) {
+ // The tab that should be closed is the active tab. Activate the
+ // previous tab before closing the tab.
+ m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1);
+ }
+ rememberClosedTab(index);
+
+ // delete tab
+ m_viewTab[index].primaryView->deleteLater();
+ if (m_viewTab[index].secondaryView) {
+ m_viewTab[index].secondaryView->deleteLater();
+ }
+ m_viewTab[index].splitter->deleteLater();
+ m_viewTab.erase(m_viewTab.begin() + index);
+
+ m_tabBar->blockSignals(true);
+ m_tabBar->removeTab(index);
+
+ if (m_tabIndex > index) {
+ m_tabIndex--;
+ Q_ASSERT(m_tabIndex >= 0);
+ }
+
+ // if only one tab is left, also remove the tab entry so that
+ // closing the last tab is not possible
+ if (m_viewTab.count() == 1) {
+ m_tabBar->removeTab(0);
+ actionCollection()->action("close_tab")->setEnabled(false);
+ } else {
+ m_tabBar->blockSignals(false);
+ }
+}
+
+void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos)
+{
+ KMenu menu(this);
+
+ QAction* newTabAction = menu.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
+ newTabAction->setShortcut(actionCollection()->action("new_tab")->shortcut());
+
+ QAction* detachTabAction = menu.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
+
+ QAction* closeOtherTabsAction = menu.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
+
+ QAction* closeTabAction = menu.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
+ closeTabAction->setShortcut(actionCollection()->action("close_tab")->shortcut());
+ QAction* selectedAction = menu.exec(pos);
+ if (selectedAction == newTabAction) {
+ const ViewTab& tab = m_viewTab[index];
+ Q_ASSERT(tab.primaryView);
+ const KUrl url = tab.secondaryView && tab.secondaryView->isActive() ?
+ tab.secondaryView->url() : tab.primaryView->url();
+ openNewTab(url);
+ m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
+ } else if (selectedAction == detachTabAction) {
+ const QString separator(QLatin1Char(' '));
+ QString command = QLatin1String("dolphin");
+
+ const ViewTab& tab = m_viewTab[index];
+ Q_ASSERT(tab.primaryView);
+
+ command += separator + tab.primaryView->url().url();
+ if (tab.secondaryView) {
+ command += separator + tab.secondaryView->url().url();
+ command += separator + QLatin1String("-split");
+ }
+
+ KRun::runCommand(command, this);
+
+ closeTab(index);
+ } else if (selectedAction == closeOtherTabsAction) {
+ const int count = m_tabBar->count();
+ for (int i = 0; i < index; ++i) {
+ closeTab(0);
+ }
+ for (int i = index + 1; i < count; ++i) {
+ closeTab(1);
+ }
+ } else if (selectedAction == closeTabAction) {
+ closeTab(index);
+ }
+}
+
+void DolphinMainWindow::slotTabMoved(int from, int to)
+{
+ m_viewTab.move(from, to);
+ m_tabIndex = m_tabBar->currentIndex();
+}
+
+void DolphinMainWindow::handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons)
+{
+ if (buttons & Qt::MidButton) {
+ openNewTab(url);
+ m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
+ } else {
+ changeUrl(url);
+ }
+}
+
+void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& canDecode)
+{
+ canDecode = KUrl::List::canDecode(event->mimeData());
+}
+
+void DolphinMainWindow::handleUrl(const KUrl& url)
+{
+ delete m_lastHandleUrlStatJob;
+ m_lastHandleUrlStatJob = 0;
+
+ if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
+ activeViewContainer()->setUrl(url);
+ } else if (KProtocolManager::supportsListing(url)) {
+ // stat the URL to see if it is a dir or not
+ m_lastHandleUrlStatJob = KIO::stat(url, KIO::HideProgressInfo);
+ connect(m_lastHandleUrlStatJob, SIGNAL(result(KJob*)),
+ this, SLOT(slotHandleUrlStatFinished(KJob*)));
+
+ } else {
+ new KRun(url, this);
+ }
+}
+
+void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job)
+{
+ m_lastHandleUrlStatJob = 0;
+ const KIO::UDSEntry entry = static_cast<KIO::StatJob*>(job)->statResult();
+ const KUrl url = static_cast<KIO::StatJob*>(job)->url();
+ if (entry.isDir()) {
+ activeViewContainer()->setUrl(url);
+ } else {
+ new KRun(url, this);
+ }
+}