2002-01-08 21:25:33 +00:00
|
|
|
/* -*- mode: c; style: linux -*- */
|
|
|
|
|
|
|
|
/* mime-edit-dialog.c
|
|
|
|
* Copyright (C) 2001 Ximian, Inc.
|
|
|
|
*
|
|
|
|
* Written by Bradford Hovinen <hovinen@ximian.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, 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
|
|
|
|
|
2002-02-04 17:48:43 +00:00
|
|
|
#include <string.h>
|
2002-01-08 21:25:33 +00:00
|
|
|
#include <glade/glade.h>
|
|
|
|
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
|
2002-01-28 18:45:27 +00:00
|
|
|
#include <libgnomevfs/gnome-vfs-application-registry.h>
|
2002-01-25 20:27:10 +00:00
|
|
|
#include <libgnomevfs/gnome-vfs-utils.h>
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
|
|
#include "mime-edit-dialog.h"
|
2002-01-14 15:28:36 +00:00
|
|
|
#include "mime-types-model.h"
|
2002-01-08 21:25:33 +00:00
|
|
|
|
2002-01-25 20:27:10 +00:00
|
|
|
#include "libuuid/uuid.h"
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
#define WID(x) (glade_xml_get_widget (dialog->p->dialog_xml, x))
|
|
|
|
|
2002-01-28 02:56:07 +00:00
|
|
|
enum {
|
|
|
|
DONE,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
2002-01-25 16:12:01 +00:00
|
|
|
PROP_MODEL,
|
2002-01-26 16:24:45 +00:00
|
|
|
PROP_INFO,
|
2002-01-25 20:27:10 +00:00
|
|
|
PROP_IS_ADD
|
2002-01-08 21:25:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _MimeEditDialogPrivate
|
|
|
|
{
|
|
|
|
MimeTypeInfo *info;
|
|
|
|
GladeXML *dialog_xml;
|
|
|
|
GtkWidget *dialog_win;
|
|
|
|
GtkTreeStore *ext_store;
|
2002-01-25 16:12:01 +00:00
|
|
|
|
2002-01-25 20:27:10 +00:00
|
|
|
gboolean is_add;
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
GtkTreeModel *model;
|
2002-01-27 17:41:06 +00:00
|
|
|
|
|
|
|
gboolean component_active : 1;
|
|
|
|
gboolean default_action_active : 1;
|
|
|
|
gboolean custom_action : 1;
|
|
|
|
gboolean use_cat_dfl : 1;
|
2002-01-08 21:25:33 +00:00
|
|
|
};
|
|
|
|
|
2002-01-28 02:56:07 +00:00
|
|
|
static guint dialog_signals[LAST_SIGNAL];
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
static GObjectClass *parent_class;
|
|
|
|
|
|
|
|
static void mime_edit_dialog_init (MimeEditDialog *mime_edit_dialog,
|
|
|
|
MimeEditDialogClass *class);
|
|
|
|
static void mime_edit_dialog_class_init (MimeEditDialogClass *class);
|
|
|
|
static void mime_edit_dialog_base_init (MimeEditDialogClass *class);
|
|
|
|
|
|
|
|
static void mime_edit_dialog_set_prop (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void mime_edit_dialog_get_prop (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void mime_edit_dialog_dispose (GObject *object);
|
|
|
|
static void mime_edit_dialog_finalize (GObject *object);
|
|
|
|
|
|
|
|
static void fill_dialog (MimeEditDialog *dialog);
|
2002-01-25 20:27:10 +00:00
|
|
|
static void setup_add_dialog (MimeEditDialog *dialog);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
|
|
static void populate_component_list (MimeEditDialog *dialog);
|
|
|
|
static void populate_application_list (MimeEditDialog *dialog);
|
|
|
|
static void populate_extensions_list (MimeEditDialog *dialog);
|
|
|
|
|
|
|
|
static void add_ext_cb (MimeEditDialog *dialog);
|
|
|
|
static void remove_ext_cb (MimeEditDialog *dialog);
|
2002-01-14 15:28:36 +00:00
|
|
|
static void choose_cat_cb (MimeEditDialog *dialog);
|
2002-01-08 21:25:33 +00:00
|
|
|
static void default_action_changed_cb (MimeEditDialog *dialog);
|
2002-01-27 17:41:06 +00:00
|
|
|
static void use_category_defaults_toggled_cb (MimeEditDialog *dialog,
|
|
|
|
GtkToggleButton *tb);
|
2002-01-08 21:25:33 +00:00
|
|
|
static void response_cb (MimeEditDialog *dialog,
|
|
|
|
gint response_id);
|
|
|
|
|
2002-01-27 17:41:06 +00:00
|
|
|
static void update_sensitivity (MimeEditDialog *dialog);
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
GType
|
|
|
|
mime_edit_dialog_get_type (void)
|
|
|
|
{
|
|
|
|
static GType mime_edit_dialog_type = 0;
|
|
|
|
|
|
|
|
if (!mime_edit_dialog_type) {
|
|
|
|
GTypeInfo mime_edit_dialog_info = {
|
|
|
|
sizeof (MimeEditDialogClass),
|
|
|
|
(GBaseInitFunc) mime_edit_dialog_base_init,
|
|
|
|
NULL, /* GBaseFinalizeFunc */
|
|
|
|
(GClassInitFunc) mime_edit_dialog_class_init,
|
|
|
|
NULL, /* GClassFinalizeFunc */
|
|
|
|
NULL, /* user-supplied data */
|
|
|
|
sizeof (MimeEditDialog),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) mime_edit_dialog_init,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
mime_edit_dialog_type =
|
|
|
|
g_type_register_static (G_TYPE_OBJECT,
|
|
|
|
"MimeEditDialog",
|
|
|
|
&mime_edit_dialog_info, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mime_edit_dialog_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mime_edit_dialog_init (MimeEditDialog *dialog, MimeEditDialogClass *class)
|
|
|
|
{
|
|
|
|
GtkSizeGroup *size_group;
|
|
|
|
GtkTreeView *view;
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
|
|
|
|
dialog->p = g_new0 (MimeEditDialogPrivate, 1);
|
|
|
|
dialog->p->dialog_xml = glade_xml_new
|
|
|
|
(GNOMECC_DATA_DIR "/interfaces/file-types-properties.glade", "edit_widget", NULL);
|
|
|
|
|
|
|
|
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
|
|
|
|
gtk_size_group_add_widget (size_group, WID ("description_label"));
|
|
|
|
gtk_size_group_add_widget (size_group, WID ("mime_type_label"));
|
2002-01-14 15:28:36 +00:00
|
|
|
gtk_size_group_add_widget (size_group, WID ("category_label"));
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
|
|
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
|
|
|
|
gtk_size_group_add_widget (size_group, WID ("component_label"));
|
|
|
|
gtk_size_group_add_widget (size_group, WID ("default_action_label"));
|
|
|
|
gtk_size_group_add_widget (size_group, WID ("program_label"));
|
|
|
|
|
|
|
|
dialog->p->ext_store = gtk_tree_store_new (1, G_TYPE_STRING);
|
|
|
|
|
|
|
|
view = GTK_TREE_VIEW (WID ("ext_list"));
|
|
|
|
gtk_tree_view_set_model (view, GTK_TREE_MODEL (dialog->p->ext_store));
|
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_text_new ();
|
|
|
|
gtk_tree_view_insert_column_with_attributes (view, -1, _("Extension"), renderer, "text", 0, NULL);
|
|
|
|
|
|
|
|
dialog->p->dialog_win = gtk_dialog_new_with_buttons
|
|
|
|
(_("Edit file type"), NULL, -1,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
2002-04-22 21:34:39 +00:00
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
2002-01-08 21:25:33 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog->p->dialog_win)->vbox), WID ("edit_widget"), TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (G_OBJECT (WID ("add_ext_button")), "clicked", (GCallback) add_ext_cb, dialog);
|
|
|
|
g_signal_connect_swapped (G_OBJECT (WID ("remove_ext_button")), "clicked", (GCallback) remove_ext_cb, dialog);
|
2002-01-14 15:28:36 +00:00
|
|
|
g_signal_connect_swapped (G_OBJECT (WID ("choose_button")), "clicked", (GCallback) choose_cat_cb, dialog);
|
2002-01-08 21:25:33 +00:00
|
|
|
g_signal_connect_swapped (G_OBJECT (WID ("default_action_select")), "changed", (GCallback) default_action_changed_cb, dialog);
|
2002-01-27 17:41:06 +00:00
|
|
|
g_signal_connect_swapped (G_OBJECT (WID ("use_category_defaults_toggle")), "toggled",
|
|
|
|
(GCallback) use_category_defaults_toggled_cb, dialog);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
|
|
g_signal_connect_swapped (G_OBJECT (dialog->p->dialog_win), "response", (GCallback) response_cb, dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mime_edit_dialog_base_init (MimeEditDialogClass *class)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mime_edit_dialog_class_init (MimeEditDialogClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
|
|
|
|
|
|
|
object_class = G_OBJECT_CLASS (class);
|
|
|
|
|
|
|
|
object_class->dispose = mime_edit_dialog_dispose;
|
|
|
|
object_class->finalize = mime_edit_dialog_finalize;
|
|
|
|
object_class->set_property = mime_edit_dialog_set_prop;
|
|
|
|
object_class->get_property = mime_edit_dialog_get_prop;
|
|
|
|
|
|
|
|
g_object_class_install_property
|
2002-01-25 16:12:01 +00:00
|
|
|
(object_class, PROP_MODEL,
|
|
|
|
g_param_spec_object ("model",
|
|
|
|
_("Model"),
|
|
|
|
_("Underlying model to notify when Ok is clicked"),
|
|
|
|
gtk_tree_model_get_type (),
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property
|
2002-01-26 16:24:45 +00:00
|
|
|
(object_class, PROP_INFO,
|
|
|
|
g_param_spec_pointer ("mime-type-info",
|
|
|
|
_("MIME type information"),
|
|
|
|
_("Structure with data on the MIME type"),
|
2002-01-08 21:25:33 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
2002-01-25 20:27:10 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_IS_ADD,
|
|
|
|
g_param_spec_boolean ("is-add",
|
|
|
|
_("Is add dialog"),
|
|
|
|
_("True if this dialog is for adding a MIME type"),
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
2002-01-28 02:56:07 +00:00
|
|
|
dialog_signals[DONE] =
|
|
|
|
g_signal_new ("done",
|
|
|
|
G_TYPE_FROM_CLASS (object_class), 0,
|
|
|
|
G_STRUCT_OFFSET (MimeEditDialogClass, done),
|
|
|
|
NULL, NULL,
|
|
|
|
(GSignalCMarshaller) g_cclosure_marshal_VOID__BOOLEAN,
|
|
|
|
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
parent_class = G_OBJECT_CLASS
|
|
|
|
(g_type_class_ref (G_TYPE_OBJECT));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mime_edit_dialog_set_prop (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MimeEditDialog *mime_edit_dialog;
|
|
|
|
|
|
|
|
g_return_if_fail (object != NULL);
|
|
|
|
g_return_if_fail (IS_MIME_EDIT_DIALOG (object));
|
|
|
|
|
|
|
|
mime_edit_dialog = MIME_EDIT_DIALOG (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2002-01-25 16:12:01 +00:00
|
|
|
case PROP_MODEL:
|
|
|
|
mime_edit_dialog->p->model = GTK_TREE_MODEL (g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
2002-01-26 16:24:45 +00:00
|
|
|
case PROP_INFO:
|
2002-01-25 20:27:10 +00:00
|
|
|
if (g_value_get_pointer (value) != NULL) {
|
2002-01-26 16:24:45 +00:00
|
|
|
mime_edit_dialog->p->info = g_value_get_pointer (value);
|
2002-01-25 20:27:10 +00:00
|
|
|
fill_dialog (mime_edit_dialog);
|
|
|
|
|
|
|
|
gtk_widget_show_all (mime_edit_dialog->p->dialog_win);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_IS_ADD:
|
|
|
|
mime_edit_dialog->p->is_add = g_value_get_boolean (value);
|
|
|
|
|
|
|
|
if (mime_edit_dialog->p->is_add) {
|
2002-01-27 16:18:36 +00:00
|
|
|
mime_edit_dialog->p->info = mime_type_info_new (NULL, NULL);
|
2002-01-25 20:27:10 +00:00
|
|
|
setup_add_dialog (mime_edit_dialog);
|
2002-04-22 18:07:39 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (mime_edit_dialog->p->dialog_win),
|
|
|
|
(_("Add file type")));
|
2002-01-25 20:27:10 +00:00
|
|
|
gtk_widget_show_all (mime_edit_dialog->p->dialog_win);
|
|
|
|
}
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_warning ("Bad property set");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mime_edit_dialog_get_prop (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MimeEditDialog *mime_edit_dialog;
|
|
|
|
|
|
|
|
g_return_if_fail (object != NULL);
|
|
|
|
g_return_if_fail (IS_MIME_EDIT_DIALOG (object));
|
|
|
|
|
|
|
|
mime_edit_dialog = MIME_EDIT_DIALOG (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2002-01-25 16:12:01 +00:00
|
|
|
case PROP_MODEL:
|
|
|
|
g_value_set_object (value, G_OBJECT (mime_edit_dialog->p->model));
|
|
|
|
break;
|
|
|
|
|
2002-01-26 16:24:45 +00:00
|
|
|
case PROP_INFO:
|
|
|
|
g_value_set_pointer (value, mime_edit_dialog->p->info);
|
2002-01-08 21:25:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_warning ("Bad property get");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mime_edit_dialog_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
MimeEditDialog *dialog;
|
|
|
|
|
|
|
|
g_return_if_fail (object != NULL);
|
|
|
|
g_return_if_fail (IS_MIME_EDIT_DIALOG (object));
|
|
|
|
|
|
|
|
dialog = MIME_EDIT_DIALOG (object);
|
|
|
|
|
|
|
|
if (dialog->p->dialog_xml != NULL) {
|
|
|
|
g_object_unref (G_OBJECT (dialog->p->dialog_xml));
|
|
|
|
dialog->p->dialog_xml = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dialog->p->dialog_win != NULL) {
|
|
|
|
gtk_widget_destroy (GTK_WIDGET (dialog->p->dialog_win));
|
|
|
|
dialog->p->dialog_win = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mime_edit_dialog_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MimeEditDialog *mime_edit_dialog;
|
|
|
|
|
|
|
|
g_return_if_fail (object != NULL);
|
|
|
|
g_return_if_fail (IS_MIME_EDIT_DIALOG (object));
|
|
|
|
|
|
|
|
mime_edit_dialog = MIME_EDIT_DIALOG (object);
|
|
|
|
|
|
|
|
g_free (mime_edit_dialog->p);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
GObject *
|
2002-01-26 16:24:45 +00:00
|
|
|
mime_edit_dialog_new (GtkTreeModel *model, MimeTypeInfo *info)
|
2002-01-08 21:25:33 +00:00
|
|
|
{
|
|
|
|
return g_object_new (mime_edit_dialog_get_type (),
|
2002-01-25 16:12:01 +00:00
|
|
|
"model", model,
|
2002-01-26 16:24:45 +00:00
|
|
|
"mime-type-info", info,
|
2002-01-08 21:25:33 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
GObject *
|
2002-01-25 16:12:01 +00:00
|
|
|
mime_add_dialog_new (GtkTreeModel *model)
|
2002-01-08 21:25:33 +00:00
|
|
|
{
|
|
|
|
return g_object_new (mime_edit_dialog_get_type (),
|
2002-01-25 16:12:01 +00:00
|
|
|
"model", model,
|
2002-01-25 20:27:10 +00:00
|
|
|
"is-add", TRUE,
|
2002-01-08 21:25:33 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2002-04-10 20:11:02 +00:00
|
|
|
static void
|
|
|
|
safe_set_entry (MimeEditDialog *dialog, char const *widget, char const *txt)
|
|
|
|
{
|
|
|
|
GtkEntry *entry = GTK_ENTRY (WID (widget));
|
|
|
|
|
|
|
|
g_return_if_fail (entry != NULL);
|
|
|
|
|
|
|
|
if (txt == NULL)
|
|
|
|
txt = "";
|
|
|
|
gtk_entry_set_text (entry, txt);
|
|
|
|
}
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
static void
|
|
|
|
fill_dialog (MimeEditDialog *dialog)
|
|
|
|
{
|
2002-04-10 20:11:02 +00:00
|
|
|
g_return_if_fail (dialog->p->info != NULL);
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
mime_type_info_load_all (dialog->p->info);
|
|
|
|
|
2002-04-10 20:11:02 +00:00
|
|
|
safe_set_entry (dialog, "description_entry",
|
|
|
|
dialog->p->info->description);
|
|
|
|
safe_set_entry (dialog, "mime_type_entry",
|
|
|
|
dialog->p->info->mime_type);
|
|
|
|
safe_set_entry (dialog, "category_entry",
|
|
|
|
mime_type_info_get_category_name (dialog->p->info));
|
2002-01-08 21:25:33 +00:00
|
|
|
|
2002-01-27 18:37:07 +00:00
|
|
|
dialog->p->use_cat_dfl = dialog->p->info->use_category;
|
2002-01-27 17:41:06 +00:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (WID ("use_category_defaults_toggle")), dialog->p->use_cat_dfl);
|
|
|
|
update_sensitivity (dialog);
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
if (dialog->p->info->mime_type != NULL && *dialog->p->info->mime_type != '\0')
|
|
|
|
gtk_widget_set_sensitive (WID ("mime_type_entry"), FALSE);
|
|
|
|
|
2002-01-25 17:27:02 +00:00
|
|
|
gnome_icon_entry_set_filename (GNOME_ICON_ENTRY (WID ("icon_entry")), mime_type_info_get_icon_path (dialog->p->info));
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
|
|
populate_component_list (dialog);
|
|
|
|
populate_application_list (dialog);
|
|
|
|
populate_extensions_list (dialog);
|
2002-01-25 20:27:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_add_dialog (MimeEditDialog *dialog)
|
|
|
|
{
|
|
|
|
GtkWidget *menu, *item;
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_label (_("None"));
|
|
|
|
menu = gtk_menu_new ();
|
2002-02-04 17:48:43 +00:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
2002-01-25 20:27:10 +00:00
|
|
|
gtk_option_menu_set_menu (GTK_OPTION_MENU (WID ("component_select")), menu);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
2002-01-25 20:27:10 +00:00
|
|
|
item = gtk_menu_item_new_with_label (_("Custom"));
|
|
|
|
menu = gtk_menu_new ();
|
2002-02-04 17:48:43 +00:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
2002-01-25 20:27:10 +00:00
|
|
|
gtk_option_menu_set_menu (GTK_OPTION_MENU (WID ("default_action_select")), menu);
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (WID ("component_box"), FALSE);
|
|
|
|
gtk_widget_set_sensitive (WID ("default_action_box"), FALSE);
|
|
|
|
|
|
|
|
gnome_icon_entry_set_filename (GNOME_ICON_ENTRY (WID ("icon_entry")),
|
|
|
|
gnome_vfs_icon_path_from_filename ("nautilus/i-regular-24.png"));
|
2002-01-08 21:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
populate_component_list (MimeEditDialog *dialog)
|
|
|
|
{
|
|
|
|
GList *component_list, *tmp;
|
|
|
|
GtkMenu *menu;
|
|
|
|
GtkWidget *menu_item;
|
|
|
|
GtkOptionMenu *component_select;
|
|
|
|
gchar *component_name;
|
2002-03-30 07:16:14 +00:00
|
|
|
Bonobo_ServerInfo *info, *default_component;
|
2002-01-08 21:25:33 +00:00
|
|
|
int found_idx = -1, i;
|
|
|
|
|
|
|
|
menu = GTK_MENU (gtk_menu_new ());
|
|
|
|
|
2002-01-28 16:43:40 +00:00
|
|
|
component_list = gnome_vfs_mime_get_all_components (dialog->p->info->mime_type);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
/* 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 */
|
|
|
|
|
2002-03-30 07:16:14 +00:00
|
|
|
default_component = dialog->p->info->default_component;
|
2002-01-08 21:25:33 +00:00
|
|
|
for (tmp = component_list, i = 0; tmp != NULL; tmp = tmp->next, i++) {
|
|
|
|
info = tmp->data;
|
|
|
|
|
2002-03-30 07:16:14 +00:00
|
|
|
g_return_if_fail (info != NULL);
|
|
|
|
|
|
|
|
if (default_component != NULL &&
|
|
|
|
!strcmp (info->iid, default_component->iid))
|
2002-01-08 21:25:33 +00:00
|
|
|
found_idx = i;
|
|
|
|
|
|
|
|
component_name = mime_type_get_pretty_name_for_server (info);
|
|
|
|
menu_item = gtk_menu_item_new_with_label (component_name);
|
|
|
|
g_free (component_name);
|
|
|
|
|
|
|
|
/* Store copy of component name in item; free when item destroyed. */
|
2002-01-25 16:12:01 +00:00
|
|
|
g_object_set_data (G_OBJECT (menu_item),
|
|
|
|
"component", info);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
2002-02-04 17:48:43 +00:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
|
2002-01-08 21:25:33 +00:00
|
|
|
gtk_widget_show (menu_item);
|
|
|
|
}
|
|
|
|
|
2002-01-27 17:41:06 +00:00
|
|
|
dialog->p->component_active = !(i == 0);
|
2002-01-25 20:27:10 +00:00
|
|
|
|
2002-01-11 14:17:40 +00:00
|
|
|
menu_item = gtk_menu_item_new_with_label (_("None"));
|
2002-02-04 17:48:43 +00:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
|
2002-01-11 14:17:40 +00:00
|
|
|
gtk_widget_show (menu_item);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
|
|
if (found_idx < 0)
|
|
|
|
found_idx = i;
|
|
|
|
|
|
|
|
component_select = GTK_OPTION_MENU (WID ("component_select"));
|
|
|
|
gtk_option_menu_set_menu (component_select, GTK_WIDGET (menu));
|
|
|
|
gtk_option_menu_set_history (component_select, found_idx);
|
2002-01-27 17:41:06 +00:00
|
|
|
|
|
|
|
update_sensitivity (dialog);
|
2002-01-08 21:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
populate_application_list (MimeEditDialog *dialog)
|
|
|
|
{
|
|
|
|
GList *app_list, *tmp;
|
|
|
|
GtkMenu *menu;
|
|
|
|
GtkWidget *menu_item;
|
|
|
|
GtkOptionMenu *app_select;
|
|
|
|
GnomeVFSMimeApplication *app;
|
|
|
|
int found_idx = -1, i;
|
|
|
|
|
|
|
|
menu = GTK_MENU (gtk_menu_new ());
|
|
|
|
|
2002-01-28 18:45:27 +00:00
|
|
|
app_list = gnome_vfs_application_registry_get_applications (dialog->p->info->mime_type);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
|
|
for (tmp = app_list, i = 0; tmp != NULL; tmp = tmp->next, i++) {
|
2002-01-28 18:45:27 +00:00
|
|
|
app = gnome_vfs_application_registry_get_mime_application (tmp->data);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
2002-01-11 20:13:50 +00:00
|
|
|
if (dialog->p->info->default_action != NULL &&
|
2002-01-28 18:39:42 +00:00
|
|
|
dialog->p->info->default_action->id != NULL &&
|
2002-01-11 20:13:50 +00:00
|
|
|
!strcmp (app->id, dialog->p->info->default_action->id))
|
2002-01-08 21:25:33 +00:00
|
|
|
found_idx = i;
|
|
|
|
|
|
|
|
menu_item = gtk_menu_item_new_with_label (app->name);
|
|
|
|
|
|
|
|
/* Store copy of application in item; free when item destroyed. */
|
|
|
|
g_object_set_data_full (G_OBJECT (menu_item),
|
|
|
|
"app", app,
|
|
|
|
(GDestroyNotify) gnome_vfs_mime_application_free);
|
|
|
|
|
2002-02-04 17:48:43 +00:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
|
2002-01-08 21:25:33 +00:00
|
|
|
gtk_widget_show (menu_item);
|
|
|
|
}
|
|
|
|
|
2002-01-27 17:41:06 +00:00
|
|
|
dialog->p->default_action_active = !(i == 0);
|
|
|
|
dialog->p->custom_action = (found_idx < 0);
|
2002-01-25 20:27:10 +00:00
|
|
|
|
2002-02-04 17:48:43 +00:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_menu_item_new_with_label (_("Custom")));
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
|
|
if (found_idx < 0) {
|
|
|
|
found_idx = i;
|
2002-01-28 18:39:42 +00:00
|
|
|
if (dialog->p->info->default_action->command != NULL)
|
2002-01-11 19:42:24 +00:00
|
|
|
gnome_file_entry_set_filename (GNOME_FILE_ENTRY (WID ("program_entry")),
|
2002-01-28 18:39:42 +00:00
|
|
|
dialog->p->info->default_action->command);
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (WID ("needs_terminal_toggle")),
|
|
|
|
dialog->p->info->default_action->requires_terminal);
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
} else {
|
|
|
|
gtk_widget_set_sensitive (WID ("program_entry_box"), FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
app_select = GTK_OPTION_MENU (WID ("default_action_select"));
|
|
|
|
gtk_option_menu_set_menu (app_select, GTK_WIDGET (menu));
|
|
|
|
gtk_option_menu_set_history (app_select, found_idx);
|
|
|
|
|
|
|
|
g_list_free (app_list);
|
2002-01-27 17:41:06 +00:00
|
|
|
|
|
|
|
update_sensitivity (dialog);
|
2002-01-08 21:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
populate_extensions_list (MimeEditDialog *dialog)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
for (tmp = dialog->p->info->file_extensions; tmp != NULL; tmp = tmp->next) {
|
|
|
|
gtk_tree_store_append (dialog->p->ext_store, &iter, NULL);
|
|
|
|
gtk_tree_store_set (dialog->p->ext_store, &iter, 0, tmp->data, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GList *
|
|
|
|
collect_filename_extensions (MimeEditDialog *dialog)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GValue value;
|
|
|
|
GList *ret = NULL;
|
|
|
|
|
2002-01-27 16:18:36 +00:00
|
|
|
if (!gtk_tree_model_get_iter_root (GTK_TREE_MODEL (dialog->p->ext_store), &iter))
|
|
|
|
return NULL;
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
|
|
value.g_type = G_TYPE_INVALID;
|
|
|
|
|
|
|
|
do {
|
|
|
|
gtk_tree_model_get_value (GTK_TREE_MODEL (dialog->p->ext_store), &iter, 0, &value);
|
|
|
|
ret = g_list_prepend (ret, g_value_dup_string (&value));
|
|
|
|
g_value_unset (&value);
|
|
|
|
} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (dialog->p->ext_store), &iter));
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
ret = g_list_reverse (ret);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
return ret;
|
2002-01-08 21:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
store_data (MimeEditDialog *dialog)
|
|
|
|
{
|
|
|
|
GtkOptionMenu *option_menu;
|
|
|
|
GtkMenuShell *menu_shell;
|
|
|
|
GObject *menu_item;
|
|
|
|
gint idx;
|
2002-01-25 16:12:01 +00:00
|
|
|
gchar *tmp;
|
|
|
|
const gchar *tmp1;
|
|
|
|
gboolean cat_changed = FALSE;
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
|
|
GList *ext_list;
|
|
|
|
|
2002-01-25 20:27:10 +00:00
|
|
|
uuid_t mime_uuid;
|
|
|
|
gchar mime_uuid_str[100];
|
|
|
|
|
2002-01-11 19:28:08 +00:00
|
|
|
GnomeVFSMimeApplication *app;
|
|
|
|
|
2002-01-26 16:24:45 +00:00
|
|
|
GtkTreeIter iter;
|
2002-01-25 16:12:01 +00:00
|
|
|
GtkTreePath *path;
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
g_free (dialog->p->info->description);
|
|
|
|
dialog->p->info->description = g_strdup (gtk_entry_get_text (GTK_ENTRY (WID ("description_entry"))));
|
|
|
|
|
|
|
|
g_free (dialog->p->info->mime_type);
|
2002-01-25 20:27:10 +00:00
|
|
|
tmp1 = gtk_entry_get_text (GTK_ENTRY (WID ("mime_type_entry")));
|
|
|
|
|
|
|
|
if (tmp1 != NULL && *tmp1 != '\0') {
|
|
|
|
dialog->p->info->mime_type = g_strdup (tmp1);
|
|
|
|
} else {
|
|
|
|
uuid_generate (mime_uuid);
|
|
|
|
uuid_unparse (mime_uuid, mime_uuid_str);
|
|
|
|
|
|
|
|
dialog->p->info->mime_type = g_strconcat ("custom/", mime_uuid_str, NULL);
|
|
|
|
}
|
2002-01-08 21:25:33 +00:00
|
|
|
|
2002-01-25 17:27:02 +00:00
|
|
|
g_free (dialog->p->info->icon_path);
|
|
|
|
dialog->p->info->icon_path = NULL;
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
g_free (dialog->p->info->icon_name);
|
|
|
|
dialog->p->info->icon_name = g_strdup (gnome_icon_entry_get_filename (GNOME_ICON_ENTRY (WID ("icon_entry"))));
|
|
|
|
|
2002-01-25 17:27:02 +00:00
|
|
|
if (dialog->p->info->icon_pixbuf != NULL) {
|
|
|
|
g_object_unref (G_OBJECT (dialog->p->info->icon_pixbuf));
|
|
|
|
dialog->p->info->icon_pixbuf = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dialog->p->info->small_icon_pixbuf != NULL) {
|
|
|
|
g_object_unref (G_OBJECT (dialog->p->info->small_icon_pixbuf));
|
|
|
|
dialog->p->info->small_icon_pixbuf = NULL;
|
|
|
|
}
|
|
|
|
|
2002-01-27 18:37:07 +00:00
|
|
|
dialog->p->info->use_category =
|
|
|
|
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (WID ("use_category_defaults_toggle")));
|
2002-01-27 17:41:06 +00:00
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
option_menu = GTK_OPTION_MENU (WID ("component_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;
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
CORBA_free (dialog->p->info->default_component);
|
|
|
|
dialog->p->info->default_component = g_object_get_data (menu_item, "component");
|
2002-01-08 21:25:33 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2002-01-11 19:28:08 +00:00
|
|
|
app = g_object_get_data (menu_item, "app");
|
2002-01-28 18:39:42 +00:00
|
|
|
if (app != NULL) {
|
|
|
|
gnome_vfs_mime_application_free (dialog->p->info->default_action);
|
2002-01-11 19:28:08 +00:00
|
|
|
dialog->p->info->default_action = gnome_vfs_mime_application_copy (app);
|
2002-01-28 18:39:42 +00:00
|
|
|
} else {
|
|
|
|
if (!mime_type_info_using_custom_app (dialog->p->info)) {
|
|
|
|
gnome_vfs_mime_application_free (dialog->p->info->default_action);
|
|
|
|
dialog->p->info->default_action = g_new0 (GnomeVFSMimeApplication, 1);
|
2002-03-12 01:35:40 +00:00
|
|
|
} else if (!dialog->p->info->default_action) {
|
|
|
|
dialog->p->info->default_action = g_new0 (GnomeVFSMimeApplication, 1);
|
2002-01-28 18:39:42 +00:00
|
|
|
}
|
2002-01-08 21:25:33 +00:00
|
|
|
|
2002-01-28 18:39:42 +00:00
|
|
|
g_free (dialog->p->info->default_action->command);
|
|
|
|
dialog->p->info->default_action->command
|
|
|
|
= g_strdup (gtk_entry_get_text (GTK_ENTRY
|
|
|
|
(gnome_file_entry_gtk_entry
|
|
|
|
(GNOME_FILE_ENTRY (WID ("program_entry"))))));
|
|
|
|
dialog->p->info->default_action->requires_terminal
|
|
|
|
= gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (WID ("needs_terminal_toggle")));
|
|
|
|
}
|
2002-01-11 20:54:55 +00:00
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
ext_list = collect_filename_extensions (dialog);
|
2002-01-25 16:12:01 +00:00
|
|
|
mime_type_info_set_file_extensions (dialog->p->info, ext_list);
|
2002-01-08 21:25:33 +00:00
|
|
|
|
2002-01-27 16:18:36 +00:00
|
|
|
tmp = mime_type_info_get_category_name (dialog->p->info);
|
|
|
|
tmp1 = gtk_entry_get_text (GTK_ENTRY (WID ("category_entry")));
|
|
|
|
if (strcmp (tmp, tmp1)) {
|
|
|
|
cat_changed = TRUE;
|
2002-02-17 18:48:49 +00:00
|
|
|
mime_type_info_set_category_name (dialog->p->info, tmp1, tmp1, dialog->p->model);
|
2002-01-27 16:18:36 +00:00
|
|
|
}
|
|
|
|
g_free (tmp);
|
2002-01-25 16:12:01 +00:00
|
|
|
|
2002-04-23 15:56:53 +00:00
|
|
|
model_entry_save (MODEL_ENTRY (dialog->p->info));
|
2002-01-25 20:27:10 +00:00
|
|
|
|
2002-01-27 16:18:36 +00:00
|
|
|
if (!cat_changed) {
|
|
|
|
mime_types_model_construct_iter (MIME_TYPES_MODEL (dialog->p->model),
|
|
|
|
MODEL_ENTRY (dialog->p->info), &iter);
|
2002-01-26 16:24:45 +00:00
|
|
|
path = gtk_tree_model_get_path (dialog->p->model, &iter);
|
|
|
|
gtk_tree_model_row_changed (dialog->p->model, path, &iter);
|
2002-01-25 16:12:01 +00:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
2002-01-08 21:25:33 +00:00
|
|
|
}
|
|
|
|
|
2002-01-25 20:27:10 +00:00
|
|
|
static gboolean
|
|
|
|
validate_data (MimeEditDialog *dialog)
|
|
|
|
{
|
|
|
|
const gchar *tmp;
|
2002-04-22 21:34:39 +00:00
|
|
|
const gchar *mesg = NULL;
|
2002-01-25 20:27:10 +00:00
|
|
|
|
|
|
|
tmp = gtk_entry_get_text (GTK_ENTRY (WID ("mime_type_entry")));
|
|
|
|
|
|
|
|
if (tmp != NULL && *tmp != '\0') {
|
|
|
|
if (strchr (tmp, ' ') || !strchr (tmp, '/')) {
|
2002-04-22 21:34:39 +00:00
|
|
|
mesg = _("Invalid MIME type. Please enter a valid MIME type, or "
|
|
|
|
"leave the field blank to have one generated for you.");
|
|
|
|
} else if (dialog->p->is_add && (gnome_vfs_mime_type_is_known (tmp) ||
|
|
|
|
get_mime_type_info (tmp) != NULL)) {
|
|
|
|
mesg = _("There already exists a MIME type of that name.");
|
2002-04-10 20:11:02 +00:00
|
|
|
}
|
|
|
|
}
|
2002-01-27 16:58:43 +00:00
|
|
|
|
2002-04-22 21:34:39 +00:00
|
|
|
if (mesg != NULL) {
|
|
|
|
GtkWidget *err_dialog = gtk_message_dialog_new (
|
|
|
|
GTK_WINDOW (dialog->p->dialog_win),
|
|
|
|
GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_OK,
|
|
|
|
mesg);
|
2002-04-10 20:11:02 +00:00
|
|
|
gtk_dialog_run (GTK_DIALOG (err_dialog));
|
2002-04-22 21:34:39 +00:00
|
|
|
gtk_object_destroy (GTK_OBJECT (err_dialog));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-25 20:27:10 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
static void
|
|
|
|
add_ext_cb (MimeEditDialog *dialog)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
2002-01-11 18:37:17 +00:00
|
|
|
const gchar *ext_name;
|
2002-01-08 21:25:33 +00:00
|
|
|
|
2002-01-11 18:37:17 +00:00
|
|
|
ext_name = gtk_entry_get_text (GTK_ENTRY (WID ("new_ext_entry")));
|
2002-01-08 21:25:33 +00:00
|
|
|
|
2002-01-11 18:37:17 +00:00
|
|
|
if (ext_name != NULL && *ext_name != '\0') {
|
2002-01-08 21:25:33 +00:00
|
|
|
gtk_tree_store_append (dialog->p->ext_store, &iter, NULL);
|
2002-01-11 18:37:17 +00:00
|
|
|
gtk_tree_store_set (dialog->p->ext_store, &iter, 0, ext_name, -1);
|
2002-01-08 21:25:33 +00:00
|
|
|
}
|
2002-01-25 20:27:10 +00:00
|
|
|
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (WID ("new_ext_entry")), "");
|
2002-01-08 21:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_ext_foreach_cb (GtkTreeModel *model, GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
{
|
|
|
|
gtk_tree_store_remove (GTK_TREE_STORE (model), iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_ext_cb (MimeEditDialog *dialog)
|
|
|
|
{
|
|
|
|
gtk_tree_selection_selected_foreach (gtk_tree_view_get_selection (GTK_TREE_VIEW (WID ("ext_list"))),
|
|
|
|
(GtkTreeSelectionForeachFunc) remove_ext_foreach_cb, NULL);
|
|
|
|
}
|
|
|
|
|
2002-01-14 15:28:36 +00:00
|
|
|
static void
|
|
|
|
choose_cat_cb (MimeEditDialog *dialog)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkWidget *treeview;
|
|
|
|
GtkWidget *dialog_win;
|
2002-01-25 20:27:10 +00:00
|
|
|
GtkWidget *scrolled_win;
|
2002-01-14 15:28:36 +00:00
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
|
2002-01-25 16:12:01 +00:00
|
|
|
model = GTK_TREE_MODEL (mime_types_model_new (TRUE));
|
2002-01-14 15:28:36 +00:00
|
|
|
treeview = gtk_tree_view_new_with_model (model);
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
|
|
|
|
gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
|
2002-01-25 20:27:10 +00:00
|
|
|
|
|
|
|
if (dialog->p->info->entry.parent != NULL) {
|
|
|
|
mime_types_model_construct_iter (MIME_TYPES_MODEL (model), dialog->p->info->entry.parent, &iter);
|
|
|
|
gtk_tree_selection_select_iter (selection, &iter);
|
|
|
|
}
|
2002-01-14 15:28:36 +00:00
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_text_new ();
|
|
|
|
gtk_tree_view_insert_column_with_attributes
|
|
|
|
(GTK_TREE_VIEW (treeview), -1, _("Category"), renderer,
|
2002-01-25 16:12:01 +00:00
|
|
|
"text", MODEL_COLUMN_DESCRIPTION,
|
2002-01-14 15:28:36 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
dialog_win = gtk_dialog_new_with_buttons
|
|
|
|
(_("Choose a file category"), NULL, -1,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
2002-04-22 21:34:39 +00:00
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
2002-01-14 15:28:36 +00:00
|
|
|
NULL);
|
|
|
|
|
2002-02-04 17:48:43 +00:00
|
|
|
gtk_widget_set_size_request (dialog_win, 300, 300);
|
2002-01-25 20:27:10 +00:00
|
|
|
|
|
|
|
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_container_add (GTK_CONTAINER (scrolled_win), treeview);
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_win)->vbox), scrolled_win, TRUE, TRUE, GNOME_PAD_SMALL);
|
2002-01-14 15:28:36 +00:00
|
|
|
gtk_widget_show_all (dialog_win);
|
|
|
|
|
|
|
|
if (gtk_dialog_run (GTK_DIALOG (dialog_win)) == GTK_RESPONSE_OK) {
|
|
|
|
gtk_tree_selection_get_selected (selection, &model, &iter);
|
2002-01-25 16:12:01 +00:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (WID ("category_entry")),
|
2002-01-27 19:02:15 +00:00
|
|
|
mime_category_info_get_full_name (MIME_CATEGORY_INFO (MODEL_ENTRY_FROM_ITER (&iter))));
|
2002-01-14 15:28:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_destroy (dialog_win);
|
|
|
|
g_object_unref (G_OBJECT (model));
|
|
|
|
}
|
|
|
|
|
2002-01-08 21:25:33 +00:00
|
|
|
static void
|
|
|
|
default_action_changed_cb (MimeEditDialog *dialog)
|
|
|
|
{
|
|
|
|
int id;
|
|
|
|
GtkOptionMenu *option_menu;
|
|
|
|
GtkMenuShell *menu;
|
|
|
|
|
|
|
|
option_menu = GTK_OPTION_MENU (WID ("default_action_select"));
|
|
|
|
menu = GTK_MENU_SHELL (gtk_option_menu_get_menu (option_menu));
|
|
|
|
id = gtk_option_menu_get_history (option_menu);
|
|
|
|
|
2002-01-27 17:41:06 +00:00
|
|
|
dialog->p->custom_action = (id == g_list_length (menu->children) - 1);
|
|
|
|
|
|
|
|
update_sensitivity (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
use_category_defaults_toggled_cb (MimeEditDialog *dialog, GtkToggleButton *tb)
|
|
|
|
{
|
|
|
|
dialog->p->use_cat_dfl = gtk_toggle_button_get_active (tb);
|
|
|
|
update_sensitivity (dialog);
|
2002-01-08 21:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
response_cb (MimeEditDialog *dialog, gint response_id)
|
|
|
|
{
|
2002-01-25 20:27:10 +00:00
|
|
|
if (response_id == GTK_RESPONSE_OK) {
|
|
|
|
if (validate_data (dialog)) {
|
|
|
|
store_data (dialog);
|
2002-01-28 02:56:07 +00:00
|
|
|
g_signal_emit (G_OBJECT (dialog), dialog_signals[DONE], 0, TRUE);
|
2002-01-25 20:27:10 +00:00
|
|
|
g_object_unref (G_OBJECT (dialog));
|
|
|
|
}
|
|
|
|
} else {
|
2002-01-26 18:30:32 +00:00
|
|
|
if (dialog->p->is_add)
|
|
|
|
mime_type_info_free (dialog->p->info);
|
|
|
|
|
2002-01-28 02:56:07 +00:00
|
|
|
g_signal_emit (G_OBJECT (dialog), dialog_signals[DONE], 0, FALSE);
|
|
|
|
|
2002-01-25 20:27:10 +00:00
|
|
|
g_object_unref (G_OBJECT (dialog));
|
|
|
|
}
|
2002-01-08 21:25:33 +00:00
|
|
|
}
|
2002-01-27 17:41:06 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
update_sensitivity (MimeEditDialog *dialog)
|
|
|
|
{
|
|
|
|
gtk_widget_set_sensitive (WID ("component_box"), dialog->p->component_active && !dialog->p->use_cat_dfl);
|
|
|
|
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);
|
|
|
|
}
|