Commit b5599b28 authored by Luci Stanescu's avatar Luci Stanescu

Modified MainWindow to use the SIP accounts from the middleware

parent 7d7a6daa
......@@ -6,16 +6,25 @@ from __future__ import with_statement
__all__ = ['MainWindow']
from PyQt4 import uic
from PyQt4.QtCore import Qt
from PyQt4.QtGui import QBrush, QColor, QPainter, QPen, QPixmap
from PyQt4.QtCore import Qt, QVariant
from PyQt4.QtGui import QBrush, QColor, QIcon, QPainter, QPen, QPixmap
from application.notification import IObserver, NotificationCenter
from application.python.util import Null
from zope.interface import implements
from sipsimple.account import AccountManager, BonjourAccount
from blink.contacts import ContactModel, ContactSearchModel
from blink.resources import Resources
from blink.util import run_in_gui_thread
ui_class, base_class = uic.loadUiType(Resources.get('blink.ui'))
class MainWindow(base_class, ui_class):
implements(IObserver)
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
......@@ -25,7 +34,7 @@ class MainWindow(base_class, ui_class):
self.setWindowTitle('Blink')
self.setWindowIconText('Blink')
self._setup_identities()
self._set_user_icon(Resources.get("icons/default-avatar.png")) # ":/resources/icons/default-avatar.png"
self.contact_model = ContactModel(self)
self.contact_search_model = ContactSearchModel(self.contact_model, self)
......@@ -51,11 +60,17 @@ class MainWindow(base_class, ui_class):
self.back_to_contacts.clicked.connect(self.search_box.clear) # this can be set in designer -Dan
self.add_contact.clicked.connect(self.test_add_contact)
self.identity.currentIndexChanged[str].connect(self.set_identity)
self.identity.activated[int].connect(self.set_identity)
#self.connect(self.contact_list, QtCore.SIGNAL("doubleClicked(const QModelIndex &)"), self.double_click_action)
#self.connect(self.contact_list.selectionModel(), QtCore.SIGNAL("selectionChanged(const QItemSelection &, const QItemSelection &)"), self.selection_changed)
notification_center = NotificationCenter()
notification_center.add_observer(self, name="SIPAccountManagerDidChangeDefaultAccount")
notification_center.add_observer(self, name="SIPAccountManagerDidStart")
notification_center.add_observer(self, name="SIPAccountDidActivate")
notification_center.add_observer(self, name="SIPAccountDidDeactivate")
def _set_user_icon(self, image_file_name):
pixmap = QPixmap(32, 32)
pixmap.fill(QColor(Qt.transparent))
......@@ -73,14 +88,9 @@ class MainWindow(base_class, ui_class):
painter.end()
self.image.setPixmap(pixmap)
def _setup_identities(self):
self.identity.addItem("31208005167@ag-projects.com")
self.identity.addItem("Bonjour")
self._set_user_icon(Resources.get("icons/default-avatar.png"))
#self._set_user_icon(":/resources/icons/default-avatar.png")
def set_identity(self, string):
print "identity changed", string
def set_identity(self, index):
account_manager = AccountManager()
account_manager.default_account = self.identity.itemData(index).toPyObject()
def search_box_text_changed(self, text):
if text:
......@@ -107,6 +117,40 @@ class MainWindow(base_class, ui_class):
contact.status = random.choice(('online', 'away', 'busy', 'offline'))
self.contact_model.addContact(contact)
@run_in_gui_thread
def handle_notification(self, notification):
handler = getattr(self, '_NH_%s' % notification.name, Null)
handler(notification)
def _NH_SIPAccountDidActivate(self, notification):
account = notification.sender
name = u'Bonjour' if account is BonjourAccount() else account.id
icon = None
if account is BonjourAccount():
pixmap = QPixmap()
if pixmap.load(Resources.get('icons/bonjour.png')):
pixmap = pixmap.scaled(16, 16, Qt.KeepAspectRatio, Qt.SmoothTransformation)
icon = QIcon(pixmap)
if icon is not None:
self.identity.addItem(icon, name, QVariant(account))
else:
self.identity.addItem(name, QVariant(account))
def _NH_SIPAccountDidDeactivate(self, notification):
account = notification.sender
name = u'Bonjour' if account is BonjourAccount() else account.id
self.identity.removeItem(self.identity.findText(name))
def _NH_SIPAccountManagerDidStart(self, notification):
account = AccountManager().default_account
name = u'Bonjour' if account is BonjourAccount() else account.id
self.identity.setCurrentIndex(self.identity.findText(name))
def _NH_SIPAccountManagerDidChangeDefaultAccount(self, notification):
account = notification.data.account
name = u'Bonjour' if account is BonjourAccount() else account.id
self.identity.setCurrentIndex(self.identity.findText(name))
del ui_class, base_class
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment