/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 19:59:24 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20140803195924-jlfiz34c0a7as52i
* woops

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