1
/* This file is part of GPump, a Pump.io client.
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.
9
* UserButton is a custom button that displays the users avatar and name.
12
const GObject = imports.gi.GObject;
13
const Gtk = imports.gi.Gtk;
14
const Lang = imports.lang;
16
const UserButton = Lang.Class ({
18
Extends: Gtk.MenuButton,
20
/** @property user_avatar
23
"user_avatar": GObject.param_spec_object ("user_avatar",
25
"A Gtk.Image that is shown in the button",
27
GObject.ParamFlags.READABLE |
28
GObject.ParamFlags.WRITABLE),
30
/** @property user_name
33
"user_name": GObject.param_spec_string ("user_name",
35
"The text to be shown on the button",
37
GObject.ParamFlags.READABLE |
38
GObject.ParamFlags.WRITABLE),
40
/** @property show_avatar_only
43
"show_avatar_only": GObject.param_spec_boolean ("show_avatar_only",
45
"When set, only the avatar will be shown" +
48
GObject.ParamFlags.READABLE |
49
GObject.ParamFlags.WRITABLE)
53
_init: function (params) {
56
this.add (this.layout = new Gtk.Box ({
57
orientation: Gtk.Orientation.HORIZONTAL
61
if (params != undefined) {
63
if (params["user_avatar"] != undefined) {
64
this.user_avatar = params["user_avatar"];
66
this._user_avatar = Gtk.Image.new_from_icon_name (
67
"avatar-default-symbolic", null);
70
if (params["user_name"] != undefined) {
71
this._user_name = params["user_name"];
73
this._user_name = "Jone Deo";
76
if (params["show_avatar_only"] != undefined) {
77
this._show_avatar_only = params["show_avatar_only"];
79
this._show_avatar_only = false;
82
if (params["popover"] != undefined) {
83
this["popover"] = params["popover"];
87
this._user_avatar = Gtk.Image.new_from_icon_name (
88
"avatar-default-symbolic", null);
89
this._user_name = "Jone Deo";
90
this._show_avatar_only = false;
91
this["popover"] = null;
98
* Hack to re-build the button, cus we can not use references in JavaScript.
100
_rebuild: function () {
104
this.layout.foreach (function (widget) {
108
this.layout.pack_start (this._user_avatar, false, false, 3);
110
this.user_avatar["icon_size"] = 5;
113
if (this._show_avatar_only == false) {
114
this.layout.pack_start (new Gtk.Separator ({
115
orientation: Gtk.Orientation.VERTICAL
116
}), false, false, 5);
119
this.layout.pack_end (
120
this._user_name_widget = new Gtk.Label ({
121
label: this._user_name,
122
justify: Gtk.Justification.CENTER
130
return this._user_avatar;
133
set user_avatar (avatar) {
134
if (avatar == undefined) {
136
this._user_avatar = Gtk.Image.new_from_icon_name (
137
"avatar-default-symbolic", null);
139
print ("Not balls!");
140
this._user_avatar = avatar;
146
return this._user_name;
149
set user_name (name) {
150
this._user_name = name;
154
get show_avatar_only () {
155
return _show_avatar_only;
158
set show_avatar_only (show_avatar_only) {
159
this._show_avatar_only = show_avatar_only;