diff options
Diffstat (limited to 'src/peerinfo/gnunet-peerinfo-gtk.c')
-rw-r--r-- | src/peerinfo/gnunet-peerinfo-gtk.c | 111 |
1 files changed, 76 insertions, 35 deletions
diff --git a/src/peerinfo/gnunet-peerinfo-gtk.c b/src/peerinfo/gnunet-peerinfo-gtk.c index 6d8569e8..85df3f3b 100644 --- a/src/peerinfo/gnunet-peerinfo-gtk.c +++ b/src/peerinfo/gnunet-peerinfo-gtk.c | |||
@@ -68,7 +68,17 @@ enum PEERINFO_ModelColumns | |||
68 | /** | 68 | /** |
69 | * A gchararray | 69 | * A gchararray |
70 | */ | 70 | */ |
71 | PEERINFO_MC_ADDRESS_AS_STRING = 6 | 71 | PEERINFO_MC_ADDRESS_AS_STRING = 6, |
72 | |||
73 | /** | ||
74 | * A GdkPixbuf | ||
75 | */ | ||
76 | PEERINFO_MC_CONNECTIVITY_LED = 7, | ||
77 | |||
78 | /** | ||
79 | * A gboolean | ||
80 | */ | ||
81 | PEERINFO_MC_CONNECTED_STATUS = 8 | ||
72 | }; | 82 | }; |
73 | 83 | ||
74 | 84 | ||
@@ -124,6 +134,22 @@ static struct GNUNET_CONTAINER_MultiHashMap *peer2info; | |||
124 | */ | 134 | */ |
125 | static int tray_only; | 135 | static int tray_only; |
126 | 136 | ||
137 | /** | ||
138 | * Green status led (connected) | ||
139 | */ | ||
140 | static GdkPixbuf *led_green; | ||
141 | |||
142 | /** | ||
143 | * Red status led (disconnected) | ||
144 | */ | ||
145 | static GdkPixbuf *led_red; | ||
146 | |||
147 | /** | ||
148 | * Main window list store. | ||
149 | */ | ||
150 | static GtkListStore *ls; | ||
151 | |||
152 | |||
127 | 153 | ||
128 | /** | 154 | /** |
129 | * Get cfg. | 155 | * Get cfg. |
@@ -212,19 +238,15 @@ static void | |||
212 | peer_address_string_cb (void *cls, const char *address) | 238 | peer_address_string_cb (void *cls, const char *address) |
213 | { | 239 | { |
214 | struct PeerInfo *info = cls; | 240 | struct PeerInfo *info = cls; |
215 | GtkListStore *ls; | ||
216 | GtkTreeModel *tm; | ||
217 | GtkTreeIter iter; | 241 | GtkTreeIter iter; |
218 | GtkTreePath *path; | 242 | GtkTreePath *path; |
219 | char *country; | 243 | char *country; |
220 | const char *colon; | 244 | const char *colon; |
221 | const char *dot; | 245 | const char *dot; |
222 | 246 | ||
223 | ls = GTK_LIST_STORE (get_object ("GNUNET_PEERINFO_GTK_list_store")); | ||
224 | tm = GTK_TREE_MODEL (ls); | ||
225 | path = gtk_tree_row_reference_get_path (info->rr); | 247 | path = gtk_tree_row_reference_get_path (info->rr); |
226 | GNUNET_assert (NULL != path); | 248 | GNUNET_assert (NULL != path); |
227 | GNUNET_assert (TRUE == gtk_tree_model_get_iter (tm, &iter, path)); | 249 | GNUNET_assert (TRUE == gtk_tree_model_get_iter (GTK_TREE_MODEL (ls), &iter, path)); |
228 | gtk_tree_path_free (path); | 250 | gtk_tree_path_free (path); |
229 | if (NULL == address) | 251 | if (NULL == address) |
230 | { | 252 | { |
@@ -235,6 +257,8 @@ peer_address_string_cb (void *cls, const char *address) | |||
235 | PEERINFO_MC_COUNTRY_NAME, NULL, | 257 | PEERINFO_MC_COUNTRY_NAME, NULL, |
236 | PEERINFO_MC_COUNTRY_FLAG, NULL, | 258 | PEERINFO_MC_COUNTRY_FLAG, NULL, |
237 | PEERINFO_MC_ADDRESS_AS_STRING, "<no address>", | 259 | PEERINFO_MC_ADDRESS_AS_STRING, "<no address>", |
260 | PEERINFO_MC_CONNECTIVITY_LED, led_green, | ||
261 | PEERINFO_MC_CONNECTED_STATUS, TRUE, | ||
238 | -1); | 262 | -1); |
239 | info->tos = NULL; | 263 | info->tos = NULL; |
240 | return; | 264 | return; |
@@ -255,6 +279,8 @@ peer_address_string_cb (void *cls, const char *address) | |||
255 | PEERINFO_MC_COUNTRY_NAME, country, | 279 | PEERINFO_MC_COUNTRY_NAME, country, |
256 | PEERINFO_MC_COUNTRY_FLAG, GNUNET_PEERINFO_GTK_get_flag (country), | 280 | PEERINFO_MC_COUNTRY_FLAG, GNUNET_PEERINFO_GTK_get_flag (country), |
257 | PEERINFO_MC_ADDRESS_AS_STRING, address, | 281 | PEERINFO_MC_ADDRESS_AS_STRING, address, |
282 | PEERINFO_MC_CONNECTIVITY_LED, led_green, | ||
283 | PEERINFO_MC_CONNECTED_STATUS, TRUE, | ||
258 | -1); | 284 | -1); |
259 | GNUNET_free (country); | 285 | GNUNET_free (country); |
260 | info->got_address = GNUNET_YES; | 286 | info->got_address = GNUNET_YES; |
@@ -273,28 +299,28 @@ peer_address_cb (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
273 | const struct GNUNET_HELLO_Address *address) | 299 | const struct GNUNET_HELLO_Address *address) |
274 | { | 300 | { |
275 | struct PeerInfo *info = cls; | 301 | struct PeerInfo *info = cls; |
276 | GtkListStore *ls; | ||
277 | GtkTreeModel *tm; | ||
278 | GtkTreeIter iter; | 302 | GtkTreeIter iter; |
279 | GtkTreePath *path; | 303 | GtkTreePath *path; |
280 | 304 | ||
305 | path = gtk_tree_row_reference_get_path (info->rr); | ||
306 | GNUNET_assert (NULL != path); | ||
307 | GNUNET_assert (TRUE == gtk_tree_model_get_iter (GTK_TREE_MODEL (ls), &iter, path)); | ||
308 | gtk_tree_path_free (path); | ||
281 | if (NULL == address) | 309 | if (NULL == address) |
282 | { | 310 | { |
283 | /* disconnect */ | 311 | /* disconnect */ |
284 | ls = GTK_LIST_STORE (get_object ("GNUNET_PEERINFO_GTK_list_store")); | ||
285 | tm = GTK_TREE_MODEL (ls); | ||
286 | path = gtk_tree_row_reference_get_path (info->rr); | ||
287 | GNUNET_assert (NULL != path); | ||
288 | GNUNET_assert (TRUE == gtk_tree_model_get_iter (tm, &iter, path)); | ||
289 | gtk_tree_path_free (path); | ||
290 | gtk_list_store_set (ls, &iter, | 312 | gtk_list_store_set (ls, &iter, |
291 | PEERINFO_MC_NUMBER_OF_ADDRESSES, (guint) 0, | 313 | PEERINFO_MC_NUMBER_OF_ADDRESSES, (guint) 0, |
292 | PEERINFO_MC_COUNTRY_NAME, NULL, | 314 | PEERINFO_MC_CONNECTIVITY_LED, led_red, |
293 | PEERINFO_MC_COUNTRY_FLAG, NULL, | 315 | PEERINFO_MC_CONNECTED_STATUS, FALSE, |
294 | PEERINFO_MC_ADDRESS_AS_STRING, "<disconnected>", | ||
295 | -1); | 316 | -1); |
296 | return; | 317 | return; |
297 | } | 318 | } |
319 | gtk_list_store_set (ls, &iter, | ||
320 | PEERINFO_MC_NUMBER_OF_ADDRESSES, 1, | ||
321 | PEERINFO_MC_CONNECTIVITY_LED, led_green, | ||
322 | PEERINFO_MC_CONNECTED_STATUS, TRUE, | ||
323 | -1); | ||
298 | if (NULL != info->tos) | 324 | if (NULL != info->tos) |
299 | GNUNET_TRANSPORT_address_to_string_cancel (info->tos); | 325 | GNUNET_TRANSPORT_address_to_string_cancel (info->tos); |
300 | info->got_address = GNUNET_NO; | 326 | info->got_address = GNUNET_NO; |
@@ -319,21 +345,12 @@ peerinfo_processor (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
319 | const struct GNUNET_HELLO_Message *hello, | 345 | const struct GNUNET_HELLO_Message *hello, |
320 | const char *err_msg) | 346 | const char *err_msg) |
321 | { | 347 | { |
322 | GtkListStore *ls; | ||
323 | GtkTreeModel *tm; | ||
324 | GtkTreeIter iter; | 348 | GtkTreeIter iter; |
325 | char *npid; | 349 | char *npid; |
326 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; | 350 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; |
327 | struct PeerInfo *info; | 351 | struct PeerInfo *info; |
328 | GtkTreePath *path; | 352 | GtkTreePath *path; |
329 | 353 | ||
330 | ls = GTK_LIST_STORE (get_object ("GNUNET_PEERINFO_GTK_list_store")); | ||
331 | if (NULL == ls) | ||
332 | { | ||
333 | GNUNET_break (0); | ||
334 | return; | ||
335 | } | ||
336 | tm = GTK_TREE_MODEL (ls); | ||
337 | info = GNUNET_CONTAINER_multihashmap_get (peer2info, &peer->hashPubKey); | 354 | info = GNUNET_CONTAINER_multihashmap_get (peer2info, &peer->hashPubKey); |
338 | if (NULL == info) | 355 | if (NULL == info) |
339 | { | 356 | { |
@@ -348,11 +365,13 @@ peerinfo_processor (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
348 | PEERINFO_MC_COUNTRY_FLAG, NULL, | 365 | PEERINFO_MC_COUNTRY_FLAG, NULL, |
349 | PEERINFO_MC_BANDWIDTH_IN, (guint64) 0, | 366 | PEERINFO_MC_BANDWIDTH_IN, (guint64) 0, |
350 | PEERINFO_MC_BANDWIDTH_OUT, (guint64) 0, | 367 | PEERINFO_MC_BANDWIDTH_OUT, (guint64) 0, |
351 | PEERINFO_MC_ADDRESS_AS_STRING, "<disconnected>", | 368 | PEERINFO_MC_ADDRESS_AS_STRING, "", |
369 | PEERINFO_MC_CONNECTIVITY_LED, led_red, | ||
370 | PEERINFO_MC_CONNECTED_STATUS, FALSE, | ||
352 | -1); | 371 | -1); |
353 | path = gtk_tree_model_get_path (tm, &iter); | 372 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (ls), &iter); |
354 | info = GNUNET_malloc (sizeof (struct PeerInfo)); | 373 | info = GNUNET_malloc (sizeof (struct PeerInfo)); |
355 | info->rr = gtk_tree_row_reference_new (tm, path); | 374 | info->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ls), path); |
356 | GNUNET_assert (NULL != info->rr); | 375 | GNUNET_assert (NULL != info->rr); |
357 | gtk_tree_path_free (path); | 376 | gtk_tree_path_free (path); |
358 | GNUNET_CONTAINER_multihashmap_put (peer2info, &peer->hashPubKey, info, | 377 | GNUNET_CONTAINER_multihashmap_put (peer2info, &peer->hashPubKey, info, |
@@ -388,19 +407,15 @@ status_cb (void *cls, | |||
388 | uint32_t ats_count) | 407 | uint32_t ats_count) |
389 | { | 408 | { |
390 | struct PeerInfo *info; | 409 | struct PeerInfo *info; |
391 | GtkListStore *ls; | ||
392 | GtkTreeModel *tm; | ||
393 | GtkTreeIter iter; | 410 | GtkTreeIter iter; |
394 | GtkTreePath *path; | 411 | GtkTreePath *path; |
395 | 412 | ||
396 | info = GNUNET_CONTAINER_multihashmap_get (peer2info, &address->peer.hashPubKey); | 413 | info = GNUNET_CONTAINER_multihashmap_get (peer2info, &address->peer.hashPubKey); |
397 | if (NULL == info) | 414 | if (NULL == info) |
398 | return; /* should rarely happen... */ | 415 | return; /* should rarely happen... */ |
399 | ls = GTK_LIST_STORE (get_object ("GNUNET_PEERINFO_GTK_list_store")); | ||
400 | tm = GTK_TREE_MODEL (ls); | ||
401 | path = gtk_tree_row_reference_get_path (info->rr); | 416 | path = gtk_tree_row_reference_get_path (info->rr); |
402 | GNUNET_assert (NULL != path); | 417 | GNUNET_assert (NULL != path); |
403 | GNUNET_assert (TRUE == gtk_tree_model_get_iter (tm, &iter, path)); | 418 | GNUNET_assert (TRUE == gtk_tree_model_get_iter (GTK_TREE_MODEL (ls), &iter, path)); |
404 | gtk_tree_path_free (path); | 419 | gtk_tree_path_free (path); |
405 | gtk_list_store_set (ls, &iter, | 420 | gtk_list_store_set (ls, &iter, |
406 | PEERINFO_MC_BANDWIDTH_IN, (guint64) ntohl (bandwidth_in.value__), | 421 | PEERINFO_MC_BANDWIDTH_IN, (guint64) ntohl (bandwidth_in.value__), |
@@ -425,6 +440,29 @@ GNUNET_PEERINFO_GTK_quit_cb (GObject * object, gpointer user_data) | |||
425 | 440 | ||
426 | 441 | ||
427 | /** | 442 | /** |
443 | * Load LED image from resource file. | ||
444 | * | ||
445 | * @param color color of the LED to load | ||
446 | * @return the image as a GdkPixbuf | ||
447 | */ | ||
448 | static GdkPixbuf * | ||
449 | load_led (const char *color) | ||
450 | { | ||
451 | GdkPixbuf *pixbuf; | ||
452 | char *dir; | ||
453 | char *fn; | ||
454 | |||
455 | dir = GNUNET_GTK_installation_get_path (GNUNET_OS_IPK_DATADIR); | ||
456 | GNUNET_asprintf (&fn, "%s%s.png", dir, | ||
457 | color); | ||
458 | GNUNET_free (dir); | ||
459 | pixbuf = gdk_pixbuf_new_from_file (fn, NULL); | ||
460 | GNUNET_free (fn); | ||
461 | return pixbuf; | ||
462 | } | ||
463 | |||
464 | |||
465 | /** | ||
428 | * Actual main function run right after GNUnet's scheduler | 466 | * Actual main function run right after GNUnet's scheduler |
429 | * is initialized. Initializes up GTK and Glade. | 467 | * is initialized. Initializes up GTK and Glade. |
430 | * | 468 | * |
@@ -442,7 +480,8 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
442 | { | 480 | { |
443 | return; | 481 | return; |
444 | } | 482 | } |
445 | 483 | led_green = load_led ("green"); | |
484 | led_red = load_led ("red"); | ||
446 | GNUNET_GTK_set_icon_search_path (); | 485 | GNUNET_GTK_set_icon_search_path (); |
447 | GNUNET_GTK_setup_nls (); | 486 | GNUNET_GTK_setup_nls (); |
448 | peer2info = GNUNET_CONTAINER_multihashmap_create (256); | 487 | peer2info = GNUNET_CONTAINER_multihashmap_create (256); |
@@ -457,6 +496,8 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
457 | ats = GNUNET_ATS_performance_init (get_configuration (), &status_cb, NULL); | 496 | ats = GNUNET_ATS_performance_init (get_configuration (), &status_cb, NULL); |
458 | /* setup main window */ | 497 | /* setup main window */ |
459 | main_window = GTK_WIDGET (get_object ("GNUNET_PEERINFO_GTK_main_window")); | 498 | main_window = GTK_WIDGET (get_object ("GNUNET_PEERINFO_GTK_main_window")); |
499 | ls = GTK_LIST_STORE (get_object ("GNUNET_PEERINFO_GTK_list_store")); | ||
500 | GNUNET_assert (NULL != ls); | ||
460 | gtk_window_maximize (GTK_WINDOW (main_window)); | 501 | gtk_window_maximize (GTK_WINDOW (main_window)); |
461 | GNUNET_GTK_tray_icon_create (GTK_WINDOW (main_window), | 502 | GNUNET_GTK_tray_icon_create (GTK_WINDOW (main_window), |
462 | "gnunet-gtk" /* FIXME: different icon? */ , | 503 | "gnunet-gtk" /* FIXME: different icon? */ , |