Merge lp:~rodrigo-moya/evolution-couchdb/allow-per-user-couchdb into lp:evolution-couchdb

Proposed by Rodrigo Moya
Status: Merged
Approved by: Elliot Murphy
Approved revision: 42
Merge reported by: Rodrigo Moya
Merged at revision: not available
Proposed branch: lp:~rodrigo-moya/evolution-couchdb/allow-per-user-couchdb
Merge into: lp:evolution-couchdb
Diff against target: None lines
To merge this branch: bzr merge lp:~rodrigo-moya/evolution-couchdb/allow-per-user-couchdb
Reviewer Review Type Date Requested Status
Elliot Murphy (community) Approve
John O'Brien (community) Abstain
dobey (community) Approve
Review via email: mp+9185@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Rodrigo Moya (rodrigo-moya) wrote :

Added UI for selecting different CouchDB instances (per user, system wide and remote server)

Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
John O'Brien (jdobrien) wrote :

This code looks good to me although I haven't written C code in >10 years.
I also don't have a simple way of testing it.

I'm not disapproving this, but I feel uncomfortable approving something I am so unfamiliar with.

review: Abstain
Revision history for this message
Elliot Murphy (statik) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/couchdb-contacts-source.c'
2--- plugins/couchdb-contacts-source.c 2009-07-07 14:51:03 +0000
3+++ plugins/couchdb-contacts-source.c 2009-07-23 10:42:13 +0000
4@@ -138,12 +138,77 @@
5 }
6 }
7
8+typedef struct {
9+ ESource *source;
10+ GtkWidget *vbox;
11+ GtkWidget *user_db_button;
12+ GtkWidget *system_db_button;
13+ GtkWidget *remote_db_button;
14+ GtkWidget *remote_db_entry;
15+} UIData;
16+
17+static void
18+destroy_ui_data (gpointer data)
19+{
20+ UIData *ui = data;
21+
22+ if (ui) {
23+ gtk_widget_destroy (ui->vbox);
24+ g_object_unref (ui->source);
25+ g_free (ui);
26+ }
27+}
28+
29+static void
30+on_user_db_toggled (GtkToggleButton *button, gpointer *user_data)
31+{
32+ UIData *ui = (UIData *) user_data;
33+
34+ if (gtk_toggle_button_get_active (button)) {
35+ e_source_set_property (ui->source, "couchdb_instance", "user");
36+ gtk_widget_set_sensitive (ui->remote_db_entry, FALSE);
37+ }
38+}
39+
40+static void
41+on_system_db_toggled (GtkToggleButton *button, gpointer *user_data)
42+{
43+ UIData *ui = (UIData *) user_data;
44+
45+ if (gtk_toggle_button_get_active (button)) {
46+ e_source_set_property (ui->source, "couchdb_instance", "system");
47+ gtk_widget_set_sensitive (ui->remote_db_entry, FALSE);
48+ }
49+}
50+
51+static void
52+on_remote_db_toggled (GtkToggleButton *button, gpointer *user_data)
53+{
54+ UIData *ui = (UIData *) user_data;
55+
56+ if (gtk_toggle_button_get_active (button)) {
57+ e_source_set_property (ui->source, "couchdb_instance", "remote");
58+ gtk_widget_set_sensitive (ui->remote_db_entry, TRUE);
59+ }
60+}
61+
62+static on_remote_db_changed (GtkEditable *entry, gpointer user_data)
63+{
64+ UIData *ui = (UIData *) user_data;
65+
66+ e_source_set_property (ui->source, "couchdb_remote_server", gtk_entry_get_text (GTK_ENTRY (entry)));
67+}
68+
69 GtkWidget *
70 plugin_couchdb_contacts (EPlugin *epl, EConfigHookItemFactoryData *data)
71 {
72 ESource *source;
73 ESourceGroup *group;
74 const gchar *base_uri;
75+ GtkWidget *parent, *parent_vbox;
76+ GtkWidget *table, *label;
77+ UIData *ui;
78+ const gchar *property;
79 EABConfigTargetSource *t = (EABConfigTargetSource *) data->target;
80
81 source = t->source;
82@@ -156,6 +221,69 @@
83 if (strcmp(base_uri, COUCHDB_BASE_URI) != 0)
84 return NULL;
85
86+ /* Build up the UI */
87+ ui = g_new0 (UIData, 1);
88+ ui->source = g_object_ref (source);
89+
90+ parent = data->parent;
91+ parent_vbox = gtk_widget_get_ancestor (gtk_widget_get_parent (parent), GTK_TYPE_VBOX);
92+
93+ ui->vbox = gtk_vbox_new (FALSE, 6);
94+ gtk_box_pack_start (GTK_BOX (parent_vbox), ui->vbox, FALSE, FALSE, 0);
95+
96+ label = gtk_label_new (NULL);
97+ gtk_label_set_markup (GTK_LABEL (label), _("<b>Server</b>"));
98+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
99+ gtk_box_pack_start (GTK_BOX (ui->vbox), label, FALSE, FALSE, 0);
100+
101+ table = gtk_table_new (3, 2, FALSE);
102+ gtk_box_pack_start (GTK_BOX (ui->vbox), table, TRUE, TRUE, 0);
103+
104+ ui->user_db_button = gtk_radio_button_new_with_label (NULL, _("User local database"));
105+ gtk_table_attach (GTK_TABLE (table), ui->user_db_button, 0, 2, 0, 1,
106+ GTK_EXPAND | GTK_FILL, GTK_FILL, 3, 3);
107+
108+ ui->system_db_button = gtk_radio_button_new_with_label (
109+ gtk_radio_button_get_group (GTK_RADIO_BUTTON (ui->user_db_button)),
110+ _("System wide database"));
111+ gtk_table_attach (GTK_TABLE (table), ui->system_db_button, 0, 2, 1, 2,
112+ GTK_EXPAND | GTK_FILL, GTK_FILL, 3, 3);
113+
114+ ui->remote_db_button = gtk_radio_button_new_with_label (
115+ gtk_radio_button_get_group (GTK_RADIO_BUTTON (ui->user_db_button)),
116+ _("Remote database"));
117+ gtk_table_attach (GTK_TABLE (table), ui->remote_db_button, 0, 1, 2, 3,
118+ GTK_EXPAND | GTK_FILL, GTK_FILL, 3, 3);
119+ ui->remote_db_entry = gtk_entry_new ();
120+ gtk_table_attach (GTK_TABLE (table), ui->remote_db_entry, 1, 2, 2, 3,
121+ GTK_EXPAND | GTK_FILL, GTK_FILL, 3, 3);
122+
123+ gtk_widget_show_all (ui->vbox);
124+
125+ /* Set values from the source */
126+ property = e_source_get_property (ui->source, "couchdb_instance");
127+ if (g_strcmp0 (property, "system") == 0) {
128+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ui->system_db_button), TRUE);
129+ gtk_widget_set_sensitive (ui->remote_db_entry, FALSE);
130+ } else if (g_strcmp0 (property, "remote") == 0) {
131+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ui->remote_db_button), TRUE);
132+ gtk_widget_set_sensitive (ui->remote_db_entry, TRUE);
133+ gtk_entry_set_text (GTK_ENTRY (ui->remote_db_entry),
134+ e_source_get_property (ui->source, "couchdb_remote_server"));
135+ } else {
136+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ui->user_db_button), TRUE);
137+ gtk_widget_set_sensitive (ui->remote_db_entry, FALSE);
138+ }
139+
140+ g_object_set_data_full (G_OBJECT (epl), "gwidget", ui, destroy_ui_data);
141+ g_signal_connect (ui->vbox, "destroy", G_CALLBACK (gtk_widget_destroyed), &ui->vbox);
142+
143+ /* Signals */
144+ g_signal_connect (G_OBJECT (ui->user_db_button), "toggled", G_CALLBACK (on_user_db_toggled), ui);
145+ g_signal_connect (G_OBJECT (ui->system_db_button), "toggled", G_CALLBACK (on_system_db_toggled), ui);
146+ g_signal_connect (G_OBJECT (ui->remote_db_button), "toggled", G_CALLBACK (on_remote_db_toggled), ui);
147+ g_signal_connect (G_OBJECT (ui->remote_db_entry), "changed", G_CALLBACK (on_remote_db_changed), ui);
148+
149 return NULL;
150 }
151

Subscribers

People subscribed via source and target branches