[Xfce4-commits] [apps/orage] 01/01: 4.11.1 Implemented enhacement 10947: Orage vertical panel clock

noreply at xfce.org noreply at xfce.org
Mon Sep 22 12:42:42 CEST 2014


This is an automated email from the git hooks/post-receive script.

juha pushed a commit to branch master
in repository apps/orage.

commit 30413ccdd5906a49a785666d310ca2a4b72ebe37
Author: Juha Kautto <juha at xfce.org>
Date:   Mon Sep 22 13:27:37 2014 +0300

    4.11.1 Implemented enhacement 10947: Orage vertical panel clock
    
    It is now possible to rotate lines, which is usefull for vertical panels.
    Also added configuration option to put rows below each other or side by side.
---
 configure.in.in                        |    2 +-
 panel-plugin/oc_config.c               |   56 +++++++++++---
 panel-plugin/xfce4-orageclock-plugin.c |  126 +++++++++++++++++++++++++-------
 panel-plugin/xfce4-orageclock-plugin.h |   10 ++-
 4 files changed, 154 insertions(+), 40 deletions(-)

diff --git a/configure.in.in b/configure.in.in
index bda4849..cd2be1b 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -9,7 +9,7 @@ dnl Written for Xfce by Juha Kautto <juha at xfce.org>
 dnl
 
 dnl Version information
-m4_define([orage_version], [4.11.0-git])
+m4_define([orage_version], [4.11.1-git])
 
 m4_define([gtk_minimum_version], [2.14.0])
 m4_define([xfce_minimum_version], [4.8.0])
diff --git a/panel-plugin/oc_config.c b/panel-plugin/oc_config.c
index 29ccb63..268cc14 100644
--- a/panel-plugin/oc_config.c
+++ b/panel-plugin/oc_config.c
@@ -102,6 +102,25 @@ static void oc_set_width_changed(GtkSpinButton *sb, Clock *clock)
     oc_size_set(clock);
 }
 
+static void oc_rotation_changed(GtkComboBox *cb, Clock *clock)
+{
+    GList *tmp_list;
+
+    clock->rotation = gtk_combo_box_get_active(cb);
+    for (tmp_list = g_list_first(clock->lines);
+            tmp_list;
+         tmp_list = g_list_next(tmp_list)) {
+        oc_line_rotate(clock, tmp_list->data);
+    }
+}
+
+static void oc_lines_vertically_toggled(GtkToggleButton *cb, Clock *clock)
+{
+    clock->lines_vertically = gtk_toggle_button_get_active(cb);
+
+    oc_reorganize_lines(clock);
+}
+
 static void oc_timezone_selected(GtkButton *button, Clock *clock)
 {
     GtkWidget *dialog;
@@ -150,10 +169,12 @@ static void oc_recreate_properties_options(Clock *clock)
 static void oc_new_line(GtkToolButton *toolbutton, ClockLine *line)
 {
     Clock *clock = line->clock;;
+    ClockLine *new_line;
     gint pos;
-
     pos = g_list_index(clock->lines, line);
-    oc_add_line(clock, "%X", "", pos+1);
+    new_line = oc_add_new_line(clock, "%X", "", pos+1);
+    oc_set_line(clock, new_line, pos+1);
+    oc_fg_set(clock);
 
     oc_recreate_properties_options(clock);
 }
@@ -179,7 +200,7 @@ static void oc_move_up_line(GtkToolButton *toolbutton, ClockLine *line)
 
     pos = g_list_index(clock->lines, line);
     pos--;
-    gtk_box_reorder_child(GTK_BOX(clock->vbox), line->label, pos);
+    gtk_box_reorder_child(GTK_BOX(clock->mbox), line->label, pos);
     clock->lines = g_list_remove(clock->lines, line);
     clock->lines = g_list_insert(clock->lines, line, pos);
 
@@ -196,7 +217,7 @@ static void oc_move_down_line(GtkToolButton *toolbutton, ClockLine *line)
     pos++;
     if (pos == line_cnt)
         pos = 0;
-    gtk_box_reorder_child(GTK_BOX(clock->vbox), line->label, pos);
+    gtk_box_reorder_child(GTK_BOX(clock->mbox), line->label, pos);
     clock->lines = g_list_remove(clock->lines, line);
     clock->lines = g_list_insert(clock->lines, line, pos);
 
@@ -215,8 +236,11 @@ static void oc_properties_appearance(GtkWidget *dlg, Clock *clock)
     GdkColor def_fg, def_bg;
     GtkStyle *def_style;
     GtkWidget *table;
+    char *clock_rotation_array[3] = {_("No rotation"), _("Rotate left")
+        , _("Rotate right")};
+
 
-    table = gtk_table_new(3, 4, FALSE);
+    table = gtk_table_new(4, 4, FALSE); /* rows, columns */
     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);
@@ -224,16 +248,16 @@ static void oc_properties_appearance(GtkWidget *dlg, Clock *clock)
     frame = orage_create_framebox_with_content(_("Appearance"), table);
     gtk_container_set_border_width(GTK_CONTAINER(frame), 6);
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), frame, FALSE, FALSE, 0);
+    
+    def_style = gtk_widget_get_default_style();
+    def_fg = def_style->fg[GTK_STATE_NORMAL];
+    def_bg = def_style->bg[GTK_STATE_NORMAL];
 
     /* show frame */
     cb = gtk_check_button_new_with_mnemonic(_("Show _frame"));
     oc_table_add(table, cb, 0, 0);
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb), clock->show_frame);
     g_signal_connect(cb, "toggled", G_CALLBACK(oc_show_frame_toggled), clock);
-    
-    def_style = gtk_widget_get_default_style();
-    def_fg = def_style->fg[GTK_STATE_NORMAL];
-    def_bg = def_style->bg[GTK_STATE_NORMAL];
 
     /* foreground color */
     cb = gtk_check_button_new_with_mnemonic(_("set foreground _color:"));
@@ -263,7 +287,7 @@ static void oc_properties_appearance(GtkWidget *dlg, Clock *clock)
     g_signal_connect(G_OBJECT(color), "color-set"
             , G_CALLBACK(oc_bg_color_changed), clock);
 
-    /* clock size (=vbox size): height and width */
+    /* clock size (=mbox size): height and width */
     cb = gtk_check_button_new_with_mnemonic(_("set _height:"));
     oc_table_add(table, cb, 0, 2);
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb), clock->height_set);
@@ -285,7 +309,6 @@ static void oc_properties_appearance(GtkWidget *dlg, Clock *clock)
     g_signal_connect(cb, "toggled", G_CALLBACK(oc_set_width_toggled), clock);
     sb = gtk_spin_button_new_with_range(10, 400, 1);
     oc_table_add(table, sb, 3, 2);
-
     if (!clock->width_set)
         clock->width = 70;
     gtk_spin_button_set_value(GTK_SPIN_BUTTON(sb), (gdouble)clock->width);
@@ -294,6 +317,17 @@ static void oc_properties_appearance(GtkWidget *dlg, Clock *clock)
             , NULL);
     g_signal_connect((gpointer) sb, "value-changed",
             G_CALLBACK(oc_set_width_changed), clock);
+
+    /* rotation and line (=box) position (top / left) */
+    cb = orage_create_combo_box_with_content(clock_rotation_array, 3);
+    oc_table_add(table, cb, 0, 3);
+    gtk_combo_box_set_active(GTK_COMBO_BOX(cb), clock->rotation);
+    g_signal_connect(cb, "changed", G_CALLBACK(oc_rotation_changed), clock);
+
+    cb = gtk_check_button_new_with_mnemonic(_("Show lines _vertically"));
+    oc_table_add(table, cb, 2, 3);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb), clock->lines_vertically);
+    g_signal_connect(cb, "toggled", G_CALLBACK(oc_lines_vertically_toggled), clock);
 }
 
 void oc_properties_options(GtkWidget *dlg, Clock *clock)
diff --git a/panel-plugin/xfce4-orageclock-plugin.c b/panel-plugin/xfce4-orageclock-plugin.c
index 4a6ad8f..96573c9 100644
--- a/panel-plugin/xfce4-orageclock-plugin.c
+++ b/panel-plugin/xfce4-orageclock-plugin.c
@@ -82,27 +82,65 @@ void oc_line_font_set(ClockLine *line)
         gtk_widget_modify_font(line->label, NULL);
 }
 
-void oc_add_line(Clock *clock, char *data, char *font, int pos)
+void oc_line_rotate(Clock *clock, ClockLine *line)
 {
-    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;
+    switch (clock->rotation) {
+        case 0:
+            gtk_label_set_angle(GTK_LABEL(line->label), 0);
+            break;
+        case 1:
+            gtk_label_set_angle(GTK_LABEL(line->label), 90);
+            break;
+        case 2:
+            gtk_label_set_angle(GTK_LABEL(line->label), 270);
+            break;
+    }
+}
 
