Prompt the user to log into Milk via the web page upon launch.
[milk] / src / milk-main-window.c
index d72b983..06d435e 100644 (file)
@@ -34,6 +34,8 @@ G_DEFINE_TYPE (MilkMainWindow, milk_main_window, HILDON_TYPE_WINDOW)
 /* less expensive than G_TYPE_INSTANCE_GET_PRIVATE */
 #define MILK_MAIN_WINDOW_PRIVATE(o) ((MILK_MAIN_WINDOW ((o)))->priv)
 
+static GtkWidget *default_window = NULL;
+
 struct _MilkMainWindowPrivate
 {
         MilkAuth *auth;
@@ -238,6 +240,25 @@ contact_column_render_func (GtkCellLayout   *cell_layout,
         g_object_unref (task);
 }
 
+static gboolean
+begin_auth_idle (MilkMainWindow *window)
+{
+        MilkMainWindowPrivate *priv;
+
+        priv = MILK_MAIN_WINDOW_PRIVATE (window);
+
+        /* FIXME: is there a better place for this? */
+        priv->auth = milk_auth_get_default ();
+        /* FIXME: plug this into the task model */
+
+        /* FIXME: cut this */
+        g_debug ("trying to run the milk auth demo");
+        /* FIXME: cut this */
+        milk_auth_run_demo (priv->auth);
+
+        return FALSE;
+}
+
 static void
 milk_main_window_constructed (GObject* object)
 {
@@ -306,14 +327,9 @@ milk_main_window_constructed (GObject* object)
         hildon_window_set_app_menu (
                         HILDON_WINDOW (self), HILDON_APP_MENU (priv->app_menu));
 
-        /* FIXME: is there a better place for this? */
-        priv->auth = milk_auth_get_default ();
-        /* FIXME: plug this into the task model */
-
-        /* FIXME: cut this */
-        g_debug ("trying to run the milk auth demo");
-        /* FIXME: cut this */
-        milk_auth_run_demo (priv->auth);
+        /* break a cyclical dependency by doing this after the window is
+         * constructed */
+        g_idle_add ((GSourceFunc) begin_auth_idle, self);
 }
 
 static void
@@ -337,8 +353,11 @@ milk_main_window_init (MilkMainWindow *self)
 }
 
 GtkWidget*
-milk_main_window_new ()
+milk_main_window_get_default ()
 {
-        return g_object_new (MILK_TYPE_MAIN_WINDOW,
-                             NULL);
+        if (!default_window) {
+                default_window = g_object_new (MILK_TYPE_MAIN_WINDOW, NULL);
+        }
+
+        return default_window;
 }