2002-05-16 23:09:02 +00:00
|
|
|
/*
|
|
|
|
* gnome-settings-default-editor.h: sync default editor changes to mime database
|
|
|
|
*
|
|
|
|
* Copyright 2002 Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Author: jacob berkman <jacob@ximian.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WARNING: This is a hack.
|
|
|
|
*
|
2002-07-24 02:08:59 +00:00
|
|
|
* All it does is keep the "text / *" and "text/plain" mime type
|
2002-05-16 23:09:02 +00:00
|
|
|
* handlers in sync with each other. The reason we do this is because
|
2002-07-24 02:08:59 +00:00
|
|
|
* there is no UI for editing the text / * handler, and this is probably
|
2002-05-16 23:09:02 +00:00
|
|
|
* what the user actually wants to do.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-06-06 11:51:40 +00:00
|
|
|
#include "gnome-settings-module.h"
|
|
|
|
#include "utils.h"
|
2002-05-16 23:09:02 +00:00
|
|
|
|
|
|
|
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
|
|
|
|
#include <libgnomevfs/gnome-vfs-mime-monitor.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2007-06-06 11:51:40 +00:00
|
|
|
typedef struct {
|
|
|
|
GnomeSettingsModule parent;
|
|
|
|
} GnomeSettingsModuleDefaultEditor;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GnomeSettingsModuleClass parent_class;
|
|
|
|
} GnomeSettingsModuleDefaultEditorClass;
|
|
|
|
|
|
|
|
static GnomeSettingsModuleRunlevel gnome_settings_module_default_editor_get_runlevel (GnomeSettingsModule *module);
|
|
|
|
static gboolean gnome_settings_module_default_editor_initialize (GnomeSettingsModule *module,
|
|
|
|
GConfClient *config_client);
|
|
|
|
static gboolean gnome_settings_module_default_editor_start (GnomeSettingsModule *module);
|
|
|
|
static gboolean gnome_settings_module_default_editor_stop (GnomeSettingsModule *module);
|
|
|
|
|
2002-05-16 23:09:02 +00:00
|
|
|
/* #define DE_DEBUG */
|
|
|
|
|
|
|
|
#define SYNC_CHANGES_KEY "/apps/gnome_settings_daemon/default_editor/sync_text_types"
|
|
|
|
|
|
|
|
static gboolean sync_changes;
|
|
|
|
|
2007-06-06 11:51:40 +00:00
|
|
|
static void
|
|
|
|
gnome_settings_module_default_editor_class_init (GnomeSettingsModuleDefaultEditorClass *klass)
|
|
|
|
{
|
|
|
|
GnomeSettingsModuleClass *module_class;
|
|
|
|
|
|
|
|
module_class = (GnomeSettingsModuleClass *) klass;
|
|
|
|
module_class->get_runlevel = gnome_settings_module_default_editor_get_runlevel;
|
|
|
|
module_class->initialize = gnome_settings_module_default_editor_initialize;
|
|
|
|
module_class->start = gnome_settings_module_default_editor_start;
|
|
|
|
module_class->stop = gnome_settings_module_default_editor_stop;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gnome_settings_module_default_editor_init (GnomeSettingsModuleDefaultEditor *module)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GType
|
|
|
|
gnome_settings_module_default_editor_get_type (void)
|
|
|
|
{
|
|
|
|
static GType module_type = 0;
|
|
|
|
|
|
|
|
if (!module_type) {
|
|
|
|
static const GTypeInfo module_info = {
|
|
|
|
sizeof (GnomeSettingsModuleDefaultEditorClass),
|
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
(GClassInitFunc) gnome_settings_module_default_editor_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GnomeSettingsModuleDefaultEditor),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gnome_settings_module_default_editor_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_type = g_type_register_static (GNOME_SETTINGS_TYPE_MODULE,
|
|
|
|
"GnomeSettingsModuleDefaultEditor",
|
|
|
|
&module_info, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return module_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GnomeSettingsModuleRunlevel
|
|
|
|
gnome_settings_module_default_editor_get_runlevel (GnomeSettingsModule *module)
|
|
|
|
{
|
|
|
|
return GNOME_SETTINGS_MODULE_RUNLEVEL_GNOME_SETTINGS;
|
|
|
|
}
|
|
|
|
|
2005-11-14 15:18:09 +00:00
|
|
|
#ifdef DE_DEBUG
|
2002-05-16 23:09:02 +00:00
|
|
|
static void
|
|
|
|
print_mime_app (const char *mime_type)
|
|
|
|
{
|
|
|
|
GnomeVFSMimeApplication *mime_app;
|
|
|
|
|
|
|
|
mime_app = gnome_vfs_mime_get_default_application (mime_type);
|
|
|
|
|
|
|
|
g_message ("Default info for %s (%p):\n"
|
|
|
|
"\t id: %s\n"
|
|
|
|
"\t name: %s\n"
|
|
|
|
"\t command: %s\n"
|
|
|
|
"\tneeds term: %s\n",
|
|
|
|
mime_type, mime_app,
|
|
|
|
mime_app->id,
|
|
|
|
mime_app->name,
|
|
|
|
mime_app->command,
|
|
|
|
mime_app->requires_terminal ? "Yes" : "No");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_state (void)
|
|
|
|
{
|
|
|
|
if (sync_changes)
|
|
|
|
g_message ("Synching changes.");
|
|
|
|
else
|
|
|
|
g_message ("Not synching changes.");
|
|
|
|
|
|
|
|
print_mime_app ("text/*");
|
|
|
|
print_mime_app ("text/plain");
|
|
|
|
}
|
|
|
|
#define PRINT_STATE print_state()
|
|
|
|
#else
|
|
|
|
#define PRINT_STATE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
sync_changes_cb (GConfEntry *entry)
|
|
|
|
{
|
|
|
|
GConfValue *value = gconf_entry_get_value (entry);
|
|
|
|
sync_changes = gconf_value_get_bool (value);
|
|
|
|
|
|
|
|
PRINT_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vfs_change_cb (GnomeVFSMIMEMonitor *monitor, GConfClient *client)
|
|
|
|
{
|
|
|
|
GnomeVFSMimeApplication *star_app, *plain_app;
|
|
|
|
GnomeVFSMimeActionType action;
|
|
|
|
|
|
|
|
PRINT_STATE;
|
|
|
|
|
2004-12-25 14:32:12 +00:00
|
|
|
if (!sync_changes)
|
2004-12-24 01:40:47 +00:00
|
|
|
return;
|
2002-05-16 23:09:02 +00:00
|
|
|
|
|
|
|
star_app = gnome_vfs_mime_get_default_application ("text/*");
|
|
|
|
plain_app = gnome_vfs_mime_get_default_application ("text/plain");
|
|
|
|
|
2004-10-21 19:41:26 +00:00
|
|
|
if (star_app == NULL || plain_app == NULL) {
|
|
|
|
if (star_app != NULL) {
|
|
|
|
gnome_vfs_mime_application_free (star_app);
|
|
|
|
}
|
|
|
|
if (plain_app != NULL) {
|
|
|
|
gnome_vfs_mime_application_free (plain_app);
|
|
|
|
}
|
2002-08-15 17:54:10 +00:00
|
|
|
return;
|
2004-10-21 19:41:26 +00:00
|
|
|
}
|
|
|
|
if (!strcmp (star_app->id, plain_app->id)) {
|
|
|
|
gnome_vfs_mime_application_free (star_app);
|
|
|
|
gnome_vfs_mime_application_free (plain_app);
|
2002-05-16 23:09:02 +00:00
|
|
|
return;
|
2004-10-21 19:41:26 +00:00
|
|
|
}
|
2002-05-16 23:09:02 +00:00
|
|
|
|
2005-11-14 15:18:09 +00:00
|
|
|
#ifdef DE_DEBUG
|
2002-05-16 23:09:02 +00:00
|
|
|
g_message ("Synching text/plain to text/*...");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
action = gnome_vfs_mime_get_default_action_type ("text/plain");
|
|
|
|
|
|
|
|
gnome_vfs_mime_set_default_application ("text/*", plain_app->id);
|
2004-10-21 19:41:26 +00:00
|
|
|
gnome_vfs_mime_application_free (plain_app);
|
|
|
|
|
2002-05-16 23:09:02 +00:00
|
|
|
gnome_vfs_mime_set_default_action_type ("text/*", action);
|
|
|
|
|
|
|
|
PRINT_STATE;
|
|
|
|
}
|
|
|
|
|
2007-06-06 11:51:40 +00:00
|
|
|
static gboolean
|
|
|
|
gnome_settings_module_default_editor_initialize (GnomeSettingsModule *module, GConfClient *config_client)
|
2002-05-16 23:09:02 +00:00
|
|
|
{
|
2007-06-06 11:51:40 +00:00
|
|
|
sync_changes = gconf_client_get_bool (config_client, SYNC_CHANGES_KEY, NULL);
|
2002-05-16 23:09:02 +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 (SYNC_CHANGES_KEY, sync_changes_cb);
|
2002-05-16 23:09:02 +00:00
|
|
|
|
|
|
|
g_signal_connect (gnome_vfs_mime_monitor_get (), "data_changed",
|
2007-06-06 11:51:40 +00:00
|
|
|
G_CALLBACK (vfs_change_cb), config_client);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gnome_settings_module_default_editor_start (GnomeSettingsModule *module)
|
|
|
|
{
|
|
|
|
vfs_change_cb (NULL, gnome_settings_module_get_config_client (module));
|
|
|
|
|
|
|
|
return TRUE;
|
2002-05-16 23:09:02 +00:00
|
|
|
}
|
|
|
|
|
2007-06-06 11:51:40 +00:00
|
|
|
static gboolean
|
|
|
|
gnome_settings_module_default_editor_stop (GnomeSettingsModule *module)
|
2002-05-16 23:09:02 +00:00
|
|
|
{
|
2007-06-06 11:51:40 +00:00
|
|
|
return TRUE;
|
2002-05-16 23:09:02 +00:00
|
|
|
}
|