Near total rewrite

This commit is contained in:
Bradford Hovinen (Gdict maintainer) 2002-01-08 21:25:33 +00:00
parent d159298d55
commit 98e37477fa
16 changed files with 4053 additions and 2002 deletions

View file

@ -1,3 +1,7 @@
2002-01-04 Bradford Hovinen <hovinen@ximian.com>
* Makefile.am: Clean up
2001-12-09 Havoc Pennington <hp@pobox.com>
* file-types-capplet.c: remove no-longer-existing header

View file

@ -1,34 +1,25 @@
SUBDIRS = libuuid
cappletname = file-types
cappletgroup = "Advanced/"
bin_PROGRAMS = file-types-capplet
bin_PROGRAMS = gnome-file-types-properties
file_types_capplet_LDADD = $(VFS_CAPPLET_LIBS) libuuid/libuuid.a
gnome_file_types_properties_LDADD = $(GNOMECC_CAPPLETS_LIBS) $(VFS_CAPPLET_LIBS) libuuid/libuuid.a
file_types_capplet_SOURCES = \
file-types-capplet.h \
file-types-capplet-dialogs.h \
file-types-icon-entry.h \
gnome_file_types_properties_SOURCES = \
file-types-capplet.c \
file-types-capplet-dialogs.c \
file-types-icon-entry.c
mime-types-model.c mime-types-model.h \
mime-type-info.c mime-type-info.h \
mime-edit-dialog.c mime-edit-dialog.h \
service-info.c service-info.h \
service-edit-dialog.c service-edit-dialog.h
pixmap_DATA =
##
## You should not need to modify anything below this line
##
@INTLTOOL_DESKTOP_RULE@
@GNOMECC_CAPPLETS_DESKTOP_IN_RULE@
Gladedir = $(GNOMECC_DATA_DIR)/interfaces
Glade_DATA = file-types-properties.glade
desktopdir = $(GNOMECC_DATA_DIR)/capplets/Advanced
desktop_DATA = file-types.desktop
INCLUDES = $(GNOMECC_CAPPLETS_CFLAGS) $(VFS_CAPPLET_CFLAGS)
CLEANFILES = $(GNOMECC_CAPPLETS_CLEANFILES)
EXTRA_DIST = $(GNOMECC_CAPPLETS_EXTRA_DIST)
iconsdir = $(GNOMECC_ICONS_DIR)
Gladedir = $(GNOMECC_GLADE_DIR)
pixmapdir = $(GNOMECC_PIXMAPS_DIR)
Glade_DATA = $(cappletname)-properties.glade
icons_DATA = $(cappletname)-capplet.png
desktop = $(cappletname).desktop
all-local: $(desktop)
EXTRA_DIST = $(Glade_DATA) $(desktop_DATA)

View file

