/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: 2014-06-09 13:00:41 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20140609130041-mn6cn3ogqw22jsas
* made the functions look more alike...
  ie: more glib-ish...

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
 
 
9
 
const Gettext = imports.gettext;
10
8
const Gio = imports.gi.Gio;
11
9
const GLib = imports.gi.GLib;
12
 
const GObject = imports.gi.GObject;
13
10
const Gtk = imports.gi.Gtk;
 
11
const Lang = imports.lang;
14
12
const _ = imports.gettext.gettext;
15
 
const Lang = imports.lang;
 
13
 
16
14
 
17
15
const SettingsData = imports.settings_data;
18
 
/* const Style = imports.style; */
19
 
const PreferencesUI = imports.preferences_ui;
20
 
const UserMenu = imports.user_menu;
21
 
const UserButton = imports.user_button;
22
16
 
23
 
/** @class
24
 
 * This class is the main application class, it creates the main wiev
25
 
 * and basically is what runs the program.
26
 
 */
27
17
const Application = new Lang.Class ({
28
18
  Name: "Application",
29
19
  Extends: Gtk.Application,
30
20
  
31
21
  _init: function () {
32
 
    this.settings = SettingsData.get_settings ();
33
 
    
34
 
    Gettext.bindtextdomain ("gpump", "./locale/"); //FIXME
35
 
    Gettext.textdomain ("gpump");
36
 
    GLib.set_prgname ("gpump");
37
 
    
38
22
    this.parent ({
39
23
      application_id: "org.gego.gpump",
40
24
      flags: Gio.ApplicationFlags.FLAGS_NONE,
41
 
      register_session: true,
 
25
      register_session: true
42
26
    });
43
 
    GLib.set_application_name (_("GPump"));
 
27
   GLib.set_application_name (_("GPump"));
44
28
    
 
29
    this.settings = SettingsData.get_settings ();
45
30
  },
46
31
  
47
32
  vfunc_activate: function () {
49
34
    let w_list = this.get_windows ();
50
35
    if (w_list.length) {
51
36
      w_list[0].present ();
52
 
      w_list[0].move (this.settings.get_setting ("ui.x").data,
53
 
                             this.settings.get_setting ("ui.y").data);
54
37
      return;
55
38
    }
56
39
    
58
41
    this._prepare_app_menu ();
59
42
    this._prepare_header_bar ();
60
43
    
61
 
    /* Style.load_css (); */
62
 
    
63
44
    this.window.show_all ();
64
45
  },
65
46
  
68
49
   * the headerbar to it.
69
50
   */
70
51
  _prepare_window: function () {
71
 
    
72
52
    this.window = new Gtk.ApplicationWindow ({
73
53
      application: this,
74
54
      type: Gtk.WindowType.TOPLEVEL,
82
62
    
83
63
    this.window.set_titlebar ((this.headerbar = new Gtk.HeaderBar({
84
64
      title: GLib.get_application_name (),
85
 
      subtitle: _("A Pump.io client"),
 
65
      subtitle: _('A Pump.io client'),
86
66
      show_close_button: true
87
67
    })));
88
68
    
89
 
    if (!(this.settings.get_setting ("ui.x").data < 0 &&
90
 
        this.settings.get_setting ("ui.y").data < 0)){
91
 
      this.window.move (this.settings.get_setting ("ui.x").data,
92
 
                                       this.settings.get_setting ("ui.y").data);
93
 
    }
94
 
    
95
 
    var gtk_settings = Gtk.Settings.get_default ();
96
 
      if ( this.settings.get_setting ("main.use_dark").data ) {
97
 
        gtk_settings["gtk_application_prefer_dark_theme"] = true;
98
 
      } else {
99
 
        gtk_settings["gtk_application_prefer_dark_theme"] = false;
100
 
      }
101
 
    
102
69
    print ("derp!\n");
103
70
    
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 */
 
71
    this.window.add (( this.scroll_view = new Gtk.ScrolledWindow () ));
 
72
    this.scroll_view.add ((this.list_box = new Gtk.ListBox ()));
 
73
    
145
74
    this.window.connect ('delete_event',
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
 
    }));
 
75
                         Lang.bind (this.window,
 
76
                                    this.window.hide_on_delete));
153
77
    
154
78
    this.add_window (this.window);
155
79
  },
161
85
    let menu = new Gio.Menu ();
162
86
    let section = new Gio.Menu ();
163
87
    
164
 
    section.append (_("Preferences"), "app.preferences");
 
88
    section.append ("Preferences", "app.preferences");
165
89
    menu.append_section (null, section);
166
90
    
167
91
    section = new Gio.Menu ();
171
95
    
172
96
    this.set_app_menu (menu);
173
97
    
174
 
    let about_action = new Gio.SimpleAction ({name: "about"});
175
 
    about_action.connect ('activate', Lang.bind (this, function () {
176
 
      let about_dialog = new Gtk.AboutDialog ({use_header_bar: true,
177
 
        transient_for: this.window,
178
 
        modal: true,
179
 
        version: "pre-alpha ~BZR~",
180
 
        program_name: GLib.get_application_name (),
181
 
        copyright: "Gustav \'Gego/XAREN\' Hartvigsson, 2014",
182
 
        license_type: Gtk.License.LGPL_3_0});
183
 
      
184
 
      about_dialog.authors =
185
 
                          ["Gustav Hartvigsson <gustav.hartvigsson@gmail.com>"];
186
 
      about_dialog.connect ("response", function () {
187
 
        about_dialog.destroy ();
188
 
      });
189
 
      about_dialog.run ();
190
 
    }));
191
 
    this.add_action (about_action);
192
 
    
193
98
    let quit_action = new Gio.SimpleAction ({name: "quit"});
194
99
    quit_action.connect ('activate', Lang.bind (this, function () {
195
 
      this._save_settings ();
196
100
      this.quit ();
197
101
    }));
198
102
    this.add_action (quit_action);
199
103
    
200
 
    let preferences_action = new Gio.SimpleAction ({name: "preferences"});
201
 
    preferences_action.connect ('activate', Lang.bind (this, function (){
202
 
      let pref_dialog = new PreferencesUI.PreferencesUI ({
203
 
        transient_for: this.window
204
 
      });
205
 
      pref_dialog.run ();
206
 
    }));
207
 
    this.add_action (preferences_action);
208
104
  },
209
105
  
210
106
  /**
212
108
   * assigning callback functions to them.
213
109
   */
214
110
  _prepare_header_bar: function () {
215
 
    
216
111
    this.headerbar.pack_start ((this.new_post_btn = new Gtk.Button ({
217
112
      image: (new Gtk.Image ({icon_name: 'text-editor-symbolic'})),
218
 
      tooltip_text: _("Create new post"),
 
113
      tooltip_text: _('Create new post')
219
114
    })));
220
115
    
221
 
   this.new_post_btn.get_style_context ().add_class ("image-button");
222
 
    
223
116
    this.headerbar.pack_start ((this.refresh_btn = new Gtk.Button({
224
117
      image: (new Gtk.Image ({icon_name: 'emblem-synchronizing-symbolic'})),
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 ();
 
118
      tooltip_text: _('Refresh the stream')
 
119
    })));
 
120
    
 
121
    this.headerbar.pack_end ((this.user_menu_btn = new Gtk.Button ({
 
122
      image: (new Gtk.Image ({icon_name: 'emblem-system-symbolic'})),
 
123
      tooltip_text: _('Switch and manage users')
 
124
    })));
247
125
  }
248
126
  
249
127
});