app: gained --date option

GcalWindow loads the date from GcalApplication.
This commit is contained in:
Erick Pérez Castellanos
2014-12-09 15:36:01 -05:00
parent 738bb89d94
commit 83345b2fb4
3 changed files with 52 additions and 25 deletions
+45 -9
View File
@@ -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);
+4 -14
View File
@@ -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 */
+3 -2
View File
@@ -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);