/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: 2014-11-20 20:20:53 UTC
  • mto: This revision was merged to the branch mainline in revision 53.
  • Revision ID: gustav.hartvigsson@gmail.com-20141120202053-ew2o6942d9uuyuzs
* made the UserButton work in tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    "user_name": GObject.param_spec_string ("user_name",
34
34
                                     "name",
35
35
                                     "The text to be shown on the button",
36
 
                                     "user name goes here",
 
36
                                     "Jone Deo",
37
37
                                     GObject.ParamFlags.READABLE |
38
38
                                     GObject.ParamFlags.WRITABLE),
39
39
    
51
51
  
52
52
  
53
53
  _init: function (params) {
54
 
    this.parent (params);
55
 
    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
    this._user_avatar = null;
 
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
    this._rebuild ();
 
83
  },
 
84
  
 
85
  /**
 
86
   * Hack to re-build the button, cus we can not use references in JavaScript.
 
87
   */
 
88
  _rebuild: function () {
 
89
    
 
90
    this.layout.hide ();
 
91
    
 
92
    this.layout.foreach (function (widget) {
 
93
      widget.destroy ();
 
94
    });
 
95
    
 
96
    this.layout.pack_start (this._user_avatar, false, false, 3);
 
97
    
 
98
    this.user_avatar["icon_size"] = 5;
 
99
    
 
100
    
 
101
    if (this._show_avatar_only == false) {
 
102
      this.layout.pack_start (new Gtk.Separator ({
 
103
        orientation: Gtk.Orientation.VERTICAL
 
104
      }), false, false, 3);
 
105
      
 
106
      
 
107
      this.layout.pack_end (
 
108
        this._user_name_widget = new Gtk.Label ({
 
109
          label: this._user_name
 
110
        }), true, true, 3
 
111
      );
 
112
    }
 
113
    this.show_all ();
56
114
  },
57
115
  
58
116
  get user_avatar () {
60
118
  },
61
119
  
62
120
  set user_avatar (avatar) {
63
 
    if (avatar == null) {
64
 
      this.set_image ();
 
121
    if (avatar == undefined) {
 
122
      print ("balls!");
 
123
      this._user_avatar = Gtk.Image.new_from_icon_name (
 
124
        "avatar-default-symbolic", null);
65
125
    } else {
66
 
      this.set_image (avatar);
 
126
     print ("Not balls!");
67
127
      this._user_avatar = avatar;
 
128
      this._rebuild ();
68
129
    }
69
130
  },
70
131
  
74
135
  
75
136
  set user_name (name) {
76
137
    this._user_name = name;
77
 
    this.parent.set_property ("label", name);
 
138
    this._rebuild ();
78
139
  },
79
140
  
80
141
  get show_avatar_only () {
81
142
    return _show_avatar_only;
82
143
  },
83
144
  
84
 
  set show_avatar_only (show_avatar) {
85
 
    this._show_avatar_only = show_avatar;
 
145
  set show_avatar_only (show_avatar_only) {
 
146
    this._show_avatar_only = show_avatar_only;
 
147
    this._rebuild ()
86
148
  }
87
149
  
88
150
});