Lukas Appelhans 写道:
Am Freitag 14 August 2009 11:10:42 schrieb 潘卫平(Peter Pan):
Hi,all

I think we should give user a hint when he/she adds a application which
already exists in quicklaunch, so I made this patch.


Regards
Hey!

Good thing! But 2 things: I'm not 100% into the code currently, but why not implementing the loop inside addProgram()?

In the beginning, I want to quit as soon as possible, to save CPU cycles.
But I agree that addProgram() is a more elegant place, but we should pay attention to initializing and sorting.

And the second one: "Cancel or Continue?" is not needed as words inside the MessageBox imo, as the buttons are named like it... "\"%1\" is already in quicklaunch!" should be enough!


agree with you.
And I modify my patch.

Regards,

Lukas
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


--
潘卫平(Peter Pan)
Red Flag Software Co., Ltd
Index: quicklaunchApplet.h
===================================================================
--- quicklaunchApplet.h	(revision 1010790)
+++ quicklaunchApplet.h	(working copy)
@@ -178,6 +178,8 @@
         Ui::quicklaunchAdd addUi;
         QuicklaunchIcon *m_rightClickedIcon;
         QPointF m_mousePressPos;
+        bool m_isInitializing;
+        bool m_isSorting;
 
         QAction* m_addAction;
         QAction* m_removeAction;
Index: quicklaunchApplet.cpp
===================================================================
--- quicklaunchApplet.cpp	(revision 1010790)
+++ quicklaunchApplet.cpp	(working copy)
@@ -21,6 +21,7 @@
 
 #include <KConfigDialog>
 #include <KDesktopFile>
+#include <KMessageBox>
 #include <QGraphicsSceneDragDropEvent>
 #include <QGraphicsWidget>
 #include <QDrag>
@@ -61,7 +62,9 @@
     m_addAction(0),
     m_removeAction(0),
     m_sortappAscending(0),
-    m_sortappDescending(0)
+    m_sortappDescending(0),
+    m_isInitializing(false),
+    m_isSorting(false)
 {
     setHasConfigurationInterface(true);
     setAcceptDrops(true);
@@ -97,6 +100,7 @@
 
 void QuicklaunchApplet::init()
 {
+    m_isInitializing = true;
     KConfigGroup cg = config();
     m_preferredIconSize = m_iconSize = qMax(s_defaultIconSize, (int)cg.readEntry("iconSize", contentsRect().height() / 2));
     m_visibleIcons = qMax(-1, cg.readEntry("visibleIcons", m_visibleIcons));
@@ -148,6 +152,8 @@
     if (firstStart) {
         resize(sizeHint(Qt::PreferredSize));
     }
+
+    m_isInitializing = false;
 }
 
 QSizeF QuicklaunchApplet::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
@@ -396,12 +402,16 @@
 
 void QuicklaunchApplet::ascendingSort() 
 {
+    m_isSorting = true;
     sortQuicklaunch(AscendingSort);
+    m_isSorting = false;
 }
 
 void QuicklaunchApplet::descendingSort()
 {
+    m_isSorting = true;
     sortQuicklaunch(DescendingSort);
+    m_isSorting = false;
 }
 
 void QuicklaunchApplet::sortQuicklaunch(SortingOrder sortingorder)
@@ -601,7 +611,29 @@
     KIcon icon;
     QString text;
     QString genericName;
+    bool do_add_program = true;
 
+    if (!m_isInitializing &&  !m_isSorting) {
+        foreach (QuicklaunchIcon *icon, m_icons) {
+            if (icon->url().url() == appUrl.url()) {
+                if (KMessageBox::warningContinueCancel(
+                        0, 
+                        i18n("\"%1\" is already in quicklaunch!", icon->url().pathOrUrl()), 
+                        i18n("Warning") 
+                    ) == KMessageBox::Cancel) {
+                    do_add_program = false;
+                    break;
+                } else {
+                    break;
+                }
+            }
+        }
+    }
+
+    if (!do_add_program) {
+        return;
+    }
+
     if (appUrl.isLocalFile() && KDesktopFile::isDesktopFile(appUrl.toLocalFile())) {
         KDesktopFile *f = new KDesktopFile(appUrl.toLocalFile());
 
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel

Reply via email to