/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
52.1.1 by Gustav Hartvigsson
Button still not worknig, saving for prosparitny
8
9
const Gettext = imports.gettext;
33 by Gustav Hartvigsson
* Main window no on par with the C version
10
const Gio = imports.gi.Gio;
11
const GLib = imports.gi.GLib;
46 by Gustav Hartvigsson
* Now saves the Height, Width, X and Y of the window on quit.
12
const GObject = imports.gi.GObject;
33 by Gustav Hartvigsson
* Main window no on par with the C version
13
const Gtk = imports.gi.Gtk;
52.1.1 by Gustav Hartvigsson
Button still not worknig, saving for prosparitny
14
const _ = imports.gettext.gettext;
33 by Gustav Hartvigsson
* Main window no on par with the C version
15
const Lang = imports.lang;
16
17
const SettingsData = imports.settings_data;
49 by Gustav Hartvigsson
* Changes a thing in the about dialoug.
18
/* const Style = imports.style; */
44 by Gustav Hartvigsson
* UI for preferences done, it is still not functional.
19
const PreferencesUI = imports.preferences_ui;
52.1.2 by Gustav Hartvigsson
* Fixed a few style errors...
20
const UserMenu = imports.user_menu;
33 by Gustav Hartvigsson
* Main window no on par with the C version
21
22
const Application = new Lang.Class ({
23
  Name: "Application",
35 by Gustav Hartvigsson
* Changed to extending Gtk.Application instead....
24
  Extends: Gtk.Application,
33 by Gustav Hartvigsson
* Main window no on par with the C version
25
  
26
  _init: function () {
46 by Gustav Hartvigsson
* Now saves the Height, Width, X and Y of the window on quit.
27
    this.settings = SettingsData.get_settings ();
28
    
52 by Gustav Hartvigsson
* Added translation files (messeges.po and sv.po)
29
    Gettext.bindtextdomain ("gpump", "./locale/"); //FIXME
30
    Gettext.textdomain ("gpump");
31
    GLib.set_prgname ("gpump");
32
    
35 by Gustav Hartvigsson
* Changed to extending Gtk.Application instead....
33
    this.parent ({
33 by Gustav Hartvigsson
* Main window no on par with the C version
34
      application_id: "org.gego.gpump",
35
      flags: Gio.ApplicationFlags.FLAGS_NONE,
46 by Gustav Hartvigsson
* Now saves the Height, Width, X and Y of the window on quit.
36
      register_session: true,
33 by Gustav Hartvigsson
* Main window no on par with the C version
37
    });
51 by Gustav Hartvigsson
* woops
38
    GLib.set_application_name (_("GPump"));
37 by Gustav Hartvigsson
* finnihed the construction of the settings file.
39
    
33 by Gustav Hartvigsson
* Main window no on par with the C version
40
  },
41
  
36 by Gustav Hartvigsson
* changed from this.connect(...) to vfunc_ .
42
  vfunc_activate: function () {
33 by Gustav Hartvigsson
* Main window no on par with the C version
43
    /* Guarantee that only one window is present at any time. */
35 by Gustav Hartvigsson
* Changed to extending Gtk.Application instead....
44
    let w_list = this.get_windows ();
33 by Gustav Hartvigsson
* Main window no on par with the C version
45
    if (w_list.length) {
46
      w_list[0].present ();
47
      return;
48
    }
49
    
43 by Gustav Hartvigsson
* made the functions look more alike...
50
    this._prepare_window ();
51
    this._prepare_app_menu ();
52
    this._prepare_header_bar ();
33 by Gustav Hartvigsson
* Main window no on par with the C version
53
    
49 by Gustav Hartvigsson
* Changes a thing in the about dialoug.
54
    /* Style.load_css (); */
46 by Gustav Hartvigsson
* Now saves the Height, Width, X and Y of the window on quit.
55
    
33 by Gustav Hartvigsson
* Main window no on par with the C version
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
   */
43 by Gustav Hartvigsson
* made the functions look more alike...
63
  _prepare_window: function () {
38 by Gustav Hartvigsson
* Can now load settings from file.
64
    this.window = new Gtk.ApplicationWindow ({
65
      application: this,
33 by Gustav Hartvigsson
* Main window no on par with the C version
66
      type: Gtk.WindowType.TOPLEVEL,
38 by Gustav Hartvigsson
* Can now load settings from file.
67
      title: GLib.get_application_name (),
46 by Gustav Hartvigsson
* Now saves the Height, Width, X and Y of the window on quit.
68
      default_height: this.settings.get_setting ("ui.h").data,
69
      default_width: this.settings.get_setting ("ui.w").data,
33 by Gustav Hartvigsson
* Main window no on par with the C version
70
      height_request: 500,
38 by Gustav Hartvigsson
* Can now load settings from file.
71
      width_request: 500,
72
      window_position: Gtk.WindowPosition.CENTER
33 by Gustav Hartvigsson
* Main window no on par with the C version
73
    });
74
    
75
    this.window.set_titlebar ((this.headerbar = new Gtk.HeaderBar({
38 by Gustav Hartvigsson
* Can now load settings from file.
76
      title: GLib.get_application_name (),
52 by Gustav Hartvigsson
* Added translation files (messeges.po and sv.po)
77
      subtitle: _("A Pump.io client"),
33 by Gustav Hartvigsson
* Main window no on par with the C version
78
      show_close_button: true
79
    })));
80
    
46 by Gustav Hartvigsson
* Now saves the Height, Width, X and Y of the window on quit.
81
    if (!(this.settings.get_setting ("ui.x").data < 0 &&
82
        this.settings.get_setting ("ui.y").data < 0)){
50 by Gustav Hartvigsson
* bound the GtkSwitch for "use dark theme"
83
      this.window.move (this.settings.get_setting ("ui.x").data,
84
                                       this.settings.get_setting ("ui.y").data);
46 by Gustav Hartvigsson
* Now saves the Height, Width, X and Y of the window on quit.
85
    }
86
    
50 by Gustav Hartvigsson
* bound the GtkSwitch for "use dark theme"
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
    
38 by Gustav Hartvigsson
* Can now load settings from file.
94
    print ("derp!\n");
95
    
33 by Gustav Hartvigsson
* Main window no on par with the C version
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
    
35 by Gustav Hartvigsson
* Changed to extending Gtk.Application instead....
103
    this.add_window (this.window);
33 by Gustav Hartvigsson
* Main window no on par with the C version
104
  },
105
  
106
  /**
107
   * This function is used to create the application menu.
108
   */
43 by Gustav Hartvigsson
* made the functions look more alike...
109
  _prepare_app_menu: function () {
33 by Gustav Hartvigsson
* Main window no on par with the C version
110
    let menu = new Gio.Menu ();
111
    let section = new Gio.Menu ();
112
    
52 by Gustav Hartvigsson
* Added translation files (messeges.po and sv.po)
113
    section.append (_("Preferences"), "app.preferences");
33 by Gustav Hartvigsson
* Main window no on par with the C version
114
    menu.append_section (null, section);
115
    
116
    section = new Gio.Menu ();
34 by Gustav Hartvigsson
* added GetText stuffs...
117
    section.append (_("About"), "app.about");
118
    section.append (_("Quit"), "app.quit");
33 by Gustav Hartvigsson
* Main window no on par with the C version
119
    menu.append_section (null, section);
120
    
35 by Gustav Hartvigsson
* Changed to extending Gtk.Application instead....
121
    this.set_app_menu (menu);
33 by Gustav Hartvigsson
* Main window no on par with the C version
122
    
47 by Gustav Hartvigsson
* Fixed the preferences dialoug. For some reasons
123
    let about_action = new Gio.SimpleAction ({name: "about"});
49 by Gustav Hartvigsson
* Changes a thing in the about dialoug.
124
    about_action.connect ('activate', Lang.bind (this, function () {
47 by Gustav Hartvigsson
* Fixed the preferences dialoug. For some reasons
125
      let about_dialog = new Gtk.AboutDialog ({use_header_bar: true,
50 by Gustav Hartvigsson
* bound the GtkSwitch for "use dark theme"
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});
48 by Gustav Hartvigsson
* added moar random information to the about dialoug.
132
      
50 by Gustav Hartvigsson
* bound the GtkSwitch for "use dark theme"
133
      about_dialog.authors =
134
                          ["Gustav Hartvigsson <gustav.hartvigsson@gmail.com>"];
47 by Gustav Hartvigsson
* Fixed the preferences dialoug. For some reasons
135
      about_dialog.connect ("response", function () {
136
        about_dialog.destroy ();
137
      });
138
      about_dialog.run ();
50 by Gustav Hartvigsson
* bound the GtkSwitch for "use dark theme"
139
    }));
47 by Gustav Hartvigsson
* Fixed the preferences dialoug. For some reasons
140
    this.add_action (about_action);
141
    
33 by Gustav Hartvigsson
* Main window no on par with the C version
142
    let quit_action = new Gio.SimpleAction ({name: "quit"});
143
    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.
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 ();
35 by Gustav Hartvigsson
* Changed to extending Gtk.Application instead....
152
      this.quit ();
33 by Gustav Hartvigsson
* Main window no on par with the C version
153
    }));
35 by Gustav Hartvigsson
* Changed to extending Gtk.Application instead....
154
    this.add_action (quit_action);
33 by Gustav Hartvigsson
* Main window no on par with the C version
155
    
44 by Gustav Hartvigsson
* UI for preferences done, it is still not functional.
156
    let preferences_action = new Gio.SimpleAction ({name: "preferences"});
157
    preferences_action.connect ('activate', Lang.bind (this, function (){
47 by Gustav Hartvigsson
* Fixed the preferences dialoug. For some reasons
158
      let pref_dialog = new PreferencesUI.PreferencesUI ();
159
      pref_dialog.set_transient_for (this.window);
44 by Gustav Hartvigsson
* UI for preferences done, it is still not functional.
160
      pref_dialog.run ();
161
    }));
50 by Gustav Hartvigsson
* bound the GtkSwitch for "use dark theme"
162
    this.add_action (preferences_action);
33 by Gustav Hartvigsson
* Main window no on par with the C version
163
  },
