[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/workspace/plasma/applets/quicklaunch
From: Sujith Haridasan <sujith.h () gmail ! com>
Date: 2009-05-22 13:21:14
Message-ID: 1242998474.119384.16262.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 971446 by sujithh:
Added sort feature in quicklaunch applet.
M +69 -0 quicklaunchApplet.cpp
M +19 -0 quicklaunchApplet.h
M +5 -0 quicklaunchIcon.cpp
M +2 -0 quicklaunchIcon.h
--- trunk/KDE/kdebase/workspace/plasma/applets/quicklaunch/quicklaunchApplet.cpp \
#971445:971446 @@ -24,6 +24,7 @@
#include <QGraphicsSceneDragDropEvent>
#include <QGraphicsWidget>
#include <QDrag>
+#include <QHash>
#include <QMouseEvent>
#include <QMimeData>
#include <QToolButton>
@@ -33,6 +34,7 @@
#include <KStandardDirs>
#include <KWindowSystem>
#include <KIconLoader>
+#include <KUrl>
#include <plasma/containment.h>
#include <plasma/dialog.h>
@@ -45,6 +47,7 @@
static const int s_defaultIconSize = 16;
static const int s_defaultSpacing = 2;
+
QuicklaunchApplet::QuicklaunchApplet(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args),
m_layout(0),
@@ -58,6 +61,8 @@
m_dialogLayout(0),
m_addDialog(0),
m_rightClickedIcon(0),
+ m_sortappAscending(0),
+ m_sortappDescending(0),
m_addAction(0),
m_removeAction(0)
{
@@ -354,10 +359,74 @@
}
tempActions << m_removeAction;
}
+
+ if (!m_sortappAscending) {
+ m_sortappAscending = new QAction(KIcon("view-sort-ascending"), i18n("Sort \
Alphabetically (A to Z)"), this); + connect(m_sortappAscending, \
SIGNAL(triggered(bool)), this, SLOT(ascendingSort())); + }
+ tempActions << m_sortappAscending;
+ if (!m_sortappDescending) {
+ m_sortappDescending = new QAction(KIcon("view-sort-descending"), i18n("Sort \
Alphabetically (Z to A)"), this); + connect(m_sortappDescending, \
SIGNAL(triggered(bool)), this, SLOT(descendingSort())); + }
+ tempActions << m_sortappDescending;
+
return tempActions;
}
+void QuicklaunchApplet::ascendingSort()
+{
+ sortQuicklaunch(AscendingSort);
+}
+
+void QuicklaunchApplet::descendingSort()
+{
+ sortQuicklaunch(DescendingSort);
+}
+
+void QuicklaunchApplet::sortQuicklaunch(SortingOrder sortingorder)
+{
+ QHash <QString,QString> quicklaunchHash;
+ KUrl::List urls;
+ QList<QString> sortedList;
+ QList<QString> saveSortedUrlList;
+
+ foreach (QuicklaunchIcon *icon, m_icons) {
+ quicklaunchHash.insert(icon->appName(),icon->url().prettyUrl());
+ }
+ sortedList = quicklaunchHash.keys();
+
+ qSort(sortedList);
+
+ for (int i = 0; i < quicklaunchHash.size(); i++) {
+ saveSortedUrlList.append(quicklaunchHash.value(sortedList.value(i)));
+ }
+
+ if (sortingorder == DescendingSort) {
+ QList<QString> tempUrl;
+
+ for (int i = saveSortedUrlList.size(); i > 0; i--) {
+ tempUrl.append(saveSortedUrlList.takeLast());
+ }
+ saveSortedUrlList = tempUrl;
+ }
+
+ foreach (QuicklaunchIcon *icon, m_icons) {
+ m_icons.removeAll(icon);
+ icon->hide();
+ icon->deleteLater();
+ }
+
+ foreach (const QString &desktopFile, saveSortedUrlList) {
+ addProgram(-1, desktopFile);
+ }
+ performUiRefactor();
+
+ KConfigGroup cg = config();
+ cg.writeEntry("iconUrls", saveSortedUrlList);
+}
+
void QuicklaunchApplet::dropApp(QGraphicsSceneDragDropEvent *event, bool \
droppedOnDialog) {
int pos;
--- trunk/KDE/kdebase/workspace/plasma/applets/quicklaunch/quicklaunchApplet.h \
#971445:971446 @@ -64,6 +64,13 @@
* @return List of QAction pointers
*/
virtual QList<QAction*> contextActions(QuicklaunchIcon *icon = 0);
+ /**
+ * This enum is to know which sorting action has to be taken.
+ */
+ enum SortingOrder {
+ AscendingSort,
+ DescendingSort
+ };
public slots:
void createConfigurationInterface(KConfigDialog *parent);
@@ -71,7 +78,17 @@
* Slot for showing the Add Icon interface
*/
void showAddInterface();
+ /**
+ * Slot for sorting the applications in the quicklaunch
+ */
+ void ascendingSort();
+ void descendingSort();
+ /**
+ * Action of sorting is taken here.
+ */
+ void sortQuicklaunch(SortingOrder );
+
protected:
/**
* Overloaded method to save the state on exit
@@ -165,6 +182,8 @@
QAction* m_addAction;
QAction* m_removeAction;
+ QAction* m_sortappAscending;
+ QAction* m_sortappDescending;
};
#endif
--- trunk/KDE/kdebase/workspace/plasma/applets/quicklaunch/quicklaunchIcon.cpp \
#971445:971446 @@ -54,6 +54,11 @@
return m_appUrl;
}
+QString QuicklaunchIcon::appName()
+{
+ return m_text;
+}
+
void QuicklaunchIcon::setIconSize(int px)
{
m_iconSize = px;
--- trunk/KDE/kdebase/workspace/plasma/applets/quicklaunch/quicklaunchIcon.h \
#971445:971446 @@ -54,6 +54,8 @@
*/
KUrl url() const;
+ QString appName();
+
/**
* Set the size of the icon to be painted
* @param size the size in pxs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic