aboutsummaryrefslogtreecommitdiff
path: root/src/anastasis/anastasis-gtk_pe-edit-policy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/anastasis/anastasis-gtk_pe-edit-policy.c')
-rw-r--r--src/anastasis/anastasis-gtk_pe-edit-policy.c295
1 files changed, 149 insertions, 146 deletions
diff --git a/src/anastasis/anastasis-gtk_pe-edit-policy.c b/src/anastasis/anastasis-gtk_pe-edit-policy.c
index f0ac3fb..6803cc2 100644
--- a/src/anastasis/anastasis-gtk_pe-edit-policy.c
+++ b/src/anastasis/anastasis-gtk_pe-edit-policy.c
@@ -50,7 +50,7 @@ struct LineContext
* Kept in a DLL.
*/
struct LineContext *prev;
-
+
/**
* Context this line context belongs with.
*/
@@ -60,17 +60,17 @@ struct LineContext
* Our combo box.
*/
GtkComboBox *cb;
-
+
/**
* Model for our combo box.
*/
GtkTreeModel *model;
-
+
/**
- * Challenge index for this line.
+ * Challenge index for this line.
*/
unsigned int cindex;
-
+
/**
* Is this challenge used?
*/
@@ -107,7 +107,7 @@ struct EditDialogContext
/**
- * Handle the response from the edit dialog.
+ * Handle the response from the edit dialog.
*
* @param dialog the dialog
* @param response_id what the user's action was
@@ -124,65 +124,66 @@ anastasis_gtk_policy_edit_dialog_response_cb (
if (GTK_RESPONSE_OK == response_id)
{
json_t *policy;
-
+
policy = json_array ();
GNUNET_assert (NULL != policy);
for (struct LineContext *lctx = edc->lc_head;
- NULL != lctx;
- lctx = lctx->next)
+ NULL != lctx;
+ lctx = lctx->next)
{
GtkTreeIter iter;
gchar *url;
-
+
if (! lctx->on)
- continue;
+ continue;
if (! gtk_combo_box_get_active_iter (lctx->cb,
- &iter))
+ &iter))
{
- GNUNET_break (0);
- continue;
+ GNUNET_break (0);
+ continue;
}
gtk_tree_model_get (lctx->model,
- &iter,
- 0, &url,
- -1);
- GNUNET_break (0 ==
- json_array_append_new (policy,
- json_pack ("{s:I, s:s}",
- "authentication_method",
- (json_int_t) lctx->cindex,
- "provider",
- url)));
+ &iter,
+ 0, &url,
+ -1);
+ GNUNET_assert (0 ==
+ json_array_append_new (
+ policy,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("authentication_method",
+ lctx->cindex),
+ GNUNET_JSON_pack_string ("provider",
+ url))));
g_free (url);
}
if (UINT_MAX == edc->pindex)
{
json_t *args;
- args = json_pack ("{s:o}",
- "policy",
- (json_int_t) policy);
+ args = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_array_steal ("policy",
+ policy));
AG_ra = ANASTASIS_redux_action (AG_redux_state,
- "add_policy",
- args,
- &AG_action_cb,
- NULL);
+ "add_policy",
+ args,
+ &AG_action_cb,
+ NULL);
json_decref (args);
}
else
{
json_t *args;
- args = json_pack ("{s:I, s:o}",
- "policy_index",
- (json_int_t) edc->pindex,
- "policy",
- policy);
+ args = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("policy_index",
+ edc->pindex),
+ GNUNET_JSON_pack_array_steal ("policy",
+ policy));
AG_ra = ANASTASIS_redux_action (AG_redux_state,
- "update_policy",
- args,
- &AG_action_cb,
- NULL);
+ "update_policy",
+ args,
+ &AG_action_cb,
+ NULL);
json_decref (args);
}
}
@@ -190,11 +191,11 @@ anastasis_gtk_policy_edit_dialog_response_cb (
{
struct LineContext *lctx;
- while (NULL != (lctx =edc->lc_head))
+ while (NULL != (lctx = edc->lc_head))
{
GNUNET_CONTAINER_DLL_remove (edc->lc_head,
- edc->lc_tail,
- lctx);
+ edc->lc_tail,
+ lctx);
GNUNET_free (lctx);
}
}
@@ -224,23 +225,23 @@ combo_box_changed_cb (
/* Update our line context's on/off flag */
{
GtkTreeIter iter;
-
+
if (! gtk_combo_box_get_active_iter (lc->cb,
- &iter))
+ &iter))
{
GNUNET_break (0);
}
else
{
gchar *url;
-
+
gtk_tree_model_get (lc->model,
- &iter,
- 0, &url,
- -1);
+ &iter,
+ 0, &url,
+ -1);
lc->on = (0 !=
- strcmp (_("<off>"),
- url));
+ strcmp (_ ("<off>"),
+ url));
g_free (url);
}
}
@@ -250,13 +251,13 @@ combo_box_changed_cb (
bool legal = false;
for (struct LineContext *lctx = edc->lc_head;
- NULL != lctx;
- lctx = lctx->next)
+ NULL != lctx;
+ lctx = lctx->next)
legal |= lctx->on;
ok_button = GTK_WIDGET (gtk_builder_get_object (edc->builder,
- "ok_button"));
+ "ok_button"));
gtk_widget_set_sensitive (ok_button,
- legal);
+ legal);
}
}
@@ -268,31 +269,31 @@ combo_box_changed_cb (
* @param type method to check for
* @param ap provider to check against
* @return true if @a ap offers @a type
- */
+ */
static bool
ap_matches (const char *type,
- json_t *ap)
+ json_t *ap)
{
json_t *methods;
size_t index;
json_t *method;
methods = json_object_get (ap,
- "methods");
+ "methods");
GNUNET_break (NULL != methods);
json_array_foreach (methods, index, method)
{
const char *offer;
offer = json_string_value (json_object_get (method,
- "type"));
+ "type"));
if (NULL == offer)
{
GNUNET_break (0);
continue;
}
if (0 == strcasecmp (type,
- offer))
+ offer))
return true;
}
return false;
@@ -301,7 +302,7 @@ ap_matches (const char *type,
/**
* Create a GtkListStore containing all of the URLs
- * of Anastasis providers offering @a type as an
+ * of Anastasis providers offering @a type as an
* authentication method.
*
* @return the model
@@ -315,26 +316,26 @@ make_model (const char *type)
json_t *ap;
ls = gtk_list_store_new (1,
- G_TYPE_STRING);
+ G_TYPE_STRING);
gtk_list_store_insert_with_values (ls,
- NULL,
- -1,
- 0, _("<off>"),
- -1);
+ NULL,
+ -1,
+ 0, _ ("<off>"),
+ -1);
aps = json_object_get (AG_redux_state,
- "authentication_providers");
+ "authentication_providers");
GNUNET_break (NULL != aps);
json_object_foreach (aps, url, ap) {
if (ap_matches (type,
- ap))
+ ap))
{
gtk_list_store_insert_with_values (ls,
- NULL,
- -1,
- 0, url,
- -1);
+ NULL,
+ -1,
+ 0, url,
+ -1);
}
- }
+ }
return GTK_TREE_MODEL (ls);
}
@@ -348,12 +349,12 @@ make_model (const char *type)
*/
static void
select_by_url (const char *url,
- struct LineContext *lctx)
+ struct LineContext *lctx)
{
GtkTreeIter iter;
if (! gtk_tree_model_get_iter_first (lctx->model,
- &iter))
+ &iter))
{
GNUNET_break (0);
return;
@@ -362,21 +363,21 @@ select_by_url (const char *url,
gchar *have;
gtk_tree_model_get (lctx->model,
- &iter,
- 0, &have,
- -1);
+ &iter,
+ 0, &have,
+ -1);
if (0 == strcmp (have,
- url))
+ url))
{
gtk_combo_box_set_active_iter (lctx->cb,
- &iter);
+ &iter);
lctx->on = true;
g_free (have);
return;
}
g_free (have);
} while (gtk_tree_model_iter_next (lctx->model,
- &iter));
+ &iter));
GNUNET_break (0); /* not found */
}
@@ -390,31 +391,31 @@ select_by_url (const char *url,
*/
static void
select_by_policy (const json_t *methods,
- struct LineContext *lctx)
+ struct LineContext *lctx)
{
size_t index;
json_t *method;
GtkTreeIter iter;
if (! gtk_tree_model_get_iter_first (lctx->model,
- &iter))
+ &iter))
{
GNUNET_break (0);
return;
}
gtk_combo_box_set_active_iter (lctx->cb,
- &iter);
+ &iter);
json_array_foreach (methods, index, method) {
- json_int_t am = json_integer_value (json_object_get (method,\
- "authentication_method"));
+ json_int_t am = json_integer_value (json_object_get (method, \
+ "authentication_method"));
const char *url;
-
+
if (am != lctx->cindex)
continue;
url = json_string_value (json_object_get (method,
- "provider"));
+ "provider"));
select_by_url (url,
- lctx);
+ lctx);
break;
}
}
@@ -426,10 +427,10 @@ AG_edit_policy (guint pindex)
struct EditDialogContext *edc;
GtkGrid *grid;
json_t *methods = NULL;
-
+
edc = GNUNET_new (struct EditDialogContext);
edc->builder = GNUNET_GTK_get_new_builder ("anastasis_gtk_edit_policy.glade",
- edc);
+ edc);
edc->pindex = pindex;
if (NULL == edc->builder)
{
@@ -443,18 +444,18 @@ AG_edit_policy (guint pindex)
json_t *policy;
policies = json_object_get (AG_redux_state,
- "policies");
+ "policies");
policy = json_array_get (policies,
- pindex);
+ pindex);
methods = json_object_get (policy,
- "methods");
+ "methods");
GNUNET_break (NULL != methods);
}
grid = GTK_GRID (gtk_builder_get_object (edc->builder,
- "policy_grid"));
+ "policy_grid"));
{
json_t *ams = json_object_get (AG_redux_state,
- "authentication_methods");
+ "authentication_methods");
json_t *am;
size_t index;
gint row = 1;
@@ -464,10 +465,10 @@ AG_edit_policy (guint pindex)
const char *instructions;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_string ("type",
- &type),
- GNUNET_JSON_spec_string ("instructions",
- &instructions),
- GNUNET_JSON_spec_end ()
+ &type),
+ GNUNET_JSON_spec_string ("instructions",
+ &instructions),
+ GNUNET_JSON_spec_end ()
};
char *labels;
GtkWidget *label;
@@ -475,69 +476,69 @@ AG_edit_policy (guint pindex)
struct LineContext *lctx;
if (GNUNET_OK !=
- GNUNET_JSON_parse (am,
- spec,
- NULL, NULL))
+ GNUNET_JSON_parse (am,
+ spec,
+ NULL, NULL))
{
- GNUNET_break (0);
- continue;
+ GNUNET_break (0);
+ continue;
}
lctx = GNUNET_new (struct LineContext);
lctx->cindex = index;
GNUNET_asprintf (&labels,
- "<b>%s</b>: %s",
- type,
- instructions);
+ "<b>%s</b>: %s",
+ type,
+ instructions);
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label),
- labels);
+ labels);
GNUNET_free (labels);
lctx->model = make_model (type);
cb = gtk_combo_box_new_with_model (lctx->model);
lctx->cb = GTK_COMBO_BOX (cb);
{
- GtkCellRenderer *renderer;
-
- renderer = gtk_cell_renderer_text_new ();
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cb),
- renderer,
- true);
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (cb),
- renderer,
- "text",
- 0);
+ GtkCellRenderer *renderer;
+
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cb),
+ renderer,
+ true);
+ gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (cb),
+ renderer,
+ "text",
+ 0);
}
lctx->edc = edc;
GNUNET_CONTAINER_DLL_insert (edc->lc_head,
- edc->lc_tail,
- lctx);
+ edc->lc_tail,
+ lctx);
g_object_connect (cb,
- "signal::changed",
- &combo_box_changed_cb, lctx,
- NULL);
+ "signal::changed",
+ &combo_box_changed_cb, lctx,
+ NULL);
if (NULL != methods)
- select_by_policy (methods,
- lctx);
+ select_by_policy (methods,
+ lctx);
gtk_grid_insert_row (grid,
- row);
+ row);
gtk_widget_show (label);
gtk_grid_attach (grid,
- label,
- 0,
- row,
- 1,
- 1);
+ label,
+ 0,
+ row,
+ 1,
+ 1);
g_object_set (cb,
- "expand",
- TRUE,
- NULL);
+ "expand",
+ TRUE,
+ NULL);
gtk_widget_show (cb);
gtk_grid_attach (grid,
- cb,
- 1,
- row,
- 1,
- 1);
+ cb,
+ 1,
+ row,
+ 1,
+ 1);
row++;
}
}
@@ -547,20 +548,22 @@ AG_edit_policy (guint pindex)
GtkWidget *anchor;
GtkRequisition req;
- anchor = GTK_WIDGET (GCG_get_main_window_object ("anastasis_gtk_main_window_quit_button"));
+ anchor = GTK_WIDGET (GCG_get_main_window_object (
+ "anastasis_gtk_main_window_quit_button"));
toplevel = gtk_widget_get_toplevel (anchor);
ad = GTK_WIDGET (gtk_builder_get_object (edc->builder,
- "anastasis_gtk_policy_edit_dialog"));
+ "anastasis_gtk_policy_edit_dialog"));
gtk_widget_get_preferred_size (ad,
- NULL,
- &req);
+ NULL,
+ &req);
gtk_window_resize (GTK_WINDOW (ad),
- req.width,
- req.height);
+ req.width,
+ req.height);
gtk_window_set_transient_for (GTK_WINDOW (ad),
GTK_WINDOW (toplevel));
gtk_window_present (GTK_WINDOW (ad));
}
}
+
/* end of anastasis-gtk_pe-edit-policy.c */