1 /* $Id: preferences.c,v 1.3 2007/12/12 13:17:33 dforsi Exp $ */
2 
3 #ifdef HAVE_CONFIG_H
4 #  include <config.h>
5 #endif
6 
7 #include <gtk/gtk.h>
8 #include <glade/glade.h>
9 #include <gnokii.h>
10 #include "utils.h"
11 
12 extern GtkWidget *window;
13 
14 enum {
15 	COL_NAME,
16 	COL_TYPE
17 };
18 
create_preferences(gn_config * cfg)19 void create_preferences(gn_config *cfg)
20 {
21 	GladeXML *prefs_xml;
22 	GtkWidget *prefs;
23 	GtkWidget *widget;
24 	GtkTreeStore *store;
25 	GtkTreeIter iter;
26 	const gchar *connection_name;
27 	gn_connection_type connection_type;
28 	gint i, res;
29 
30 	prefs_xml = create_gladexml("gnocky-preferences.glade", "gnocky_preferences");
31 
32 	if (!prefs_xml)
33 		g_error("Cannot create preferences!\n");
34 
35 	prefs = glade_xml_get_widget(prefs_xml, "gnocky_preferences");
36 
37 	if (prefs == NULL)
38 		g_error("Wrong glade data!\n");
39 
40 	widget = glade_xml_get_widget(prefs_xml, "connection");
41 	store = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_INT);
42 	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(store), COL_NAME, GTK_SORT_ASCENDING);
43 	gtk_combo_box_set_model(GTK_COMBO_BOX(widget), GTK_TREE_MODEL(store));
44 	g_object_unref(store);
45 
46 	for (i = 0; connection_name = gn_lib_get_supported_connection(i); i++) {
47 		connection_type = gn_get_connectiontype(connection_name);
48 
49 		gtk_tree_store_append (store, &iter, NULL);
50 		gtk_tree_store_set (store, &iter, COL_NAME, connection_name, COL_TYPE, connection_type, -1);
51 
52 		/* do not use the variable "i" because the combo is sorted
53 		  (also "i" doesn't correspond to GN_CT_* if some connection types aren't compiled in libgnokii
54 		  or if positions in libgnokii private array are changed) */
55 		if (connection_type == cfg->connection_type)
56 			gtk_combo_box_set_active_iter (GTK_COMBO_BOX(widget), &iter);
57 	}
58 
59 	widget = glade_xml_get_widget(prefs_xml, "model_entry");
60 	gtk_entry_set_text(GTK_ENTRY(widget), cfg->model);
61 
62 	widget = glade_xml_get_widget(prefs_xml, "port_entry");
63 	gtk_entry_set_text(GTK_ENTRY(widget), cfg->port_device);
64 
65 	/* disable OK and Apply because at this moment changes are ignored in any case */
66 	widget = glade_xml_get_widget(prefs_xml, "okbutton1");
67 	gtk_widget_set_sensitive(widget, FALSE);
68 	widget = glade_xml_get_widget(prefs_xml, "applybutton1");
69 	gtk_widget_set_sensitive(widget, FALSE);
70 
71 	gtk_window_set_transient_for(GTK_WINDOW (prefs), GTK_WINDOW (window));
72 	res = gtk_dialog_run(GTK_DIALOG(prefs));
73 
74 	gtk_widget_destroy(prefs);
75 	g_object_unref(G_OBJECT(prefs_xml));
76 
77 	return;
78 }
79