More callbacks, further GUI work
This commit is contained in:
parent
d1e0ca32db
commit
44f70f5275
9 changed files with 699 additions and 91 deletions
|
@ -62,6 +62,38 @@ void mw_get_battery_voltage_response_cb(mwdevice_t *mwdevice, unsigned short *vo
|
|||
gtk_progress_bar_set_text(batbar, batstr);
|
||||
}
|
||||
|
||||
void on_notify_ok_clicked (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
GtkWidget *notify_win;
|
||||
GtkTextView *tview;
|
||||
GtkTextBuffer *tbuf;
|
||||
GtkTextIter siter, eiter;
|
||||
gchar *text;
|
||||
|
||||
tview = GTK_TEXT_VIEW (gtk_builder_get_object (mdata->builder, "notify_textview"));
|
||||
tbuf = gtk_text_view_get_buffer(tview);
|
||||
gtk_text_buffer_get_start_iter(tbuf, &siter);
|
||||
gtk_text_buffer_get_end_iter(tbuf, &eiter);
|
||||
|
||||
text = gtk_text_buffer_get_text(tbuf, &siter, &eiter, FALSE);
|
||||
|
||||
mw_do_notification(&mdata->mwdevice, "Notification", text, 2);
|
||||
|
||||
notify_win = GTK_WIDGET (gtk_builder_get_object (mdata->builder, "notify_win"));
|
||||
gtk_widget_hide (notify_win);
|
||||
}
|
||||
|
||||
void on_notify_cancel_clicked (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
GtkWidget *notify_win;
|
||||
|
||||
notify_win = GTK_WIDGET (gtk_builder_get_object (mdata->builder, "notify_win"));
|
||||
gtk_widget_hide (notify_win);
|
||||
}
|
||||
|
||||
|
||||
void on_rtc_button_clicked (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
|
@ -72,7 +104,10 @@ void on_rtc_button_clicked (GtkButton *button, gpointer user_data)
|
|||
void on_notify_button_clicked (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
GtkWidget *notify_win;
|
||||
|
||||
notify_win = GTK_WIDGET (gtk_builder_get_object (mdata->builder, "notify_win"));
|
||||
gtk_widget_show (notify_win);
|
||||
}
|
||||
|
||||
void bitmap_read(mwdevice_t *mwdevice, char *filename)
|
||||
|
@ -143,6 +178,28 @@ void bitmap_read(mwdevice_t *mwdevice, char *filename)
|
|||
free(bmapbuf);
|
||||
}
|
||||
|
||||
void on_vibrate_button_clicked (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
}
|
||||
|
||||
void on_set_hands_clicked (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
time_t mtime;
|
||||
struct tm mtm;
|
||||
unsigned short hour;
|
||||
|
||||
mtime = time(NULL);
|
||||
localtime_r(&mtime, &mtm);
|
||||
|
||||
hour = (unsigned char) mtm.tm_hour;
|
||||
if (hour > 12)
|
||||
hour -= 12;
|
||||
|
||||
mw_advance_watch_hands(&mdata->mwdevice, hour, (unsigned char) mtm.tm_min, (unsigned char) mtm.tm_sec);
|
||||
}
|
||||
|
||||
void on_bitmap_button_clicked (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
|
@ -163,6 +220,31 @@ void on_bitmap_button_clicked (GtkButton *button, gpointer user_data)
|
|||
gtk_widget_destroy(dialog);
|
||||
}
|
||||
|
||||
void setup_watchtype_gui(mwdata_t *mdata)
|
||||
{
|
||||
GtkWidget *w;
|
||||
|
||||
if (mdata->mwdevice.devtype == MW_DEVICE_TYPE_DIGITAL || mdata->mwdevice.devtype == MW_DEVICE_TYPE_DEVB_DIGI) {
|
||||
w = GTK_WIDGET (gtk_builder_get_object (mdata->builder, "set_hands"));
|
||||
gtk_widget_hide(w);
|
||||
}
|
||||
if (mdata->mwdevice.devtype == MW_DEVICE_TYPE_ANA_DIGI || mdata->mwdevice.devtype == MW_DEVICE_TYPE_DEVB_ANA_DIGI) {
|
||||
w = GTK_WIDGET (gtk_builder_get_object (mdata->builder, "F_button_label"));
|
||||
gtk_widget_hide(w);
|
||||
w = GTK_WIDGET (gtk_builder_get_object (mdata->builder, "E_button_label"));
|
||||
gtk_widget_hide(w);
|
||||
w = GTK_WIDGET (gtk_builder_get_object (mdata->builder, "D_button_label"));
|
||||
gtk_widget_hide(w);
|
||||
}
|
||||
}
|
||||
|
||||
void mw_get_device_type_response_cb(mwdevice_t *mwdevice, unsigned char devtype, void *user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
|
||||
setup_watchtype_gui(mdata);
|
||||
}
|
||||
|
||||
void mw_get_real_time_clock_response_cb(mwdevice_t *mwdevice, struct tm *mw_tm, void *user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
|
@ -182,7 +264,7 @@ gboolean handle_mw_io(GIOChannel *mw_io, GIOCondition condition, gpointer udata)
|
|||
int rcvd;
|
||||
int processed;
|
||||
|
||||
rcvd = read(mdata->mwdevice.mw_fd, mdata->rcvbuf+mdata->rcvbuf_pos, 64);
|
||||
rcvd = read(mdata->mwdevice.mw_fd, mdata->rcvbuf/*+mdata->rcvbuf_pos*/, 64);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "read %d bytes:\n", rcvd);
|
||||
#endif
|
||||
|
@ -211,9 +293,7 @@ on_window_destroy (GtkObject *object, gpointer user_data)
|
|||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GtkWidget *window;
|
||||
|
@ -269,6 +349,7 @@ main (int argc, char *argv[])
|
|||
|
||||
mw_init(&mdata.mwdevice, mw_fd);
|
||||
|
||||
mw_set_get_device_type_response_cb(&mdata.mwdevice, mw_get_device_type_response_cb, &mdata);
|
||||
mw_set_get_real_time_clock_response_cb(&mdata.mwdevice, mw_get_real_time_clock_response_cb, &mdata);
|
||||
mw_set_get_battery_voltage_response_cb(&mdata.mwdevice, mw_get_battery_voltage_response_cb, &mdata);
|
||||
|
||||
|
@ -276,7 +357,9 @@ main (int argc, char *argv[])
|
|||
|
||||
mdata.bat_timeout_id = g_timeout_add_seconds(10, battery_level_get_timeout, &mdata);
|
||||
|
||||
// setup_watchtype_gui(&mdata);
|
||||
gtk_main ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue