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
=== modified file 'demo/main.vala'
--- demo/main.vala 2013-03-20 15:42:25 +0000
+++ demo/main.vala 2013-04-10 16:09:20 +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,
@@ -275,33 +275,6 @@
275 right_sep.draw = false;275 right_sep.draw = false;
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);
278
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 Entry278 // Search Entry
306 var search_entry = new Granite.Widgets.SearchBar ("Search");279 var search_entry = new Granite.Widgets.SearchBar ("Search");
307 var search_item = new Gtk.ToolItem ();280 var search_item = new Gtk.ToolItem ();
@@ -343,42 +316,42 @@
343316
344 private void show_light_window () {317 private void show_light_window () {
345 var light_window = new Granite.Widgets.LightWindow ();318 var light_window = new Granite.Widgets.LightWindow ();
346 319
347 var light_window_notebook = new Granite.Widgets.StaticNotebook ();320 var light_window_notebook = new Granite.Widgets.StaticNotebook ();
348 var entry = new Gtk.Entry ();321 var entry = new Gtk.Entry ();
349 var open_drop = new Gtk.ComboBoxText ();322 var open_drop = new Gtk.ComboBoxText ();
350 var open_lbl = new LLabel ("Alwas Open Mpeg Video Files with Audience");323 var open_lbl = new LLabel ("Alwas Open Mpeg Video Files with Audience");
351 324
352 var grid = new Gtk.Grid ();325 var grid = new Gtk.Grid ();
353 grid.attach (new Gtk.Image.from_icon_name ("video-x-generic", Gtk.IconSize.DIALOG), 0, 0, 1, 2);326 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);327 grid.attach (entry, 1, 0, 1, 1);
355 grid.attach (new LLabel ("1.13 GB, Mpeg Video File"), 1, 1, 1, 1);328 grid.attach (new LLabel ("1.13 GB, Mpeg Video File"), 1, 1, 1, 1);
356 329
357 grid.attach (light_window_notebook, 0, 2, 2, 1);330 grid.attach (light_window_notebook, 0, 2, 2, 1);
358 331
359 var general = new Gtk.Grid ();332 var general = new Gtk.Grid ();
360 general.attach (new LLabel.markup ("<b>Info:</b>"), 0, 0, 2, 1);333 general.attach (new LLabel.markup ("<b>Info:</b>"), 0, 0, 2, 1);
361 334
362 general.attach (new LLabel.right ("Created:"), 0, 1, 1, 1);335 general.attach (new LLabel.right ("Created:"), 0, 1, 1, 1);
363 general.attach (new LLabel.right ("Modified:"), 0, 2, 1, 1);336 general.attach (new LLabel.right ("Modified:"), 0, 2, 1, 1);
364 general.attach (new LLabel.right ("Opened:"), 0, 3, 1, 1);337 general.attach (new LLabel.right ("Opened:"), 0, 3, 1, 1);
365 general.attach (new LLabel.right ("Mimetype:"), 0, 4, 1, 1);338 general.attach (new LLabel.right ("Mimetype:"), 0, 4, 1, 1);
366 general.attach (new LLabel.right ("Location:"), 0, 5, 1, 1);339 general.attach (new LLabel.right ("Location:"), 0, 5, 1, 1);
367 340
368 general.attach (new LLabel ("Today at 9:50 PM"), 1, 1, 1, 1);341 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);342 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);343 general.attach (new LLabel ("Today at 10:00 PM"), 1, 3, 1, 1);
371 general.attach (new LLabel ("video/mpeg"), 1, 4, 1, 1);344 general.attach (new LLabel ("video/mpeg"), 1, 4, 1, 1);
372 general.attach (new LLabel ("/home/daniel/Downloads"), 1, 5, 1, 1);345 general.attach (new LLabel ("/home/daniel/Downloads"), 1, 5, 1, 1);
373 346
374 general.attach (new LLabel.markup ("<b>Open with:</b>"), 0, 6, 2, 1);347 general.attach (new LLabel.markup ("<b>Open with:</b>"), 0, 6, 2, 1);
375 general.attach (open_drop, 0, 7, 2, 1);348 general.attach (open_drop, 0, 7, 2, 1);
376 general.attach (open_lbl, 0, 8, 2, 1);349 general.attach (open_lbl, 0, 8, 2, 1);
377 350
378 light_window_notebook.append_page (general, new Gtk.Label ("General"));351 light_window_notebook.append_page (general, new Gtk.Label ("General"));
379 light_window_notebook.append_page (new Gtk.Label ("More"), new Gtk.Label ("More"));352 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"));353 light_window_notebook.append_page (new Gtk.Label ("Sharing"), new Gtk.Label ("Sharing"));
381 354
382 open_lbl.margin_left = 24;355 open_lbl.margin_left = 24;
383 open_drop.margin_left = 12;356 open_drop.margin_left = 12;
384 open_drop.append ("audience", "Audience");357 open_drop.append ("audience", "Audience");
@@ -389,7 +362,7 @@
389 entry.text = "Cool Hand Luke";362 entry.text = "Cool Hand Luke";
390 general.column_spacing = 6;363 general.column_spacing = 6;
391 general.row_spacing = 6;364 general.row_spacing = 6;
392 365
393 light_window.add (grid);366 light_window.add (grid);
394 light_window.show_all ();367 light_window.show_all ();
395 }368 }
396369
=== modified file 'lib/Services/Contractor.vala'
--- lib/Services/Contractor.vala 2013-04-04 20:05:38 +0000
+++ lib/Services/Contractor.vala 2013-04-10 16:09:20 +0000
@@ -1,5 +1,6 @@
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>
34
4 This program or library is free software; you can redistribute it5 This program or library is free software; you can redistribute it
5 and/or modify it under the terms of the GNU Lesser General Public6 and/or modify it under the terms of the GNU Lesser General Public
@@ -10,7 +11,7 @@
10 but WITHOUT ANY WARRANTY; without even the implied warranty of11 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.13 Lesser General Public License for more details.
13 14
14 You should have received a copy of the GNU Lesser General15 You should have received a copy of the GNU Lesser General
15 Public License along with this library; if not, write to the16 Public License along with this library; if not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
@@ -19,86 +20,176 @@
1920
20namespace Granite.Services {21namespace Granite.Services {
2122
22 [DBus (name = "org.elementary.contractor")]23 public struct GenericContract {
23 interface ContractorDBus : Object24 string id;
24 {25 string display_name;
26 string description;
27 string icon_path;
28 }
29
30 [DBus (name = "org.elementary.Contractor")]
31 interface ContractorDBus : Object {
32 public abstract GenericContract[] list_all_contracts () throws Error;
33 public abstract GenericContract[] get_contracts_by_mime (string mime_type) throws Error;
34 public abstract GenericContract[] get_contracts_by_mimelist (string[] mime_types) throws Error;
35 public abstract int execute_with_uri (string id, string path) throws Error;
36 public abstract int execute_with_uri_list (string id, string[] path) throws Error;
37 [Deprecated]
25 public abstract GLib.HashTable<string,string>[] GetServicesByLocation (string strlocation, string? file_mime="") throws IOError;38 public abstract GLib.HashTable<string,string>[] GetServicesByLocation (string strlocation, string? file_mime="") throws IOError;
39 [Deprecated]
26 public abstract GLib.HashTable<string,string>[] GetServicesByLocationsList (GLib.HashTable<string,string>[] locations) throws IOError;40 public abstract GLib.HashTable<string,string>[] GetServicesByLocationsList (GLib.HashTable<string,string>[] locations) throws IOError;
27 }41 }
2842
29 /**43 /**
30 * A way to handle contractor, a way to communicate between apps.44 * A way to handle contractor, a way to communicate between apps.
31 * 45 *
32 * /!\ Highly unstable API
33 */46 */
34 public class Contractor : Object47 public class Contractor : Object {
35 {
3648
37 internal ContractorDBus contract;49 internal ContractorDBus contract;
3850
39 internal static Contractor? contractor = null;51 internal static Contractor? contractor = null;
4052
41 /**53 /**
42 * This creates a new Contractor 54 * This creates a new Contractor
43 */55 */
44 public Contractor()56 public Contractor () {
45 {57 try {
46 try
47 {
48 contract = Bus.get_proxy_sync (BusType.SESSION,58 contract = Bus.get_proxy_sync (BusType.SESSION,
49 "org.elementary.contractor",59 "org.elementary.Contractor",
50 "/org/elementary/contractor");60 "/org/elementary/contractor");
51 }61 } catch (IOError e) {
52 catch (IOError e)62 stderr.printf ("%s\n", e.message);
53 {63 }
54 stderr.printf ("%s\n", e.message);64 }
55 }65
56 }66 internal static void ensure () {
5767 if (contractor == null) {
58 internal static void ensure ()68 contractor = new Contractor ();
59 {69 }
60 if(contractor == null) contractor = new Contractor ();70 }
61 }71 /**
6272 * Lists all the contracts
63 /**73 *
64 * This searches for available contracts of a particular file74 * @return an array of struct GenericContract
65 * 75 */
76 public static GenericContract[] list_all_contracts () {
77 ensure ();
78 GenericContract[] contracts = null;
79
80 try {
81 contracts = contractor.contract.list_all_contracts ();
82 } catch (Error e) {
83 stderr.printf ("%s\n", e.message);
84 }
85
86 return contracts;
87 }
88 /**
89 * This searches for available contracts of a particular file
90 *
91 * @param mime mime type of file
92 * @return an array of struct GenericContract
93 */
94 public static GenericContract[] get_contracts_by_mime (string mime_type) {
95 ensure ();
96 GenericContract[] contracts = null;
97
98 try {
99 contracts = contractor.contract.get_contracts_by_mime (mime_type);
100 } catch (IOError e) {
101 stderr.printf ("%s\n", e.message);
102 }
103
104 return contracts;
105 }
106
107 /**
108 * generate contracts for a list of mime types. the contracts which support
109 * all of them are returned
110 *
111 * @param locations Array of MimeTypes
112 * @return array of struct (GenericContract)
113 */
114 public static GenericContract[] get_contracts_by_mimelist (string[] mime_types) {
115 ensure ();
116 GenericContract[] contracts = null;
117
118 try {
119 contracts = contractor.contract.get_contracts_by_mimelist (mime_types);
120 } catch (IOError e) {
121 stderr.printf ("%s\n", e.message);
122 }
123
124 return contracts;
125 }
126 /**
127 * This executes the exec parameter provided by the contract of given id
128 * with the path as arguments
129 *
130 * @param id id of the contract
131 * @param paths path to execute
132 * @return int status of execution
133 */
134 public static int execute_with_uri (string id, string path) {
135 ensure ();
136 int ret_val = 1;
137
138 try {
139 ret_val = contractor.contract.execute_with_uri (id, path);
140 } catch (Error e) {
141 stderr.printf ("%s\n", e.message);
142 }
143 return ret_val;
144 }
145 /**
146 * This executes the exec parameter provided by the contract of given id
147 * with the paths as arguments
148 *
149 * @param id id of the contract
150 * @param paths array of paths to execute
151 * @return int status of execution
152 */
153 public static int execute_with_uri_list (string id, string[] paths) {
154 ensure ();
155 int ret_val = 1;
156
157 try {
158 ret_val = contractor.contract.execute_with_uri_list (id, paths);
159 } catch (Error e) {
160 stderr.printf ("%s\n", e.message);
161 }
162 return ret_val;
163 }
164 /**
165 * The functions below have been deprecated in order to support the
166 * the new contractor API.
167 */
168
169 /**
170 * This searches for available contracts of a particular file
171 *
66 * @param uri uri of file172 * @param uri uri of file
67 * @param mime mime type of file173 * @param mime mime type of file
68 * @return Hashtable of available contracts174 * @return Hashtable of available contracts
69 */175 */
70 public static GLib.HashTable<string,string>[] get_contract(string uri, string mime)176 [Deprecated]
71 {177 public static GLib.HashTable<string,string>[] get_contract(string uri, string mime) {
72 ensure ();178
73 GLib.HashTable<string,string>[] contracts = null;179 return { new GLib.HashTable<string,string> (null, null) };
74
75 try {
76 contracts = contractor.contract.GetServicesByLocation(uri, mime);
77 }catch (IOError e) {
78 stderr.printf ("%s\n", e.message);
79 }
80
81 return contracts;
82 }180 }
83181
84 /**182 /**
85 * generate contracts for rguments and filter them by common parent mimetype.183 * generate contracts for rguments and filter them by common parent mimetype.
86 * 184 *
87 * @param locations Hashtable of locations185 * @param locations Hashtable of locations
88 * @return Hashtable of available contracts186 * @return Hashtable of available contracts
89 */187 */
90 public static GLib.HashTable<string,string>[] get_selection_contracts (GLib.HashTable<string, string>[] locations)188 [Deprecated]
91 {189 public static GLib.HashTable<string,string>[] get_selection_contracts (GLib.HashTable<string, string>[] locations) {
92 ensure ();190
93 GLib.HashTable<string,string>[] contracts = null;191 return { new GLib.HashTable<string,string> (null, null) };
94
95 try {
96 contracts = contractor.contract.GetServicesByLocationsList (locations);
97 }catch (IOError e) {
98 stderr.printf ("%s\n", e.message);
99 }
100
101 return contracts;
102 }192 }
103 }193 }
104}194}
195
105196
=== modified file 'lib/Widgets/ContractorMenu.vala'
--- lib/Widgets/ContractorMenu.vala 2013-03-20 15:42:25 +0000
+++ lib/Widgets/ContractorMenu.vala 2013-04-10 16:09:20 +0000
@@ -10,7 +10,7 @@
10 but WITHOUT ANY WARRANTY; without even the implied warranty of10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.12 Lesser General Public License for more details.
13 13
14 You should have received a copy of the GNU Lesser General14 You should have received a copy of the GNU Lesser General
15 Public License along with this library; if not, write to the15 Public License along with this library; if not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
@@ -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]
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
@@ -32,12 +33,12 @@
32 public delegate void ContractCallback ();33 public delegate void ContractCallback ();
33 private string filepath;34 private string filepath;
34 private string filemime;35 private string filemime;
35 36
36 /**37 /**
37 * Passes when contract is clicked38 * Passes when contract is clicked
38 */39 */
39 public signal void contract_activated (string contract_name);40 public signal void contract_activated (string contract_name);
40 41
41 /**42 /**
42 * Makes new Contractor Meu43 * Makes new Contractor Meu
43 *44 *
@@ -49,7 +50,7 @@
49 filemime = mime;50 filemime = mime;
50 load_items (filename, mime);51 load_items (filename, mime);
51 }52 }
52 53
53 /**54 /**
54 * Adds new item to Contractor Menu55 * Adds new item to Contractor Menu
55 *56 *
@@ -73,7 +74,7 @@
73 insert(item, position);74 insert(item, position);
74 item.show ();75 item.show ();
75 }76 }
76 77
77 /**78 /**
78 * Deletes a group of menu items79 * Deletes a group of menu items
79 *80 *
@@ -85,14 +86,14 @@
85 remove (item);86 remove (item);
86 });87 });
87 }88 }
88 89
89 private void load_items (string filename, string mime) {90 private void load_items (string filename, string mime) {
90 contracts = Granite.Services.Contractor.get_contract (filename, mime);91 contracts = Granite.Services.Contractor.get_contract (filename, mime);
91 execs = new Gee.HashMap<string,string> ();92 execs = new Gee.HashMap<string,string> ();
92 93
93 for (int i=0;i<contracts.length;i++) {94 for (int i=0;i<contracts.length;i++) {
94 execs[contracts[i].lookup ("Name")] = contracts[i].lookup ("Exec");95 execs[contracts[i].lookup ("Name")] = contracts[i].lookup ("Exec");
95 96
96 var item = new Gtk.ImageMenuItem ();97 var item = new Gtk.ImageMenuItem ();
97 item.set_always_show_image (true);98 item.set_always_show_image (true);
98 var image = new Gtk.Image.from_icon_name (contracts[i].lookup ("IconName"), Gtk.IconSize.MENU);99 var image = new Gtk.Image.from_icon_name (contracts[i].lookup ("IconName"), Gtk.IconSize.MENU);
@@ -109,7 +110,7 @@
109 item.show_all ();110 item.show_all ();
110 }111 }
111 }112 }
112 113
113 /**114 /**
114 * Updates Contractor menu items115 * Updates Contractor menu items
115 *116 *
@@ -118,24 +119,24 @@
118 */119 */
119 public void update (string? filename, string? mime) {120 public void update (string? filename, string? mime) {
120 this.foreach ((w) => {remove (w);});121 this.foreach ((w) => {remove (w);});
121 122
122 string fn = "";123 string fn = "";
123 string mm = "";124 string mm = "";
124 125
125 if (filename != null) {126 if (filename != null) {
126 fn = filename;127 fn = filename;
127 filepath = filename;128 filepath = filename;
128 } else {129 } else {
129 fn = filepath;130 fn = filepath;
130 }131 }
131 132
132 if (mime != null) {133 if (mime != null) {
133 mm = mime;134 mm = mime;
134 filemime = mime;135 filemime = mime;
135 } else {136 } else {
136 mm = filemime;137 mm = filemime;
137 }138 }
138 139
139 load_items (fn, mm);140 load_items (fn, mm);
140 }141 }
141}142}
142143
=== modified file 'lib/Widgets/ContractorView.vala'
--- lib/Widgets/ContractorView.vala 2013-03-20 15:42:25 +0000
+++ lib/Widgets/ContractorView.vala 2013-04-10 16:09:20 +0000
@@ -10,7 +10,7 @@
10 but WITHOUT ANY WARRANTY; without even the implied warranty of10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.12 Lesser General Public License for more details.
13 13
14 You should have received a copy of the GNU Lesser General14 You should have received a copy of the GNU Lesser General
15 Public License along with this library; if not, write to the15 Public License along with this library; if not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
@@ -22,20 +22,21 @@
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 ()]
25public class Granite.Widgets.ContractorView : TreeView {26public class Granite.Widgets.ContractorView : TreeView {
26 27
27 /**28 /**
28 * indicates if it was possible to connect to contractor29 * indicates if it was possible to connect to contractor
29 */30 */
30 public bool contractor_available;31 public bool contractor_available;
31 32
32 public delegate void ContractCallback ();33 public delegate void ContractCallback ();
33 private Gee.HashMap<int, DelegateWrapper?> outsiders;34 private Gee.HashMap<int, DelegateWrapper?> outsiders;
34 private int[] blacklisted_pos;35 private int[] blacklisted_pos;
35 private ListStore list;36 private ListStore list;
3637
37 private struct DelegateWrapper { unowned ContractCallback method; }38 private struct DelegateWrapper { unowned ContractCallback method; }
38 39
39 /**40 /**
40 * the index of the currently selected contract41 * the index of the currently selected contract
41 */42 */
@@ -49,17 +50,17 @@
49 this.set_cursor (new TreePath.from_string (value.to_string ()), null, false);50 this.set_cursor (new TreePath.from_string (value.to_string ()), null, false);
50 }51 }
51 }52 }
52 53
53 /**54 /**
54 * A contract was launched using double clicking55 * A contract was launched using double clicking
55 */56 */
56 public signal void executed ();57 public signal void executed ();
57 58
58 /**59 /**
59 * the original array of contracts returned by contractor60 * the original array of contracts returned by contractor
60 */61 */
61 HashTable<string,string>[] contracts;62 HashTable<string,string>[] contracts;
62 63
63 /**64 /**
64 * Create the default ContractorView65 * Create the default ContractorView
65 *66 *
@@ -73,17 +74,17 @@
73 list = new ListStore (2, typeof (Gdk.Pixbuf), typeof (string));74 list = new ListStore (2, typeof (Gdk.Pixbuf), typeof (string));
74 outsiders = new Gee.HashMap<int, DelegateWrapper?> ();75 outsiders = new Gee.HashMap<int, DelegateWrapper?> ();
75 this.model = list;76 this.model = list;
76 77
77 /* GUI */78 /* GUI */
78 this.headers_visible = false;79 this.headers_visible = false;
79 this.hexpand = true;80 this.hexpand = true;
80 81
81 /* Events */82 /* Events */
82 row_activated.connect (() => { 83 row_activated.connect (() => {
83 run_selected ();84 run_selected ();
84 executed ();85 executed ();
85 });86 });
86 87
87 /* View */88 /* View */
88 var cell1 = new CellRendererPixbuf ();89 var cell1 = new CellRendererPixbuf ();
89 cell1.set_padding (5, 8);90 cell1.set_padding (5, 8);
@@ -102,9 +103,9 @@
102 string message = contractor_installed ? _("Could not contact Contractor. You may need to install it") : _("No action found for this file");103 string message = contractor_installed ? _("Could not contact Contractor. You may need to install it") : _("No action found for this file");
103 try {104 try {
104 var icon = IconTheme.get_default ().load_icon (105 var icon = IconTheme.get_default ().load_icon (
105 contractor_installed ? Gtk.Stock.DIALOG_ERROR : Gtk.Stock.DIALOG_INFO, 106 contractor_installed ? Gtk.Stock.DIALOG_ERROR : Gtk.Stock.DIALOG_INFO,
106 icon_size, 0);107 icon_size, 0);
107 list.set (it, 108 list.set (it,
108 0, icon, 1, message);109 0, icon, 1, message);
109 }110 }
110 catch (Error e) {111 catch (Error e) {
@@ -114,7 +115,7 @@
114 }115 }
115 else {116 else {
116 contractor_available = true;117 contractor_available = true;
117 118
118 for (var i=0; i<this.contracts.length; i++){119 for (var i=0; i<this.contracts.length; i++){
119 TreeIter it;120 TreeIter it;
120 list.append (out it);121 list.append (out it);
@@ -122,8 +123,8 @@
122 if (show_contract_name)123 if (show_contract_name)
123 text = "<b>"+this.contracts[i].lookup ("Name")+"</b>\n"+text;124 text = "<b>"+this.contracts[i].lookup ("Name")+"</b>\n"+text;
124 try{125 try{
125 list.set (it, 126 list.set (it,
126 0, IconTheme.get_default ().load_icon (this.contracts[i].lookup ("IconName"), 127 0, IconTheme.get_default ().load_icon (this.contracts[i].lookup ("IconName"),
127 icon_size, 0), 1, text);128 icon_size, 0), 1, text);
128 }129 }
129 catch (Error e) {130 catch (Error e) {
@@ -133,7 +134,7 @@
133 this.selected = 0;134 this.selected = 0;
134 }135 }
135 }136 }
136 137
137 /**138 /**
138 * A method to add items to the tree139 * A method to add items to the tree
139 *140 *
@@ -148,21 +149,21 @@
148 public void add_item (string name, string desc, string icon_name, int icon_size, int position, ContractCallback method) {149 public void add_item (string name, string desc, string icon_name, int icon_size, int position, ContractCallback method) {
149 TreeIter it;150 TreeIter it;
150 list.insert (out it, position);151 list.insert (out it, position);
151 152
152 string text = "<b>" + name + "</b>\n" + desc;153 string text = "<b>" + name + "</b>\n" + desc;
153 154
154 try{155 try{
155 list.set (it, 0, IconTheme.get_default ().load_icon (icon_name, icon_size, 0), 1, text);156 list.set (it, 0, IconTheme.get_default ().load_icon (icon_name, icon_size, 0), 1, text);
156 } catch (Error e) {157 } catch (Error e) {
157 error (e.message);158 error (e.message);
158 }159 }
159 160
160 DelegateWrapper wr = { method };161 DelegateWrapper wr = { method };
161 outsiders[position] = wr;162 outsiders[position] = wr;
162 163
163 this.selected = 0;164 this.selected = 0;
164 }165 }
165 166
166 public void name_blacklist (string[] names) {167 public void name_blacklist (string[] names) {
167 TreeIter it;168 TreeIter it;
168 TreeIter it2;169 TreeIter it2;
@@ -171,25 +172,25 @@
171 int cur_pos = 0;172 int cur_pos = 0;
172 list.get_iter_first (out it);173 list.get_iter_first (out it);
173 list.get_iter_first (out it2);174 list.get_iter_first (out it2);
174 175
175 while (true) {176 while (true) {
176 list.get_value (it, 1, out value);177 list.get_value (it, 1, out value);
177 check = list.iter_next (ref it2);178 check = list.iter_next (ref it2);
178 string text = value.get_string ();179 string text = value.get_string ();
179 180
180 if (text[3:text.index_of ("</b>")] in names) {181 if (text[3:text.index_of ("</b>")] in names) {
181 list.remove (it);182 list.remove (it);
182 blacklisted_pos += cur_pos;183 blacklisted_pos += cur_pos;
183 }184 }
184 if (!check)185 if (!check)
185 break;186 break;
186 187
187 it = it2;188 it = it2;
188 cur_pos++; 189 cur_pos++;
189 }190 }
190 }191 }
191 192
192 193
193 public void run_selected () {194 public void run_selected () {
194 if (this.selected in outsiders.keys ) {195 if (this.selected in outsiders.keys ) {
195 outsiders[this.selected].method ();196 outsiders[this.selected].method ();

Subscribers

People subscribed via source and target branches