Merge lp:~axlrose112/midori/webmedia-now-playing into lp:midori

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
Reviewer Review Type Date Requested Status
Robert Roth (community) Needs Fixing
Review via email: mp+245478@code.launchpad.net

Description of the change

Add ZippCast for webmedia-now-playing extension
Correct some issues in Restful client extension

To post a comment you must log in.
Revision history for this message
Robert Roth (evfool) wrote :

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.

review: Needs Fixing

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

Subscribers

People subscribed via source and target branches

to all changes: