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