summaryrefslogtreecommitdiff
path: root/wikipedia/src/endless_wikipedia/models/WikipediaModel.js
blob: d6660b8d3339e2566a435599c62308d0d818544e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const Endless = imports.gi.Endless;
const Gio = imports.gi.Gio;
const GObject = imports.gi.GObject;
const Json = imports.gi.Json;
const Lang = imports.lang;

// Local libraries
//const CategoryModel = imports.models.category_model;
const JsonUtils = imports.models.utils.json_utils;

const CONTENT_DIRECTORY = Endless.getCurrentFileDir() + "/../../content/";
const DEFAULT_METADATA_FILE = CONTENT_DIRECTORY +  "metadata.json";

const WikipediaModel = new Lang.Class({
    Name: "WikipediaModel",
    Extends: GObject.Object,

    _init: function(f) {

        let jsonFile;
        jsonFile = f || DEFAULT_METADATA_FILE;

        this._categories = new Array();

        this.initFromJsonFile(jsonFile);
    },

    initFromJsonFile: function(theFile) {

        let parser = new Json.Parser();

        try {
            parser.load_from_file(theFile);

            let root = parser.get_root();
            let reader = new Json.Reader();
            reader.root = root;

            reader.read_member("categories");
            let categoryCount = reader.count_elements();
            for(let i=0; i<categoryCount; i++) {
                reader.read_element(i);
                print("hello");
                let vId = reader.get_string_value();
                //let newCategory = new CategoryModel.CategoryModel({ id: vId });
                //this._categories.push(newCategory);

                reader.end_element();
            }
            reader.end_member();
        } catch (e) {
            throw e;
        }
    },

    getCategories: function() {
        return this._categories;
    },
});