Updating branch refs/heads/master
         to d3550ac272cd930dbd2dd0a58290a4da0f54ec23 (commit)
       from 3e8da068a495af8e3a32aa6282d880271ed8c7c8 (commit)

commit d3550ac272cd930dbd2dd0a58290a4da0f54ec23
Author: Juha Kautto <j...@xfce.org>
Date:   Wed Dec 30 12:12:20 2009 +0200

    4.7.5.6: Panel plugin handles now dynamic rows instead of 3 fixed lines
    
    Replaced old table implementation of panel plugin rows. Now using GList
    and any number of lines can be used and ony used lines take space.
    Also fixed error when reading the timezone first time happened too late.
    
    Minor tunings also in main Orage code. Fixed bug where <&Ynnnn> was not
    correctly used in new test alarm.

 configure.in.in                        |    2 +-
 panel-plugin/oc_config.c               |  260 +++++++++++++++++-----------
 panel-plugin/xfce4-orageclock-plugin.c |  297 +++++++++++++++-----------------
 panel-plugin/xfce4-orageclock-plugin.h |   46 +++---
 src/appointment.c                      |    3 +-
 src/ical-code.c                        |    2 +-
 src/main.c                             |    2 +-
 src/reminder.c                         |   10 +-
 8 files changed, 325 insertions(+), 297 deletions(-)

diff --git a/configure.in.in b/configure.in.in
index fa4b3ef..28cf0b1 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -9,7 +9,7 @@ dnl Written for Xfce by Juha Kautto <j...@xfce.org>
 dnl
 
 dnl Version information
-m4_define([orage_version], [4.7.5.5-git])
+m4_define([orage_version], [4.7.5.6-git])
 
 m4_define([gtk_minimum_version], [2.10.0])
 m4_define([xfce_minimum_version], [4.6.0])
diff --git a/panel-plugin/oc_config.c b/panel-plugin/oc_config.c
index d6a74cb..07ecf19 100644
--- a/panel-plugin/oc_config.c
+++ b/panel-plugin/oc_config.c
@@ -42,6 +42,8 @@
 #include "timezone_selection.h"
 
 
+void oc_properties_options(GtkWidget *dlg, Clock *clock);
+
 /* -------------------------------------------------------------------- *
  *                        Configuration Dialog                          *
  * -------------------------------------------------------------------- */
@@ -114,57 +116,91 @@ static void oc_timezone_selected(GtkButton *button, Clock 
*clock)
     }
 }
 
-static void oc_show1(GtkToggleButton *cb, Clock *clock)
+static void oc_hib_timing_toggled(GtkToggleButton *cb, Clock *clock)
 {
-    clock->line[0].show = gtk_toggle_button_get_active(cb);
-    oc_show_line_set(clock, 0);
+    clock->hib_timing = gtk_toggle_button_get_active(cb);
 }
 
-static void oc_show2(GtkToggleButton *cb, Clock *clock)
+static gboolean oc_line_changed(GtkWidget *entry, GdkEventKey *key
+        , GString *data)
 {
-    clock->line[1].show = gtk_toggle_button_get_active(cb);
-    oc_show_line_set(clock, 1);
+    g_string_assign(data, gtk_entry_get_text(GTK_ENTRY(entry)));
+
+    return(FALSE);
 }
 
-static void oc_show3(GtkToggleButton *cb, Clock *clock)
+static void oc_line_font_changed(GtkWidget *widget, ClockLine *line)
 {
-    clock->line[2].show = gtk_toggle_button_get_active(cb);
-    oc_show_line_set(clock, 2);
+    g_string_assign(line->font
+            , gtk_font_button_get_font_name((GtkFontButton *)widget));
+    oc_line_font_set(line);
 }
 
-static void oc_hib_timing_toggled(GtkToggleButton *cb, Clock *clock)
+static void oc_recreate_properties_options(Clock *clock)
 {
-    clock->hib_timing = gtk_toggle_button_get_active(cb);
-    /* oc_hib_timing_set(clock); */
+    GtkWidget *dialog, *frame;
+
+    dialog = g_object_get_data(G_OBJECT(clock->plugin), "dialog");
+    frame  = g_object_get_data(G_OBJECT(clock->plugin), "properties_frame");
+    gtk_widget_destroy(frame);
+    oc_properties_options(dialog, clock);
+    gtk_widget_show_all(dialog);
 }
 
-static gboolean oc_line_changed(GtkWidget *entry, GdkEventKey *key
-        , GString *data)
+static void oc_new_line(GtkToolButton *toolbutton, ClockLine *line)
 {
-    g_string_assign(data, gtk_entry_get_text(GTK_ENTRY(entry)));
+    Clock *clock = line->clock;;
+    gint pos;
 
-    return(FALSE);
+    pos = g_list_index(clock->lines, line);
+    oc_add_line(clock, "%X", "", pos+1);
+
+    oc_recreate_properties_options(clock);
 }
 
-static void oc_line_font_changed1(GtkWidget *widget, Clock *clock)
+static void oc_delete_line(GtkToolButton *toolbutton, ClockLine *line)
 {
-    g_string_assign(clock->line[0].font
-            , gtk_font_button_get_font_name((GtkFontButton *)widget));
-    oc_line_font_set(clock, 0);
+    Clock *clock = line->clock;;
+
+    /* remove the data from the list and from the panel */
+    g_string_free(line->data, TRUE);
+    g_string_free(line->font, TRUE);
+    gtk_widget_destroy(line->label);
+    clock->lines = g_list_remove(clock->lines, line);
+    g_free(line);
+
+    oc_recreate_properties_options(clock);
 }
 
-static void oc_line_font_changed2(GtkWidget *widget, Clock *clock)
+static void oc_move_up_line(GtkToolButton *toolbutton, ClockLine *line)
 {
-    g_string_assign(clock->line[1].font
-            , gtk_font_button_get_font_name((GtkFontButton *)widget));
-    oc_line_font_set(clock, 1);
+    Clock *clock = line->clock;;
+    gint pos;
+
+    pos = g_list_index(clock->lines, line);
+    pos--;
+    gtk_box_reorder_child(GTK_BOX(clock->vbox), line->label, pos);
+    clock->lines = g_list_remove(clock->lines, line);
+    clock->lines = g_list_insert(clock->lines, line, pos);
+
+    oc_recreate_properties_options(clock);
 }
 
