diff --git a/calendar-daemon.cpp b/calendar-daemon.cpp index 38fd7ca..a970275 100644 --- a/calendar-daemon.cpp +++ b/calendar-daemon.cpp @@ -11,21 +11,26 @@ #include #include -#include + +#include #include #include #include const int MINUTE = 1000000; -void update_database() { - std::vector objects = util::parse_cal_dir(); +void init_database(std::string calendar) { + db::init(calendar + ".db"); +} + +void update_database(std::string directory) { + std::vector objects = util::parse_cal_dir(directory); } -void do_heartbeat() +void do_heartbeat(std::string directory) { - util::notify("Testing", ""); - update_database(); + util::notify("Updating files from " + directory, ""); + update_database(directory); } // For security purposes, we don't allow any arguments to be passed into the daemon @@ -88,11 +93,14 @@ int main(void) // Daemon-specific intialization should go here const int SLEEP_INTERVAL = 5 * MINUTE; + std::string calendar = "dummy"; + std::string directory = "/home/stefan/.local/share/khal/calendars/" + calendar + "/"; + init_database(calendar); // Enter daemon loop while(1) { // Execute daemon heartbeat, where your recurring activity occurs - do_heartbeat(); + do_heartbeat(directory); exit(0); // Sleep for a period of time diff --git a/db/create.h b/db/create.h new file mode 100644 index 0000000..7d9d21c --- /dev/null +++ b/db/create.h @@ -0,0 +1,12 @@ +#pragma once + +#include +#include + +namespace db { + sql::Database init(std::string name) { + sql::Database db(name, SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE); + DEBUG << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n"; + return db; + } +} diff --git a/db/db.h b/db/db.h new file mode 100644 index 0000000..265d8e3 --- /dev/null +++ b/db/db.h @@ -0,0 +1,8 @@ +#pragma once + +#include +#include + +namespace sql = SQLite; + +#include diff --git a/util/calendar_parsing.cpp b/util/calendar_parsing.cpp index b17419e..062ab05 100644 --- a/util/calendar_parsing.cpp +++ b/util/calendar_parsing.cpp @@ -3,14 +3,17 @@ #include namespace util { - std::vector parse_cal_dir() { + std::vector parse_cal_dir(std::string directory) { std::vector objects; std::vector components; - for (boost::filesystem::directory_entry& entry : boost::filesystem::directory_iterator(cal_dir)) { + uint counter = 0; + for (boost::filesystem::directory_entry& entry : boost::filesystem::directory_iterator(directory)) { DEBUG << "Parsing: " + entry.path().generic_string(); ical::ical_object* object = new ical::ical_object(); parse_main_component(object, parse_ics_file(entry.path().generic_string())); + counter++; } + DEBUG << "files parsed: " << counter; return objects; } @@ -57,7 +60,7 @@ namespace util { } case ICAL_VEVENT_COMPONENT: { - DEBUG << "parsed component: ICAL_VEVENT_COMPONENT"; + //DEBUG << "parsed component: ICAL_VEVENT_COMPONENT"; //DEBUG << "\n" << icalcomponent_as_ical_string_r(component); ical::Event(object, component); break; diff --git a/util/calendar_parsing.h b/util/calendar_parsing.h index bca1aa8..c699100 100644 --- a/util/calendar_parsing.h +++ b/util/calendar_parsing.h @@ -13,10 +13,8 @@ #include -const std::string cal_dir = "/home/stefan/.local/share/khal/calendars/dummy/"; - namespace util { - std::vector parse_cal_dir(); + std::vector parse_cal_dir(std::string directory); icalcomponent* parse_main_component(ical::ical_object* object, icalcomponent* component); void parse_component(ical::ical_object* object, icalcomponent* component);