aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-29 22:13:18 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-29 22:13:18 +0000
commiteece228d8cdef54757a29525d14487533c7146b0 (patch)
tree31de1497ab7b2d4df880f1ce66189d23b32f7755
parentbcb2521d7e3e9e00effe7200fb5f0a3ddcd1853e (diff)
downloadgnunet-gtk-eece228d8cdef54757a29525d14487533c7146b0.tar.gz
gnunet-gtk-eece228d8cdef54757a29525d14487533c7146b0.zip
-support for relative expiration time and setting absolute expiration time via cal
-rw-r--r--contrib/Makefile.am1
-rw-r--r--contrib/gnunet_setup_calendar_dialog.glade84
-rw-r--r--contrib/gnunet_setup_gtk_main_window.glade19
-rw-r--r--src/setup/gnunet-setup-gns.c417
4 files changed, 316 insertions, 205 deletions
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index 738d4305..2bb565c9 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -45,6 +45,7 @@ pkgdata_DATA = \
45 gnunet_peerinfo_gtk_main_window.glade \ 45 gnunet_peerinfo_gtk_main_window.glade \
46 gnunet_statistics_gtk_about_window.glade \ 46 gnunet_statistics_gtk_about_window.glade \
47 gnunet_statistics_gtk_main_window.glade \ 47 gnunet_statistics_gtk_main_window.glade \
48 gnunet_setup_calendar_dialog.glade \
48 gnunet_setup_qr_save_as_dialog.glade \ 49 gnunet_setup_qr_save_as_dialog.glade \
49 gnunet_setup_gtk_main_window.glade 50 gnunet_setup_gtk_main_window.glade
50 51
diff --git a/contrib/gnunet_setup_calendar_dialog.glade b/contrib/gnunet_setup_calendar_dialog.glade
new file mode 100644
index 00000000..9652c230
--- /dev/null
+++ b/contrib/gnunet_setup_calendar_dialog.glade
@@ -0,0 +1,84 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<interface>
3 <requires lib="gtk+" version="2.24"/>
4 <!-- interface-naming-policy project-wide -->
5 <object class="GtkDialog" id="GNUNET_setup_calendar_dialog">
6 <property name="can_focus">False</property>
7 <property name="border_width">5</property>
8 <property name="type_hint">dialog</property>
9 <signal name="response" handler="GNUNET_setup_calendar_dialog_response_cb" swapped="no"/>
10 <child internal-child="vbox">
11 <object class="GtkVBox" id="GNUNET_setup_calendar_dialog-vbox">
12 <property name="visible">True</property>
13 <property name="can_focus">False</property>
14 <property name="spacing">2</property>
15 <child internal-child="action_area">
16 <object class="GtkHButtonBox" id="GNUNET_setup_calendar_dialog-action_area">
17 <property name="visible">True</property>
18 <property name="can_focus">False</property>
19 <property name="layout_style">end</property>
20 <child>
21 <object class="GtkButton" id="GNUNET_setup_calendar_cancel_button">
22 <property name="label">gtk-cancel</property>
23 <property name="use_action_appearance">False</property>
24 <property name="visible">True</property>
25 <property name="can_focus">True</property>
26 <property name="receives_default">True</property>
27 <property name="use_stock">True</property>
28 </object>
29 <packing>
30 <property name="expand">False</property>
31 <property name="fill">False</property>
32 <property name="position">0</property>
33 </packing>
34 </child>
35 <child>
36 <object class="GtkButton" id="GNUNET_setup_calendar_ok_button">
37 <property name="label">gtk-ok</property>
38 <property name="use_action_appearance">False</property>
39 <property name="visible">True</property>
40 <property name="can_focus">True</property>
41 <property name="receives_default">True</property>
42 <property name="use_stock">True</property>
43 </object>
44 <packing>
45 <property name="expand">False</property>
46 <property name="fill">False</property>
47 <property name="position">1</property>
48 </packing>
49 </child>
50 </object>
51 <packing>
52 <property name="expand">False</property>
53 <property name="fill">True</property>
54 <property name="pack_type">end</property>
55 <property name="position">0</property>
56 </packing>
57 </child>
58 <child>
59 <object class="GtkCalendar" id="GNUNET_setup_calendar">
60 <property name="visible">True</property>
61 <property name="can_focus">True</property>
62 <property name="year">2012</property>
63 <property name="month">5</property>
64 <property name="day">29</property>
65 <property name="show_week_numbers">True</property>
66 <property name="show_details">False</property>
67 </object>
68 <packing>
69 <property name="expand">True</property>
70 <property name="fill">True</property>
71 <property name="position">1</property>
72 </packing>
73 </child>
74 <child>
75 <placeholder/>
76 </child>
77 </object>
78 </child>
79 <action-widgets>
80 <action-widget response="-6">GNUNET_setup_calendar_cancel_button</action-widget>
81 <action-widget response="-5">GNUNET_setup_calendar_ok_button</action-widget>
82 </action-widgets>
83 </object>
84</interface>
diff --git a/contrib/gnunet_setup_gtk_main_window.glade b/contrib/gnunet_setup_gtk_main_window.glade
index 6f1ccc96..e55dfda5 100644
--- a/contrib/gnunet_setup_gtk_main_window.glade
+++ b/contrib/gnunet_setup_gtk_main_window.glade
@@ -4878,6 +4878,7 @@
4878 <property name="visible">True</property> 4878 <property name="visible">True</property>
4879 <property name="can_focus">False</property> 4879 <property name="can_focus">False</property>
4880 <property name="label" translatable="yes">1 day</property> 4880 <property name="label" translatable="yes">1 day</property>
4881 <signal name="activate" handler="GNUNET_setup_gns_popup_1d_exp_button_activate_cb" swapped="no"/>
4881 </object> 4882 </object>
4882 </child> 4883 </child>
4883 <child> 4884 <child>
@@ -4907,6 +4908,24 @@
4907 <signal name="activate" handler="GNUNET_setup_gns_popup_forever_exp_button_activate_cb" swapped="no"/> 4908 <signal name="activate" handler="GNUNET_setup_gns_popup_forever_exp_button_activate_cb" swapped="no"/>
4908 </object> 4909 </object>
4909 </child> 4910 </child>
4911 <child>
4912 <object class="GtkSeparatorMenuItem" id="&lt;separator2&gt;">
4913 <property name="use_action_appearance">False</property>
4914 <property name="visible">True</property>
4915 <property name="can_focus">False</property>
4916 </object>
4917 </child>
4918 <child>
4919 <object class="GtkMenuItem" id="GNUNET_setup_gns_popup_cal_button">
4920 <property name="use_action_appearance">False</property>
4921 <property name="visible">True</property>
4922 <property name="can_focus">False</property>
4923 <property name="tooltip_text" translatable="yes">Pick expiration date from calendar</property>
4924 <property name="label" translatable="yes">Calendar</property>
4925 <property name="use_underline">True</property>
4926 <signal name="activate" handler="GNUNET_setup_gns_popup_cal_button_activate_cb" swapped="no"/>
4927 </object>
4928 </child>
4910 </object> 4929 </object>
4911 <object class="GtkListStore" id="GNUNET_setup_gns_exit_dialog_liststore"> 4930 <object class="GtkListStore" id="GNUNET_setup_gns_exit_dialog_liststore">
4912 <columns> 4931 <columns>
diff --git a/src/setup/gnunet-setup-gns.c b/src/setup/gnunet-setup-gns.c
index b0c5fdfe..eb0a320f 100644
--- a/src/setup/gnunet-setup-gns.c
+++ b/src/setup/gnunet-setup-gns.c
@@ -523,12 +523,14 @@ check_name_validity_and_commit (const gchar *path, const char * oldname)
523 } 523 }
524 else 524 else
525 { 525 {
526 if (FALSE == n_public) 526 if (n_public)
527 rd[c].flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_PRIVATE; 527 rd[c].flags = GNUNET_NAMESTORE_RF_AUTHORITY;
528 else 528 else
529 rd[c].flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_NONE; 529 rd[c].flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_PRIVATE;
530 rd[c].record_type = n_type; 530 rd[c].record_type = n_type;
531 rd[c].expiration_time = n_exp_time; 531 rd[c].expiration_time = n_exp_time;
532 if (n_is_relative)
533 rd[c].flags |= GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
532 rd[c].data_size = data_size; 534 rd[c].data_size = data_size;
533 rd[c].data = GNUNET_malloc(data_size); 535 rd[c].data = GNUNET_malloc(data_size);
534 memcpy ((void *) rd[c].data, data, data_size); 536 memcpy ((void *) rd[c].data, data, data_size);
@@ -817,18 +819,18 @@ GNUNET_setup_gns_type_cellrenderercombo_edited_cb (GtkCellRendererCombo *combo,
817 else if ((NULL != name_str) && (0 != strcmp (NEW_NAME_STR, name_str))) 819 else if ((NULL != name_str) && (0 != strcmp (NEW_NAME_STR, name_str)))
818 { 820 {
819 /* Adding a new record */ 821 /* Adding a new record */
820 gtk_tree_store_insert_with_values(ts, &child , &it, -1, 822 gtk_tree_store_insert_with_values (ts, &child , &it, -1,
821 GNS_TREESTORE_COL_NAME, name_str, 823 GNS_TREESTORE_COL_NAME, name_str,
822 GNS_TREESTORE_COL_NAME_IS_VISIBLE, FALSE, 824 GNS_TREESTORE_COL_NAME_IS_VISIBLE, FALSE,
823 GNS_TREESTORE_COL_RECORD_TYPE, type, 825 GNS_TREESTORE_COL_RECORD_TYPE, type,
824 GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, new_text, 826 GNS_TREESTORE_COL_RECORD_TYPE_AS_STR, new_text,
825 GNS_TREESTORE_COL_EXP_TIME_AS_STR, EXPIRE_NEVER_STRING, 827 GNS_TREESTORE_COL_EXP_TIME_AS_STR, EXPIRE_NEVER_STRING,
826 GNS_TREESTORE_COL_EXP_TIME, GNUNET_TIME_UNIT_FOREVER_ABS, 828 GNS_TREESTORE_COL_EXP_TIME, GNUNET_TIME_UNIT_FOREVER_ABS,
827 GNS_TREESTORE_COL_EXP_TIME_IS_REL, FALSE, 829 GNS_TREESTORE_COL_EXP_TIME_IS_REL, FALSE,
828 GNS_TREESTORE_COL_IS_RECORD_ROW, TRUE, 830 GNS_TREESTORE_COL_IS_RECORD_ROW, TRUE,
829 GNS_TREESTORE_COL_NOT_DUMMY_ROW, TRUE, 831 GNS_TREESTORE_COL_NOT_DUMMY_ROW, TRUE,
830 GNS_TREESTORE_COL_VAL_COLOR, "red", 832 GNS_TREESTORE_COL_VAL_COLOR, "red",
831 -1); 833 -1);
832 /* select new row and start editing 'value' */ 834 /* select new row and start editing 'value' */
833 gtk_tree_view_expand_row (tv, gtk_tree_model_get_path(tm, &it), 0); 835 gtk_tree_view_expand_row (tv, gtk_tree_model_get_path(tm, &it), 0);
834 sel = gtk_tree_view_get_selection (tv); 836 sel = gtk_tree_view_get_selection (tv);
@@ -868,125 +870,14 @@ GNUNET_setup_gns_ispublic_cellrenderertoggle_toggled_cb (GtkCellRendererToggle *
868 GtkTreeIter it; 870 GtkTreeIter it;
869 gboolean value; 871 gboolean value;
870 872
871 gtk_tree_model_get_iter_from_string(tm, &it, path); 873 gtk_tree_model_get_iter_from_string (tm, &it, path);
872 gtk_tree_model_get(tm, &it, GNS_TREESTORE_COL_IS_PUBLIC, &value, -1); 874 gtk_tree_model_get (tm, &it, GNS_TREESTORE_COL_IS_PUBLIC, &value, -1);
873 gtk_tree_store_set(ts, &it, GNS_TREESTORE_COL_IS_PUBLIC, !value, -1); 875 gtk_tree_store_set (ts, &it, GNS_TREESTORE_COL_IS_PUBLIC, !value, -1);
874
875 check_name_validity_and_commit (path, NULL); 876 check_name_validity_and_commit (path, NULL);
876} 877}
877 878
878 879
879/** 880/**
880 * FIXME: should use routines from gnunet-util (or move this to
881 * gnunet-util if it doesn't exist there!).
882 */
883static char *
884convert_time_to_string (struct GNUNET_TIME_Absolute t)
885{
886 time_t tt;
887 struct tm *time;
888 char *ret;
889
890 if (t.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
891 return GNUNET_strdup (_(EXPIRE_NEVER_STRING));
892 if (t.abs_value == GNUNET_TIME_UNIT_ZERO_ABS.abs_value)
893 return GNUNET_strdup (_(EXPIRE_INVALID_STRING));
894
895 tt = t.abs_value / 1000;
896 time = localtime (&tt);
897
898 GNUNET_asprintf(&ret, "%02u/%02u/%04u %02u:%02u",time->tm_mon, time->tm_mday, 1900 + time->tm_year, time->tm_hour, time->tm_min);
899 return ret;
900}
901
902
903/**
904 *
905 */
906static int
907check_time (const char * text)
908{
909 unsigned int t_mon;
910 unsigned int t_day;
911 unsigned int t_year;
912 unsigned int t_hrs;
913 unsigned int t_min;
914
915 int count = SSCANF (text, "%02u/%02u/%04u %02u:%02u", &t_mon, &t_day, &t_year, &t_hrs, &t_min);
916 if ((EOF == count) || (5 != count))
917 {
918 return GNUNET_SYSERR;
919 }
920
921 if (t_mon > 12)
922 return GNUNET_SYSERR;
923 if (t_day > 31)
924 return GNUNET_SYSERR;
925 if (t_hrs > 24)
926 return GNUNET_SYSERR;
927 if (t_min > 59)
928 return GNUNET_SYSERR;
929
930 return GNUNET_OK;
931}
932
933
934/**
935 *
936 */
937static const struct GNUNET_TIME_Absolute
938convert_string_to_abs_time (const char * text)
939{
940 static struct GNUNET_TIME_Absolute abs_t;
941 struct tm time;
942 time_t t;
943
944 int t_mon;
945 int t_day;
946 int t_year;
947 int t_hrs;
948 int t_min;
949
950 GNUNET_assert (NULL != text);
951
952 if (0 == strcmp(text, EXPIRE_NEVER_STRING))
953 return GNUNET_TIME_UNIT_FOREVER_ABS;
954
955 memset (&time, '\0', sizeof (struct tm));
956
957 if (GNUNET_SYSERR == check_time(text))
958 {
959 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
960 _("Invalid time `%s'\n"), text);
961 GNUNET_break (0);
962 return GNUNET_TIME_UNIT_ZERO_ABS;
963 }
964
965 int count = SSCANF (text, "%02d/%02d/%04d %02d:%02d", &t_mon, &t_day, &t_year, &t_hrs, &t_min);
966 if ((EOF == count) || (5 != count))
967 {
968 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
969 _("Invalid time `%s', returning 0\n"), text);
970 return GNUNET_TIME_UNIT_ZERO_ABS;
971 }
972
973 time.tm_mon = (t_mon - 1);
974 time.tm_mday = t_day;
975 time.tm_year = t_year - 1900;
976 time.tm_hour = (t_hrs);
977 time.tm_min = t_min;
978
979 t = mktime (&time);
980 if (-1 == t)
981 return GNUNET_TIME_UNIT_ZERO_ABS;
982
983 abs_t.abs_value = t * 1000;
984
985 return abs_t;
986}
987
988
989/**
990 * The user has edited a 'expiration' cell. Update the model. 881 * The user has edited a 'expiration' cell. Update the model.
991 * 882 *
992 * @param renderer updated renderer 883 * @param renderer updated renderer
@@ -1002,56 +893,45 @@ GNUNET_setup_gns_expiration_cellrenderertext_edited_cb (GtkCellRendererText *ren
1002{ 893{
1003 GtkTreeIter it; 894 GtkTreeIter it;
1004 struct GNUNET_TIME_Absolute abstime; 895 struct GNUNET_TIME_Absolute abstime;
1005 gboolean is_rel; 896 struct GNUNET_TIME_Relative reltime;
1006 char *old_text;
1007 897
1008 if (NULL == new_text) 898 if (NULL == new_text)
1009 return; /* can this happen? */ 899 return; /* can this happen? */
1010 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1011 "New expiration time: `%s'\n", 901 "New expiration time: `%s'\n",
1012 new_text); 902 new_text);
1013 gtk_tree_model_get_iter_from_string(tm, &it, path); 903 gtk_tree_model_get_iter_from_string (tm, &it, path);
1014 gtk_tree_model_get(tm, &it, 904 if (GNUNET_OK ==
1015 GNS_TREESTORE_COL_EXP_TIME_AS_STR, &old_text, 905 GNUNET_STRINGS_fancy_time_to_relative (new_text,
1016 GNS_TREESTORE_COL_EXP_TIME_IS_REL, &is_rel, 906 &reltime))
1017 -1);
1018 if ( (NULL != old_text) &&
1019 (0 == strcmp(new_text, old_text)) )
1020 return;
1021
1022 if ((0 == strcmp(new_text,"")) || (0 == strcmp(new_text,EXPIRE_NEVER_STRING)))
1023 { 907 {
1024 new_text = EXPIRE_NEVER_STRING; 908 gtk_tree_store_set (ts, &it,
1025 abstime = GNUNET_TIME_UNIT_FOREVER_ABS; 909 GNS_TREESTORE_COL_EXP_TIME_AS_STR, new_text,
910 GNS_TREESTORE_COL_EXP_TIME, reltime.rel_value,
911 GNS_TREESTORE_COL_EXP_TIME_IS_REL, TRUE,
912 GNS_TREESTORE_COL_EXP_TIME_COLOR, NULL,
913 -1);
914 check_name_validity_and_commit (path, NULL);
915 return;
1026 } 916 }
1027 else 917 if (GNUNET_OK ==
918 GNUNET_STRINGS_fancy_time_to_absolute (new_text,
919 &abstime))
1028 { 920 {
1029 if (GNUNET_SYSERR == check_time(new_text)) 921 gtk_tree_store_set (ts, &it,
1030 { 922 GNS_TREESTORE_COL_EXP_TIME_AS_STR, new_text,
1031 gtk_tree_store_set (ts, &it, 923 GNS_TREESTORE_COL_EXP_TIME, abstime.abs_value,
1032 GNS_TREESTORE_COL_EXP_TIME_AS_STR, new_text, 924 GNS_TREESTORE_COL_EXP_TIME_IS_REL, FALSE,
1033 GNS_TREESTORE_COL_EXP_TIME_COLOR, "red", 925 GNS_TREESTORE_COL_EXP_TIME_COLOR, NULL,
1034 GNS_TREESTORE_COL_EXP_TIME, 0, 926 -1);
1035 -1); 927 check_name_validity_and_commit (path, NULL);
1036 abstime = GNUNET_TIME_UNIT_ZERO_ABS; 928 return;
1037 return;
1038 }
1039 /* TODO: fix this when we have relative time */
1040 if (TRUE == is_rel)
1041 {
1042 abstime = convert_string_to_abs_time(new_text);
1043 }
1044 else
1045 {
1046 abstime = convert_string_to_abs_time(new_text);
1047 }
1048 } 929 }
1049 gtk_tree_store_set (ts, &it, 930 gtk_tree_store_set (ts, &it,
1050 GNS_TREESTORE_COL_EXP_TIME_AS_STR, new_text, 931 GNS_TREESTORE_COL_EXP_TIME_AS_STR, new_text,
1051 GNS_TREESTORE_COL_EXP_TIME, abstime.abs_value, 932 GNS_TREESTORE_COL_EXP_TIME_COLOR, "red",
1052 GNS_TREESTORE_COL_EXP_TIME_COLOR, NULL, 933 GNS_TREESTORE_COL_EXP_TIME, 0,
1053 -1); 934 -1);
1054 check_name_validity_and_commit (path, NULL);
1055} 935}
1056 936
1057 937
@@ -1125,14 +1005,13 @@ GNUNET_setup_gns_value_cellrenderertext_edited_cb (GtkCellRendererText *renderer
1125 */ 1005 */
1126void 1006void
1127GNUNET_setup_gns_name_cellrenderertext_edited_cb (GtkCellRendererText *renderer, 1007GNUNET_setup_gns_name_cellrenderertext_edited_cb (GtkCellRendererText *renderer,
1128 gchar *path, 1008 gchar *path,
1129 gchar *new_text, 1009 gchar *new_text,
1130 gpointer user_data) 1010 gpointer user_data)
1131{ 1011{
1132 GtkTreeIter it; 1012 GtkTreeIter it;
1133 GtkTreeIter child; 1013 GtkTreeIter child;
1134 GtkTreeModel *tm = GTK_TREE_MODEL(ts); 1014 gboolean not_dummy;
1135 int not_dummy;
1136 char *name; 1015 char *name;
1137 1016
1138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New text for `%s' is `%s'\n", path, new_text); 1017 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New text for `%s' is `%s'\n", path, new_text);
@@ -1143,7 +1022,7 @@ GNUNET_setup_gns_name_cellrenderertext_edited_cb (GtkCellRendererText *renderer,
1143 gtk_tree_model_get(tm, &it, GNS_TREESTORE_COL_NOT_DUMMY_ROW, &not_dummy, -1); 1022 gtk_tree_model_get(tm, &it, GNS_TREESTORE_COL_NOT_DUMMY_ROW, &not_dummy, -1);
1144 gtk_tree_model_get(tm, &it, GNS_TREESTORE_COL_NAME, &name, -1); 1023 gtk_tree_model_get(tm, &it, GNS_TREESTORE_COL_NAME, &name, -1);
1145 1024
1146 if (not_dummy == GNUNET_NO) 1025 if (not_dummy)
1147 { 1026 {
1148 /* update name */ 1027 /* update name */
1149 gtk_tree_store_set (ts, &it, 1028 gtk_tree_store_set (ts, &it,
@@ -1303,16 +1182,16 @@ set_relative_expiration_time (struct GNUNET_TIME_Relative reltime)
1303 GtkTreeIter it; 1182 GtkTreeIter it;
1304 GtkTreeIter parent; 1183 GtkTreeIter parent;
1305 GtkCellRendererText *renderer; 1184 GtkCellRendererText *renderer;
1306 GtkTreeModel *tm; 1185 GtkTreeSelection * ts;
1307 GtkTreeSelection * ts = gtk_tree_view_get_selection(tv);
1308 gboolean has_parent; 1186 gboolean has_parent;
1309 struct GNUNET_TIME_Absolute abstime;
1310 char *path; 1187 char *path;
1188 char *tstr;
1311 int not_dummy; 1189 int not_dummy;
1312 1190
1191 ts = gtk_tree_view_get_selection(tv);
1313 if (! gtk_tree_selection_get_selected (ts, &tm, &it)) 1192 if (! gtk_tree_selection_get_selected (ts, &tm, &it))
1314 return; 1193 return;
1315 gtk_tree_model_get(tm, &it, GNS_TREESTORE_COL_NOT_DUMMY_ROW, &not_dummy, -1); 1194 gtk_tree_model_get (tm, &it, GNS_TREESTORE_COL_NOT_DUMMY_ROW, &not_dummy, -1);
1316 if (GNUNET_NO == not_dummy) 1195 if (GNUNET_NO == not_dummy)
1317 return; 1196 return;
1318 1197
@@ -1320,17 +1199,15 @@ set_relative_expiration_time (struct GNUNET_TIME_Relative reltime)
1320 has_parent = gtk_tree_model_iter_parent (tm, &parent, &it); 1199 has_parent = gtk_tree_model_iter_parent (tm, &parent, &it);
1321 if (FALSE == has_parent) 1200 if (FALSE == has_parent)
1322 return; 1201 return;
1323
1324 /* FIXME: should keep as relative time! */
1325 abstime = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), reltime);
1326
1327 /* this is a single record */ 1202 /* this is a single record */
1328 renderer = GTK_CELL_RENDERER_TEXT((GNUNET_SETUP_get_object ("GNUNET_setup_gns_name_cellrenderertext"))); 1203 renderer = GTK_CELL_RENDERER_TEXT((GNUNET_SETUP_get_object ("GNUNET_setup_gns_name_cellrenderertext")));
1329 path = gtk_tree_model_get_string_from_iter (tm, &it); 1204 path = gtk_tree_model_get_string_from_iter (tm, &it);
1205 tstr = GNUNET_STRINGS_relative_time_to_string (reltime);
1330 GNUNET_setup_gns_expiration_cellrenderertext_edited_cb (renderer, 1206 GNUNET_setup_gns_expiration_cellrenderertext_edited_cb (renderer,
1331 path, 1207 path,
1332 convert_time_to_string (abstime), 1208 tstr,
1333 NULL); 1209 NULL);
1210 GNUNET_free (tstr);
1334} 1211}
1335 1212
1336 1213
@@ -1339,7 +1216,7 @@ set_relative_expiration_time (struct GNUNET_TIME_Relative reltime)
1339 */ 1216 */
1340void 1217void
1341GNUNET_setup_gns_popup_1d_exp_button_activate_cb (GtkWidget *widget, 1218GNUNET_setup_gns_popup_1d_exp_button_activate_cb (GtkWidget *widget,
1342 gpointer user_data) 1219 gpointer user_data)
1343{ 1220{
1344 set_relative_expiration_time (GNUNET_TIME_UNIT_DAYS); 1221 set_relative_expiration_time (GNUNET_TIME_UNIT_DAYS);
1345} 1222}
@@ -1378,6 +1255,146 @@ GNUNET_setup_gns_popup_forever_exp_button_activate_cb (GtkWidget *widget,
1378} 1255}
1379 1256
1380 1257
1258
1259/**
1260 * Function called upon completion of the calendar dialog.
1261 *
1262 * @param dialog the dialog
1263 * @param response_id reason for the dialog closing
1264 * @param user_data the 'GtkBuilder' we used to create the dialog
1265 */
1266void
1267GNUNET_setup_calendar_dialog_response_cb (GtkDialog *dialog,
1268 gint response_id,
1269 gpointer user_data)
1270{
1271 GtkBuilder *builder = user_data;
1272 guint year;
1273 guint month;
1274 guint day;
1275 GtkTreeIter it;
1276 GtkTreeIter parent;
1277 GtkCellRendererText *renderer;
1278 GtkTreeSelection * ts;
1279 gboolean has_parent;
1280 char *path;
1281 int not_dummy;
1282 char fancydate[128];
1283 char *gndate;
1284 struct GNUNET_TIME_Absolute atime;
1285
1286 if (GTK_RESPONSE_OK != response_id)
1287 {
1288 gtk_widget_destroy (GTK_WIDGET (dialog));
1289 g_object_unref (G_OBJECT (builder));
1290 return;
1291 }
1292 gtk_calendar_get_date (GTK_CALENDAR (gtk_builder_get_object (builder,
1293 "GNUNET_setup_calendar")),
1294 &year, &month, &day);
1295 GNUNET_snprintf (fancydate,
1296 sizeof (fancydate),
1297 "%u-%u-%u",
1298 (unsigned int) year,
1299 (unsigned int) month + 1,
1300 (unsigned int) day);
1301 GNUNET_break (GNUNET_OK ==
1302 GNUNET_STRINGS_fancy_time_to_absolute (fancydate,
1303 &atime));
1304 gndate = GNUNET_STRINGS_absolute_time_to_string (atime);
1305 ts = gtk_tree_view_get_selection(tv);
1306 if (gtk_tree_selection_get_selected (ts, &tm, &it))
1307 {
1308 gtk_tree_model_get (tm, &it,
1309 GNS_TREESTORE_COL_NOT_DUMMY_ROW, &not_dummy,
1310 -1);
1311 if (GNUNET_NO != not_dummy)
1312 {
1313 /* Has parent? */
1314 has_parent = gtk_tree_model_iter_parent (tm, &parent, &it);
1315 if (FALSE != has_parent)
1316 {
1317 /* this is a single record */
1318 renderer = GTK_CELL_RENDERER_TEXT((GNUNET_SETUP_get_object ("GNUNET_setup_gns_name_cellrenderertext")));
1319 path = gtk_tree_model_get_string_from_iter (tm, &it);
1320 GNUNET_setup_gns_expiration_cellrenderertext_edited_cb (renderer,
1321 path,
1322 gndate,
1323 NULL);
1324 }
1325 }
1326 }
1327 GNUNET_free (gndate);
1328 gtk_widget_destroy (GTK_WIDGET (dialog));
1329 g_object_unref (G_OBJECT (builder));
1330}
1331
1332
1333/**
1334 * User selected the 'calendar' option in the expiration context menu.
1335 * Popup the calendar dialog and allow the user to select a date.
1336 *
1337 * @param widget unused
1338 * @param user_data unused
1339 */
1340void
1341GNUNET_setup_gns_popup_cal_button_activate_cb (GtkWidget *widget,
1342 gpointer user_data)
1343{
1344 GtkBuilder *builder;
1345 GtkWindow *dialog;
1346 GtkTreeSelection * tsel;
1347 gboolean has_parent;
1348 int not_dummy;
1349 guint64 et;
1350 gboolean is_relative;
1351 GtkTreeIter it;
1352 GtkTreeIter parent;
1353 struct GNUNET_TIME_Absolute now;
1354 time_t tp;
1355 struct tm *ymd;
1356
1357 tsel = gtk_tree_view_get_selection(tv);
1358 if (! gtk_tree_selection_get_selected (tsel, &tm, &it))
1359 return;
1360 gtk_tree_model_get (tm, &it,
1361 GNS_TREESTORE_COL_NOT_DUMMY_ROW, &not_dummy,
1362 GNS_TREESTORE_COL_EXP_TIME_IS_REL, &is_relative,
1363 GNS_TREESTORE_COL_EXP_TIME, &et,
1364 -1);
1365 if (! not_dummy)
1366 return;
1367 has_parent = gtk_tree_model_iter_parent (tm, &parent, &it);
1368 if (! has_parent)
1369 return;
1370 now = GNUNET_TIME_absolute_get (); now = GNUNET_TIME_absolute_get ();
1371 if (is_relative)
1372 et = now.abs_value; /* use today as starting point */
1373 if (et < now.abs_value)
1374 et = now.abs_value; /* no not allow starting point in the past */
1375 tp = (time_t) (et / 1000LL); /* convert to seconds */
1376 builder =
1377 GNUNET_GTK_get_new_builder ("gnunet_setup_calendar_dialog.glade",
1378 NULL);
1379 if (NULL == builder)
1380 {
1381 GNUNET_break (0);
1382 return;
1383 }
1384 ymd = gmtime (&tp);
1385 gtk_calendar_select_month (GTK_CALENDAR (gtk_builder_get_object (builder,
1386 "GNUNET_setup_calendar")),
1387 ymd->tm_mon,
1388 ymd->tm_year + 1900);
1389 gtk_calendar_mark_day (GTK_CALENDAR (gtk_builder_get_object (builder,
1390 "GNUNET_setup_calendar")),
1391 ymd->tm_mday);
1392 dialog = GTK_WINDOW (gtk_builder_get_object
1393 (builder, "GNUNET_setup_calendar_dialog"));
1394 gtk_window_present (dialog);
1395}
1396
1397
1381/** 1398/**
1382 * A button was pressed in the GtkTreeView, check for right button and 1399 * A button was pressed in the GtkTreeView, check for right button and
1383 * if applicable create the popup menu. 1400 * if applicable create the popup menu.
@@ -1515,12 +1532,12 @@ zone_iteration_proc (void *cls,
1515 GtkTreeIter iter_record; 1532 GtkTreeIter iter_record;
1516 GtkEntry *pseu_entry; 1533 GtkEntry *pseu_entry;
1517 int c; 1534 int c;
1518 int time_is_relative;
1519 struct GNUNET_CRYPTO_ShortHashAsciiEncoded shenc; 1535 struct GNUNET_CRYPTO_ShortHashAsciiEncoded shenc;
1520 char *exp; 1536 char *exp;
1521 char *val; 1537 char *val;
1522 char * type_str; 1538 char * type_str;
1523 int public; 1539 gboolean time_is_relative;
1540 gboolean public;
1524 guint64 exp_t; 1541 guint64 exp_t;
1525 1542
1526 GNUNET_assert (NULL != zc_ctx); 1543 GNUNET_assert (NULL != zc_ctx);
@@ -1569,26 +1586,16 @@ zone_iteration_proc (void *cls,
1569 c, rd[c].record_type, rd[c].flags, rd[c].expiration_time, rd[c].data_size); 1586 c, rd[c].record_type, rd[c].flags, rd[c].expiration_time, rd[c].data_size);
1570 1587
1571 /* Set public toggle */ 1588 /* Set public toggle */
1572 if ((rd[c].flags & GNUNET_NAMESTORE_RF_PRIVATE) == GNUNET_NAMESTORE_RF_PRIVATE) 1589 public = ((rd[c].flags & GNUNET_NAMESTORE_RF_PRIVATE) != GNUNET_NAMESTORE_RF_PRIVATE);
1573 {
1574 public = GNUNET_NO;
1575 }
1576 else
1577 {
1578 public = GNUNET_YES;
1579 }
1580
1581 /* Expiration time */ 1590 /* Expiration time */
1582 time_is_relative = GNUNET_NO; 1591 time_is_relative = (0 != (rd[c].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION));
1583 1592 if (time_is_relative)
1584 if (GNUNET_YES == time_is_relative)
1585 { 1593 {
1586 /* TODO: FIX THIS WHEN WE HAVE RELATIVE TIME */ 1594 struct GNUNET_TIME_Relative rel_time;
1587 struct GNUNET_TIME_Relative rel_time = GNUNET_TIME_UNIT_ZERO; 1595
1588 struct GNUNET_TIME_Absolute exp_abs; 1596 rel_time.rel_value = rd[c].expiration_time;
1589 exp_abs = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), rel_time); 1597 exp_t = rel_time.rel_value;
1590 exp_t = exp_abs.abs_value; 1598 exp = GNUNET_STRINGS_relative_time_to_string (rel_time);
1591 exp = convert_time_to_string (exp_abs);
1592 } 1599 }
1593 else 1600 else
1594 { 1601 {
@@ -1596,21 +1603,21 @@ zone_iteration_proc (void *cls,
1596 1603
1597 exp_abs.abs_value = rd[c].expiration_time; 1604 exp_abs.abs_value = rd[c].expiration_time;
1598 exp_t = exp_abs.abs_value; 1605 exp_t = exp_abs.abs_value;
1599 exp = convert_time_to_string (exp_abs); 1606 exp = GNUNET_STRINGS_absolute_time_to_string (exp_abs);
1600 } 1607 }
1601 /* value */ 1608 /* value */
1602 val = GNUNET_NAMESTORE_value_to_string (rd[c].record_type, 1609 val = GNUNET_NAMESTORE_value_to_string (rd[c].record_type,
1603 rd[c].data, 1610 rd[c].data,
1604 rd[c].data_size); 1611 rd[c].data_size);
1605 if (NULL == val) 1612 if (NULL == val)
1606 GNUNET_asprintf(&val, "%s", EXPIRE_INVALID_STRING); 1613 GNUNET_asprintf (&val, "%s", EXPIRE_INVALID_STRING);
1607 1614
1608 if (NULL != GNUNET_NAMESTORE_number_to_typename(rd[c].record_type)) 1615 if (NULL != GNUNET_NAMESTORE_number_to_typename(rd[c].record_type))
1609 type_str = strdup (GNUNET_NAMESTORE_number_to_typename(rd[c].record_type)); 1616 type_str = strdup (GNUNET_NAMESTORE_number_to_typename(rd[c].record_type));
1610 else 1617 else
1611 GNUNET_asprintf(&type_str, "%s", EXPIRE_INVALID_STRING); 1618 GNUNET_asprintf(&type_str, "%s", EXPIRE_INVALID_STRING);
1612 1619
1613 if ((0 ==strcmp (name, ROOT_STR)) && (GNUNET_NAMESTORE_TYPE_PSEU == rd[c].record_type)) 1620 if ((0 == strcmp (name, ROOT_STR)) && (GNUNET_NAMESTORE_TYPE_PSEU == rd[c].record_type))
1614 { 1621 {
1615 zc_ctx->label = strdup(val); 1622 zc_ctx->label = strdup(val);
1616 iteration = GNUNET_YES; 1623 iteration = GNUNET_YES;