[gnome-calendar/calendar-management] source-manager: show row headers according to the type
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/calendar-management] source-manager: show row headers according to the type
- Date: Tue, 3 Feb 2015 17:30:13 +0000 (UTC)
commit 85f111fb1a076ac81b8cdb8b93870968d6da7844
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Tue Feb 3 14:53:41 2015 -0200
source-manager: show row headers according to the type
data/theme/gtk-styles.css | 4 ++
src/gcal-source-manager-dialog.c | 76 +++++++++++++++++++++++++++++++++++---
2 files changed, 74 insertions(+), 6 deletions(-)
---
diff --git a/data/theme/gtk-styles.css b/data/theme/gtk-styles.css
index 2a66f0c..170fbfa 100644
--- a/data/theme/gtk-styles.css
+++ b/data/theme/gtk-styles.css
@@ -222,3 +222,7 @@ GcalEventWidget.color-light:backdrop {
border-right: 0px;
border-top: 0px;
}
+
+GtkFrame.header-frame {
+ background-color: @theme_bg_color;
+}
diff --git a/src/gcal-source-manager-dialog.c b/src/gcal-source-manager-dialog.c
index 6979529..9f25536 100644
--- a/src/gcal-source-manager-dialog.c
+++ b/src/gcal-source-manager-dialog.c
@@ -35,6 +35,8 @@ struct _GcalSourceManagerDialogPrivate
GHashTable *row_to_source;
GHashTable *source_to_row;
+ GHashTable *source_origin;
+
/* actions */
GSimpleActionGroup *action_group;
@@ -86,6 +88,8 @@ static void url_action_activated (GSimpleAction
/* private */
static void fill_sources_list (GcalSourceManagerDialog *dialog);
+static GtkWidget* make_header_for_data (GcalSourceOrigin *origin);
+
static GtkWidget* make_row_for_source (GcalSourceManagerDialog *dialog,
ESource *source);
@@ -178,15 +182,41 @@ display_header_func (GtkListBoxRow *row,
GtkListBoxRow *before,
gpointer user_data)
{
+ GcalSourceManagerDialogPrivate *priv;
+ GcalSourceOrigin *row_origin;
+ ESource *row_source;
+ GtkWidget *header;
+
+ priv = gcal_source_manager_dialog_get_instance_private (GCAL_SOURCE_MANAGER_DIALOG (user_data));
+ row_source = g_hash_table_lookup (priv->row_to_source, row);
+ row_origin = g_hash_table_lookup (priv->source_origin, row_source);
+
if (before != NULL)
{
- GtkWidget *header;
+ GcalSourceOrigin *prev_origin;
+ ESource *prev_source;
+
+ prev_source = g_hash_table_lookup (priv->row_to_source, before);
+ prev_origin = g_hash_table_lookup (priv->source_origin, prev_source);
+
+ if (g_strcmp0 (prev_origin->name, row_origin->name) == 0 &&
+ g_strcmp0 (prev_origin->account, row_origin->account) == 0)
+ {
+ header = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+ }
+ else
+ {
+ header = make_header_for_data (row_origin);
+ }
+ }
+ else
+ {
+ header = make_header_for_data (row_origin);
+ }
- header = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
- gtk_widget_show (header);
+ gtk_widget_show (header);
- gtk_list_box_row_set_header (row, header);
- }
+ gtk_list_box_row_set_header (row, header);
}
/**
@@ -235,13 +265,16 @@ source_added_cb (GcalManager *manager,
gpointer user_data)
{
GcalSourceManagerDialogPrivate *priv;
+ GcalSourceOrigin *origin;
GtkWidget *row;
priv = gcal_source_manager_dialog_get_instance_private (GCAL_SOURCE_MANAGER_DIALOG (user_data));
row = make_row_for_source (GCAL_SOURCE_MANAGER_DIALOG (user_data), source);
+ origin = gcal_manager_get_origin (priv->manager, source);
g_hash_table_insert (priv->row_to_source, row, source);
g_hash_table_insert (priv->source_to_row, source, row);
+ g_hash_table_insert (priv->source_origin, source, origin);
gtk_container_add (GTK_CONTAINER (priv->sources_listbox), row);
}
@@ -330,6 +363,36 @@ source_removed_cb (GcalManager *manager,
g_hash_table_remove (priv->row_to_source, row);
g_hash_table_remove (priv->source_to_row, source);
+ g_hash_table_remove (priv->source_origin, source);
+}
+
+static GtkWidget*
+make_header_for_data (GcalSourceOrigin *origin)
+{
+ GtkWidget *frame, *box, *label1, *label2;
+
+ frame = gtk_frame_new (NULL);
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+ label1 = gtk_label_new (origin->name);
+ label2 = gtk_label_new (origin->account);
+
+ gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
+
+ g_object_set (box, "margin-start", 16, "margin-end", 16, "margin-top", 4, "margin-bottom", 4, NULL);
+
+ gtk_widget_set_hexpand (label1, TRUE);
+ gtk_label_set_xalign (GTK_LABEL (label1), 0.0);
+
+ gtk_style_context_add_class (gtk_widget_get_style_context (frame), "header-frame");
+ gtk_style_context_add_class (gtk_widget_get_style_context (label2), "dim-label");
+
+ gtk_container_add (GTK_CONTAINER (box), label1);
+ gtk_container_add (GTK_CONTAINER (box), label2);
+ gtk_container_add (GTK_CONTAINER (frame), box);
+
+ gtk_widget_show_all (frame);
+
+ return frame;
}
static void
@@ -538,7 +601,7 @@ gcal_source_manager_dialog_constructed (GObject *object)
g_action_map_add_action (G_ACTION_MAP (priv->action_group), G_ACTION (url_action));
/* add separators to the listbox */
- gtk_list_box_set_header_func (GTK_LIST_BOX (priv->sources_listbox), display_header_func, NULL, NULL);
+ gtk_list_box_set_header_func (GTK_LIST_BOX (priv->sources_listbox), display_header_func, object, NULL);
gtk_list_box_set_sort_func (GTK_LIST_BOX (priv->sources_listbox), sort_func_cb, object, NULL);
}
@@ -552,6 +615,7 @@ gcal_source_manager_dialog_init (GcalSourceManagerDialog *self)
priv->row_to_source = g_hash_table_new_full (g_direct_hash, g_direct_equal, (GDestroyNotify)
gtk_widget_destroy,
NULL);
priv->source_to_row = g_hash_table_new (g_direct_hash, g_direct_equal);
+ priv->source_origin = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) g_free);
gtk_widget_init_template (GTK_WIDGET (self));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]