Set custom program entry and needs terminal here

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

	* service-edit-dialog.c (populate_app_list): Set custom program
	entry and needs terminal here

	* service-info.c (service_info_using_custom_app): Implement

	* service-edit-dialog.c (populate_app_list): Add destroy notify
	for app

	* service-info.[ch]: Eliminate custom_line and needs_terminal; use
	app for that
This commit is contained in:
Bradford Hovinen 2002-01-28 19:08:14 +00:00 committed by Bradford Hovinen (Gdict maintainer)
parent 049ab3cb31
commit 66fa37fc6e
4 changed files with 105 additions and 24 deletions

View file

@ -1,5 +1,16 @@
2002-01-28 Bradford Hovinen <hovinen@ximian.com>
* service-edit-dialog.c (populate_app_list): Set custom program
entry and needs terminal here
* service-info.c (service_info_using_custom_app): Implement
* service-edit-dialog.c (populate_app_list): Add destroy notify
for app
* service-info.[ch]: Eliminate custom_line and needs_terminal; use
app for that
* mime-edit-dialog.c (populate_application_list): Use
gnome_vfs_application_registry_get_applications

View file

@ -339,9 +339,6 @@ fill_dialog (ServiceEditDialog *dialog)
if (!dialog->p->info->run_program && strcmp (dialog->p->info->protocol, "ftp"))
gtk_widget_set_sensitive (WID ("program_frame"), FALSE);
if (dialog->p->info->custom_line != NULL)
gnome_file_entry_set_filename (GNOME_FILE_ENTRY (WID ("custom_program_entry")), dialog->p->info->custom_line);
populate_app_list (dialog);
}
@ -367,6 +364,7 @@ populate_app_list (ServiceEditDialog *dialog)
GtkOptionMenu *option_menu;
GtkMenu *menu;
GtkWidget *item;
gint found_idx = -1, i = 0;
const GList *service_apps;
GnomeVFSMimeApplication *app;
@ -380,17 +378,36 @@ populate_app_list (ServiceEditDialog *dialog)
while (service_apps != NULL) {
app = service_apps->data;
if (dialog->p->info->app != NULL &&
dialog->p->info->app->id != NULL &&
!strcmp (dialog->p->info->app->id, app->id))
found_idx = i;
item = gtk_menu_item_new_with_label (app->name);
g_object_set_data (G_OBJECT (item), "app", app);
g_object_set_data_full (G_OBJECT (item), "app", app, (GDestroyNotify) gnome_vfs_mime_application_free);
gtk_widget_show (item);
gtk_menu_append (menu, item);
service_apps = service_apps->next;
i++;
}
item = gtk_menu_item_new_with_label (_("Custom"));
gtk_widget_show (item);
gtk_menu_append (menu, item);
if (found_idx < 0) {
if (dialog->p->info->app != NULL) {
if (dialog->p->info->app->command != NULL)
gnome_file_entry_set_filename (GNOME_FILE_ENTRY (WID ("custom_program_entry")),
dialog->p->info->app->command);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (WID ("needs_terminal_toggle")),
dialog->p->info->app->requires_terminal);
}
}
gtk_option_menu_set_menu (option_menu, GTK_WIDGET (menu));
}
@ -402,6 +419,8 @@ store_data (ServiceEditDialog *dialog)
GObject *menu_item;
gint idx;
GnomeVFSMimeApplication *app;
GtkTreePath *path;
GtkTreeIter iter;
@ -414,18 +433,29 @@ store_data (ServiceEditDialog *dialog)
dialog->p->info->run_program =
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (WID ("run_program_toggle")));
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));
option_menu = GTK_OPTION_MENU (WID ("program_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->app);
dialog->p->info->app =
gnome_vfs_mime_application_copy (g_object_get_data (menu_item, "app"));
app = g_object_get_data (menu_item, "app");
if (app != NULL) {
gnome_vfs_mime_application_free (dialog->p->info->app);
dialog->p->info->app = gnome_vfs_mime_application_copy (app);
} else {
if (!service_info_using_custom_app (dialog->p->info)) {
gnome_vfs_mime_application_free (dialog->p->info->app);
dialog->p->info->app = g_new0 (GnomeVFSMimeApplication, 1);
}
g_free (dialog->p->info->app->command);
dialog->p->info->app->command
= g_strdup (gtk_entry_get_text (GTK_ENTRY
(gnome_file_entry_gtk_entry
(GNOME_FILE_ENTRY (WID ("custom_program_entry"))))));
dialog->p->info->app->requires_terminal
= gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (WID ("needs_terminal_toggle")));
}
model_entry_append_to_dirty_list (MODEL_ENTRY (dialog->p->info));

View file

@ -29,6 +29,8 @@
#include <gconf/gconf-client.h>
#include <libgnomevfs/gnome-vfs-application-registry.h>
#include "libuuid/uuid.h"
#include "service-info.h"
#include "mime-types-model.h"
@ -119,15 +121,15 @@ service_info_load_all (ServiceInfo *info)
info->run_program = TRUE;
#endif
if (info->custom_line == NULL)
info->custom_line = get_string (info, "command");
info->need_terminal = get_bool (info, "need-terminal");
if (info->app == NULL) {
id = get_string (info, "command-id");
if (id != NULL)
info->app = gnome_vfs_mime_application_new_from_id (id);
else {
info->app = g_new0 (GnomeVFSMimeApplication, 1);
info->app->command = get_string (info, "command");
info->app->requires_terminal = get_bool (info, "needs-terminal");
}
g_free (id);
}
}
@ -151,21 +153,61 @@ service_info_get_description (ServiceInfo *info)
return info->description;
}
gboolean
service_info_using_custom_app (const ServiceInfo *info)
{
gchar *tmp;
gboolean ret;
if (info->app->name == NULL)
return TRUE;
tmp = g_strdup_printf ("Custom %s", info->protocol);
ret = !strcmp (tmp, info->app->name);
g_free (tmp);
return ret;
}
void
service_info_save (const ServiceInfo *info)
{
gchar *tmp;
uuid_t app_uuid;
gchar app_uuid_str[100];
set_string (info, "description", info->description);
if (info->app == NULL) {
set_string (info, "command", info->custom_line);
set_string (info, "command-id", "");
} else {
if (info->app != NULL && info->app->command != NULL && *info->app->command != '\0') {
tmp = g_strdup_printf ("Custom %s", info->protocol);
if (info->app->name == NULL)
info->app->name = tmp;
if (info->app->id == NULL) {
uuid_generate (app_uuid);
uuid_unparse (app_uuid, app_uuid_str);
info->app->id = g_strdup (app_uuid_str);
gnome_vfs_application_registry_save_mime_application (info->app);
gnome_vfs_application_registry_sync ();
}
else if (!strcmp (tmp, info->app->name)) {
gnome_vfs_application_registry_set_value (info->app->id, "command",
info->app->command);
gnome_vfs_application_registry_set_bool_value (info->app->id, "requires_terminal",
info->app->requires_terminal);
}
set_string (info, "command", info->app->command);
set_string (info, "command-id", info->app->id);
} else {
set_string (info, "command", NULL);
set_string (info, "command-id", NULL);
}
set_bool (info, "type", info->run_program);
set_bool (info, "need-terminal", info->need_terminal);
}
void
@ -200,7 +242,6 @@ service_info_free (ServiceInfo *info)
g_free (info->protocol);
g_free (info->description);
gnome_vfs_mime_application_free (info->app);
g_free (info->custom_line);
g_free (info);
}

View file

@ -45,8 +45,6 @@ struct _ServiceInfo {
gboolean run_program;
GnomeVFSMimeApplication *app;
gchar *custom_line;
gboolean need_terminal;
};
void load_all_services (GtkTreeModel *model);
@ -55,6 +53,7 @@ ServiceInfo *service_info_new (const gchar *protocol,
GtkTreeModel *model);
void service_info_load_all (ServiceInfo *info);
const gchar *service_info_get_description (ServiceInfo *info);
gboolean service_info_using_custom_app (const ServiceInfo *info);
void service_info_save (const ServiceInfo *info);
void service_info_delete (const ServiceInfo *info);
void service_info_free (ServiceInfo *info);