Exemple #1
0
static void
load_themes (DialogData *data)
{
	GFile        *style_dir;
	GFile        *data_dir;
	char         *default_theme;
	GtkTreeModel *model;
	GtkTreeIter   iter;

	/* local themes */

	style_dir = gth_user_dir_get_file_for_read (GTH_DIR_DATA, PIX_DIR, "albumthemes", NULL);
	add_themes_from_dir (data, style_dir);
	g_object_unref (style_dir);

	/* system themes */

	data_dir = g_file_new_for_path (WEBALBUM_DATADIR);
	style_dir = _g_file_get_child (data_dir, "albumthemes", NULL);
	add_themes_from_dir (data, style_dir);
	g_object_unref (style_dir);
	g_object_unref (data_dir);

	/**/

	gtk_widget_set_size_request (GET_WIDGET ("theme_iconview"), (150 * 3), 140);
	gtk_widget_realize (GET_WIDGET ("theme_iconview"));

	default_theme = g_settings_get_string (data->settings, PREF_WEBALBUMS_THEME);

	model = GTK_TREE_MODEL (GET_WIDGET ("theme_liststore"));
	if (gtk_tree_model_get_iter_first (model, &iter)) {
		do {
			char *name;

			gtk_tree_model_get(model, &iter, THEME_COLUMN_ID, &name, -1);

			if (g_strcmp0 (name, default_theme) == 0) {
				GtkTreePath *path;

				path = gtk_tree_model_get_path (model, &iter);
				gtk_icon_view_select_path (GTK_ICON_VIEW (GET_WIDGET ("theme_iconview")), path);
				gtk_icon_view_scroll_to_path (GTK_ICON_VIEW (GET_WIDGET ("theme_iconview")), path, TRUE, 0.5, 0.5);

				gtk_tree_path_free (path);
				g_free (name);
				break;
			}

			g_free (name);
		}
		while (gtk_tree_model_iter_next (model, &iter));
	}

	g_free (default_theme);
}
Exemple #2
0
static void
get_theme_names(GPtrArray* names)
{
	void add_themes_from_dir(GPtrArray* names, const char* dir)
	{
		if (access(dir, F_OK) != 0)	return;

		GPtrArray* list = list_dir((guchar*)dir);
		g_return_if_fail(list != NULL);

		int i;
		for (i = 0; i < list->len; i++){
			char* index_path = g_build_filename(dir, list->pdata[i], "index.theme", NULL);
			
			if (access(index_path, F_OK) == 0){
				g_ptr_array_add(names, list->pdata[i]);
			}
			else g_free(list->pdata[i]);

			g_free(index_path);
		}

		g_ptr_array_free(list, TRUE);
	}

	gint n_dirs = 0;
	gchar** theme_dirs = NULL;
	gtk_icon_theme_get_search_path(icon_theme, &theme_dirs, &n_dirs); // dir list is derived from XDG_DATA_DIRS
	int i; for (i = 0; i < n_dirs; i++) add_themes_from_dir(names, theme_dirs[i]);
	g_strfreev(theme_dirs);

	g_ptr_array_sort(names, strcmp2);
}