Skip to content

Commit

Permalink
Merge commit 'remotes/luckyluke/gtk'
Browse files Browse the repository at this point in the history
  • Loading branch information
borisfaure committed Sep 27, 2009
2 parents 6059555 + 391404c commit 79e4509
Show file tree
Hide file tree
Showing 12 changed files with 257 additions and 103 deletions.
1 change: 1 addition & 0 deletions README
Expand Up @@ -3,6 +3,7 @@ TEMPORARY README:
In theory, you don't need much...
python-pyopenssl
python-crypto
python-imaging
maybe some other stuff...

Before launching amsn2 you have to fetch the submodules (papyon). Instructions can be found on the aMSN forum:
Expand Down
4 changes: 2 additions & 2 deletions amsn2/backend/defaultaccountbackend.py
Expand Up @@ -174,8 +174,8 @@ def removeAccount(self, email):
""" DPs """
def getFileLocationDP(self, email, uid, shac):
dir = os.path.join(self.dps_dir, self._getDir(email))
if not os.path.isdir(self.dps_dir):
os.makedirs(self.dps_dir, 0700)
if not os.path.isdir(dir):
os.makedirs(dir, 0700)
return os.path.join(dir, shac+".img")

def _getDir(self, email):
Expand Down
42 changes: 42 additions & 0 deletions amsn2/core/account_manager.py
@@ -1,8 +1,13 @@
import os
import Image
import logging
import papyon
import __builtin__
from views import AccountView
from views import StringView

logger = logging.getLogger('amsn2.core.account_manager')

class aMSNAccount(object):
""" aMSNAccount : a Class to represent an aMSN account
This class will contain all settings relative to an account
Expand All @@ -20,6 +25,7 @@ def __init__(self, core, accountview):
self.personalinfoview = core._personalinfo_manager._personalinfoview
self.do_save = accountview.save
self.backend_manager = core._backend_manager
self.client = None
self.lock()
self.load()

Expand Down Expand Up @@ -47,6 +53,42 @@ def save(self):
self.view.dp = self.personalinfoview.dp
self.backend_manager.saveAccount(self)

def set_dp(self, path):
if path:
try:
im = Image.open(path)
im.resize((96, 96), Image.BILINEAR)

# Write the file and rename it instead of creating a tmpfile
profile = self.client.profile
dp_path_tmp = self.backend_manager.getFileLocationDP(self.view.email, profile.id, 'tmp')
im.save(dp_path_tmp, "PNG")
f = open(dp_path_tmp)
dp_object = papyon.p2p.MSNObject(self.client.profile,
os.path.getsize(dp_path_tmp),
papyon.p2p.MSNObjectType.DISPLAY_PICTURE,
os.path.basename(path),
os.path.basename(path),
data=f)
f.close()

dp_path = self.backend_manager.getFileLocationDP(self.view.email, profile.id, dp_object._data_sha)
os.rename(dp_path_tmp, dp_path)

except OSError, e:
# FIXME: on Windows, it's raised if dp_path already exists
# http://docs.python.org/library/os.html#os.rename
logger.error('Trying to overwrite a saved dp')
return

except IOError, e:
logger.error(e)
return

else:
self.client.msn_object_store.publish(dp_object)
self.personalinfoview.dp = dp_object

class aMSNAccountManager(object):
""" aMSNAccountManager : The account manager that takes care of storing
and retreiving all the account.
Expand Down
15 changes: 10 additions & 5 deletions amsn2/core/amsn.py
Expand Up @@ -242,18 +242,23 @@ def contactCB(account):

self._gui.gui.aMSNContactDeleteWindow('Contact to remove: ', contactCB, ())

def changeDP(self):
self._gui.gui.aMSNDPChooserWindow(self._account.set_dp ,self._backend_manager)

