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

List:       kde-commits
Subject:    [kdeplasma-addons/bettio/qml-gsoc-timer] applets/timer: Replaced old Timer plasmoid with the QML por
From:       Davide Bettio <bettio () kde ! org>
Date:       2012-07-23 15:01:01
Message-ID: 20120723150101.F2D81A6094 () git ! kde ! org
[Download RAW message or body]

Git commit 94f7cc98d4c9325c0033f22864bfee300307bf81 by Davide Bettio.
Committed on 23/07/2012 at 16:58.
Pushed by bettio into branch 'bettio/qml-gsoc-timer'.

Replaced old Timer plasmoid with the QML port of it.

M  +6    -15   applets/timer/CMakeLists.txt
A  +42   -0    applets/timer/package/contents/config/main.xml
A  +34   -0    applets/timer/package/contents/ui/TimerDigit.qml     [License: GPL \
(v2+)] R  +13   -13   applets/timer/package/contents/ui/config.ui [from: \
applets/timer/timerConfig.ui - 085% similarity] A  +139  -0    \
applets/timer/package/contents/ui/timer.qml     [License: GPL (v2+)] R  +2    -0    \
applets/timer/package/metadata.desktop [from: \
applets/timer/plasma-applet-timer.desktop - 098% similarity] D  +0    -547  \
applets/timer/timer.cpp D  +0    -122  applets/timer/timer.h
D  +0    -40   applets/timer/timerdigit.cpp
D  +0    -50   applets/timer/timerdigit.h

http://commits.kde.org/kdeplasma-addons/94f7cc98d4c9325c0033f22864bfee300307bf81

diff --git a/applets/timer/CMakeLists.txt b/applets/timer/CMakeLists.txt
index d677506..896363d 100644
--- a/applets/timer/CMakeLists.txt
+++ b/applets/timer/CMakeLists.txt
@@ -1,21 +1,12 @@
-
-# Project needs a name of course
 project(timer)
 
-# We add our source code here
-set(timer_SRCS timer.cpp timerdigit.cpp customtimeeditor.cpp)
-kde4_add_ui_files(timer_SRCS timerConfig.ui predefinedTimersConfig.ui)
-
-# Now make sure all files get to the right place
-kde4_add_plugin(plasma_applet_timer ${timer_SRCS})
-target_link_libraries(plasma_applet_timer
-                      ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS})
+install(DIRECTORY package/
+        DESTINATION ${DATA_INSTALL_DIR}/plasma/plasmoids/timer)
 
-install(TARGETS plasma_applet_timer
-        DESTINATION ${PLUGIN_INSTALL_DIR})
-
-install(FILES plasma-applet-timer.desktop
-        DESTINATION ${SERVICES_INSTALL_DIR})
+install(FILES package/metadata.desktop
+        DESTINATION ${SERVICES_INSTALL_DIR}
+        RENAME plasma-applet-timer.desktop)
 
 install(FILES timer.svgz
 	DESTINATION ${DATA_INSTALL_DIR}/desktoptheme/default/widgets/)
+
diff --git a/applets/timer/package/contents/config/main.xml \
b/applets/timer/package/contents/config/main.xml new file mode 100644
index 0000000..fb1983a
--- /dev/null
+++ b/applets/timer/package/contents/config/main.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+      xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
+      http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
+  <kcfgfile name=""/>
+
+  <group name="General">
+    <entry name="predefinedTimers" type="StringList" />
+
+    <entry name="startedAt" type="DateTime" />
+
+    <entry name="showTitle" type="Bool">
+      <default>false</default>
+    </entry>
+
+    <entry name="title" type="String">
+      <default>Timer</default>
+    </entry>
+
+    <entry name="hideSeconds" type="Bool">
+      <default>false</default>
+    </entry>
+
+    <entry name="showMessage" type="Bool">
+      <default>true</default>
+    </entry>
+
+    <entry name="message" type="String">
+      <default>Timer Timeout</default>
+    </entry>
+
+    <entry name="runCommand" type="Bool">
+      <default>false</default>
+    </entry>
+
+    <entry name="command" type="String">
+      <default></default>
+    </entry>
+  </group>
+</kcfg>
+
diff --git a/applets/timer/package/contents/ui/TimerDigit.qml \
b/applets/timer/package/contents/ui/TimerDigit.qml new file mode 100644
index 0000000..7f88d8b
--- /dev/null
+++ b/applets/timer/package/contents/ui/TimerDigit.qml
@@ -0,0 +1,34 @@
+/***************************************************************************
+ *   Copyright 2008,2012 by Davide Bettio <davide.bettio@kdemail.net>      *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
+ ***************************************************************************/
+
+import QtQuick 1.0;
+import org.kde.plasma.core 0.1 as PlasmaCore
+
+PlasmaCore.SvgItem
+{
+        property int meaning;
+        property int num;
+        property string suffix;
+
+        width: digitW;
+        height: digitH;
+        svg: timerSvg
+        elementId: num + suffix;
+}
+
diff --git a/applets/timer/timerConfig.ui \
b/applets/timer/package/contents/ui/config.ui similarity index 85%
rename from applets/timer/timerConfig.ui
rename to applets/timer/package/contents/ui/config.ui
index 38c6cdb..a146db4 100644
--- a/applets/timer/timerConfig.ui
+++ b/applets/timer/package/contents/ui/config.ui
@@ -41,17 +41,17 @@
     </spacer>
    </item>
    <item row="1" column="1">
-    <widget class="QCheckBox" name="showTitleCheckBox">
+    <widget class="QCheckBox" name="kcfg_showTitle">
      <property name="text">
       <string>Show title:</string>
      </property>
     </widget>
    </item>
    <item row="1" column="3">
-    <widget class="KLineEdit" name="titleLineEdit"/>
+    <widget class="KLineEdit" name="kcfg_title"/>
    </item>
    <item row="2" column="1">
-    <widget class="QCheckBox" name="hideSecondsCheckBox">
+    <widget class="QCheckBox" name="kcfg_hideSeconds">
      <property name="text">
       <string>Hide seconds</string>
      </property>
@@ -71,10 +71,10 @@
     </widget>
    </item>
    <item row="6" column="3">
-    <widget class="KLineEdit" name="messageLineEdit"/>
+    <widget class="KLineEdit" name="kcfg_message"/>
    </item>
    <item row="7" column="3">
-    <widget class="KLineEdit" name="commandLineEdit"/>
+    <widget class="KLineEdit" name="kcfg_command"/>
    </item>
    <item row="8" column="2">
     <spacer name="verticalSpacer">
@@ -90,14 +90,14 @@
     </spacer>
    </item>
    <item row="6" column="1">
-    <widget class="QCheckBox" name="showMessageCheckBox">
+    <widget class="QCheckBox" name="kcfg_showMessage">
      <property name="text">
       <string>Show a message:</string>
      </property>
     </widget>
    </item>
    <item row="7" column="1">
-    <widget class="QCheckBox" name="runCommandCheckBox">
+    <widget class="QCheckBox" name="kcfg_runCommand">
      <property name="text">
       <string>Run a command:</string>
      </property>
@@ -131,9 +131,9 @@
  <resources/>
  <connections>
   <connection>
-   <sender>showMessageCheckBox</sender>
+   <sender>kcfg_showMessage</sender>
    <signal>toggled(bool)</signal>
-   <receiver>messageLineEdit</receiver>
+   <receiver>kcfg_message</receiver>
    <slot>setEnabled(bool)</slot>
    <hints>
     <hint type="sourcelabel">
@@ -147,9 +147,9 @@
    </hints>
   </connection>
   <connection>
-   <sender>runCommandCheckBox</sender>
+   <sender>kcfg_runCommand</sender>
    <signal>toggled(bool)</signal>
-   <receiver>commandLineEdit</receiver>
+   <receiver>kcfg_command</receiver>
    <slot>setEnabled(bool)</slot>
    <hints>
     <hint type="sourcelabel">
@@ -163,9 +163,9 @@
    </hints>
   </connection>
   <connection>
-   <sender>showTitleCheckBox</sender>
+   <sender>kcfg_showTitle</sender>
    <signal>toggled(bool)</signal>
-   <receiver>titleLineEdit</receiver>
+   <receiver>kcfg_title</receiver>
    <slot>setEnabled(bool)</slot>
    <hints>
     <hint type="sourcelabel">
