Merge lp:~voldyman/granite/contractor-wid-dep-new-Contractor into lp:~elementary-pantheon/granite/granite

Proposed by Akshay Shekher
Status: Superseded
Proposed branch: lp:~voldyman/granite/contractor-wid-dep-new-Contractor
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 649 lines (+200/-134)
4 files modified
demo/main.vala (+11/-38)
lib/Services/Contractor.vala (+146/-55)
lib/Widgets/ContractorMenu.vala (+14/-13)
lib/Widgets/ContractorView.vala (+29/-28)
To merge this branch: bzr merge lp:~voldyman/granite/contractor-wid-dep-new-Contractor
Reviewer Review Type Date Requested Status
Sergey "Shnatsel" Davidoff (community) Needs Fixing
Review via email: mp+158154@code.launchpad.net

This proposal has been superseded by a proposal from 2013-04-10.

Description of the change

the contractor widgets have been deprecated and the Services/Contractor.vala has been updated to work with the new Contractor API

To post a comment you must log in.
Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

This seems to break the ABI (according to Rico's check in deb-packaging) even thought it shouldn't.

review: Needs Fixing
557. By Akshay Shekher

Deprecated ContractorView and ContractorMenu. Added support for the new contractor API in services/Contractor.vala

558. By Akshay Shekher

Change the constructor of Contractor.vala to private

559. By Akshay Shekher

Changed GenericContract to ContractorContract and renamed arguments

560. By Akshay Shekher

fixed coding style

561. By Akshay Shekher

More OO contractor interface

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'demo/main.vala'
2--- demo/main.vala 2013-03-20 15:42:25 +0000
3+++ demo/main.vala 2013-04-10 16:09:20 +0000
4@@ -13,7 +13,7 @@
5 but WITHOUT ANY WARRANTY; without even the implied warranty of
6 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7 Lesser General Public License for more details.
8-
9+
10 You should have received a copy of the GNU Lesser General
11 Public License along with this library; if not, write to the
12 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
13@@ -275,33 +275,6 @@
14 right_sep.draw = false;
15 right_sep.set_expand (true);
16 main_toolbar.insert (right_sep, -1);
17-
18- // Contractor
19- var contractor_tab = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
20- var text_view = new Gtk.TextView ();
21-
22- var hash_tables = Granite.Services.Contractor.get_contract ("/.zip", "application/zip");
23- foreach (var hash_table in hash_tables) {
24- text_view.buffer.text += hash_table.lookup ("Name")
25- + ": " + hash_table.lookup ("Description")
26- + " icon: " + hash_table.lookup ("Exec") + "\n";
27- }
28-
29- contractor_tab.add (text_view);
30- contractor_tab.add (new Granite.Widgets.ContractorView ("file:///home/user/file.txt", "text/plain"));
31- var contractor_menu = new Granite.Widgets.ContractorMenu ("/home/user/file.txt", "text");
32- var contractor_button_image = new Gtk.Image.from_icon_name ("document-export",
33- Gtk.IconSize.LARGE_TOOLBAR);
34- var contractor_tool_item = new Granite.Widgets.ToolButtonWithMenu (contractor_button_image,
35- "Share", contractor_menu);
36- main_toolbar.insert (contractor_tool_item, -1);
37-
38- contractor_tool_item.halign = contractor_tool_item.valign = Gtk.Align.CENTER;
39-
40- var contractor_item = new SourceListItem ("Contractor");
41- contractor_item.page_num = page_switcher.append_page (contractor_tab, null);
42- services_category.add (contractor_item);
43-
44 // Search Entry
45 var search_entry = new Granite.Widgets.SearchBar ("Search");
46 var search_item = new Gtk.ToolItem ();
47@@ -343,42 +316,42 @@
48
49 private void show_light_window () {
50 var light_window = new Granite.Widgets.LightWindow ();
51-
52+
53 var light_window_notebook = new Granite.Widgets.StaticNotebook ();
54 var entry = new Gtk.Entry ();
55 var open_drop = new Gtk.ComboBoxText ();
56 var open_lbl = new LLabel ("Alwas Open Mpeg Video Files with Audience");
57-
58+
59 var grid = new Gtk.Grid ();
60 grid.attach (new Gtk.Image.from_icon_name ("video-x-generic", Gtk.IconSize.DIALOG), 0, 0, 1, 2);
61 grid.attach (entry, 1, 0, 1, 1);
62 grid.attach (new LLabel ("1.13 GB, Mpeg Video File"), 1, 1, 1, 1);
63-
64+
65 grid.attach (light_window_notebook, 0, 2, 2, 1);
66-
67+
68 var general = new Gtk.Grid ();
69 general.attach (new LLabel.markup ("<b>Info:</b>"), 0, 0, 2, 1);
70-
71+
72 general.attach (new LLabel.right ("Created:"), 0, 1, 1, 1);
73 general.attach (new LLabel.right ("Modified:"), 0, 2, 1, 1);
74 general.attach (new LLabel.right ("Opened:"), 0, 3, 1, 1);
75 general.attach (new LLabel.right ("Mimetype:"), 0, 4, 1, 1);
76 general.attach (new LLabel.right ("Location:"), 0, 5, 1, 1);
77-
78+
79 general.attach (new LLabel ("Today at 9:50 PM"), 1, 1, 1, 1);
80 general.attach (new LLabel ("Today at 9:50 PM"), 1, 2, 1, 1);
81 general.attach (new LLabel ("Today at 10:00 PM"), 1, 3, 1, 1);
82 general.attach (new LLabel ("video/mpeg"), 1, 4, 1, 1);
83 general.attach (new LLabel ("/home/daniel/Downloads"), 1, 5, 1, 1);
84-
85+
86 general.attach (new LLabel.markup ("<b>Open with:</b>"), 0, 6, 2, 1);
87 general.attach (open_drop, 0, 7, 2, 1);
88 general.attach (open_lbl, 0, 8, 2, 1);
89-
90+
91 light_window_notebook.append_page (general, new Gtk.Label ("General"));
92 light_window_notebook.append_page (new Gtk.Label ("More"), new Gtk.Label ("More"));
93 light_window_notebook.append_page (new Gtk.Label ("Sharing"), new Gtk.Label ("Sharing"));
94-
95+
96 open_lbl.margin_left = 24;
97 open_drop.margin_left = 12;
98 open_drop.append ("audience", "Audience");
99@@ -389,7 +362,7 @@
100 entry.text = "Cool Hand Luke";
101 general.column_spacing = 6;
102 general.row_spacing = 6;
103-
104+
105 light_window.add (grid);
106 light_window.show_all ();
107 }
108
109=== modified file 'lib/Services/Contractor.vala'
110--- lib/Services/Contractor.vala 2013-04-04 20:05:38 +0000
111+++ lib/Services/Contractor.vala 2013-04-10 16:09:20 +0000
112@@ -1,5 +1,6 @@
113 /***
114- Copyright (C) 2011-2013 Lucas Baudin <xapantu@gmail.com>
115+ Copyright (C) 2011-2013 Lucas Baudin <xapantu@gmail.com>,
116+ Akshay Shekher <voldyman666@gmail.com>
117
118 This program or library is free software; you can redistribute it
119 and/or modify it under the terms of the GNU Lesser General Public
120@@ -10,7 +11,7 @@
121 but WITHOUT ANY WARRANTY; without even the implied warranty of
122 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
123 Lesser General Public License for more details.
124-
125+
126 You should have received a copy of the GNU Lesser General
127 Public License along with this library; if not, write to the
128 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
129@@ -19,86 +20,176 @@
130
131 namespace Granite.Services {
132
133- [DBus (name = "org.elementary.contractor")]
134- interface ContractorDBus : Object
135- {
136+ public struct GenericContract {
137+ string id;
138+ string display_name;
139+ string description;
140+ string icon_path;
141+ }
142+
143+ [DBus (name = "org.elementary.Contractor")]
144+ interface ContractorDBus : Object {
145+ public abstract GenericContract[] list_all_contracts () throws Error;
146+ public abstract GenericContract[] get_contracts_by_mime (string mime_type) throws Error;
147+ public abstract GenericContract[] get_contracts_by_mimelist (string[] mime_types) throws Error;
148+ public abstract int execute_with_uri (string id, string path) throws Error;
149+ public abstract int execute_with_uri_list (string id, string[] path) throws Error;
150+ [Deprecated]
151 public abstract GLib.HashTable<string,string>[] GetServicesByLocation (string strlocation, string? file_mime="") throws IOError;
152+ [Deprecated]
153 public abstract GLib.HashTable<string,string>[] GetServicesByLocationsList (GLib.HashTable<string,string>[] locations) throws IOError;
154 }
155
156 /**
157 * A way to handle contractor, a way to communicate between apps.
158- *
159- * /!\ Highly unstable API
160+ *
161 */
162- public class Contractor : Object
163- {
164+ public class Contractor : Object {
165
166 internal ContractorDBus contract;
167
168 internal static Contractor? contractor = null;
169
170 /**
171- * This creates a new Contractor
172+ * This creates a new Contractor
173 */
174- public Contractor()
175- {
176- try
177- {
178+ public Contractor () {
179+ try {
180 contract = Bus.get_proxy_sync (BusType.SESSION,
181- "org.elementary.contractor",
182+ "org.elementary.Contractor",
183 "/org/elementary/contractor");
184- }
185- catch (IOError e)
186- {
187- stderr.printf ("%s\n", e.message);
188- }
189- }
190-
191- internal static void ensure ()
192- {
193- if(contractor == null) contractor = new Contractor ();
194- }
195-
196- /**
197- * This searches for available contracts of a particular file
198- *
199+ } catch (IOError e) {
200+ stderr.printf ("%s\n", e.message);
201+ }
202+ }
203+
204+ internal static void ensure () {
205+ if (contractor == null) {
206+ contractor = new Contractor ();
207+ }
208+ }
209+ /**
210+ * Lists all the contracts
211+ *
212+ * @return an array of struct GenericContract
213+ */
214+ public static GenericContract[] list_all_contracts () {
215+ ensure ();
216+ GenericContract[] contracts = null;
217+
218+ try {
219+ contracts = contractor.contract.list_all_contracts ();
220+ } catch (Error e) {
221+ stderr.printf ("%s\n", e.message);
222+ }
223+
224+ return contracts;
225+ }
226+ /**
227+ * This searches for available contracts of a particular file
228+ *
229+ * @param mime mime type of file
230+ * @return an array of struct GenericContract
231+ */
232+ public static GenericContract[] get_contracts_by_mime (string mime_type) {
233+ ensure ();
234+ GenericContract[] contracts = null;
235+
236+ try {
237+ contracts = contractor.contract.get_contracts_by_mime (mime_type);
238+ } catch (IOError e) {
239+ stderr.printf ("%s\n", e.message);
240+ }
241+
242+ return contracts;
243+ }
244+
245+ /**
246+ * generate contracts for a list of mime types. the contracts which support
247+ * all of them are returned
248+ *
249+ * @param locations Array of MimeTypes
250+ * @return array of struct (GenericContract)
251+ */
252+ public static GenericContract[] get_contracts_by_mimelist (string[] mime_types) {
253+ ensure ();
254+ GenericContract[] contracts = null;
255+
256+ try {
257+ contracts = contractor.contract.get_contracts_by_mimelist (mime_types);
258+ } catch (IOError e) {
259+ stderr.printf ("%s\n", e.message);
260+ }
261+
262+ return contracts;
263+ }
264+ /**
265+ * This executes the exec parameter provided by the contract of given id
266+ * with the path as arguments
267+ *
268+ * @param id id of the contract
269+ * @param paths path to execute
270+ * @return int status of execution
271+ */
272+ public static int execute_with_uri (string id, string path) {
273+ ensure ();
274+ int ret_val = 1;
275+
276+ try {
277+ ret_val = contractor.contract.execute_with_uri (id, path);
278+ } catch (Error e) {
279+ stderr.printf ("%s\n", e.message);
280+ }
281+ return ret_val;
282+ }
283+ /**
284+ * This executes the exec parameter provided by the contract of given id
285+ * with the paths as arguments
286+ *
287+ * @param id id of the contract
288+ * @param paths array of paths to execute
289+ * @return int status of execution
290+ */
291+ public static int execute_with_uri_list (string id, string[] paths) {
292+ ensure ();
293+ int ret_val = 1;
294+
295+ try {
296+ ret_val = contractor.contract.execute_with_uri_list (id, paths);
297+ } catch (Error e) {
298+ stderr.printf ("%s\n", e.message);
299+ }
300+ return ret_val;
301+ }
302+ /**
303+ * The functions below have been deprecated in order to support the
304+ * the new contractor API.
305+ */
306+
307+ /**
308+ * This searches for available contracts of a particular file
309+ *
310 * @param uri uri of file
311 * @param mime mime type of file
312 * @return Hashtable of available contracts
313 */
314- public static GLib.HashTable<string,string>[] get_contract(string uri, string mime)
315- {
316- ensure ();
317- GLib.HashTable<string,string>[] contracts = null;
318-
319- try {
320- contracts = contractor.contract.GetServicesByLocation(uri, mime);
321- }catch (IOError e) {
322- stderr.printf ("%s\n", e.message);
323- }
324-
325- return contracts;
326+ [Deprecated]
327+ public static GLib.HashTable<string,string>[] get_contract(string uri, string mime) {
328+
329+ return { new GLib.HashTable<string,string> (null, null) };
330 }
331
332 /**
333 * generate contracts for rguments and filter them by common parent mimetype.
334- *
335+ *
336 * @param locations Hashtable of locations
337 * @return Hashtable of available contracts
338 */
339- public static GLib.HashTable<string,string>[] get_selection_contracts (GLib.HashTable<string, string>[] locations)
340- {
341- ensure ();
342- GLib.HashTable<string,string>[] contracts = null;
343-
344- try {
345- contracts = contractor.contract.GetServicesByLocationsList (locations);
346- }catch (IOError e) {
347- stderr.printf ("%s\n", e.message);
348- }
349-
350- return contracts;
351+ [Deprecated]
352+ public static GLib.HashTable<string,string>[] get_selection_contracts (GLib.HashTable<string, string>[] locations) {
353+
354+ return { new GLib.HashTable<string,string> (null, null) };
355 }
356 }
357 }
358+
359
360=== modified file 'lib/Widgets/ContractorMenu.vala'
361--- lib/Widgets/ContractorMenu.vala 2013-03-20 15:42:25 +0000
362+++ lib/Widgets/ContractorMenu.vala 2013-04-10 16:09:20 +0000
363@@ -10,7 +10,7 @@
364 but WITHOUT ANY WARRANTY; without even the implied warranty of
365 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
366 Lesser General Public License for more details.
367-
368+
369 You should have received a copy of the GNU Lesser General
370 Public License along with this library; if not, write to the
371 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
372@@ -20,6 +20,7 @@
373 /**
374 * This class provides a simple menu for managing Contractor.
375 */
376+[Deprecated]
377 public class Granite.Widgets.ContractorMenu : Gtk.Menu {
378 /**
379 * The Hashtable of available contracts
380@@ -32,12 +33,12 @@
381 public delegate void ContractCallback ();
382 private string filepath;
383 private string filemime;
384-
385+
386 /**
387 * Passes when contract is clicked
388 */
389 public signal void contract_activated (string contract_name);
390-
391+
392 /**
393 * Makes new Contractor Meu
394 *
395@@ -49,7 +50,7 @@
396 filemime = mime;
397 load_items (filename, mime);
398 }
399-
400+
401 /**
402 * Adds new item to Contractor Menu
403 *
404@@ -73,7 +74,7 @@
405 insert(item, position);
406 item.show ();
407 }
408-
409+
410 /**
411 * Deletes a group of menu items
412 *
413@@ -85,14 +86,14 @@
414 remove (item);
415 });
416 }
417-
418+
419 private void load_items (string filename, string mime) {
420 contracts = Granite.Services.Contractor.get_contract (filename, mime);
421 execs = new Gee.HashMap<string,string> ();
422-
423+
424 for (int i=0;i<contracts.length;i++) {
425 execs[contracts[i].lookup ("Name")] = contracts[i].lookup ("Exec");
426-
427+
428 var item = new Gtk.ImageMenuItem ();
429 item.set_always_show_image (true);
430 var image = new Gtk.Image.from_icon_name (contracts[i].lookup ("IconName"), Gtk.IconSize.MENU);
431@@ -109,7 +110,7 @@
432 item.show_all ();
433 }
434 }
435-
436+
437 /**
438 * Updates Contractor menu items
439 *
440@@ -118,24 +119,24 @@
441 */
442 public void update (string? filename, string? mime) {
443 this.foreach ((w) => {remove (w);});
444-
445+
446 string fn = "";
447 string mm = "";
448-
449+
450 if (filename != null) {
451 fn = filename;
452 filepath = filename;
453 } else {
454 fn = filepath;
455 }
456-
457+
458 if (mime != null) {
459 mm = mime;
460 filemime = mime;
461 } else {
462 mm = filemime;
463 }
464-
465+
466 load_items (fn, mm);
467 }
468 }
469
470=== modified file 'lib/Widgets/ContractorView.vala'
471--- lib/Widgets/ContractorView.vala 2013-03-20 15:42:25 +0000
472+++ lib/Widgets/ContractorView.vala 2013-04-10 16:09:20 +0000
473@@ -10,7 +10,7 @@
474 but WITHOUT ANY WARRANTY; without even the implied warranty of
475 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
476 Lesser General Public License for more details.
477-
478+
479 You should have received a copy of the GNU Lesser General
480 Public License along with this library; if not, write to the
481 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
482@@ -22,20 +22,21 @@
483 /**
484 * This class provides a simple way to look at contracts from Contractor
485 */
486+[Deprecated ()]
487 public class Granite.Widgets.ContractorView : TreeView {
488-
489+
490 /**
491 * indicates if it was possible to connect to contractor
492 */
493 public bool contractor_available;
494-
495+
496 public delegate void ContractCallback ();
497 private Gee.HashMap<int, DelegateWrapper?> outsiders;
498 private int[] blacklisted_pos;
499 private ListStore list;
500
501 private struct DelegateWrapper { unowned ContractCallback method; }
502-
503+
504 /**
505 * the index of the currently selected contract
506 */
507@@ -49,17 +50,17 @@
508 this.set_cursor (new TreePath.from_string (value.to_string ()), null, false);
509 }
510 }
511-
512+
513 /**
514 * A contract was launched using double clicking
515 */
516 public signal void executed ();
517-
518+
519 /**
520 * the original array of contracts returned by contractor
521 */
522 HashTable<string,string>[] contracts;
523-
524+
525 /**
526 * Create the default ContractorView
527 *
528@@ -73,17 +74,17 @@
529 list = new ListStore (2, typeof (Gdk.Pixbuf), typeof (string));
530 outsiders = new Gee.HashMap<int, DelegateWrapper?> ();
531 this.model = list;
532-
533+
534 /* GUI */
535 this.headers_visible = false;
536 this.hexpand = true;
537-
538+
539 /* Events */
540- row_activated.connect (() => {
541+ row_activated.connect (() => {
542 run_selected ();
543 executed ();
544 });
545-
546+
547 /* View */
548 var cell1 = new CellRendererPixbuf ();
549 cell1.set_padding (5, 8);
550@@ -102,9 +103,9 @@
551 string message = contractor_installed ? _("Could not contact Contractor. You may need to install it") : _("No action found for this file");
552 try {
553 var icon = IconTheme.get_default ().load_icon (
554- contractor_installed ? Gtk.Stock.DIALOG_ERROR : Gtk.Stock.DIALOG_INFO,
555+ contractor_installed ? Gtk.Stock.DIALOG_ERROR : Gtk.Stock.DIALOG_INFO,
556 icon_size, 0);
557- list.set (it,
558+ list.set (it,
559 0, icon, 1, message);
560 }
561 catch (Error e) {
562@@ -114,7 +115,7 @@
563 }
564 else {
565 contractor_available = true;
566-
567+
568 for (var i=0; i<this.contracts.length; i++){
569 TreeIter it;
570 list.append (out it);
571@@ -122,8 +123,8 @@
572 if (show_contract_name)
573 text = "<b>"+this.contracts[i].lookup ("Name")+"</b>\n"+text;
574 try{
575- list.set (it,
576- 0, IconTheme.get_default ().load_icon (this.contracts[i].lookup ("IconName"),
577+ list.set (it,
578+ 0, IconTheme.get_default ().load_icon (this.contracts[i].lookup ("IconName"),
579 icon_size, 0), 1, text);
580 }
581 catch (Error e) {
582@@ -133,7 +134,7 @@
583 this.selected = 0;
584 }
585 }
586-
587+
588 /**
589 * A method to add items to the tree
590 *
591@@ -148,21 +149,21 @@
592 public void add_item (string name, string desc, string icon_name, int icon_size, int position, ContractCallback method) {
593 TreeIter it;
594 list.insert (out it, position);
595-
596+
597 string text = "<b>" + name + "</b>\n" + desc;
598-
599+
600 try{
601 list.set (it, 0, IconTheme.get_default ().load_icon (icon_name, icon_size, 0), 1, text);
602 } catch (Error e) {
603 error (e.message);
604 }
605-
606+
607 DelegateWrapper wr = { method };
608 outsiders[position] = wr;
609-
610+
611 this.selected = 0;
612 }
613-
614+
615 public void name_blacklist (string[] names) {
616 TreeIter it;
617 TreeIter it2;
618@@ -171,25 +172,25 @@
619 int cur_pos = 0;
620 list.get_iter_first (out it);
621 list.get_iter_first (out it2);
622-
623+
624 while (true) {
625 list.get_value (it, 1, out value);
626 check = list.iter_next (ref it2);
627 string text = value.get_string ();
628-
629+
630 if (text[3:text.index_of ("</b>")] in names) {
631 list.remove (it);
632 blacklisted_pos += cur_pos;
633 }
634 if (!check)
635 break;
636-
637+
638 it = it2;
639- cur_pos++;
640+ cur_pos++;
641 }
642 }
643-
644-
645+
646+
647 public void run_selected () {
648 if (this.selected in outsiders.keys ) {
649 outsiders[this.selected].method ();

Subscribers

People subscribed via source and target branches