static void screenshot_application_startup (GApplication *app) { ScreenshotApplication *self = SCREENSHOT_APPLICATION (app); GtkBuilder *builder; GMenuModel *menu; G_APPLICATION_CLASS (screenshot_application_parent_class)->startup (app); gtk_window_set_default_icon_name (SCREENSHOOTER_ICON); screenshooter_init_stock_icons (); g_action_map_add_action_entries (G_ACTION_MAP (self), action_entries, G_N_ELEMENTS (action_entries), self); builder = gtk_builder_new (); gtk_builder_add_from_resource (builder, "/org/gnome/screenshot/screenshot-app-menu.ui", NULL); menu = G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")); gtk_application_set_app_menu (GTK_APPLICATION (self), menu); g_object_unref (builder); g_object_unref (menu); /* interactive mode: trigger the dialog and wait for the response */ if (screenshot_config->interactive) screenshot_show_interactive_dialog (self); else screenshot_start (self); }
static void interactive_dialog_response_cb (GtkWidget *d, gint response, gpointer user_data) { ScreenshotApplication *self = user_data; if (response != GTK_RESPONSE_HELP) gtk_widget_destroy (d); switch (response) { case GTK_RESPONSE_DELETE_EVENT: break; case GTK_RESPONSE_OK: screenshot_start (self); break; case GTK_RESPONSE_HELP: screenshot_display_help (GTK_WINDOW (d)); break; default: g_assert_not_reached (); break; } }
static void interactive_dialog_response_cb (GtkWidget *d, gint response, gpointer _user_data) { gtk_widget_destroy (d); switch (response) { case GTK_RESPONSE_DELETE_EVENT: case GTK_RESPONSE_CANCEL: gtk_main_quit (); break; case GTK_RESPONSE_OK: screenshot_start (); break; default: g_assert_not_reached (); break; } }
/* main */ int main (int argc, char *argv[]) { GOptionContext *context; gboolean clipboard_arg = FALSE; gboolean window_arg = FALSE; gboolean area_arg = FALSE; gboolean include_border_arg = FALSE; gboolean disable_border_arg = FALSE; gboolean interactive_arg = FALSE; gchar *border_effect_arg = NULL; guint delay_arg = 0; GError *error = NULL; gboolean res; const GOptionEntry entries[] = { { "clipboard", 'c', 0, G_OPTION_ARG_NONE, &clipboard_arg, N_("Send the grab directly to the clipboard"), NULL }, { "window", 'w', 0, G_OPTION_ARG_NONE, &window_arg, N_("Grab a window instead of the entire screen"), NULL }, { "area", 'a', 0, G_OPTION_ARG_NONE, &area_arg, N_("Grab an area of the screen instead of the entire screen"), NULL }, { "include-border", 'b', 0, G_OPTION_ARG_NONE, &include_border_arg, N_("Include the window border with the screenshot"), NULL }, { "remove-border", 'B', 0, G_OPTION_ARG_NONE, &disable_border_arg, N_("Remove the window border from the screenshot"), NULL }, { "delay", 'd', 0, G_OPTION_ARG_INT, &delay_arg, N_("Take screenshot after specified delay [in seconds]"), N_("seconds") }, { "border-effect", 'e', 0, G_OPTION_ARG_STRING, &border_effect_arg, N_("Effect to add to the border (shadow, border or none)"), N_("effect") }, { "interactive", 'i', 0, G_OPTION_ARG_NONE, &interactive_arg, N_("Interactively set options"), NULL }, { NULL }, }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); g_thread_init (NULL); context = g_option_context_new (_("Take a picture of the screen")); g_option_context_set_ignore_unknown_options (context, FALSE); g_option_context_set_help_enabled (context, TRUE); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, &error); if (error) { g_critical ("Unable to parse arguments: %s", error->message); g_error_free (error); g_option_context_free (context); exit (1); } g_option_context_free (context); res = screenshot_load_config (clipboard_arg, window_arg, area_arg, include_border_arg, disable_border_arg, border_effect_arg, delay_arg, interactive_arg); if (!res || !screenshot_app_init ()) exit (1); /* interactive mode: trigger the dialog and wait for the response */ if (interactive_arg) { GtkWidget *dialog; dialog = screenshot_interactive_dialog_new (); gtk_widget_show (dialog); g_signal_connect (dialog, "response", G_CALLBACK (interactive_dialog_response_cb), NULL); } else { screenshot_start (); } gtk_main (); g_clear_object (&connection); return EXIT_SUCCESS; }