25
25
namespace Contractor {
26
26
[DBus (name = "org.elementary.ContractorError")]
28
* Errors specific to the Contractor D-Bus service.
27
30
public errordomain ContractorError {
32
* Error if no MIME type was passed where mandatory.
38
* A D-Bus service handling requests for Contracts defined by .contract
31
41
[DBus (name = "org.elementary.Contractor")]
32
42
public class DBusService : Object {
44
* Signal which gets sent when Contracts change.
33
46
public signal void contracts_changed ();
49
* Source from where .Contracts are loaded.
35
51
private ContractSource contract_source;
54
* Constructor to create a DBusService object and setup a
37
57
public DBusService () {
38
58
contract_source = new ContractSource ();
39
59
contract_source.changed.connect (() => contracts_changed ());
63
* This method gets an array of GenericContracts filtered by a
66
* @param mime_type a MIME type string, e.g. text, image
68
* @return an array of GenericContracts
42
70
public GenericContract[] get_contracts_by_mime (string mime_type) throws Error {
43
71
string[] mime_types = { mime_type };
44
72
return get_contracts_by_mimelist (mime_types);
76
* This method gets an array of GenericContracts filtered by an array of
79
* @param mime_types an array of MIME type strings, e.g. text, image
81
* @return an array of GenericContracts
47
83
public GenericContract[] get_contracts_by_mimelist (string[] mime_types) throws Error {
48
84
var all_contracts = contract_source.get_contracts ();
49
85
var contracts = ContractMatcher.get_contracts_for_types (mime_types, all_contracts);
50
86
return convert_to_generic_contracts (contracts);
90
* This method gets an array of GenericContracts filtered by the file
93
* @param file_size the file size in bytes, e.g. from FileInfo.get_size ()
95
* @return an array of GenericContracts
97
public GenericContract[] get_contracts_by_file_size (int64 file_size) throws Error {
98
var all_contracts = contract_source.get_contracts ();
99
var contracts = ContractMatcher.get_contracts_for_file_size (file_size, all_contracts);
100
return convert_to_generic_contracts (contracts);
104
* This method gets an array of GenericContracts filtered by a MIME type
105
* and the file size in bytes.
107
* @param mime_type a MIME type string, e.g. text, image
108
* @param file_size the file size in bytes, e.g. from FileInfo.get_size ()
110
* @return an array of GenericContracts
112
public GenericContract[] get_contracts_by_mime_and_file_size (string mime_type, int64 file_size) throws Error {
113
string[] mime_types = { mime_type };
114
return get_contracts_by_mimelist_and_file_size (mime_types, file_size);
118
* This method gets an array of GenericContracts filtered by an array of
119
* MIME types and the file size in bytes.
121
* The file size should probably be the sum of all files file size.
123
* @param mime_types an array of MIME type strings, e.g. text, image
124
* @param file_size the file size in bytes, e.g. from FileInfo.get_size ()
126
* @return an array of GenericContracts
128
public GenericContract[] get_contracts_by_mimelist_and_file_size (string[] mime_types, int64 file_size) throws Error {
129
var all_contracts = contract_source.get_contracts ();
130
var contracts = ContractMatcher.get_contracts_for_types_and_file_size (mime_types, file_size, all_contracts);
131
return convert_to_generic_contracts (contracts);
53
134
public void execute_with_uri (string id, string uri) throws Error {
54
135
string[] uris = { uri };
55
136
execute_with_uri_list (id, uris);
60
141
contract.launch_uris (uris);
145
* This method gets an array of GenericContracts containing all
146
* contracts that exist.
148
* @return an array of GenericContracts containing all contracts
63
150
public GenericContract[] list_all_contracts () {
64
151
var contracts = contract_source.get_contracts ();
65
152
return convert_to_generic_contracts (contracts);
156
* Converts a Collection of Contracts into an array of
159
* @return an array of GenericContracts
68
161
private static GenericContract[] convert_to_generic_contracts (Gee.Collection<Contract> contracts) {
69
162
var generic_contracts = new GenericContract[0];
71
foreach (var contract in contracts)
164
foreach (var contract in contracts) {
72
165
generic_contracts += contract.get_generic ();
74
168
return generic_contracts;