Ejemplo n.º 1
0
    def __init__(self, amsn_core, parent):
        base.aMSNContactListWidget.__init__(self, amsn_core, parent)
        StyledWidget.__init__(self, parent._parent)
        self._amsn_core = amsn_core
        self.ui = Ui_ContactList()
        self.ui.setupUi(self)
        delegate = itemDelegate(self)
        self.ui.cList.setItemDelegate(delegate)
        self._parent = parent
        self._mainWindow = parent._parent
        self._model = QStandardItemModel(self)
        self._model.setColumnCount(4)
        self._proxyModel = QSortFilterProxyModel(self)
        self._proxyModel.setSourceModel(self._model)
        self.ui.cList.setModel(self._proxyModel)
        self._contactDict = dict()
        self.groups = []
        self.contacts = {}

        self._proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive)
        self._proxyModel.setFilterKeyColumn(-1)

        (self.ui.cList.header()).resizeSections(1) #auto-resize column wigth
        (self.ui.cList.header()).setSectionHidden(1, True) #hide --> (group/contact ID)
        (self.ui.cList.header()).setSectionHidden(2, True) #hide --> (boolean value. Do I really need this?)
        (self.ui.cList.header()).setSectionHidden(3, True) #hide --> (contact/group view object)

        self.connect(self.ui.searchLine, SIGNAL('textChanged(QString)'), self._proxyModel, SLOT('setFilterFixedString(QString)'))
        QObject.connect(self.ui.nickName, SIGNAL('textChanged(QString)'), self.__slotChangeNick)
        self.connect(self.ui.cList, SIGNAL('doubleClicked(QModelIndex)'), self.__slotContactCallback)
Ejemplo n.º 2
0
    def __init__(self, amsn_core, parent):
        StyledWidget.__init__(self, parent._parent)
        self._amsn_core = amsn_core
        self._myview = parent._myview
        self.ui = Ui_ContactList()
        self.ui.setupUi(self)
        delegate = itemDelegate(self)
        self.ui.cList.setItemDelegate(delegate)
        self._parent = parent
        self._mainWindow = parent._parent
        self._model = QStandardItemModel(self)
        self._model.setColumnCount(4)
        self._proxyModel = QSortFilterProxyModel(self)
        self._proxyModel.setSourceModel(self._model)
        self.ui.cList.setModel(self._proxyModel)
        self._contactDict = dict()
        self.groups = []
        self.contacts = {}

        self._proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive)
        self._proxyModel.setFilterKeyColumn(-1)

        (self.ui.cList.header()).resizeSections(1) #auto-resize column wigth
        (self.ui.cList.header()).setSectionHidden(1, True) #hide --> (group/contact ID)
        (self.ui.cList.header()).setSectionHidden(2, True) #hide --> (boolean value. Do I really need this?)
        (self.ui.cList.header()).setSectionHidden(3, True) #hide --> (contact/group view object)

        self.connect(self.ui.searchLine, SIGNAL('textChanged(QString)'), self._proxyModel, SLOT('setFilterFixedString(QString)'))
        self.connect(self.ui.nickName, SIGNAL('nickChange()'), self.__nickChange)
        self.connect(self.ui.statusMessage, SIGNAL('psmChange()'), self.__psmChange)
        self.connect(self.ui.status, SIGNAL('currentIndexChanged(int)'), self.__statusChange)
        self.connect(self.ui.cList, SIGNAL('doubleClicked(QModelIndex)'), self.__clDoubleClick)

        self.ui.nickName.installEventFilter(GlobalFilter(self.ui.nickName))
        self.ui.statusMessage.installEventFilter(GlobalFilter(self.ui.statusMessage))
