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