164
  
165
  /**
166
   * This function is used to prepare the hearderbar by adding buttons and
167
   * assigning callback functions to them.
168
   */
43 by Gustav Hartvigsson
* made the functions look more alike...
169
  _prepare_header_bar: function () {
33 by Gustav Hartvigsson
* Main window no on par with the C version
170
    this.headerbar.pack_start ((this.new_post_btn = new Gtk.Button ({
171
      image: (new Gtk.Image ({icon_name: 'text-editor-symbolic'})),
52 by Gustav Hartvigsson
* Added translation files (messeges.po and sv.po)
172
      tooltip_text: _("Create new post")
33 by Gustav Hartvigsson
* Main window no on par with the C version
173
    })));
174
    
175
    this.headerbar.pack_start ((this.refresh_btn = new Gtk.Button({
176
      image: (new Gtk.Image ({icon_name: 'emblem-synchronizing-symbolic'})),
52 by Gustav Hartvigsson
* Added translation files (messeges.po and sv.po)
177
      tooltip_text: _("Refresh the stream")
33 by Gustav Hartvigsson
* Main window no on par with the C version
178
    })));
179
    
52.1.2 by Gustav Hartvigsson
* Fixed a few style errors...
180
    this.headerbar.pack_end ((this.user_menu_btn = new Gtk.MenuButton ({
33 by Gustav Hartvigsson
* Main window no on par with the C version
181
      image: (new Gtk.Image ({icon_name: 'emblem-system-symbolic'})),
52.1.2 by Gustav Hartvigsson
* Fixed a few style errors...
182
      tooltip_text: _("Switch and manage users"),
183
      popover: (this.user_menu = new UserMenu.UserMenu ()),
33 by Gustav Hartvigsson
* Main window no on par with the C version
184
    })));
52.1.2 by Gustav Hartvigsson
* Fixed a few style errors...
185
    
33 by Gustav Hartvigsson
* Main window no on par with the C version
186
  }
187
  
188
});