/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 11:51:50 UTC
  • mfrom: (30.1.1 GPump)
  • Revision ID: gustav.hartvigsson@gmail.com-20140609115150-mhsw860izyg9twfv
* merged from trunk

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;
9
8
const Gio = imports.gi.Gio;
10
9
const GLib = imports.gi.GLib;
11
 
const GObject = imports.gi.GObject;
12
10
const Gtk = imports.gi.Gtk;
13
11
const Lang = imports.lang;
14
12
const _ = imports.gettext.gettext;
15
 
const Gettext = imports.gettext;
 
13
 
16
14
 
17
15
const SettingsData = imports.settings_data;
18
 
/* const Style = imports.style; */
19
 
const PreferencesUI = imports.preferences_ui;
20
16
 
21
17
const Application = new Lang.Class ({
22
18
  Name: "Application",
23
19
  Extends: Gtk.Application,
24
20
  
25
21
  _init: function () {
26
 
    this.settings = SettingsData.get_settings ();
27
 
    
28
 
    Gettext.bindtextdomain ("gpump", "./locale/"); //FIXME
29
 
    Gettext.textdomain ("gpump");
30
 
    GLib.set_prgname ("gpump");
31
 
    
32
22
    this.parent ({
33
23
      application_id: "org.gego.gpump",
34
24
      flags: Gio.ApplicationFlags.FLAGS_NONE,
35
 
      register_session: true,
 
25
      register_session: true
36
26
    });
37
 
    GLib.set_application_name (_("GPump"));
 
27
   GLib.set_application_name (_("GPump"));
38
28
    
 
29
    this.settings = SettingsData.get_settings ();
39
30
  },
40
31
  
41
32
  vfunc_activate: function () {
46
37
      return;
47
38
    }
48
39
    
49
 
    this._prepare_window ();
50
 
    this._prepare_app_menu ();
51
 
    this._prepare_header_bar ();
52
 
    
53
 
    /* Style.load_css (); */
 
40
    this._prepareWindow ();
 
41
    this._prepareAppMenu ();
 
42
    this._prepareHeaderBar ();
54
43
    
55
44
    this.window.show_all ();
56
45
  },
59
48
   * This function is used to prepare the window, it also initializes and adds
60
49
   * the headerbar to it.
61
50
   */
62
 
  _prepare_window: function () {
 
51
  _prepareWindow: function () {
63
52
    this.window = new Gtk.ApplicationWindow ({
64
53
      application: this,
65
54
      type: Gtk.WindowType.TOPLEVEL,
66
55
      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,
 
56
      default_height: 500,
 
57
      default_width: 500,
69
58
      height_request: 500,
70
59
      width_request: 500,
71
60
      window_position: Gtk.WindowPosition.CENTER
73
62
    
74
63
    this.window.set_titlebar ((this.headerbar = new Gtk.HeaderBar({
75
64
      title: GLib.get_application_name (),
76
 
      subtitle: _("A Pump.io client"),
 
65
      subtitle: _('A Pump.io client'),
77
66
      show_close_button: true
78
67
    })));
79
68
    
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);
84
 
    }
85
 
    
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;
89
 
      } else {
90
 
        gtk_settings["gtk_application_prefer_dark_theme"] = false;
91
 
      }
92
 
    
93
69
    print ("derp!\n");
94
70
    
95
71
    this.window.add (( this.scroll_view = new Gtk.ScrolledWindow () ));
105
81
  /**
106
82
   * This function is used to create the application menu.
107
83
   */
108
 
  _prepare_app_menu: function () {
 
84
  _prepareAppMenu: function () {
109
85
    let menu = new Gio.Menu ();
110
86
    let section = new Gio.Menu ();
111
87
    
112
 
    section.append (_("Preferences"), "app.preferences");
 
88
    section.append ("Preferences", "app.preferences");
113
89
    menu.append_section (null, section);
114
90
    
115
91
    section = new Gio.Menu ();
119
95
    
120
96
    this.set_app_menu (menu);
121
97
    
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,
126
 
        modal: true,
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});
131
 
      
132
 
      about_dialog.authors =
133
 
                          ["Gustav Hartvigsson <gustav.hartvigsson@gmail.com>"];
134
 
      about_dialog.connect ("response", function () {
135
 
        about_dialog.destroy ();
136
 
      });
137
 
      about_dialog.run ();
138
 
    }));
139
 
    this.add_action (about_action);
140
 
    
141
98
    let quit_action = new Gio.SimpleAction ({name: "quit"});
142
99
    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 ();
151
100
      this.quit ();
152
101
    }));
153
102
    this.add_action (quit_action);
154
103
    
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);
159
 
      pref_dialog.run ();
160
 
    }));
161
 
    this.add_action (preferences_action);
162
104
  },
163
105
  
164
106
  /**
165
107
   * This function is used to prepare the hearderbar by adding buttons and
166
108
   * assigning callback functions to them.
167
109
   */
168
 
  _prepare_header_bar: function () {
 
110
  _prepareHeaderBar: function () {
169
111
    this.headerbar.pack_start ((this.new_post_btn = new Gtk.Button ({
170
112
      image: (new Gtk.Image ({icon_name: 'text-editor-symbolic'})),
171
 
      tooltip_text: _("Create new post")
 
113
      tooltip_text: _('Create new post')
172
114
    })));
173
115
    
174
116
    this.headerbar.pack_start ((this.refresh_btn = new Gtk.Button({
175
117
      image: (new Gtk.Image ({icon_name: 'emblem-synchronizing-symbolic'})),
176
 
      tooltip_text: _("Refresh the stream")
 
118
      tooltip_text: _('Refresh the stream')
177
119
    })));
178
120
    
179
121
    this.headerbar.pack_end ((this.user_menu_btn = new Gtk.Button ({
180
122
      image: (new Gtk.Image ({icon_name: 'emblem-system-symbolic'})),
181
 
      tooltip_text: _("Switch and manage users")
 
123
      tooltip_text: _('Switch and manage users')
182
124
    })));
183
125
  }
184
126