Terminate column list with -1

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

	* mime-edit-dialog.c (add_ext_cb): Terminate column list with -1

	* service-edit-dialog.c (store_data): Call service_info_update

	* mime-edit-dialog.c (store_data): Call mime_type_info_update

	* mime-type-info.c (mime_type_info_update): Implement. Updates the
	model with data from the structure

	* service-info.c (service_info_update): Implement. Updates the
	model with data from the structure

	* mime-type-info.c (form_extensions_string): Implement. Factor
	from mime_type_info_save

	* service-info.c (service_info_load): Accept model and iter rather
	than protocol name; read protocol name from model

	* mime-type-info.c (mime_type_info_load): Accept model and iter
	rather than mime type; read the mime type from the model

	* mime-types-model.c (get_icon_pixbuf): Make this public
This commit is contained in:
Bradford Hovinen 2002-01-11 15:32:10 +00:00 committed by Bradford Hovinen (Gdict maintainer)
parent b097229244
commit ee6a2823a4
11 changed files with 221 additions and 112 deletions

View file

@ -1,5 +1,40 @@
2002-01-11 Bradford Hovinen <hovinen@ximian.com>
* mime-edit-dialog.c (add_ext_cb): Terminate column list with -1
* service-edit-dialog.c (store_data): Call service_info_update
* mime-edit-dialog.c (store_data): Call mime_type_info_update
* mime-type-info.c (mime_type_info_update): Implement. Updates the
model with data from the structure
* service-info.c (service_info_update): Implement. Updates the
model with data from the structure
* mime-type-info.c (form_extensions_string): Implement. Factor
from mime_type_info_save
* service-info.c (service_info_load): Accept model and iter rather
than protocol name; read protocol name from model
* mime-type-info.c (mime_type_info_load): Accept model and iter
rather than mime type; read the mime type from the model
* mime-types-model.c (get_icon_pixbuf): Make this public
* service-edit-dialog.c (fill_dialog): Set the protocol entry
insensitive if the protocol is already set; don't put unknown in
the protocol entry
* mime-types-model.c: Include gnome-vfs-mime-info.h
* service-info.c (get_string): Call get_description_for_protocol
if we are fetching the description and it is not in the changeset
* mime-types-model.c (get_description_for_protocol): Make this
public
* service-edit-dialog.c (store_data): Implement
(program_sensitive_cb): Implement
(response_cb): Call store_data if response_id is OK

View file

@ -1,7 +1,7 @@
- Get icon name (esp. use of stock icons) working correctly
- Add categories to many types in MIME database
- Validation
- Talk to gnome-vfs people about categories, edit and print lines, custom line, gnome-vfs-mime-info.h install
- Talk to gnome-vfs people about edit and print lines
- Do something better about custom-line (i.e. create a dummy app in the app register)
- Make MIME types tree accept double clicks
- Implement tree cascading
@ -14,3 +14,5 @@
CVS Surgery
- Move file-types to gnome-control-center, rename ???
- Move default-apps to control-center-plus
- Rename .glade files in standard convention (gnome-xxx-properties.glade)
- Rename primary .c files in standard convention (gnome-xxx-properties.c)

View file

@ -59,7 +59,6 @@ edit_cb (GtkButton *button, GladeXML *dialog)
GtkTreeModel *model;
GtkTreeSelection *selection;
GtkTreeIter iter;
GValue mime_type;
GObject *edit_dialog;
@ -67,15 +66,10 @@ edit_cb (GtkButton *button, GladeXML *dialog)
selection = gtk_tree_view_get_selection (treeview);
gtk_tree_selection_get_selected (selection, &model, &iter);
mime_type.g_type = G_TYPE_INVALID;
gtk_tree_model_get_value (model, &iter, MIME_TYPE_COLUMN, &mime_type);
if (model_entry_is_protocol (model, &iter))
edit_dialog = service_edit_dialog_new (service_info_load (g_value_get_string (&mime_type), NULL));
edit_dialog = service_edit_dialog_new (service_info_load (model, &iter, NULL));
else
edit_dialog = mime_edit_dialog_new (mime_type_info_load (g_value_get_string (&mime_type)));
g_value_unset (&mime_type);
edit_dialog = mime_edit_dialog_new (mime_type_info_load (model, &iter));
}
static void

