From a036012fe5971e8c46c69e3b43323abc9522dd8e Mon Sep 17 00:00:00 2001 From: "Gene Z. Ragan" Date: Sun, 17 Sep 2000 03:15:40 +0000 Subject: [PATCH] Fixed bug 3042, Adding new mime type doesn't work 2000-09-16 Gene Z. Ragan Fixed bug 3042, Adding new mime type doesn't work * mime-type-capplet/nautilus-mime-type-capplet-dialogs.c: (nautilus_mime_type_capplet_show_new_mime_window): Return the new mime type if one was created * mime-type-capplet/nautilus-mime-type-capplet-dialogs.h: * mime-type-capplet/nautilus-mime-type-capplet.c: (nautilus_mime_type_capplet_update_info), (add_mime_clicked): Add info to main list. --- .../file-types/file-types-capplet-dialogs.c | 23 +++- .../file-types/file-types-capplet-dialogs.h | 2 +- capplets/file-types/file-types-capplet.c | 113 +++++++++++++++++- 3 files changed, 131 insertions(+), 7 deletions(-) diff --git a/capplets/file-types/file-types-capplet-dialogs.c b/capplets/file-types/file-types-capplet-dialogs.c index 077a84c55..133a738a2 100644 --- a/capplets/file-types/file-types-capplet-dialogs.c +++ b/capplets/file-types/file-types-capplet-dialogs.c @@ -562,15 +562,20 @@ name_from_oaf_server_info (OAF_ServerInfo *server) return g_strdup(view_as_name); } -void +char * nautilus_mime_type_capplet_show_new_mime_window (void) { GtkWidget *dialog; GtkWidget *mime_entry; GtkWidget *label; - GtkWidget *ext_entry; + GtkWidget *desc_entry; GtkWidget *hbox; GtkWidget *vbox; + GnomeVFSResult result; + const char *type, *description; + char *mime_type; + + mime_type = NULL; dialog = gnome_dialog_new (_("Add Mime Type"), GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, NULL); label = gtk_label_new (_("Add a new Mime Type\nFor example: image/tiff; text/x-scheme")); @@ -598,15 +603,23 @@ nautilus_mime_type_capplet_show_new_mime_window (void) gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); hbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL); gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (_("Description:")), FALSE, FALSE, 0); - ext_entry = gtk_entry_new (); - gtk_box_pack_start (GTK_BOX (hbox), ext_entry, TRUE, TRUE, 0); + desc_entry = gtk_entry_new (); + gtk_box_pack_start (GTK_BOX (hbox), desc_entry, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); gtk_widget_show_all (GNOME_DIALOG (dialog)->vbox); switch (gnome_dialog_run (GNOME_DIALOG (dialog))) { case 0: + type = gtk_entry_get_text (GTK_ENTRY (mime_entry)); + description = gtk_entry_get_text (GTK_ENTRY (desc_entry)); + /* Add new mime type here */ + if (strlen (type) > 3) { + result = gnome_vfs_mime_set_registered_type_key (type, "description", description); + mime_type = g_strdup (type); + } + /* Fall through to close dialog */ case 1: gtk_widget_destroy (dialog); @@ -615,6 +628,8 @@ nautilus_mime_type_capplet_show_new_mime_window (void) default: break; } + + return mime_type; } void diff --git a/capplets/file-types/file-types-capplet-dialogs.h b/capplets/file-types/file-types-capplet-dialogs.h index 35142967b..0a3395dab 100644 --- a/capplets/file-types/file-types-capplet-dialogs.h +++ b/capplets/file-types/file-types-capplet-dialogs.h @@ -28,7 +28,7 @@ void show_edit_applications_dialog (const char *mime_type); void show_edit_components_dialog (const char *mime_type); char *name_from_oaf_server_info (OAF_ServerInfo *server); -void nautilus_mime_type_capplet_show_new_mime_window (void); +char *nautilus_mime_type_capplet_show_new_mime_window (void); void nautilus_mime_type_capplet_show_new_extension_window (void); #endif /* NAUTILUS_MIME_TYPE_CAPPLET_DIALOGS_H */ diff --git a/capplets/file-types/file-types-capplet.c b/capplets/file-types/file-types-capplet.c index ef3271326..93b590b3e 100644 --- a/capplets/file-types/file-types-capplet.c +++ b/capplets/file-types/file-types-capplet.c @@ -513,7 +513,6 @@ nautilus_mime_type_capplet_update_info (const char *mime_type) { /* Update text items */ gtk_label_set_text (GTK_LABEL (mime_label), mime_type); - /* Add description to first column */ description = gnome_vfs_mime_get_description (mime_type); if (description != NULL && strlen (description) > 0) { gtk_entry_set_text (GTK_ENTRY (description_entry), description); @@ -881,7 +880,117 @@ delete_mime_clicked (GtkWidget *widget, gpointer data) static void add_mime_clicked (GtkWidget *widget, gpointer data) { - nautilus_mime_type_capplet_show_new_mime_window (); + static gchar *text[3]; + const char *description, *action_icon_name, *description_icon_name; + char *extensions, *mime_string, *action_icon_path, *description_icon_path; + gint row; + GdkPixbuf *pixbuf; + GdkPixmap *pixmap; + GdkBitmap *bitmap; + GnomeVFSMimeAction *action; + GnomeVFSMimeApplication *default_app; + OAF_ServerInfo *default_component; + + mime_string = nautilus_mime_type_capplet_show_new_mime_window (); + if (mime_string != NULL) { + /* Add new type to mime list */ + pixbuf = NULL; + + /* Add description to first column */ + description = gnome_vfs_mime_get_description (mime_string); + if (description != NULL && strlen (description) > 0) { + text[0] = g_strdup (description); + } else { + text[0] = g_strdup (""); + } + + /* Add mime type to second column */ + text[1] = mime_string; + + /* Add extension to third columns */ + extensions = gnome_vfs_mime_get_extensions_pretty_string (mime_string); + if (extensions != NULL) { + text[2] = extensions; + } else { + text[2] = ""; + } + + /* Add default action to fourth column */ + text[3] = _("None"); + + /* Insert item into list */ + row = gtk_clist_insert (GTK_CLIST (mime_list), 1, text); + gtk_clist_set_row_data (GTK_CLIST (mime_list), row, g_strdup(mime_string)); + + /* Set description column icon */ + description_icon_name = gnome_vfs_mime_get_icon (mime_string); + if (description_icon_name != NULL) { + /* Get custom icon */ + description_icon_path = gnome_pixmap_file (description_icon_name); + if (description_icon_path != NULL) { + pixbuf = gdk_pixbuf_new_from_file (description_icon_path); + g_free (description_icon_path); + } + } else { + /* Use default icon */ + pixbuf = gdk_pixbuf_new_from_file ("/gnome/share/pixmaps/nautilus/i-regular-24.png"); + } + + if (pixbuf != NULL) { + pixbuf = capplet_gdk_pixbuf_scale_to_fit (pixbuf, 18, 18); + gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &bitmap, 100); + gtk_clist_set_pixtext (GTK_CLIST (mime_list), row, 0, text[0], 5, pixmap, bitmap); + gdk_pixbuf_unref (pixbuf); + } + + /* Set up action column */ + pixbuf = NULL; + action = gnome_vfs_mime_get_default_action (mime_string); + if (action != NULL) { + switch (action->action_type) { + case GNOME_VFS_MIME_ACTION_TYPE_APPLICATION: + /* Get the default application */ + default_app = gnome_vfs_mime_get_default_application (mime_string); + text[3] = default_app->name; + + action_icon_name = gnome_vfs_mime_get_icon (mime_string); + if (action_icon_name != NULL) { + /* Get custom icon */ + action_icon_path = gnome_pixmap_file (action_icon_name); + if (action_icon_path != NULL) { + pixbuf = gdk_pixbuf_new_from_file (action_icon_path); + g_free (action_icon_path); + } + } else { + /* Use default icon */ + pixbuf = gdk_pixbuf_new_from_file ("/gnome/share/pixmaps/nautilus/i-executable.png"); + } + break; + + case GNOME_VFS_MIME_ACTION_TYPE_COMPONENT: + /* Get the default component */ + default_component = gnome_vfs_mime_get_default_component (mime_string); + text[3] = name_from_oaf_server_info (default_component); + pixbuf = gdk_pixbuf_new_from_file ("/gnome/share/pixmaps/nautilus/gnome-library.png"); + break; + + default: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (application_button), TRUE); + break; + } + } + + /* Set column icon */ + if (pixbuf != NULL) { + pixbuf = capplet_gdk_pixbuf_scale_to_fit (pixbuf, 18, 18); + gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &bitmap, 100); + gtk_clist_set_pixtext (GTK_CLIST (mime_list), row, 3, text[3], 5, pixmap, bitmap); + gdk_pixbuf_unref (pixbuf); + } + + g_free (text[0]); + g_free (extensions); + } } static void