diff --git a/applets/timer/package/contents/ui/timer.qml \
b/applets/timer/package/contents/ui/timer.qml new file mode 100644
index 0000000..cc36eeb
--- /dev/null
+++ b/applets/timer/package/contents/ui/timer.qml
@@ -0,0 +1,139 @@
+/***************************************************************************
+ *   Copyright 2008,2012 by Davide Bettio <davide.bettio@kdemail.net>      *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
+ ***************************************************************************/
+
+import QtQuick 1.0;
+import org.kde.plasma.core 0.1 as PlasmaCore
+
+Item
+{
+    property int seconds : 95;
+    property bool running: true;
+    property variant predefinedTimers;
+    property date startedAt;
+    property bool showTitle: false;
+    property string title;
+    property bool hideSeconds: false;
+    property bool showMessage: true;
+    property string message;
+    property bool runCommand: false;
+    property string command;
+    property real digits: (hideSeconds) ? 4.5 : 7;
+    property int digitH: ((height / 2) * digits < width ? height : ((width - (digits \
- 1)) / digits) * 2); +    property int digitW: digitH / 2;
+
+    PlasmaCore.Svg {
+        id: timerSvg
+        imagePath: "widgets/timer"
+    }
+
+    Timer {
+        id: t;
+        interval: 1000;
+        onTriggered: seconds--;
+        repeat: true;
+    }
+
+    Column {
+        anchors.centerIn: parent;
+        Text {
+            id: titleLabel;
+            text: title;
+            visible: showTitle;
+            horizontalAlignment: Text.AlignHCenter
+            font.pixelSize: parent.parent.height - digitH;
+        }
+        Row {
+            TimerDigit {
+                meaning: 60*60*10;
+                num: ~~((seconds / (60*60)) / 10);
+                suffix: (running && seconds < 60) ? "_1" : "";
+            }
+            TimerDigit {
+                meaning: 60*60;
+                num: (seconds / (60*60)) % 10;
+                suffix: (running && seconds < 60) ? "_1" : "";
+            }
+
+            PlasmaCore.SvgItem {
+                svg: timerSvg;
+                width: digitW / 2;
+                height: digitH;
+                elementId: "separator" + ((running && seconds < 60) ? "_1" : "");
+            }
+            TimerDigit {
+                meaning: 600;
+                num: ~~(~~((seconds % (60*60)) / 60) / 10);
+                suffix: (running && seconds < 60) ? "_1" : "";
+            }
+            TimerDigit {
+                meaning: 60;
+                num: ~~((seconds % (60*60)) / 60) % 10;
+                suffix: (running && seconds < 60) ? "_1" : "";
+            }
+
+            PlasmaCore.SvgItem {
+                svg: timerSvg;
+                width: digitW / 2;
+                height: digitH;
+                elementId: "separator" + ((running && seconds < 60) ? "_1" : "");
+                visible: !hideSeconds;
+            }
+            TimerDigit {
+                meaning: 10;
+                num: ~~((seconds % 60) / 10);
+                suffix: (running && seconds < 60) ? "_1" : "";
+                visible: !hideSeconds;
+            }
+            TimerDigit {
+                meaning: 1;
+                num: (seconds % 60) % 10;
+                suffix: (running && seconds < 60) ? "_1" : "";
+                visible: !hideSeconds;
+            }
+        }
+    }
+
+    MouseArea {
+        anchors.fill: parent;
+        onClicked: t.start();
+    }
+
+    //PlasmaComponents.ContextMenu {
+    //    model: predefinedTimers;
+    //}
+
+    Component.onCompleted: {
+        plasmoid.addEventListener ('ConfigChanged', configChanged);
+    }
+
+    function configChanged() {
+        predefinedTimers = plasmoid.readConfig("predefinedTimers", ["00:00:30", \
"00:01:00", "00:02:00", "00:05:00", "00:07:30", +                                     \
"00:10:00", "00:15:00", "00:20:00", "00:25:00", "00:30:00", +                         \
"00:45:00", "01:00:00" ]);  +        startedAt = plasmoid.readConfig("startedAt", new \
Date()); +        showTitle = plasmoid.readConfig("showTitle", false);
+        title = plasmoid.readConfig("title", i18n("Timer"));
+        hideSeconds = plasmoid.readConfig("hideSeconds", false);
+        showMessage = plasmoid.readConfig("showMessage", true);
+        message = plasmoid.readConfig("message", i18n("Timer Timeout"));
+        runCommand = plasmoid.readConfig("runCommand", false);
+        command = plasmoid.readConfig("command", "");
+    }
+}
+
diff --git a/applets/timer/plasma-applet-timer.desktop \
b/applets/timer/package/metadata.desktop similarity index 98%
rename from applets/timer/plasma-applet-timer.desktop
rename to applets/timer/package/metadata.desktop
index c2dc2fb..1442736 100644
--- a/applets/timer/plasma-applet-timer.desktop
+++ b/applets/timer/package/metadata.desktop
@@ -123,5 +123,7 @@ X-KDE-PluginInfo-Depends=
 X-KDE-PluginInfo-License=GPL
 X-KDE-PluginInfo-EnabledByDefault=true
 
+X-Plasma-API=declarativeappletscript
+X-Plasma-MainScript=ui/timer.qml
 X-Plasma-Requires-FileDialog=Unused
 X-Plasma-Requires-LaunchApp=Unused
diff --git a/applets/timer/timer.cpp b/applets/timer/timer.cpp
deleted file mode 100644
index ba5ee66..0000000
--- a/applets/timer/timer.cpp
+++ /dev/null
@@ -1,547 +0,0 @@
-/***************************************************************************
- *   Copyright 2008 by Davide Bettio <davide.bettio@kdemail.net>           *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
- ***************************************************************************/
-
-#include "timer.h"
-
-#include <QSequentialAnimationGroup>
-#include <QPropertyAnimation>
-#include <QtCore/QEasingCurve>
-#include <QtGui/QGraphicsSceneMouseEvent>
-
-#include <KAuthorized>
-#include <KConfigDialog>
-#include <KDebug>
-#include <KNotification>
-#include <KShell>
-#include <KToolInvocation>
-
-#include <Plasma/Label>
-#include <Plasma/Svg>
-#include <Plasma/SvgWidget>
-
-#include "customtimeeditor.h"
-
-
-Timer::Timer(QObject *parent, const QVariantList &args)
-    : Plasma::Applet(parent, args),
-      m_seconds(0),
-      m_startingSeconds(0),
-      m_running(false),
-      m_blinkAnim(0)
-{
-    resize(315, 125);
-    setHasConfigurationInterface(true);
-    setAspectRatioMode(Plasma::KeepAspectRatio);
-}
-
-Timer::~Timer()
-{
-    saveTimer();
-}
-
-void Timer::init()
-{
-    m_svg = new Plasma::Svg(this);
-    m_svg->setImagePath("widgets/timer");
-    m_svg->setContainsMultipleImages(true);
-
-    // Choose graphical separator based on the text one.
-    m_separatorBasename = QString("separator");
-    QString textSeparator = CustomTimeEditor::timerSeparator().remove(' ');
-    if (textSeparator == QString('.')) {
-        m_separatorBasename += 'B';
-    } else if (textSeparator == QString(' ')) {
-        m_separatorBasename += 'C';
-    }
-
-    m_hoursDigit[0] = new TimerDigit(m_svg, 36000, this);
-    m_hoursDigit[1] = new TimerDigit(m_svg, 3600, this);
-    m_minutesDigit[0] = new TimerDigit(m_svg, 600, this);
-    m_minutesDigit[1] = new TimerDigit(m_svg, 60, this);
-    m_secondsDigit[0] = new TimerDigit(m_svg, 10, this);
-    m_secondsDigit[1] = new TimerDigit(m_svg, 1, this);
-    m_separator[0] = new Plasma::SvgWidget(m_svg, m_separatorBasename, this);
-    m_separator[1] = new Plasma::SvgWidget(m_svg, m_separatorBasename, this);
-    m_title = new Plasma::Label(this);
-    m_title->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
-
-    connect(m_hoursDigit[0], SIGNAL(changed(int)), this, SLOT(digitChanged(int)));
-    connect(m_hoursDigit[1], SIGNAL(changed(int)), this, SLOT(digitChanged(int)));
-    connect(m_minutesDigit[0], SIGNAL(changed(int)), this, SLOT(digitChanged(int)));
-    connect(m_minutesDigit[1], SIGNAL(changed(int)), this, SLOT(digitChanged(int)));
-    connect(m_secondsDigit[0], SIGNAL(changed(int)), this, SLOT(digitChanged(int)));
-    connect(m_secondsDigit[1], SIGNAL(changed(int)), this, SLOT(digitChanged(int)));
-
-    connect(&m_timer, SIGNAL(timeout()), this, SLOT(updateTimer()));
-
-    m_startAction = new QAction(i18n("Start"), this);
-    m_startAction->setEnabled(false);
-    connect(m_startAction, SIGNAL(triggered(bool)), this, SLOT(startTimer()));
-
-    m_stopAction = new QAction(i18n("Stop"), this);
-    m_stopAction->setEnabled(false);
-    connect(m_stopAction, SIGNAL(triggered(bool)), this, SLOT(stopTimer()));
-
-    m_resetAction = new QAction(i18n("Reset"), this);
-    m_resetAction->setEnabled(false);
-    connect(m_resetAction, SIGNAL(triggered(bool)), this, SLOT(resetTimer()));
-
-    configChanged();
-    createMenuAction();
-}
-
-void Timer::configChanged()
-{
-    KConfigGroup cg = config();
-    m_predefinedTimers = cg.readEntry("predefinedTimers", QStringList() << \
                "00:00:30" << "00:01:00"
-                                                       << "00:02:00" << "00:05:00" \
                << "00:07:30"
-                                                       << "00:10:00" << "00:15:00" \
                << "00:20:00"
-                                                       << "00:25:00" << "00:30:00" \
                << "00:45:00"
-                                                       << "01:00:00");
-    m_showTitle = cg.readEntry("showTitle", false);
-    m_timerTitle = cg.readEntry("title", i18n("Timer"));
-    m_hideSeconds = cg.readEntry("hideSeconds", false);
-    m_showMessage = cg.readEntry("showMessage", true);
-    m_message = cg.readEntry("message", i18n("Timer Timeout"));
-    m_runCommand = cg.readEntry("runCommand", false);
-    m_command = cg.readEntry("command", "");
-
-    m_title->setVisible(m_showTitle);
-    m_title->setText(m_timerTitle);
-
-    // update the display for the seconds hiding setting
-    m_secondsDigit[0]->setVisible(!m_hideSeconds);
-    m_secondsDigit[1]->setVisible(!m_hideSeconds);
-    m_separator[1]->setVisible(!m_hideSeconds);
-    constraintsEvent(Plasma::SizeConstraint);
-
-    // Timers are kept non-localized in the config, to work across language changes.
-    QStringList localizedTimers;
-    foreach (const QString &timer, m_predefinedTimers) {
-        localizedTimers.append(CustomTimeEditor::toLocalizedTimer(timer));
-    }
-    m_predefinedTimers = localizedTimers;
-
-    if (isUserConfiguring()) {
-        // immediate update of the display
-        setSeconds(m_seconds);
-        return;
-    }
-
-    // everything from here down is run when not called due to the config UI
-    m_startedAt = cg.readEntry("startedAt", QDateTime::currentDateTime());
-    m_startingSeconds = cg.readEntry("seconds", 0);
-    const int runningTime = config().readEntry("running", 0);
-    m_running = runningTime > 0;
-    if (m_running) {
-        int tmpSeconds = runningTime - \
                m_startedAt.secsTo(QDateTime::currentDateTime());
-        if (tmpSeconds > 0) {
-            setSeconds(tmpSeconds);
-            startTimer();
-        } else {
-            //TODO: We should notify user about expired timer
-            m_running = false;
-        }
-    } else {
-        setSeconds(m_startingSeconds);
-        if (m_seconds){
-            m_startAction->setEnabled(true);
-            m_resetAction->setEnabled(true);
-        }
-    }
-}
-
-void Timer::constraintsEvent(Plasma::Constraints constraints)
-{
-    if (constraints == Plasma::SizeConstraint) {
-        int appletHeight = (int) contentsRect().height();
-        int appletWidth = (int) contentsRect().width();
-        float digits = m_secondsDigit[0]->isVisible() ? 7 : 4.5;
-
-        int h = (int) ((appletHeight / 2) * digits < appletWidth ? appletHeight : \
                ((appletWidth - (digits - 1)) / digits) * 2);
-        int w = h / 2;
-        int y = (int) (contentsRect().y() + (appletHeight - h) / 2);
-        int x = (int) (contentsRect().x() + (appletWidth - w * digits) / 2);
-
-        m_hoursDigit[0]->setGeometry(x, y, w, h);
-        m_hoursDigit[1]->setGeometry(x + w, y, w, h);  
-
-        m_separator[0]->setGeometry(x + (w * 2), y, w/2, h);
-
-        m_minutesDigit[0]->setGeometry(x + (w * 2) + (w/2), y, w, h);
-        m_minutesDigit[1]->setGeometry(x + (w * 3) + (w/2), y, w, h);
-
-        m_separator[1]->setGeometry(x + (w * 4) + (w/2), y, w/2, h);
-
-        m_secondsDigit[0]->setGeometry(x + (w * 5), y, w, h);
-        m_secondsDigit[1]->setGeometry(x + (w * 6), y, w, h);
-
-        QFont font = this->font();
-        font.setPixelSize( y - 6 );
-        m_title->nativeWidget()->setFont( font );
-        m_title->setGeometry(QRectF(0, 4, appletWidth, y - 2));
-    }
-}
-
-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;
-
-    QStringList::const_iterator end =  m_predefinedTimers.constEnd();
-    lstActionTimer = new QActionGroup(this);
-    for (QStringList::const_iterator it = m_predefinedTimers.constBegin(); it != \
                end; ++it) {
-        action = new QAction(*it, this);
-        action->setProperty("seconds", QTime(0, 0, 0).secsTo(QTime::fromString(*it, \
                CustomTimeEditor::toLocalizedTimer(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();
-    ui.setupUi(widget);
-
-    QWidget *predefinedTimersWidget = new QWidget();
-    predefinedTimersUi.setupUi(predefinedTimersWidget);
-
-    parent->addPage(widget, i18n("General"), icon());
-    parent->addPage(predefinedTimersWidget, i18n("Predefined Timers"), icon());
-    connect(parent, SIGNAL(applyClicked()), this, SLOT(configAccepted()));
-    connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted()));
-
-    //Allow sysadmins to run arbitrary commands on timeout
-    bool enableCommandLine = KAuthorized::authorizeKAction("run_command") && \
                KAuthorized::authorizeKAction("shell_access");
-    m_runCommand = enableCommandLine;
-    ui.runCommandCheckBox->setEnabled(enableCommandLine);
-    ui.commandLineEdit->setEnabled(enableCommandLine);
-
-    ui.showTitleCheckBox->setChecked(m_title->isVisible());
-    ui.titleLineEdit->setEnabled(m_title->isVisible());
-    ui.titleLineEdit->setText(m_title->text());
-    ui.hideSecondsCheckBox->setChecked(!m_secondsDigit[0]->isVisible());
-    ui.showMessageCheckBox->setChecked(m_showMessage);
-    ui.messageLineEdit->setEnabled(m_showMessage);
-    ui.messageLineEdit->setText(m_message);
-    ui.runCommandCheckBox->setChecked(m_runCommand);
-    ui.commandLineEdit->setEnabled(m_runCommand);
-    ui.commandLineEdit->setText(m_command);
-
-    CustomTimeEditor *aCustomEditor = new CustomTimeEditor();
-    predefinedTimersUi.defaulttimers->setCustomEditor(*(aCustomEditor->getCustomEditor()));
                
-    predefinedTimersUi.defaulttimers->setItems(m_predefinedTimers);
-    connect(ui.showTitleCheckBox, SIGNAL(toggled(bool)), parent, \
                SLOT(settingsModified()));
-    connect(ui.hideSecondsCheckBox, SIGNAL(toggled(bool)), parent, \
                SLOT(settingsModified()));
-    connect(ui.showMessageCheckBox, SIGNAL(toggled(bool)), parent, \
                SLOT(settingsModified()));
-    connect(ui.runCommandCheckBox, SIGNAL(toggled(bool)), parent, \
                SLOT(settingsModified()));
-    connect(ui.titleLineEdit, SIGNAL(userTextChanged(QString)), parent, \
                SLOT(settingsModified()));
-    connect(ui.messageLineEdit, SIGNAL(userTextChanged(QString)), parent, \
                SLOT(settingsModified()));
-    connect(ui.commandLineEdit, SIGNAL(userTextChanged(QString)), parent, \
                SLOT(settingsModified()));
-    connect(predefinedTimersUi.defaulttimers , SIGNAL(changed()), parent, \
                SLOT(settingsModified()));
-}
-
-void Timer::configAccepted()
-{
-    KConfigGroup cg = config();
-
-    m_predefinedTimers = predefinedTimersUi.defaulttimers->items();
-    QStringList unlocalizedTimers;
-    foreach (const QString &timer, m_predefinedTimers) {
-        unlocalizedTimers.append(CustomTimeEditor::fromLocalizedTimer(timer));
-    }
-    cg.writePathEntry("predefinedTimers", unlocalizedTimers);
-
-    m_title->setVisible(ui.showTitleCheckBox->isChecked());
-    cg.writeEntry("showTitle", m_title->isVisible());
-
-    bool hideSeconds = ui.hideSecondsCheckBox->isChecked();
-    cg.writeEntry("hideSeconds", hideSeconds);
-
-    m_title->setText(ui.titleLineEdit->text());
-    cg.writeEntry("title", m_title->text());
-
-    m_showMessage = ui.showMessageCheckBox->isChecked();
-    cg.writeEntry("showMessage", m_showMessage);
-
-    m_message = ui.messageLineEdit->text();
-    cg.writeEntry("message", m_message);
-
-    m_runCommand = ui.runCommandCheckBox->isChecked();
-    cg.writeEntry("runCommand", m_runCommand);
-
-    m_command = ui.commandLineEdit->text();
-    cg.writeEntry("command", m_command);
-
-    createMenuAction();
-    updateConstraints(Plasma::SizeConstraint);
-    emit configNeedsSaving();
-}
-
-void Timer::updateTimer()
-{
-    if (m_seconds < 2) {
-        m_timer.stop();
-        m_running = false;
-
-        m_startAction->setEnabled(false);
-        m_stopAction->setEnabled(false);
-        m_resetAction->setEnabled(false);
-
-        slotCountDone();
-    }
-
-    if (m_seconds != 0){
-        setSeconds(--m_seconds);
-    }
-}
-
-void Timer::setSeconds(int secs)
-{
-    m_seconds = secs;
-
-    int seconds = m_seconds % 60;
-    int mins = (m_seconds % (60 * 60)) / 60 + (m_hideSeconds && seconds > 0 ? 1 : \
                0);
-    int hours =  m_seconds / (60 * 60);
-
-    const QString suffix = (m_seconds < 60 && m_running) ? "_1" : "";
-
-    m_hoursDigit[0]->setElementID(QString::number(hours / 10) + suffix);
-    m_hoursDigit[1]->setElementID(QString::number(hours % 10) + suffix);
-
-    m_separator[0]->setElementID(m_separatorBasename + suffix);
-
-    m_minutesDigit[0]->setElementID(QString::number(mins / 10) + suffix);
-    m_minutesDigit[1]->setElementID(QString::number(mins % 10) + suffix);
-
-    if (!m_hideSeconds) {
-        m_separator[1]->setElementID(m_separatorBasename + suffix);
-
-        m_secondsDigit[0]->setElementID(QString::number(seconds / 10) + suffix);
-        m_secondsDigit[1]->setElementID(QString::number(seconds % 10) + suffix);
-    }
-}
-
-void Timer::slotCountDone()
-{
-    if (m_showMessage){
-        QPixmap icon = KIconLoader::global()->loadIcon("chronometer", \
                KIconLoader::Dialog);
-
-        KNotification *notification = \
                KNotification::event(KNotification::Notification);
-        notification->setPixmap(icon);
-        notification->setTitle(i18n("Plasma Timer Applet"));
-        notification->setText(m_title->isVisible() ? m_title->text() + " - " + \
                m_message : m_message);
-        notification->sendEvent();
-    }
-
-    if (m_runCommand && !m_command.isEmpty() && \
KAuthorized::authorizeKAction("run_command") && \
                KAuthorized::authorizeKAction("shell_access")){
-        QStringList args = KShell::splitArgs(m_command);
-        QString command = args[0];
-        args.removeFirst();
-        KToolInvocation::kdeinitExec(command, args);
-    }
-}
-
-void Timer::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *)
-{
-    resetTimer();
-}
-
-void Timer::saveTimer()
-{
-    KConfigGroup cg = config();
-    cg.writeEntry("running", m_running ? m_seconds : 0);
-    cg.writeEntry("startedAt", QDateTime::currentDateTime());
-    cg.writeEntry("seconds", 0);
-
-    emit configNeedsSaving();
-}
-
-void Timer::startTimer()
-{
-    m_running = true;
-    saveTimer();
-    setBlinking(false);
-    m_timer.start(1000);
-
-    m_startAction->setEnabled(false);
-    m_resetAction->setEnabled(true);
-    m_stopAction->setEnabled(true);
-}
-
-void Timer::stopTimer()
-{
-    m_running = false;
-    saveTimer();
-    setBlinking(true);
-    m_timer.stop();
-
-    m_startAction->setEnabled(true);
-    m_resetAction->setEnabled(true);
-    m_stopAction->setEnabled(false);
-}
-
-void Timer::resetTimer()
-{
-    m_running = false;
-    saveTimer();
-    setBlinking(false);
-    m_timer.stop();
-
-    setSeconds(m_startingSeconds);
-    m_startAction->setEnabled(true);
-    m_resetAction->setEnabled(false);
-    m_stopAction->setEnabled(false);
-}
-
-void Timer::mousePressEvent(QGraphicsSceneMouseEvent *)
-{
-    // does nothing but ensure the event is accepted so we get release events
-}
-
-void Timer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
-{
-    if (event->button() == Qt::LeftButton && geometry().contains(event->pos())) {
-        if (m_running) {
-            stopTimer();
-        } else if (m_seconds > 0) {
-            startTimer();
-        }
-    }
-}
-
-QList<QAction*> Timer::contextualActions()
-{
-    lstActionTimer->setEnabled( !m_running );
-    return actions;
-}
-
-void Timer::startTimerFromAction()
-{
-    QAction *action = dynamic_cast<QAction*> (sender());
-    if (!action || action->property("seconds").type() != QVariant::Int) {
-        return;
-    }
-
-    m_startingSeconds = action->property("seconds").toInt();
-    setSeconds(m_startingSeconds);
-    startTimer();
-}
-
-void Timer::digitChanged(int value)
-{
-    if (m_running) {
-        return;
-    }
-
-    if (value < 0) {
-        if (m_seconds >= abs(value)) {
-            setSeconds((m_seconds - abs(value)) % 86400);
-        }
-    } else {
-        setSeconds((m_seconds + abs(value)) % 86400);
-    }
-
-    if (m_seconds != 0) {
-        m_startAction->setEnabled(true);
-        m_resetAction->setEnabled(true);
-    } else {
-        m_startAction->setEnabled(false);
-        m_resetAction->setEnabled(false);
-    }
-}
-
-void Timer::toggleTimerVisible()
-{
-    if (!m_blinkAnim) {
-        QSequentialAnimationGroup *animGroup = new QSequentialAnimationGroup(this);
-
-        QPropertyAnimation *anim = new QPropertyAnimation(this, "digitOpacity", \
                animGroup);
-        anim->setDuration(800);
-        anim->setEasingCurve(QEasingCurve::InOutQuad);
-        anim->setStartValue(1.0);
-        anim->setEndValue(0.2);
-
-        animGroup->addAnimation(anim);
-        animGroup->addPause(400);
-
-        m_blinkAnim = animGroup;
-    }
-
-    m_blinkAnim->setDirection(qFuzzyCompare(m_hoursDigit[0]->opacity(), 1.0) ?
-                              QAbstractAnimation::Forward : \
                QAbstractAnimation::Backward);
-    m_blinkAnim->start();
-}
-
-void Timer::setBlinking(bool blinking)
-{
-    if (blinking) {
-        toggleTimerVisible();
-        connect(m_blinkAnim, SIGNAL(finished()), this, SLOT(reverseBlinkAnim()));
-    } else if (m_blinkAnim) {
-        disconnect(m_blinkAnim, SIGNAL(finished()), this, SLOT(reverseBlinkAnim()));
-        m_blinkAnim->setDirection(QAbstractAnimation::Backward);
-    }
-}
-
-qreal Timer::digitOpacity() const
-{
-    return m_hoursDigit[0]->opacity();
-}
-
-void Timer::setDigitOpacity(qreal opacity)
-{
-    m_hoursDigit[0]->setOpacity(opacity);
-    m_hoursDigit[1]->setOpacity(opacity);
-
-    m_minutesDigit[0]->setOpacity(opacity);
-    m_minutesDigit[1]->setOpacity(opacity);
-
-    m_secondsDigit[0]->setOpacity(opacity);
-    m_secondsDigit[1]->setOpacity(opacity);
-
-    m_separator[0]->setOpacity(opacity);
-    m_separator[1]->setOpacity(opacity);
-}
-
-void Timer::reverseBlinkAnim()
-{
-    m_blinkAnim->setDirection(m_blinkAnim->direction() == \
                QAbstractAnimation::Forward ?
-                              QAbstractAnimation::Backward :
-                              QAbstractAnimation::Forward);
-    if (m_blinkAnim->state() != QAbstractAnimation::Running) {
-        m_blinkAnim->start();
-    }
-}
-
-#include "timer.moc"
diff --git a/applets/timer/timer.h b/applets/timer/timer.h
deleted file mode 100644
index 12dfa96..0000000
--- a/applets/timer/timer.h
+++ /dev/null
@@ -1,122 +0,0 @@
-/***************************************************************************
- *   Copyright 2008 by Davide Bettio <davide.bettio@kdemail.net>           *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
- ***************************************************************************/
-
-#ifndef TIMER_HEADER
-#define TIMER_HEADER
-
-#include <QtCore/QList>
-#include <QtCore/QTimer>
-
-#include <Plasma/Applet>
-
-#include "ui_predefinedTimersConfig.h"
-#include "ui_timerConfig.h"
-#include "timerdigit.h"
-
-class QGraphicsSceneMouseEvent;
-class QActionGroup;
-class QAbstractAnimation;
-
-namespace Plasma
-{
-    class Label;
-    class Svg;
-    class SvgWidget;
-}
-
-class Timer : public Plasma::Applet
-{
-    Q_OBJECT
-    Q_PROPERTY(qreal digitOpacity READ digitOpacity WRITE setDigitOpacity)
-
-    public:
-        Timer(QObject *parent, const QVariantList &args);
-        ~Timer();
-
-        void init();
-        void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
-        void mousePressEvent(QGraphicsSceneMouseEvent * event);
-        void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
-        QList<QAction*> contextualActions();
-
-        qreal digitOpacity() const;
-        void setDigitOpacity(qreal opacity);
-
-    protected:
-        void createConfigurationInterface(KConfigDialog *parent);
-        void createMenuAction();
-        void constraintsEvent(Plasma::Constraints constraints);
-
-    public slots:
-        void configChanged();
-
-    private slots:
-        void updateTimer();
-        void slotCountDone();
-        void startTimer();
-        void stopTimer();
-        void resetTimer();
-        void startTimerFromAction();
-        void digitChanged(int value);
-        void toggleTimerVisible();
-        void reverseBlinkAnim();
-
-    private:
-        void setBlinking(bool blinking);
-        void saveTimer();
-        void setSeconds(int seconds);
-
-        int m_seconds;
-        int m_startingSeconds;
-        bool m_running;
-
-        QTimer m_timer;
-        QAbstractAnimation *m_blinkAnim;
-        Plasma::Svg *m_svg;
-        TimerDigit *m_hoursDigit[2];
-        TimerDigit *m_minutesDigit[2];
-        TimerDigit *m_secondsDigit[2];
-        Plasma::SvgWidget *m_separator[2];
-        Plasma::Label *m_title;
-
-        QAction *m_startAction;
-        QAction *m_stopAction;
-        QAction *m_resetAction;
-        Ui::predefinedTimersConfig predefinedTimersUi;
-        Ui::timerConfig ui;
-
-        QStringList m_predefinedTimers;    
-        bool m_showMessage;
-        QString m_message;
-        bool m_runCommand;
-        QString m_command;
-        QList<QAction *>actions;
-        QActionGroup *lstActionTimer;
-        QString m_separatorBasename;
-        QDateTime m_startedAt;
-        bool m_showTitle;
-        QString m_timerTitle;
-        bool m_hideSeconds;
-
-    protected slots:
-        void configAccepted();
-};
-
-K_EXPORT_PLASMA_APPLET(timer, Timer)
-#endif
diff --git a/applets/timer/timerdigit.cpp b/applets/timer/timerdigit.cpp
deleted file mode 100644
index 9f87ab1..0000000
--- a/applets/timer/timerdigit.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- *   Copyright 2009 by Davide Bettio <davide.bettio@kdemail.net>
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU Library General Public License as
- *   published by the Free Software Foundation; either version 2, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details
- *
- *   You should have received a copy of the GNU Library General Public
- *   License along with this program; if not, write to the
- *   Free Software Foundation, Inc.,
- *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "timerdigit.h"
-
-#include <QGraphicsSceneMouseEvent>
-
-TimerDigit::TimerDigit(Plasma::Svg *svg, int seconds, QGraphicsItem *parent)
-    : SvgWidget(svg, "0", parent)
-{
-    m_seconds = seconds;
-}
-
-TimerDigit::~TimerDigit()
-{
-
-}
-
-void TimerDigit::wheelEvent(QGraphicsSceneWheelEvent * event)
-{
-    emit changed((event->delta() < 0) ? -m_seconds : m_seconds);
-}
-
-#include "timerdigit.moc"
diff --git a/applets/timer/timerdigit.h b/applets/timer/timerdigit.h
deleted file mode 100644
index d5bb9ed..0000000
--- a/applets/timer/timerdigit.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- *   Copyright 2009 by Davide Bettio <davide.bettio@kdemail.net>
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU Library General Public License as
- *   published by the Free Software Foundation; either version 2, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details
- *
- *   You should have received a copy of the GNU Library General Public
- *   License along with this program; if not, write to the
- *   Free Software Foundation, Inc.,
- *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#ifndef TIMERDIGIT_H
-#define TIMERDIGIT_H
-
-#include <Plasma/SvgWidget>
-
-class QGraphicsItem;
-class QGraphicsSceneWheelEvent;
-
-namespace Plasma
-{
-    class Svg;
-}
-
-class TimerDigit : public Plasma::SvgWidget
-{
-    Q_OBJECT
-
-    public:
-        TimerDigit(Plasma::Svg *svg, int seconds, QGraphicsItem *parent = 0);
-        void wheelEvent(QGraphicsSceneWheelEvent * event);
-
-        virtual ~TimerDigit();
-
-    Q_SIGNALS:
-        void changed(int value);
-
-    private:
-        int m_seconds;
-};
-
-#endif


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

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