[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-06-24 20:01:58
Message-ID: 1245873718.569398.4748.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 986621 by sujithh:

Added ascending and descending sort for applications in quicklaunch applet.

 M  +68 -0     quicklaunchApplet.cpp  
 M  +18 -0     quicklaunchApplet.h  
 M  +5 -0      quicklaunchIcon.cpp  
 M  +2 -0      quicklaunchIcon.h  


--- trunk/KDE/kdebase/workspace/plasma/applets/quicklaunch/quicklaunchApplet.cpp \
#986620:986621 @@ -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>
@@ -59,6 +61,8 @@
     m_dialogLayout(0),
     m_addDialog(0),
     m_rightClickedIcon(0),
+    m_sortappAscending(0),
+    m_sortappDescending(0),
     m_addAction(0),
     m_removeAction(0)
 {
@@ -372,10 +376,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 = 0;
--- trunk/KDE/kdebase/workspace/plasma/applets/quicklaunch/quicklaunchApplet.h \
#986620:986621 @@ -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,6 +78,15 @@
          * 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:
         /**
@@ -166,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 \
#986620:986621 @@ -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 \
#986620:986621 @@ -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