Skip to content

Commit

Permalink
* New contact list (roster animations currently are not supported, pl…
Browse files Browse the repository at this point in the history
…ease disable them until the proper implementation is provided).

* Added timeouts for account reconnects.
* Minor improvements / refactorings.
  • Loading branch information
mblsha committed Feb 3, 2010
1 parent 1198dc5 commit 379da6c
Show file tree
Hide file tree
Showing 94 changed files with 14,771 additions and 544 deletions.
186 changes: 186 additions & 0 deletions src/contactlistaccountgroup.cpp
@@ -0,0 +1,186 @@
/*
* contactlistaccountgroup.h
* Copyright (C) 2009-2010 Michail Pishchagin
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/

#include "contactlistaccountgroup.h"

#include <QStringList>

#include "psicontact.h"
#include "psiaccount.h"
#include "contactlistitemproxy.h"
#include "psiselfcontact.h"
#include "contactlistaccountmenu.h"
#include "contactlistgroupcache.h"

ContactListAccountGroup::ContactListAccountGroup(ContactListModel* model, ContactListGroup* parent, PsiAccount* account)
: ContactListNestedGroup(model, parent, QString())
, isRoot_(!account)
, account_(account)
{
if (account_) {
model->groupCache()->addGroup(this);
connect(account_, SIGNAL(destroyed(QObject*)), SLOT(accountUpdated()));
connect(account_, SIGNAL(updatedAccount()), SLOT(accountUpdated()));
}
}

ContactListAccountGroup::~ContactListAccountGroup()
{
clearGroup();
}

void ContactListAccountGroup::clearGroup()
{
foreach(ContactListAccountGroup* account, accounts_) {
removeItem(findGroup(account));
}
qDeleteAll(accounts_);
accounts_.clear();

ContactListNestedGroup::clearGroup();
}

PsiAccount* ContactListAccountGroup::account() const
{
return account_;
}

ContactListModel::Type ContactListAccountGroup::type() const
{
return ContactListModel::AccountType;
}

void ContactListAccountGroup::addContact(PsiContact* contact, QStringList contactGroups)
{
Q_ASSERT(contact);
if (isRoot()) {
ContactListAccountGroup* accountGroup = findAccount(contact->account());
if (!accountGroup) {
accountGroup = new ContactListAccountGroup(model(), this, contact->account());
accounts_.append(accountGroup);
addItem(new ContactListItemProxy(this, accountGroup));
accountGroup->addContact(accountGroup->account()->selfContact(), QStringList() << QString());
}

accountGroup->addContact(contact, contactGroups);
}
else {
if (model()->groupsEnabled() && !contact->isSelf()) {
ContactListNestedGroup::addContact(contact, contactGroups);
}
else {
ContactListGroup::addContact(contact, contactGroups);
}
}
}

void ContactListAccountGroup::contactGroupsChanged(PsiContact* contact, QStringList contactGroups)
{
if (isRoot()) {
ContactListAccountGroup* accountGroup = findAccount(contact->account());
if (accountGroup) {
accountGroup->contactGroupsChanged(contact, contactGroups);
}
}
else {
if (model()->groupsEnabled() && !contact->isSelf()) {
ContactListNestedGroup::contactGroupsChanged(contact, contactGroups);
}
else {
ContactListGroup::contactGroupsChanged(contact, contactGroups);
}
}
}

bool ContactListAccountGroup::isRoot() const
{
return isRoot_;
}

ContactListAccountGroup* ContactListAccountGroup::findAccount(PsiAccount* account) const
{
Q_ASSERT(isRoot());
foreach(ContactListAccountGroup* accountGroup, accounts_)
if (accountGroup->account() == account)
return accountGroup;

return 0;
}

void ContactListAccountGroup::removeAccount(ContactListAccountGroup* accountGroup)
{
Q_ASSERT(accountGroup);
accounts_.removeAll(accountGroup);
removeItem(ContactListGroup::findGroup(accountGroup));
accountGroup->deleteLater();
}

void ContactListAccountGroup::accountUpdated()
{
Q_ASSERT(!isRoot());
ContactListAccountGroup* root = dynamic_cast<ContactListAccountGroup*>(parent());
Q_ASSERT(root);

model()->updatedItem(root->findGroup(this));

if (account_.isNull() || !account_->enabled()) {
clearGroup();
root->removeAccount(this);
}
}

const QString& ContactListAccountGroup::displayName() const
{
if (account_) {
return account_->name();
}

static QString emptyName;
return emptyName;
}

QString ContactListAccountGroup::internalGroupName() const
{
if (account_) {
return account_->id();
}

return QString();
}

ContactListItemProxy* ContactListAccountGroup::findGroup(ContactListGroup* group) const
{
return ContactListGroup::findGroup(group);
}

ContactListItemMenu* ContactListAccountGroup::contextMenu(ContactListModel* model)
{
return new ContactListAccountMenu(this, model);
}

bool ContactListAccountGroup::isEditable() const
{
return true;
}

bool ContactListAccountGroup::canContainSpecialGroups() const
{
return !isRoot() && model()->groupsEnabled();
}
69 changes: 69 additions & 0 deletions src/contactlistaccountgroup.h
@@ -0,0 +1,69 @@
/*
* contactlistaccountgroup.h
* Copyright (C) 2009-2010 Michail Pishchagin
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/

#ifndef CONTACTLISTACCOUNTGROUP_H
#define CONTACTLISTACCOUNTGROUP_H

#include "contactlistnestedgroup.h"

#include <QPointer>

class PsiAccount;

class ContactListAccountGroup : public ContactListNestedGroup
{
Q_OBJECT
public:
ContactListAccountGroup(ContactListModel* model, ContactListGroup* parent, PsiAccount* account);
~ContactListAccountGroup();

PsiAccount* account() const;
ContactListAccountGroup* findAccount(PsiAccount* account) const;

// reimplemented
virtual ContactListModel::Type type() const;
virtual const QString& displayName() const;
virtual QString internalGroupName() const;
virtual ContactListItemMenu* contextMenu(ContactListModel* model);
virtual bool isEditable() const;
virtual bool canContainSpecialGroups() const;

// reimplemented
virtual void addContact(PsiContact* contact, QStringList contactGroups);
virtual void contactGroupsChanged(PsiContact* contact, QStringList contactGroups);

protected:
void removeAccount(ContactListAccountGroup* accountGroup);
ContactListItemProxy* findGroup(ContactListGroup* group) const;
bool isRoot() const;

// reimplemented
virtual void clearGroup();

private slots:
void accountUpdated();

private:
bool isRoot_;
QPointer<PsiAccount> account_;
QList<ContactListAccountGroup*> accounts_;
};

#endif

3 comments on commit 379da6c

@AlekSi
Copy link
Contributor

@AlekSi AlekSi commented on 379da6c Feb 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\o/

@ivan101
Copy link

@ivan101 ivan101 commented on 379da6c Feb 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\m/

@zet
Copy link

@zet zet commented on 379da6c Feb 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O_O

Please sign in to comment.