File Types and Programs capplet work in progress.
2000-06-17 Gene Z. Ragan <gzr@eazel.com> File Types and Programs capplet work in progress. * mime-type-capplet/mime-info.c: * mime-type-capplet/mime-info.h: Removed obsolete files from capplet. * mime-type-capplet/Makefile.am: Remove above files form makefile. * libgnomevfs/gnome-vfs-mime-info.c: * libgnomevfs/gnome-vfs-mime-info.h: (list_context_new), (context_destroy_and_unlink), (load_mime_type_info_from), (load_mime_list_info_from), (mime_list_load), (load_mime_type_info), (gnome_vfs_mime_init), (gnome_vfs_mime_info_clear), (gnome_vfs_mime_info_shutdown), (get_key_name), (gnome_vfs_get_registered_mime_types): Various fixes and modifications. Fixed a bug in the mime key database parser that caused comments to be read in incorrectly. * mime-type-capplet/mime-data.c: (add_to_key), (add_mime_vals_to_clist), (add_new_mime_type), (add_new_mime_type), (write_mime_foreach): Capplet work in progress. * mime-type-capplet/nautilus-mime-type-capplet-dialogs.c: (nautilus_mime_type_capplet_show_new_mime_window): Capplet work in progress. * mime-type-capplet/nautilus-mime-type-capplet.c: * mime-type-capplet/nautilus-mime-type-capplet.h: (main), (g_list_free_deep), (try_callback), (revert_callback), (ok_callback), (cancel_callback), (populate_extension_list), (mime_list_selected_row_callback), (init_mime_capplet), (nautilus_mime_type_capplet_update_info), (delete_mime_clicked), (edit_applications_clicked), (edit_components_clicked), (insert_mime_vals_into_clist), (create_mime_list_and_scroller): Capplet work in progress.
This commit is contained in:
parent
662a6f1803
commit
bb5059111b
8 changed files with 232 additions and 935 deletions
|
@ -10,10 +10,7 @@ bin_PROGRAMS = nautilus-mime-type-capplet
|
||||||
nautilus_mime_type_capplet_SOURCES =\
|
nautilus_mime_type_capplet_SOURCES =\
|
||||||
nautilus-mime-type-capplet.c\
|
nautilus-mime-type-capplet.c\
|
||||||
nautilus-mime-type-capplet-dialogs.c\
|
nautilus-mime-type-capplet-dialogs.c\
|
||||||
mime-data.h \
|
mime-data.c
|
||||||
mime-data.c \
|
|
||||||
mime-info.c \
|
|
||||||
mime-info.h
|
|
||||||
|
|
||||||
nautilus_mime_type_capplet_LDADD =\
|
nautilus_mime_type_capplet_LDADD =\
|
||||||
$(CAPPLET_LIBDIR) \
|
$(CAPPLET_LIBDIR) \
|
||||||
|
|
|
@ -533,7 +533,6 @@ nautilus_mime_type_capplet_show_new_mime_window (void)
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog;
|
||||||
GtkWidget *mime_entry;
|
GtkWidget *mime_entry;
|
||||||
GtkWidget *label;
|
GtkWidget *label;
|
||||||
GtkWidget *frame;
|
|
||||||
GtkWidget *ext_entry;
|
GtkWidget *ext_entry;
|
||||||
GtkWidget *hbox;
|
GtkWidget *hbox;
|
||||||
GtkWidget *vbox;
|
GtkWidget *vbox;
|
||||||
|
@ -552,18 +551,18 @@ nautilus_mime_type_capplet_show_new_mime_window (void)
|
||||||
gtk_box_pack_start (GTK_BOX (hbox), mime_entry, TRUE, TRUE, 0);
|
gtk_box_pack_start (GTK_BOX (hbox), mime_entry, TRUE, TRUE, 0);
|
||||||
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 0);
|
||||||
|
|
||||||
frame = gtk_frame_new (_("Extensions"));
|
|
||||||
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), frame, FALSE, FALSE, 0);
|
|
||||||
vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL);
|
vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL);
|
||||||
|
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), vbox, FALSE, FALSE, 0);
|
||||||
|
//gtk_container_add (GTK_CONTAINER (frame), vbox);
|
||||||
gtk_container_set_border_width (GTK_CONTAINER (vbox), GNOME_PAD_SMALL);
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), GNOME_PAD_SMALL);
|
||||||
label = gtk_label_new (_("Type in the extensions for this mime-type.\nFor example: .html, .htm"));
|
label = gtk_label_new (_("Type in a description for this mime-type."));
|
||||||
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
|
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
|
||||||
hbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL);
|
hbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL);
|
||||||
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
||||||
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
|
||||||
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
||||||
hbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL);
|
hbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL);
|
||||||
gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (_("Extension:")), FALSE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (_("Description:")), FALSE, FALSE, 0);
|
||||||
ext_entry = gtk_entry_new ();
|
ext_entry = gtk_entry_new ();
|
||||||
gtk_box_pack_start (GTK_BOX (hbox), ext_entry, TRUE, TRUE, 0);
|
gtk_box_pack_start (GTK_BOX (hbox), ext_entry, TRUE, TRUE, 0);
|
||||||
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
||||||
|
|
|
@ -39,20 +39,22 @@
|
||||||
#include <libgnomevfs/gnome-vfs-mime-info.h>
|
#include <libgnomevfs/gnome-vfs-mime-info.h>
|
||||||
|
|
||||||
#include "mime-data.h"
|
#include "mime-data.h"
|
||||||
#include "mime-info.h"
|
//#include "mime-info.h"
|
||||||
#include "nautilus-mime-type-capplet-dialogs.h"
|
#include "nautilus-mime-type-capplet-dialogs.h"
|
||||||
|
|
||||||
#include "nautilus-mime-type-capplet.h"
|
#include "nautilus-mime-type-capplet.h"
|
||||||
|
|
||||||
|
|
||||||
/* Local Prototypes */
|
/* Local Prototypes */
|
||||||
static void init_mime_capplet (void);
|
static void init_mime_capplet (void);
|
||||||
static void populate_application_menu (GtkWidget *menu, const char *mime_string);
|
static void populate_application_menu (GtkWidget *menu, const char *mime_string);
|
||||||
static void populate_component_menu (GtkWidget *menu, const char *mime_string);
|
static void populate_component_menu (GtkWidget *menu, const char *mime_string);
|
||||||
static void delete_mime_clicked (GtkWidget *widget, gpointer data);
|
static void delete_mime_clicked (GtkWidget *widget, gpointer data);
|
||||||
static void add_mime_clicked (GtkWidget *widget, gpointer data);
|
static void add_mime_clicked (GtkWidget *widget, gpointer data);
|
||||||
static void edit_applications_clicked (GtkWidget *widget, gpointer data);
|
static void edit_applications_clicked (GtkWidget *widget, gpointer data);
|
||||||
static void edit_components_clicked (GtkWidget *widget, gpointer data);
|
static void edit_components_clicked (GtkWidget *widget, gpointer data);
|
||||||
|
static GtkWidget *create_mime_list_and_scroller (void);
|
||||||
|
|
||||||
|
|
||||||
static void try_callback (void);
|
static void try_callback (void);
|
||||||
static void revert_callback (void);
|
static void revert_callback (void);
|
||||||
|
@ -94,13 +96,19 @@ main (int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (init_results == 0) {
|
if (init_results == 0) {
|
||||||
init_mime_type ();
|
|
||||||
init_mime_capplet ();
|
init_mime_capplet ();
|
||||||
capplet_gtk_main ();
|
capplet_gtk_main ();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
g_list_free_deep (GList *list)
|
||||||
|
{
|
||||||
|
g_list_foreach (list, (GFunc) g_free, NULL);
|
||||||
|
g_list_free (list);
|
||||||
|
}
|
||||||
|
|
||||||
static GtkWidget *
|
static GtkWidget *
|
||||||
left_aligned_button (gchar *label)
|
left_aligned_button (gchar *label)
|
||||||
{
|
{
|
||||||
|
@ -116,31 +124,31 @@ left_aligned_button (gchar *label)
|
||||||
static void
|
static void
|
||||||
try_callback ()
|
try_callback ()
|
||||||
{
|
{
|
||||||
write_user_keys ();
|
//write_user_keys ();
|
||||||
write_user_mime ();
|
//write_user_mime ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
revert_callback ()
|
revert_callback ()
|
||||||
{
|
{
|
||||||
write_initial_keys ();
|
//write_initial_keys ();
|
||||||
write_initial_mime ();
|
//write_initial_mime ();
|
||||||
discard_key_info ();
|
//discard_key_info ();
|
||||||
discard_mime_info ();
|
//discard_mime_info ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ok_callback ()
|
ok_callback ()
|
||||||
{
|
{
|
||||||
write_user_keys ();
|
//write_user_keys ();
|
||||||
write_user_mime ();
|
//write_user_mime ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cancel_callback ()
|
cancel_callback ()
|
||||||
{
|
{
|
||||||
write_initial_keys ();
|
//write_initial_keys ();
|
||||||
write_initial_mime ();
|
//write_initial_mime ();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -152,15 +160,20 @@ help_callback ()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
populate_extension_list (const MimeInfo *info, GtkCList *list)
|
populate_extension_list (const char *mime_type, GtkCList *list)
|
||||||
{
|
{
|
||||||
GList *element;
|
//GList *element;
|
||||||
gchar *extension[1];
|
//gchar *extension[1];
|
||||||
gint row;
|
//gint row;
|
||||||
|
|
||||||
|
if (mime_type == NULL || list == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Clear out old items */
|
/* Clear out old items */
|
||||||
gtk_clist_clear (list);
|
gtk_clist_clear (list);
|
||||||
|
|
||||||
|
/*
|
||||||
if (info->ext[0]) {
|
if (info->ext[0]) {
|
||||||
for (element = info->ext[0]; element; element = element->next) {
|
for (element = info->ext[0]; element; element = element->next) {
|
||||||
extension[0] = g_strdup (element->data);
|
extension[0] = g_strdup (element->data);
|
||||||
|
@ -176,6 +189,7 @@ populate_extension_list (const MimeInfo *info, GtkCList *list)
|
||||||
gtk_clist_set_row_data (list, row, GINT_TO_POINTER (FALSE));
|
gtk_clist_set_row_data (list, row, GINT_TO_POINTER (FALSE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/* Select first item in extension list */
|
/* Select first item in extension list */
|
||||||
gtk_clist_select_row (list, 0, 0);
|
gtk_clist_select_row (list, 0, 0);
|
||||||
|
@ -268,6 +282,26 @@ extension_list_deselected (GtkWidget *clist, gint row, gint column, gpointer dat
|
||||||
gtk_widget_set_sensitive (remove_button, FALSE);
|
gtk_widget_set_sensitive (remove_button, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mime_list_selected_row_callback (GtkWidget *widget, gint row, gint column, GdkEvent *event, gpointer data)
|
||||||
|
{
|
||||||
|
const char *mime_type;
|
||||||
|
|
||||||
|
if (column < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
mime_type = (const char *) gtk_clist_get_row_data (GTK_CLIST (widget),row);
|
||||||
|
|
||||||
|
/* Update info on selection */
|
||||||
|
nautilus_mime_type_capplet_update_info (mime_type);
|
||||||
|
|
||||||
|
/* FIXME: Get user mime info */
|
||||||
|
//if (g_hash_table_lookup (user_mime_types, mi->mime_type)) {
|
||||||
|
// gtk_widget_set_sensitive (delete_button, TRUE);
|
||||||
|
//} else
|
||||||
|
// gtk_widget_set_sensitive (delete_button, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_mime_capplet (void)
|
init_mime_capplet (void)
|
||||||
{
|
{
|
||||||
|
@ -279,7 +313,6 @@ init_mime_capplet (void)
|
||||||
GtkWidget *icon_entry;
|
GtkWidget *icon_entry;
|
||||||
GtkWidget *mime_list_container;
|
GtkWidget *mime_list_container;
|
||||||
GtkWidget *extension_scroller;
|
GtkWidget *extension_scroller;
|
||||||
GList *children, *child;
|
|
||||||
|
|
||||||
gchar *title[2] = {"Extensions"};
|
gchar *title[2] = {"Extensions"};
|
||||||
|
|
||||||
|
@ -293,14 +326,9 @@ init_mime_capplet (void)
|
||||||
/* Main horizontal box and mime list*/
|
/* Main horizontal box and mime list*/
|
||||||
hbox = gtk_hbox_new (FALSE, GNOME_PAD);
|
hbox = gtk_hbox_new (FALSE, GNOME_PAD);
|
||||||
gtk_box_pack_start (GTK_BOX (main_vbox), hbox, TRUE, TRUE, 0);
|
gtk_box_pack_start (GTK_BOX (main_vbox), hbox, TRUE, TRUE, 0);
|
||||||
mime_list_container = create_mime_clist ();
|
mime_list_container = create_mime_list_and_scroller ();
|
||||||
gtk_box_pack_start (GTK_BOX (hbox), mime_list_container, TRUE, TRUE, 0);
|
gtk_box_pack_start (GTK_BOX (hbox), mime_list_container, TRUE, TRUE, 0);
|
||||||
|
|
||||||
/* Get pointer to mime list */
|
|
||||||
children = gtk_container_children (GTK_CONTAINER (mime_list_container));
|
|
||||||
child = g_list_first (children);
|
|
||||||
mime_list = child->data;
|
|
||||||
|
|
||||||
vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL);
|
vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL);
|
||||||
|
|
||||||
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
|
||||||
|
@ -407,6 +435,9 @@ init_mime_capplet (void)
|
||||||
GTK_SIGNAL_FUNC(help_callback), NULL);
|
GTK_SIGNAL_FUNC(help_callback), NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
gtk_signal_connect (GTK_OBJECT (mime_list),"select_row",
|
||||||
|
GTK_SIGNAL_FUNC (mime_list_selected_row_callback), NULL);
|
||||||
|
|
||||||
/* Select first item in list and update menus */
|
/* Select first item in list and update menus */
|
||||||
gtk_clist_select_row (GTK_CLIST (mime_list), 0, 0);
|
gtk_clist_select_row (GTK_CLIST (mime_list), 0, 0);
|
||||||
}
|
}
|
||||||
|
@ -419,21 +450,21 @@ init_mime_capplet (void)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
nautilus_mime_type_capplet_update_info (const MimeInfo *info) {
|
nautilus_mime_type_capplet_update_info (const char *mime_type) {
|
||||||
|
|
||||||
/* Update frame label with mime type */
|
/* Update frame label with mime type */
|
||||||
gtk_frame_set_label (GTK_FRAME (info_frame), info->mime_type);
|
gtk_frame_set_label (GTK_FRAME (info_frame), mime_type);
|
||||||
|
|
||||||
/* Update menus */
|
/* Update menus */
|
||||||
populate_application_menu (application_menu, info->mime_type);
|
populate_application_menu (application_menu, mime_type);
|
||||||
populate_component_menu (component_menu, info->mime_type);
|
populate_component_menu (component_menu, mime_type);
|
||||||
|
|
||||||
/* Update extesnions list */
|
/* Update extesnions list */
|
||||||
populate_extension_list (info, GTK_CLIST (extension_list));
|
populate_extension_list (mime_type, GTK_CLIST (extension_list));
|
||||||
|
|
||||||
/* Set icon for mime type */
|
/* Set icon for mime type */
|
||||||
gnome_icon_entry_set_icon (GNOME_ICON_ENTRY (icon_entry),
|
gnome_icon_entry_set_icon (GNOME_ICON_ENTRY (icon_entry),
|
||||||
gnome_vfs_mime_get_value (info->mime_type, "icon-filename"));
|
gnome_vfs_mime_get_value (mime_type, "icon-filename"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -581,10 +612,6 @@ populate_component_menu (GtkWidget *component_menu, const char *mime_string)
|
||||||
gtk_option_menu_set_menu (GTK_OPTION_MENU (component_menu), new_menu);
|
gtk_option_menu_set_menu (GTK_OPTION_MENU (component_menu), new_menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
free_mime_info (MimeInfo *mi)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* delete_mime_clicked
|
* delete_mime_clicked
|
||||||
|
@ -595,19 +622,19 @@ free_mime_info (MimeInfo *mi)
|
||||||
static void
|
static void
|
||||||
delete_mime_clicked (GtkWidget *widget, gpointer data)
|
delete_mime_clicked (GtkWidget *widget, gpointer data)
|
||||||
{
|
{
|
||||||
MimeInfo *mi;
|
const char *mime_type;
|
||||||
gint row = 0;
|
gint row = 0;
|
||||||
|
|
||||||
if (GTK_CLIST (mime_list)->selection)
|
if (GTK_CLIST (mime_list)->selection)
|
||||||
row = GPOINTER_TO_INT ((GTK_CLIST (mime_list)->selection)->data);
|
row = GPOINTER_TO_INT ((GTK_CLIST (mime_list)->selection)->data);
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
mi = (MimeInfo *) gtk_clist_get_row_data (GTK_CLIST (mime_list), row);
|
mime_type = (const char *) gtk_clist_get_row_data (GTK_CLIST (mime_list), row);
|
||||||
|
|
||||||
gtk_clist_remove (GTK_CLIST (mime_list), row);
|
gtk_clist_remove (GTK_CLIST (mime_list), row);
|
||||||
g_hash_table_remove (user_mime_types, mi->mime_type);
|
/* FIXME: Get user mime info */
|
||||||
remove_mime_info (mi->mime_type);
|
//g_hash_table_remove (user_mime_types, mi->mime_type);
|
||||||
free_mime_info (mi);
|
//remove_mime_info (mi->mime_type);
|
||||||
capplet_widget_state_changed (CAPPLET_WIDGET (capplet),
|
capplet_widget_state_changed (CAPPLET_WIDGET (capplet),
|
||||||
TRUE);
|
TRUE);
|
||||||
}
|
}
|
||||||
|
@ -622,7 +649,7 @@ static void
|
||||||
edit_applications_clicked (GtkWidget *widget, gpointer data)
|
edit_applications_clicked (GtkWidget *widget, gpointer data)
|
||||||
{
|
{
|
||||||
GtkWidget *list;
|
GtkWidget *list;
|
||||||
MimeInfo *mi;
|
const char *mime_type;
|
||||||
GList *p;
|
GList *p;
|
||||||
GtkCListRow *row;
|
GtkCListRow *row;
|
||||||
|
|
||||||
|
@ -644,15 +671,15 @@ edit_applications_clicked (GtkWidget *widget, gpointer data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show dialog */
|
/* Show dialog */
|
||||||
mi = (MimeInfo *) row->data;
|
mime_type = (const char *) row->data;
|
||||||
show_edit_applications_dialog (mi->mime_type);
|
show_edit_applications_dialog (mime_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
edit_components_clicked (GtkWidget *widget, gpointer data)
|
edit_components_clicked (GtkWidget *widget, gpointer data)
|
||||||
{
|
{
|
||||||
GtkWidget *list;
|
GtkWidget *list;
|
||||||
MimeInfo *mi;
|
const char *mime_type;
|
||||||
GList *p;
|
GList *p;
|
||||||
GtkCListRow *row;
|
GtkCListRow *row;
|
||||||
|
|
||||||
|
@ -674,8 +701,8 @@ edit_components_clicked (GtkWidget *widget, gpointer data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show dialog */
|
/* Show dialog */
|
||||||
mi = (MimeInfo *) row->data;
|
mime_type = (const char *) row->data;
|
||||||
show_edit_components_dialog (mi->mime_type);
|
show_edit_components_dialog (mime_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -704,3 +731,66 @@ nautilus_mime_type_capplet_update_component_info (const char *mime_type)
|
||||||
populate_component_menu (component_menu, mime_type);
|
populate_component_menu (component_menu, mime_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
insert_mime_vals_into_clist (GList *type_list, GtkCList *clist)
|
||||||
|
{
|
||||||
|
static gchar *text[2];
|
||||||
|
const char *description;
|
||||||
|
char *mime_string;
|
||||||
|
gint row;
|
||||||
|
GList *element;
|
||||||
|
|
||||||
|
for (element = type_list; element != NULL; element= element->next) {
|
||||||
|
mime_string = (char *)element->data;
|
||||||
|
|
||||||
|
/* Make sure we do not include comments */
|
||||||
|
if (mime_string[0] != '#') {
|
||||||
|
/* Add mime type to first column */
|
||||||
|
text[0] = mime_string;
|
||||||
|
|
||||||
|
/* Add description to second column */
|
||||||
|
description = gnome_vfs_mime_description (mime_string);
|
||||||
|
if (description != NULL && strlen (description) > 0) {
|
||||||
|
text[1] = g_strdup (description);
|
||||||
|
} else {
|
||||||
|
text[1] = g_strdup ("");
|
||||||
|
}
|
||||||
|
|
||||||
|
row = gtk_clist_insert (GTK_CLIST (clist), 1, text);
|
||||||
|
gtk_clist_set_row_data (GTK_CLIST (clist), row, g_strdup(mime_string));
|
||||||
|
|
||||||
|
g_free (text[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static GtkWidget *
|
||||||
|
create_mime_list_and_scroller (void)
|
||||||
|
{
|
||||||
|
GtkWidget *window;
|
||||||
|
gchar *titles[3];
|
||||||
|
GList *type_list;
|
||||||
|
|
||||||
|
titles[0] = _("Mime Type");
|
||||||
|
titles[1] = _("Description");
|
||||||
|
titles[2] = _("Application");
|
||||||
|
|
||||||
|
window = gtk_scrolled_window_new (NULL, NULL);
|
||||||
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (window),
|
||||||
|
GTK_POLICY_AUTOMATIC,
|
||||||
|
GTK_POLICY_AUTOMATIC);
|
||||||
|
mime_list = gtk_clist_new_with_titles (3, titles);
|
||||||
|
gtk_clist_set_selection_mode (GTK_CLIST (mime_list), GTK_SELECTION_BROWSE);
|
||||||
|
gtk_clist_set_auto_sort (GTK_CLIST (mime_list), TRUE);
|
||||||
|
|
||||||
|
type_list = gnome_vfs_get_registered_mime_types ();
|
||||||
|
insert_mime_vals_into_clist (type_list, GTK_CLIST (mime_list));
|
||||||
|
g_list_free_deep (type_list);
|
||||||
|
|
||||||
|
gtk_clist_columns_autosize (GTK_CLIST (mime_list));
|
||||||
|
gtk_clist_select_row (GTK_CLIST (mime_list), 0, 0);
|
||||||
|
gtk_container_add (GTK_CONTAINER (window), mime_list);
|
||||||
|
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#include "mime-data.h"
|
#include "mime-data.h"
|
||||||
|
|
||||||
void nautilus_mime_type_capplet_update_info (const MimeInfo *info);
|
void nautilus_mime_type_capplet_update_info (const char *mime_type);
|
||||||
void nautilus_mime_type_capplet_update_application_info (const char *mime_type);
|
void nautilus_mime_type_capplet_update_application_info (const char *mime_type);
|
||||||
void nautilus_mime_type_capplet_update_component_info (const char *mime_type);
|
void nautilus_mime_type_capplet_update_component_info (const char *mime_type);
|
||||||
void nautilus_mime_type_capplet_add_extension (const char *extension);
|
void nautilus_mime_type_capplet_add_extension (const char *extension);
|
||||||
|
|
|
@ -25,26 +25,24 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include "capplet-widget.h"
|
#include <capplet-widget.h>
|
||||||
#include "gnome.h"
|
#include <gnome.h>
|
||||||
#include <string.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <regex.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include "mime-data.h"
|
|
||||||
#include "mime-info.h"
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#include <libgnomevfs/gnome-vfs-mime-info.h>
|
#include <libgnomevfs/gnome-vfs-mime-info.h>
|
||||||
|
|
||||||
|
#include "mime-data.h"
|
||||||
#include "nautilus-mime-type-capplet.h"
|
#include "nautilus-mime-type-capplet.h"
|
||||||
|
|
||||||
|
#define MIME_COMMENT_CHAR '#'
|
||||||
|
|
||||||
/* Prototypes */
|
/* Prototypes */
|
||||||
static void mime_fill_from_file (const char *filename, gboolean init_user);
|
|
||||||
static void mime_load_from_dir (const char *mime_info_dir, gboolean system_dir);
|
|
||||||
void add_to_key (char *mime_type, char *def, GHashTable *table, gboolean init_user);
|
void add_to_key (char *mime_type, char *def, GHashTable *table, gboolean init_user);
|
||||||
static char *get_priority (char *def, int *priority);
|
static char *get_priority (char *def, int *priority);
|
||||||
|
|
||||||
|
@ -71,6 +69,7 @@ run_error (gchar *message)
|
||||||
NULL);
|
NULL);
|
||||||
gnome_dialog_run_and_close (GNOME_DIALOG (error_box));
|
gnome_dialog_run_and_close (GNOME_DIALOG (error_box));
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
get_priority (char *def, int *priority)
|
get_priority (char *def, int *priority)
|
||||||
{
|
{
|
||||||
|
@ -105,16 +104,10 @@ add_to_key (char *mime_type, char *def, GHashTable *table, gboolean init_user)
|
||||||
if (info == NULL) {
|
if (info == NULL) {
|
||||||
info = g_malloc (sizeof (MimeInfo));
|
info = g_malloc (sizeof (MimeInfo));
|
||||||
info->mime_type = g_strdup (mime_type);
|
info->mime_type = g_strdup (mime_type);
|
||||||
info->regex[0] = NULL;
|
|
||||||
info->regex[1] = NULL;
|
|
||||||
info->ext[0] = NULL;
|
info->ext[0] = NULL;
|
||||||
info->ext[1] = NULL;
|
info->ext[1] = NULL;
|
||||||
info->user_ext[0] = NULL;
|
info->user_ext[0] = NULL;
|
||||||
info->user_ext[1] = NULL;
|
info->user_ext[1] = NULL;
|
||||||
info->regex_readable[0] = NULL;
|
|
||||||
info->regex_readable[1] = NULL;
|
|
||||||
info->ext_readable[0] = NULL;
|
|
||||||
info->ext_readable[1] = NULL;
|
|
||||||
info->keys = gnome_vfs_mime_get_keys (mime_type);
|
info->keys = gnome_vfs_mime_get_keys (mime_type);
|
||||||
g_hash_table_insert (table, info->mime_type, info);
|
g_hash_table_insert (table, info->mime_type, info);
|
||||||
}
|
}
|
||||||
|
@ -145,149 +138,26 @@ add_to_key (char *mime_type, char *def, GHashTable *table, gboolean init_user)
|
||||||
g_free (p);
|
g_free (p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp (def, "regex", 5) == 0) {
|
|
||||||
regex_t *regex;
|
|
||||||
|
|
||||||
regex = g_new (regex_t, 1);
|
|
||||||
def += 5;
|
|
||||||
def = get_priority (def, &priority);
|
|
||||||
|
|
||||||
while (*def && isspace (*def))
|
|
||||||
def++;
|
|
||||||
|
|
||||||
if (!*def) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (regcomp (regex, def, REG_EXTENDED | REG_NOSUB)) {
|
|
||||||
g_free (regex);
|
|
||||||
} else {
|
|
||||||
info->regex[priority] = regex;
|
|
||||||
g_free (info->regex_readable[priority]);
|
|
||||||
info->regex_readable[priority] = g_strdup (def);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
mime_fill_from_file (const char *filename, gboolean init_user)
|
|
||||||
{
|
|
||||||
FILE *f;
|
|
||||||
char buf [1024];
|
|
||||||
char *current_key;
|
|
||||||
gboolean used;
|
|
||||||
|
|
||||||
g_assert (filename != NULL);
|
|
||||||
|
|
||||||
f = fopen (filename, "r");
|
int
|
||||||
if (!f)
|
|
||||||
return;
|
|
||||||
|
|
||||||
current_key = NULL;
|
|
||||||
used = FALSE;
|
|
||||||
while (fgets (buf, sizeof (buf), f)){
|
|
||||||
char *p;
|
|
||||||
|
|
||||||
if (buf [0] == '#')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* Trim trailing spaces */
|
|
||||||
for (p = buf + strlen (buf) - 1; p >= buf; p--){
|
|
||||||
if (isspace (*p) || *p == '\n')
|
|
||||||
*p = 0;
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!buf [0])
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (buf [0] == '\t' || buf [0] == ' '){
|
|
||||||
if (current_key){
|
|
||||||
char *p = buf;
|
|
||||||
|
|
||||||
while (*p && isspace (*p))
|
|
||||||
p++;
|
|
||||||
|
|
||||||
if (*p == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
add_to_key (current_key, p, mime_types, init_user);
|
|
||||||
if (init_user) {
|
|
||||||
add_to_key (current_key, p,
|
|
||||||
initial_user_mime_types,
|
|
||||||
TRUE);
|
|
||||||
add_to_key (current_key, p,
|
|
||||||
user_mime_types, TRUE);
|
|
||||||
}
|
|
||||||
used = TRUE;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!used && current_key)
|
|
||||||
g_free (current_key);
|
|
||||||
current_key = g_strdup (buf);
|
|
||||||
if (current_key [strlen (current_key)-1] == ':')
|
|
||||||
current_key [strlen (current_key)-1] = 0;
|
|
||||||
|
|
||||||
used = FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose (f);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
mime_load_from_dir (const char *mime_info_dir, gboolean system_dir)
|
|
||||||
{
|
|
||||||
DIR *dir;
|
|
||||||
struct dirent *dent;
|
|
||||||
const int extlen = sizeof (".mime") - 1;
|
|
||||||
char *filename;
|
|
||||||
|
|
||||||
dir = opendir (mime_info_dir);
|
|
||||||
if (!dir)
|
|
||||||
return;
|
|
||||||
if (system_dir) {
|
|
||||||
filename = g_concat_dir_and_file (mime_info_dir, "gnome.mime");
|
|
||||||
mime_fill_from_file (filename, FALSE);
|
|
||||||
g_free (filename);
|
|
||||||
}
|
|
||||||
while ((dent = readdir (dir)) != NULL){
|
|
||||||
|
|
||||||
int len = strlen (dent->d_name);
|
|
||||||
|
|
||||||
if (len <= extlen)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (strcmp (dent->d_name + len - extlen, ".mime"))
|
|
||||||
continue;
|
|
||||||
if (system_dir && !strcmp (dent->d_name, "gnome.mime"))
|
|
||||||
continue;
|
|
||||||
if (!system_dir && !strcmp (dent->d_name, "user.mime"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
filename = g_concat_dir_and_file (mime_info_dir, dent->d_name);
|
|
||||||
mime_fill_from_file (filename, FALSE);
|
|
||||||
g_free (filename);
|
|
||||||
}
|
|
||||||
if (!system_dir) {
|
|
||||||
filename = g_concat_dir_and_file (mime_info_dir, "user.mime");
|
|
||||||
mime_fill_from_file (filename, TRUE);
|
|
||||||
g_free (filename);
|
|
||||||
}
|
|
||||||
closedir (dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
add_mime_vals_to_clist (gchar *mime_type, gpointer mi, gpointer cl)
|
add_mime_vals_to_clist (gchar *mime_type, gpointer mi, gpointer cl)
|
||||||
{
|
{
|
||||||
static gchar *text[2];
|
static gchar *text[2];
|
||||||
const char *description;
|
const char *description;
|
||||||
|
MimeInfo *info;
|
||||||
gint row;
|
gint row;
|
||||||
|
|
||||||
|
/* Skip comments */
|
||||||
|
if (mime_type[0] == MIME_COMMENT_CHAR) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
info = (MimeInfo *) mi;
|
||||||
|
|
||||||
/* Add mime type to first column */
|
/* Add mime type to first column */
|
||||||
text[0] = ((MimeInfo *) mi)->mime_type;
|
text[0] = info->mime_type;
|
||||||
|
|
||||||
/* Add description to second column */
|
/* Add description to second column */
|
||||||
description = gnome_vfs_mime_description (mime_type);
|
description = gnome_vfs_mime_description (mime_type);
|
||||||
|
@ -305,142 +175,67 @@ add_mime_vals_to_clist (gchar *mime_type, gpointer mi, gpointer cl)
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
selected_row_callback (GtkWidget *widget, gint row, gint column, GdkEvent *event, gpointer data)
|
|
||||||
{
|
|
||||||
MimeInfo *mi;
|
|
||||||
|
|
||||||
if (column < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
mi = (MimeInfo *) gtk_clist_get_row_data (GTK_CLIST (widget),row);
|
|
||||||
|
|
||||||
/* Update info on selection */
|
|
||||||
nautilus_mime_type_capplet_update_info (mi);
|
|
||||||
|
|
||||||
if (g_hash_table_lookup (user_mime_types, mi->mime_type)) {
|
|
||||||
gtk_widget_set_sensitive (delete_button, TRUE);
|
|
||||||
} else
|
|
||||||
gtk_widget_set_sensitive (delete_button, FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* create_mime_clist:
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
GtkWidget *
|
|
||||||
create_mime_clist (void)
|
|
||||||
{
|
|
||||||
GtkWidget *window;
|
|
||||||
gchar *titles[3];
|
|
||||||
|
|
||||||
titles[0] = _("Mime Type");
|
|
||||||
titles[1] = _("Description");
|
|
||||||
titles[2] = _("Application");
|
|
||||||
|
|
||||||
window = gtk_scrolled_window_new (NULL, NULL);
|
|
||||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (window),
|
|
||||||
GTK_POLICY_AUTOMATIC,
|
|
||||||
GTK_POLICY_AUTOMATIC);
|
|
||||||
clist = gtk_clist_new_with_titles (3, titles);
|
|
||||||
gtk_signal_connect (GTK_OBJECT (clist),"select_row",
|
|
||||||
GTK_SIGNAL_FUNC (selected_row_callback), NULL);
|
|
||||||
gtk_clist_set_selection_mode (GTK_CLIST (clist), GTK_SELECTION_BROWSE);
|
|
||||||
gtk_clist_set_auto_sort (GTK_CLIST (clist), TRUE);
|
|
||||||
|
|
||||||
g_hash_table_foreach (mime_types, (GHFunc) add_mime_vals_to_clist, clist);
|
|
||||||
|
|
||||||
gtk_clist_columns_autosize (GTK_CLIST (clist));
|
|
||||||
gtk_clist_select_row (GTK_CLIST (clist), 0, 0);
|
|
||||||
gtk_container_add (GTK_CONTAINER (window), clist);
|
|
||||||
|
|
||||||
return window;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
finalize_mime_type_foreach (gpointer mime_type, gpointer info, gpointer data)
|
|
||||||
{
|
|
||||||
MimeInfo *mi = (MimeInfo *)info;
|
|
||||||
GList *list;
|
|
||||||
GString *extension;
|
|
||||||
|
|
||||||
extension = g_string_new ("");
|
|
||||||
for (list = ((MimeInfo *) mi)->ext[0];list; list=list->next) {
|
|
||||||
g_string_append (extension, (gchar *) list->data);
|
|
||||||
if (list->next != NULL)
|
|
||||||
g_string_append (extension, ", ");
|
|
||||||
}
|
|
||||||
if (strcmp (extension->str, "") != 0 && mi->user_ext[0])
|
|
||||||
g_string_append (extension, ", ");
|
|
||||||
for (list = ((MimeInfo *) mi)->user_ext[0]; list; list=list->next) {
|
|
||||||
g_string_append (extension, (gchar *) list->data);
|
|
||||||
if (list->next != NULL)
|
|
||||||
g_string_append (extension, ", ");
|
|
||||||
}
|
|
||||||
((MimeInfo *) mi)->ext_readable[0] = extension->str;
|
|
||||||
g_string_free (extension, FALSE);
|
|
||||||
|
|
||||||
extension = g_string_new ("");
|
|
||||||
for (list = ((MimeInfo *) mi)->ext[1];list; list=list->next) {
|
|
||||||
g_string_append (extension, (gchar *) list->data);
|
|
||||||
if (list->next)
|
|
||||||
g_string_append (extension, ", ");
|
|
||||||
}
|
|
||||||
if (strcmp (extension->str, "") != 0 && mi->user_ext[1])
|
|
||||||
g_string_append (extension, ", ");
|
|
||||||
for (list = ((MimeInfo *) mi)->user_ext[1]; list; list=list->next) {
|
|
||||||
g_string_append (extension, (gchar *) list->data);
|
|
||||||
if (list->next != NULL)
|
|
||||||
g_string_append (extension, ", ");
|
|
||||||
}
|
|
||||||
((MimeInfo *) mi)->ext_readable[1] = extension->str;
|
|
||||||
g_string_free (extension, FALSE);
|
|
||||||
|
|
||||||
if (((MimeInfo *) mi)->ext[0] || ((MimeInfo *) mi)->user_ext[0]) {
|
|
||||||
extension = g_string_new ((((MimeInfo *) mi)->ext_readable[0]));
|
|
||||||
if (((MimeInfo *) mi)->ext[1] || ((MimeInfo *) mi)->user_ext[1]) {
|
|
||||||
g_string_append (extension, ", ");
|
|
||||||
g_string_append (extension, (((MimeInfo *) mi)->ext_readable[1]));
|
|
||||||
}
|
|
||||||
} else if (((MimeInfo *) mi)->ext[1] || ((MimeInfo *) mi)->user_ext[1])
|
|
||||||
extension = g_string_new ((((MimeInfo *) mi)->ext_readable[1]));
|
|
||||||
else
|
|
||||||
extension = g_string_new ("");
|
|
||||||
g_string_free (extension, TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
finalize_user_mime (void)
|
|
||||||
{
|
|
||||||
g_hash_table_foreach (user_mime_types, finalize_mime_type_foreach, NULL);
|
|
||||||
g_hash_table_foreach (initial_user_mime_types, finalize_mime_type_foreach, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
init_mime_type (void)
|
add_new_mime_type (gchar *mime_type, gchar *description)
|
||||||
{
|
{
|
||||||
char *mime_info_dir;
|
gchar *temp;
|
||||||
|
MimeInfo *mi = NULL;
|
||||||
mime_types = g_hash_table_new (g_str_hash, g_str_equal);
|
gint row;
|
||||||
initial_user_mime_types = g_hash_table_new (g_str_hash, g_str_equal);
|
gchar *desc_key = NULL;
|
||||||
user_mime_types = g_hash_table_new (g_str_hash, g_str_equal);
|
gchar *ptr, *ptr2;
|
||||||
|
|
||||||
|
/* First we make sure that the information is good */
|
||||||
|
if (mime_type == NULL || *mime_type == '\000') {
|
||||||
|
run_error (_("You must enter a mime-type"));
|
||||||
|
return;
|
||||||
|
} else if (description == NULL || *description == '\000') {
|
||||||
|
run_error (_("You must add a description"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* FIXME bugzilla.eazel.com 796: Looks in gnome-libs prefix instead of gnome-vfs prefix. */
|
if (strchr (mime_type, '/') == NULL) {
|
||||||
mime_info_dir = gnome_unconditional_datadir_file ("mime-info");
|
run_error (_("Please put your mime-type in the format:\nCATEGORY/TYPE\n\nFor Example:\nimage/png"));
|
||||||
mime_load_from_dir (mime_info_dir, TRUE);
|
return;
|
||||||
g_free (mime_info_dir);
|
}
|
||||||
|
|
||||||
mime_info_dir = g_concat_dir_and_file (gnome_util_user_home (), ".gnome/mime-info");
|
if (g_hash_table_lookup (user_mime_types, mime_type) ||
|
||||||
mime_load_from_dir (mime_info_dir, FALSE);
|
g_hash_table_lookup (mime_types, mime_type)) {
|
||||||
g_free (mime_info_dir);
|
run_error (_("This mime-type already exists"));
|
||||||
finalize_user_mime ();
|
return;
|
||||||
init_mime_info ();
|
}
|
||||||
|
|
||||||
|
if (description || *description) {
|
||||||
|
ptr2 = desc_key = g_malloc (sizeof (description));
|
||||||
|
for (ptr = description; *ptr; ptr++) {
|
||||||
|
if (*ptr != '.' && *ptr != ',') {
|
||||||
|
*ptr2 = *ptr;
|
||||||
|
ptr2 += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*ptr2 = '\000';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Passed check, Now we add it. */
|
||||||
|
if (desc_key) {
|
||||||
|
temp = g_strconcat ("description: ", desc_key, NULL);
|
||||||
|
add_to_key (mime_type, temp, user_mime_types, TRUE);
|
||||||
|
mi = (MimeInfo *) g_hash_table_lookup (user_mime_types, mime_type);
|
||||||
|
g_free (temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Finally add it to the clist */
|
||||||
|
if (mi) {
|
||||||
|
row = add_mime_vals_to_clist (mime_type, mi, clist);
|
||||||
|
if (row >= 0) {
|
||||||
|
gtk_clist_select_row (GTK_CLIST (clist), row, 0);
|
||||||
|
gtk_clist_moveto (GTK_CLIST (clist), row, 0, 0.5, 0.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//g_free (desc_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
void
|
void
|
||||||
add_new_mime_type (gchar *mime_type, gchar *raw_ext)
|
add_new_mime_type (gchar *mime_type, gchar *raw_ext)
|
||||||
{
|
{
|
||||||
|
@ -489,11 +284,14 @@ add_new_mime_type (gchar *mime_type, gchar *raw_ext)
|
||||||
/* Finally add it to the clist */
|
/* Finally add it to the clist */
|
||||||
if (mi) {
|
if (mi) {
|
||||||
row = add_mime_vals_to_clist (mime_type, mi, clist);
|
row = add_mime_vals_to_clist (mime_type, mi, clist);
|
||||||
gtk_clist_select_row (GTK_CLIST (clist), row, 0);
|
if (row >= 0) {
|
||||||
gtk_clist_moveto (GTK_CLIST (clist), row, 0, 0.5, 0.0);
|
gtk_clist_select_row (GTK_CLIST (clist), row, 0);
|
||||||
|
gtk_clist_moveto (GTK_CLIST (clist), row, 0, 0.5, 0.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
g_free (ext);
|
g_free (ext);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
write_mime_foreach (gpointer mime_type, gpointer info, gpointer data)
|
write_mime_foreach (gpointer mime_type, gpointer info, gpointer data)
|
||||||
|
@ -502,27 +300,6 @@ write_mime_foreach (gpointer mime_type, gpointer info, gpointer data)
|
||||||
MimeInfo *mi = (MimeInfo *) info;
|
MimeInfo *mi = (MimeInfo *) info;
|
||||||
fwrite ((char *) mi->mime_type, 1, strlen ((char *) mi->mime_type), (FILE *) data);
|
fwrite ((char *) mi->mime_type, 1, strlen ((char *) mi->mime_type), (FILE *) data);
|
||||||
fwrite ("\n", 1, 1, (FILE *) data);
|
fwrite ("\n", 1, 1, (FILE *) data);
|
||||||
if (mi->ext_readable[0]) {
|
|
||||||
fwrite ("\text: ", 1, strlen ("\text: "), (FILE *) data);
|
|
||||||
fwrite (mi->ext_readable[0], 1,
|
|
||||||
strlen (mi->ext_readable[0]),
|
|
||||||
(FILE *) data);
|
|
||||||
fwrite ("\n", 1, 1, (FILE *) data);
|
|
||||||
}
|
|
||||||
if (mi->regex_readable[0]) {
|
|
||||||
fwrite ("\tregex: ", 1, strlen ("\tregex: "), (FILE *) data);
|
|
||||||
fwrite (mi->regex_readable[0], 1,
|
|
||||||
strlen (mi->regex_readable[0]),
|
|
||||||
(FILE *) data);
|
|
||||||
fwrite ("\n", 1, 1, (FILE *) data);
|
|
||||||
}
|
|
||||||
if (mi->regex_readable[1]) {
|
|
||||||
fwrite ("\tregex,2: ", 1, strlen ("\tregex,2: "), (FILE *) data);
|
|
||||||
fwrite (mi->regex_readable[1], 1,
|
|
||||||
strlen (mi->regex_readable[1]),
|
|
||||||
(FILE *) data);
|
|
||||||
fwrite ("\n", 1, 1, (FILE *) data);
|
|
||||||
}
|
|
||||||
fwrite ("\n", 1, 1, (FILE *) data);
|
fwrite ("\n", 1, 1, (FILE *) data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -584,27 +361,3 @@ reread_list (void)
|
||||||
gtk_clist_thaw (GTK_CLIST (clist));
|
gtk_clist_thaw (GTK_CLIST (clist));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
clean_mime_type (gpointer mime_type, gpointer mime_info, gpointer data)
|
|
||||||
{
|
|
||||||
/* FIXME: we should write this )-: */
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
discard_mime_info (void)
|
|
||||||
{
|
|
||||||
gchar *filename;
|
|
||||||
|
|
||||||
g_hash_table_foreach (user_mime_types, clean_mime_type, NULL);
|
|
||||||
g_hash_table_destroy (user_mime_types);
|
|
||||||
g_hash_table_foreach (initial_user_mime_types, clean_mime_type, NULL);
|
|
||||||
g_hash_table_destroy (initial_user_mime_types);
|
|
||||||
user_mime_types = g_hash_table_new (g_str_hash, g_str_equal);
|
|
||||||
initial_user_mime_types = g_hash_table_new (g_str_hash, g_str_equal);
|
|
||||||
|
|
||||||
filename = g_concat_dir_and_file (gnome_util_user_home (), "/.gnome/mime-info/user.keys");
|
|
||||||
mime_fill_from_file (filename, TRUE);
|
|
||||||
finalize_user_mime ();
|
|
||||||
reread_list ();
|
|
||||||
g_free (filename);
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,30 +5,23 @@
|
||||||
#ifndef MIME_DATA_H
|
#ifndef MIME_DATA_H
|
||||||
#define MIME_DATA_H
|
#define MIME_DATA_H
|
||||||
|
|
||||||
#include "gnome.h"
|
#include <gnome.h>
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
|
|
||||||
/* Typedefs */
|
/* Typedefs */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *mime_type;
|
char *mime_type;
|
||||||
regex_t *regex[2];
|
|
||||||
GList *ext[2];
|
GList *ext[2];
|
||||||
GList *user_ext[2];
|
GList *user_ext[2];
|
||||||
char *ext_readable[2];
|
|
||||||
char *regex_readable[2];
|
|
||||||
char *file_name;
|
|
||||||
GList *keys;
|
GList *keys;
|
||||||
} MimeInfo;
|
} MimeInfo;
|
||||||
|
|
||||||
extern GHashTable *user_mime_types;
|
|
||||||
extern void add_to_key (char *mime_type, char *def, GHashTable *table, gboolean init_user);
|
extern void add_to_key (char *mime_type, char *def, GHashTable *table, gboolean init_user);
|
||||||
|
|
||||||
GtkWidget *create_mime_clist (void);
|
int add_mime_vals_to_clist (gchar *mime_type, gpointer mi, gpointer cl);
|
||||||
void init_mime_type (void);
|
|
||||||
void add_new_mime_type (gchar *mime_type, gchar *ext);
|
void add_new_mime_type (gchar *mime_type, gchar *ext);
|
||||||
void write_user_mime (void);
|
void write_user_mime (void);
|
||||||
void write_initial_mime (void);
|
void write_initial_mime (void);
|
||||||
void reread_list (void);
|
void reread_list (void);
|
||||||
void discard_mime_info (void);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,493 +0,0 @@
|
||||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
|
|
||||||
/* Copyright (C) 1998 Redhat Software Inc.
|
|
||||||
* Authors: Jonathan Blandford <jrb@redhat.com>
|
|
||||||
*/
|
|
||||||
#include <config.h>
|
|
||||||
#include "capplet-widget.h"
|
|
||||||
#include "gnome.h"
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <regex.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include "mime-info.h"
|
|
||||||
#include "mime-data.h"
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#if !defined getc_unlocked && !defined HAVE_GETC_UNLOCKED
|
|
||||||
# define getc_unlocked(fp) getc (fp)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char *mime_type;
|
|
||||||
GHashTable *keys;
|
|
||||||
} GnomeMimeContext;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
STATE_NONE,
|
|
||||||
STATE_LANG,
|
|
||||||
STATE_LOOKING_FOR_KEY,
|
|
||||||
STATE_ON_MIME_TYPE,
|
|
||||||
STATE_ON_KEY,
|
|
||||||
STATE_ON_VALUE
|
|
||||||
} ParserState;
|
|
||||||
|
|
||||||
static char *current_lang = NULL;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* A hash table containing all of the Mime records for specific
|
|
||||||
* mime types (full description, like image/png)
|
|
||||||
*/
|
|
||||||
static GHashTable *specific_types;
|
|
||||||
static GHashTable *initial_specific_types;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* A hash table containing all of the Mime records for non-specific
|
|
||||||
* mime types (like image/\*)
|
|
||||||
*/
|
|
||||||
static GHashTable *generic_types;
|
|
||||||
static GHashTable *initial_generic_types;
|
|
||||||
|
|
||||||
#define SWITCH_TO_MIME_TYPE() {
|
|
||||||
static GnomeMimeContext *
|
|
||||||
context_new (GString *str, gboolean is_default_context)
|
|
||||||
{
|
|
||||||
GnomeMimeContext *context;
|
|
||||||
GHashTable *table;
|
|
||||||
char *mime_type, *p;
|
|
||||||
|
|
||||||
mime_type = g_strdup (str->str);
|
|
||||||
|
|
||||||
if (is_default_context) {
|
|
||||||
if ((p = strstr (mime_type, "/*")) == NULL){
|
|
||||||
table = initial_specific_types;
|
|
||||||
} else {
|
|
||||||
*(p+1) = 0;
|
|
||||||
table = initial_generic_types;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ((p = strstr (mime_type, "/*")) == NULL){
|
|
||||||
table = specific_types;
|
|
||||||
} else {
|
|
||||||
*(p+1) = 0;
|
|
||||||
table = generic_types;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
context = g_hash_table_lookup (table, mime_type);
|
|
||||||
|
|
||||||
if (context)
|
|
||||||
return context;
|
|
||||||
|
|
||||||
context = g_new (GnomeMimeContext, 1);
|
|
||||||
context->mime_type = mime_type;
|
|
||||||
context->keys = g_hash_table_new (g_str_hash, g_str_equal);
|
|
||||||
|
|
||||||
g_hash_table_insert (table, context->mime_type, context);
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
release_key_and_value (gpointer key, gpointer value, gpointer user_data)
|
|
||||||
{
|
|
||||||
g_free (key);
|
|
||||||
g_free (value);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
remove_this_key (gpointer key, gpointer value, gpointer user_data)
|
|
||||||
{
|
|
||||||
if (strcmp ((gchar *)key, (gchar *)user_data) == 0){
|
|
||||||
g_free (key);
|
|
||||||
g_free (value);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
static void
|
|
||||||
context_add_key (GnomeMimeContext *context, char *key, char *value)
|
|
||||||
{
|
|
||||||
char *v;
|
|
||||||
|
|
||||||
v = g_hash_table_lookup (context->keys, key);
|
|
||||||
if (v)
|
|
||||||
g_hash_table_foreach_remove (context->keys, remove_this_key, key);
|
|
||||||
|
|
||||||
g_hash_table_insert (context->keys, g_strdup (key), g_strdup (value));
|
|
||||||
}
|
|
||||||
static void
|
|
||||||
context_destroy (GnomeMimeContext *context)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Remove the context from our hash tables, we dont know
|
|
||||||
* where it is: so just remove it from both (it can
|
|
||||||
* only be in one).
|
|
||||||
*/
|
|
||||||
if (context->mime_type) {
|
|
||||||
g_hash_table_remove (specific_types, context->mime_type);
|
|
||||||
g_hash_table_remove (generic_types, context->mime_type);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Destroy it
|
|
||||||
*/
|
|
||||||
if (context->keys) {
|
|
||||||
g_hash_table_foreach_remove (context->keys, release_key_and_value, NULL);
|
|
||||||
g_hash_table_destroy (context->keys);
|
|
||||||
}
|
|
||||||
g_free (context->mime_type);
|
|
||||||
g_free (context);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
load_mime_type_info_from (char *filename)
|
|
||||||
{
|
|
||||||
FILE *mime_file;
|
|
||||||
gboolean in_comment, context_used;
|
|
||||||
GString *line;
|
|
||||||
int column, c;
|
|
||||||
ParserState state;
|
|
||||||
GnomeMimeContext *context, *default_context;
|
|
||||||
char *key;
|
|
||||||
|
|
||||||
mime_file = fopen (filename, "r");
|
|
||||||
if (mime_file == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
in_comment = FALSE;
|
|
||||||
context_used = FALSE;
|
|
||||||
column = 0;
|
|
||||||
context = NULL;
|
|
||||||
default_context = NULL;
|
|
||||||
key = NULL;
|
|
||||||
line = g_string_sized_new (120);
|
|
||||||
state = STATE_NONE;
|
|
||||||
|
|
||||||
while ((c = getc_unlocked (mime_file)) != EOF){
|
|
||||||
column++;
|
|
||||||
if (c == '\r')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (c == '#' && column == 0){
|
|
||||||
in_comment = TRUE;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == '\n'){
|
|
||||||
in_comment = FALSE;
|
|
||||||
column = 0;
|
|
||||||
if (state == STATE_ON_MIME_TYPE){
|
|
||||||
context = context_new (line, FALSE);
|
|
||||||
default_context = context_new (line, TRUE);
|
|
||||||
context_used = FALSE;
|
|
||||||
g_string_assign (line, "");
|
|
||||||
state = STATE_LOOKING_FOR_KEY;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (state == STATE_ON_VALUE){
|
|
||||||
context_used = TRUE;
|
|
||||||
context_add_key (context, key, line->str);
|
|
||||||
context_add_key (default_context, key, line->str);
|
|
||||||
g_string_assign (line, "");
|
|
||||||
g_free (key);
|
|
||||||
key = NULL;
|
|
||||||
state = STATE_LOOKING_FOR_KEY;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in_comment)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
switch (state){
|
|
||||||
case STATE_NONE:
|
|
||||||
if (c != ' ' && c != '\t')
|
|
||||||
state = STATE_ON_MIME_TYPE;
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
/* fall down */
|
|
||||||
|
|
||||||
case STATE_ON_MIME_TYPE:
|
|
||||||
if (c == ':'){
|
|
||||||
in_comment = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
g_string_append_c (line, c);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATE_LOOKING_FOR_KEY:
|
|
||||||
if (c == '\t' || c == ' ')
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (c == '['){
|
|
||||||
state = STATE_LANG;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (column == 1){
|
|
||||||
state = STATE_ON_MIME_TYPE;
|
|
||||||
g_string_append_c (line, c);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
state = STATE_ON_KEY;
|
|
||||||
/* falldown */
|
|
||||||
|
|
||||||
case STATE_ON_KEY:
|
|
||||||
if (c == '\\'){
|
|
||||||
c = getc (mime_file);
|
|
||||||
if (c == EOF)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (c == '='){
|
|
||||||
key = g_strdup (line->str);
|
|
||||||
g_string_assign (line, "");
|
|
||||||
state = STATE_ON_VALUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
g_string_append_c (line, c);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATE_ON_VALUE:
|
|
||||||
g_string_append_c (line, c);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATE_LANG:
|
|
||||||
if (c == ']'){
|
|
||||||
state = STATE_ON_KEY;
|
|
||||||
if (current_lang && line->str [0]){
|
|
||||||
if (strcmp (current_lang, line->str) != 0){
|
|
||||||
in_comment = TRUE;
|
|
||||||
state = STATE_LOOKING_FOR_KEY;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
in_comment = TRUE;
|
|
||||||
state = STATE_LOOKING_FOR_KEY;
|
|
||||||
}
|
|
||||||
g_string_assign (line, "");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
g_string_append_c (line, c);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (context){
|
|
||||||
if (key && line->str [0]) {
|
|
||||||
context_add_key (context, key, line->str);
|
|
||||||
context_add_key (default_context, key, line->str);
|
|
||||||
} else
|
|
||||||
if (!context_used) {
|
|
||||||
context_destroy (context);
|
|
||||||
context_destroy (default_context);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
g_string_free (line, TRUE);
|
|
||||||
if (key)
|
|
||||||
g_free (key);
|
|
||||||
|
|
||||||
fclose (mime_file);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
set_mime_key_value (gchar *mime_type, gchar *key, gchar *value)
|
|
||||||
{
|
|
||||||
GnomeMimeContext *context;
|
|
||||||
|
|
||||||
/* Assume no generic context's for now. */
|
|
||||||
context = g_hash_table_lookup (specific_types, mime_type);
|
|
||||||
if (context == NULL) {
|
|
||||||
GString *str = g_string_new (mime_type);
|
|
||||||
context = context_new (str, FALSE);
|
|
||||||
g_string_free (str, TRUE);
|
|
||||||
}
|
|
||||||
context_add_key (context, key, value);
|
|
||||||
}
|
|
||||||
void
|
|
||||||
init_mime_info (void)
|
|
||||||
{
|
|
||||||
gchar *filename;
|
|
||||||
|
|
||||||
current_lang = getenv ("LANG");
|
|
||||||
specific_types = g_hash_table_new (g_str_hash, g_str_equal);
|
|
||||||
generic_types = g_hash_table_new (g_str_hash, g_str_equal);
|
|
||||||
initial_specific_types = g_hash_table_new (g_str_hash, g_str_equal);
|
|
||||||
initial_generic_types = g_hash_table_new (g_str_hash, g_str_equal);
|
|
||||||
|
|
||||||
filename = g_concat_dir_and_file (gnome_util_user_home (), "/.gnome/mime-info/user.keys");
|
|
||||||
load_mime_type_info_from (filename);
|
|
||||||
g_free (filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *
|
|
||||||
local_mime_get_value (const char *mime_type, char *key)
|
|
||||||
{
|
|
||||||
char *value, *generic_type, *p;
|
|
||||||
GnomeMimeContext *context;
|
|
||||||
|
|
||||||
g_return_val_if_fail (mime_type != NULL, NULL);
|
|
||||||
g_return_val_if_fail (key != NULL, NULL);
|
|
||||||
context = g_hash_table_lookup (specific_types, mime_type);
|
|
||||||
if (context){
|
|
||||||
value = g_hash_table_lookup (context->keys, key);
|
|
||||||
|
|
||||||
if (value)
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
generic_type = g_strdup (mime_type);
|
|
||||||
p = strchr (generic_type, '/');
|
|
||||||
if (p)
|
|
||||||
*(p+1) = 0;
|
|
||||||
|
|
||||||
context = g_hash_table_lookup (generic_types, generic_type);
|
|
||||||
g_free (generic_type);
|
|
||||||
|
|
||||||
if (context){
|
|
||||||
value = g_hash_table_lookup (context->keys, key);
|
|
||||||
if (value)
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
static void
|
|
||||||
clean_mime_foreach (gpointer mime_type, gpointer gmc, gpointer data)
|
|
||||||
{
|
|
||||||
context_destroy ((GnomeMimeContext *) gmc);
|
|
||||||
}
|
|
||||||
static void
|
|
||||||
write_mime_keys_foreach (gpointer key_name, gpointer value, gpointer data)
|
|
||||||
{
|
|
||||||
gchar *buf;
|
|
||||||
if (current_lang && strcmp (current_lang, "C"))
|
|
||||||
buf = g_strconcat ("\t[",
|
|
||||||
current_lang,
|
|
||||||
"]",
|
|
||||||
(gchar *) key_name,
|
|
||||||
"=",
|
|
||||||
(gchar *) value,
|
|
||||||
"\n", NULL);
|
|
||||||
else
|
|
||||||
buf = g_strconcat ("\t",
|
|
||||||
(gchar *) key_name,
|
|
||||||
"=",
|
|
||||||
(gchar *) value,
|
|
||||||
"\n", NULL);
|
|
||||||
fwrite (buf, 1, strlen (buf), (FILE *) data);
|
|
||||||
g_free (buf);
|
|
||||||
}
|
|
||||||
static void
|
|
||||||
write_mime_foreach (gpointer mime_type, gpointer gmc, gpointer data)
|
|
||||||
{
|
|
||||||
gchar *buf;
|
|
||||||
GnomeMimeContext *context = (GnomeMimeContext *) gmc;
|
|
||||||
|
|
||||||
buf = g_strconcat ((gchar *) mime_type, ":\n", NULL);
|
|
||||||
fwrite (buf, 1, strlen (buf), (FILE *) data);
|
|
||||||
g_free (buf);
|
|
||||||
g_hash_table_foreach (context->keys, write_mime_keys_foreach, data);
|
|
||||||
fwrite ("\n", 1, strlen ("\n"), (FILE *) data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
run_error (gchar *message)
|
|
||||||
{
|
|
||||||
GtkWidget *error_box;
|
|
||||||
|
|
||||||
error_box = gnome_message_box_new (
|
|
||||||
message,
|
|
||||||
GNOME_MESSAGE_BOX_ERROR,
|
|
||||||
GNOME_STOCK_BUTTON_OK,
|
|
||||||
NULL);
|
|
||||||
gnome_dialog_run_and_close (GNOME_DIALOG (error_box));
|
|
||||||
}
|
|
||||||
static void
|
|
||||||
write_keys (GHashTable *spec_hash, GHashTable *generic_hash)
|
|
||||||
{
|
|
||||||
struct stat s;
|
|
||||||
gchar *dirname, *filename;
|
|
||||||
FILE *file;
|
|
||||||
/* GtkWidget *error_box; */
|
|
||||||
|
|
||||||
dirname = g_concat_dir_and_file (gnome_util_user_home (), ".gnome/mime-info");
|
|
||||||
if ((stat (dirname, &s) < 0) || !(S_ISDIR (s.st_mode))){
|
|
||||||
if (errno == ENOENT) {
|
|
||||||
if (mkdir (dirname, S_IRWXU) < 0) {
|
|
||||||
run_error (_("We are unable to create the directory\n"
|
|
||||||
"~/.gnome/mime-info.\n\n"
|
|
||||||
"We will not be able to save the state."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
run_error (_("We are unable to access the directory\n"
|
|
||||||
"~/.gnome/mime-info.\n\n"
|
|
||||||
"We will not be able to save the state."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
filename = g_concat_dir_and_file (dirname, "user.keys");
|
|
||||||
|
|
||||||
remove (filename);
|
|
||||||
file = fopen (filename, "w");
|
|
||||||
if (file == NULL) {
|
|
||||||
run_error (_("Cannot create the file\n~/.gnome/mime-info/user.keys.\n\n"
|
|
||||||
"We will not be able to save the state"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
g_hash_table_foreach (spec_hash, write_mime_foreach, file);
|
|
||||||
g_hash_table_foreach (generic_hash, write_mime_foreach, file);
|
|
||||||
fclose (file);
|
|
||||||
}
|
|
||||||
void
|
|
||||||
write_initial_keys (void)
|
|
||||||
{
|
|
||||||
write_keys (initial_generic_types, initial_specific_types);
|
|
||||||
}
|
|
||||||
void
|
|
||||||
write_user_keys (void)
|
|
||||||
{
|
|
||||||
write_keys (generic_types, specific_types);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
static void
|
|
||||||
print_mime_foreach (gpointer mime_info, gpointer mi, gpointer data)
|
|
||||||
{
|
|
||||||
g_print ("mime_info:%s:\n", (char *)mime_info);
|
|
||||||
g_print ("\t:%s:\n", ((MimeInfo *)mi)->mime_type);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void
|
|
||||||
discard_key_info (void)
|
|
||||||
{
|
|
||||||
gchar *filename;
|
|
||||||
|
|
||||||
current_lang = getenv ("LANG");
|
|
||||||
g_hash_table_foreach (generic_types, clean_mime_foreach, NULL);
|
|
||||||
/* g_hash_table_foreach (specific_types, print_mime_foreach, NULL); */
|
|
||||||
g_hash_table_foreach (specific_types, clean_mime_foreach, NULL);
|
|
||||||
g_hash_table_destroy (generic_types);
|
|
||||||
g_hash_table_destroy (specific_types);
|
|
||||||
specific_types = g_hash_table_new (g_str_hash, g_str_equal);
|
|
||||||
generic_types = g_hash_table_new (g_str_hash, g_str_equal);
|
|
||||||
|
|
||||||
filename = g_concat_dir_and_file (gnome_util_user_home (), "/.gnome/mime-info/user.keys");
|
|
||||||
load_mime_type_info_from (filename);
|
|
||||||
reread_list ();
|
|
||||||
g_free (filename);
|
|
||||||
}
|
|
||||||
void
|
|
||||||
remove_mime_info (gchar *mime_type)
|
|
||||||
{
|
|
||||||
g_hash_table_remove (generic_types, mime_type);
|
|
||||||
g_hash_table_remove (specific_types, mime_type);
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
|
|
||||||
|
|
||||||
/* mime-info.h
|
|
||||||
*
|
|
||||||
* Copyright (C) 1998 Redhat Software Inc.
|
|
||||||
* Copyright (C) 2000 Free Software Foundaton
|
|
||||||
* Copyright (C) 2000 Eazel, Inc.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* Authors: Jonathan Blandford <jrb@redhat.com>
|
|
||||||
* Gene Z. Ragan <gzr@eazel.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef MIME_INFO_H
|
|
||||||
#define MIME_INFO_H
|
|
||||||
|
|
||||||
#include "gnome.h"
|
|
||||||
#include <regex.h>
|
|
||||||
|
|
||||||
void init_mime_info (void);
|
|
||||||
void discard_key_info (void);
|
|
||||||
void set_mime_key_value (gchar *mime_type, gchar *key, gchar *value);
|
|
||||||
const char * local_mime_get_value (const char *mime_type, char *key);
|
|
||||||
void write_user_keys (void);
|
|
||||||
void write_initial_keys (void);
|
|
||||||
void remove_mime_info (gchar *mime_type);
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Add table
Add a link
Reference in a new issue