date-selector: initial implementetation

No functionality is ready, only project settings and class type.
This commit is contained in:
Georges Basile Stavracas Neto
2014-12-23 12:01:38 -05:00
committed by Erick Pérez Castellanos
parent 6bea205cfd
commit 40683e5e10
11 changed files with 340 additions and 540 deletions
+1
View File
@@ -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 \
+1
View File
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/calendar">
<file alias="date-selector.ui" compressed="true" preprocess="xml-stripblanks">ui/date-selector.ui</file>
<file alias="edit-dialog.ui" compressed="true" preprocess="xml-stripblanks">ui/edit-dialog.ui</file>
<file alias="menus.ui" compressed="true" preprocess="xml-stripblanks">ui/menus.ui</file>
<file alias="nav_bar.ui" compressed="true" preprocess="xml-stripblanks">ui/nav_bar.ui</file>
+8
View File
@@ -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;
}
+74
View File
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkGrid" id="grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">12</property>
<property name="row_spacing">6</property>
<child>
<object class="GtkBox" id="date_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkEntry" id="entry1">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<style>
<class name="middle-entry"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry3">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<style>
<class name="linked"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkCalendar" id="calendar">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="year">2014</property>
<property name="month">11</property>
<property name="day">18</property>
<property name="show_week_numbers">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
</interface>
+2 -2
View File
@@ -247,7 +247,7 @@
</packing>
</child>
<child>
<object class="GcalDateEntry" id="start_date_entry">
<object class="GcalDateSelector" id="start_date_selector">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
@@ -267,7 +267,7 @@
</packing>
</child>
<child>
<object class="GcalDateEntry" id="end_date_entry">
<object class="GcalDateSelector" id="end_date_selector">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
+2 -2
View File
@@ -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 \
-439
View File
@@ -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 <erickpc@gnome.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "gcal-date-entry.h"
#include <locale.h>
#include <langinfo.h>
#include <glib/gi18n.h>
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;
}
-72
View File
@@ -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 <erickpc@gnome.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef __GCAL_DATE_ENTRY_H__
#define __GCAL_DATE_ENTRY_H__
#include <gtk/gtk.h>
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__ */
+156
View File
@@ -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 <erickpc@gnome.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "gcal-date-selector.h"
#include <locale.h>
#include <langinfo.h>
#include <glib/gi18n.h>
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;
}
+69
View File
@@ -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 <erickpc@gnome.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef __GCAL_DATE_SELECTOR_H__
#define __GCAL_DATE_SELECTOR_H__
#include <gtk/gtk.h>
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__ */
+27 -25
View File
@@ -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 <libecal/libecal.h>
@@ -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);