static void load_print_settings (GeditApp *app) { GeditAppPrivate *priv; gchar *filename; GError *error = NULL; priv = gedit_app_get_instance_private (app); g_return_if_fail (priv->print_settings == NULL); filename = get_print_settings_file (); priv->print_settings = gtk_print_settings_new_from_file (filename, &error); if (error) { /* Ignore file not found error */ if (error->domain != G_FILE_ERROR || error->code != G_FILE_ERROR_NOENT) { g_warning ("%s", error->message); } g_error_free (error); } g_free (filename); /* fall back to default settings */ if (priv->print_settings == NULL) { priv->print_settings = gtk_print_settings_new (); } }
static VALUE rg_initialize(int argc, VALUE *argv, VALUE self) { VALUE arg1, arg2; GtkPrintSettings* settings = NULL; GError *error = NULL; rb_scan_args(argc, argv, "02", &arg1, &arg2); if (NIL_P(arg1)){ settings = gtk_print_settings_new(); } else if (NIL_P(arg2)){ settings = gtk_print_settings_new_from_file(RVAL2CSTR(arg1), &error); if (!settings) { RAISE_GERROR(error); } } else { settings = gtk_print_settings_new_from_key_file((GKeyFile*)RVAL2BOXED(arg1, G_TYPE_KEY_FILE), RVAL2CSTR(arg2), &error); if (!settings) { RAISE_GERROR(error); } } G_INITIALIZE(self, settings); return Qnil; }
/** * ephy_embed_shell_get_print_settings: * @shell: the #EphyEmbedShell * * Gets the global #GtkPrintSettings object. * * Returns: (transfer none): a #GtkPrintSettings object **/ GtkPrintSettings * ephy_embed_shell_get_print_settings (EphyEmbedShell *shell) { EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell); g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL); if (priv->print_settings == NULL) { GError *error = NULL; char *path; path = g_build_filename (ephy_dot_dir (), PRINT_SETTINGS_FILENAME, NULL); priv->print_settings = gtk_print_settings_new_from_file (path, &error); g_free (path); /* Note: the gtk print settings file format is the same as our * legacy one, so no need to migrate here. */ if (priv->print_settings == NULL) priv->print_settings = gtk_print_settings_new (); } return priv->print_settings; }
int main (int argc, char **argv) { GtkApplication *app; GError *error = NULL; gtk_init (NULL, NULL); settings = gtk_print_settings_new_from_file ("print-settings.ini", &error); if (error) { g_print ("Failed to load print settings: %s\n", error->message); g_clear_error (&error); settings = gtk_print_settings_new (); } g_assert (settings != NULL); page_setup = gtk_page_setup_new_from_file ("page-setup.ini", &error); if (error) { g_print ("Failed to load page setup: %s\n", error->message); g_clear_error (&error); } app = gtk_application_new ("org.gtk.PrintEditor", 0); g_action_map_add_action_entries (G_ACTION_MAP (app), app_entries, G_N_ELEMENTS (app_entries), app); g_signal_connect (app, "startup", G_CALLBACK (startup), NULL); g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL); g_application_run (G_APPLICATION (app), argc, argv); if (!gtk_print_settings_to_file (settings, "print-settings.ini", &error)) { g_print ("Failed to save print settings: %s\n", error->message); g_clear_error (&error); } if (page_setup && !gtk_page_setup_to_file (page_setup, "page-setup.ini", &error)) { g_print ("Failed to save page setup: %s\n", error->message); g_clear_error (&error); } return 0; }
int main (int argc, char **argv) { GError *error = NULL; g_set_application_name ("Print editor"); gtk_init (&argc, &argv); settings = gtk_print_settings_new_from_file ("print-settings.ini", &error); if (error) { g_print ("Failed to load print settings: %s\n", error->message); g_clear_error (&error); settings = gtk_print_settings_new (); } g_assert (settings != NULL); page_setup = gtk_page_setup_new_from_file ("page-setup.ini", &error); if (error) { g_print ("Failed to load page setup: %s\n", error->message); g_clear_error (&error); } create_window (); if (argc == 2) load_file (argv[1]); gtk_main (); if (!gtk_print_settings_to_file (settings, "print-settings.ini", &error)) { g_print ("Failed to save print settings: %s\n", error->message); g_clear_error (&error); } if (page_setup && !gtk_page_setup_to_file (page_setup, "page-setup.ini", &error)) { g_print ("Failed to save page setup: %s\n", error->message); g_clear_error (&error); } return 0; }
static void load_print_settings (GeditApp *app) { GeditAppPrivate *priv; gchar *filename; GError *error = NULL; priv = gedit_app_get_instance_private (app); g_return_if_fail (priv->print_settings == NULL); filename = get_print_settings_file (); priv->print_settings = gtk_print_settings_new_from_file (filename, &error); if (error != NULL) { /* - Ignore file not found error. * - Ignore empty file error, i.e. group not found. This happens * when we click on cancel in the print dialog, when using the * printing for the first time in gedit. */ if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT) && !g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) { g_warning ("Load print settings error: %s", error->message); } g_error_free (error); } g_free (filename); /* fall back to default settings */ if (priv->print_settings == NULL) { priv->print_settings = gtk_print_settings_new (); } }