-static void oc_line_font_changed3(GtkWidget *widget, Clock *clock)
+static void oc_move_down_line(GtkToolButton *toolbutton, ClockLine *line)
 {
-    g_string_assign(clock->line[2].font
-            , gtk_font_button_get_font_name((GtkFontButton *)widget));
-    oc_line_font_set(clock, 2);
+    Clock *clock = line->clock;;
+    gint pos, line_cnt;
+
+    line_cnt = g_list_length(clock->lines);
+    pos = g_list_index(clock->lines, line);
+    pos++;
+    if (pos == line_cnt)
+        pos = 0;
+    gtk_box_reorder_child(GTK_BOX(clock->vbox), line->label, pos);
+    clock->lines = g_list_remove(clock->lines, line);
+    clock->lines = g_list_insert(clock->lines, line, pos);
+
+    oc_recreate_properties_options(clock);
 }
 
 static void oc_table_add(GtkWidget *table, GtkWidget *widget, int col, int row)
@@ -238,6 +274,9 @@ static void oc_properties_appearance(GtkWidget *dlg, Clock 
*clock)
     if (!clock->height_set)
         clock->height = 32;
     gtk_spin_button_set_value(GTK_SPIN_BUTTON(sb), (gdouble)clock->height);
+    gtk_tooltips_set_tip(clock->tips, GTK_WIDGET(cb),
+            _("Note that you can not change the height of horizontal panels")
+            , NULL);
     g_signal_connect((gpointer) sb, "value-changed",
             G_CALLBACK(oc_set_height_changed), clock);
 
@@ -251,22 +290,35 @@ static void oc_properties_appearance(GtkWidget *dlg, 
Clock *clock)
     if (!clock->width_set)
         clock->width = 70;
     gtk_spin_button_set_value(GTK_SPIN_BUTTON(sb), (gdouble)clock->width);
+    gtk_tooltips_set_tip(clock->tips, GTK_WIDGET(cb),
+            _("Note that you can not change the width of vertical panels")
+            , NULL);
     g_signal_connect((gpointer) sb, "value-changed",
             G_CALLBACK(oc_set_width_changed), clock);
 }
 
-static void oc_properties_options(GtkWidget *dlg, Clock *clock)
+void oc_properties_options(GtkWidget *dlg, Clock *clock)
 {
-    GtkWidget *frame, *bin, *hbox, *cb, *label, *entry, *font, *button, *image;
+    GtkWidget *frame, *bin, *cb, *label, *entry, *font, *button;
     GtkStyle *def_style;
-    gchar *def_font;
-    GtkWidget *table;
+    gchar *def_font, tmp[100];
+    GtkWidget *table, *toolbar;
+    GtkToolItem *tool_button;
+    gint line_cnt, cur_line;
+    ClockLine *line;
+    GList   *tmp_list;
 
     frame = xfce_create_framebox(_("Clock Options"), &bin);
     gtk_container_set_border_width(GTK_CONTAINER(frame), 6);
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), frame, FALSE, FALSE, 0);
-
-    table = gtk_table_new(6, 3, FALSE);
+    /* we sometimes call this function again, so we need to put it to the 
+       correct position */
+    gtk_box_reorder_child(GTK_BOX(GTK_DIALOG(dlg)->vbox), frame, 3);
+    /* this is needed when we restructure this frame */
+    g_object_set_data(G_OBJECT(clock->plugin), "properties_frame", frame);
+
+    line_cnt = g_list_length(clock->lines);
+    table = gtk_table_new(3+line_cnt, 4, FALSE);
     gtk_container_set_border_width(GTK_CONTAINER(table), 10);
     gtk_table_set_row_spacings(GTK_TABLE(table), 6);
     gtk_table_set_col_spacings(GTK_TABLE(table), 6);
@@ -283,95 +335,91 @@ static void oc_properties_options(GtkWidget *dlg, Clock 
*clock)
     g_signal_connect(G_OBJECT(button), "clicked"
             , G_CALLBACK(oc_timezone_selected), clock);
 
-    /* line 1 */
-    cb = gtk_check_button_new_with_mnemonic(_("show line _1:"));
-    oc_table_add(table, cb, 0, 1);
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb), clock->line[0].show);
-    g_signal_connect(cb, "toggled", G_CALLBACK(oc_show1), clock);
-
-    entry = gtk_entry_new();
-    gtk_entry_set_text(GTK_ENTRY(entry), clock->line[0].data->str); 
-    oc_table_add(table, entry, 1, 1);
-    g_signal_connect(entry, "key-release-event", G_CALLBACK(oc_line_changed)
-            , clock->line[0].data);
-    gtk_tooltips_set_tip(clock->tips, GTK_WIDGET(entry),
-            _("Enter any valid strftime function parameter.")
-            , NULL);
-    
+    /* lines */
+    line_cnt = g_list_length(clock->lines);
     def_style = gtk_widget_get_default_style();
     def_font = pango_font_description_to_string(def_style->font_desc);
-    if (clock->line[0].font->len) {
-        font = gtk_font_button_new_with_font(clock->line[0].font->str);
-    }
-    else {
-        font = gtk_font_button_new_with_font(def_font);
-    }
-    oc_table_add(table, font, 2, 1);
-    g_signal_connect(G_OBJECT(font), "font-set"
-            , G_CALLBACK(oc_line_font_changed1), clock);
 
-    /* line 2 */
-    cb = gtk_check_button_new_with_mnemonic(_("show line _2:"));
-    oc_table_add(table, cb, 0, 2);
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb), clock->line[1].show);
-    g_signal_connect(cb, "toggled", G_CALLBACK(oc_show2), clock);
-
-    entry = gtk_entry_new();
-    gtk_entry_set_text(GTK_ENTRY(entry), clock->line[1].data->str); 
-    oc_table_add(table, entry, 1, 2);
-    g_signal_connect(entry, "key-release-event", G_CALLBACK(oc_line_changed)
-            , clock->line[1].data);
-    
-    if (clock->line[1].font->len) {
-        font = gtk_font_button_new_with_font(clock->line[1].font->str);
-    }
-    else {
-        font = gtk_font_button_new_with_font(def_font);
-    }
-    oc_table_add(table, font, 2, 2);
-    g_signal_connect(G_OBJECT(font), "font-set"
-            , G_CALLBACK(oc_line_font_changed2), clock);
-    
-    /* line 3 */
-    cb = gtk_check_button_new_with_mnemonic(_("show line _3:"));
-    oc_table_add(table, cb, 0, 3);
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb), clock->line[2].show);
-    g_signal_connect(cb, "toggled", G_CALLBACK(oc_show3), clock);
-    
-    entry = gtk_entry_new();
-    gtk_entry_set_text(GTK_ENTRY(entry), clock->line[2].data->str); 
-    oc_table_add(table, entry, 1, 3);
-    g_signal_connect(entry, "key-release-event", G_CALLBACK(oc_line_changed)
-            , clock->line[2].data);
-    
-    if (clock->line[2].font->len) {
-        font = gtk_font_button_new_with_font(clock->line[2].font->str);
+    cur_line = 0;
+    for (tmp_list = g_list_first(clock->lines);
+            tmp_list;
+         tmp_list = g_list_next(tmp_list)) {
+        cur_line++;
+        line = tmp_list->data;
+        sprintf(tmp, _("Line %d:"), cur_line);
+        label = gtk_label_new(tmp);
+        oc_table_add(table, label, 0, cur_line);
+
+        entry = gtk_entry_new();
+        gtk_entry_set_text(GTK_ENTRY(entry), line->data->str); 
+        g_signal_connect(entry, "key-release-event", 
G_CALLBACK(oc_line_changed)
+                , line->data);
+        if (cur_line == 1)
+            gtk_tooltips_set_tip(clock->tips, GTK_WIDGET(entry),
+                    _("Enter any valid strftime function parameter."), NULL);
+        oc_table_add(table, entry, 1, cur_line);
+
+        if (line->font->len) {
+            font = gtk_font_button_new_with_font(line->font->str);
+        }
+        else {
+            font = gtk_font_button_new_with_font(def_font);
+        }
+        g_signal_connect(G_OBJECT(font), "font-set"
+                , G_CALLBACK(oc_line_font_changed), line);
+        oc_table_add(table, font, 2, cur_line);
+
+        toolbar = gtk_toolbar_new();
+        if (line_cnt < OC_MAX_LINES) { /* no real reason to limit this though 
*/
+            tool_button = gtk_tool_button_new_from_stock(GTK_STOCK_ADD);
+            gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tool_button, 0);
+            g_signal_connect(tool_button, "clicked"
+                    , G_CALLBACK(oc_new_line), line);
+        }
+        if (line_cnt > 1) { /* do not delete last line */
+            tool_button = gtk_tool_button_new_from_stock(GTK_STOCK_DELETE);
+            gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tool_button, 1);
+            g_signal_connect(tool_button, "clicked"
+                    , G_CALLBACK(oc_delete_line), line);
+            /* we do not need these if we only have 1 line */
+            tool_button = gtk_tool_button_new_from_stock(GTK_STOCK_GO_UP);
+            gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tool_button, 2);
+            g_signal_connect(tool_button, "clicked"
+                    , G_CALLBACK(oc_move_up_line), line);
+            tool_button = gtk_tool_button_new_from_stock(GTK_STOCK_GO_DOWN);
+            gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tool_button, 3);
+            g_signal_connect(tool_button, "clicked"
+                    , G_CALLBACK(oc_move_down_line), line);
+        }
+        oc_table_add(table, toolbar, 3, cur_line);
+
+        button = gtk_button_new_from_stock(GTK_STOCK_DELETE);
     }
-    else {
-        font = gtk_font_button_new_with_font(def_font);
-    }
-    oc_table_add(table, font, 2, 3);
-    g_signal_connect(G_OBJECT(font), "font-set"
-            , G_CALLBACK(oc_line_font_changed3), clock);
+
 
     /* Tooltip hint */
     label = gtk_label_new(_("Tooltip:"));
-    oc_table_add(table, label, 0, 4);
+    oc_table_add(table, label, 0, line_cnt+1);
 
     entry = gtk_entry_new();
     gtk_entry_set_text(GTK_ENTRY(entry), clock->tooltip_data->str); 
-    oc_table_add(table, entry, 1, 4);
+    oc_table_add(table, entry, 1, line_cnt+1);
     g_signal_connect(entry, "key-release-event", G_CALLBACK(oc_line_changed)
             , clock->tooltip_data);
     
     /* special timing for SUSPEND/HIBERNATE */
     cb = gtk_check_button_new_with_mnemonic(_("fix time after 
suspend/hibernate"));
-    oc_table_add(table, cb, 1, 5);
+    oc_table_add(table, cb, 1, line_cnt+2);
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb), clock->hib_timing);
     gtk_tooltips_set_tip(clock->tips, GTK_WIDGET(cb),
             _("You only need this if you do short term (less than 5 hours) 
suspend or hibernate and your visible time does not include seconds. Under 
these circumstances it is possible that Orageclock shows time inaccurately 
unless you have this selected. (Selecting this prevents cpu and interrupt 
saving features from working.)")
             , NULL);
     g_signal_connect(cb, "toggled", G_CALLBACK(oc_hib_timing_toggled), clock);
+}
+
+void oc_instructions(GtkWidget *dlg, Clock *clock)
+{
+    GtkWidget *hbox, *label, *image;
 
     /* Instructions */
     hbox = gtk_hbox_new(FALSE, 0);
@@ -389,6 +437,7 @@ static void oc_properties_options(GtkWidget *dlg, Clock 
*clock)
 static void oc_dialog_response(GtkWidget *dlg, int response, Clock *clock)
 {
     g_object_set_data(G_OBJECT(clock->plugin), "dialog", NULL);
+    g_object_set_data(G_OBJECT(clock->plugin), "properties_frame", NULL);
     gtk_widget_destroy(dlg);
     xfce_panel_plugin_unblock_menu(clock->plugin);
     oc_write_rc_file(clock->plugin, clock);
@@ -401,8 +450,8 @@ void oc_properties_dialog(XfcePanelPlugin *plugin, Clock 
*clock)
 
     xfce_panel_plugin_block_menu(plugin);
     
-    clock->interval = 200; /* 0,2 sec, so that we can show quick feedback
-                            * on the panel */
+    /* change interval to show quick feedback on panel */
+    clock->interval = OC_CONFIG_INTERVAL; 
     oc_start_timer(clock);
     dlg = gtk_dialog_new_with_buttons(_("Orage clock Preferences"), 
             GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(plugin))),
@@ -426,6 +475,7 @@ void oc_properties_dialog(XfcePanelPlugin *plugin, Clock 
*clock)
     
     oc_properties_appearance(dlg, clock);
     oc_properties_options(dlg, clock);
+    oc_instructions(dlg, clock);
 
     gtk_widget_show_all(dlg);
 }
