mirror of https://github.com/MidnightCommander/mc
1999-09-07 <jrb@redhat.com>
* capplets/mime-type/mime-type-capplet.c: Patch added from Iain Holmes <iain@webtribe.net> to add the ability to edit mime-type extensions.
This commit is contained in:
parent
5818c1b0ff
commit
c2fb5e5320
|
@ -5,21 +5,29 @@
|
|||
|
||||
|
||||
extern GtkWidget *capplet;
|
||||
extern GHashTable *user_mime_types;
|
||||
|
||||
typedef struct {
|
||||
GtkWidget *window;
|
||||
GtkWidget *icon_entry;
|
||||
GtkWidget *mime_type;
|
||||
GtkWidget *ext_tag_label;
|
||||
/* GtkWidget *ext_tag_label; */
|
||||
GtkWidget *regexp1_tag_label;
|
||||
GtkWidget *regexp2_tag_label;
|
||||
GtkWidget *ext_label;
|
||||
/* GtkWidget *ext_label; */
|
||||
GtkWidget *regexp1_label;
|
||||
GtkWidget *regexp2_label;
|
||||
GtkWidget *open_entry;
|
||||
GtkWidget *edit_entry;
|
||||
GtkWidget *view_entry;
|
||||
GtkWidget *ext_scroll;
|
||||
GtkWidget *ext_clist;
|
||||
GtkWidget *ext_entry;
|
||||
GtkWidget *ext_add_button;
|
||||
GtkWidget *ext_remove_button;
|
||||
MimeInfo *mi;
|
||||
MimeInfo *user_mi;
|
||||
GList *tmp_ext[2];
|
||||
} edit_window;
|
||||
static edit_window *main_win = NULL;
|
||||
static gboolean changing = TRUE;
|
||||
|
@ -37,6 +45,80 @@ entry_changed (GtkWidget *widget, gpointer data)
|
|||
TRUE);
|
||||
}
|
||||
static void
|
||||
ext_clist_selected (GtkWidget *clist, gint row, gint column, gpointer data)
|
||||
{
|
||||
gboolean deletable;
|
||||
|
||||
deletable = GPOINTER_TO_INT (gtk_clist_get_row_data (GTK_CLIST (clist), row));
|
||||
if (deletable)
|
||||
gtk_widget_set_sensitive (main_win->ext_remove_button, TRUE);
|
||||
else
|
||||
gtk_widget_set_sensitive (main_win->ext_remove_button, FALSE);
|
||||
}
|
||||
static void
|
||||
ext_clist_deselected (GtkWidget *clist, gint row, gint column, gpointer data)
|
||||
{
|
||||
if (g_list_length (GTK_CLIST (clist)->selection) == 0)
|
||||
gtk_widget_set_sensitive (main_win->ext_remove_button, FALSE);
|
||||
}
|
||||
static void
|
||||
ext_entry_changed (GtkWidget *entry, gpointer data)
|
||||
{
|
||||
gchar *text;
|
||||
text = gtk_entry_get_text (GTK_ENTRY (entry));
|
||||
gtk_widget_set_sensitive (main_win->ext_add_button, (strlen (text) >0));
|
||||
}
|
||||
static void
|
||||
ext_add (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
gchar *row[1];
|
||||
gint rownumber;
|
||||
|
||||
row[0] = g_strdup (gtk_entry_get_text (GTK_ENTRY (main_win->ext_entry)));
|
||||
rownumber = gtk_clist_append (GTK_CLIST (main_win->ext_clist), row);
|
||||
gtk_clist_set_row_data (GTK_CLIST (main_win->ext_clist), rownumber,
|
||||
GINT_TO_POINTER (TRUE));
|
||||
gtk_entry_set_text (GTK_ENTRY (main_win->ext_entry), "");
|
||||
|
||||
main_win->tmp_ext[0] = g_list_prepend (main_win->tmp_ext[0], row[0]);
|
||||
if (changing == FALSE)
|
||||
capplet_widget_state_changed (CAPPLET_WIDGET (capplet),
|
||||
TRUE);
|
||||
}
|
||||
static void
|
||||
ext_remove (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
gint row;
|
||||
gchar *text;
|
||||
gchar *store;
|
||||
GList *tmp;
|
||||
|
||||
text = (gchar *)g_malloc (sizeof (gchar) * 1024);
|
||||
gtk_clist_freeze (GTK_CLIST (main_win->ext_clist));
|
||||
row = GPOINTER_TO_INT (GTK_CLIST (main_win->ext_clist)->selection->data);
|
||||
gtk_clist_get_text (GTK_CLIST (main_win->ext_clist), row, 0, &text);
|
||||
store = g_strdup (text);
|
||||
gtk_clist_remove (GTK_CLIST (main_win->ext_clist), row);
|
||||
|
||||
gtk_clist_thaw (GTK_CLIST (main_win->ext_clist));
|
||||
|
||||
for (tmp = main_win->tmp_ext[0]; tmp; tmp = tmp->next) {
|
||||
GList *found;
|
||||
|
||||
if (strcmp (tmp->data, store) == 0) {
|
||||
found = tmp;
|
||||
|
||||
main_win->tmp_ext[0] = g_list_remove_link (main_win->tmp_ext[0], found);
|
||||
g_list_free_1 (found);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (changing == FALSE)
|
||||
capplet_widget_state_changed (CAPPLET_WIDGET (capplet),
|
||||
TRUE);
|
||||
}
|
||||
static void
|
||||
apply_entry_change (GtkWidget *entry, gchar *key, MimeInfo *mi)
|
||||
{
|
||||
const gchar *buf;
|
||||
|
@ -49,7 +131,7 @@ apply_entry_change (GtkWidget *entry, gchar *key, MimeInfo *mi)
|
|||
text = gtk_entry_get_text (GTK_ENTRY (entry));
|
||||
if (text && !*text)
|
||||
text = NULL;
|
||||
|
||||
|
||||
/* First we see if they've added something. */
|
||||
if (buf == NULL && text)
|
||||
set_mime_key_value (mi->mime_type, key, text);
|
||||
|
@ -66,9 +148,47 @@ apply_entry_change (GtkWidget *entry, gchar *key, MimeInfo *mi)
|
|||
;
|
||||
}
|
||||
}
|
||||
static GList*
|
||||
copy_mi_extensions (GList *orig)
|
||||
{
|
||||
GList *tmp;
|
||||
GList *list = NULL;
|
||||
|
||||
for (tmp = orig; tmp; tmp = tmp->next) {
|
||||
list = g_list_append (list, g_strdup (tmp->data));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
static void
|
||||
make_readable (MimeInfo *mi)
|
||||
{
|
||||
GList *list;
|
||||
GString *extension;
|
||||
|
||||
extension = g_string_new ("");
|
||||
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, ", ");
|
||||
}
|
||||
mi->ext_readable[0] = extension->str;
|
||||
g_string_free (extension, FALSE);
|
||||
|
||||
extension = g_string_new ("");
|
||||
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, ", ");
|
||||
}
|
||||
mi->ext_readable[1] = extension->str;
|
||||
g_string_free (extension, FALSE);
|
||||
}
|
||||
static void
|
||||
apply_changes (MimeInfo *mi)
|
||||
{
|
||||
GList *tmp;
|
||||
int i;
|
||||
|
||||
apply_entry_change (gnome_icon_entry_gtk_entry (GNOME_ICON_ENTRY (main_win->icon_entry)),
|
||||
"icon-filename", mi);
|
||||
apply_entry_change (gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (main_win->open_entry)),
|
||||
|
@ -77,6 +197,41 @@ apply_changes (MimeInfo *mi)
|
|||
"view", mi);
|
||||
apply_entry_change (gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (main_win->edit_entry)),
|
||||
"edit", mi);
|
||||
|
||||
if (!main_win->user_mi) {
|
||||
add_to_key (mi->mime_type, "ext: tmp", user_mime_types, TRUE);
|
||||
/* the tmp extension will be removed when we copy the tmp_ext
|
||||
* stuff over the top of it.
|
||||
*/
|
||||
main_win->user_mi = g_hash_table_lookup (user_mime_types,
|
||||
mi->mime_type);
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (main_win->tmp_ext[i]) {
|
||||
main_win->user_mi->user_ext[i] = copy_mi_extensions (main_win->tmp_ext[i]);
|
||||
mi->user_ext[i] = copy_mi_extensions (main_win->tmp_ext[i]);
|
||||
} else {
|
||||
main_win->user_mi->user_ext[i] = NULL;
|
||||
mi->user_ext[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
make_readable (main_win->user_mi);
|
||||
|
||||
if (! (main_win->user_mi->ext[0] || main_win->user_mi->ext[1] ||
|
||||
main_win->user_mi->user_ext[0] || main_win->user_mi->ext[1]))
|
||||
g_hash_table_remove (user_mime_types, mi->mime_type);
|
||||
|
||||
/* Free the 2 tmp lists */
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (main_win->tmp_ext[i])
|
||||
for (tmp = main_win->tmp_ext[i]; tmp; tmp = tmp->next)
|
||||
g_free (tmp->data);
|
||||
}
|
||||
if (changing == FALSE)
|
||||
capplet_widget_state_changed (CAPPLET_WIDGET (capplet),
|
||||
TRUE);
|
||||
}
|
||||
static void
|
||||
browse_callback (GtkWidget *widget, gpointer data)
|
||||
|
@ -85,10 +240,11 @@ browse_callback (GtkWidget *widget, gpointer data)
|
|||
static void
|
||||
initialize_main_win ()
|
||||
{
|
||||
GtkWidget *align, *vbox, *hbox, *vbox2;
|
||||
GtkWidget *align, *vbox, *hbox, *vbox2, *vbox3;
|
||||
GtkWidget *frame, *table, *label;
|
||||
GtkWidget *button;
|
||||
GString *extension;
|
||||
gchar *title[2] = {"Extensions"};
|
||||
|
||||
main_win = g_new (edit_window, 1);
|
||||
main_win->window = gnome_dialog_new ("",
|
||||
|
@ -120,13 +276,60 @@ initialize_main_win ()
|
|||
/* extension/regexp */
|
||||
vbox2 = gtk_vbox_new (FALSE, GNOME_PAD_SMALL);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), vbox2, FALSE, FALSE, 0);
|
||||
|
||||
hbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL);
|
||||
main_win->ext_label = gtk_label_new ("");
|
||||
main_win->ext_tag_label = gtk_label_new (_("Extension: "));
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), main_win->ext_tag_label,
|
||||
main_win->ext_clist = gtk_clist_new_with_titles (1, title);
|
||||
gtk_clist_column_titles_passive (GTK_CLIST (main_win->ext_clist));
|
||||
gtk_clist_set_auto_sort (GTK_CLIST (main_win->ext_clist), TRUE);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (main_win->ext_clist),
|
||||
"select-row",
|
||||
GTK_SIGNAL_FUNC (ext_clist_selected),
|
||||
NULL);
|
||||
gtk_signal_connect (GTK_OBJECT (main_win->ext_clist),
|
||||
"unselect-row",
|
||||
GTK_SIGNAL_FUNC (ext_clist_deselected),
|
||||
NULL);
|
||||
main_win->ext_scroll = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (main_win->ext_scroll),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
gtk_container_add (GTK_CONTAINER (main_win->ext_scroll),
|
||||
main_win->ext_clist);
|
||||
|
||||
vbox3 = gtk_vbox_new (FALSE, GNOME_PAD_SMALL);
|
||||
main_win->ext_add_button = gtk_button_new_with_label (_("Add"));
|
||||
gtk_signal_connect (GTK_OBJECT (main_win->ext_add_button),
|
||||
"clicked",
|
||||
GTK_SIGNAL_FUNC (ext_add),
|
||||
NULL);
|
||||
gtk_box_pack_start (GTK_BOX (vbox3), main_win->ext_add_button, FALSE, FALSE, 0);
|
||||
gtk_widget_set_sensitive (main_win->ext_add_button, FALSE);
|
||||
|
||||
main_win->ext_remove_button = gtk_button_new_with_label (_("Remove"));
|
||||
gtk_signal_connect (GTK_OBJECT (main_win->ext_remove_button),
|
||||
"clicked",
|
||||
GTK_SIGNAL_FUNC (ext_remove),
|
||||
NULL);
|
||||
gtk_widget_set_sensitive (main_win->ext_remove_button, FALSE);
|
||||
gtk_box_pack_start (GTK_BOX (vbox3), main_win->ext_remove_button,
|
||||
FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), main_win->ext_label, FALSE, FALSE, 0);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (hbox), main_win->ext_scroll, TRUE, TRUE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), vbox3, FALSE, FALSE, 0);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), hbox, TRUE, TRUE, 0);
|
||||
|
||||
main_win->ext_entry = gtk_entry_new ();
|
||||
gtk_signal_connect (GTK_OBJECT (main_win->ext_entry),
|
||||
"changed",
|
||||
ext_entry_changed,
|
||||
NULL);
|
||||
gtk_signal_connect (GTK_OBJECT (main_win->ext_entry),
|
||||
"activate",
|
||||
ext_add,
|
||||
NULL);
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), main_win->ext_entry, TRUE, TRUE, 0);
|
||||
|
||||
hbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL);
|
||||
main_win->regexp1_label = gtk_label_new ("");
|
||||
|
@ -221,12 +424,14 @@ initialize_main_win_vals (void)
|
|||
{
|
||||
MimeInfo *mi;
|
||||
gchar *title;
|
||||
gboolean showext = FALSE;
|
||||
if (main_win == NULL)
|
||||
return;
|
||||
mi = main_win->mi;
|
||||
if (mi == NULL)
|
||||
return;
|
||||
/* now we fill in the fields with the mi stuff. */
|
||||
|
||||
changing = TRUE;
|
||||
gtk_label_set_text (GTK_LABEL (main_win->mime_type), mi->mime_type);
|
||||
gnome_icon_entry_set_icon (GNOME_ICON_ENTRY (main_win->icon_entry),
|
||||
|
@ -238,22 +443,67 @@ initialize_main_win_vals (void)
|
|||
title = g_strdup_printf (_("Set actions for %s"), mi->mime_type);
|
||||
gtk_window_set_title (GTK_WINDOW (main_win->window), title);
|
||||
g_free (title);
|
||||
|
||||
/* not sure why this is necessary */
|
||||
gtk_clist_clear (GTK_CLIST (main_win->ext_clist));
|
||||
if (mi->ext[0]) {
|
||||
GString *extension;
|
||||
extension = g_string_new (mi->ext_readable[0]);
|
||||
if (mi->ext[1]) {
|
||||
g_string_append (extension, ", ");
|
||||
g_string_append (extension, (mi->ext_readable[1]));
|
||||
}
|
||||
gtk_label_set_text (GTK_LABEL (main_win->ext_label),
|
||||
extension->str);
|
||||
g_string_free (extension, TRUE);
|
||||
} else if (mi->ext[1])
|
||||
gtk_label_set_text (GTK_LABEL (main_win->ext_label),
|
||||
mi->ext_readable[1]);
|
||||
else {
|
||||
gtk_widget_hide (main_win->ext_label);
|
||||
gtk_widget_hide (main_win->ext_tag_label);
|
||||
GList *tmp;
|
||||
gchar *extension[1];
|
||||
gint row;
|
||||
for (tmp = mi->ext[0]; tmp; tmp = tmp->next) {
|
||||
extension[0] = g_strdup (tmp->data);
|
||||
row = gtk_clist_append (GTK_CLIST (main_win->ext_clist),
|
||||
extension);
|
||||
gtk_clist_set_row_data (GTK_CLIST (main_win->ext_clist),
|
||||
row, GINT_TO_POINTER (FALSE));
|
||||
}
|
||||
showext = TRUE;
|
||||
}
|
||||
if (mi->ext[1]) {
|
||||
GList *tmp;
|
||||
gchar *extension[1];
|
||||
gint row;
|
||||
for (tmp = mi->ext[1]; tmp; tmp = tmp->next) {
|
||||
extension[0] = g_strdup (tmp->data);
|
||||
row = gtk_clist_append (GTK_CLIST (main_win->ext_clist),
|
||||
extension);
|
||||
gtk_clist_set_row_data (GTK_CLIST (main_win->ext_clist),
|
||||
row, GINT_TO_POINTER (FALSE));
|
||||
}
|
||||
showext = TRUE;
|
||||
}
|
||||
if (main_win->tmp_ext[0]) {
|
||||
GList *tmp;
|
||||
gchar *extension[1];
|
||||
gint row;
|
||||
for (tmp = main_win->tmp_ext[0]; tmp; tmp = tmp->next) {
|
||||
extension[0] = g_strdup (tmp->data);
|
||||
row = gtk_clist_append (GTK_CLIST (main_win->ext_clist),
|
||||
extension);
|
||||
gtk_clist_set_row_data (GTK_CLIST (main_win->ext_clist),
|
||||
row, GINT_TO_POINTER (TRUE));
|
||||
}
|
||||
showext = TRUE;
|
||||
}
|
||||
if (main_win->tmp_ext[1]) {
|
||||
GList *tmp;
|
||||
gchar *extension[1];
|
||||
gint row;
|
||||
for (tmp = main_win->tmp_ext[0]; tmp; tmp = tmp->next) {
|
||||
extension[0] = g_strdup (tmp->data);
|
||||
row = gtk_clist_append (GTK_CLIST (main_win->ext_clist),
|
||||
extension);
|
||||
gtk_clist_set_row_data (GTK_CLIST (main_win->ext_clist),
|
||||
row, GINT_TO_POINTER (TRUE));
|
||||
}
|
||||
showext = TRUE;
|
||||
}
|
||||
if (!showext) {
|
||||
gtk_widget_hide (main_win->ext_clist);
|
||||
gtk_widget_hide (main_win->ext_entry);
|
||||
gtk_widget_hide (main_win->ext_add_button);
|
||||
gtk_widget_hide (main_win->ext_remove_button);
|
||||
gtk_widget_hide (main_win->ext_scroll);
|
||||
}
|
||||
if (mi->regex_readable[0])
|
||||
gtk_label_set_text (GTK_LABEL (main_win->regexp1_label),
|
||||
|
@ -284,6 +534,15 @@ launch_edit_window (MimeInfo *mi)
|
|||
if (main_win == NULL)
|
||||
initialize_main_win ();
|
||||
main_win->mi = mi;
|
||||
main_win->user_mi = g_hash_table_lookup (user_mime_types, mi->mime_type);
|
||||
main_win->tmp_ext[0] = NULL;
|
||||
main_win->tmp_ext[1] = NULL;
|
||||
if (main_win->user_mi) {
|
||||
if (main_win->user_mi->user_ext[0])
|
||||
main_win->tmp_ext[0] = copy_mi_extensions (main_win->user_mi->user_ext[0]);
|
||||
if (main_win->user_mi->user_ext[1])
|
||||
main_win->tmp_ext[1] = copy_mi_extensions (main_win->user_mi->user_ext[1]);
|
||||
}
|
||||
initialize_main_win_vals ();
|
||||
|
||||
switch(gnome_dialog_run (GNOME_DIALOG (main_win->window))) {
|
||||
|
@ -308,3 +567,7 @@ show_edit_window (void)
|
|||
if (main_win && main_win->mi && main_win->window)
|
||||
gtk_widget_show (main_win->window);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
/* 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);
|
||||
static void add_to_key (char *mime_type, char *def, GHashTable *table);
|
||||
void add_to_key (char *mime_type, char *def, GHashTable *table, gboolean init_user);
|
||||
static char *get_priority (char *def, int *priority);
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@ static char *get_priority (char *def, int *priority);
|
|||
static char *current_lang;
|
||||
static GHashTable *mime_types = NULL;
|
||||
static GHashTable *initial_user_mime_types = NULL;
|
||||
static GHashTable *user_mime_types = NULL;
|
||||
GHashTable *user_mime_types = NULL;
|
||||
static GtkWidget *clist = NULL;
|
||||
extern GtkWidget *delete_button;
|
||||
extern GtkWidget *capplet;
|
||||
|
@ -73,8 +73,8 @@ free_mime_info (MimeInfo *mi)
|
|||
{
|
||||
|
||||
}
|
||||
static void
|
||||
add_to_key (char *mime_type, char *def, GHashTable *table)
|
||||
void
|
||||
add_to_key (char *mime_type, char *def, GHashTable *table, gboolean init_user)
|
||||
{
|
||||
int priority = 1;
|
||||
char *s, *p, *ext;
|
||||
|
@ -89,6 +89,8 @@ add_to_key (char *mime_type, char *def, GHashTable *table)
|
|||
info->regex[1] = NULL;
|
||||
info->ext[0] = NULL;
|
||||
info->ext[1] = NULL;
|
||||
info->user_ext[0] = NULL;
|
||||
info->user_ext[1] = NULL;
|
||||
info->regex_readable[0] = NULL;
|
||||
info->regex_readable[1] = NULL;
|
||||
info->ext_readable[0] = NULL;
|
||||
|
@ -107,7 +109,11 @@ add_to_key (char *mime_type, char *def, GHashTable *table)
|
|||
|
||||
while ((ext = strtok_r (s, " \t\n\r,", &tokp)) != NULL){
|
||||
/* FIXME: We really need to check for duplicates before entering this. */
|
||||
info->ext[priority] = g_list_prepend (info->ext[priority], ext);
|
||||
if (!init_user) {
|
||||
info->ext[priority] = g_list_prepend (info->ext[priority], ext);
|
||||
} else {
|
||||
info->user_ext[priority] = g_list_prepend (info->user_ext[priority], ext);
|
||||
}
|
||||
used = 1;
|
||||
s = NULL;
|
||||
}
|
||||
|
@ -178,10 +184,13 @@ mime_fill_from_file (const char *filename, gboolean init_user)
|
|||
|
||||
if (*p == 0)
|
||||
continue;
|
||||
add_to_key (current_key, p, mime_types);
|
||||
add_to_key (current_key, p, mime_types, init_user);
|
||||
if (init_user) {
|
||||
add_to_key (current_key, p, initial_user_mime_types);
|
||||
add_to_key (current_key, p, user_mime_types);
|
||||
add_to_key (current_key, p,
|
||||
initial_user_mime_types,
|
||||
TRUE);
|
||||
add_to_key (current_key, p,
|
||||
user_mime_types, TRUE);
|
||||
}
|
||||
used = TRUE;
|
||||
}
|
||||
|
@ -255,6 +264,13 @@ add_mime_vals_to_clist (gchar *mime_type, gpointer mi, gpointer cl)
|
|||
if (list->next != NULL)
|
||||
g_string_append (extension, ", ");
|
||||
}
|
||||
if (strcmp (extension->str, "") != 0 && ((MimeInfo *)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);
|
||||
|
||||
|
@ -264,16 +280,23 @@ add_mime_vals_to_clist (gchar *mime_type, gpointer mi, gpointer cl)
|
|||
if (list->next)
|
||||
g_string_append (extension, ", ");
|
||||
}
|
||||
if (strcmp (extension->str, "") != 0 && ((MimeInfo *)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]) {
|
||||
if (((MimeInfo *) mi)->ext[0] || ((MimeInfo *) mi)->user_ext[0]) {
|
||||
extension = g_string_new ((((MimeInfo *) mi)->ext_readable[0]));
|
||||
if (((MimeInfo *) mi)->ext[1]) {
|
||||
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])
|
||||
} 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 ("");
|
||||
|
@ -338,6 +361,9 @@ edit_clicked (GtkWidget *widget, gpointer data)
|
|||
mi = (MimeInfo *) gtk_clist_get_row_data (GTK_CLIST (clist), row);
|
||||
if (mi)
|
||||
launch_edit_window (mi);
|
||||
gtk_clist_remove (GTK_CLIST (clist), row);
|
||||
row = add_mime_vals_to_clist (mi->mime_type, mi, clist);
|
||||
gtk_clist_select_row (GTK_CLIST (clist), row, 0);
|
||||
}
|
||||
void
|
||||
add_clicked (GtkWidget *widget, gpointer data)
|
||||
|
@ -378,7 +404,6 @@ finalize_mime_type_foreach (gpointer mime_type, gpointer info, gpointer data)
|
|||
MimeInfo *mi = (MimeInfo *)info;
|
||||
GList *list;
|
||||
GString *extension;
|
||||
gint row;
|
||||
|
||||
extension = g_string_new ("");
|
||||
for (list = ((MimeInfo *) mi)->ext[0];list; list=list->next) {
|
||||
|
@ -386,6 +411,13 @@ finalize_mime_type_foreach (gpointer mime_type, gpointer info, gpointer 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);
|
||||
|
||||
|
@ -395,16 +427,23 @@ finalize_mime_type_foreach (gpointer mime_type, gpointer info, gpointer 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]) {
|
||||
if (((MimeInfo *) mi)->ext[0] || ((MimeInfo *) mi)->user_ext[0]) {
|
||||
extension = g_string_new ((((MimeInfo *) mi)->ext_readable[0]));
|
||||
if (((MimeInfo *) mi)->ext[1]) {
|
||||
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])
|
||||
} 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 ("");
|
||||
|
@ -476,18 +515,18 @@ add_new_mime_type (gchar *mime_type, gchar *raw_ext, gchar *regexp1, gchar *rege
|
|||
/* passed check, now we add it. */
|
||||
if (ext) {
|
||||
temp = g_strconcat ("ext: ", ext, NULL);
|
||||
add_to_key (mime_type, temp, user_mime_types);
|
||||
add_to_key (mime_type, temp, user_mime_types, TRUE);
|
||||
mi = (MimeInfo *) g_hash_table_lookup (user_mime_types, mime_type);
|
||||
g_free (temp);
|
||||
}
|
||||
if (regexp1) {
|
||||
temp = g_strconcat ("regex: ", regexp1, NULL);
|
||||
add_to_key (mime_type, temp, user_mime_types);
|
||||
add_to_key (mime_type, temp, user_mime_types, TRUE);
|
||||
g_free (temp);
|
||||
}
|
||||
if (regexp2) {
|
||||
temp = g_strconcat ("regex,2: ", regexp2, NULL);
|
||||
add_to_key (mime_type, temp, user_mime_types);
|
||||
add_to_key (mime_type, temp, user_mime_types, TRUE);
|
||||
g_free (temp);
|
||||
}
|
||||
/* Finally add it to the clist */
|
||||
|
@ -609,3 +648,9 @@ discard_mime_info ()
|
|||
g_free (filename);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -11,12 +11,16 @@ typedef struct {
|
|||
char *mime_type;
|
||||
regex_t *regex[2];
|
||||
GList *ext[2];
|
||||
GList *user_ext[2];
|
||||
char *ext_readable[2];
|
||||
char *regex_readable[2];
|
||||
char *file_name;
|
||||
GList *keys;
|
||||
} MimeInfo;
|
||||
|
||||
extern GHashTable *user_mime_types;
|
||||
extern void add_to_key (char *mime_type, char *def, GHashTable *table, gboolean init_user);
|
||||
|
||||
GtkWidget *get_mime_clist (void);
|
||||
void init_mime_type (void);
|
||||
void delete_clicked (GtkWidget *widget, gpointer data);
|
||||
|
|
|
@ -468,8 +468,8 @@ discard_key_info (void)
|
|||
|
||||
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_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);
|
||||
|
|
|
@ -30,7 +30,7 @@ left_aligned_button (gchar *label)
|
|||
0.0, 0.5);
|
||||
gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child),
|
||||
GNOME_PAD_SMALL, 0);
|
||||
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ init_mime_capplet ()
|
|||
GtkWidget *vbox;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *button;
|
||||
|
||||
|
||||
capplet = capplet_widget_new ();
|
||||
delete_button = left_aligned_button (_("Delete"));
|
||||
gtk_signal_connect (GTK_OBJECT (delete_button), "clicked",
|
||||
|
|
Loading…
Reference in New Issue