Fix logic (mime_type_info_load_all): Don't load default_action if

2002-01-28  Bradford Hovinen  <hovinen@ximian.com>

	* mime-type-info.c (update_subcategories): Fix logic
	(mime_type_info_load_all): Don't load default_action if
	custom_line is set

	* mime-category-edit-dialog.c (store_data): Call
	mime_category_info_update
	(store_data): Don't notify the model -- nothing there could have
	changed

	* mime-type-info.c (mime_category_info_update): Implement
	(update_subcategories): Update; split from set_subcategory_ids

	* mime-category-edit-dialog.c (populate_application_list): Notify
	destruction with gnome_vfs_mime_application_free
	(store_data): Store default action
	(store_data): Store custom line, needs terminal
	(populate_application_list): Set needs_terminal_toggle

	* mime-type-info.c (mime_type_info_get_use_category):
	Implement. Factor from mime_type_info_load_all
	(find_possible_supported_apps, reduce_supported_app_list): Use
	mime_type_info_get_use_category
	(get_gconf_base_name): Replace parentheses with '-'
	(mime_category_info_load_all): Only load default action, custom
	line if not already loaded

	* mime-edit-dialog.c (populate_component_list): Use get_all_components
	(populate_application_list): Use get_all_applications
This commit is contained in:
Bradford Hovinen 2002-01-28 16:43:40 +00:00 committed by Bradford Hovinen (Gdict maintainer)
parent 77558b138d
commit 2073f4108f
6 changed files with 156 additions and 63 deletions

View file

@ -1,3 +1,34 @@
2002-01-28 Bradford Hovinen <hovinen@ximian.com>
* mime-type-info.c (update_subcategories): Fix logic
(mime_type_info_load_all): Don't load default_action if
custom_line is set
* mime-category-edit-dialog.c (store_data): Call
mime_category_info_update
(store_data): Don't notify the model -- nothing there could have
changed
* mime-type-info.c (mime_category_info_update): Implement
(update_subcategories): Update; split from set_subcategory_ids
* mime-category-edit-dialog.c (populate_application_list): Notify
destruction with gnome_vfs_mime_application_free
(store_data): Store default action
(store_data): Store custom line, needs terminal
(populate_application_list): Set needs_terminal_toggle
* mime-type-info.c (mime_type_info_get_use_category):
Implement. Factor from mime_type_info_load_all
(find_possible_supported_apps, reduce_supported_app_list): Use
mime_type_info_get_use_category
(get_gconf_base_name): Replace parentheses with '-'
(mime_category_info_load_all): Only load default action, custom
line if not already loaded
* mime-edit-dialog.c (populate_component_list): Use get_all_components
(populate_application_list): Use get_all_applications
2002-01-27 Seth Nickell <snickell@stanford.edu>
* file-types.desktop.in:

View file

@ -1,4 +1,2 @@
- Add categories to many types in MIME database
- Better sorting on the MIME types tree
- Disable look at content for now
- Edit MIME type directly with command line option

View file

