Hello,
The attached patch improves the update of the contact list by repainting
the list instead of rebuilding the content every time the presence is
changed.
What it does is when a contact is changed it checks if the contact must
be added, removed or updated.
If it needs to be added or removed, it behaves like it used to (for now).
If it needs to be updated, it will ask the view to repaint itself, which
is still a bit too much, but is definitely better than deleting all
items and recreating them.
The other benefit of this patch is that you no longer loose your
selection when a contact is updated.
The only drawback is that it does not reorder items: the unpatched
behavior is to sort contact by presence, therefore when the presence of
a contact changes, the contact will get moved with other contacts of the
same presence. With the patch, the contact stays where it was.
I personally think grouping by presence is not a good idea. What do you
think about this?
Aurélien
Index: contactlist/QtContactWidget.h
===================================================================
--- contactlist/QtContactWidget.h (révision 10200)
+++ contactlist/QtContactWidget.h (copie de travail)
@@ -57,6 +57,8 @@
return _text;
}
+ void updateButtons();
+
Q_SIGNALS:
/**
Index: contactlist/QtContactManager.h
===================================================================
--- contactlist/QtContactManager.h (révision 10191)
+++ contactlist/QtContactManager.h (copie de travail)
@@ -73,6 +73,8 @@
*/
bool groupsAreHidden() const;
+ void updateContact(const std::string& contactId);
+
public Q_SLOTS:
void setMouseButton(Qt::MouseButton button);
Index: contactlist/QtContactWidget.cpp
===================================================================
--- contactlist/QtContactWidget.cpp (révision 10200)
+++ contactlist/QtContactWidget.cpp (copie de travail)
@@ -51,39 +51,12 @@
_cWengoPhone(cWengoPhone) {
_contactId = contactId;
- ContactProfile contactProfile = _cWengoPhone.getCUserProfileHandler().getCUserProfile()->getCContactList().getContactProfile(_contactId);
_ui = new Ui::ContactWidget();
_ui->setupUi(this);
- std::string foregroundPixmapData = contactProfile.getIcon().getData();
- _ui->avatarButton->setIcon(PixmapMerging::merge(foregroundPixmapData, AVATAR_BACKGROUND));
+ updateButtons();
- QString str = QString::fromUtf8(contactProfile.getHomePhone().c_str());
- if (!str.isEmpty()) {
- _ui->landlineButton->setText(str);
- }
-
- str = QString::fromUtf8(contactProfile.getMobilePhone().c_str());
- if (!str.isEmpty()) {
- _ui->mobileButton->setText(str);
- }
- else {
- _ui->smsButton->setEnabled(false);
- }
-
- if (!contactProfile.hasFreeCall() && !contactProfile.hasVoiceMail()) {
- _ui->callButton->setEnabled(false);
- }
-
- if (!contactProfile.hasIM()) {
- _ui->chatButton->setEnabled(false);
- }
-
- if (!contactProfile.hasFileTransfer()) {
- _ui->sendFileButton->setEnabled(false);
- }
-
SAFE_CONNECT(_ui->callButton, SIGNAL(clicked()), SLOT(callButtonClicked()));
SAFE_CONNECT(_ui->chatButton, SIGNAL(clicked()), SLOT(chatButtonClicked()));
SAFE_CONNECT(_ui->smsButton, SIGNAL(clicked()), SLOT(smsButtonClicked()));
@@ -99,6 +72,34 @@
delete _ui;
}
+void QtContactWidget::updateButtons() {
+ ContactProfile contactProfile = _cWengoPhone.getCUserProfileHandler().getCUserProfile()->getCContactList().getContactProfile(_contactId);
+ std::string foregroundPixmapData = contactProfile.getIcon().getData();
+ _ui->avatarButton->setIcon(PixmapMerging::merge(foregroundPixmapData, AVATAR_BACKGROUND));
+
+ QString str = QString::fromUtf8(contactProfile.getHomePhone().c_str());
+ if (str.isEmpty()) {
+ _ui->landlineButton->setText(tr("No landline phone number set"));
+ } else {
+ _ui->landlineButton->setText(str);
+ }
+
+ str = QString::fromUtf8(contactProfile.getMobilePhone().c_str());
+ if (str.isEmpty()) {
+ _ui->mobileButton->setText(tr("No mobile phone number set"));
+ _ui->smsButton->setEnabled(false);
+ } else {
+ _ui->mobileButton->setText(str);
+ _ui->smsButton->setEnabled(true);
+ }
+
+ _ui->callButton->setEnabled(contactProfile.hasFreeCall() || contactProfile.hasVoiceMail());
+
+ _ui->chatButton->setEnabled(contactProfile.hasIM());
+
+ _ui->sendFileButton->setEnabled(contactProfile.hasFileTransfer());
+}
+
void QtContactWidget::callButtonClicked() {
QtContactListManager * ul = QtContactListManager::getInstance();
ul->startFreeCall(QString::fromStdString(_contactId));
Index: contactlist/QtContactManager.cpp
===================================================================
--- contactlist/QtContactManager.cpp (révision 10191)
+++ contactlist/QtContactManager.cpp (copie de travail)
@@ -19,6 +19,7 @@
#include "QtContactManager.h"
+#include "QtContactWidget.h"
#include "QtContactList.h"
#include "QtContactPixmap.h"
#include "QtContactInfo.h"
@@ -806,3 +807,29 @@
_trStringStartChat = tr("Start chat");
_trStringInviteToConference = tr("Invite to conference");
}
+
+void QtContactManager::updateContact(const std::string& contactId) {
+ QtContactListManager * ul = QtContactListManager::getInstance();
+ bool oldVisible = ul->getContact((QString::fromStdString(contactId))) != 0;
+
+ ul->contactUpdated(QString::fromStdString(contactId));
+
+ ContactProfile profile = _qtContactList.getCContactList().getContactProfile(contactId);
+ bool newVisible = canShowUser(&profile);
+
+ if (oldVisible && !newVisible) {
+ // Remove
+ redrawContacts();
+ } else if (!oldVisible && newVisible) {
+ // Add
+ redrawContacts();
+ } else if (oldVisible && newVisible) {
+ // Update
+ _tree->viewport()->update();
+ QtContactWidget* widget = static_cast<QtContactWidget*>( _tree->findChild<QtContactWidget*>() );
+ if (widget) {
+ widget->updateButtons();
+ widget->update();
+ }
+ }
+}
Index: contactlist/QtContactList.cpp
===================================================================
--- contactlist/QtContactList.cpp (révision 10191)
+++ contactlist/QtContactList.cpp (copie de travail)
@@ -216,8 +216,7 @@
void QtContactList::contactChangedEvent(const std::string & contactId) {
QtContactListManager * ul = QtContactListManager::getInstance();
if (ul->contains(QString::fromStdString(contactId))) {
- ul->contactUpdated(QString::fromStdString(contactId));
- updatePresentation();
+ _contactManager->updateContact(contactId);
} else {
contactAddedEvent(contactId);
}
_______________________________________________
Wengophone-devel mailing list
[email protected]
http://dev.openwengo.com/mailman/listinfo/wengophone-devel