summaryrefslogtreecommitdiff
path: root/totimer.cpp
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2015-09-06 15:10:51 -0600
committerJoe Zhao <ztuowen@gmail.com>2015-09-06 15:10:51 -0600
commit2f63794da7acbfcf61558428cd84f590a73fc13f (patch)
treebda4bc9682ee5704ad752d601b9ede81de198bbe /totimer.cpp
parent3507dcb7a51249962e40847626f72f5207e8c0af (diff)
downloadpomodori-2f63794da7acbfcf61558428cd84f590a73fc13f.tar.gz
pomodori-2f63794da7acbfcf61558428cd84f590a73fc13f.tar.bz2
pomodori-2f63794da7acbfcf61558428cd84f590a73fc13f.zip
revert to original time
Diffstat (limited to 'totimer.cpp')
-rw-r--r--totimer.cpp37
1 files changed, 31 insertions, 6 deletions
diff --git a/totimer.cpp b/totimer.cpp
index 05e2a01..ec9b5dd 100644
--- a/totimer.cpp
+++ b/totimer.cpp
@@ -4,6 +4,21 @@
#include "totimer.h"
#include<stdio.h>
+#include "pomodori.h"
+#include "trayicon.h"
+
+bool timeout;
+guint timerid;
+
+void timer_kill()
+{
+ if (timeout)
+ {
+ g_source_remove(timerid);
+ timeout=false;
+ tray_deactivate();
+ }
+}
void quit(NotifyNotification *note,gpointer user_data)
{
@@ -16,7 +31,7 @@ void timeup(NotifyNotification *note,const char *action,gpointer user_data){
tres* lastres = (tres*)user_data;
switch (action[0]){
case 'M':
- settimer(lastres, POTEXT);
+ timer_set(lastres, POTEXT);
break;
case 'G':
log(lastres,1);
@@ -30,6 +45,7 @@ void timeup(NotifyNotification *note,const char *action,gpointer user_data){
bool notify(gpointer user_data)
{
+ timeout=false;
tres* lastres = (tres*)user_data;
NotifyNotification *n;
char str[20];
@@ -37,19 +53,28 @@ bool notify(gpointer user_data)
sprintf(str,"Time's up!(%d)",lastres->time-POTIME);
else
sprintf(str,"Time's up!");
- n = notify_notification_new ("Pomodori",str, NULL);
+ n = notify_notification_new (APPNAME,str, NULL);
notify_notification_set_urgency(n,NOTIFY_URGENCY_CRITICAL);
notify_notification_add_action(n,"M", "More",(NotifyActionCallback)timeup,lastres,NULL);
notify_notification_add_action(n,"G", "Good",(NotifyActionCallback)timeup,lastres,NULL);
g_signal_connect (n, "closed", G_CALLBACK(quit), NULL);
-// printf("1");
notify_notification_set_timeout(n,0); //3 seconds
notify_notification_show(n,NULL);
return FALSE;
}
-int settimer(tres* lastres, guint32 wait)
+void timer_set(tres* lastres, guint32 wait)
+{
+ if (!timeout)
+ {
+ timeout=true;
+ lastres->time = lastres->time + wait;
+ timerid = g_timeout_add(wait*60*1000,(GSourceFunc)notify,lastres);
+ }
+}
+
+void timer_init()
{
- lastres->time = lastres->time + wait;
- g_timeout_add(wait*60*1000,(GSourceFunc)notify,lastres);
+ timeout=false;
+ notify_init(APPNAME);
} \ No newline at end of file