/gpump/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/gpump/trunk

« back to all changes in this revision

Viewing changes to src/app.js

  • Committer: Gustav Hartvigsson
  • Date: 2015-06-05 19:06:14 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20150605190614-s410mh65n2jdxtcv
* Cleaded up a lille code
* Fixed a nasty segfault that could occur if the conig folder did not exist.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 * in the file lgpl-3.0.txt in the root of this project.
6
6
 */
7
7
 
8
 
const cairo = imports.gi.cairo;
 
8
 
 
9
const Gettext = imports.gettext;
9
10
const Gio = imports.gi.Gio;
10
11
const GLib = imports.gi.GLib;
11
12
const GObject = imports.gi.GObject;
12
13
const Gtk = imports.gi.Gtk;
 
14
const _ = imports.gettext.gettext;
13
15
const Lang = imports.lang;
14
 
const _ = imports.gettext.gettext;
15
 
const Gettext = imports.gettext;
16
16
 
17
17
const SettingsData = imports.settings_data;
18
18
/* const Style = imports.style; */
19
19
const PreferencesUI = imports.preferences_ui;
 
20
const UserMenu = imports.user_menu;
 
21
const UserButton = imports.user_button;
20
22
 
 
23
/** @class
 
24
 * This class is the main application class, it creates the main wiev
 
25
 * and basically is what runs the program.
 
26
 */
21
27
const Application = new Lang.Class ({
22
28
  Name: "Application",
23
29
  Extends: Gtk.Application,
43
49
    let w_list = this.get_windows ();
44
50
    if (w_list.length) {
45
51
      w_list[0].present ();
 
52
      w_list[0].move (this.settings.get_setting ("ui.x").data,
 
53
                             this.settings.get_setting ("ui.y").data);
46
54
      return;
47
55
    }
48
56
    
60
68
   * the headerbar to it.
61
69
   */
62
70
  _prepare_window: function () {
 
71
    
63
72
    this.window = new Gtk.ApplicationWindow ({
64
73
      application: this,
65
74
      type: Gtk.WindowType.TOPLEVEL,
66
75
      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,
 
76
      default_height: 500,
 
77
      default_width: 500,
69
78
      height_request: 500,
70
79
      width_request: 500,
71
80
      window_position: Gtk.WindowPosition.CENTER
92
101
    
93
102
    print ("derp!\n");
94
103
    
95
 
    this.window.add (( this.scroll_view = new Gtk.ScrolledWindow () ));
96
 
    this.scroll_view.add ((this.list_box = new Gtk.ListBox ()));
97
 
    
 
104
    
 
105
    
 
106
    this.window.add ((this.layout = new Gtk.Box ({
 
107
      orientation: Gtk.Orientation.VERTICAL
 
108
    })));
 
109
    
 
110
    /* * Building the stack switched views */
 
111
    /* switcher */
 
112
    /* Hack to centre the damn switcher */
 
113
    this.layout.pack_start ((this.switcher_box = new Gtk.Box ({
 
114
      orientation: Gtk.Orientation.HORIZONTAL
 
115
    })), false, false, 0);
 
116
    
 
117
    this.switcher_box.set_center_widget (
 
118
      (this.stack_switcher = new Gtk.StackSwitcher ())
 
119
    );
 
120
    
 
121
    /* the stack */
 
122
    this.layout.pack_end ((this.stack = new Gtk.Stack ({
 
123
      homogeneous: true,
 
124
      transition_duration: 250,
 
125
      transition_type: Gtk.StackTransitionType.CROSSFADE
 
126
    })), true, true, 0);
 
127
    
 
128
    /* main view */
 
129
    this.stack.add_titled ((new Gtk.ScrolledWindow ({
 
130
      child: (this.main_list_box = new Gtk.ListBox()),
 
131
      margin: 1
 
132
    })), "main", _("Main"));
 
133
    
 
134
    
 
135
    /* 'mean while' view */
 
136
    this.stack.add_titled ((new Gtk.ScrolledWindow ({
 
137
      child: (this.mw_list_box = new Gtk.ListBox()),
 
138
      margin: 1
 
139
    })), "meanwhile", _("Meanwhile"));
 
140
    
 
141
    /* * Hook up the stack and the stack switcher */
 
142
    this.stack_switcher.set_stack (this.stack);
 
143
    
 
144
    /* * Hide the window so, so we can show it later */
98
145
    this.window.connect ('delete_event',
99
 
                         Lang.bind (this.window,
100
 
                                    this.window.hide_on_delete));
 
146
                         Lang.bind (this, function () {
 
147
      print ("balls to it!");
 
148
      this._save_settings ();
 
149
      this.window.hide ();
 
150
      /* To Prevent the widow from rely being destroyed? */
 
151
      return true;
 
152
    }));
101
153
    
102
154
    this.add_window (this.window);
103
155
  },
140
192
    
141
193
    let quit_action = new Gio.SimpleAction ({name: "quit"});
142
194
    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);
146
 
      
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 ();
 
195
      this._save_settings ();
151
196
      this.quit ();
152
197
    }));
153
198
    this.add_action (quit_action);
154
199
    
155
200
    let preferences_action = new Gio.SimpleAction ({name: "preferences"});
156
201
    preferences_action.connect ('activate', Lang.bind (this, function (){
157
 
      let pref_dialog = new PreferencesUI.PreferencesUI ();
158
 
      pref_dialog.set_transient_for (this.window);
 
202
      let pref_dialog = new PreferencesUI.PreferencesUI ({
 
203
        transient_for: this.window
 
204
      });
159
205
      pref_dialog.run ();
160
206
    }));
161
207
    this.add_action (preferences_action);
166
212
   * assigning callback functions to them.
167
213
   */
168
214
  _prepare_header_bar: function () {
 
215
    
169
216
    this.headerbar.pack_start ((this.new_post_btn = new Gtk.Button ({
170
217
      image: (new Gtk.Image ({icon_name: 'text-editor-symbolic'})),
171
 
      tooltip_text: _("Create new post")
 
218
      tooltip_text: _("Create new post"),
172
219
    })));
173
220
    
 
221
   this.new_post_btn.get_style_context ().add_class ("image-button");
 
222
    
174
223
    this.headerbar.pack_start ((this.refresh_btn = new Gtk.Button({
175
224
      image: (new Gtk.Image ({icon_name: 'emblem-synchronizing-symbolic'})),
176
 
      tooltip_text: _("Refresh the stream")
177
 
    })));
178
 
    
179
 
    this.headerbar.pack_end ((this.user_menu_btn = new Gtk.Button ({
180
 
      image: (new Gtk.Image ({icon_name: 'emblem-system-symbolic'})),
181
 
      tooltip_text: _("Switch and manage users")
182
 
    })));
 
225
      tooltip_text: _("Refresh the stream"),
 
226
    })));
 
227
    
 
228
    this.refresh_btn.get_style_context ().add_class ("image-button");
 
229
    
 
230
    this.headerbar.pack_end ((this.user_menu_btn = new UserButton.UserButton ({
 
231
      image: (new Gtk.Image ({icon_name: 'mail-send-symbolic'})),
 
232
      tooltip_text: _("Switch and manage users"),
 
233
      popover: (this.user_menu = new UserMenu.UserMenu ()),
 
234
    })));
 
235
    
 
236
  },
 
237
  
 
238
  _save_settings: function () {
 
239
    let allocation = this.window.get_allocation ();
 
240
    this.settings.set_setting ("ui.h", allocation.height);
 
241
    this.settings.set_setting ("ui.w", allocation.width);
 
242
    
 
243
    let win_pos = this.window.get_position ();
 
244
    this.settings.set_setting ("ui.x", win_pos[0]);
 
245
    this.settings.set_setting ("ui.y", win_pos[1]);
 
246
    this.settings.commit_to_file ();
183
247
  }
184
248
  
185
249
});