diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-21 13:24:58 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-21 13:24:58 +0000 |
commit | 526656d4ae436ab751b92ecdffe5beacfa44cf3a (patch) | |
tree | a603edbae545db615561fc703d05048d3791488f | |
parent | 0dcc525572b266218108e0aa8579138e34ed992e (diff) | |
download | gnunet-gtk-526656d4ae436ab751b92ecdffe5beacfa44cf3a.tar.gz gnunet-gtk-526656d4ae436ab751b92ecdffe5beacfa44cf3a.zip |
- expiration time
-rw-r--r-- | src/gns/gnunet-gns-gtk.c | 1 | ||||
-rw-r--r-- | src/gns/gnunet-gns-gtk.h | 1 | ||||
-rw-r--r-- | src/gns/gnunet-gns-gtk_zone.c | 155 |
3 files changed, 151 insertions, 6 deletions
diff --git a/src/gns/gnunet-gns-gtk.c b/src/gns/gnunet-gns-gtk.c index dbcdaa76..f1fdeac4 100644 --- a/src/gns/gnunet-gns-gtk.c +++ b/src/gns/gnunet-gns-gtk.c | |||
@@ -434,6 +434,7 @@ namestore_service_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *t | |||
434 | gns->main_window = GTK_WIDGET (get_object ("GNUNET_GNS_GTK_main_window")); | 434 | gns->main_window = GTK_WIDGET (get_object ("GNUNET_GNS_GTK_main_window")); |
435 | gns->ts = GTK_TREE_STORE (gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_treestore")); | 435 | gns->ts = GTK_TREE_STORE (gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_treestore")); |
436 | gns->ls = GTK_LIST_STORE (gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_type_liststore")); | 436 | gns->ls = GTK_LIST_STORE (gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_type_liststore")); |
437 | gns->tm = GTK_TREE_MODEL(gns->ts); | ||
437 | gns->shorten_menu = GTK_CHECK_MENU_ITEM(gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_autoshort_imagemenuitem")); | 438 | gns->shorten_menu = GTK_CHECK_MENU_ITEM(gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_autoshort_imagemenuitem")); |
438 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (get_configuration (), | 439 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (get_configuration (), |
439 | "gns", | 440 | "gns", |
diff --git a/src/gns/gnunet-gns-gtk.h b/src/gns/gnunet-gns-gtk.h index 24f82398..9c554aee 100644 --- a/src/gns/gnunet-gns-gtk.h +++ b/src/gns/gnunet-gns-gtk.h | |||
@@ -42,6 +42,7 @@ struct GNUNET_GNS_Context | |||
42 | 42 | ||
43 | GtkTreeStore *ts; | 43 | GtkTreeStore *ts; |
44 | GtkListStore *ls; | 44 | GtkListStore *ls; |
45 | GtkTreeModel *tm; | ||
45 | 46 | ||
46 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; | 47 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; |
47 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | 48 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; |
diff --git a/src/gns/gnunet-gns-gtk_zone.c b/src/gns/gnunet-gns-gtk_zone.c index 1ab55cd4..0d6fff3a 100644 --- a/src/gns/gnunet-gns-gtk_zone.c +++ b/src/gns/gnunet-gns-gtk_zone.c | |||
@@ -29,7 +29,7 @@ | |||
29 | #define NEW_NAME_STR "<new name>" | 29 | #define NEW_NAME_STR "<new name>" |
30 | #define NEW_RECORD_STR "<new record>" | 30 | #define NEW_RECORD_STR "<new record>" |
31 | 31 | ||
32 | enum | 32 | enum TREESTORE_COLUMNS |
33 | { | 33 | { |
34 | TREE_COL_NAME = 0, | 34 | TREE_COL_NAME = 0, |
35 | TREE_COL_IS_PUBLIC, | 35 | TREE_COL_IS_PUBLIC, |
@@ -42,15 +42,24 @@ enum | |||
42 | TREE_COL_VAL_COLOR, | 42 | TREE_COL_VAL_COLOR, |
43 | TREE_COL_NAME_IS_VISIBLE, | 43 | TREE_COL_NAME_IS_VISIBLE, |
44 | TREE_COL_IS_RECORD_ROW, | 44 | TREE_COL_IS_RECORD_ROW, |
45 | TREE_COL_NOT_DUMMY_ROW | 45 | TREE_COL_NOT_DUMMY_ROW, |
46 | TREE_COL_EXP_TIME_COLOR | ||
46 | }; | 47 | }; |
47 | 48 | ||
48 | enum | 49 | enum LIST_COLUMNS |
49 | { | 50 | { |
50 | TYPE_LIST_TYPE = 0, | 51 | TYPE_LIST_TYPE = 0, |
51 | TYPE_LIST_TYPENAME | 52 | TYPE_LIST_TYPENAME |
52 | }; | 53 | }; |
53 | 54 | ||
55 | |||
56 | void | ||
57 | check_record_validity () | ||
58 | { | ||
59 | GNUNET_break (0); | ||
60 | } | ||
61 | |||
62 | |||
54 | /** | 63 | /** |
55 | * The user has selected a new record type. Update the | 64 | * The user has selected a new record type. Update the |
56 | * model, possibly invalidating (marking 'red') the existing | 65 | * model, possibly invalidating (marking 'red') the existing |
@@ -138,6 +147,8 @@ GNUNET_GNS_GTK_type_cellrenderercombo_changed_cb (GtkCellRendererCombo *combo, | |||
138 | gtk_tree_store_set (gns->ts, &child, TREE_COL_VAL_COLOR, "red", -1); | 147 | gtk_tree_store_set (gns->ts, &child, TREE_COL_VAL_COLOR, "red", -1); |
139 | } | 148 | } |
140 | 149 | ||
150 | check_record_validity (); | ||
151 | |||
141 | } | 152 | } |
142 | 153 | ||
143 | 154 | ||
@@ -181,7 +192,59 @@ GNUNET_GNS_GTK_expiration_cellrenderertext_edited_cb (GtkCellRendererText *rende | |||
181 | gchar *new_text, | 192 | gchar *new_text, |
182 | gpointer user_data) | 193 | gpointer user_data) |
183 | { | 194 | { |
184 | GNUNET_break (0); // FIXME, not implemented | 195 | struct GNUNET_GNS_Context * gns = user_data; |
196 | GtkTreeIter it; | ||
197 | struct GNUNET_TIME_Relative reltime; | ||
198 | struct GNUNET_TIME_Absolute abstime; | ||
199 | gboolean is_rel; | ||
200 | char * time = new_text; | ||
201 | char * old_text; | ||
202 | |||
203 | if ((NULL != new_text)) | ||
204 | { | ||
205 | gtk_tree_model_get_iter_from_string(gns->tm, &it, path); | ||
206 | gtk_tree_model_get(gns->tm, &it, | ||
207 | TREE_COL_EXP_TIME_AS_STR, &old_text, | ||
208 | TREE_COL_EXP_TIME_IS_REL, &is_rel, | ||
209 | -1); | ||
210 | if (0 == strcmp(new_text, old_text)) | ||
211 | return; | ||
212 | if ((0 == strcmp(new_text,"")) || (0 == strcmp(new_text,"end of time"))) | ||
213 | { | ||
214 | time = "end of time"; | ||
215 | abstime = GNUNET_TIME_absolute_get_forever(); | ||
216 | } | ||
217 | else | ||
218 | { | ||
219 | if (GNUNET_SYSERR == GNUNET_STRINGS_fancy_time_to_relative (time, &reltime)) | ||
220 | { | ||
221 | gtk_tree_store_set (gns->ts, &it, | ||
222 | TREE_COL_EXP_TIME_AS_STR, new_text, | ||
223 | TREE_COL_EXP_TIME_COLOR, "red", | ||
224 | TREE_COL_EXP_TIME, 0, | ||
225 | -1); | ||
226 | abstime = GNUNET_TIME_absolute_get_zero(); | ||
227 | return; | ||
228 | } | ||
229 | /* TODO: fix this when we have relative time */ | ||
230 | if (TRUE == is_rel) | ||
231 | { | ||
232 | abstime = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), reltime); | ||
233 | } | ||
234 | else | ||
235 | { | ||
236 | abstime = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), reltime); | ||
237 | } | ||
238 | } | ||
239 | |||
240 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New text for `%s' is `%s'\n", path, GNUNET_STRINGS_absolute_time_to_string(abstime)); | ||
241 | gtk_tree_store_set (gns->ts, &it, | ||
242 | TREE_COL_EXP_TIME_AS_STR, GNUNET_STRINGS_absolute_time_to_string(abstime), | ||
243 | TREE_COL_EXP_TIME, abstime.abs_value, | ||
244 | TREE_COL_EXP_TIME_COLOR, NULL, | ||
245 | -1); | ||
246 | } | ||
247 | check_record_validity (); | ||
185 | } | 248 | } |
186 | 249 | ||
187 | 250 | ||
@@ -225,6 +288,8 @@ GNUNET_GNS_GTK_value_cellrenderertext_edited_cb (GtkCellRendererText *renderer, | |||
225 | gtk_tree_store_set (gns->ts, &it, TREE_COL_VAL_COLOR, "red", -1); | 288 | gtk_tree_store_set (gns->ts, &it, TREE_COL_VAL_COLOR, "red", -1); |
226 | gtk_tree_store_set (gns->ts, &it, TREE_COL_VAL_AS_STR, new_text, -1); | 289 | gtk_tree_store_set (gns->ts, &it, TREE_COL_VAL_AS_STR, new_text, -1); |
227 | } | 290 | } |
291 | |||
292 | check_record_validity (); | ||
228 | } | 293 | } |
229 | } | 294 | } |
230 | 295 | ||
@@ -317,6 +382,84 @@ GNUNET_GNS_GTK_main_treeview_popup_menu_cb (GtkWidget *widget, | |||
317 | return TRUE; | 382 | return TRUE; |
318 | } | 383 | } |
319 | 384 | ||
385 | void set_exp (struct GNUNET_GNS_Context *gns, char * exp) | ||
386 | { | ||
387 | GtkTreeIter it; | ||
388 | GtkTreeIter parent; | ||
389 | GtkTreeIter child; | ||
390 | int not_dummy; | ||
391 | gboolean has_parent; | ||
392 | GtkCellRendererText *renderer; | ||
393 | |||
394 | char *path; | ||
395 | |||
396 | GtkTreeView *tv = GTK_TREE_VIEW(gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_main_treeview")); | ||
397 | GtkTreeModel *tm; | ||
398 | GtkTreeSelection * ts = gtk_tree_view_get_selection(tv); | ||
399 | |||
400 | gtk_tree_selection_get_selected (ts, &tm, &it); | ||
401 | gtk_tree_model_get(tm, &it, TREE_COL_NOT_DUMMY_ROW, ¬_dummy, -1); | ||
402 | if (GNUNET_NO == not_dummy) | ||
403 | return; | ||
404 | |||
405 | /* Has parent? */ | ||
406 | has_parent = gtk_tree_model_iter_parent (tm, &parent, &it); | ||
407 | |||
408 | if (TRUE == has_parent) | ||
409 | { | ||
410 | /* this is a single record */ | ||
411 | GNUNET_break (0); | ||
412 | renderer = GTK_CELL_RENDERER_TEXT((gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_name_cellrenderertext"))); | ||
413 | path = gtk_tree_model_get_string_from_iter (tm, &it); | ||
414 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "PATH `%s'\n", path); | ||
415 | GNUNET_GNS_GTK_expiration_cellrenderertext_edited_cb (renderer, | ||
416 | path, | ||
417 | exp, | ||
418 | gns); | ||
419 | } | ||
420 | else | ||
421 | { | ||
422 | GNUNET_break (0); | ||
423 | } | ||
424 | } | ||
425 | |||
426 | |||
427 | gboolean | ||
428 | GNUNET_GNS_GTK_main_treeview_popup_menu_exp1d_cb (GtkWidget *widget, | ||
429 | gpointer user_data) | ||
430 | { | ||
431 | GNUNET_break(0); | ||
432 | set_exp (user_data, "1 d"); | ||
433 | return TRUE; | ||
434 | } | ||
435 | |||
436 | |||
437 | gboolean | ||
438 | GNUNET_GNS_GTK_main_treeview_popup_menu_exp1w_cb (GtkWidget *widget, | ||
439 | gpointer user_data) | ||
440 | { | ||
441 | set_exp (user_data, "7 d"); | ||
442 | return TRUE; | ||
443 | } | ||
444 | |||
445 | gboolean | ||
446 | GNUNET_GNS_GTK_main_treeview_popup_menu_exp1y_cb (GtkWidget *widget, | ||
447 | gpointer user_data) | ||
448 | { | ||
449 | set_exp (user_data, "1 a"); | ||
450 | return TRUE; | ||
451 | } | ||
452 | |||
453 | gboolean | ||
454 | GNUNET_GNS_GTK_main_treeview_popup_menu_expinf_cb (GtkWidget *widget, | ||
455 | gpointer user_data) | ||
456 | { | ||
457 | set_exp (user_data, "end of time"); | ||
458 | return TRUE; | ||
459 | } | ||
460 | |||
461 | |||
462 | |||
320 | gboolean | 463 | gboolean |
321 | GNUNET_GNS_GTK_main_treeview_button_press_popup_menu_cb (GtkWidget *widget, GdkEventButton *event, gpointer user_data) | 464 | GNUNET_GNS_GTK_main_treeview_button_press_popup_menu_cb (GtkWidget *widget, GdkEventButton *event, gpointer user_data) |
322 | { | 465 | { |
@@ -434,6 +577,7 @@ build_rd_from_datastore (GtkTreeModel *tm, GtkTreeIter *it) | |||
434 | return rd; | 577 | return rd; |
435 | } | 578 | } |
436 | 579 | ||
580 | |||
437 | void GNUNET_GNS_GTK_delete_popup_menu_delete_cb (GtkMenuItem *menuitem, | 581 | void GNUNET_GNS_GTK_delete_popup_menu_delete_cb (GtkMenuItem *menuitem, |
438 | gpointer user_data) | 582 | gpointer user_data) |
439 | { | 583 | { |
@@ -494,7 +638,6 @@ void GNUNET_GNS_GTK_delete_popup_menu_delete_cb (GtkMenuItem *menuitem, | |||
494 | rcc->gns = gns; | 638 | rcc->gns = gns; |
495 | rcc->tm = tm; | 639 | rcc->tm = tm; |
496 | rcc->path = gtk_tree_model_get_string_from_iter (tm, &child); | 640 | rcc->path = gtk_tree_model_get_string_from_iter (tm, &child); |
497 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CALLING\n"); | ||
498 | GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name,(const struct GNUNET_NAMESTORE_RecordData *) rd, &remove_proc, rcc); | 641 | GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name,(const struct GNUNET_NAMESTORE_RecordData *) rd, &remove_proc, rcc); |
499 | gtk_tree_model_iter_next (tm, &child); | 642 | gtk_tree_model_iter_next (tm, &child); |
500 | } | 643 | } |
@@ -592,7 +735,7 @@ void zone_iteration_proc (void *cls, | |||
592 | 735 | ||
593 | if (GNUNET_YES == time_is_relative) | 736 | if (GNUNET_YES == time_is_relative) |
594 | { | 737 | { |
595 | /* FIX THIS WHEN WE HAVE RELATIVE TIME */ | 738 | /* TODO: FIX THIS WHEN WE HAVE RELATIVE TIME */ |
596 | struct GNUNET_TIME_Relative rel_time = GNUNET_TIME_relative_get_zero(); | 739 | struct GNUNET_TIME_Relative rel_time = GNUNET_TIME_relative_get_zero(); |
597 | struct GNUNET_TIME_Absolute exp_abs; | 740 | struct GNUNET_TIME_Absolute exp_abs; |
598 | exp_abs = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), rel_time); | 741 | exp_abs = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), rel_time); |