/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:
6
6
 */
7
7
 
8
8
const Gio = imports.gi.Gio;
9
 
const Gst = imports.gi.Gst;
10
9
const GLib = imports.gi.GLib;
11
10
const Gtk = imports.gi.Gtk;
12
11
const Lang = imports.lang;
 
12
const _ = imports.gettext.gettext;
 
13
 
13
14
 
14
15
const SettingsData = imports.settings_data;
15
16
 
16
17
const Application = new Lang.Class ({
17
18
  Name: "Application",
 
19
  Extends: Gtk.Application,
18
20
  
19
21
  _init: function () {
20
 
    this.application = new Gtk.Application ({
 
22
    this.parent ({
21
23
      application_id: "org.gego.gpump",
22
24
      flags: Gio.ApplicationFlags.FLAGS_NONE,
23
25
      register_session: true
24
26
    });
25
 
    this.application.connect('activate', Lang.bind(this, this._on_activate));
 
27
   GLib.set_application_name (_("GPump"));
 
28
    
 
29
    this.settings = SettingsData.get_settings ();
26
30
  },
27
31
  
28
 
  _on_activate: function () {
 
32
  vfunc_activate: function () {
29
33
    /* Guarantee that only one window is present at any time. */
30
 
    let w_list = this.application.get_windows ();
 
34
    let w_list = this.get_windows ();
31
35
    if (w_list.length) {
32
36
      w_list[0].present ();
33
37
      return;
34
38
    }
35
39
    
36
 
    this._prepareWindow ();
37
 
    this._prepareAppMenu ();
38
 
    this._prepareHeaderBar ();
 
40
    this._prepare_window ();
 
41
    this._prepare_app_menu ();
 
42
    this._prepare_header_bar ();
39
43
    
40
44
    this.window.show_all ();
41
45
  },
44
48
   * This function is used to prepare the window, it also initializes and adds
45
49
   * the headerbar to it.
46
50
   */
47
 
  _prepareWindow: function () {
48
 
    this.window = new Gtk.Window ({
 
51
  _prepare_window: function () {
 
52
    this.window = new Gtk.ApplicationWindow ({
 
53
      application: this,
49
54
      type: Gtk.WindowType.TOPLEVEL,
50
 
      title: 'GPump',
 
55
      title: GLib.get_application_name (),
51
56
      default_height: 500,
52
57
      default_width: 500,
53
58
      height_request: 500,
54
 
      width_request: 500
 
59
      width_request: 500,
 
60
      window_position: Gtk.WindowPosition.CENTER
55
61
    });
56
62
    
57
63
    this.window.set_titlebar ((this.headerbar = new Gtk.HeaderBar({
58
 
      title: 'GPump',
59
 
      subtitle: 'A Pump.io client',
 
64
      title: GLib.get_application_name (),
 
65
      subtitle: _('A Pump.io client'),
60
66
      show_close_button: true
61
67
    })));
62
68
    
 
69
    print ("derp!\n");
 
70
    
63
71
    this.window.add (( this.scroll_view = new Gtk.ScrolledWindow () ));
64
72
    this.scroll_view.add ((this.list_box = new Gtk.ListBox ()));
65
73
    
67
75
                         Lang.bind (this.window,
68
76
                                    this.window.hide_on_delete));
69
77
    
70
 
    this.application.add_window (this.window);
 
78
    this.add_window (this.window);
71
79
  },
72
80
  
73
81
  /**
74
82
   * This function is used to create the application menu.
75
83
   */
76
 
  _prepareAppMenu: function () {
 
84
  _prepare_app_menu: function () {
77
85
    let menu = new Gio.Menu ();
78
86
    let section = new Gio.Menu ();
79
87
    
81
89
    menu.append_section (null, section);
82
90
    
83
91
    section = new Gio.Menu ();
84
 
    section.append ("About", "app.about");
85
 
    section.append ("Quit", "app.quit");
 
92
    section.append (_("About"), "app.about");
 
93
    section.append (_("Quit"), "app.quit");
86
94
    menu.append_section (null, section);
87
95
    
88
 
    this.application.set_app_menu (menu);
 
96
    this.set_app_menu (menu);
89
97
    
90
98
    let quit_action = new Gio.SimpleAction ({name: "quit"});
91
99
    quit_action.connect ('activate', Lang.bind (this, function () {
92
 
      this.application.quit ();
 
100
      this.quit ();
93
101
    }));
94
 
    this.application.add_action (quit_action);
 
102
    this.add_action (quit_action);
95
103
    
96
104
  },
97
105
  
99
107
   * This function is used to prepare the hearderbar by adding buttons and
100
108
   * assigning callback functions to them.
101
109
   */
102
 
  _prepareHeaderBar: function () {
 
110
  _prepare_header_bar: function () {
103
111
    this.headerbar.pack_start ((this.new_post_btn = new Gtk.Button ({
104
112
      image: (new Gtk.Image ({icon_name: 'text-editor-symbolic'})),
105
 
      tooltip_text: 'Create new post'
 
113
      tooltip_text: _('Create new post')
106
114
    })));
107
115
    
108
116
    this.headerbar.pack_start ((this.refresh_btn = new Gtk.Button({
109
117
      image: (new Gtk.Image ({icon_name: 'emblem-synchronizing-symbolic'})),
110
 
      tooltip_text: 'Refresh the stream'
 
118
      tooltip_text: _('Refresh the stream')
111
119
    })));
112
120
    
113
121
    this.headerbar.pack_end ((this.user_menu_btn = new Gtk.Button ({
114
122
      image: (new Gtk.Image ({icon_name: 'emblem-system-symbolic'})),
115
 
      tooltip_text: 'Switch and manage users'
 
123
      tooltip_text: _('Switch and manage users')
116
124
    })));
117
125
  }
118
126