[gnome-calendar] gcal-new-event-widget: finished API
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] gcal-new-event-widget: finished API
- Date: Thu, 4 Dec 2014 22:27:28 +0000 (UTC)
commit a98d90591c6bbc8db51b66232dbfd9dac4fc78f6
Author: Erick Pérez Castellanos <erick red gmail com>
Date: Wed Jul 3 20:20:58 2013 -0400
gcal-new-event-widget: finished API
Added method to set calendars
Added method to set default calendar
Added method to get selected calendar
Added method to get entered smmary string
Fixed formatting issues
src/gcal-new-event-widget.c | 190 +++++++++++++++++++++++++++++++++++++++++++
src/gcal-new-event-widget.h | 24 ++++--
2 files changed, 207 insertions(+), 7 deletions(-)
---
diff --git a/src/gcal-new-event-widget.c b/src/gcal-new-event-widget.c
index 406e923..3f72363 100644
--- a/src/gcal-new-event-widget.c
+++ b/src/gcal-new-event-widget.c
@@ -19,6 +19,7 @@
#include "gcal-new-event-widget.h"
#include "gcal-arrow-bin.h"
+#include "gcal-utils.h"
typedef struct
{
@@ -32,9 +33,42 @@ typedef struct
GtkWidget *close_button;
} GcalNewEventWidgetPrivate;
+static void item_activated (GtkWidget *item,
+ gpointer user_data);
+
G_DEFINE_TYPE_WITH_PRIVATE (GcalNewEventWidget, gcal_new_event_widget, GTK_TYPE_OVERLAY)
static void
+item_activated (GtkWidget *item,
+ gpointer user_data)
+{
+ GcalNewEventWidgetPrivate *priv;
+
+ gchar *uid;
+ gchar *color_name;
+ GdkColor color;
+
+ GdkPixbuf *pix;
+ GtkWidget *image;
+
+ priv = gcal_new_event_widget_get_instance_private (
+ GCAL_NEW_EVENT_WIDGET (user_data));
+
+ uid = g_object_get_data (G_OBJECT (item), "calendar-uid");
+ color_name = g_object_get_data (G_OBJECT (item), "color");
+ gdk_color_parse (color_name, &color);
+
+ pix = gcal_get_pixbuf_from_color (&color, 16);
+ image = gtk_image_new_from_pixbuf (pix);
+ gtk_button_set_image (GTK_BUTTON (priv->calendar_button), image);
+
+ /* saving the value */
+ g_object_set_data (G_OBJECT (priv->calendar_button),
+ "calendar-uid", uid);
+ g_object_unref (pix);
+}
+
+static void
gcal_new_event_widget_class_init (GcalNewEventWidgetClass *klass)
{
GtkWidgetClass *widget_class;
@@ -76,6 +110,125 @@ gcal_new_event_widget_set_title (GcalNewEventWidget *widget,
gtk_label_set_text (GTK_LABEL (priv->title_label), title);
}
+void
+gcal_new_event_widget_set_calendars (GcalNewEventWidget *widget,
+ GtkTreeModel *sources_model)
+{
+ GcalNewEventWidgetPrivate *priv;
+ GtkWidget *menu;
+ GtkWidget *item;
+
+ gboolean valid;
+ GtkTreeIter iter;
+
+ priv = gcal_new_event_widget_get_instance_private (widget);
+
+ valid = gtk_tree_model_get_iter_first (sources_model, &iter);
+ if (! valid)
+ return;
+
+ menu = gtk_menu_new ();
+ gtk_menu_button_set_popup (GTK_MENU_BUTTON (priv->calendar_button), menu);
+
+ while (valid)
+ {
+ /* Walk through the list, reading each row */
+ gchar *uid;
+ gchar *name;
+ gboolean active;
+ GdkColor *color;
+
+ GtkWidget *box;
+ GtkWidget *name_label;
+ GtkWidget *cal_image;
+ GdkPixbuf *pix;
+
+ gtk_tree_model_get (sources_model, &iter,
+ 0, &uid,
+ 1, &name,
+ 2, &active,
+ 3, &color,
+ -1);
+
+ if (! active)
+ {
+ valid = gtk_tree_model_iter_next (sources_model, &iter);
+ continue;
+ }
+
+ item = gtk_menu_item_new ();
+ g_object_set_data_full (G_OBJECT (item),
+ "calendar-uid", uid, g_free);
+ g_object_set_data_full (G_OBJECT (item),
+ "color", gdk_color_to_string (color), g_free);
+ g_signal_connect (item,
+ "activate",
+ G_CALLBACK (item_activated),
+ widget);
+
+ pix = gcal_get_pixbuf_from_color (color, 16);
+ cal_image = gtk_image_new_from_pixbuf (pix);
+ name_label = gtk_label_new (name);
+ box = gtk_grid_new ();
+ gtk_grid_set_column_spacing (GTK_GRID (box), 6);
+ gtk_container_add (GTK_CONTAINER (box), cal_image);
+ gtk_container_add (GTK_CONTAINER (box), name_label);
+ gtk_container_add (GTK_CONTAINER (item), box);
+
+ gtk_container_add (GTK_CONTAINER (menu), item);
+
+ g_object_unref (pix);
+ g_free (name);
+ gdk_color_free (color);
+
+ valid = gtk_tree_model_iter_next (sources_model, &iter);
+ }
+
+ gtk_widget_show_all (GTK_WIDGET (menu));
+}
+
+void
+gcal_new_event_widget_set_default_calendar (GcalNewEventWidget *widget,
+ const gchar *source_uid)
+{
+ GcalNewEventWidgetPrivate *priv;
+
+ GList *l;
+ GtkMenu *menu;
+
+ gchar *uid;
+ gchar *color_name;
+ GdkColor color;
+ GdkPixbuf *pix;
+ GtkWidget *image;
+
+ priv = gcal_new_event_widget_get_instance_private (widget);
+
+ menu = gtk_menu_button_get_popup (GTK_MENU_BUTTON (priv->calendar_button));
+ for (l = gtk_container_get_children (GTK_CONTAINER (menu));
+ l != NULL;
+ l = l->next)
+ {
+ GObject *item = l->data;
+ uid = g_object_get_data (item, "calendar-uid");
+ if (g_strcmp0 (source_uid, uid) == 0)
+ {
+ color_name = g_object_get_data (item, "color");
+ break;
+ }
+ }
+
+ gdk_color_parse (color_name, &color);
+ pix = gcal_get_pixbuf_from_color (&color, 16);
+ image = gtk_image_new_from_pixbuf (pix);
+ gtk_button_set_image (GTK_BUTTON (priv->calendar_button), image);
+
+ /* saving the value */
+ g_object_set_data (G_OBJECT (priv->calendar_button),
+ "calendar-uid", uid);
+ g_object_unref (pix);
+}
+
/**
* gcal_new_event_widget_get_entry:
* @widget:
@@ -127,3 +280,40 @@ gcal_new_event_widget_get_close_button (GcalNewEventWidget *widget)
priv = gcal_new_event_widget_get_instance_private (widget);
return priv->close_button;
}
+
+/**
+ * gcal_new_event_widget_get_calendar_uid:
+ * @widget: a #GcalNewEventWidget
+ *
+ * Returns the selected calendar uid.
+ *
+ * Returns: (transfer full) a c-string
+ **/
+gchar*
+gcal_new_event_widget_get_calendar_uid (GcalNewEventWidget *widget)
+{
+ GcalNewEventWidgetPrivate *priv;
+
+ priv = gcal_new_event_widget_get_instance_private (widget);
+
+ return g_strdup (g_object_get_data (G_OBJECT (priv->calendar_button),
+ "calendar-uid"));
+}
+
+/**
+ * gcal_new_event_widget_get_summary:
+ * @widget: a #GcalNewEventWidget
+ *
+ * Return the summary written down in the entry
+ *
+ * Returns: (transfer full) a c-string
+ **/
+gchar*
+gcal_new_event_widget_get_summary (GcalNewEventWidget *widget)
+{
+ GcalNewEventWidgetPrivate *priv;
+
+ priv = gcal_new_event_widget_get_instance_private (widget);
+
+ return g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->what_entry)));
+}
diff --git a/src/gcal-new-event-widget.h b/src/gcal-new-event-widget.h
index 02ec6bd..3efeeb3 100644
--- a/src/gcal-new-event-widget.h
+++ b/src/gcal-new-event-widget.h
@@ -58,18 +58,28 @@ struct _GcalNewEventWidgetClass
GType gcal_new_event_widget_get_type (void);
-GtkWidget* gcal_new_event_widget_new (void);
+GtkWidget* gcal_new_event_widget_new (void);
-void gcal_new_event_widget_set_title (GcalNewEventWidget *widget,
- const gchar *title);
+void gcal_new_event_widget_set_title (GcalNewEventWidget *widget,
+ const gchar *title);
-GtkWidget* gcal_new_event_widget_get_entry (GcalNewEventWidget *widget);
+void gcal_new_event_widget_set_calendars (GcalNewEventWidget *widget,
+ GtkTreeModel *sources_model);
-GtkWidget* gcal_new_event_widget_get_create_button (GcalNewEventWidget *widget);
+void gcal_new_event_widget_set_default_calendar (GcalNewEventWidget *widget,
+ const gchar *source_uid);
-GtkWidget* gcal_new_event_widget_get_details_button (GcalNewEventWidget *widget);
+GtkWidget* gcal_new_event_widget_get_entry (GcalNewEventWidget *widget);
-GtkWidget* gcal_new_event_widget_get_close_button (GcalNewEventWidget *widget);
+GtkWidget* gcal_new_event_widget_get_create_button (GcalNewEventWidget *widget);
+
+GtkWidget* gcal_new_event_widget_get_details_button (GcalNewEventWidget *widget);
+
+GtkWidget* gcal_new_event_widget_get_close_button (GcalNewEventWidget *widget);
+
+gchar* gcal_new_event_widget_get_calendar_uid (GcalNewEventWidget *widget);
+
+gchar* gcal_new_event_widget_get_summary (GcalNewEventWidget *widget);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]