~kelemeng/activity-log-manager/bug1409550

« back to all changes in this revision

Viewing changes to src/searchresults-widget.vala

  • Committer: Manish Sinha
  • Date: 2013-08-01 07:48:23 UTC
  • Revision ID: manishsinha@ubuntu.com-20130801074823-tk5k8cevqlnpo1ie
Get the list of all the scopes present in XDG_DATA_DIRS

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
            scroll.set_shadow_type(ShadowType.IN);
132
132
            scroll.set_border_width(1);
133
133
            this.pack_start(scroll);
 
134
 
 
135
            this.fetch_data();
 
136
        }
 
137
 
 
138
        private void fetch_data() {
 
139
            string[] xdg_data_dirs = this.get_xdg_data_dirs();
 
140
            var all_scopes =  this.get_all_scopes(xdg_data_dirs);
 
141
        }
 
142
 
 
143
        private ScopeData get_scope_data(string scope_filename) {
 
144
            return null;
 
145
        }
 
146
 
 
147
        private HashTable<string, GenericArray<string>> get_all_scopes(string[] xdg_data_dirs) {
 
148
            var all_scopes = new HashTable<string, GenericArray<string>>(str_hash, str_equal);
 
149
 
 
150
            foreach(string xdg_data in xdg_data_dirs) {
 
151
                string dir_path = Path.build_filename(xdg_data, "unity", "scopes");
 
152
                if(!FileUtils.test(dir_path, FileTest.EXISTS))
 
153
                    continue;
 
154
 
 
155
                GenericArray<string> scopes = this.get_scope_files(dir_path);
 
156
                all_scopes.insert(dir_path, scopes);
 
157
                for(int i=0; i < scopes.length; i++) {
 
158
                    stdout.printf("%s\n", scopes[i]);
 
159
                }
 
160
            }
 
161
            return all_scopes;
 
162
        }
 
163
 
 
164
        private GenericArray<string> get_scope_files(string dir_path) {
 
165
            GenericArray<string> scopes = new GenericArray<string>();
 
166
            var dir = Dir.open(dir_path);
 
167
            string? name = null;
 
168
            while ((name = dir.read_name ()) != null) {
 
169
                        string path = Path.build_filename (dir_path, name);
 
170
                if(FileUtils.test(path, FileTest.IS_REGULAR) && path.has_suffix(".scope")) {
 
171
                    scopes.add(path);
 
172
                }
 
173
                if(FileUtils.test(path, FileTest.IS_DIR)) {
 
174
                    var sub_scopes = this.get_scope_files(path);
 
175
                    for(int i=0;i<sub_scopes.length;i++)
 
176
                        scopes.add(sub_scopes[i]);
 
177
                }
 
178
            }
 
179
            return scopes;
 
180
        }
 
181
 
 
182
        private string[] get_xdg_data_dirs() {
 
183
            string xdg_data = Environment.get_variable("XDG_DATA_DIRS");
 
184
            if(xdg_data == null || xdg_data.strip().length == 0)
 
185
                xdg_data = "/usr/share";
 
186
            return xdg_data.split(":");
 
187
        }
 
188
    }
 
189
 
 
190
    private class ScopeData {
 
191
        public ScopeData(string scope_filepath) {
 
192
 
134
193
        }
135
194
    }
136
195
}