/* Internal: Load script (enhanced) command from config */ void _verve_db_load_script_rc (VerveDb *db, const XfceRc *rc) { g_return_if_fail (xfce_rc_has_entry (rc, "Target")); g_return_if_fail (xfce_rc_has_entry (rc, "Shell")); /* Get basename of target */ const gchar *basename = xfce_rc_read_entry (rc, "Target", NULL); /* Get resource path */ gchar *resource = g_build_filename (g_get_application_name (), basename, NULL); /* Get absolute filename */ gchar *filename = xfce_resource_lookup (XFCE_RESOURCE_DATA, resource); VerveScriptCommand *cmd; cmd = (VerveScriptCommand *)malloc (sizeof (VerveScriptCommand)); cmd->name = g_strdup (xfce_rc_read_entry (rc, "Name", NULL)); cmd->shell = g_strdup (xfce_rc_read_entry (rc, "Shell", "sh")); cmd->target_filename = g_strdup (filename); g_hash_table_insert (db->script_commands, (gpointer) cmd->name, (gpointer) cmd); g_free (resource); g_free (filename); }
static void xfce_xkb_configure_layout (GtkWidget *widget, gpointer user_data) { gchar *desktop_file = xfce_resource_lookup (XFCE_RESOURCE_DATA, "applications/xfce-keyboard-settings.desktop"); GarconMenuItem *item = garcon_menu_item_new_for_path (desktop_file); if (item) { GError *error = NULL; gchar **argv; gboolean succeed; g_shell_parse_argv (garcon_menu_item_get_command (item), NULL, &argv, &error); succeed = xfce_spawn_on_screen (gtk_widget_get_screen (GTK_WIDGET (widget)), garcon_menu_item_get_path (item), argv, NULL, G_SPAWN_SEARCH_PATH, garcon_menu_item_supports_startup_notification (item), gtk_get_current_event_time (), garcon_menu_item_get_icon_name (item), &error); g_strfreev (argv); garcon_menu_item_unref (item); g_assert (succeed); } g_free (desktop_file); }
static void terminal_toolbars_model_init (TerminalToolbarsModel *model) { gchar *file; exo_toolbars_model_set_actions (EXO_TOOLBARS_MODEL (model), (gchar **) actions, G_N_ELEMENTS (actions)); xfce_resource_push_path (XFCE_RESOURCE_DATA, DATADIR); file = xfce_resource_lookup (XFCE_RESOURCE_DATA, "Terminal/Terminal-toolbars.ui"); xfce_resource_pop_path (XFCE_RESOURCE_DATA); if (G_LIKELY (file != NULL)) { exo_toolbars_model_load_from_file (EXO_TOOLBARS_MODEL (model), file, NULL); g_free (file); } else { g_warning ("Unable to locate Terminal/Terminal-toolbars.ui, " "the toolbars may not work correctly"); } g_signal_connect (G_OBJECT (model), "item-added", G_CALLBACK (terminal_toolbars_model_queue_sync), NULL); g_signal_connect (G_OBJECT (model), "item-removed", G_CALLBACK (terminal_toolbars_model_queue_sync), NULL); g_signal_connect (G_OBJECT (model), "toolbar-added", G_CALLBACK (terminal_toolbars_model_queue_sync), NULL); g_signal_connect (G_OBJECT (model), "toolbar-changed", G_CALLBACK (terminal_toolbars_model_queue_sync), NULL); g_signal_connect (G_OBJECT (model), "toolbar-removed", G_CALLBACK (terminal_toolbars_model_queue_sync), NULL); }
static void _verve_history_cache_load (void) { const gchar *basename = _verve_history_cache_get_filename (); gchar *filename = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, basename); if (G_UNLIKELY (filename == NULL)) return; GError *error = NULL; GIOChannel *handle = g_io_channel_new_file (filename, "r", &error); if (error) g_error_free (error); if (G_LIKELY (handle != NULL)) { gchar *line; gsize length; GIOStatus status; status = g_io_channel_read_line (handle, &line, &length, NULL, &error); while (status != G_IO_STATUS_EOF && error == NULL) { GString *strline = g_string_new (g_strstrip (line)); g_free (line); if (strline->len > 0) { _verve_history_append (strline->str); } g_string_free (strline, FALSE); status = g_io_channel_read_line (handle, &line, &length, NULL, &error); } if (error) g_error_free (error); g_io_channel_shutdown (handle, TRUE, &error); if (error) g_error_free (error); g_io_channel_unref (handle); } g_free (filename); }
GdkPixbuf * xfsm_load_session_preview (const gchar *name) { GdkDisplay *display; GdkPixbuf *pb = NULL; gchar *display_name; gchar *filename; gchar *path; /* determine thumb file */ display = gdk_display_get_default (); display_name = xfsm_gdk_display_get_fullname (display); path = g_strconcat ("sessions/thumbs-", display_name, "/", name, ".png", NULL); filename = xfce_resource_lookup (XFCE_RESOURCE_CACHE, path); g_free (display_name); g_free (path); if (filename != NULL) pb = gdk_pixbuf_new_from_file (filename, NULL); g_free (filename); return pb; }
static void rstto_settings_init (GObject *object) { gchar *accelmap_path = NULL; RsttoSettings *settings = RSTTO_SETTINGS (object); settings->priv = g_new0 (RsttoSettingsPriv, 1); settings->priv->channel = xfconf_channel_new ("ristretto"); accelmap_path = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, "ristretto/accels.scm"); if (accelmap_path) { gtk_accel_map_load (accelmap_path); g_free (accelmap_path); accelmap_path = NULL; } else { /* If the accels.scm file is missing, we are probably * dealing with a first-boot. Add default accelerators. */ gtk_accel_map_change_entry ("<Window>/fullscreen", GDK_KEY_F, 0, FALSE); gtk_accel_map_change_entry ("<Window>/unfullscreen", GDK_KEY_Escape, 0, FALSE); gtk_accel_map_change_entry ("<Window>/next-image", GDK_KEY_Page_Down, 0, FALSE); gtk_accel_map_change_entry ("<Window>/previous-image", GDK_KEY_Page_Up, 0, FALSE); gtk_accel_map_change_entry ("<Window>/quit", GDK_KEY_q, 0, FALSE); gtk_accel_map_change_entry ("<Window>/delete", GDK_KEY_Delete, GDK_SHIFT_MASK, FALSE); gtk_accel_map_change_entry ("<Window>/refresh", GDK_KEY_r, GDK_CONTROL_MASK, FALSE); gtk_accel_map_change_entry ("<Actions>/RsttoWindow/play", GDK_KEY_F5, 0, FALSE); } settings->priv->slideshow_timeout = 5; settings->priv->bgcolor = g_new0 (GdkColor, 1); settings->priv->bgcolor_fullscreen = g_new0 (GdkColor, 1); settings->priv->navigationbar_position = g_strdup ("left"); settings->priv->show_toolbar = TRUE; settings->priv->window_width = 600; settings->priv->window_height = 440; settings->priv->wrap_images = TRUE; settings->priv->show_thumbnailbar = TRUE; settings->priv->show_statusbar = TRUE; settings->priv->use_thunar_properties = TRUE; settings->priv->maximize_on_startup = TRUE; settings->priv->hide_thumbnails_fullscreen = TRUE; settings->priv->errors.missing_thumbnailer = TRUE; settings->priv->thumbnail_size = THUMBNAIL_SIZE_NORMAL; xfconf_g_property_bind ( settings->priv->channel, "/window/width", G_TYPE_UINT, settings, "window-width"); xfconf_g_property_bind ( settings->priv->channel, "/window/height", G_TYPE_UINT, settings, "window-height"); xfconf_g_property_bind ( settings->priv->channel, "/file/current-uri", G_TYPE_STRING, settings, "current-uri"); xfconf_g_property_bind ( settings->priv->channel, "/window/toolbar/show", G_TYPE_BOOLEAN, settings, "show-toolbar"); xfconf_g_property_bind ( settings->priv->channel, "/window/navigationbar/sort-type", G_TYPE_UINT, settings, "sort-type"); xfconf_g_property_bind ( settings->priv->channel, "/window/navigationbar/position", G_TYPE_STRING, settings, "navigationbar-position"); xfconf_g_property_bind ( settings->priv->channel, "/window/thumbnails/show", G_TYPE_BOOLEAN, settings, "show-thumbnailbar"); xfconf_g_property_bind ( settings->priv->channel, "/window/statusbar/show", G_TYPE_BOOLEAN, settings, "show-statusbar"); xfconf_g_property_bind ( settings->priv->channel, "/window/thumbnails/size", G_TYPE_UINT, settings, "thumbnail-size"); xfconf_g_property_bind ( settings->priv->channel, "/window/thumbnails/hide-fullscreen", G_TYPE_BOOLEAN, settings, "hide-thumbnails-fullscreen"); xfconf_g_property_bind ( settings->priv->channel, "/slideshow/timeout", G_TYPE_UINT, settings, "slideshow-timeout"); xfconf_g_property_bind ( settings->priv->channel, "/window/bgcolor-override", G_TYPE_BOOLEAN, settings, "bgcolor-override"); xfconf_g_property_bind_gdkcolor ( settings->priv->channel, "/window/bgcolor", settings, "bgcolor"); xfconf_g_property_bind_gdkcolor ( settings->priv->channel, "/window/bgcolor-fullscreen", settings, "bgcolor-fullscreen"); xfconf_g_property_bind ( settings->priv->channel, "/window/invert-zoom-direction", G_TYPE_BOOLEAN, settings, "invert-zoom-direction"); xfconf_g_property_bind ( settings->priv->channel, "/window/show-clock", G_TYPE_BOOLEAN, settings, "show-clock"); xfconf_g_property_bind ( settings->priv->channel, "/image/wrap", G_TYPE_BOOLEAN, settings, "wrap-images"); xfconf_g_property_bind ( settings->priv->channel, "/image/limit-quality", G_TYPE_BOOLEAN, settings, "limit-quality"); xfconf_g_property_bind ( settings->priv->channel, "/window/use-thunar-properties", G_TYPE_BOOLEAN, settings, "use-thunar-properties"); xfconf_g_property_bind ( settings->priv->channel, "/window/maximize-on-startup", G_TYPE_BOOLEAN, settings, "maximize-on-startup"); xfconf_g_property_bind ( settings->priv->channel, "/errors/missing-thumbnailer", G_TYPE_BOOLEAN, settings, "show-error-missing-thumbnailer"); xfconf_g_property_bind ( settings->priv->channel, "/desktop/type", G_TYPE_STRING, settings, "desktop-type"); }
/** * xfce_panel_pixbuf_from_source_at_size: * @source: string that contains the location of an icon * @icon_theme: icon theme or %NULL to use the default icon theme * @dest_width: the maximum returned width of the GdkPixbuf * @dest_height: the maximum returned height of the GdkPixbuf * * Try to load a pixbuf from a source string. The source could be * an abolute path, an icon name or a filename that points to a * file in the pixmaps directory. * * This function is particularly usefull for loading names from * the Icon key of desktop files. * * The pixbuf is never bigger than @dest_width and @dest_height. * If it is when loaded from the disk, the pixbuf is scaled * preserving the aspect ratio. * * Returns: a GdkPixbuf or %NULL if nothing was found. The value should * be released with g_object_unref when no longer used. * * See also: XfcePanelImage * * Since: 4.10 **/ GdkPixbuf * xfce_panel_pixbuf_from_source_at_size (const gchar *source, GtkIconTheme *icon_theme, gint dest_width, gint dest_height) { GdkPixbuf *pixbuf = NULL; gchar *p; gchar *name; gchar *filename; gint src_w, src_h; gdouble ratio; GdkPixbuf *dest; GError *error = NULL; gint size = MIN (dest_width, dest_height); g_return_val_if_fail (source != NULL, NULL); g_return_val_if_fail (icon_theme == NULL || GTK_IS_ICON_THEME (icon_theme), NULL); g_return_val_if_fail (dest_width > 0, NULL); g_return_val_if_fail (dest_height > 0, NULL); if (G_UNLIKELY (g_path_is_absolute (source))) { pixbuf = gdk_pixbuf_new_from_file (source, &error); if (G_UNLIKELY (pixbuf == NULL)) { g_message ("Failed to load image \"%s\": %s", source, error->message); g_error_free (error); } } else { if (G_UNLIKELY (icon_theme == NULL)) icon_theme = gtk_icon_theme_get_default (); /* try to load from the icon theme */ pixbuf = gtk_icon_theme_load_icon (icon_theme, source, size, 0, NULL); if (G_UNLIKELY (pixbuf == NULL)) { /* try to lookup names like application.png in the theme */ p = strrchr (source, '.'); if (p != NULL) { name = g_strndup (source, p - source); pixbuf = gtk_icon_theme_load_icon (icon_theme, name, size, 0, NULL); g_free (name); } /* maybe they point to a file in the pixbufs folder */ if (G_UNLIKELY (pixbuf == NULL)) { filename = g_build_filename ("pixmaps", source, NULL); name = xfce_resource_lookup (XFCE_RESOURCE_DATA, filename); g_free (filename); if (name != NULL) { pixbuf = gdk_pixbuf_new_from_file (name, NULL); g_free (name); } } } } if (G_UNLIKELY (pixbuf == NULL)) { if (G_UNLIKELY (icon_theme == NULL)) icon_theme = gtk_icon_theme_get_default (); /* bit ugly as a fallback, but in most cases better then no icon */ pixbuf = gtk_icon_theme_load_icon (icon_theme, GTK_STOCK_MISSING_IMAGE, size, GTK_ICON_LOOKUP_USE_BUILTIN, NULL); } /* scale the pixbug if required */ if (G_LIKELY (pixbuf != NULL)) { src_w = gdk_pixbuf_get_width (pixbuf); src_h = gdk_pixbuf_get_height (pixbuf); if (src_w > dest_width || src_h > dest_height) { /* calculate the new dimensions */ ratio = MIN ((gdouble) dest_width / (gdouble) src_w, (gdouble) dest_height / (gdouble) src_h); dest_width = rint (src_w * ratio); dest_height = rint (src_h * ratio); dest = gdk_pixbuf_scale_simple (pixbuf, MAX (dest_width, 1), MAX (dest_height, 1), GDK_INTERP_BILINEAR); g_object_unref (G_OBJECT (pixbuf)); pixbuf = dest; } } return pixbuf; }
static void verve_history_cache_load (void) { const gchar *basename = verve_history_cache_get_filename (); /* Search for cache file */ gchar *filename = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, basename); /* Only read cache if file exists */ if (G_LIKELY (filename != NULL)) { GError *error = NULL; GIOChannel *handle; /* Open file input stream */ handle = g_io_channel_new_file (filename, "r", &error); /* Instantly destroy error messages - just ignore them */ if (G_UNLIKELY (error != NULL)) g_error_free (error); /* Only read contents if stream could be opened */ if (G_LIKELY (handle != NULL)) { GIOStatus status; gchar *line; gsize length; /* Read first line */ status = g_io_channel_read_line (handle, &line, &length, NULL, &error); /* Read lines until EOF is reached or an error occurs */ while (status != G_IO_STATUS_EOF && error == NULL) { /* Get current line, remove leading and trailing whitespace */ GString *strline = g_string_new (g_strstrip (line)); /* Only add non-empty lines to the history */ if (G_LIKELY (strline->len > 0)) verve_history_append (strline->str); /* Free string data */ g_free (line); g_string_free (strline, FALSE); /* Read next line */ status = g_io_channel_read_line (handle, &line, &length, NULL, &error); } /* Free error message */ if (G_UNLIKELY (error != NULL)) g_error_free (error); /* Close file handle */ g_io_channel_shutdown (handle, TRUE, &error); /* Again: Free error message */ if (G_UNLIKELY (error != NULL)) g_error_free (error); /* Destroy stream object */ g_io_channel_unref (handle); } } /* Free filename string */ g_free (filename); }
static GIcon * xfdesktop_load_icon_from_desktop_file(XfdesktopRegularFileIcon *regular_icon) { gchar *contents, *icon_name; gsize length; GIcon *gicon = NULL; gchar *p; GKeyFile *key_file; /* try to load the file into memory */ if(!g_file_load_contents(regular_icon->priv->file, NULL, &contents, &length, NULL, NULL)) return NULL; /* allocate a new key file */ key_file = g_key_file_new(); /* try to parse the key file from the contents of the file */ if(!g_key_file_load_from_data(key_file, contents, length, 0, NULL)) { g_free(contents); return NULL; } /* try to determine the custom icon name */ icon_name = g_key_file_get_string(key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, NULL); /* No icon name in the desktop file */ if(icon_name == NULL) { /* free key file and in-memory data */ g_key_file_free(key_file); g_free(contents); return NULL; } /* icon_name is an absolute path, create it as a file icon */ if(g_file_test(icon_name, G_FILE_TEST_IS_REGULAR)) { gicon = g_file_icon_new(g_file_new_for_path(icon_name)); } /* check if the icon theme includes the icon name as-is */ if(gicon == NULL) { if(gtk_icon_theme_has_icon(gtk_icon_theme_get_default(), icon_name)) { /* load it */ gicon = g_themed_icon_new(icon_name); } } /* drop any suffix (e.g. '.png') from themed icons and try to laod that */ if(gicon == NULL) { gchar *tmp_name = NULL; p = strrchr(icon_name, '.'); if(p != NULL) tmp_name = g_strndup(icon_name, p - icon_name); /* check if the icon theme includes the icon name */ if(tmp_name && gtk_icon_theme_has_icon(gtk_icon_theme_get_default(), tmp_name)) { /* load it */ gicon = g_themed_icon_new(tmp_name); } g_free(tmp_name); } /* maybe it points to a file in the pixmaps folder */ if(gicon == NULL) { gchar *filename = g_build_filename("pixmaps", icon_name, NULL); gchar *tmp_name = NULL; if(filename) tmp_name = xfce_resource_lookup(XFCE_RESOURCE_DATA, filename); if(tmp_name) gicon = g_file_icon_new(g_file_new_for_path(tmp_name)); g_free(filename); g_free(tmp_name); } /* free key file and in-memory data */ g_key_file_free(key_file); g_free(contents); g_free(icon_name); return gicon; }
gint main (gint argc, gchar **argv) { GError *error = NULL; GtkWidget *dialog; GtkWidget *button; gint result; gint retval = EXIT_SUCCESS; gint default_response = GTK_RESPONSE_CANCEL; XfconfChannel *channel; gint configver; gchar *filename_46; gchar *filename_default; gboolean migrate_vendor_default; /* set translation domain */ xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8"); #ifndef NDEBUG /* terminate the program on warnings and critical messages */ g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); #endif gtk_init (&argc, &argv); if (!xfconf_init (&error)) { g_critical ("Failed to initialize Xfconf: %s", error->message); g_error_free (error); return EXIT_FAILURE; } channel = xfconf_channel_get (XFCE_PANEL_CHANNEL_NAME); if (!xfconf_channel_has_property (channel, "/panels")) { /* lookup the old 4.6 config file */ filename_46 = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, XFCE_46_CONFIG); /* lookup the default configuration */ xfce_resource_push_path (XFCE_RESOURCE_CONFIG, XDGCONFIGDIR); filename_default = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, DEFAULT_CONFIG_FILENAME); xfce_resource_pop_path (XFCE_RESOURCE_CONFIG); if (filename_46 == NULL && filename_default == NULL) { g_warning ("No default or old configuration found"); return EXIT_FAILURE; } /* if the default configuration does not match with the file found * by the resource lookup, migrate it without asking */ migrate_vendor_default = (g_strcmp0 (DEFAULT_CONFIG_PATH, filename_default) != 0); /* check if we auto-migrate the default configuration */ if (g_getenv ("XFCE_PANEL_MIGRATE_DEFAULT") != NULL || migrate_vendor_default) { if (filename_46 != NULL) g_message ("Tried to auto-migrate, but old configuration found"); else if (filename_default == NULL) g_message ("Tried to auto-migrate, but no default configuration found"); else goto migrate_default; } /* create question dialog */ dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, _("Welcome to the first start of the panel")); gtk_window_set_title (GTK_WINDOW (dialog), _("Panel")); gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_PREFERENCES); gtk_window_stick (GTK_WINDOW (dialog)); gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE); if (filename_46 != NULL) { gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s\n%s", _("Because the panel moved to a new system for storing the " "settings, it has to load a fresh initial configuration."), _("Choose below which setup you want for the first startup.")); button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Migrate old config"), GTK_RESPONSE_OK); gtk_widget_set_tooltip_text (button, _("Migrate the old 4.6 configuration to Xfconf")); default_response = GTK_RESPONSE_OK; } else { gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("Choose below which setup you want for the first startup.")); } if (filename_default != NULL) { button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Use default config"), GTK_RESPONSE_YES); gtk_widget_set_tooltip_text (button, _("Load the default configuration")); if (default_response == GTK_RESPONSE_CANCEL) default_response = GTK_RESPONSE_YES; } button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("One empty panel"), GTK_RESPONSE_CANCEL); gtk_widget_set_tooltip_text (button, _("Start with one empty panel")); gtk_dialog_set_default_response (GTK_DIALOG (dialog), default_response); result = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); if (result == GTK_RESPONSE_OK && filename_46 != NULL) { /* restore 4.6 config */ if (!migrate_46 (filename_46, channel, &error)) { xfce_dialog_show_error (NULL, error, _("Failed to migrate the old panel configuration")); g_error_free (error); retval = EXIT_FAILURE; } } else if (result == GTK_RESPONSE_YES && filename_default != NULL) { migrate_default: /* apply default config */ if (!migrate_default (filename_default, &error)) { xfce_dialog_show_error (NULL, error, _("Failed to load the default configuration")); g_error_free (error); retval = EXIT_FAILURE; } } g_free (filename_46); g_free (filename_default); } configver = xfconf_channel_get_int (channel, "/configver", -1); if (configver < XFCE4_PANEL_CONFIG_VERSION) { g_message (_("Panel config needs migration...")); if (!migrate_config (channel, configver, &error)) { xfce_dialog_show_error (NULL, error, _("Failed to migrate the existing configuration")); g_error_free (error); retval = EXIT_FAILURE; } else { g_message (_("Panel configuration has been updated.")); } /* migration complete, set new version */ xfconf_channel_set_int (channel, "/configver", XFCE4_PANEL_CONFIG_VERSION); } xfconf_shutdown (); return retval; }