@ -0,0 +1,9 @@
- Get icon name (esp. use of stock icons) working correctly
- Add categories to many types in MIME database
- Do dialog for Internet service
- Validation
- Talk to gnome-vfs people about categories, edit and print lines, custom line, gnome-vfs-mime-info.h install
- Do something better about custom-line (i.e. create a dummy app in the app register)
- Make MIME types tree accept double clicks
- Implement tree cascading
- Fix gnome_url_show

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,561 @@
/* -*- mode: c; style: linux -*- */
/* mime-edit-dialog.c
* Copyright (C) 2001 Ximian, Inc.
*
* Written by Bradford Hovinen <hovinen@ximian.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.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <glade/glade.h>
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
#include "mime-edit-dialog.h"
#define WID(x) (glade_xml_get_widget (dialog->p->dialog_xml, x))
enum {
PROP_0,
PROP_MIME_TYPE_INFO
};
struct _MimeEditDialogPrivate
{
MimeTypeInfo *info;
GladeXML *dialog_xml;
GtkWidget *dialog_win;
GtkTreeStore *ext_store;
};
static GObjectClass *parent_class;
static void mime_edit_dialog_init (MimeEditDialog *mime_edit_dialog,
MimeEditDialogClass *class);
static void mime_edit_dialog_class_init (MimeEditDialogClass *class);
static void mime_edit_dialog_base_init (MimeEditDialogClass *class);
static void mime_edit_dialog_set_prop (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void mime_edit_dialog_get_prop (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void mime_edit_dialog_dispose (GObject *object);
static void mime_edit_dialog_finalize (GObject *object);
static void fill_dialog (MimeEditDialog *dialog);
static void populate_component_list (MimeEditDialog *dialog);
static void populate_application_list (MimeEditDialog *dialog);
static void populate_extensions_list (MimeEditDialog *dialog);
static void add_ext_cb (MimeEditDialog *dialog);
static void remove_ext_cb (MimeEditDialog *dialog);
static void default_action_changed_cb (MimeEditDialog *dialog);
static void response_cb (MimeEditDialog *dialog,
gint response_id);
GType
mime_edit_dialog_get_type (void)
{
static GType mime_edit_dialog_type = 0;
if (!mime_edit_dialog_type) {
GTypeInfo mime_edit_dialog_info = {
sizeof (MimeEditDialogClass),
(GBaseInitFunc) mime_edit_dialog_base_init,
NULL, /* GBaseFinalizeFunc */
(GClassInitFunc) mime_edit_dialog_class_init,
NULL, /* GClassFinalizeFunc */
NULL, /* user-supplied data */
sizeof (MimeEditDialog),
0, /* n_preallocs */
(GInstanceInitFunc) mime_edit_dialog_init,
NULL
};
mime_edit_dialog_type =
g_type_register_static (G_TYPE_OBJECT,
"MimeEditDialog",
&mime_edit_dialog_info, 0);
}
return mime_edit_dialog_type;
}
static void
mime_edit_dialog_init (MimeEditDialog *dialog, MimeEditDialogClass *class)
{
GtkSizeGroup *size_group;
GtkTreeView *view;
GtkCellRenderer *renderer;
dialog->p = g_new0 (MimeEditDialogPrivate, 1);
dialog->p->dialog_xml = glade_xml_new
(GNOMECC_DATA_DIR "/interfaces/file-types-properties.glade", "edit_widget", NULL);
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_size_group_add_widget (size_group, WID ("description_label"));
gtk_size_group_add_widget (size_group, WID ("mime_type_label"));
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_size_group_add_widget (size_group, WID ("component_label"));
gtk_size_group_add_widget (size_group, WID ("default_action_label"));
gtk_size_group_add_widget (size_group, WID ("program_label"));
dialog->p->ext_store = gtk_tree_store_new (1, G_TYPE_STRING);
view = GTK_TREE_VIEW (WID ("ext_list"));
gtk_tree_view_set_model (view, GTK_TREE_MODEL (dialog->p->ext_store));
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (view, -1, _("Extension"), renderer, "text", 0, NULL);
dialog->p->dialog_win = gtk_dialog_new_with_buttons
(_("Edit file type"), NULL, -1,
GTK_STOCK_OK, GTK_RESPONSE_OK,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog->p->dialog_win)->vbox), WID ("edit_widget"), TRUE, TRUE, 0);
g_signal_connect_swapped (G_OBJECT (WID ("add_ext_button")), "clicked", (GCallback) add_ext_cb, dialog);
g_signal_connect_swapped (G_OBJECT (WID ("remove_ext_button")), "clicked", (GCallback) remove_ext_cb, dialog);
g_signal_connect_swapped (G_OBJECT (WID ("default_action_select")), "changed", (GCallback) default_action_changed_cb, dialog);
g_signal_connect_swapped (G_OBJECT (dialog->p->dialog_win), "response", (GCallback) response_cb, dialog);
}
static void
mime_edit_dialog_base_init (MimeEditDialogClass *class)
{
}
static void
mime_edit_dialog_class_init (MimeEditDialogClass *class)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (class);
object_class->dispose = mime_edit_dialog_dispose;
object_class->finalize = mime_edit_dialog_finalize;
object_class->set_property = mime_edit_dialog_set_prop;
object_class->get_property = mime_edit_dialog_get_prop;
g_object_class_install_property
(object_class, PROP_MIME_TYPE_INFO,
g_param_spec_pointer ("mime-type-info",
_("MIME type info"),
_("Information on MIME type to edit"),
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
parent_class = G_OBJECT_CLASS
(g_type_class_ref (G_TYPE_OBJECT));
}
static void
mime_edit_dialog_set_prop (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
MimeEditDialog *mime_edit_dialog;
g_return_if_fail (object != NULL);
g_return_if_fail (IS_MIME_EDIT_DIALOG (object));
mime_edit_dialog = MIME_EDIT_DIALOG (object);
switch (prop_id) {
case PROP_MIME_TYPE_INFO:
mime_edit_dialog->p->info = g_value_get_pointer (value);
fill_dialog (mime_edit_dialog);
break;
default:
g_warning ("Bad property set");
break;
}
}
static void
mime_edit_dialog_get_prop (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
MimeEditDialog *mime_edit_dialog;
g_return_if_fail (object != NULL);
g_return_if_fail (IS_MIME_EDIT_DIALOG (object));
mime_edit_dialog = MIME_EDIT_DIALOG (object);
switch (prop_id) {
case PROP_MIME_TYPE_INFO:
g_value_set_pointer (value, mime_edit_dialog->p->info);
break;
default:
g_warning ("Bad property get");
break;
}
}
static void
mime_edit_dialog_dispose (GObject *object)
{
MimeEditDialog *dialog;
g_return_if_fail (object != NULL);
g_return_if_fail (IS_MIME_EDIT_DIALOG (object));
dialog = MIME_EDIT_DIALOG (object);
if (dialog->p->dialog_xml != NULL) {
g_object_unref (G_OBJECT (dialog->p->dialog_xml));
dialog->p->dialog_xml = NULL;
}
if (dialog->p->dialog_win != NULL) {
gtk_widget_destroy (GTK_WIDGET (dialog->p->dialog_win));
dialog->p->dialog_win = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
mime_edit_dialog_finalize (GObject *object)
{
MimeEditDialog *mime_edit_dialog;
g_return_if_fail (object != NULL);
g_return_if_fail (IS_MIME_EDIT_DIALOG (object));
mime_edit_dialog = MIME_EDIT_DIALOG (object);
g_free (mime_edit_dialog->p);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
GObject *
mime_edit_dialog_new (MimeTypeInfo *info)
{
return g_object_new (mime_edit_dialog_get_type (),
"mime-type-info", info,
NULL);
}
GObject *
mime_add_dialog_new (void)
{
return g_object_new (mime_edit_dialog_get_type (),
"mime-type-info", g_new0 (MimeTypeInfo, 1),
NULL);
}
static void
fill_dialog (MimeEditDialog *dialog)
{
gtk_entry_set_text (GTK_ENTRY (WID ("description_entry")), dialog->p->info->description);
gtk_entry_set_text (GTK_ENTRY (WID ("mime_type_entry")), dialog->p->info->mime_type);
if (dialog->p->info->custom_line != NULL)
gnome_file_entry_set_filename (GNOME_FILE_ENTRY (WID ("program_entry")), dialog->p->info->custom_line);
if (dialog->p->info->mime_type != NULL && *dialog->p->info->mime_type != '\0')
gtk_widget_set_sensitive (WID ("mime_type_entry"), FALSE);
if (dialog->p->info->icon_name == NULL)
gnome_icon_entry_set_filename (GNOME_ICON_ENTRY (WID ("icon_entry")), "nautilus/i-regular-24.png");
else
gnome_icon_entry_set_filename (GNOME_ICON_ENTRY (WID ("icon_entry")), dialog->p->info->icon_name);
populate_component_list (dialog);
populate_application_list (dialog);
populate_extensions_list (dialog);
gtk_widget_show_all (dialog->p->dialog_win);
}
static void
populate_component_list (MimeEditDialog *dialog)
{
GList *component_list, *tmp;
GtkMenu *menu;
GtkWidget *menu_item;
GtkOptionMenu *component_select;
gchar *component_name;
Bonobo_ServerInfo *info;
int found_idx = -1, i;
menu = GTK_MENU (gtk_menu_new ());
component_list = gnome_vfs_mime_get_short_list_components (dialog->p->info->mime_type);
for (tmp = component_list, i = 0; tmp != NULL; tmp = tmp->next, i++) {
info = tmp->data;
if (!strcmp (info->iid, dialog->p->info->default_component_id))
found_idx = i;
component_name = mime_type_get_pretty_name_for_server (info);
menu_item = gtk_menu_item_new_with_label (component_name);
g_free (component_name);
/* Store copy of component name in item; free when item destroyed. */
g_object_set_data_full (G_OBJECT (menu_item),
"iid",
g_strdup (info->iid),
(GDestroyNotify) g_free);
gtk_menu_append (menu, menu_item);
gtk_widget_show (menu_item);
}
gtk_menu_append (menu, gtk_menu_item_new_with_label (_("None")));
if (found_idx < 0)
found_idx = i;
component_select = GTK_OPTION_MENU (WID ("component_select"));
gtk_option_menu_set_menu (component_select, GTK_WIDGET (menu));
gtk_option_menu_set_history (component_select, found_idx);
gnome_vfs_mime_component_list_free (component_list);
}
static void
populate_application_list (MimeEditDialog *dialog)
{
GList *app_list, *tmp;
GtkMenu *menu;
GtkWidget *menu_item;
GtkOptionMenu *app_select;
GnomeVFSMimeApplication *app;
int found_idx = -1, i;
menu = GTK_MENU (gtk_menu_new ());
app_list = gnome_vfs_mime_get_short_list_applications (dialog->p->info->mime_type);
for (tmp = app_list, i = 0; tmp != NULL; tmp = tmp->next, i++) {
app = tmp->data;
if (!strcmp (app->id, dialog->p->info->default_action->id))
found_idx = i;
menu_item = gtk_menu_item_new_with_label (app->name);
/* Store copy of application in item; free when item destroyed. */
g_object_set_data_full (G_OBJECT (menu_item),
"app", app,
(GDestroyNotify) gnome_vfs_mime_application_free);
gtk_menu_append (menu, menu_item);
gtk_widget_show (menu_item);
}
gtk_menu_append (menu, gtk_menu_item_new_with_label (_("Custom")));
if (found_idx < 0) {
found_idx = i;
gnome_file_entry_set_filename (GNOME_FILE_ENTRY (WID ("program_entry")),
dialog->p->info->default_action->command);
} else {
gtk_widget_set_sensitive (WID ("program_entry_box"), FALSE);
}
app_select = GTK_OPTION_MENU (WID ("default_action_select"));
gtk_option_menu_set_menu (app_select, GTK_WIDGET (menu));
gtk_option_menu_set_history (app_select, found_idx);
g_list_free (app_list);
}
static void
populate_extensions_list (MimeEditDialog *dialog)
{
GList *tmp;
GtkTreeIter iter;
for (tmp = dialog->p->info->file_extensions; tmp != NULL; tmp = tmp->next) {
gtk_tree_store_append (dialog->p->ext_store, &iter, NULL);
gtk_tree_store_set (dialog->p->ext_store, &iter, 0, tmp->data, -1);
}
}
static GList *
collect_filename_extensions (MimeEditDialog *dialog)
{
GtkTreeIter iter;
GValue value;
GList *ret = NULL;
gtk_tree_model_get_iter_root (GTK_TREE_MODEL (dialog->p->ext_store), &iter);
value.g_type = G_TYPE_INVALID;
do {
gtk_tree_model_get_value (GTK_TREE_MODEL (dialog->p->ext_store), &iter, 0, &value);
ret = g_list_prepend (ret, g_value_dup_string (&value));
g_value_unset (&value);
} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (dialog->p->ext_store), &iter));
return ret;
}
static GList *
merge_ext_lists (GList *list1, GList *list2)
{
GList *tmp, *tmp1;
for (tmp = list2; tmp != NULL; tmp = tmp->next) {
for (tmp1 = list1; tmp1 != NULL && strcmp (tmp->data, tmp1->data); tmp1 = tmp1->next);
if (tmp1 == NULL)
list1 = g_list_prepend (list1, g_strdup (tmp->data));
}
return list1;
}
static void
store_data (MimeEditDialog *dialog)
{
GtkOptionMenu *option_menu;
GtkMenuShell *menu_shell;
GObject *menu_item;
gint idx;
GList *ext_list;
g_free (dialog->p->info->description);
dialog->p->info->description = g_strdup (gtk_entry_get_text (GTK_ENTRY (WID ("description_entry"))));
g_free (dialog->p->info->mime_type);
dialog->p->info->mime_type = g_strdup (gtk_entry_get_text (GTK_ENTRY (WID ("mime_type_entry"))));
g_free (dialog->p->info->icon_name);
dialog->p->info->icon_name = g_strdup (gnome_icon_entry_get_filename (GNOME_ICON_ENTRY (WID ("icon_entry"))));
option_menu = GTK_OPTION_MENU (WID ("component_select"));
menu_shell = GTK_MENU_SHELL (gtk_option_menu_get_menu (option_menu));
idx = gtk_option_menu_get_history (option_menu);
menu_item = (g_list_nth (menu_shell->children, idx))->data;
g_free (dialog->p->info->default_component_id);
dialog->p->info->default_component_id = g_strdup (g_object_get_data (menu_item, "iid"));
option_menu = GTK_OPTION_MENU (WID ("default_action_select"));
menu_shell = GTK_MENU_SHELL (gtk_option_menu_get_menu (option_menu));
idx = gtk_option_menu_get_history (option_menu);
menu_item = (g_list_nth (menu_shell->children, idx))->data;
gnome_vfs_mime_application_free (dialog->p->info->default_action);
dialog->p->info->default_action = gnome_vfs_mime_application_copy (g_object_get_data (menu_item, "app"));
g_free (dialog->p->info->custom_line);
dialog->p->info->custom_line = g_strdup (gnome_file_entry_get_full_path (GNOME_FILE_ENTRY (WID ("program_entry")), FALSE));
ext_list = collect_filename_extensions (dialog);
dialog->p->info->file_extensions = merge_ext_lists (dialog->p->info->file_extensions, ext_list);
g_list_foreach (ext_list, (GFunc) g_free, NULL);
g_list_free (ext_list);
mime_type_append_to_dirty_list (dialog->p->info);
}
static void
add_ext_cb (MimeEditDialog *dialog)
{
GladeXML *add_dialog_xml;
GtkWidget *add_dialog;
GtkWidget *add_widget;
GtkWidget *ext_entry;
gint response_id;
GtkTreeIter iter;
add_dialog_xml = glade_xml_new (GNOMECC_DATA_DIR "/interfaces/file-types-properties.glade", "add_ext_widget", NULL);
add_dialog = gtk_dialog_new_with_buttons
(_("Add filename extension"), NULL, -1,
GTK_STOCK_OK, GTK_RESPONSE_OK,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL);
add_widget = glade_xml_get_widget (add_dialog_xml, "add_ext_widget");
ext_entry = glade_xml_get_widget (add_dialog_xml, "add_ext_entry");
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (add_dialog)->vbox), add_widget, TRUE, TRUE, 0);
gtk_widget_show_all (add_dialog);
response_id = gtk_dialog_run (GTK_DIALOG (add_dialog));
if (response_id == GTK_RESPONSE_OK) {
gtk_tree_store_append (dialog->p->ext_store, &iter, NULL);
gtk_tree_store_set (dialog->p->ext_store, &iter, 0,
gtk_entry_get_text (GTK_ENTRY (ext_entry)));
}
gtk_widget_destroy (GTK_WIDGET (add_dialog));
g_object_unref (G_OBJECT (add_dialog_xml));
}
static void
remove_ext_foreach_cb (GtkTreeModel *model, GtkTreePath *path,
GtkTreeIter *iter)
{
gtk_tree_store_remove (GTK_TREE_STORE (model), iter);
}
static void
remove_ext_cb (MimeEditDialog *dialog)
{
gtk_tree_selection_selected_foreach (gtk_tree_view_get_selection (GTK_TREE_VIEW (WID ("ext_list"))),
(GtkTreeSelectionForeachFunc) remove_ext_foreach_cb, NULL);
}
static void
default_action_changed_cb (MimeEditDialog *dialog)
{
int id;
GtkOptionMenu *option_menu;
GtkMenuShell *menu;
option_menu = GTK_OPTION_MENU (WID ("default_action_select"));
menu = GTK_MENU_SHELL (gtk_option_menu_get_menu (option_menu));
id = gtk_option_menu_get_history (option_menu);
if (id == g_list_length (menu->children) - 1)
gtk_widget_set_sensitive (WID ("program_entry_box"), TRUE);
else
gtk_widget_set_sensitive (WID ("program_entry_box"), FALSE);
}
static void
response_cb (MimeEditDialog *dialog, gint response_id)
{
if (response_id == GTK_RESPONSE_OK)
store_data (dialog);
g_object_unref (G_OBJECT (dialog));
}

View file

@ -0,0 +1,60 @@
/* -*- mode: c; style: linux -*- */
/* mime-edit-dialog.h
* Copyright (C) 2001 Ximian, Inc.
*
* Written by Bradford Hovinen <hovinen@ximian.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.
*/
#ifndef __MIME_EDIT_DIALOG_H
#define __MIME_EDIT_DIALOG_H
#include <gnome.h>
#include "mime-type-info.h"
G_BEGIN_DECLS
#define MIME_EDIT_DIALOG(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, mime_edit_dialog_get_type (), MimeEditDialog)
#define MIME_EDIT_DIALOG_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, mime_edit_dialog_get_type (), MimeEditDialogClass)
#define IS_MIME_EDIT_DIALOG(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, mime_edit_dialog_get_type ())
typedef struct _MimeEditDialog MimeEditDialog;
typedef struct _MimeEditDialogClass MimeEditDialogClass;
typedef struct _MimeEditDialogPrivate MimeEditDialogPrivate;
struct _MimeEditDialog
{
GObject parent;
MimeEditDialogPrivate *p;
};
struct _MimeEditDialogClass
{
GObjectClass g_object_class;
};
GType mime_edit_dialog_get_type (void);
GObject *mime_edit_dialog_new (MimeTypeInfo *info);
GObject *mime_add_dialog_new (void);
G_END_DECLS
#endif /* __MIME_EDIT_DIALOG_H */

View file

@ -0,0 +1,193 @@
/* -*- mode: c; style: linux -*- */
/* mime-type-info.c
*
* Copyright (C) 2000 Eazel, Inc.
* Copyright (C) 2002 Ximian, Inc.
*
* Written by Bradford Hovinen <hovinen@ximian.com>,
* Jonathan Blandford <jrb@redhat.com>,
* Gene Z. Ragan <gzr@eazel.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 of the
* License, 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.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <bonobo.h>
#include "mime-type-info.h"
static GList *dirty_list = NULL;
static GSList *
get_lang_list (void)
{
GSList *retval;
const char *lang;
char *equal_char;
retval = NULL;
lang = g_getenv ("LANGUAGE");
if (lang == NULL)
lang = g_getenv ("LANG");
if (lang != NULL) {
equal_char = strchr (lang, '=');
if (equal_char != NULL)
lang = equal_char + 1;
retval = g_slist_prepend (retval, g_strdup (lang));
}
return retval;
}
MimeTypeInfo *
mime_type_info_load (const gchar *mime_type)
{
MimeTypeInfo *info;
Bonobo_ServerInfo *component_info;
info = g_new0 (MimeTypeInfo, 1);
info->mime_type = g_strdup (mime_type);
info->description = g_strdup (gnome_vfs_mime_get_description (mime_type));
info->icon_name = g_strdup (gnome_vfs_mime_get_icon (mime_type));
info->file_extensions = gnome_vfs_mime_get_extensions_list (mime_type);
info->edit_line = g_strdup (gnome_vfs_mime_get_value (mime_type, "edit-line"));
info->print_line = g_strdup (gnome_vfs_mime_get_value (mime_type, "print-line"));
info->default_action = gnome_vfs_mime_get_default_application (mime_type);
info->custom_line = g_strdup (gnome_vfs_mime_get_value (mime_type, "custom-line"));
component_info = gnome_vfs_mime_get_default_component (mime_type);
if (component_info != NULL) {
info->default_component_id = component_info->iid;
CORBA_free (component_info);
}
return info;
}
void
mime_type_info_save (const MimeTypeInfo *info)
{
gchar *tmp;
gchar **array;
GList *l;
gint i = 0;
gnome_vfs_mime_set_description (info->mime_type, info->description);
gnome_vfs_mime_set_icon (info->mime_type, info->icon_name);
gnome_vfs_mime_set_default_application (info->mime_type, info->default_action->id);
gnome_vfs_mime_set_value (info->mime_type, "custom-line", info->custom_line);
gnome_vfs_mime_set_value (info->mime_type, "print-line", info->print_line);
gnome_vfs_mime_set_value (info->mime_type, "edit-line", info->edit_line);
array = g_new0 (gchar *, g_list_length (info->file_extensions) + 1);
for (l = info->file_extensions; l != NULL; l = l->next)
array[i++] = l->data;
tmp = g_strjoinv (" ", array);
g_free (array);
gnome_vfs_mime_set_extensions_list (info->mime_type, tmp);
g_free (tmp);
}
void
mime_type_info_free (MimeTypeInfo *info)
{
g_free (info->mime_type);
g_free (info->description);
g_free (info->icon_name);
gnome_vfs_mime_extensions_list_free (info->file_extensions);
g_free (info->default_component_id);
gnome_vfs_mime_application_free (info->default_action);
g_free (info->custom_line);
g_free (info->edit_line);
g_free (info->print_line);
g_free (info);
}
char *
mime_type_get_pretty_name_for_server (Bonobo_ServerInfo *server)
{
const char *view_as_name;
char *display_name;
GSList *langs;
display_name = NULL;
langs = get_lang_list ();
view_as_name = bonobo_server_info_prop_lookup (server, "nautilus:view_as_name", langs);
if (view_as_name == NULL)
view_as_name = bonobo_server_info_prop_lookup (server, "name", langs);
if (view_as_name == NULL)
view_as_name = server->iid;
g_slist_foreach (langs, (GFunc) g_free, NULL);
g_slist_free (langs);
/* if the name is an OAFIID, clean it up for display */
if (!strncmp (view_as_name, "OAFIID:", strlen ("OAFIID:"))) {
char *display_name, *colon_ptr;
display_name = g_strdup (view_as_name + strlen ("OAFIID:"));
colon_ptr = strchr (display_name, ':');
if (colon_ptr)
*colon_ptr = '\0';
return display_name;
}
return g_strdup_printf ("View as %s", view_as_name);
}
void
mime_type_append_to_dirty_list (MimeTypeInfo *info)
{
if (g_list_find (dirty_list, info) == NULL)
dirty_list = g_list_prepend (dirty_list, info);
}
void
mime_type_remove_from_dirty_list (const gchar *mime_type)
{
GList *tmp = dirty_list, *tmp1;
while (tmp != NULL) {
tmp1 = tmp->next;
if (!strcmp (mime_type, ((MimeTypeInfo *) tmp->data)->mime_type))
dirty_list = g_list_remove_link (dirty_list, tmp);
tmp = tmp1;
}
}
void
mime_type_commit_dirty_list (void)
{
gnome_vfs_mime_freeze ();
g_list_foreach (dirty_list, (GFunc) mime_type_info_save, NULL);
gnome_vfs_mime_thaw ();
}

