]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinrecenttabsmenu.cpp
DolphinView: Conform to global scroll speed
[dolphin.git] / src / dolphinrecenttabsmenu.cpp
index fa3eaf166d4db726b21c3c786e44d4825b7c04c1..d9b103c0cc0ae3d3bcbf2c433323556f335d916b 100644 (file)
@@ -1,52 +1,45 @@
-/***************************************************************************
- * Copyright (C) 2014 by Emmanuel Pescosta <emmanuelpescosta099@gmail.com> *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2014 Emmanuel Pescosta <emmanuelpescosta099@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
 
 #include "dolphinrecenttabsmenu.h"
+#include "search/dolphinquery.h"
 
-#include <KLocalizedString>
 #include <KAcceleratorManager>
-#include <KMimeType>
-#include <KMenu>
+#include <KLocalizedString>
+#include <kio/global.h>
 
-DolphinRecentTabsMenu::DolphinRecentTabsMenu(QObject* parent) :
-    KActionMenu(KIcon("edit-undo"), i18n("Recently Closed Tabs"), parent)
+#include <QMenu>
+#include <QUrlQuery>
+
+DolphinRecentTabsMenu::DolphinRecentTabsMenu(QObject *parent)
+    : KActionMenu(QIcon::fromTheme(QStringLiteral("edit-undo")), i18n("Recently Closed Tabs"), parent)
 {
-    setDelayed(false);
+    setPopupMode(QToolButton::InstantPopup);
     setEnabled(false);
 
     m_clearListAction = new QAction(i18n("Empty Recently Closed Tabs"), this);
-    m_clearListAction->setIcon(KIcon("edit-clear-list"));
+    m_clearListAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-clear-history")));
     addAction(m_clearListAction);
 
     addSeparator();
 
-    connect(menu(), SIGNAL(triggered(QAction*)),
-            this, SLOT(handleAction(QAction*)));
+    connect(menu(), &QMenu::triggered, this, &DolphinRecentTabsMenu::handleAction);
 }
 
-void DolphinRecentTabsMenu::rememberClosedTab(const KUrl& url, const QByteArray& state)
+void DolphinRecentTabsMenu::rememberClosedTab(const QUrl &url, const QByteArray &state)
 {
-    QAction* action = new QAction(menu());
-    action->setText(url.path());
+    QAction *action = new QAction(menu());
+    if (Search::isSupportedSearchScheme(url.scheme())) {
+        action->setText(Search::DolphinQuery{url, QUrl{}}.title());
+    } else {
+        action->setText(url.path());
+    }
     action->setData(state);
-    const QString iconName = KMimeType::iconNameForUrl(url);
-    action->setIcon(KIcon(iconName));
+    const QString iconName = KIO::iconNameForUrl(url);
+    action->setIcon(QIcon::fromTheme(iconName));
 
     // Add the closed tab menu entry after the separator and
     // "Empty Recently Closed Tabs" entry
@@ -55,7 +48,7 @@ void DolphinRecentTabsMenu::rememberClosedTab(const KUrl& url, const QByteArray&
     } else {
         insertAction(menu()->actions().at(2), action);
     }
-    emit closedTabsCountChanged(menu()->actions().size() - 2);
+    Q_EMIT closedTabsCountChanged(menu()->actions().size() - 2);
     // Assure that only up to 6 closed tabs are shown in the menu.
     // 8 because of clear action + separator + 6 closed tabs
     if (menu()->actions().size() > 8) {
@@ -71,27 +64,29 @@ void DolphinRecentTabsMenu::undoCloseTab()
     handleAction(menu()->actions().at(2));
 }
 
-void DolphinRecentTabsMenu::handleAction(QActionaction)
+void DolphinRecentTabsMenu::handleAction(QAction *action)
 {
     if (action == m_clearListAction) {
         // Clear all actions except the "Empty Recently Closed Tabs"
         // action and the separator
-        QList<QAction*> actions = menu()->actions();
+        QList<QAction *> actions = menu()->actions();
         const int count = actions.size();
-        for (int i = 2; i < count; ++i) {
+        for (int i = count - 1; i >= 2; i--) {
             removeAction(actions.at(i));
         }
-        emit closedTabsCountChanged(0);
+        Q_EMIT closedTabsCountChanged(0);
     } else {
-        const QByteArray state = action->data().value<QByteArray>();
+        const QByteArray state = action->data().toByteArray();
         removeAction(action);
         delete action;
-        action = 0;
-        emit restoreClosedTab(state);
-        emit closedTabsCountChanged(menu()->actions().size() - 2);
+        action = nullptr;
+        Q_EMIT restoreClosedTab(state);
+        Q_EMIT closedTabsCountChanged(menu()->actions().size() - 2);
     }
 
     if (menu()->actions().count() <= 2) {
         setEnabled(false);
     }
-}
\ No newline at end of file
+}
+
+#include "moc_dolphinrecenttabsmenu.cpp"