get rid of theme-common.[ch] for good

This commit is contained in:
Jonathan Blandford 2002-11-01 23:16:35 +00:00
parent 9405d72d2f
commit ff045c00cd
7 changed files with 11 additions and 277 deletions

View file

@ -17,7 +17,6 @@ libcommon_la_SOURCES = \
gconf-property-editor.c gconf-property-editor.h \
gconf-property-editor-marshal.c gconf-property-editor-marshal.h \
file-transfer-dialog.c file-transfer-dialog.h \
theme-common.c theme-common.h \
gnome-theme-info.c gnome-theme-info.h \
wm-common.c wm-common.h

View file

@ -1,240 +0,0 @@
#include <config.h>
#include <gnome.h>
#include <glade/glade.h>
#include <gconf/gconf-client.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <libgnomevfs/gnome-vfs-ops.h>
#include <glib-object.h>
#include "theme-common.h"
static void theme_info_free (ThemeInfo *info);
typedef struct _ThemeCallbackData
{
GFunc func;
gpointer data;
} ThemeCallbackData;
GList *theme_list = NULL;
GList *callbacks = NULL;
const gchar *gtk2_suffix = "gtk-2.0";
const gchar *key_suffix = "gtk-2.0-key";
const gchar *metacity_suffix = "metacity-1";
static ThemeInfo *
find_theme_info_by_dir (const gchar *theme_dir)
{
GList *list;
for (list = theme_list; list; list = list->next)
{
ThemeInfo *info = list->data;
if (! strcmp (info->path, theme_dir))
return info;
}
return NULL;
}
static void
update_theme_dir (const gchar *theme_dir)
{
ThemeInfo *info = NULL;
gboolean changed = FALSE;
gboolean has_gtk = FALSE;
gboolean has_keybinding = FALSE;
gboolean has_metacity = FALSE;
gchar *tmp;
tmp = g_build_filename (theme_dir, gtk2_suffix, NULL);
if (g_file_test (tmp, G_FILE_TEST_IS_DIR))
{
has_gtk = TRUE;
}
g_free (tmp);
tmp = g_build_filename (theme_dir, key_suffix, NULL);
if (g_file_test (tmp, G_FILE_TEST_IS_DIR))
{
has_keybinding = TRUE;
}
g_free (tmp);
tmp = g_build_filename (theme_dir, metacity_suffix, NULL);
if (g_file_test (tmp, G_FILE_TEST_IS_DIR))
{
has_metacity = TRUE;
}
g_free (tmp);
info = find_theme_info_by_dir (theme_dir);
if (info)
{
if (!has_gtk && ! has_keybinding && ! has_metacity)
{
theme_list = g_list_remove (theme_list, info);
theme_info_free (info);
changed = TRUE;
}
else if ((info->has_keybinding != has_keybinding) ||
(info->has_gtk != has_gtk) ||
(info->has_metacity != has_metacity))
{
info->has_keybinding = has_keybinding;
info->has_gtk = has_gtk;
info->has_metacity = has_metacity;
changed = TRUE;
}
}
else
{
if (has_gtk || has_keybinding || has_metacity)
{
info = g_new0 (ThemeInfo, 1);
info->path = g_strdup (theme_dir);
info->name = g_strdup (strrchr (theme_dir, '/') + 1);
info->has_gtk = has_gtk;
info->has_keybinding = has_keybinding;
info->has_metacity = has_metacity;
theme_list = g_list_prepend (theme_list, info);
changed = TRUE;
}
}
if (changed)
{
GList *list;
for (list = callbacks; list; list = list->next)
{
ThemeCallbackData *callback_data = list->data;
(* callback_data->func) ((gpointer)theme_dir, callback_data->data);
}
}
}
static void
top_theme_dir_changed_callback (GnomeVFSMonitorHandle *handle,
const gchar *monitor_uri,
const gchar *info_uri,
GnomeVFSMonitorEventType event_type,
gpointer user_data)
{
switch (event_type)
{
case GNOME_VFS_MONITOR_EVENT_CHANGED:
case GNOME_VFS_MONITOR_EVENT_CREATED:
case GNOME_VFS_MONITOR_EVENT_DELETED:
if (!strncmp (info_uri, "file://", strlen ("file://")))
update_theme_dir (info_uri + strlen ("file://"));
else
update_theme_dir (info_uri);
break;
default:
break;
}
}
static void
themes_common_list_add_dir (const char *dirname)
{
GnomeVFSMonitorHandle *handle = NULL;
DIR *dir;
struct dirent *de;
g_return_if_fail (dirname != NULL);
dir = opendir (dirname);
gnome_vfs_monitor_add (&handle,
dirname,
GNOME_VFS_MONITOR_DIRECTORY,
top_theme_dir_changed_callback,
NULL);
if (!dir)
return;
while ((de = readdir (dir)))
{
char *tmp;
if (de->d_name[0] == '.')
continue;
tmp = g_build_filename (dirname, de->d_name, NULL);
update_theme_dir (tmp);
g_free (tmp);
}
closedir (dir);
}
void
theme_common_init (void)
{
static gboolean initted = FALSE;
gchar *dir;
GnomeVFSURI *uri;
if (initted)
return;
initted = TRUE;
dir = g_build_filename (g_get_home_dir (), ".themes", NULL);
/* Make sure it exists */
uri = gnome_vfs_uri_new (dir);
if (!gnome_vfs_uri_exists (uri))
gnome_vfs_make_directory_for_uri (uri, 0775);
gnome_vfs_uri_unref (uri);
themes_common_list_add_dir (dir);
g_free (dir);
dir = gtk_rc_get_theme_dir ();
themes_common_list_add_dir (dir);
g_free (dir);
}
GList *
theme_common_get_list (void)
{
theme_common_init ();
return theme_list;
}
void
theme_common_register_theme_change (GFunc func,
gpointer data)
{
ThemeCallbackData *callback_data;
callback_data = g_new0 (ThemeCallbackData, 1);
callback_data->func = func;
callback_data->data = data;
callbacks = g_list_prepend (callbacks, callback_data);
}
static void
theme_info_free (ThemeInfo *info)
{
g_free (info->path);
g_free (info->name);
g_free (info);
}

