/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-08-03 21:09:38 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20140803210938-jfhdl23v4mzji6pf
* Added translation files (messeges.po and sv.po)
* fixed a few gettext errors in app.js
* TODO:
  * Make the translations not be as "fixed" as they are now.
  * Add auto update/compile for the translations to makefile.

  * Switch to a better build system?

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