summaryrefslogtreecommitdiff
path: root/test/smoke-tests/app-window.js
blob: 42381a845682ed67d5bda6f38f619990be3f4298 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// Copyright 2013 Endless Mobile, Inc.

const Lang = imports.lang;
const Endless = imports.gi.Endless;
const Gtk = imports.gi.Gtk;
const GObject = imports.gi.GObject;

const TEST_APPLICATION_ID = 'com.endlessm.example.test';

const CAT_BACKGROUND_PATH = './test/smoke-tests/images/cat_eye.jpg';
const DOG_BACKGROUND_PATH = './test/smoke-tests/images/dog_eye.jpg';

const Page0 = new Lang.Class ({
    Name: 'Page0',
    Extends: Gtk.Grid,

    _init: function(pm, props) {
        props = props || {};
        props.orientation = Gtk.Orientation.VERTICAL;
        this.parent(props);

        this.button1 = new Gtk.Button({ label: 'Go to page1' });
        this.add(this.button1);
        this.button2 = new Gtk.Button({ label: 'Go to page named "page1"' });
        this.add(this.button2);

        this._addTransitionOptions(pm);
    },

    _addTransitionOptions: function(pm) {
        // Combo box for transition type...
        let typeMenu = new Gtk.ComboBoxText();
        let type_options = {
            "Transition type: None": Endless.PageManagerTransitionType.NONE,
            "Transition type: Fade": Endless.PageManagerTransitionType.CROSSFADE,
            "Transition type: Slide Right": Endless.PageManagerTransitionType.SLIDE_RIGHT,
            "Transition type: Slide Left": Endless.PageManagerTransitionType.SLIDE_LEFT,
            "Transition type: Slide Down": Endless.PageManagerTransitionType.SLIDE_DOWN,
            "Transition type: Slide Up": Endless.PageManagerTransitionType.SLIDE_UP
        }
        for (let key in type_options) {
            typeMenu.append_text(key);
        }
        typeMenu.set_active (0);
        this.add(typeMenu);
        typeMenu.connect('changed', Lang.bind(this, function () {
            let activeKey = typeMenu.get_active_text();
            pm.set_transition_type(type_options[activeKey]);
        }));
        // Combo box for transition time...
        let durationMenu = new Gtk.ComboBoxText();
        let duration_options = {
            "Transition time: 200": 200,
            "Transition time: 500": 500,
            "Transition time: 1000": 1000,
            "Transition time: 2000": 2000
        }
        for (let key in duration_options) {
            durationMenu.append_text(key);
        }
        durationMenu.set_active (0);
        this.add(durationMenu);
        durationMenu.connect('changed', Lang.bind(this, function () {
            let activeKey = durationMenu.get_active_text();
            pm.set_transition_duration(duration_options[activeKey]);
        }));
    }
});

const Page1 = new Lang.Class ({
    Name: 'Page1',
    Extends: Gtk.Grid,

    _init: function(props) {
        props = props || {};
        props.orientation = Gtk.Orientation.HORIZONTAL;
        this.parent(props);

        this.button1 = new Gtk.Button({ label: 'Go to page0' });
        this.add(this.button1);
        this.button2 = new Gtk.Button({ label: 'Go to page named "page0"' });
        this.add(this.button2);
        this.button3 = new Gtk.Button({ label: 'Swap this page background' });
        this.add(this.button3);
    }
});

const Toolbox = new Lang.Class ({
    Name: 'Toolbox',
    Extends: Gtk.Grid,

    _init: function(props) {
        props = props || {};
        props.orientation = Gtk.Orientation.VERTICAL;
        this.parent(props);

        this._label = new Gtk.Label({ label: 'The Toolbox' });
        this._label1 = new Gtk.Label({ label: 'Actions on page 0' });
        this._label2 = new Gtk.Label({ label: 'Actions on page 1' });
        this.switch1 = new Gtk.Switch({ active: false });
        this.switch2 = new Gtk.Switch({ active: true });

        this.add(this._label);
        this.add(this._label1);
        this.add(this.switch1);
        this.add(this._label2);
        this.add(this.switch2);
    }
});

const LeftTopbar = new Lang.Class ({
    Name: 'LeftTopBar',
    Extends: Gtk.Grid,

    _init: function(props) {
        props = props || {};
        props.orientation = Gtk.Orientation.VERTICAL;
        this.parent(props);

        this._label = new Gtk.Label({ label: 'The Left Topbar' });

        this.add(this._label);
    }
});

const CenterTopbar = new Lang.Class ({
    Name: 'CenterTopBar',
    Extends: Gtk.Grid,

    _init: function(props) {
        props = props || {};
        props.orientation = Gtk.Orientation.VERTICAL;
        this.parent(props);

        this._label = new Gtk.Label({ label: 'The Center Topbar' });

        this.add(this._label);
    }
});

const TestApplication = new Lang.Class ({
    Name: 'TestApplication',
    Extends: Endless.Application,

    vfunc_startup: function() {
        this.parent();

        this._pm = new Endless.PageManager();

        // First page
        this._page0 = new Page0(this._pm);
        this._page0.button1.connect('clicked', Lang.bind(this, function () {
            this._pm.visible_page = this._page1;
        }));
        this._page0.button2.connect('clicked', Lang.bind(this, function () {
            this._pm.visible_page_name = "page1";
        }));

        // Second page
        this._page1 = new Page1();
        this._page1.button1.connect('clicked', Lang.bind(this, function () {
            this._pm.visible_page = this._page0;
        }));
        this._page1.button2.connect('clicked', Lang.bind(this, function () {
            this._pm.visible_page_name = "page0";
        }));
        this._page1.button3.connect('clicked', Lang.bind(this, function () {
            let background_uri = this._pm.get_page_background_uri(this._page1);
            if (background_uri === CAT_BACKGROUND_PATH)
                background_uri = DOG_BACKGROUND_PATH;
            else
                background_uri = CAT_BACKGROUND_PATH;
            this._pm.set_page_background_uri(this._page1, background_uri);
        }));


        this._toolbox = new Toolbox();
        this._toolbox.switch1.connect('notify::active', Lang.bind(this, function () {
            this._pm.set_page_actions(this._page0,
                this._toolbox.switch1.active);
        }));
        this._toolbox.switch2.connect('notify::active', Lang.bind(this, function () {
            this._pm.set_page_actions(this._page1,
                this._toolbox.switch2.active);
        }));

        this._left_topbar = new LeftTopbar();

        this._center_topbar = new CenterTopbar();

        this._pm.add(this._page0, {
            name: "page0",
            background_uri: CAT_BACKGROUND_PATH,
            custom_toolbox_widget: this._toolbox,
            left_topbar_widget: this._left_topbar,
            center_topbar_widget: this._center_topbar 
        });

        this._pm.add(this._page1, {
            name: "page1",
            background_uri: DOG_BACKGROUND_PATH,
            custom_toolbox_widget: this._toolbox,
            left_topbar_widget: this._left_topbar,
            center_topbar_widget: this._center_topbar,
            page_actions: true
        });

        this._window = new Endless.Window({
            application: this,
            page_manager: this._pm
        });
        this._window.show_all();
    },

    _onButtonClicked: function () {
        this._window.destroy();
    }
});

let app = new TestApplication({ application_id: TEST_APPLICATION_ID,
                                flags: 0 });
app.run(ARGV);