[gnome-calendar] app: gained --date option
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] app: gained --date option
- Date: Wed, 10 Dec 2014 13:49:41 +0000 (UTC)
commit 83345b2fb468a129281c4ee48239c97698696d38
Author: Erick Pérez Castellanos <erick red gmail com>
Date: Tue Dec 9 15:36:01 2014 -0500
app: gained --date option
GcalWindow loads the date from GcalApplication.
src/gcal-application.c | 54 ++++++++++++++++++++++++++++++++++++++++--------
src/gcal-window.c | 20 ++++-------------
src/gcal-window.h | 5 ++-
3 files changed, 53 insertions(+), 26 deletions(-)
---
diff --git a/src/gcal-application.c b/src/gcal-application.c
index daf6cff..e0ecd4c 100644
--- a/src/gcal-application.c
+++ b/src/gcal-application.c
@@ -39,6 +39,8 @@ typedef struct
GcalManager *manager;
GtkCssProvider *provider;
+
+ icaltimetype *initial_date;
} GcalApplicationPrivate;
static void gcal_application_finalize (GObject *object);
@@ -75,6 +77,7 @@ static void gcal_application_quit (GSimpleAction *
G_DEFINE_TYPE_WITH_PRIVATE (GcalApplication, gcal_application, GTK_TYPE_APPLICATION);
static gboolean show_version = FALSE;
+static gchar* date = NULL;
static GOptionEntry gcal_application_goptions[] = {
{
@@ -82,6 +85,11 @@ static GOptionEntry gcal_application_goptions[] = {
G_OPTION_ARG_NONE, &show_version,
N_("Display version number"), NULL
},
+ {
+ "date", 'd', 0,
+ G_OPTION_ARG_STRING, &date,
+ N_("Open calendar on the passed date"), NULL
+ },
{ NULL }
};
@@ -120,7 +128,7 @@ gcal_application_init (GcalApplication *self)
static void
gcal_application_finalize (GObject *object)
{
- GcalApplicationPrivate *priv;
+ GcalApplicationPrivate *priv;
priv = gcal_application_get_instance_private (GCAL_APPLICATION (object));
@@ -128,6 +136,9 @@ gcal_application_finalize (GObject *object)
g_clear_object (&(priv->provider));
g_clear_object (&(priv->manager));
+ if (priv->initial_date != NULL)
+ g_free (priv->initial_date);
+
G_OBJECT_CLASS (gcal_application_parent_class)->finalize (object);
}
@@ -144,14 +155,18 @@ gcal_application_activate (GApplication *application)
}
else
{
- priv->window =
- gcal_window_new_with_view (GCAL_APPLICATION (application),
- g_settings_get_enum (priv->settings,
- "active-view"));
- g_settings_bind (priv->settings,
- "active-view",
- priv->window,
- "active-view",
+ if (priv->initial_date == NULL)
+ {
+ /* FIXME: here read the initial date from somewehere */
+ *(priv->initial_date) = icaltime_current_time_with_zone (gcal_manager_get_system_timezone
(priv->manager));
+ *(priv->initial_date) = icaltime_set_timezone (priv->initial_date,
+ gcal_manager_get_system_timezone (priv->manager));
+ }
+
+ priv->window = gcal_window_new_with_view_and_date (GCAL_APPLICATION (application),
+ g_settings_get_enum (priv->settings, "active-view"),
+ priv->initial_date);
+ g_settings_bind (priv->settings, "active-view", priv->window, "active-view",
G_SETTINGS_BIND_SET | G_SETTINGS_BIND_GET);
gtk_widget_show_all (priv->window);
@@ -204,11 +219,14 @@ static gint
gcal_application_command_line (GApplication *app,
GApplicationCommandLine *command_line)
{
+ GcalApplicationPrivate *priv;
+
GOptionContext *context;
gchar **argv;
GError *error;
gint argc;
+ priv = gcal_application_get_instance_private (GCAL_APPLICATION (app));
argv = g_application_command_line_get_arguments (command_line, &argc);
context = g_option_context_new (N_("- Calendar management"));
g_option_context_add_main_entries (context, gcal_application_goptions, GETTEXT_PACKAGE);
@@ -228,6 +246,24 @@ gcal_application_command_line (GApplication *app,
return 0;
}
+ if (date != NULL)
+ {
+ struct tm result;
+
+ if (e_time_parse_date_and_time (date, &result) == E_TIME_PARSE_OK)
+ {
+ if (priv->initial_date == NULL)
+ priv->initial_date = g_new0 (icaltimetype, 1);
+ *(priv->initial_date) = tm_to_icaltimetype (&result, FALSE);
+
+ *(priv->initial_date) = icaltime_set_timezone (priv->initial_date,
+ gcal_manager_get_system_timezone (priv->manager));
+ print_date ("loading date", priv->initial_date);
+ }
+
+ g_clear_pointer (&date, g_free);
+ }
+
g_option_context_free (context);
g_strfreev (argv);
diff --git a/src/gcal-window.c b/src/gcal-window.c
index d3e2a31..2773355 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -1286,26 +1286,16 @@ gcal_window_state_event (GtkWidget *widget,
/* Public API */
GtkWidget*
-gcal_window_new_with_view (GcalApplication *app,
- GcalWindowViewType view_type)
+gcal_window_new_with_view_and_date (GcalApplication *app,
+ GcalWindowViewType view_type,
+ icaltimetype *date)
{
GcalWindow *win;
GcalManager *manager;
- icaltimetype date;
manager = gcal_application_get_manager (GCAL_APPLICATION (app));
- /* FIXME: here read the initial date from somewehere */
- date = icaltime_current_time_with_zone (gcal_manager_get_system_timezone (manager));
- date = icaltime_set_timezone (&date,
- gcal_manager_get_system_timezone (manager));
-
- win = g_object_new (GCAL_TYPE_WINDOW,
- "application",
- GTK_APPLICATION (app),
- "active-date",
- &date,
- "manager",
- manager,
+
+ win = g_object_new (GCAL_TYPE_WINDOW, "application", GTK_APPLICATION (app), "active-date", date,
"manager", manager,
NULL);
/* loading size */
diff --git a/src/gcal-window.h b/src/gcal-window.h
index 778f06d..0ba14ab 100644
--- a/src/gcal-window.h
+++ b/src/gcal-window.h
@@ -51,8 +51,9 @@ struct _GcalWindowClass
GType gcal_window_get_type (void);
-GtkWidget* gcal_window_new_with_view (GcalApplication *app,
- GcalWindowViewType view_type);
+GtkWidget* gcal_window_new_with_view_and_date (GcalApplication *app,
+ GcalWindowViewType view_type,
+ icaltimetype *date);
void gcal_window_new_event (GcalWindow *window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]