[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdeplasma-addons/applets/timer
From:       Laurent Montel <montel () kde ! org>
Date:       2008-08-14 7:23:49
Message-ID: 1218698629.268529.25438.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 846796 by mlaurent:

don't regenerate menu each time that we right click and fix mem leak


 M  +32 -27    timer.cpp  
 M  +4 -2      timer.h  


--- trunk/KDE/kdeplasma-addons/applets/timer/timer.cpp #846795:846796
@@ -84,8 +84,38 @@
     m_resetAction = new QAction(i18n("Reset"), this);
     m_resetAction->setEnabled(false);
     connect(m_resetAction, SIGNAL(triggered(bool)), this, SLOT(resetTimer()));
+    createMenuAction();
 }
 
+void Timer::createMenuAction()
+{
+    //necessary when we change predefined timer in config dialogbox
+    actions.clear();
+    qDeleteAll( actions );
+    actions.append(m_startAction);
+    actions.append(m_stopAction);
+    actions.append(m_resetAction);
+
+    QAction *separator0 = new QAction(this);
+    separator0->setSeparator(true);
+    actions.append(separator0);
+
+    QAction *action = 0;
+
+    const QStringList::Iterator end =  m_predefinedTimers.end();
+    lstActionTimer = new QActionGroup(this);
+    for (QStringList::Iterator it = m_predefinedTimers.begin(); it != end; ++it) {
+        action = new QAction(*it, this);
+        action->setProperty("seconds", QTime(0, 0, 0).secsTo(QTime::fromString(*it, \
CustomTimeEditor::TIME_FORMAT))); +        lstActionTimer->addAction(action);
+        connect(action, SIGNAL(triggered(bool)), this, \
SLOT(startTimerFromAction())); +        actions.append(action);
+    }
+    QAction *separator1 = new QAction(this);
+    separator1->setSeparator(true);
+    actions.append(separator1);
+}
+
 void Timer::createConfigurationInterface(KConfigDialog *parent)
 {
     QWidget *widget = new QWidget();
@@ -133,6 +163,7 @@
     m_command = ui.commandLineEdit->text();
     cg.writeEntry("command", m_command);
 
+    createMenuAction();
     emit configNeedsSaving();
 }
 
@@ -217,33 +248,7 @@
 
 QList<QAction*> Timer::contextualActions()
 {
-    QList<QAction*> actions;
-    actions.append(m_startAction);
-    actions.append(m_stopAction);
-    actions.append(m_resetAction);
-
-    //FIXME: Probably here I have a small memory leak
-    QAction *separator0 = new QAction(this);
-    separator0->setSeparator(true);
-    actions.append(separator0);
-
-    QAction *action = 0;
-
-    //FIXME: Probably here I have a small memory leak
-    const QStringList::Iterator end =  m_predefinedTimers.end();
-    for (QStringList::Iterator it = m_predefinedTimers.begin(); it != end; ++it) {
-        action = new QAction(*it, this);
-        action->setProperty("seconds", QTime(0, 0, 0).secsTo(QTime::fromString(*it, \
                CustomTimeEditor::TIME_FORMAT)));
-        action->setEnabled(!m_running);
-        connect(action, SIGNAL(triggered(bool)), this, \
                SLOT(startTimerFromAction()));
-        actions.append(action);
-    }
-
-    //FIXME: Probably here I have a small memory leak
-    QAction *separator1 = new QAction(this);
-    separator1->setSeparator(true);
-    actions.append(separator1);
-
+    lstActionTimer->setEnabled( !m_running );
     return actions;
 }
 
--- trunk/KDE/kdeplasma-addons/applets/timer/timer.h #846795:846796
@@ -31,6 +31,7 @@
 class QGraphicsSceneMouseEvent;
 class QMenu;
 class CustomTimeEditor;
+class QActionGroup;
 
 class Timer : public Plasma::Applet
 {
@@ -50,7 +51,7 @@
 
     protected:
         void createConfigurationInterface(KConfigDialog *parent);
-
+        void createMenuAction();
     private slots:
         void updateTimer();
         void slotCountDone();
@@ -76,7 +77,8 @@
         QString m_message;
         bool m_runCommand;
         QString m_command;
-
+        QList<QAction *>actions;
+        QActionGroup *lstActionTimer;
     protected slots:
         void configAccepted();
 };


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic