]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinrecenttabsmenu.cpp
1 /***************************************************************************
2 * Copyright (C) 2014 by Emmanuel Pescosta <emmanuelpescosta099@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "dolphinrecenttabsmenu.h"
22 #include <KLocalizedString>
23 #include <KAcceleratorManager>
24 #include <kio/global.h>
27 DolphinRecentTabsMenu::DolphinRecentTabsMenu(QObject
* parent
) :
28 KActionMenu(QIcon::fromTheme("edit-undo"), i18n("Recently Closed Tabs"), parent
)
33 m_clearListAction
= new QAction(i18n("Empty Recently Closed Tabs"), this);
34 m_clearListAction
->setIcon(QIcon::fromTheme("edit-clear-list"));
35 addAction(m_clearListAction
);
39 connect(menu(), SIGNAL(triggered(QAction
*)),
40 this, SLOT(handleAction(QAction
*)));
43 void DolphinRecentTabsMenu::rememberClosedTab(const KUrl
& url
, const QByteArray
& state
)
45 QAction
* action
= new QAction(menu());
46 action
->setText(url
.path());
47 action
->setData(state
);
48 const QString iconName
= KIO::iconNameForUrl(url
);
49 action
->setIcon(QIcon::fromTheme(iconName
));
51 // Add the closed tab menu entry after the separator and
52 // "Empty Recently Closed Tabs" entry
53 if (menu()->actions().size() == 2) {
56 insertAction(menu()->actions().at(2), action
);
58 emit
closedTabsCountChanged(menu()->actions().size() - 2);
59 // Assure that only up to 6 closed tabs are shown in the menu.
60 // 8 because of clear action + separator + 6 closed tabs
61 if (menu()->actions().size() > 8) {
62 removeAction(menu()->actions().last());
65 KAcceleratorManager::manage(menu());
68 void DolphinRecentTabsMenu::undoCloseTab()
70 Q_ASSERT(menu()->actions().size() > 2);
71 handleAction(menu()->actions().at(2));
74 void DolphinRecentTabsMenu::handleAction(QAction
* action
)
76 if (action
== m_clearListAction
) {
77 // Clear all actions except the "Empty Recently Closed Tabs"
78 // action and the separator
79 QList
<QAction
*> actions
= menu()->actions();
80 const int count
= actions
.size();
81 for (int i
= 2; i
< count
; ++i
) {
82 removeAction(actions
.at(i
));
84 emit
closedTabsCountChanged(0);
86 const QByteArray state
= action
->data().value
<QByteArray
>();
90 emit
restoreClosedTab(state
);
91 emit
closedTabsCountChanged(menu()->actions().size() - 2);
94 if (menu()->actions().count() <= 2) {