1
/* This file is part of GPump, a Pump.io client.
3
* GPump (THE SOFTWARE) is made available under the terms and conditions of the
4
* GNU Lesser General Public Licence 3.0. A copy of the licence can be read
5
* in the file lgpl-3.0.txt in the root of this project.
8
const cairo = imports.gi.cairo;
9
const Gio = imports.gi.Gio;
10
const GLib = imports.gi.GLib;
11
const GObject = imports.gi.GObject;
12
const Gtk = imports.gi.Gtk;
13
const Lang = imports.lang;
14
const _ = imports.gettext.gettext;
17
const SettingsData = imports.settings_data;
18
/* const Style = imports.style; */
19
const PreferencesUI = imports.preferences_ui;
21
const Application = new Lang.Class ({
23
Extends: Gtk.Application,
26
this.settings = SettingsData.get_settings ();
29
application_id: "org.gego.gpump",
30
flags: Gio.ApplicationFlags.FLAGS_NONE,
31
register_session: true,
33
GLib.set_application_name (_("GPump"));
37
vfunc_activate: function () {
38
/* Guarantee that only one window is present at any time. */
39
let w_list = this.get_windows ();
45
this._prepare_window ();
46
this._prepare_app_menu ();
47
this._prepare_header_bar ();
49
/* Style.load_css (); */
51
this.window.show_all ();
55
* This function is used to prepare the window, it also initializes and adds
56
* the headerbar to it.
58
_prepare_window: function () {
59
this.window = new Gtk.ApplicationWindow ({
61
type: Gtk.WindowType.TOPLEVEL,
62
title: GLib.get_application_name (),
63
default_height: this.settings.get_setting ("ui.h").data,
64
default_width: this.settings.get_setting ("ui.w").data,
67
window_position: Gtk.WindowPosition.CENTER
70
this.window.set_titlebar ((this.headerbar = new Gtk.HeaderBar({
71
title: GLib.get_application_name (),
72
subtitle: _('A Pump.io client'),
73
show_close_button: true
76
if (!(this.settings.get_setting ("ui.x").data < 0 &&
77
this.settings.get_setting ("ui.y").data < 0)){
78
this.window.move (this.settings.get_setting ("ui.x").data,
79
this.settings.get_setting ("ui.y").data);
82
var gtk_settings = Gtk.Settings.get_default ();
83
if ( this.settings.get_setting ("main.use_dark").data ) {
84
gtk_settings["gtk_application_prefer_dark_theme"] = true;
86
gtk_settings["gtk_application_prefer_dark_theme"] = false;
91
this.window.add (( this.scroll_view = new Gtk.ScrolledWindow () ));
92
this.scroll_view.add ((this.list_box = new Gtk.ListBox ()));
94
this.window.connect ('delete_event',
95
Lang.bind (this.window,
96
this.window.hide_on_delete));
98
this.add_window (this.window);
102
* This function is used to create the application menu.
104
_prepare_app_menu: function () {
105
let menu = new Gio.Menu ();
106
let section = new Gio.Menu ();
108
section.append ("Preferences", "app.preferences");
109
menu.append_section (null, section);
111
section = new Gio.Menu ();
112
section.append (_("About"), "app.about");
113
section.append (_("Quit"), "app.quit");
114
menu.append_section (null, section);
116
this.set_app_menu (menu);
118
let about_action = new Gio.SimpleAction ({name: "about"});
119
about_action.connect ('activate', Lang.bind (this, function () {
120
let about_dialog = new Gtk.AboutDialog ({use_header_bar: true,
121
transient_for: this.window,
123
version: "pre-alpha ~BZR~",
124
program_name: GLib.get_application_name (),
125
copyright: "Gustav \'Gego/XAREN\' Hartvigsson, 2014",
126
license_type: Gtk.License.LGPL_3_0});
128
about_dialog.authors =
129
["Gustav Hartvigsson <gustav.hartvigsson@gmail.com>"];
130
about_dialog.connect ("response", function () {
131
about_dialog.destroy ();
135
this.add_action (about_action);
137
let quit_action = new Gio.SimpleAction ({name: "quit"});
138
quit_action.connect ('activate', Lang.bind (this, function () {
139
let allocation = this.window.get_allocation ();
140
this.settings.set_setting ("ui.h", allocation.height);
141
this.settings.set_setting ("ui.w", allocation.width);
143
let win_pos = this.window.get_position ();
144
this.settings.set_setting ("ui.x", win_pos[0]);
145
this.settings.set_setting ("ui.y", win_pos[1]);
146
this.settings.commit_to_file ();
149
this.add_action (quit_action);
151
let preferences_action = new Gio.SimpleAction ({name: "preferences"});
152
preferences_action.connect ('activate', Lang.bind (this, function (){
153
let pref_dialog = new PreferencesUI.PreferencesUI ();
154
pref_dialog.set_transient_for (this.window);
157
this.add_action (preferences_action);
161
* This function is used to prepare the hearderbar by adding buttons and
162
* assigning callback functions to them.
164
_prepare_header_bar: function () {
165
this.headerbar.pack_start ((this.new_post_btn = new Gtk.Button ({
166
image: (new Gtk.Image ({icon_name: 'text-editor-symbolic'})),
167
tooltip_text: _('Create new post')
170
this.headerbar.pack_start ((this.refresh_btn = new Gtk.Button({
171
image: (new Gtk.Image ({icon_name: 'emblem-synchronizing-symbolic'})),
172
tooltip_text: _('Refresh the stream')
175
this.headerbar.pack_end ((this.user_menu_btn = new Gtk.Button ({
176
image: (new Gtk.Image ({icon_name: 'emblem-system-symbolic'})),
177
tooltip_text: _('Switch and manage users')