</widget>
<widget class="GtkMessageDialog" id="log_fail_dialog">
<property name="border_width">5</property>
- <property name="type">popup</property>
+ <property name="title" translatable="yes">Failed to create log</property>
<property name="type_hint">normal</property>
<property name="skip_taskbar_hint">True</property>
+ <property name="transient_for">aoview</property>
<property name="message_type">error</property>
<property name="buttons">close</property>
<property name="text">Cannot create log file</property>
</widget>
</child>
</widget>
+ <widget class="GtkMessageDialog" id="dev_open_fail_dialog">
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Failed to open device</property>
+ <property name="type_hint">normal</property>
+ <property name="skip_taskbar_hint">True</property>
+ <property name="transient_for">aoview</property>
+ <property name="message_type">error</property>
+ <property name="buttons">close</property>
+ <property name="text">Cannot open device</property>
+ <child internal-child="vbox">
+ <widget class="GtkVBox" id="dialog-vbox6">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <widget class="GtkHButtonBox" id="dialog-action_area6">
+ <property name="visible">True</property>
+ <property name="layout_style">end</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+ </widget>
</glade-interface>
void
aoview_monitor_disconnect(void);
-void
+gboolean
aoview_monitor_connect(char *tty);
struct aoview_serial *
void
aoview_serial_close(struct aoview_serial *serial);
+typedef void (*aoview_serial_callback)(gpointer user_data, struct aoview_serial *serial, gint revents);
+
void
aoview_serial_set_callback(struct aoview_serial *serial,
- GSourceFunc func,
+ aoview_serial_callback func,
gpointer data,
GDestroyNotify notify);
gtk_tree_view_columns_autosize(dev_list);
}
+static GtkMessageDialog *dev_open_fail_dialog;
+
+static void
+aoview_dev_open_failed(char *name)
+{
+ char *utf8_file;
+ utf8_file = g_filename_to_utf8(name, -1, NULL, NULL, NULL);
+ if (!utf8_file)
+ utf8_file = name;
+ gtk_message_dialog_format_secondary_text(dev_open_fail_dialog,
+ "\"%s\"", utf8_file);
+ if (utf8_file != name)
+ g_free(utf8_file);
+ gtk_dialog_run(GTK_DIALOG(dev_open_fail_dialog));
+ gtk_widget_hide(GTK_WIDGET(dev_open_fail_dialog));
+}
+
static void
aoview_dev_selected(GtkTreeModel *model,
GtkTreePath *path,
gtk_tree_model_get(model, iter,
2, &string,
-1);
- aoview_monitor_connect(string);
+ if (!aoview_monitor_connect(string))
+ aoview_dev_open_failed(string);
}
static GtkWidget *dialog;
g_signal_connect(G_OBJECT(ao_disconnect), "activate",
G_CALLBACK(aoview_dev_disconnect),
ao_disconnect);
+
+ dev_open_fail_dialog = GTK_MESSAGE_DIALOG(glade_xml_get_widget(xml, "dev_open_fail_dialog"));
+ assert(dev_open_fail_dialog);
}
"\"%s\"", utf8_file);
if (utf8_file != name)
g_free(utf8_file);
- gtk_widget_show(GTK_WIDGET(log_fail_dialog));
+ gtk_dialog_run(GTK_DIALOG(log_fail_dialog));
+ gtk_widget_hide(GTK_WIDGET(log_fail_dialog));
aoview_log_failed = 1;
}
aoview_state_notify(&state);
}
-static gboolean
-aoview_monitor_callback(void *user_data)
+static void
+aoview_monitor_callback(gpointer user_data,
+ struct aoview_serial *serial,
+ gint revents)
{
int c;
- if (!monitor_serial)
- return FALSE;
-
- for (;;) {
- c = aoview_serial_getc(monitor_serial);
- if (c == -1)
- break;
- if (c == '\r')
- continue;
- if (c == '\n') {
- monitor_line[monitor_pos] = '\0';
- if (monitor_pos)
- aoview_monitor_parse(monitor_line);
- monitor_pos = 0;
- } else if (monitor_pos < MONITOR_LEN)
- monitor_line[monitor_pos++] = c;
+ if (revents & (G_IO_HUP|G_IO_ERR)) {
+ aoview_monitor_disconnect();
+ return;
+ }
+ if (revents & G_IO_IN) {
+ for (;;) {
+ c = aoview_serial_getc(serial);
+ if (c == -1)
+ break;
+ if (c == '\r')
+ continue;
+ if (c == '\n') {
+ monitor_line[monitor_pos] = '\0';
+ if (monitor_pos)
+ aoview_monitor_parse(monitor_line);
+ monitor_pos = 0;
+ } else if (monitor_pos < MONITOR_LEN)
+ monitor_line[monitor_pos++] = c;
+ }
}
- return TRUE;
}
-void
+gboolean
aoview_monitor_connect(char *tty)
{
aoview_monitor_disconnect();
monitor_serial = aoview_serial_open(tty);
+ if (!monitor_serial)
+ return FALSE;
aoview_serial_set_callback(monitor_serial,
aoview_monitor_callback,
monitor_serial,
NULL);
+ return TRUE;
}
gpointer user_data)
{
struct aoview_serial *serial = (struct aoview_serial *) source;
+ aoview_serial_callback func = (aoview_serial_callback) callback;
gint revents = serial->poll_fd.revents;
if (revents & G_IO_IN)
if (revents & G_IO_OUT)
aoview_buf_flush(&serial->out_buf, serial->fd);
- if (callback && (revents & G_IO_IN))
- (*callback)(user_data);
+ if (func)
+ (*func)(user_data, serial, revents);
return TRUE;
}
void
aoview_serial_set_callback(struct aoview_serial *serial,
- GSourceFunc func,
+ aoview_serial_callback func,
gpointer data,
GDestroyNotify notify)
{
- g_source_set_callback(&serial->source, func, data, notify);
+ g_source_set_callback(&serial->source, (GSourceFunc) func, data, notify);
}