More callbacks, further GUI work

This commit is contained in:
Nils Faerber 2011-08-27 20:38:16 +02:00
parent d1e0ca32db
commit 44f70f5275
9 changed files with 699 additions and 91 deletions

View file

@ -4,7 +4,7 @@
# prefix for installation and search path (like icons)
PREFIX = /usr/local/
CFLAGS = -DDEBUG -Wall -O2 -Wl,--export-dynamic $(CCFLAGS) -I.. `pkg-config --cflags glib-2.0` `pkg-config --cflags dbus-glib-1` `pkg-config --cflags dbus-1` `pkg-config --cflags gtk+-2.0`
CFLAGS = -DDEBUG -g -Wall -O2 -Wl,--export-dynamic $(CCFLAGS) -I.. `pkg-config --cflags glib-2.0` `pkg-config --cflags dbus-glib-1` `pkg-config --cflags dbus-1` `pkg-config --cflags gtk+-2.0`
#CFLAGS = -Wall -O2 $(CCFLAGS)
LDFLAGS = `pkg-config --libs glib-2.0` `pkg-config --libs dbus-glib-1` `pkg-config --libs dbus-1` `pkg-config --libs gtk+-2.0` `pkg-config --libs gmodule-export-2.0` -L.. -lmetawatch

View file

@ -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;
}

View file

@ -194,7 +194,7 @@
<object class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_rows">3</property>
<property name="n_rows">2</property>
<property name="n_columns">3</property>
<child>
<object class="GtkVButtonBox" id="vbuttonbox1">
@ -296,52 +296,6 @@
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="notify_button">
<property name="label" translatable="yes">Notification</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="on_notify_button_clicked" swapped="no"/>
</object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="bitmap_button">
<property name="label" translatable="yes">Bitmap</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="on_bitmap_button_clicked" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="vibrate_button">
<property name="label" translatable="yes">Vibration</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="on_vibrate_button_clicked" swapped="no"/>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="rtc_button">
<property name="label" translatable="yes">RTC</property>
@ -354,11 +308,10 @@
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options"></property>
<property name="y_options"></property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkVBox" id="vbox2">
<property name="visible">True</property>
@ -408,6 +361,21 @@
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="info_button">
<property name="label">gtk-about</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_info_button_clicked" swapped="no"/>
</object>
<packing>
<property name="x_options"></property>
<property name="y_options"></property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
@ -415,6 +383,77 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHButtonBox" id="hbuttonbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton" id="notify_button">
<property name="label" translatable="yes">Notification</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="on_notify_button_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="bitmap_button">
<property name="label" translatable="yes">Bitmap</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="on_bitmap_button_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="vibrate_button">
<property name="label" translatable="yes">Vibration</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="on_vibrate_button_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="set_hands">
<property name="label" translatable="yes">Set Hands</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="on_set_hands_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkStatusbar" id="statusbar1">
<property name="visible">True</property>
@ -424,6 +463,353 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkWindow" id="notify_win">
<property name="can_focus">False</property>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<child>
<object class="GtkVBox" id="vbox3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="ypad">1</property>
<property name="label" translatable="yes">&lt;b&gt;Notification text&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<child>
<object class="GtkTextView" id="notify_textview">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHButtonBox" id="hbuttonbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton" id="notify_cancel">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_notify_cancel_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="notify_ok">
<property name="label">gtk-apply</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_notify_ok_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkVBox" id="vbox4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">&lt;b&gt;RTC&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTable" id="table3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_rows">2</property>
<property name="n_columns">4</property>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Date</property>
</object>
</child>
<child>
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Time</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="h12_radio">
<property name="label" translatable="yes">12h</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<property name="group">h24_radio</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="h24_radio">
<property name="label" translatable="yes">24h</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbox6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkCalendar" id="calendar1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="year">2011</property>
<property name="month">7</property>
<property name="day">21</property>
<property name="show_week_numbers">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Format</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="mmdd_radio">
<property name="label" translatable="yes">MM/DD</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<property name="group">ddmm_radio</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="ddmm_radio">
<property name="label" translatable="yes">DD.MM</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHButtonBox" id="hbuttonbox3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkVBox" id="vbox5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton" id="get_watch_rtc_button">
<property name="label" translatable="yes">Get RTC from
watch</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="get_sys_rtc_button">
<property name="label" translatable="yes">Get RTC from
System</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="set_rtc_button">
<property name="label" translatable="yes">Set RTC</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="rtc_ok_button">
<property name="label">gtk-apply</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>