~andybarilla/heybuddy/trunk1

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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
'''
this is a part of the heybuddy project
copyright 2010 jezra lickter http://www.jezra.net
'''
import gtk
import gobject
import PlatformSpecific
from FilterFrame import FilterFrame

class SettingsPage(gtk.VBox,gobject.GObject):
	__gsignals__={
		'update-account': (
			gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
							 (gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
			),
		'option-run-as-tray-app': (
			gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
						 (gobject.TYPE_BOOLEAN,)
		),
		'option-context-backwards': (
			gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
						 (gobject.TYPE_BOOLEAN,)
		),
		'option-no-avatars': (
			gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
						 (gobject.TYPE_BOOLEAN,)
		),
		'option-notifications':(
			gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
						 (gobject.TYPE_BOOLEAN,)
		),
		'option-notify-replies':(
			gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
						 (gobject.TYPE_BOOLEAN,)
		),
		'initial-dents': (
			gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
						 (gobject.TYPE_INT,)
		),
		'pull-time': (
			gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
						 (gobject.TYPE_INT,)
		),
		'link-color': (
			gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
						 (gobject.TYPE_STRING,)
		),
		'add-string-filter': (
			gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
						 (gobject.TYPE_STRING,)
		),
		'remove-string-filter' : (
			gobject.SIGNAL_RUN_FIRST,gobject.TYPE_NONE,
				(gobject.TYPE_STRING,)
		),
		'add-user-filter': (
			gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
						 (gobject.TYPE_STRING,)
		),
		'remove-user-filter' : (
			gobject.SIGNAL_RUN_FIRST,gobject.TYPE_NONE,
				(gobject.TYPE_STRING,)
		)
	}
	
	def __init__(self,has_hildon=False,has_pynotify=False):
		self.has_hildon=has_hildon
		gtk.VBox.__init__(self)
		gobject.GObject.__init__(self)
		self.set_homogeneous(False)
		self.set_border_width(5)
		#make this a scrollable thing
		vbox = gtk.VBox(False)
		scroller = PlatformSpecific.ScrollThingy()
		#put the vbox in a view port
		vport = gtk.Viewport()
		vport.set_shadow_type(gtk.SHADOW_NONE)
		vport.add(vbox)
		#add the vport to the scrollthingy
		scroller.add(vport)
		self.pack_start(scroller)
		
		#start with a table
		table = gtk.Table(4,2)
		table.attach(gtk.Label(_("Name:")),0,1,0,1,gtk.SHRINK,gtk.SHRINK)
		table.attach(gtk.Label(_("Password:")),0,1,1,2,gtk.SHRINK,gtk.SHRINK)
		table.attach(gtk.Label(_("Service:")),0,1,2,3,gtk.SHRINK,gtk.SHRINK)
		self.account_name_entry = gtk.Entry()
		self.account_password_entry = gtk.Entry()
		self.account_password_entry.set_invisible_char("*")
		self.account_password_entry.set_visibility(False)
		self.account_apiroot_entry = gtk.Entry()
		#add the entries to the table
		table.attach(self.account_name_entry,1,2,0,1,gtk.SHRINK,gtk.SHRINK)
		table.attach(self.account_password_entry,1,2,1,2,gtk.SHRINK,gtk.SHRINK)
		table.attach(self.account_apiroot_entry,1,2,2,3,gtk.SHRINK,gtk.SHRINK)
		#make a button to register "submit clicks
		enter_button = gtk.Button(_("Submit"))
		enter_button.connect('clicked', self.submit_clicked)
		#attach the button to the table
		table.attach(enter_button,1,2,3,4,gtk.SHRINK,gtk.SHRINK)
		account_frame = gtk.Frame(_("Account"))
		account_frame.add(table)
		vbox.pack_start(account_frame,False,False,0)
		#add the options settings
		options_box = gtk.VBox(False)
		self.run_as_tray_app = gtk.CheckButton(_("Run as tray application"))
		self.run_as_tray_app.connect('toggled', self.option_toggled,'option-run-as-tray-app')
		self.context_back_asswards = gtk.CheckButton(_("Conversation: oldest first"))
		self.context_back_asswards.connect('toggled', self.option_toggled,'option-context-backwards')
		self.disable_avatars = gtk.CheckButton(_("Disable avatar downloading"))
		self.disable_avatars.connect('toggled', self.option_toggled,'option-no-avatars')

		self.enable_notifications = gtk.CheckButton(_("Enable notifications"))
		self.enable_notifications.connect("toggled", self.option_toggled,'option-notifications')
		self.enable_notify_replies = gtk.CheckButton(_("Enable @replies notifications"))
		self.enable_notify_replies.connect('toggled', self.option_toggled,'option-notify-replies')

		options_box.pack_start(self.run_as_tray_app,False,False,0)
		options_box.pack_start(self.context_back_asswards,False,False,0)
		options_box.pack_start(self.disable_avatars,False,False,0)
		#does the app have notifications?
		if has_pynotify:
			options_box.pack_start(self.enable_notifications,False,False,0)
			options_box.pack_start(self.enable_notify_replies,False,False,0)
		options_frame = gtk.Frame(_("Options"))
		options_frame.add(options_box)
		vbox.pack_start(options_frame,False,False,0)
		#initial dents
		idhbox = gtk.HBox(False)
		idhbox.pack_start(gtk.Label(_("Number of dents at start-up: ")),False,False,0)
		self.initial_dents = gtk.HScale()
		self.initial_dents.connect('value-changed', self.initial_dents_changed)
		self.initial_dents.set_digits(0)
		self.initial_dents.set_range(20,100)
		self.initial_dents.set_increments(5,5)
		self.initial_dents.set_value_pos(gtk.POS_LEFT)
		#add the dpr to the options
		idhbox.pack_start(self.initial_dents)
		options_box.pack_start(idhbox,False,False,0)
		
		#pull time
		pthbox = gtk.HBox(False)
		pthbox.pack_start(gtk.Label(_("Update Interval: ")),False,False,0)
		self.pull_time = gtk.HScale()
		self.pull_time.connect('value-changed', self.pull_time_changed)
		self.pull_time.set_digits(0)
		self.pull_time.set_range(30,300)
		self.pull_time.set_increments(15,30)
		self.pull_time.set_value_pos(gtk.POS_LEFT)
		
		#add the pulltime slider+label
		pthbox.pack_start(self.pull_time)
		options_box.pack_start(pthbox,False,False,0)
		
		#how do we handle the link color?
		#don't show this on Maemo
		if not has_hildon:
			colorlabel = gtk.Label(_("Link Color: "))
			chbox = gtk.HBox(False)
			chbox.pack_start(colorlabel,False,False,0)
			self.color = gtk.Entry()
			self.color.connect('changed', self.check_color )
			self.color.set_tooltip_text(
			_("enter a hexidecimal color such as '#3333ff' or a color name such as 'orange'"))
			chbox.pack_start(self.color,False,False,0)
			self.colorevent = gtk.EventBox()
			chbox.pack_start(self.colorevent)
			options_box.pack_start(chbox,False,False,0)
			
		#add the fucking filter stuff
		filters_frame = gtk.Frame( _("Filters") )
		filters_vbox = gtk.VBox(False)
		filters_frame.add(filters_vbox)
		#create and add a FilterFrame for users
		self.userfilterframe = FilterFrame(_("User"))
		filters_vbox.pack_start(self.userfilterframe)
		#connect the userfilterframe
		self.userfilterframe.connect('add-filter', self.add_user_filter)
		self.userfilterframe.connect('remove-filter', self.remove_user_filter)
		#create and add a FilterFrame for strings
		self.stringfilterframe = FilterFrame(_("String"))
		filters_vbox.pack_start(self.stringfilterframe)
		vbox.pack_start(filters_frame)
		#connect the stringfilterframe
		self.stringfilterframe.connect('add-filter', self.add_string_filter)
		self.stringfilterframe.connect('remove-filter', self.remove_string_filter)
		
		
	def check_color(self,widget):
		color_string = self.color.get_text()
		try:
			color = gtk.gdk.Color(color_string)
			self.set_link_color(color_string)
			self.emit('link-color', color_string)
		except:
			pass
			
	def set_link_color(self,color_name):
		if not self.has_hildon:
			self.color.set_text(color_name)
			the_color = gtk.gdk.color_parse(color_name)
			self.colorevent.modify_bg(gtk.STATE_NORMAL,the_color )
		
	def set_run_as_tray_app(self,boolean):
		self.run_as_tray_app.set_active(boolean)	
	
	def set_context_backwards(self,boolean):
		self.context_back_asswards.set_active(boolean)
		
	def set_no_avatars(self,boolean):
		self.disable_avatars.set_active(boolean)

	#More Code for notifications			
	def set_notifications(self,boolean):
		self.enable_notifications.set_active(boolean)

	def set_notify_replies(self,boolean):
		self.enable_notify_replies.set_active(boolean)
	
	def set_name(self,name):
		self.account_name_entry.set_text(name)

	def set_password(self,password):
		self.account_password_entry.set_text(password)

	def set_service(self,service):
		self.account_apiroot_entry.set_text(service)

	def set_initial_dents(self,initial_dents):
		#convert the dents to a number
		self.initial_dents.set_value( int(initial_dents) )
		
	def set_pull_time(self,pull_time_str):
		"""Sets the value of the self.pull_time hslider.
		If the call comes from heybuddy.py it will come from
		ConfigParser which stores things as strings. To simplify
		the code it is assumed to be a string and converted to an int
		everytime"""
		self.pull_time.set_value( int(pull_time_str) )

	def submit_clicked(self,widget):
		#get the name and password
		n=self.account_name_entry.get_text()
		p=self.account_password_entry.get_text()
		a=self.account_apiroot_entry.get_text()
		if n!="" and p!="" and a!="" :
			self.emit('update-account',n,p,a)

	def option_toggled(self,widget,signal):
		value = widget.get_active()
		self.emit(signal,value)
		
	def initial_dents_changed(self,widget):
		value = self.initial_dents.get_value()
		self.emit('initial-dents',value)
	
	def pull_time_changed(self,widget):
		"""Gets the value of the pull time slider then emits a
		signal to notify other classes of the change"""
		value = self.pull_time.get_value()
		self.emit('pull-time',value)

	def add_string_filter(self,filterframe,string):
		self.emit('add-string-filter',string)
		
	def remove_string_filter(self,filterframe,string):
		self.emit('remove-string-filter',string)

	def set_string_filters(self, filters ):
		self.stringfilterframe.set_filters(filters)

	def add_user_filter(self,filterframe,user):
		self.emit('add-user-filter',user)
		
	def remove_user_filter(self,filterframe,user):
		self.emit('remove-user-filter',user)

	def set_user_filters(self, filters ):
		self.userfilterframe.set_filters(filters)