bzr branch
http://gegoxaren.bato24.eu/bzr/gpump/trunk
52.1.1
by Gustav Hartvigsson
Button still not worknig, saving for prosparitny |
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 |
/** @file
|
|
9 |
* UserButton is a custom button that displays the users avatar and name.
|
|
10 |
*/
|
|
11 |
||
12 |
const GObject = imports.gi.GObject; |
|
13 |
const Gtk = imports.gi.Gtk; |
|
14 |
const Lang = imports.lang; |
|
15 |
||
16 |
const UserButton = Lang.Class ({ |
|
17 |
Name: "UserButton", |
|
52.1.11
by Gustav Hartvigsson
* switched the UserButton to be a GtkMenuButton instead of a GtkButton |
18 |
Extends: Gtk.MenuButton, |
52.1.1
by Gustav Hartvigsson
Button still not worknig, saving for prosparitny |
19 |
Properties: { |
52.1.8
by Gustav Hartvigsson
* Strted work on changing how the SettingsData class works, |
20 |
/** @property user_avatar |
21 |
*
|
|
22 |
*/
|
|
52.1.1
by Gustav Hartvigsson
Button still not worknig, saving for prosparitny |
23 |
"user_avatar": GObject.param_spec_object ("user_avatar", |
24 |
"avatar", |
|
25 |
"A Gtk.Image that is shown in the button", |
|
26 |
GObject.Object, |
|
27 |
GObject.ParamFlags.READABLE | |
|
28 |
GObject.ParamFlags.WRITABLE), |
|
29 |
|
|
52.1.8
by Gustav Hartvigsson
* Strted work on changing how the SettingsData class works, |
30 |
/** @property user_name |
31 |
*
|
|
32 |
*/
|
|
52.1.1
by Gustav Hartvigsson
Button still not worknig, saving for prosparitny |
33 |
"user_name": GObject.param_spec_string ("user_name", |
34 |
"name", |
|
35 |
"The text to be shown on the button", |
|
52.1.10
by Gustav Hartvigsson
* made the UserButton work in tests. |
36 |
"Jone Deo", |
52.1.1
by Gustav Hartvigsson
Button still not worknig, saving for prosparitny |
37 |
GObject.ParamFlags.READABLE | |
38 |
GObject.ParamFlags.WRITABLE), |
|
39 |
|
|
52.1.8
by Gustav Hartvigsson
* Strted work on changing how the SettingsData class works, |
40 |
/** @property show_avatar_only |
41 |
*
|
|
42 |
*/
|
|
52.1.1
by Gustav Hartvigsson
Button still not worknig, saving for prosparitny |
43 |
"show_avatar_only": GObject.param_spec_boolean ("show_avatar_only", |
44 |
"show only avatar", |
|
45 |
"When set, only the avatar will be shown" + |
|
46 |
"in the user button", |
|
47 |
false, |
|
48 |
GObject.ParamFlags.READABLE | |
|
49 |
GObject.ParamFlags.WRITABLE) |
|
50 |
}, |
|
51 |
|
|
52 |
|
|
53 |
_init: function (params) { |
|
52.1.10
by Gustav Hartvigsson
* made the UserButton work in tests. |
54 |
this.parent (); |
55 |
|
|
56 |
this.add (this.layout = new Gtk.Box ({ |
|
57 |
orientation: Gtk.Orientation.HORIZONTAL |
|
58 |
}) |
|
59 |
); |
|
60 |
|
|
52.1.11
by Gustav Hartvigsson
* switched the UserButton to be a GtkMenuButton instead of a GtkButton |
61 |
if (params != undefined) { |
52.1.10
by Gustav Hartvigsson
* made the UserButton work in tests. |
62 |
|
52.1.11
by Gustav Hartvigsson
* switched the UserButton to be a GtkMenuButton instead of a GtkButton |
63 |
if (params["user_avatar"] != undefined) { |
64 |
this.user_avatar = params["user_avatar"]; |
|
65 |
} else { |
|
66 |
this._user_avatar = Gtk.Image.new_from_icon_name ( |
|
67 |
"avatar-default-symbolic", null); |
|
68 |
} |
|
69 |
|
|
70 |
if (params["user_name"] != undefined) { |
|
71 |
this._user_name = params["user_name"]; |
|
72 |
} else { |
|
73 |
this._user_name = "Jone Deo"; |
|
74 |
} |
|
75 |
|
|
76 |
if (params["show_avatar_only"] != undefined) { |
|
77 |
this._show_avatar_only = params["show_avatar_only"]; |
|
78 |
} else { |
|
79 |
this._show_avatar_only = false; |
|
80 |
} |
|
81 |
|
|
82 |
if (params["popover"] != undefined) { |
|
83 |
this["popover"] = params["popover"]; |
|
84 |
} |
|
85 |
|
|
52.1.10
by Gustav Hartvigsson
* made the UserButton work in tests. |
86 |
} else { |
87 |
this._user_avatar = Gtk.Image.new_from_icon_name ( |
|
52.1.11
by Gustav Hartvigsson
* switched the UserButton to be a GtkMenuButton instead of a GtkButton |
88 |
"avatar-default-symbolic", null); |
52.1.10
by Gustav Hartvigsson
* made the UserButton work in tests. |
89 |
this._user_name = "Jone Deo"; |
90 |
this._show_avatar_only = false; |
|
52.1.11
by Gustav Hartvigsson
* switched the UserButton to be a GtkMenuButton instead of a GtkButton |
91 |
this["popover"] = null; |
52.1.10
by Gustav Hartvigsson
* made the UserButton work in tests. |
92 |
} |
93 |
|
|
94 |
this._rebuild (); |
|
95 |
}, |
|
96 |
|
|
97 |
/** |
|
98 |
* Hack to re-build the button, cus we can not use references in JavaScript.
|
|
99 |
*/
|
|
100 |
_rebuild: function () { |
|
101 |
|
|
102 |
this.layout.hide (); |
|
103 |
|
|
104 |
this.layout.foreach (function (widget) { |
|
105 |
widget.destroy (); |
|
106 |
}); |
|
107 |
|
|
108 |
this.layout.pack_start (this._user_avatar, false, false, 3); |
|
109 |
|
|
57
by Gustav Hartvigsson
* Made sure that the icons are square |
110 |
this.user_avatar["icon_size"] = 4; |
52.1.10
by Gustav Hartvigsson
* made the UserButton work in tests. |
111 |
|
112 |
|
|
113 |
if (this._show_avatar_only == false) { |
|
57
by Gustav Hartvigsson
* Made sure that the icons are square |
114 |
|
52.1.10
by Gustav Hartvigsson
* made the UserButton work in tests. |
115 |
this.layout.pack_start (new Gtk.Separator ({ |
116 |
orientation: Gtk.Orientation.VERTICAL |
|
52.1.12
by Gustav Hartvigsson
* Made a few style changes |
117 |
}), false, false, 5); |
52.1.10
by Gustav Hartvigsson
* made the UserButton work in tests. |
118 |
|
119 |
|
|
120 |
this.layout.pack_end ( |
|
121 |
this._user_name_widget = new Gtk.Label ({ |
|
52.1.12
by Gustav Hartvigsson
* Made a few style changes |
122 |
label: this._user_name, |
123 |
justify: Gtk.Justification.CENTER |
|
124 |
}), true, true, 10 |
|
52.1.10
by Gustav Hartvigsson
* made the UserButton work in tests. |
125 |
); |
126 |
} |
|
127 |
this.show_all (); |
|
52.1.1
by Gustav Hartvigsson
Button still not worknig, saving for prosparitny |
128 |
}, |
129 |
|
|
130 |
get user_avatar () { |
|
131 |
return this._user_avatar; |
|
132 |
}, |
|
133 |
|
|
134 |
set user_avatar (avatar) { |
|
52.1.10
by Gustav Hartvigsson
* made the UserButton work in tests. |
135 |
if (avatar == undefined) { |
136 |
print ("balls!"); |
|
137 |
this._user_avatar = Gtk.Image.new_from_icon_name ( |
|
138 |
"avatar-default-symbolic", null); |
|
52.1.1
by Gustav Hartvigsson
Button still not worknig, saving for prosparitny |
139 |
} else { |
52.1.10
by Gustav Hartvigsson
* made the UserButton work in tests. |
140 |
print ("Not balls!"); |
52.1.1
by Gustav Hartvigsson
Button still not worknig, saving for prosparitny |
141 |
this._user_avatar = avatar; |
52.1.10
by Gustav Hartvigsson
* made the UserButton work in tests. |
142 |
this._rebuild (); |
52.1.1
by Gustav Hartvigsson
Button still not worknig, saving for prosparitny |
143 |
} |
144 |
}, |
|
145 |
|
|
146 |
get user_name () { |
|
147 |
return this._user_name; |
|
148 |
}, |
|
149 |
|
|
150 |
set user_name (name) { |
|
151 |
this._user_name = name; |
|
52.1.10
by Gustav Hartvigsson
* made the UserButton work in tests. |
152 |
this._rebuild (); |
52.1.1
by Gustav Hartvigsson
Button still not worknig, saving for prosparitny |
153 |
}, |
154 |
|
|
155 |
get show_avatar_only () { |
|
156 |
return _show_avatar_only; |
|
157 |
}, |
|
158 |
|
|
52.1.10
by Gustav Hartvigsson
* made the UserButton work in tests. |
159 |
set show_avatar_only (show_avatar_only) { |
160 |
this._show_avatar_only = show_avatar_only; |
|
161 |
this._rebuild () |
|
52.1.1
by Gustav Hartvigsson
Button still not worknig, saving for prosparitny |
162 |
} |
163 |
|
|
164 |
});
|