From 3baa71f07dd60202a9ffcfc139e089d6fc3f46b4 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Sat, 27 Apr 2019 22:16:37 -0300 Subject: [PATCH] application: Reorganize file a bit --- src/gcal-application.c | 284 ++++++++++++++++++++--------------------- 1 file changed, 136 insertions(+), 148 deletions(-) diff --git a/src/gcal-application.c b/src/gcal-application.c index 1890f3fe..64c7e8a7 100644 --- a/src/gcal-application.c +++ b/src/gcal-application.c @@ -51,22 +51,6 @@ struct _GcalApplication GcalContext *context; }; -static void gcal_application_launch_search (GSimpleAction *search, - GVariant *parameter, - gpointer app); - -static void gcal_application_show_about (GSimpleAction *simple, - GVariant *parameter, - gpointer user_data); - -static void gcal_application_sync (GSimpleAction *sync, - GVariant *parameter, - gpointer app); - -static void gcal_application_quit (GSimpleAction *simple, - GVariant *parameter, - gpointer user_data); - G_DEFINE_TYPE (GcalApplication, gcal_application, DZL_TYPE_APPLICATION); static gboolean show_version = FALSE; @@ -100,13 +84,6 @@ static GOptionEntry gcal_application_goptions[] = { { NULL } }; -static const GActionEntry gcal_app_entries[] = { - { "sync", gcal_application_sync }, - { "search", gcal_application_launch_search }, - { "about", gcal_application_show_about }, - { "quit", gcal_application_quit }, -}; - enum { PROP_0, @@ -184,6 +161,135 @@ load_css_provider (GcalApplication *self) gtk_css_provider_load_from_resource (self->provider, "/org/gnome/calendar/theme/Adwaita.css"); } +/* + * Callbacks + */ + +static void +gcal_application_sync (GSimpleAction *sync, + GVariant *parameter, + gpointer app) +{ + GcalWeatherService *weather_service; + GcalApplication *self; + + self = GCAL_APPLICATION (app); + weather_service = gcal_context_get_weather_service (self->context); + + gcal_manager_refresh (gcal_context_get_manager (self->context)); + gcal_weather_service_update (weather_service); +} + +static void +gcal_application_launch_search (GSimpleAction *search, + GVariant *parameter, + gpointer app) +{ + GcalApplication *self = GCAL_APPLICATION (app); + gcal_window_set_search_mode (GCAL_WINDOW (self->window), TRUE); +} + +static void +on_about_response (GtkAboutDialog *about, + int response_id, + gpointer user_data) +{ + g_return_if_fail (GTK_IS_ABOUT_DIALOG (about)); + g_return_if_fail (user_data == NULL); + + if (response_id == GTK_RESPONSE_CANCEL) + gtk_widget_destroy (GTK_WIDGET (about)); +} + +static gchar* +build_about_copyright (GcalApplication *self) +{ + g_autoptr (GDateTime) dt = NULL; + GcalWeatherService *weather_service; + const gchar *attribution; + GString *builder; + + builder = g_string_new (""); + dt = g_date_time_new_now_local (); + + /* Build string: */ + g_string_append_printf (builder, + _("Copyright \xC2\xA9 2012\xE2\x80\x93%d " "The Calendar authors"), + g_date_time_get_year (dt)); + + weather_service = gcal_context_get_weather_service (self->context); + attribution = gcal_weather_service_get_attribution (weather_service); + if (attribution) + { + g_string_append_c (builder, '\n'); + g_string_append (builder, attribution); + } + g_string_append (builder, ""); + + return g_string_free (builder, FALSE); +} + +static void +gcal_application_show_about (GSimpleAction *simple, + GVariant *parameter, + gpointer user_data) +{ + GcalApplication *self; + GtkWidget *dialog; + GtkLabel *copyright_label; + g_autofree gchar *copyright = NULL; + + const gchar *authors[] = { + "Erick Pérez Castellanos ", + "Georges Basile Stavracas Neto ", + "Isaque Galdino ", + NULL + }; + const gchar *artists[] = { + "Jakub Steiner ", + "Lapo Calamandrei ", + "Reda Lazri ", + "William Jon McCann ", + NULL + }; + + + self = GCAL_APPLICATION (user_data); + + dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG, + "transient-for", GTK_WINDOW (self->window), + "modal", TRUE, + "destroy-with-parent", TRUE, + "program-name", _("Calendar"), + "version", VERSION, + "license-type", GTK_LICENSE_GPL_3_0, + "authors", authors, + "artists", artists, + "logo-icon-name", "org.gnome.Calendar", + "translator-credits", _("translator-credits"), + NULL); + + copyright = build_about_copyright (self); + copyright_label = GTK_LABEL (gtk_widget_get_template_child (GTK_WIDGET (dialog), + GTK_TYPE_ABOUT_DIALOG, + "copyright_label")); + gtk_label_set_markup (copyright_label, copyright); + gtk_widget_show (GTK_WIDGET (copyright_label)); + + g_signal_connect (dialog, "response", G_CALLBACK (on_about_response), NULL); + gtk_widget_show (dialog); +} + +static void +gcal_application_quit (GSimpleAction *simple, + GVariant *parameter, + gpointer user_data) +{ + GcalApplication *self = GCAL_APPLICATION (user_data); + + gtk_widget_destroy (self->window); +} + /* * GObject overrides @@ -290,6 +396,13 @@ gcal_application_startup (GApplication *app) { GcalApplication *self; + static const GActionEntry gcal_app_entries[] = { + { "sync", gcal_application_sync }, + { "search", gcal_application_launch_search }, + { "about", gcal_application_show_about }, + { "quit", gcal_application_quit }, + }; + GCAL_ENTRY; self = GCAL_APPLICATION (app); @@ -487,131 +600,6 @@ gcal_application_init (GcalApplication *self) self->search_provider = gcal_shell_search_provider_new (self->context); } -static void -gcal_application_sync (GSimpleAction *sync, - GVariant *parameter, - gpointer app) -{ - GcalWeatherService *weather_service; - GcalApplication *self; - - self = GCAL_APPLICATION (app); - weather_service = gcal_context_get_weather_service (self->context); - - gcal_manager_refresh (gcal_context_get_manager (self->context)); - gcal_weather_service_update (weather_service); -} - -static void -gcal_application_launch_search (GSimpleAction *search, - GVariant *parameter, - gpointer app) -{ - GcalApplication *self = GCAL_APPLICATION (app); - gcal_window_set_search_mode (GCAL_WINDOW (self->window), TRUE); -} - -static void -on_about_response (GtkAboutDialog *about, - int response_id, - gpointer user_data) -{ - g_return_if_fail (GTK_IS_ABOUT_DIALOG (about)); - g_return_if_fail (user_data == NULL); - - if (response_id == GTK_RESPONSE_CANCEL) - gtk_widget_destroy (GTK_WIDGET (about)); -} - -static gchar* -build_about_copyright (GcalApplication *self) -{ - g_autoptr (GDateTime) dt = NULL; - GcalWeatherService *weather_service; - const gchar *attribution; - GString *builder; - - builder = g_string_new (""); - dt = g_date_time_new_now_local (); - - /* Build string: */ - g_string_append_printf (builder, - _("Copyright \xC2\xA9 2012\xE2\x80\x93%d " "The Calendar authors"), - g_date_time_get_year (dt)); - - weather_service = gcal_context_get_weather_service (self->context); - attribution = gcal_weather_service_get_attribution (weather_service); - if (attribution) - { - g_string_append_c (builder, '\n'); - g_string_append (builder, attribution); - } - g_string_append (builder, ""); - - return g_string_free (builder, FALSE); -} - -static void -gcal_application_show_about (GSimpleAction *simple, - GVariant *parameter, - gpointer user_data) -{ - GcalApplication *self; - GtkWidget *dialog; - GtkLabel *copyright_label; - g_autofree gchar *copyright = NULL; - - const gchar *authors[] = { - "Erick Pérez Castellanos ", - "Georges Basile Stavracas Neto ", - "Isaque Galdino ", - NULL - }; - const gchar *artists[] = { - "Jakub Steiner ", - "Lapo Calamandrei ", - "Reda Lazri ", - "William Jon McCann ", - NULL - }; - - - self = GCAL_APPLICATION (user_data); - - dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG, - "transient-for", GTK_WINDOW (self->window), - "modal", TRUE, - "destroy-with-parent", TRUE, - "program-name", _("Calendar"), - "version", VERSION, - "license-type", GTK_LICENSE_GPL_3_0, - "authors", authors, - "artists", artists, - "logo-icon-name", "org.gnome.Calendar", - "translator-credits", _("translator-credits"), - NULL); - - copyright = build_about_copyright (self); - copyright_label = GTK_LABEL (gtk_widget_get_template_child (GTK_WIDGET (dialog), - GTK_TYPE_ABOUT_DIALOG, - "copyright_label")); - gtk_label_set_markup (copyright_label, copyright); - gtk_widget_show (GTK_WIDGET (copyright_label)); - - g_signal_connect (dialog, "response", G_CALLBACK (on_about_response), NULL); - gtk_widget_show (dialog); -} - -static void -gcal_application_quit (GSimpleAction *simple, - GVariant *parameter, - gpointer user_data) -{ - GcalApplication *self = GCAL_APPLICATION (user_data); - - gtk_widget_destroy (self->window); -} - /* Public API */ GcalApplication* gcal_application_new (void)