| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # |
|---|
| 3 | # QuteCom, a voice over Internet phone |
|---|
| 4 | # Copyright (C) 2010 Mbdsys |
|---|
| 5 | # |
|---|
| 6 | # This program is free software; you can redistribute it and/or modify |
|---|
| 7 | # it under the terms of the GNU General Public License as published by |
|---|
| 8 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | # (at your option) any later version. |
|---|
| 10 | # |
|---|
| 11 | # This program is distributed in the hope that it will be useful, |
|---|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | # GNU General Public License for more details. |
|---|
| 15 | # |
|---|
| 16 | # You should have received a copy of the GNU General Public License |
|---|
| 17 | # along with this program; if not, write to the Free Software |
|---|
| 18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | # |
|---|
| 20 | # @author Philippe Bernery |
|---|
| 21 | |
|---|
| 22 | from ContactDelegate import ContactDelegate |
|---|
| 23 | from ContactEditWidget import ContactEditWidget |
|---|
| 24 | from ContactListModel import ContactListModel |
|---|
| 25 | from ContactListWidget_ui import Ui_ContactListWidget |
|---|
| 26 | |
|---|
| 27 | from PyCoIpManager import * |
|---|
| 28 | |
|---|
| 29 | from PyQt4.QtCore import * |
|---|
| 30 | from PyQt4.QtGui import * |
|---|
| 31 | |
|---|
| 32 | import logging |
|---|
| 33 | |
|---|
| 34 | log = logging.getLogger("PyQuteCom.ContactListWidget") |
|---|
| 35 | |
|---|
| 36 | class ContactListWidget(QWidget): |
|---|
| 37 | """ This class manages the contact list widget. |
|---|
| 38 | """ |
|---|
| 39 | def __init__(self, parent, tCoIpManager): |
|---|
| 40 | QWidget.__init__(self, parent) |
|---|
| 41 | |
|---|
| 42 | self.__tCoIpManager = tCoIpManager |
|---|
| 43 | self.__lastOpenedIndex = QModelIndex() |
|---|
| 44 | |
|---|
| 45 | ## Initializing UI |
|---|
| 46 | self.__ui = Ui_ContactListWidget() |
|---|
| 47 | self.__ui.setupUi(self) |
|---|
| 48 | #### |
|---|
| 49 | |
|---|
| 50 | ## Registering to ContactListWidget signals |
|---|
| 51 | QObject.connect(self.__ui.removeContactButton, SIGNAL("clicked()"), self.removeContactClicked) |
|---|
| 52 | QObject.connect(self.__ui.contactListView, SIGNAL("clicked(const QModelIndex &)"), self.contactListViewClicked) |
|---|
| 53 | #### |
|---|
| 54 | |
|---|
| 55 | ## Setting model |
|---|
| 56 | contactDelegate = ContactDelegate(self.__tCoIpManager, self) |
|---|
| 57 | self.__ui.contactListView.setItemDelegate(contactDelegate) |
|---|
| 58 | contactListModel = ContactListModel(self.__tCoIpManager, self) |
|---|
| 59 | self.__ui.contactListView.setModel(contactListModel) |
|---|
| 60 | #### |
|---|
| 61 | |
|---|
| 62 | def contactListViewClicked(self, index): |
|---|
| 63 | if self.__lastOpenedIndex.isValid(): |
|---|
| 64 | self.__ui.contactListView.closePersistentEditor(self.__lastOpenedIndex) |
|---|
| 65 | self.__ui.contactListView.itemDelegate().resetEditedIndex() |
|---|
| 66 | |
|---|
| 67 | if self.__lastOpenedIndex != index: |
|---|
| 68 | self.__ui.contactListView.openPersistentEditor(index) |
|---|
| 69 | self.__lastOpenedIndex = index |
|---|
| 70 | else: |
|---|
| 71 | self.__lastOpenedIndex = QModelIndex() |
|---|
| 72 | |
|---|
| 73 | self.__ui.contactListView.doItemsLayout() |
|---|
| 74 | |
|---|
| 75 | def addContactClicked(self): |
|---|
| 76 | contact = Contact() |
|---|
| 77 | editWidget = ContactEditWidget(contact, self.__tCoIpManager, self) |
|---|
| 78 | if editWidget.exec_() == QDialog.Accepted: |
|---|
| 79 | self.__tCoIpManager.getTUserProfileManager().getTContactManager().add(contact) |
|---|
| 80 | |
|---|
| 81 | def removeContactClicked(self): |
|---|
| 82 | indexList = self.__ui.contactListView.selectedIndexes() |
|---|
| 83 | if len(indexList) > 0: |
|---|
| 84 | index = indexList[0] |
|---|
| 85 | contact = index.model().getContact(index) |
|---|
| 86 | if QMessageBox.question(self, self.tr("Remove a contact"), |
|---|
| 87 | self.tr("Are you sure you want to remove %1?").arg(contact.getDisplayName()), QMessageBox.Yes, QMessageBox.No) == QMessageBox.Yes: |
|---|
| 88 | self.__tCoIpManager.getTUserProfileManager().getTContactManager().remove(contact.getUUID()) |
|---|