~elementary-pantheon/contractor/master

« back to all changes in this revision

Viewing changes to src/Contractor.vala

  • Committer: Akshay Shekher
  • Date: 2013-04-05 16:42:27 UTC
  • Revision ID: git-v1:2062e624fd269d0127538fae910198c10ebe81d5
Added support to execute contracts on the bases of id's and files

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 */
23
23
 
24
24
using GLib;
25
 
using Gee;
26
25
 
27
26
namespace Contractor {
28
27
 
69
68
        /  return:
70
69
        /  status: TODO
71
70
        */
72
 
        public int execute_with_file_list (string id, string[] file_path) {
 
71
        public int execute_with_file_list (string id, string[] file_paths) {
73
72
            ContractFileInfo contract = cfs.get_contracts_for_id (id)[0];
74
 
            print (contract.exec + "\n");
75
 
            return 0;
 
73
            List<string> uris = new List<string> ();
 
74
            foreach (var file_path in file_paths) {
 
75
                uris.append (file_path);
 
76
            }
 
77
            if (execute_with_uris (contract.exec, uris) == true ) {
 
78
                return 0;
 
79
            } else {
 
80
                return 1;
 
81
            }
76
82
        }
77
83
        /*
78
84
        /  return:
80
86
        */
81
87
        public int execute_with_file (string id, string file_path) {
82
88
            ContractFileInfo contract = cfs.get_contracts_for_id (id)[0];
83
 
            print (contract.exec + "\n");
84
 
            return 0;
 
89
            List<string> uri = new List<string> ();
 
90
            uri.append (file_path);
 
91
            if (execute_with_uris (contract.exec, uri) == true ) {
 
92
                return 0;
 
93
            } else {
 
94
                return 1;
 
95
            }
85
96
        }
86
97
 
87
98
        public GenericContract[] list_all_contracts () {
88
99
            var cts = cfs.list_all_contracts ();
89
100
            return cfs.to_GenericContract_arr (cts);
90
101
        }
 
102
        private bool execute_with_uris (string exec_str, List<string>? uris) {
 
103
            try {
 
104
                return AppInfo.create_from_commandline (exec_str, null, AppInfoCreateFlags.SUPPORTS_URIS).launch_uris(uris, null);
 
105
            } catch (Error e) {
 
106
                    warning (e.message);
 
107
            }
 
108
            return false;
 
109
        }
91
110
    }
92
111
    /* starts the contractor goodnes
93
112
       creates a new Bus and enters the main loops