Classic KMenu Extension
Cyberbeat
cyberbeat at gmx.de
Wed Jan 7 19:27:22 CET 2009
Hi,
I made modifications to the classic-kmenu-applet:
- configuration-option: if it should show recent applications on top of
standard-menu-view
- configuration-option: how many recent applications should be stored. I use
the "recentapplications" class for that. I am not shure, if this is the right
place to show this configuration-option, because it should be duplicated in
kickoff-modern-menu-configuration-interface. but I see no alternative.
- the recent applications are shown on top, if this feature is activated. I
reduced a copy of recentlyusedmodel to applications for this: a new
class "recentlyusedapplicationsmodel".
I send a svn-diff for an overview of the changes to existing files. And an
archive with all modified/new files. I will be happy if I get
feedback/suggestions. This is my first qt/kde-programming-experience :)
-------------- next part --------------
Index: simpleapplet/menuview.cpp
===================================================================
--- simpleapplet/menuview.cpp (Revision 903067)
+++ simpleapplet/menuview.cpp (Arbeitskopie)
@@ -26,7 +26,7 @@
#include <QtCore/QStack>
#include <QtGui/QApplication>
#include <QtGui/QMouseEvent>
-#include <QPersistentModelIndex>
+#include <QtCore/QPersistentModelIndex>
// KDE
#include <KDebug>
Index: simpleapplet/simpleapplet.cpp
===================================================================
--- simpleapplet/simpleapplet.cpp (Revision 903067)
+++ simpleapplet/simpleapplet.cpp (Arbeitskopie)
@@ -23,14 +23,16 @@
#include "simpleapplet/menuview.h"
// Qt
-#include <QLabel>
-#include <QComboBox>
-#include <QGridLayout>
-#include <QGraphicsView>
-#include <QMetaObject>
-#include <QMetaEnum>
-#include <QPointer>
-#include <QGraphicsLinearLayout>
+#include <QtGui/QLabel>
+#include <QtGui/QComboBox>
+#include <QtGui/QSpinBox>
+#include <QtGui/QCheckBox>
+#include <QtGui/QGridLayout>
+#include <QtGui/QGraphicsView>
+#include <QtCore/QMetaObject>
+#include <QtCore/QMetaEnum>
+#include <QtCore/QPointer>
+#include <QtGui/QGraphicsLinearLayout>
// KDE
#include <KIcon>
@@ -52,6 +54,8 @@
#include "core/favoritesmodel.h"
#include "core/systemmodel.h"
#include "core/recentlyusedmodel.h"
+#include "core/recentapplications.h"
+#include "core/recentlyusedapplicationsmodel.h"
#include "core/leavemodel.h"
#include "core/urlitemlauncher.h"
@@ -84,9 +88,12 @@
MenuLauncherApplet::ViewType viewtype;
MenuLauncherApplet::FormatType formattype;
+ bool showRecentApplications;
QComboBox *viewComboBox;
QComboBox *formatComboBox;
+ QCheckBox *showRecentCheckBox;
+ QSpinBox *recentApplicationsSpinBox;
QList<QAction*> actions;
QAction* switcher;
@@ -204,6 +211,7 @@
d->viewtype = Combined;
d->formattype = NameDescription;
+ d->showRecentApplications = true;
}
MenuLauncherApplet::~MenuLauncherApplet()
@@ -232,6 +240,8 @@
d->formattype = (MenuLauncherApplet::FormatType) e.keyToValue(ba);
}
+ d->showRecentApplications = cg.readEntry("showRecentApplications", d->showRecentApplications);
+
d->icon->setIcon(KIcon(d->viewIcon()));
//d->icon->setIcon(KIcon(cg.readEntry("icon","start-here-kde")));
//setMinimumContentSize(d->icon->iconSize()); //setSize(d->icon->iconSize())
@@ -316,6 +326,24 @@
d->addItem(d->formatComboBox, i18nc("@item:inlistbox Format:", "Name - Description"), MenuLauncherApplet::NameDashDescription);
l->addWidget(d->formatComboBox, 1, 1);
+ QLabel *showRecentLabel = new QLabel(i18n("Recent applications:"), p);
+ l->addWidget(showRecentLabel, 2, 0);
+ d->showRecentCheckBox = new QCheckBox(i18n("Show on top of standard menu"),p);
+ d->showRecentCheckBox->setChecked(d->showRecentApplications);
+ showRecentLabel->setBuddy(d->showRecentCheckBox);
+ l->addWidget(d->showRecentCheckBox, 2, 1);
+
+ QLabel *recentLabel = new QLabel(i18n("Recent applications:"), p);
+ l->addWidget(recentLabel, 3, 0);
+ d->recentApplicationsSpinBox = new QSpinBox(p);
+ d->recentApplicationsSpinBox->setMaximum(10);
+ d->recentApplicationsSpinBox->setMinimum(0);
+ d->recentApplicationsSpinBox->setValue(Kickoff::RecentApplications::self()->maximum());
+ recentLabel->setBuddy(d->recentApplicationsSpinBox);
+ l->addWidget(d->recentApplicationsSpinBox, 3, 1);
+
+
+
l->setColumnStretch(1, 1);
d->setCurrentItem(d->viewComboBox, d->viewtype);
@@ -352,6 +380,15 @@
cg.writeEntry("format", QByteArray(e.valueToKey(d->formattype)));
}
+ if (d->showRecentCheckBox->isChecked() != d->showRecentApplications) {
+ d->showRecentApplications = d->showRecentCheckBox->isChecked();
+ needssaving = true;
+
+ cg.writeEntry("showRecentApplications",d->showRecentApplications );
+ }
+
+ Kickoff::RecentApplications::self()->setMaximum(d->recentApplicationsSpinBox->value());
+
if (needssaving) {
emit configNeedsSaving();
@@ -377,16 +414,25 @@
switch (d->viewtype) {
case Combined: {
+
+ if (d->showRecentApplications){
+ Kickoff::MenuView *recentlyview = d->createMenuView(new Kickoff::RecentlyUsedApplicationsModel(d->menuview));
+ d->addMenu(recentlyview, true);
+ d->menuview->addSeparator();
+ }
Kickoff::ApplicationModel *appModel = new Kickoff::ApplicationModel(d->menuview);
appModel->setDuplicatePolicy(Kickoff::ApplicationModel::ShowLatestOnlyPolicy);
appModel->setSystemApplicationPolicy(Kickoff::ApplicationModel::ShowApplicationAndSystemPolicy);
Kickoff::MenuView *appview = d->createMenuView(appModel);
d->addMenu(appview, false);
- d->menuview->addSeparator();
+
+ d->menuview->addSeparator();
Kickoff::MenuView *favview = d->createMenuView(new Kickoff::FavoritesModel(d->menuview));
d->addMenu(favview, false);
+
+
d->menuview->addSeparator();
QAction *switchaction = d->menuview->addAction(KIcon("system-switch-user"), i18n("Switch User"));
switchaction->setData(KUrl("leave:/switch"));
Index: simpleapplet/menuview.h
===================================================================
--- simpleapplet/menuview.h (Revision 903067)
+++ simpleapplet/menuview.h (Arbeitskopie)
@@ -22,7 +22,7 @@
#define MENUVIEW_H
// Qt
-#include <QModelIndex>
+#include <QtCore/QModelIndex>
// KDE
#include <KMenu>
Index: core/org.kde.kickoff.recent.xml
===================================================================
--- core/org.kde.kickoff.recent.xml (Revision 903067)
+++ core/org.kde.kickoff.recent.xml (Arbeitskopie)
@@ -2,6 +2,6 @@
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kde.kickoff.recent">
- <signal name="cleanRecentDocumentsAndDocuments"/>
+ <signal name="clearRecentDocumentsAndApplications"/>
</interface>
</node>
Index: core/recentapplications.cpp
===================================================================
--- core/recentapplications.cpp (Revision 903067)
+++ core/recentapplications.cpp (Arbeitskopie)
@@ -21,8 +21,8 @@
#include "core/recentapplications.h"
// Qt
-#include <QHash>
-#include <QLinkedList>
+#include <QtCore/QHash>
+#include <QtCore/QLinkedList>
// KDE
#include <KConfigGroup>
@@ -101,7 +101,7 @@
emit instance.applicationRemoved(KService::serviceByStorageId(removeId));
}
}
-
+
class ServiceInfo
{
public:
@@ -160,8 +160,14 @@
}
void RecentApplications::setMaximum(int maximum)
{
- Q_ASSERT(maximum > 0);
+ Q_ASSERT(maximum >= 0);
privateSelf->maxServices = maximum;
+ while (privateSelf->serviceQueue.count() > privateSelf->maxServices) {
+ QString removeId = privateSelf->serviceQueue.takeFirst();
+ kDebug() << "More than max services added. Removing" << removeId << "from queue.";
+ privateSelf->serviceInfo.remove(removeId);
+ emit applicationRemoved(KService::serviceByStorageId(removeId));
+ }
}
int RecentApplications::maximum() const
{
Index: core/recentlyusedmodel.cpp
===================================================================
--- core/recentlyusedmodel.cpp (Revision 903067)
+++ core/recentlyusedmodel.cpp (Arbeitskopie)
@@ -120,7 +120,7 @@
QDBusConnection dbus = QDBusConnection::sessionBus();
(void)new RecentAdaptor(this);
QDBusConnection::sessionBus().registerObject("/kickoff/RecentAppDoc", this);
- dbus.connect(QString(), "/kickoff/RecentAppDoc", "org.kde.plasma", "cleanRecentDocumentsAndDocuments", this, SLOT(clearRecentDocumentsAndApplications()));
+ dbus.connect(QString(), "/kickoff/RecentAppDoc", "org.kde.plasma", "clearRecentDocumentsAndApplications", this, SLOT(clearRecentDocumentsAndApplications()));
d->loadRecentApplications();
d->loadRecentDocuments();
Index: ui/launcher.cpp
===================================================================
--- ui/launcher.cpp (Revision 903067)
+++ ui/launcher.cpp (Arbeitskopie)
@@ -169,11 +169,11 @@
view->setItemStateProvider(delegate);
addView(i18n("Favorites"), KIcon("bookmarks"), model, view);
- QAction *sortAscendingAction = new QAction(KIcon("view-sort-ascending"),
+ QAction *sortAscendingAction = new QAction(KIcon("view-sort-ascending"),
i18n("Sort Alphabetically (A to Z)"), q);
- QAction *sortDescendingAction = new QAction(KIcon("view-sort-descending"),
- i18n("Sort Alphabetically (Z to A)"), q);
+ QAction *sortDescendingAction = new QAction(KIcon("view-sort-descending"),
+ i18n("Sort Alphabetically (Z to A)"), q);
connect(model, SIGNAL(rowsInserted(QModelIndex, int, int)), q, SLOT(focusFavoritesView()));
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt (Revision 903067)
+++ CMakeLists.txt (Arbeitskopie)
@@ -14,6 +14,7 @@
core/models.cpp
core/recentapplications.cpp
core/recentlyusedmodel.cpp
+ core/recentlyusedapplicationsmodel.cpp
core/searchmodel.cpp
core/systemmodel.cpp
core/urlitemlauncher.cpp
@@ -28,6 +29,7 @@
ui/tabbar.cpp
ui/urlitemview.cpp )
qt4_add_dbus_adaptor(Kickoff_SRCS core/org.kde.kickoff.xml core/applicationmodel.h Kickoff::ApplicationModel)
+qt4_add_dbus_adaptor(Kickoff_SRCS core/org.kde.kickoff.recentapp.xml core/recentlyusedapplicationsmodel.h Kickoff::RecentlyUsedApplicationsModel)
qt4_add_dbus_adaptor(Kickoff_SRCS core/org.kde.kickoff.recent.xml core/recentlyusedmodel.h Kickoff::RecentlyUsedModel)
set(screensaver_xml ${KDEBASE_WORKSPACE_SOURCE_DIR}/krunner/dbus/org.freedesktop.ScreenSaver.xml)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Archiv.tar.gz
Type: application/x-tgz
Size: 66624 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/plasma-devel/attachments/20090107/a8d4aeac/attachment-0001.bin
More information about the Plasma-devel
mailing list