Merge lp:~axlrose112/midori/webmedia-now-playing into lp:midori
- webmedia-now-playing
- Merge into trunk
Proposed by
axlrose112
Status: | Work in progress |
---|---|
Proposed branch: | lp:~axlrose112/midori/webmedia-now-playing |
Merge into: | lp:midori |
Diff against target: |
797 lines (+727/-5) 4 files modified
CMakeLists.txt (+9/-0) configure (+2/-0) extensions/restful-client.vala (+702/-0) extensions/webmedia-now-playing.vala (+14/-5) |
To merge this branch: | bzr merge lp:~axlrose112/midori/webmedia-now-playing |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Robert Roth (community) | Needs Fixing | ||
Review via email:
|
Commit message
Description of the change
Add ZippCast for webmedia-
Correct some issues in Restful client extension
To post a comment you must log in.
Unmerged revisions
- 6861. By axlrose112
-
Add ZippCast
- 6860. By axlrose112
-
extension:Restful client
- 6859. By axlrose112
-
Add COUB http://
coub.com
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2014-11-10 22:59:26 +0000 | |||
3 | +++ CMakeLists.txt 2014-12-31 23:30:47 +0000 | |||
4 | @@ -161,6 +161,7 @@ | |||
5 | 161 | option(USE_APIDOCS "API documentation" OFF) | 161 | option(USE_APIDOCS "API documentation" OFF) |
6 | 162 | option(USE_GIR "Generate GObject Introspection bindings" OFF) | 162 | option(USE_GIR "Generate GObject Introspection bindings" OFF) |
7 | 163 | option(EXTRA_WARNINGS "Additional compiler warnings" OFF) | 163 | option(EXTRA_WARNINGS "Additional compiler warnings" OFF) |
8 | 164 | option(USE_GEE "Vala collection library" OFF) | ||
9 | 164 | 165 | ||
10 | 165 | # GTK+3 is implied here, whether set or not | 166 | # GTK+3 is implied here, whether set or not |
11 | 166 | if (USE_GRANITE OR HALF_BRO_INCOM_WEBKIT2) | 167 | if (USE_GRANITE OR HALF_BRO_INCOM_WEBKIT2) |
12 | @@ -187,6 +188,14 @@ | |||
13 | 187 | set(PKGS ${PKGS} zeitgeist-1.0) | 188 | set(PKGS ${PKGS} zeitgeist-1.0) |
14 | 188 | endif() | 189 | endif() |
15 | 189 | 190 | ||
16 | 191 | if (USE_GEE) | ||
17 | 192 | pkg_check_modules(GEE gee-0.8>=0.16) | ||
18 | 193 | set(OPTS_INCLUDE_DIRS "${OPTS_INCLUDE_DIRS};${GEE_INCLUDE_DIRS}") | ||
19 | 194 | set(OPTS_LIBRARIES "${OPTS_LIBRARIES};${GEE_LIBRARIES}") | ||
20 | 195 | add_definitions("-DHAVE_GEE") | ||
21 | 196 | set(PKGS ${PKGS} gee-0.8) | ||
22 | 197 | endif() | ||
23 | 198 | |||
24 | 190 | if (USE_GTK3) | 199 | if (USE_GTK3) |
25 | 191 | pkg_check_modules(GCR gcr-3>=2.32) | 200 | pkg_check_modules(GCR gcr-3>=2.32) |
26 | 192 | if (GCR_VERSION) | 201 | if (GCR_VERSION) |
27 | 193 | 202 | ||
28 | === modified file 'configure' | |||
29 | --- configure 2013-11-05 18:00:59 +0000 | |||
30 | +++ configure 2014-12-31 23:30:47 +0000 | |||
31 | @@ -37,6 +37,8 @@ | |||
32 | 37 | ARGS="$ARGS -DUSE_GRANITE=1";; | 37 | ARGS="$ARGS -DUSE_GRANITE=1";; |
33 | 38 | --enable-apidocs) | 38 | --enable-apidocs) |
34 | 39 | ARGS="$ARGS -DUSE_APIDOCS=1";; | 39 | ARGS="$ARGS -DUSE_APIDOCS=1";; |
35 | 40 | --enable-gee) | ||
36 | 41 | ARGS="$ARGS -DUSE_GEE=1";; | ||
37 | 40 | --extra-warnings) | 42 | --extra-warnings) |
38 | 41 | ARGS="$ARGS -DEXTRA_WARNINGS=1";; | 43 | ARGS="$ARGS -DEXTRA_WARNINGS=1";; |
39 | 42 | --prefix=*) | 44 | --prefix=*) |
40 | 43 | 45 | ||
41 | === added file 'extensions/restful-client.vala' | |||
42 | --- extensions/restful-client.vala 1970-01-01 00:00:00 +0000 | |||
43 | +++ extensions/restful-client.vala 2014-12-31 23:30:47 +0000 | |||
44 | @@ -0,0 +1,702 @@ | |||
45 | 1 | /* | ||
46 | 2 | Copyright (C) 2014 James Axl <axlrose112@gmail.com> | ||
47 | 3 | |||
48 | 4 | This library is free software; you can redistribute it and/or | ||
49 | 5 | modify it under the terms of the GNU Lesser General Public | ||
50 | 6 | License as published by the Free Software Foundation; either | ||
51 | 7 | version 2.1 of the License, or (at your option) any later version. | ||
52 | 8 | |||
53 | 9 | See the file COPYING for the full license text. | ||
54 | 10 | */ | ||
55 | 11 | |||
56 | 12 | |||
57 | 13 | using Soup; | ||
58 | 14 | namespace RestFul { | ||
59 | 15 | private class Manager : Midori.Extension { | ||
60 | 16 | private MainWindow _MainWindow; | ||
61 | 17 | |||
62 | 18 | internal Manager () { | ||
63 | 19 | GLib.Object (name: _("Restful Client"), | ||
64 | 20 | description: _("Test your requests with Restful-Server"), | ||
65 | 21 | version: "0.1" + Midori.VERSION_SUFFIX, | ||
66 | 22 | authors: "James Axl <axlrose112@gmail.com>"); | ||
67 | 23 | activate.connect (this.activated); | ||
68 | 24 | deactivate.connect (this.deactivated); | ||
69 | 25 | } | ||
70 | 26 | |||
71 | 27 | void tool_menu_populated (Gtk.Menu menu) { | ||
72 | 28 | var item = new Gtk.MenuItem.with_label("Restful Client"); | ||
73 | 29 | menu.add(item); | ||
74 | 30 | item.activate.connect (() => { | ||
75 | 31 | _MainWindow = new MainWindow(); | ||
76 | 32 | _MainWindow.show_all(); | ||
77 | 33 | }); | ||
78 | 34 | item.show(); | ||
79 | 35 | } | ||
80 | 36 | |||
81 | 37 | void browser_added (Midori.Browser browser) { | ||
82 | 38 | browser.populate_tool_menu.connect(tool_menu_populated); | ||
83 | 39 | } | ||
84 | 40 | |||
85 | 41 | void activated (Midori.App app) { | ||
86 | 42 | foreach (var browser in app.get_browsers ()) | ||
87 | 43 | browser_added (browser); | ||
88 | 44 | app.add_browser.connect (browser_added); | ||
89 | 45 | } | ||
90 | 46 | |||
91 | 47 | void deactivated () { | ||
92 | 48 | var app = get_app (); | ||
93 | 49 | app.add_browser.disconnect (browser_added); | ||
94 | 50 | } | ||
95 | 51 | |||
96 | 52 | } | ||
97 | 53 | |||
98 | 54 | public class RequestGui : Gtk.Box { | ||
99 | 55 | public string method {get; private set;} | ||
100 | 56 | public string HttpHttps {get; private set;} | ||
101 | 57 | public string Header {get; private set;} | ||
102 | 58 | public string UrlText {get; private set;} | ||
103 | 59 | public string DataText {get; private set;} | ||
104 | 60 | private Gtk.Entry Url; | ||
105 | 61 | private Gtk.Entry Data; | ||
106 | 62 | private Gtk.ComboBox Cbox; | ||
107 | 63 | private Gtk.ComboBox Htbox; | ||
108 | 64 | private Gtk.ComboBox HeaderBox; | ||
109 | 65 | private Project project; | ||
110 | 66 | private RestfulData Db; | ||
111 | 67 | private Gtk.Window _MainWindow; | ||
112 | 68 | |||
113 | 69 | public RequestGui(Gtk.Window mainWindow) { | ||
114 | 70 | |||
115 | 71 | Object (orientation : Gtk.Orientation.VERTICAL, spacing : 5); | ||
116 | 72 | _MainWindow = mainWindow; | ||
117 | 73 | var paned = new Gtk.Paned (Gtk.Orientation.HORIZONTAL); | ||
118 | 74 | var scrolledResultView = new Gtk.ScrolledWindow (null, null); | ||
119 | 75 | var scrolledProject = new Gtk.ScrolledWindow (null, null); | ||
120 | 76 | var status = new Gtk.Statusbar(); | ||
121 | 77 | var notebook = new Gtk.Notebook (); | ||
122 | 78 | var title = new Gtk.Label ("Projects"); | ||
123 | 79 | var vbox1 = new Gtk.Box (Gtk.Orientation.VERTICAL, 3); | ||
124 | 80 | var hbox1 = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 3); | ||
125 | 81 | var hbox2 = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 3); | ||
126 | 82 | var hbox3 = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 3); | ||
127 | 83 | var hbox4 = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 3); | ||
128 | 84 | var appendRequest = new Gtk.Button.with_label("Append"); | ||
129 | 85 | var resultView = new Gtk.TextView(); | ||
130 | 86 | Db = new RestfulData(); | ||
131 | 87 | var soupRequest = new RestfulSoup(); | ||
132 | 88 | project = new Project(this, appendRequest, Db); | ||
133 | 89 | appendRequest.clicked.connect (() => { | ||
134 | 90 | project.AddRequest(); | ||
135 | 91 | }); | ||
136 | 92 | appendRequest.set_sensitive(false); | ||
137 | 93 | Url = new Gtk.Entry(); | ||
138 | 94 | Data = new Gtk.Entry(); | ||
139 | 95 | Url.set_placeholder_text ("Set URL"); | ||
140 | 96 | Data.set_placeholder_text ("Set DATA"); | ||
141 | 97 | Url.changed.connect (() => { | ||
142 | 98 | UrlText = Url.get_text (); | ||
143 | 99 | if(UrlText == "") appendRequest.set_sensitive(false); | ||
144 | 100 | else appendRequest.set_sensitive(true); | ||
145 | 101 | }); | ||
146 | 102 | Url.activate.connect (() => { | ||
147 | 103 | if (UrlText == "") {InfoDialog(); return;} | ||
148 | 104 | soupRequest.SendRequest(UrlText, DataText, method, Header); | ||
149 | 105 | resultView.buffer.text = soupRequest.ResfultBody; | ||
150 | 106 | }); | ||
151 | 107 | Url.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "edit-clear"); | ||
152 | 108 | Url.icon_press.connect ((pos, event) => { | ||
153 | 109 | if (pos == Gtk.EntryIconPosition.SECONDARY) { | ||
154 | 110 | Url.set_text (""); | ||
155 | 111 | } | ||
156 | 112 | }); | ||
157 | 113 | Data.changed.connect (() => { | ||
158 | 114 | |||
159 | 115 | DataText = Data.get_text (); | ||
160 | 116 | }); | ||
161 | 117 | Data.activate.connect (() => { | ||
162 | 118 | if (UrlText == "") {InfoDialog(); return;} | ||
163 | 119 | soupRequest.SendRequest(UrlText, DataText, method, Header); | ||
164 | 120 | resultView.buffer.text = soupRequest.ResfultBody; | ||
165 | 121 | }); | ||
166 | 122 | Data.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "edit-clear"); | ||
167 | 123 | Data.icon_press.connect ((pos, event) => { | ||
168 | 124 | if (pos == Gtk.EntryIconPosition.SECONDARY) { | ||
169 | 125 | Data.set_text (""); | ||
170 | 126 | |||
171 | 127 | } | ||
172 | 128 | }); | ||
173 | 129 | |||
174 | 130 | resultView.editable = false; | ||
175 | 131 | var bar = new Gtk.MenuBar (); | ||
176 | 132 | var itemFile = new Gtk.MenuItem.with_label ("File"); | ||
177 | 133 | bar.add (itemFile); | ||
178 | 134 | var fileMenu = new Gtk.Menu (); | ||
179 | 135 | itemFile.set_submenu (fileMenu); | ||
180 | 136 | var itemOpen = new Gtk.MenuItem.with_label ("Open project"); | ||
181 | 137 | var itemNew = new Gtk.MenuItem.with_label ("New project"); | ||
182 | 138 | fileMenu.add (itemOpen); | ||
183 | 139 | fileMenu.add (itemNew); | ||
184 | 140 | |||
185 | 141 | itemNew.activate.connect (() => { | ||
186 | 142 | project.ItemNewProject(); | ||
187 | 143 | }); | ||
188 | 144 | |||
189 | 145 | /* cb method */ | ||
190 | 146 | var method_store = new Gtk.ListStore (1, typeof (string)); | ||
191 | 147 | Gtk.TreeIter iter; | ||
192 | 148 | method = "POST"; | ||
193 | 149 | method_store.append (out iter); | ||
194 | 150 | method_store.set (iter, 0, method); | ||
195 | 151 | method_store.append (out iter); | ||
196 | 152 | method_store.set (iter, 0, "GET"); | ||
197 | 153 | method_store.append (out iter); | ||
198 | 154 | method_store.set (iter, 0, "PUT"); | ||
199 | 155 | method_store.append (out iter); | ||
200 | 156 | method_store.set (iter, 0, "DELETE"); | ||
201 | 157 | /* cb method */ | ||
202 | 158 | |||
203 | 159 | /*cb http or https */ | ||
204 | 160 | Gtk.ListStore htlist = new Gtk.ListStore (1, typeof (string)); | ||
205 | 161 | |||
206 | 162 | htlist.append (out iter); | ||
207 | 163 | htlist.set (iter, 0, "http"); | ||
208 | 164 | htlist.append (out iter); | ||
209 | 165 | htlist.set (iter, 0, "https"); | ||
210 | 166 | |||
211 | 167 | /* cb header */ | ||
212 | 168 | Gtk.ListStore headerlist = new Gtk.ListStore (1, typeof (string)); | ||
213 | 169 | |||
214 | 170 | headerlist.append (out iter); | ||
215 | 171 | headerlist.set (iter, 0, "application/x-www-form-urlencoded"); | ||
216 | 172 | headerlist.append (out iter); | ||
217 | 173 | headerlist.set (iter, 0, "application/json"); | ||
218 | 174 | |||
219 | 175 | /* The Box */ | ||
220 | 176 | |||
221 | 177 | Htbox = new Gtk.ComboBox.with_model (htlist); | ||
222 | 178 | Cbox = new Gtk.ComboBox.with_model (method_store); | ||
223 | 179 | HeaderBox = new Gtk.ComboBox.with_model (headerlist); | ||
224 | 180 | |||
225 | 181 | var renderer = new Gtk.CellRendererText (); | ||
226 | 182 | Cbox.pack_start (renderer, false); | ||
227 | 183 | Cbox.add_attribute (renderer, "text", 0); | ||
228 | 184 | Cbox.active = 0; | ||
229 | 185 | |||
230 | 186 | var htrenderer = new Gtk.CellRendererText (); | ||
231 | 187 | Htbox.pack_start (htrenderer, false); | ||
232 | 188 | Htbox.add_attribute (htrenderer, "text", 0); | ||
233 | 189 | Htbox.active = 0; | ||
234 | 190 | |||
235 | 191 | var headerrenderer = new Gtk.CellRendererText (); | ||
236 | 192 | HeaderBox.pack_start (headerrenderer, false); | ||
237 | 193 | HeaderBox.add_attribute (headerrenderer, "text", 0); | ||
238 | 194 | HeaderBox.active = 0; | ||
239 | 195 | |||
240 | 196 | Cbox.changed.connect (() => { | ||
241 | 197 | GLib.Value val1; | ||
242 | 198 | |||
243 | 199 | Cbox.get_active_iter (out iter); | ||
244 | 200 | method_store.get_value (iter, 0, out val1); | ||
245 | 201 | |||
246 | 202 | method = (string) val1; | ||
247 | 203 | }); | ||
248 | 204 | |||
249 | 205 | Htbox.changed.connect (() => { | ||
250 | 206 | GLib.Value val1; | ||
251 | 207 | |||
252 | 208 | Htbox.get_active_iter (out iter); | ||
253 | 209 | htlist.get_value (iter, 0, out val1); | ||
254 | 210 | |||
255 | 211 | HttpHttps = (string) val1; | ||
256 | 212 | }); | ||
257 | 213 | |||
258 | 214 | HeaderBox.changed.connect (() => { | ||
259 | 215 | GLib.Value val1; | ||
260 | 216 | HeaderBox.get_active_iter (out iter); | ||
261 | 217 | headerlist.get_value (iter, 0, out val1); | ||
262 | 218 | Header = (string) val1; | ||
263 | 219 | }); | ||
264 | 220 | |||
265 | 221 | hbox1.pack_start (Cbox, false, false, 5); | ||
266 | 222 | hbox1.pack_start (Htbox, false, false, 5); | ||
267 | 223 | hbox1.pack_start (Url, true, true, 5); | ||
268 | 224 | hbox1.pack_start (appendRequest , false, false, 5); | ||
269 | 225 | hbox2.pack_start (HeaderBox, false, false, 5); | ||
270 | 226 | hbox2.pack_start (Data, true, true, 5); | ||
271 | 227 | scrolledResultView.add(resultView); | ||
272 | 228 | hbox3.pack_start (scrolledResultView, true, true, 5); | ||
273 | 229 | scrolledProject.add(project); | ||
274 | 230 | notebook.append_page (scrolledProject, title); | ||
275 | 231 | paned.add1(notebook); | ||
276 | 232 | paned.add2(vbox1); | ||
277 | 233 | vbox1.pack_start (hbox1, false, false, 5); | ||
278 | 234 | vbox1.pack_start (hbox2, false, false, 5); | ||
279 | 235 | vbox1.pack_start (hbox3, true, true, 5); | ||
280 | 236 | hbox4.pack_start (paned, true, true, 7); | ||
281 | 237 | this.pack_start (bar, false, false, 1); | ||
282 | 238 | this.pack_start (hbox4, true, true, 5); | ||
283 | 239 | this.pack_start (status, false, false, 1); | ||
284 | 240 | BackToZero(); | ||
285 | 241 | } | ||
286 | 242 | |||
287 | 243 | public void FillWidgets(Gee.ArrayList<string> dataResquest) { | ||
288 | 244 | Url.set_text(dataResquest[0]); | ||
289 | 245 | Data.set_text(dataResquest[1]); | ||
290 | 246 | Cbox.set_active(int.parse(dataResquest[2])); | ||
291 | 247 | HeaderBox.set_active(int.parse(dataResquest[3])); | ||
292 | 248 | dataResquest.clear(); | ||
293 | 249 | } | ||
294 | 250 | |||
295 | 251 | public void BackToZero() { | ||
296 | 252 | Url.set_text(""); | ||
297 | 253 | Data.set_text(""); | ||
298 | 254 | Cbox.set_active(0); | ||
299 | 255 | HeaderBox.set_active(0); | ||
300 | 256 | Header = "application/x-www-form-urlencoded"; | ||
301 | 257 | method = "POST"; | ||
302 | 258 | UrlText = ""; | ||
303 | 259 | DataText = ""; | ||
304 | 260 | } | ||
305 | 261 | |||
306 | 262 | public void InfoDialog() { | ||
307 | 263 | var dialog = new Gtk.MessageDialog(_MainWindow, Gtk.DialogFlags.MODAL,Gtk.MessageType.WARNING, Gtk.ButtonsType.OK, "Impossible Man :D go to sleep please"); | ||
308 | 264 | dialog.set_title("Midori"); | ||
309 | 265 | dialog.run(); | ||
310 | 266 | dialog.destroy(); | ||
311 | 267 | } | ||
312 | 268 | } | ||
313 | 269 | |||
314 | 270 | class MainWindow : Gtk.Window { | ||
315 | 271 | public MainWindow() { | ||
316 | 272 | var gui = new RequestGui(this); | ||
317 | 273 | this.title = "Midori Restful-clientt"; | ||
318 | 274 | this.set_default_size (800, 600); | ||
319 | 275 | this.window_position = Gtk.WindowPosition.CENTER; | ||
320 | 276 | this.add(gui); | ||
321 | 277 | this.destroy.connect (() => { | ||
322 | 278 | this.destroy(); | ||
323 | 279 | }); | ||
324 | 280 | } | ||
325 | 281 | } | ||
326 | 282 | |||
327 | 283 | public class RestfulSoup { | ||
328 | 284 | public string ResfultBody {get; private set;} | ||
329 | 285 | |||
330 | 286 | public void SendRequest(string url, string data, string method, string header) { | ||
331 | 287 | var new_url = url; | ||
332 | 288 | try { | ||
333 | 289 | var regex = new Regex("""^(http|https)(:\/\/[a-zA-Z0-9?=#.\/]+)"""); | ||
334 | 290 | if (!regex.match(new_url)) | ||
335 | 291 | new_url = "http://" + url; | ||
336 | 292 | } catch( RegexError re ) { | ||
337 | 293 | warning ("%s", re.message); | ||
338 | 294 | } | ||
339 | 295 | |||
340 | 296 | var session = new Soup.Session (); | ||
341 | 297 | var message = new Soup.Message (method, new_url); | ||
342 | 298 | if (data != "" || data == null) | ||
343 | 299 | message.set_request(header, MemoryUse.COPY, data.data); | ||
344 | 300 | session.send_message (message); | ||
345 | 301 | ResfultBody = (string) message.response_body.data; | ||
346 | 302 | } | ||
347 | 303 | } | ||
348 | 304 | |||
349 | 305 | public class RestfulData { | ||
350 | 306 | private Sqlite.Database DB; | ||
351 | 307 | private int EC; | ||
352 | 308 | private string ErrMsg; | ||
353 | 309 | public Gee.ArrayList<string?> ProjectList{get; private set;} | ||
354 | 310 | public Gee.ArrayList<string?> RequestList{get; private set;} | ||
355 | 311 | public Gee.ArrayList<string?> RequestDataList{get; private set;} | ||
356 | 312 | public RestfulData() { | ||
357 | 313 | |||
358 | 314 | // Open/Create a database: I used /tmp just for testing but after i am going to use config dir | ||
359 | 315 | EC = Sqlite.Database.open ("/home/jamesaxl/midori_restful.db", out DB); | ||
360 | 316 | ProjectList = new Gee.ArrayList<string?>(); | ||
361 | 317 | RequestList = new Gee.ArrayList<string?>(); | ||
362 | 318 | RequestDataList = new Gee.ArrayList<string?>(); | ||
363 | 319 | if (EC != Sqlite.OK) { | ||
364 | 320 | stderr.printf ("Can't open database: %d: %s\n", DB.errcode (), DB.errmsg ()); | ||
365 | 321 | return; | ||
366 | 322 | } | ||
367 | 323 | string query = """ | ||
368 | 324 | create table if not exists `project` ( | ||
369 | 325 | `id_project` INTEGER, | ||
370 | 326 | `name` Text NOT NULL UNIQUE, | ||
371 | 327 | `date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
372 | 328 | PRIMARY KEY(id_project)); | ||
373 | 329 | create table if not exists `request` ( | ||
374 | 330 | `id_request` INTEGER, | ||
375 | 331 | `name` Text NOT NULL UNIQUE, | ||
376 | 332 | `url` Text NOT NULL, | ||
377 | 333 | `data` Text NOT NULL, | ||
378 | 334 | `method` Text NOT NULL, | ||
379 | 335 | `header` Text NOT NULL, | ||
380 | 336 | `date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
381 | 337 | `id_project` integer, | ||
382 | 338 | PRIMARY KEY(id_request), | ||
383 | 339 | Foreign key(id_project) references project on delete cascade on update cascade); | ||
384 | 340 | """; | ||
385 | 341 | string on_key = "PRAGMA foreign_keys = ON;"; | ||
386 | 342 | EC = DB.exec (on_key, null, out ErrMsg); | ||
387 | 343 | |||
388 | 344 | // Execute our query: | ||
389 | 345 | EC = DB.exec (query, null, out ErrMsg); | ||
390 | 346 | if (EC != Sqlite.OK){ | ||
391 | 347 | stderr.printf ("Error: %s\n", ErrMsg); | ||
392 | 348 | return; | ||
393 | 349 | } | ||
394 | 350 | } | ||
395 | 351 | |||
396 | 352 | public bool RegisterProject(string name) { | ||
397 | 353 | string query = "INSERT INTO project (name) VALUES ('"+ name +"');"; | ||
398 | 354 | EC = DB.exec (query, null, out ErrMsg); | ||
399 | 355 | if (EC != Sqlite.OK) { | ||
400 | 356 | stderr.printf ("Error: %s\n", ErrMsg); | ||
401 | 357 | return false; | ||
402 | 358 | } | ||
403 | 359 | |||
404 | 360 | return true; | ||
405 | 361 | } | ||
406 | 362 | |||
407 | 363 | public bool DeleteProject(string name) { | ||
408 | 364 | string query = "DELETE from project WHERE name = '"+ name +"';"; | ||
409 | 365 | EC = DB.exec (query, null, out ErrMsg); | ||
410 | 366 | if (EC != Sqlite.OK) { | ||
411 | 367 | stderr.printf ("Error: %s\n", ErrMsg); | ||
412 | 368 | return false; | ||
413 | 369 | } | ||
414 | 370 | return true; | ||
415 | 371 | } | ||
416 | 372 | |||
417 | 373 | public bool CheckDuplicatProject (string name) { | ||
418 | 374 | Sqlite.Statement stmt; | ||
419 | 375 | var query = "select name from project where name = '"+ name +"';"; | ||
420 | 376 | if ((EC = DB.prepare_v2 (query, -1, out stmt, null)) == Sqlite.ERROR) { | ||
421 | 377 | printerr ("SQL error: %d, %s\n", EC, DB.errmsg ()); | ||
422 | 378 | return false; | ||
423 | 379 | } | ||
424 | 380 | EC = stmt.step(); | ||
425 | 381 | if (EC != Sqlite.ROW && EC != Sqlite.DONE) | ||
426 | 382 | return false; | ||
427 | 383 | return (EC == Sqlite.ROW); | ||
428 | 384 | } | ||
429 | 385 | |||
430 | 386 | public bool RetrieveProject() { | ||
431 | 387 | var query = "select name from project;"; | ||
432 | 388 | EC = DB.exec (query, exec_callback, out ErrMsg); | ||
433 | 389 | if (EC != Sqlite.OK) { | ||
434 | 390 | stderr.printf ("Error: %s\n", ErrMsg); | ||
435 | 391 | return false; | ||
436 | 392 | } | ||
437 | 393 | return true; | ||
438 | 394 | } | ||
439 | 395 | |||
440 | 396 | private int exec_callback (int n_columns, string[] values, string[] column_names) { | ||
441 | 397 | for (int i = 0; i < n_columns; i++) { | ||
442 | 398 | this.ProjectList.add(values[i]); | ||
443 | 399 | } | ||
444 | 400 | return 0; | ||
445 | 401 | } | ||
446 | 402 | |||
447 | 403 | public bool RegisterRequest(string p_name, string r_name, string r_url, string method, string r_data, string r_header){ | ||
448 | 404 | Sqlite.Statement stmt; | ||
449 | 405 | int id_project = 0; | ||
450 | 406 | string p_query = "select id_project from project where name = '"+ p_name +"';"; | ||
451 | 407 | if ((EC = DB.prepare_v2 (p_query, -1, out stmt, null)) == Sqlite.ERROR) { | ||
452 | 408 | printerr ("SQL error: %d, %s\n", EC, DB.errmsg ()); | ||
453 | 409 | return false; | ||
454 | 410 | } | ||
455 | 411 | |||
456 | 412 | if (stmt.step () == Sqlite.ROW) { | ||
457 | 413 | id_project = int.parse(stmt.column_text (0)); | ||
458 | 414 | } | ||
459 | 415 | |||
460 | 416 | string query = "INSERT INTO request (name, url, data, id_project, method, header) VALUES ('"+ r_name +"', '"+ r_url +"', '"+ r_data +"' , ?, '"+ method +"', '"+ r_header +"');"; | ||
461 | 417 | |||
462 | 418 | EC = DB.prepare_v2(query, -1, out stmt); | ||
463 | 419 | EC = stmt.bind_int(1, id_project); | ||
464 | 420 | EC = stmt.step(); | ||
465 | 421 | if (EC != Sqlite.DONE) { | ||
466 | 422 | stderr.printf ("Error: %s\n", ErrMsg); | ||
467 | 423 | return false; | ||
468 | 424 | } | ||
469 | 425 | |||
470 | 426 | return true; | ||
471 | 427 | } | ||
472 | 428 | |||
473 | 429 | public bool DuplicatRequest(string p_name, string r_name) { | ||
474 | 430 | Sqlite.Statement stmt; | ||
475 | 431 | var query = "select project.name from request, project where request.id_project = project.id_project and request.name = '"+r_name+"' and project.name='"+p_name+"';"; | ||
476 | 432 | if ((EC = DB.prepare_v2 (query, -1, out stmt, null)) == Sqlite.ERROR) { | ||
477 | 433 | printerr ("SQL error: %d, %s\n", EC, DB.errmsg ()); | ||
478 | 434 | return false; | ||
479 | 435 | } | ||
480 | 436 | EC = stmt.step(); | ||
481 | 437 | if (EC != Sqlite.ROW && EC != Sqlite.DONE) | ||
482 | 438 | return false; | ||
483 | 439 | return (EC == Sqlite.ROW); | ||
484 | 440 | } | ||
485 | 441 | |||
486 | 442 | public bool DeleteRequest(string name) { | ||
487 | 443 | |||
488 | 444 | string query = "DELETE FROM request WHERE name = '"+ name +"';"; | ||
489 | 445 | EC = DB.exec (query, null, out ErrMsg); | ||
490 | 446 | if (EC != Sqlite.OK) { | ||
491 | 447 | stderr.printf ("Error here: %s\n", ErrMsg); | ||
492 | 448 | return false; | ||
493 | 449 | } | ||
494 | 450 | return true; | ||
495 | 451 | } | ||
496 | 452 | |||
497 | 453 | public bool RetrieveRequestByProject(string name) { | ||
498 | 454 | Sqlite.Statement stmt; | ||
499 | 455 | string query = "select request.name from project, request where request.id_project = project .id_project and project.name = '"+ name +"';"; | ||
500 | 456 | if ((EC = DB.prepare_v2 (query, -1, out stmt, null)) == Sqlite.ERROR) { | ||
501 | 457 | printerr ("SQL error: %d, %s\n", EC, DB.errmsg ()); | ||
502 | 458 | return false; | ||
503 | 459 | } | ||
504 | 460 | while (stmt.step () == Sqlite.ROW) { | ||
505 | 461 | this.RequestList.add(stmt.column_text(0)); | ||
506 | 462 | return true; | ||
507 | 463 | } | ||
508 | 464 | return false; | ||
509 | 465 | } | ||
510 | 466 | |||
511 | 467 | public bool RetrieveRequestData(string name){ | ||
512 | 468 | Sqlite.Statement stmt; | ||
513 | 469 | string query = "select url, data, method, header from request where name = '"+ name +"';"; | ||
514 | 470 | if ((EC = DB.prepare_v2 (query, -1, out stmt, null)) == Sqlite.ERROR) { | ||
515 | 471 | printerr ("SQL error: %d, %s\n", EC, DB.errmsg ()); | ||
516 | 472 | return false; | ||
517 | 473 | } | ||
518 | 474 | if (stmt.step () == Sqlite.ROW) { | ||
519 | 475 | this.RequestDataList.add(stmt.column_text(0)); | ||
520 | 476 | this.RequestDataList.add(stmt.column_text(1)); | ||
521 | 477 | switch (stmt.column_text(2)) { | ||
522 | 478 | case "POST": | ||
523 | 479 | this.RequestDataList.add("0"); | ||
524 | 480 | break; | ||
525 | 481 | case "GET": | ||
526 | 482 | this.RequestDataList.add("1"); | ||
527 | 483 | break; | ||
528 | 484 | case "PUT": | ||
529 | 485 | this.RequestDataList.add("2"); | ||
530 | 486 | break; | ||
531 | 487 | case "DELETE": | ||
532 | 488 | this.RequestDataList.add("3"); | ||
533 | 489 | break; | ||
534 | 490 | } | ||
535 | 491 | switch (stmt.column_text(3)) { | ||
536 | 492 | case "application/x-www-form-urlencoded": | ||
537 | 493 | this.RequestDataList.add("0"); | ||
538 | 494 | break; | ||
539 | 495 | case "application/json": | ||
540 | 496 | this.RequestDataList.add("1"); | ||
541 | 497 | break; | ||
542 | 498 | } | ||
543 | 499 | return true; | ||
544 | 500 | } | ||
545 | 501 | return false; | ||
546 | 502 | } | ||
547 | 503 | } | ||
548 | 504 | |||
549 | 505 | |||
550 | 506 | public class Project : Gtk.TreeView { | ||
551 | 507 | |||
552 | 508 | public string SelectedRow {get; private set;} | ||
553 | 509 | private Gtk.TreeStore ProjectStore; | ||
554 | 510 | private Gtk.TreeIter ProjectParent; | ||
555 | 511 | private Gtk.TreeIter RequestChild; | ||
556 | 512 | private Gtk.TreeIter selected_iter; | ||
557 | 513 | private Gtk.Button AppendRequest; | ||
558 | 514 | private RestfulData Db; | ||
559 | 515 | private InputDialog Name; | ||
560 | 516 | private RequestGui _RequestGui; | ||
561 | 517 | private Gtk.TreeSelection _Selection; | ||
562 | 518 | private Gtk.Menu menuSystem; | ||
563 | 519 | Gtk.MenuItem delete_project; | ||
564 | 520 | Gtk.MenuItem delete_request; | ||
565 | 521 | |||
566 | 522 | public Project (RequestGui requestGui , Gtk.Button appendRequest, RestfulData db) { | ||
567 | 523 | AppendRequest = appendRequest; | ||
568 | 524 | Db = db; | ||
569 | 525 | _RequestGui = requestGui; | ||
570 | 526 | var selected = this.get_selection (); | ||
571 | 527 | selected.changed.connect (this.SeletedRow); | ||
572 | 528 | this.headers_visible = false; | ||
573 | 529 | menuSystem = new Gtk.Menu(); | ||
574 | 530 | delete_project = new Gtk.MenuItem.with_label ("Delete project"); | ||
575 | 531 | delete_request = new Gtk.MenuItem.with_label ("Delete request"); | ||
576 | 532 | delete_project.activate.connect (() => { | ||
577 | 533 | DeleteProjectRequest(); | ||
578 | 534 | }); | ||
579 | 535 | delete_request.activate.connect (() => { | ||
580 | 536 | DeleteProjectRequest(); | ||
581 | 537 | }); | ||
582 | 538 | menuSystem.add(delete_project); | ||
583 | 539 | menuSystem.add(delete_request); | ||
584 | 540 | menuSystem.show(); | ||
585 | 541 | |||
586 | 542 | |||
587 | 543 | this.button_press_event.connect((w, event) => { | ||
588 | 544 | if (event.button == 3) { | ||
589 | 545 | return PopUpHandler (menuSystem, event); | ||
590 | 546 | } | ||
591 | 547 | return false; | ||
592 | 548 | }); | ||
593 | 549 | this.popup_menu.connect((event) => { | ||
594 | 550 | return PopUpHandler (menuSystem, null); | ||
595 | 551 | }); | ||
596 | 552 | |||
597 | 553 | ProjectStore = new Gtk.TreeStore (1, typeof (string)); | ||
598 | 554 | this.set_model (ProjectStore); | ||
599 | 555 | this.insert_column_with_attributes (-1, "Projects", new Gtk.CellRendererText (), "text", 0, null); | ||
600 | 556 | if (Db.RetrieveProject()) { | ||
601 | 557 | foreach (string project in Db.ProjectList) { | ||
602 | 558 | ProjectStore.append (out ProjectParent, null); | ||
603 | 559 | ProjectStore.set (ProjectParent, 0, project, -1); | ||
604 | 560 | if(Db.RetrieveRequestByProject(project)){ | ||
605 | 561 | foreach (string request in Db.RequestList) { | ||
606 | 562 | ProjectStore.append (out RequestChild, ProjectParent); | ||
607 | 563 | ProjectStore.set (RequestChild, 0, request, -1); | ||
608 | 564 | } | ||
609 | 565 | } | ||
610 | 566 | } | ||
611 | 567 | Db.ProjectList.clear(); | ||
612 | 568 | Db.RequestList.clear(); | ||
613 | 569 | } | ||
614 | 570 | } | ||
615 | 571 | |||
616 | 572 | private bool PopUpHandler (Gtk.Menu popup, Gdk.EventButton? eb) { | ||
617 | 573 | if (eb.button == 3) { | ||
618 | 574 | Gtk.TreePath path; | ||
619 | 575 | Gtk.TreeViewColumn column; | ||
620 | 576 | int mousex = (int) eb.x; | ||
621 | 577 | int mousey = (int) eb.y; | ||
622 | 578 | int x; | ||
623 | 579 | int y; | ||
624 | 580 | int a; | ||
625 | 581 | int b; | ||
626 | 582 | convert_tree_to_bin_window_coords (mousex, mousey, out a, out b); | ||
627 | 583 | if (get_path_at_pos (a, b, out path, out column, out x, out y)) | ||
628 | 584 | set_cursor (path, column, true); | ||
629 | 585 | popup.popup (null, null, null, eb.button, eb.time); | ||
630 | 586 | return true; | ||
631 | 587 | } | ||
632 | 588 | return false; | ||
633 | 589 | } | ||
634 | 590 | |||
635 | 591 | public void ItemNewProject() { | ||
636 | 592 | Name = new InputDialog(); | ||
637 | 593 | Name.show_all (); | ||
638 | 594 | Name.b_ok.clicked.connect (() => { | ||
639 | 595 | if (AddProject(Name.get_text())) | ||
640 | 596 | Name.close(); | ||
641 | 597 | Name.Warnning.set_text("Already exists"); | ||
642 | 598 | Name.Warnning.show(); | ||
643 | 599 | }); | ||
644 | 600 | } | ||
645 | 601 | |||
646 | 602 | private bool AddProject(string name) { | ||
647 | 603 | if (Db.CheckDuplicatProject(name)) return false; | ||
648 | 604 | if(!Db.RegisterProject(name)) return false; | ||
649 | 605 | ProjectStore.append (out ProjectParent, null); | ||
650 | 606 | ProjectStore.set (ProjectParent, 0, name, -1); | ||
651 | 607 | return true; | ||
652 | 608 | } | ||
653 | 609 | |||
654 | 610 | public void DeleteProjectRequest() { | ||
655 | 611 | GLib.Value val; | ||
656 | 612 | Gtk.TreeModel model; | ||
657 | 613 | Gtk.TreeIter iter; | ||
658 | 614 | if (_Selection.get_selected (out model, out selected_iter)) { | ||
659 | 615 | ProjectStore.get_value(selected_iter, 0, out val); | ||
660 | 616 | if (!model.iter_parent (out iter, selected_iter)) { | ||
661 | 617 | if(Db.DeleteProject((string) val)) | ||
662 | 618 | ProjectStore.remove(ref selected_iter); | ||
663 | 619 | } else { | ||
664 | 620 | if(Db.DeleteRequest((string) val)) | ||
665 | 621 | ProjectStore.remove(ref selected_iter); | ||
666 | 622 | } | ||
667 | 623 | } | ||
668 | 624 | } | ||
669 | 625 | |||
670 | 626 | public void SeletedRow(Gtk.TreeSelection selection) { | ||
671 | 627 | |||
672 | 628 | Gtk.TreeModel model; | ||
673 | 629 | Gtk.TreeIter iter; | ||
674 | 630 | _Selection = selection; | ||
675 | 631 | Value val; | ||
676 | 632 | if (_Selection.get_selected (out model, out selected_iter)) { | ||
677 | 633 | ProjectStore.get_value( selected_iter, 0, out val); | ||
678 | 634 | SelectedRow = (string)val; | ||
679 | 635 | if (model.iter_parent (out iter, selected_iter)) { | ||
680 | 636 | delete_project.hide(); | ||
681 | 637 | delete_request.show(); | ||
682 | 638 | AppendRequest.set_sensitive(false); | ||
683 | 639 | if (Db.RetrieveRequestData(SelectedRow)) | ||
684 | 640 | _RequestGui.FillWidgets(Db.RequestDataList); | ||
685 | 641 | else | ||
686 | 642 | _RequestGui.BackToZero(); | ||
687 | 643 | } else { | ||
688 | 644 | delete_request.hide(); | ||
689 | 645 | delete_project.show(); | ||
690 | 646 | _RequestGui.BackToZero(); | ||
691 | 647 | } | ||
692 | 648 | } | ||
693 | 649 | } | ||
694 | 650 | |||
695 | 651 | public void AddRequest() { | ||
696 | 652 | GLib.Value valProject; | ||
697 | 653 | ProjectStore.get_value(selected_iter, 0, out valProject); | ||
698 | 654 | Name = new InputDialog(); | ||
699 | 655 | Name.show_all(); | ||
700 | 656 | Name.b_ok.clicked.connect (() => { | ||
701 | 657 | if (Db.DuplicatRequest((string)valProject, Name.get_text())){ | ||
702 | 658 | Name.Warnning.set_text("Already exists"); | ||
703 | 659 | Name.Warnning.show(); | ||
704 | 660 | return; | ||
705 | 661 | } | ||
706 | 662 | if (!Db.RegisterRequest( (string)valProject, Name.get_text(), _RequestGui.UrlText , _RequestGui.method, _RequestGui.DataText, _RequestGui.Header)) return ; | ||
707 | 663 | Gtk.TreeIter project_iter; | ||
708 | 664 | ProjectStore.append (out project_iter, selected_iter); | ||
709 | 665 | ProjectStore.set (project_iter, 0, Name.get_text(), -1); | ||
710 | 666 | Name.close(); | ||
711 | 667 | }); | ||
712 | 668 | } | ||
713 | 669 | } | ||
714 | 670 | |||
715 | 671 | public class InputDialog : Gtk.Window { | ||
716 | 672 | public Gtk.Button b_ok; | ||
717 | 673 | private Gtk.Entry input; | ||
718 | 674 | public Gtk.Label Warnning; | ||
719 | 675 | |||
720 | 676 | public InputDialog() { | ||
721 | 677 | this.title = "Restful-clientt"; | ||
722 | 678 | this.set_default_size (50, 30); | ||
723 | 679 | this.window_position = Gtk.WindowPosition.CENTER; | ||
724 | 680 | var hbox1 = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 5); | ||
725 | 681 | var vbox1 = new Gtk.Box (Gtk.Orientation.VERTICAL, 5); | ||
726 | 682 | input = new Gtk.Entry(); | ||
727 | 683 | Warnning = new Gtk.Label(""); | ||
728 | 684 | b_ok = new Gtk.Button.with_label ("Ok"); | ||
729 | 685 | input.set_placeholder_text("Set a name"); | ||
730 | 686 | hbox1.pack_start (Warnning, false, false, 5); | ||
731 | 687 | hbox1.pack_start (input, true, false, 5); | ||
732 | 688 | hbox1.pack_start (b_ok, false, false, 5); | ||
733 | 689 | vbox1.pack_start (hbox1, false, false, 5); | ||
734 | 690 | this.add(vbox1); | ||
735 | 691 | } | ||
736 | 692 | |||
737 | 693 | public string get_text() { | ||
738 | 694 | return input.get_text(); | ||
739 | 695 | } | ||
740 | 696 | } | ||
741 | 697 | |||
742 | 698 | } | ||
743 | 699 | public Midori.Extension extension_init () { | ||
744 | 700 | return new RestFul.Manager (); | ||
745 | 701 | } | ||
746 | 702 | |||
747 | 0 | 703 | ||
748 | === modified file 'extensions/webmedia-now-playing.vala' | |||
749 | --- extensions/webmedia-now-playing.vala 2014-07-31 13:25:05 +0000 | |||
750 | +++ extensions/webmedia-now-playing.vala 2014-12-31 23:30:47 +0000 | |||
751 | @@ -9,7 +9,7 @@ | |||
752 | 9 | See the file COPYING for the full license text. | 9 | See the file COPYING for the full license text. |
753 | 10 | */ | 10 | */ |
754 | 11 | 11 | ||
756 | 12 | namespace Sandcat { | 12 | namespace WebMedia { |
757 | 13 | 13 | ||
758 | 14 | private class Manager : Midori.Extension { | 14 | private class Manager : Midori.Extension { |
759 | 15 | DbusService dbus_service { get; set; } | 15 | DbusService dbus_service { get; set; } |
760 | @@ -33,18 +33,27 @@ | |||
761 | 33 | web_media_uri = browser.uri; | 33 | web_media_uri = browser.uri; |
762 | 34 | web_media_title = browser.title; | 34 | web_media_title = browser.title; |
763 | 35 | try { | 35 | try { |
765 | 36 | var youtube = new Regex("""(http|https)://www.youtube.com/watch\?v=[&=_\-A-Za-z0-9.]+"""); | 36 | var youtube = new Regex("""(http|https)://www.youtube.com/watch\?v=[&=_\-A-Za-z0-9.\|]+"""); |
766 | 37 | var vimeo = new Regex("""(http|https)://vimeo.com/[0-9]+"""); | 37 | var vimeo = new Regex("""(http|https)://vimeo.com/[0-9]+"""); |
767 | 38 | var dailymotion = new Regex("""(http|https)://www.dailymotion.com/video/[_\-A-Za-z0-9]+"""); | 38 | var dailymotion = new Regex("""(http|https)://www.dailymotion.com/video/[_\-A-Za-z0-9]+"""); |
768 | 39 | var coud = new Regex("""(http|https)://coub.com/view/[&=_\-A-Za-z0-9.\|]+"""); | ||
769 | 40 | var zippcast = new Regex("""(http|https)://www.zippcast.com/video/[&=_\-A-Za-z0-9.\|]+"""); | ||
770 | 41 | |||
771 | 39 | string website = null; | 42 | string website = null; |
773 | 40 | if (web_media_uri.contains("youtube") || web_media_uri.contains("vimeo") || web_media_uri.contains ("dailymotion")) { | 43 | if (web_media_uri.contains("youtube") || web_media_uri.contains("vimeo") || |
774 | 44 | web_media_uri.contains ("dailymotion") || web_media_uri.contains ("coub") || | ||
775 | 45 | web_media_uri.contains ("zippcast") ) { | ||
776 | 41 | if (youtube.match(web_media_uri)) | 46 | if (youtube.match(web_media_uri)) |
777 | 42 | website = "Youtube"; | 47 | website = "Youtube"; |
778 | 43 | else if (vimeo.match(web_media_uri)) | 48 | else if (vimeo.match(web_media_uri)) |
779 | 44 | website = "Vimeo"; | 49 | website = "Vimeo"; |
780 | 45 | else if (dailymotion.match(web_media_uri)) | 50 | else if (dailymotion.match(web_media_uri)) |
781 | 46 | website = "Dailymotion"; | 51 | website = "Dailymotion"; |
783 | 47 | 52 | else if (coud.match(web_media_uri)) | |
784 | 53 | website = "Coud"; | ||
785 | 54 | else if (zippcast.match(web_media_uri)) | ||
786 | 55 | website = "ZippCast"; | ||
787 | 56 | |||
788 | 48 | if (website != null) { | 57 | if (website != null) { |
789 | 49 | dbus_service.video_title = web_media_title; | 58 | dbus_service.video_title = web_media_title; |
790 | 50 | web_media_notify.notify_media = website; | 59 | web_media_notify.notify_media = website; |
791 | @@ -136,5 +145,5 @@ | |||
792 | 136 | } | 145 | } |
793 | 137 | 146 | ||
794 | 138 | public Midori.Extension extension_init () { | 147 | public Midori.Extension extension_init () { |
796 | 139 | return new Sandcat.Manager (); | 148 | return new WebMedia.Manager (); |
797 | 140 | } | 149 | } |
This merge proposal contains mostly the same changes as lp:~axlrose112/midori/restful-client. A restful client and a webmedia extension change look mostly unrelated to me (but correct me if I'm wrong), so these should be separate merge proposals: one for the new extension, the restful client, and another for webmedia extension changes.