View file

@ -483,6 +483,7 @@ store_data (MimeEditDialog *dialog)
g_list_foreach (ext_list, (GFunc) g_free, NULL);
g_list_free (ext_list);
mime_type_info_update (dialog->p->info);
mime_type_append_to_dirty_list (dialog->p->info);
}
@ -515,7 +516,7 @@ add_ext_cb (MimeEditDialog *dialog)
if (response_id == GTK_RESPONSE_OK) {
gtk_tree_store_append (dialog->p->ext_store, &iter, NULL);
gtk_tree_store_set (dialog->p->ext_store, &iter, 0,
gtk_entry_get_text (GTK_ENTRY (ext_entry)));
gtk_entry_get_text (GTK_ENTRY (ext_entry)), -1);
}
gtk_widget_destroy (GTK_WIDGET (add_dialog));

View file

@ -32,6 +32,7 @@
#include <bonobo.h>
#include "mime-type-info.h"
#include "mime-types-model.h"
static GList *dirty_list = NULL;
@ -61,29 +62,57 @@ get_lang_list (void)
return retval;
}
MimeTypeInfo *
mime_type_info_load (const gchar *mime_type)
static gchar *
form_extensions_string (const MimeTypeInfo *info, gchar *sep, gchar *prepend)
{
MimeTypeInfo *info;
Bonobo_ServerInfo *component_info;
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;
}
MimeTypeInfo *
mime_type_info_load (GtkTreeModel *model, GtkTreeIter *iter)
{
MimeTypeInfo *info;
Bonobo_ServerInfo *component_info;
GValue mime_type;
mime_type.g_type = G_TYPE_INVALID;
gtk_tree_model_get_value (model, iter, MIME_TYPE_COLUMN, &mime_type);
info = g_new0 (MimeTypeInfo, 1);
info->mime_type = g_strdup (mime_type);
info->description = g_strdup (gnome_vfs_mime_get_description (mime_type));
info->icon_name = g_strdup (gnome_vfs_mime_get_icon (mime_type));
info->file_extensions = gnome_vfs_mime_get_extensions_list (mime_type);
info->edit_line = g_strdup (gnome_vfs_mime_get_value (mime_type, "edit-line"));
info->print_line = g_strdup (gnome_vfs_mime_get_value (mime_type, "print-line"));
info->default_action = gnome_vfs_mime_get_default_application (mime_type);
info->custom_line = g_strdup (gnome_vfs_mime_get_value (mime_type, "custom-line"));
info->model = model;
info->iter = gtk_tree_iter_copy (iter);
info->mime_type = g_value_dup_string (&mime_type);
info->description = g_strdup (gnome_vfs_mime_get_description (info->mime_type));
info->icon_name = g_strdup (gnome_vfs_mime_get_icon (info->mime_type));
info->file_extensions = gnome_vfs_mime_get_extensions_list (info->mime_type);
info->edit_line = g_strdup (gnome_vfs_mime_get_value (info->mime_type, "edit-line"));
info->print_line = g_strdup (gnome_vfs_mime_get_value (info->mime_type, "print-line"));
info->default_action = gnome_vfs_mime_get_default_application (info->mime_type);
info->custom_line = g_strdup (gnome_vfs_mime_get_value (info->mime_type, "custom-line"));
component_info = gnome_vfs_mime_get_default_component (mime_type);
component_info = gnome_vfs_mime_get_default_component (info->mime_type);
if (component_info != NULL) {
info->default_component_id = component_info->iid;
CORBA_free (component_info);
}
g_value_unset (&mime_type);
return info;
}
@ -91,9 +120,6 @@ void
mime_type_info_save (const MimeTypeInfo *info)
{
gchar *tmp;
gchar **array;
GList *l;
gint i = 0;
gnome_vfs_mime_set_description (info->mime_type, info->description);
gnome_vfs_mime_set_icon (info->mime_type, info->icon_name);
@ -102,16 +128,28 @@ mime_type_info_save (const MimeTypeInfo *info)
gnome_vfs_mime_set_value (info->mime_type, "print-line", info->print_line);
gnome_vfs_mime_set_value (info->mime_type, "edit-line", info->edit_line);
array = g_new0 (gchar *, g_list_length (info->file_extensions) + 1);
for (l = info->file_extensions; l != NULL; l = l->next)
array[i++] = l->data;
tmp = g_strjoinv (" ", array);
g_free (array);
tmp = form_extensions_string (info, " ", NULL);
gnome_vfs_mime_set_extensions_list (info->mime_type, tmp);
g_free (tmp);
}
void
mime_type_info_update (MimeTypeInfo *info)
{
GdkPixbuf *pixbuf;
gchar *tmp;
pixbuf = get_icon_pixbuf (info->icon_name);
tmp = form_extensions_string (info, ", ", ".");
gtk_tree_store_set (GTK_TREE_STORE (info->model), info->iter,
DESCRIPTION_COLUMN, info->description,
ICON_COLUMN, pixbuf,
EXTENSIONS_COLUMN, tmp,
-1);
g_free (tmp);
}
void
mime_type_info_free (MimeTypeInfo *info)
{

View file

@ -36,6 +36,9 @@ typedef struct _MimeTypeInfo MimeTypeInfo;
struct _MimeTypeInfo
{
GtkTreeModel *model;
GtkTreeIter *iter;
gchar *mime_type;
gchar *description;
gchar *icon_name;
@ -50,9 +53,11 @@ struct _MimeTypeInfo
gboolean is_category;
};
MimeTypeInfo *mime_type_info_load (const gchar *mime_type);
void mime_type_info_save (const MimeTypeInfo *info);
void mime_type_info_free (MimeTypeInfo *info);
MimeTypeInfo *mime_type_info_load (GtkTreeModel *model,
GtkTreeIter *iter);
void mime_type_info_save (const MimeTypeInfo *info);
void mime_type_info_update (MimeTypeInfo *info);
void mime_type_info_free (MimeTypeInfo *info);
char *mime_type_get_pretty_name_for_server (Bonobo_ServerInfo *server);

View file

@ -29,6 +29,7 @@
#include <libgnomevfs/gnome-vfs.h>
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
#include <libgnomevfs/gnome-vfs-mime-utils.h>
#include <libgnomevfs/gnome-vfs-mime-info.h>
#include <gconf/gconf.h>
#include <gconf/gconf-client.h>
@ -49,56 +50,15 @@ const gchar *url_descriptions[][2] = {
{ NULL, NULL }
};
static GdkPixbuf *
get_icon_pixbuf (const gchar *short_icon_name)
{
gchar *icon_name;
GdkPixbuf *pixbuf, *pixbuf1;
static GHashTable *pixbuf_table;
if (pixbuf_table == NULL)
pixbuf_table = g_hash_table_new (g_str_hash, g_str_equal);
if (short_icon_name == NULL)
short_icon_name = "nautilus/i-regular-24.png";
icon_name = gnome_program_locate_file
(gnome_program_get (), GNOME_FILE_DOMAIN_PIXMAP,
short_icon_name, TRUE, NULL);
if (icon_name != NULL) {
pixbuf1 = g_hash_table_lookup (pixbuf_table, icon_name);
if (pixbuf1 != NULL) {
g_object_ref (G_OBJECT (pixbuf1));
} else {
pixbuf = gdk_pixbuf_new_from_file (icon_name, NULL);
if (pixbuf == NULL)
pixbuf = get_icon_pixbuf (NULL);
pixbuf1 = gdk_pixbuf_scale_simple (pixbuf, 16, 16, GDK_INTERP_BILINEAR);
g_object_unref (G_OBJECT (pixbuf));
}
g_free (icon_name);
} else {
pixbuf1 = get_icon_pixbuf (NULL);
}
return pixbuf1;
}
static gchar *
get_category_path_for_mime_type (const gchar *mime_type)
{
gchar *path;
const gchar *path;
path = gnome_vfs_mime_get_value (mime_type, "category");
if (path != NULL)
return path;
return g_strdup (path);
else if (!strncmp (mime_type, "image", strlen ("image")))
return "Images";
else if (!strncmp (mime_type, "video", strlen ("video")))
@ -179,27 +139,6 @@ get_protocol_name (const gchar *key)
return NULL;
}
static gchar *
get_description_for_protocol (const gchar *protocol_name)
{
gchar *description;
gchar *key;
int i;
key = g_strconcat ("/desktop/gnome/url-handlers/", protocol_name, "/description", NULL);
description = gconf_client_get_string (gconf_client_get_default (), key, NULL);
g_free (key);
if (description != NULL)
return description;
for (i = 0; url_descriptions[i][0] != NULL; i++)
if (!strcmp (url_descriptions[i][0], protocol_name))
return g_strdup (url_descriptions[i][1]);
return NULL;
}
GtkTreeModel *
mime_types_model_new (void)
{
@ -288,6 +227,68 @@ mime_types_model_new (void)
return GTK_TREE_MODEL (model);
}
GdkPixbuf *
get_icon_pixbuf (const gchar *short_icon_name)
{
gchar *icon_name;
GdkPixbuf *pixbuf, *pixbuf1;
static GHashTable *pixbuf_table;
if (pixbuf_table == NULL)
pixbuf_table = g_hash_table_new (g_str_hash, g_str_equal);
if (short_icon_name == NULL)
short_icon_name = "nautilus/i-regular-24.png";
icon_name = gnome_program_locate_file
(gnome_program_get (), GNOME_FILE_DOMAIN_PIXMAP,
short_icon_name, TRUE, NULL);
if (icon_name != NULL) {
pixbuf1 = g_hash_table_lookup (pixbuf_table, icon_name);
if (pixbuf1 != NULL) {
g_object_ref (G_OBJECT (pixbuf1));
} else {
pixbuf = gdk_pixbuf_new_from_file (icon_name, NULL);
if (pixbuf == NULL)
pixbuf = get_icon_pixbuf (NULL);
pixbuf1 = gdk_pixbuf_scale_simple (pixbuf, 16, 16, GDK_INTERP_BILINEAR);
g_object_unref (G_OBJECT (pixbuf));
}
g_free (icon_name);
} else {
pixbuf1 = get_icon_pixbuf (NULL);
}
return pixbuf1;
}
gchar *
get_description_for_protocol (const gchar *protocol_name)
{
gchar *description;
gchar *key;
int i;
key = g_strconcat ("/desktop/gnome/url-handlers/", protocol_name, "/description", NULL);
description = gconf_client_get_string (gconf_client_get_default (), key, NULL);
g_free (key);
if (description != NULL)
return description;
for (i = 0; url_descriptions[i][0] != NULL; i++)
if (!strcmp (url_descriptions[i][0], protocol_name))
return g_strdup (url_descriptions[i][1]);
return NULL;
}
gboolean
model_entry_is_protocol (GtkTreeModel *model, GtkTreeIter *iter)
{

View file

@ -36,9 +36,13 @@ enum {
EXTENSIONS_COLUMN
};
GtkTreeModel *mime_types_model_new (void);
GtkTreeModel *mime_types_model_new (void);
gboolean model_entry_is_protocol (GtkTreeModel *model, GtkTreeIter *iter);
GdkPixbuf *get_icon_pixbuf (const gchar *short_icon_name);
gchar *get_description_for_protocol (const gchar *protocol_name);
gboolean model_entry_is_protocol (GtkTreeModel *model,
GtkTreeIter *iter);
G_END_DECLS

View file

@ -250,8 +250,12 @@ fill_dialog (ServiceEditDialog *dialog)
if (dialog->p->info->description != NULL)
gtk_entry_set_text (GTK_ENTRY (WID ("description_entry")), dialog->p->info->description);
if (dialog->p->info->protocol != NULL)
gtk_entry_set_text (GTK_ENTRY (WID ("protocol_entry")), dialog->p->info->protocol);
if (dialog->p->info->protocol != NULL) {
if (strcmp (dialog->p->info->protocol, "unknown"))
gtk_entry_set_text (GTK_ENTRY (WID ("protocol_entry")), dialog->p->info->protocol);
gtk_widget_set_sensitive (WID ("protocol_entry"), FALSE);
}
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (WID ("look_at_content_toggle")), !dialog->p->info->run_program);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (WID ("run_program_toggle")), dialog->p->info->run_program);
@ -297,6 +301,8 @@ store_data (ServiceEditDialog *dialog)
g_free (dialog->p->info->custom_line);
dialog->p->info->custom_line =
g_strdup (gnome_file_entry_get_full_path (GNOME_FILE_ENTRY (WID ("custom_program_entry")), FALSE));
service_info_update (dialog->p->info);
}
static void

View file

@ -29,6 +29,7 @@
#include <gconf/gconf-client.h>
#include "service-info.h"
#include "mime-types-model.h"
static gchar *
get_key_name (const ServiceInfo *info, gchar *end)
@ -79,7 +80,10 @@ get_string (const ServiceInfo *info, gchar *end, GConfChangeSet *changeset)
found = gconf_change_set_check_value (changeset, key, &value);
if (!found || changeset == NULL) {
ret = gconf_client_get_string (gconf_client_get_default (), key, NULL);
if (!strcmp (end, "description"))
ret = get_description_for_protocol (info->protocol);
else
ret = gconf_client_get_string (gconf_client_get_default (), key, NULL);
} else {
ret = g_strdup (gconf_value_get_string (value));
gconf_value_free (value);
@ -116,13 +120,19 @@ get_bool (const ServiceInfo *info, gchar *end, GConfChangeSet *changeset)
}
ServiceInfo *
service_info_load (const gchar *protocol, GConfChangeSet *changeset)
service_info_load (GtkTreeModel *model, GtkTreeIter *iter, GConfChangeSet *changeset)
{
ServiceInfo *info;
gchar *id;
gchar *id;
GValue protocol;
protocol.g_type = G_TYPE_INVALID;
gtk_tree_model_get_value (model, iter, MIME_TYPE_COLUMN, &protocol);
info = g_new0 (ServiceInfo, 1);
info->protocol = g_strdup (protocol);
info->model = model;
info->iter = gtk_tree_iter_copy (iter);
info->protocol = g_value_dup_string (&protocol);
info->description = get_string (info, "description", changeset);
info->run_program = get_bool (info, "type", changeset);
info->custom_line = get_string (info, "command", changeset);
@ -153,6 +163,14 @@ service_info_save (const ServiceInfo *info, GConfChangeSet *changeset)
set_bool (info, "need-terminal", info->need_terminal, changeset);
}
void
service_info_update (ServiceInfo *info)
{
gtk_tree_store_set (GTK_TREE_STORE (info->model), info->iter,
DESCRIPTION_COLUMN, info->description,
-1);
}
void
service_info_free (ServiceInfo *info)
{

View file

@ -35,6 +35,9 @@ G_BEGIN_DECLS
typedef struct _ServiceInfo ServiceInfo;
struct _ServiceInfo {
GtkTreeModel *model;
GtkTreeIter *iter;
gchar *protocol;
gchar *description;
gboolean run_program;
@ -44,11 +47,13 @@ struct _ServiceInfo {
gboolean need_terminal;
};
ServiceInfo *service_info_load (const gchar *protocol,
GConfChangeSet *changeset);
void service_info_save (const ServiceInfo *info,
GConfChangeSet *changeset);
void service_info_free (ServiceInfo *info);
ServiceInfo *service_info_load (GtkTreeModel *model,
GtkTreeIter *iter,
GConfChangeSet *changeset);
void service_info_save (const ServiceInfo *info,
GConfChangeSet *changeset);
void service_info_update (ServiceInfo *info);
void service_info_free (ServiceInfo *info);
G_END_DECLS