@ -329,7 +329,7 @@ populate_application_list (MimeCategoryEditDialog *dialog)
/* Store copy of application in item; free when item destroyed. */
g_object_set_data_full (G_OBJECT (menu_item),
"app", app,
(GDestroyNotify) g_free);
(GDestroyNotify) gnome_vfs_mime_application_free);
gtk_menu_append (menu, menu_item);
gtk_widget_show (menu_item);
@ -342,9 +342,13 @@ populate_application_list (MimeCategoryEditDialog *dialog)
if (found_idx < 0) {
found_idx = i;
if (dialog->p->info->custom_line != NULL)
if (dialog->p->info->custom_line != NULL) {
gnome_file_entry_set_filename (GNOME_FILE_ENTRY (WID ("program_entry")),
dialog->p->info->custom_line);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (WID ("needs_terminal_toggle")),
dialog->p->info->needs_terminal);
}
} else {
gtk_widget_set_sensitive (WID ("program_entry_box"), FALSE);
}
@ -361,18 +365,36 @@ populate_application_list (MimeCategoryEditDialog *dialog)
static void
store_data (MimeCategoryEditDialog *dialog)
{
GtkTreePath *path;
GtkTreeIter iter;
GtkOptionMenu *option_menu;
GtkMenuShell *menu_shell;
GObject *menu_item;
gint idx;
model_entry_append_to_dirty_list (MODEL_ENTRY (dialog->p->info));
GnomeVFSMimeApplication *app;
mime_types_model_construct_iter (MIME_TYPES_MODEL (dialog->p->model), MODEL_ENTRY (dialog->p->info), &iter);
path = gtk_tree_model_get_path (dialog->p->model, &iter);
gtk_tree_model_row_changed (dialog->p->model, path, &iter);
gtk_tree_path_free (path);
option_menu = GTK_OPTION_MENU (WID ("default_action_select"));
menu_shell = GTK_MENU_SHELL (gtk_option_menu_get_menu (option_menu));
idx = gtk_option_menu_get_history (option_menu);
menu_item = (g_list_nth (menu_shell->children, idx))->data;
gnome_vfs_mime_application_free (dialog->p->info->default_action);
app = g_object_get_data (menu_item, "app");
if (app != NULL)
dialog->p->info->default_action = gnome_vfs_mime_application_copy (app);
else
dialog->p->info->default_action = NULL;
dialog->p->info->custom_line = g_strdup (gtk_entry_get_text (GTK_ENTRY
(gnome_file_entry_gtk_entry
(GNOME_FILE_ENTRY (WID ("program_entry"))))));
dialog->p->info->needs_terminal = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (WID ("needs_terminal_toggle")));
dialog->p->info->use_parent_category =
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (WID ("use_category_toggle")));
model_entry_append_to_dirty_list (MODEL_ENTRY (dialog->p->info));
mime_category_info_update (dialog->p->info);
}
static void

View file

@ -417,7 +417,7 @@ populate_component_list (MimeEditDialog *dialog)
menu = GTK_MENU (gtk_menu_new ());
component_list = gnome_vfs_mime_get_short_list_components (dialog->p->info->mime_type);
component_list = gnome_vfs_mime_get_all_components (dialog->p->info->mime_type);
/* FIXME: We are leaking the whole list here, but this will be the case until I know of an easy way to duplicate
* Bonobo_ServerInfo structures */
@ -468,7 +468,7 @@ populate_application_list (MimeEditDialog *dialog)
menu = GTK_MENU (gtk_menu_new ());
app_list = gnome_vfs_mime_get_short_list_applications (dialog->p->info->mime_type);
app_list = gnome_vfs_mime_get_all_applications (dialog->p->info->mime_type);
for (tmp = app_list, i = 0; tmp != NULL; tmp = tmp->next, i++) {
app = tmp->data;

View file

@ -93,21 +93,19 @@ void
mime_type_info_load_all (MimeTypeInfo *info)
{
gchar *tmp;
const gchar *tmp1;
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) {
if (info->default_action == NULL && info->custom_line == NULL) {
info->default_action = gnome_vfs_mime_get_default_application (info->mime_type);
tmp = g_strdup_printf ("Custom %s", info->mime_type);
if (info->default_action != NULL && !strcmp (info->default_action->name, tmp)) {
@ -124,16 +122,7 @@ mime_type_info_load_all (MimeTypeInfo *info)
if (info->default_component == NULL)
info->default_component = gnome_vfs_mime_get_default_component (info->mime_type);
if (!info->use_cat_loaded) {
tmp1 = gnome_vfs_mime_get_value (info->mime_type, "use_category_default");
if (tmp1 != NULL && !strcmp (tmp1, "yes"))
info->use_category = TRUE;
else
info->use_category = FALSE;
info->use_cat_loaded = TRUE;
}
mime_type_info_get_use_category (info);
}
const gchar *
@ -204,6 +193,25 @@ mime_type_info_get_file_extensions (MimeTypeInfo *info)
return info->file_extensions;
}
gboolean
mime_type_info_get_use_category (MimeTypeInfo *info)
{
const gchar *tmp1;
if (!info->use_cat_loaded) {
tmp1 = gnome_vfs_mime_get_value (info->mime_type, "use_category_default");
if (tmp1 != NULL && !strcmp (tmp1, "yes"))
info->use_category = TRUE;
else
info->use_category = FALSE;
info->use_cat_loaded = TRUE;
}
return info->use_category;
}
gchar *
mime_type_info_get_file_extensions_pretty_string (MimeTypeInfo *info)
{
@ -336,7 +344,7 @@ get_gconf_base_name (MimeCategoryInfo *category)
tmp1 = mime_category_info_get_full_name (category);
for (tmp = tmp1; *tmp != '\0'; tmp++)
if (isspace (*tmp)) *tmp = '-';
if (isspace (*tmp) || *tmp == '(' || *tmp == ')') *tmp = '-';
tmp = g_strconcat ("/desktop/gnome/file-types-categories/",
tmp1, "/default-action-id", NULL);
@ -353,25 +361,28 @@ mime_category_info_load_all (MimeCategoryInfo *category)
GnomeVFSMimeApplication *app;
tmp1 = get_gconf_base_name (category);
tmp = g_strconcat (tmp1, "/default-action-id", NULL);
appid = gconf_client_get_string (gconf_client_get_default (), tmp, NULL);
g_free (tmp);
if (appid != NULL && *appid != '\0') {
tmp = g_strdup_printf ("Custom %s", category->name);
app = gnome_vfs_application_registry_get_mime_application (appid);
if (!strcmp (app->name, tmp)) {
category->default_action = NULL;
category->custom_line = app->command;
category->needs_terminal = app->requires_terminal;
gnome_vfs_mime_application_free (app);
if (category->default_action == NULL && category->custom_line == NULL) {
tmp = g_strconcat (tmp1, "/default-action-id", NULL);
appid = gconf_client_get_string (gconf_client_get_default (), tmp, NULL);
g_free (tmp);
if (appid != NULL && *appid != '\0') {
tmp = g_strdup_printf ("Custom %s", category->name);
app = gnome_vfs_application_registry_get_mime_application (appid);
if (!strcmp (app->name, tmp)) {
category->default_action = NULL;
category->custom_line = app->command;
category->needs_terminal = app->requires_terminal;
gnome_vfs_mime_application_free (app);
} else {
category->default_action = app;
category->custom_line = NULL;
}
} else {
category->default_action = app;
category->default_action = NULL;
category->custom_line = NULL;
}
} else {
category->default_action = NULL;
category->custom_line = NULL;
}
if (!category->use_parent_cat_loaded) {
@ -396,24 +407,8 @@ set_subcategory_ids (ModelEntry *entry, MimeCategoryInfo *category, gchar *app_i
switch (entry->type) {
case MODEL_ENTRY_MIME_TYPE:
if (MIME_TYPE_INFO (entry)->use_category) {
if (MIME_TYPE_INFO (entry)->use_category)
gnome_vfs_mime_set_default_application (MIME_TYPE_INFO (entry)->mime_type, app_id);
gnome_vfs_mime_application_free (MIME_TYPE_INFO (entry)->default_action);
if (category->default_action == NULL)
MIME_TYPE_INFO (entry)->default_action = NULL;
else
MIME_TYPE_INFO (entry)->default_action = gnome_vfs_mime_application_copy (category->default_action);
g_free (MIME_TYPE_INFO (entry)->custom_line);
if (app_id == NULL)
MIME_TYPE_INFO (entry)->custom_line = NULL;
else
MIME_TYPE_INFO (entry)->custom_line = g_strdup (category->custom_line);
MIME_TYPE_INFO (entry)->needs_terminal = category->needs_terminal;
}
break;
@ -479,6 +474,50 @@ mime_category_info_save (MimeCategoryInfo *category)
set_subcategory_ids (MODEL_ENTRY (category), category, app_id);
}
static void
update_subcategories (ModelEntry *entry, MimeCategoryInfo *category)
{
ModelEntry *tmp;
switch (entry->type) {
case MODEL_ENTRY_MIME_TYPE:
if (MIME_TYPE_INFO (entry)->use_category) {
gnome_vfs_mime_application_free (MIME_TYPE_INFO (entry)->default_action);
if (category->default_action == NULL)
MIME_TYPE_INFO (entry)->default_action = NULL;
else
MIME_TYPE_INFO (entry)->default_action = gnome_vfs_mime_application_copy (category->default_action);
g_free (MIME_TYPE_INFO (entry)->custom_line);
if (category->custom_line == NULL)
MIME_TYPE_INFO (entry)->custom_line = NULL;
else
MIME_TYPE_INFO (entry)->custom_line = g_strdup (category->custom_line);
MIME_TYPE_INFO (entry)->needs_terminal = category->needs_terminal;
}
break;
case MODEL_ENTRY_CATEGORY:
if (entry == MODEL_ENTRY (category) || MIME_CATEGORY_INFO (entry)->use_parent_category)
for (tmp = entry->first_child; tmp != NULL; tmp = tmp->next)
update_subcategories (tmp, category);
break;
default:
break;
}
}
void
mime_category_info_update (MimeCategoryInfo *info)
{
update_subcategories (MODEL_ENTRY (info), info);
}
static GList *
find_possible_supported_apps (ModelEntry *entry, gboolean top)
{
@ -502,7 +541,7 @@ find_possible_supported_apps (ModelEntry *entry, gboolean top)
return NULL;
case MODEL_ENTRY_MIME_TYPE:
if (MIME_TYPE_INFO (entry)->use_category)
if (mime_type_info_get_use_category (MIME_TYPE_INFO (entry)))
return gnome_vfs_application_registry_get_applications (MIME_TYPE_INFO (entry)->mime_type);
else
return NULL;
@ -551,7 +590,7 @@ reduce_supported_app_list (ModelEntry *entry, GList *list, gboolean top)
break;
case MODEL_ENTRY_MIME_TYPE:
if (MIME_TYPE_INFO (entry)->use_category) {
if (mime_type_info_get_use_category (MIME_TYPE_INFO (entry))) {
type_list = gnome_vfs_application_registry_get_applications (MIME_TYPE_INFO (entry)->mime_type);
list = intersect_lists (list, type_list);
g_list_free (type_list);

View file

@ -85,6 +85,7 @@ const gchar *mime_type_info_get_description (MimeTypeInfo *info);
GdkPixbuf *mime_type_info_get_icon (MimeTypeInfo *info);
const GList *mime_type_info_get_file_extensions (MimeTypeInfo *info);
const gchar *mime_type_info_get_icon_path (MimeTypeInfo *info);
gboolean mime_type_info_get_use_category (MimeTypeInfo *info);
void mime_type_info_save (const MimeTypeInfo *info);
void mime_type_info_free (MimeTypeInfo *info);
@ -104,6 +105,8 @@ MimeCategoryInfo *mime_category_info_new (MimeCategoryInfo *parent,
GtkTreeModel *model);
void mime_category_info_load_all (MimeCategoryInfo *category);
void mime_category_info_save (MimeCategoryInfo *category);
void mime_category_info_update (MimeCategoryInfo *info);
GList *mime_category_info_find_apps (MimeCategoryInfo *info);
gchar *mime_category_info_get_full_name (MimeCategoryInfo *info);