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.
9
const Gettext = imports.gettext;
10
const Gio = imports.gi.Gio;
11
const GLib = imports.gi.GLib;
12
const GObject = imports.gi.GObject;
13
const Gtk = imports.gi.Gtk;
14
const _ = imports.gettext.gettext;
15
const Lang = imports.lang;
17
const SettingsData = imports.settings_data;
18
/* const Style = imports.style; */
19
const PreferencesUI = imports.preferences_ui;
20
const UserMenu = imports.user_menu;
22
const Application = new Lang.Class ({
24
Extends: Gtk.Application,
27
this.settings = SettingsData.get_settings ();
29
Gettext.bindtextdomain ("gpump", "./locale/"); //FIXME
30
Gettext.textdomain ("gpump");
31
GLib.set_prgname ("gpump");
34
application_id: "org.gego.gpump",
35
flags: Gio.ApplicationFlags.FLAGS_NONE,
36
register_session: true,
38
GLib.set_application_name (_("GPump"));
42
vfunc_activate: function () {
43
/* Guarantee that only one window is present at any time. */
44
let w_list = this.get_windows ();
50
this._prepare_window ();
51
this._prepare_app_menu ();
52
this._prepare_header_bar ();
54
/* Style.load_css (); */
56
this.window.show_all ();
60
* This function is used to prepare the window, it also initializes and adds
61
* the headerbar to it.
63
_prepare_window: function () {
64
this.window = new Gtk.ApplicationWindow ({
66
type: Gtk.WindowType.TOPLEVEL,
67
title: GLib.get_application_name (),
68
default_height: this.settings.get_setting ("ui.h").data,
69
default_width: this.settings.get_setting ("ui.w").data,
72
window_position: Gtk.WindowPosition.CENTER
75
this.window.set_titlebar ((this.headerbar = new Gtk.HeaderBar({
76
title: GLib.get_application_name (),
77
subtitle: _("A Pump.io client"),
78
show_close_button: true
81
if (!(this.settings.get_setting ("ui.x").data < 0 &&
82
this.settings.get_setting ("ui.y").data < 0)){
83
this.window.move (this.settings.get_setting ("ui.x").data,
84
this.settings.get_setting ("ui.y").data);
87
var gtk_settings = Gtk.Settings.get_default ();
88
if ( this.settings.get_setting ("main.use_dark").data ) {
89
gtk_settings["gtk_application_prefer_dark_theme"] = true;
91
gtk_settings["gtk_application_prefer_dark_theme"] = false;
96
this.window.add (( this.scroll_view = new Gtk.ScrolledWindow () ));
97
this.scroll_view.add ((this.list_box = new Gtk.ListBox ()));
99
this.window.connect ('delete_event',
100
Lang.bind (this.window,
101
this.window.hide_on_delete));
103
this.add_window (this.window);
107
* This function is used to create the application menu.
109
_prepare_app_menu: function () {
110
let menu = new Gio.Menu ();
111
let section = new Gio.Menu ();
113
section.append (_("Preferences"), "app.preferences");
114
menu.append_section (null, section);
116
section = new Gio.Menu ();
117
section.append (_("About"), "app.about");
118
section.append (_("Quit"), "app.quit");
119
menu.append_section (null, section);
121
this.set_app_menu (menu);
123
let about_action = new Gio.SimpleAction ({name: "about"});
124
about_action.connect ('activate', Lang.bind (this, function () {
125
let about_dialog = new Gtk.AboutDialog ({use_header_bar: true,
126
transient_for: this.window,
128
version: "pre-alpha ~BZR~",
129
program_name: GLib.get_application_name (),
130
copyright: "Gustav \'Gego/XAREN\' Hartvigsson, 2014",
131
license_type: Gtk.License.LGPL_3_0});
133
about_dialog.authors =
134
["Gustav Hartvigsson <gustav.hartvigsson@gmail.com>"];
135
about_dialog.connect ("response", function () {
136
about_dialog.destroy ();
140
this.add_action (about_action);
142
let quit_action = new Gio.SimpleAction ({name: "quit"});
143
quit_action.connect ('activate', Lang.bind (this, function () {
144
let allocation = this.window.get_allocation ();
145
this.settings.set_setting ("ui.h", allocation.height);
146
this.settings.set_setting ("ui.w", allocation.width);
148
let win_pos = this.window.get_position ();
149
this.settings.set_setting ("ui.x", win_pos[0]);
150
this.settings.set_setting ("ui.y", win_pos[1]);
151
this.settings.commit_to_file ();
154
this.add_action (quit_action);
156
let preferences_action = new Gio.SimpleAction ({name: "preferences"});
157
preferences_action.connect ('activate', Lang.bind (this, function (){
158
let pref_dialog = new PreferencesUI.PreferencesUI ();
159
pref_dialog.set_transient_for (this.window);
162
this.add_action (preferences_action);
166
* This function is used to prepare the hearderbar by adding buttons and
167
* assigning callback functions to them.
169
_prepare_header_bar: function () {
170
this.headerbar.pack_start ((this.new_post_btn = new Gtk.Button ({
171
image: (new Gtk.Image ({icon_name: 'text-editor-symbolic'})),
172
tooltip_text: _("Create new post")
175
this.headerbar.pack_start ((this.refresh_btn = new Gtk.Button({
176
image: (new Gtk.Image ({icon_name: 'emblem-synchronizing-symbolic'})),
177
tooltip_text: _("Refresh the stream")
180
this.headerbar.pack_end ((this.user_menu_btn = new Gtk.MenuButton ({
181
image: (new Gtk.Image ({icon_name: 'emblem-system-symbolic'})),
182
tooltip_text: _("Switch and manage users"),
183
popover: (this.user_menu = new UserMenu.UserMenu ()),