aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-03-22 16:27:34 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-03-22 16:27:34 +0000
commitfcefc4f107da4fb80ea744a377ee8abe14e3ca5e (patch)
tree2741e0f9e5a23a9f65d65ae3b249e88536ee8d0a
parentdca397cfa4b7c7acec558552f4baf50a3d25b562 (diff)
downloadgnunet-gtk-fcefc4f107da4fb80ea744a377ee8abe14e3ca5e.tar.gz
gnunet-gtk-fcefc4f107da4fb80ea744a377ee8abe14e3ca5e.zip
- rewritten time management
-rw-r--r--contrib/gnunet_gns_gtk_main_window.glade8
-rw-r--r--src/gns/gnunet-gns-gtk.c2
-rw-r--r--src/gns/gnunet-gns-gtk_zone.c150
3 files changed, 125 insertions, 35 deletions
diff --git a/contrib/gnunet_gns_gtk_main_window.glade b/contrib/gnunet_gns_gtk_main_window.glade
index ea49dfba..fae30716 100644
--- a/contrib/gnunet_gns_gtk_main_window.glade
+++ b/contrib/gnunet_gns_gtk_main_window.glade
@@ -26,7 +26,7 @@
26 <property name="visible">True</property> 26 <property name="visible">True</property>
27 <property name="can_focus">False</property> 27 <property name="can_focus">False</property>
28 <property name="use_action_appearance">False</property> 28 <property name="use_action_appearance">False</property>
29 <property name="label" translatable="yes">Set expiration 1 day</property> 29 <property name="label" translatable="yes">Record expires in 1 day</property>
30 <property name="use_underline">True</property> 30 <property name="use_underline">True</property>
31 <signal name="activate" handler="GNUNET_GNS_GTK_main_treeview_popup_menu_exp1d_cb" swapped="no"/> 31 <signal name="activate" handler="GNUNET_GNS_GTK_main_treeview_popup_menu_exp1d_cb" swapped="no"/>
32 </object> 32 </object>
@@ -36,7 +36,7 @@
36 <property name="visible">True</property> 36 <property name="visible">True</property>
37 <property name="can_focus">False</property> 37 <property name="can_focus">False</property>
38 <property name="use_action_appearance">False</property> 38 <property name="use_action_appearance">False</property>
39 <property name="label" translatable="yes">Set expiration 1 week</property> 39 <property name="label" translatable="yes">Record expires in 1 week</property>
40 <property name="use_underline">True</property> 40 <property name="use_underline">True</property>
41 <signal name="activate" handler="GNUNET_GNS_GTK_main_treeview_popup_menu_exp1w_cb" swapped="no"/> 41 <signal name="activate" handler="GNUNET_GNS_GTK_main_treeview_popup_menu_exp1w_cb" swapped="no"/>
42 </object> 42 </object>
@@ -46,7 +46,7 @@
46 <property name="visible">True</property> 46 <property name="visible">True</property>
47 <property name="can_focus">False</property> 47 <property name="can_focus">False</property>
48 <property name="use_action_appearance">False</property> 48 <property name="use_action_appearance">False</property>
49 <property name="label" translatable="yes">Set expiration 1 year</property> 49 <property name="label" translatable="yes">Record expires in 1 year</property>
50 <property name="use_underline">True</property> 50 <property name="use_underline">True</property>
51 <signal name="activate" handler="GNUNET_GNS_GTK_main_treeview_popup_menu_exp1y_cb" swapped="no"/> 51 <signal name="activate" handler="GNUNET_GNS_GTK_main_treeview_popup_menu_exp1y_cb" swapped="no"/>
52 </object> 52 </object>
@@ -56,7 +56,7 @@
56 <property name="visible">True</property> 56 <property name="visible">True</property>
57 <property name="can_focus">False</property> 57 <property name="can_focus">False</property>
58 <property name="use_action_appearance">False</property> 58 <property name="use_action_appearance">False</property>
59 <property name="label" translatable="yes">Set expiration end of time</property> 59 <property name="label" translatable="yes">Record never expires</property>
60 <property name="use_underline">True</property> 60 <property name="use_underline">True</property>
61 <signal name="activate" handler="GNUNET_GNS_GTK_main_treeview_popup_menu_expinf_cb" swapped="no"/> 61 <signal name="activate" handler="GNUNET_GNS_GTK_main_treeview_popup_menu_expinf_cb" swapped="no"/>
62 </object> 62 </object>
diff --git a/src/gns/gnunet-gns-gtk.c b/src/gns/gnunet-gns-gtk.c
index 70fa5314..995aa3f8 100644
--- a/src/gns/gnunet-gns-gtk.c
+++ b/src/gns/gnunet-gns-gtk.c
@@ -247,8 +247,6 @@ GNUNET_GNS_GTK_zone_open_dialog_response_cb (GtkDialog * dialog,
247 /* FIXME: move to new zone 'filename' */ 247 /* FIXME: move to new zone 'filename' */
248 fprintf (stderr, "Got zone `%s'\n", filename); 248 fprintf (stderr, "Got zone `%s'\n", filename);
249 249
250 fork();
251
252 GNUNET_free (filename); 250 GNUNET_free (filename);
253} 251}
254 252
diff --git a/src/gns/gnunet-gns-gtk_zone.c b/src/gns/gnunet-gns-gtk_zone.c
index bfd54760..52970006 100644
--- a/src/gns/gnunet-gns-gtk_zone.c
+++ b/src/gns/gnunet-gns-gtk_zone.c
@@ -28,6 +28,8 @@
28 28
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#define EXPIRE_NEVER_STRING "never"
32#define EXPIRE_INVALID_STRING "invalid"
31 33
32enum TREESTORE_COLUMNS 34enum TREESTORE_COLUMNS
33{ 35{
@@ -459,6 +461,95 @@ GNUNET_GNS_GTK_ispublic_cellrenderertoggle_toggled_cb (GtkCellRendererToggle *ce
459 check_name_validity_and_commit (gns, path); 461 check_name_validity_and_commit (gns, path);
460} 462}
461 463
464static
465char * convert_time_to_string (struct GNUNET_TIME_Absolute t)
466{
467 time_t tt;
468 struct tm *time;
469 char *ret;
470
471 if (t.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
472 return GNUNET_strdup (_(EXPIRE_NEVER_STRING));
473 if (t.abs_value == GNUNET_TIME_UNIT_ZERO_ABS.abs_value)
474 return GNUNET_strdup (_(EXPIRE_INVALID_STRING));
475
476 tt = t.abs_value / 1000;
477 time = localtime (&tt);
478
479 GNUNET_asprintf(&ret, "%02u/%02u/%04u %02u:%02u",time->tm_mon, time->tm_mday, 1900 + time->tm_year, time->tm_hour, time->tm_min);
480 return ret;
481}
482
483static
484int check_time (const char * text)
485{
486 unsigned int t_mon;
487 unsigned int t_day;
488 unsigned int t_year;
489 unsigned int t_hrs;
490 unsigned int t_min;
491
492 int count = SSCANF (text, "%02u/%02u/%04u %02u:%02u", &t_mon, &t_day, &t_year, &t_hrs, &t_min);
493 if ((EOF == count) || (5 != count))
494 return GNUNET_SYSERR;
495
496 if (t_mon > 12)
497 return GNUNET_SYSERR;
498 if (t_day > 31)
499 return GNUNET_SYSERR;
500 if (t_hrs > 24)
501 return GNUNET_SYSERR;
502 if (t_min > 59)
503 return GNUNET_SYSERR;
504
505 return GNUNET_OK;
506}
507
508static
509const struct GNUNET_TIME_Absolute convert_string_to_abs_time (const char * text)
510{
511 static struct GNUNET_TIME_Absolute abs_t;
512 struct tm time;
513 time_t t;
514
515 int t_mon;
516 int t_day;
517 int t_year;
518 int t_hrs;
519 int t_min;
520
521 GNUNET_assert (NULL != text);
522
523 if (0 == strcmp(text, EXPIRE_NEVER_STRING))
524 return GNUNET_TIME_absolute_get_forever();
525
526 memset (&time, '\0', sizeof (struct tm));
527
528 if (GNUNET_SYSERR == check_time(text))
529 {
530 GNUNET_break (0);
531 return GNUNET_TIME_absolute_get_zero();
532 }
533
534 int count = SSCANF (text, "%02d/%02d/%04d %02d:%02d", &t_mon, &t_day, &t_year, &t_hrs, &t_min);
535 if ((EOF == count) || (5 != count))
536 return GNUNET_TIME_absolute_get_zero();
537
538 time.tm_mon = (t_mon - 1);
539 time.tm_mday = t_day;
540 time.tm_year = t_year - 1900;
541 time.tm_hour = (t_hrs);
542 time.tm_min = t_min;
543
544 t = mktime (&time);
545 if (-1 == t)
546 return GNUNET_TIME_absolute_get_zero();
547
548 abs_t.abs_value = t * 1000;
549
550 return abs_t;
551}
552
462 553
463/** 554/**
464 * The user has edited a 'expiration' cell. Update the model. 555 * The user has edited a 'expiration' cell. Update the model.
@@ -476,11 +567,10 @@ GNUNET_GNS_GTK_expiration_cellrenderertext_edited_cb (GtkCellRendererText *rende
476{ 567{
477 struct GNUNET_GNS_Context * gns = user_data; 568 struct GNUNET_GNS_Context * gns = user_data;
478 GtkTreeIter it; 569 GtkTreeIter it;
479 struct GNUNET_TIME_Relative reltime;
480 struct GNUNET_TIME_Absolute abstime; 570 struct GNUNET_TIME_Absolute abstime;
481 gboolean is_rel; 571 gboolean is_rel;
482 char * time = new_text; 572 char *time = new_text;
483 char * old_text; 573 char *old_text;
484 574
485 if ((NULL != new_text)) 575 if ((NULL != new_text))
486 { 576 {
@@ -491,14 +581,15 @@ GNUNET_GNS_GTK_expiration_cellrenderertext_edited_cb (GtkCellRendererText *rende
491 -1); 581 -1);
492 if (0 == strcmp(new_text, old_text)) 582 if (0 == strcmp(new_text, old_text))
493 return; 583 return;
494 if ((0 == strcmp(new_text,"")) || (0 == strcmp(new_text,"end of time"))) 584
585 if ((0 == strcmp(new_text,"")) || (0 == strcmp(new_text,EXPIRE_NEVER_STRING)))
495 { 586 {
496 time = "end of time"; 587 time = EXPIRE_NEVER_STRING;
497 abstime = GNUNET_TIME_absolute_get_forever(); 588 abstime = GNUNET_TIME_absolute_get_forever();
498 } 589 }
499 else 590 else
500 { 591 {
501 if (GNUNET_SYSERR == GNUNET_STRINGS_fancy_time_to_relative (time, &reltime)) 592 if (GNUNET_SYSERR == check_time(new_text))
502 { 593 {
503 gtk_tree_store_set (gns->ts, &it, 594 gtk_tree_store_set (gns->ts, &it,
504 TREE_COL_EXP_TIME_AS_STR, new_text, 595 TREE_COL_EXP_TIME_AS_STR, new_text,
@@ -511,17 +602,15 @@ GNUNET_GNS_GTK_expiration_cellrenderertext_edited_cb (GtkCellRendererText *rende
511 /* TODO: fix this when we have relative time */ 602 /* TODO: fix this when we have relative time */
512 if (TRUE == is_rel) 603 if (TRUE == is_rel)
513 { 604 {
514 abstime = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), reltime); 605 abstime = convert_string_to_abs_time(new_text);
515 } 606 }
516 else 607 else
517 { 608 {
518 abstime = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), reltime); 609 abstime = convert_string_to_abs_time(new_text);
519 } 610 }
520 } 611 }
521
522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New text for `%s' is `%s'\n", path, GNUNET_STRINGS_absolute_time_to_string(abstime));
523 gtk_tree_store_set (gns->ts, &it, 612 gtk_tree_store_set (gns->ts, &it,
524 TREE_COL_EXP_TIME_AS_STR, GNUNET_STRINGS_absolute_time_to_string(abstime), 613 TREE_COL_EXP_TIME_AS_STR, new_text,
525 TREE_COL_EXP_TIME, abstime.abs_value, 614 TREE_COL_EXP_TIME, abstime.abs_value,
526 TREE_COL_EXP_TIME_COLOR, NULL, 615 TREE_COL_EXP_TIME_COLOR, NULL,
527 -1); 616 -1);
@@ -595,7 +684,6 @@ GNUNET_GNS_GTK_name_cellrenderertext_edited_cb (GtkCellRendererText *renderer,
595 GtkTreeIter child; 684 GtkTreeIter child;
596 GtkTreeModel *tm = GTK_TREE_MODEL(gns->ts); 685 GtkTreeModel *tm = GTK_TREE_MODEL(gns->ts);
597 int not_dummy; 686 int not_dummy;
598 int children;
599 687
600 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New text for `%s' is `%s'\n", path, new_text); 688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New text for `%s' is `%s'\n", path, new_text);
601 if ((0 == strcmp (new_text, NEW_NAME_STR)) || (0 == strcmp (new_text, ""))) 689 if ((0 == strcmp (new_text, NEW_NAME_STR)) || (0 == strcmp (new_text, "")))
@@ -696,13 +784,14 @@ GNUNET_GNS_GTK_main_treeview_popup_menu_cb (GtkWidget *widget,
696 return TRUE; 784 return TRUE;
697} 785}
698 786
699void set_exp (struct GNUNET_GNS_Context *gns, char * exp) 787void set_relative_expiration_time (struct GNUNET_GNS_Context *gns, struct GNUNET_TIME_Relative reltime)
700{ 788{
701 GtkTreeIter it; 789 GtkTreeIter it;
702 GtkTreeIter parent; 790 GtkTreeIter parent;
703 int not_dummy; 791 int not_dummy;
704 gboolean has_parent; 792 gboolean has_parent;
705 GtkCellRendererText *renderer; 793 GtkCellRendererText *renderer;
794 struct GNUNET_TIME_Absolute abstime;
706 795
707 char *path; 796 char *path;
708 797
@@ -718,16 +807,19 @@ void set_exp (struct GNUNET_GNS_Context *gns, char * exp)
718 /* Has parent? */ 807 /* Has parent? */
719 has_parent = gtk_tree_model_iter_parent (tm, &parent, &it); 808 has_parent = gtk_tree_model_iter_parent (tm, &parent, &it);
720 809
721 if (TRUE == has_parent) 810 if (FALSE == has_parent)
722 { 811 return;
723 /* this is a single record */ 812
724 renderer = GTK_CELL_RENDERER_TEXT((gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_name_cellrenderertext"))); 813 abstime = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), reltime);
725 path = gtk_tree_model_get_string_from_iter (tm, &it); 814
726 GNUNET_GNS_GTK_expiration_cellrenderertext_edited_cb (renderer, 815 /* this is a single record */
727 path, 816 renderer = GTK_CELL_RENDERER_TEXT((gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_name_cellrenderertext")));
728 exp, 817 path = gtk_tree_model_get_string_from_iter (tm, &it);
729 gns); 818 GNUNET_GNS_GTK_expiration_cellrenderertext_edited_cb (renderer,
730 } 819 path,
820 convert_time_to_string (abstime),
821 gns);
822
731} 823}
732 824
733 825
@@ -735,7 +827,7 @@ gboolean
735GNUNET_GNS_GTK_main_treeview_popup_menu_exp1d_cb (GtkWidget *widget, 827GNUNET_GNS_GTK_main_treeview_popup_menu_exp1d_cb (GtkWidget *widget,
736 gpointer user_data) 828 gpointer user_data)
737{ 829{
738 set_exp (user_data, "1 d"); 830 set_relative_expiration_time (user_data, GNUNET_TIME_UNIT_DAYS);
739 return TRUE; 831 return TRUE;
740} 832}
741 833
@@ -744,7 +836,7 @@ gboolean
744GNUNET_GNS_GTK_main_treeview_popup_menu_exp1w_cb (GtkWidget *widget, 836GNUNET_GNS_GTK_main_treeview_popup_menu_exp1w_cb (GtkWidget *widget,
745 gpointer user_data) 837 gpointer user_data)
746{ 838{
747 set_exp (user_data, "7 d"); 839 set_relative_expiration_time (user_data, GNUNET_TIME_UNIT_WEEKS);
748 return TRUE; 840 return TRUE;
749} 841}
750 842
@@ -752,7 +844,7 @@ gboolean
752GNUNET_GNS_GTK_main_treeview_popup_menu_exp1y_cb (GtkWidget *widget, 844GNUNET_GNS_GTK_main_treeview_popup_menu_exp1y_cb (GtkWidget *widget,
753 gpointer user_data) 845 gpointer user_data)
754{ 846{
755 set_exp (user_data, "1 a"); 847 set_relative_expiration_time (user_data, GNUNET_TIME_UNIT_YEARS);
756 return TRUE; 848 return TRUE;
757} 849}
758 850
@@ -760,7 +852,7 @@ gboolean
760GNUNET_GNS_GTK_main_treeview_popup_menu_expinf_cb (GtkWidget *widget, 852GNUNET_GNS_GTK_main_treeview_popup_menu_expinf_cb (GtkWidget *widget,
761 gpointer user_data) 853 gpointer user_data)
762{ 854{
763 set_exp (user_data, "end of time"); 855 set_relative_expiration_time (user_data, GNUNET_TIME_UNIT_FOREVER_REL);
764 return TRUE; 856 return TRUE;
765} 857}
766 858
@@ -928,13 +1020,13 @@ void zone_iteration_proc (void *cls,
928 struct GNUNET_TIME_Absolute exp_abs; 1020 struct GNUNET_TIME_Absolute exp_abs;
929 exp_abs = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), rel_time); 1021 exp_abs = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), rel_time);
930 exp_t = exp_abs.abs_value; 1022 exp_t = exp_abs.abs_value;
931 exp = GNUNET_STRINGS_absolute_time_to_string (exp_abs); 1023 exp = convert_time_to_string (exp_abs);
932 } 1024 }
933 else 1025 else
934 { 1026 {
935 struct GNUNET_TIME_Absolute exp_abs = rd[c].expiration; 1027 struct GNUNET_TIME_Absolute exp_abs = rd[c].expiration;
936 exp_t = exp_abs.abs_value; 1028 exp_t = exp_abs.abs_value;
937 exp = GNUNET_STRINGS_absolute_time_to_string (exp_abs); 1029 exp = convert_time_to_string (exp_abs);
938 } 1030 }
939 /* value */ 1031 /* value */
940 val = GNUNET_NAMESTORE_value_to_string (rd[c].record_type, 1032 val = GNUNET_NAMESTORE_value_to_string (rd[c].record_type,