summaryrefslogtreecommitdiff
path: root/wikipedia/PrebuiltFrontPage.js
blob: 352220d4126a79d4fec7dcf1853a9b8cfd928cd7 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;

const EndlessWikipedia = imports.wikipedia.EndlessWikipedia;
const CategorySelectorView = imports.views.category_selector_view;
const TitleLabelView = imports.views.title_label_view;

const TITLE_CATEGORY_COLUMN_SPACING = 10;  // pixels

GObject.ParamFlags.READWRITE = GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE;

const PrebuiltFrontPage = new Lang.Class({
    Name: 'PrebuiltFrontPage',
    Extends: Gtk.Grid,
    Properties: {
        'title': GObject.ParamSpec.string('title',
            'Front page title',
            'Name of the Wikipedia-based application',
            GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
            ''),
        'image-uri': GObject.ParamSpec.string('image-uri',
            'Image URI',
            'Image URI for title image',
            GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
            '')
    },
    Signals: {
        'category-chosen': {
            param_types: [GObject.TYPE_STRING, GObject.TYPE_INT]
        }
    },

    _init: function(props) {
        this._title = null;
        this._image_uri = null;

        this._title_label = new TitleLabelView.TitleLabelView();
        let context = this._title_label.get_style_context()
        context.add_class(EndlessWikipedia.STYLE_CLASS_TITLE);
        context.add_class(EndlessWikipedia.STYLE_CLASS_PREBUILT);
        context.add_class(EndlessWikipedia.STYLE_CLASS_FRONT_PAGE);
        this._category_selector = new CategorySelectorView.CategorySelectorView();

        props = props || {};
        props.orientation = Gtk.Orientation.HORIZONTAL;
        props.column_spacing = TITLE_CATEGORY_COLUMN_SPACING;
        this.parent(props);

        this.add(this._title_label);
        this.add(this._category_selector);
        this._category_selector.connect('category-chosen',
            Lang.bind(this, this._onCategoryChosen));
    },

    get title() {
        return this._title;
    },

    set title(value) {
        this._title = value;
        this._title_label.title = value;
    },

    get image_uri() {
        return this._image_uri;
    },

    set image_uri(value) {
        this._image_uri = value;
        this._title_label.image_uri = value;
    },

    setCategories: function(categories) {
        this._category_selector.setCategories(categories);
    },

    // Proxy signal
    _onCategoryChosen: function(widget, title, index) {
        this.emit('category-chosen', title, index);
    }
});