Merge lp:~midori/midori/32dwarves into lp:midori

Proposed by Cris Dywan
Status: Merged
Approved by: Paweł Forysiuk
Approved revision: 6527
Merged at revision: 6522
Proposed branch: lp:~midori/midori/32dwarves
Merge into: lp:midori
Diff against target: 325 lines (+103/-86)
5 files modified
midori/midori-browser.c (+32/-46)
midori/midori-database.vala (+4/-2)
midori/midori-history.c (+16/-16)
midori/midori-historydatabase.vala (+25/-1)
tests/completion.vala (+26/-21)
To merge this branch: bzr merge lp:~midori/midori/32dwarves
Reviewer Review Type Date Requested Status
Paweł Forysiuk Approve
Review via email: mp+198857@code.launchpad.net

Commit message

Use int64 arguments in HistoryDatabase.query

To post a comment you must log in.
Revision history for this message
Paweł Forysiuk (tuxator) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'midori/midori-browser.c'
2--- midori/midori-browser.c 2013-12-09 20:13:43 +0000
3+++ midori/midori-browser.c 2013-12-19 19:59:34 +0000
4@@ -90,6 +90,7 @@
5 KatzeArray* trash;
6 KatzeArray* search_engines;
7 KatzeArray* history;
8+ MidoriHistoryDatabase* history_database;
9 MidoriSpeedDial* dial;
10 gboolean show_tabs;
11
12@@ -177,10 +178,6 @@
13 midori_bookmarkbar_clear (GtkWidget* toolbar);
14
15 static void
16-midori_browser_new_history_item (MidoriBrowser* browser,
17- KatzeItem* item);
18-
19-static void
20 _midori_browser_set_toolbar_style (MidoriBrowser* browser,
21 MidoriToolbarStyle toolbar_style);
22
23@@ -748,7 +745,7 @@
24 {
25 if (midori_view_get_load_status (view) != MIDORI_LOAD_COMMITTED)
26 return;
27- if (!browser->history || !browser->maximum_history_age)
28+ if (!browser->history_database || !browser->maximum_history_age)
29 return;
30
31 KatzeItem* proxy = midori_view_get_proxy_item (view);
32@@ -759,8 +756,24 @@
33 if (katze_item_get_meta_integer (proxy, "history-step") == -1
34 && !katze_item_get_meta_boolean (proxy, "dont-write-history"))
35 {
36- midori_browser_new_history_item (browser, proxy);
37+ GError* error = NULL;
38+ time_t now = time (NULL);
39+ katze_item_set_added (proxy, now);
40+ gint64 day = sokoke_time_t_to_julian (&now);
41+ midori_history_database_insert (browser->history_database,
42+ katze_item_get_uri (proxy),
43+ katze_item_get_name (proxy),
44+ katze_item_get_added (proxy), day, &error);
45+ if (error != NULL)
46+ {
47+ g_printerr (_("Failed to insert new history item: %s\n"), error->message);
48+ g_error_free (error);
49+ return;
50+ }
51 katze_item_set_meta_integer (proxy, "history-step", 1);
52+ /* FIXME: No signal for adding/ removing */
53+ katze_array_add_item (browser->history, proxy);
54+ katze_array_remove_item (browser->history, proxy);
55 }
56 else if (katze_item_get_name (proxy)
57 && katze_item_get_meta_integer (proxy, "history-step") >= 1)
58@@ -5568,46 +5581,6 @@
59 }
60
61 static void
62-midori_browser_new_history_item (MidoriBrowser* browser,
63- KatzeItem* item)
64-{
65- time_t now;
66- gint64 day;
67- sqlite3* db;
68- static sqlite3_stmt* stmt = NULL;
69-
70- g_return_if_fail (katze_item_get_uri (item) != NULL);
71-
72- now = time (NULL);
73- katze_item_set_added (item, now);
74- day = sokoke_time_t_to_julian (&now);
75-
76- db = g_object_get_data (G_OBJECT (browser->history), "db");
77- g_return_if_fail (db != NULL);
78- if (!stmt)
79- {
80- const gchar* sqlcmd;
81-
82- sqlcmd = "INSERT INTO history (uri, title, date, day) VALUES (?,?,?,?)";
83- sqlite3_prepare_v2 (db, sqlcmd, -1, &stmt, NULL);
84- }
85- sqlite3_bind_text (stmt, 1, katze_item_get_uri (item), -1, 0);
86- sqlite3_bind_text (stmt, 2, katze_item_get_name (item), -1, 0);
87- sqlite3_bind_int64 (stmt, 3, katze_item_get_added (item));
88- sqlite3_bind_int64 (stmt, 4, day);
89-
90- if (sqlite3_step (stmt) != SQLITE_DONE)
91- g_printerr (_("Failed to insert new history item: %s\n"),
92- sqlite3_errmsg (db));
93- sqlite3_reset (stmt);
94- sqlite3_clear_bindings (stmt);
95-
96- /* FIXME: Workaround for the lack of a database interface */
97- katze_array_add_item (browser->history, item);
98- katze_array_remove_item (browser->history, item);
99-}
100-
101-static void
102 midori_browser_set_history (MidoriBrowser* browser,
103 KatzeArray* history)
104 {
105@@ -5617,10 +5590,20 @@
106 if (history)
107 g_object_ref (history);
108 katze_object_assign (browser->history, history);
109+ katze_object_assign (browser->history_database, NULL);
110
111 if (!history)
112 return;
113
114+ GError* error = NULL;
115+ browser->history_database = midori_history_database_new (NULL, &error);
116+ if (error != NULL)
117+ {
118+ g_printerr (_("Failed to initialize history: %s"), error->message);
119+ g_printerr ("\n");
120+ g_error_free (error);
121+ return;
122+ }
123 g_object_set (_action_by_name (browser, "Location"), "history",
124 browser->history, NULL);
125 }
126@@ -5735,6 +5718,8 @@
127 browser->settings = midori_web_settings_new ();
128 browser->proxy_array = katze_array_new (KATZE_TYPE_ARRAY);
129 browser->bookmarks = NULL;
130+ browser->history = NULL;
131+ browser->history_database = NULL;
132 browser->trash = NULL;
133 browser->search_engines = NULL;
134 browser->dial = NULL;
135@@ -6122,6 +6107,7 @@
136 katze_object_assign (browser->trash, NULL);
137 katze_object_assign (browser->search_engines, NULL);
138 katze_object_assign (browser->history, NULL);
139+ katze_object_assign (browser->history_database, NULL);
140 katze_object_assign (browser->dial, NULL);
141
142 g_idle_remove_by_data (browser);
143
144=== modified file 'midori/midori-database.vala'
145--- midori/midori-database.vala 2013-12-10 21:51:01 +0000
146+++ midori/midori-database.vala 2013-12-19 19:59:34 +0000
147@@ -105,8 +105,10 @@
148 */
149 public int64 get_int64 (string name) throws DatabaseError {
150 int index = column_index (name);
151- if (stmt.column_type (index) != Sqlite.INTEGER)
152- throw new DatabaseError.TYPE ("Getting '%s' with wrong type in row: %s".printf (name, query));
153+ int type = stmt.column_type (index);
154+ if (type != Sqlite.INTEGER && type != Sqlite.NULL)
155+ throw new DatabaseError.TYPE ("Getting '%s' with value '%s' of wrong type %d in row: %s".printf (
156+ name, stmt.column_text (index), type, query));
157 return stmt.column_int64 (index);
158 }
159
160
161=== modified file 'midori/midori-history.c'
162--- midori/midori-history.c 2013-09-17 21:30:59 +0000
163+++ midori/midori-history.c 2013-12-19 19:59:34 +0000
164@@ -18,13 +18,16 @@
165 midori_history_clear_cb (KatzeArray* array,
166 sqlite3* db)
167 {
168- char* errmsg = NULL;
169- if (sqlite3_exec (db, "DELETE FROM history; DELETE FROM search",
170- NULL, NULL, &errmsg) != SQLITE_OK)
171+ GError* error = NULL;
172+ MidoriHistoryDatabase* database = midori_history_database_new (NULL, &error);
173+ if (error == NULL)
174+ midori_history_database_clear (database, 0, &error);
175+ if (error != NULL)
176 {
177- g_printerr (_("Failed to clear history: %s\n"), errmsg);
178- sqlite3_free (errmsg);
179+ g_printerr (_("Failed to clear history: %s\n"), error->message);
180+ g_error_free (error);
181 }
182+ g_object_unref (database);
183 }
184
185 KatzeArray*
186@@ -60,19 +63,16 @@
187 MidoriWebSettings* settings)
188 {
189 gint max_history_age = katze_object_get_int (settings, "maximum-history-age");
190- sqlite3* db = g_object_get_data (G_OBJECT (array), "db");
191- char* errmsg = NULL;
192- gchar* sqlcmd = g_strdup_printf (
193- "DELETE FROM history WHERE "
194- "(julianday(date('now')) - julianday(date(date,'unixepoch')))"
195- " >= %d", max_history_age);
196- if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) != SQLITE_OK)
197+ GError* error = NULL;
198+ MidoriHistoryDatabase* database = midori_history_database_new (NULL, &error);
199+ if (error == NULL)
200+ midori_history_database_clear (database, max_history_age, &error);
201+ if (error != NULL)
202 {
203 /* i18n: Couldn't remove items that are older than n days */
204- g_printerr (_("Failed to remove old history items: %s\n"), errmsg);
205- sqlite3_free (errmsg);
206+ g_printerr (_("Failed to remove old history items: %s\n"), error->message);
207+ g_error_free (error);
208 }
209- g_free (sqlcmd);
210- sqlite3_close (db);
211+ g_object_unref (database);
212 }
213
214
215=== modified file 'midori/midori-historydatabase.vala'
216--- midori/midori-historydatabase.vala 2013-12-10 21:52:28 +0000
217+++ midori/midori-historydatabase.vala 2013-12-19 19:59:34 +0000
218@@ -49,7 +49,7 @@
219 }
220 }
221
222- public async List<HistoryItem>? query (string sqlcmd, string? filter, int day, int max_items, Cancellable cancellable) {
223+ public async List<HistoryItem>? query (string sqlcmd, string? filter, int64 day, int64 max_items, Cancellable cancellable) {
224 return_val_if_fail (db != null, null);
225
226 Midori.DatabaseStatement statement;
227@@ -118,5 +118,29 @@
228 """;
229 return yield query (sqlcmd, filter, 0, max_items, cancellable);
230 }
231+
232+ public bool insert (string uri, string title, int64 date, int64 day) throws DatabaseError {
233+ unowned string sqlcmd = "INSERT INTO history (uri, title, date, day) VALUES (:uri, :title, :date, :day)";
234+ var statement = prepare (sqlcmd,
235+ ":uri", typeof (string), uri,
236+ ":title", typeof (string), title,
237+ ":date", typeof (int64), date,
238+ ":day", typeof (int64), day);
239+ return statement.exec ();
240+ }
241+
242+ public bool clear (int64 maximum_age=0) throws DatabaseError {
243+ unowned string sqlcmd = """
244+ DELETE FROM history WHERE
245+ (julianday(date('now')) - julianday(date(date,'unixepoch')))
246+ >= :maximum_age;
247+ DELETE FROM search WHERE
248+ (julianday(date('now')) - julianday(date(date,'unixepoch')))
249+ >= :maximum_age;
250+ """;
251+ var statement = prepare (sqlcmd,
252+ ":maximum_age", typeof (int64), maximum_age);
253+ return statement.exec ();
254+ }
255 }
256 }
257
258=== modified file 'tests/completion.vala'
259--- tests/completion.vala 2013-10-11 22:36:30 +0000
260+++ tests/completion.vala 2013-12-19 19:59:34 +0000
261@@ -87,38 +87,43 @@
262 error ("Expected %d but got %d", 3, n);
263 }
264
265-struct TestCaseCompletion {
266- public string prefix;
267- public string text;
268- public int expected_count;
269-}
270-
271-const TestCaseCompletion[] completions = {
272- { "history", "example", 1 }
273-};
274-
275-async void complete_spec (Midori.Completion completion, TestCaseCompletion spec) {
276- assert (completion.can_complete (spec.text));
277+async void complete_history (Midori.HistoryDatabase history) {
278+ try {
279+ history.insert ("http://example.com", "Ejemplo", 0, 0);
280+ } catch (Error error) {
281+ assert_not_reached ();
282+ }
283 var cancellable = new Cancellable ();
284- var suggestions = yield completion.complete (spec.text, null, cancellable);
285- if (spec.expected_count != suggestions.length ())
286- error ("%u expected for %s/ %s but got %u",
287- spec.expected_count, spec.prefix, spec.text, suggestions.length ());
288+ var results = yield history.list_by_count_with_bookmarks ("example", 1, cancellable);
289+ assert (results.length () == 1);
290+ var first = results.nth_data (0);
291+ assert (first.title == "Ejemplo");
292+ results = yield history.list_by_count_with_bookmarks ("ejemplo", 1, cancellable);
293+ assert (results.length () == 1);
294+ first = results.nth_data (0);
295+ assert (first.title == "Ejemplo");
296+ complete_history_done = true;
297 }
298
299+bool complete_history_done = false;
300 void completion_history () {
301+ var app = new Midori.App ();
302+ Midori.HistoryDatabase history;
303 try {
304 var bookmarks_database = new Midori.BookmarksDatabase ();
305 assert (bookmarks_database.db != null);
306+ history = new Midori.HistoryDatabase (app);
307+ assert (history.db != null);
308+ history.clear (0);
309 } catch (Midori.DatabaseError error) {
310 assert_not_reached();
311 }
312
313- var completion = new Midori.HistoryCompletion ();
314- var app = new Midori.App ();
315- completion.prepare (app);
316- foreach (var spec in completions)
317- complete_spec.begin (completion, spec);
318+ Midori.Test.grab_max_timeout ();
319+ var loop = MainContext.default ();
320+ complete_history.begin (history);
321+ do { loop.iteration (true); } while (!complete_history_done);
322+ Midori.Test.release_max_timeout ();
323 }
324
325 struct TestCaseRender {

Subscribers

People subscribed via source and target branches

to all changes: