summaryrefslogtreecommitdiff
path: root/tp-account-widgets
diff options
context:
space:
mode:
authorMarco Barisione <marco.barisione@collabora.co.uk>2013-07-29 14:20:00 +0100
committerMarco Barisione <marco.barisione@collabora.co.uk>2013-08-20 11:03:06 +0100
commit7f50fe46dc08956800ee9d63f5191b0d754ca106 (patch)
tree5af2de7a233d0a573940adddb4eb4177c35faeaa /tp-account-widgets
parent45e5ffdb0c84f0026cf552fe885f06498eaddb39 (diff)
downloadtelepathy-account-widgets-7f50fe46dc08956800ee9d63f5191b0d754ca106.tar.gz
calendar-button: move from Empathy to tp-accounts-widgets
https://bugzilla.gnome.org/show_bug.cgi?id=699492
Diffstat (limited to 'tp-account-widgets')
-rw-r--r--tp-account-widgets/Makefile.am2
-rw-r--r--tp-account-widgets/tpaw-calendar-button.c273
-rw-r--r--tp-account-widgets/tpaw-calendar-button.h67
3 files changed, 342 insertions, 0 deletions
diff --git a/tp-account-widgets/Makefile.am b/tp-account-widgets/Makefile.am
index 5397854c..3aafe3df 100644
--- a/tp-account-widgets/Makefile.am
+++ b/tp-account-widgets/Makefile.am
@@ -22,6 +22,7 @@ libtp_account_widgets_sources = \
tpaw-account-widget-private.h \
tpaw-account-widget-sip.c \
tpaw-builder.c \
+ tpaw-calendar-button.c \
tpaw-connection-managers.c \
tpaw-contactinfo-utils.c \
tpaw-keyring.c \
@@ -44,6 +45,7 @@ libtp_account_widgets_headers = \
tpaw-account-widget-irc.h \
tpaw-account-widget-sip.h \
tpaw-builder.h \
+ tpaw-calendar-button.h \
tpaw-connection-managers.h \
tpaw-contactinfo-utils.h \
tpaw-keyring.h \
diff --git a/tp-account-widgets/tpaw-calendar-button.c b/tp-account-widgets/tpaw-calendar-button.c
new file mode 100644
index 00000000..5d525785
--- /dev/null
+++ b/tp-account-widgets/tpaw-calendar-button.c
@@ -0,0 +1,273 @@
+/*
+ * tpaw-calendar-button.c - Source for TpawCalendarButton
+ * Copyright (C) 2012 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "tpaw-calendar-button.h"
+
+#include <glib/gi18n-lib.h>
+
+#define DEBUG_FLAG EMPATHY_DEBUG_OTHER_THING
+#include "empathy-debug.h"
+
+G_DEFINE_TYPE (TpawCalendarButton, tpaw_calendar_button, GTK_TYPE_BOX)
+
+/* signal enum */
+enum {
+ DATE_CHANGED,
+ LAST_SIGNAL,
+};
+
+static guint signals[LAST_SIGNAL] = {0};
+
+struct _TpawCalendarButtonPriv {
+ GDate *date;
+
+ GtkWidget *button_date;
+ GtkWidget *button_clear;
+ GtkWidget *dialog;
+ GtkWidget *calendar;
+};
+
+static void
+tpaw_calendar_button_finalize (GObject *object)
+{
+ TpawCalendarButton *self = (TpawCalendarButton *) object;
+
+ tp_clear_pointer (&self->priv->date, g_date_free);
+
+ G_OBJECT_CLASS (tpaw_calendar_button_parent_class)->finalize (object);
+}
+
+static void
+update_label (TpawCalendarButton *self)
+{
+ if (self->priv->date == NULL)
+ {
+ gtk_button_set_label (GTK_BUTTON (self->priv->button_date),
+ _("Select..."));
+ }
+ else
+ {
+ gchar buffer[128];
+
+ g_date_strftime (buffer, 128, "%e %b %Y", self->priv->date);
+ gtk_button_set_label (GTK_BUTTON (self->priv->button_date), buffer);
+ }
+}
+
+static void
+tpaw_calendar_button_constructed (GObject *object)
+{
+ TpawCalendarButton *self = (TpawCalendarButton *) object;
+
+ G_OBJECT_CLASS (tpaw_calendar_button_parent_class)->constructed (
+ object);
+
+ update_label (self);
+}
+
+static void
+dialog_response (GtkDialog *dialog,
+ gint response,
+ TpawCalendarButton *self)
+{
+ GDate *date;
+ guint year, month, day;
+
+ if (response != GTK_RESPONSE_OK)
+ goto out;
+
+ gtk_calendar_get_date (GTK_CALENDAR (self->priv->calendar),
+ &year, &month, &day);
+ date = g_date_new_dmy (day, month + 1, year);
+
+ tpaw_calendar_button_set_date (self, date);
+
+ g_date_free (date);
+
+out:
+ gtk_widget_hide (GTK_WIDGET (dialog));
+}
+
+static gboolean
+dialog_destroy (GtkWidget *widget,
+ TpawCalendarButton *self)
+{
+ self->priv->dialog = NULL;
+ self->priv->calendar = NULL;
+
+ return FALSE;
+}
+
+static void
+update_calendar (TpawCalendarButton *self)
+{
+ if (self->priv->calendar == NULL)
+ return;
+
+ gtk_calendar_clear_marks (GTK_CALENDAR (self->priv->calendar));
+
+ if (self->priv->date == NULL)
+ return;
+
+ gtk_calendar_select_day (GTK_CALENDAR (self->priv->calendar),
+ g_date_get_day (self->priv->date));
+ gtk_calendar_select_month (GTK_CALENDAR (self->priv->calendar),
+ g_date_get_month (self->priv->date) - 1,
+ g_date_get_year (self->priv->date));
+ gtk_calendar_mark_day (GTK_CALENDAR (self->priv->calendar),
+ g_date_get_day (self->priv->date));
+}
+
+static void
+tpaw_calendar_button_date_clicked (GtkButton *button,
+ TpawCalendarButton *self)
+{
+ if (self->priv->dialog == NULL)
+ {
+ GtkWidget *parent, *content;
+
+ parent = gtk_widget_get_toplevel (GTK_WIDGET (button));
+
+ self->priv->dialog = gtk_dialog_new_with_buttons (NULL,
+ GTK_WINDOW (parent), GTK_DIALOG_MODAL,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ _("_Select"), GTK_RESPONSE_OK,
+ NULL);
+
+ gtk_window_set_transient_for (GTK_WINDOW (self->priv->dialog),
+ GTK_WINDOW (parent));
+
+ self->priv->calendar = gtk_calendar_new ();
+
+ update_calendar (self);
+
+ content = gtk_dialog_get_content_area (GTK_DIALOG (self->priv->dialog));
+
+ gtk_box_pack_start (GTK_BOX (content), self->priv->calendar, TRUE, TRUE,
+ 6);
+ gtk_widget_show (self->priv->calendar);
+
+ g_signal_connect (self->priv->dialog, "response",
+ G_CALLBACK (dialog_response), self);
+ g_signal_connect (self->priv->dialog, "destroy",
+ G_CALLBACK (dialog_destroy), self);
+ }
+
+ gtk_window_present (GTK_WINDOW (self->priv->dialog));
+}
+
+static void
+tpaw_calendar_button_clear_clicked (GtkButton *button,
+ TpawCalendarButton *self)
+{
+ tpaw_calendar_button_set_date (self, NULL);
+}
+
+static void
+tpaw_calendar_button_init (TpawCalendarButton *self)
+{
+ GtkWidget *image;
+ GtkStyleContext *context;
+
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ TPAW_TYPE_CALENDAR_BUTTON, TpawCalendarButtonPriv);
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (self));
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_LINKED);
+
+ /* Date */
+ self->priv->button_date = gtk_button_new ();
+
+ g_signal_connect (self->priv->button_date, "clicked",
+ G_CALLBACK (tpaw_calendar_button_date_clicked), self);
+
+ gtk_button_set_alignment (GTK_BUTTON (self->priv->button_date), 0, 0.5);
+
+ gtk_box_pack_start (GTK_BOX (self), self->priv->button_date, TRUE, TRUE, 0);
+ gtk_widget_show (self->priv->button_date);
+
+ /* Clear */
+ self->priv->button_clear = gtk_button_new ();
+
+ image = gtk_image_new_from_stock (GTK_STOCK_CLEAR,
+ GTK_ICON_SIZE_MENU);
+ gtk_button_set_image (GTK_BUTTON (self->priv->button_clear), image);
+ gtk_widget_show (image);
+
+ g_signal_connect (self->priv->button_clear, "clicked",
+ G_CALLBACK (tpaw_calendar_button_clear_clicked), self);
+
+ gtk_box_pack_start (GTK_BOX (self), self->priv->button_clear,
+ FALSE, FALSE, 0);
+ gtk_widget_show (self->priv->button_clear);
+}
+
+static void
+tpaw_calendar_button_class_init (TpawCalendarButtonClass *klass)
+{
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (TpawCalendarButtonPriv));
+
+ oclass->finalize = tpaw_calendar_button_finalize;
+ oclass->constructed = tpaw_calendar_button_constructed;
+
+ signals[DATE_CHANGED] = g_signal_new ("date-changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST, 0,
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 1, G_TYPE_DATE);
+}
+
+GtkWidget *
+tpaw_calendar_button_new (void)
+{
+ return g_object_new (TPAW_TYPE_CALENDAR_BUTTON,
+ "orientation", GTK_ORIENTATION_HORIZONTAL,
+ NULL);
+}
+
+GDate *
+tpaw_calendar_button_get_date (TpawCalendarButton *self)
+{
+ return self->priv->date;
+}
+
+void
+tpaw_calendar_button_set_date (TpawCalendarButton *self,
+ GDate *date)
+{
+ if (date == self->priv->date)
+ return;
+
+ tp_clear_pointer (&self->priv->date, g_date_free);
+
+ if (date != NULL)
+ {
+ /* There is no g_date_copy()... */
+ self->priv->date = g_date_new_dmy (date->day, date->month, date->year);
+ }
+
+ update_label (self);
+ update_calendar (self);
+
+ g_signal_emit (self, signals[DATE_CHANGED], 0, self->priv->date);
+}
diff --git a/tp-account-widgets/tpaw-calendar-button.h b/tp-account-widgets/tpaw-calendar-button.h
new file mode 100644
index 00000000..38f23224
--- /dev/null
+++ b/tp-account-widgets/tpaw-calendar-button.h
@@ -0,0 +1,67 @@
+/*
+ * tpaw-calendar-button.h - Header for TpawCalendarButton
+ * Copyright (C) 2012 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __TPAW_CALENDAR_BUTTON_H__
+#define __TPAW_CALENDAR_BUTTON_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+typedef struct _TpawCalendarButton TpawCalendarButton;
+typedef struct _TpawCalendarButtonClass TpawCalendarButtonClass;
+typedef struct _TpawCalendarButtonPriv TpawCalendarButtonPriv;
+
+struct _TpawCalendarButtonClass {
+ GtkBoxClass parent_class;
+};
+
+struct _TpawCalendarButton {
+ GtkBox parent;
+ TpawCalendarButtonPriv *priv;
+};
+
+GType tpaw_calendar_button_get_type (void);
+
+#define TPAW_TYPE_CALENDAR_BUTTON \
+ (tpaw_calendar_button_get_type ())
+#define TPAW_CALENDAR_BUTTON(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), TPAW_TYPE_CALENDAR_BUTTON, \
+ TpawCalendarButton))
+#define TPAW_CALENDAR_BUTTON_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), TPAW_TYPE_CALENDAR_BUTTON, \
+ TpawCalendarButtonClass))
+#define TPAW_IS_CALENDAR_BUTTON(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), TPAW_TYPE_CALENDAR_BUTTON))
+#define TPAW_IS_CALENDAR_BUTTON_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), TPAW_TYPE_CALENDAR_BUTTON))
+#define TPAW_CALENDAR_BUTTON_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), TPAW_TYPE_CALENDAR_BUTTON, \
+ TpawCalendarButtonClass))
+
+GtkWidget * tpaw_calendar_button_new (void);
+
+GDate * tpaw_calendar_button_get_date (TpawCalendarButton *self);
+
+void tpaw_calendar_button_set_date (TpawCalendarButton *self,
+ GDate *date);
+
+G_END_DECLS
+
+#endif /* #ifndef __TPAW_CALENDAR_BUTTON_H__*/