Ejemplo n.º 3
0
    def __init__(self, amsn_core, parent):
        base.aMSNContactListWidget.__init__(self, amsn_core, parent)
        StyledWidget.__init__(self, parent._parent)
        self._amsn_core = amsn_core
        self.ui = Ui_ContactList()
        self.ui.setupUi(self)
        delegate = itemDelegate(self)
        self.ui.cList.setItemDelegate(delegate)
        self._parent = parent
        self._mainWindow = parent._parent
        self._model = QStandardItemModel(self)
        self._model.setColumnCount(4)
        self._proxyModel = QSortFilterProxyModel(self)
        self._proxyModel.setSourceModel(self._model)
        self.ui.cList.setModel(self._proxyModel)
        self._contactDict = dict()
        self.groups = []
        self.contacts = {}

        self._proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive)
        self._proxyModel.setFilterKeyColumn(-1)

        (self.ui.cList.header()).resizeSections(1)  # auto-resize column wigth
        (self.ui.cList.header()).setSectionHidden(1, True)  # hide --> (group/contact ID)
        (self.ui.cList.header()).setSectionHidden(2, True)  # hide --> (boolean value. Do I really need this?)
        (self.ui.cList.header()).setSectionHidden(3, True)  # hide --> (contact/group view object)

        self.connect(
            self.ui.searchLine, SIGNAL("textChanged(QString)"), self._proxyModel, SLOT("setFilterFixedString(QString)")
        )
        QObject.connect(self.ui.nickName, SIGNAL("textChanged(QString)"), self.__slotChangeNick)
        self.connect(self.ui.cList, SIGNAL("doubleClicked(QModelIndex)"), self.__slotContactCallback)
Ejemplo n.º 4
0
 def __init__(self, amsn_core, parent):
     StyledWidget.__init__(self, parent._parent)
     self._amsn_core = amsn_core
     self.ui = Ui_ContactList()
     self.ui.setupUi(self)
     self._parent = parent
     self._mainWindow = parent._parent
     self._model = QStandardItemModel(self)
     self._proxyModel = QSortFilterProxyModel(self)
     self._proxyModel.setSourceModel(self._model)
     self.ui.cList.setModel(self._proxyModel)
     self._contactDict = dict()
     
     self._proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive)
     self._proxyModel.setFilterKeyColumn(-1)
     
     self.connect(self.ui.searchLine, SIGNAL('textChanged(QString)'),
                  self._proxyModel, SLOT('setFilterFixedString(QString)'))
     QObject.connect(self.ui.nickName, SIGNAL('textChanged(QString)'),
                     self.__slotChangeNick)
Ejemplo n.º 5
0
class aMSNContactListWidget(StyledWidget, base.aMSNContactListWidget):
    def __init__(self, amsn_core, parent):
        StyledWidget.__init__(self, parent._parent)
        self._amsn_core = amsn_core
        self._myview = parent._myview
        self.ui = Ui_ContactList()
        self.ui.setupUi(self)
        delegate = itemDelegate(self)
        self.ui.cList.setItemDelegate(delegate)
        self._parent = parent
        self._mainWindow = parent._parent
        self._model = QStandardItemModel(self)
        self._model.setColumnCount(4)
        self._proxyModel = QSortFilterProxyModel(self)
        self._proxyModel.setSourceModel(self._model)
        self.ui.cList.setModel(self._proxyModel)
        self._contactDict = dict()
        self.groups = []
        self.contacts = {}

        self._proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive)
        self._proxyModel.setFilterKeyColumn(-1)

        (self.ui.cList.header()).resizeSections(1) #auto-resize column wigth
        (self.ui.cList.header()).setSectionHidden(1, True) #hide --> (group/contact ID)
        (self.ui.cList.header()).setSectionHidden(2, True) #hide --> (boolean value. Do I really need this?)
        (self.ui.cList.header()).setSectionHidden(3, True) #hide --> (contact/group view object)

        self.connect(self.ui.searchLine, SIGNAL('textChanged(QString)'), self._proxyModel, SLOT('setFilterFixedString(QString)'))
        self.connect(self.ui.nickName, SIGNAL('nickChange()'), self.__nickChange)
        self.connect(self.ui.statusMessage, SIGNAL('psmChange()'), self.__psmChange)
        self.connect(self.ui.status, SIGNAL('currentIndexChanged(int)'), self.__statusChange)
        self.connect(self.ui.cList, SIGNAL('doubleClicked(QModelIndex)'), self.__clDoubleClick)

        self.ui.nickName.installEventFilter(GlobalFilter(self.ui.nickName))
        self.ui.statusMessage.installEventFilter(GlobalFilter(self.ui.statusMessage))


    def show(self):
        self._mainWindow.fadeIn(self)

    def hide(self):
        pass

    def __nickChange(self):
        sv = StringView()
        sv.append_text(str(self.ui.nickName.toPlainText()))
        self._myview.nick = sv

    def __psmChange(self):
        sv = StringView()
        sv.append_text(str(self.ui.statusMessage.toPlainText()))
        self._myview.psm = sv

    def __statusChange(self, i):
        for key in self._amsn_core.p2s:
            if key == str(self.ui.status.itemData(i).toString()):
                self._myview.presence = self._amsn_core.p2s[key]

    def __search_by_id(self, id):
        parent = self._model.item(0)

        while (parent is not None):
            obj = str(self._model.item(self._model.indexFromItem(parent).row(), 1).text())

            if (obj == id): return parent
            child = parent.child(0)
            nc = 0
            while (child is not None):
                cobj = str(parent.child(nc, 1).text())
                if (cobj == id): return child
                nc = nc + 1
                child = self._model.item(self._model.indexFromItem(parent).row()).child(nc)
            parent = self._model.item(self._model.indexFromItem(parent).row() + 1)
            if parent is None: break

        return None

    def contactlist_updated(self, view):
        guids = self.groups
        self.groups = []

        # New groups
        for gid in view.group_ids:
            if (gid == 0): gid = '0'
            if gid not in guids:
                self.groups.append(gid)
                self._model.appendRow([QStandardItem(gid), QStandardItem(gid), QStandardItem("group"), QStandardItem()])

        # Remove unused groups
        for gid in guids:
            if gid not in self.groups:
                gitem = self.__search_by_id(gid)
                self._model.removeRow((self._model.indexFromItem(gitem)).row())
                self.groups.remove(gid)

    def contact_updated(self, contact):
        
        citem = self.__search_by_id(contact.uid)
        if citem is None: return

        gitem = citem.parent()
        if gitem is None: return

        dp = Image(self._parent._theme_manager, contact.dp)
        dp = dp.to_size(28, 28)
        #icon = Image(self._parent._theme_manager, contact.icon)

        gitem.child(self._model.indexFromItem(citem).row(), 0).setData(QVariant(dp), Qt.DecorationRole)
        #gitem.child(self._model.indexFromItem(citem).row(), 0).setData(QVariant(icon), Qt.DecorationRole)

        gitem.child(self._model.indexFromItem(citem).row(), 3).setData(QVariant(contact), Qt.DisplayRole)
        cname = StringView()
        cname = contact.name.to_HTML_string()
        gitem.child(self._model.indexFromItem(citem).row(), 0).setText(QString.fromUtf8(cname))

    def group_updated(self, group):
        if (group.uid == 0): group.uid = '0'
        if group.uid not in self.groups: return
        
        gitem = self.__search_by_id(group.uid)
        self._model.item(self._model.indexFromItem(gitem).row(), 3).setData(QVariant(group), Qt.DisplayRole)
        gname = StringView()
        gname = group.name
        self._model.item((self._model.indexFromItem(gitem)).row(), 0).setText('<b>'+QString.fromUtf8(gname.to_HTML_string())+'</b>')

        try:
            cuids = self.contacts[group.uid]
        except:
            cuids = []
        self.contacts[group.uid] = group.contact_ids.copy()

        for cid in group.contact_ids:
            if cid not in cuids:
                gitem = self.__search_by_id(group.uid)
                gitem.appendRow([QStandardItem(cid), QStandardItem(cid), QStandardItem("contact"), QStandardItem()])

        # Remove unused contacts
        for cid in cuids:
            if cid not in self.contacts[group.uid]:
                citem = self.__search_by_id(cid)
                self._model.removeRow((self._model.indexFromItem(citem)).row())

    def group_removed(self, group):
        gid = self.__search_by_id(group.uid)
        self._model.takeRow(self._model.indexFromItem(gid))

    def configure(self, option, value):
        pass

    def cget(self, option, value):
        pass

    def size_request_set(self, w, h):
        pass

    def __clDoubleClick(self, index):

        model = index.model()
        qvart = model.data(model.index(index.row(), 2, index.parent()))
        qvarv = model.data(model.index(index.row(), 3, index.parent()))

        type = qvart.toString()
        view = qvarv.toPyObject()

        #is the doble-clicked item a contact?
        if type == "contact":
            view.on_click(view.uid)
        else:
            print "Doble click on group!"

    def set_contact_context_menu(self, cb):
        #TODO:
        pass

    def group_added(self, group):
        pi = self._model.invisibleRootItem()

        # Adding Group Item

        groupItem = QStandardItem()
        gname = StringView()
        gname = group.name
        self._model.item(groupItem.row(), 0).setText('<b>'+QString.fromUtf8(gname.toHtmlString())+'</b>')
        self._model.item(groupItem.row(), 1).setText(QString.fromUtf8(str(group.uid)))
        pi.appendRow(groupItem)

        for contact in group.contacts:
            contactItem = QStandardItem()
            cname = StringView()
            cname = contact.name
            self._model.item(contactItem.row(), 0).setText(QString.fromUtf8(cname.toHtmlString()))
            self._model.item(contactItem.row(), 1).setText(QString.fromUtf8(str(contact.uid)))

            groupItem.appendRow(contactItem)

            self._contactDict[contact.uid] = contact
