[kde-doc-english] [kdeplasma-addons] applets/timer: Timer: Added config ui (Appearance and command execution settings)
Bernhard Friedreich
friesoft at gmail.com
Tue Apr 7 21:08:24 UTC 2015
Git commit 57aeac6278d8085b481850d62eb2f2ad8109a316 by Bernhard Friedreich.
Committed on 07/04/2015 at 20:58.
Pushed by friedreich into branch 'master'.
Timer: Added config ui (Appearance and command execution settings)
Added configuration ui for "Appearance" and "Advanced" settings
REVIEW: 123274
GUI:
In the "Appearance" tab you can adjust whether to
* show seconds (default: true)
* show title (default: false, resizing is buggy: 304923)
In the "Advanced" tab a command for execution can be configured
M +19 -1 applets/timer/CMakeLists.txt
A +35 -0 applets/timer/package/contents/config/config.qml [License: GPL (v2+)]
M +2 -2 applets/timer/package/contents/config/main.xml
A +58 -0 applets/timer/package/contents/ui/configAdvanced.qml [License: GPL (v2+)]
A +42 -0 applets/timer/package/contents/ui/configAppearance.qml [License: GPL (v2+)]
M +10 -5 applets/timer/package/contents/ui/timer.qml
A +2 -0 applets/timer/plugin/qmldir
A +33 -0 applets/timer/plugin/timer.cpp [License: GPL (v2+)]
A +34 -0 applets/timer/plugin/timer.h [License: GPL (v2+)]
A +37 -0 applets/timer/plugin/timerplugin.cpp [License: GPL (v2+)]
A +34 -0 applets/timer/plugin/timerplugin.h [License: GPL (v2+)]
http://commits.kde.org/kdeplasma-addons/57aeac6278d8085b481850d62eb2f2ad8109a316
diff --git a/applets/timer/CMakeLists.txt b/applets/timer/CMakeLists.txt
index c7cba10..4bddb0f 100644
--- a/applets/timer/CMakeLists.txt
+++ b/applets/timer/CMakeLists.txt
@@ -1,4 +1,22 @@
+plasma_install_package(package org.kde.plasma.timer)
+
+add_definitions(-DTRANSLATION_DOMAIN="plasma_applet_org.kde.plasma.timer")
+
+set(timer_SRCS
+ plugin/timer.cpp
+ plugin/timerplugin.cpp
+)
+
+install(FILES plugin/qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/timer)
+add_library(timerplugin SHARED ${timer_SRCS})
+
+target_link_libraries(timerplugin
+ Qt5::Core
+ Qt5::Qml
+)
+
+install(TARGETS timerplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/timer)
+
install(FILES timer.svgz
DESTINATION ${PLASMA_DATA_INSTALL_DIR}/desktoptheme/default/widgets/)
-plasma_install_package(package org.kde.plasma.timer)
diff --git a/applets/timer/package/contents/config/config.qml b/applets/timer/package/contents/config/config.qml
new file mode 100644
index 0000000..711959c
--- /dev/null
+++ b/applets/timer/package/contents/config/config.qml
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2015 Bernhard Friedreich <friesoft at gmail.com>
+ *
+ * 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 2.010-1301, USA.
+ */
+
+import QtQuick 2.0
+
+import org.kde.plasma.configuration 2.0
+
+ConfigModel {
+ ConfigCategory {
+ name: i18n("Appearance")
+ icon: "preferences-desktop-color"
+ source: "configAppearance.qml"
+ }
+
+ ConfigCategory {
+ name: i18n("Advanced")
+ icon: "preferences-other"
+ source: "configAdvanced.qml"
+ }
+}
diff --git a/applets/timer/package/contents/config/main.xml b/applets/timer/package/contents/config/main.xml
index 6d4cdd3..886bcd4 100644
--- a/applets/timer/package/contents/config/main.xml
+++ b/applets/timer/package/contents/config/main.xml
@@ -26,8 +26,8 @@
<default>Timer</default>
</entry>
- <entry name="hideSeconds" type="Bool">
- <default>false</default>
+ <entry name="showSeconds" type="Bool">
+ <default>true</default>
</entry>
<entry name="showMessage" type="Bool">
diff --git a/applets/timer/package/contents/ui/configAdvanced.qml b/applets/timer/package/contents/ui/configAdvanced.qml
new file mode 100644
index 0000000..c315c89
--- /dev/null
+++ b/applets/timer/package/contents/ui/configAdvanced.qml
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2015 Bernhard Friedrich <friesoft at gmail.com>
+ *
+ * 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 2.010-1301, USA.
+ */
+
+import QtQuick 2.0
+import QtQuick.Controls 1.3 as QtControls
+import QtQuick.Layouts 1.0 as QtLayouts
+
+QtLayouts.ColumnLayout {
+ id: generalPage
+
+ property alias cfg_runCommand: runCommand.checked
+ property alias cfg_command: command.text
+
+ QtControls.GroupBox {
+ id: runCommandGroup
+ title: i18n("Run command")
+
+ QtLayouts.Layout.fillWidth: true
+ QtLayouts.Layout.fillHeight: true
+ flat: true
+
+ QtLayouts.ColumnLayout {
+ QtLayouts.Layout.fillWidth: true
+
+ QtControls.CheckBox {
+ id: runCommand
+ text: i18n("Execute command")
+ }
+
+ QtLayouts.RowLayout {
+ QtControls.Label {
+ text: i18n("Command:")
+ }
+ QtControls.TextField {
+ id: command
+ width: runCommandGroup.width * 0.8
+ enabled: runCommand.checked
+ }
+ }
+ }
+ }
+}
+
diff --git a/applets/timer/package/contents/ui/configAppearance.qml b/applets/timer/package/contents/ui/configAppearance.qml
new file mode 100644
index 0000000..ceb9732
--- /dev/null
+++ b/applets/timer/package/contents/ui/configAppearance.qml
@@ -0,0 +1,42 @@
+ /*
+ * Copyright 2015 Bernhard Friedreich <friesoft at gmail.com>
+ *
+ * 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 2.010-1301, USA.
+ */
+
+import QtQuick 2.0
+import QtQuick.Controls 1.0 as QtControls
+import QtQuick.Layouts 1.0 as QtLayouts
+
+QtLayouts.ColumnLayout {
+ id: appearancePage
+
+ property alias cfg_showTitle: showTitle.checked
+ property alias cfg_showSeconds: showSeconds.checked
+
+ QtLayouts.ColumnLayout {
+ QtLayouts.Layout.alignment: Qt.AlignTop
+
+ QtControls.CheckBox {
+ id: showTitle
+ text: i18n("Show title");
+ }
+ QtControls.CheckBox {
+ id: showSeconds
+ text: i18n("Show seconds");
+ }
+ }
+}
+
diff --git a/applets/timer/package/contents/ui/timer.qml b/applets/timer/package/contents/ui/timer.qml
index f675b93..82fee52 100644
--- a/applets/timer/package/contents/ui/timer.qml
+++ b/applets/timer/package/contents/ui/timer.qml
@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright 2008,2014 by Davide Bettio <davide.bettio at kdemail.net> *
+ * Copyright 2015 by Bernhard Friedreich <friesoft at gmail.com> *
* *
* 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 *
@@ -21,6 +22,7 @@ import QtQuick 2.2
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.kquickcontrolsaddons 2.0 as QtExtra
+import org.kde.plasma.private.timer 0.1 as TimerPlasmoid
Item {
id: root;
@@ -31,12 +33,12 @@ Item {
property date savedAt: plasmoid.configuration.savedAt;
property bool showTitle: plasmoid.configuration.showTitle;
property string title: plasmoid.configuration.title;
- property bool hideSeconds: plasmoid.configuration.hideSeconds;
+ property bool showSeconds: plasmoid.configuration.showSeconds;
property bool showMessage: plasmoid.configuration.showMessage;
property string message: plasmoid.configuration.message;
property bool runCommand: plasmoid.configuration.runCommand;
property string command: plasmoid.configuration.command;
- property real digits: (hideSeconds) ? 4.5 : 7;
+ property real digits: (showSeconds) ? 7 : 4.5;
property int digitH: ((height / 2) * digits < width ? height : ((width - (digits - 1)) / digits) * 2);
property int digitW: digitH / 2;
property bool suspended: false;
@@ -57,6 +59,9 @@ Item {
parent.running = false;
showNotification();
+ if (runCommand) {
+ TimerPlasmoid.Timer.runCommand(command);
+ }
saveTimer();
}
}
@@ -137,19 +142,19 @@ Item {
width: digitW / 2;
height: digitH;
elementId: "separator" + ((running && seconds < 60) ? "_1" : "");
- visible: !hideSeconds;
+ visible: showSeconds;
}
TimerDigit {
meaning: 10;
num: ~~((seconds % 60) / 10);
suffix: (running && seconds < 60) ? "_1" : "";
- visible: !hideSeconds;
+ visible: showSeconds;
}
TimerDigit {
meaning: 1;
num: (seconds % 60) % 10;
suffix: (running && seconds < 60) ? "_1" : "";
- visible: !hideSeconds;
+ visible: showSeconds;
}
}
}
diff --git a/applets/timer/plugin/qmldir b/applets/timer/plugin/qmldir
new file mode 100644
index 0000000..7c3eff4
--- /dev/null
+++ b/applets/timer/plugin/qmldir
@@ -0,0 +1,2 @@
+module org.kde.plasma.private.timer
+plugin timerplugin
diff --git a/applets/timer/plugin/timer.cpp b/applets/timer/plugin/timer.cpp
new file mode 100644
index 0000000..ff0fac8
--- /dev/null
+++ b/applets/timer/plugin/timer.cpp
@@ -0,0 +1,33 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Bernhard Friedreich <friesoft at gmail.com> *
+ * *
+ * 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 <QProcess>
+
+Timer::Timer(QObject *parent) : QObject(parent)
+{
+
+}
+
+void Timer::runCommand(const QString &command)
+{
+ QProcess::startDetached(command);
+}
+
diff --git a/applets/timer/plugin/timer.h b/applets/timer/plugin/timer.h
new file mode 100644
index 0000000..e831d38
--- /dev/null
+++ b/applets/timer/plugin/timer.h
@@ -0,0 +1,34 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Bernhard Friedreich <friesoft at gmail.com> *
+ * *
+ * 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_H
+#define TIMER_H
+
+#include <QObject>
+
+class Timer : public QObject
+{
+ Q_OBJECT
+
+public:
+ Timer(QObject *parent = nullptr);
+ Q_INVOKABLE void runCommand(const QString &command);
+};
+
+#endif // TIMER_H
diff --git a/applets/timer/plugin/timerplugin.cpp b/applets/timer/plugin/timerplugin.cpp
new file mode 100644
index 0000000..761b549
--- /dev/null
+++ b/applets/timer/plugin/timerplugin.cpp
@@ -0,0 +1,37 @@
+/*
+ Copyright (C) 2015 Bernhard Friedreich <friesoft at gmail.com>
+
+ 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 "timerplugin.h"
+#include "timer.h"
+
+#include <QtQml>
+
+static QObject *timer_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
+{
+ Q_UNUSED(engine)
+ Q_UNUSED(scriptEngine)
+
+ return new Timer();
+}
+
+void TimerPlugin::registerTypes(const char *uri)
+{
+ Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.timer"));
+
+ qmlRegisterSingletonType<Timer>(uri, 0, 1, "Timer", timer_singletontype_provider);
+}
diff --git a/applets/timer/plugin/timerplugin.h b/applets/timer/plugin/timerplugin.h
new file mode 100644
index 0000000..c55d33c
--- /dev/null
+++ b/applets/timer/plugin/timerplugin.h
@@ -0,0 +1,34 @@
+/*
+ Copyright (C) 2015 Bernhard Friedreich <friesoft at gmail.com>
+
+ 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 TIMERPLUGIN_H
+#define TIMERPLUGIN_H
+
+#include <QQmlExtensionPlugin>
+
+class QQmlEngine;
+class TimerPlugin : public QQmlExtensionPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
+
+public:
+ void registerTypes(const char *uri);
+};
+
+#endif // TIMERPLUGIN_H
More information about the kde-doc-english
mailing list