Merge lp:~voldyman/granite/contractor-wid-dep-new-Contractor into lp:~elementary-pantheon/granite/granite
- contractor-wid-dep-new-Contractor
- Merge into granite
Status: | Merged |
---|---|
Merged at revision: | 559 |
Proposed branch: | lp:~voldyman/granite/contractor-wid-dep-new-Contractor |
Merge into: | lp:~elementary-pantheon/granite/granite |
Diff against target: |
448 lines (+232/-91) 4 files modified
demo/main.vala (+11/-37) lib/Services/Contractor.vala (+219/-54) lib/Widgets/ContractorMenu.vala (+1/-0) lib/Widgets/ContractorView.vala (+1/-0) |
To merge this branch: | bzr merge lp:~voldyman/granite/contractor-wid-dep-new-Contractor |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Sergey "Shnatsel" Davidoff (community) | Approve | ||
elementary Apps team | Pending | ||
Review via email: mp+158161@code.launchpad.net |
This proposal supersedes a proposal from 2013-04-10.
Commit message
Description of the change
* Added Granite.
* Deprecated the widgets that work with the old and abandoned API instead of including updated widgets, because Dan doesn't want any Contractor widgets in Granite
This merge does not cause an API/ABI break.
Sergey "Shnatsel" Davidoff (shnatsel) wrote : Posted in a previous version of this proposal | # |
- 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
Victor Martinez (victored) wrote : | # |
Wow, fantastic work here!
Since overall this is very cohesive and well done, I'll just focus on a couple of details to make it even better IMHO:
(1) Why isn't ensure() private?
(2) Make sure the interface ContractorDBus is internal to Granite.
(3) The names of execute_* () suggest URIs, but in the parameters they are named paths. What do these really expect?
(1) and (2) are easily fixable.
Regarding (3), since this is a wrapper to the DBus API, I could suggest receiving GLib.File objects instead, and calling get_path() or get_uri() on them depending on what Contractor is expecting. Make sure you rename the methods accordingly (..._with_files).
Regarding the API, it would be nice to have something like:
Granite.
File file;
// get some instances from somewhere...
contract.
Instead of:
string contract_id;
string file_uri;
// get those strings from somewhere...
Granite.
We'd have something like:
public interface Granite.
public abstract void execute_with_file (File file);
public abstract void execute_with_files (File[] files);
}
public class Granite.
private struct GenericContract { ... }
// Private implementation of Contract
private class ContractorContract : Object, Contract {
private GenericContract data;
private Con
public ContractorContract (GenericContract data) {
}
public void execute_with_file (File file) {
// Yes, we have access to the parent class's private static methods
}
[...]
}
[...]
// Of course, this method could be removed and its contents may be moved to
// Contract.
private static void execute_with_uri (string id, string uri);
[...]
}
Finally, please fix the coding style issues. A quick read through the code will show what I mean. Of course there are only a couple of them :)
- 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
Victor Martinez (victored) wrote : | # |
Thank you for your work Akshay!
Actually, my suggestion was not related to hiding contractor behind an interface, since it's only a facade. What I was suggesting was abstracting the Contracts themselves, so that no implementation details are made available to the client code.
Please take a look to rev. 562 of lp:~victored/granite/contractor-wrapper
Victor Martinez (victored) wrote : | # |
For an overview of the API, you can go here: http://
Sergey "Shnatsel" Davidoff (shnatsel) wrote : | # |
Looks good to me (but disregard my opinion because I'm OOP-impaired). In hindsight, using Glib.File instead of messing with paths and URIs is a good idea.
Sergey "Shnatsel" Davidoff (shnatsel) : | # |
Sergey "Shnatsel" Davidoff (shnatsel) wrote : | # |
Argh, Victor's updated branch is not yet merged into this one... but I don't have anything left to review here anyway, so "Approved" from me it is.
Preview Diff
1 | === modified file 'demo/main.vala' | |||
2 | --- demo/main.vala 2013-03-20 15:42:25 +0000 | |||
3 | +++ demo/main.vala 2013-04-18 12:53:23 +0000 | |||
4 | @@ -13,7 +13,7 @@ | |||
5 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
6 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
7 | 15 | Lesser General Public License for more details. | 15 | Lesser General Public License for more details. |
9 | 16 | 16 | ||
10 | 17 | You should have received a copy of the GNU Lesser General | 17 | You should have received a copy of the GNU Lesser General |
11 | 18 | Public License along with this library; if not, write to the | 18 | Public License along with this library; if not, write to the |
12 | 19 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
13 | @@ -276,32 +276,6 @@ | |||
14 | 276 | right_sep.set_expand (true); | 276 | right_sep.set_expand (true); |
15 | 277 | main_toolbar.insert (right_sep, -1); | 277 | main_toolbar.insert (right_sep, -1); |
16 | 278 | 278 | ||
17 | 279 | // Contractor | ||
18 | 280 | var contractor_tab = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); | ||
19 | 281 | var text_view = new Gtk.TextView (); | ||
20 | 282 | |||
21 | 283 | var hash_tables = Granite.Services.Contractor.get_contract ("/.zip", "application/zip"); | ||
22 | 284 | foreach (var hash_table in hash_tables) { | ||
23 | 285 | text_view.buffer.text += hash_table.lookup ("Name") | ||
24 | 286 | + ": " + hash_table.lookup ("Description") | ||
25 | 287 | + " icon: " + hash_table.lookup ("Exec") + "\n"; | ||
26 | 288 | } | ||
27 | 289 | |||
28 | 290 | contractor_tab.add (text_view); | ||
29 | 291 | contractor_tab.add (new Granite.Widgets.ContractorView ("file:///home/user/file.txt", "text/plain")); | ||
30 | 292 | var contractor_menu = new Granite.Widgets.ContractorMenu ("/home/user/file.txt", "text"); | ||
31 | 293 | var contractor_button_image = new Gtk.Image.from_icon_name ("document-export", | ||
32 | 294 | Gtk.IconSize.LARGE_TOOLBAR); | ||
33 | 295 | var contractor_tool_item = new Granite.Widgets.ToolButtonWithMenu (contractor_button_image, | ||
34 | 296 | "Share", contractor_menu); | ||
35 | 297 | main_toolbar.insert (contractor_tool_item, -1); | ||
36 | 298 | |||
37 | 299 | contractor_tool_item.halign = contractor_tool_item.valign = Gtk.Align.CENTER; | ||
38 | 300 | |||
39 | 301 | var contractor_item = new SourceListItem ("Contractor"); | ||
40 | 302 | contractor_item.page_num = page_switcher.append_page (contractor_tab, null); | ||
41 | 303 | services_category.add (contractor_item); | ||
42 | 304 | |||
43 | 305 | // Search Entry | 279 | // Search Entry |
44 | 306 | var search_entry = new Granite.Widgets.SearchBar ("Search"); | 280 | var search_entry = new Granite.Widgets.SearchBar ("Search"); |
45 | 307 | var search_item = new Gtk.ToolItem (); | 281 | var search_item = new Gtk.ToolItem (); |
46 | @@ -343,42 +317,42 @@ | |||
47 | 343 | 317 | ||
48 | 344 | private void show_light_window () { | 318 | private void show_light_window () { |
49 | 345 | var light_window = new Granite.Widgets.LightWindow (); | 319 | var light_window = new Granite.Widgets.LightWindow (); |
51 | 346 | 320 | ||
52 | 347 | var light_window_notebook = new Granite.Widgets.StaticNotebook (); | 321 | var light_window_notebook = new Granite.Widgets.StaticNotebook (); |
53 | 348 | var entry = new Gtk.Entry (); | 322 | var entry = new Gtk.Entry (); |
54 | 349 | var open_drop = new Gtk.ComboBoxText (); | 323 | var open_drop = new Gtk.ComboBoxText (); |
55 | 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"); |
57 | 351 | 325 | ||
58 | 352 | var grid = new Gtk.Grid (); | 326 | var grid = new Gtk.Grid (); |
59 | 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); |
60 | 354 | grid.attach (entry, 1, 0, 1, 1); | 328 | grid.attach (entry, 1, 0, 1, 1); |
61 | 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); |
63 | 356 | 330 | ||
64 | 357 | grid.attach (light_window_notebook, 0, 2, 2, 1); | 331 | grid.attach (light_window_notebook, 0, 2, 2, 1); |
66 | 358 | 332 | ||
67 | 359 | var general = new Gtk.Grid (); | 333 | var general = new Gtk.Grid (); |
68 | 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); |
70 | 361 | 335 | ||
71 | 362 | general.attach (new LLabel.right ("Created:"), 0, 1, 1, 1); | 336 | general.attach (new LLabel.right ("Created:"), 0, 1, 1, 1); |
72 | 363 | general.attach (new LLabel.right ("Modified:"), 0, 2, 1, 1); | 337 | general.attach (new LLabel.right ("Modified:"), 0, 2, 1, 1); |
73 | 364 | general.attach (new LLabel.right ("Opened:"), 0, 3, 1, 1); | 338 | general.attach (new LLabel.right ("Opened:"), 0, 3, 1, 1); |
74 | 365 | general.attach (new LLabel.right ("Mimetype:"), 0, 4, 1, 1); | 339 | general.attach (new LLabel.right ("Mimetype:"), 0, 4, 1, 1); |
75 | 366 | general.attach (new LLabel.right ("Location:"), 0, 5, 1, 1); | 340 | general.attach (new LLabel.right ("Location:"), 0, 5, 1, 1); |
77 | 367 | 341 | ||
78 | 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); |
79 | 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); |
80 | 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); |
81 | 371 | general.attach (new LLabel ("video/mpeg"), 1, 4, 1, 1); | 345 | general.attach (new LLabel ("video/mpeg"), 1, 4, 1, 1); |
82 | 372 | general.attach (new LLabel ("/home/daniel/Downloads"), 1, 5, 1, 1); | 346 | general.attach (new LLabel ("/home/daniel/Downloads"), 1, 5, 1, 1); |
84 | 373 | 347 | ||
85 | 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); |
86 | 375 | general.attach (open_drop, 0, 7, 2, 1); | 349 | general.attach (open_drop, 0, 7, 2, 1); |
87 | 376 | general.attach (open_lbl, 0, 8, 2, 1); | 350 | general.attach (open_lbl, 0, 8, 2, 1); |
89 | 377 | 351 | ||
90 | 378 | light_window_notebook.append_page (general, new Gtk.Label ("General")); | 352 | light_window_notebook.append_page (general, new Gtk.Label ("General")); |
91 | 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")); |
92 | 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")); |
94 | 381 | 355 | ||
95 | 382 | open_lbl.margin_left = 24; | 356 | open_lbl.margin_left = 24; |
96 | 383 | open_drop.margin_left = 12; | 357 | open_drop.margin_left = 12; |
97 | 384 | open_drop.append ("audience", "Audience"); | 358 | open_drop.append ("audience", "Audience"); |
98 | @@ -389,7 +363,7 @@ | |||
99 | 389 | entry.text = "Cool Hand Luke"; | 363 | entry.text = "Cool Hand Luke"; |
100 | 390 | general.column_spacing = 6; | 364 | general.column_spacing = 6; |
101 | 391 | general.row_spacing = 6; | 365 | general.row_spacing = 6; |
103 | 392 | 366 | ||
104 | 393 | light_window.add (grid); | 367 | light_window.add (grid); |
105 | 394 | light_window.show_all (); | 368 | light_window.show_all (); |
106 | 395 | } | 369 | } |
107 | 396 | 370 | ||
108 | === modified file 'lib/Services/Contractor.vala' | |||
109 | --- lib/Services/Contractor.vala 2013-04-04 20:05:38 +0000 | |||
110 | +++ lib/Services/Contractor.vala 2013-04-18 12:53:23 +0000 | |||
111 | @@ -10,7 +10,7 @@ | |||
112 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
113 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
114 | 12 | Lesser General Public License for more details. | 12 | Lesser General Public License for more details. |
116 | 13 | 13 | ||
117 | 14 | You should have received a copy of the GNU Lesser General | 14 | You should have received a copy of the GNU Lesser General |
118 | 15 | Public License along with this library; if not, write to the | 15 | Public License along with this library; if not, write to the |
119 | 16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
120 | @@ -19,86 +19,251 @@ | |||
121 | 19 | 19 | ||
122 | 20 | namespace Granite.Services { | 20 | namespace Granite.Services { |
123 | 21 | 21 | ||
127 | 22 | [DBus (name = "org.elementary.contractor")] | 22 | public struct ContractorContract { |
128 | 23 | interface ContractorDBus : Object | 23 | string id; |
129 | 24 | { | 24 | string display_name; |
130 | 25 | string description; | ||
131 | 26 | string icon_path; | ||
132 | 27 | |||
133 | 28 | public int execute_uri (string uri) { | ||
134 | 29 | return Contractor.execute_with_uri (this.id, uri); | ||
135 | 30 | } | ||
136 | 31 | public int execute_uris (string[] uris) { | ||
137 | 32 | return Contractor.execute_with_uri_list (this.id, uris); | ||
138 | 33 | } | ||
139 | 34 | } | ||
140 | 35 | |||
141 | 36 | [DBus (name = "org.elementary.Contractor")] | ||
142 | 37 | internal interface ContractorDBus : Object { | ||
143 | 38 | [Deprecated] | ||
144 | 25 | public abstract GLib.HashTable<string,string>[] GetServicesByLocation (string strlocation, string? file_mime="") throws IOError; | 39 | public abstract GLib.HashTable<string,string>[] GetServicesByLocation (string strlocation, string? file_mime="") throws IOError; |
145 | 40 | [Deprecated] | ||
146 | 26 | public abstract GLib.HashTable<string,string>[] GetServicesByLocationsList (GLib.HashTable<string,string>[] locations) throws IOError; | 41 | public abstract GLib.HashTable<string,string>[] GetServicesByLocationsList (GLib.HashTable<string,string>[] locations) throws IOError; |
147 | 42 | public abstract ContractorContract[] list_all_contracts () throws Error; | ||
148 | 43 | public abstract ContractorContract[] get_contracts_by_mime (string mime_type) throws Error; | ||
149 | 44 | public abstract ContractorContract[] get_contracts_by_mimelist (string[] mime_types) throws Error; | ||
150 | 45 | public abstract int execute_with_uri (string id, string uri) throws Error; | ||
151 | 46 | public abstract int execute_with_uri_list (string id, string[] uri) throws Error; | ||
152 | 47 | } | ||
153 | 48 | |||
154 | 49 | /* | ||
155 | 50 | * interface that the contractor class must implement | ||
156 | 51 | */ | ||
157 | 52 | public interface ContractorIface { | ||
158 | 53 | public abstract ContractorContract[] get_contracts () throws ContractError; | ||
159 | 54 | public abstract ContractorContract get_for_id (string id) throws ContractError; | ||
160 | 27 | } | 55 | } |
161 | 28 | 56 | ||
162 | 29 | /** | 57 | /** |
163 | 30 | * A way to handle contractor, a way to communicate between apps. | 58 | * A way to handle contractor, a way to communicate between apps. |
166 | 31 | * | 59 | * |
165 | 32 | * /!\ Highly unstable API | ||
167 | 33 | */ | 60 | */ |
170 | 34 | public class Contractor : Object | 61 | public class Contractor : Object, ContractorIface { |
171 | 35 | { | 62 | |
172 | 63 | private string? mime_type; | ||
173 | 64 | private string[]? mime_types; | ||
174 | 65 | private ContractorContract[]? contracts; | ||
175 | 66 | |||
176 | 36 | 67 | ||
177 | 37 | internal ContractorDBus contract; | 68 | internal ContractorDBus contract; |
178 | 38 | 69 | ||
179 | 39 | internal static Contractor? contractor = null; | 70 | internal static Contractor? contractor = null; |
180 | 40 | 71 | ||
181 | 41 | /** | 72 | /** |
183 | 42 | * This creates a new Contractor | 73 | * This creates a new Contractor |
184 | 43 | */ | 74 | */ |
189 | 44 | public Contractor() | 75 | private Contractor () { |
190 | 45 | { | 76 | try { |
187 | 46 | try | ||
188 | 47 | { | ||
191 | 48 | contract = Bus.get_proxy_sync (BusType.SESSION, | 77 | contract = Bus.get_proxy_sync (BusType.SESSION, |
193 | 49 | "org.elementary.contractor", | 78 | "org.elementary.Contractor", |
194 | 50 | "/org/elementary/contractor"); | 79 | "/org/elementary/contractor"); |
210 | 51 | } | 80 | } catch (IOError e) { |
211 | 52 | catch (IOError e) | 81 | stderr.printf ("%s\n", e.message); |
212 | 53 | { | 82 | } |
213 | 54 | stderr.printf ("%s\n", e.message); | 83 | } |
214 | 55 | } | 84 | |
215 | 56 | } | 85 | internal static void ensure () { |
216 | 57 | 86 | if (contractor == null) { | |
217 | 58 | internal static void ensure () | 87 | contractor = new Contractor (); |
218 | 59 | { | 88 | } |
219 | 60 | if(contractor == null) contractor = new Contractor (); | 89 | } |
220 | 61 | } | 90 | |
221 | 62 | 91 | /* | |
222 | 63 | /** | 92 | * Class constructor for single mime type |
223 | 64 | * This searches for available contracts of a particular file | 93 | */ |
224 | 65 | * | 94 | public Contractor.for_mime (string mime) { |
225 | 95 | this.mime_type = mime; | ||
226 | 96 | this.mime_types = null; | ||
227 | 97 | } | ||
228 | 98 | |||
229 | 99 | /* | ||
230 | 100 | * Class constructor for multiple mime types | ||
231 | 101 | */ | ||
232 | 102 | public Contractor.for_mime_list (string[] mimes) { | ||
233 | 103 | this.mime_types = mimes; | ||
234 | 104 | this.mime_type = null; | ||
235 | 105 | } | ||
236 | 106 | |||
237 | 107 | /* | ||
238 | 108 | * searches for contracts that support the specified mime type(s) | ||
239 | 109 | * throws error if mime type is not set. | ||
240 | 110 | */ | ||
241 | 111 | public ContractorContract[] get_contracts () throws ContractError { | ||
242 | 112 | if (this.mime_type != null) { | ||
243 | 113 | this.contracts = get_contracts_by_mime (this.mime_type); | ||
244 | 114 | return contracts; | ||
245 | 115 | } else if (this.mime_types != null) { | ||
246 | 116 | contracts = get_contracts_by_mimelist (this.mime_types); | ||
247 | 117 | return this.contracts; | ||
248 | 118 | } | ||
249 | 119 | throw new ContractError.OBJECT_ERROR ("data members are null"); | ||
250 | 120 | } | ||
251 | 121 | |||
252 | 122 | /* | ||
253 | 123 | * Searches for the contract with with the id as specified | ||
254 | 124 | * if not found, throws NOT_FOUND error | ||
255 | 125 | */ | ||
256 | 126 | public ContractorContract get_for_id (string id) throws ContractError { | ||
257 | 127 | if (this.contracts == null) { | ||
258 | 128 | throw new ContractError.NOT_FOUND ("contracts were not found"); | ||
259 | 129 | } | ||
260 | 130 | foreach (var cont in this.contracts) { | ||
261 | 131 | if (cont.id == id) | ||
262 | 132 | return cont; | ||
263 | 133 | } | ||
264 | 134 | throw new ContractError.NOT_FOUND ("Contract of this ID was not found"); | ||
265 | 135 | } | ||
266 | 136 | |||
267 | 137 | /** | ||
268 | 138 | * Lists all the contracts | ||
269 | 139 | * | ||
270 | 140 | * @return an array of struct ContractorContract | ||
271 | 141 | */ | ||
272 | 142 | public static ContractorContract[] list_all_contracts () { | ||
273 | 143 | ensure (); | ||
274 | 144 | ContractorContract[] contracts = null; | ||
275 | 145 | |||
276 | 146 | try { | ||
277 | 147 | contracts = contractor.contract.list_all_contracts (); | ||
278 | 148 | } catch (Error e) { | ||
279 | 149 | stderr.printf ("%s\n", e.message); | ||
280 | 150 | } | ||
281 | 151 | |||
282 | 152 | return contracts; | ||
283 | 153 | } | ||
284 | 154 | |||
285 | 155 | /** | ||
286 | 156 | * This searches for available contracts of a particular file | ||
287 | 157 | * | ||
288 | 158 | * @param mime mime type of file | ||
289 | 159 | * @return an array of struct ContractorContract | ||
290 | 160 | */ | ||
291 | 161 | public static ContractorContract[] get_contracts_by_mime (string mime_type) { | ||
292 | 162 | ensure (); | ||
293 | 163 | ContractorContract[] contracts = null; | ||
294 | 164 | |||
295 | 165 | try { | ||
296 | 166 | contracts = contractor.contract.get_contracts_by_mime (mime_type); | ||
297 | 167 | } catch (Error e) { | ||
298 | 168 | stderr.printf ("%s\n", e.message); | ||
299 | 169 | } | ||
300 | 170 | |||
301 | 171 | return contracts; | ||
302 | 172 | } | ||
303 | 173 | |||
304 | 174 | /** | ||
305 | 175 | * generate contracts for a list of mime types. the contracts which support | ||
306 | 176 | * all of them are returned | ||
307 | 177 | * | ||
308 | 178 | * @param locations Array of MimeTypes | ||
309 | 179 | * @return array of struct (ContractorContract) | ||
310 | 180 | */ | ||
311 | 181 | public static ContractorContract[] get_contracts_by_mimelist (string[] mime_types) { | ||
312 | 182 | ensure (); | ||
313 | 183 | ContractorContract[] contracts = null; | ||
314 | 184 | |||
315 | 185 | try { | ||
316 | 186 | contracts = contractor.contract.get_contracts_by_mimelist (mime_types); | ||
317 | 187 | } catch (Error e) { | ||
318 | 188 | stderr.printf ("%s\n", e.message); | ||
319 | 189 | } | ||
320 | 190 | |||
321 | 191 | return contracts; | ||
322 | 192 | } | ||
323 | 193 | |||
324 | 194 | /** | ||
325 | 195 | * This executes the exec parameter provided by the contract of given id | ||
326 | 196 | * with the uri as arguments | ||
327 | 197 | * | ||
328 | 198 | * @param id id of the contract | ||
329 | 199 | * @param uris uri to execute | ||
330 | 200 | * @return int status of execution | ||
331 | 201 | */ | ||
332 | 202 | public static int execute_with_uri (string id, string uri) { | ||
333 | 203 | ensure (); | ||
334 | 204 | int ret_val = 1; | ||
335 | 205 | |||
336 | 206 | try { | ||
337 | 207 | ret_val = contractor.contract.execute_with_uri (id, uri); | ||
338 | 208 | } catch (Error e) { | ||
339 | 209 | stderr.printf ("%s\n", e.message); | ||
340 | 210 | } | ||
341 | 211 | return ret_val; | ||
342 | 212 | } | ||
343 | 213 | |||
344 | 214 | /** | ||
345 | 215 | * This executes the exec parameter provided by the contract of given id | ||
346 | 216 | * with the uris as arguments | ||
347 | 217 | * | ||
348 | 218 | * @param id id of the contract | ||
349 | 219 | * @param uris array of uris to execute | ||
350 | 220 | * @return int status of execution | ||
351 | 221 | */ | ||
352 | 222 | public static int execute_with_uri_list (string id, string[] uris) { | ||
353 | 223 | ensure (); | ||
354 | 224 | int ret_val = 1; | ||
355 | 225 | |||
356 | 226 | try { | ||
357 | 227 | ret_val = contractor.contract.execute_with_uri_list (id, uris); | ||
358 | 228 | } catch (Error e) { | ||
359 | 229 | stderr.printf ("%s\n", e.message); | ||
360 | 230 | } | ||
361 | 231 | return ret_val; | ||
362 | 232 | } | ||
363 | 233 | |||
364 | 234 | /** | ||
365 | 235 | * The functions below have been deprecated in order to support the | ||
366 | 236 | * the new contractor API. | ||
367 | 237 | */ | ||
368 | 238 | |||
369 | 239 | /** | ||
370 | 240 | * This searches for available contracts of a particular file | ||
371 | 241 | * | ||
372 | 66 | * @param uri uri of file | 242 | * @param uri uri of file |
373 | 67 | * @param mime mime type of file | 243 | * @param mime mime type of file |
374 | 68 | * @return Hashtable of available contracts | 244 | * @return Hashtable of available contracts |
375 | 69 | */ | 245 | */ |
388 | 70 | public static GLib.HashTable<string,string>[] get_contract(string uri, string mime) | 246 | [Deprecated] |
389 | 71 | { | 247 | public static GLib.HashTable<string,string>[] get_contract(string uri, string mime) { |
390 | 72 | ensure (); | 248 | |
391 | 73 | GLib.HashTable<string,string>[] contracts = null; | 249 | return { new GLib.HashTable<string,string> (null, null) }; |
380 | 74 | |||
381 | 75 | try { | ||
382 | 76 | contracts = contractor.contract.GetServicesByLocation(uri, mime); | ||
383 | 77 | }catch (IOError e) { | ||
384 | 78 | stderr.printf ("%s\n", e.message); | ||
385 | 79 | } | ||
386 | 80 | |||
387 | 81 | return contracts; | ||
392 | 82 | } | 250 | } |
393 | 83 | 251 | ||
394 | 84 | /** | 252 | /** |
395 | 85 | * generate contracts for rguments and filter them by common parent mimetype. | 253 | * generate contracts for rguments and filter them by common parent mimetype. |
397 | 86 | * | 254 | * |
398 | 87 | * @param locations Hashtable of locations | 255 | * @param locations Hashtable of locations |
399 | 88 | * @return Hashtable of available contracts | 256 | * @return Hashtable of available contracts |
400 | 89 | */ | 257 | */ |
413 | 90 | public static GLib.HashTable<string,string>[] get_selection_contracts (GLib.HashTable<string, string>[] locations) | 258 | [Deprecated] |
414 | 91 | { | 259 | public static GLib.HashTable<string,string>[] get_selection_contracts (GLib.HashTable<string, string>[] locations) { |
415 | 92 | ensure (); | 260 | |
416 | 93 | GLib.HashTable<string,string>[] contracts = null; | 261 | return { new GLib.HashTable<string,string> (null, null) }; |
405 | 94 | |||
406 | 95 | try { | ||
407 | 96 | contracts = contractor.contract.GetServicesByLocationsList (locations); | ||
408 | 97 | }catch (IOError e) { | ||
409 | 98 | stderr.printf ("%s\n", e.message); | ||
410 | 99 | } | ||
411 | 100 | |||
412 | 101 | return contracts; | ||
417 | 102 | } | 262 | } |
418 | 103 | } | 263 | } |
419 | 264 | |||
420 | 265 | public errordomain ContractError { | ||
421 | 266 | OBJECT_ERROR, | ||
422 | 267 | NOT_FOUND | ||
423 | 268 | } | ||
424 | 104 | } | 269 | } |
425 | 105 | 270 | ||
426 | === modified file 'lib/Widgets/ContractorMenu.vala' | |||
427 | --- lib/Widgets/ContractorMenu.vala 2013-03-20 15:42:25 +0000 | |||
428 | +++ lib/Widgets/ContractorMenu.vala 2013-04-18 12:53:23 +0000 | |||
429 | @@ -20,6 +20,7 @@ | |||
430 | 20 | /** | 20 | /** |
431 | 21 | * This class provides a simple menu for managing Contractor. | 21 | * This class provides a simple menu for managing Contractor. |
432 | 22 | */ | 22 | */ |
433 | 23 | [Deprecated] | ||
434 | 23 | public class Granite.Widgets.ContractorMenu : Gtk.Menu { | 24 | public class Granite.Widgets.ContractorMenu : Gtk.Menu { |
435 | 24 | /** | 25 | /** |
436 | 25 | * The Hashtable of available contracts | 26 | * The Hashtable of available contracts |
437 | 26 | 27 | ||
438 | === modified file 'lib/Widgets/ContractorView.vala' | |||
439 | --- lib/Widgets/ContractorView.vala 2013-03-20 15:42:25 +0000 | |||
440 | +++ lib/Widgets/ContractorView.vala 2013-04-18 12:53:23 +0000 | |||
441 | @@ -22,6 +22,7 @@ | |||
442 | 22 | /** | 22 | /** |
443 | 23 | * This class provides a simple way to look at contracts from Contractor | 23 | * This class provides a simple way to look at contracts from Contractor |
444 | 24 | */ | 24 | */ |
445 | 25 | [Deprecated] | ||
446 | 25 | public class Granite.Widgets.ContractorView : TreeView { | 26 | public class Granite.Widgets.ContractorView : TreeView { |
447 | 26 | 27 | ||
448 | 27 | /** | 28 | /** |
This seems to break the ABI (according to Rico's check in deb-packaging) even thought it shouldn't.