From 40683e5e104b63f0d7fde062b76ea7dbc17169c6 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Thu, 18 Dec 2014 14:20:20 -0200 Subject: [PATCH] date-selector: initial implementetation No functionality is ready, only project settings and class type. --- data/Makefile.am | 1 + data/calendar.gresource.xml | 1 + data/theme/gtk-styles.css | 8 + data/ui/date-selector.ui | 74 ++++++ data/ui/edit-dialog.ui | 4 +- src/Makefile.am | 4 +- src/gcal-date-entry.c | 439 ------------------------------------ src/gcal-date-entry.h | 72 ------ src/gcal-date-selector.c | 156 +++++++++++++ src/gcal-date-selector.h | 69 ++++++ src/gcal-edit-dialog.c | 52 +++-- 11 files changed, 340 insertions(+), 540 deletions(-) create mode 100644 data/ui/date-selector.ui delete mode 100644 src/gcal-date-entry.c delete mode 100644 src/gcal-date-entry.h create mode 100644 src/gcal-date-selector.c create mode 100644 src/gcal-date-selector.h diff --git a/data/Makefile.am b/data/Makefile.am index 6e4adb8d..a33de3e5 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -33,6 +33,7 @@ gsettings_SCHEMAS = $(gsettingsschema_in_files:.xml.in=.xml) EXTRA_DIST= \ org.gnome.Calendar.desktop \ calendar.gresource.xml \ + ui/date-selector.ui \ ui/edit-dialog.ui \ ui/menus.ui \ ui/nav_bar.ui \ diff --git a/data/calendar.gresource.xml b/data/calendar.gresource.xml index 0ce5b824..f5749338 100644 --- a/data/calendar.gresource.xml +++ b/data/calendar.gresource.xml @@ -1,6 +1,7 @@ + ui/date-selector.ui ui/edit-dialog.ui ui/menus.ui ui/nav_bar.ui diff --git a/data/theme/gtk-styles.css b/data/theme/gtk-styles.css index 9a4a498e..8f87a2dc 100644 --- a/data/theme/gtk-styles.css +++ b/data/theme/gtk-styles.css @@ -83,3 +83,11 @@ GcalEventWidget.color-light { GcalEventWidget.color-light:backdrop { color: rgba(0, 0, 0, 0.3); } + +.middle-entry { + border-left: 0px; + border-bottom-left-radius: 0px; + border-top-left-radius: 0px; + border-bottom-right-radius: 0px; + border-top-right-radius: 0px; +} diff --git a/data/ui/date-selector.ui b/data/ui/date-selector.ui new file mode 100644 index 00000000..997de6e5 --- /dev/null +++ b/data/ui/date-selector.ui @@ -0,0 +1,74 @@ + + + + + + True + False + 12 + 6 + + + True + False + + + True + True + + + False + True + 0 + + + + + True + True + + + + False + True + 1 + + + + + True + True + + + False + True + 2 + + + + + + 0 + 0 + + + + + True + True + 2014 + 11 + 18 + True + + + 0 + 1 + + + + diff --git a/data/ui/edit-dialog.ui b/data/ui/edit-dialog.ui index 9544ec75..9206f563 100644 --- a/data/ui/edit-dialog.ui +++ b/data/ui/edit-dialog.ui @@ -247,7 +247,7 @@ - + True True @@ -267,7 +267,7 @@ - + True True diff --git a/src/Makefile.am b/src/Makefile.am index aa64ec23..c0919ad7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -45,8 +45,8 @@ gnome_calendar_SOURCES = \ gcal-edit-dialog.h \ gcal-time-selector.c \ gcal-time-selector.h \ - gcal-date-entry.c \ - gcal-date-entry.h \ + gcal-date-selector.c \ + gcal-date-selector.h \ gcal-manager.c \ gcal-manager.h \ gcal-nav-bar.h \ diff --git a/src/gcal-date-entry.c b/src/gcal-date-entry.c deleted file mode 100644 index 3c0e822a..00000000 --- a/src/gcal-date-entry.c +++ /dev/null @@ -1,439 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * gcal-date-entry.c - * Copyright (C) 2012 Erick Pérez Castellanos - * - * gnome-calendar is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * gnome-calendar 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#include "gcal-date-entry.h" - -#include -#include -#include - -struct _GcalDateEntryPrivate -{ - gboolean internal_skip; - - gint day; /* 1 - 28 || 29 || 30 || 31 */ - gint month; /* 1 - 12 */ - gint year; - - gchar *mask; - guint day_pos; - guint month_pos; - guint year_pos; - gboolean have_long_year; -}; - -enum -{ - MODIFIED, - NUM_SIGNALS -}; - -static guint signals[NUM_SIGNALS] = { 0, }; - -static void gtk_editable_iface_init (GtkEditableInterface *iface); - -static void gcal_date_entry_constructed (GObject *object); - -static void gcal_date_entry_icon_press (GtkEntry *entry, - GtkEntryIconPosition icon_pos, - GdkEvent *event, - gpointer user_data); - -static void gcal_date_entry_insert_text (GtkEditable *editable, - const gchar *new_text, - gint new_text_length, - gint *position); - -static void gcal_date_entry_delete_text (GtkEditable *editable, - gint start_pos, - gint end_pos); - -static void gcal_date_entry_validate_and_insert (GcalDateEntry *entry); - -G_DEFINE_TYPE_WITH_CODE (GcalDateEntry, - gcal_date_entry, - GTK_TYPE_ENTRY, - G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, - gtk_editable_iface_init)); - -static void -gcal_date_entry_class_init (GcalDateEntryClass *klass) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (klass); - object_class->constructed = gcal_date_entry_constructed; - - signals[MODIFIED] = g_signal_new ("modified", - GCAL_TYPE_DATE_ENTRY, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GcalDateEntryClass, - modified), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - g_type_class_add_private ((gpointer)klass, sizeof(GcalDateEntryPrivate)); -} - -static void -gcal_date_entry_init (GcalDateEntry *self) -{ - GcalDateEntryPrivate *priv; - gchar *have_y; - - gtk_widget_set_has_window (GTK_WIDGET (self), FALSE); - - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - GCAL_TYPE_DATE_ENTRY, - GcalDateEntryPrivate); - priv = self->priv; - - priv->internal_skip = FALSE; - priv->day = 1; - priv->month = 1; - priv->year = 1970; - - setlocale (LC_ALL,""); - priv->mask = nl_langinfo (D_FMT); - - priv->day_pos = - (priv->mask - g_strstr_len (priv->mask, -1, "%d")); - priv->month_pos = - (priv->mask - g_strstr_len (priv->mask, -1, "%m")); - if ((have_y = g_strstr_len (priv->mask, - 1, "%y")) != NULL) - { - priv->have_long_year = FALSE; - priv->year_pos = - (priv->mask - have_y); - } - else - { - priv->have_long_year = TRUE; - priv->year_pos = - (priv->mask - g_strstr_len (priv->mask, -1, "%Y")); - if (priv->year_pos < priv->day_pos) - priv->day_pos += 2; - if (priv->year_pos < priv->month_pos) - priv->month_pos += 2; - } -} - -static void -gtk_editable_iface_init (GtkEditableInterface *iface) -{ - iface->insert_text = gcal_date_entry_insert_text; - iface->delete_text = gcal_date_entry_delete_text; -} - -static void -gcal_date_entry_constructed (GObject *object) -{ - GcalDateEntryPrivate *priv; - - priv = GCAL_DATE_ENTRY (object)->priv; - - /* chaining up */ - G_OBJECT_CLASS (gcal_date_entry_parent_class)->constructed (object); - - gtk_entry_set_width_chars ( - GTK_ENTRY (object), - strlen (priv->mask) + (priv->have_long_year ? 4 : 2)); - gtk_entry_set_alignment (GTK_ENTRY (object), 0.5); - - gtk_entry_set_icon_from_icon_name (GTK_ENTRY (object), - GTK_ENTRY_ICON_SECONDARY, - "x-office-calendar-symbolic"); - gtk_entry_set_icon_tooltip_text (GTK_ENTRY (object), - GTK_ENTRY_ICON_SECONDARY, - _("Change the date")); - - /* default text */ - gcal_date_entry_validate_and_insert (GCAL_DATE_ENTRY (object)); - - /* setting signals */ - g_signal_connect (object, - "icon-press", - G_CALLBACK (gcal_date_entry_icon_press), - object); -} - -static void -gcal_date_entry_icon_press (GtkEntry *entry, - GtkEntryIconPosition icon_pos, - GdkEvent *event, - gpointer user_data) -{ - g_debug ("Icon pressed"); -} - -static void -gcal_date_entry_insert_text (GtkEditable *editable, - const gchar *new_text, - gint new_text_length, - gint *position) -{ - GcalDateEntryPrivate *priv; - GtkEditableInterface *parent_editable_iface; - gboolean new_string_set; - gchar new_string [16]; - gint i; - - priv = GCAL_DATE_ENTRY (editable)->priv; - parent_editable_iface = g_type_interface_peek (gcal_date_entry_parent_class, - GTK_TYPE_EDITABLE); - - if (priv->internal_skip) - { - parent_editable_iface->insert_text (editable, - new_text, - new_text_length, - position); - *position = 0; - return; - } - - new_string_set = FALSE; - memset (new_string, 0, 16); - /* Is it day */ - if (*position >= priv->day_pos && - *position < priv->day_pos + 2) - { - //trim string, decide what to remove - for (i = 0; i < priv->day_pos + 2 - *position; i++) - { - if (g_ascii_isdigit (new_text[i])) - { - new_string_set = TRUE; - new_string[i] = new_text[i]; - } - else - { - break; - } - } - } - - /* Is it month */ - if (*position >= priv->month_pos && - *position < priv->month_pos + 2) - { - //trim string, decide what to remove - for (i = 0; i < priv->month_pos + 2 - *position; i++) - { - if (g_ascii_isdigit (new_text[i])) - { - new_string_set = TRUE; - new_string[i] = new_text[i]; - } - else - { - break; - } - } - } - - /* Is it year */ - if (*position >= priv->year_pos && - *position < priv->year_pos + (priv->have_long_year ? 4 : 2)) - { - //trim string, decide what to remove - for (i = 0; - i < priv->year_pos + (priv->have_long_year ? 4 : 2) - *position; - i++) - { - if (g_ascii_isdigit (new_text[i])) - { - new_string_set = TRUE; - new_string[i] = new_text[i]; - } - else - { - break; - } - } - } - - if (new_string_set) - { - gchar* unit_string; - const gchar* text; - - gint new_day; - gint new_month; - gint new_year; - - /* making space for new_string */ - priv->internal_skip = TRUE; - gtk_editable_delete_text (editable, - *position, - *position + strlen (new_string)); - priv->internal_skip = FALSE; - - parent_editable_iface->insert_text (editable, - new_string, - strlen (new_string), - position); - - /* Updating internal data and validating */ - text = gtk_entry_get_text (GTK_ENTRY (editable)); - unit_string = g_strndup (text + priv->day_pos, 2); - new_day = (gint) g_ascii_strtoull (unit_string, NULL, 10); - g_free (unit_string); - - unit_string = g_strndup (text + priv->month_pos, 2); - new_month = (gint) g_ascii_strtoull (unit_string, NULL, 10); - g_free (unit_string); - - unit_string = g_strndup (text + priv->year_pos, (priv->have_long_year ? 4 : 2)); - new_year = (gint) g_ascii_strtoull (unit_string, NULL, 10); - g_free (unit_string); - - if (priv->day != new_day || - priv->month != new_month || - priv->year != new_year) - { - priv->day = new_day; - priv->month = new_month; - priv->year = new_year; - - gcal_date_entry_validate_and_insert (GCAL_DATE_ENTRY (editable)); - } - } -} - -static void -gcal_date_entry_delete_text (GtkEditable *editable, - gint start_pos, - gint end_pos) -{ - /* do nothing, unless we mark it */ - GcalDateEntryPrivate *priv; - GtkEditableInterface *parent_editable_iface; - - priv = GCAL_DATE_ENTRY (editable)->priv; - parent_editable_iface = g_type_interface_peek (gcal_date_entry_parent_class, - GTK_TYPE_EDITABLE); - - if (priv->internal_skip) - { - /* FIXME: Handle delete_text */ - /* handle delete */ - } - - parent_editable_iface->delete_text (editable, - start_pos, - end_pos); -} - -static void -gcal_date_entry_validate_and_insert (GcalDateEntry *entry) -{ - GcalDateEntryPrivate *priv; - gchar *tmp; - gchar *tmp1; - gchar **tokens; - gchar *unit; - - priv = entry->priv; - - if (priv->month > 12) - priv->month = 12; - if (priv->day > g_date_days_in_month (priv->month, priv->year)) - priv->day = g_date_days_in_month (priv->month, priv->year); - - tokens = g_strsplit (priv->mask, "%d", -1); - unit = g_strdup_printf ("%.2d", priv->day); - tmp = g_strjoinv (unit, tokens); - g_free (unit); - g_strfreev (tokens); - - tokens = g_strsplit (tmp, "%m", -1); - unit = g_strdup_printf ("%.2d", priv->month); - tmp1 = g_strjoinv (unit, tokens); - g_free (unit); - g_strfreev (tokens); - - g_free (tmp); - if (priv->have_long_year) - { - tokens = g_strsplit (tmp1, "%Y", -1); - unit = g_strdup_printf ("%.4d", priv->year); - tmp = g_strjoinv (unit, tokens); - } - else - { - tokens = g_strsplit (tmp1, "%y", -1); - unit = g_strdup_printf ("%.2d", priv->year); - tmp = g_strjoinv (unit, tokens); - } - - g_free (unit); - g_strfreev (tokens); - - priv->internal_skip = TRUE; - gtk_entry_set_text (GTK_ENTRY (entry), tmp); - priv->internal_skip = FALSE; - - g_signal_emit (entry, signals[MODIFIED], 0); - - g_free (tmp); - g_free (tmp1); -} - -/* Public API */ -GtkWidget* -gcal_date_entry_new (void) -{ - return g_object_new (GCAL_TYPE_DATE_ENTRY, NULL); -} - -void -gcal_date_entry_set_date (GcalDateEntry *entry, - gint day, - gint month, - gint year) -{ - GcalDateEntryPrivate *priv; - - g_return_if_fail (GCAL_IS_DATE_ENTRY (entry)); - priv = entry->priv; - - priv->day = day; - priv->month = month; - priv->year = year; - - gcal_date_entry_validate_and_insert (entry); -} - -void -gcal_date_entry_get_date (GcalDateEntry *entry, - gint *day, - gint *month, - gint *year) -{ - GcalDateEntryPrivate *priv; - - g_return_if_fail (GCAL_IS_DATE_ENTRY (entry)); - priv = entry->priv; - - if (day != NULL) - *day = priv->day; - if (month != NULL) - *month = priv->month; - if (year != NULL) - *year = priv->year; -} diff --git a/src/gcal-date-entry.h b/src/gcal-date-entry.h deleted file mode 100644 index 80137783..00000000 --- a/src/gcal-date-entry.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * gcal-date-entry.h - * Copyright (C) 2012 Erick Pérez Castellanos - * - * gnome-calendar is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * gnome-calendar 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef __GCAL_DATE_ENTRY_H__ -#define __GCAL_DATE_ENTRY_H__ - -#include - -G_BEGIN_DECLS - -#define GCAL_TYPE_DATE_ENTRY (gcal_date_entry_get_type ()) -#define GCAL_DATE_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCAL_TYPE_DATE_ENTRY, GcalDateEntry)) -#define GCAL_DATE_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GCAL_TYPE_DATE_ENTRY, GcalDateEntryClass)) -#define GCAL_IS_DATE_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCAL_TYPE_DATE_ENTRY)) -#define GCAL_IS_DATE_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GCAL_TYPE_DATE_ENTRY)) -#define GCAL_DATE_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GCAL_TYPE_DATE_ENTRY, GcalDateEntryClass)) - -typedef struct _GcalTime GcalTime; - -typedef struct _GcalDateEntry GcalDateEntry; -typedef struct _GcalDateEntryClass GcalDateEntryClass; -typedef struct _GcalDateEntryPrivate GcalDateEntryPrivate; - -struct _GcalDateEntry -{ - GtkEntry parent; - /* add your public declarations here */ - - GcalDateEntryPrivate *priv; -}; - -struct _GcalDateEntryClass -{ - GtkEntryClass parent_class; - - /* signals */ - void (*modified) (GcalDateEntry *entry); -}; - -GType gcal_date_entry_get_type (void); - -GtkWidget* gcal_date_entry_new (void); - -void gcal_date_entry_set_date (GcalDateEntry *entry, - gint day, - gint month, - gint year); - -void gcal_date_entry_get_date (GcalDateEntry *entry, - gint *day, - gint *month, - gint *year); - -G_END_DECLS - -#endif /* __GCAL_DATE_ENTRY_H__ */ diff --git a/src/gcal-date-selector.c b/src/gcal-date-selector.c new file mode 100644 index 00000000..1fdd459c --- /dev/null +++ b/src/gcal-date-selector.c @@ -0,0 +1,156 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * gcal-date-selector.c + * Copyright (C) 2012 Erick Pérez Castellanos + * + * gnome-calendar is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gnome-calendar 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "gcal-date-selector.h" + +#include +#include +#include + +struct _GcalDateSelectorPrivate +{ + gboolean internal_skip; + + gint day; + gint month; + gint year; + + gchar *mask; + guint day_pos; + guint month_pos; + guint year_pos; + gboolean have_long_year; +}; + +enum +{ + MODIFIED, + NUM_SIGNALS +}; + +static guint signals[NUM_SIGNALS] = { 0, }; + +static void gcal_date_selector_constructed (GObject *object); + +G_DEFINE_TYPE_WITH_PRIVATE (GcalDateSelector, gcal_date_selector, GTK_TYPE_TOGGLE_BUTTON); + +static void +gcal_date_selector_class_init (GcalDateSelectorClass *klass) +{ + GObjectClass *object_class; + + object_class = G_OBJECT_CLASS (klass); + object_class->constructed = gcal_date_selector_constructed; + + signals[MODIFIED] = g_signal_new ("modified", + GCAL_TYPE_DATE_SELECTOR, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GcalDateSelectorClass, modified), + NULL, NULL, NULL, + G_TYPE_NONE, 0); +} + +static void +gcal_date_selector_init (GcalDateSelector *self) +{ + GcalDateSelectorPrivate *priv; + gchar *have_y; + + gtk_widget_set_has_window (GTK_WIDGET (self), FALSE); + + priv = gcal_date_selector_get_instance_private (GCAL_DATE_SELECTOR (self));; + + priv->internal_skip = FALSE; + priv->day = 1; + priv->month = 1; + priv->year = 1970; + + setlocale (LC_ALL,""); + priv->mask = nl_langinfo (D_FMT); + + priv->day_pos = - (priv->mask - g_strstr_len (priv->mask, -1, "%d")); + priv->month_pos = - (priv->mask - g_strstr_len (priv->mask, -1, "%m")); + if ((have_y = g_strstr_len (priv->mask, - 1, "%y")) != NULL) + { + priv->have_long_year = FALSE; + priv->year_pos = - (priv->mask - have_y); + } + else + { + priv->have_long_year = TRUE; + priv->year_pos = - (priv->mask - g_strstr_len (priv->mask, -1, "%Y")); + if (priv->year_pos < priv->day_pos) + priv->day_pos += 2; + if (priv->year_pos < priv->month_pos) + priv->month_pos += 2; + } +} + +static void +gcal_date_selector_constructed (GObject *object) +{ + GcalDateSelectorPrivate *priv; + + priv = gcal_date_selector_get_instance_private (GCAL_DATE_SELECTOR (object)); + + /* chaining up */ + G_OBJECT_CLASS (gcal_date_selector_parent_class)->constructed (object); +} + +/* Public API */ +GtkWidget* +gcal_date_selector_new (void) +{ + return g_object_new (GCAL_TYPE_DATE_SELECTOR, NULL); +} + +void +gcal_date_selector_set_date (GcalDateSelector *selector, + gint day, + gint month, + gint year) +{ + GcalDateSelectorPrivate *priv; + + g_return_if_fail (GCAL_IS_DATE_SELECTOR (selector)); + priv = gcal_date_selector_get_instance_private (selector); + + priv->day = day; + priv->month = month; + priv->year = year; +} + +void +gcal_date_selector_get_date (GcalDateSelector *selector, + gint *day, + gint *month, + gint *year) +{ + GcalDateSelectorPrivate *priv; + + g_return_if_fail (GCAL_IS_DATE_SELECTOR (selector)); + priv = gcal_date_selector_get_instance_private (selector); + + if (day != NULL) + *day = priv->day; + if (month != NULL) + *month = priv->month; + if (year != NULL) + *year = priv->year; +} diff --git a/src/gcal-date-selector.h b/src/gcal-date-selector.h new file mode 100644 index 00000000..99762cdb --- /dev/null +++ b/src/gcal-date-selector.h @@ -0,0 +1,69 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * gcal-date-selector.h + * Copyright (C) 2012 Erick Pérez Castellanos + * + * gnome-calendar is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gnome-calendar 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef __GCAL_DATE_SELECTOR_H__ +#define __GCAL_DATE_SELECTOR_H__ + +#include + +G_BEGIN_DECLS + +#define GCAL_TYPE_DATE_SELECTOR (gcal_date_selector_get_type ()) +#define GCAL_DATE_SELECTOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCAL_TYPE_DATE_SELECTOR, GcalDateSelector)) +#define GCAL_DATE_SELECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GCAL_TYPE_DATE_SELECTOR, GcalDateSelectorClass)) +#define GCAL_IS_DATE_SELECTOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCAL_TYPE_DATE_SELECTOR)) +#define GCAL_IS_DATE_SELECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GCAL_TYPE_DATE_SELECTOR)) +#define GCAL_DATE_SELECTOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GCAL_TYPE_DATE_SELECTOR, GcalDateSelectorClass)) + +typedef struct _GcalTime GcalTime; + +typedef struct _GcalDateSelector GcalDateSelector; +typedef struct _GcalDateSelectorClass GcalDateSelectorClass; +typedef struct _GcalDateSelectorPrivate GcalDateSelectorPrivate; + +struct _GcalDateSelector +{ + GtkToggleButton parent; +}; + +struct _GcalDateSelectorClass +{ + GtkToggleButtonClass parent_class; + + /* signals */ + void (*modified) (GcalDateSelector *selector); +}; + +GType gcal_date_selector_get_type (void); + +GtkWidget* gcal_date_selector_new (void); + +void gcal_date_selector_set_date (GcalDateSelector *selector, + gint day, + gint month, + gint year); + +void gcal_date_selector_get_date (GcalDateSelector *selector, + gint *day, + gint *month, + gint *year); + +G_END_DECLS + +#endif /* __GCAL_DATE_SELECTOR_H__ */ diff --git a/src/gcal-edit-dialog.c b/src/gcal-edit-dialog.c index d4c19f8f..efdd746e 100644 --- a/src/gcal-edit-dialog.c +++ b/src/gcal-edit-dialog.c @@ -19,7 +19,7 @@ #include "gcal-edit-dialog.h" #include "gcal-time-selector.h" -#include "gcal-date-entry.h" +#include "gcal-date-selector.h" #include "gcal-utils.h" #include @@ -47,8 +47,8 @@ typedef struct GtkWidget *summary_entry; - GtkWidget *start_date_entry; - GtkWidget *end_date_entry; + GtkWidget *start_date_selector; + GtkWidget *end_date_selector; GtkWidget *all_day_check; GtkWidget *start_time_selector; GtkWidget *end_time_selector; @@ -234,7 +234,7 @@ update_date (GtkEntry *entry, if (icaltime_compare (*start_date, *end_date) != -1) { /* change the non-editing entry */ - if (GTK_WIDGET (entry) == priv->start_date_entry) + if (GTK_WIDGET (entry) == priv->start_date_selector) { end_date->day = start_date->day; end_date->month = start_date->month; @@ -260,26 +260,26 @@ update_date (GtkEntry *entry, } /* update the entries with the new sane values */ - g_signal_handlers_block_by_func (priv->start_date_entry, + g_signal_handlers_block_by_func (priv->start_date_selector, update_date, user_data); - g_signal_handlers_block_by_func (priv->end_date_entry, + g_signal_handlers_block_by_func (priv->end_date_selector, update_date, user_data); - gcal_date_entry_set_date (GCAL_DATE_ENTRY (priv->start_date_entry), + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->start_date_selector), start_date->day, start_date->month, start_date->year); - gcal_date_entry_set_date (GCAL_DATE_ENTRY (priv->end_date_entry), + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->end_date_selector), end_date->day, end_date->month, end_date->year); - g_signal_handlers_unblock_by_func (priv->start_date_entry, + g_signal_handlers_unblock_by_func (priv->start_date_selector, update_date, user_data); - g_signal_handlers_unblock_by_func (priv->end_date_entry, + g_signal_handlers_unblock_by_func (priv->end_date_selector, update_date, user_data); } @@ -406,14 +406,14 @@ update_time (GtkEntry *entry, gcal_time_selector_set_time (GCAL_TIME_SELECTOR (priv->start_time_selector), start_date->hour, start_date->minute); - gcal_date_entry_set_date (GCAL_DATE_ENTRY (priv->start_date_entry), + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->start_date_selector), start_date->day, start_date->month, start_date->year); gcal_time_selector_set_time (GCAL_TIME_SELECTOR (priv->end_time_selector), end_date->hour, end_date->minute); - gcal_date_entry_set_date (GCAL_DATE_ENTRY (priv->end_date_entry), + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->end_date_selector), end_date->day, end_date->month, end_date->year); @@ -468,9 +468,9 @@ gcal_edit_dialog_class_init (GcalEditDialogClass *klass) /* Entries */ gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, summary_entry); gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, start_time_selector); - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, start_date_entry); + gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, start_date_selector); gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, end_time_selector); - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, end_date_entry); + gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, end_date_selector); gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, location_entry); /* Other */ gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, notes_text); @@ -582,12 +582,12 @@ gcal_edit_dialog_constructed (GObject* object) G_CALLBACK (update_location), object); - g_signal_connect (priv->start_date_entry, + g_signal_connect (priv->start_date_selector, "modified", G_CALLBACK (update_date), object); - g_signal_connect (priv->end_date_entry, + g_signal_connect (priv->end_date_selector, "modified", G_CALLBACK (update_date), object); @@ -651,8 +651,6 @@ gcal_edit_dialog_set_writable (GcalEditDialog *dialog, } gtk_editable_set_editable (GTK_EDITABLE (priv->summary_entry), writable); - gtk_editable_set_editable (GTK_EDITABLE (priv->start_date_entry), writable); - gtk_editable_set_editable (GTK_EDITABLE (priv->end_date_entry), writable); gtk_editable_set_editable (GTK_EDITABLE (priv->location_entry), writable); gtk_text_view_set_editable (GTK_TEXT_VIEW (priv->notes_text), writable); @@ -663,11 +661,15 @@ gcal_edit_dialog_set_writable (GcalEditDialog *dialog, { gtk_widget_set_sensitive (priv->start_time_selector, FALSE); gtk_widget_set_sensitive (priv->end_time_selector, FALSE); + gtk_widget_set_sensitive (priv->start_date_selector, FALSE); + gtk_widget_set_sensitive (priv->end_date_selector, FALSE); } else { gtk_widget_set_sensitive (priv->start_time_selector, TRUE); gtk_widget_set_sensitive (priv->end_time_selector, TRUE); + gtk_widget_set_sensitive (priv->start_date_selector, TRUE); + gtk_widget_set_sensitive (priv->end_date_selector, TRUE); } gtk_button_set_label (GTK_BUTTON (priv->done_button), @@ -701,9 +703,9 @@ gcal_edit_dialog_clear_data (GcalEditDialog *dialog) } /* date and time */ - gtk_entry_set_text (GTK_ENTRY (priv->start_date_entry), ""); + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->start_date_selector), 0, 0, 0); gcal_time_selector_set_time (GCAL_TIME_SELECTOR (priv->start_time_selector), 0, 0); - gtk_entry_set_text (GTK_ENTRY (priv->end_date_entry), ""); + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->end_date_selector), 0, 0, 0); gcal_time_selector_set_time (GCAL_TIME_SELECTOR (priv->end_time_selector), 0, 0); /* location */ @@ -874,7 +876,7 @@ gcal_edit_dialog_set_event_data (GcalEditDialog *dialog, /* start date */ e_cal_component_get_dtstart (priv->component, &dtstart); - gcal_date_entry_set_date (GCAL_DATE_ENTRY (priv->start_date_entry), + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->start_date_selector), dtstart.value->day, dtstart.value->month, dtstart.value->year); @@ -891,7 +893,7 @@ gcal_edit_dialog_set_event_data (GcalEditDialog *dialog, e_cal_component_get_dtend (priv->component, &dtend); if (dtend.value != NULL) { - gcal_date_entry_set_date (GCAL_DATE_ENTRY (priv->end_date_entry), + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->end_date_selector), dtend.value->day, dtend.value->month, dtend.value->year); all_day = (dtstart.value->is_date == 1 && dtend.value->is_date == 1); @@ -900,7 +902,7 @@ gcal_edit_dialog_set_event_data (GcalEditDialog *dialog, } else { - gcal_date_entry_set_date (GCAL_DATE_ENTRY (priv->end_date_entry), + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->end_date_selector), dtstart.value->day, dtstart.value->month, dtstart.value->year); gcal_time_selector_set_time (GCAL_TIME_SELECTOR (priv->end_time_selector), dtstart.value->hour, dtstart.value->minute); all_day = FALSE; @@ -1036,7 +1038,7 @@ gcal_edit_dialog_get_start_date (GcalEditDialog *dialog) icaltime_set_timezone (date, gcal_manager_get_system_timezone (priv->manager)); - gcal_date_entry_get_date (GCAL_DATE_ENTRY (priv->start_date_entry), + gcal_date_selector_get_date (GCAL_DATE_SELECTOR (priv->start_date_selector), &value1, &value2, &value3); @@ -1077,7 +1079,7 @@ gcal_edit_dialog_get_end_date (GcalEditDialog *dialog) icaltime_set_timezone (date, gcal_manager_get_system_timezone (priv->manager)); - gcal_date_entry_get_date (GCAL_DATE_ENTRY (priv->end_date_entry), + gcal_date_selector_get_date (GCAL_DATE_SELECTOR (priv->end_date_selector), &value1, &value2, &value3);