#include <KProtocolInfo>
#include <QMenu>
#include <KMessageBox>
+#include <KFilePlacesModel>
#include <KFileItemListProperties>
#include <KRun>
#include <KShell>
m_settingsDialog(),
m_controlButton(0),
m_updateToolBarTimer(0),
- m_lastHandleUrlStatJob(0)
+ m_lastHandleUrlStatJob(0),
+#ifndef Q_OS_WIN
+ m_terminalPanel(0),
+#endif
+ m_placesPanel(0),
+ m_tearDownFromPlacesRequested(false)
{
Q_INIT_RESOURCE(dolphin);
void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl& url)
{
+ if (m_tearDownFromPlacesRequested && url == QUrl::fromLocalFile(QDir::homePath())) {
+ m_placesPanel->proceedWithTearDown();
+ m_tearDownFromPlacesRequested = false;
+ }
+
m_activeViewContainer->setAutoGrabFocus(false);
changeUrl(url);
m_activeViewContainer->setAutoGrabFocus(true);
void DolphinMainWindow::setUrlAsCaption(const QUrl& url)
{
- QString caption;
+ static KFilePlacesModel s_placesModel;
+
+ QString schemePrefix;
if (!url.isLocalFile()) {
- caption.append(url.scheme() + " - ");
+ schemePrefix.append(url.scheme() + " - ");
if (!url.host().isEmpty()) {
- caption.append(url.host() + " - ");
+ schemePrefix.append(url.host() + " - ");
}
}
if (GeneralSettings::showFullPathInTitlebar()) {
const QString path = url.adjusted(QUrl::StripTrailingSlash).path();
- caption.append(path);
+ setWindowTitle(schemePrefix + path);
+ return;
+ }
+
+ const auto& matchedPlaces = s_placesModel.match(s_placesModel.index(0,0), KFilePlacesModel::UrlRole, url, 1, Qt::MatchExactly);
+
+ if (!matchedPlaces.isEmpty()) {
+ setWindowTitle(s_placesModel.text(matchedPlaces.first()));
+ return;
+ }
+
+ QString fileName = url.adjusted(QUrl::StripTrailingSlash).fileName();
+ if (fileName.isEmpty()) {
+ fileName = '/';
+ }
+
+ setWindowTitle(schemePrefix + fileName);
+}
+
+void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath)
+{
+#ifndef Q_OS_WIN
+ if (m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
+ m_tearDownFromPlacesRequested = true;
+ m_terminalPanel->goHome();
+ // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
} else {
- QString fileName = url.adjusted(QUrl::StripTrailingSlash).fileName();
- if (fileName.isEmpty()) {
- fileName = '/';
- }
- caption.append(fileName);
+ m_placesPanel->proceedWithTearDown();
}
+#endif
+}
- setWindowTitle(caption);
+void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString& mountPath)
+{
+#ifndef Q_OS_WIN
+ if (m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
+ m_tearDownFromPlacesRequested = false;
+ m_terminalPanel->goHome();
+ }
+#endif
}
void DolphinMainWindow::setupActions()
closeTab->setEnabled(false);
connect(closeTab, &QAction::triggered, m_tabWidget, static_cast<void(DolphinTabWidget::*)()>(&DolphinTabWidget::closeTab));
- KStandardAction::quit(this, SLOT(quit()), actionCollection());
+ KStandardAction::quit(this, &DolphinMainWindow::quit, actionCollection());
// setup 'Edit' menu
KStandardAction::undo(this,
- SLOT(undo()),
+ &DolphinMainWindow::undo,
actionCollection());
- KStandardAction::cut(this, SLOT(cut()), actionCollection());
- KStandardAction::copy(this, SLOT(copy()), actionCollection());
- QAction* paste = KStandardAction::paste(this, SLOT(paste()), actionCollection());
+ KStandardAction::cut(this, &DolphinMainWindow::cut, actionCollection());
+ KStandardAction::copy(this, &DolphinMainWindow::copy, actionCollection());
+ QAction* paste = KStandardAction::paste(this, &DolphinMainWindow::paste, actionCollection());
// The text of the paste-action is modified dynamically by Dolphin
// (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
// due to the long text, the text "Paste" is used:
paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
- KStandardAction::find(this, SLOT(find()), actionCollection());
+ KStandardAction::find(this, &DolphinMainWindow::find, actionCollection());
QAction* selectAll = actionCollection()->addAction(QStringLiteral("select_all"));
selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
actionCollection()->setDefaultShortcut(stashSplit, Qt::CTRL | Qt::Key_S);
stashSplit->setText(i18nc("@action:intoolbar Stash", "Stash"));
stashSplit->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
- stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-visiting")));
+ stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
stashSplit->setCheckable(false);
stashSplit->setVisible(KProtocolInfo::isKnownProtocol("stash"));
connect(stashSplit, &QAction::triggered, this, &DolphinMainWindow::toggleSplitStash);
connect(replaceLocation, &QAction::triggered, this, &DolphinMainWindow::replaceLocation);
// setup 'Go' menu
- QAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
+ QAction* backAction = KStandardAction::back(this, &DolphinMainWindow::goBack, actionCollection());
auto backShortcuts = backAction->shortcuts();
backShortcuts.append(QKeySequence(Qt::Key_Backspace));
actionCollection()->setDefaultShortcuts(backAction, backShortcuts);
auto undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
undoAction->setEnabled(false); // undo should be disabled by default
- KStandardAction::forward(this, SLOT(goForward()), actionCollection());
- KStandardAction::up(this, SLOT(goUp()), actionCollection());
- KStandardAction::home(this, SLOT(goHome()), actionCollection());
+ KStandardAction::forward(this, &DolphinMainWindow::goForward, actionCollection());
+ KStandardAction::up(this, &DolphinMainWindow::goUp, actionCollection());
+ KStandardAction::home(this, &DolphinMainWindow::goHome, actionCollection());
// setup 'Tools' menu
QAction* showFilterBar = actionCollection()->addAction(QStringLiteral("show_filter_bar"));
terminalDock->setLocked(lock);
terminalDock->setObjectName(QStringLiteral("terminalDock"));
terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
- TerminalPanel* terminalPanel = new TerminalPanel(terminalDock);
- terminalPanel->setCustomContextMenuActions({lockLayoutAction});
- terminalDock->setWidget(terminalPanel);
+ m_terminalPanel = new TerminalPanel(terminalDock);
+ m_terminalPanel->setCustomContextMenuActions({lockLayoutAction});
+ terminalDock->setWidget(m_terminalPanel);
- connect(terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide);
- connect(terminalPanel, &TerminalPanel::changeUrl, this, &DolphinMainWindow::slotTerminalDirectoryChanged);
+ connect(m_terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide);
+ connect(m_terminalPanel, &TerminalPanel::changeUrl, this, &DolphinMainWindow::slotTerminalDirectoryChanged);
connect(terminalDock, &DolphinDockWidget::visibilityChanged,
- terminalPanel, &TerminalPanel::dockVisibilityChanged);
+ m_terminalPanel, &TerminalPanel::dockVisibilityChanged);
QAction* terminalAction = terminalDock->toggleViewAction();
createPanelAction(QIcon::fromTheme(QStringLiteral("utilities-terminal")), Qt::Key_F4, terminalAction, QStringLiteral("show_terminal_panel"));
addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
connect(this, &DolphinMainWindow::urlChanged,
- terminalPanel, &TerminalPanel::setUrl);
+ m_terminalPanel, &TerminalPanel::setUrl);
if (GeneralSettings::version() < 200) {
terminalDock->hide();
placesDock->setObjectName(QStringLiteral("placesDock"));
placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
- PlacesPanel* placesPanel = new PlacesPanel(placesDock);
- placesPanel->setCustomContextMenuActions({lockLayoutAction});
- placesDock->setWidget(placesPanel);
+ m_placesPanel = new PlacesPanel(placesDock);
+ m_placesPanel->setCustomContextMenuActions({lockLayoutAction});
+ placesDock->setWidget(m_placesPanel);
- QAction* placesAction = placesDock->toggleViewAction();
+ QAction *placesAction = placesDock->toggleViewAction();
createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9, placesAction, QStringLiteral("show_places_panel"));
addDockWidget(Qt::LeftDockWidgetArea, placesDock);
- connect(placesPanel, &PlacesPanel::placeActivated,
+ connect(m_placesPanel, &PlacesPanel::placeActivated,
this, &DolphinMainWindow::slotPlaceActivated);
- connect(placesPanel, &PlacesPanel::placeMiddleClicked,
+ connect(m_placesPanel, &PlacesPanel::placeMiddleClicked,
this, &DolphinMainWindow::openNewTab);
- connect(placesPanel, &PlacesPanel::errorMessage,
+ connect(m_placesPanel, &PlacesPanel::errorMessage,
this, &DolphinMainWindow::showErrorMessage);
connect(this, &DolphinMainWindow::urlChanged,
- placesPanel, &PlacesPanel::setUrl);
+ m_placesPanel, &PlacesPanel::setUrl);
connect(placesDock, &DolphinDockWidget::visibilityChanged,
m_tabWidget, &DolphinTabWidget::slotPlacesPanelVisibilityChanged);
connect(this, &DolphinMainWindow::settingsChanged,
- placesPanel, &PlacesPanel::readSettings);
-
- m_tabWidget->slotPlacesPanelVisibilityChanged(placesPanel->isVisible());
+ m_placesPanel, &PlacesPanel::readSettings);
+ connect(m_placesPanel, &PlacesPanel::storageTearDownRequested,
+ this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested);
+ connect(m_placesPanel, &PlacesPanel::storageTearDownExternallyRequested,
+ this, &DolphinMainWindow::slotStorageTearDownExternallyRequested);
+ m_tabWidget->slotPlacesPanelVisibilityChanged(m_placesPanel->isVisible());
// Add actions into the "Panels" menu
KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);