Author: juha Date: 2007-01-29 22:48:57 +0000 (Mon, 29 Jan 2007) New Revision: 24797
Modified: xfcalendar/trunk/src/appointment.c xfcalendar/trunk/src/ical-code.c xfcalendar/trunk/src/ical-code.h xfcalendar/trunk/src/interface.h xfcalendar/trunk/src/main.c xfcalendar/trunk/src/mainbox.c xfcalendar/trunk/src/parameters.c xfcalendar/trunk/src/parameters.h Log: combining common code & cleaning Modified: xfcalendar/trunk/src/appointment.c =================================================================== --- xfcalendar/trunk/src/appointment.c 2007-01-29 20:46:52 UTC (rev 24796) +++ xfcalendar/trunk/src/appointment.c 2007-01-29 22:48:57 UTC (rev 24797) @@ -62,12 +62,6 @@ static void fill_appt_window(appt_win *apptw, char *action, char *par); -enum { - LOCATION, - LOCATION_ENG, - N_COLUMNS -}; - static gboolean ical_to_year_month_day_hour_minute(char *ical , int *year, int *month, int *day, int *hour, int *minute) { @@ -1019,153 +1013,40 @@ gtk_widget_destroy(selDate_Window_dialog); } -static void on_appTimezone_clicked_cb(GtkWidget *button, appt_win *apptw - , gchar **tz) -{ -#define MAX_AREA_LENGTH 20 - GtkTreeStore *store; - GtkTreeIter iter1, iter2; - GtkWidget *tree; - GtkCellRenderer *rend; - GtkTreeViewColumn *col; - GtkWidget *window; - GtkWidget *sw; - xfical_timezone_array tz_a; - int i, j, result; - char area_old[MAX_AREA_LENGTH], *loc, *loc_eng, *loc_int; - GtkTreeSelection *sel; - GtkTreeModel *model; - GtkTreeIter iter; - - /* enter data */ - store = gtk_tree_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING); - strcpy(area_old, "S T a R T"); - tz_a = xfical_get_timezones(); - for (i=0; i < tz_a.count-2; i++) { - /* first area */ - if (! g_str_has_prefix(tz_a.city[i], area_old)) { - for (j=0; tz_a.city[i][j] != '/' && j < MAX_AREA_LENGTH; j++) { - area_old[j] = tz_a.city[i][j]; - } - if (j < MAX_AREA_LENGTH) - area_old[j] = 0; - else - g_warning("on_appStartEndTimezone_clicked_cb: too long line in zones.tab %s", tz_a.city[i]); - - gtk_tree_store_append(store, &iter1, NULL); - gtk_tree_store_set(store, &iter1 - , LOCATION, _(area_old) - , LOCATION_ENG, area_old - , -1); - } - /* then city translated and in base form used internally */ - gtk_tree_store_append(store, &iter2, &iter1); - gtk_tree_store_set(store, &iter2 - , LOCATION, _(tz_a.city[i]) - , LOCATION_ENG, tz_a.city[i] - , -1); - } - - /* create view */ - tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); - rend = gtk_cell_renderer_text_new(); - col = gtk_tree_view_column_new_with_attributes(_("Location") - , rend, "text", LOCATION, NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(tree), col); - - rend = gtk_cell_renderer_text_new(); - col = gtk_tree_view_column_new_with_attributes(_("Location") - , rend, "text", LOCATION_ENG, NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(tree), col); - gtk_tree_view_column_set_visible(col, FALSE); - - /* show it */ - window = gtk_dialog_new_with_buttons(_("Pick timezone") - , GTK_WINDOW(apptw->Window) - , GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT - , _("UTC"), 1 - , _("floating"), 2 - , GTK_STOCK_OK, GTK_RESPONSE_ACCEPT - , NULL); - sw = gtk_scrolled_window_new(NULL, NULL); - gtk_container_add(GTK_CONTAINER(sw), tree); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), sw, TRUE, TRUE, 0); - gtk_window_set_default_size(GTK_WINDOW(window), 300, 500); - - gtk_widget_show_all(window); - do { - result = gtk_dialog_run(GTK_DIALOG(window)); - switch (result) { - case GTK_RESPONSE_ACCEPT: - sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)); - if (gtk_tree_selection_get_selected(sel, &model, &iter)) - if (gtk_tree_model_iter_has_child(model, &iter)) - result = 0; - else { - gtk_tree_model_get(model, &iter, LOCATION, &loc, -1); - gtk_tree_model_get(model, &iter, LOCATION_ENG - , &loc_eng, -1); - } - else { - loc = g_strdup(_(*tz)); - loc_eng = g_strdup((*tz)); - } - break; - case 1: - loc = g_strdup(_("UTC")); - loc_eng = g_strdup("UTC"); - break; - case 2: - loc = g_strdup(_("floating")); - loc_eng = g_strdup("floating"); - break; - default: - loc = g_strdup(_(*tz)); - loc_eng = g_strdup((*tz)); - break; - } - } while (result == 0) ; - if (g_ascii_strcasecmp((gchar *)loc - , (gchar *)gtk_button_get_label(GTK_BUTTON(button))) != 0) { - mark_appointment_changed(apptw); - } - gtk_button_set_label(GTK_BUTTON(button), loc); - if (*tz) - g_free(*tz); - *tz = g_strdup(loc_eng); - g_free(loc); - g_free(loc_eng); - gtk_widget_destroy(window); -} - -static void on_appStartTimezone_clicked_cb(GtkWidget *button +static void on_appStartTimezone_clicked_cb(GtkButton *button , gpointer *user_data) { appt_win *apptw = (appt_win *)user_data; appt_data *appt; appt = apptw->appt; - on_appTimezone_clicked_cb(button, apptw, &appt->start_tz_loc); + if (xfical_timezone_button_clicked(button, GTK_WINDOW(apptw->Window) + , &appt->start_tz_loc)) + mark_appointment_changed(apptw); } -static void on_appEndTimezone_clicked_cb(GtkWidget *button +static void on_appEndTimezone_clicked_cb(GtkButton *button , gpointer *user_data) { appt_win *apptw = (appt_win *)user_data; appt_data *appt; appt = apptw->appt; - on_appTimezone_clicked_cb(button, apptw, &appt->end_tz_loc); + if (xfical_timezone_button_clicked(button, GTK_WINDOW(apptw->Window) + , &appt->end_tz_loc)) + mark_appointment_changed(apptw); } -static void on_appCompletedTimezone_clicked_cb(GtkWidget *button +static void on_appCompletedTimezone_clicked_cb(GtkButton *button , gpointer *user_data) { appt_win *apptw = (appt_win *)user_data; appt_data *appt; appt = apptw->appt; - on_appTimezone_clicked_cb(button, apptw, &appt->completed_tz_loc); + if (xfical_timezone_button_clicked(button, GTK_WINDOW(apptw->Window) + , &appt->completed_tz_loc)) + mark_appointment_changed(apptw); } static void fill_appt_window_times(appt_win *apptw, appt_data *appt) Modified: xfcalendar/trunk/src/ical-code.c =================================================================== --- xfcalendar/trunk/src/ical-code.c 2007-01-29 20:46:52 UTC (rev 24796) +++ xfcalendar/trunk/src/ical-code.c 2007-01-29 22:48:57 UTC (rev 24797) @@ -73,6 +73,12 @@ struct icaltimetype ctime; /* completed time for VTODO appointmnets */ } xfical_period; +typedef struct +{ + int count; /* how many timezones we have */ + char **city; /* pointer to timezone location name strings */ +} xfical_timezone_array; + static icalcomponent *ical = NULL, *aical = NULL; static icalset *fical = NULL, @@ -472,7 +478,7 @@ N_("Pacific/Yap"), }; -xfical_timezone_array xfical_get_timezones() +static xfical_timezone_array xfical_get_timezones() { static xfical_timezone_array tz={0, NULL}; static char tz_utc[]="UTC"; @@ -3033,3 +3039,129 @@ } return(NULL); } + +gboolean xfical_timezone_button_clicked(GtkButton *button, GtkWindow *parent + , gchar **tz) +{ +#define MAX_AREA_LENGTH 20 + +enum { + LOCATION, + LOCATION_ENG, + N_COLUMNS +}; + + GtkTreeStore *store; + GtkTreeIter iter1, iter2; + GtkWidget *tree; + GtkCellRenderer *rend; + GtkTreeViewColumn *col; + GtkWidget *window; + GtkWidget *sw; + xfical_timezone_array tz_a; + int i, j, result; + char area_old[MAX_AREA_LENGTH], *loc, *loc_eng; + GtkTreeSelection *sel; + GtkTreeModel *model; + GtkTreeIter iter; + gboolean changed = FALSE; + + /* enter data */ + store = gtk_tree_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING); + strcpy(area_old, "S T a R T"); + tz_a = xfical_get_timezones(); + for (i=0; i < tz_a.count-2; i++) { + /* first area */ + if (! g_str_has_prefix(tz_a.city[i], area_old)) { + for (j=0; tz_a.city[i][j] != '/' && j < MAX_AREA_LENGTH; j++) { + area_old[j] = tz_a.city[i][j]; + } + if (j < MAX_AREA_LENGTH) + area_old[j] = 0; + else + g_warning("xfical_timezone_button_clicked: too long line in zones.tab %s", tz_a.city[i]); + + gtk_tree_store_append(store, &iter1, NULL); + gtk_tree_store_set(store, &iter1 + , LOCATION, _(area_old) + , LOCATION_ENG, area_old + , -1); + } + /* then city translated and in base form used internally */ + gtk_tree_store_append(store, &iter2, &iter1); + gtk_tree_store_set(store, &iter2 + , LOCATION, _(tz_a.city[i]) + , LOCATION_ENG, tz_a.city[i] + , -1); + } + + /* create view */ + tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); + rend = gtk_cell_renderer_text_new(); + col = gtk_tree_view_column_new_with_attributes(_("Location") + , rend, "text", LOCATION, NULL); + gtk_tree_view_append_column(GTK_TREE_VIEW(tree), col); + + rend = gtk_cell_renderer_text_new(); + col = gtk_tree_view_column_new_with_attributes(_("Location") + , rend, "text", LOCATION_ENG, NULL); + gtk_tree_view_append_column(GTK_TREE_VIEW(tree), col); + gtk_tree_view_column_set_visible(col, FALSE); + + /* show it */ + window = gtk_dialog_new_with_buttons(_("Pick timezone") + , parent + , GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT + , _("UTC"), 1 + , _("floating"), 2 + , GTK_STOCK_OK, GTK_RESPONSE_ACCEPT + , NULL); + sw = gtk_scrolled_window_new(NULL, NULL); + gtk_container_add(GTK_CONTAINER(sw), tree); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), sw, TRUE, TRUE, 0); + gtk_window_set_default_size(GTK_WINDOW(window), 300, 500); + + gtk_widget_show_all(window); + do { + result = gtk_dialog_run(GTK_DIALOG(window)); + switch (result) { + case GTK_RESPONSE_ACCEPT: + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)); + if (gtk_tree_selection_get_selected(sel, &model, &iter)) + if (gtk_tree_model_iter_has_child(model, &iter)) + result = 0; + else { + gtk_tree_model_get(model, &iter, LOCATION, &loc, -1); + gtk_tree_model_get(model, &iter, LOCATION_ENG, &loc_eng + , -1); } + else { + loc = g_strdup(_(*tz)); + loc_eng = g_strdup(*tz); + } + break; + case 1: + loc = g_strdup(_("UTC")); + loc_eng = g_strdup("UTC"); + break; + case 2: + loc = g_strdup(_("floating")); + loc_eng = g_strdup("floating"); + break; + default: + loc = g_strdup(_(*tz)); + loc_eng = g_strdup(*tz); + break; + } + } while (result == 0); + if (g_ascii_strcasecmp(loc, (gchar *)gtk_button_get_label(button)) != 0) + changed = TRUE; + gtk_button_set_label(button, loc); + + if (*tz) + g_free(*tz); + *tz = g_strdup(loc_eng); + g_free(loc); + g_free(loc_eng); + gtk_widget_destroy(window); + return(changed); +} Modified: xfcalendar/trunk/src/ical-code.h =================================================================== --- xfcalendar/trunk/src/ical-code.h 2007-01-29 20:46:52 UTC (rev 24796) +++ xfcalendar/trunk/src/ical-code.h 2007-01-29 22:48:57 UTC (rev 24797) @@ -24,17 +24,8 @@ #ifndef __ICAL_CODE_H__ #define __ICAL_CODE_H__ -#include "appointment.h" - #define ORAGE_UID_LEN 200 -typedef struct -{ - int count; /* how many timezones we have */ - char **city; /* pointer to timezone location name strings */ -} xfical_timezone_array; -xfical_timezone_array xfical_get_timezones(); - gboolean xfical_set_local_timezone(); gboolean xfical_file_open(void); @@ -65,4 +56,7 @@ gboolean xfical_import_file(char *file_name); gboolean xfical_export_file(char *file_name, int type, char *uids); +gboolean xfical_timezone_button_clicked(GtkButton *button, GtkWindow *parent + , gchar **tz); + #endif /* !__ICAL_CODE_H__ */ Modified: xfcalendar/trunk/src/interface.h =================================================================== --- xfcalendar/trunk/src/interface.h 2007-01-29 20:46:52 UTC (rev 24796) +++ xfcalendar/trunk/src/interface.h 2007-01-29 22:48:57 UTC (rev 24797) @@ -23,9 +23,6 @@ #ifndef __INTERFACE_H__ #define __INTERFACE_H__ -#include <gtk/gtk.h> -#include <gdk/gdk.h> - typedef struct { GtkWidget *main_window; Modified: xfcalendar/trunk/src/main.c =================================================================== --- xfcalendar/trunk/src/main.c 2007-01-29 20:46:52 UTC (rev 24796) +++ xfcalendar/trunk/src/main.c 2007-01-29 22:48:57 UTC (rev 24797) @@ -48,14 +48,15 @@ #define ORAGE_MAIN "orage" +#include "mainbox.h" #include "functions.h" -#include "mainbox.h" #include "event-list.h" #include "xfce_trayicon.h" #include "tray_icon.h" #include "reminder.h" +#include "appointment.h" +#include "parameters.h" #include "ical-code.h" -#include "parameters.h" #include "orage-dbus.h" Modified: xfcalendar/trunk/src/mainbox.c =================================================================== --- xfcalendar/trunk/src/mainbox.c 2007-01-29 20:46:52 UTC (rev 24796) +++ xfcalendar/trunk/src/mainbox.c 2007-01-29 22:48:57 UTC (rev 24797) @@ -55,13 +55,13 @@ { guint year, month, day; - if (xfical_file_open()) { - gtk_calendar_get_date(GTK_CALENDAR(g_par.xfcal->mCalendar) - , &year, &month, &day); - xfical_mark_calendar(GTK_CALENDAR(g_par.xfcal->mCalendar) - , year, month+1); - xfical_file_close(); - } + if (!xfical_file_open()) + return(FALSE); + gtk_calendar_get_date(GTK_CALENDAR(g_par.xfcal->mCalendar) + , &year, &month, &day); + xfical_mark_calendar(GTK_CALENDAR(g_par.xfcal->mCalendar) + , year, month+1); + xfical_file_close(); return(TRUE); } Modified: xfcalendar/trunk/src/parameters.c =================================================================== --- xfcalendar/trunk/src/parameters.c 2007-01-29 20:46:52 UTC (rev 24796) +++ xfcalendar/trunk/src/parameters.c 2007-01-29 22:48:57 UTC (rev 24797) @@ -34,21 +34,18 @@ #include <libxfcegui4/libxfcegui4.h> #include <libxfce4util/libxfce4util.h> -#include "parameters.h" #include "mainbox.h" #include "functions.h" +#include "event-list.h" #include "tray_icon.h" #include "xfce_trayicon.h" +#include "appointment.h" +#include "parameters.h" +#include "ical-code.h" static gboolean is_running = FALSE; -enum { - LOCATION, - LOCATION_ENG, - N_COLUMNS -}; - typedef struct _Itf { GtkWidget *orage_dialog; @@ -473,141 +470,13 @@ { Itf *itf = (Itf *)user_data; -#define MAX_AREA_LENGTH 20 -#define MAX_BUFF_LENGTH 80 - - GtkTreeStore *store; - GtkTreeIter iter1, iter2; - GtkWidget *tree; - GtkCellRenderer *rend; - GtkTreeViewColumn *col; - GtkWidget *window; - GtkWidget *sw; - int j, result, latitude, longitude; - char area_old[MAX_AREA_LENGTH], tz[MAX_BUFF_LENGTH], buf[MAX_BUFF_LENGTH] - , *loc, *loc_eng; - GtkTreeSelection *sel; - GtkTreeModel *model; - GtkTreeIter iter; - gchar *fpath; - FILE *fp; - - fpath = g_strconcat(PACKAGE_DATA_DIR - , G_DIR_SEPARATOR_S, "orage" - , G_DIR_SEPARATOR_S, "zoneinfo" - , G_DIR_SEPARATOR_S, "zones.tab" - , NULL); - if ((fp = fopen(fpath, "r")) == NULL) { - g_warning("Unable to open timezones %s", fpath); - return; - } - - store = gtk_tree_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING); - strcpy(area_old, "S T a R T"); - while (fgets(buf, MAX_BUFF_LENGTH, fp) != NULL) { - if (sscanf(buf, "%d %d %s", &latitude, &longitude, tz) != 3) { - g_warning("Malformed timezones 1 %s (%s)", fpath, buf); - return; - } - /* first area */ - if (! g_str_has_prefix(tz, area_old)) { - for (j=0; tz[j] != '/' && j < MAX_AREA_LENGTH; j++) { - area_old[j] = tz[j]; - } - if (j >= MAX_AREA_LENGTH) { - g_warning("Malformed timezones 2 %s (%s)", fpath, tz); - return; - } - area_old[j] = 0; - - gtk_tree_store_append(store, &iter1, NULL); - gtk_tree_store_set(store, &iter1 - , LOCATION, _(area_old) - , LOCATION_ENG, area_old - , -1); - } - /* then city translated and in base form used internally */ - gtk_tree_store_append(store, &iter2, &iter1); - gtk_tree_store_set(store, &iter2 - , LOCATION, _(tz) - , LOCATION_ENG, tz - , -1); - } - g_free(fpath); - - /* create view */ - tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); - rend = gtk_cell_renderer_text_new(); - col = gtk_tree_view_column_new_with_attributes(_("Location") - , rend, "text", LOCATION, NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(tree), col); - - rend = gtk_cell_renderer_text_new(); - col = gtk_tree_view_column_new_with_attributes(_("Location") - , rend, "text", LOCATION_ENG, NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(tree), col); - gtk_tree_view_column_set_visible(col, FALSE); - - /* show it */ - window = gtk_dialog_new_with_buttons(_("Pick local timezone") - , GTK_WINDOW (itf->orage_dialog) - , GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT - , _("UTC"), 1 - , _("floating"), 2 - , GTK_STOCK_OK, GTK_RESPONSE_ACCEPT - , NULL); - sw = gtk_scrolled_window_new(NULL, NULL); - gtk_container_add(GTK_CONTAINER(sw), tree); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), sw, TRUE, TRUE, 0); - gtk_window_set_default_size(GTK_WINDOW(window), 300, 500); - - gtk_widget_show_all(window); if (g_par.local_timezone == NULL || strlen(g_par.local_timezone) == 0) { g_warning("timezone pressed: local timezone missing"); g_par.local_timezone = g_strdup("floating"); } - do { - result = gtk_dialog_run(GTK_DIALOG(window)); - switch (result) { - case GTK_RESPONSE_ACCEPT: - sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)); - if (gtk_tree_selection_get_selected(sel, &model, &iter)) - if (gtk_tree_model_iter_has_child(model, &iter)) - result = 0; - else { - gtk_tree_model_get(model, &iter, LOCATION, &loc, -1); - gtk_tree_model_get(model, &iter, LOCATION_ENG, &loc_eng - , -1); - } - else { - loc = g_strdup(_(g_par.local_timezone)); - loc_eng = g_strdup(g_par.local_timezone); - } - break; - case 1: - loc = g_strdup(_("UTC")); - loc_eng = g_strdup("UTC"); - break; - case 2: - loc = g_strdup(_("floating")); - loc_eng = g_strdup("floating"); - break; - default: - loc = g_strdup(_(g_par.local_timezone)); - loc_eng = g_strdup(g_par.local_timezone); - break; - } - } while (result == 0); - gtk_button_set_label(GTK_BUTTON(button), loc); - - if (g_par.local_timezone) - g_free(g_par.local_timezone); - g_par.local_timezone = g_strdup(loc_eng); - xfical_set_local_timezone(); - - g_free(loc); - g_free(loc_eng); - gtk_widget_destroy(window); + if (xfical_timezone_button_clicked(button, GTK_WINDOW(itf->orage_dialog) + , &g_par.local_timezone)) + xfical_set_local_timezone(); } static void archive_threshold_spin_changed(GtkSpinButton *sb Modified: xfcalendar/trunk/src/parameters.h =================================================================== --- xfcalendar/trunk/src/parameters.h 2007-01-29 20:46:52 UTC (rev 24796) +++ xfcalendar/trunk/src/parameters.h 2007-01-29 22:48:57 UTC (rev 24797) @@ -23,7 +23,6 @@ #ifndef __ORAGE_PARAMETERS_H__ #define __ORAGE_PARAMETERS_H__ -#include "mainbox.h" #include <xfce_trayicon.h> #define ORAGE_DIR "orage" G_DIR_SEPARATOR_S _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits