Merge lp:~kalikiana/midori/historydial into lp:~kalikiana/midori/historydb

Proposed by Cris Dywan
Status: Work in progress
Proposed branch: lp:~kalikiana/midori/historydial
Merge into: lp:~kalikiana/midori/historydb
Diff against target: 180 lines (+70/-11)
3 files modified
midori/midori-frontend.c (+1/-1)
midori/midori-historydatabase.vala (+11/-2)
midori/midori-speeddial.vala (+58/-8)
To merge this branch: bzr merge lp:~kalikiana/midori/historydial
Reviewer Review Type Date Requested Status
Danielle Foré (community) Needs Fixing
Cris Dywan Pending
Review via email: mp+176749@code.launchpad.net

Description of the change

This branch uses the new HistoryDatabase API for filling up empty slots in the speed dial with recently visited pages.

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

Tried it out and it's pretty cool! I only have 1 small complaint: It creates duplicate dials with the things that I've manually added. If that were fixed, I think it'd be super cool :)

review: Needs Fixing

Unmerged revisions

6278. By Cris Dywan

Fill up speed dial with recently visited websites

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'midori/midori-frontend.c'
2--- midori/midori-frontend.c 2013-06-30 14:58:59 +0000
3+++ midori/midori-frontend.c 2013-07-24 17:50:33 +0000
4@@ -534,7 +534,7 @@
5 }
6
7 katze_assign (config_file, midori_paths_get_config_filename_for_reading ("speeddial"));
8- MidoriSpeedDial* dial = midori_speed_dial_new (config_file, NULL);
9+ MidoriSpeedDial* dial = midori_speed_dial_new (config_file, NULL, G_OBJECT (app));
10
11 if (error_messages->len)
12 {
13
14=== modified file 'midori/midori-historydatabase.vala'
15--- midori/midori-historydatabase.vala 2013-07-22 23:05:26 +0000
16+++ midori/midori-historydatabase.vala 2013-07-24 17:50:33 +0000
17@@ -46,7 +46,7 @@
18 return_val_if_fail (db != null, null);
19 }
20
21- public async List<HistoryItem>? query (string sqlcmd, string? filter, int day, int max_items, Cancellable cancellable) {
22+ public async List<HistoryItem>? query (string sqlcmd, string? filter, int day, uint max_items, Cancellable cancellable) {
23 return_val_if_fail (db != null, null);
24
25 Sqlite.Statement stmt;
26@@ -108,7 +108,7 @@
27 return items;
28 }
29
30- public async List<HistoryItem>? list_by_count_with_bookmarks (string? filter, int max_items, Cancellable cancellable) {
31+ public async List<HistoryItem>? list_by_count_with_bookmarks (string? filter, uint max_items, Cancellable cancellable) {
32 unowned string sqlcmd = """
33 SELECT type, date, uri, title FROM (
34 SELECT 1 AS type, date, uri, title, count() AS ct FROM history
35@@ -124,5 +124,14 @@
36 """;
37 return yield query (sqlcmd, filter, 0, max_items, cancellable);
38 }
39+
40+ public async List<HistoryItem>? list_by_count (string? filter, uint max_items, Cancellable cancellable) {
41+ unowned string sqlcmd = """
42+ SELECT 1 AS type, date, uri, title, count() AS ct FROM history
43+ WHERE uri LIKE :filter OR title LIKE :filter
44+ GROUP BY uri ORDER BY ct DESC LIMIT :limit
45+ """;
46+ return yield query (sqlcmd, filter, 0, max_items, cancellable);
47+ }
48 }
49 }
50
51=== modified file 'midori/midori-speeddial.vala'
52--- midori/midori-speeddial.vala 2013-06-25 22:32:12 +0000
53+++ midori/midori-speeddial.vala 2013-07-24 17:50:33 +0000
54@@ -36,21 +36,25 @@
55 Spec? spec = null;
56
57 public GLib.KeyFile keyfile;
58+ GLib.Object? app;
59+ List<Midori.HistoryItem> recent_items;
60 public bool close_buttons_left { get; set; default = false; }
61 public signal void refresh ();
62
63 public class Spec {
64- public string dial_id;
65+ public string? dial_id;
66 public string uri;
67- public Spec (string dial_id, string uri) {
68+ public Spec (string? dial_id, string uri) {
69 this.dial_id = dial_id;
70 this.uri = uri;
71 }
72 }
73
74- public SpeedDial (string new_filename, string? fallback = null) {
75+ public SpeedDial (string new_filename, string? fallback = null, GLib.Object? app = null) {
76 filename = new_filename;
77 thumb_queue = new GLib.List<Spec> ();
78+ recent_items = new List<Midori.HistoryItem> ();
79+ this.app = app;
80 keyfile = new GLib.KeyFile ();
81 try {
82 keyfile.load_from_file (filename, GLib.KeyFileFlags.NONE);
83@@ -153,9 +157,11 @@
84 }
85 }
86
87- public void add_with_id (string id, string uri, string title, Gdk.Pixbuf? img) {
88- keyfile.set_string (id, "uri", uri);
89- keyfile.set_string (id, "title", title);
90+ public void add_with_id (string? id, string uri, string title, Gdk.Pixbuf? img) {
91+ if (id != null) {
92+ keyfile.set_string (id, "uri", uri);
93+ keyfile.set_string (id, "title", title);
94+ }
95
96 Katze.mkdir_with_parents (Path.build_path (Path.DIR_SEPARATOR_S,
97 Paths.get_cache_dir (), "thumbnails"), 0700);
98@@ -174,6 +180,24 @@
99 return Path.build_filename (Paths.get_cache_dir (), "thumbnails", thumbnail);
100 }
101
102+ public async void queue_recent_tiles (uint max_items, Cancellable? cancellable) {
103+ if (app == null)
104+ return;
105+ var database = new Midori.HistoryDatabase (app);
106+ recent_items = yield database.list_by_count (null, max_items, cancellable);
107+ foreach (var item in recent_items) {
108+ var website = item as Midori.HistoryWebsite;
109+ if (Posix.access (build_thumbnail_path (website.uri), Posix.F_OK) != 0)
110+ get_thumb (null, website.uri);
111+ }
112+
113+ /* FIXME: determine if anything changed at all */
114+ app = null;
115+
116+ html = null;
117+ refresh ();
118+ }
119+
120 public unowned string get_html () throws Error {
121 bool load_missing = true;
122
123@@ -195,6 +219,10 @@
124 string dial_id = get_next_free_slot (out slot_count);
125 uint next_slot = dial_id.substring (5, -1).to_int ();
126
127+ /* Fill up empty dials with recently visited pages */
128+ uint recent_count = slot_count < 9 ? 9 - slot_count : 0;
129+ slot_count += recent_count;
130+
131 /* Try to guess the best X by X grid size */
132 uint grid_index = 3;
133 while ((grid_index * grid_index) < slot_count)
134@@ -260,6 +288,28 @@
135 catch (KeyFileError error) { }
136 }
137
138+ if (recent_count > 0)
139+ queue_recent_tiles.begin (recent_count, null);
140+ foreach (var item in recent_items) {
141+ var website = item as Midori.HistoryWebsite;
142+ string encoded;
143+ try {
144+ uint8[] thumb;
145+ FileUtils.get_data (build_thumbnail_path (website.uri), out thumb);
146+ encoded = Base64.encode (thumb);
147+ }
148+ catch (FileError error) {
149+ encoded = null;
150+ }
151+ markup.append_printf ("""
152+ <div class="shortcut" id="%u"><div class="preview">
153+ <a class="cross" href="#"></a>
154+ <a href="%s"><img src="data:image/png;base64,%s" title='%s'></a>
155+ </div><div class="title">%s</div></div>
156+ """,
157+ next_slot, website.uri, encoded ?? "", website.title, website.title);
158+ }
159+
160 markup.append_printf ("""
161 <div class="shortcut" id="%u"><div class="preview new">
162 <a class="add" href="#"></a>
163@@ -390,7 +440,7 @@
164 return false;
165 }
166
167- void get_thumb (string dial_id, string uri) {
168+ void get_thumb (string? dial_id, string uri) {
169 #if !HAVE_WEBKIT2
170 if (thumb_view == null) {
171 thumb_view = new WebKit.WebView ();
172@@ -409,7 +459,7 @@
173
174 /* Don't load thumbnails already queued */
175 foreach (var spec_ in thumb_queue)
176- if (spec_.dial_id == dial_id)
177+ if (spec_.uri == uri)
178 return;
179
180 thumb_queue.append (new Spec (dial_id, uri));

Subscribers

People subscribed via source and target branches

to all changes: