Implement

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

	* mime-type-info.c (get_gconf_base_name): Implement

	* mime-category-edit-dialog.c (fill_dialog): Disable
	use_category_toggle if this is a toplevel category
	(populate_application_list, default_action_changed_cb)
	(use_category_toggled_cb, update_sensitivity): Set widget
	sensitivity based on various values

	* mime-type-info.c (mime_type_info_load_all)
	(mime_category_info_load_all): Check use_[parent_]cat_loaded
	(mime_category_info_load_all): Override use_parent_category with
	FALSE if this is a toplevel category
This commit is contained in:
Bradford Hovinen 2002-01-27 19:54:56 +00:00 committed by Bradford Hovinen (Gdict maintainer)
parent e34f1df774
commit 9b549da9bf
6 changed files with 129 additions and 38 deletions

View file

@ -1,5 +1,21 @@
2002-01-27 Bradford Hovinen <hovinen@ximian.com>
* mime-type-info.c (get_gconf_base_name): Implement
* mime-category-edit-dialog.c (fill_dialog): Disable
use_category_toggle if this is a toplevel category
(populate_application_list, default_action_changed_cb)
(use_category_toggled_cb, update_sensitivity): Set widget
sensitivity based on various values
* mime-type-info.c (mime_type_info_load_all)
(mime_category_info_load_all): Check use_[parent_]cat_loaded
(mime_category_info_load_all): Override use_parent_category with
FALSE if this is a toplevel category
* mime-category-edit-dialog.c (store_data, fill_dialog): Get/set
use_parent_category
* mime-type-info.c (set_subcategory_ids): Don't set subcategory
ids unless use_parent_category is set
(mime_category_info_save, mime_category_info_load_all): Get/set

View file

@ -1114,17 +1114,6 @@
<property name="spacing">8</property>
<property name="visible">yes</property>
<child>
<widget class="GtkButton" id="button13">
<property name="can_default">yes</property>
<property name="can_focus">yes</property>
<property name="visible">yes</property>
<property name="label" translatable="yes">gtk-ok</property>
<property name="use_stock">yes</property>
<property name="use_underline">yes</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="button14">
<property name="can_default">yes</property>
@ -1141,7 +1130,7 @@
<property name="can_default">yes</property>
<property name="can_focus">yes</property>
<property name="visible">yes</property>
<property name="label" translatable="yes">gtk-cancel</property>
<property name="label" translatable="yes">gtk-close</property>
<property name="use_stock">yes</property>
<property name="use_underline">yes</property>
</widget>
@ -1223,6 +1212,21 @@
<property name="spacing">4</property>
<property name="visible">yes</property>
<child>
<widget class="GtkCheckButton" id="use_category_toggle">
<property name="can_focus">yes</property>
<property name="label" translatable="yes">Use parent category defaults</property>
<property name="active">no</property>
<property name="draw_indicator">yes</property>
<property name="visible">yes</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">no</property>
<property name="fill">no</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="default_action_box">
<property name="homogeneous">no</property>

View file

@ -1169,6 +1169,20 @@
<homogeneous>False</homogeneous>
<spacing>4</spacing>
<widget>
<class>GtkCheckButton</class>
<name>use_category_toggle</name>
<can_focus>True</can_focus>
<label>Use parent category defaults</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkHBox</class>
<name>default_action_box</name>

View file

@ -48,6 +48,10 @@ struct _MimeCategoryEditDialogPrivate
MimeCategoryInfo *info;
GtkTreeModel *model;
gboolean default_action_active : 1;
gboolean custom_action : 1;
gboolean use_cat_dfl : 1;
};
static GObjectClass *parent_class;
@ -75,9 +79,13 @@ static void fill_dialog (MimeCategoryEditDialog *dialo
static void store_data (MimeCategoryEditDialog *dialog);
static void default_action_changed_cb (MimeCategoryEditDialog *dialog);
static void use_category_toggled_cb (MimeCategoryEditDialog *dialog,
GtkToggleButton *tb);
static void response_cb (MimeCategoryEditDialog *dialog,
gint response_id);
static void update_sensitivity (MimeCategoryEditDialog *dialog);
GType
mime_category_edit_dialog_get_type (void)
{
@ -133,6 +141,8 @@ mime_category_edit_dialog_init (MimeCategoryEditDialog *dialog, MimeCategoryEdit
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog->p->dialog_win)->vbox), WID ("mime_category_edit_widget"), TRUE, TRUE, 0);
g_signal_connect_swapped (G_OBJECT (WID ("default_action_select")), "changed", (GCallback) default_action_changed_cb, dialog);
g_signal_connect_swapped (G_OBJECT (WID ("use_category_toggle")), "toggled",
(GCallback) use_category_toggled_cb, dialog);
g_signal_connect_swapped (G_OBJECT (dialog->p->dialog_win), "response", (GCallback) response_cb, dialog);
}
@ -282,6 +292,10 @@ fill_dialog (MimeCategoryEditDialog *dialog)
mime_category_info_load_all (dialog->p->info);
gtk_entry_set_text (GTK_ENTRY (WID ("name_entry")), dialog->p->info->name);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (WID ("use_category_toggle")), dialog->p->info->use_parent_category);
if (dialog->p->info->entry.parent->type == MODEL_ENTRY_NONE)
gtk_widget_set_sensitive (WID ("use_category_toggle"), FALSE);
populate_application_list (dialog);
@ -321,8 +335,8 @@ populate_application_list (MimeCategoryEditDialog *dialog)
gtk_widget_show (menu_item);
}
if (i == 0)
gtk_widget_set_sensitive (WID ("default_action_box"), FALSE);
dialog->p->default_action_active = !(i == 0);
dialog->p->custom_action = (found_idx < 0);
gtk_menu_append (menu, gtk_menu_item_new_with_label (_("Custom")));
@ -340,6 +354,8 @@ populate_application_list (MimeCategoryEditDialog *dialog)
gtk_option_menu_set_history (app_select, found_idx);
g_list_free (app_list);
update_sensitivity (dialog);
}
static void
@ -354,6 +370,9 @@ store_data (MimeCategoryEditDialog *dialog)
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);
dialog->p->info->use_parent_category =
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (WID ("use_category_toggle")));
}
static void
@ -367,13 +386,15 @@ default_action_changed_cb (MimeCategoryEditDialog *dialog)
menu = GTK_MENU_SHELL (gtk_option_menu_get_menu (option_menu));
id = gtk_option_menu_get_history (option_menu);
if (id == g_list_length (menu->children) - 1) {
gtk_widget_set_sensitive (WID ("program_entry_box"), TRUE);
gtk_widget_set_sensitive (WID ("needs_terminal_toggle"), TRUE);
} else {
gtk_widget_set_sensitive (WID ("program_entry_box"), FALSE);
gtk_widget_set_sensitive (WID ("needs_terminal_toggle"), FALSE);
}
dialog->p->custom_action = (id == g_list_length (menu->children) - 1);
update_sensitivity (dialog);
}
static void
use_category_toggled_cb (MimeCategoryEditDialog *dialog, GtkToggleButton *tb)
{
dialog->p->use_cat_dfl = gtk_toggle_button_get_active (tb);
update_sensitivity (dialog);
}
static void
@ -384,3 +405,11 @@ response_cb (MimeCategoryEditDialog *dialog, gint response_id)
g_object_unref (G_OBJECT (dialog));
}
static void
update_sensitivity (MimeCategoryEditDialog *dialog)
{
gtk_widget_set_sensitive (WID ("default_action_box"), dialog->p->default_action_active && !dialog->p->use_cat_dfl);
gtk_widget_set_sensitive (WID ("program_entry_box"), dialog->p->custom_action && !dialog->p->use_cat_dfl);
gtk_widget_set_sensitive (WID ("needs_terminal_toggle"), dialog->p->custom_action && !dialog->p->use_cat_dfl);
}

View file

@ -33,6 +33,7 @@
#include <libgnomevfs/gnome-vfs-application-registry.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include <gconf/gconf-client.h>
#include <ctype.h>
#include "libuuid/uuid.h"
@ -123,12 +124,16 @@ mime_type_info_load_all (MimeTypeInfo *info)
if (info->default_component == NULL)
info->default_component = gnome_vfs_mime_get_default_component (info->mime_type);
tmp1 = gnome_vfs_mime_get_value (info->mime_type, "use-category");
if (!info->use_cat_loaded) {
tmp1 = gnome_vfs_mime_get_value (info->mime_type, "use-category");
if (tmp1 != NULL && !strcmp (tmp1, "yes"))
info->use_category = TRUE;
else
info->use_category = FALSE;
if (tmp1 != NULL && !strcmp (tmp1, "yes"))
info->use_category = TRUE;
else
info->use_category = FALSE;
info->use_cat_loaded = TRUE;
}
}
const gchar *
@ -323,6 +328,23 @@ mime_category_info_new (MimeCategoryInfo *parent, const gchar *name, GtkTreeMode
return info;
}
static gchar *
get_gconf_base_name (MimeCategoryInfo *category)
{
gchar *tmp, *tmp1;
tmp1 = mime_category_info_get_full_name (category);
for (tmp = tmp1; *tmp != '\0'; tmp++)
if (isspace (tmp)) *tmp = '-';
tmp = g_strconcat ("/desktop/gnome/file-types-categories/",
tmp1, "/default-action-id", NULL);
g_free (tmp1);
return tmp;
}
void
mime_category_info_load_all (MimeCategoryInfo *category)
{
@ -330,9 +352,8 @@ mime_category_info_load_all (MimeCategoryInfo *category)
gchar *appid;
GnomeVFSMimeApplication *app;
tmp1 = mime_category_info_get_full_name (category);
tmp = g_strconcat ("/desktop/gnome/file-types-categories/",
tmp1, "/default-action-id", NULL);
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);
@ -353,10 +374,17 @@ mime_category_info_load_all (MimeCategoryInfo *category)
category->custom_line = NULL;
}
tmp = g_strconcat ("/desktop/gnome/file-types-categories/",
tmp1, "/use-parent-category", NULL);
category->use_parent_category = gconf_client_get_bool (gconf_client_get_default (), tmp, NULL);
g_free (tmp);
if (!category->use_parent_cat_loaded) {
if (category->entry.parent->type == MODEL_ENTRY_CATEGORY) {
tmp = g_strconcat (tmp1, "/use-parent-category", NULL);
category->use_parent_category = gconf_client_get_bool (gconf_client_get_default (), tmp, NULL);
g_free (tmp);
} else {
category->use_parent_category = FALSE;
}
category->use_parent_cat_loaded = TRUE;
}
g_free (tmp1);
}
@ -409,9 +437,8 @@ mime_category_info_save (MimeCategoryInfo *category)
gchar app_uuid_str[100];
GnomeVFSMimeApplication app;
tmp1 = mime_category_info_get_full_name (category);
tmp = g_strconcat ("/desktop/gnome/file-types-categories/",
tmp1, "/default-action-id", NULL);
tmp1 = get_gconf_base_name (category);
tmp = g_strconcat (tmp1, "/default-action-id", NULL);
if (category->default_action != NULL) {
gconf_client_set_string (gconf_client_get_default (),
@ -444,8 +471,7 @@ mime_category_info_save (MimeCategoryInfo *category)
g_free (tmp);
tmp1 = mime_category_info_get_full_name (category);
tmp = g_strconcat ("/desktop/gnome/file-types-categories/",
tmp1, "/use-parent-category", NULL);
tmp = g_strconcat (tmp1, "/use-parent-category", NULL);
gconf_client_set_bool (gconf_client_get_default (), tmp, category->use_parent_category, NULL);
g_free (tmp1);

View file

@ -54,6 +54,7 @@ struct _MimeTypeInfo
GdkPixbuf *small_icon_pixbuf;
gboolean use_category;
gboolean use_cat_loaded;
Bonobo_ServerInfo *default_component;
GnomeVFSMimeApplication *default_action;
@ -71,6 +72,7 @@ struct _MimeCategoryInfo
gboolean needs_terminal;
gboolean use_parent_category;
gboolean use_parent_cat_loaded;
};
void load_all_mime_types (GtkTreeModel *model);