1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/* This file is part of GPump, a Pump.io client.
*
* GPump (THE SOFTWARE) is made available under the terms and conditions of the
* GNU Lesser General Public Licence 3.0. A copy of the licence can be read
* in the file lgpl-3.0.txt in the root of this project.
*/
/** @file
* UserButton is a custom button that displays the users avatar and name.
*/
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const UserButton = Lang.Class ({
Name: "UserButton",
Extends: Gtk.MenuButton,
Properties: {
/** @property user_avatar
*
*/
"user_avatar": GObject.param_spec_object ("user_avatar",
"avatar",
"A Gtk.Image that is shown in the button",
GObject.Object,
GObject.ParamFlags.READABLE |
GObject.ParamFlags.WRITABLE),
/** @property user_name
*
*/
"user_name": GObject.param_spec_string ("user_name",
"name",
"The text to be shown on the button",
"Jone Deo",
GObject.ParamFlags.READABLE |
GObject.ParamFlags.WRITABLE),
/** @property show_avatar_only
*
*/
"show_avatar_only": GObject.param_spec_boolean ("show_avatar_only",
"show only avatar",
"When set, only the avatar will be shown" +
"in the user button",
false,
GObject.ParamFlags.READABLE |
GObject.ParamFlags.WRITABLE)
},
_init: function (params) {
this.parent ();
this.add (this.layout = new Gtk.Box ({
orientation: Gtk.Orientation.HORIZONTAL
})
);
if (params != undefined) {
if (params["user_avatar"] != undefined) {
this.user_avatar = params["user_avatar"];
} else {
this._user_avatar = Gtk.Image.new_from_icon_name (
"avatar-default-symbolic", null);
}
if (params["user_name"] != undefined) {
this._user_name = params["user_name"];
} else {
this._user_name = "Jone Deo";
}
if (params["show_avatar_only"] != undefined) {
this._show_avatar_only = params["show_avatar_only"];
} else {
this._show_avatar_only = false;
}
if (params["popover"] != undefined) {
this["popover"] = params["popover"];
}
} else {
this._user_avatar = Gtk.Image.new_from_icon_name (
"avatar-default-symbolic", null);
this._user_name = "Jone Deo";
this._show_avatar_only = false;
this["popover"] = null;
}
this._rebuild ();
},
/**
* Hack to re-build the button, cus we can not use references in JavaScript.
*/
_rebuild: function () {
this.layout.hide ();
this.layout.foreach (function (widget) {
widget.destroy ();
});
this.layout.pack_start (this._user_avatar, false, false, 3);
this.user_avatar["icon_size"] = 4;
if (this._show_avatar_only == false) {
this.layout.pack_start (new Gtk.Separator ({
orientation: Gtk.Orientation.VERTICAL
}), false, false, 5);
this.layout.pack_end (
this._user_name_widget = new Gtk.Label ({
label: this._user_name,
justify: Gtk.Justification.CENTER
}), true, true, 10
);
}
this.show_all ();
},
get user_avatar () {
return this._user_avatar;
},
set user_avatar (avatar) {
if (avatar == undefined) {
print ("balls!");
this._user_avatar = Gtk.Image.new_from_icon_name (
"avatar-default-symbolic", null);
} else {
print ("Not balls!");
this._user_avatar = avatar;
this._rebuild ();
}
},
get user_name () {
return this._user_name;
},
set user_name (name) {
this._user_name = name;
this._rebuild ();
},
get show_avatar_only () {
return _show_avatar_only;
},
set show_avatar_only (show_avatar_only) {
this._show_avatar_only = show_avatar_only;
this._rebuild ()
}
});
|