2002-08-19 19:14:21 +00:00
|
|
|
/* -*- mode: c; style: linux -*- */
|
|
|
|
|
|
|
|
/* gnome-settings-gtk1theme.c
|
|
|
|
*
|
|
|
|
* Copyright © 2002 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Written by Owen Taylor <otaylor@redhat.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2007-06-06 11:51:40 +00:00
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
#include "gnome-settings-module.h"
|
|
|
|
#include "utils.h"
|
2002-08-19 19:14:21 +00:00
|
|
|
|
|
|
|
#define GTK_THEME_KEY "/desktop/gnome/interface/gtk_theme"
|
|
|
|
|
2007-06-06 11:51:40 +00:00
|
|
|
typedef struct {
|
|
|
|
GnomeSettingsModule parent;
|
|
|
|
} GnomeSettingsModuleGtk1;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GnomeSettingsModuleClass parent_class;
|
|
|
|
} GnomeSettingsModuleGtk1Class;
|
|
|
|
|
|
|
|
static GnomeSettingsModuleRunlevel gnome_settings_module_gtk1_get_runlevel (GnomeSettingsModule *module);
|
|
|
|
static gboolean gnome_settings_module_gtk1_initialize (GnomeSettingsModule *module, GConfClient *config_client);
|
|
|
|
static gboolean gnome_settings_module_gtk1_start (GnomeSettingsModule *module);
|
|
|
|
static gboolean gnome_settings_module_gtk1_stop (GnomeSettingsModule *module);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gnome_settings_module_gtk1_class_init (GnomeSettingsModuleGtk1Class *klass)
|
|
|
|
{
|
|
|
|
GnomeSettingsModuleClass *module_class;
|
|
|
|
|
|
|
|
module_class = (GnomeSettingsModuleClass *) klass;
|
|
|
|
module_class->get_runlevel = gnome_settings_module_gtk1_get_runlevel;
|
|
|
|
module_class->initialize = gnome_settings_module_gtk1_initialize;
|
|
|
|
module_class->start = gnome_settings_module_gtk1_start;
|
|
|
|
module_class->stop = gnome_settings_module_gtk1_stop;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gnome_settings_module_gtk1_init (GnomeSettingsModuleGtk1 *module)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GType
|
|
|
|
gnome_settings_module_gtk1_get_type (void)
|
|
|
|
{
|
|
|
|
static GType module_type = 0;
|
2007-07-01 15:56:19 +00:00
|
|
|
|
2007-06-06 11:51:40 +00:00
|
|
|
if (!module_type) {
|
2007-07-01 15:56:19 +00:00
|
|
|
const GTypeInfo module_info = {
|
2007-06-06 11:51:40 +00:00
|
|
|
sizeof (GnomeSettingsModuleGtk1Class),
|
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
(GClassInitFunc) gnome_settings_module_gtk1_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GnomeSettingsModuleGtk1),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gnome_settings_module_gtk1_init,
|
|
|
|
};
|
2007-07-01 15:56:19 +00:00
|
|
|
|
2007-06-06 11:51:40 +00:00
|
|
|
module_type = g_type_register_static (GNOME_SETTINGS_TYPE_MODULE,
|
|
|
|
"GnomeSettingsModuleGtk1",
|
|
|
|
&module_info, 0);
|
|
|
|
}
|
2007-07-01 15:56:19 +00:00
|
|
|
|
2007-06-06 11:51:40 +00:00
|
|
|
return module_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GnomeSettingsModuleRunlevel
|
|
|
|
gnome_settings_module_gtk1_get_runlevel (GnomeSettingsModule *module)
|
|
|
|
{
|
|
|
|
return GNOME_SETTINGS_MODULE_RUNLEVEL_GNOME_SETTINGS;
|
|
|
|
}
|
|
|
|
|
2002-08-19 19:14:21 +00:00
|
|
|
/* Given the theme filename, return the needed contents for the RC file
|
|
|
|
* in the user's home directory
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
make_contents (const char *filename)
|
|
|
|
{
|
|
|
|
GString *result = g_string_new (NULL);
|
|
|
|
|
|
|
|
g_string_append (result,
|
|
|
|
"# Autowritten by gnome-settings-daemon. Do not edit\n"
|
|
|
|
"\n");
|
|
|
|
if (filename)
|
|
|
|
g_string_append_printf (result,
|
|
|
|
"include \"%s\"\n"
|
|
|
|
"\n",
|
|
|
|
filename);
|
2007-07-01 15:56:19 +00:00
|
|
|
g_string_append_printf (result,
|
2002-08-19 19:14:21 +00:00
|
|
|
"include \"%s/.gtkrc.mine\"\n",
|
|
|
|
g_get_home_dir ());
|
|
|
|
|
|
|
|
return g_string_free (result, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Writes @contents to @rc_filename atomically (using rename); returns
|
|
|
|
* %TRUE on sucess
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
write_contents (const char *rc_filename,
|
|
|
|
const char *contents)
|
|
|
|
{
|
|
|
|
char *tmp_filename = g_strconcat (rc_filename, ".new", NULL);
|
|
|
|
GIOChannel *channel;
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
channel = g_io_channel_new_file (tmp_filename, "w", &err);
|
|
|
|
if (!channel) {
|
|
|
|
g_warning ("Cannot open %s: %s", tmp_filename, err->message);
|
|
|
|
goto bail2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_io_channel_write_chars (channel, contents, -1, NULL, &err) != G_IO_STATUS_NORMAL) {
|
|
|
|
g_warning ("Cannot open %s: %s", tmp_filename, err->message);
|
|
|
|
goto bail0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_io_channel_flush (channel, &err) != G_IO_STATUS_NORMAL) {
|
|
|
|
g_warning ("Error flushing %s: %s", tmp_filename, err->message);
|
|
|
|
goto bail0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_io_channel_shutdown (channel, TRUE, &err) != G_IO_STATUS_NORMAL) {
|
|
|
|
g_warning ("Error closing %s: %s", tmp_filename, err->message);
|
|
|
|
goto bail1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rename (tmp_filename, rc_filename) < 0) {
|
|
|
|
g_warning ("Cannot move %s to %s: %s", tmp_filename, rc_filename, g_strerror (errno));
|
|
|
|
goto bail1;
|
2007-07-01 15:56:19 +00:00
|
|
|
|
2002-08-19 19:14:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (tmp_filename);
|
2007-07-01 15:56:19 +00:00
|
|
|
|
2002-08-19 19:14:21 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
bail0:
|
|
|
|
g_io_channel_shutdown (channel, FALSE, NULL);
|
|
|
|
bail1:
|
|
|
|
unlink (tmp_filename);
|
|
|
|
bail2:
|
|
|
|
g_clear_error (&err);
|
|
|
|
g_free (tmp_filename);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send a client message telling GTK+-1.2 apps to reread their RC files
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
send_change_message (void)
|
|
|
|
{
|
|
|
|
GdkEventClient sev;
|
|
|
|
int i;
|
2007-07-01 15:56:19 +00:00
|
|
|
|
2002-08-19 19:14:21 +00:00
|
|
|
for(i = 0; i < 5; i++)
|
|
|
|
sev.data.l[i] = 0;
|
2007-07-01 15:56:19 +00:00
|
|
|
|
2002-08-19 19:14:21 +00:00
|
|
|
sev.data_format = 32;
|
|
|
|
sev.message_type = gdk_atom_intern("_GTK_READ_RCFILES", FALSE);
|
2007-07-01 15:56:19 +00:00
|
|
|
|
2002-08-19 19:14:21 +00:00
|
|
|
gdk_event_send_clientmessage_toall ((GdkEvent *) &sev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See if a theme called @theme exists in @base_dir. Takes ownership of @base_dir
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
check_filename (char *base_dir,
|
|
|
|
const char *theme)
|
|
|
|
{
|
|
|
|
char *theme_filename = g_build_filename (base_dir, theme, "gtk", "gtkrc", NULL);
|
2007-07-01 15:56:19 +00:00
|
|
|
|
2002-08-19 19:14:21 +00:00
|
|
|
if (!g_file_test (theme_filename, G_FILE_TEST_EXISTS)) {
|
|
|
|
g_free (theme_filename);
|
|
|
|
theme_filename = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (base_dir);
|
|
|
|
|
|
|
|
return theme_filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
apply_settings (void)
|
|
|
|
{
|
return NULL when there is an error, not exit(), so that we do proper
2007-04-02 Rodrigo Moya <rodrigo@gnome-db.org>
* gnome-settings-daemon.c (gnome_settings_daemon_new): return NULL
when there is an error, not exit(), so that we do proper cleanup.
Remove code to register GConf callbacks, that is done in utils.c.
(gnome_settings_daemon_get_conf_client,
gnome_settings_daemon_register_callback,
gnome_settings_daemon_spawn_with_input,
gnome_settings_daemon_get_invisible,
gnome_settings_daemon_delayed_show_dialog): removed from the
GnomeSettingsDaemon interface.
* utils.c (gnome_settings_get_config_client,
gnome_settings_get_invisible,
gnome_settings_register_config_callback,
gnome_settings_spawn_with_input,
gnome_settings_delayed_show_dialog): moved from GnomeSettingsDaemon
interface.
* factory.c (main): check return value from gnome_settings_daemon().
* *.c: adapted to changes in function names.
* Makefile.am: put source files in alphabetical order.
svn path=/trunk/; revision=7434
2007-04-02 15:27:35 +00:00
|
|
|
GConfClient *client = gnome_settings_get_config_client ();
|
2002-08-19 19:14:21 +00:00
|
|
|
gchar *current_theme;
|
|
|
|
gchar *theme_filename;
|
|
|
|
gchar *rc_filename;
|
|
|
|
gchar *current_contents;
|
2004-02-06 10:53:58 +00:00
|
|
|
gsize current_length;
|
2002-08-19 19:14:21 +00:00
|
|
|
gchar *new_contents;
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
current_theme = gconf_client_get_string (client, GTK_THEME_KEY, NULL);
|
|
|
|
if (!current_theme)
|
|
|
|
current_theme = g_strdup ("Default");
|
|
|
|
|
|
|
|
/* Translate Default into Raleigh, since it's a better
|
|
|
|
* match than the default gtk1 theme.
|
|
|
|
*/
|
|
|
|
if (strcmp (current_theme, "Default") == 0) {
|
|
|
|
g_free (current_theme);
|
|
|
|
current_theme = g_strdup ("Raleigh");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now look for a gtk1 theme with the name
|
|
|
|
*/
|
|
|
|
theme_filename = check_filename (g_build_filename (g_get_home_dir (),".themes", NULL),
|
|
|
|
current_theme);
|
|
|
|
|
|
|
|
if (!theme_filename) {
|
|
|
|
theme_filename = check_filename (g_build_filename (DATADIR, "themes", NULL),
|
|
|
|
current_theme);
|
|
|
|
}
|
2004-10-21 19:41:26 +00:00
|
|
|
g_free (current_theme);
|
2002-08-19 19:14:21 +00:00
|
|
|
|
|
|
|
/* If we don't find a match, use Raleigh
|
|
|
|
*/
|
|
|
|
if (!theme_filename) {
|
|
|
|
theme_filename = check_filename (g_build_filename (DATADIR, "themes", NULL),
|
|
|
|
"Raleigh");
|
|
|
|
}
|
|
|
|
|
|
|
|
rc_filename = g_build_filename (g_get_home_dir(), ".gtkrc-1.2-gnome2", NULL);
|
2007-07-01 15:56:19 +00:00
|
|
|
|
2002-08-19 19:14:21 +00:00
|
|
|
if (!g_file_get_contents (rc_filename, ¤t_contents, ¤t_length, &err) &&
|
|
|
|
!g_error_matches (err, G_FILE_ERROR, G_FILE_ERROR_NOENT)) {
|
|
|
|
g_warning ("Can't get contents of %s: %s", rc_filename, err->message);
|
|
|
|
g_clear_error (&err);
|
|
|
|
}
|
2007-07-01 15:56:19 +00:00
|
|
|
|
2002-08-19 19:14:21 +00:00
|
|
|
new_contents = make_contents (theme_filename);
|
2004-10-21 19:41:26 +00:00
|
|
|
g_free (theme_filename);
|
2007-07-01 15:56:19 +00:00
|
|
|
|
2002-08-19 19:14:21 +00:00
|
|
|
if (!current_contents ||
|
|
|
|
current_length != strlen (new_contents) ||
|
|
|
|
memcmp (current_contents, new_contents, current_length) != 0) {
|
|
|
|
if (write_contents (rc_filename, new_contents))
|
|
|
|
send_change_message ();
|
|
|
|
}
|
declare a global GConfClient. (main): unref the global GConfClient.
2005-10-16 Rodrigo Moya <rodrigo@novell.com>
* factory.c: declare a global GConfClient.
(main): unref the global GConfClient.
* gnome-settings-daemon.[ch] (gnome_settings_daemon_get_conf_client):
new function to use the same GConfClient everywhere.
(gnome_settings_daemon_new): use the global GConfClient.
* gnome-settings-accessibility-keyboard.c (set_server_from_gconf,
ax_response_callback, set_gconf_from_server):
* gnome-settings-gtk1theme.c (apply_settings):
* gnome-settings-keybindings.c (bindings_get_entry):
* gnome-settings-keyboard.c (numlock_get_gconf_state,
numlock_set_gconf_state, apply_settings):
* gnome-settings-keyboard-xkb.c (apply_xkb_settings,
gnome_settings_keyboard_xkb_sysconfig_changed_response,
gnome_settings_keyboard_xkb_analyze_sysconfig,
gnome_settings_chk_file_list):
* gnome-settings-screensaver.c (key_toggled_cb,
really_start_screensaver):
* gnome-settings-sound.c (apply_settings):
* gnome-settings-xmodmap.c (check_button_callback,
gnome_settings_load_modmap_files, remove_button_clicked_callback,
load_button_clicked_callback, gnome_settings_modmap_dialog_call):
* gnome-settings-xsettings.c (xft_callback):
use the global GConfClient.
* gnome-settings-keyboard-xkb.c (gnome_settings_keyboard_xkb_load):
don't get another GConfClient when we're getting one passed!
2005-10-17 14:53:19 +00:00
|
|
|
|
2002-08-19 19:14:21 +00:00
|
|
|
g_free (new_contents);
|
|
|
|
g_free (current_contents);
|
|
|
|
g_free (rc_filename);
|
|
|
|
}
|
|
|
|
|
2007-06-06 11:51:40 +00:00
|
|
|
static gboolean
|
|
|
|
gnome_settings_module_gtk1_initialize (GnomeSettingsModule *module, GConfClient *config_client)
|
2002-08-19 19:14:21 +00:00
|
|
|
{
|
return NULL when there is an error, not exit(), so that we do proper
2007-04-02 Rodrigo Moya <rodrigo@gnome-db.org>
* gnome-settings-daemon.c (gnome_settings_daemon_new): return NULL
when there is an error, not exit(), so that we do proper cleanup.
Remove code to register GConf callbacks, that is done in utils.c.
(gnome_settings_daemon_get_conf_client,
gnome_settings_daemon_register_callback,
gnome_settings_daemon_spawn_with_input,
gnome_settings_daemon_get_invisible,
gnome_settings_daemon_delayed_show_dialog): removed from the
GnomeSettingsDaemon interface.
* utils.c (gnome_settings_get_config_client,
gnome_settings_get_invisible,
gnome_settings_register_config_callback,
gnome_settings_spawn_with_input,
gnome_settings_delayed_show_dialog): moved from GnomeSettingsDaemon
interface.
* factory.c (main): check return value from gnome_settings_daemon().
* *.c: adapted to changes in function names.
* Makefile.am: put source files in alphabetical order.
svn path=/trunk/; revision=7434
2007-04-02 15:27:35 +00:00
|
|
|
gnome_settings_register_config_callback (GTK_THEME_KEY,
|
|
|
|
(GnomeSettingsConfigCallback) apply_settings);
|
2007-06-06 11:51:40 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2002-08-19 19:14:21 +00:00
|
|
|
}
|
|
|
|
|
2007-06-06 11:51:40 +00:00
|
|
|
static gboolean
|
|
|
|
gnome_settings_module_gtk1_start (GnomeSettingsModule *module)
|
2002-08-19 19:14:21 +00:00
|
|
|
{
|
|
|
|
apply_settings ();
|
2007-06-06 11:51:40 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gnome_settings_module_gtk1_stop (GnomeSettingsModule *module)
|
|
|
|
{
|
|
|
|
return TRUE;
|
2002-08-19 19:14:21 +00:00
|
|
|
}
|