2002-01-08 21:25:33 +00:00
|
|
|
|
/* -*- mode: c; style: linux -*- */
|
|
|
|
|
|
|
|
|
|
/* mime-type-info.c
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2000 Eazel, Inc.
|
|
|
|
|
* Copyright (C) 2002 Ximian, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Written by Bradford Hovinen <hovinen@ximian.com>,
|
|
|
|
|
* Jonathan Blandford <jrb@redhat.com>,
|
|
|
|
|
* Gene Z. Ragan <gzr@eazel.com>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
# include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <bonobo.h>
|
2002-01-11 19:28:08 +00:00
|
|
|
|
#include <libgnomevfs/gnome-vfs-application-registry.h>
|
2002-01-25 17:27:02 +00:00
|
|
|
|
#include <libgnomevfs/gnome-vfs-utils.h>
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
2002-01-11 20:45:15 +00:00
|
|
|
|
#include "libuuid/uuid.h"
|
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
|
#include "mime-type-info.h"
|
2002-01-11 15:32:10 +00:00
|
|
|
|
#include "mime-types-model.h"
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
/* List of MimeTypeInfo structures that have data to be committed */
|
2002-01-11 20:13:50 +00:00
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
|
static GList *dirty_list = NULL;
|
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
static const gchar *get_category_name (const gchar *mime_type);
|
|
|
|
|
static GSList *get_lang_list (void);
|
|
|
|
|
static gchar *form_extensions_string (const MimeTypeInfo *info,
|
|
|
|
|
gchar *sep,
|
|
|
|
|
gchar *prepend);
|
|
|
|
|
static void get_icon_pixbuf (MimeTypeInfo *info,
|
2002-01-25 17:27:02 +00:00
|
|
|
|
const gchar *icon_path,
|
2002-01-25 16:12:01 +00:00
|
|
|
|
gboolean want_large);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
static MimeTypeInfo *get_category (const gchar *category_name);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
void
|
|
|
|
|
load_all_mime_types (void)
|
|
|
|
|
{
|
|
|
|
|
GList *list, *tmp;
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
list = gnome_vfs_get_registered_mime_types ();
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
for (tmp = list; tmp != NULL; tmp = tmp->next)
|
|
|
|
|
mime_type_info_new (tmp->data);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
g_list_free (list);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
MimeTypeInfo *
|
|
|
|
|
mime_type_info_new (const gchar *mime_type)
|
2002-01-11 15:32:10 +00:00
|
|
|
|
{
|
2002-01-25 16:12:01 +00:00
|
|
|
|
MimeTypeInfo *info;
|
2002-01-11 15:32:10 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
info = g_new0 (MimeTypeInfo, 1);
|
|
|
|
|
MODEL_ENTRY (info)->type = MODEL_ENTRY_MIME_TYPE;
|
2002-01-11 15:32:10 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
if (mime_type != NULL) {
|
|
|
|
|
info->mime_type = g_strdup (mime_type);
|
2002-01-11 15:32:10 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
mime_type_info_set_category_name (info, get_category_name (mime_type));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return info;
|
2002-01-11 15:32:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
|
MimeTypeInfo *
|
2002-01-25 16:12:01 +00:00
|
|
|
|
mime_type_info_new_category (MimeTypeInfo *parent, const gchar *category)
|
2002-01-08 21:25:33 +00:00
|
|
|
|
{
|
2002-01-11 15:32:10 +00:00
|
|
|
|
MimeTypeInfo *info;
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
info = g_new0 (MimeTypeInfo, 1);
|
|
|
|
|
MODEL_ENTRY (info)->type = MODEL_ENTRY_CATEGORY;
|
2002-01-11 20:13:50 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
info->description = g_strdup (category);
|
|
|
|
|
MODEL_ENTRY (info)->parent = MODEL_ENTRY (parent);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
if (parent != NULL)
|
|
|
|
|
model_entry_insert_child (MODEL_ENTRY (parent), MODEL_ENTRY (info));
|
2002-01-11 20:13:50 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
return info;
|
|
|
|
|
}
|
2002-01-11 20:13:50 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
/* Fill in the remaining fields in a MimeTypeInfo structure; suitable for
|
|
|
|
|
* subsequent use in an edit dialog */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
mime_type_info_load_all (MimeTypeInfo *info)
|
|
|
|
|
{
|
|
|
|
|
gchar *tmp;
|
|
|
|
|
|
|
|
|
|
mime_type_info_get_description (info);
|
|
|
|
|
mime_type_info_get_file_extensions (info);
|
|
|
|
|
|
|
|
|
|
if (info->default_action == NULL)
|
|
|
|
|
info->default_action = gnome_vfs_mime_get_default_application (info->mime_type);
|
|
|
|
|
|
|
|
|
|
if (info->icon_name == NULL)
|
|
|
|
|
info->icon_name = g_strdup (gnome_vfs_mime_get_icon (info->mime_type));
|
|
|
|
|
|
|
|
|
|
if (info->icon_pixbuf == NULL)
|
|
|
|
|
get_icon_pixbuf (info, info->icon_name, TRUE);
|
|
|
|
|
|
|
|
|
|
if (info->custom_line == NULL) {
|
|
|
|
|
tmp = g_strdup_printf ("Custom %s", info->mime_type);
|
|
|
|
|
|
|
|
|
|
if (info->default_action != NULL && !strcmp (info->default_action->name, tmp)) {
|
|
|
|
|
info->custom_line = g_strdup (info->default_action->command);
|
|
|
|
|
info->needs_terminal = gnome_vfs_application_registry_get_bool_value
|
|
|
|
|
(info->default_action->id, "requires_terminal", NULL);
|
|
|
|
|
gnome_vfs_mime_application_free (info->default_action);
|
|
|
|
|
info->default_action = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (tmp);
|
2002-01-11 19:28:08 +00:00
|
|
|
|
}
|
2002-01-11 15:32:10 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
if (info->default_component == NULL)
|
|
|
|
|
info->default_component = gnome_vfs_mime_get_default_component (info->mime_type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
|
mime_type_info_get_description (MimeTypeInfo *info)
|
|
|
|
|
{
|
|
|
|
|
if (info->description == NULL)
|
|
|
|
|
info->description = g_strdup (gnome_vfs_mime_get_description (info->mime_type));
|
|
|
|
|
|
|
|
|
|
return info->description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GdkPixbuf *
|
|
|
|
|
mime_type_info_get_icon (MimeTypeInfo *info)
|
|
|
|
|
{
|
|
|
|
|
if (info->small_icon_pixbuf == NULL)
|
2002-01-25 17:27:02 +00:00
|
|
|
|
get_icon_pixbuf (info, mime_type_info_get_icon_path (info), FALSE);
|
2002-01-25 16:12:01 +00:00
|
|
|
|
|
|
|
|
|
g_object_ref (G_OBJECT (info->small_icon_pixbuf));
|
|
|
|
|
|
|
|
|
|
return info->small_icon_pixbuf;
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-25 17:27:02 +00:00
|
|
|
|
const gchar *
|
|
|
|
|
mime_type_info_get_icon_path (MimeTypeInfo *info)
|
|
|
|
|
{
|
|
|
|
|
gchar *tmp;
|
|
|
|
|
|
|
|
|
|
if (info->icon_name == NULL)
|
|
|
|
|
info->icon_name = g_strdup (gnome_vfs_mime_get_icon (info->mime_type));
|
|
|
|
|
|
|
|
|
|
if (g_file_exists (info->icon_name)) {
|
|
|
|
|
info->icon_path = g_strdup (info->icon_name);
|
|
|
|
|
return info->icon_path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info->icon_path = gnome_vfs_icon_path_from_filename (info->icon_name);
|
|
|
|
|
|
|
|
|
|
if (info->icon_path == NULL) {
|
|
|
|
|
tmp = g_strconcat (info->icon_name, ".png", NULL);
|
|
|
|
|
info->icon_path = gnome_vfs_icon_path_from_filename (tmp);
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (info->icon_path == NULL) {
|
|
|
|
|
tmp = g_strconcat ("nautilus/", info->icon_name, NULL);
|
|
|
|
|
info->icon_path = gnome_vfs_icon_path_from_filename (tmp);
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (info->icon_path == NULL) {
|
|
|
|
|
tmp = g_strconcat ("nautilus/", info->icon_name, ".png", NULL);
|
|
|
|
|
info->icon_path = gnome_vfs_icon_path_from_filename (tmp);
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (info->icon_path == NULL)
|
|
|
|
|
info->icon_path = gnome_vfs_icon_path_from_filename ("nautilus/i-regular-24.png");
|
|
|
|
|
|
|
|
|
|
return info->icon_path;
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
const GList *
|
|
|
|
|
mime_type_info_get_file_extensions (MimeTypeInfo *info)
|
|
|
|
|
{
|
|
|
|
|
if (info->file_extensions == NULL)
|
|
|
|
|
info->file_extensions = gnome_vfs_mime_get_extensions_list (info->mime_type);
|
|
|
|
|
|
|
|
|
|
return info->file_extensions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gchar *
|
|
|
|
|
mime_type_info_get_file_extensions_pretty_string (MimeTypeInfo *info)
|
|
|
|
|
{
|
|
|
|
|
mime_type_info_get_file_extensions (info);
|
|
|
|
|
|
|
|
|
|
return form_extensions_string (info, ", ", ".");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gchar *
|
|
|
|
|
mime_type_info_get_category_name (const MimeTypeInfo *info)
|
|
|
|
|
{
|
|
|
|
|
GString *string;
|
|
|
|
|
ModelEntry *tmp;
|
|
|
|
|
gchar *ret;
|
2002-01-11 20:45:15 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
string = g_string_new ("");
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
if (info->entry.type == MODEL_ENTRY_CATEGORY)
|
|
|
|
|
tmp = MODEL_ENTRY (info);
|
|
|
|
|
else
|
|
|
|
|
tmp = info->entry.parent;
|
|
|
|
|
|
|
|
|
|
for (; tmp->type != MODEL_ENTRY_NONE; tmp = tmp->parent) {
|
|
|
|
|
g_string_prepend (string, MIME_TYPE_INFO (tmp)->description);
|
|
|
|
|
g_string_prepend (string, "/");
|
2002-01-08 21:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
ret = g_strdup ((*string->str == '\0') ? string->str : string->str + 1);
|
|
|
|
|
g_string_free (string, TRUE);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2002-01-11 15:32:10 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
GList *
|
|
|
|
|
mime_type_info_category_find_supported_apps (MimeTypeInfo *info)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
mime_type_info_set_category_name (const MimeTypeInfo *info, const gchar *category_name)
|
|
|
|
|
{
|
|
|
|
|
if (MODEL_ENTRY (info)->parent != NULL)
|
|
|
|
|
model_entry_remove_child (MODEL_ENTRY (info)->parent, MODEL_ENTRY (info));
|
|
|
|
|
|
|
|
|
|
if (category_name != NULL) {
|
|
|
|
|
MODEL_ENTRY (info)->parent = MODEL_ENTRY (get_category (category_name));
|
|
|
|
|
|
|
|
|
|
if (MODEL_ENTRY (info)->parent != NULL)
|
|
|
|
|
model_entry_insert_child (MODEL_ENTRY (info)->parent, MODEL_ENTRY (info));
|
|
|
|
|
} else {
|
|
|
|
|
MODEL_ENTRY (info)->parent = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
mime_type_info_set_file_extensions (MimeTypeInfo *info, GList *list)
|
|
|
|
|
{
|
|
|
|
|
/* FIXME: Free the old list */
|
|
|
|
|
info->file_extensions = list;
|
2002-01-08 21:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
mime_type_info_save (const MimeTypeInfo *info)
|
|
|
|
|
{
|
2002-01-14 15:28:36 +00:00
|
|
|
|
gchar *tmp;
|
2002-01-11 20:45:15 +00:00
|
|
|
|
uuid_t app_uuid;
|
|
|
|
|
gchar app_uuid_str[100];
|
|
|
|
|
GnomeVFSMimeApplication app;
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
|
|
|
|
gnome_vfs_mime_set_description (info->mime_type, info->description);
|
|
|
|
|
gnome_vfs_mime_set_icon (info->mime_type, info->icon_name);
|
|
|
|
|
|
2002-01-11 19:28:08 +00:00
|
|
|
|
if (info->default_action != NULL) {
|
|
|
|
|
gnome_vfs_mime_set_default_application (info->mime_type, info->default_action->id);
|
|
|
|
|
}
|
|
|
|
|
else if (info->custom_line != NULL && *info->custom_line != '\0') {
|
2002-01-11 20:45:15 +00:00
|
|
|
|
uuid_generate (app_uuid);
|
|
|
|
|
uuid_unparse (app_uuid, app_uuid_str);
|
|
|
|
|
|
|
|
|
|
app.id = app_uuid_str;
|
|
|
|
|
app.name = g_strdup_printf ("Custom %s", info->mime_type);
|
|
|
|
|
app.command = info->custom_line;
|
|
|
|
|
app.can_open_multiple_files = FALSE;
|
|
|
|
|
app.expects_uris = FALSE;
|
|
|
|
|
app.supported_uri_schemes = NULL;
|
2002-01-11 20:54:55 +00:00
|
|
|
|
app.requires_terminal = info->needs_terminal;
|
2002-01-11 20:45:15 +00:00
|
|
|
|
|
|
|
|
|
gnome_vfs_application_registry_save_mime_application (&app);
|
|
|
|
|
gnome_vfs_application_registry_sync ();
|
|
|
|
|
|
|
|
|
|
gnome_vfs_mime_set_default_application (info->mime_type, app.id);
|
|
|
|
|
g_free (app.name);
|
2002-01-11 19:28:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-01-11 15:32:10 +00:00
|
|
|
|
tmp = form_extensions_string (info, " ", NULL);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
gnome_vfs_mime_set_extensions_list (info->mime_type, tmp);
|
|
|
|
|
g_free (tmp);
|
2002-01-11 15:32:10 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
if (info->default_component != NULL)
|
|
|
|
|
gnome_vfs_mime_set_default_component (info->mime_type, info->default_component->iid);
|
|
|
|
|
else
|
|
|
|
|
gnome_vfs_mime_set_default_component (info->mime_type, NULL);
|
2002-01-11 15:32:10 +00:00
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
tmp = mime_type_info_get_category_name (info);
|
|
|
|
|
gnome_vfs_mime_set_value (info->mime_type, "category", tmp);
|
2002-01-11 15:32:10 +00:00
|
|
|
|
g_free (tmp);
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
|
void
|
|
|
|
|
mime_type_info_free (MimeTypeInfo *info)
|
|
|
|
|
{
|
2002-01-11 20:14:51 +00:00
|
|
|
|
dirty_list = g_list_remove (dirty_list, info);
|
2002-01-11 20:13:50 +00:00
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
|
g_free (info->mime_type);
|
|
|
|
|
g_free (info->description);
|
|
|
|
|
g_free (info->icon_name);
|
2002-01-25 17:27:02 +00:00
|
|
|
|
g_free (info->icon_path);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
gnome_vfs_mime_extensions_list_free (info->file_extensions);
|
2002-01-25 16:12:01 +00:00
|
|
|
|
CORBA_free (info->default_component);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
gnome_vfs_mime_application_free (info->default_action);
|
|
|
|
|
g_free (info->custom_line);
|
2002-01-25 16:12:01 +00:00
|
|
|
|
|
|
|
|
|
if (info->icon_pixbuf != NULL)
|
|
|
|
|
g_object_unref (G_OBJECT (info->icon_pixbuf));
|
|
|
|
|
if (info->small_icon_pixbuf != NULL)
|
|
|
|
|
g_object_unref (G_OBJECT (info->small_icon_pixbuf));
|
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
|
g_free (info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
mime_type_get_pretty_name_for_server (Bonobo_ServerInfo *server)
|
|
|
|
|
{
|
|
|
|
|
const char *view_as_name;
|
|
|
|
|
char *display_name;
|
|
|
|
|
GSList *langs;
|
|
|
|
|
|
|
|
|
|
display_name = NULL;
|
|
|
|
|
|
|
|
|
|
langs = get_lang_list ();
|
|
|
|
|
view_as_name = bonobo_server_info_prop_lookup (server, "nautilus:view_as_name", langs);
|
|
|
|
|
|
|
|
|
|
if (view_as_name == NULL)
|
|
|
|
|
view_as_name = bonobo_server_info_prop_lookup (server, "name", langs);
|
|
|
|
|
|
|
|
|
|
if (view_as_name == NULL)
|
|
|
|
|
view_as_name = server->iid;
|
|
|
|
|
|
|
|
|
|
g_slist_foreach (langs, (GFunc) g_free, NULL);
|
|
|
|
|
g_slist_free (langs);
|
|
|
|
|
|
|
|
|
|
/* if the name is an OAFIID, clean it up for display */
|
|
|
|
|
if (!strncmp (view_as_name, "OAFIID:", strlen ("OAFIID:"))) {
|
|
|
|
|
char *display_name, *colon_ptr;
|
|
|
|
|
|
|
|
|
|
display_name = g_strdup (view_as_name + strlen ("OAFIID:"));
|
|
|
|
|
colon_ptr = strchr (display_name, ':');
|
|
|
|
|
if (colon_ptr)
|
|
|
|
|
*colon_ptr = '\0';
|
|
|
|
|
|
|
|
|
|
return display_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return g_strdup_printf ("View as %s", view_as_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
mime_type_append_to_dirty_list (MimeTypeInfo *info)
|
|
|
|
|
{
|
|
|
|
|
if (g_list_find (dirty_list, info) == NULL)
|
|
|
|
|
dirty_list = g_list_prepend (dirty_list, info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
mime_type_remove_from_dirty_list (const gchar *mime_type)
|
|
|
|
|
{
|
|
|
|
|
GList *tmp = dirty_list, *tmp1;
|
|
|
|
|
|
|
|
|
|
while (tmp != NULL) {
|
|
|
|
|
tmp1 = tmp->next;
|
|
|
|
|
if (!strcmp (mime_type, ((MimeTypeInfo *) tmp->data)->mime_type))
|
|
|
|
|
dirty_list = g_list_remove_link (dirty_list, tmp);
|
|
|
|
|
tmp = tmp1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
mime_type_commit_dirty_list (void)
|
|
|
|
|
{
|
|
|
|
|
gnome_vfs_mime_freeze ();
|
|
|
|
|
g_list_foreach (dirty_list, (GFunc) mime_type_info_save, NULL);
|
|
|
|
|
gnome_vfs_mime_thaw ();
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const gchar *
|
|
|
|
|
get_category_name (const gchar *mime_type)
|
|
|
|
|
{
|
|
|
|
|
const gchar *path;
|
|
|
|
|
|
|
|
|
|
path = gnome_vfs_mime_get_value (mime_type, "category");
|
|
|
|
|
|
|
|
|
|
if (path != NULL)
|
|
|
|
|
return g_strdup (path);
|
|
|
|
|
else if (!strncmp (mime_type, "image/", strlen ("image/")))
|
|
|
|
|
return "Images";
|
|
|
|
|
else if (!strncmp (mime_type, "video/", strlen ("video/")))
|
|
|
|
|
return "Video";
|
|
|
|
|
else if (!strncmp (mime_type, "audio/", strlen ("audio/")))
|
|
|
|
|
return "Audio";
|
|
|
|
|
else
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GSList *
|
|
|
|
|
get_lang_list (void)
|
|
|
|
|
{
|
|
|
|
|
GSList *retval;
|
|
|
|
|
const char *lang;
|
|
|
|
|
char *equal_char;
|
|
|
|
|
|
|
|
|
|
retval = NULL;
|
|
|
|
|
|
|
|
|
|
lang = g_getenv ("LANGUAGE");
|
|
|
|
|
|
|
|
|
|
if (lang == NULL)
|
|
|
|
|
lang = g_getenv ("LANG");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (lang != NULL) {
|
|
|
|
|
equal_char = strchr (lang, '=');
|
|
|
|
|
if (equal_char != NULL)
|
|
|
|
|
lang = equal_char + 1;
|
|
|
|
|
|
|
|
|
|
retval = g_slist_prepend (retval, g_strdup (lang));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
|
form_extensions_string (const MimeTypeInfo *info, gchar *sep, gchar *prepend)
|
|
|
|
|
{
|
|
|
|
|
gchar *tmp;
|
|
|
|
|
gchar **array;
|
|
|
|
|
GList *l;
|
|
|
|
|
gint i = 0;
|
|
|
|
|
|
|
|
|
|
if (prepend == NULL)
|
|
|
|
|
prepend = "";
|
|
|
|
|
|
|
|
|
|
array = g_new0 (gchar *, g_list_length (info->file_extensions) + 1);
|
|
|
|
|
for (l = info->file_extensions; l != NULL; l = l->next)
|
|
|
|
|
array[i++] = g_strconcat (prepend, l->data, NULL);
|
|
|
|
|
tmp = g_strjoinv (sep, array);
|
|
|
|
|
g_strfreev (array);
|
|
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Loads a pixbuf for the icon, falling back on the default icon if
|
|
|
|
|
* necessary
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void
|
2002-01-25 17:27:02 +00:00
|
|
|
|
get_icon_pixbuf (MimeTypeInfo *info, const gchar *icon_path, gboolean want_large)
|
2002-01-25 16:12:01 +00:00
|
|
|
|
{
|
|
|
|
|
static GHashTable *icon_table = NULL;
|
|
|
|
|
|
2002-01-25 17:27:02 +00:00
|
|
|
|
if (icon_path == NULL)
|
|
|
|
|
icon_path = gnome_vfs_icon_path_from_filename ("nautilus/i-regular-24.png");
|
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
|
if ((want_large && info->icon_pixbuf != NULL) || info->small_icon_pixbuf != NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (icon_table == NULL)
|
|
|
|
|
icon_table = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
|
|
2002-01-25 17:27:02 +00:00
|
|
|
|
if (!want_large)
|
|
|
|
|
info->small_icon_pixbuf = g_hash_table_lookup (icon_table, icon_path);
|
2002-01-25 16:12:01 +00:00
|
|
|
|
|
2002-01-25 17:27:02 +00:00
|
|
|
|
if (info->small_icon_pixbuf != NULL) {
|
|
|
|
|
g_object_ref (G_OBJECT (info->small_icon_pixbuf));
|
|
|
|
|
} else {
|
|
|
|
|
info->icon_pixbuf = gdk_pixbuf_new_from_file (icon_path, NULL);
|
2002-01-25 16:12:01 +00:00
|
|
|
|
|
2002-01-25 17:27:02 +00:00
|
|
|
|
if (info->icon_pixbuf == NULL) {
|
|
|
|
|
get_icon_pixbuf (info, NULL, want_large);
|
2002-01-25 16:12:01 +00:00
|
|
|
|
}
|
2002-01-25 17:27:02 +00:00
|
|
|
|
else if (!want_large) {
|
|
|
|
|
info->small_icon_pixbuf =
|
|
|
|
|
gdk_pixbuf_scale_simple (info->icon_pixbuf, 16, 16, GDK_INTERP_HYPER);
|
2002-01-25 16:12:01 +00:00
|
|
|
|
|
2002-01-25 17:27:02 +00:00
|
|
|
|
g_hash_table_insert (icon_table, g_strdup (icon_path), info->small_icon_pixbuf);
|
|
|
|
|
}
|
2002-01-25 16:12:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MimeTypeInfo *
|
|
|
|
|
get_category (const gchar *category_name)
|
|
|
|
|
{
|
|
|
|
|
ModelEntry *current, *child;
|
|
|
|
|
gchar **categories;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (category_name == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
categories = g_strsplit (category_name, "/", -1);
|
|
|
|
|
|
|
|
|
|
current = get_model_entries ();
|
|
|
|
|
|
|
|
|
|
for (i = 0; categories[i] != NULL; i++) {
|
|
|
|
|
for (child = current->first_child; child != NULL; child = child->next) {
|
|
|
|
|
if (child->type != MODEL_ENTRY_CATEGORY)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!strcmp (MIME_TYPE_INFO (child)->description, categories[i]))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (child == NULL)
|
|
|
|
|
child = MODEL_ENTRY (mime_type_info_new_category (MIME_TYPE_INFO (current), categories[i]));
|
|
|
|
|
|
|
|
|
|
current = child;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_strfreev (categories);
|
|
|
|
|
|
|
|
|
|
return MIME_TYPE_INFO (current);
|
|
|
|
|
}
|