public
Description: A Clutter-based Twitter client
Homepage: http://live.gnome.org/Tweet
Clone URL: git://github.com/ebassi/tweet.git
Use NM-GLib to check for connection state changes

If we have a network connection at the beginning of our session,
start immediately by downloading the user timeline. If we don't
have one, wait until the state changes.

If Tweet was compiled without NetworkManager-GLib support, the
usual behaviour applies.
Emmanuele Bassi (author)
Tue Jun 03 11:34:39 -0700 2008
commit  70fce3a9d80e2ef761372b9a9a8735bf711337ab
tree    0bbfefb7a4c4272b1dbaf364720f910a55bdb380
parent  12acb74791bcf0e4b1fbb56e390a635fb8a48b37
...
27
28
29
 
 
 
 
30
31
32
...
92
93
94
 
 
 
 
 
95
96
97
...
132
133
134
 
 
 
 
 
 
 
 
 
135
136
137
...
474
475
476
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477
478
479
...
481
482
483
 
484
485
486
...
506
507
508
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
509
510
511
...
513
514
515
 
516
517
518
...
27
28
29
30
31
32
33
34
35
36
...
96
97
98
99
100
101
102
103
104
105
106
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
...
538
539
540
541
542
543
544
...
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
...
591
592
593
594
595
596
597
0
@@ -27,6 +27,10 @@
0
 
0
 #include <glib-object.h>
0
 
0
+#ifdef HAVE_NM_GLIB
0
+#include <libnm_glib.h>
0
+#endif
0
+
0
 #include <gtk/gtk.h>
0
 
0
 #include <clutter/clutter.h>
0
@@ -92,6 +96,11 @@ struct _TweetWindowPrivate
0
   guint refresh_id;
0
 
0
   TweetWindowMode mode;
0
+
0
+#ifdef HAVE_NM_GLIB
0
+ libnm_glib_ctx *nm_context;
0
+ guint nm_id;
0
+#endif
0
 };
0
 
0
 G_DEFINE_TYPE (TweetWindow, tweet_window, GTK_TYPE_WINDOW);
0
@@ -132,6 +141,15 @@ tweet_window_dispose (GObject *gobject)
0
       priv->action_group = NULL;
0
     }
0
 
0
+ if (priv->nm_id)
0
+ {
0
+ libnm_glib_unregister_callback (priv->nm_context, priv->nm_id);
0
+ libnm_glib_shutdown (priv->nm_context);
0
+
0
+ priv->nm_id = 0;
0
+ priv->nm_context = NULL;
0
+ }
0
+
0
   G_OBJECT_CLASS (tweet_window_parent_class)->dispose (gobject);
0
 }
0
 
0
@@ -474,6 +492,45 @@ refresh_timeout (gpointer data)
0
   return TRUE;
0
 }
0
 
0
+#ifdef HAVE_NM_GLIB
0
+static void
0
+nm_context_callback (libnm_glib_ctx *libnm_ctx,
0
+ gpointer user_data)
0
+{
0
+ TweetWindow *window = user_data;
0
+ TweetWindowPrivate *priv = window->priv;
0
+ libnm_glib_state nm_state;
0
+
0
+ nm_state = libnm_glib_get_network_state (libnm_ctx);
0
+ switch (nm_state)
0
+ {
0
+ case LIBNM_ACTIVE_NETWORK_CONNECTION:
0
+ twitter_client_get_user_timeline (priv->client, NULL, 0, NULL);
0
+
0
+ if (tweet_config_get_refresh_time (priv->config) > 0)
0
+ priv->refresh_id =
0
+ g_timeout_add_seconds (tweet_config_get_refresh_time (priv->config),
0
+ refresh_timeout,
0
+ window);
0
+ break;
0
+
0
+ case LIBNM_NO_DBUS:
0
+ case LIBNM_NO_NETWORKMANAGER:
0
+ g_critical ("No NetworkManager running");
0
+ break;
0
+
0
+ case LIBNM_NO_NETWORK_CONNECTION:
0
+ g_source_remove (priv->refresh_id);
0
+ priv->refresh_id = 0;
0
+ break;
0
+
0
+ case LIBNM_INVALID_CONTEXT:
0
+ g_critical ("Invalid NetworkManager-GLib context");
0
+ break;
0
+ }
0
+}
0
+#endif /* HAVE_NM_GLIB */
0
+
0
 static void
0
 tweet_window_constructed (GObject *gobject)
0
 {
0
@@ -481,6 +538,7 @@ tweet_window_constructed (GObject *gobject)
0
   TweetWindowPrivate *priv = window->priv;
0
   ClutterActor *stage;
0
   ClutterActor *img;
0
+ libnm_glib_state nm_state;
0
 
0
   stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->canvas));
0
 
0
@@ -506,6 +564,26 @@ tweet_window_constructed (GObject *gobject)
0
 
0
   gtk_widget_show_all (GTK_WIDGET (window));
0
 
0
+#ifdef HAVE_NM_GLIB
0
+ priv->nm_context = libnm_glib_init ();
0
+
0
+ nm_state = libnm_glib_get_network_state (priv->nm_context);
0
+ if (nm_state == LIBNM_ACTIVE_NETWORK_CONNECTION)
0
+ {
0
+ twitter_client_get_user_timeline (priv->client, NULL, 0, NULL);
0
+
0
+ if (tweet_config_get_refresh_time (priv->config) > 0)
0
+ priv->refresh_id =
0
+ g_timeout_add_seconds (tweet_config_get_refresh_time (priv->config),
0
+ refresh_timeout,
0
+ window);
0
+ }
0
+
0
+ priv->nm_id = libnm_glib_register_callback (priv->nm_context,
0
+ nm_context_callback,
0
+ window,
0
+ NULL);
0
+#else
0
   twitter_client_get_user_timeline (priv->client, NULL, 0, NULL);
0
 
0
   if (tweet_config_get_refresh_time (priv->config) > 0)
0
@@ -513,6 +591,7 @@ tweet_window_constructed (GObject *gobject)
0
       g_timeout_add_seconds (tweet_config_get_refresh_time (priv->config),
0
                              refresh_timeout,
0
                              window);
0
+#endif /* HAVE_NM_GLIB */
0
 }
0
 
0
 static void

Comments

    No one has commented yet.