From 45218a79918ec554cd666272fc738ebfcebc3fbc Mon Sep 17 00:00:00 2001 From: Thomas Wood Date: Tue, 5 Oct 2010 10:35:35 +0100 Subject: [PATCH] datetime: Start implementing new UI designs New UI design from Jakub Steiner and Hylke Bons --- panels/datetime/Makefile.am | 1 + panels/datetime/cc-datetime-panel.c | 158 +++++--- panels/datetime/cc-timezone-map.c | 95 +---- panels/datetime/data/pin.png | Bin 0 -> 561 bytes panels/datetime/datetime.ui | 582 +++++++++++++++++++--------- 5 files changed, 529 insertions(+), 307 deletions(-) create mode 100644 panels/datetime/data/pin.png diff --git a/panels/datetime/Makefile.am b/panels/datetime/Makefile.am index 0fd2f2f4a..7afc3f08a 100644 --- a/panels/datetime/Makefile.am +++ b/panels/datetime/Makefile.am @@ -19,6 +19,7 @@ dist_ui_DATA = \ datetime.ui \ data/bg.png \ data/cc.png \ + data/pin.png \ data/timezone_0.png \ data/timezone_-10.png \ data/timezone_10.png \ diff --git a/panels/datetime/cc-datetime-panel.c b/panels/datetime/cc-datetime-panel.c index 773ea03cc..084e650f1 100644 --- a/panels/datetime/cc-datetime-panel.c +++ b/panels/datetime/cc-datetime-panel.c @@ -23,6 +23,8 @@ #include "cc-timezone-map.h" #include "set-timezone.h" +#include +#include G_DEFINE_DYNAMIC_TYPE (CcDateTimePanel, cc_date_time_panel, CC_TYPE_PANEL) @@ -36,6 +38,8 @@ enum { CITY_NUM_COLS }; +#define W(x) (GtkWidget*) gtk_builder_get_object (priv->builder, x) + struct _CcDateTimePanelPrivate { GtkBuilder *builder; @@ -47,6 +51,9 @@ struct _CcDateTimePanelPrivate GtkTreeModel *locations; GtkTreeModelFilter *city_filter; + + guint hour; + guint minute; }; @@ -130,16 +137,25 @@ update_time (CcDateTimePanel *self) GtkWidget *widget; gchar label[32]; time_t t; + struct tm time_info; g_get_current_time (&timeval); - priv->timeout = gdk_threads_add_timeout (1000 - timeval.tv_usec / 1000, - (GSourceFunc) update_time, self); - - widget = (GtkWidget*) gtk_builder_get_object (priv->builder, - "label_current_time"); t = time (NULL); - strftime (label, 32, "%X", localtime (&t)); + + localtime_r (&t, &time_info); + + priv->hour = time_info.tm_hour; + priv->minute = time_info.tm_min; + + /* Update the hours label */ + strftime (label, 32, "%H", &time_info); + widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "hours_label"); + gtk_label_set_text (GTK_LABEL (widget), label); + + /* Update the minutes label */ + strftime (label, 32, "%M", &time_info); + widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "minutes_label"); gtk_label_set_text (GTK_LABEL (widget), label); return FALSE; @@ -171,24 +187,22 @@ static void apply_button_clicked_cb (GtkButton *button, CcDateTimePanel *self) { - GtkWidget *widget; CcDateTimePanelPrivate *priv = self->priv; - guint h, mon, y, min, d; + guint mon, y, d; struct tm fulltime; time_t unixtime; gchar *filename; - widget = (GtkWidget *) gtk_builder_get_object (priv->builder, "spin_hour"); - h = gtk_spin_button_get_value (GTK_SPIN_BUTTON (widget)); - widget = (GtkWidget *) gtk_builder_get_object (priv->builder, "spin_minute"); - min = gtk_spin_button_get_value (GTK_SPIN_BUTTON (widget)); + mon = 1 + gtk_combo_box_get_active (GTK_COMBO_BOX (W ("month-combobox"))); + + y = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (W ("year-spinbutton"))); + d = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (W ("day-spinbutton"))); + - widget = (GtkWidget *) gtk_builder_get_object (priv->builder, "calendar"); - gtk_calendar_get_date (GTK_CALENDAR (widget), &y, &mon, &d); fulltime.tm_sec = 0; - fulltime.tm_min = min; - fulltime.tm_hour = h; + fulltime.tm_min = priv->minute; + fulltime.tm_hour = priv->hour; fulltime.tm_mday = d; fulltime.tm_mon = mon; fulltime.tm_year = y - 1900; @@ -217,7 +231,6 @@ location_changed_cb (CcTimezoneMap *map, GtkWidget *widget; time_t t; struct tm *ltime; - gchar slabel[32]; gchar **split; GtkTreeIter iter; GtkTreeModel *model; @@ -230,16 +243,6 @@ location_changed_cb (CcTimezoneMap *map, t = time (NULL); ltime = localtime (&t); - widget = (GtkWidget *) gtk_builder_get_object (priv->builder, "spin_hour"); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), ltime->tm_hour); - widget = (GtkWidget *) gtk_builder_get_object (priv->builder, "spin_minute"); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), ltime->tm_min); - - widget = (GtkWidget*) gtk_builder_get_object (priv->builder, - "label_current_time"); - strftime (slabel, 32, "%X", localtime (&t)); - gtk_label_set_text (GTK_LABEL (widget), slabel); - split = g_strsplit (location->zone, "/", 2); /* remove underscores */ @@ -433,18 +436,59 @@ city_changed_cb (GtkComboBox *box, inside = FALSE; } +static void +change_time (GtkButton *button, + CcDateTimePanel *panel) +{ + CcDateTimePanelPrivate *priv = panel->priv; + const gchar *widget_name; + gchar *new_str; + guint *value, max, min; + GtkWidget *label; + + widget_name = gtk_buildable_get_name (GTK_BUILDABLE (button)); + + min = 0; + if (widget_name[0] == 'h') + { + /* change hour */ + label = W ("hours_label"); + max = 23; + value = &priv->hour; + } + else + { + /* change minute */ + label = W ("minutes_label"); + max = 59; + value = &priv->minute; + } + + if (strstr (widget_name, "up")) + *value = *value + 1; + else + *value = *value - 1; + + if (*value > max) + *value = min; + else if (*value < min) + *value = max; + + new_str = g_strdup_printf ("%02d", *value); + gtk_label_set_text (GTK_LABEL (label), new_str); + g_free (new_str); +} + static void cc_date_time_panel_init (CcDateTimePanel *self) { CcDateTimePanelPrivate *priv; - gchar *objects[] = { "datetime-panel", "adjustment_min", "adjustment_hour", - "adjustment_sec", "region-liststore", "city-liststore", - "city-modelfilter", "city-modelsort", NULL }; + gchar *objects[] = { "datetime-panel", "region-liststore", "city-liststore", + "month-liststore", "city-modelfilter", "city-modelsort", NULL }; GtkWidget *widget; + GtkAdjustment *adjustment; GError *err = NULL; GDate *date; - struct tm *ltime; - time_t t; GtkTreeModelFilter *city_modelfilter; GtkTreeModelSort *city_modelsort; int ret; @@ -464,6 +508,37 @@ cc_date_time_panel_init (CcDateTimePanel *self) return; } + /* set up time editing widgets */ + g_signal_connect (W("hour_up_button"), "clicked", G_CALLBACK (change_time), + self); + g_signal_connect (W("hour_down_button"), "clicked", G_CALLBACK (change_time), + self); + g_signal_connect (W("min_up_button"), "clicked", G_CALLBACK (change_time), + self); + g_signal_connect (W("min_down_button"), "clicked", G_CALLBACK (change_time), + self); + + /* set up date editing widgets */ + date = g_date_new (); + g_date_set_time_t (date, time (NULL)); + + gtk_combo_box_set_active (GTK_COMBO_BOX (W ("month-combobox")), + g_date_get_month (date) - 1); + + adjustment = (GtkAdjustment*) gtk_adjustment_new (g_date_get_day (date), 0, + 31, 1, 10, 1); + gtk_spin_button_set_adjustment (GTK_SPIN_BUTTON (W ("day-spinbutton")), + adjustment); + + adjustment = (GtkAdjustment*) gtk_adjustment_new (g_date_get_year (date), + G_MINDOUBLE, G_MAXDOUBLE, 1, + 10, 1); + gtk_spin_button_set_adjustment (GTK_SPIN_BUTTON (W ("year-spinbutton")), + adjustment); + g_date_free (date); + date = NULL; + + /* set up timezone map */ priv->map = widget = (GtkWidget *) cc_timezone_map_new (); g_signal_connect (widget, "location-changed", G_CALLBACK (location_changed_cb), self); @@ -477,26 +552,11 @@ cc_date_time_panel_init (CcDateTimePanel *self) GTK_WIDGET (gtk_builder_get_object (priv->builder, "datetime-panel"))); - widget = (GtkWidget *) gtk_builder_get_object (priv->builder, "calendar"); - date = g_date_new (); - g_date_set_time_t (date, time (NULL)); - gtk_calendar_select_day (GTK_CALENDAR (widget), g_date_get_day (date)); - gtk_calendar_select_month (GTK_CALENDAR (widget), g_date_get_month (date) -1, - g_date_get_year (date)); - g_date_free (date); - date = NULL; update_time (self); - t = time (NULL); - ltime = localtime (&t); - - widget = (GtkWidget *) gtk_builder_get_object (priv->builder, "spin_hour"); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), ltime->tm_hour); - widget = (GtkWidget *) gtk_builder_get_object (priv->builder, "spin_minute"); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), ltime->tm_min); - - g_signal_connect ((GtkWidget*) gtk_builder_get_object (priv->builder, "button_apply"), + g_signal_connect ((GtkWidget*) gtk_builder_get_object (priv->builder, + "button_apply"), "clicked", G_CALLBACK (apply_button_clicked_cb), self); diff --git a/panels/datetime/cc-timezone-map.c b/panels/datetime/cc-timezone-map.c index fa4bc2e1b..487d09cef 100644 --- a/panels/datetime/cc-timezone-map.c +++ b/panels/datetime/cc-timezone-map.c @@ -194,6 +194,8 @@ cc_timezone_map_size_request (GtkWidget *widget, { CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv; + GTK_WIDGET_CLASS (cc_timezone_map_parent_class)->size_request (widget, req); + req->width = gdk_pixbuf_get_width (priv->orig_background) * 0.6; req->height = gdk_pixbuf_get_height (priv->orig_background) * 0.6; } @@ -306,7 +308,7 @@ cc_timezone_map_draw (GtkWidget *widget, cairo_t *cr) { CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv; - GdkPixbuf *hilight, *orig_hilight; + GdkPixbuf *hilight, *orig_hilight, *pin; GtkAllocation alloc; gchar *file; GError *err = NULL; @@ -344,92 +346,33 @@ cc_timezone_map_draw (GtkWidget *widget, g_object_unref (orig_hilight); } + /* load pin icon */ + pin = gdk_pixbuf_new_from_file (DATADIR "/pin.png", &err); + + if (err) + { + g_warning ("Could not load pin icon: %s", err->message); + g_clear_error (&err); + } + if (priv->location) { - PangoLayout *layout; - PangoRectangle rect; - gint width, height; - gdouble x1, y1, radius = 5; - gchar *zone; - pointx = convert_longtitude_to_x (priv->location->longitude, alloc.width); pointy = convert_latitude_to_y (priv->location->latitude, alloc.height); if (pointy > alloc.height) pointy = alloc.height; - /* allow for the line width */ - pointy -= 2; - - zone = g_strdup (priv->location->zone); - - /* convert underscores to spaces */ - g_strdelimit (zone, "_", ' '); - - layout = gtk_widget_create_pango_layout (widget, zone); - - pango_layout_get_pixel_extents (layout, NULL, &rect); - width = rect.width - rect.x; - height = rect.height - rect.y; - - x1 = (int) (pointx - width / 2); - y1 = (int) (pointy - 10 - height - radius); - - /* rotate the bubble upside-down if there is not enough vertical room */ - if (y1 < radius) + if (pin) { - cairo_translate (cr, pointx, pointy); - cairo_rotate (cr, G_PI); - cairo_translate (cr, -pointx, -pointy); + gdk_cairo_set_source_pixbuf (cr, pin, pointx - 8, pointy - 14); + cairo_paint (cr); } + } - /* offset the arrow if there is not enough horizontal room */ - if (x1 - radius - 2 < 0) - x1 -= (x1 - radius - 2); - - if (x1 + width + radius + 2 > alloc.width) - x1 -= (x1 + width + radius + 2) - alloc.width; - - /* draw the bubble */ - cairo_arc (cr, x1, y1, radius, G_PI, G_PI * 1.5); - cairo_line_to (cr, x1 + width, y1 - radius); - - cairo_arc (cr, x1 + width, y1, radius, G_PI * 1.5, 0); - cairo_line_to (cr, x1 + width + radius, y1 + height); - - cairo_arc (cr, x1 + width, y1 + height, radius, 0, G_PI * 0.5); - cairo_line_to (cr, pointx + 10, pointy - 10); - - cairo_line_to (cr, pointx, pointy); - cairo_line_to (cr, pointx - 10, pointy - 10); - cairo_line_to (cr, x1, y1 + height + radius); - - cairo_arc (cr, x1, y1 + height, radius, G_PI * 0.5, G_PI); - cairo_line_to (cr, x1 - radius, y1); - - cairo_set_source_rgba (cr, 1, 1, 1, 0.7); - cairo_fill_preserve (cr); - - cairo_set_source_rgba (cr, 0, 0, 0, 0.7); - cairo_stroke (cr); - - - if (y1 < radius) - { - cairo_translate (cr, pointx, pointy); - cairo_rotate (cr, G_PI); - cairo_translate (cr, -pointx, -pointy); - - y1 += height + 20 + 2 * radius; - } - - /* draw the location name */ - cairo_set_source_rgb (cr, 0, 0, 0); - cairo_move_to (cr, x1, y1); - pango_cairo_show_layout (cr, layout); - - g_object_unref (layout); - g_free (zone); + if (pin) + { + g_object_unref (pin); } return TRUE; diff --git a/panels/datetime/data/pin.png b/panels/datetime/data/pin.png new file mode 100644 index 0000000000000000000000000000000000000000..599a751e2d955a72bc96115cb9f0e431a43434ca GIT binary patch literal 561 zcmV-10?z%3P)4I4F`kNg6A#UhP% zuix52EMn_V2!fEpe!(L379uVP79vO>3Oj*B!7v#$bGJ~zm-vEuU|^c4RN5BuGd zlN;;Y(lA84KS&{}6VubV-1@qgkP`0d3W;n4BpH4eH0fL;ro7^Wi-Ud+lZb! zoeqfT`C9-fq#m1#sNk`{HkI*_^kc|6Z_aBdO1xe00000NkvXXu0mjfioEQ% literal 0 HcmV?d00001 diff --git a/panels/datetime/datetime.ui b/panels/datetime/datetime.ui index 0d94fa40e..d9e551baa 100644 --- a/panels/datetime/datetime.ui +++ b/panels/datetime/datetime.ui @@ -4,44 +4,115 @@ - + True - vertical - 6 + 12 + 12 - + True - 12 + vertical - + True - vertical - 6 + 24 - + True - 0 - none - 0 - 0 + vertical + 6 - + + True + 0 + none + + + + + + 0 + + + + + True + 12 + + + True + 0 + Region: + + + False + 12 + 0 + + + + + True + region-liststore + + + + 0 + + + + + 1 + + + + + True + 0 + City: + + + False + 2 + + + + + True + city-modelfilter + + + + 0 + + + + + 3 + + + + + False + end + 1 + - False 0 - + True - 12 + vertical - - True - 0 - Region: + + Set time automatically + True + False + True False @@ -49,25 +120,154 @@ - + True - region-liststore + 0 - - - 0 - + + True + 3 + 3 + 12 + 6 + + + True + : + + + + + + + 1 + 2 + 1 + 2 + + + + + True + 16 + + + + + + + 1 + 2 + + + + + True + 45 + + + + + + + 2 + 3 + 1 + 2 + + + + + True + True + True + none + + + True + up + + + + + + + True + True + True + none + + + True + down + + + + + 2 + 3 + + + + + True + True + True + none + + + True + up + + + + + 2 + 3 + + + + + True + True + True + none + + + True + down + + + + + 2 + 3 + 2 + 3 + + + + + + + + + + False + 12 1 - - True - 0 - City: + + 12 hour format + True + False + True + True False @@ -75,18 +275,107 @@ - + + 24 hour format + True + False + True + 12_radiobutton + + + False + 3 + + + + True - city-modelsort + 3 + 2 + 6 + 6 - - - 0 - + + True + 0 + Month: + + + + + True + 0 + Day: + + + 1 + 2 + + + + + True + 1 + Year: + + + 2 + 3 + + + + + True + month-liststore + + + + 0 + + + + + 1 + 2 + + + + + True + True + + 5 + True + True + + + 1 + 2 + 2 + 3 + + + + + True + True + + 3 + True + True + + + 1 + 2 + 1 + 2 + - 3 + False + 12 + 4 @@ -101,123 +390,21 @@ - + True - vertical - 12 + end - - Keep date and time updated automatically - True - False - True - True - - - False - 0 - - - - + + gtk-apply True True - 2010 - 4 - 25 + True + True False False - 1 - - - - - True - 2 - 2 - 6 - 6 - - - True - 6 - - - True - True - - 2 - adjustment_hour - - - 0 - - - - - True - : - - - False - 1 - - - - - True - True - - 2 - adjustment_min - - - 2 - - - - - 1 - 2 - 1 - 2 - - - - - True - 0 - Current Time: - - - - - True - 0 - 12:00:00 - - - 1 - 2 - - - - - True - 0 - Time: - - - 1 - 2 - - - - - False - 2 + 0 @@ -227,45 +414,10 @@ - - 0 - - - - - True - end - - - gtk-apply - True - True - True - True - - - False - False - 0 - - - - - False - 1 - - - 23 - 1 - - - 60 - 1 - @@ -282,6 +434,72 @@ + + + + + + + + January + + + February + + + March + + + April + + + May + + + June + + + July + + + August + + + September + + + October + + + November + + + December + + + + + + + + + + + 22 + + + + + + + + + + + 2010 + + + city-liststore