def createMainMenuView(self):
menu = MenuView()
quitMenuItem = MenuItemView(MenuItemView.COMMAND, label="Quit", command
= self.quit)
logOutMenuItem = MenuItemView(MenuItemView.COMMAND, label="Log out",
quitMenuItem = MenuItemView(MenuItemView.COMMAND, label="Quit",
command = self.quit)
logOutMenuItem = MenuItemView(MenuItemView.COMMAND, label="Log out",
command = self.signOutOfAccount)
mainMenu = MenuItemView(MenuItemView.CASCADE_MENU, label="Main")
mainMenu.addItem(logOutMenuItem)
mainMenu.addItem(quitMenuItem)

addContactItem = MenuItemView(MenuItemView.COMMAND, label="Add Contact", command=self.addContact)
removeContact = MenuItemView(MenuItemView.COMMAND, label='Remove contact', command=self.removeContact)
addContactItem = MenuItemView(MenuItemView.COMMAND, label="Add Contact",
command=self.addContact)
removeContact = MenuItemView(MenuItemView.COMMAND, label='Remove contact',
command=self.removeContact)

contactsMenu = MenuItemView(MenuItemView.CASCADE_MENU, label="Contacts")
contactsMenu.addItem(addContactItem)
Expand Down
19 changes: 9 additions & 10 deletions amsn2/core/personalinfo_manager.py
Expand Up @@ -7,6 +7,7 @@ def __init__(self, core):
"""

self._core = core
self._backend_manager = core._backend_manager
self._em = core._event_manager
self._personalinfoview = PersonalInfoView(self)
self._papyon_profile = None
Expand All @@ -33,7 +34,7 @@ def setAccount(self, amsn_account):
self._personalinfoview.psm = strv

# set login presence, from this moment the client appears to the others
self._personalinfoview.presence = amsn_account.view.presence
self._personalinfoview.presence = self._core.p2s[amsn_account.view.presence]

""" Actions from ourselves """
def _onNickChanged(self, new_nick):
Expand All @@ -51,13 +52,8 @@ def _onPresenceChanged(self, new_presence):
break
self._papyon_profile.presence = key

def _onDPChangeRequest(self):
# TODO: tell the core to invoke a file chooser and change DP
pass

def _onDPChanged(self, new_dp):
# TODO: manage msn_objects
self._papyon_profile.msn_object = new_dp
def _onDPChanged(self, dp_msnobj):
self._papyon_profile.msn_object = dp_msnobj

""" Actions from the core """
def _onCMChanged(self, new_media):
Expand All @@ -76,9 +72,12 @@ def onPSMUpdated(self, psm):
self._personalinfoview._psm.appendText(psm)
self._em.emit(self._em.events.PERSONALINFO_UPDATED, self._personalinfoview)

def onDPUpdated(self, dp):
def onDPUpdated(self, dp_msnobj):
self._personalinfoview._image.reset()
self._personalinfoview._image.load(dp)
path = self._backend_manager.getFileLocationDP(self._papyon_profile.account,
self._papyon_profile.id,
dp_msnobj._data_sha)
self._personalinfoview._image.load('Filename', path)
self._em.emit(self._em.events.PERSONALINFO_UPDATED, self._personalinfoview)

def onPresenceUpdated(self, presence):
Expand Down
4 changes: 2 additions & 2 deletions amsn2/core/views/personalinfoview.py
Expand Up @@ -41,8 +41,8 @@ def fset(self, psm):
def dp():
def fget(self):
return self._image
def fset(self, imagev):
self._personalinfo_manager._onDPChanged(imagev)
def fset(self, dp_msnobj):
self._personalinfo_manager._onDPChanged(dp_msnobj)
return locals()

@rw_property
Expand Down
26 changes: 14 additions & 12 deletions amsn2/gui/base/choosers.py
Expand Up @@ -4,32 +4,34 @@ class aMSNFileChooserWindow(object):
This Interface represent a window used to choose a file,
which could be an image for the dp, a file to send, a theme file, etc.
"""
def __init__(self, filter, directory):
def __init__(self, filters, directory, callback):
"""
@type filter: tuple
@param filter: A tuple containing strings, that will represent the file
formats to filter.
@type filter: dict of tuple
@param filter: A dict whose keys are the names of the filters,
and the values are a tuple containing strings,
that will represent the patterns to filter.
@type directory: str
@param directory: The path to start from.
@type callback: function
@param callback: The function called when the file has been choosed.
Its prototype is callback(file_path)
This will eventually call the related show() method, so the window is
displayed when created.
"""
raise NotImplementedError

class aMSNDPChooser(object):
class aMSNDPChooserWindow(object):
"""
This Interface represent a window used to choose a display picture,
should show a list of default dps and the possibility to catch a picture from a webcam.
"""
def __init__(self, default_dps, actions):
def __init__(self, callback, backend_manager):
"""
@type default_dps: tuple
@params default_dps: a tuple containing strings representing the paths of the default dps.
@type actions: tuple
@param actions: A tuple containing the options between
which the user can choose. Every option is a tuple itself, of the form (name, callback),
where callback is the function that will be called if the option is selected.
@type callback: function
@param callback: The function called when the dp has been choosed.
Its prototype is callback(dp_path)
@type backend_manager: aMSNBackendManager
This will eventually call the related show() method, so the window is
displayed when created.
Expand Down

0 comments on commit 79e4509

Please sign in to comment.