Merge lp:~victored/granite/contractor-wrapper into lp:~elementary-pantheon/granite/granite

Proposed by Victor Martinez
Status: Merged
Merged at revision: 559
Proposed branch: lp:~victored/granite/contractor-wrapper
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 508 lines (+269/-120)
6 files modified
demo/main.vala (+11/-37)
lib/CMakeLists.txt (+1/-0)
lib/Services/Contractor.vala (+67/-0)
lib/Services/ContractorProxy.vala (+188/-83)
lib/Widgets/ContractorMenu.vala (+1/-0)
lib/Widgets/ContractorView.vala (+1/-0)
To merge this branch: bzr merge lp:~victored/granite/contractor-wrapper
Reviewer Review Type Date Requested Status
Sergey "Shnatsel" Davidoff (community) Approve
Victor Martinez (community) Approve
Review via email: mp+159948@code.launchpad.net

Description of the change

I've modified the public API of Contractor to be contract-id independent, so that we encourage code that manages contracts "blindly".

---
Akshay will be away from coding for a couple of days (or weeks?), so I'm proposing this alternative API for contractor. This is based on Akshay's work.

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

After a long discussion about the API this seems to be the best option we could possibly get. Yay!

There are two things to do before this goes in:
1) Update Contractor daemon D-bus API to throw errors
2) Create a test client for this API

review: Approve
Revision history for this message
Victor Martinez (victored) wrote :
Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

Too bad I can't test it with testing scripts because the Granite build fails due to symbol changes.

Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

Here are the symbol changes: http://pastebin.com/dyGnNqUi

Looks like this branch breaks ABI.

Revision history for this message
Victor Martinez (victored) wrote :

Indeed, this breaks the ABI, since it removes the constructors. I want to propose a solution that doesn't break the ABI:

1) Leave the previous Contractor class and it's DBus interface as they are, make their methods return empty hashmaps, and add the proper deprecation annotations. In other words, leave the previous contractor ABI untouched.

2) In addition to (1), Modify the class name for the new Contractor API. Instead of Granite.Services.Contractor we could use something like Granite.Services.ContractorProxy (please let me know if you can figure out a better name!) for the new API. This way we only add symbols without removing or modifying any previous symbol.

review: Needs Fixing
Revision history for this message
Rico Tzschichholz (ricotz) wrote :

"Removing" the constructor is fine since it is suppose to be a singleton which is a needed API break. And preserving ABI in this area shouldn't be a target anyway. So better break it for real if the consumers are fixable in no-time.

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

Please list/mention the current consumers of the contractor api

Revision history for this message
Victor Martinez (victored) wrote :

The only ones I know are Scratch and Pantheon Files. Of course there might be others, but since the new API depends on a new daemon, those applications will have to migrate to the new API eventually.

I am handling the port of Pantheon Files to the new API on the branch mentioned above.

The ABI breakage should be gone now.

Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

Here's a list of current Contractor users (From https://docs.google.com/a/elementaryos.org/document/d/1Ijsc57vYEHBZxVdM0fRgCuBX2NbdRDv1kuOj0OG75v4/edit#):

    ContractorMenu widget in Granite

    ContractorView widget in Granite

    Context menu of Pantheon-Files

    Maya, Scratch, Midori and elementary-flavored Simple Scan access Contractor via Granite convenience functions and rely on the fact that Contractor returns a string to be executed

    Eidete uses ContractorView widget from Granite, needs to be updated due to API break

Revision history for this message
Victor Martinez (victored) wrote :

ABI break fixed. Now we only have symbol additions and no removals.

Build log: http://pastebin.ubuntu.com/5594664/

Revision history for this message
Victor Martinez (victored) wrote :

The current merge stopper is bug #1171690 IMO.

review: Needs Fixing
Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

Bug #1171690 debunked.

Revision history for this message
Victor Martinez (victored) :
review: Approve
Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

I've tested it with lp:~victored/pantheon-files/contractor-plugin and it seems to work fine.

review: Approve
574. By Victor Martinez

Contracts can specify either an icon name or an absolute path to an icon file. Make sure we support both of them properly.

575. By Victor Martinez

Avoid copying structs to avoid segmentation fault

Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

Files still exhibits a bug that's not present in raw D-bus API: https://dl.dropboxusercontent.com/u/5279564/contractor-item-dupe-bug.webm

review: Needs Fixing
Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

