Browse Source

init db creation

- also changed dir handling for ics-files and
 - added/removed some debug output
main
Stefan Pranger 4 years ago
parent
commit
b166d96a41
  1. 22
      calendar-daemon.cpp
  2. 12
      db/create.h
  3. 8
      db/db.h
  4. 9
      util/calendar_parsing.cpp
  5. 4
      util/calendar_parsing.h

22
calendar-daemon.cpp

@ -11,21 +11,26 @@
#include <unistd.h>
#include <vector>
#include <sqlite3.h>
#include <db/db.h>
#include <util/notifications.h>
#include <util/calendar_parsing.h>
#include <io/debug.h>
const int MINUTE = 1000000;
void update_database() {
std::vector<ical::ical_object*> objects = util::parse_cal_dir();
void init_database(std::string calendar) {
db::init(calendar + ".db");
}
void update_database(std::string directory) {
std::vector<ical::ical_object*> 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

12
db/create.h

@ -0,0 +1,12 @@
#pragma once
#include <db/db.h>
#include <string>
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;
}
}

8
db/db.h

@ -0,0 +1,8 @@
#pragma once
#include <SQLiteCpp.h>
#include <io/debug.h>
namespace sql = SQLite;
#include <db/create.h>

9
util/calendar_parsing.cpp

@ -3,14 +3,17 @@
#include <memory>
namespace util {
std::vector<ical::ical_object*> parse_cal_dir() {
std::vector<ical::ical_object*> parse_cal_dir(std::string directory) {
std::vector<ical::ical_object*> objects;
std::vector<icalcomponent*> 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;

4
util/calendar_parsing.h

@ -13,10 +13,8 @@
#include <io/debug.h>
const std::string cal_dir = "/home/stefan/.local/share/khal/calendars/dummy/";
namespace util {
std::vector<ical::ical_object*> parse_cal_dir();
std::vector<ical::ical_object*> 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);

Loading…
Cancel
Save