diff options
author | Ross Burton <ross@linux.intel.com> | 2010-02-19 16:36:15 +0000 |
---|---|---|
committer | Ross Burton <ross@linux.intel.com> | 2010-04-15 16:39:55 +0100 |
commit | 997b186fd1b07c27b3b8c5f9ece33c91179c03c0 (patch) | |
tree | 1b7f7d72c8ec0dda81a4fda9d3c09cf222a58c3c /moblin | |
parent | 8d7355ab648b4558466bbcd9ededd2e37420a84b (diff) | |
download | gnome-bluetooth-997b186fd1b07c27b3b8c5f9ece33c91179c03c0.tar.gz |
Make the host discoverable for two minutes when opening the panel
Diffstat (limited to 'moblin')
-rw-r--r-- | moblin/main.c | 17 | ||||
-rw-r--r-- | moblin/moblin-panel.c | 68 | ||||
-rw-r--r-- | moblin/moblin-panel.h | 5 |
3 files changed, 83 insertions, 7 deletions
diff --git a/moblin/main.c b/moblin/main.c index 0531c3bb..dc88768d 100644 --- a/moblin/main.c +++ b/moblin/main.c @@ -65,11 +65,19 @@ panel_request_focus (MoblinPanel *panel, gpointer user_data) * i.e. stop any discovery and show the defaults devices view */ static void -_reset_view_cb (MplPanelClient *client, gpointer user_data) +panel_hidden_cb (MplPanelClient *client, gpointer user_data) { MoblinPanel *panel = MOBLIN_PANEL (user_data); - moblin_panel_reset_view (panel); + moblin_panel_hidden (panel); +} + +static void +panel_shown_cb (MplPanelClient *client, gpointer user_data) +{ + MoblinPanel *panel = MOBLIN_PANEL (user_data); + + moblin_panel_shown (panel); } int @@ -118,6 +126,8 @@ main (int argc, char *argv[]) gtk_container_add (GTK_CONTAINER (window), content); gtk_widget_show (window); + + moblin_panel_shown (MOBLIN_PANEL (content)); } else { panel = mpl_panel_gtk_new (MPL_PANEL_BLUETOOTH, _("bluetooth"), THEME_DIR "/bluetooth-panel.css", @@ -125,7 +135,8 @@ main (int argc, char *argv[]) window = mpl_panel_gtk_get_window (MPL_PANEL_GTK (panel)); content = moblin_panel_new (); - g_signal_connect (panel, "hide-end", (GCallback) _reset_view_cb, content); + g_signal_connect (panel, "show", (GCallback) panel_shown_cb, content); + g_signal_connect (panel, "hide-end", (GCallback) panel_hidden_cb, content); g_signal_connect (content, "state-changed", G_CALLBACK (bluetooth_status_changed), panel); g_signal_connect (content, "request-focus", diff --git a/moblin/moblin-panel.c b/moblin/moblin-panel.c index 1863842d..58634d99 100644 --- a/moblin/moblin-panel.c +++ b/moblin/moblin-panel.c @@ -66,6 +66,9 @@ struct _MoblinPanelPrivate /* Page widgets that need to be "globally" accessible */ GtkWidget *power_switch; + guint visible_countdown; /* seconds */ + GtkWidget *visible_label; + GtkWidget *visible_button; GtkWidget *notebook; GtkWidget *label_pin_help; GtkWidget *label_pin; @@ -154,6 +157,52 @@ power_switch_toggled_cb (MxGtkLightSwitch *light_switch, } } +static gboolean +update_visible (gpointer data) +{ + MoblinPanel *panel = MOBLIN_PANEL (data); + MoblinPanelPrivate *priv = MOBLIN_PANEL_GET_PRIVATE (panel); + char *s; + + if (priv->visible_countdown -= 5) { + gtk_widget_hide (priv->visible_button); + gtk_widget_show (priv->visible_label); + + /* TODO: better display formatting */ + s = g_strdup_printf (_("Your computer is visible on Bluetooth for %d seconds."), + priv->visible_countdown); + gtk_label_set_text (GTK_LABEL (priv->visible_label), s); + g_free (s); + return TRUE; + } else { + bluetooth_client_set_discoverable (priv->client, FALSE); + + gtk_widget_show (priv->visible_button); + gtk_widget_hide (priv->visible_label); + + return FALSE; + } +} + +static void +make_discoverable (MoblinPanel *panel) +{ + MoblinPanelPrivate *priv = MOBLIN_PANEL_GET_PRIVATE (panel); + + bluetooth_client_set_discoverable (priv->client, TRUE); + + priv->visible_countdown = 60 * 2; /* 2 minutes */ + + update_visible (panel); + g_timeout_add_seconds (5, update_visible, panel); +} + +static void +visible_button_cb (GtkButton *button, gpointer user_data) +{ + make_discoverable (MOBLIN_PANEL (user_data)); +} + static void enable_send_file (MoblinPanel *self) { @@ -1463,6 +1512,14 @@ create_devices_page (MoblinPanel *self) gtk_widget_show (priv->power_switch); gtk_box_pack_start (GTK_BOX (hbox), priv->power_switch, FALSE, FALSE, 4); + priv->visible_label = gtk_label_new (NULL); + gtk_label_set_line_wrap (GTK_LABEL (priv->visible_label), TRUE); + gtk_box_pack_start (GTK_BOX (vbox), priv->visible_label, FALSE, FALSE, 4); + + priv->visible_button = gtk_button_new_with_label (_("Make visible on Bluetooth")); + g_signal_connect (priv->visible_button, "clicked", G_CALLBACK (visible_button_cb), self); + gtk_box_pack_start (GTK_BOX (vbox), priv->visible_button, FALSE, FALSE, 4); + /* Button for Send file */ priv->send_button = gtk_button_new_with_label (_("Send file from your computer")); gtk_widget_show (priv->send_button); @@ -1677,12 +1734,19 @@ moblin_panel_new (void) /** * - * moblin_panel_reset_view: + * moblin_panel_hidden: * * @self: A #MoblinPanel widget **/ void -moblin_panel_reset_view (MoblinPanel *self) +moblin_panel_hidden (MoblinPanel *self) +{ + set_current_page (self, PAGE_DEVICES); +} + +void +moblin_panel_shown (MoblinPanel *self) { set_current_page (self, PAGE_DEVICES); + make_discoverable (self); } diff --git a/moblin/moblin-panel.h b/moblin/moblin-panel.h index d273e79b..c688312b 100644 --- a/moblin/moblin-panel.h +++ b/moblin/moblin-panel.h @@ -62,7 +62,6 @@ struct _MoblinPanel struct _MoblinPanelClass { GtkHBoxClass parent_class; - MoblinPanelPrivate *priv; void (*status_connecting) (MoblinPanel *self, gboolean connecting); }; @@ -71,7 +70,9 @@ GType moblin_panel_get_type (void); GtkWidget *moblin_panel_new (void); -void moblin_panel_reset_view (MoblinPanel *self); +void moblin_panel_shown (MoblinPanel *self); + +void moblin_panel_hidden (MoblinPanel *self); G_END_DECLS |