~muelnet/heybuddy/pulltimes

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
'''
this is a part of the heybuddy project
copyright 2010 jezra lickter http://www.jezra.net
'''
from DentScroller import DentScroller
import gtk,gobject
from PlatformSpecific import links_unavailable
class GroupPage(gtk.VBox,gobject.GObject):
	__gsignals__={
		'group-page-hide': (
			gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
						 ()
		),
		'join-group' : (
			gobject.SIGNAL_RUN_FIRST,gobject.TYPE_NONE,
				(gobject.TYPE_STRING,gobject.TYPE_BOOLEAN)
			),
		'open-link': (
			gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
							 (gobject.TYPE_STRING,)
			),
	}
	def __init__(self):
		gtk.VBox.__init__(self)
		gobject.GObject.__init__(self)
		self.set_homogeneous(False)
		self.toggle_enabled=True

		self.image = gtk.Image()
		#make an
		imagevbox = gtk.VBox(False,0)
		imagevbox.pack_start(self.image,False,False,0)

		#make an hbox to hold image and group info
		grouphbox=gtk.HBox(False,5)
		self.pack_start(grouphbox,False,False,0)
		grouphbox.pack_start(imagevbox,False,False,0)
		infovbox = gtk.VBox(False)
		grouphbox.pack_start(infovbox,False,False)
		
		self.name_label = gtk.Label()
		infovbox.pack_start(self.name_label,False,False,0)
		
		self.homepage_label = gtk.Label()
		if not links_unavailable:
			self.homepage_label.connect('activate-link', self.process_link )
		infovbox.pack_start(self.homepage_label,False,False,0)
		
		self.description_label = gtk.Label()
		infovbox.pack_start(self.description_label,False,False,0)
		self.description_label.set_line_wrap(True)
		
		self.location_label = gtk.Label()
		infovbox.pack_start(self.location_label,False,False,0)
		
		#make a checkbutton if we are following
		self.joined_checkbutton = gtk.CheckButton(_("joined"))
		self.joined_checkbutton.connect('toggled', self.joined_toggled)
		infovbox.pack_start(self.joined_checkbutton,False,False,0)
		
		#create a group dent scroller and add it to the group page
		self.dentScroller = DentScroller()
		self.pack_start(self.dentScroller)
		
		#make a "close" button
		hbox = gtk.HBox(False)
		user_close_button=gtk.Button(_("Close"))
		hbox.pack_start(user_close_button,False,False,0)
		user_close_button.connect('clicked',self.close)
		self.pack_end(hbox,False,False,0)
		
	def set_group_data(self,data):
		self.joined_checkbutton.set_sensitive(True)
		self.group_id= data['id']
		self.group_name = data['fullname']
		self.name_label.set_text("%s" %(data['fullname']) )
		if data['location']!=None:
			self.location_label.set_text("%s" %(data['location']) )
			self.location_label.show()
		else:
			self.location_label.hide_all()
			
		if data['description']!=None:
			self.description_label.set_text("%s" %(data['description']) )
			self.description_label.show()
		else:
			self.description_label.hide_all()
		
		if data['homepage']!=None:
			try:
				self.homepage_label.set_markup('<a href="%(homepage)s">%(homepage)s</a>' % ({'homepage':data['homepage']}) )
			except:
				self.homepage_label.set_text("%s" %(data['homepage']) )
			self.homepage_label.show()
		else:
			self.homepage_label.hide_all()
		#is the user a member?
		if data['member']=='true':
			self.set_is_member(True)
	
	def set_image(self,image):
		self.image.set_from_file(image)
		self.image.show()
			
	def set_is_member(self,bool):
		self.toggle_enabled=False
		self.is_joined=bool
		self.joined_checkbutton.set_active( bool )
		self.toggle_enabled=True
		
	def clear(self):
		self.dentScroller.clear()
		self.image.hide()
	
	def joined_toggled(self,widget):
		if self.toggle_enabled:
			self.new_is_joined = self.joined_checkbutton.get_active()
			self.emit('join-group',self.group_id,self.new_is_joined)
		
	def close(self,button):
		#we don't need to talk to the controller
		#self.hide()
		self.emit('group-page-hide')
		
	def process_link(self, label, uri ):
		self.emit('open-link', uri )
		return True