diff options
author | q5sys <jt@obs-sec.com> | 2017-03-09 11:44:41 -0500 |
---|---|---|
committer | q5sys <jt@obs-sec.com> | 2017-03-09 11:44:41 -0500 |
commit | 5a1a8b47ea784cc004f6e0e00d92e68204515364 (patch) | |
tree | 3f573c38a129b1618198a44a72c0928acd4be1a4 /src-qt5/core/lumina-desktop/panel-plugins/alarm | |
parent | Merge branch 'master' of http://github.com/trueos/lumina (diff) | |
download | lumina-5a1a8b47ea784cc004f6e0e00d92e68204515364.tar.gz lumina-5a1a8b47ea784cc004f6e0e00d92e68204515364.tar.bz2 lumina-5a1a8b47ea784cc004f6e0e00d92e68204515364.zip |
add alarm panel-plugin
Diffstat (limited to 'src-qt5/core/lumina-desktop/panel-plugins/alarm')
11 files changed, 390 insertions, 0 deletions
diff --git a/src-qt5/core/lumina-desktop/panel-plugins/alarm/main.cpp b/src-qt5/core/lumina-desktop/panel-plugins/alarm/main.cpp new file mode 100644 index 00000000..b103c4cb --- /dev/null +++ b/src-qt5/core/lumina-desktop/panel-plugins/alarm/main.cpp @@ -0,0 +1,18 @@ +//=========================================== +// qalarm source code +// Copyright (c) 2017, q5sys +// Available under the MIT License +// See the LICENSE file for full details +//=========================================== + +#include "mainwindow.h" +#include <QApplication> + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + mainWindow w; + w.show(); + + return a.exec(); +} diff --git a/src-qt5/core/lumina-desktop/panel-plugins/alarm/mainwindow.cpp b/src-qt5/core/lumina-desktop/panel-plugins/alarm/mainwindow.cpp new file mode 100644 index 00000000..17d9ec6f --- /dev/null +++ b/src-qt5/core/lumina-desktop/panel-plugins/alarm/mainwindow.cpp @@ -0,0 +1,149 @@ +//=========================================== +// qalarm source code +// Copyright (c) 2017, q5sys +// Available under the MIT License +// See the LICENSE file for full details +//=========================================== + +#include "mainwindow.h" +#include "ui_mainwindow.h" +//#include "ui_snooze.h" +#include <QMenu> +#include <QtMultimedia/QMediaPlayer> +#include <QCloseEvent> +#include <QDebug> + +mainWindow::mainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::mainWindow){ + ui->setupUi(this); + trayIcon=new QSystemTrayIcon(this); + trayIconMenu=new QMenu(this); + QAction *actionShow=new QAction("&Show",this); + QAction *actionQuit=new QAction("&Quit",this); + + trayIconMenu->addAction(actionShow); + trayIconMenu->addSeparator(); + trayIconMenu->addAction(actionQuit); + trayIcon->setContextMenu(trayIconMenu); + trayIcon->setIcon(QIcon(":/media/alarm.svg")); + trayIcon->setToolTip("Alarm"); + trayIcon->show(); + setClock(); + + connect(actionQuit,SIGNAL(triggered()),this,SLOT(quitApp())); + connect(actionShow,SIGNAL(triggered()),this,SLOT(showWindow())); + connect(trayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(ShowWindow(QSystemTrayIcon::ActivationReason))); + connect(ui->pushButtonActivate,SIGNAL(clicked()),this,SLOT(SetCustomTime())); + connect(ui->pushButtonTest, SIGNAL(clicked()), this,SLOT(testAlarm())); +// QTimer *countDownTimer = new QTimer(this); // This alarm not written yet. +// connect (countDownTimer, SIGNAL(timeout()), this, SLOT(tripAlarm())); + + //Set Volume + int volume = 25; + ui->volumeSlider->setValue(volume<=0? 50:volume); +} + +mainWindow::~mainWindow(){ + delete ui; +} + +void mainWindow::closeEvent(QCloseEvent * event){ + event->ignore(); + this->hide(); +} + +void mainWindow::tripAlarm(){ + QMessageBox *alarmBox = new QMessageBox; + alarmBox->setText(tr("ALARM")); + alarmFile = new QMediaPlayer(this); + alarmFile->setMedia(QUrl::fromLocalFile(":/media/alarm.mp3")); + alarmFile->setVolume(volume); + alarmFile->play(); + QAbstractButton* pushButtonStop = alarmBox->addButton(tr("Stop Alarm"), QMessageBox::YesRole); + alarmBox->addButton(tr("Snooze for 5 Minutes"), QMessageBox::NoRole); + alarmBox->exec(); + if (alarmBox->clickedButton()==pushButtonStop){ + alarmFile->stop(); + } + else{ + alarmFile->stop(); + QTimer *snoozeabit = new QTimer(this); + connect(snoozeabit,SIGNAL(timeout()), this, SLOT(tripAlarm())); + snoozeabit->start(50000); + } +} + +void mainWindow::testAlarm(){ + QMessageBox *alarmTestBox = new QMessageBox; + alarmTestBox->setText("Ba Doop A Doop"); + alarmFile = new QMediaPlayer(this); + alarmFile->setMedia(QUrl(":/media/alarm.mp3")); + alarmFile->setVolume(volume); + alarmFile->play(); + QAbstractButton* pushButtonStop = alarmTestBox->addButton(tr("Stop Alarm"), QMessageBox::YesRole); + alarmTestBox->addButton(tr("Snooze for 5 Minutes"), QMessageBox::NoRole); + alarmTestBox->exec(); + if (alarmTestBox->clickedButton()==pushButtonStop){ + alarmFile->stop(); + } + else{ + alarmFile->stop(); + QTimer *snoozeabit = new QTimer(this); + connect(snoozeabit,SIGNAL(timeout()), this, SLOT(tripAlarm())); + snoozeabit->start(50000); + } + }ur ue. + +void mainWindow::setClock(){ + //Sync Clock in App with System Clock + QTimer *CurrentTime=new QTimer(this); + connect(CurrentTime,SIGNAL(timeout()),this,SLOT(syncClock())); + CurrentTime->start(500); +} + +void mainWindow::showWindow(QSystemTrayIcon::ActivationReason Reason){ + if(Reason==QSystemTrayIcon::DoubleClick || Reason==QSystemTrayIcon::Trigger) + { + showWindow(); + } +} + +void mainWindow::showWindow(){ + this->show(); +} + +void mainWindow::setCustomTime() +{ + ui->alarmDateTime->setDate(ui->calendarWidget->selectedDate()); + qDebug() << "selected date" << ui->calendarWidget->selectedDate(); + customDateTime.setTime(ui->alarmDateTime->time()); //this is not working yet + customDateTime.setDate(ui->calendarWidget->selectedDate()); //this is not working yet + qDebug() << "customDateTime" << customDateTime.toString("d MMMM yyyy hh:mm:ss"); + userDateTime = customDateTime.toString("d MMMM yyyy hh:mm:ss"); + qDebug() << "userDateTime" << userDateTime; + qDebug() << "nowtime" << QDateTime::currentDateTime().toString("d MMMM yyyy hh:mm:ss"); + startTimer(); +} + +void mainWindow::startTimer(){ + QTimer *rechecktimer = new QTimer(this); + connect(rechecktimer,SIGNAL(timeout()),this,SLOT(alarmCheck())); + qDebug() << "Timer Started"; + rechecktimer->start(1000); +} + +void mainWindow::alarmCheck(){ + nowDateTime = QDateTime::currentDateTime().toString("d MMMM yyyy hh:mm:ss"); + qDebug() << "nowDateTime" << nowDateTime; + qDebug() << "userDateTime" << userDateTime; + qDebug() << "customDateTime" << customDateTime.toString("d MMMM yyyy hh:mm:ss"); + if(nowDateTime==userDateTime){tripAlarm();} + } + +void mainWindow::quitApp(){ + qApp->quit(); +} + +void mainWindow::syncClock(){ + ui->currentClock->setText(QDateTime::currentDateTime().toString("hh:mm:ss ap")); +} + diff --git a/src-qt5/core/lumina-desktop/panel-plugins/alarm/mainwindow.h b/src-qt5/core/lumina-desktop/panel-plugins/alarm/mainwindow.h new file mode 100644 index 00000000..258b187a --- /dev/null +++ b/src-qt5/core/lumina-desktop/panel-plugins/alarm/mainwindow.h @@ -0,0 +1,68 @@ +//=========================================== +// qalarm source code +// Copyright (c) 2017, q5sys +// Available under the MIT License +// See the LICENSE file for full details +//=========================================== + + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> +#include <QDateTime> +#include <QDialog> +#include <QTimer> +#include <QString> +#include <QSystemTrayIcon> +#include <QMessageBox> +#include <QObject> +#include <QSettings> +#include <QMediaPlayer> +#include <QDir> + +namespace Ui { +class mainWindow; +} + +class mainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit mainWindow(QWidget *parent = 0); + ~mainWindow(); + + QDateTime customDateTime; + QString nowDateTime; + QString userDateTime; + int volume; + +public slots: +// void setVolume(int); + void setCustomTime(); + +private: + Ui::mainWindow *ui; + QSystemTrayIcon *trayIcon; + QMenu *trayIconMenu; + QTimer *rechecktimer; + QMediaPlayer *alarmFile; + QString alarmFilePath; + void closeEvent(QCloseEvent*); + void setClock(); + +private slots: + void showWindow(); + void showWindow(QSystemTrayIcon::ActivationReason); + void quitApp(); + void testAlarm(); + void syncClock(); + void alarmCheck(); + void tripAlarm(); + void startTimer(); +}; + +#endif // MAINWINDOW_H + + diff --git a/src-qt5/core/lumina-desktop/panel-plugins/alarm/mainwindow.ui b/src-qt5/core/lumina-desktop/panel-plugins/alarm/mainwindow.ui new file mode 100644 index 00000000..01f827b2 --- /dev/null +++ b/src-qt5/core/lumina-desktop/panel-plugins/alarm/mainwindow.ui @@ -0,0 +1,118 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>mainWindow</class> + <widget class="QMainWindow" name="mainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>408</width> + <height>623</height> + </rect> + </property> + <property name="windowTitle"> + <string>mainWindow</string> + </property> + <widget class="QWidget" name="centralWidget"> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="acceptDrops"> + <bool>false</bool> + </property> + <property name="autoFillBackground"> + <bool>false</bool> + </property> + <property name="title"> + <string>Current Time:</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="flat"> + <bool>false</bool> + </property> + <property name="checkable"> + <bool>false</bool> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="currentClock"> + <property name="minimumSize"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + <property name="font"> + <font> + <pointsize>26</pointsize> + </font> + </property> + <property name="frameShadow"> + <enum>QFrame::Sunken</enum> + </property> + <property name="text"> + <string>TextLabel</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QCalendarWidget" name="calendarWidget"/> + </item> + <item> + <widget class="QDateTimeEdit" name="alarmDateTime"> + <property name="displayFormat"> + <string>d MMM yyyy hh:mm:ss:AP</string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QLabel" name="labelVolume"> + <property name="text"> + <string>Volume</string> + </property> + </widget> + </item> + <item> + <widget class="QSlider" name="volumeSlider"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButtonTest"> + <property name="text"> + <string>Test</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QPushButton" name="pushButtonActivate"> + <property name="text"> + <string>Activate</string> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QStatusBar" name="statusBar"/> + </widget> + <layoutdefault spacing="6" margin="11"/> + <resources/> + <connections/> +</ui> diff --git a/src-qt5/core/lumina-desktop/panel-plugins/alarm/media.qrc b/src-qt5/core/lumina-desktop/panel-plugins/alarm/media.qrc new file mode 100644 index 00000000..ff8c652d --- /dev/null +++ b/src-qt5/core/lumina-desktop/panel-plugins/alarm/media.qrc @@ -0,0 +1,9 @@ +<RCC> + <qresource prefix="/media"> + <file alias="alarm.svg">media/ic_alarm_48px.svg</file> + <file alias="alarm_add.svg">media/ic_alarm_add_48px.svg</file> + <file alias="alarm_off.svg">media/ic_alarm_off_48px.svg</file> + <file alias="alarm_on.svg">media/ic_alarm_on_48px.svg</file> + <file alias="alarm.mp3">media/alarm.mp3</file> + </qresource> +</RCC> diff --git a/src-qt5/core/lumina-desktop/panel-plugins/alarm/media/alarm.mp3 b/src-qt5/core/lumina-desktop/panel-plugins/alarm/media/alarm.mp3 Binary files differnew file mode 100644 index 00000000..fb660393 --- /dev/null +++ b/src-qt5/core/lumina-desktop/panel-plugins/alarm/media/alarm.mp3 diff --git a/src-qt5/core/lumina-desktop/panel-plugins/alarm/media/ic_alarm_48px.svg b/src-qt5/core/lumina-desktop/panel-plugins/alarm/media/ic_alarm_48px.svg new file mode 100644 index 00000000..1a5c5397 --- /dev/null +++ b/src-qt5/core/lumina-desktop/panel-plugins/alarm/media/ic_alarm_48px.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 48 48"><path d="M44 11.44l-9.19-7.71-2.57 3.06 9.19 7.71L44 11.44zM15.76 6.78l-2.57-3.06L4 11.43l2.57 3.06 9.19-7.71zM25 16h-3v12l9.49 5.71L33 31.24l-8-4.74V16zm-1.01-8C14.04 8 6 16.06 6 26s8.04 18 17.99 18S42 35.94 42 26 33.94 8 23.99 8zM24 40c-7.73 0-14-6.27-14-14s6.27-14 14-14 14 6.27 14 14-6.26 14-14 14z"/></svg>
\ No newline at end of file diff --git a/src-qt5/core/lumina-desktop/panel-plugins/alarm/media/ic_alarm_add_48px.svg b/src-qt5/core/lumina-desktop/panel-plugins/alarm/media/ic_alarm_add_48px.svg new file mode 100644 index 00000000..b39d8b9d --- /dev/null +++ b/src-qt5/core/lumina-desktop/panel-plugins/alarm/media/ic_alarm_add_48px.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 48 48"><path d="M15.76 6.78l-2.57-3.06L4 11.43l2.57 3.06 9.19-7.71zM44 11.44l-9.19-7.71-2.57 3.06 9.19 7.71L44 11.44zM23.99 8C14.04 8 6 16.06 6 26s8.04 18 17.99 18S42 35.94 42 26 33.94 8 23.99 8zM24 40c-7.73 0-14-6.27-14-14s6.27-14 14-14 14 6.27 14 14-6.26 14-14 14zm2-22h-4v6h-6v4h6v6h4v-6h6v-4h-6v-6z"/></svg>
\ No newline at end of file diff --git a/src-qt5/core/lumina-desktop/panel-plugins/alarm/media/ic_alarm_off_48px.svg b/src-qt5/core/lumina-desktop/panel-plugins/alarm/media/ic_alarm_off_48px.svg new file mode 100644 index 00000000..8a9f2d2d --- /dev/null +++ b/src-qt5/core/lumina-desktop/panel-plugins/alarm/media/ic_alarm_off_48px.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 48 48"><path d="M24 12c7.73 0 14 6.27 14 14 0 1.69-.31 3.3-.86 4.8l3.04 3.04C41.34 31.47 42 28.81 42 26c0-9.94-8.06-18-18.01-18-2.81 0-5.46.66-7.84 1.81l3.05 3.05c1.5-.55 3.11-.86 4.8-.86zm20-.56l-9.19-7.71-2.57 3.06 9.19 7.71L44 11.44zM5.84 4.59L3.29 7.13l2.66 2.66-2.22 1.86 2.84 2.84 2.22-1.86 1.6 1.6C7.66 17.39 6 21.5 6 26c0 9.94 8.04 18 17.99 18 4.51 0 8.62-1.67 11.77-4.4l4.4 4.4 2.54-2.55L7.79 6.54 5.84 4.59zm27.1 32.19C30.51 38.79 27.4 40 24 40c-7.73 0-14-6.27-14-14 0-3.4 1.21-6.51 3.22-8.94l19.72 19.72zM16.03 6.55l-2.84-2.84-1.7 1.43 2.84 2.84 1.7-1.43z"/></svg>
\ No newline at end of file diff --git a/src-qt5/core/lumina-desktop/panel-plugins/alarm/media/ic_alarm_on_48px.svg b/src-qt5/core/lumina-desktop/panel-plugins/alarm/media/ic_alarm_on_48px.svg new file mode 100644 index 00000000..61f434df --- /dev/null +++ b/src-qt5/core/lumina-desktop/panel-plugins/alarm/media/ic_alarm_on_48px.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 48 48"><path d="M44 11.44l-9.19-7.71-2.57 3.06 9.19 7.71L44 11.44zM15.76 6.78l-2.57-3.06L4 11.43l2.57 3.06 9.19-7.71zM23.99 8C14.04 8 6 16.06 6 26s8.04 18 17.99 18S42 35.94 42 26 33.94 8 23.99 8zM24 40c-7.73 0-14-6.27-14-14s6.27-14 14-14 14 6.27 14 14-6.26 14-14 14zm-2.93-10.95l-4.24-4.24-2.12 2.12 6.36 6.36 12.01-12.01-2.12-2.12-9.89 9.89z"/></svg>
\ No newline at end of file diff --git a/src-qt5/core/lumina-desktop/panel-plugins/alarm/trayalarm.pro b/src-qt5/core/lumina-desktop/panel-plugins/alarm/trayalarm.pro new file mode 100644 index 00000000..61480fc2 --- /dev/null +++ b/src-qt5/core/lumina-desktop/panel-plugins/alarm/trayalarm.pro @@ -0,0 +1,24 @@ +#=========================================== +# qalarm source code +# Copyright (c) 2017, q5sys +# Available under the -clause BSD license +# See the LICENSE file for full details +#=========================================== + +QT += core gui multimedia + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = trayalarm +TEMPLATE = app + + +SOURCES += main.cpp\ + mainwindow.cpp + +HEADERS += mainwindow.h + +FORMS += mainwindow.ui + +RESOURCES += \ + media.qrc |