Ejemplo n.º 6
0
class aMSNContactListWidget(StyledWidget, base.aMSNContactListWidget):
    def __init__(self, amsn_core, parent):
        base.aMSNContactListWidget.__init__(self, amsn_core, parent)
        StyledWidget.__init__(self, parent._parent)
        self._amsn_core = amsn_core
        self.ui = Ui_ContactList()
        self.ui.setupUi(self)
        self._parent = parent
        self._mainWindow = parent._parent
        self._model = QStandardItemModel(self)
        self._proxyModel = QSortFilterProxyModel(self)
        self._proxyModel.setSourceModel(self._model)
        self.ui.cList.setModel(self._proxyModel)
        self._contactDict = dict()
        self._groupList = list()
        	
        self._proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive)
        self._proxyModel.setFilterKeyColumn(-1)
        
        self.connect(self.ui.searchLine, SIGNAL('textChanged(QString)'),
                     self._proxyModel, SLOT('setFilterFixedString(QString)'))
        QObject.connect(self.ui.nickName, SIGNAL('textChanged(QString)'),
                        self.__slotChangeNick)

    def show(self):
        self._mainWindow.fadeIn(self)

    def hide(self):
        pass
    
    def __slotChangeNick(self):
        sv = StringView()
        sv.appendText(str(self.ui.nickName.text()))
        self._amsn_core._profile.client.changeNick(sv)
        
    def contactListUpdated(self, view):
        print "ContactListUpdate"
        guids = self._groupList
        self._groupList = list()

        # New groups
        for gid in view.group_ids:
           if (gid == 0): gid = '0'
           if gid not in guids:
              self._groupList.append(gid)
              item = GroupItem()
              item.setGroupName(gid)
              item.setUid(gid)
              self._model.appendRow(item)
    
    def contactUpdated(self, contact):
        print unicode("Contact Updated: " + QString.fromUtf8(contact.name.toString()))
        l = self._model.findItems("*", Qt.MatchWildcard | Qt.MatchRecursive)
        
        for itm in l:
            if itm.uid() == contact.uid:
                itm.setContactName(QString.fromUtf8(contact.name.toString()))
                img = Image()
                img.loadFromImageView(contact.icon)
                itm.setContactIcon(img)
                break

    def groupUpdated(self, group):
        print "GroupUpdated"
        l = self._model.findItems("*", Qt.MatchWildcard)
        
        for itm in l:
            if itm.uid() == group.uid:
                itm.setText(QString.fromUtf8(group.name.toString()))
                for contact in group.contact_ids:
                    for ent in l:
                        if ent.uid() == contact:
                            itm.setText(QString.fromUtf8(contact))
                            continue
                        
                    #print "  * " + contact.name.toString()
            
                    contactItem = ContactItem()
                    contactItem.setContactName(contact)
                    contactItem.setUid(contact)
            
                    itm.appendRow(contactItem)

                break

    def groupRemoved(self, group):
        l = self._model.findItems("", Qt.MatchWildcard)
        
        for itm in l:
            if itm.uid() == group.uid:
                row = self._model.indexFromItem(itm)
                self._model.takeRow(row)
                break

    def configure(self, option, value):
        pass

    def cget(self, option, value):
        pass

    def size_request_set(self, w,h):
        pass

    def setContactCallback(self, cb):
        self._callback = cb
        if cb is not None:
            self.connect(self.ui.cList, SIGNAL('doubleClicked(QModelIndex)'),
                         self.__slotContactCallback)

    def __slotContactCallback(self, index):
        data = str(index.uid())
        if self._callback is not None:
            self._callback(self._contactDict[data])

    def setContactContextMenu(self, cb):
        #TODO:
        pass

    def groupAdded(self, group):
        print group.name.toString()
        
        pi = self._model.invisibleRootItem();
        
        # Adding Group Item
        
        groupItem = GroupItemself()
        groupItem.setText(QString.fromUtf8(group.name.toString()))
        groupItem.setUid(group.uid)
        pi.appendRow(groupItem)
        
        for contact in group.contacts:
            print "  * " + contact.name.toString()
            
            contactItem = ContactItem(self)
            contactItem.setContactName(QString.fromUtf8(contact.name.toString()))
            contactItem.setUid(contact.uid)
            
            groupItem.appendRow(contactItem)
            
            self._contactDict[contact.uid] = contact