diff --git a/panel-plugin/xfce4-orageclock-plugin.c 
b/panel-plugin/xfce4-orageclock-plugin.c
index 4ca643f..49de0b8 100644
--- a/panel-plugin/xfce4-orageclock-plugin.c
+++ b/panel-plugin/xfce4-orageclock-plugin.c
@@ -44,7 +44,7 @@
  *                               Clock                                  *
  * -------------------------------------------------------------------- */
 
-static void utf8_strftime(char *res, int res_l, char *format, struct tm *tm)
+static void oc_utf8_strftime(char *res, int res_l, char *format, struct tm *tm)
 {
     char *tmp = NULL;
 
@@ -68,11 +68,47 @@ static void utf8_strftime(char *res, int res_l, char 
*format, struct tm *tm)
     }
 }
 
+void oc_line_font_set(ClockLine *line)
+{
+    PangoFontDescription *font;
+
+    if (line->font->str) {
+        font = pango_font_description_from_string(line->font->str);
+        gtk_widget_modify_font(line->label, font);
+        pango_font_description_free(font);
+    }
+    else
+        gtk_widget_modify_font(line->label, NULL);
+}
+
+void oc_add_line(Clock *clock, char *data, char *font, int pos)
+{
+    ClockLine *clock_line;
+
+    clock_line = g_new0(ClockLine, 1);
+
+    clock_line->data = g_string_new(data);
+    clock_line->font = g_string_new(font);
+    strcpy(clock_line->prev, "New line");
+    clock_line->clock = clock;
+
+    clock_line->label = gtk_label_new("");
+    gtk_box_pack_start(GTK_BOX(clock->vbox), clock_line->label
+            , FALSE, FALSE, 0);
+    gtk_box_reorder_child(GTK_BOX(clock->vbox), clock_line->label, pos);
+    oc_line_font_set(clock_line);
+    gtk_widget_show(clock_line->label);
+    /* clicking does not work after this
+    gtk_label_set_selectable(GTK_LABEL(clock_line->label), TRUE);
+    */
+    clock->lines = g_list_insert(clock->lines, clock_line, pos);
+}
+
 static void oc_tooltip_set(Clock *clock)
 {
     char res[OC_MAX_LINE_LENGTH-1];
 
-    utf8_strftime(res, sizeof(res), clock->tooltip_data->str, &clock->now);
+    oc_utf8_strftime(res, sizeof(res), clock->tooltip_data->str, &clock->now);
     if (strcmp(res,  clock->tooltip_prev)) {
         gtk_tooltips_set_tip(clock->tips, GTK_WIDGET(clock->plugin),res, NULL);
         strcpy(clock->tooltip_prev, res);
@@ -83,26 +119,26 @@ static gboolean oc_get_time(Clock *clock)
 {
     time_t  t;
     char    res[OC_MAX_LINE_LENGTH-1];
-    int     i;
     ClockLine *line;
+    GList   *tmp_list;
 
     time(&t);
     localtime_r(&t, &clock->now);
-    for (i = 0; i < OC_MAX_LINES; i++) {
-        line = &clock->line[i];
-        if (line->show) {
-            utf8_strftime(res, sizeof(res), line->data->str, &clock->now);
-            /* gtk_label_set_text call takes almost
-             * 100 % of the time wasted in this procedure 
-             * Note that even though we only wake up when needed, we 
-             * may not have to update all lines, so this check still
-             * probably is worth doing. Specially after we added the
-             * hibernate update option.
-             * */
-            if (strcmp(res,  line->prev)) {
-                gtk_label_set_text(GTK_LABEL(line->label), res);
-                strcpy(line->prev, res);
-            }
+    for (tmp_list = g_list_first(clock->lines); 
+            tmp_list;
+         tmp_list = g_list_next(tmp_list)) {
+        line = tmp_list->data;
+        oc_utf8_strftime(res, sizeof(res), line->data->str, &clock->now);
+        /* gtk_label_set_text call takes almost
+         * 100 % of the time used in this procedure.
+         * Note that even though we only wake up when needed, we 
+         * may not have to update all lines, so this check still
+         * probably is worth doing. Specially after we added the
+         * hibernate update option.
+         * */
+        if (strcmp(res, line->prev)) {
+            gtk_label_set_text(GTK_LABEL(line->label), res);
+            strcpy(line->prev, res);
         }
     }
     oc_tooltip_set(clock);
@@ -135,7 +171,7 @@ static gboolean oc_get_time_delay(Clock *clock)
 
 void oc_start_timer(Clock *clock)
 {
-    gint delay_time; /* this is used to set the clock start tie correct */
+    gint delay_time; /* this is used to set the clock start time correct */
 
     /*
     g_message("oc_start_timer: (%s) interval %d  %d:%d:%d", 
clock->tooltip_prev, clock->interval, clock->now.tm_hour, clock->now.tm_min, 
clock->now.tm_sec);
@@ -160,7 +196,7 @@ void oc_start_timer(Clock *clock)
     else { /* need to tune time */
         if (clock->interval <= 60000) /* adjust to next full minute */
             delay_time = (clock->interval - clock->now.tm_sec*1000);
-        else /* if (clock->interval <= 3600000) *//* adjust to next full hour 
*/
+        else /* adjust to next full hour */
             delay_time = (clock->interval -
                     (clock->now.tm_min*60000 + clock->now.tm_sec*1000));
 
@@ -177,8 +213,9 @@ gboolean oc_check_if_same(Clock *clock, int diff)
     time_t  t, t_next;
     struct tm tm, tm_next;
     char    res[OC_MAX_LINE_LENGTH-1], res_next[OC_MAX_LINE_LENGTH-1];
-    int     i, max_len;
+    int     max_len;
     ClockLine *line;
+    GList   *tmp_list;
     gboolean same_time = TRUE, first_check = TRUE, result_known = FALSE;
     
     max_len = sizeof(res); 
@@ -187,21 +224,22 @@ gboolean oc_check_if_same(Clock *clock, int diff)
         t_next = t + diff;  /* diff secs forward */
         localtime_r(&t, &tm);
         localtime_r(&t_next, &tm_next);
-        for (i = 0; (i < OC_MAX_LINES) && same_time; i++) {
-            line = &clock->line[i];
-            if (line->show) {
-                utf8_strftime(res, max_len, line->data->str, &tm);
-                utf8_strftime(res_next, max_len, line->data->str, &tm_next);
-                if (strcmp(res,  res_next)) { /* differ */
-                    same_time = FALSE;
-                }
+        for (tmp_list = g_list_first(clock->lines);
+                (tmp_list && same_time);
+             tmp_list = g_list_next(tmp_list)) {
+            line = tmp_list->data;
+            oc_utf8_strftime(res, max_len, line->data->str, &tm);
+            oc_utf8_strftime(res_next, max_len, line->data->str, &tm_next);
+            if (strcmp(res, res_next)) { /* differ */
+                same_time = FALSE;
             }
         }
         /* Need to check also tooltip */
         if (same_time) { /* we only check tooltip if needed */
-            utf8_strftime(res, max_len, clock->tooltip_data->str, &tm);
-            utf8_strftime(res_next, max_len, 
clock->tooltip_data->str,&tm_next);
-            if (strcmp(res,  res_next)) { /* differ */
+            oc_utf8_strftime(res, max_len, clock->tooltip_data->str, &tm);
+            oc_utf8_strftime(res_next, max_len, clock->tooltip_data->str
+                    , &tm_next);
+            if (strcmp(res, res_next)) { /* differ */
                 same_time = FALSE;
             }
         }
@@ -248,7 +286,6 @@ void oc_tune_interval(Clock *clock)
 void oc_init_timer(Clock *clock)
 {
     clock->interval = OC_BASE_INTERVAL;
-    oc_get_time(clock); /* update clock once */
     if (!clock->hib_timing) /* using suspend/hibernate, do not tune time */
         oc_tune_interval(clock);
     oc_start_timer(clock);
@@ -306,7 +343,7 @@ static gboolean popup_program(GtkWidget *widget, gchar 
*program, Clock *clock
         return(TRUE);
     }
     else { /* not running, let's try to start it. Need to reset TZ! */
-        static guint prev_event_time = 0; /* prevenst double start (BUG 4096) 
*/
+        static guint prev_event_time = 0; /* prevents double start (BUG 4096) 
*/
 
         if (prev_event_time && ((event_time - prev_event_time) < 1000)) {
             g_message("%s: double start of %s prevented", OC_NAME, program);
@@ -373,22 +410,39 @@ static void oc_free_data(XfcePanelPlugin *plugin, Clock 
*clock)
     if (clock->timeout_id) {
         g_source_remove(clock->timeout_id);
     }
-    g_object_unref(clock->tips);
-    g_object_unref(clock->line[0].label);
-    g_object_unref(clock->line[1].label);
-    g_object_unref(clock->line[2].label);
+    g_list_free(clock->lines);
     g_free(clock->TZ_orig);
+    g_object_unref(clock->tips);
     g_free(clock);
 }
 
+static GdkColor oc_rc_read_color(XfceRc *rc, char *par, char *def)
+{
+    const gchar *ret;
+    GdkColor color;
+
+    ret = xfce_rc_read_entry(rc, par, def);
+    color.pixel = 0;
+    if (!strcmp(ret, def)
+    ||  sscanf(ret, OC_RC_COLOR
+                , (unsigned int *)&color.red
+                , (unsigned int *)&color.green
+                , (unsigned int *)&color.blue) != 3) {
+        gint i = sscanf(ret, OC_RC_COLOR , (unsigned int *)&color.red , 
(unsigned int *)&color.green , (unsigned int *)&color.blue);
+        g_warning("unable to read %s colour from rc file ret=(%s) def=(%s) 
cnt=%d", par, ret, def, i);
+        gdk_color_parse(ret, &color);
+    }
+    return(color);
+}
+
 static void oc_read_rc_file(XfcePanelPlugin *plugin, Clock *clock)
 {
     gchar  *file;
     XfceRc *rc;
-    const gchar  *ret;
+    const gchar  *ret, *data, *font;
     gchar tmp[100];
+    gboolean more_lines;
     gint i;
-    unsigned int red, green, blue;
 
     if (!(file = xfce_panel_plugin_lookup_rc_file(plugin)))
         return; /* if it does not exist, we use defaults from orage_oc_new */
@@ -396,41 +450,19 @@ static void oc_read_rc_file(XfcePanelPlugin *plugin, 
Clock *clock)
         g_warning("unable to read-open rc file (%s)", file);
         return;
     }
-    g_free(file);
 
     clock->show_frame = xfce_rc_read_bool_entry(rc, "show_frame", TRUE);
 
     clock->fg_set = xfce_rc_read_bool_entry(rc, "fg_set", FALSE);
     if (clock->fg_set) {
-        ret = xfce_rc_read_entry(rc, "fg", NULL);
-        /*
-        sscanf(ret, "%uR %uG %uB"
-                , (unsigned int *)&clock->fg.red
-                , (unsigned int *)&clock->fg.green
-                , (unsigned int *)&clock->fg.blue);
-                */
-        sscanf(ret, "%uR %uG %uB", &red, &green, &blue);
-        clock->fg.red = red;
-        clock->fg.green = green;
-        clock->fg.blue = blue;
-        clock->fg.pixel = 0;
+        clock->fg = oc_rc_read_color(rc, "fg", "black");
     }
 
     clock->bg_set = xfce_rc_read_bool_entry(rc, "bg_set", FALSE);
     if (clock->bg_set) {
-        ret = xfce_rc_read_entry(rc, "bg", NULL);
-        /*
-        sscanf(ret, "%uR %uG %uB"
-                , (unsigned int *)&clock->bg.red
-                , (unsigned int *)&clock->bg.green
-                , (unsigned int *)&clock->bg.blue);
-                */
-        sscanf(ret, "%uR %uG %uB", &red, &green, &blue);
-        clock->bg.red = red;
-        clock->bg.green = green;
-        clock->bg.blue = blue;
-        clock->bg.pixel = 0;
+        clock->bg = oc_rc_read_color(rc, "bg", "white");
     }
+    g_free(file);
 
     ret = xfce_rc_read_entry(rc, "timezone", NULL);
     g_string_assign(clock->timezone, ret); 
@@ -444,19 +476,19 @@ static void oc_read_rc_file(XfcePanelPlugin *plugin, 
Clock *clock)
         clock->height = xfce_rc_read_int_entry(rc, "height", -1);
     }
     
-    for (i = 0; i < OC_MAX_LINES; i++) {
-        sprintf(tmp, "show%d", i);
-        clock->line[i].show = xfce_rc_read_bool_entry(rc, tmp, FALSE);
-        if (clock->line[i].show) {
-            sprintf(tmp, "data%d", i);
-            ret = xfce_rc_read_entry(rc, tmp, NULL);
-            g_string_assign(clock->line[i].data, ret);
-
+    for (i = 0, more_lines = TRUE; more_lines; i++) {
+        sprintf(tmp, "data%d", i);
+        data = xfce_rc_read_entry(rc, tmp, NULL);
+        if (data) { /* let's add it */
             sprintf(tmp, "font%d", i);
-            ret = xfce_rc_read_entry(rc, tmp, NULL);
-            g_string_assign(clock->line[i].font, ret);
+            font = xfce_rc_read_entry(rc, tmp, NULL);
+            oc_add_line(clock, (char *)data, (char *)font, -1);
+        }
+        else { /* no more clock lines */
+            more_lines = FALSE;
         }
     }
+    clock->orig_line_cnt = i; 
 
     if ((ret = xfce_rc_read_entry(rc, "tooltip", NULL)))
         g_string_assign(clock->tooltip_data, ret); 
@@ -471,7 +503,9 @@ void oc_write_rc_file(XfcePanelPlugin *plugin, Clock *clock)
     gchar  *file;
     XfceRc *rc;
     gchar   tmp[100];
-    gint i;
+    int     i;
+    ClockLine *line;
+    GList   *tmp_list;
 
     if (!(file = xfce_panel_plugin_save_location(plugin, TRUE))) {
         g_warning("unable to write rc file");
@@ -523,21 +557,21 @@ void oc_write_rc_file(XfcePanelPlugin *plugin, Clock 
*clock)
         xfce_rc_delete_entry(rc, "height", TRUE);
     }
 
-    for (i = 0; i < OC_MAX_LINES; i++) {
-        sprintf(tmp, "show%d", i);
-        xfce_rc_write_bool_entry(rc, tmp, clock->line[i].show);
-        if (clock->line[i].show) {
-            sprintf(tmp, "data%d", i);
-            xfce_rc_write_entry(rc, tmp,  clock->line[i].data->str);
-            sprintf(tmp, "font%d", i);
-            xfce_rc_write_entry(rc, tmp,  clock->line[i].font->str);
-        }
-        else {
-            sprintf(tmp, "data%d", i);
-            xfce_rc_delete_entry(rc, tmp,  FALSE);
-            sprintf(tmp, "font%d", i);
-            xfce_rc_delete_entry(rc, tmp,  FALSE);
-        }
+    for (i = 0, tmp_list = g_list_first(clock->lines);
+            tmp_list;
+         i++, tmp_list = g_list_next(tmp_list)) {
+        line = tmp_list->data;
+        sprintf(tmp, "data%d", i);
+        xfce_rc_write_entry(rc, tmp,  line->data->str);
+        sprintf(tmp, "font%d", i);
+        xfce_rc_write_entry(rc, tmp,  line->font->str);
+    }
+    /* delete extra lines */
+    for (; i <= clock->orig_line_cnt; i++) {
+        sprintf(tmp, "data%d", i);
+        xfce_rc_delete_entry(rc, tmp,  FALSE);
+        sprintf(tmp, "font%d", i);
+        xfce_rc_delete_entry(rc, tmp,  FALSE);
     }
 
     xfce_rc_write_entry(rc, "tooltip",  clock->tooltip_data->str);
@@ -550,10 +584,7 @@ void oc_write_rc_file(XfcePanelPlugin *plugin, Clock 
*clock)
 /* Create widgets and connect to signals */
 Clock *orage_oc_new(XfcePanelPlugin *plugin)
 {
-    Clock *clock = g_new0(Clock, 1);
-    gchar *data_init[] = {"%X", "%A", "%x"};
-    gboolean show_init[] = {TRUE, FALSE, FALSE};
-    gint  i;
+    Clock     *clock = g_new0(Clock, 1);
 
     clock->plugin = plugin;
 
@@ -577,17 +608,7 @@ Clock *orage_oc_new(XfcePanelPlugin *plugin)
     clock->timezone = g_string_new(""); /* = not set */
     clock->TZ_orig = g_strdup(g_getenv("TZ"));
 
-    for (i = 0; i < OC_MAX_LINES; i++) {
-        clock->line[i].label = gtk_label_new("");
-        /* clicking does not work after this
-        gtk_label_set_selectable(GTK_LABEL(clock->line[i].label), TRUE);
-        */
-        g_object_ref(clock->line[i].label); /* it is not always in the vbox */
-        gtk_widget_show(clock->line[i].label);
-        clock->line[i].show = show_init[i];
-        clock->line[i].data = g_string_new(data_init[i]);
-        clock->line[i].font = g_string_new("");
-    }
+    clock->lines = NULL; /* no lines yet */
 
     /* TRANSLATORS: Use format characters from strftime(3)
      * to get the proper string for your locale.
@@ -618,13 +639,18 @@ void oc_show_frame_set(Clock *clock)
 void oc_fg_set(Clock *clock)
 {
     GdkColor *fg = NULL;
-    gint      i;
+    ClockLine *line;
+    GList   *tmp_list;
 
     if (clock->fg_set)
         fg = &clock->fg;
 
-    for (i = 0; i < OC_MAX_LINES; i++)
-        gtk_widget_modify_fg(clock->line[i].label, GTK_STATE_NORMAL, fg);
+    for (tmp_list = g_list_first(clock->lines);
+            tmp_list;
+         tmp_list = g_list_next(tmp_list)) {
+        line = tmp_list->data;
+        gtk_widget_modify_fg(line->label, GTK_STATE_NORMAL, fg);
+    }
 }
 
 void oc_bg_set(Clock *clock)
@@ -661,51 +687,9 @@ void oc_size_set(Clock *clock)
     gtk_widget_set_size_request(clock->vbox, w, h);
 }
 
-void oc_show_line_set(Clock *clock, gint lno)
-{
-    GtkWidget *line_label = clock->line[lno].label;
-
-    if (clock->line[lno].show) {
-        gtk_box_pack_start(GTK_BOX(clock->vbox), line_label, FALSE, FALSE, 0);
-        switch (lno) {
-            case 0: /* always on top */
-                gtk_box_reorder_child(GTK_BOX(clock->vbox), line_label, 0);
-                break;
-            case 1: /* if line 0 is missing, we are first */
-                if (clock->line[0].show)  /* we are second line */
-                    gtk_box_reorder_child(GTK_BOX(clock->vbox), line_label, 1);
-                else /* we are top line */
-                    gtk_box_reorder_child(GTK_BOX(clock->vbox), line_label, 0);
-                break;
-            case 2: /* always last */
-                break;
-        }
-    }
-    else {
-        gtk_container_remove(GTK_CONTAINER(clock->vbox), line_label);
-    }
-
-    oc_update_size(clock,
-            xfce_panel_plugin_get_size(XFCE_PANEL_PLUGIN(clock->plugin)));
-}
-
-void oc_line_font_set(Clock *clock, gint lno)
-{
-    PangoFontDescription *font;
-
-    if (clock->line[lno].font->str) {
-        font = pango_font_description_from_string(clock->line[lno].font->str);
-        gtk_widget_modify_font(clock->line[lno].label, font);
-        pango_font_description_free(font);
-    }
-    else
-        gtk_widget_modify_font(clock->line[lno].label, NULL);
-}
-
 static void oc_construct(XfcePanelPlugin *plugin)
 {
     Clock *clock;
-    gint i;
 
     xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
 
@@ -714,18 +698,16 @@ static void oc_construct(XfcePanelPlugin *plugin)
     gtk_container_add(GTK_CONTAINER(plugin), clock->ebox);
 
     oc_read_rc_file(plugin, clock);
-    oc_init_timer(clock);
+    if (clock->lines == NULL) /* Let's setup a default clock_line */
+        oc_add_line(clock, "%X", "", -1);
 
     oc_show_frame_set(clock);
     oc_fg_set(clock);
     oc_bg_set(clock);
     oc_timezone_set(clock);
     oc_size_set(clock);
-    for (i = 0; i < OC_MAX_LINES; i++) {
-        if (clock->line[i].show)  /* need to add */
-            oc_show_line_set(clock, i);
-        oc_line_font_set(clock, i);
-    }
+
+    oc_init_timer(clock);
 
     oc_update_size(clock, 
             xfce_panel_plugin_get_size(XFCE_PANEL_PLUGIN(plugin)));
@@ -749,7 +731,6 @@ static void oc_construct(XfcePanelPlugin *plugin)
 /* callback for calendar and globaltime popup */
     g_signal_connect(clock->ebox, "button-press-event",
             G_CALLBACK(on_button_press_event_cb), clock);
-
 }
 
 /* Register with the panel */
diff --git a/panel-plugin/xfce4-orageclock-plugin.h 
b/panel-plugin/xfce4-orageclock-plugin.h
index 85e7ffa..bb5869d 100644
--- a/panel-plugin/xfce4-orageclock-plugin.h
+++ b/panel-plugin/xfce4-orageclock-plugin.h
@@ -1,5 +1,5 @@
 /*  xfce4
- *  Copyright (C) 2006-2007 Juha Kautto (j...@xfce.org)
+ *  Copyright (C) 2006-2010 Juha Kautto (j...@xfce.org)
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -18,19 +18,11 @@
  */
 
 #define OC_NAME "orageclock panel plugin"
-#define OC_MAX_LINES 3 /* changing this causes trouble. don't do it */
+#define OC_MAX_LINES 10             /* max number of lines in the plugin */
 #define OC_MAX_LINE_LENGTH 100 
-#define OC_BASE_INTERVAL 1000  /* best accurance of the clock = 1 sec */
-#define OC_CONFIG_INTERVAL 200 /* special fast interval used in setup */
-
-typedef struct _clockline
-{
-    GtkWidget *label;
-    gboolean   show;
-    GString   *data; /* the time formatting data */
-    GString   *font;
-    gchar      prev[OC_MAX_LINE_LENGTH+1];
-} ClockLine;
+#define OC_BASE_INTERVAL 1000       /* best accurance of the clock = 1 sec */
+#define OC_CONFIG_INTERVAL 200      /* special fast interval used in setup */
+#define OC_RC_COLOR "%uR %uG %uB"   /* this is how we store colors */
 
 typedef struct _clock
 {
@@ -39,18 +31,19 @@ typedef struct _clock
     GtkWidget *ebox;
     GtkWidget *frame;
     GtkWidget *vbox;
-    gboolean   width_set;
-    gint       width;
-    gboolean   height_set;
-    gint       height;
     gboolean   show_frame;
     gboolean   fg_set;
     GdkColor   fg;
     gboolean   bg_set;
     GdkColor   bg;
+    gboolean   width_set;
+    gint       width;
+    gboolean   height_set;
+    gint       height;
     GString   *timezone;
     gchar     *TZ_orig;
-    ClockLine  line[OC_MAX_LINES];
+    GList     *lines;
+    gint       orig_line_cnt;
     GString   *tooltip_data;
     gchar      tooltip_prev[OC_MAX_LINE_LENGTH+1];
     gboolean   hib_timing;
@@ -59,9 +52,18 @@ typedef struct _clock
     int timeout_id;  /* timer id for the clock */
     int delay_timeout_id;
     int interval;
-    struct tm   now;
+    struct tm  now;
 } Clock;
 
+typedef struct _clockline
+{
+    GtkWidget *label;
+    GString   *data; /* the time formatting data */
+    GString   *font;
+    gchar      prev[OC_MAX_LINE_LENGTH+1];
+    Clock     *clock; /* pointer back to main clock structure */
+} ClockLine;
+
 void oc_properties_dialog(XfcePanelPlugin *plugin, Clock *clock);
 
 void oc_show_frame_set(Clock *clock);
@@ -69,10 +71,8 @@ void oc_fg_set(Clock *clock);
 void oc_bg_set(Clock *clock);
 void oc_size_set(Clock *clock);
 void oc_timezone_set(Clock *clock);
-void oc_show_line_set(Clock *clock, gint lno);
-void oc_line_font_set(Clock *clock, gint lno);
-void oc_hib_timing_set(Clock *clock);
+void oc_line_font_set(ClockLine *line);
 void oc_write_rc_file(XfcePanelPlugin *plugin, Clock *clock);
 void oc_start_timer(Clock *clock);
 void oc_init_timer(Clock *clock);
-
+void oc_add_line(Clock *clock, char *data, char *font, int pos);
diff --git a/src/appointment.c b/src/appointment.c
index 2ab8e33..d69c8d5 100644
--- a/src/appointment.c
+++ b/src/appointment.c
@@ -1680,8 +1680,7 @@ GdkColor *orage_category_list_contains(char *categories)
     
     if (categories == NULL)
         return(NULL);
-    cat_l = orage_category_list;
-    for (cat_l = g_list_first(cat_l);
+    for (cat_l = g_list_first(orage_category_list);
          cat_l != NULL;
          cat_l = g_list_next(cat_l)) {
         cat = (orage_category_struct *)cat_l->data;
diff --git a/src/ical-code.c b/src/ical-code.c
index 720d674..2ef5851 100644
--- a/src/ical-code.c
+++ b/src/ical-code.c
@@ -2740,7 +2740,7 @@ static void process_alarm_data(icalcomponent *ca, 
alarm_struct *new_alarm)
     get_alarm_data(ca, appt);
 
     new_alarm->persistent = appt->alarm_persistent;
-    if (appt->display_alarm_orage ||  appt->display_alarm_notify) {
+    if (appt->display_alarm_orage || appt->display_alarm_notify) {
         new_alarm->display_orage = appt->display_alarm_orage;
         new_alarm->display_notify = appt->display_alarm_notify;
         new_alarm->notify_timeout = appt->display_notify_timeout;
diff --git a/src/main.c b/src/main.c
index 8b614e5..d5ed68a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -214,7 +214,7 @@ static void print_version(void)
 #ifdef HAVE_LIBICAL
     g_print(_("\tUsing operating system package libical.\n"));
 #else
-    g_print(_("\tUsing Oracle local version of libical.\n"));
+    g_print(_("\tUsing Orage local version of libical.\n"));
 #endif
     g_print("\n");
 }
diff --git a/src/reminder.c b/src/reminder.c
index 39bbe1b..e53c457 100644
--- a/src/reminder.c
+++ b/src/reminder.c
@@ -199,9 +199,9 @@ static alarm_struct *alarm_copy(alarm_struct *alarm, 
gboolean init)
     if (alarm->uid != NULL)
         n_alarm->uid = g_strdup(alarm->uid);
     if (alarm->title != NULL)
-        n_alarm->title = g_strdup(alarm->title);
+        n_alarm->title = orage_process_text_commands(alarm->title);
     if (alarm->description != NULL)
-        n_alarm->description = g_strdup(alarm->description);
+        n_alarm->description = orage_process_text_commands(alarm->description);
     n_alarm->persistent = alarm->persistent;
     n_alarm->temporary = FALSE;
     n_alarm->notify_timeout = alarm->notify_timeout;
@@ -927,8 +927,7 @@ static gboolean orage_alarm_clock(gpointer user_data)
     t = orage_localtime();
     time_now = orage_tm_time_to_icaltime(t);
   /* Check if there are any alarms to show */
-    alarm_l = g_par.alarm_list;
-    for (alarm_l = g_list_first(alarm_l);
+    for (alarm_l = g_list_first(g_par.alarm_list);
          alarm_l != NULL && more_alarms;
          alarm_l = g_list_next(alarm_l)) {
         /* remember that it is sorted list */
@@ -1016,8 +1015,7 @@ static gboolean orage_tooltip_update(gpointer user_data)
     g_string_append(tooltip, " </span>");
 #endif
   /* Check if there are any alarms to show */
-    alarm_l = g_par.alarm_list;
-    for (alarm_l = g_list_first(alarm_l);
+    for (alarm_l = g_list_first(g_par.alarm_list);
          alarm_l != NULL && more_alarms;
          alarm_l = g_list_next(alarm_l)) {
         /* remember that it is sorted list */
_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to