bzr branch
http://gegoxaren.bato24.eu/bzr/gpump/trunk
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
1 |
/* This file is part of GPump, a Pump.io client.
|
2 |
*
|
|
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.
|
|
6 |
*/
|
|
7 |
||
|
46
by Gustav Hartvigsson
* Now saves the Height, Width, X and Y of the window on quit. |
8 |
const cairo = imports.gi.cairo; |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
9 |
const Gio = imports.gi.Gio; |
10 |
const GLib = imports.gi.GLib; |
|
|
46
by Gustav Hartvigsson
* Now saves the Height, Width, X and Y of the window on quit. |
11 |
const GObject = imports.gi.GObject; |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
12 |
const Gtk = imports.gi.Gtk; |
13 |
const Lang = imports.lang; |
|
|
34
by Gustav Hartvigsson
* added GetText stuffs... |
14 |
const _ = imports.gettext.gettext; |
15 |
||
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
16 |
|
17 |
const SettingsData = imports.settings_data; |
|
|
49
by Gustav Hartvigsson
* Changes a thing in the about dialoug. |
18 |
/* const Style = imports.style; */
|
|
44
by Gustav Hartvigsson
* UI for preferences done, it is still not functional. |
19 |
const PreferencesUI = imports.preferences_ui; |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
20 |
|
21 |
const Application = new Lang.Class ({ |
|
22 |
Name: "Application", |
|
|
35
by Gustav Hartvigsson
* Changed to extending Gtk.Application instead.... |
23 |
Extends: Gtk.Application, |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
24 |
|
25 |
_init: function () { |
|
|
46
by Gustav Hartvigsson
* Now saves the Height, Width, X and Y of the window on quit. |
26 |
this.settings = SettingsData.get_settings (); |
27 |
|
|
|
35
by Gustav Hartvigsson
* Changed to extending Gtk.Application instead.... |
28 |
this.parent ({ |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
29 |
application_id: "org.gego.gpump", |
30 |
flags: Gio.ApplicationFlags.FLAGS_NONE, |
|
|
46
by Gustav Hartvigsson
* Now saves the Height, Width, X and Y of the window on quit. |
31 |
register_session: true, |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
32 |
}); |
|
38
by Gustav Hartvigsson
* Can now load settings from file. |
33 |
GLib.set_application_name (_("GPump")); |
|
37
by Gustav Hartvigsson
* finnihed the construction of the settings file. |
34 |
|
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
35 |
}, |
36 |
|
|
|
36
by Gustav Hartvigsson
* changed from this.connect(...) to vfunc_ . |
37 |
vfunc_activate: function () { |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
38 |
/* Guarantee that only one window is present at any time. */ |
|
35
by Gustav Hartvigsson
* Changed to extending Gtk.Application instead.... |
39 |
let w_list = this.get_windows (); |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
40 |
if (w_list.length) { |
41 |
w_list[0].present (); |
|
42 |
return; |
|
43 |
} |
|
44 |
|
|
|
43
by Gustav Hartvigsson
* made the functions look more alike... |
45 |
this._prepare_window (); |
46 |
this._prepare_app_menu (); |
|
47 |
this._prepare_header_bar (); |
|
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
48 |
|
|
49
by Gustav Hartvigsson
* Changes a thing in the about dialoug. |
49 |
/* Style.load_css (); */ |
|
46
by Gustav Hartvigsson
* Now saves the Height, Width, X and Y of the window on quit. |
50 |
|
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
51 |
this.window.show_all (); |
52 |
}, |
|
53 |
|
|
54 |
/** |
|
55 |
* This function is used to prepare the window, it also initializes and adds
|
|
56 |
* the headerbar to it.
|
|
57 |
*/
|
|
|
43
by Gustav Hartvigsson
* made the functions look more alike... |
58 |
_prepare_window: function () { |
|
38
by Gustav Hartvigsson
* Can now load settings from file. |
59 |
this.window = new Gtk.ApplicationWindow ({ |
60 |
application: this, |
|
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
61 |
type: Gtk.WindowType.TOPLEVEL, |
|
38
by Gustav Hartvigsson
* Can now load settings from file. |
62 |
title: GLib.get_application_name (), |
|
46
by Gustav Hartvigsson
* Now saves the Height, Width, X and Y of the window on quit. |
63 |
default_height: this.settings.get_setting ("ui.h").data, |
64 |
default_width: this.settings.get_setting ("ui.w").data, |
|
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
65 |
height_request: 500, |
|
38
by Gustav Hartvigsson
* Can now load settings from file. |
66 |
width_request: 500, |
67 |
window_position: Gtk.WindowPosition.CENTER |
|
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
68 |
}); |
69 |
|
|
70 |
this.window.set_titlebar ((this.headerbar = new Gtk.HeaderBar({ |
|
|
38
by Gustav Hartvigsson
* Can now load settings from file. |
71 |
title: GLib.get_application_name (), |
|
34
by Gustav Hartvigsson
* added GetText stuffs... |
72 |
subtitle: _('A Pump.io client'), |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
73 |
show_close_button: true |
74 |
}))); |
|
75 |
|
|
|
46
by Gustav Hartvigsson
* Now saves the Height, Width, X and Y of the window on quit. |
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, this.settings.get_setting ("ui.y").data); |
|
79 |
} |
|
80 |
|
|
|
38
by Gustav Hartvigsson
* Can now load settings from file. |
81 |
print ("derp!\n"); |
82 |
|
|
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
83 |
this.window.add (( this.scroll_view = new Gtk.ScrolledWindow () )); |
84 |
this.scroll_view.add ((this.list_box = new Gtk.ListBox ())); |
|
85 |
|
|
86 |
this.window.connect ('delete_event', |
|
87 |
Lang.bind (this.window, |
|
88 |
this.window.hide_on_delete)); |
|
89 |
|
|
|
35
by Gustav Hartvigsson
* Changed to extending Gtk.Application instead.... |
90 |
this.add_window (this.window); |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
91 |
}, |
92 |
|
|
93 |
/** |
|
94 |
* This function is used to create the application menu.
|
|
95 |
*/
|
|
|
43
by Gustav Hartvigsson
* made the functions look more alike... |
96 |
_prepare_app_menu: function () { |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
97 |
let menu = new Gio.Menu (); |
98 |
let section = new Gio.Menu (); |
|
99 |
|
|
100 |
section.append ("Preferences", "app.preferences"); |
|
101 |
menu.append_section (null, section); |
|
102 |
|
|
103 |
section = new Gio.Menu (); |
|
|
34
by Gustav Hartvigsson
* added GetText stuffs... |
104 |
section.append (_("About"), "app.about"); |
105 |
section.append (_("Quit"), "app.quit"); |
|
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
106 |
menu.append_section (null, section); |
107 |
|
|
|
35
by Gustav Hartvigsson
* Changed to extending Gtk.Application instead.... |
108 |
this.set_app_menu (menu); |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
109 |
|
|
47
by Gustav Hartvigsson
* Fixed the preferences dialoug. For some reasons |
110 |
let about_action = new Gio.SimpleAction ({name: "about"}); |
|
49
by Gustav Hartvigsson
* Changes a thing in the about dialoug. |
111 |
about_action.connect ('activate', Lang.bind (this, function () { |
|
47
by Gustav Hartvigsson
* Fixed the preferences dialoug. For some reasons |
112 |
let about_dialog = new Gtk.AboutDialog ({use_header_bar: true, |
113 |
transient_for: this.window, |
|
|
48
by Gustav Hartvigsson
* added moar random information to the about dialoug. |
114 |
modal: true, |
115 |
version: "pre-alpha ~BZR~", |
|
116 |
program_name: GLib.get_application_name (), |
|
|
49
by Gustav Hartvigsson
* Changes a thing in the about dialoug. |
117 |
copyright: "Gustav \'Gego/XAREN\' Hartvigsson, 2014", |
|
48
by Gustav Hartvigsson
* added moar random information to the about dialoug. |
118 |
license_type: Gtk.License.LGPL_3_0}); |
119 |
|
|
|
47
by Gustav Hartvigsson
* Fixed the preferences dialoug. For some reasons |
120 |
about_dialog.authors = ["Gustav Hartvigsson <gustav.hartvigsson@gmail.com>"]; |
121 |
about_dialog.connect ("response", function () { |
|
122 |
about_dialog.destroy (); |
|
123 |
}); |
|
124 |
about_dialog.run (); |
|
125 |
})) |
|
126 |
this.add_action (about_action); |
|
127 |
|
|
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
128 |
let quit_action = new Gio.SimpleAction ({name: "quit"}); |
129 |
quit_action.connect ('activate', Lang.bind (this, function () { |
|
|
46
by Gustav Hartvigsson
* Now saves the Height, Width, X and Y of the window on quit. |
130 |
let allocation = this.window.get_allocation (); |
131 |
this.settings.set_setting ("ui.h", allocation.height); |
|
132 |
this.settings.set_setting ("ui.w", allocation.width); |
|
133 |
|
|
134 |
let win_pos = this.window.get_position (); |
|
135 |
this.settings.set_setting ("ui.x", win_pos[0]); |
|
136 |
this.settings.set_setting ("ui.y", win_pos[1]); |
|
137 |
this.settings.commit_to_file (); |
|
|
35
by Gustav Hartvigsson
* Changed to extending Gtk.Application instead.... |
138 |
this.quit (); |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
139 |
})); |
|
35
by Gustav Hartvigsson
* Changed to extending Gtk.Application instead.... |
140 |
this.add_action (quit_action); |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
141 |
|
|
44
by Gustav Hartvigsson
* UI for preferences done, it is still not functional. |
142 |
let preferences_action = new Gio.SimpleAction ({name: "preferences"}); |
143 |
preferences_action.connect ('activate', Lang.bind (this, function (){ |
|
|
47
by Gustav Hartvigsson
* Fixed the preferences dialoug. For some reasons |
144 |
let pref_dialog = new PreferencesUI.PreferencesUI (); |
145 |
pref_dialog.set_transient_for (this.window); |
|
|
44
by Gustav Hartvigsson
* UI for preferences done, it is still not functional. |
146 |
pref_dialog.run (); |
147 |
})); |
|
148 |
this.add_action (preferences_action) |
|
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
149 |
}, |
150 |
|
|
151 |
/** |
|
152 |
* This function is used to prepare the hearderbar by adding buttons and
|
|
153 |
* assigning callback functions to them.
|
|
154 |
*/
|
|
|
43
by Gustav Hartvigsson
* made the functions look more alike... |
155 |
_prepare_header_bar: function () { |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
156 |
this.headerbar.pack_start ((this.new_post_btn = new Gtk.Button ({ |
157 |
image: (new Gtk.Image ({icon_name: 'text-editor-symbolic'})), |
|
|
34
by Gustav Hartvigsson
* added GetText stuffs... |
158 |
tooltip_text: _('Create new post') |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
159 |
}))); |
160 |
|
|
161 |
this.headerbar.pack_start ((this.refresh_btn = new Gtk.Button({ |
|
162 |
image: (new Gtk.Image ({icon_name: 'emblem-synchronizing-symbolic'})), |
|
|
34
by Gustav Hartvigsson
* added GetText stuffs... |
163 |
tooltip_text: _('Refresh the stream') |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
164 |
}))); |
165 |
|
|
166 |
this.headerbar.pack_end ((this.user_menu_btn = new Gtk.Button ({ |
|
167 |
image: (new Gtk.Image ({icon_name: 'emblem-system-symbolic'})), |
|
|
34
by Gustav Hartvigsson
* added GetText stuffs... |
168 |
tooltip_text: _('Switch and manage users') |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
169 |
}))); |
170 |
} |
|
171 |
|
|
172 |
});
|