/gpump/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/gpump/trunk

« back to all changes in this revision

Viewing changes to src/user_button.js

  • Committer: Gustav Hartvigsson
  • Date: 2015-06-05 19:06:14 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20150605190614-s410mh65n2jdxtcv
* Cleaded up a lille code
* Fixed a nasty segfault that could occur if the conig folder did not exist.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
const UserButton = Lang.Class ({
17
17
  Name: "UserButton",
18
 
  Extends: Gtk.Button,
 
18
  Extends: Gtk.MenuButton,
19
19
  Properties: {
 
20
    /** @property user_avatar
 
21
     *
 
22
     */
20
23
    "user_avatar": GObject.param_spec_object ("user_avatar",
21
24
                                     "avatar",
22
25
                                     "A Gtk.Image that is shown in the button",
24
27
                                     GObject.ParamFlags.READABLE |
25
28
                                     GObject.ParamFlags.WRITABLE),
26
29
    
 
30
    /** @property user_name
 
31
     *
 
32
     */
27
33
    "user_name": GObject.param_spec_string ("user_name",
28
34
                                     "name",
29
35
                                     "The text to be shown on the button",
30
 
                                     "user name goes here",
 
36
                                     "Jone Deo",
31
37
                                     GObject.ParamFlags.READABLE |
32
38
                                     GObject.ParamFlags.WRITABLE),
33
39
    
 
40
    /** @property show_avatar_only
 
41
     *
 
42
     */
34
43
    "show_avatar_only": GObject.param_spec_boolean ("show_avatar_only",
35
44
                                     "show only avatar",
36
45
                                     "When set, only the avatar will be shown" +
42
51
  
43
52
  
44
53
  _init: function (params) {
45
 
    this.parent (params);
46
 
    this.set_property ('always-show-image', true);
 
54
    this.parent ();
 
55
    
 
56
    this.add (this.layout = new Gtk.Box ({
 
57
        orientation: Gtk.Orientation.HORIZONTAL
 
58
      })
 
59
    );
 
60
    
 
61
    if (params != undefined) {
 
62
    
 
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
     
 
86
    } else {
 
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;
 
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
    
 
110
    this.user_avatar["icon_size"] = 4;
 
111
    
 
112
    
 
113
    if (this._show_avatar_only == false) {
 
114
      
 
115
      this.layout.pack_start (new Gtk.Separator ({
 
116
        orientation: Gtk.Orientation.VERTICAL
 
117
      }), false, false, 5);
 
118
      
 
119
      
 
120
      this.layout.pack_end (
 
121
        this._user_name_widget = new Gtk.Label ({
 
122
          label: this._user_name,
 
123
          justify: Gtk.Justification.CENTER
 
124
        }), true, true, 10
 
125
      );
 
126
    }
 
127
    this.show_all ();
47
128
  },
48
129
  
49
130
  get user_avatar () {
51
132
  },
52
133
  
53
134
  set user_avatar (avatar) {
54
 
    if (avatar == null) {
55
 
      this.set_image ();
 
135
    if (avatar == undefined) {
 
136
      print ("balls!");
 
137
      this._user_avatar = Gtk.Image.new_from_icon_name (
 
138
        "avatar-default-symbolic", null);
56
139
    } else {
57
 
      this.set_image (avatar);
 
140
     print ("Not balls!");
58
141
      this._user_avatar = avatar;
 
142
      this._rebuild ();
59
143
    }
60
144
  },
61
145
  
65
149
  
66
150
  set user_name (name) {
67
151
    this._user_name = name;
68
 
    this.parent.set_property ("label", name);
 
152
    this._rebuild ();
69
153
  },
70
154
  
71
155
  get show_avatar_only () {
72
156
    return _show_avatar_only;
73
157
  },
74
158
  
75
 
  set show_avatar_only (show_avatar) {
76
 
    this._show_avatar_only = show_avatar;
 
159
  set show_avatar_only (show_avatar_only) {
 
160
    this._show_avatar_only = show_avatar_only;
 
161
    this._rebuild ()
77
162
  }
78
163
  
79
164
});