/gpump/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/gpump/trunk
33 by Gustav Hartvigsson
* Main window no on par with the C version
1
/* This file is part of GPump, a Pump.io client.
2
 *
3
 * GPump (THE SOFTWARE) is made available under the terms and conditions of the
4
 * GNU Lesser General Public Licence 3.0. A copy of the licence can be read
5
 * in the file lgpl-3.0.txt in the root of this project.
6
 */
7
8
const Gio = imports.gi.Gio;
9
const GLib = imports.gi.GLib;
10
const Gtk = imports.gi.Gtk;
11
const Lang = imports.lang;
34 by Gustav Hartvigsson
* added GetText stuffs...
12
const _ = imports.gettext.gettext;
13
33 by Gustav Hartvigsson
* Main window no on par with the C version
14
15
const SettingsData = imports.settings_data;
16
17
const Application = new Lang.Class ({
18
  Name: "Application",
35 by Gustav Hartvigsson
* Changed to extending Gtk.Application instead....
19
  Extends: Gtk.Application,
33 by Gustav Hartvigsson
* Main window no on par with the C version
20
  
21
  _init: function () {
35 by Gustav Hartvigsson
* Changed to extending Gtk.Application instead....
22
    this.parent ({
33 by Gustav Hartvigsson
* Main window no on par with the C version
23
      application_id: "org.gego.gpump",
24
      flags: Gio.ApplicationFlags.FLAGS_NONE,
25
      register_session: true
26
    });
27
  },
28
  
36 by Gustav Hartvigsson
* changed from this.connect(...) to vfunc_ .
29
  vfunc_activate: function () {
33 by Gustav Hartvigsson
* Main window no on par with the C version
30
    /* Guarantee that only one window is present at any time. */
35 by Gustav Hartvigsson
* Changed to extending Gtk.Application instead....
31
    let w_list = this.get_windows ();
33 by Gustav Hartvigsson
* Main window no on par with the C version
32
    if (w_list.length) {
33
      w_list[0].present ();
34
      return;
35
    }
36
    
37
    this._prepareWindow ();
38
    this._prepareAppMenu ();
39
    this._prepareHeaderBar ();
40
    
41
    this.window.show_all ();
42
  },
43
  
44
  /**
45
   * This function is used to prepare the window, it also initializes and adds
46
   * the headerbar to it.
47
   */
48
  _prepareWindow: function () {
49
    this.window = new Gtk.Window ({
50
      type: Gtk.WindowType.TOPLEVEL,
51
      title: 'GPump',
52
      default_height: 500,
53
      default_width: 500,
54
      height_request: 500,
55
      width_request: 500
56
    });
57
    
58
    this.window.set_titlebar ((this.headerbar = new Gtk.HeaderBar({
59
      title: 'GPump',
34 by Gustav Hartvigsson
* added GetText stuffs...
60
      subtitle: _('A Pump.io client'),
33 by Gustav Hartvigsson
* Main window no on par with the C version
61
      show_close_button: true
62
    })));
63
    
64
    this.window.add (( this.scroll_view = new Gtk.ScrolledWindow () ));
65
    this.scroll_view.add ((this.list_box = new Gtk.ListBox ()));
66
    
67
    this.window.connect ('delete_event',
68
                         Lang.bind (this.window,
69
                                    this.window.hide_on_delete));
70
    
35 by Gustav Hartvigsson
* Changed to extending Gtk.Application instead....
71
    this.add_window (this.window);
33 by Gustav Hartvigsson
* Main window no on par with the C version
72
  },
73
  
74
  /**
75
   * This function is used to create the application menu.
76
   */
77
  _prepareAppMenu: function () {
78
    let menu = new Gio.Menu ();
79
    let section = new Gio.Menu ();
80
    
81
    section.append ("Preferences", "app.preferences");
82
    menu.append_section (null, section);
83
    
84
    section = new Gio.Menu ();
34 by Gustav Hartvigsson
* added GetText stuffs...
85
    section.append (_("About"), "app.about");
86
    section.append (_("Quit"), "app.quit");
33 by Gustav Hartvigsson
* Main window no on par with the C version
87
    menu.append_section (null, section);
88
    
35 by Gustav Hartvigsson
* Changed to extending Gtk.Application instead....
89
    this.set_app_menu (menu);
33 by Gustav Hartvigsson
* Main window no on par with the C version
90
    
91
    let quit_action = new Gio.SimpleAction ({name: "quit"});
92
    quit_action.connect ('activate', Lang.bind (this, function () {
35 by Gustav Hartvigsson
* Changed to extending Gtk.Application instead....
93
      this.quit ();
33 by Gustav Hartvigsson
* Main window no on par with the C version
94
    }));
35 by Gustav Hartvigsson
* Changed to extending Gtk.Application instead....
95
    this.add_action (quit_action);
33 by Gustav Hartvigsson
* Main window no on par with the C version
96
    
97
  },
98
  
99
  /**
100
   * This function is used to prepare the hearderbar by adding buttons and
101
   * assigning callback functions to them.
102
   */
103
  _prepareHeaderBar: function () {
104
    this.headerbar.pack_start ((this.new_post_btn = new Gtk.Button ({
105
      image: (new Gtk.Image ({icon_name: 'text-editor-symbolic'})),
34 by Gustav Hartvigsson
* added GetText stuffs...
106
      tooltip_text: _('Create new post')
33 by Gustav Hartvigsson
* Main window no on par with the C version
107
    })));
108
    
109
    this.headerbar.pack_start ((this.refresh_btn = new Gtk.Button({
110
      image: (new Gtk.Image ({icon_name: 'emblem-synchronizing-symbolic'})),
34 by Gustav Hartvigsson
* added GetText stuffs...
111
      tooltip_text: _('Refresh the stream')
33 by Gustav Hartvigsson
* Main window no on par with the C version
112
    })));
113
    
114
    this.headerbar.pack_end ((this.user_menu_btn = new Gtk.Button ({
115
      image: (new Gtk.Image ({icon_name: 'emblem-system-symbolic'})),
34 by Gustav Hartvigsson
* added GetText stuffs...
116
      tooltip_text: _('Switch and manage users')
33 by Gustav Hartvigsson
* Main window no on par with the C version
117
    })));
118
  }
119
  
120
});