+void oc_set_line(Clock *clock, ClockLine *clock_line, int pos)
+{
     clock_line->label = gtk_label_new("");
-    gtk_box_pack_start(GTK_BOX(clock->vbox), clock_line->label
+    gtk_box_pack_start(GTK_BOX(clock->mbox), clock_line->label
             , FALSE, FALSE, 0);
-    gtk_box_reorder_child(GTK_BOX(clock->vbox), clock_line->label, pos);
+    gtk_box_reorder_child(GTK_BOX(clock->mbox), clock_line->label, pos);
     oc_line_font_set(clock_line);
+    oc_line_rotate(clock, 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_set_lines_to_panel(Clock *clock)
+{
+    ClockLine *clock_line;
+    GList   *tmp_list;
+
+    if (clock->lines_vertically)
+        clock->mbox = gtk_vbox_new(TRUE, 0);
+    else
+        clock->mbox = gtk_hbox_new(TRUE, 0);
+    gtk_widget_show(clock->mbox);
+    gtk_container_add(GTK_CONTAINER(clock->frame), clock->mbox);
+
+    for (tmp_list = g_list_first(clock->lines); 
+            tmp_list;
+         tmp_list = g_list_next(tmp_list)) {
+        clock_line = tmp_list->data;
+        /* make sure clock face is updated */
+        strcpy(clock_line->prev, "New line");
+        oc_set_line(clock, clock_line, -1);
+    }
+}
+
+void oc_reorganize_lines(Clock *clock)
+{
+    /* let's just do this easily as it is very seldom called: 
+       delete and recreate lines */
+    gtk_widget_destroy(GTK_WIDGET(clock->mbox));
+    oc_set_lines_to_panel(clock);
+    oc_fg_set(clock);
+    oc_size_set(clock);
 }
 
 static void oc_tooltip_set(Clock *clock)
@@ -298,11 +336,9 @@ static void oc_update_size(Clock *clock, int size)
 {
     if (size > 26) {
         gtk_container_set_border_width(GTK_CONTAINER(clock->frame), 2);
-        size -= 3;
     }
     else {
         gtk_container_set_border_width(GTK_CONTAINER(clock->frame), 0);
-        size -= 1;
     }
 }
 
@@ -401,6 +437,22 @@ static gboolean on_button_press_event_cb(GtkWidget *widget
 static gboolean oc_set_size(XfcePanelPlugin *plugin, int size, Clock *clock)
 {
     oc_update_size(clock, size);
+    if (clock->first_call) {
+    /* default is horizontal panel. 
+       we need to check and change if it is vertical */
+        if (xfce_panel_plugin_get_mode(plugin) 
+                == XFCE_PANEL_PLUGIN_MODE_VERTICAL) {
+            clock->lines_vertically = FALSE;
+        /* check rotation handling from oc_rotation_changed in oc_config.c */
+            if (xfce_screen_position_is_right(
+                        xfce_panel_plugin_get_screen_position(plugin)))
+                clock->rotation = 2;
+            else
+                clock->rotation = 1;
+            oc_reorganize_lines(clock);
+        }
+
+    }
 
     return(TRUE);
 }
@@ -440,6 +492,18 @@ static GdkColor oc_rc_read_color(XfceRc *rc, char *par, char *def)
     return(color);
 }
 
+ClockLine * oc_add_new_line(Clock *clock, const char *data, const char *font, int pos)
+{
+    ClockLine *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->lines = g_list_insert(clock->lines, clock_line, pos);
+    return(clock_line);
+}
+
 static void oc_read_rc_file(XfcePanelPlugin *plugin, Clock *clock)
 {
     gchar  *file;
@@ -455,6 +519,7 @@ static void oc_read_rc_file(XfcePanelPlugin *plugin, Clock *clock)
         g_warning("unable to read-open rc file (%s)", file);
         return;
     }
+    clock->first_call = FALSE;
 
     clock->show_frame = xfce_rc_read_bool_entry(rc, "show_frame", TRUE);
 
@@ -480,6 +545,9 @@ static void oc_read_rc_file(XfcePanelPlugin *plugin, Clock *clock)
     if (clock->height_set) {
         clock->height = xfce_rc_read_int_entry(rc, "height", -1);
     }
+
+    clock->lines_vertically = xfce_rc_read_bool_entry(rc, "lines_vertically", FALSE);
+    clock->rotation = xfce_rc_read_int_entry(rc, "rotation", 0);
     
     for (i = 0, more_lines = TRUE; more_lines; i++) {
         sprintf(tmp, "data%d", i);
@@ -487,7 +555,7 @@ static void oc_read_rc_file(XfcePanelPlugin *plugin, Clock *clock)
         if (data) { /* let's add it */
             sprintf(tmp, "font%d", i);
             font = xfce_rc_read_entry(rc, tmp, NULL);
-            oc_add_line(clock, (char *)data, (char *)font, -1);
+            oc_add_new_line(clock, data, font, -1);
         }
         else { /* no more clock lines */
             more_lines = FALSE;
@@ -562,6 +630,9 @@ void oc_write_rc_file(XfcePanelPlugin *plugin, Clock *clock)
         xfce_rc_delete_entry(rc, "height", TRUE);
     }
 
+    xfce_rc_write_bool_entry(rc, "lines_vertically", clock->lines_vertically);
+    xfce_rc_write_int_entry(rc, "rotation", clock->rotation);
+
     for (i = 0, tmp_list = g_list_first(clock->lines);
             tmp_list;
          i++, tmp_list = g_list_next(tmp_list)) {
@@ -589,8 +660,9 @@ 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);
+    Clock *clock = g_new0(Clock, 1);
 
+    clock->first_call = TRUE; /* this is starting point */
     clock->plugin = plugin;
 
     clock->ebox = gtk_event_box_new();
@@ -600,20 +672,21 @@ Clock *orage_oc_new(XfcePanelPlugin *plugin)
     gtk_container_add(GTK_CONTAINER(clock->ebox), clock->frame);
     gtk_widget_show(clock->frame);
 
-    clock->vbox = gtk_vbox_new(TRUE, 0);
-    gtk_widget_show(clock->vbox);
-    gtk_container_add(GTK_CONTAINER(clock->frame), clock->vbox);
+    gtk_container_add(GTK_CONTAINER(plugin), clock->ebox);
 
     clock->show_frame = TRUE;
     clock->fg_set = FALSE;
     clock->bg_set = FALSE;
     clock->width_set = FALSE;
     clock->height_set = FALSE;
+    clock->lines_vertically = TRUE;
+    clock->rotation = 0; /* no rotation */
 
     clock->timezone = g_string_new(""); /* = not set */
     clock->TZ_orig = g_strdup(g_getenv("TZ"));
 
     clock->lines = NULL; /* no lines yet */
+    clock->orig_line_cnt = 0;
 
     /* TRANSLATORS: Use format characters from strftime(3)
      * to get the proper string for your locale.
@@ -689,7 +762,7 @@ void oc_size_set(Clock *clock)
 
     w = clock->width_set ? clock->width : -1;
     h = clock->height_set ? clock->height : -1;
-    gtk_widget_set_size_request(clock->vbox, w, h);
+    gtk_widget_set_size_request(clock->mbox, w, h);
 }
 
 static void oc_construct(XfcePanelPlugin *plugin)
@@ -700,12 +773,12 @@ static void oc_construct(XfcePanelPlugin *plugin)
 
     clock = orage_oc_new(plugin);
 
-    gtk_container_add(GTK_CONTAINER(plugin), clock->ebox);
-
     oc_read_rc_file(plugin, clock);
-    if (clock->lines == NULL) /* Let's setup a default clock_line */
-        oc_add_line(clock, "%X", "", -1);
+    if (clock->lines == NULL) { /* Let's setup a default clock_line */
+        oc_add_new_line(clock, "%X", "", -1);
+    }
 
+    oc_set_lines_to_panel(clock);
     oc_show_frame_set(clock);
     oc_fg_set(clock);
     oc_bg_set(clock);
@@ -714,8 +787,9 @@ static void oc_construct(XfcePanelPlugin *plugin)
 
     oc_init_timer(clock);
 
-    oc_update_size(clock, 
-            xfce_panel_plugin_get_size(XFCE_PANEL_PLUGIN(plugin)));
+    /* we are called through size-changed trigger
+    oc_update_size(clock, xfce_panel_plugin_get_size(plugin));
+    */
 
     xfce_panel_plugin_add_action_widget(plugin, clock->ebox);
     
diff --git a/panel-plugin/xfce4-orageclock-plugin.h b/panel-plugin/xfce4-orageclock-plugin.h
index 7b923e7..d5b23e1 100644
--- a/panel-plugin/xfce4-orageclock-plugin.h
+++ b/panel-plugin/xfce4-orageclock-plugin.h
@@ -30,7 +30,7 @@ typedef struct _clock
 
     GtkWidget *ebox;
     GtkWidget *frame;
-    GtkWidget *vbox;
+    GtkWidget *mbox; /* main box. Either vertical or horizontal */
     gboolean   show_frame;
     gboolean   fg_set;
     GdkColor   fg;
@@ -40,6 +40,8 @@ typedef struct _clock
     gint       width;
     gboolean   height_set;
     gint       height;
+    gboolean   lines_vertically;
+    gint       rotation;
     GString   *timezone;
     gchar     *TZ_orig;
     GList     *lines;
@@ -53,6 +55,7 @@ typedef struct _clock
     int delay_timeout_id;
     int interval;
     struct tm  now;
+    gboolean first_call; /* set defaults correct when clock is created */
 } Clock;
 
 typedef struct _clockline
@@ -72,7 +75,10 @@ void oc_bg_set(Clock *clock);
 void oc_size_set(Clock *clock);
 void oc_timezone_set(Clock *clock);
 void oc_line_font_set(ClockLine *line);
+void oc_line_rotate(Clock *clock, 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);
+void oc_set_line(Clock *clock, ClockLine *clock_line, int pos);
+ClockLine * oc_add_new_line(Clock *clock, const char *data, const char *font, int pos);
+void oc_reorganize_lines(Clock *clock);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list