Merge lp:~voldyman/maya/contractor-fix into lp:~elementary-apps/maya/trunk

Proposed by Akshay Shekher
Status: Merged
Approved by: Corentin Noël
Approved revision: 470
Merged at revision: 468
Proposed branch: lp:~voldyman/maya/contractor-fix
Merge into: lp:~elementary-apps/maya/trunk
Diff against target: 140 lines (+37/-70)
3 files modified
CMakeLists.txt (+0/-1)
Maya/Services/Contractor.vala (+0/-27)
Maya/View/Widgets/ContractorButtonWithMenu.vala (+37/-42)
To merge this branch: bzr merge lp:~voldyman/maya/contractor-fix
Reviewer Review Type Date Requested Status
Corentin Noël Approve
Review via email: mp+174409@code.launchpad.net

Commit message

now using the new Contractor API from granite.

Description of the change

now using the new Contractor API from granite.

To post a comment you must log in.
Revision history for this message
Corentin Noël (tintou) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2013-06-09 23:29:58 +0000
3+++ CMakeLists.txt 2013-07-12 13:28:00 +0000
4@@ -86,7 +86,6 @@
5 Maya/Application.vala
6 Maya/Model/CalendarModel.vala
7 Maya/Model/SourceManager.vala
8- Maya/Services/Contractor.vala
9 Maya/Services/Dexter.vala
10 Maya/Settings/MayaSettings.vala
11 Maya/Settings/SavedState.vala
12
13=== removed file 'Maya/Services/Contractor.vala'
14--- Maya/Services/Contractor.vala 2012-03-18 03:12:54 +0000
15+++ Maya/Services/Contractor.vala 1970-01-01 00:00:00 +0000
16@@ -1,27 +0,0 @@
17-//
18-// Copyright (C) 2011-2012 Jaap Broekhuizen <jaapz.b@gmail.com>
19-//
20-// This program is free software: you can redistribute it and/or modify
21-// it under the terms of the GNU General Public License as published by
22-// the Free Software Foundation, either version 3 of the License, or
23-// (at your option) any later version.
24-//
25-// This program is distributed in the hope that it will be useful,
26-// but WITHOUT ANY WARRANTY; without even the implied warranty of
27-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28-// GNU General Public License for more details.
29-//
30-// You should have received a copy of the GNU General Public License
31-// along with this program. If not, see <http://www.gnu.org/licenses/>.
32-//
33-
34-namespace Maya.Services {
35-
36- [DBus (name = "org.elementary.contractor")]
37- public interface Contractor : Object
38- {
39- public abstract GLib.HashTable<string,string>[] GetServicesByLocation (string strlocation, string? file_mime="text/calendar") throws IOError;
40- }
41-
42-}
43-
44
45=== modified file 'Maya/View/Widgets/ContractorButtonWithMenu.vala'
46--- Maya/View/Widgets/ContractorButtonWithMenu.vala 2013-02-17 17:04:21 +0000
47+++ Maya/View/Widgets/ContractorButtonWithMenu.vala 2013-07-12 13:28:00 +0000
48@@ -17,55 +17,50 @@
49
50 namespace Maya.View.Widgets {
51
52+ public class ContractorMenuItem : Gtk.MenuItem {
53+ private Granite.Services.Contract contract;
54+
55+ public ContractorMenuItem (Granite.Services.Contract cont) {
56+ this.contract = cont;
57+
58+ label = cont.get_display_name ();
59+ }
60+
61+ public override void activate () {
62+ /* creates a .ics file */
63+ Util.save_temp_selected_calendars ();
64+
65+ string file_path = GLib.Environment.get_tmp_dir () + "/calendar.ics";
66+ File cal_file = File.new_for_path(file_path);
67+
68+ try {
69+ contract.execute_with_file (cal_file);
70+ } catch (Error err) {
71+ warning (err.message);
72+ }
73+ }
74+ }
75+
76 public class ContractorButtonWithMenu : Granite.Widgets.ToolButtonWithMenu {
77
78- private Maya.Services.Contractor contract;
79- private HashTable<string,string>[] services;
80 private Gtk.FileChooserDialog filechooser;
81
82 public ContractorButtonWithMenu (string tooltiptext) {
83
84 base (new Gtk.Image.from_icon_name ("document-export", Gtk.IconSize.MENU), tooltiptext, new Gtk.Menu());
85-
86- // try to connect
87- try {
88- contract = Bus.get_proxy_sync (BusType.SESSION,
89- "org.elementary.contractor",
90- "/org/elementary/contractor");
91-
92- // get the list and parse it into the menu
93- services = contract.GetServicesByLocation (GLib.Environment.get_tmp_dir () + "/calendar.ics");
94- foreach (HashTable<string,string> service in services) {
95- Gtk.MenuItem item = new Gtk.MenuItem.with_label(service.lookup ("Description"));
96- item.activate.connect (activate_contract);
97- menu.append (item);
98- }
99- Gtk.MenuItem item = new Gtk.MenuItem.with_label(_("Export Calendar..."));
100- item.activate.connect (savecal);
101- menu.append (item);
102- } catch (IOError e) {
103- stderr.printf ("%s\n", e.message);
104- }
105-
106- }
107-
108- private void activate_contract () {
109- /* creates a .ics file */
110- Util.save_temp_selected_calendars ();
111- Gtk.MenuItem menuitem = (Gtk.MenuItem) menu.get_active();
112- string app_menu = menuitem.get_label();
113-
114- foreach (HashTable<string,string> service in services) {
115- if (app_menu == service.lookup ("Description")) {
116- try {
117- GLib.Process.spawn_command_line_async (service.lookup ("Exec"));
118- } catch (SpawnError e) {
119- warning (e.message);
120- }
121-
122- break;
123- }
124- }
125+ var contracts = Granite.Services.ContractorProxy.get_contracts_by_mime ("text/calender");
126+
127+ for (int i = 0; i < contracts.size; i++) {
128+ var contract = contracts.get (i);
129+ Gtk.MenuItem menu_item;
130+
131+ menu_item = new ContractorMenuItem (contract);
132+ menu.append (menu_item);
133+ }
134+ Gtk.MenuItem item = new Gtk.MenuItem.with_label(_("Export Calendar..."));
135+ item.activate.connect (savecal);
136+ menu.append (item);
137+
138 }
139
140 private void savecal () {

Subscribers

People subscribed via source and target branches