Ejemplo n.º 7
0
class aMSNContactListWidget(StyledWidget, base.aMSNContactListWidget):
    def __init__(self, amsn_core, parent):
        base.aMSNContactListWidget.__init__(self, amsn_core, parent)
        StyledWidget.__init__(self, parent._parent)
        self._amsn_core = amsn_core
        self.ui = Ui_ContactList()
        self.ui.setupUi(self)
        delegate = itemDelegate(self)
        self.ui.cList.setItemDelegate(delegate)
        self._parent = parent
        self._mainWindow = parent._parent
        self._model = QStandardItemModel(self)
        self._model.setColumnCount(4)
        self._proxyModel = QSortFilterProxyModel(self)
        self._proxyModel.setSourceModel(self._model)
        self.ui.cList.setModel(self._proxyModel)
        self._contactDict = dict()
        self.groups = []
        self.contacts = {}

        self._proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive)
        self._proxyModel.setFilterKeyColumn(-1)

        (self.ui.cList.header()).resizeSections(1) #auto-resize column wigth
        (self.ui.cList.header()).setSectionHidden(1, True) #hide --> (group/contact ID)
        (self.ui.cList.header()).setSectionHidden(2, True) #hide --> (boolean value. Do I really need this?)
        (self.ui.cList.header()).setSectionHidden(3, True) #hide --> (contact/group view object)

        self.connect(self.ui.searchLine, SIGNAL('textChanged(QString)'), self._proxyModel, SLOT('setFilterFixedString(QString)'))
        QObject.connect(self.ui.nickName, SIGNAL('textChanged(QString)'), self.__slotChangeNick)
        self.connect(self.ui.cList, SIGNAL('doubleClicked(QModelIndex)'), self.__slotContactCallback)

    def show(self):
        self._mainWindow.fadeIn(self)

    def hide(self):
        pass

    def __slotChangeNick(self):
        sv = StringView()
        sv.appendText(str(self.ui.nickName.text()))
        self._amsn_core._profile.client.changeNick(sv)

    def __search_by_id(self, id):
        parent = self._model.item(0)

        while (parent is not None):
            obj = str(self._model.item(self._model.indexFromItem(parent).row(), 1).text())

            if (obj == id): return parent
            child = parent.child(0)
            nc = 0
            while (child is not None):
                cobj = str(parent.child(nc, 1).text())
                if (cobj == id): return child
                nc = nc + 1
                child = self._model.item(self._model.indexFromItem(parent).row()).child(nc)
            parent = self._model.item(self._model.indexFromItem(parent).row() + 1)
            if parent is None: break

        return None

    def contactListUpdated(self, view):
        guids = self.groups
        self.groups = []

        # New groups
        for gid in view.group_ids:
            if (gid == 0): gid = '0'
            if gid not in guids:
                self.groups.append(gid)
                self._model.appendRow([QStandardItem(gid), QStandardItem(gid), QStandardItem("group"), QStandardItem()])
        
        # Remove unused groups
        for gid in guids:
            if gid not in self.groups:
                gitem = self.__search_by_id(gid)
                self._model.removeRow((self._model.indexFromItem(gitem)).row())
                self.groups.remove(gid)

    def contactUpdated(self, contact):
        
        citem = self.__search_by_id(contact.uid)
        if citem is None: return

        gitem = citem.parent()
        if gitem is None: return

        dp = Image(self._parent._theme_manager, contact.dp)
        dp = dp.to_size(28, 28)
        #icon = Image(self._parent._theme_manager, contact.icon)

        gitem.child(self._model.indexFromItem(citem).row(), 0).setData(QVariant(dp), Qt.DecorationRole)
        #gitem.child(self._model.indexFromItem(citem).row(), 0).setData(QVariant(icon), Qt.DecorationRole)

        gitem.child(self._model.indexFromItem(citem).row(), 3).setData(QVariant(contact), Qt.DisplayRole)
        cname = StringView()
        cname = contact.name.toHtmlString()
        gitem.child(self._model.indexFromItem(citem).row(), 0).setText(QString.fromUtf8(cname))

    def groupUpdated(self, group):
        if (group.uid == 0): group.uid = '0'
        if group.uid not in self.groups: return
        
        gitem = self.__search_by_id(group.uid)
        self._model.item(self._model.indexFromItem(gitem).row(), 3).setData(QVariant(group), Qt.DisplayRole)
        gname = StringView()
        gname = group.name
        self._model.item((self._model.indexFromItem(gitem)).row(), 0).setText('<b>'+QString.fromUtf8(gname.toHtmlString())+'</b>')

        try:
            cuids = self.contacts[group.uid]
        except:
            cuids = []
        self.contacts[group.uid] = group.contact_ids.copy()

        for cid in group.contact_ids:
            if cid not in cuids:
                gitem = self.__search_by_id(group.uid)
                gitem.appendRow([QStandardItem(cid), QStandardItem(cid), QStandardItem("contact"), QStandardItem()])

        # Remove unused contacts
        for cid in cuids:
            if cid not in self.contacts[group.uid]:
                citem = self.__search_by_id(cid)
                self._model.removeRow((self._model.indexFromItem(citem)).row())

    def groupRemoved(self, group):
        gid = self.__search_by_id(group.uid)
        self._model.takeRow(self._model.indexFromItem(gid))

    def configure(self, option, value):
        pass

    def cget(self, option, value):
        pass

    def size_request_set(self, w,h):
        pass

    def __slotContactCallback(self, index):

        model = index.model()
        qvart = model.data(model.index(index.row(), 2, index.parent()))
        qvarv = model.data(model.index(index.row(), 3, index.parent()))

        type = qvart.toString()
        view = qvarv.toPyObject()

        #is the doble-clicked item a contact?
        if type == "contact":
            view.on_click(view.uid)
        else:
            print "Doble click on group!"

    def setContactContextMenu(self, cb):
        #TODO:
        pass

    def groupAdded(self, group):
        pi = self._model.invisibleRootItem()

        # Adding Group Item

        groupItem = QStandardItem()
        gname = StringView()
        gname = group.name
        self._model.item(groupItem.row(), 0).setText('<b>'+QString.fromUtf8(gname.toHtmlString())+'</b>')
        self._model.item(groupItem.row(), 1).setText(QString.fromUtf8(str(group.uid)))
        pi.appendRow(groupItem)

        for contact in group.contacts:
            contactItem = QStandardItem()
            cname = StringView()
            cname = contact.name
            self._model.item(contactItem.row(), 0).setText(QString.fromUtf8(cname.toHtmlString()))
            self._model.item(contactItem.row(), 1).setText(QString.fromUtf8(str(contact.uid)))

            groupItem.appendRow(contactItem)

            self._contactDict[contact.uid] = contact