View file

@ -1,25 +0,0 @@
#ifndef THEME_COMMON_H
#define THEME_COMMON_H
#include <glib.h>
typedef struct _ThemeInfo ThemeInfo;
struct _ThemeInfo
{
gchar *path;
gchar *name;
guint has_gtk : 1;
guint has_keybinding : 1;
guint has_metacity : 1;
guint user_writable : 1;
};
void theme_common_init (void);
GList *theme_common_get_list (void);
void theme_common_register_theme_change (GFunc func,
gpointer data);
#endif /* THEME_COMMON_H */

View file

@ -15,7 +15,6 @@
#include <X11/Xft/Xft.h>
#endif /* HAVE_XFT2 */
#include "theme-common.h"
#include "capplet-util.h"
#include "activate-settings-daemon.h"
#include "gconf-property-editor.h"

View file

@ -1,3 +1,8 @@
Fri Nov 1 17:46:06 2002 Jonathan Blandford <jrb@gnome.org>
* gnome-keybinding-properties.c: move to use gnome-theme-info
instead of theme-common.
2002-10-21 Jody Goldberg <jody@gnome.org>
* Release 2.1.1

View file

@ -11,7 +11,7 @@
#include <glade/glade.h>
#include <X11/Xatom.h>
#include "theme-common.h"
#include "gnome-theme-info.h"
#include "wm-common.h"
#include "capplet-util.h"
#include "eggcellrendererkeys.h"
@ -591,13 +591,13 @@ theme_changed_func (gpointer uri,
GList *list;
client = gconf_client_get_default ();
key_theme_list = theme_common_get_list ();
key_theme_list = gnome_theme_info_find_by_type (GNOME_THEME_GTK_2_KEYBINDING);
omenu = WID ("key_theme_omenu");
menu = gtk_menu_new ();
for (list = key_theme_list; list; list = list->next)
{
ThemeInfo *info = list->data;
GnomeThemeInfo *info = list->data;
if (! info->has_keybinding)
continue;
@ -699,11 +699,11 @@ setup_dialog (GladeXML *dialog)
client = gconf_client_get_default ();
key_theme_list = theme_common_get_list ();
key_theme_list = gnome_theme_info_find_by_type (GNOME_THEME_GTK_2_KEYBINDING);
for (list = key_theme_list; list; list = list->next)
{
ThemeInfo *info = list->data;
GnomeThemeInfo *info = list->data;
if (info->has_keybinding)
{
found_keys = TRUE;
@ -725,7 +725,7 @@ setup_dialog (GladeXML *dialog)
else
{
theme_changed_func (NULL, dialog);
theme_common_register_theme_change ((GFunc) theme_changed_func, dialog);
gnome_theme_info_register_theme_change ((GFunc) theme_changed_func, dialog);
gconf_client_add_dir (client, "/desktop/gnome/interface", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
gconf_client_notify_add (client,
KEY_THEME_KEY,

View file

@ -21,10 +21,6 @@
#include "file-transfer-dialog.h"
#include "gnome-theme-installer.h"
/* FIXME: This shouldn't be hardcoded
*/
#define METACITY_THEME_LOCATION "/usr/share/themes"
#define GTK_THEME_KEY "/desktop/gnome/interface/gtk_theme"
#define WINDOW_THEME_KEY "/desktop/gnome/applications/window_manager/theme"
#define ICON_THEME_KEY "/desktop/gnome/interface/icon_theme"