5
5
* in the file lgpl-3.0.txt in the root of this project.
8
const cairo = imports.gi.cairo;
8
9
const Gio = imports.gi.Gio;
9
10
const GLib = imports.gi.GLib;
11
const GObject = imports.gi.GObject;
10
12
const Gtk = imports.gi.Gtk;
11
13
const Lang = imports.lang;
12
14
const _ = imports.gettext.gettext;
15
const Gettext = imports.gettext;
15
17
const SettingsData = imports.settings_data;
18
/* const Style = imports.style; */
19
const PreferencesUI = imports.preferences_ui;
17
21
const Application = new Lang.Class ({
18
22
Name: "Application",
19
23
Extends: Gtk.Application,
21
25
_init: function () {
26
this.settings = SettingsData.get_settings ();
28
Gettext.bindtextdomain ("gpump", "./locale/"); //FIXME
29
Gettext.textdomain ("gpump");
30
GLib.set_prgname ("gpump");
23
33
application_id: "org.gego.gpump",
24
34
flags: Gio.ApplicationFlags.FLAGS_NONE,
25
register_session: true
35
register_session: true,
27
GLib.set_application_name (_("GPump"));
37
GLib.set_application_name (_("GPump"));
29
this.settings = SettingsData.get_settings ();
32
41
vfunc_activate: function () {
48
59
* This function is used to prepare the window, it also initializes and adds
49
60
* the headerbar to it.
51
_prepareWindow: function () {
62
_prepare_window: function () {
52
63
this.window = new Gtk.ApplicationWindow ({
54
65
type: Gtk.WindowType.TOPLEVEL,
55
66
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,
58
69
height_request: 500,
59
70
width_request: 500,
60
71
window_position: Gtk.WindowPosition.CENTER
63
74
this.window.set_titlebar ((this.headerbar = new Gtk.HeaderBar({
64
75
title: GLib.get_application_name (),
65
subtitle: _('A Pump.io client'),
76
subtitle: _("A Pump.io client"),
66
77
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;
71
95
this.window.add (( this.scroll_view = new Gtk.ScrolledWindow () ));
82
106
* This function is used to create the application menu.
84
_prepareAppMenu: function () {
108
_prepare_app_menu: function () {
85
109
let menu = new Gio.Menu ();
86
110
let section = new Gio.Menu ();
88
section.append ("Preferences", "app.preferences");
112
section.append (_("Preferences"), "app.preferences");
89
113
menu.append_section (null, section);
91
115
section = new Gio.Menu ();
96
120
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);
98
141
let quit_action = new Gio.SimpleAction ({name: "quit"});
99
142
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 ();
102
153
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);
107
165
* This function is used to prepare the hearderbar by adding buttons and
108
166
* assigning callback functions to them.
110
_prepareHeaderBar: function () {
168
_prepare_header_bar: function () {
111
169
this.headerbar.pack_start ((this.new_post_btn = new Gtk.Button ({
112
170
image: (new Gtk.Image ({icon_name: 'text-editor-symbolic'})),
113
tooltip_text: _('Create new post')
171
tooltip_text: _("Create new post")
116
174
this.headerbar.pack_start ((this.refresh_btn = new Gtk.Button({
117
175
image: (new Gtk.Image ({icon_name: 'emblem-synchronizing-symbolic'})),
118
tooltip_text: _('Refresh the stream')
176
tooltip_text: _("Refresh the stream")
121
179
this.headerbar.pack_end ((this.user_menu_btn = new Gtk.Button ({
122
180
image: (new Gtk.Image ({icon_name: 'emblem-system-symbolic'})),
123
tooltip_text: _('Switch and manage users')
181
tooltip_text: _("Switch and manage users")