summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2014-08-13 01:57:02 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2014-08-13 02:59:57 +0300
commit3ad1dcc47319ac19af49aa5ac645315e33b9c375 (patch)
treec13a1fa109733ad9581040f879226bcf7b116b3c
parent4af098f507f8df26423071e2cd0c46c22eecc31e (diff)
Updates for pep-8, py3k and pyefl compatibilityHEADmaster
-rw-r--r--apathy/AccountEditor.py293
-rw-r--r--apathy/Accounts.py113
-rw-r--r--apathy/Apathy.py12
-rw-r--r--apathy/Approver.py81
-rw-r--r--apathy/Call.py3
-rw-r--r--apathy/ContactInfo.py18
-rw-r--r--apathy/Contacts.py178
-rw-r--r--apathy/Conversation.py39
-rw-r--r--apathy/ErrorDialog.py4
-rw-r--r--apathy/FileTransfer.py8
-rw-r--r--apathy/Globals.py7
-rw-r--r--apathy/Handler.py69
-rw-r--r--apathy/NewAccount.py8
-rw-r--r--apathy/NewContact.py20
-rw-r--r--apathy/Parser.py19
-rw-r--r--apathy/PresenceEditor.py24
-rw-r--r--apathy/PresenceWidget.py50
-rwxr-xr-xbin/apathy-accounts23
-rwxr-xr-xbin/apathy-approver23
-rwxr-xr-xbin/apathy-contacts23
-rwxr-xr-xbin/apathy-handler23
21 files changed, 646 insertions, 392 deletions
diff --git a/apathy/AccountEditor.py b/apathy/AccountEditor.py
index 5caa917..0051273 100644
--- a/apathy/AccountEditor.py
+++ b/apathy/AccountEditor.py
@@ -1,10 +1,8 @@
1#!/usr/bin/env python
2
3######################################################################### 1#########################################################################
4# # 2# #
5# Apathy - A telepathy based communications client for mobile platforms # 3# Apathy - A telepathy based communications client for mobile platforms #
6# Copyright (C) 2009 Alasdair MacLeod <alasdair.macleod@gmail.com> # 4# Copyright (C) 2009 Alasdair MacLeod <alasdair.macleod@gmail.com> #
7# Copyright 2012 Kai Huuhko <kai@kaihuuhko.com> # 5# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com> #
8# # 6# #
9# This program is free software: you can redistribute it and/or modify # 7# This program is free software: you can redistribute it and/or modify #
10# it under the terms of the GNU General Public License as published by # 8# it under the terms of the GNU General Public License as published by #
@@ -21,32 +19,26 @@
21# # 19# #
22######################################################################### 20#########################################################################
23 21
24import os.path
25import logging 22import logging
26from getpass import getuser 23from getpass import getuser
27import mimetypes 24import mimetypes
28import tempfile 25import tempfile
29 26
30try: 27from efl.elementary.box import Box
31 from elementary import Box, Scroller, Button, Frame, Icon, \ 28from efl.elementary.scroller import Scroller
32 Hoversel, ELM_ICON_STANDARD, ELM_ICON_NONE, Entry, Check, \ 29from efl.elementary.button import Button
33 Fileselector, Photo, InnerWindow, Label, Spinner, Popup 30from efl.elementary.frame import Frame
34except ImportError: 31from efl.elementary.icon import Icon
35 from efl.elementary.box import Box 32from efl.elementary.hoversel import Hoversel, ELM_ICON_STANDARD, \
36 from efl.elementary.scroller import Scroller 33 ELM_ICON_NONE
37 from efl.elementary.button import Button 34from efl.elementary.entry import Entry
38 from efl.elementary.frame import Frame 35from efl.elementary.check import Check
39 from efl.elementary.icon import Icon 36from efl.elementary.fileselector import Fileselector
40 from efl.elementary.hoversel import Hoversel, ELM_ICON_STANDARD, \ 37from efl.elementary.photo import Photo
41 ELM_ICON_NONE 38from efl.elementary.innerwindow import InnerWindow
42 from efl.elementary.entry import Entry 39from efl.elementary.label import Label
43 from efl.elementary.check import Check 40from efl.elementary.spinner import Spinner
44 from efl.elementary.fileselector import Fileselector 41from efl.elementary.popup import Popup
45 from efl.elementary.photo import Photo
46 from efl.elementary.innerwindow import InnerWindow
47 from efl.elementary.label import Label
48 from efl.elementary.spinner import Spinner
49 from efl.elementary.popup import Popup
50 42
51from ErrorDialog import ErrorDialog 43from ErrorDialog import ErrorDialog
52from Globals import * 44from Globals import *
@@ -54,6 +46,7 @@ from Globals import *
54from gi.repository import GObject 46from gi.repository import GObject
55from gi.repository import TelepathyGLib as Tp 47from gi.repository import TelepathyGLib as Tp
56 48
49
57class AccountEditor(object): 50class AccountEditor(object):
58 def __init__(self, parent, pager, am, account=None): 51 def __init__(self, parent, pager, am, account=None):
59 self.parentwin = parent 52 self.parentwin = parent
@@ -68,7 +61,7 @@ class AccountEditor(object):
68 self.box = box = Box(parent) 61 self.box = box = Box(parent)
69 62
70 self.protocol_list = protocol_list = Hoversel(box) 63 self.protocol_list = protocol_list = Hoversel(box)
71 protocol_list.text= _("Select protocol").encode("utf-8") 64 protocol_list.text = _("Select protocol").encode("utf-8")
72 self.populate_protocol_list(protocol_list) 65 self.populate_protocol_list(protocol_list)
73 box.pack_end(protocol_list) 66 box.pack_end(protocol_list)
74 protocol_list.show() 67 protocol_list.show()
@@ -128,7 +121,14 @@ class AccountEditor(object):
128 ic.standard_set("im-"+proto.get_name()) 121 ic.standard_set("im-"+proto.get_name())
129 except: 122 except:
130 pass 123 pass
131 component.item_add(str.capitalize(proto.get_name()+" ("+cm.get_name()+")"), "im-"+proto.get_name(), ELM_ICON_STANDARD, self._protocol_selected, proto, cm) 124 component.item_add(
125 str.capitalize(
126 proto.get_name() + " (" + cm.get_name() + ")"
127 ),
128 "im-" + proto.get_name(),
129 ELM_ICON_STANDARD,
130 self._protocol_selected, proto, cm
131 )
132 132
133 if self.account: 133 if self.account:
134 self.populate_data(self.account) 134 self.populate_data(self.account)
@@ -142,18 +142,32 @@ class AccountEditor(object):
142 account.get_avatar_async(self.got_avatar, None) 142 account.get_avatar_async(self.got_avatar, None)
143 143
144 if proto == "jabber": 144 if proto == "jabber":
145 self.jabber_service_selected(self.props[Tp.IFACE_ACCOUNT+".Service"], None, account.get_service()) 145 self.jabber_service_selected(
146 self.props[Tp.IFACE_ACCOUNT+".Service"],
147 None,
148 account.get_service()
149 )
146 elif proto == "irc": 150 elif proto == "irc":
147 self.irc_service_selected(self.props[Tp.IFACE_ACCOUNT+".Service"], None, account.get_service()) 151 self.irc_service_selected(
152 self.props[Tp.IFACE_ACCOUNT+".Service"],
153 None,
154 account.get_service()
155 )
148 156
149 self.dname.text_set(account.get_display_name()) 157 self.dname.text_set(account.get_display_name())
150 158
151 self.props[Tp.IFACE_ACCOUNT+".Icon"].text_set(account.get_icon_name()) 159 self.props[Tp.IFACE_ACCOUNT+".Icon"].text_set(account.get_icon_name())
152 self.props[Tp.IFACE_ACCOUNT+".Nickname"].text_set(account.get_nickname()) 160 self.props[Tp.IFACE_ACCOUNT+".Nickname"].text_set(
161 account.get_nickname()
162 )
153 self.props[Tp.IFACE_ACCOUNT+".Enabled"].state_set(account.is_enabled()) 163 self.props[Tp.IFACE_ACCOUNT+".Enabled"].state_set(account.is_enabled())
154 self.props[Tp.IFACE_ACCOUNT+".ConnectAutomatically"].state_set(account.get_connect_automatically()) 164 self.props[Tp.IFACE_ACCOUNT+".ConnectAutomatically"].state_set(
165 account.get_connect_automatically()
166 )
155 167
156 self.auto_presence_selected(None, None, account.get_automatic_presence()) 168 self.auto_presence_selected(
169 None, None, account.get_automatic_presence()
170 )
157 171
158 for param, v in self.params.iteritems(): 172 for param, v in self.params.iteritems():
159 params = account.get_parameters() 173 params = account.get_parameters()
@@ -176,7 +190,9 @@ class AccountEditor(object):
176 def _protocol_selected(self, obj, data, proto, cm): 190 def _protocol_selected(self, obj, data, proto, cm):
177 self.proto = proto 191 self.proto = proto
178 self.cm = cm 192 self.cm = cm
179 self.protocol_list.text_set(str.capitalize(proto.get_name()+" ("+cm.get_name()+")")) 193 self.protocol_list.text_set(
194 str.capitalize(proto.get_name()+" ("+cm.get_name()+")")
195 )
180 self.box1.clear() 196 self.box1.clear()
181 197
182 self.props = {} 198 self.props = {}
@@ -201,7 +217,8 @@ class AccountEditor(object):
201 # Service 217 # Service
202 proto_name = proto.get_name() 218 proto_name = proto.get_name()
203 if proto_name == "jabber" or proto_name == "irc": 219 if proto_name == "jabber" or proto_name == "irc":
204 self.props[Tp.IFACE_ACCOUNT+".Service"] = service = Hoversel(self.box) 220 service = Hoversel(self.box)
221 self.props[Tp.IFACE_ACCOUNT+".Service"] = service
205 service.text_set(_("Select").encode("utf-8")) 222 service.text_set(_("Select").encode("utf-8"))
206 servframe = Frame(self.box) 223 servframe = Frame(self.box)
207 servframe.size_hint_align_set(-1.0, -1.0) 224 servframe.size_hint_align_set(-1.0, -1.0)
@@ -213,11 +230,20 @@ class AccountEditor(object):
213 230
214 proto_name = proto.get_name() 231 proto_name = proto.get_name()
215 if proto_name == "jabber": 232 if proto_name == "jabber":
216 for s in ["jabber", "google-talk", "ovi-chat", "facebook", "lj-talk", "windows-live"]: 233 for s in (
217 service.item_add(str.capitalize(s), "im-"+s, ELM_ICON_STANDARD, self.jabber_service_selected, s) 234 "jabber", "google-talk", "ovi-chat", "facebook", "lj-talk",
235 "windows-live"
236 ):
237 service.item_add(
238 str.capitalize(s), "im-"+s, ELM_ICON_STANDARD,
239 self.jabber_service_selected, s
240 )
218 elif proto_name == "irc": 241 elif proto_name == "irc":
219 for s in ["Freenode", "IRCNet", "GimpNet"]: 242 for s in ("Freenode", "IRCNet", "GimpNet"):
220 service.item_add(s, None, ELM_ICON_NONE, self.irc_service_selected, s) 243 service.item_add(
244 s, None, ELM_ICON_NONE,
245 self.irc_service_selected, s
246 )
221 247
222 # Display Name 248 # Display Name
223 dnameframe = Frame(self.box) 249 dnameframe = Frame(self.box)
@@ -232,7 +258,10 @@ class AccountEditor(object):
232 dname.text_set(getuser()+" ("+proto.get_name()+")") 258 dname.text_set(getuser()+" ("+proto.get_name()+")")
233 259
234 # Entries: Nickname, Icon 260 # Entries: Nickname, Icon
235 for name, title in {Tp.IFACE_ACCOUNT+".Nickname": _("Nickname").encode("utf-8"), Tp.IFACE_ACCOUNT+".Icon": _("Icon").encode("utf-8")}.iteritems(): 261 for name, title in {
262 Tp.IFACE_ACCOUNT + ".Nickname": _("Nickname").encode("utf-8"),
263 Tp.IFACE_ACCOUNT + ".Icon": _("Icon").encode("utf-8")
264 }.items():
236 frame = Frame(self.box) 265 frame = Frame(self.box)
237 frame.text_set(title) 266 frame.text_set(title)
238 frame.size_hint_align_set(-1.0, -1.0) 267 frame.size_hint_align_set(-1.0, -1.0)
@@ -246,7 +275,10 @@ class AccountEditor(object):
246 self.props[Tp.IFACE_ACCOUNT+".Icon"].text_set("im-"+proto.get_name()) 275 self.props[Tp.IFACE_ACCOUNT+".Icon"].text_set("im-"+proto.get_name())
247 276
248 # Checks: Enabled, ConnectAutomatically 277 # Checks: Enabled, ConnectAutomatically
249 for name, title in {Tp.IFACE_ACCOUNT+".Enabled": _("Enabled").encode("utf-8"), Tp.IFACE_ACCOUNT+".ConnectAutomatically": _("Connect Automatically").encode("utf-8")}.iteritems(): 278 for name, title in {
279 Tp.IFACE_ACCOUNT + ".Enabled": _("Enabled").encode("utf-8"),
280 Tp.IFACE_ACCOUNT + ".ConnectAutomatically": _("Connect Automatically").encode("utf-8")
281 }.items():
250 frame = Frame(self.box) 282 frame = Frame(self.box)
251 frame.text_set(title) 283 frame.text_set(title)
252 frame.size_hint_align_set(-1.0, -1.0) 284 frame.size_hint_align_set(-1.0, -1.0)
@@ -270,7 +302,9 @@ class AccountEditor(object):
270 #apres.show() 302 #apres.show()
271 303
272 paramhead = Label(self.box) 304 paramhead = Label(self.box)
273 paramhead.text_set("<br/>"+_("Account parameters:").encode("utf-8")+"<br/>") 305 paramhead.text_set(
306 "<br/>" + _("Account parameters:").encode("utf-8") + "<br/>"
307 )
274 paramhead.show() 308 paramhead.show()
275 self.box1.pack_end(paramhead) 309 self.box1.pack_end(paramhead)
276 310
@@ -293,15 +327,21 @@ class AccountEditor(object):
293 327
294 if ptype == "b": 328 if ptype == "b":
295 entry = self.params[pname] = Check(self.box) 329 entry = self.params[pname] = Check(self.box)
296 entry.callback_changed_add(lambda x, pname=pname: self._changed(x, pname)) 330 entry.callback_changed_add(
331 lambda x, pname=pname: self._changed(x, pname)
332 )
297 if param.get_default(defaultvalue): 333 if param.get_default(defaultvalue):
298 pdefault = defaultvalue.get_boolean() 334 pdefault = defaultvalue.get_boolean()
299 entry.state_set(pdefault) 335 entry.state_set(pdefault)
300 frametext = frametext+" - "+_("Default: %s") % (str(pdefault)) 336 frametext = frametext + " - " + _("Default: %s") % (
337 str(pdefault)
338 )
301 339
302 elif ptype == "s": 340 elif ptype == "s":
303 entry = self.params[pname] = Entry(self.box) 341 entry = self.params[pname] = Entry(self.box)
304 entry.callback_changed_user_add(lambda x, pname=pname: self._changed(x, pname)) 342 entry.callback_changed_user_add(
343 lambda x, pname=pname: self._changed(x, pname)
344 )
305 entry.single_line_set(True) 345 entry.single_line_set(True)
306 if param.is_secret(): 346 if param.is_secret():
307 entry.password_set(True) 347 entry.password_set(True)
@@ -312,7 +352,9 @@ class AccountEditor(object):
312 352
313 elif ptype in ["n", "q", "i", "u", "x", "t"]: 353 elif ptype in ["n", "q", "i", "u", "x", "t"]:
314 entry = self.params[pname] = Spinner(self.box) 354 entry = self.params[pname] = Spinner(self.box)
315 entry.callback_changed_add(lambda x, pname=pname: self._changed(x, pname)) 355 entry.callback_changed_add(
356 lambda x, pname=pname: self._changed(x, pname)
357 )
316 if "port" in pname: 358 if "port" in pname:
317 entry.min_max_set(0, 65535) 359 entry.min_max_set(0, 65535)
318 else: 360 else:
@@ -323,16 +365,22 @@ class AccountEditor(object):
323 else: 365 else:
324 pdefault = defaultvalue.get_uint() 366 pdefault = defaultvalue.get_uint()
325 entry.value_set(pdefault) 367 entry.value_set(pdefault)
326 frametext = frametext+" - "+_("Default: %s") % (str(pdefault)) 368 frametext = frametext + " - " + _("Default: %s") % (
369 str(pdefault)
370 )
327 371
328 #elif ptype == "as": 372 #elif ptype == "as":
329 #Multiline entry? Comma-delimited? List with buttons? 373 #Multiline entry? Comma-delimited? List with buttons?
330 #entry = self.params[pname] = List(self.box) 374 #entry = self.params[pname] = List(self.box)
331 375
332 else: 376 else:
333 logging.debug("Unknown parameter type %s in %s" % (ptype, pname)) 377 logging.debug(
378 "Unknown parameter type %s in %s" % (ptype, pname)
379 )
334 entry = self.params[pname] = Entry(self.box) 380 entry = self.params[pname] = Entry(self.box)
335 entry.callback_changed_user_add(lambda x, pname=pname: self._changed(x, pname)) 381 entry.callback_changed_user_add(
382 lambda x, pname=pname: self._changed(x, pname)
383 )
336 entry.single_line_set(True) 384 entry.single_line_set(True)
337 385
338 frame.text_set(frametext) 386 frame.text_set(frametext)
@@ -388,13 +436,13 @@ class AccountEditor(object):
388 if not req: 436 if not req:
389 req = Tp.AvatarRequirements.new( 437 req = Tp.AvatarRequirements.new(
390 ("image/png", "image/jpeg", "image/gif"), 438 ("image/png", "image/jpeg", "image/gif"),
391 32, #min 439 32, # min
392 32, 440 32,
393 64, #recommended 441 64, # recommended
394 64, 442 64,
395 96, #max 443 96, # max
396 96, 444 96,
397 32768 #max file 445 32768 # max file
398 ) 446 )
399 447
400 warn_file_size = 8192 448 warn_file_size = 8192
@@ -402,15 +450,44 @@ class AccountEditor(object):
402 450
403 # Mime type checks 451 # Mime type checks
404 if not mimetype in req.supported_mime_types: 452 if not mimetype in req.supported_mime_types:
405 dialog = ErrorDialog(self.parentwin, _("Error").encode("utf-8"), _("Your avatar file is of wrong type, %s, the allowed types are %s") % (mimetype, str(req.supported_mime_types))) 453 ErrorDialog(
454 self.parentwin,
455 _("Error").encode("utf-8"),
456 _(
457 "Your avatar file is of wrong type, %s, "
458 "the allowed types are %s"
459 ) % (
460 mimetype, str(req.supported_mime_types)
461 )
462 )
406 valid = False 463 valid = False
407 464
408 # File Size checks 465 # File Size checks
409 if len(avatar)>req.maximum_bytes: 466 if len(avatar) > req.maximum_bytes:
410 dialog = ErrorDialog(self.parentwin, _("Error").encode("utf-8"), _("Your avatar file is too large, %d bytes, the limit is %d bytes") % (len(avatar), req.maximum_bytes)) 467 ErrorDialog(
468 self.parentwin,
469 _("Error").encode("utf-8"),
470 _(
471 "Your avatar file is too large, %d bytes, "
472 "the limit is %d bytes"
473 ) % (
474 len(avatar), req.maximum_bytes
475 )
476 )
411 valid = False 477 valid = False
412 elif len(avatar)>warn_file_size: 478 elif len(avatar) > warn_file_size:
413 dialog = ErrorDialog(self.parentwin, _("Warning").encode("utf-8"), _("Your avatar file is of size %d bytes, which is larger than the recommended size %d bytes. Be aware that this account may not be able to set its presence correctly.") % (len(avatar), warn_file_size)) 479 ErrorDialog(
480 self.parentwin,
481 _("Warning").encode("utf-8"),
482 _(
483 "Your avatar file is of size %d bytes, "
484 "which is larger than the recommended size %d bytes. "
485 "Be aware that this account may not be able to set its "
486 "presence correctly."
487 ) % (
488 len(avatar), warn_file_size
489 )
490 )
414 491
415 return valid 492 return valid
416 493
@@ -419,10 +496,15 @@ class AccountEditor(object):
419 self.changed[key] = x 496 self.changed[key] = x
420 497
421 def save(self, data): 498 def save(self, data):
422 try: self.proto 499 try:
423 except: 500 self.proto
501 except Exception:
424 logging.info("No Protocol Selected") 502 logging.info("No Protocol Selected")
425 errdlg = ErrorDialog(self.parentwin, _("Error").encode("utf-8"), _("No Protocol Selected").encode("utf-8")) 503 ErrorDialog(
504 self.parentwin,
505 _("Error").encode("utf-8"),
506 _("No Protocol Selected").encode("utf-8")
507 )
426 return 508 return
427 509
428 account = {} 510 account = {}
@@ -445,7 +527,9 @@ class AccountEditor(object):
445 logging.debug("prop list %s" % (k)) 527 logging.debug("prop list %s" % (k))
446 account["props"][k] = v 528 account["props"][k] = v
447 else: 529 else:
448 logging.debug("Unknown prop type %s in %s" % (type(v).__name__, k)) 530 logging.debug(
531 "Unknown prop type %s in %s" % (type(v).__name__, k)
532 )
449 533
450 for k, v in self.changed.iteritems(): 534 for k, v in self.changed.iteritems():
451 k = k.rsplit(".", 1)[-1] 535 k = k.rsplit(".", 1)[-1]
@@ -462,31 +546,58 @@ class AccountEditor(object):
462 account["params"][k] = int(param) 546 account["params"][k] = int(param)
463 #elif type(v).__name__ == "": 547 #elif type(v).__name__ == "":
464 else: 548 else:
465 logging.debug("Unknown param type %s in %s" % (type(v).__name__, k)) 549 logging.debug(
466 550 "Unknown param type %s in %s" % (type(v).__name__, k)
467 logging.info("Saving account for Display Name %s" % (account["displayname"])) 551 )
552
553 logging.info(
554 "Saving account for Display Name %s" % (
555 account["displayname"]
556 )
557 )
468 558
469 if self.account: 559 if self.account:
470 #We are editing an account 560 #We are editing an account
471 apaccount = self.account 561 apaccount = self.account
472 apaccount.set_display_name_async(account["displayname"], self._display_name_set, None) 562 apaccount.set_display_name_async(
473 apaccount.set_enabled_async(account["props"][Tp.IFACE_ACCOUNT+".Enabled"], self._prop_set, None) 563 account["displayname"], self._display_name_set, None
474 apaccount.set_icon_name_async(account["props"][Tp.IFACE_ACCOUNT+".Icon"], self._prop_set, None) 564 )
475 try: account["props"][Tp.IFACE_ACCOUNT+".Service"] 565 apaccount.set_enabled_async(
566 account["props"][Tp.IFACE_ACCOUNT+".Enabled"],
567 self._prop_set, None
568 )
569 apaccount.set_icon_name_async(
570 account["props"][Tp.IFACE_ACCOUNT+".Icon"],
571 self._prop_set, None
572 )
573 try:
574 account["props"][Tp.IFACE_ACCOUNT+".Service"]
476 except KeyError: 575 except KeyError:
477 pass 576 pass
478 else: 577 else:
479 apaccount.set_service_async(account["props"][Tp.IFACE_ACCOUNT+".Service"], self._prop_set, None) 578 apaccount.set_service_async(
579 account["props"][Tp.IFACE_ACCOUNT+".Service"],
580 self._prop_set, None
581 )
480 #TODO: apaccount.set_automatic_presence_async(account["props"]["autopres"], self._prop_set, None) 582 #TODO: apaccount.set_automatic_presence_async(account["props"]["autopres"], self._prop_set, None)
481 apaccount.set_connect_automatically_async(account["props"][Tp.IFACE_ACCOUNT+".ConnectAutomatically"], self._prop_set, None) 583 apaccount.set_connect_automatically_async(
482 apaccount.set_nickname_async(account["props"][Tp.IFACE_ACCOUNT+".Nickname"], self._prop_set, None) 584 account["props"][Tp.IFACE_ACCOUNT+".ConnectAutomatically"],
483 585 self._prop_set, None
484 try: self.avatardata 586 )
587 apaccount.set_nickname_async(
588 account["props"][Tp.IFACE_ACCOUNT+".Nickname"],
589 self._prop_set, None
590 )
591
592 try:
593 self.avatardata
485 except AttributeError: 594 except AttributeError:
486 pass 595 pass
487 else: 596 else:
488 avatar, mimetype = self.avatardata 597 avatar, mimetype = self.avatardata
489 apaccount.set_avatar_async(avatar, mimetype, self._avatar_set, None) 598 apaccount.set_avatar_async(
599 avatar, mimetype, self._avatar_set, None
600 )
490 601
491 if account["params"]: 602 if account["params"]:
492 # XXX: update_parameters(_vardict)_async is broken by https://bugs.freedesktop.org/show_bug.cgi?id=59757 603 # XXX: update_parameters(_vardict)_async is broken by https://bugs.freedesktop.org/show_bug.cgi?id=59757
@@ -502,30 +613,52 @@ class AccountEditor(object):
502 logging.info("Account %s updated" % (account["displayname"])) 613 logging.info("Account %s updated" % (account["displayname"]))
503 #self._close() 614 #self._close()
504 else: 615 else:
505 self.am.create_account_async(self.cm.get_name(), self.proto.get_name(), self.dname.entry_get(), account["params"], account["props"], self.account_created, None) 616 self.am.create_account_async(
617 self.cm.get_name(),
618 self.proto.get_name(),
619 self.dname.entry_get(),
620 account["params"], account["props"],
621 self.account_created, None
622 )
506 623
507 def account_created(self, am, result, user_data): 624 def account_created(self, am, result, user_data):
508 try: 625 try:
509 account = am.create_account_finish(result) 626 account = am.create_account_finish(result)
510 except GObject.GError as gerror: 627 except GObject.GError as gerror:
511 logging.exception("Error while creating account") 628 logging.exception("Error while creating account")
512 ErrorDialog(self.parentwin, _("Error").encode("utf-8"), gerror.message) 629 ErrorDialog(
630 self.parentwin,
631 _("Error").encode("utf-8"),
632 gerror.message
633 )
513 else: 634 else:
514 logging.info("Account %s created" % (account.get_display_name())) 635 logging.info("Account %s created" % (account.get_display_name()))
515 try: self.avatardata 636 try:
516 except: pass 637 self.avatardata
638 except:
639 pass
517 else: 640 else:
518 avatar, mimetype = self.avatardata 641 avatar, mimetype = self.avatardata
519 account.set_avatar_async(avatar, mimetype, self._avatar_set, None) 642 account.set_avatar_async(
643 avatar, mimetype, self._avatar_set, None
644 )
520 self._close() 645 self._close()
521 646
522 def _display_name_set(self, account, result, user_data): 647 def _display_name_set(self, account, result, user_data):
523 if not account.set_display_name_finish(result): 648 if not account.set_display_name_finish(result):
524 errordlg = ErrorDialog(self.parentwin, _("Error").encode("utf-8"), "Could not set Display Name") 649 ErrorDialog(
650 self.parentwin,
651 _("Error").encode("utf-8"),
652 "Could not set Display Name"
653 )
525 654
526 def _avatar_set(self, account, result, user_data): 655 def _avatar_set(self, account, result, user_data):
527 if not account.set_avatar_finish(result): 656 if not account.set_avatar_finish(result):
528 errordlg = ErrorDialog(self.parentwin, _("Error").encode("utf-8"), "Could not set Avatar") 657 ErrorDialog(
658 self.parentwin,
659 _("Error").encode("utf-8"),
660 "Could not set Avatar"
661 )
529 662
530 def _prop_set(self, account, result, user_data): 663 def _prop_set(self, account, result, user_data):
531 pass 664 pass
diff --git a/apathy/Accounts.py b/apathy/Accounts.py
index bf5fcf1..24368fc 100644
--- a/apathy/Accounts.py
+++ b/apathy/Accounts.py
@@ -4,7 +4,7 @@
4# # 4# #
5# Apathy - A telepathy based communications client for mobile platforms # 5# Apathy - A telepathy based communications client for mobile platforms #
6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> # 6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> #
7# Copyright 2012 Kai Huuhko <kai@kaihuuhko.com> # 7# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com> #
8# # 8# #
9# This program is free software: you can redistribute it and/or modify # 9# This program is free software: you can redistribute it and/or modify #
10# it under the terms of the GNU General Public License as published by # 10# it under the terms of the GNU General Public License as published by #
@@ -25,27 +25,18 @@ import os.path
25import gettext 25import gettext
26import logging 26import logging
27 27
28try: 28from efl import ecore, elementary as elm
29 import ecore 29from efl.evas import EVAS_ASPECT_CONTROL_VERTICAL, EVAS_HINT_FILL, \
30 import elementary as elm 30 EVAS_HINT_EXPAND
31 from evas import EVAS_ASPECT_CONTROL_VERTICAL, EVAS_HINT_FILL, \ 31from efl.elementary.window import StandardWindow
32 EVAS_HINT_EXPAND 32from efl.elementary.box import Box
33 from elementary import StandardWindow, Box, Genlist, \ 33from efl.elementary.genlist import Genlist, GenlistItemClass, \
34 GenlistItemClass, ELM_GENLIST_ITEM_NONE, ELM_LIST_COMPRESS, \ 34 ELM_GENLIST_ITEM_NONE, ELM_LIST_COMPRESS
35 Button, Hoversel, Naviframe, Progressbar, Icon 35from efl.elementary.button import Button
36except ImportError: 36from efl.elementary.hoversel import Hoversel
37 from efl import ecore, elementary as elm 37from efl.elementary.naviframe import Naviframe
38 from efl.evas import EVAS_ASPECT_CONTROL_VERTICAL, EVAS_HINT_FILL, \ 38from efl.elementary.progressbar import Progressbar
39 EVAS_HINT_EXPAND 39from efl.elementary.icon import Icon
40 from efl.elementary.window import StandardWindow
41 from efl.elementary.box import Box
42 from efl.elementary.genlist import Genlist, GenlistItemClass, \
43 ELM_GENLIST_ITEM_NONE, ELM_LIST_COMPRESS
44 from efl.elementary.button import Button
45 from efl.elementary.hoversel import Hoversel
46 from efl.elementary.naviframe import Naviframe
47 from efl.elementary.progressbar import Progressbar
48 from efl.elementary.icon import Icon
49 40
50from Globals import * 41from Globals import *
51from AccountEditor import AccountEditor 42from AccountEditor import AccountEditor
@@ -55,6 +46,7 @@ from gi.repository import GObject
55GObject.threads_init() 46GObject.threads_init()
56from gi.repository import TelepathyGLib as Tp 47from gi.repository import TelepathyGLib as Tp
57 48
49
58class Accounts(object): 50class Accounts(object):
59 def __init__(self): 51 def __init__(self):
60 self.accounts = {} 52 self.accounts = {}
@@ -109,9 +101,11 @@ class Accounts(object):
109 window.resize(480, 640) 101 window.resize(480, 640)
110 window.show() 102 window.show()
111 103
112 am = self.am = Tp.AccountManager.dup() 104 self.am = Tp.AccountManager.dup()
113 factory = self.am.get_factory() 105 factory = self.am.get_factory()
114 factory.add_account_features([Tp.Account.get_feature_quark_connection()]) 106 factory.add_account_features(
107 [Tp.Account.get_feature_quark_connection()]
108 )
115 factory.add_connection_features([ 109 factory.add_connection_features([
116 Tp.Connection.get_feature_quark_avatar_requirements(), 110 Tp.Connection.get_feature_quark_avatar_requirements(),
117 ]) 111 ])
@@ -122,7 +116,9 @@ class Accounts(object):
122 am.connect("account-enabled", self.am_account_enabled) 116 am.connect("account-enabled", self.am_account_enabled)
123 am.connect("account-disabled", self.am_account_disabled) 117 am.connect("account-disabled", self.am_account_disabled)
124 am.connect("account-removed", self.am_account_removed) 118 am.connect("account-removed", self.am_account_removed)
125 am.connect("account-validity-changed", self.am_account_validity_changed) 119 am.connect(
120 "account-validity-changed", self.am_account_validity_changed
121 )
126 accounts = am.get_valid_accounts() 122 accounts = am.get_valid_accounts()
127 for account in accounts: 123 for account in accounts:
128 account.prepare_async(None, self.am_account_ready, None) 124 account.prepare_async(None, self.am_account_ready, None)
@@ -166,13 +162,25 @@ class Accounts(object):
166 try: 162 try:
167 message = conf.get("StatusMessages", status) 163 message = conf.get("StatusMessages", status)
168 except: 164 except:
169 logging.exception("Status message for status %s not found in configuration file." % (status)) 165 logging.exception(
166 "Status message for status %s not found in "
167 "configuration file." % (status)
168 )
170 message = "" 169 message = ""
171 self.presence_list.item_add(status.capitalize(), None, 0, self._set_presence, presence, status, message) 170 self.presence_list.item_add(
171 status.capitalize(), None, 0,
172 self._set_presence, presence, status, message
173 )
172 else: 174 else:
173 self.presence_list.item_add(status.capitalize(), None, 0, self._set_presence, presence, status) 175 self.presence_list.item_add(
176 status.capitalize(), None, 0,
177 self._set_presence, presence, status
178 )
174 179
175 self.presence_list.item_add(_("Edit")+"...", None, 0, self._edit_presences) 180 self.presence_list.item_add(
181 _("Edit")+"...", None, 0,
182 self._edit_presences
183 )
176 184
177 def _edit_presences(self, obj, event, *args): 185 def _edit_presences(self, obj, event, *args):
178 editor = PresenceEditor(self.window, self.pager) 186 editor = PresenceEditor(self.window, self.pager)
@@ -195,9 +203,15 @@ class Accounts(object):
195 def _set_presence(self, obj, event, prestype, presence, message=""): 203 def _set_presence(self, obj, event, prestype, presence, message=""):
196 if self.accounts_list.selected_item: 204 if self.accounts_list.selected_item:
197 account = self.accounts_list.selected_item.data 205 account = self.accounts_list.selected_item.data
198 logging.info("Setting presence %s for account %s" % (presence, account.get_display_name())) 206 logging.info(
199 account.request_presence_async(prestype, presence, message, self._changed_presence, None) 207 "Setting presence %s for account %s" % (
200 obj.text = _("Set presence")+" ("+presence+")" 208 presence, account.get_display_name()
209 )
210 )
211 account.request_presence_async(
212 prestype, presence, message, self._changed_presence, None
213 )
214 obj.text = _("Set presence") + " (" + presence + ")"
201 215
202 def _changed_presence(self, account, result, *args): 216 def _changed_presence(self, account, result, *args):
203 try: 217 try:
@@ -216,19 +230,25 @@ class Accounts(object):
216 def item_selected_cb(self, obj, item): 230 def item_selected_cb(self, obj, item):
217 account = item.data_get() 231 account = item.data_get()
218 presence, status, status_message = account.get_requested_presence() 232 presence, status, status_message = account.get_requested_presence()
219 self.presence_list.text_set(_("Set presence")+" ("+status.capitalize()+")") 233 self.presence_list.text_set(
234 _("Set presence") + " (" + status.capitalize() + ")"
235 )
220 236
221 def quit(self, *args): 237 def quit(self, *args):
222 elm.exit() 238 elm.exit()
223 239
224class AccountManager(object): 240
225 def __init__(self, am): 241# class AccountManager(object):
226 pass 242# def __init__(self, am):
243# pass
244
227 245
228class Account(object): 246class Account(object):
229 def __init__(self, parent, account): 247 def __init__(self, parent, account):
230 self.account = account 248 self.account = account
231 self.list_item = parent.accounts_list.item_append(AccountItem("default"), account, None, ELM_GENLIST_ITEM_NONE) 249 self.list_item = parent.accounts_list.item_append(
250 AccountItem("default"), account, None, ELM_GENLIST_ITEM_NONE
251 )
232 account.connect("presence-changed", self._presence_changed) 252 account.connect("presence-changed", self._presence_changed)
233 account.connect("notify::changing-presence", self._presence_changing) 253 account.connect("notify::changing-presence", self._presence_changing)
234 254
@@ -238,6 +258,7 @@ class Account(object):
238 def _presence_changing(self, account, changing): 258 def _presence_changing(self, account, changing):
239 self.list_item.update() 259 self.list_item.update()
240 260
261
241class AccountItem(GenlistItemClass): 262class AccountItem(GenlistItemClass):
242 def text_get(self, obj, part, account): 263 def text_get(self, obj, part, account):
243 presence, status, status_message = account.get_current_presence() 264 presence, status, status_message = account.get_current_presence()
@@ -251,7 +272,11 @@ class AccountItem(GenlistItemClass):
251 ic = Icon(obj) 272 ic = Icon(obj)
252 if account.get_icon_name(): 273 if account.get_icon_name():
253 try: 274 try:
254 ic.file_set(os.path.join(IMAGE_PATH, account.get_icon_name()+".png")) 275 ic.file_set(
276 os.path.join(
277 IMAGE_PATH, account.get_icon_name() + ".png"
278 )
279 )
255 except: 280 except:
256 try: 281 try:
257 ic.standard = account.get_icon_name() 282 ic.standard = account.get_icon_name()
@@ -283,8 +308,16 @@ if __name__ == "__main__":
283 308
284 # Log 309 # Log
285 if not os.path.exists(USER_PATH): 310 if not os.path.exists(USER_PATH):
286 os.mkdir(USER_PATH, 0700) 311 os.mkdir(USER_PATH, 0x700)
287 logging.basicConfig(format="[%(levelname)s] in %(module)s line %(lineno)s (%(funcName)s): %(message)s", level=logging.DEBUG) 312 log = logging.getLogger("apathy.accounts")
313 log.setLevel(logging.DEBUG)
314 streamformatter = logging.Formatter(
315 "[%(levelname)s] in %(module)s "
316 "line %(lineno)s (%(funcName)s): %(message)s"
317 )
318 handler_stream = logging.StreamHandler()
319 handler_stream.setFormatter(streamformatter)
320 log.addHandler(handler_stream)
288 321
289 elm.init() 322 elm.init()
290 323
diff --git a/apathy/Apathy.py b/apathy/Apathy.py
index d33d21f..4265827 100644
--- a/apathy/Apathy.py
+++ b/apathy/Apathy.py
@@ -4,7 +4,7 @@
4# # 4# #
5# Apathy - A telepathy based communications client for mobile platforms # 5# Apathy - A telepathy based communications client for mobile platforms #
6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> # 6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> #
7# Copyright 2012 Kai Huuhko <kai@kaihuuhko.com> # 7# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com> #
8# # 8# #
9# This program is free software: you can redistribute it and/or modify # 9# This program is free software: you can redistribute it and/or modify #
10# it under the terms of the GNU General Public License as published by # 10# it under the terms of the GNU General Public License as published by #
@@ -38,7 +38,7 @@ from gi.repository import TelepathyGLib as Tp
38class Apathy(e.Window): 38class Apathy(e.Window):
39 def __init__(self, log): 39 def __init__(self, log):
40 e.Window.__init__(self, "apathy", e.ELM_WIN_BASIC) 40 e.Window.__init__(self, "apathy", e.ELM_WIN_BASIC)
41 41
42 self.title_set("Apathy") 42 self.title_set("Apathy")
43 self.callback_delete_request_add(self.quit) 43 self.callback_delete_request_add(self.quit)
44 44
@@ -46,7 +46,7 @@ class Apathy(e.Window):
46 bg.size_hint_weight_set(1.0, 1.0) 46 bg.size_hint_weight_set(1.0, 1.0)
47 self.resize_object_add(bg) 47 self.resize_object_add(bg)
48 bg.show() 48 bg.show()
49 49
50 self.flip = flip = e.Flip(self) 50 self.flip = flip = e.Flip(self)
51 self.contacts = contacts = Contacts(self) 51 self.contacts = contacts = Contacts(self)
52 self.accounts = accounts = Accounts(self) 52 self.accounts = accounts = Accounts(self)
@@ -56,10 +56,10 @@ class Apathy(e.Window):
56 flip.size_hint_align_set(-1.0, -1.0) 56 flip.size_hint_align_set(-1.0, -1.0)
57 self.resize_object_add(flip) 57 self.resize_object_add(flip)
58 flip.show() 58 flip.show()
59 59
60 self.resize(480, 640) 60 self.resize(480, 640)
61 self.show() 61 self.show()
62 62
63 def quit(self, *args): 63 def quit(self, *args):
64 log.info("Apathy is exiting") 64 log.info("Apathy is exiting")
65 e.exit() 65 e.exit()
@@ -77,7 +77,7 @@ if __name__ == "__main__":
77 dbus.set_default_main_loop(dbus_mainloop) 77 dbus.set_default_main_loop(dbus_mainloop)
78 78
79 apathy = Apathy(log) 79 apathy = Apathy(log)
80 80
81 ecore.main_loop_glib_integrate() 81 ecore.main_loop_glib_integrate()
82 82
83 e.run() 83 e.run()
diff --git a/apathy/Approver.py b/apathy/Approver.py
index a364bf3..446e383 100644
--- a/apathy/Approver.py
+++ b/apathy/Approver.py
@@ -4,7 +4,7 @@
4# # 4# #
5# Apathy - A telepathy based communications client for mobile platforms # 5# Apathy - A telepathy based communications client for mobile platforms #
6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> # 6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> #
7# Copyright 2012 Kai Huuhko <kai@kaihuuhko.com> # 7# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com> #
8# # 8# #
9# This program is free software: you can redistribute it and/or modify # 9# This program is free software: you can redistribute it and/or modify #
10# it under the terms of the GNU General Public License as published by # 10# it under the terms of the GNU General Public License as published by #
@@ -25,24 +25,18 @@ import os.path
25import gettext 25import gettext
26import logging 26import logging
27 27
28try: 28from efl import ecore, elementary as elm
29 import ecore 29from efl.elementary.window import Window
30 import elementary as elm 30from efl.elementary.background import Background
31 from elementary import Window, Background, Box, Label, Button 31from efl.elementary.box import Box
32 from evas import EVAS_ASPECT_CONTROL_VERTICAL 32from efl.elementary.label import Label
33except ImportError: 33from efl.elementary.button import Button
34 from efl import ecore, elementary as elm
35 from efl.evas import EVAS_ASPECT_CONTROL_VERTICAL
36 from efl.elementary.window import Window
37 from efl.elementary.background import Background
38 from efl.elementary.box import Box
39 from efl.elementary.label import Label
40 from efl.elementary.button import Button
41 34
42from Globals import * 35from Globals import *
43 36
44from gi.repository import TelepathyGLib as Tp 37from gi.repository import TelepathyGLib as Tp
45 38
39
46class Approver(object): 40class Approver(object):
47 def __init__(self): 41 def __init__(self):
48 global log 42 global log
@@ -50,7 +44,9 @@ class Approver(object):
50 44
51 daemon = Tp.DBusDaemon.dup() 45 daemon = Tp.DBusDaemon.dup()
52 factory = Tp.AutomaticClientFactory.new(daemon) 46 factory = Tp.AutomaticClientFactory.new(daemon)
53 factory.add_account_features([Tp.Account.get_feature_quark_connection()]) 47 factory.add_account_features(
48 [Tp.Account.get_feature_quark_connection()]
49 )
54 factory.add_connection_features([ 50 factory.add_connection_features([
55 Tp.Connection.get_feature_quark_contact_list(), 51 Tp.Connection.get_feature_quark_contact_list(),
56 Tp.Connection.get_feature_quark_contact_groups(), 52 Tp.Connection.get_feature_quark_contact_groups(),
@@ -68,21 +64,25 @@ class Approver(object):
68 ]) 64 ])
69 65
70 self.approver = Tp.SimpleApprover.new_with_factory( 66 self.approver = Tp.SimpleApprover.new_with_factory(
71 factory, #Factory/am/tpdbus 67 factory, # Factory/am/tpdbus
72 'Apathy.Approver', #name 68 'Apathy.Approver', # name
73 False, #uniquify 69 False, # uniquify
74 self.channel_approver, #handler func 70 self.channel_approver, # handler func
75 None, #data 71 None, # data
76 ) 72 )
77 self.approver.add_approver_filter({ 73 self.approver.add_approver_filter({
78 }) 74 })
79 self.approver.register() 75 self.approver.register()
80 76
81 def accept(self, button, dispatch_operation, win): 77 def accept(self, button, dispatch_operation, win):
82 dispatch_operation.handle_with_async(Tp.CLIENT_BUS_NAME_BASE+"Apathy.Handler", self.channel_handled, win) 78 dispatch_operation.handle_with_async(
79 Tp.CLIENT_BUS_NAME_BASE+"Apathy.Handler", self.channel_handled, win
80 )
83 81
84 def cancelled(self, button, dispatch_operation, win): 82 def cancelled(self, button, dispatch_operation, win):
85 dispatch_operation.destroy_channels_async(Tp.ChannelGroupChangeReason.NONE, "", self.channel_dropped, win) 83 dispatch_operation.destroy_channels_async(
84 Tp.ChannelGroupChangeReason.NONE, "", self.channel_dropped, win
85 )
86 86
87 def channel_handled(self, dispatch_operation, result, win): 87 def channel_handled(self, dispatch_operation, result, win):
88 dispatch_operation.handle_with_finish(result) 88 dispatch_operation.handle_with_finish(result)
@@ -95,10 +95,20 @@ class Approver(object):
95 win.delete() 95 win.delete()
96 96
97 def channel_lost(self, channel, domain, code, message, user_data): 97 def channel_lost(self, channel, domain, code, message, user_data):
98 log.debug("%s %s %s %s %s" % (channel, domain, code, message, user_data)) 98 log.debug(
99 99 "%s %s %s %s %s" % (channel, domain, code, message, user_data)
100 def channel_approver(self, approver, account, connection, channels, dispatch_operation, context, user_data): 100 )
101 log.debug("%s %s %s %s %s %s %s" % (approver, account, connection, channels, dispatch_operation, context, user_data)) 101
102 def channel_approver(
103 self, approver, account, connection, channels, dispatch_operation,
104 context, user_data
105 ):
106 log.debug(
107 "%s %s %s %s %s %s %s" % (
108 approver, account, connection, channels, dispatch_operation,
109 context, user_data
110 )
111 )
102 112
103 dispatch_operation.connect("channel-lost", self.channel_lost) 113 dispatch_operation.connect("channel-lost", self.channel_lost)
104 114
@@ -117,12 +127,20 @@ class Approver(object):
117 box.show() 127 box.show()
118 128
119 title = Label(window) 129 title = Label(window)
120 title.text_set("<b>"+_("Accept channel from").encode("ascii", "xmlcharrefreplace")+"</b>") 130 title.text_set(
131 "<b>"+_("Accept channel from").encode(
132 "ascii", "xmlcharrefreplace"
133 )+"</b>"
134 )
121 box.pack_end(title) 135 box.pack_end(title)
122 title.show() 136 title.show()
123 137
124 for channel in channels: 138 for channel in channels:
125 log.info("Asking approval for a channel from %s" % (channel.get_identifier())) 139 log.info(
140 "Asking approval for a channel from %s" % (
141 channel.get_identifier()
142 )
143 )
126 144
127 identifier = channel.get_target_contact().get_alias() 145 identifier = channel.get_target_contact().get_alias()
128 if not identifier: 146 if not identifier:
@@ -170,10 +188,13 @@ if __name__ == "__main__":
170 188
171 # Log 189 # Log
172 if not os.path.exists(USER_PATH): 190 if not os.path.exists(USER_PATH):
173 os.mkdir(USER_PATH, 0700) 191 os.mkdir(USER_PATH, 0x700)
174 log = logging.getLogger("apathy.approver") 192 log = logging.getLogger("apathy.approver")
175 log.setLevel(logging.DEBUG) 193 log.setLevel(logging.DEBUG)
176 streamformatter = logging.Formatter("[%(levelname)s] in %(module)s line %(lineno)s (%(funcName)s): %(message)s") 194 streamformatter = logging.Formatter(
195 "[%(levelname)s] in %(module)s "
196 "line %(lineno)s (%(funcName)s): %(message)s"
197 )
177 handler_stream = logging.StreamHandler() 198 handler_stream = logging.StreamHandler()
178 handler_stream.setFormatter(streamformatter) 199 handler_stream.setFormatter(streamformatter)
179 log.addHandler(handler_stream) 200 log.addHandler(handler_stream)
diff --git a/apathy/Call.py b/apathy/Call.py
index fe9655f..f4f3cf1 100644
--- a/apathy/Call.py
+++ b/apathy/Call.py
@@ -1,9 +1,8 @@
1#!/usr/bin/env python
2
3######################################################################### 1#########################################################################
4# # 2# #
5# Apathy - A telepathy based communications client for mobile platforms # 3# Apathy - A telepathy based communications client for mobile platforms #
6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> # 4# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> #
5# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com> #
7# # 6# #
8# This program is free software: you can redistribute it and/or modify # 7# This program is free software: you can redistribute it and/or modify #
9# it under the terms of the GNU General Public License as published by # 8# it under the terms of the GNU General Public License as published by #
diff --git a/apathy/ContactInfo.py b/apathy/ContactInfo.py
index a07df1e..26bc94f 100644
--- a/apathy/ContactInfo.py
+++ b/apathy/ContactInfo.py
@@ -1,10 +1,8 @@
1#!/usr/bin/env python
2
3######################################################################### 1#########################################################################
4# # 2# #
5# Apathy - A telepathy based communications client for mobile platforms # 3# Apathy - A telepathy based communications client for mobile platforms #
6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> # 4# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> #
7# Copyright 2012 Kai Huuhko <kai@kaihuuhko.com> # 5# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com> #
8# # 6# #
9# This program is free software: you can redistribute it and/or modify # 7# This program is free software: you can redistribute it and/or modify #
10# it under the terms of the GNU General Public License as published by # 8# it under the terms of the GNU General Public License as published by #
@@ -21,18 +19,14 @@
21# # 19# #
22######################################################################### 20#########################################################################
23 21
24try: 22from efl.elementary.box import Box
25 from elementary import * 23from efl.elementary.label import Label
26 from evas import EVAS_ASPECT_CONTROL_VERTICAL 24from efl.elementary.photo import Photo
27except ImportError: 25from efl.elementary.button import Button
28 from efl.evas import EVAS_ASPECT_CONTROL_VERTICAL
29 from efl.elementary.box import Box
30 from efl.elementary.label import Label
31 from efl.elementary.photo import Photo
32 from efl.elementary.button import Button
33 26
34from gi.repository import TelepathyGLib as Tp 27from gi.repository import TelepathyGLib as Tp
35 28
29
36class ContactInfo(Box): 30class ContactInfo(Box):
37 def __init__(self, parent, contact): 31 def __init__(self, parent, contact):
38 self.parentwin = parent 32 self.parentwin = parent
diff --git a/apathy/Contacts.py b/apathy/Contacts.py
index 95cb578..384d2d0 100644
--- a/apathy/Contacts.py
+++ b/apathy/Contacts.py
@@ -4,7 +4,7 @@
4# # 4# #
5# Apathy - A telepathy based communications client for mobile platforms # 5# Apathy - A telepathy based communications client for mobile platforms #
6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> # 6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> #
7# Copyright 2012 Kai Huuhko <kai@kaihuuhko.com> # 7# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com> #
8# # 8# #
9# This program is free software: you can redistribute it and/or modify # 9# This program is free software: you can redistribute it and/or modify #
10# it under the terms of the GNU General Public License as published by # 10# it under the terms of the GNU General Public License as published by #
@@ -25,25 +25,17 @@ import os.path
25import gettext 25import gettext
26import logging 26import logging
27 27
28try: 28from efl import ecore, elementary as elm
29 import ecore, elementary as elm 29from efl.evas import EVAS_ASPECT_CONTROL_VERTICAL
30 from evas import EVAS_ASPECT_CONTROL_VERTICAL 30from efl.elementary.window import StandardWindow
31 from elementary import StandardWindow, Genlist, GenlistItemClass, \ 31from efl.elementary.genlist import Genlist, GenlistItemClass, \
32 ELM_GENLIST_ITEM_NONE, ELM_GENLIST_ITEM_GROUP, \ 32 ELM_GENLIST_ITEM_NONE, ELM_GENLIST_ITEM_GROUP, \
33 ELM_LIST_COMPRESS, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, \ 33 ELM_LIST_COMPRESS, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY
34 Box, Label, Naviframe, Icon, Menu 34from efl.elementary.box import Box
35except ImportError: 35from efl.elementary.label import Label
36 from efl import ecore, elementary as elm 36from efl.elementary.naviframe import Naviframe
37 from efl.evas import EVAS_ASPECT_CONTROL_VERTICAL 37from efl.elementary.icon import Icon
38 from efl.elementary.window import StandardWindow 38from efl.elementary.menu import Menu
39 from efl.elementary.genlist import Genlist, GenlistItemClass, \
40 ELM_GENLIST_ITEM_NONE, ELM_GENLIST_ITEM_GROUP, \
41 ELM_LIST_COMPRESS, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY
42 from efl.elementary.box import Box
43 from efl.elementary.label import Label
44 from efl.elementary.naviframe import Naviframe
45 from efl.elementary.icon import Icon
46 from efl.elementary.menu import Menu
47 39
48from ContactInfo import ContactInfo 40from ContactInfo import ContactInfo
49from Globals import * 41from Globals import *
@@ -53,12 +45,15 @@ from gi.repository import GObject
53GObject.threads_init() 45GObject.threads_init()
54from gi.repository import TelepathyGLib as Tp 46from gi.repository import TelepathyGLib as Tp
55 47
48
56class ContactItem(GenlistItemClass): 49class ContactItem(GenlistItemClass):
57 def text_get(self, obj, part, contact): 50 def text_get(self, obj, part, contact):
58 if part == "elm.text": 51 if part == "elm.text":
59 msg = contact.get_presence_message() 52 msg = contact.get_presence_message()
60 if msg: 53 if msg:
61 string = " %s - %s" % (contact.get_alias(), contact.get_presence_message()) 54 string = " %s - %s" % (
55 contact.get_alias(), contact.get_presence_message()
56 )
62 else: 57 else:
63 string = " %s" % (contact.get_alias()) 58 string = " %s" % (contact.get_alias())
64 return string 59 return string
@@ -90,6 +85,7 @@ class ContactItem(GenlistItemClass):
90 85
91 return ic 86 return ic
92 87
88
93class ContactGroup(GenlistItemClass): 89class ContactGroup(GenlistItemClass):
94 def text_get(self, obj, part, contactgroup): 90 def text_get(self, obj, part, contactgroup):
95 return contactgroup 91 return contactgroup
@@ -103,6 +99,7 @@ class ContactGroup(GenlistItemClass):
103 else: 99 else:
104 return 100 return
105 101
102
106class Contacts(object): 103class Contacts(object):
107 def __init__(self): 104 def __init__(self):
108 self.accounts = {} 105 self.accounts = {}
@@ -121,7 +118,9 @@ class Contacts(object):
121 118
122 self.am = am = Tp.AccountManager.dup() 119 self.am = am = Tp.AccountManager.dup()
123 factory = am.get_factory() 120 factory = am.get_factory()
124 factory.add_account_features([Tp.Account.get_feature_quark_connection()]) 121 factory.add_account_features(
122 [Tp.Account.get_feature_quark_connection()]
123 )
125 factory.add_connection_features([ 124 factory.add_connection_features([
126 Tp.Connection.get_feature_quark_contact_list(), 125 Tp.Connection.get_feature_quark_contact_list(),
127 Tp.Connection.get_feature_quark_contact_groups(), 126 Tp.Connection.get_feature_quark_contact_groups(),
@@ -185,10 +184,14 @@ class Contacts(object):
185 for account in am.get_valid_accounts(): 184 for account in am.get_valid_accounts():
186 self.accounts[account.get_path_suffix()] = item = Account(self) 185 self.accounts[account.get_path_suffix()] = item = Account(self)
187 account.prepare_async(None, item.account_ready, None) 186 account.prepare_async(None, item.account_ready, None)
188 log.info("Added account for %s to the list of accounts" % (account.get_display_name())) 187 log.info(
188 "Added account for %s to the list of accounts" % (
189 account.get_display_name()
190 )
191 )
189 192
190 def new_contact(self, obj, *args): 193 def new_contact(self, obj, *args):
191 new_contact_page = NewContact(self, self.am) 194 NewContact(self, self.am)
192 195
193 def create_contact_info(self, genlist, item): 196 def create_contact_info(self, genlist, item):
194 contact = item.data_get() 197 contact = item.data_get()
@@ -248,15 +251,27 @@ class Contacts(object):
248 def show_menu(self, genlist, item): 251 def show_menu(self, genlist, item):
249 contact = item.data_get() 252 contact = item.data_get()
250 menu = Menu(self.window) 253 menu = Menu(self.window)
251 menu.item_add(None, _("Text").encode("utf-8"), "message", self.menu_conversation, genlist, item) 254 menu.item_add(
255 None, _("Text").encode("utf-8"), "message",
256 self.menu_conversation, genlist, item
257 )
252 #menu.item_add(None, _("Call"), "call", self.menu_call, genlist, item) 258 #menu.item_add(None, _("Call"), "call", self.menu_call, genlist, item)
253 #menu.item_add(None, _("Send file", "file", self.menu_file, genlist, item) 259 #menu.item_add(None, _("Send file", "file", self.menu_file, genlist, item)
254 menu.item_separator_add() 260 menu.item_separator_add()
255 if contact.is_blocked(): 261 if contact.is_blocked():
256 menu.item_add(None, _("Unblock").encode("utf-8"), "", self.menu_unblock, genlist, item) 262 menu.item_add(
263 None, _("Unblock").encode("utf-8"), "",
264 self.menu_unblock, genlist, item
265 )
257 else: 266 else:
258 menu.item_add(None, _("Block").encode("utf-8"), "", self.menu_block, genlist, item) 267 menu.item_add(
259 menu.item_add(None, _("Information").encode("utf-8"), "", self.menu_contact_info, genlist, item) 268 None, _("Block").encode("utf-8"), "",
269 self.menu_block, genlist, item
270 )
271 menu.item_add(
272 None, _("Information").encode("utf-8"), "",
273 self.menu_contact_info, genlist, item
274 )
260 275
261 w, h = genlist.size_get() 276 w, h = genlist.size_get()
262 menu.move(w/2-50, h/2-100) 277 menu.move(w/2-50, h/2-100)
@@ -264,20 +279,26 @@ class Contacts(object):
264 279
265 def menu_conversation(self, menu, menuitem, genlist, item): 280 def menu_conversation(self, menu, menuitem, genlist, item):
266 self.start_conversation(genlist, item) 281 self.start_conversation(genlist, item)
282
267 def menu_call(self, menu, menuitem, genlist, item): 283 def menu_call(self, menu, menuitem, genlist, item):
268 self.start_call(genlist, item) 284 self.start_call(genlist, item)
285
269 def menu_file(self, menu, menuitem, genlist, item): 286 def menu_file(self, menu, menuitem, genlist, item):
270 pass 287 pass
288
271 def menu_block(self, menu, menuitem, genlist, item): 289 def menu_block(self, menu, menuitem, genlist, item):
272 self.block_contact(genlist, item) 290 self.block_contact(genlist, item)
291
273 def menu_unblock(self, menu, menuitem, genlist, item): 292 def menu_unblock(self, menu, menuitem, genlist, item):
274 self.unblock_contact(genlist, item) 293 self.unblock_contact(genlist, item)
294
275 def menu_contact_info(self, menu, menuitem, genlist, item): 295 def menu_contact_info(self, menu, menuitem, genlist, item):
276 self.create_contact_info(genlist, item) 296 self.create_contact_info(genlist, item)
277 297
278 def quit(self, *args): 298 def quit(self, *args):
279 elm.exit() 299 elm.exit()
280 300
301
281class Account(object): 302class Account(object):
282 def __init__(self, parent): 303 def __init__(self, parent):
283 self.parent = parent 304 self.parent = parent
@@ -293,36 +314,53 @@ class Account(object):
293 314
294 account.connect("status-changed", self._status_changed) 315 account.connect("status-changed", self._status_changed)
295 316
296 def _status_changed(self, account, old_status, new_status, reason, dbus_error_name, details, *args): 317 def _status_changed(
297 log.debug("Connection status for %s changed from %s to %s, reason %s, dbus error %s, details %s" % (account.get_display_name(), old_status, new_status, reason, dbus_error_name, details)) 318 self, account, old_status, new_status, reason, dbus_error_name,
319 details, *args
320 ):
321 log.debug(
322 "Connection status for %s changed from %s to %s, reason %s, "
323 "dbus error %s, details %s" % (
324 account.get_display_name(), old_status, new_status, reason,
325 dbus_error_name, details
326 )
327 )
298 connection = account.get_connection() 328 connection = account.get_connection()
299 contact_list = self.parent
300 329
301 if new_status == Tp.ConnectionStatus.CONNECTED: 330 if new_status == Tp.ConnectionStatus.CONNECTED:
302 if connection.get_contact_list_state() == Tp.ContactListState.SUCCESS: 331 state = connection.get_contact_list_state()
303 self._signals.append(connection.connect("groups-created", self._groups_created)) 332 if state == Tp.ContactListState.SUCCESS:
304 self._signals.append(connection.connect("groups-removed", self._groups_removed)) 333 self._signals.append(
334 connection.connect("groups-created", self._groups_created)
335 )
336 self._signals.append(
337 connection.connect("groups-removed", self._groups_removed)
338 )
305 self.get_contacts(connection) 339 self.get_contacts(connection)
306 else: 340 else:
307 self._signals.append(connection.connect("notify::contact-list-state", self._contact_list_state_changed)) 341 self._signals.append(
342 connection.connect(
343 "notify::contact-list-state",
344 self._contact_list_state_changed
345 )
346 )
308 347
309 elif new_status == Tp.ConnectionStatus.DISCONNECTED: 348 elif new_status == Tp.ConnectionStatus.DISCONNECTED:
349 if not connection:
350 return
351
310 log.debug("%s disconnected" % (connection.get_object_path())) 352 log.debug("%s disconnected" % (connection.get_object_path()))
311 for sigid in self._signals: 353 for sigid in self._signals:
312 connection.disconnect(sigid) 354 connection.disconnect(sigid)
313 try: 355 for k, v in connection.contact_items.items():
314 for k, v in connection.contact_items.iteritems(): 356 for item in v:
315 for item in v: 357 item.delete()
316 item.delete() 358 for k, v in connection.group_items.items():
317 for k, v in connection.group_items.iteritems(): 359 v.delete()
318 v.delete()
319 except:
320 pass
321 360
322 def get_contacts(self, connection): 361 def get_contacts(self, connection):
323 connection.group_items = {} 362 connection.group_items = {}
324 connection.contact_items = {} 363 connection.contact_items = {}
325 contact_list = self.parent
326 groups = connection.get_contact_groups() 364 groups = connection.get_contact_groups()
327 if not groups: 365 if not groups:
328 groups.append(_("Non-grouped contacts").encode("utf-8")) 366 groups.append(_("Non-grouped contacts").encode("utf-8"))
@@ -330,14 +368,20 @@ class Account(object):
330 contacts = connection.dup_contact_list() 368 contacts = connection.dup_contact_list()
331 self._contact_list_changed(contacts, None) 369 self._contact_list_changed(contacts, None)
332 370
333 self._signals.append(connection.connect("contact-list-changed", self._contact_list_changed)) 371 self._signals.append(
372 connection.connect(
373 "contact-list-changed",
374 self._contact_list_changed
375 )
376 )
334 #connection.connect("balance-changed", self._balance_changed) 377 #connection.connect("balance-changed", self._balance_changed)
335 #connection.connect("blocked-contacts-changed", self._blocked_contacts_changed) 378 #connection.connect("blocked-contacts-changed", self._blocked_contacts_changed)
336 #connection.connect("group-renamed", self._group_renamed) 379 #connection.connect("group-renamed", self._group_renamed)
337 380
338 def _groups_created(self, added): 381 def _groups_created(self, added):
339 for group in added: 382 for group in added:
340 self.account.get_connection().group_items[group] = item = self.add_group(group) 383 item = self.add_group(group)
384 self.account.get_connection().group_items[group] = item
341 item.select_mode_set(ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) 385 item.select_mode_set(ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY)
342 386
343 def _groups_removed(self, removed): 387 def _groups_removed(self, removed):
@@ -366,7 +410,9 @@ class Account(object):
366 group = connection.group_items[group] 410 group = connection.group_items[group]
367 except KeyError: 411 except KeyError:
368 group = None 412 group = None
369 contact_item = self.parent.contact_list.item_append(item_class, contact, group, ELM_GENLIST_ITEM_NONE) 413 contact_item = self.parent.contact_list.item_append(
414 item_class, contact, group, ELM_GENLIST_ITEM_NONE
415 )
370 contact_item.tooltip_content_cb_set(self._contact_tooltip, contact) 416 contact_item.tooltip_content_cb_set(self._contact_tooltip, contact)
371 contact_items.append(contact_item) 417 contact_items.append(contact_item)
372 return contact_items 418 return contact_items
@@ -375,7 +421,9 @@ class Account(object):
375 if added: 421 if added:
376 for contact in added: 422 for contact in added:
377 log.debug("contact %s added" % contact.get_handle()) 423 log.debug("contact %s added" % contact.get_handle())
378 contact.get_connection().contact_items[contact.get_handle()] = items = self.add_contact(contact) 424 conn = contact.get_connection()
425 items = self.add_contact(contact)
426 conn.contact_items[contact.get_handle()] = items
379 #~ for item in items: 427 #~ for item in items:
380 #~ if contact.get_presence_status() == "offline": 428 #~ if contact.get_presence_status() == "offline":
381 #~ item.disabled_set(True) 429 #~ item.disabled_set(True)
@@ -388,13 +436,17 @@ class Account(object):
388 if removed: 436 if removed:
389 for contact in removed: 437 for contact in removed:
390 log.debug("contact %s removed" % contact.get_handle()) 438 log.debug("contact %s removed" % contact.get_handle())
391 contact.get_connection().contact_items[contact.get_handle()].delete() 439 conn = contact.get_connection()
440 conn.contact_items[contact.get_handle()].delete()
392 del contact 441 del contact
393 442
394 def _contact_tooltip(self, list, item, contact): 443 def _contact_tooltip(self, list, item, contact):
395 helplabel = Label(self.parent.window) 444 helplabel = Label(self.parent.window)
396 helplabel.size_hint_align_set(0.0, 0.0) 445 helplabel.size_hint_align_set(0.0, 0.0)
397 helplabel.text_set("<b>Double-click</b> for contact options<br/><b>Longpress</b> for more information") 446 helplabel.text_set(
447 "<b>Double-click</b> for contact options<br/>"
448 "<b>Longpress</b> for more information"
449 )
398 450
399 avatar = Photo(self.parent.window) 451 avatar = Photo(self.parent.window)
400 avatar.size_set(100) 452 avatar.size_set(100)
@@ -422,11 +474,12 @@ class Account(object):
422 Tp.SubscriptionState.ASK: _("Waiting confirmation"), 474 Tp.SubscriptionState.ASK: _("Waiting confirmation"),
423 Tp.SubscriptionState.YES: _("Yes") 475 Tp.SubscriptionState.YES: _("Yes")
424 } 476 }
477 conn = contact.get_connection()
425 texts = { 478 texts = {
426 _("Identifier"): contact.get_identifier(), 479 _("Identifier"): contact.get_identifier(),
427 _("Status"): contact.get_presence_status().capitalize(), 480 _("Status"): contact.get_presence_status().capitalize(),
428 _("Message"): contact.get_presence_message().decode("utf-8"), 481 _("Message"): contact.get_presence_message().decode("utf-8"),
429 _("Account"): contact.get_connection().get_account().get_display_name(), 482 _("Account"): conn.get_account().get_display_name(),
430 _("Subscribed to"): states[contact.get_subscribe_state()], 483 _("Subscribed to"): states[contact.get_subscribe_state()],
431 _("Published to"): states[contact.get_publish_state()], 484 _("Published to"): states[contact.get_publish_state()],
432 _("Can send text"): textcap, 485 _("Can send text"): textcap,
@@ -458,22 +511,30 @@ class Account(object):
458 511
459 def add_group(self, group): 512 def add_group(self, group):
460 group_class = ContactGroup() 513 group_class = ContactGroup()
461 return self.parent.contact_list.item_append(group_class, group, None, ELM_GENLIST_ITEM_GROUP) 514 return self.parent.contact_list.item_append(
515 group_class, group, None, ELM_GENLIST_ITEM_GROUP
516 )
462 517
463 def _group_renamed(self, old_name, new_name, *args): 518 def _group_renamed(self, old_name, new_name, *args):
464 pass 519 pass
465 520
466 def _presence_changed(self, contact, presence, status, message, *args): 521 def _presence_changed(self, contact, presence, status, message, *args):
467 for item in contact.get_connection().contact_items[contact.get_handle()]: 522 conn = contact.get_connection()
523 for item in conn.contact_items[contact.get_handle()]:
468 #~ if status == "offline": 524 #~ if status == "offline":
469 #~ item.disabled_set(True) 525 #~ item.disabled_set(True)
470 #~ else: 526 #~ else:
471 #~ item.disabled_set(False) 527 #~ item.disabled_set(False)
472 item.update() 528 item.update()
473 notify(_("Presence changed"), _("%s is now %s").encode("utf-8") % (contact.get_alias(), status), "notification-information") 529 notify(
530 _("Presence changed"),
531 _("%s is now %s").encode("utf-8") % (contact.get_alias(), status),
532 "notification-information"
533 )
474 534
475 def _contact_changed(self, contact, signal): 535 def _contact_changed(self, contact, signal):
476 for item in contact.get_connection().contact_items[contact.get_handle()]: 536 conn = contact.get_connection()
537 for item in conn.contact_items[contact.get_handle()]:
477 item.update() 538 item.update()
478 539
479if __name__ == "__main__": 540if __name__ == "__main__":
@@ -481,10 +542,13 @@ if __name__ == "__main__":
481 542
482 # Log 543 # Log
483 if not os.path.exists(USER_PATH): 544 if not os.path.exists(USER_PATH):
484 os.mkdir(USER_PATH, 0700) 545 os.mkdir(USER_PATH, 0x700)
485 log = logging.getLogger("apathy.contacts") 546 log = logging.getLogger("apathy.contacts")
486 log.setLevel(logging.DEBUG) 547 log.setLevel(logging.DEBUG)
487 streamformatter = logging.Formatter("[%(levelname)s] in %(module)s line %(lineno)s (%(funcName)s): %(message)s") 548 streamformatter = logging.Formatter(
549 "[%(levelname)s] in %(module)s "
550 "line %(lineno)s (%(funcName)s): %(message)s"
551 )
488 handler_stream = logging.StreamHandler() 552 handler_stream = logging.StreamHandler()
489 handler_stream.setFormatter(streamformatter) 553 handler_stream.setFormatter(streamformatter)
490 log.addHandler(handler_stream) 554 log.addHandler(handler_stream)
diff --git a/apathy/Conversation.py b/apathy/Conversation.py
index f12a9be..8732de8 100644
--- a/apathy/Conversation.py
+++ b/apathy/Conversation.py
@@ -1,10 +1,8 @@
1#!/usr/bin/env python
2
3######################################################################### 1#########################################################################
4# # 2# #
5# Apathy - A telepathy based communications client for mobile platforms # 3# Apathy - A telepathy based communications client for mobile platforms #
6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> # 4# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> #
7# Copyright 2012 Kai Huuhko <kai@kaihuuhko.com> # 5# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com> #
8# # 6# #
9# This program is free software: you can redistribute it and/or modify # 7# This program is free software: you can redistribute it and/or modify #
10# it under the terms of the GNU General Public License as published by # 8# it under the terms of the GNU General Public License as published by #
@@ -27,30 +25,25 @@ from time import time
27from threading import Timer 25from threading import Timer
28import webbrowser 26import webbrowser
29 27
30try: 28from efl.evas import EVAS_ASPECT_CONTROL_VERTICAL
31 from evas import EVAS_ASPECT_CONTROL_VERTICAL 29from efl.elementary.box import Box
32 import elementary as elm 30from efl.elementary.scroller import Scroller
33 from elementary import Box, Scroller, Frame, Entry, Bubble, Button, \ 31from efl.elementary.frame import Frame
34 Check, Icon, InnerWindow, Web 32from efl.elementary.entry import Entry
35except: 33from efl.elementary.bubble import Bubble, ELM_BUBBLE_POS_TOP_LEFT, \
36 from efl.evas import EVAS_ASPECT_CONTROL_VERTICAL 34 ELM_BUBBLE_POS_TOP_RIGHT
37 from efl.elementary.box import Box 35from efl.elementary.button import Button
38 from efl.elementary.scroller import Scroller 36from efl.elementary.check import Check
39 from efl.elementary.frame import Frame 37from efl.elementary.icon import Icon
40 from efl.elementary.entry import Entry 38from efl.elementary.innerwindow import InnerWindow
41 from efl.elementary.bubble import Bubble, ELM_BUBBLE_POS_TOP_LEFT, \ 39from efl.elementary.web import Web
42 ELM_BUBBLE_POS_TOP_RIGHT
43 from efl.elementary.button import Button
44 from efl.elementary.check import Check
45 from efl.elementary.icon import Icon
46 from efl.elementary.innerwindow import InnerWindow
47 from efl.elementary.web import Web
48 40
49from Globals import * 41from Globals import *
50from Parser import parse 42from Parser import parse
51 43
52from gi.repository import TelepathyGLib as Tp 44from gi.repository import TelepathyGLib as Tp
53 45
46
54class Conversation(object): 47class Conversation(object):
55 def __init__(self, parent, channel): 48 def __init__(self, parent, channel):
56 self.parentwin = parent.window 49 self.parentwin = parent.window
@@ -69,7 +62,7 @@ class Conversation(object):
69 self.scroll = Scroller(self.box) 62 self.scroll = Scroller(self.box)
70 self.scroll.size_hint_weight_set(1.0, 1.0) 63 self.scroll.size_hint_weight_set(1.0, 1.0)
71 self.scroll.size_hint_align_set(-1.0, -1.0) 64 self.scroll.size_hint_align_set(-1.0, -1.0)
72 self.scroll.bounce_set(False,True) 65 self.scroll.bounce_set(False, True)
73 box.pack_end(self.scroll) 66 box.pack_end(self.scroll)
74 self.scroll.show() 67 self.scroll.show()
75 68
@@ -132,7 +125,7 @@ class Conversation(object):
132 def request_channel_error_cb(self, exception): 125 def request_channel_error_cb(self, exception):
133 log.error("Error" % (str(exception))) 126 log.error("Error" % (str(exception)))
134 127
135 def add_bubble(self, text, timestamp, sender, corner, avatar = None): 128 def add_bubble(self, text, timestamp, sender, corner, avatar=None):
136 timestr = datetime.fromtimestamp(timestamp).strftime("%c") 129 timestr = datetime.fromtimestamp(timestamp).strftime("%c")
137 bb = Bubble(self.box) 130 bb = Bubble(self.box)
138 bb.pos_set(corner) 131 bb.pos_set(corner)
diff --git a/apathy/ErrorDialog.py b/apathy/ErrorDialog.py
index cc54b94..28a9510 100644
--- a/apathy/ErrorDialog.py
+++ b/apathy/ErrorDialog.py
@@ -1,10 +1,8 @@
1#!/usr/bin/env python
2
3######################################################################### 1#########################################################################
4# # 2# #
5# Apathy - A telepathy based communications client for mobile platforms # 3# Apathy - A telepathy based communications client for mobile platforms #
6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> # 4# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> #
7# Copyright 2012 Kai Huuhko <kai@kaihuuhko.com> # 5# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com> #
8# # 6# #
9# This program is free software: you can redistribute it and/or modify # 7# This program is free software: you can redistribute it and/or modify #
10# it under the terms of the GNU General Public License as published by # 8# it under the terms of the GNU General Public License as published by #
diff --git a/apathy/FileTransfer.py b/apathy/FileTransfer.py
index 1c64540..6a2c60a 100644
--- a/apathy/FileTransfer.py
+++ b/apathy/FileTransfer.py
@@ -1,10 +1,8 @@
1#!/usr/bin/env python
2
3######################################################################### 1#########################################################################
4# # 2# #
5# Apathy - A telepathy based communications client for mobile platforms # 3# Apathy - A telepathy based communications client for mobile platforms #
6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> # 4# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> #
7# Copyright 2012 Kai Huuhko <kai@kaihuuhko.com> # 5# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com> #
8# # 6# #
9# This program is free software: you can redistribute it and/or modify # 7# This program is free software: you can redistribute it and/or modify #
10# it under the terms of the GNU General Public License as published by # 8# it under the terms of the GNU General Public License as published by #
@@ -29,6 +27,6 @@ from gi.repository import TelepathyGLib as Tp
29class FileTransfer(Box): 27class FileTransfer(Box):
30 def __init__(self, parent, channel): 28 def __init__(self, parent, channel):
31 Box.__init__(self, parent) 29 Box.__init__(self, parent)
32 30
33 channel.connect("notify::state", self.state_changed) 31 channel.connect("notify::state", self.state_changed)
34 32
diff --git a/apathy/Globals.py b/apathy/Globals.py
index 89c80bd..3ec85b1 100644
--- a/apathy/Globals.py
+++ b/apathy/Globals.py
@@ -1,9 +1,8 @@
1
2######################################################################### 1#########################################################################
3# # 2# #
4# Apathy - A telepathy based communications client for mobile platforms # 3# Apathy - A telepathy based communications client for mobile platforms #
5# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> # 4# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> #
6# Copyright 2012 Kai Huuhko <kai@kaihuuhko.com> # 5# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com> #
7# # 6# #
8# This program is free software: you can redistribute it and/or modify # 7# This program is free software: you can redistribute it and/or modify #
9# it under the terms of the GNU General Public License as published by # 8# it under the terms of the GNU General Public License as published by #
@@ -35,7 +34,7 @@ else:
35 n = LibNotify.Notification.new(title, msg, importance) 34 n = LibNotify.Notification.new(title, msg, importance)
36 n.set_timeout(3000) 35 n.set_timeout(3000)
37 n.show() 36 n.show()
38 37
39try: 38try:
40 import ecore.x 39 import ecore.x
41except ImportError: 40except ImportError:
@@ -57,7 +56,7 @@ if not USER_PATH:
57 USER_PATH = os.path.expanduser(os.path.join("~", ".apathy")) 56 USER_PATH = os.path.expanduser(os.path.join("~", ".apathy"))
58if not IMAGE_PATH: 57if not IMAGE_PATH:
59 IMAGE_PATH = os.path.join(USER_PATH, "images") 58 IMAGE_PATH = os.path.join(USER_PATH, "images")
60 59
61def get_conf(): 60def get_conf():
62 conf = ConfigParser.SafeConfigParser() 61 conf = ConfigParser.SafeConfigParser()
63 conf_path = os.path.join(USER_PATH, "apathy.conf") 62 conf_path = os.path.join(USER_PATH, "apathy.conf")
diff --git a/apathy/Handler.py b/apathy/Handler.py
index d8e21a6..cbe344d 100644
--- a/apathy/Handler.py
+++ b/apathy/Handler.py
@@ -4,7 +4,7 @@
4# # 4# #
5# Apathy - A telepathy based communications client for mobile platforms # 5# Apathy - A telepathy based communications client for mobile platforms #
6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> # 6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> #
7# Copyright 2012 Kai Huuhko <kai@kaihuuhko.com> # 7# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com> #
8# # 8# #
9# This program is free software: you can redistribute it and/or modify # 9# This program is free software: you can redistribute it and/or modify #
10# it under the terms of the GNU General Public License as published by # 10# it under the terms of the GNU General Public License as published by #
@@ -25,17 +25,12 @@ import os.path
25import gettext 25import gettext
26import logging 26import logging
27 27
28try: 28from efl import ecore, elementary as elm
29 import ecore, elementary as elm 29from efl.elementary.window import StandardWindow
30 from evas import EVAS_ASPECT_CONTROL_VERTICAL 30from efl.elementary.box import Box
31except ImportError: 31from efl.elementary.hoversel import Hoversel, ELM_ICON_FILE
32 from efl import ecore, elementary as elm 32from efl.elementary.naviframe import Naviframe
33 from efl.evas import EVAS_ASPECT_CONTROL_VERTICAL 33from efl.elementary.button import Button
34 from efl.elementary.window import StandardWindow
35 from efl.elementary.box import Box
36 from efl.elementary.hoversel import Hoversel, ELM_ICON_FILE
37 from efl.elementary.naviframe import Naviframe
38 from efl.elementary.button import Button
39 34
40from Globals import * 35from Globals import *
41from Conversation import Conversation 36from Conversation import Conversation
@@ -44,6 +39,7 @@ from gi.repository import GObject
44GObject.threads_init() 39GObject.threads_init()
45from gi.repository import TelepathyGLib as Tp 40from gi.repository import TelepathyGLib as Tp
46 41
42
47class Handler(object): 43class Handler(object):
48 def __init__(self): 44 def __init__(self):
49 global log 45 global log
@@ -110,13 +106,13 @@ class Handler(object):
110 ]) 106 ])
111 107
112 self.handler = Tp.SimpleHandler.new_with_factory( 108 self.handler = Tp.SimpleHandler.new_with_factory(
113 factory, #Factory/am/tpdbus 109 factory, # Factory/am/tpdbus
114 False, #bypass approval 110 False, # bypass approval
115 False, #requests 111 False, # requests
116 'Apathy.Handler', #name 112 'Apathy.Handler', # name
117 False, #uniquify 113 False, # uniquify
118 self.channel_handler, #handler func 114 self.channel_handler, # handler func
119 None, #data 115 None, # data
120 ) 116 )
121 self.handler.add_handler_filter( 117 self.handler.add_handler_filter(
122 { 118 {
@@ -129,8 +125,16 @@ class Handler(object):
129 ]) 125 ])
130 self.handler.register() 126 self.handler.register()
131 127
132 def channel_handler(self, handler, account, connection, channels, requests, user_action_time, context, user_data): 128 def channel_handler(
133 log.debug("%s %s %s %s %s %s %s %s" % (handler, account, connection, channels, requests, user_action_time, context, user_data)) 129 self, handler, account, connection, channels, requests,
130 user_action_time, context, user_data
131 ):
132 log.debug(
133 "%s %s %s %s %s %s %s %s" % (
134 handler, account, connection, channels, requests,
135 user_action_time, context, user_data
136 )
137 )
134 for c in channels: 138 for c in channels:
135 log.debug(c.get_handle()) 139 log.debug(c.get_handle())
136 140
@@ -142,11 +146,14 @@ class Handler(object):
142 identifier = channels[0].get_identifier() 146 identifier = channels[0].get_identifier()
143 147
144 try: 148 try:
145 avatar = channels[0].get_target_contact().get_avatar_file().get_path() 149 contact = channels[0].get_target_contact()
146 except: 150 avatar = contact.get_avatar_file().get_path()
151 except Exception:
147 avatar = None 152 avatar = None
148 153
149 box_of_channels.list_item = self.chatlist.item_add(identifier, avatar, ELM_ICON_FILE, self.selected, box_of_channels) 154 box_of_channels.list_item = self.chatlist.item_add(
155 identifier, avatar, ELM_ICON_FILE, self.selected, box_of_channels
156 )
150 157
151 self.pager.item_simple_push(box_of_channels) 158 self.pager.item_simple_push(box_of_channels)
152 self.window.resize(480, 640) 159 self.window.resize(480, 640)
@@ -173,6 +180,7 @@ class Handler(object):
173 def quit(self, *args): 180 def quit(self, *args):
174 elm.exit() 181 elm.exit()
175 182
183
176class Channels(Box): 184class Channels(Box):
177 def __init__(self, parent, channels): 185 def __init__(self, parent, channels):
178 Box.__init__(self, parent.window) 186 Box.__init__(self, parent.window)
@@ -184,7 +192,11 @@ class Channels(Box):
184 192
185 for channel in channels: 193 for channel in channels:
186 if isinstance(channel, Tp.TextChannel): 194 if isinstance(channel, Tp.TextChannel):
187 log.info("Handling text channel with %s" % (channel.get_identifier())) 195 log.info(
196 "Handling text channel with %s" % (
197 channel.get_identifier()
198 )
199 )
188 conversation = Conversation(parent, channel) 200 conversation = Conversation(parent, channel)
189 self.pack_end(conversation.box) 201 self.pack_end(conversation.box)
190 self.channels.append(channel) 202 self.channels.append(channel)
@@ -196,10 +208,13 @@ if __name__ == "__main__":
196 208
197 # Log 209 # Log
198 if not os.path.exists(USER_PATH): 210 if not os.path.exists(USER_PATH):
199 os.mkdir(USER_PATH, 0700) 211 os.mkdir(USER_PATH, 0x700)
200 log = logging.getLogger("apathy.handler") 212 log = logging.getLogger("apathy.handler")
201 log.setLevel(logging.DEBUG) 213 log.setLevel(logging.DEBUG)
202 streamformatter = logging.Formatter("[%(levelname)s] in %(module)s line %(lineno)s (%(funcName)s): %(message)s") 214 streamformatter = logging.Formatter(
215 "[%(levelname)s] in %(module)s "
216 "line %(lineno)s (%(funcName)s): %(message)s"
217 )
203 handler_stream = logging.StreamHandler() 218 handler_stream = logging.StreamHandler()
204 handler_stream.setFormatter(streamformatter) 219 handler_stream.setFormatter(streamformatter)
205 log.addHandler(handler_stream) 220 log.addHandler(handler_stream)
diff --git a/apathy/NewAccount.py b/apathy/NewAccount.py
index f650c7c..32bdf71 100644
--- a/apathy/NewAccount.py
+++ b/apathy/NewAccount.py
@@ -1,10 +1,8 @@
1#!/usr/bin/env python
2
3######################################################################### 1#########################################################################
4# # 2# #
5# Apathy - A telepathy based communications client for mobile platforms # 3# Apathy - A telepathy based communications client for mobile platforms #
6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> # 4# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> #
7# Copyright 2012 Kai Huuhko <kai@kaihuuhko.com> # 5# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com> #
8# # 6# #
9# This program is free software: you can redistribute it and/or modify # 7# This program is free software: you can redistribute it and/or modify #
10# it under the terms of the GNU General Public License as published by # 8# it under the terms of the GNU General Public License as published by #
@@ -32,8 +30,8 @@ class NewAccount(InnerWindow):
32 def __init__(self, parent, am): 30 def __init__(self, parent, am):
33 self.parentwin = parent 31 self.parentwin = parent
34 InnerWindow.__init__(self, parent) 32 InnerWindow.__init__(self, parent)
35 33
36 global log 34 global log
37 log = get_log() 35 log = get_log()
38 36
39 self.box = box = Box(self) 37 self.box = box = Box(self)
diff --git a/apathy/NewContact.py b/apathy/NewContact.py
index 3cc3cfc..67a324b 100644
--- a/apathy/NewContact.py
+++ b/apathy/NewContact.py
@@ -1,10 +1,8 @@
1#!/usr/bin/env python
2
3######################################################################### 1#########################################################################
4# # 2# #
5# Apathy - A telepathy based communications client for mobile platforms # 3# Apathy - A telepathy based communications client for mobile platforms #
6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> # 4# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> #
7# Copyright 2012 Kai Huuhko <kai@kaihuuhko.com> # 5# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com> #
8# # 6# #
9# This program is free software: you can redistribute it and/or modify # 7# This program is free software: you can redistribute it and/or modify #
10# it under the terms of the GNU General Public License as published by # 8# it under the terms of the GNU General Public License as published by #
@@ -34,10 +32,10 @@ class NewContact(InnerWindow):
34 def __init__(self, parent, am): 32 def __init__(self, parent, am):
35 self.parentwin = parent 33 self.parentwin = parent
36 InnerWindow.__init__(self, parent) 34 InnerWindow.__init__(self, parent)
37 35
38 global log 36 global log
39 log = get_log() 37 log = get_log()
40 38
41 self.box = box = Box(self) 39 self.box = box = Box(self)
42 40
43 acc_sel = Hoversel(self) 41 acc_sel = Hoversel(self)
@@ -46,27 +44,27 @@ class NewContact(InnerWindow):
46 acc_sel.size_hint_align_set(-1.0, 0.0) 44 acc_sel.size_hint_align_set(-1.0, 0.0)
47 box.pack_end(acc_sel) 45 box.pack_end(acc_sel)
48 acc_sel.show() 46 acc_sel.show()
49 47
50 self.btn_box = btn_box = Box(self) 48 self.btn_box = btn_box = Box(self)
51 btn_box.horizontal_set(True) 49 btn_box.horizontal_set(True)
52 btn_box.size_hint_weight_set(1.0, 0.0) 50 btn_box.size_hint_weight_set(1.0, 0.0)
53 btn_box.size_hint_align_set(-1.0, 0.0) 51 btn_box.size_hint_align_set(-1.0, 0.0)
54 box.pack_end(btn_box) 52 box.pack_end(btn_box)
55 btn_box.show() 53 btn_box.show()
56 54
57 xbtn = Button(self) 55 xbtn = Button(self)
58 xbtn.text_set(_("Close")) 56 xbtn.text_set(_("Close"))
59 #xbtn.callback_clicked_add(lambda x: parent.pager.content_pop()) 57 #xbtn.callback_clicked_add(lambda x: parent.pager.content_pop())
60 xbtn.callback_clicked_add(lambda x: self.delete()) 58 xbtn.callback_clicked_add(lambda x: self.delete())
61 btn_box.pack_end(xbtn) 59 btn_box.pack_end(xbtn)
62 xbtn.show() 60 xbtn.show()
63 61
64 self.content_set(box) 62 self.content_set(box)
65 self.show() 63 self.show()
66 64
67 for account in am.get_valid_accounts(): 65 for account in am.get_valid_accounts():
68 acc_sel.item_add(account.get_display_name(), account.get_icon_name(), ELM_ICON_STANDARD, self.selected, account) 66 acc_sel.item_add(account.get_display_name(), account.get_icon_name(), ELM_ICON_STANDARD, self.selected, account)
69 67
70 def selected(self, acc_sel, item, account): 68 def selected(self, acc_sel, item, account):
71 frame = Frame(self) 69 frame = Frame(self)
72 frame.text_set("Identifier of contact") 70 frame.text_set("Identifier of contact")
@@ -78,7 +76,7 @@ class NewContact(InnerWindow):
78 self.box.pack_before(frame, self.btn_box) 76 self.box.pack_before(frame, self.btn_box)
79 entry.show() 77 entry.show()
80 frame.show() 78 frame.show()
81 79
82 go = Button(self) 80 go = Button(self)
83 go.callback_clicked_add(self.add_go, entry, account) 81 go.callback_clicked_add(self.add_go, entry, account)
84 go.text_set(_("Add")) 82 go.text_set(_("Add"))
@@ -88,7 +86,7 @@ class NewContact(InnerWindow):
88 def add_go(self, obj, entry, account): 86 def add_go(self, obj, entry, account):
89 identifier = entry.entry_get() 87 identifier = entry.entry_get()
90 account.request_presence_async(Tp.ConnectionPresenceType.AVAILABLE, "available", "", self.online, identifier) 88 account.request_presence_async(Tp.ConnectionPresenceType.AVAILABLE, "available", "", self.online, identifier)
91 89
92 def online(self, account, result, identifier, *args): 90 def online(self, account, result, identifier, *args):
93 account.get_connection().get_contacts_by_id( 91 account.get_connection().get_contacts_by_id(
94 ( 92 (
diff --git a/apathy/Parser.py b/apathy/Parser.py
index 145fcf5..bcef6de 100644
--- a/apathy/Parser.py
+++ b/apathy/Parser.py
@@ -1,10 +1,8 @@
1#!/usr/bin/env python
2
3######################################################################### 1#########################################################################
4# # 2# #
5# Apathy - A telepathy based communications client for mobile platforms # 3# Apathy - A telepathy based communications client for mobile platforms #
6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> # 4# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> #
7# Copyright 2012 Kai Huuhko <kai@kaihuuhko.com> # 5# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com> #
8# # 6# #
9# This program is free software: you can redistribute it and/or modify # 7# This program is free software: you can redistribute it and/or modify #
10# it under the terms of the GNU General Public License as published by # 8# it under the terms of the GNU General Public License as published by #
@@ -23,21 +21,22 @@
23 21
24import re 22import re
25 23
24
26def parse(text, urls=True, emotes=True): 25def parse(text, urls=True, emotes=True):
27 text = text.replace("<br/>", "\n") 26 text = text.replace("<br/>", "\n")
28 text = text.replace("&", "&amp;") 27 text = text.replace("&", "&amp;")
29 text = text.replace("<", "&lt;") 28 text = text.replace("<", "&lt;")
30 text = text.replace(">", "&gt;") 29 text = text.replace(">", "&gt;")
31 30
32 if urls: 31 if urls:
33 #URLs 32 #URLs
34 p = re.compile(r'(\b\S*://\S*\b)') 33 p = re.compile(r'(\b\S*://\S*\b)')
35 text = p.sub(r'<a href=url:\1>\1</a>', text) 34 text = p.sub(r'<a href=url:\1>\1</a>', text)
36 35
37 #mail 36 #mail
38 p = re.compile(r'(\b(\.|\w)*@\w*(\.|\w)*\b)') 37 p = re.compile(r'(\b(\.|\w)*@\w*(\.|\w)*\b)')
39 text = p.sub(r'<a href=mailto:\1>\1</a>', text) 38 text = p.sub(r'<a href=mailto:\1>\1</a>', text)
40 39
41 if emotes: 40 if emotes:
42 #emoticons 41 #emoticons
43 emoticons = { 42 emoticons = {
@@ -128,7 +127,11 @@ def parse(text, urls=True, emotes=True):
128 } 127 }
129 for k, v in emoticons.iteritems(): 128 for k, v in emoticons.iteritems():
130 p = re.compile(re.escape(k)) 129 p = re.compile(re.escape(k))
131 text = p.sub(r'<item size=32x32 vsize=full href=emoticon/%s></item>' % v, text) 130 text = p.sub(
132 131 r'<item size=32x32 vsize=full href=emoticon/%s></item>' % (
132 v, text
133 )
134 )
135
133 text = text.replace("\n", "<br/>") 136 text = text.replace("\n", "<br/>")
134 return text 137 return text
diff --git a/apathy/PresenceEditor.py b/apathy/PresenceEditor.py
index fbd244d..d0dad2c 100644
--- a/apathy/PresenceEditor.py
+++ b/apathy/PresenceEditor.py
@@ -1,10 +1,8 @@
1#!/usr/bin/env python
2
3######################################################################### 1#########################################################################
4# # 2# #
5# Apathy - A telepathy based communications client for mobile platforms # 3# Apathy - A telepathy based communications client for mobile platforms #
6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> # 4# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> #
7# Copyright 2012 Kai Huuhko <kai@kaihuuhko.com> # 5# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com> #
8# # 6# #
9# This program is free software: you can redistribute it and/or modify # 7# This program is free software: you can redistribute it and/or modify #
10# it under the terms of the GNU General Public License as published by # 8# it under the terms of the GNU General Public License as published by #
@@ -21,15 +19,13 @@
21# # 19# #
22######################################################################### 20#########################################################################
23 21
24try: 22from efl.elementary.box import Box
25 from elementary import Box, Frame, Button 23from efl.elementary.frame import Frame
26except ImportError: 24from efl.elementary.button import Button
27 from efl.elementary.box import Box
28 from efl.elementary.frame import Frame
29 from efl.elementary.button import Button
30 25
31from Globals import * 26from Globals import *
32 27
28
33class PresenceEditor(object): 29class PresenceEditor(object):
34 def __init__(self, parent, pager): 30 def __init__(self, parent, pager):
35 self.parentwin = parent 31 self.parentwin = parent
@@ -40,10 +36,10 @@ class PresenceEditor(object):
40 self.conf = get_conf() 36 self.conf = get_conf()
41 messages = self.conf.items("StatusMessages") 37 messages = self.conf.items("StatusMessages")
42 38
43 self.box = box = elm.Box(parent) 39 self.box = box = Box(parent)
44 40
45 for status, message in messages: 41 for status, message in messages:
46 frame = elm.Frame(parent) 42 frame = Frame(parent)
47 frame.size_hint_weight_set(1.0, 0.0) 43 frame.size_hint_weight_set(1.0, 0.0)
48 frame.size_hint_align_set(-1.0, -1.0) 44 frame.size_hint_align_set(-1.0, -1.0)
49 frame.text_set(status.capitalize()) 45 frame.text_set(status.capitalize())
@@ -57,12 +53,12 @@ class PresenceEditor(object):
57 entry.show() 53 entry.show()
58 frame.show() 54 frame.show()
59 55
60 box1 = elm.Box(parent) 56 box1 = Box(parent)
61 box1.horizontal_set(True) 57 box1.horizontal_set(True)
62 box1.size_hint_weight_set(1.0, 0.0) 58 box1.size_hint_weight_set(1.0, 0.0)
63 box1.size_hint_align_set(-1.0, 0.0) 59 box1.size_hint_align_set(-1.0, 0.0)
64 60
65 save_btn = elm.Button(parent) 61 save_btn = Button(parent)
66 save_btn.size_hint_weight_set(1.0, 0.0) 62 save_btn.size_hint_weight_set(1.0, 0.0)
67 save_btn.size_hint_align_set(-1.0, 0.0) 63 save_btn.size_hint_align_set(-1.0, 0.0)
68 save_btn.text_set(_("Save")) 64 save_btn.text_set(_("Save"))
@@ -70,7 +66,7 @@ class PresenceEditor(object):
70 box1.pack_end(save_btn) 66 box1.pack_end(save_btn)
71 save_btn.show() 67 save_btn.show()
72 68
73 xbtn = elm.Button(parent) 69 xbtn = Button(parent)
74 xbtn.size_hint_weight_set(1.0, 0.0) 70 xbtn.size_hint_weight_set(1.0, 0.0)
75 xbtn.size_hint_align_set(-1.0, 0.0) 71 xbtn.size_hint_align_set(-1.0, 0.0)
76 xbtn.text_set(_("Close")) 72 xbtn.text_set(_("Close"))
diff --git a/apathy/PresenceWidget.py b/apathy/PresenceWidget.py
index be00aaa..87d646d 100644
--- a/apathy/PresenceWidget.py
+++ b/apathy/PresenceWidget.py
@@ -4,7 +4,7 @@
4# # 4# #
5# Apathy - A telepathy based communications client for mobile platforms # 5# Apathy - A telepathy based communications client for mobile platforms #
6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> # 6# Copyright (C) 2009 Michael Sheldon <mike@mikeasoft.com> #
7# Copyright 2012 Kai Huuhko <kai@kaihuuhko.com> # 7# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com> #
8# # 8# #
9# This program is free software: you can redistribute it and/or modify # 9# This program is free software: you can redistribute it and/or modify #
10# it under the terms of the GNU General Public License as published by # 10# it under the terms of the GNU General Public License as published by #
@@ -24,9 +24,8 @@
24import gettext 24import gettext
25import logging 25import logging
26 26
27import ecore 27from efl import ecore
28from elementary import * 28from efl import elementary as elm
29from evas import EVAS_ASPECT_CONTROL_VERTICAL
30 29
31from Globals import * 30from Globals import *
32from PresenceEditor import PresenceEditor 31from PresenceEditor import PresenceEditor
@@ -35,10 +34,11 @@ from gi.repository import GObject
35GObject.threads_init() 34GObject.threads_init()
36from gi.repository import TelepathyGLib as Tp 35from gi.repository import TelepathyGLib as Tp
37 36
37
38class PresenceWidget(Window): 38class PresenceWidget(Window):
39 def __init__(self): 39 def __init__(self):
40 Window.__init__(self, "presence", ELM_WIN_BASIC) 40 Window.__init__(self, "presence", ELM_WIN_BASIC)
41 41
42 global log 42 global log
43 log = logging.getLogger("apathy.presence") 43 log = logging.getLogger("apathy.presence")
44 44
@@ -50,25 +50,27 @@ class PresenceWidget(Window):
50 bg.size_hint_weight_set(1.0, 1.0) 50 bg.size_hint_weight_set(1.0, 1.0)
51 self.resize_object_add(bg) 51 self.resize_object_add(bg)
52 bg.show() 52 bg.show()
53 53
54 self.presence_list = presence_list = Hoversel(self) 54 self.presence_list = presence_list = Hoversel(self)
55 presence_list.size_hint_weight_set(1.0, 1.0) 55 presence_list.size_hint_weight_set(1.0, 1.0)
56 presence_list.size_hint_align_set(-1.0, 0.0) 56 presence_list.size_hint_align_set(-1.0, 0.0)
57 self._populate_presence_list() 57 self._populate_presence_list()
58 58
59 box = Box(self) 59 box = Box(self)
60 box.size_hint_weight_set(1.0, 1.0) 60 box.size_hint_weight_set(1.0, 1.0)
61 self.resize_object_add(box) 61 self.resize_object_add(box)
62 box.pack_end(presence_list) 62 box.pack_end(presence_list)
63 box.show() 63 box.show()
64 presence_list.show() 64 presence_list.show()
65 65
66 self.resize(300, 400) 66 self.resize(300, 400)
67 self.show() 67 self.show()
68 68
69 self.am = am = Tp.AccountManager.dup() 69 self.am = am = Tp.AccountManager.dup()
70 factory = am.get_factory() 70 factory = am.get_factory()
71 factory.add_account_features([Tp.Account.get_feature_quark_connection()]) 71 factory.add_account_features(
72 [Tp.Account.get_feature_quark_connection()]
73 )
72 factory.add_connection_features([ 74 factory.add_connection_features([
73 Tp.Connection.get_feature_quark_contact_list(), 75 Tp.Connection.get_feature_quark_contact_list(),
74 Tp.Connection.get_feature_quark_contact_groups(), 76 Tp.Connection.get_feature_quark_contact_groups(),
@@ -76,7 +78,7 @@ class PresenceWidget(Window):
76 ]) 78 ])
77 79
78 am.prepare_async(None, self._am_ready, None) 80 am.prepare_async(None, self._am_ready, None)
79 81
80 def _am_ready(self, am, result, error): 82 def _am_ready(self, am, result, error):
81 am.prepare_finish(result) 83 am.prepare_finish(result)
82 am.connect("most-available-presence-changed", self.presence_changed) 84 am.connect("most-available-presence-changed", self.presence_changed)
@@ -97,7 +99,7 @@ class PresenceWidget(Window):
97 "unknown": (7, False, False), 99 "unknown": (7, False, False),
98 "error": (8, False, False), 100 "error": (8, False, False),
99 } 101 }
100 102
101 conf = get_conf() 103 conf = get_conf()
102 104
103 for status, spec in presences.iteritems(): 105 for status, spec in presences.iteritems():
@@ -107,7 +109,10 @@ class PresenceWidget(Window):
107 try: 109 try:
108 message = conf.get("StatusMessages", status) 110 message = conf.get("StatusMessages", status)
109 except: 111 except:
110 log.exception("Status message for status %s not found in configuration file." % (status)) 112 log.exception(
113 "Status message for status %s not found in "
114 "configuration file." % (status)
115 )
111 message = "" 116 message = ""
112 if status == "xa": 117 if status == "xa":
113 icon = "user-away-extended" 118 icon = "user-away-extended"
@@ -118,7 +123,7 @@ class PresenceWidget(Window):
118 else: 123 else:
119 icon = "user-"+status 124 icon = "user-"+status
120 self.presence_list.item_add(status.capitalize(), icon, ELM_ICON_STANDARD, self._set_presence, presence, status, message) 125 self.presence_list.item_add(status.capitalize(), icon, ELM_ICON_STANDARD, self._set_presence, presence, status, message)
121 126
122 #self.presence_list.item_add(_("Edit")+"...", None, 0, self._edit_presences) 127 #self.presence_list.item_add(_("Edit")+"...", None, 0, self._edit_presences)
123 128
124 def _set_presence(self, obj, event, presence, status, message=""): 129 def _set_presence(self, obj, event, presence, status, message=""):
@@ -127,13 +132,13 @@ class PresenceWidget(Window):
127 def _edit_presences(self, obj, event, *args): 132 def _edit_presences(self, obj, event, *args):
128 editor = PresenceEditor(self) 133 editor = PresenceEditor(self)
129 self.pager.item_simple_push(editor) 134 self.pager.item_simple_push(editor)
130 135
131 def presence_changed(self, am, presence, status, message): 136 def presence_changed(self, am, presence, status, message):
132 self.presence_list.text_set(status.capitalize()) 137 self.presence_list.text_set(status.capitalize())
133 ic = Icon(self) 138 ic = Icon(self)
134 ic.standard_set("user-"+status) 139 ic.standard_set("user-"+status)
135 self.presence_list.content_set(ic) 140 self.presence_list.content_set(ic)
136 141
137 def quit(self, *args): 142 def quit(self, *args):
138 exit() 143 exit()
139 144
@@ -142,18 +147,21 @@ if __name__ == "__main__":
142 147
143 # Log 148 # Log
144 if not os.path.exists(USER_PATH): 149 if not os.path.exists(USER_PATH):
145 os.mkdir(USER_PATH, 0700) 150 os.mkdir(USER_PATH, 0x700)
146 log = logging.getLogger("apathy.presence") 151 log = logging.getLogger("apathy.presence")
147 log.setLevel(logging.DEBUG) 152 log.setLevel(logging.DEBUG)
148 streamformatter = logging.Formatter("[%(levelname)s] in %(module)s line %(lineno)s (%(funcName)s): %(message)s") 153 streamformatter = logging.Formatter(
154 "[%(levelname)s] in %(module)s "
155 "line %(lineno)s (%(funcName)s): %(message)s"
156 )
149 handler_stream = logging.StreamHandler() 157 handler_stream = logging.StreamHandler()
150 handler_stream.setFormatter(streamformatter) 158 handler_stream.setFormatter(streamformatter)
151 log.addHandler(handler_stream) 159 log.addHandler(handler_stream)
152 160
153 init() 161 elm.init()
154 162
155 ecore.main_loop_glib_integrate() 163 ecore.main_loop_glib_integrate()
156 presence = PresenceWidget() 164 presence = PresenceWidget()
157 165
158 run() 166 elm.run()
159 shutdown() 167 elm.shutdown()
diff --git a/bin/apathy-accounts b/bin/apathy-accounts
index dd92609..d5d7ef0 100755
--- a/bin/apathy-accounts
+++ b/bin/apathy-accounts
@@ -1,20 +1,16 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2import os 2import os
3import sys
4import logging 3import logging
5import gettext 4import gettext
6 5
7try: 6from efl import ecore, elementary as elm
8 import ecore, elementary as elm
9except ImportError:
10 from efl import ecore, elementary as elm
11 7
12ENV_PATHS = {"APATHY_IMAGE_PATH" : "/usr/share/apathy/images/"} 8ENV_PATHS = {"APATHY_IMAGE_PATH": "/usr/share/apathy/images/"}
13 9
14#must set variables before importing Globals because it requires them 10#must set variables before importing Globals because it requires them
15for var, path in ENV_PATHS.iteritems(): 11for var, path in ENV_PATHS.iteritems():
16 #if it is not already set, set the enviroment variable. 12 #if it is not already set, set the enviroment variable.
17 os.environ.setdefault(var, path) 13 os.environ.setdefault(var, path)
18 14
19import apathy.Accounts as Accounts 15import apathy.Accounts as Accounts
20from apathy.Globals import * 16from apathy.Globals import *
@@ -23,11 +19,16 @@ gettext.install("apathy", "/usr/share/locale", unicode=1)
23 19
24# Log 20# Log
25if not os.path.exists(USER_PATH): 21if not os.path.exists(USER_PATH):
26 os.mkdir(USER_PATH, 0700) 22 os.mkdir(USER_PATH, 0x700)
27log = logging.getLogger("apathy.accounts") 23log = logging.getLogger("apathy.accounts")
28log.setLevel(logging.DEBUG) 24log.setLevel(logging.DEBUG)
29fileformatter = logging.Formatter("[%(created)s] [%(levelname)s] in %(module)s line %(lineno)s (%(funcName)s): %(message)s") 25fileformatter = logging.Formatter(
30handler_file = logging.FileHandler(os.path.join(USER_PATH, "apathy-accounts.log"), "w") 26 "[%(created)s] [%(levelname)s] in %(module)s "
27 "line %(lineno)s (%(funcName)s): %(message)s"
28 )
29handler_file = logging.FileHandler(
30 os.path.join(USER_PATH, "apathy-accounts.log"), "w"
31 )
31handler_file.setFormatter(fileformatter) 32handler_file.setFormatter(fileformatter)
32handler_file.setLevel(logging.ERROR) 33handler_file.setLevel(logging.ERROR)
33log.addHandler(handler_file) 34log.addHandler(handler_file)
diff --git a/bin/apathy-approver b/bin/apathy-approver
index 5924d97..ba5501f 100755
--- a/bin/apathy-approver
+++ b/bin/apathy-approver
@@ -1,20 +1,16 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2import os 2import os
3import sys
4import logging 3import logging
5import gettext 4import gettext
6 5
7try: 6from efl import ecore, elementary as elm
8 import ecore, elementary as elm
9except ImportError:
10 from efl import ecore, elementary as elm
11 7
12ENV_PATHS = {"APATHY_IMAGE_PATH" : "/usr/share/apathy/images/"} 8ENV_PATHS = {"APATHY_IMAGE_PATH": "/usr/share/apathy/images/"}
13 9
14#must set variables before importing Globals because it requires them 10#must set variables before importing Globals because it requires them
15for var, path in ENV_PATHS.iteritems(): 11for var, path in ENV_PATHS.iteritems():
16 #if it is not already set, set the enviroment variable. 12 #if it is not already set, set the enviroment variable.
17 os.environ.setdefault(var, path) 13 os.environ.setdefault(var, path)
18 14
19import apathy.Approver as Approver 15import apathy.Approver as Approver
20from apathy.Globals import * 16from apathy.Globals import *
@@ -23,11 +19,16 @@ gettext.install("apathy", "/usr/share/locale", unicode=1)
23 19
24# Log 20# Log
25if not os.path.exists(USER_PATH): 21if not os.path.exists(USER_PATH):
26 os.mkdir(USER_PATH, 0700) 22 os.mkdir(USER_PATH, 0x700)
27log = logging.getLogger("apathy.approver") 23log = logging.getLogger("apathy.approver")
28log.setLevel(logging.DEBUG) 24log.setLevel(logging.DEBUG)
29fileformatter = logging.Formatter("[%(created)s] [%(levelname)s] in %(module)s line %(lineno)s (%(funcName)s): %(message)s") 25fileformatter = logging.Formatter(
30handler_file = logging.FileHandler(os.path.join(USER_PATH, "apathy-approver.log"), "w") 26 "[%(created)s] [%(levelname)s] in %(module)s "
27 "line %(lineno)s (%(funcName)s): %(message)s"
28 )
29handler_file = logging.FileHandler(
30 os.path.join(USER_PATH, "apathy-approver.log"), "w"
31 )
31handler_file.setFormatter(fileformatter) 32handler_file.setFormatter(fileformatter)
32handler_file.setLevel(logging.ERROR) 33handler_file.setLevel(logging.ERROR)
33log.addHandler(handler_file) 34log.addHandler(handler_file)
diff --git a/bin/apathy-contacts b/bin/apathy-contacts
index 921a66b..6b5bde5 100755
--- a/bin/apathy-contacts
+++ b/bin/apathy-contacts
@@ -1,20 +1,16 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2import os 2import os
3import sys
4import logging 3import logging
5import gettext 4import gettext
6 5
7try: 6from efl import ecore, elementary as elm
8 import ecore, elementary as elm
9except ImportError:
10 from efl import ecore, elementary as elm
11 7
12ENV_PATHS = {"APATHY_IMAGE_PATH" : "/usr/share/apathy/images/"} 8ENV_PATHS = {"APATHY_IMAGE_PATH": "/usr/share/apathy/images/"}
13 9
14#must set variables before importing Globals because it requires them 10#must set variables before importing Globals because it requires them
15for var, path in ENV_PATHS.iteritems(): 11for var, path in ENV_PATHS.iteritems():
16 #if it is not already set, set the enviroment variable. 12 #if it is not already set, set the enviroment variable.
17 os.environ.setdefault(var, path) 13 os.environ.setdefault(var, path)
18 14
19import apathy.Contacts as Contacts 15import apathy.Contacts as Contacts
20from apathy.Globals import * 16from apathy.Globals import *
@@ -23,11 +19,16 @@ gettext.install("apathy", "/usr/share/locale", unicode=1)
23 19
24# Log 20# Log
25if not os.path.exists(USER_PATH): 21if not os.path.exists(USER_PATH):
26 os.mkdir(USER_PATH, 0700) 22 os.mkdir(USER_PATH, 0x700)
27log = logging.getLogger("apathy.contacts") 23log = logging.getLogger("apathy.contacts")
28log.setLevel(logging.DEBUG) 24log.setLevel(logging.DEBUG)
29fileformatter = logging.Formatter("[%(created)s] [%(levelname)s] in %(module)s line %(lineno)s (%(funcName)s): %(message)s") 25fileformatter = logging.Formatter(
30handler_file = logging.FileHandler(os.path.join(USER_PATH, "apathy-contacts.log"), "w") 26 "[%(created)s] [%(levelname)s] in %(module)s "
27 "line %(lineno)s (%(funcName)s): %(message)s"
28 )
29handler_file = logging.FileHandler(
30 os.path.join(USER_PATH, "apathy-contacts.log"), "w"
31 )
31handler_file.setFormatter(fileformatter) 32handler_file.setFormatter(fileformatter)
32handler_file.setLevel(logging.ERROR) 33handler_file.setLevel(logging.ERROR)
33log.addHandler(handler_file) 34log.addHandler(handler_file)
diff --git a/bin/apathy-handler b/bin/apathy-handler
index 2e89bde..4d4c9f2 100755
--- a/bin/apathy-handler
+++ b/bin/apathy-handler
@@ -1,20 +1,16 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2import os 2import os
3import sys
4import logging 3import logging
5import gettext 4import gettext
6 5
7try: 6from efl import ecore, elementary as elm
8 import ecore, elementary as elm
9except ImportError:
10 from efl import ecore, elementary as elm
11 7
12ENV_PATHS = {"APATHY_IMAGE_PATH" : "/usr/share/apathy/images/"} 8ENV_PATHS = {"APATHY_IMAGE_PATH": "/usr/share/apathy/images/"}
13 9
14#must set variables before importing Globals because it requires them 10#must set variables before importing Globals because it requires them
15for var, path in ENV_PATHS.iteritems(): 11for var, path in ENV_PATHS.iteritems():
16 #if it is not already set, set the enviroment variable. 12 #if it is not already set, set the enviroment variable.
17 os.environ.setdefault(var, path) 13 os.environ.setdefault(var, path)
18 14
19import apathy.Handler as Handler 15import apathy.Handler as Handler
20from apathy.Globals import * 16from apathy.Globals import *
@@ -23,11 +19,16 @@ gettext.install("apathy", "/usr/share/locale", unicode=1)
23 19
24# Log 20# Log
25if not os.path.exists(USER_PATH): 21if not os.path.exists(USER_PATH):
26 os.mkdir(USER_PATH, 0700) 22 os.mkdir(USER_PATH, 0x700)
27log = logging.getLogger("apathy.handler") 23log = logging.getLogger("apathy.handler")
28log.setLevel(logging.DEBUG) 24log.setLevel(logging.DEBUG)
29fileformatter = logging.Formatter("[%(created)s] [%(levelname)s] in %(module)s line %(lineno)s (%(funcName)s): %(message)s") 25fileformatter = logging.Formatter(
30handler_file = logging.FileHandler(os.path.join(USER_PATH, "apathy-handler.log"), "w") 26 "[%(created)s] [%(levelname)s] in %(module)s "
27 "line %(lineno)s (%(funcName)s): %(message)s"
28 )
29handler_file = logging.FileHandler(
30 os.path.join(USER_PATH, "apathy-handler.log"), "w"
31 )
31handler_file.setFormatter(fileformatter) 32handler_file.setFormatter(fileformatter)
32handler_file.setLevel(logging.ERROR) 33handler_file.setLevel(logging.ERROR)
33log.addHandler(handler_file) 34log.addHandler(handler_file)