View file

@ -0,0 +1,62 @@
/* -*- mode: c; style: linux -*- */
/* mime-type-info.h
*
* Copyright (C) 2002 Ximian, Inc.
*
* Written by Bradford Hovinen <hovinen@ximian.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 of the
* License, 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.
*/
#ifndef __MIME_TYPE_INFO_H
#define __MIME_TYPE_INFO_H
#include <gnome.h>
#include <bonobo.h>
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
G_BEGIN_DECLS
typedef struct _MimeTypeInfo MimeTypeInfo;
struct _MimeTypeInfo
{
gchar *mime_type;
gchar *description;
gchar *icon_name;
GList *file_extensions;
gchar *default_component_id;
GnomeVFSMimeApplication *default_action;
gchar *custom_line;
gchar *edit_line;
gchar *print_line;
};
MimeTypeInfo *mime_type_info_load (const gchar *mime_type);
void mime_type_info_save (const MimeTypeInfo *info);
void mime_type_info_free (MimeTypeInfo *info);
char *mime_type_get_pretty_name_for_server (Bonobo_ServerInfo *server);
void mime_type_append_to_dirty_list (MimeTypeInfo *info);
void mime_type_remove_from_dirty_list (const gchar *mime_type);
void mime_type_commit_dirty_list (void);
G_END_DECLS
#endif /* __MIME_TYPE_INFO_H */

View file

