/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-11-18 20:53:37 UTC
  • mto: This revision was merged to the branch mainline in revision 53.
  • Revision ID: gustav.hartvigsson@gmail.com-20141118205337-j6opehfighclrkqc
* added 'make gettext' for generating gettext information
* updated 'messages.po' to fit the resent changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
9
const Gettext = imports.gettext;
 
10
const Gio = imports.gi.Gio;
 
11
const GLib = imports.gi.GLib;
 
12
const GObject = imports.gi.GObject;
 
13
const Gtk = imports.gi.Gtk;
 
14
const _ = imports.gettext.gettext;
 
15
const Lang = imports.lang;
 
16
 
 
17
const SettingsData = imports.settings_data;
 
18
/* const Style = imports.style; */
 
19
const PreferencesUI = imports.preferences_ui;
 
20
const UserMenu = imports.user_menu;
 
21
 
 
22
const Application = new Lang.Class ({
 
23
  Name: "Application",
 
24
  Extends: Gtk.Application,
 
25
  
 
26
  _init: function () {
 
27
    this.settings = SettingsData.get_settings ();
 
28
    
 
29
    Gettext.bindtextdomain ("gpump", "./locale/"); //FIXME
 
30
    Gettext.textdomain ("gpump");
 
31
    GLib.set_prgname ("gpump");
 
32
    
 
33
    this.parent ({
 
34
      application_id: "org.gego.gpump",
 
35
      flags: Gio.ApplicationFlags.FLAGS_NONE,
 
36
      register_session: true,
 
37
    });
 
38
    GLib.set_application_name (_("GPump"));
 
39
    
 
40
  },
 
41
  
 
42
  vfunc_activate: function () {
 
43
    /* Guarantee that only one window is present at any time. */
 
44
    let w_list = this.get_windows ();
 
45
    if (w_list.length) {
 
46
      w_list[0].present ();
 
47
      return;
 
48
    }
 
49
    
 
50
    this._prepare_window ();
 
51
    this._prepare_app_menu ();
 
52
    this._prepare_header_bar ();
 
53
    
 
54
    /* Style.load_css (); */
 
55
    
 
56
    this.window.show_all ();
 
57
  },
 
58
  
 
59
  /**
 
60
   * This function is used to prepare the window, it also initializes and adds
 
61
   * the headerbar to it.
 
62
   */
 
63
  _prepare_window: function () {
 
64
    this.window = new Gtk.ApplicationWindow ({
 
65
      application: this,
 
66
      type: Gtk.WindowType.TOPLEVEL,
 
67
      title: GLib.get_application_name (),
 
68
      default_height: this.settings.get_setting ("ui.h").data,
 
69
      default_width: this.settings.get_setting ("ui.w").data,
 
70
      height_request: 500,
 
71
      width_request: 500,
 
72
      window_position: Gtk.WindowPosition.CENTER
 
73
    });
 
74
    
 
75
    this.window.set_titlebar ((this.headerbar = new Gtk.HeaderBar({
 
76
      title: GLib.get_application_name (),
 
77
      subtitle: _("A Pump.io client"),
 
78
      show_close_button: true
 
79
    })));
 
80
    
 
81
    if (!(this.settings.get_setting ("ui.x").data < 0 &&
 
82
        this.settings.get_setting ("ui.y").data < 0)){
 
83
      this.window.move (this.settings.get_setting ("ui.x").data,
 
84
                                       this.settings.get_setting ("ui.y").data);
 
85
    }
 
86
    
 
87
    var gtk_settings = Gtk.Settings.get_default ();
 
88
      if ( this.settings.get_setting ("main.use_dark").data ) {
 
89
        gtk_settings["gtk_application_prefer_dark_theme"] = true;
 
90
      } else {
 
91
        gtk_settings["gtk_application_prefer_dark_theme"] = false;
 
92
      }
 
93
    
 
94
    print ("derp!\n");
 
95
    
 
96
    this.window.add (( this.scroll_view = new Gtk.ScrolledWindow () ));
 
97
    this.scroll_view.add ((this.list_box = new Gtk.ListBox ()));
 
98
    
 
99
    this.window.connect ('delete_event',
 
100
                         Lang.bind (this.window,
 
101
                                    this.window.hide_on_delete));
 
102
    
 
103
    this.add_window (this.window);
 
104
  },
 
105
  
 
106
  /**
 
107
   * This function is used to create the application menu.
 
108
   */
 
109
  _prepare_app_menu: function () {
 
110
    let menu = new Gio.Menu ();
 
111
    let section = new Gio.Menu ();
 
112
    
 
113
    section.append (_("Preferences"), "app.preferences");
 
114
    menu.append_section (null, section);
 
115
    
 
116
    section = new Gio.Menu ();
 
117
    section.append (_("About"), "app.about");
 
118
    section.append (_("Quit"), "app.quit");
 
119
    menu.append_section (null, section);
 
120
    
 
121
    this.set_app_menu (menu);
 
122
    
 
123
    let about_action = new Gio.SimpleAction ({name: "about"});
 
124
    about_action.connect ('activate', Lang.bind (this, function () {
 
125
      let about_dialog = new Gtk.AboutDialog ({use_header_bar: true,
 
126
        transient_for: this.window,
 
127
        modal: true,
 
128
        version: "pre-alpha ~BZR~",
 
129
        program_name: GLib.get_application_name (),
 
130
        copyright: "Gustav \'Gego/XAREN\' Hartvigsson, 2014",
 
131
        license_type: Gtk.License.LGPL_3_0});
 
132
      
 
133
      about_dialog.authors =
 
134
                          ["Gustav Hartvigsson <gustav.hartvigsson@gmail.com>"];
 
135
      about_dialog.connect ("response", function () {
 
136
        about_dialog.destroy ();
 
137
      });
 
138
      about_dialog.run ();
 
139
    }));
 
140
    this.add_action (about_action);
 
141
    
 
142
    let quit_action = new Gio.SimpleAction ({name: "quit"});
 
143
    quit_action.connect ('activate', Lang.bind (this, function () {
 
144
      let allocation = this.window.get_allocation ();
 
145
      this.settings.set_setting ("ui.h", allocation.height);
 
146
      this.settings.set_setting ("ui.w", allocation.width);
 
147
      
 
148
      let win_pos = this.window.get_position ();
 
149
      this.settings.set_setting ("ui.x", win_pos[0]);
 
150
      this.settings.set_setting ("ui.y", win_pos[1]);
 
151
      this.settings.commit_to_file ();
 
152
      this.quit ();
 
153
    }));
 
154
    this.add_action (quit_action);
 
155
    
 
156
    let preferences_action = new Gio.SimpleAction ({name: "preferences"});
 
157
    preferences_action.connect ('activate', Lang.bind (this, function (){
 
158
      let pref_dialog = new PreferencesUI.PreferencesUI ();
 
159
      pref_dialog.set_transient_for (this.window);
 
160
      pref_dialog.run ();
 
161
    }));
 
162
    this.add_action (preferences_action);
 
163
  },
 
164
  
 
165
  /**
 
166
   * This function is used to prepare the hearderbar by adding buttons and
 
167
   * assigning callback functions to them.
 
168
   */
 
169
  _prepare_header_bar: function () {
 
170
    this.headerbar.pack_start ((this.new_post_btn = new Gtk.Button ({
 
171
      image: (new Gtk.Image ({icon_name: 'text-editor-symbolic'})),
 
172
      tooltip_text: _("Create new post")
 
173
    })));
 
174
    
 
175
    this.headerbar.pack_start ((this.refresh_btn = new Gtk.Button({
 
176
      image: (new Gtk.Image ({icon_name: 'emblem-synchronizing-symbolic'})),
 
177
      tooltip_text: _("Refresh the stream")
 
178
    })));
 
179
    
 
180
    this.headerbar.pack_end ((this.user_menu_btn = new Gtk.MenuButton ({
 
181
      image: (new Gtk.Image ({icon_name: 'emblem-system-symbolic'})),
 
182
      tooltip_text: _("Switch and manage users"),
 
183
      popover: (this.user_menu = new UserMenu.UserMenu ()),
 
184
    })));
 
185
    
 
186
  }
 
187
  
 
188
});