5
5
* in the file lgpl-3.0.txt in the root of this project.
8
const cairo = imports.gi.cairo;
9
8
const Gio = imports.gi.Gio;
10
9
const GLib = imports.gi.GLib;
11
const GObject = imports.gi.GObject;
12
10
const Gtk = imports.gi.Gtk;
13
11
const Lang = imports.lang;
14
12
const _ = imports.gettext.gettext;
15
const Gettext = imports.gettext;
17
15
const SettingsData = imports.settings_data;
18
/* const Style = imports.style; */
19
const PreferencesUI = imports.preferences_ui;
21
17
const Application = new Lang.Class ({
22
18
Name: "Application",
23
19
Extends: Gtk.Application,
25
21
_init: function () {
26
this.settings = SettingsData.get_settings ();
28
Gettext.bindtextdomain ("gpump", "./locale/"); //FIXME
29
Gettext.textdomain ("gpump");
30
GLib.set_prgname ("gpump");
33
23
application_id: "org.gego.gpump",
34
24
flags: Gio.ApplicationFlags.FLAGS_NONE,
35
register_session: true,
25
register_session: true
37
GLib.set_application_name (_("GPump"));
27
GLib.set_application_name (_("GPump"));
29
this.settings = SettingsData.get_settings ();
41
32
vfunc_activate: function () {
59
48
* This function is used to prepare the window, it also initializes and adds
60
49
* the headerbar to it.
62
_prepare_window: function () {
51
_prepareWindow: function () {
63
52
this.window = new Gtk.ApplicationWindow ({
65
54
type: Gtk.WindowType.TOPLEVEL,
66
55
title: GLib.get_application_name (),
67
default_height: this.settings.get_setting ("ui.h").data,
68
default_width: this.settings.get_setting ("ui.w").data,
69
58
height_request: 500,
70
59
width_request: 500,
71
60
window_position: Gtk.WindowPosition.CENTER
74
63
this.window.set_titlebar ((this.headerbar = new Gtk.HeaderBar({
75
64
title: GLib.get_application_name (),
76
subtitle: _("A Pump.io client"),
65
subtitle: _('A Pump.io client'),
77
66
show_close_button: true
80
if (!(this.settings.get_setting ("ui.x").data < 0 &&
81
this.settings.get_setting ("ui.y").data < 0)){
82
this.window.move (this.settings.get_setting ("ui.x").data,
83
this.settings.get_setting ("ui.y").data);
86
var gtk_settings = Gtk.Settings.get_default ();
87
if ( this.settings.get_setting ("main.use_dark").data ) {
88
gtk_settings["gtk_application_prefer_dark_theme"] = true;
90
gtk_settings["gtk_application_prefer_dark_theme"] = false;
95
71
this.window.add (( this.scroll_view = new Gtk.ScrolledWindow () ));
106
82
* This function is used to create the application menu.
108
_prepare_app_menu: function () {
84
_prepareAppMenu: function () {
109
85
let menu = new Gio.Menu ();
110
86
let section = new Gio.Menu ();
112
section.append (_("Preferences"), "app.preferences");
88
section.append ("Preferences", "app.preferences");
113
89
menu.append_section (null, section);
115
91
section = new Gio.Menu ();
120
96
this.set_app_menu (menu);
122
let about_action = new Gio.SimpleAction ({name: "about"});
123
about_action.connect ('activate', Lang.bind (this, function () {
124
let about_dialog = new Gtk.AboutDialog ({use_header_bar: true,
125
transient_for: this.window,
127
version: "pre-alpha ~BZR~",
128
program_name: GLib.get_application_name (),
129
copyright: "Gustav \'Gego/XAREN\' Hartvigsson, 2014",
130
license_type: Gtk.License.LGPL_3_0});
132
about_dialog.authors =
133
["Gustav Hartvigsson <gustav.hartvigsson@gmail.com>"];
134
about_dialog.connect ("response", function () {
135
about_dialog.destroy ();
139
this.add_action (about_action);
141
98
let quit_action = new Gio.SimpleAction ({name: "quit"});
142
99
quit_action.connect ('activate', Lang.bind (this, function () {
143
let allocation = this.window.get_allocation ();
144
this.settings.set_setting ("ui.h", allocation.height);
145
this.settings.set_setting ("ui.w", allocation.width);
147
let win_pos = this.window.get_position ();
148
this.settings.set_setting ("ui.x", win_pos[0]);
149
this.settings.set_setting ("ui.y", win_pos[1]);
150
this.settings.commit_to_file ();
153
102
this.add_action (quit_action);
155
let preferences_action = new Gio.SimpleAction ({name: "preferences"});
156
preferences_action.connect ('activate', Lang.bind (this, function (){
157
let pref_dialog = new PreferencesUI.PreferencesUI ();
158
pref_dialog.set_transient_for (this.window);
161
this.add_action (preferences_action);
165
107
* This function is used to prepare the hearderbar by adding buttons and
166
108
* assigning callback functions to them.
168
_prepare_header_bar: function () {
110
_prepareHeaderBar: function () {
169
111
this.headerbar.pack_start ((this.new_post_btn = new Gtk.Button ({
170
112
image: (new Gtk.Image ({icon_name: 'text-editor-symbolic'})),
171
tooltip_text: _("Create new post")
113
tooltip_text: _('Create new post')
174
116
this.headerbar.pack_start ((this.refresh_btn = new Gtk.Button({
175
117
image: (new Gtk.Image ({icon_name: 'emblem-synchronizing-symbolic'})),
176
tooltip_text: _("Refresh the stream")
118
tooltip_text: _('Refresh the stream')
179
121
this.headerbar.pack_end ((this.user_menu_btn = new Gtk.Button ({
180
122
image: (new Gtk.Image ({icon_name: 'emblem-system-symbolic'})),
181
tooltip_text: _("Switch and manage users")
123
tooltip_text: _('Switch and manage users')