From 4e296d5f189c2a5a4505149a7cfba3b1f50f0d85 Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Fri, 4 Sep 2015 11:28:34 -0600 Subject: sqlite logging --- CMakeLists.txt | 2 +- logging.cpp | 30 ++++++++++++++++++++++++------ main.cpp | 7 +++++-- 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 -#include +#include "stdio.h" #include +#include +#include +#include +#include + +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<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 diff --git a/main.cpp b/main.cpp index 43a7764..43d599e 100644 --- a/main.cpp +++ b/main.cpp @@ -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); -- cgit v1.2.3-70-g09d2