Status: | Merged |
---|---|
Approved by: | Paweł Forysiuk |
Approved revision: | 6352 |
Merged at revision: | 6375 |
Proposed branch: | lp:~cavalier/midori/consec |
Merge into: | lp:midori |
Diff against target: |
447 lines (+370/-2) 2 files modified
extensions/cookie-permissions/cookie-permission-manager-preferences-window.c (+93/-1) extensions/nojs/nojs-preferences.c (+277/-1) |
To merge this branch: | bzr merge lp:~cavalier/midori/consec |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Midori Devs | Pending | ||
Review via email:
|
Commit message
Unify nojs and cookie policy dialogs, make policy changeable within the list
Description of the change
Make the nojs and cookies dialog consistent.
Also make the policy changeable within the list.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'extensions/cookie-permissions/cookie-permission-manager-preferences-window.c' |
2 | --- extensions/cookie-permissions/cookie-permission-manager-preferences-window.c 2013-08-12 19:15:42 +0000 |
3 | +++ extensions/cookie-permissions/cookie-permission-manager-preferences-window.c 2013-09-02 20:12:15 +0000 |
4 | @@ -43,6 +43,7 @@ |
5 | GtkListStore *listStore; |
6 | GtkWidget *list; |
7 | GtkTreeSelection *listSelection; |
8 | + GtkWidget *editingCombo; |
9 | GtkWidget *deleteButton; |
10 | GtkWidget *deleteAllButton; |
11 | GtkWidget *askForUnknownPolicyCheckbox; |
12 | @@ -345,6 +346,93 @@ |
13 | g_signal_handler_unblock(priv->manager, priv->signalManagerAskForUnknownPolicyID); |
14 | } |
15 | |
16 | +static void _cookie_permission_manager_preferences_on_policy_editing_started(CookiePermissionManagerPreferencesWindow *self, |
17 | + GtkCellEditable *editable, |
18 | + gchar *path, |
19 | + gpointer *inUserData) |
20 | +{ |
21 | + CookiePermissionManagerPreferencesWindowPrivate *priv=self->priv; |
22 | + |
23 | + priv->editingCombo=NULL; |
24 | + |
25 | + if(!GTK_IS_COMBO_BOX(editable)) return; |
26 | + |
27 | + priv->editingCombo=GTK_WIDGET(editable); |
28 | +} |
29 | + |
30 | +static void _cookie_permission_manager_preferences_on_policy_editing_canceled(CookiePermissionManagerPreferencesWindow *self, |
31 | + gpointer *inUserData) |
32 | +{ |
33 | + CookiePermissionManagerPreferencesWindowPrivate *priv=self->priv; |
34 | + |
35 | + priv->editingCombo=NULL; |
36 | +} |
37 | + |
38 | +static void _cookie_permission_manager_preferences_on_policy_edited(CookiePermissionManagerPreferencesWindow *self, |
39 | + gchar *path, |
40 | + gchar *newText, |
41 | + gpointer *inUserData) |
42 | +{ |
43 | + CookiePermissionManagerPreferencesWindowPrivate *priv=self->priv; |
44 | + gchar *domain; |
45 | + GtkTreeIter iter; |
46 | + GtkTreeIter policyIter; |
47 | + |
48 | + g_return_if_fail(priv->database); |
49 | + |
50 | + if (priv->editingCombo == NULL) return; |
51 | + |
52 | + gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(priv->listStore), &iter, path); |
53 | + |
54 | + gtk_tree_model_get(GTK_TREE_MODEL(priv->listStore), |
55 | + &iter, |
56 | + DOMAIN_COLUMN, &domain, |
57 | + -1); |
58 | + |
59 | + /* Get policy from combo box */ |
60 | + if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(priv->editingCombo), &policyIter)) |
61 | + { |
62 | + gchar *sql; |
63 | + gchar *error=NULL; |
64 | + gint success; |
65 | + gint policy; |
66 | + gchar *policyName; |
67 | + |
68 | + /* Get policy value to set for domain */ |
69 | + gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(priv->editingCombo)), |
70 | + &policyIter, |
71 | + 0, &policy, |
72 | + 1, &policyName, |
73 | + -1); |
74 | + |
75 | + g_return_if_fail(g_strcmp0(policyName, newText)==0); |
76 | + |
77 | + /* Add domain name and the selected policy to database */ |
78 | + sql=sqlite3_mprintf("UPDATE policies SET value = %d WHERE domain = '%q';", |
79 | + policy, |
80 | + domain); |
81 | + success=sqlite3_exec(priv->database, sql, NULL, NULL, &error); |
82 | + |
83 | + /* Show error message if any */ |
84 | + if(success==SQLITE_OK) |
85 | + { |
86 | + gtk_list_store_set(priv->listStore, |
87 | + &iter, |
88 | + POLICY_COLUMN, newText, |
89 | + -1); |
90 | + } |
91 | + else g_warning(_("SQL fails: %s"), error); |
92 | + |
93 | + |
94 | + if(error) sqlite3_free(error); |
95 | + |
96 | + /* Free allocated resources */ |
97 | + sqlite3_free(sql); |
98 | + } |
99 | + |
100 | + priv->editingCombo=NULL; |
101 | +} |
102 | + |
103 | /* Selection in list changed */ |
104 | void _cookie_permission_manager_preferences_changed_selection(CookiePermissionManagerPreferencesWindow *self, |
105 | GtkTreeSelection *inSelection) |
106 | @@ -744,7 +832,11 @@ |
107 | gtk_tree_view_column_set_sort_column_id(column, DOMAIN_COLUMN); |
108 | gtk_tree_view_append_column(GTK_TREE_VIEW(priv->list), column); |
109 | |
110 | - renderer=gtk_cell_renderer_text_new(); |
111 | + renderer=gtk_cell_renderer_combo_new(); |
112 | + g_object_set(G_OBJECT(renderer), "model", list, "text-column", 1, "has-entry", false, "editable", true, NULL); |
113 | + g_signal_connect_swapped(renderer, "editing-started", G_CALLBACK(_cookie_permission_manager_preferences_on_policy_editing_started), self); |
114 | + g_signal_connect_swapped(renderer, "editing-canceled", G_CALLBACK(_cookie_permission_manager_preferences_on_policy_editing_canceled), self); |
115 | + g_signal_connect_swapped(renderer, "edited", G_CALLBACK(_cookie_permission_manager_preferences_on_policy_edited), self); |
116 | column=gtk_tree_view_column_new_with_attributes(_("Policy"), |
117 | renderer, |
118 | "text", POLICY_COLUMN, |
119 | |
120 | === modified file 'extensions/nojs/nojs-preferences.c' |
121 | --- extensions/nojs/nojs-preferences.c 2013-08-12 19:19:57 +0000 |
122 | +++ extensions/nojs/nojs-preferences.c 2013-09-02 20:12:15 +0000 |
123 | @@ -43,11 +43,15 @@ |
124 | GtkListStore *listStore; |
125 | GtkWidget *list; |
126 | GtkTreeSelection *listSelection; |
127 | + GtkWidget *editingCombo; |
128 | GtkWidget *deleteButton; |
129 | GtkWidget *deleteAllButton; |
130 | GtkWidget *allowAllSitesCheckbox; |
131 | GtkWidget *blockUnknownDomainsCheckbox; |
132 | GtkWidget *checkSecondLevelOnlyCheckbox; |
133 | + GtkWidget *addDomainEntry; |
134 | + GtkWidget *addDomainPolicyCombo; |
135 | + GtkWidget *addDomainButton; |
136 | |
137 | gint signalAllowAllSitesToggledID; |
138 | gint signalBlockUnknownDomainsToggledID; |
139 | @@ -69,6 +73,149 @@ |
140 | |
141 | /* IMPLEMENTATION: Private variables and methods */ |
142 | |
143 | +/* "Add domain"-button was pressed */ |
144 | +static void _nojs_preferences_on_add_domain_clicked(NoJSPreferences *self, |
145 | + gpointer *inUserData) |
146 | +{ |
147 | + NoJSPreferencesPrivate *priv=self->priv; |
148 | + gchar *domain; |
149 | + const gchar *domainStart, *domainEnd; |
150 | + gchar *realDomain; |
151 | + GtkTreeIter policyIter; |
152 | + |
153 | + g_return_if_fail(priv->database); |
154 | + |
155 | + /* Get domain name entered */ |
156 | + domain=g_hostname_to_ascii(gtk_entry_get_text(GTK_ENTRY(priv->addDomainEntry))); |
157 | + |
158 | + /* Trim whitespaces from start and end of entered domain name */ |
159 | + domainStart=domain; |
160 | + while(*domainStart && g_ascii_isspace(*domainStart)) domainStart++; |
161 | + |
162 | + domainEnd=domain+strlen(domain)-1; |
163 | + while(*domainEnd && g_ascii_isspace(*domainEnd)) domainEnd--; |
164 | + if(domainEnd<=domainStart) return; |
165 | + |
166 | + /* Seperate domain name from whitespaces */ |
167 | + realDomain=g_strndup(domain, domainEnd-domainStart+1); |
168 | + if(!realDomain) return; |
169 | + |
170 | + /* Get policy from combo box */ |
171 | + if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(priv->addDomainPolicyCombo), &policyIter)) |
172 | + { |
173 | + gchar *sql; |
174 | + gchar *error=NULL; |
175 | + gint success; |
176 | + gint policy; |
177 | + gchar *policyName; |
178 | + |
179 | + /* Get policy value to set for domain */ |
180 | + gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(priv->addDomainPolicyCombo)), |
181 | + &policyIter, |
182 | + 0, &policy, |
183 | + 1, &policyName, |
184 | + -1); |
185 | + |
186 | + /* Add domain name and the selected policy to database */ |
187 | + sql=sqlite3_mprintf("INSERT OR REPLACE INTO policies (site, value) VALUES ('%q', %d);", |
188 | + realDomain, |
189 | + policy); |
190 | + success=sqlite3_exec(priv->database, sql, NULL, NULL, &error); |
191 | + |
192 | + /* Show error message if any */ |
193 | + if(success==SQLITE_OK) |
194 | + { |
195 | + gtk_list_store_append(priv->listStore, &policyIter); |
196 | + gtk_list_store_set(priv->listStore, |
197 | + &policyIter, |
198 | + DOMAIN_COLUMN, realDomain, |
199 | + POLICY_COLUMN, policyName, |
200 | + -1); |
201 | + } |
202 | + else g_warning(_("SQL fails: %s"), error); |
203 | + |
204 | + |
205 | + if(error) sqlite3_free(error); |
206 | + |
207 | + /* Free allocated resources */ |
208 | + sqlite3_free(sql); |
209 | + } |
210 | + |
211 | + /* Free allocated resources */ |
212 | + g_free(realDomain); |
213 | + g_free(domain); |
214 | +} |
215 | + |
216 | +/* Entry containing domain name which may be added to list has changed */ |
217 | +static void _nojs_preferences_on_add_domain_entry_changed(NoJSPreferences *self, |
218 | + GtkEditable *inEditable) |
219 | +{ |
220 | + NoJSPreferencesPrivate *priv=self->priv; |
221 | + gchar *asciiDomain, *checkAsciiDomain; |
222 | + gchar *asciiDomainStart, *asciiDomainEnd; |
223 | + gint dots; |
224 | + gboolean isValid=FALSE; |
225 | + |
226 | + /* Get ASCII representation of domain name entered */ |
227 | + asciiDomain=g_hostname_to_ascii(gtk_entry_get_text(GTK_ENTRY(priv->addDomainEntry))); |
228 | + |
229 | + /* Trim whitespaces from start and end of entered domain name */ |
230 | + asciiDomainStart=asciiDomain; |
231 | + while(*asciiDomainStart && g_ascii_isspace(*asciiDomainStart)) asciiDomainStart++; |
232 | + |
233 | + asciiDomainEnd=asciiDomain+strlen(asciiDomain)-1; |
234 | + while(*asciiDomainEnd && g_ascii_isspace(*asciiDomainEnd)) asciiDomainEnd--; |
235 | + |
236 | + /* We allow only domain names and not cookie domain name so entered name |
237 | + * must not start with a dot |
238 | + */ |
239 | + checkAsciiDomain=asciiDomainStart; |
240 | + isValid=(*asciiDomainStart!='.' && *asciiDomainEnd!='.'); |
241 | + |
242 | + /* Now check if ASCII domain name is valid (very very simple check) |
243 | + * and contains a hostname besides TLD |
244 | + */ |
245 | + dots=0; |
246 | + |
247 | + while(*checkAsciiDomain && |
248 | + checkAsciiDomain<=asciiDomainEnd && |
249 | + isValid) |
250 | + { |
251 | + /* Check for dot as (at least the first one) seperates hostname from TLD */ |
252 | + if(*checkAsciiDomain=='.') dots++; |
253 | + else |
254 | + { |
255 | + /* Check for valid characters in domain name. |
256 | + * Valid domain name can only contain ASCII alphabetic letters, |
257 | + * digits (0-9) and hyphens ('-') |
258 | + */ |
259 | + isValid=(g_ascii_isalpha(*checkAsciiDomain) || |
260 | + g_ascii_isdigit(*checkAsciiDomain) || |
261 | + *checkAsciiDomain=='-'); |
262 | + } |
263 | + |
264 | + checkAsciiDomain++; |
265 | + } |
266 | + |
267 | + /* If we have not reached the trimmed end of string something must have gone wrong |
268 | + * and domain entered is invalid. If domain name entered excluding dots is longer |
269 | + * than 255 character it is also invalid. |
270 | + */ |
271 | + if(checkAsciiDomain<asciiDomainEnd) isValid=FALSE; |
272 | + else if((checkAsciiDomain-asciiDomainStart-dots)>255) isValid=FALSE; |
273 | + |
274 | + /* We need at least one dot in domain name (minimum number of dots to seperate |
275 | + * hostname from TLD) |
276 | + */ |
277 | + isValid=(isValid && dots>0); |
278 | + |
279 | + /* Activate "add" button if hostname (equal to domain name here) is valid */ |
280 | + gtk_widget_set_sensitive(priv->addDomainButton, isValid); |
281 | + |
282 | + /* Free allocated resources */ |
283 | + g_free(asciiDomain); |
284 | +} |
285 | + |
286 | /* Fill domain list with stored policies */ |
287 | static void _nojs_preferences_fill(NoJSPreferences *self) |
288 | { |
289 | @@ -286,6 +433,93 @@ |
290 | g_signal_handler_unblock(priv->checkSecondLevelOnlyCheckbox, priv->signalCheckSecondLevelOnlyToggledID); |
291 | } |
292 | |
293 | +static void _nojs_preferences_on_policy_editing_started(NoJSPreferences *self, |
294 | + GtkCellEditable *editable, |
295 | + gchar *path, |
296 | + gpointer *inUserData) |
297 | +{ |
298 | + NoJSPreferencesPrivate *priv=self->priv; |
299 | + |
300 | + priv->editingCombo=NULL; |
301 | + |
302 | + if(!GTK_IS_COMBO_BOX(editable)) return; |
303 | + |
304 | + priv->editingCombo=GTK_WIDGET(editable); |
305 | +} |
306 | + |
307 | +static void _nojs_preferences_on_policy_editing_canceled(NoJSPreferences *self, |
308 | + gpointer *inUserData) |
309 | +{ |
310 | + NoJSPreferencesPrivate *priv=self->priv; |
311 | + |
312 | + priv->editingCombo=NULL; |
313 | +} |
314 | + |
315 | +static void _nojs_preferences_on_policy_edited(NoJSPreferences *self, |
316 | + gchar *path, |
317 | + gchar *newText, |
318 | + gpointer *inUserData) |
319 | +{ |
320 | + NoJSPreferencesPrivate *priv=self->priv; |
321 | + gchar *domain; |
322 | + GtkTreeIter iter; |
323 | + GtkTreeIter policyIter; |
324 | + |
325 | + g_return_if_fail(priv->database); |
326 | + |
327 | + if (priv->editingCombo == NULL) return; |
328 | + |
329 | + gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(priv->listStore), &iter, path); |
330 | + |
331 | + gtk_tree_model_get(GTK_TREE_MODEL(priv->listStore), |
332 | + &iter, |
333 | + DOMAIN_COLUMN, &domain, |
334 | + -1); |
335 | + |
336 | + /* Get policy from combo box */ |
337 | + if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(priv->editingCombo), &policyIter)) |
338 | + { |
339 | + gchar *sql; |
340 | + gchar *error=NULL; |
341 | + gint success; |
342 | + gint policy; |
343 | + gchar *policyName; |
344 | + |
345 | + /* Get policy value to set for domain */ |
346 | + gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(priv->editingCombo)), |
347 | + &policyIter, |
348 | + 0, &policy, |
349 | + 1, &policyName, |
350 | + -1); |
351 | + |
352 | + g_return_if_fail(g_strcmp0(policyName, newText)==0); |
353 | + |
354 | + /* Add domain name and the selected policy to database */ |
355 | + sql=sqlite3_mprintf("UPDATE policies SET value = %d WHERE site = '%q';", |
356 | + policy, |
357 | + domain); |
358 | + success=sqlite3_exec(priv->database, sql, NULL, NULL, &error); |
359 | + |
360 | + /* Show error message if any */ |
361 | + if(success==SQLITE_OK) |
362 | + { |
363 | + gtk_list_store_set(priv->listStore, |
364 | + &iter, |
365 | + POLICY_COLUMN, newText, |
366 | + -1); |
367 | + } |
368 | + else g_warning(_("SQL fails: %s"), error); |
369 | + |
370 | + |
371 | + if(error) sqlite3_free(error); |
372 | + |
373 | + /* Free allocated resources */ |
374 | + sqlite3_free(sql); |
375 | + } |
376 | + |
377 | + priv->editingCombo=NULL; |
378 | +} |
379 | + |
380 | /* Selection in list changed */ |
381 | void _nojs_preferences_changed_selection(NoJSPreferences *self, |
382 | GtkTreeSelection *inSelection) |
383 | @@ -595,6 +829,8 @@ |
384 | GtkWidget *vbox; |
385 | GtkWidget *hbox; |
386 | gint width, height; |
387 | + GtkListStore *list; |
388 | + GtkTreeIter listIter; |
389 | |
390 | priv=self->priv=NOJS_PREFERENCES_GET_PRIVATE(self); |
391 | |
392 | @@ -650,6 +886,42 @@ |
393 | NULL); |
394 | gtk_tree_sortable_set_sort_column_id(sortableList, DOMAIN_COLUMN, GTK_SORT_ASCENDING); |
395 | |
396 | + /* Set up domain addition widgets */ |
397 | +#ifdef HAVE_GTK3 |
398 | + hbox=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
399 | + gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE); |
400 | +#else |
401 | + hbox=gtk_hbox_new(FALSE, 0); |
402 | +#endif |
403 | + |
404 | + priv->addDomainEntry=gtk_entry_new(); |
405 | + gtk_entry_set_max_length(GTK_ENTRY(priv->addDomainEntry), 64); |
406 | + gtk_container_add(GTK_CONTAINER(hbox), priv->addDomainEntry); |
407 | + g_signal_connect_swapped(priv->addDomainEntry, "changed", G_CALLBACK(_nojs_preferences_on_add_domain_entry_changed), self); |
408 | + |
409 | + list=gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING); |
410 | + gtk_list_store_append(list, &listIter); |
411 | + gtk_list_store_set(list, &listIter, 0, NOJS_POLICY_ACCEPT, 1, _("Accept"), -1); |
412 | + gtk_list_store_append(list, &listIter); |
413 | + gtk_list_store_set(list, &listIter, 0, NOJS_POLICY_ACCEPT_TEMPORARILY, 1, _("Accept for session"), -1); |
414 | + gtk_list_store_append(list, &listIter); |
415 | + gtk_list_store_set(list, &listIter, 0, NOJS_POLICY_BLOCK, 1, _("Block"), -1); |
416 | + |
417 | + priv->addDomainPolicyCombo=gtk_combo_box_new_with_model(GTK_TREE_MODEL(list)); |
418 | + gtk_combo_box_set_active(GTK_COMBO_BOX(priv->addDomainPolicyCombo), 0); |
419 | + gtk_container_add(GTK_CONTAINER(hbox), priv->addDomainPolicyCombo); |
420 | + |
421 | + renderer=gtk_cell_renderer_text_new(); |
422 | + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(priv->addDomainPolicyCombo), renderer, TRUE); |
423 | + gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(priv->addDomainPolicyCombo), renderer, "text", 1); |
424 | + |
425 | + priv->addDomainButton=gtk_button_new_from_stock(GTK_STOCK_ADD); |
426 | + gtk_widget_set_sensitive(priv->addDomainButton, FALSE); |
427 | + gtk_container_add(GTK_CONTAINER(hbox), priv->addDomainButton); |
428 | + g_signal_connect_swapped(priv->addDomainButton, "clicked", G_CALLBACK(_nojs_preferences_on_add_domain_clicked), self); |
429 | + |
430 | + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 5); |
431 | + |
432 | /* Set up domain list view */ |
433 | priv->list=gtk_tree_view_new_with_model(GTK_TREE_MODEL(priv->listStore)); |
434 | |
435 | @@ -669,7 +941,11 @@ |
436 | gtk_tree_view_column_set_sort_column_id(column, DOMAIN_COLUMN); |
437 | gtk_tree_view_append_column(GTK_TREE_VIEW(priv->list), column); |
438 | |
439 | - renderer=gtk_cell_renderer_text_new(); |
440 | + renderer=gtk_cell_renderer_combo_new(); |
441 | + g_object_set(G_OBJECT(renderer), "model", list, "text-column", 1, "has-entry", false, "editable", true, NULL); |
442 | + g_signal_connect_swapped(renderer, "editing-started", G_CALLBACK(_nojs_preferences_on_policy_editing_started), self); |
443 | + g_signal_connect_swapped(renderer, "editing-canceled", G_CALLBACK(_nojs_preferences_on_policy_editing_canceled), self); |
444 | + g_signal_connect_swapped(renderer, "edited", G_CALLBACK(_nojs_preferences_on_policy_edited), self); |
445 | column=gtk_tree_view_column_new_with_attributes(_("Policy"), |
446 | renderer, |
447 | "text", POLICY_COLUMN, |