Author: juha Date: 2008-03-06 14:44:26 +0000 (Thu, 06 Mar 2008) New Revision: 26668
Modified: xfcalendar/trunk/src/appointment.c xfcalendar/trunk/src/functions.c xfcalendar/trunk/src/functions.h xfcalendar/trunk/src/interface.c xfcalendar/trunk/src/main.c xfcalendar/trunk/src/parameters.c xfcalendar/trunk/src/reminder.c xfcalendar/trunk/src/tray_icon.c Log: 1) internal code cleanouts. Modified: xfcalendar/trunk/src/appointment.c =================================================================== --- xfcalendar/trunk/src/appointment.c 2008-03-05 04:47:56 UTC (rev 26667) +++ xfcalendar/trunk/src/appointment.c 2008-03-06 14:44:26 UTC (rev 26668) @@ -47,7 +47,6 @@ #include <glib/gstdio.h> #include <libxfcegui4/libxfcegui4.h> -#include <libxfce4util/libxfce4util.h> #include "functions.h" #include "mainbox.h" @@ -1437,39 +1436,21 @@ } /************************************************************/ -/* categories start. this will go to functions.c when ready */ +/* categories start. */ /************************************************************/ -#define ORAGE_CATEGORIES "orage_categories.txt" -#define ORAGE_COLOR_FORMAT "%uR %uG %uB" - -XfceRc *orage_category_file_open(gboolean read_only) +static OrageRc *orage_category_file_open(gboolean read_only) { gchar *fpath; - XfceRc *rc; + OrageRc *orc; - fpath = orage_data_file_location(ORAGE_CATEGORIES); - if (!fpath) { - g_warning("orage_category_file_open: category filename build failed (%s)\n", fpath); - return(NULL); + fpath = orage_data_file_location(ORAGE_CATEGORIES_FILE); + if ((orc = (OrageRc *)orage_rc_file_open(fpath, read_only)) == NULL) { + orage_message(150, "orage_category_file_open: category file open failed."); } - if ((rc = xfce_rc_simple_open(fpath, read_only)) == NULL) { - g_warning("Unable to open RC file."); - /* let's try to build it if we opened in read mode */ - if (read_only && (rc = xfce_rc_simple_open(fpath, FALSE)) == NULL) { - /* still failed, can't do more */ - g_warning("Unable to open (write) RC file."); - return(NULL); - } - } - g_free(fpath); - return(rc); -} -void orage_category_file_close(XfceRc *rc) -{ - xfce_rc_close(rc); + return(orc); } typedef struct _orage_category @@ -1501,7 +1482,7 @@ return(NULL); } -void orage_category_free(gpointer gcat, gpointer dummy) +static void orage_category_free(gpointer gcat, gpointer dummy) { orage_category_struct *cat = (orage_category_struct *)gcat; @@ -1518,7 +1499,7 @@ void orage_category_get_list() { - XfceRc *rc; + OrageRc *orc; gchar **cat_groups, *color; gint i; orage_category_struct *cat; @@ -1527,34 +1508,35 @@ if (orage_category_list != NULL) orage_category_free_list(); pic1_cmap = gdk_colormap_get_system(); - rc = orage_category_file_open(TRUE); - cat_groups = xfce_rc_get_groups(rc); + orc = orage_category_file_open(TRUE); + cat_groups = orage_rc_get_groups(orc); for (i=1; cat_groups[i] != NULL; i++) { - xfce_rc_set_group(rc, cat_groups[i]); - color = (char *)xfce_rc_read_entry(rc, "Color", NULL); + orage_rc_set_group(orc, cat_groups[i]); + color = orage_rc_get_str(orc, "Color", NULL); if (color) { - cat= g_new(orage_category_struct, 1); + cat = g_new(orage_category_struct, 1); cat->category = g_strdup(cat_groups[i]); sscanf(color, ORAGE_COLOR_FORMAT, &(cat->color.red) , &(cat->color.green), &(cat->color.blue)); gdk_colormap_alloc_color(pic1_cmap, &cat->color, FALSE, TRUE); orage_category_list = g_list_prepend(orage_category_list, cat); + g_free(color); } } g_strfreev(cat_groups); - orage_category_file_close(rc); + orage_rc_file_close(orc); } gboolean category_fill_cb(GtkComboBox *cb, char *select) { - XfceRc *rc; + OrageRc *orc; gchar **cat_gourps; gint i; gboolean found=FALSE; - rc = orage_category_file_open(TRUE); - cat_gourps = xfce_rc_get_groups(rc); - /* cat_gourps[0] is special [NULL] entry always */ + orc = orage_category_file_open(TRUE); + cat_gourps = orage_rc_get_groups(orc); + /* cat_groups[0] is special [NULL] entry always */ gtk_combo_box_append_text(cb, _("Not set")); gtk_combo_box_set_active(cb, 0); for (i=1; cat_gourps[i] != NULL; i++) { @@ -1565,7 +1547,7 @@ } } g_strfreev(cat_gourps); - orage_category_file_close(rc); + orage_rc_file_close(orc); return(found); } @@ -1614,7 +1596,7 @@ void orage_category_write_entry(gchar *category, GdkColor *color) { - XfceRc *rc; + OrageRc *orc; char *color_str; if (!ORAGE_STR_EXISTS(category)) { @@ -1623,24 +1605,24 @@ } color_str = g_strdup_printf(ORAGE_COLOR_FORMAT , color->red, color->green, color->blue); - rc = orage_category_file_open(FALSE); - xfce_rc_set_group(rc, category); - xfce_rc_write_entry(rc, "Color", color_str); + orc = orage_category_file_open(FALSE); + orage_rc_set_group(orc, category); + orage_rc_put_str(orc, "Color", color_str); g_free(color_str); - orage_category_file_close(rc); + orage_rc_file_close(orc); } static void orage_category_remove_entry(gchar *category) { - XfceRc *rc; + OrageRc *orc; if (!ORAGE_STR_EXISTS(category)) { orage_message(50, "orage_category_write_entry: empty category. Not removed"); return; } - rc = orage_category_file_open(FALSE); - xfce_rc_delete_group(rc, category, FALSE); - orage_category_file_close(rc); + orc = orage_category_file_open(FALSE); + orage_rc_del_group(orc, category); + orage_rc_file_close(orc); } static void close_cat_window(gpointer user_data) Modified: xfcalendar/trunk/src/functions.c =================================================================== --- xfcalendar/trunk/src/functions.c 2008-03-05 04:47:56 UTC (rev 26667) +++ xfcalendar/trunk/src/functions.c 2008-03-06 14:44:26 UTC (rev 26668) @@ -496,12 +496,113 @@ orage_select_date(cal, t->tm_year+1900, t->tm_mon, t->tm_mday); } +/******************************************************* + * rc file interface + *******************************************************/ + gchar *orage_data_file_location(char *name) { char *file_name, *dir_name; dir_name = g_strconcat(ORAGE_DIR, name, NULL); - file_name = xfce_resource_save_location(XFCE_RESOURCE_DATA, dir_name, TRUE); + file_name = xfce_resource_save_location(XFCE_RESOURCE_DATA, dir_name + , TRUE); g_free(dir_name); return(file_name); } + +gchar *orage_config_file_location(char *name) +{ + char *file_name, *dir_name; + + dir_name = g_strconcat(ORAGE_DIR, name, NULL); + file_name = xfce_resource_save_location(XFCE_RESOURCE_CONFIG, dir_name + , TRUE); + g_free(dir_name); + return(file_name); +} + +OrageRc *orage_rc_file_open(char *fpath, gboolean read_only) +{ + XfceRc *rc; + OrageRc *orc = NULL; + + if ((rc = xfce_rc_simple_open(fpath, read_only)) == NULL && read_only) { + orage_message(-90, "orage_rc_open: Unable to open (read) RC file (%s). Creating it.", fpath); + /* let's try to build it */ + if ((rc = xfce_rc_simple_open(fpath, FALSE)) == NULL) { + /* still failed, can't do more */ + orage_message(150, "orage_rc_open: Unable to open (write) RC file (%s).", fpath); + } + } + + if (rc) { /* we managed to open it */ + orc = g_new(OrageRc, 1); + orc->rc = rc; + } + return(orc); +} + +void orage_rc_file_close(OrageRc *orc) +{ + if (orc) { + xfce_rc_close((XfceRc *)orc->rc); + g_free(orc); + } +} + +gchar **orage_rc_get_groups(OrageRc *orc) +{ + return(xfce_rc_get_groups((XfceRc *)orc->rc)); +} + +void orage_rc_set_group(OrageRc *orc, char *grp) +{ + xfce_rc_set_group((XfceRc *)orc->rc, grp); +} + +void orage_rc_del_group(OrageRc *orc, char *grp) +{ + xfce_rc_delete_group((XfceRc *)orc->rc, grp, FALSE); +} + +gchar *orage_rc_get_str(OrageRc *orc, char *key, char *def) +{ + return(g_strdup(xfce_rc_read_entry((XfceRc *)orc->rc, key, def))); +} + +gint orage_rc_get_int(OrageRc *orc, char *key, gint def) +{ + return(xfce_rc_read_int_entry((XfceRc *)orc->rc, key, def)); +} + +gboolean orage_rc_get_bool(OrageRc *orc, char *key, gboolean def) +{ + return(xfce_rc_read_bool_entry((XfceRc *)orc->rc, key, def)); +} + +void orage_rc_put_str(OrageRc *orc, char *key, char *val) +{ + if (val != NULL) + xfce_rc_write_entry((XfceRc *)orc->rc, key, val); +} + +void orage_rc_put_int(OrageRc *orc, char *key, gint val) +{ + xfce_rc_write_int_entry((XfceRc *)orc->rc, key, val); +} + +void orage_rc_put_bool(OrageRc *orc, char *key, gboolean val) +{ + xfce_rc_write_bool_entry((XfceRc *)orc->rc, key, val); +} + +gboolean orage_rc_exists_item(OrageRc *orc, char *key) +{ + return(xfce_rc_has_entry((XfceRc *)orc->rc, key)); +} + +void orage_rc_del_item(OrageRc *orc, char *key) +{ + xfce_rc_delete_entry((XfceRc *)orc->rc, key, FALSE); +} Modified: xfcalendar/trunk/src/functions.h =================================================================== --- xfcalendar/trunk/src/functions.h 2008-03-05 04:47:56 UTC (rev 26667) +++ xfcalendar/trunk/src/functions.h 2008-03-06 14:44:26 UTC (rev 26668) @@ -28,14 +28,22 @@ #define XFICAL_APPT_TIME_FORMAT_LEN 16 #define XFICAL_APPT_DATE_FORMAT "%04d%02d%02d" #define XFICAL_APPT_DATE_FORMAT_LEN 9 +#define ORAGE_COLOR_FORMAT "%uR %uG %uB" #define ORAGE_DIR "orage" G_DIR_SEPARATOR_S -#define ORAGE_PARFILE "oragerc" -#define ORAGE_APPFILE "orage.ics" -#define ORAGE_ARCFILE "orage_archive.ics" +#define ORAGE_PAR_FILE "oragerc" +#define ORAGE_APP_FILE "orage.ics" +#define ORAGE_ARC_FILE "orage_archive.ics" +#define ORAGE_CATEGORIES_FILE "orage_categories.txt" +#define ORAGE_PERSISTENT_ALARMS_FILE "orage_persistent_alarms.txt" #define ORAGE_STR_EXISTS(str) ((str != NULL) && (str[0] != 0)) +typedef struct _OrageRc +{ + void *rc; +} OrageRc; + void orage_message(gint level, const char *format, ...); GtkWidget *orage_create_combo_box_with_content(char *text[], int size); @@ -78,5 +86,19 @@ void orage_select_today(GtkCalendar *cal); gchar *orage_data_file_location(char *name); +gchar *orage_config_file_location(char *name); +OrageRc *orage_rc_file_open(char *fpath, gboolean read_only); +void orage_rc_file_close(OrageRc *orc); +gchar **orage_rc_get_groups(OrageRc *orc); +void orage_rc_set_group(OrageRc *orc, char *grp); +void orage_rc_del_group(OrageRc *orc, char *grp); +gchar *orage_rc_get_str(OrageRc *orc, char *key, char *def); +gint orage_rc_get_int(OrageRc *orc, char *key, gint def); +gboolean orage_rc_get_bool(OrageRc *orc, char *key, gboolean def); +void orage_rc_put_str(OrageRc *orc, char *key, char *val); +void orage_rc_put_int(OrageRc *orc, char *key, gint val); +void orage_rc_put_bool(OrageRc *orc, char *key, gboolean val); +gboolean orage_rc_exists_item(OrageRc *orc, char *key); +void orage_rc_del_item(OrageRc *orc, char *key); #endif /* !__ORAGE_FUNCTIONS_H__ */ Modified: xfcalendar/trunk/src/interface.c =================================================================== --- xfcalendar/trunk/src/interface.c 2008-03-05 04:47:56 UTC (rev 26667) +++ xfcalendar/trunk/src/interface.c 2008-03-06 14:44:26 UTC (rev 26668) @@ -323,7 +323,7 @@ rcfile = orage_data_file_location(NULL); f_chooser = orage_file_chooser(intf_w->main_window, TRUE - , g_par.orage_file, rcfile, ORAGE_APPFILE); + , g_par.orage_file, rcfile, ORAGE_APP_FILE); g_free(rcfile); if (gtk_dialog_run(GTK_DIALOG(f_chooser)) == GTK_RESPONSE_ACCEPT) { @@ -350,7 +350,7 @@ rcfile = orage_data_file_location(NULL); f_chooser = orage_file_chooser(intf_w->main_window, TRUE - , g_par.archive_file, rcfile, ORAGE_ARCFILE); + , g_par.archive_file, rcfile, ORAGE_ARC_FILE); g_free(rcfile); if (gtk_dialog_run(GTK_DIALOG(f_chooser)) == GTK_RESPONSE_ACCEPT) { Modified: xfcalendar/trunk/src/main.c =================================================================== --- xfcalendar/trunk/src/main.c 2008-03-05 04:47:56 UTC (rev 26667) +++ xfcalendar/trunk/src/main.c 2008-03-06 14:44:26 UTC (rev 26668) @@ -39,7 +39,6 @@ #endif #include <time.h> -#include <libxfce4util/libxfce4util.h> #include <libxfcegui4/libxfcegui4.h> #include <glib.h> Modified: xfcalendar/trunk/src/parameters.c =================================================================== --- xfcalendar/trunk/src/parameters.c 2008-03-05 04:47:56 UTC (rev 26667) +++ xfcalendar/trunk/src/parameters.c 2008-03-06 14:44:26 UTC (rev 26668) @@ -38,7 +38,6 @@ #include <gdk/gdk.h> #include <libxfcegui4/libxfcegui4.h> -#include <libxfce4util/libxfce4util.h> #include "functions.h" #include "tray_icon.h" @@ -867,146 +866,135 @@ return(dialog); } -void write_parameters() +OrageRc *orage_parameters_file_open(gboolean read_only) { gchar *fpath; - XfceRc *rc; + OrageRc *orc; + + fpath = orage_config_file_location(ORAGE_PAR_FILE); + if ((orc = (OrageRc *)orage_rc_file_open(fpath, read_only)) == NULL) { + orage_message(150, "orage_category_file_open: Parameter file open failed."); + } + g_free(fpath); + + return(orc); +} + +void write_parameters() +{ + OrageRc *orc; gint i; gchar f_par[50]; - fpath = xfce_resource_save_location(XFCE_RESOURCE_CONFIG - , ORAGE_DIR ORAGE_PARFILE, TRUE); - if ((rc = xfce_rc_simple_open(fpath, FALSE)) == NULL) { - g_warning("Unable to open RC file."); - return; - } - xfce_rc_write_entry(rc, "Timezone", g_par.local_timezone); + orc = orage_parameters_file_open(FALSE); + + orage_rc_put_str(orc, "Timezone", g_par.local_timezone); #ifdef HAVE_ARCHIVE - xfce_rc_write_int_entry(rc, "Archive limit", g_par.archive_limit); - xfce_rc_write_entry(rc, "Archive file", g_par.archive_file); + orage_rc_put_int(orc, "Archive limit", g_par.archive_limit); + orage_rc_put_str(orc, "Archive file", g_par.archive_file); #endif - xfce_rc_write_entry(rc, "Orage file", g_par.orage_file); - xfce_rc_write_entry(rc, "Sound application", g_par.sound_application); + orage_rc_put_str(orc, "Orage file", g_par.orage_file); + orage_rc_put_str(orc, "Sound application", g_par.sound_application); gtk_window_get_position(GTK_WINDOW(g_par.xfcal->mWindow) , &g_par.pos_x, &g_par.pos_y); - xfce_rc_write_int_entry(rc, "Main window X", g_par.pos_x); - xfce_rc_write_int_entry(rc, "Main window Y", g_par.pos_y); - xfce_rc_write_int_entry(rc, "Eventlist window X", g_par.el_size_x); - xfce_rc_write_int_entry(rc, "Eventlist window Y", g_par.el_size_y); - xfce_rc_write_bool_entry(rc, "Show Main Window Menu", g_par.show_menu); - xfce_rc_write_bool_entry(rc, "Select Always Today" + orage_rc_put_int(orc, "Main window X", g_par.pos_x); + orage_rc_put_int(orc, "Main window Y", g_par.pos_y); + orage_rc_put_int(orc, "Eventlist window X", g_par.el_size_x); + orage_rc_put_int(orc, "Eventlist window Y", g_par.el_size_y); + orage_rc_put_bool(orc, "Show Main Window Menu", g_par.show_menu); + orage_rc_put_bool(orc, "Select Always Today" , g_par.select_always_today); - xfce_rc_write_bool_entry(rc, "Show borders", g_par.show_borders); - xfce_rc_write_bool_entry(rc, "Show todos", g_par.show_todos); - xfce_rc_write_bool_entry(rc, "Show events", g_par.show_events); - xfce_rc_write_bool_entry(rc, "Show in pager", g_par.show_pager); - xfce_rc_write_bool_entry(rc, "Show in systray", g_par.show_systray); - xfce_rc_write_bool_entry(rc, "Show in taskbar", g_par.show_taskbar); - xfce_rc_write_bool_entry(rc, "Start visible", g_par.start_visible); - xfce_rc_write_bool_entry(rc, "Start minimized", g_par.start_minimized); - xfce_rc_write_bool_entry(rc, "Set sticked", g_par.set_stick); - xfce_rc_write_bool_entry(rc, "Set ontop", g_par.set_ontop); - xfce_rc_write_int_entry(rc, "Dynamic icon X", g_par.icon_size_x); - xfce_rc_write_int_entry(rc, "Dynamic icon Y", g_par.icon_size_y); + orage_rc_put_bool(orc, "Show borders", g_par.show_borders); + orage_rc_put_bool(orc, "Show todos", g_par.show_todos); + orage_rc_put_bool(orc, "Show events", g_par.show_events); + orage_rc_put_bool(orc, "Show in pager", g_par.show_pager); + orage_rc_put_bool(orc, "Show in systray", g_par.show_systray); + orage_rc_put_bool(orc, "Show in taskbar", g_par.show_taskbar); + orage_rc_put_bool(orc, "Start visible", g_par.start_visible); + orage_rc_put_bool(orc, "Start minimized", g_par.start_minimized); + orage_rc_put_bool(orc, "Set sticked", g_par.set_stick); + orage_rc_put_bool(orc, "Set ontop", g_par.set_ontop); + orage_rc_put_int(orc, "Dynamic icon X", g_par.icon_size_x); + orage_rc_put_int(orc, "Dynamic icon Y", g_par.icon_size_y); /* we write this with X so that we do not read it back unless * it is manually changed. It should need changes really seldom. */ - xfce_rc_write_int_entry(rc, "XIcal week start day" + orage_rc_put_int(orc, "XIcal week start day" , g_par.ical_weekstartday); - xfce_rc_write_bool_entry(rc, "Show days", g_par.show_days); - xfce_rc_write_int_entry(rc, "Foreign file count", g_par.foreign_count); + orage_rc_put_bool(orc, "Show days", g_par.show_days); + orage_rc_put_int(orc, "Foreign file count", g_par.foreign_count); /* add what we have and remove the rest */ for (i = 0; i < g_par.foreign_count; i++) { g_sprintf(f_par, "Foreign file %02d name", i); - xfce_rc_write_entry(rc, f_par, g_par.foreign_data[i].file); + orage_rc_put_str(orc, f_par, g_par.foreign_data[i].file); g_sprintf(f_par, "Foreign file %02d read-only", i); - xfce_rc_write_bool_entry(rc, f_par, g_par.foreign_data[i].read_only); + orage_rc_put_bool(orc, f_par, g_par.foreign_data[i].read_only); } for (i = g_par.foreign_count; i < 10; i++) { g_sprintf(f_par, "Foreign file %02d name", i); - if (!xfce_rc_has_entry(rc, f_par)) + if (!orage_rc_exists_item(orc, f_par)) break; /* it is in order, so we know that the rest are missing */ - xfce_rc_delete_entry(rc, f_par, TRUE); + orage_rc_del_item(orc, f_par); g_sprintf(f_par, "Foreign file %02d read-only", i); - xfce_rc_delete_entry(rc, f_par, TRUE); + orage_rc_del_item(orc, f_par); } - xfce_rc_write_int_entry(rc, "Logging level", g_par.log_level); + orage_rc_put_int(orc, "Logging level", g_par.log_level); - g_free(fpath); - xfce_rc_close(rc); + orage_rc_file_close(orc); } void read_parameters(void) { - gchar *fpath, *fpath2; - XfceRc *rc; + gchar *fpath; + OrageRc *orc; gint i; gchar f_par[100]; - fpath = xfce_resource_save_location(XFCE_RESOURCE_CONFIG - , ORAGE_DIR ORAGE_PARFILE, TRUE); + orc = orage_parameters_file_open(TRUE); - if ((rc = xfce_rc_simple_open(fpath, TRUE)) == NULL) { - g_warning("Unable to open (read) RC file."); - /* let's try to build it */ - if ((rc = xfce_rc_simple_open(fpath, FALSE)) == NULL) { - /* still failed, can't do more */ - g_warning("Unable to open (write) RC file."); - return; - } - } - g_par.local_timezone = - g_strdup(xfce_rc_read_entry(rc, "Timezone", "floating")); + g_par.local_timezone = orage_rc_get_str(orc, "Timezone", "floating"); #ifdef HAVE_ARCHIVE - g_par.archive_limit = xfce_rc_read_int_entry(rc, "Archive limit", 0); - fpath2 = orage_data_file_location(ORAGE_ARCFILE); - g_par.archive_file = - g_strdup(xfce_rc_read_entry(rc, "Archive file", fpath2)); - g_free(fpath2); + g_par.archive_limit = orage_rc_get_int(orc, "Archive limit", 0); + fpath = orage_data_file_location(ORAGE_ARC_FILE); + g_par.archive_file = orage_rc_get_str(orc, "Archive file", fpath); + g_free(fpath); #endif - fpath2 = orage_data_file_location(ORAGE_APPFILE); - g_par.orage_file = g_strdup(xfce_rc_read_entry(rc, "Orage file", fpath2)); - g_free(fpath2); - g_par.sound_application = - g_strdup(xfce_rc_read_entry(rc, "Sound application", "play")); - g_par.pos_x = xfce_rc_read_int_entry(rc, "Main window X", 0); - g_par.pos_y = xfce_rc_read_int_entry(rc, "Main window Y", 0); - g_par.el_size_x = xfce_rc_read_int_entry(rc, "Eventlist window X", 500); - g_par.el_size_y = xfce_rc_read_int_entry(rc, "Eventlist window Y", 350); - g_par.show_menu = - xfce_rc_read_bool_entry(rc, "Show Main Window Menu", TRUE); + fpath = orage_data_file_location(ORAGE_APP_FILE); + g_par.orage_file = orage_rc_get_str(orc, "Orage file", fpath); + g_free(fpath); + g_par.sound_application=orage_rc_get_str(orc, "Sound application", "play"); + g_par.pos_x = orage_rc_get_int(orc, "Main window X", 0); + g_par.pos_y = orage_rc_get_int(orc, "Main window Y", 0); + g_par.el_size_x = orage_rc_get_int(orc, "Eventlist window X", 500); + g_par.el_size_y = orage_rc_get_int(orc, "Eventlist window Y", 350); + g_par.show_menu = orage_rc_get_bool(orc, "Show Main Window Menu", TRUE); g_par.select_always_today = - xfce_rc_read_bool_entry(rc, "Select Always Today", FALSE); - g_par.show_borders = xfce_rc_read_bool_entry(rc, "Show borders", TRUE); - g_par.show_todos = xfce_rc_read_bool_entry(rc, "Show todos", TRUE); - g_par.show_events = xfce_rc_read_bool_entry(rc, "Show events", TRUE); - g_par.show_pager = xfce_rc_read_bool_entry(rc, "Show in pager", TRUE); - g_par.show_systray = xfce_rc_read_bool_entry(rc, "Show in systray", TRUE); - g_par.show_taskbar = xfce_rc_read_bool_entry(rc, "Show in taskbar", TRUE); - g_par.start_visible = xfce_rc_read_bool_entry(rc, "Start visible", TRUE); - g_par.start_minimized = - xfce_rc_read_bool_entry(rc, "Start minimized", FALSE); - g_par.set_stick = xfce_rc_read_bool_entry(rc, "Set sticked", TRUE); - g_par.set_ontop = xfce_rc_read_bool_entry(rc, "Set ontop", FALSE); - g_par.icon_size_x = xfce_rc_read_int_entry(rc, "Dynamic icon X", 42); - g_par.icon_size_y = xfce_rc_read_int_entry(rc, "Dynamic icon Y", 32); + orage_rc_get_bool(orc, "Select Always Today", FALSE); + g_par.show_borders = orage_rc_get_bool(orc, "Show borders", TRUE); + g_par.show_todos = orage_rc_get_bool(orc, "Show todos", TRUE); + g_par.show_events = orage_rc_get_bool(orc, "Show events", TRUE); + g_par.show_pager = orage_rc_get_bool(orc, "Show in pager", TRUE); + g_par.show_systray = orage_rc_get_bool(orc, "Show in systray", TRUE); + g_par.show_taskbar = orage_rc_get_bool(orc, "Show in taskbar", TRUE); + g_par.start_visible = orage_rc_get_bool(orc, "Start visible", TRUE); + g_par.start_minimized = orage_rc_get_bool(orc, "Start minimized", FALSE); + g_par.set_stick = orage_rc_get_bool(orc, "Set sticked", TRUE); + g_par.set_ontop = orage_rc_get_bool(orc, "Set ontop", FALSE); + g_par.icon_size_x = orage_rc_get_int(orc, "Dynamic icon X", 42); + g_par.icon_size_y = orage_rc_get_int(orc, "Dynamic icon Y", 32); /* 0 = monday, ..., 6 = sunday */ - g_par.ical_weekstartday = xfce_rc_read_int_entry(rc, "Ical week start day" + g_par.ical_weekstartday = orage_rc_get_int(orc, "Ical week start day" , get_first_weekday_from_locale()); - g_par.show_days = xfce_rc_read_bool_entry(rc, "Show days", FALSE); - g_par.foreign_count = - xfce_rc_read_int_entry(rc, "Foreign file count", 0); + g_par.show_days = orage_rc_get_bool(orc, "Show days", FALSE); + g_par.foreign_count = orage_rc_get_int(orc, "Foreign file count", 0); for (i = 0; i < g_par.foreign_count; i++) { g_sprintf(f_par, "Foreign file %02d name", i); - g_par.foreign_data[i].file = - g_strdup(xfce_rc_read_entry(rc, f_par, NULL)); + g_par.foreign_data[i].file = orage_rc_get_str(orc, f_par, NULL); g_sprintf(f_par, "Foreign file %02d read-only", i); - g_par.foreign_data[i].read_only = - xfce_rc_read_bool_entry(rc, f_par, TRUE); + g_par.foreign_data[i].read_only = orage_rc_get_bool(orc, f_par, TRUE); } - g_par.log_level = xfce_rc_read_int_entry(rc, "Logging level", 0); + g_par.log_level = orage_rc_get_int(orc, "Logging level", 0); - g_free(fpath); - xfce_rc_close(rc); + orage_rc_file_close(orc); } void show_parameters() Modified: xfcalendar/trunk/src/reminder.c =================================================================== --- xfcalendar/trunk/src/reminder.c 2008-03-05 04:47:56 UTC (rev 26667) +++ xfcalendar/trunk/src/reminder.c 2008-03-06 14:44:26 UTC (rev 26668) @@ -57,7 +57,6 @@ #include "tray_icon.h" #include "parameters.h" -#define ORAGE_PERSISTENT_ALARMS "orage_persistent_alarms.txt" static void create_notify_reminder(alarm_struct *alarm); static void create_reminders(alarm_struct *alarm); @@ -106,116 +105,73 @@ alarm->repeat_cnt = 0; } -static int orage_persistent_file_open(gboolean write) -{ - int p_file; - char *file_name; +/************************************************************/ +/* persistent alarms start */ +/************************************************************/ - file_name = orage_data_file_location(ORAGE_PERSISTENT_ALARMS); - if (!file_name) { - g_warning("orage_persistent_file_open: Persistent alarms filename build failed, alarms not saved (%s)\n", file_name); - return(-1); - } - if (write) - p_file = g_open(file_name, O_WRONLY|O_CREAT|O_APPEND|O_TRUNC - , S_IRUSR|S_IWUSR); - else - p_file = g_open(file_name, O_RDONLY|O_CREAT, S_IRUSR|S_IWUSR); - g_free(file_name); - if (p_file == -1) - g_warning("orage_persistent_file_open: Persistent alarms file open failed, alarms not saved (%s)\n", file_name); - return(p_file); -} - -static gboolean alarm_read_next_value(int p_file, char *buf) +static OrageRc *orage_persistent_file_open(gboolean read_only) { #undef P_N -#define P_N "alarm_read_next_value: " - int len; +#define P_N "orage_persistent_file_open: " + gchar *fpath; + OrageRc *orc; #ifdef ORAGE_DEBUG g_print(P_N "\n"); #endif - if (read(p_file, buf, 3) == 0) - return(FALSE); - buf[3] = '\0'; - len = atoi(buf); - for (read(p_file, buf, 1); buf[0] != '='; read(p_file, buf, 1)) - ; /* skip until =, which starts the value */ - read(p_file, buf, len); - buf[len] = '\0'; - lseek(p_file, 1, SEEK_CUR); /* skip new line */ - return(TRUE); -} + fpath = orage_data_file_location(ORAGE_PERSISTENT_ALARMS_FILE); + if (!read_only) /* we need to empty it before each write */ + g_remove(fpath); + if ((orc = (OrageRc *)orage_rc_file_open(fpath, read_only)) == NULL) { + orage_message(150, "orage_persistent_file_open: persistent alarms file open failed."); + } + g_free(fpath); -static gboolean alarm_read_boolean(char *buf) -{ - if (!strncmp(buf, "TRUE", 4)) - return(TRUE); - else - return(FALSE); + return(orc); } -static alarm_struct *alarm_read_next_alarm(int p_file, char *buf) +static alarm_struct *alarm_read_next_alarm(OrageRc *orc, gchar *time_now) { #undef P_N #define P_N "alarm_read_next_alarm: " alarm_struct *new_alarm; + gchar *alarm_time; #ifdef ORAGE_DEBUG g_print(P_N "\n"); #endif - /* We trust here that the order is the same than what we used in writing */ - if (!alarm_read_next_value(p_file, buf)) + /* let's first check if the time has gone so that we need to + * send that delayed alarm or can we just ignore it since it is + * still in the future */ + alarm_time = orage_rc_get_str(orc, "ALARM_TIME", "0000"); + if (strcmp(time_now, alarm_time) < 0) { /* alarm has not happened, ignore */ + g_free(alarm_time); return(NULL); + } + + /* this alarm has gone, so read it and show it */ new_alarm = g_new0(alarm_struct, 1); + new_alarm->alarm_time = alarm_time; - new_alarm->alarm_time = strdup(buf); - - alarm_read_next_value(p_file, buf); - new_alarm->uid = strdup(buf); - - alarm_read_next_value(p_file, buf); - new_alarm->title = strdup(buf); - - alarm_read_next_value(p_file, buf); - new_alarm->description = strdup(buf); - - alarm_read_next_value(p_file, buf); + new_alarm->title = orage_rc_get_str(orc, "TITLE", NULL); + new_alarm->description = orage_rc_get_str(orc, "DESCRIPTION", NULL); new_alarm->persistent = TRUE; /* this must be */ + new_alarm->display_orage = orage_rc_get_bool(orc, "DISPLAY_ORAGE", FALSE); - alarm_read_next_value(p_file, buf); - new_alarm->display_orage = alarm_read_boolean(buf); - #ifdef HAVE_NOTIFY - alarm_read_next_value(p_file, buf); - new_alarm->display_notify = alarm_read_boolean(buf); - - alarm_read_next_value(p_file, buf); - new_alarm->notify_refresh = alarm_read_boolean(buf); - - alarm_read_next_value(p_file, buf); - new_alarm->notify_timeout = atoi(buf); + new_alarm->display_notify = orage_rc_get_bool(orc, "DISPLAY_NOTIFY", FALSE); + new_alarm->notify_refresh = orage_rc_get_bool(orc, "NOTIFY_REFRESH", FALSE); + new_alarm->notify_timeout = orage_rc_get_int(orc, "NOTIFY_TIMEOUT", FALSE); #endif - alarm_read_next_value(p_file, buf); - new_alarm->audio = alarm_read_boolean(buf); + new_alarm->audio = orage_rc_get_bool(orc, "AUDIO", FALSE); + new_alarm->sound = orage_rc_get_str(orc, "SOUND", NULL); + new_alarm->repeat_cnt = orage_rc_get_int(orc, "REPEAT_CNT", 0); + new_alarm->repeat_delay = orage_rc_get_int(orc, "REPEAT_DELAY", 2); + new_alarm->procedure = orage_rc_get_bool(orc, "PROCEDURE", FALSE); + new_alarm->cmd = orage_rc_get_str(orc, "CMD", NULL); - alarm_read_next_value(p_file, buf); - new_alarm->sound = strdup(buf); - - alarm_read_next_value(p_file, buf); - new_alarm->repeat_cnt = atoi(buf); - - alarm_read_next_value(p_file, buf); - new_alarm->repeat_delay = atoi(buf); - - alarm_read_next_value(p_file, buf); - new_alarm->procedure = alarm_read_boolean(buf); - - alarm_read_next_value(p_file, buf); - new_alarm->cmd = strdup(buf); return(new_alarm); } @@ -223,37 +179,39 @@ { #undef P_N #define P_N "alarm_read: " - int p_file; - char buf[1000]; alarm_struct *new_alarm; + OrageRc *orc; struct tm *t; gchar *time_now; + gchar **alarm_groups; + gint i; #ifdef ORAGE_DEBUG g_print(P_N "\n"); #endif - if ((p_file = orage_persistent_file_open(FALSE)) == -1) - return; t = orage_localtime(); time_now = orage_tm_time_to_icaltime(t); - for (new_alarm = alarm_read_next_alarm(p_file, buf); - new_alarm; - new_alarm = alarm_read_next_alarm(p_file, buf)) { - if (strcmp(time_now, new_alarm->alarm_time) > 0) { + orc = orage_persistent_file_open(TRUE); + alarm_groups = orage_rc_get_groups(orc); + /* alarm_groups[0] is special [NULL] entry always */ + for (i=1; alarm_groups[i] != NULL; i++) { + orage_rc_set_group(orc, alarm_groups[i]); + if ((new_alarm = alarm_read_next_alarm(orc, time_now)) != NULL) { + new_alarm->uid = alarm_groups[i]; create_reminders(new_alarm); + alarm_free(new_alarm, NULL); } - alarm_free(new_alarm, NULL); } - close(p_file); + orage_rc_file_close(orc); } -static void alarm_store(gpointer galarm, gpointer gfile) +static void alarm_store(gpointer galarm, gpointer par) { #undef P_N #define P_N "alarm_store: " alarm_struct *alarm = (alarm_struct *)galarm; - int file = (int)gfile; + OrageRc *orc = (OrageRc *)par; char buf[1000], *s_boolean, s_num[20]; #ifdef ORAGE_DEBUG @@ -262,90 +220,47 @@ if (!alarm->persistent) return; /* only store persistent alarms */ - g_sprintf(buf, "%03dALARM_TIME=%s\n" - , strlen(alarm->alarm_time), alarm->alarm_time); - write(file, buf, strlen(buf)); + orage_rc_set_group(par, alarm->uid); - g_snprintf(buf, 999, "%03dUID=%s\n" - , strlen(alarm->uid), alarm->uid); - write(file, buf, strlen(buf)); + orage_rc_put_str(orc, "ALARM_TIME", alarm->alarm_time); + orage_rc_put_str(orc, "TITLE", alarm->title); + orage_rc_put_str(orc, "DESCRIPTION", alarm->description); + orage_rc_put_bool(orc, "DISPLAY_ORAGE", alarm->display_orage); - g_snprintf(buf, 999, "%03dTITLE=%s\n" - , strlen(alarm->title), alarm->title); - write(file, buf, strlen(buf)); - - g_snprintf(buf, 999, "%03dDESCRIPTION=%s\n" - , strlen(alarm->description), alarm->description); - write(file, buf, strlen(buf)); - - /* this is TRUE since we are here */ - g_sprintf(buf, "%03dPERSISTENT=%s\n", strlen("TRUE"), "TRUE"); - write(file, buf, strlen(buf)); - - s_boolean = alarm->display_orage ? "TRUE" : "FALSE"; - g_sprintf(buf, "%03dDISPLAY_ORAGE=%s\n", strlen(s_boolean), s_boolean); - write(file, buf, strlen(buf)); - #ifdef HAVE_NOTIFY - s_boolean = alarm->display_notify ? "TRUE" : "FALSE"; - g_sprintf(buf, "%03dDISPLAY_NOTIFY=%s\n", strlen(s_boolean), s_boolean); - write(file, buf, strlen(buf)); - - s_boolean = alarm->notify_refresh ? "TRUE" : "FALSE"; - g_sprintf(buf, "%03dNOTIFY_REFRESH=%s\n", strlen(s_boolean), s_boolean); - write(file, buf, strlen(buf)); - - g_sprintf(s_num, "%d", alarm->notify_timeout); - g_sprintf(buf, "%03dNOTIFY_TIMEOUT=%s\n", strlen(s_num), s_num); - write(file, buf, strlen(buf)); + orage_rc_put_bool(orc, "DISPLAY_NOTIFY", alarm->display_notify); + /* FIXME: is NOTIFY_REFRESH really needed here? I doubt that. + * Probably should be set to TRUE ?? */ + orage_rc_put_bool(orc, "NOTIFY_REFRESH", alarm->notify_refresh); + orage_rc_put_int(orc, "NOTIFY_TIMEOUT", alarm->notify_timeout); #endif - s_boolean = alarm->audio ? "TRUE" : "FALSE"; - g_sprintf(buf, "%03dAUDIO=%s\n", strlen(s_boolean), s_boolean); - write(file, buf, strlen(buf)); - - if (alarm->audio) - g_snprintf(buf, 999, "%03dSOUND=%s\n" - , strlen(alarm->sound), alarm->sound); - else - g_sprintf(buf, "000SOUND=\n"); - write(file, buf, strlen(buf)); - - g_sprintf(s_num, "%d", alarm->repeat_cnt); - g_sprintf(buf, "%03dREPEAT_CNT=%s\n", strlen(s_num), s_num); - write(file, buf, strlen(buf)); - - g_sprintf(s_num, "%d", alarm->repeat_delay); - g_sprintf(buf, "%03dREPEAT_DELAY=%s\n", strlen(s_num), s_num); - write(file, buf, strlen(buf)); - - s_boolean = alarm->procedure ? "TRUE" : "FALSE"; - g_sprintf(buf, "%03dPROCEDURE=%s\n", strlen(s_boolean), s_boolean); - write(file, buf, strlen(buf)); - - if (alarm->procedure) - g_snprintf(buf, 999, "%03dCMD=%s\n" - , strlen(alarm->cmd), alarm->cmd); - else - g_sprintf(buf, "000CMD=\n"); - write(file, buf, strlen(buf)); + orage_rc_put_bool(orc, "AUDIO", alarm->audio); + orage_rc_put_str(orc, "SOUND", alarm->sound); + orage_rc_put_int(orc, "REPEAT_CNT", alarm->repeat_cnt); + orage_rc_put_int(orc, "REPEAT_DELAY", alarm->repeat_delay); + orage_rc_put_bool(orc, "PROCEDURE", alarm->procedure); + orage_rc_put_str(orc, "CMD", alarm->cmd); } static void store_persistent_alarms() { #undef P_N #define P_N "store_persistent_alarms: " - int p_file; + OrageRc *orc; #ifdef ORAGE_DEBUG g_print(P_N "\n"); #endif - if ((p_file = orage_persistent_file_open(TRUE)) == -1) - return; - g_list_foreach(g_par.alarm_list, alarm_store, (gpointer)p_file); - close(p_file); + orc = orage_persistent_file_open(FALSE); + g_list_foreach(g_par.alarm_list, alarm_store, (gpointer)orc); + orage_rc_file_close(orc); } +/************************************************************/ +/* persistent alarms end */ +/************************************************************/ + #ifdef HAVE_NOTIFY static void notify_action_open(NotifyNotification *n, const char *action , gpointer par) Modified: xfcalendar/trunk/src/tray_icon.c =================================================================== --- xfcalendar/trunk/src/tray_icon.c 2008-03-05 04:47:56 UTC (rev 26667) +++ xfcalendar/trunk/src/tray_icon.c 2008-03-06 14:44:26 UTC (rev 26668) @@ -33,7 +33,6 @@ #include <gdk/gdk.h> #include <gtk/gtk.h> #include <glib/gprintf.h> -#include <libxfce4util/libxfce4util.h> #include <libxfcegui4/libxfcegui4.h> #include <libxfcegui4/netk-trayicon.h> _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits