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

Subscribers

People subscribed via source and target branches

to all changes: