/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
 
 
9
 
const Gettext = imports.gettext;
 
8
const cairo = imports.gi.cairo;
10
9
const Gio = imports.gi.Gio;
11
10
const GLib = imports.gi.GLib;
12
11
const GObject = imports.gi.GObject;
13
12
const Gtk = imports.gi.Gtk;
 
13
const Lang = imports.lang;
14
14
const _ = imports.gettext.gettext;
15
 
const Lang = imports.lang;
 
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;
22
20
 
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
21
const Application = new Lang.Class ({
28
22
  Name: "Application",
29
23
  Extends: Gtk.Application,
49
43
    let w_list = this.get_windows ();
50
44
    if (w_list.length) {
51
45
      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
46
      return;
55
47
    }
56
48
    
68
60
   * the headerbar to it.
69
61
   */
70
62
  _prepare_window: function () {
71
 
    
72
63
    this.window = new Gtk.ApplicationWindow ({
73
64
      application: this,
74
65
      type: Gtk.WindowType.TOPLEVEL,
75
66
      title: GLib.get_application_name (),
76
 
      default_height: 500,
77
 
      default_width: 500,
 
67
      default_height: this.settings.get_setting ("ui.h").data,
 
68
      default_width: this.settings.get_setting ("ui.w").data,
78
69
      height_request: 500,
79
70
      width_request: 500,
80
71
      window_position: Gtk.WindowPosition.CENTER
101
92
    
102
93
    print ("derp!\n");
103
94
    
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 */
 
95
    this.window.add (( this.scroll_view = new Gtk.ScrolledWindow () ));
 
96
    this.scroll_view.add ((this.list_box = new Gtk.ListBox ()));
 
97
    
145
98
    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
 
    }));
 
99
                         Lang.bind (this.window,
 
100
                                    this.window.hide_on_delete));
153
101
    
154
102
    this.add_window (this.window);
155
103
  },
192
140
    
193
141
    let quit_action = new Gio.SimpleAction ({name: "quit"});
194
142
    quit_action.connect ('activate', Lang.bind (this, function () {
195
 
      this._save_settings ();
 
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 ();
196
151
      this.quit ();
197
152
    }));
198
153
    this.add_action (quit_action);
199
154
    
200
155
    let preferences_action = new Gio.SimpleAction ({name: "preferences"});
201
156
    preferences_action.connect ('activate', Lang.bind (this, function (){
202
 
      let pref_dialog = new PreferencesUI.PreferencesUI ({
203
 
        transient_for: this.window
204
 
      });
 
157
      let pref_dialog = new PreferencesUI.PreferencesUI ();
 
158
      pref_dialog.set_transient_for (this.window);
205
159
      pref_dialog.run ();
206
160
    }));
207
161
    this.add_action (preferences_action);
212
166
   * assigning callback functions to them.
213
167
   */
214
168
  _prepare_header_bar: function () {
215
 
    
216
169
    this.headerbar.pack_start ((this.new_post_btn = new Gtk.Button ({
217
170
      image: (new Gtk.Image ({icon_name: 'text-editor-symbolic'})),
218
 
      tooltip_text: _("Create new post"),
 
171
      tooltip_text: _("Create new post")
219
172
    })));
220
173
    
221
 
   this.new_post_btn.get_style_context ().add_class ("image-button");
222
 
    
223
174
    this.headerbar.pack_start ((this.refresh_btn = new Gtk.Button({
224
175
      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 ();
 
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
    })));
247
183
  }
248
184
  
249
185
});