After this is approved I'll land Contractor 0.3 to PPA. Everything is ready, we just have to enable the recipe: https://code.launchpad.net/~elementary-os/+recipe/contractor-daily

576. By Victor Martinez

Let's keep the references to the contracts around all the time.

Previously we were depending on references held by client code, but it's a source of bugs, so better keep our own references in addition to external references.

Revision history for this message
Victor Martinez (victored) wrote :

> Files still exhibits a bug that's not present in raw D-bus API: https://dl.dropboxusercontent.com/u/5279564/contractor-item-dupe-bug.webm

This bug is only related to Files. The DBus API and this wrapper API are doing their job properly.

Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

Works fine for me now. Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'demo/main.vala'
--- demo/main.vala 2013-03-20 15:42:25 +0000
+++ demo/main.vala 2013-04-24 17:07:27 +0000
@@ -13,7 +13,7 @@
13 but WITHOUT ANY WARRANTY; without even the implied warranty of13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.15 Lesser General Public License for more details.
16 16
17 You should have received a copy of the GNU Lesser General17 You should have received a copy of the GNU Lesser General
18 Public License along with this library; if not, write to the18 Public License along with this library; if not, write to the
19 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,19 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
@@ -276,32 +276,6 @@
276 right_sep.set_expand (true);276 right_sep.set_expand (true);
277 main_toolbar.insert (right_sep, -1);277 main_toolbar.insert (right_sep, -1);
278278
279 // Contractor
280 var contractor_tab = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
281 var text_view = new Gtk.TextView ();
282
283 var hash_tables = Granite.Services.Contractor.get_contract ("/.zip", "application/zip");
284 foreach (var hash_table in hash_tables) {
285 text_view.buffer.text += hash_table.lookup ("Name")
286 + ": " + hash_table.lookup ("Description")
287 + " icon: " + hash_table.lookup ("Exec") + "\n";
288 }
289
290 contractor_tab.add (text_view);
291 contractor_tab.add (new Granite.Widgets.ContractorView ("file:///home/user/file.txt", "text/plain"));
292 var contractor_menu = new Granite.Widgets.ContractorMenu ("/home/user/file.txt", "text");
293 var contractor_button_image = new Gtk.Image.from_icon_name ("document-export",
294 Gtk.IconSize.LARGE_TOOLBAR);
295 var contractor_tool_item = new Granite.Widgets.ToolButtonWithMenu (contractor_button_image,
296 "Share", contractor_menu);
297 main_toolbar.insert (contractor_tool_item, -1);
298
299 contractor_tool_item.halign = contractor_tool_item.valign = Gtk.Align.CENTER;
300
301 var contractor_item = new SourceListItem ("Contractor");
302 contractor_item.page_num = page_switcher.append_page (contractor_tab, null);
303 services_category.add (contractor_item);
304
305 // Search Entry279 // Search Entry
306 var search_entry = new Granite.Widgets.SearchBar ("Search");280 var search_entry = new Granite.Widgets.SearchBar ("Search");
307 var search_item = new Gtk.ToolItem ();281 var search_item = new Gtk.ToolItem ();
@@ -343,42 +317,42 @@
343317
344 private void show_light_window () {318 private void show_light_window () {
345 var light_window = new Granite.Widgets.LightWindow ();319 var light_window = new Granite.Widgets.LightWindow ();
346 320
347 var light_window_notebook = new Granite.Widgets.StaticNotebook ();321 var light_window_notebook = new Granite.Widgets.StaticNotebook ();
348 var entry = new Gtk.Entry ();322 var entry = new Gtk.Entry ();
349 var open_drop = new Gtk.ComboBoxText ();323 var open_drop = new Gtk.ComboBoxText ();
350 var open_lbl = new LLabel ("Alwas Open Mpeg Video Files with Audience");324 var open_lbl = new LLabel ("Alwas Open Mpeg Video Files with Audience");
351 325
352 var grid = new Gtk.Grid ();326 var grid = new Gtk.Grid ();
353 grid.attach (new Gtk.Image.from_icon_name ("video-x-generic", Gtk.IconSize.DIALOG), 0, 0, 1, 2);327 grid.attach (new Gtk.Image.from_icon_name ("video-x-generic", Gtk.IconSize.DIALOG), 0, 0, 1, 2);
354 grid.attach (entry, 1, 0, 1, 1);328 grid.attach (entry, 1, 0, 1, 1);
355 grid.attach (new LLabel ("1.13 GB, Mpeg Video File"), 1, 1, 1, 1);329 grid.attach (new LLabel ("1.13 GB, Mpeg Video File"), 1, 1, 1, 1);
356 330
357 grid.attach (light_window_notebook, 0, 2, 2, 1);331 grid.attach (light_window_notebook, 0, 2, 2, 1);
358 332
359 var general = new Gtk.Grid ();333 var general = new Gtk.Grid ();
360 general.attach (new LLabel.markup ("<b>Info:</b>"), 0, 0, 2, 1);334 general.attach (new LLabel.markup ("<b>Info:</b>"), 0, 0, 2, 1);
361 335
362 general.attach (new LLabel.right ("Created:"), 0, 1, 1, 1);336 general.attach (new LLabel.right ("Created:"), 0, 1, 1, 1);
363 general.attach (new LLabel.right ("Modified:"), 0, 2, 1, 1);337 general.attach (new LLabel.right ("Modified:"), 0, 2, 1, 1);
364 general.attach (new LLabel.right ("Opened:"), 0, 3, 1, 1);338 general.attach (new LLabel.right ("Opened:"), 0, 3, 1, 1);
365 general.attach (new LLabel.right ("Mimetype:"), 0, 4, 1, 1);339 general.attach (new LLabel.right ("Mimetype:"), 0, 4, 1, 1);
366 general.attach (new LLabel.right ("Location:"), 0, 5, 1, 1);340 general.attach (new LLabel.right ("Location:"), 0, 5, 1, 1);
367 341
368 general.attach (new LLabel ("Today at 9:50 PM"), 1, 1, 1, 1);342 general.attach (new LLabel ("Today at 9:50 PM"), 1, 1, 1, 1);
369 general.attach (new LLabel ("Today at 9:50 PM"), 1, 2, 1, 1);343 general.attach (new LLabel ("Today at 9:50 PM"), 1, 2, 1, 1);
370 general.attach (new LLabel ("Today at 10:00 PM"), 1, 3, 1, 1);344 general.attach (new LLabel ("Today at 10:00 PM"), 1, 3, 1, 1);
371 general.attach (new LLabel ("video/mpeg"), 1, 4, 1, 1);345 general.attach (new LLabel ("video/mpeg"), 1, 4, 1, 1);
372 general.attach (new LLabel ("/home/daniel/Downloads"), 1, 5, 1, 1);346 general.attach (new LLabel ("/home/daniel/Downloads"), 1, 5, 1, 1);
373 347
374 general.attach (new LLabel.markup ("<b>Open with:</b>"), 0, 6, 2, 1);348 general.attach (new LLabel.markup ("<b>Open with:</b>"), 0, 6, 2, 1);
375 general.attach (open_drop, 0, 7, 2, 1);349 general.attach (open_drop, 0, 7, 2, 1);
376 general.attach (open_lbl, 0, 8, 2, 1);350 general.attach (open_lbl, 0, 8, 2, 1);
377 351
378 light_window_notebook.append_page (general, new Gtk.Label ("General"));352 light_window_notebook.append_page (general, new Gtk.Label ("General"));
379 light_window_notebook.append_page (new Gtk.Label ("More"), new Gtk.Label ("More"));353 light_window_notebook.append_page (new Gtk.Label ("More"), new Gtk.Label ("More"));
380 light_window_notebook.append_page (new Gtk.Label ("Sharing"), new Gtk.Label ("Sharing"));354 light_window_notebook.append_page (new Gtk.Label ("Sharing"), new Gtk.Label ("Sharing"));
381 355
382 open_lbl.margin_left = 24;356 open_lbl.margin_left = 24;
383 open_drop.margin_left = 12;357 open_drop.margin_left = 12;
384 open_drop.append ("audience", "Audience");358 open_drop.append ("audience", "Audience");
@@ -389,7 +363,7 @@
389 entry.text = "Cool Hand Luke";363 entry.text = "Cool Hand Luke";
390 general.column_spacing = 6;364 general.column_spacing = 6;
391 general.row_spacing = 6;365 general.row_spacing = 6;
392 366
393 light_window.add (grid);367 light_window.add (grid);
394 light_window.show_all ();368 light_window.show_all ();
395 }369 }
396370
=== modified file 'lib/CMakeLists.txt'
--- lib/CMakeLists.txt 2012-12-21 00:46:56 +0000
+++ lib/CMakeLists.txt 2013-04-24 17:07:27 +0000
@@ -16,6 +16,7 @@
16 Services/Paths.vala16 Services/Paths.vala
17 Services/System.vala17 Services/System.vala
18 Services/Contractor.vala18 Services/Contractor.vala
19 Services/ContractorProxy.vala
19 Services/IconFactory.vala20 Services/IconFactory.vala
20 Services/SimpleCommand.vala21 Services/SimpleCommand.vala
21 Widgets/Utils.vala22 Widgets/Utils.vala
2223
=== added file 'lib/Services/Contractor.vala'
--- lib/Services/Contractor.vala 1970-01-01 00:00:00 +0000
+++ lib/Services/Contractor.vala 2013-04-24 17:07:27 +0000
@@ -0,0 +1,67 @@
1/***
2 Copyright (C) 2011-2013 Lucas Baudin <xapantu@gmail.com>
3
4 This program or library is free software; you can redistribute it
5 and/or modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library; if not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301 USA.
18***/
19
20namespace Granite.Services {
21 [DBus (name = "org.elementary.Contractor")]
22 interface ContractorDBus : Object {
23 public abstract GLib.HashTable<string,string>[] GetServicesByLocation (string strlocation, string? file_mime = "") throws IOError;
24 public abstract GLib.HashTable<string,string>[] GetServicesByLocationsList (GLib.HashTable<string,string>[] locations) throws IOError;
25 }
26
27 /**
28 * A way to handle contractor, a way to communicate between apps.
29 *
30 * /!\ Highly unstable API
31 */
32 [Deprecated (replacement = "Granite.Services.ContractorProxy", since = "0.2")]
33 public class Contractor : Object {
34 internal ContractorDBus contract;
35 internal static Contractor? contractor = null;
36
37 /**
38 * This creates a new Contractor
39 */
40 public Contractor () {
41 }
42
43 internal static void ensure () {
44 }
45
46 /**
47 * This searches for available contracts of a particular file
48 *
49 * @param uri uri of file
50 * @param mime mime type of file
51 * @return Hashtable of available contracts
52 */
53 public static GLib.HashTable<string,string>[] get_contract (string uri, string mime) {
54 return { new GLib.HashTable<string,string> (null, null) };
55 }
56
57 /**
58 * generate contracts for arguments and filter them by common parent mimetype.
59 *
60 * @param locations Hashtable of locations
61 * @return Hashtable of available contracts
62 */
63 public static GLib.HashTable<string,string>[] get_selection_contracts (GLib.HashTable<string, string>[] locations) {
64 return { new GLib.HashTable<string,string> (null, null) };
65 }
66 }
67}
068
=== renamed file 'lib/Services/Contractor.vala' => 'lib/Services/ContractorProxy.vala'
--- lib/Services/Contractor.vala 2013-04-04 20:05:38 +0000
+++ lib/Services/ContractorProxy.vala 2013-04-24 17:07:27 +0000
@@ -1,5 +1,7 @@
1/***1/***
2 Copyright (C) 2011-2013 Lucas Baudin <xapantu@gmail.com>2 Copyright (C) 2011-2013 Lucas Baudin <xapantu@gmail.com>,
3 Akshay Shekher <voldyman666@gmail.com>,
4 Victor Martinez <victoreduardm@gmail.com>
35
4 This program or library is free software; you can redistribute it6 This program or library is free software; you can redistribute it
5 and/or modify it under the terms of the GNU Lesser General Public7 and/or modify it under the terms of the GNU Lesser General Public
@@ -10,7 +12,7 @@
10 but WITHOUT ANY WARRANTY; without even the implied warranty of12 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.14 Lesser General Public License for more details.
13 15
14 You should have received a copy of the GNU Lesser General16 You should have received a copy of the GNU Lesser General
15 Public License along with this library; if not, write to the17 Public License along with this library; if not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
@@ -18,87 +20,190 @@
18***/20***/
1921
20namespace Granite.Services {22namespace Granite.Services {
2123 public interface Contract : Object {
22 [DBus (name = "org.elementary.contractor")]24 public abstract string get_display_name ();
23 interface ContractorDBus : Object25 public abstract string get_description ();
24 {26 public abstract Icon get_icon ();
25 public abstract GLib.HashTable<string,string>[] GetServicesByLocation (string strlocation, string? file_mime="") throws IOError;27 public abstract int execute_with_file (File file) throws Error;
26 public abstract GLib.HashTable<string,string>[] GetServicesByLocationsList (GLib.HashTable<string,string>[] locations) throws IOError;28 public abstract int execute_with_files (File[] files) throws Error;
27 }29 }
2830
29 /**31 public errordomain ContractorError {
30 * A way to handle contractor, a way to communicate between apps.32 SERVICE_NOT_AVAILABLE
31 * 33 }
32 * /!\ Highly unstable API34
33 */35 internal struct ContractData {
34 public class Contractor : Object36 string id;
35 {37 string display_name;
3638 string description;
37 internal ContractorDBus contract;39 string icon;
3840 }
39 internal static Contractor? contractor = null;41
4042 [DBus (name = "org.elementary.Contractor")]
41 /**43 internal interface ContractorDBusAPI : Object {
42 * This creates a new Contractor 44 public abstract ContractData[] list_all_contracts () throws Error;
43 */45 public abstract ContractData[] get_contracts_by_mime (string mime_type) throws Error;
44 public Contractor()46 public abstract ContractData[] get_contracts_by_mimelist (string[] mime_types) throws Error;
45 {47 public abstract int execute_with_uri (string id, string uri) throws Error;
46 try48 public abstract int execute_with_uri_list (string id, string[] uri) throws Error;
47 {49 }
48 contract = Bus.get_proxy_sync (BusType.SESSION,50
49 "org.elementary.contractor",51 public class ContractorProxy {
50 "/org/elementary/contractor");52 private class GenericContract : Object, Contract {
51 }53 private string id;
52 catch (IOError e)54 private string display_name;
53 {55 private string description;
54 stderr.printf ("%s\n", e.message);56 private string icon_key;
55 }57
56 }58 private Icon icon;
5759
58 internal static void ensure ()60 public GenericContract (ContractData data) {
59 {61 icon_key = "";
60 if(contractor == null) contractor = new Contractor ();62 update_data (data);
61 }63 }
6264
63 /**65 public void update_data (ContractData data) {
64 * This searches for available contracts of a particular file66 id = data.id ?? "";
65 * 67 display_name = data.display_name ?? "";
66 * @param uri uri of file68 description = data.description ?? "";
67 * @param mime mime type of file69
68 * @return Hashtable of available contracts70 if (icon_key != data.icon) {
69 */71 icon_key = data.icon ?? "";
70 public static GLib.HashTable<string,string>[] get_contract(string uri, string mime)72 icon = null;
71 {73 }
72 ensure ();74 }
73 GLib.HashTable<string,string>[] contracts = null;75
7476 public string get_display_name () {
75 try {77 return display_name;
76 contracts = contractor.contract.GetServicesByLocation(uri, mime);78 }
77 }catch (IOError e) {79
78 stderr.printf ("%s\n", e.message);80 public string get_description () {
79 }81 return description;
8082 }
81 return contracts;83
82 }84 public Icon get_icon () {
8385 if (icon == null) {
84 /**86 if (Path.is_absolute (icon_key))
85 * generate contracts for rguments and filter them by common parent mimetype.87 icon = new FileIcon (File.new_for_path (icon_key));
86 * 88 else
87 * @param locations Hashtable of locations89 icon = new ThemedIcon.with_default_fallbacks (icon_key);
88 * @return Hashtable of available contracts90 }
89 */91
90 public static GLib.HashTable<string,string>[] get_selection_contracts (GLib.HashTable<string, string>[] locations)92 return icon;
91 {93 }
92 ensure ();94
93 GLib.HashTable<string,string>[] contracts = null;95 public int execute_with_file (File file) throws Error {
9496 return ContractorProxy.execute_with_uri (id, file.get_uri ());
95 try {97 }
96 contracts = contractor.contract.GetServicesByLocationsList (locations);98
97 }catch (IOError e) {99 public int execute_with_files (File[] files) throws Error {
98 stderr.printf ("%s\n", e.message);100 string[] uris = new string[files.length];
99 }101
100102 foreach (var file in files)
101 return contracts;103 uris += file.get_uri ();
104
105 return ContractorProxy.execute_with_uri_list (id, uris);
106 }
107 }
108
109
110 private static ContractorDBusAPI contractor_dbus;
111 private static Gee.HashMap<string, GenericContract> contracts;
112
113 private ContractorProxy () { }
114
115 private static void ensure () throws Error {
116 if (contractor_dbus == null) {
117 try {
118 contractor_dbus = Bus.get_proxy_sync (BusType.SESSION,
119 "org.elementary.Contractor",
120 "/org/elementary/contractor");
121 } catch (IOError e) {
122 throw new ContractorError.SERVICE_NOT_AVAILABLE (e.message);
123 }
124 }
125
126 if (contracts == null)
127 contracts = new Gee.HashMap<string, GenericContract> ();
128 }
129
130 private static int execute_with_uri (string id, string uri) throws Error {
131 ensure ();
132 return contractor_dbus.execute_with_uri (id, uri);
133 }
134
135 private static int execute_with_uri_list (string id, string[] uris) throws Error {
136 ensure ();
137 return contractor_dbus.execute_with_uri_list (id, uris);
138 }
139
140 /**
141 * Provides all the contracts.
142 *
143 * @return List containing all the contracts available in the system.
144 */
145 public static Gee.List<Contract> get_all_contracts () throws Error {
146 ensure ();
147
148 var data = contractor_dbus.list_all_contracts ();
149
150 return get_contracts_from_data (data);
151 }
152
153 /**
154 * This searches for available contracts of a particular file type.
155 *
156 * @param mime_type Mimetype of file.
157 * @return List of contracts that support the given mimetype.
158 */
159 public static Gee.List<Contract> get_contracts_by_mime (string mime_type) throws Error {
160 ensure ();
161
162 var data = contractor_dbus.get_contracts_by_mime (mime_type);
163
164 return get_contracts_from_data (data);
165 }
166
167 /**
168 * Generate contracts for a list of mimetypes.
169 *
170 * Only the contracts that support all the mimetypes are returned.
171 *
172 * @param mime_types Array of mimetypes.
173 * @return List of contracts that support the given mimetypes.
174 */
175 public static Gee.List<Contract> get_contracts_by_mimelist (string[] mime_types) throws Error {
176 ensure ();
177
178 var data = contractor_dbus.get_contracts_by_mimelist (mime_types);
179
180 return get_contracts_from_data (data);
181 }
182
183 private static Gee.List<Contract> get_contracts_from_data (ContractData[] data) {
184 var contract_list = new Gee.LinkedList<Contract> ();
185
186 if (data != null) {
187 foreach (var contract_data in data) {
188 string contract_id = contract_data.id;
189
190 // See if we have a contract already. Otherwise create a new one.
191 // We do this in order to be able to compare contracts by reference
192 // from client code.
193 var contract = contracts.get (contract_id);
194
195 if (contract == null) {
196 contract = new GenericContract (contract_data);
197 contracts.set (contract_id, contract);
198 } else {
199 contract.update_data (contract_data);
200 }
201
202 contract_list.add (contract);
203 }
204 }
205
206 return contract_list;
102 }207 }
103 }208 }
104}209}
105210
=== modified file 'lib/Widgets/ContractorMenu.vala'
--- lib/Widgets/ContractorMenu.vala 2013-03-20 15:42:25 +0000
+++ lib/Widgets/ContractorMenu.vala 2013-04-24 17:07:27 +0000
@@ -20,6 +20,7 @@
20/**20/**
21 * This class provides a simple menu for managing Contractor.21 * This class provides a simple menu for managing Contractor.
22 */22 */
23[Deprecated (since = "0.2")]
23public class Granite.Widgets.ContractorMenu : Gtk.Menu {24public class Granite.Widgets.ContractorMenu : Gtk.Menu {
24 /**25 /**
25 * The Hashtable of available contracts26 * The Hashtable of available contracts
2627
=== modified file 'lib/Widgets/ContractorView.vala'
--- lib/Widgets/ContractorView.vala 2013-03-20 15:42:25 +0000
+++ lib/Widgets/ContractorView.vala 2013-04-24 17:07:27 +0000
@@ -22,6 +22,7 @@
22/**22/**
23 * This class provides a simple way to look at contracts from Contractor23 * This class provides a simple way to look at contracts from Contractor
24 */24 */
25[Deprecated (since = "0.2")]
25public class Granite.Widgets.ContractorView : TreeView {26public class Granite.Widgets.ContractorView : TreeView {
26 27
27 /**28 /**

Subscribers

People subscribed via source and target branches