2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 aoview_dev_dialog_map(GtkWidget *widget, gpointer data)
23 GtkTreeView *dev_list = data;
24 GtkListStore *list_store;
29 list_store = gtk_list_store_new(3,
34 ndev = aoview_usb_scan(&devs);
35 for (n = 0; n < ndev; n++) {
36 gtk_list_store_append(list_store, &iter);
37 gtk_list_store_set(list_store, &iter,
43 gtk_tree_view_set_model (dev_list, GTK_TREE_MODEL(list_store));
44 g_object_unref(G_OBJECT(list_store));
45 gtk_tree_view_columns_autosize(dev_list);
48 static GtkMessageDialog *dev_open_fail_dialog;
51 aoview_dev_open_failed(char *name)
54 utf8_file = g_filename_to_utf8(name, -1, NULL, NULL, NULL);
57 gtk_message_dialog_format_secondary_text(dev_open_fail_dialog,
59 if (utf8_file != name)
61 gtk_dialog_run(GTK_DIALOG(dev_open_fail_dialog));
62 gtk_widget_hide(GTK_WIDGET(dev_open_fail_dialog));
65 gboolean dialog_save_log;
68 aoview_dev_selected(GtkTreeModel *model,
74 gtk_tree_model_get(model, iter,
77 if (dialog_save_log) {
78 dialog_save_log = FALSE;
79 if (!aoview_eeprom_save(string))
80 aoview_dev_open_failed(string);
82 if (!aoview_monitor_connect(string))
83 aoview_dev_open_failed(string);
87 static GtkWidget *dialog;
90 aoview_dev_dialog_connect(GtkWidget *widget, gpointer data)
92 GtkTreeView *dev_list = data;
93 GtkListStore *list_store;
94 GtkTreeSelection *tree_selection;
96 list_store = GTK_LIST_STORE(gtk_tree_view_get_model(dev_list));
97 tree_selection = gtk_tree_view_get_selection(dev_list);
98 gtk_tree_selection_selected_foreach(tree_selection,
101 gtk_widget_hide(dialog);
105 aoview_dev_disconnect(GtkWidget *widget)
107 aoview_monitor_disconnect();
111 aoview_dev_savelog(GtkWidget *widget, gpointer data)
113 dialog_save_log = TRUE;
114 gtk_widget_show(dialog);
120 aoview_dev_dialog_init(GladeXML *xml)
122 GtkTreeView *dev_list;
123 GtkWidget *connect_button;
124 GtkTreeSelection *dev_selection;
125 GtkWidget *ao_disconnect;
126 GtkWidget *ao_savelog;
128 dialog = glade_xml_get_widget(xml, "device_connect_dialog");
131 dev_list = GTK_TREE_VIEW(glade_xml_get_widget(xml, "dev_list"));
134 aoview_add_plain_text_column(dev_list, _("Product"), 0, 16);
135 aoview_add_plain_text_column(dev_list, _("Serial"), 1, 8);
136 aoview_add_plain_text_column(dev_list, _("Device"), 2, 13);
138 dev_selection = gtk_tree_view_get_selection(dev_list);
139 gtk_tree_selection_set_mode(dev_selection, GTK_SELECTION_SINGLE);
141 g_signal_connect(G_OBJECT(dialog), "map",
142 G_CALLBACK(aoview_dev_dialog_map),
145 connect_button = glade_xml_get_widget(xml, "connect_button");
146 assert(connect_button);
148 g_signal_connect(G_OBJECT(connect_button), "clicked",
149 G_CALLBACK(aoview_dev_dialog_connect),
153 ao_disconnect = glade_xml_get_widget(xml, "ao_disconnect");
154 assert(ao_disconnect);
156 g_signal_connect(G_OBJECT(ao_disconnect), "activate",
157 G_CALLBACK(aoview_dev_disconnect),
160 ao_savelog = glade_xml_get_widget(xml, "ao_savelog");
163 g_signal_connect(G_OBJECT(ao_savelog), "activate",
164 G_CALLBACK(aoview_dev_savelog),
166 dev_open_fail_dialog = GTK_MESSAGE_DIALOG(glade_xml_get_widget(xml, "dev_open_fail_dialog"));
167 assert(dev_open_fail_dialog);