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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 aoview_dev_dialog_map(GtkWidget *widget, gpointer data)
24 GtkTreeView *dev_list = data;
25 GtkListStore *list_store;
28 struct cc_usbdevs *devs;
29 struct cc_usbdev *dev;
31 list_store = gtk_list_store_new(3,
36 devs = cc_usbdevs_scan();
38 for (n = 0; n < devs->ndev; n++) {
40 gtk_list_store_append(list_store, &iter);
41 gtk_list_store_set(list_store, &iter,
48 gtk_tree_view_set_model (dev_list, GTK_TREE_MODEL(list_store));
49 g_object_unref(G_OBJECT(list_store));
50 gtk_tree_view_columns_autosize(dev_list);
51 cc_usbdevs_free(devs);
54 static GtkMessageDialog *dev_open_fail_dialog;
57 aoview_dev_open_failed(char *name)
60 utf8_file = g_filename_to_utf8(name, -1, NULL, NULL, NULL);
63 gtk_message_dialog_format_secondary_text(dev_open_fail_dialog,
65 if (utf8_file != name)
67 gtk_dialog_run(GTK_DIALOG(dev_open_fail_dialog));
68 gtk_widget_hide(GTK_WIDGET(dev_open_fail_dialog));
71 gboolean dialog_save_log;
74 aoview_dev_selected(GtkTreeModel *model,
80 gtk_tree_model_get(model, iter,
83 if (dialog_save_log) {
84 dialog_save_log = FALSE;
85 if (!aoview_eeprom_save(string))
86 aoview_dev_open_failed(string);
88 if (!aoview_monitor_connect(string))
89 aoview_dev_open_failed(string);
93 static GtkWidget *dialog;
96 aoview_dev_dialog_connect(GtkWidget *widget, gpointer data)
98 GtkTreeView *dev_list = data;
99 GtkListStore *list_store;
100 GtkTreeSelection *tree_selection;
102 list_store = GTK_LIST_STORE(gtk_tree_view_get_model(dev_list));
103 tree_selection = gtk_tree_view_get_selection(dev_list);
104 gtk_tree_selection_selected_foreach(tree_selection,
107 gtk_widget_hide(dialog);
111 aoview_dev_disconnect(GtkWidget *widget)
113 aoview_monitor_disconnect();
117 aoview_dev_savelog(GtkWidget *widget, gpointer data)
119 dialog_save_log = TRUE;
120 gtk_widget_show(dialog);
126 aoview_dev_dialog_init(GladeXML *xml)
128 GtkTreeView *dev_list;
129 GtkWidget *connect_button;
130 GtkTreeSelection *dev_selection;
131 GtkWidget *ao_disconnect;
132 GtkWidget *ao_savelog;
134 dialog = glade_xml_get_widget(xml, "device_connect_dialog");
137 dev_list = GTK_TREE_VIEW(glade_xml_get_widget(xml, "dev_list"));
140 aoview_add_plain_text_column(dev_list, _("Product"), 0, 16);
141 aoview_add_plain_text_column(dev_list, _("Serial"), 1, 8);
142 aoview_add_plain_text_column(dev_list, _("Device"), 2, 13);
144 dev_selection = gtk_tree_view_get_selection(dev_list);
145 gtk_tree_selection_set_mode(dev_selection, GTK_SELECTION_SINGLE);
147 g_signal_connect(G_OBJECT(dialog), "map",
148 G_CALLBACK(aoview_dev_dialog_map),
151 connect_button = glade_xml_get_widget(xml, "connect_button");
152 assert(connect_button);
154 g_signal_connect(G_OBJECT(connect_button), "clicked",
155 G_CALLBACK(aoview_dev_dialog_connect),
159 ao_disconnect = glade_xml_get_widget(xml, "ao_disconnect");
160 assert(ao_disconnect);
162 g_signal_connect(G_OBJECT(ao_disconnect), "activate",
163 G_CALLBACK(aoview_dev_disconnect),
166 ao_savelog = glade_xml_get_widget(xml, "ao_savelog");
169 g_signal_connect(G_OBJECT(ao_savelog), "activate",
170 G_CALLBACK(aoview_dev_savelog),
172 dev_open_fail_dialog = GTK_MESSAGE_DIALOG(glade_xml_get_widget(xml, "dev_open_fail_dialog"));
173 assert(dev_open_fail_dialog);