diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | logging.cpp | 30 | ||||
-rw-r--r-- | main.cpp | 7 | ||||
-rw-r--r-- | totimer.cpp | 2 |
4 files changed, 31 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index fefeba2..ea48c46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ pkg_check_modules(GTKLIB REQUIRED "gtk+-2.0") include_directories(${GTKLIB_INCLUDE_DIRS}) link_directories(${GTKLIB_LIBRARY_DIRS}) -set(CMAKE_CXX_FLAGS " -std=c++11 -lnotify") +set(CMAKE_CXX_FLAGS " -std=c++11 -lnotify -lsqlite3") set(SOURCE_FILES main.cpp totimer.cpp totimer.h logging.cpp logging.h) add_executable(pomodori ${SOURCE_FILES}) diff --git a/logging.cpp b/logging.cpp index 3d1fb14..f9b3100 100644 --- a/logging.cpp +++ b/logging.cpp @@ -4,19 +4,37 @@ #include "logging.h" #include "stdlib.h" -#include<iostream> -#include <fstream> +#include "stdio.h" #include <ctime> +#include <string> +#include <sqlite3.h> +#include <unistd.h> +#include <pwd.h> + +struct passwd *pw = getpwuid(getuid()); using namespace std; void log(tres* res,int code) { if (code) { - ofstream fot; - fot.open("~/.pomodori"); - time_t now = time(0); - fot<<ctime(&now)<<endl; + sqlite3 *db; + char *zErrMsg = 0; + char sqlop[50]; + sprintf(sqlop,"%s/.pomodori",pw->pw_dir); + int rc = sqlite3_open(sqlop,&db); + if( rc ){ + fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); + sqlite3_close(db); + exit(0); + } + sprintf(sqlop,"insert into log (Cat) Values ('%s');",res->reason); + rc = sqlite3_exec(db, sqlop, NULL, 0, &zErrMsg); + if( rc!=SQLITE_OK ){ + fprintf(stderr, "SQL error: %s\n", zErrMsg); + sqlite3_free(zErrMsg); + } + sqlite3_close(db); } exit(0); }
\ No newline at end of file @@ -6,11 +6,14 @@ int main(int argc, char** argv) { + if (argc<2) + return 0; gtk_init(&argc, &argv); - notify_init("Tomodori"); + notify_init("pomodori"); tres lastres; lastres.time=0; - settimer(&lastres,POTIME); + lastres.reason=argv[1]; + settimer(&lastres,1); gtk_main(); return 0; }
\ No newline at end of file diff --git a/totimer.cpp b/totimer.cpp index 66a6b52..05e2a01 100644 --- a/totimer.cpp +++ b/totimer.cpp @@ -37,7 +37,7 @@ bool notify(gpointer user_data) sprintf(str,"Time's up!(%d)",lastres->time-POTIME); else sprintf(str,"Time's up!"); - n = notify_notification_new ("Tomodori",str, NULL); + n = notify_notification_new ("Pomodori",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); |