@ -0,0 +1,308 @@
/* -*- mode: c; style: linux -*- */
/* mime-types-model.c
*
* Copyright (C) 2002 Ximian, Inc.
*
* Written by Bradford Hovinen <hovinen@ximian.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 of the
* License, 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.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <libgnomevfs/gnome-vfs.h>
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
#include <libgnomevfs/gnome-vfs-mime-utils.h>
#include <gconf/gconf.h>
#include <gconf/gconf-client.h>
#include "mime-types-model.h"
const gchar *categories[] = {
"Documents", "Images", "Audio", "Video", "Internet Services", NULL
};
const gchar *url_descriptions[][2] = {
{ "unknown", N_("Unknown service types") },
{ "http", N_("World wide web") },
{ "ftp", N_("File transfer protocol") },
{ "info", N_("Detailed documentation") },
{ "man", N_("Manual pages") },
{ "mailto", N_("Electronic mail transmission") },
{ NULL, NULL }
};
static GdkPixbuf *
get_icon_pixbuf (const gchar *short_icon_name)
{
gchar *icon_name;
GdkPixbuf *pixbuf, *pixbuf1;
static GHashTable *pixbuf_table;
if (pixbuf_table == NULL)
pixbuf_table = g_hash_table_new (g_str_hash, g_str_equal);
if (short_icon_name == NULL)
short_icon_name = "nautilus/i-regular-24.png";
icon_name = gnome_program_locate_file
(gnome_program_get (), GNOME_FILE_DOMAIN_PIXMAP,
short_icon_name, TRUE, NULL);
if (icon_name != NULL) {
pixbuf1 = g_hash_table_lookup (pixbuf_table, icon_name);
if (pixbuf1 != NULL) {
g_object_ref (G_OBJECT (pixbuf1));
} else {
pixbuf = gdk_pixbuf_new_from_file (icon_name, NULL);
if (pixbuf == NULL)
pixbuf = get_icon_pixbuf (NULL);
pixbuf1 = gdk_pixbuf_scale_simple (pixbuf, 16, 16, GDK_INTERP_BILINEAR);
g_object_unref (G_OBJECT (pixbuf));
}
g_free (icon_name);
} else {
pixbuf1 = get_icon_pixbuf (NULL);
}
return pixbuf1;
}
static gchar *
get_category_path_for_mime_type (const gchar *mime_type)
{
gchar *path;
path = gnome_vfs_mime_get_value (mime_type, "category");
if (path != NULL)
return path;
else if (!strncmp (mime_type, "image", strlen ("image")))
return "Images";
else if (!strncmp (mime_type, "video", strlen ("video")))
return "Video";
else if (!strncmp (mime_type, "audio", strlen ("audio")))
return "Audio";
else
return NULL;
}
static void
get_path_num_from_str (GtkTreeStore *model, GtkTreeIter *iter, const gchar *path_str, GString *path_num)
{
gchar *first_component;
gchar *rest_components;
GValue value;
GtkTreeIter child_iter;
int i, n;
if (path_str == NULL || *path_str == '\0')
return;
rest_components = strchr (path_str, '/');
if (rest_components != NULL) {
first_component = g_strndup (path_str, rest_components - path_str);
rest_components++;
} else {
first_component = g_strdup (path_str);
}
gtk_tree_model_iter_children (GTK_TREE_MODEL (model), &child_iter, iter);
n = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model), iter);
value.g_type = G_TYPE_INVALID;
for (i = 0; i < n; i++) {
gtk_tree_model_get_value (GTK_TREE_MODEL (model), &child_iter, DESCRIPTION_COLUMN, &value);
if (!strcmp (first_component, g_value_get_string (&value))) {
g_string_append_printf (path_num, ":%d", i);
get_path_num_from_str (model, &child_iter, rest_components, path_num);
g_free (first_component);
return;
}
gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &child_iter);
g_value_unset (&value);
}
gtk_tree_store_append (model, &child_iter, iter);
gtk_tree_store_set (model, &child_iter, DESCRIPTION_COLUMN, first_component, -1);
g_string_append_printf (path_num, ":%d", n);
g_free (first_component);
}
static void
get_insertion_point (GtkTreeStore *model, const gchar *path_str, GtkTreeIter *iter)
{
GString *path_num;
path_num = g_string_new ("");
get_path_num_from_str (model, NULL, path_str, path_num);
gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (model), iter, path_num->str + 1);
g_string_free (path_num, TRUE);
}
static const gchar *
get_protocol_name (const gchar *key)
{
gchar *protocol_name;
protocol_name = strrchr (key, '/');
if (protocol_name != NULL)
return protocol_name + 1;
else
return NULL;
}
static gchar *
get_description_for_protocol (const gchar *protocol_name)
{
gchar *description;
gchar *key;
int i;
key = g_strconcat ("/desktop/gnome/url-handlers/", protocol_name, "/description", NULL);
description = gconf_client_get_string (gconf_client_get_default (), key, NULL);
g_free (key);
if (description != NULL)
return description;
for (i = 0; url_descriptions[i][0] != NULL; i++)
if (!strcmp (url_descriptions[i][0], protocol_name))
return g_strdup (url_descriptions[i][1]);
return NULL;
}
GtkTreeModel *
mime_types_model_new (void)
{
GtkTreeStore *model;
GList *type_list;
GList *tmp;
GtkTreeIter iter;
GtkTreeIter child_iter;
gchar *mime_type;
gchar *path_str;
const gchar *description;
const gchar *extensions;
GdkPixbuf *pixbuf;
GSList *url_list;
GSList *tmps;
const gchar *protocol_name;
gchar *protocol_desc;
gint i;
model = gtk_tree_store_new (4, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
tmp = type_list = gnome_vfs_get_registered_mime_types ();
for (i = 0; categories[i] != NULL; i++) {
gtk_tree_store_append (model, &iter, NULL);
gtk_tree_store_set (model, &iter, DESCRIPTION_COLUMN, categories[i], -1);
}
for (; tmp != NULL; tmp = tmp->next) {
mime_type = tmp->data;
path_str = get_category_path_for_mime_type (mime_type);
if (path_str != NULL) {
description = gnome_vfs_mime_get_description (mime_type);
extensions = gnome_vfs_mime_get_extensions_pretty_string (mime_type);
if (extensions == NULL || *extensions == '\0')
continue;
pixbuf = get_icon_pixbuf (gnome_vfs_mime_get_icon (mime_type));
get_insertion_point (model, path_str, &iter);
gtk_tree_store_append (model, &child_iter, &iter);
gtk_tree_store_set (model, &child_iter,
ICON_COLUMN, pixbuf,
DESCRIPTION_COLUMN, description,
MIME_TYPE_COLUMN, mime_type,
EXTENSIONS_COLUMN, extensions,
-1);
}
}
g_list_free (type_list);
tmps = url_list = gconf_client_all_dirs
(gconf_client_get_default (), "/desktop/gnome/url-handlers", NULL);
get_insertion_point (model, "Internet Services", &iter);
for (; tmps != NULL; tmps = tmps->next) {
protocol_name = get_protocol_name (tmps->data);
if (protocol_name == NULL)
continue;
protocol_desc = get_description_for_protocol (protocol_name);
gtk_tree_store_append (model, &child_iter, &iter);
gtk_tree_store_set (model, &child_iter,
DESCRIPTION_COLUMN, protocol_desc,
MIME_TYPE_COLUMN, protocol_name,
-1);
if (strcmp (protocol_name, "unknown"))
gtk_tree_store_set (model, &child_iter, EXTENSIONS_COLUMN, protocol_name, -1);
g_free (protocol_desc);
g_free (tmps->data);
}
g_slist_free (url_list);
return GTK_TREE_MODEL (model);
}
gboolean
model_entry_is_protocol (GtkTreeModel *model, GtkTreeIter *iter)
{
GtkTreeIter parent_iter;
GtkTreePath *parent_path, *child_path;
gboolean ret;
get_insertion_point (GTK_TREE_STORE (model), "Internet Services", &parent_iter);
parent_path = gtk_tree_model_get_path (model, &parent_iter);
child_path = gtk_tree_model_get_path (model, iter);
ret = gtk_tree_path_is_ancestor (parent_path, child_path);
gtk_tree_path_free (parent_path);
gtk_tree_path_free (child_path);
return ret;
}

View file

@ -0,0 +1,45 @@
/* -*- mode: c; style: linux -*- */
/* mime-types-model.h
*
* Copyright (C) 2002 Ximian, Inc.
*
* Written by Bradford Hovinen <hovinen@ximian.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 of the
* License, 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.
*/
#ifndef __MIME_TYPES_MODEL_H
#define __MIME_TYPES_MODEL_H
#include <gnome.h>
G_BEGIN_DECLS
enum {
ICON_COLUMN,
DESCRIPTION_COLUMN,
MIME_TYPE_COLUMN,
EXTENSIONS_COLUMN
};
GtkTreeModel *mime_types_model_new (void);
gboolean model_entry_is_protocol (GtkTreeModel *model, GtkTreeIter *iter);
G_END_DECLS
#endif /* __MIME_TYPES_MODEL_H */

View file

@ -0,0 +1,270 @@
/* -*- mode: c; style: linux -*- */
/* service-edit-dialog.c
* Copyright (C) 2001 Ximian, Inc.
*
* Written by Bradford Hovinen <hovinen@ximian.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.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <glade/glade.h>
#include "service-edit-dialog.h"
#define WID(x) (glade_xml_get_widget (dialog->p->dialog_xml, x))
enum {
PROP_0,
PROP_SERVICE_INFO
};
struct _ServiceEditDialogPrivate
{
ServiceInfo *info;
GladeXML *dialog_xml;
GtkWidget *dialog_win;
};
static GObjectClass *parent_class;
static void service_edit_dialog_init (ServiceEditDialog *dialog,
ServiceEditDialogClass *class);
static void service_edit_dialog_class_init (ServiceEditDialogClass *class);
static void service_edit_dialog_base_init (ServiceEditDialogClass *class);
static void service_edit_dialog_set_prop (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void service_edit_dialog_get_prop (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void service_edit_dialog_dispose (GObject *object);
static void service_edit_dialog_finalize (GObject *object);
static void fill_dialog (ServiceEditDialog *dialog);
static void populate_app_list (ServiceEditDialog *dialog);
static void response_cb (ServiceEditDialog *dialog);
GType
service_edit_dialog_get_type (void)
{
static GType service_edit_dialog_type = 0;
if (!service_edit_dialog_type) {
GTypeInfo service_edit_dialog_info = {
sizeof (ServiceEditDialogClass),
(GBaseInitFunc) service_edit_dialog_base_init,
NULL, /* GBaseFinalizeFunc */
(GClassInitFunc) service_edit_dialog_class_init,
NULL, /* GClassFinalizeFunc */
NULL, /* user-supplied data */
sizeof (ServiceEditDialog),
0, /* n_preallocs */
(GInstanceInitFunc) service_edit_dialog_init,
NULL
};
service_edit_dialog_type =
g_type_register_static (G_TYPE_OBJECT,
"ServiceEditDialog",
&service_edit_dialog_info, 0);
}
return service_edit_dialog_type;
}
static void
service_edit_dialog_init (ServiceEditDialog *dialog, ServiceEditDialogClass *class)
{
GtkSizeGroup *size_group;
dialog->p = g_new0 (ServiceEditDialogPrivate, 1);
dialog->p->dialog_xml = glade_xml_new
(GNOMECC_DATA_DIR "/interfaces/file-types-properties.glade", "service_edit_widget", NULL);
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_size_group_add_widget (size_group, WID ("description_label"));
gtk_size_group_add_widget (size_group, WID ("protocol_label"));
dialog->p->dialog_win = gtk_dialog_new_with_buttons
(_("Edit file type"), NULL, -1,
GTK_STOCK_OK, GTK_RESPONSE_OK,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog->p->dialog_win)->vbox), WID ("service_edit_widget"), TRUE, TRUE, 0);
g_signal_connect_swapped (G_OBJECT (dialog->p->dialog_win), "response", (GCallback) response_cb, dialog);
}
static void
service_edit_dialog_base_init (ServiceEditDialogClass *class)
{
}
static void
service_edit_dialog_class_init (ServiceEditDialogClass *class)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (class);
object_class->dispose = service_edit_dialog_dispose;
object_class->finalize = service_edit_dialog_finalize;
object_class->set_property = service_edit_dialog_set_prop;
object_class->get_property = service_edit_dialog_get_prop;
g_object_class_install_property
(object_class, PROP_SERVICE_INFO,
g_param_spec_pointer ("service-info",
_("Servie information"),
_("Data structure containing service information"),
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
parent_class = G_OBJECT_CLASS
(g_type_class_ref (G_TYPE_OBJECT));
}
static void
service_edit_dialog_set_prop (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
ServiceEditDialog *dialog;
g_return_if_fail (object != NULL);
g_return_if_fail (IS_SERVICE_EDIT_DIALOG (object));
dialog = SERVICE_EDIT_DIALOG (object);
switch (prop_id) {
case PROP_SERVICE_INFO:
dialog->p->info = g_value_get_pointer (value);
fill_dialog (dialog);
break;
default:
g_warning ("Bad property set");
break;
}
}
static void
service_edit_dialog_get_prop (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
ServiceEditDialog *dialog;
g_return_if_fail (object != NULL);
g_return_if_fail (IS_SERVICE_EDIT_DIALOG (object));
dialog = SERVICE_EDIT_DIALOG (object);
switch (prop_id) {
case PROP_SERVICE_INFO:
g_value_set_pointer (value, dialog->p->info);
break;
default:
g_warning ("Bad property get");
break;
}
}
static void
service_edit_dialog_dispose (GObject *object)
{
ServiceEditDialog *dialog;
g_return_if_fail (object != NULL);
g_return_if_fail (IS_SERVICE_EDIT_DIALOG (object));
dialog = SERVICE_EDIT_DIALOG (object);
if (dialog->p->dialog_win != NULL) {
gtk_widget_destroy (dialog->p->dialog_win);
dialog->p->dialog_win = NULL;
}
if (dialog->p->dialog_xml != NULL) {
g_object_unref (G_OBJECT (dialog->p->dialog_xml));
dialog->p->dialog_xml = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
service_edit_dialog_finalize (GObject *object)
{
ServiceEditDialog *service_edit_dialog;
g_return_if_fail (object != NULL);
g_return_if_fail (IS_SERVICE_EDIT_DIALOG (object));
service_edit_dialog = SERVICE_EDIT_DIALOG (object);
g_free (service_edit_dialog->p);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
GObject *
service_edit_dialog_new (ServiceInfo *info)
{
return g_object_new (service_edit_dialog_get_type (),
"service-info", info,
NULL);
}
static void
fill_dialog (ServiceEditDialog *dialog)
{
if (dialog->p->info->description != NULL)
gtk_entry_set_text (GTK_ENTRY (WID ("description_entry")), dialog->p->info->description);
if (dialog->p->info->protocol != NULL)
gtk_entry_set_text (GTK_ENTRY (WID ("protocol_entry")), dialog->p->info->protocol);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (WID ("look_at_content_toggle")), dialog->p->info->use_content);
if (dialog->p->info->use_content && strcmp (dialog->p->info->protocol, "ftp"))
gtk_widget_set_sensitive (WID ("program_frame"), FALSE);
if (dialog->p->info->custom_line != NULL)
gnome_file_entry_set_filename (GNOME_FILE_ENTRY (WID ("custom_program_entry")), dialog->p->info->custom_line);
populate_app_list (dialog);
gtk_widget_show_all (dialog->p->dialog_win);
}
static void
populate_app_list (ServiceEditDialog *dialog)
{
}
static void
response_cb (ServiceEditDialog *dialog)
{
g_object_unref (G_OBJECT (dialog));
}

View file

@ -0,0 +1,59 @@
/* -*- mode: c; style: linux -*- */
/* service-edit-dialog.h
* Copyright (C) 2001 Ximian, Inc.
*
* Written by Bradford Hovinen <hovinen@ximian.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.
*/
#ifndef __SERVICE_EDIT_DIALOG_H
#define __SERVICE_EDIT_DIALOG_H
#include <gnome.h>
#include "service-info.h"
G_BEGIN_DECLS
#define SERVICE_EDIT_DIALOG(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, service_edit_dialog_get_type (), ServiceEditDialog)
#define SERVICE_EDIT_DIALOG_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, service_edit_dialog_get_type (), ServiceEditDialogClass)
#define IS_SERVICE_EDIT_DIALOG(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, service_edit_dialog_get_type ())
typedef struct _ServiceEditDialog ServiceEditDialog;
typedef struct _ServiceEditDialogClass ServiceEditDialogClass;
typedef struct _ServiceEditDialogPrivate ServiceEditDialogPrivate;
struct _ServiceEditDialog
{
GObject parent;
ServiceEditDialogPrivate *p;
};
struct _ServiceEditDialogClass
{
GObjectClass g_object_class;
};
GType service_edit_dialog_get_type (void);
GObject *service_edit_dialog_new (ServiceInfo *info);
G_END_DECLS
#endif /* __SERVICE_EDIT_DIALOG_H */

View file

@ -0,0 +1,163 @@
/* -*- mode: c; style: linux -*- */
/* service-info.c
*
* Copyright (C) 2002 Ximian, Inc.
*
* Written by Bradford Hovinen <hovinen@ximian.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 of the
* License, 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.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <gconf/gconf-client.h>
#include "service-info.h"
static gchar *
get_key_name (const ServiceInfo *info, gchar *end)
{
return g_strconcat ("/desktop/gnome/url-handlers/", info->protocol, "/", end, NULL);
}
static void
set_string (const ServiceInfo *info, gchar *end, gchar *value, GConfChangeSet *changeset)
{
gchar *key;
key = get_key_name (info, end);
if (changeset != NULL)
gconf_change_set_set_string (changeset, key, value);
else
gconf_client_set_string (gconf_client_get_default (), key, value, NULL);
g_free (key);
}
static void
set_bool (const ServiceInfo *info, gchar *end, gboolean value, GConfChangeSet *changeset)
{
gchar *key;
key = get_key_name (info, end);
if (changeset != NULL)
gconf_change_set_set_bool (changeset, key, value);
else
gconf_client_set_bool (gconf_client_get_default (), key, value, NULL);
g_free (key);
}
static gchar *
get_string (const ServiceInfo *info, gchar *end, GConfChangeSet *changeset)
{
gchar *key, *ret;
GConfValue *value;
gboolean found;
key = get_key_name (info, end);
if (changeset != NULL)
found = gconf_change_set_check_value (changeset, key, &value);
if (!found || changeset == NULL) {
ret = gconf_client_get_string (gconf_client_get_default (), key, NULL);
} else {
ret = g_strdup (gconf_value_get_string (value));
gconf_value_free (value);
}
g_free (key);
return ret;
}
static gboolean
get_bool (const ServiceInfo *info, gchar *end, GConfChangeSet *changeset)
{
gchar *key;
gboolean ret;
GConfValue *value;
gboolean found;
key = get_key_name (info, end);
if (changeset != NULL)
found = gconf_change_set_check_value (changeset, key, &value);
if (!found || changeset == NULL) {
ret = gconf_client_get_bool (gconf_client_get_default (), key, NULL);
} else {
ret = gconf_value_get_bool (value);
gconf_value_free (value);
}
g_free (key);
return ret;
}
ServiceInfo *
service_info_load (const gchar *protocol, GConfChangeSet *changeset)
{
ServiceInfo *info;
gchar *id;
info = g_new0 (ServiceInfo, 1);
info->protocol = g_strdup (protocol);
info->description = get_string (info, "description", changeset);
info->use_content = get_bool (info, "use-content", changeset);
info->custom_line = get_string (info, "command", changeset);
info->need_terminal = get_bool (info, "need-terminal", changeset);
id = get_string (info, "command-id", changeset);
if (id != NULL)
info->app = gnome_vfs_mime_application_new_from_id (id);
g_free (id);
return info;
}
void
service_info_save (const ServiceInfo *info, GConfChangeSet *changeset)
{
set_string (info, "description", info->description, changeset);
if (info->app == NULL) {
set_string (info, "command", info->custom_line, changeset);
set_string (info, "command-id", "", changeset);
} else {
set_string (info, "command", info->app->command, changeset);
set_string (info, "command-id", info->app->id, changeset);
}
set_bool (info, "use-content", info->use_content, changeset);
set_bool (info, "need-terminal", info->need_terminal, changeset);
}
void
service_info_free (ServiceInfo *info)
{
g_free (info->protocol);
g_free (info->description);
gnome_vfs_mime_application_free (info->app);
g_free (info->custom_line);
}

View file

@ -0,0 +1,55 @@
/* -*- mode: c; style: linux -*- */
/* service-info.h
*
* Copyright (C) 2002 Ximian, Inc.
*
* Written by Bradford Hovinen <hovinen@ximian.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 of the
* License, 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.
*/
#ifndef __SERVICE_INFO_H
#define __SERVICE_INFO_H
#include <gnome.h>
#include <bonobo.h>
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
#include <gconf/gconf-changeset.h>
G_BEGIN_DECLS
typedef struct _ServiceInfo ServiceInfo;
struct _ServiceInfo {
gchar *protocol;
gchar *description;
gboolean use_content;
GnomeVFSMimeApplication *app;
gchar *custom_line;
gboolean need_terminal;
};
ServiceInfo *service_info_load (const gchar *protocol,
GConfChangeSet *changeset);
void service_info_save (const ServiceInfo *info,
GConfChangeSet *changeset);
void service_info_free (ServiceInfo *info);
G_END_DECLS
#endif /* __SERVICE_INFO_H */