]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinrecenttabsmenu.cpp
Merge branch 'master' of git.kde.org:dolphin
[dolphin.git] / src / dolphinrecenttabsmenu.cpp
index d0b694c03cd022c5c66f04e27ff7fca9453a2e48..c155632c6707c8f68593466bcc3606a1166f1552 100644 (file)
 
 #include <KLocalizedString>
 #include <KAcceleratorManager>
-#include <KMimeType>
-#include <KMenu>
+#include <kio/global.h>
+#include <QMenu>
 
 DolphinRecentTabsMenu::DolphinRecentTabsMenu(QObject* parent) :
-    KActionMenu(QIcon::fromTheme("edit-undo"), i18n("Recently Closed Tabs"), parent)
+    KActionMenu(QIcon::fromTheme(QStringLiteral("edit-undo")), i18n("Recently Closed Tabs"), parent)
 {
     setDelayed(false);
     setEnabled(false);
 
     m_clearListAction = new QAction(i18n("Empty Recently Closed Tabs"), this);
-    m_clearListAction->setIcon(QIcon::fromTheme("edit-clear-list"));
+    m_clearListAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-clear-list")));
     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& primaryUrl, const KUrl& secondaryUrl)
+void DolphinRecentTabsMenu::rememberClosedTab(const QUrl& url, const QByteArray& state)
 {
     QAction* action = new QAction(menu());
-    action->setText(primaryUrl.path());
-
-    const QString iconName = KMimeType::iconNameForUrl(primaryUrl);
+    action->setText(url.path());
+    action->setData(state);
+    const QString iconName = KIO::iconNameForUrl(url);
     action->setIcon(QIcon::fromTheme(iconName));
 
-    KUrl::List urls;
-    urls << primaryUrl;
-    urls << secondaryUrl;
-    action->setData(QVariant::fromValue(urls));
-
     // Add the closed tab menu entry after the separator and
     // "Empty Recently Closed Tabs" entry
     if (menu()->actions().size() == 2) {
@@ -60,7 +55,7 @@ void DolphinRecentTabsMenu::rememberClosedTab(const KUrl& primaryUrl, const KUrl
     } else {
         insertAction(menu()->actions().at(2), action);
     }
-
+    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) {
@@ -70,6 +65,12 @@ void DolphinRecentTabsMenu::rememberClosedTab(const KUrl& primaryUrl, const KUrl
     KAcceleratorManager::manage(menu());
 }
 
+void DolphinRecentTabsMenu::undoCloseTab()
+{
+    Q_ASSERT(menu()->actions().size() > 2);
+    handleAction(menu()->actions().at(2));
+}
+
 void DolphinRecentTabsMenu::handleAction(QAction* action)
 {
     if (action == m_clearListAction) {
@@ -80,17 +81,17 @@ void DolphinRecentTabsMenu::handleAction(QAction* action)
         for (int i = 2; i < count; ++i) {
             removeAction(actions.at(i));
         }
+        emit closedTabsCountChanged(0);
     } else {
-        const KUrl::List urls = action->data().value<KUrl::List>();
-        if (urls.count() == 2) {
-            emit restoreClosedTab(urls.first(), urls.last());
-        }
+        const QByteArray state = action->data().toByteArray();
         removeAction(action);
         delete action;
         action = 0;
+        emit restoreClosedTab(state);
+        emit closedTabsCountChanged(menu()->actions().size() - 2);
     }
 
     if (menu()->actions().count() <= 2) {
         setEnabled(false);
     }
-}
\ No newline at end of file
+}