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
|
/* This file is part of GPump, a Pump.io client.
*
* GPump (THE SOFTWARE) is made available under the terms and conditions of the
* GNU Lesser General Public Licence 3.0. A copy of the licence can be read
* in the file lgpl-3.0.txt in the root of this project.
*/
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const _ = imports.gettext.gettext;
const SettingsData = imports.settings_data;
const Application = new Lang.Class ({
Name: "Application",
Extends: Gtk.Application,
_init: function () {
this.parent ({
application_id: "org.gego.gpump",
flags: Gio.ApplicationFlags.FLAGS_NONE,
register_session: true
});
GLib.set_application_name (_("GPump"));
this.settings = SettingsData.get_settings ();
},
vfunc_activate: function () {
/* Guarantee that only one window is present at any time. */
let w_list = this.get_windows ();
if (w_list.length) {
w_list[0].present ();
return;
}
this._prepareWindow ();
this._prepareAppMenu ();
this._prepareHeaderBar ();
this.window.show_all ();
},
/**
* This function is used to prepare the window, it also initializes and adds
* the headerbar to it.
*/
_prepareWindow: function () {
this.window = new Gtk.ApplicationWindow ({
application: this,
type: Gtk.WindowType.TOPLEVEL,
title: GLib.get_application_name (),
default_height: 500,
default_width: 500,
height_request: 500,
width_request: 500,
window_position: Gtk.WindowPosition.CENTER
});
this.window.set_titlebar ((this.headerbar = new Gtk.HeaderBar({
title: GLib.get_application_name (),
subtitle: _('A Pump.io client'),
show_close_button: true
})));
print ("derp!\n");
this.window.add (( this.scroll_view = new Gtk.ScrolledWindow () ));
this.scroll_view.add ((this.list_box = new Gtk.ListBox ()));
this.window.connect ('delete_event',
Lang.bind (this.window,
this.window.hide_on_delete));
this.add_window (this.window);
},
/**
* This function is used to create the application menu.
*/
_prepareAppMenu: function () {
let menu = new Gio.Menu ();
let section = new Gio.Menu ();
section.append ("Preferences", "app.preferences");
menu.append_section (null, section);
section = new Gio.Menu ();
section.append (_("About"), "app.about");
section.append (_("Quit"), "app.quit");
menu.append_section (null, section);
this.set_app_menu (menu);
let quit_action = new Gio.SimpleAction ({name: "quit"});
quit_action.connect ('activate', Lang.bind (this, function () {
this.quit ();
}));
this.add_action (quit_action);
},
/**
* This function is used to prepare the hearderbar by adding buttons and
* assigning callback functions to them.
*/
_prepareHeaderBar: function () {
this.headerbar.pack_start ((this.new_post_btn = new Gtk.Button ({
image: (new Gtk.Image ({icon_name: 'text-editor-symbolic'})),
tooltip_text: _('Create new post')
})));
this.headerbar.pack_start ((this.refresh_btn = new Gtk.Button({
image: (new Gtk.Image ({icon_name: 'emblem-synchronizing-symbolic'})),
tooltip_text: _('Refresh the stream')
})));
this.headerbar.pack_end ((this.user_menu_btn = new Gtk.Button ({
image: (new Gtk.Image ({icon_name: 'emblem-system-symbolic'})),
tooltip_text: _('Switch and manage users')
})));
}
});
|