Commit b79789e0 authored by Martin Klapetek's avatar Martin Klapetek

Fix coding style

parent bbb2f598
......@@ -113,4 +113,3 @@ void ContactList::onGenericOperationFinished(Tp::PendingOperation *op)
kDebug() << op->errorMessage();
}
}
......@@ -23,18 +23,17 @@
#include <KTp/Models/flat-model-proxy.h>
#include <KTp/Models/accounts-filter-model.h>
#include <TelepathyQt/Types>
/** Exposes general contact list stuff to QML*/
class ContactList : public QObject
{
Q_OBJECT
Q_PROPERTY(QObject* model READ flatModel CONSTANT)
Q_PROPERTY(QObject* filter READ filterModel CONSTANT)
Q_PROPERTY(QObject *model READ flatModel CONSTANT)
Q_PROPERTY(QObject *filter READ filterModel CONSTANT)
public:
ContactList(QObject *parent=0);
ContactList(QObject *parent = 0);
FlatModelProxy* flatModel() const;
AccountsFilterModel* filterModel() const;
......@@ -46,9 +45,9 @@ class ContactList : public QObject
void onGenericOperationFinished(Tp::PendingOperation *op);
private:
ContactsModel* m_contactsModel;
AccountsFilterModel* m_filterModel;
FlatModelProxy* m_flatModel;
ContactsModel *m_contactsModel;
AccountsFilterModel *m_filterModel;
FlatModelProxy *m_flatModel;
Tp::AccountManagerPtr m_accountManager;
};
......
/*
Copyright (C) 2012 Aleix Pol <aleixpol@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
......@@ -21,10 +21,11 @@
#include <TelepathyQt/Contact>
#include "pinned-contacts-model.h"
ContactPin::ContactPin(QObject* parent)
ContactPin::ContactPin(QObject *parent)
: QObject(parent)
, m_model(0)
{}
{
}
Tp::AccountPtr ContactPin::account() const
{
......@@ -44,7 +45,7 @@ PinnedContactsModel* ContactPin::model() const
bool ContactPin::isPinned() const
{
bool ret = false;
if(m_model && m_account && m_contact) {
if (m_model && m_account && m_contact) {
QModelIndex idx = m_model->indexForContact(m_account, m_contact);
ret = idx.isValid();
}
......@@ -59,21 +60,21 @@ void ContactPin::toggle()
}
void ContactPin::setAccount(const Tp::AccountPtr& v)
void ContactPin::setAccount(const Tp::AccountPtr &account)
{
Q_ASSERT(v);
m_account = v;
Q_ASSERT(account);
m_account = account;
Q_EMIT pinnedChanged();
}
void ContactPin::setContact(const Tp::ContactPtr& v)
void ContactPin::setContact(const Tp::ContactPtr &contact)
{
m_contact = v;
m_contact = contact;
Q_EMIT pinnedChanged();
}
void ContactPin::setModel(PinnedContactsModel* m)
void ContactPin::setModel(PinnedContactsModel *model)
{
m_model = m;
m_model = model;
Q_EMIT pinnedChanged();
}
......@@ -29,20 +29,20 @@ class ContactPin : public QObject
Q_OBJECT
Q_PROPERTY(Tp::ContactPtr contact READ contact WRITE setContact)
Q_PROPERTY(Tp::AccountPtr account READ account WRITE setAccount)
Q_PROPERTY(PinnedContactsModel* model READ model WRITE setModel)
Q_PROPERTY(PinnedContactsModel *model READ model WRITE setModel)
Q_PROPERTY(bool pinned READ isPinned NOTIFY pinnedChanged)
public:
explicit ContactPin(QObject* parent = 0);
explicit ContactPin(QObject *parent = 0);
Tp::ContactPtr contact() const;
Tp::AccountPtr account() const;
PinnedContactsModel* model() const;
bool isPinned() const;
void setContact(const Tp::ContactPtr& v);
void setAccount(const Tp::AccountPtr& v);
void setModel(PinnedContactsModel* m);
void setContact(const Tp::ContactPtr &contact);
void setAccount(const Tp::AccountPtr &account);
void setModel(PinnedContactsModel *model);
Q_SCRIPTABLE void toggle();
......@@ -50,7 +50,7 @@ class ContactPin : public QObject
void pinnedChanged();
private:
PinnedContactsModel* m_model;
PinnedContactsModel *m_model;
Tp::ContactPtr m_contact;
Tp::AccountPtr m_account;
};
......
......@@ -30,7 +30,7 @@ class ConversationTarget::ConversationTargetPrivate
Tp::AccountPtr account;
};
ConversationTarget::ConversationTarget(const Tp::AccountPtr& account, const Tp::ContactPtr& contact, QObject* parent) :
ConversationTarget::ConversationTarget(const Tp::AccountPtr &account, const Tp::ContactPtr &contact, QObject *parent) :
QObject(parent),
d(new ConversationTargetPrivate)
{
......@@ -116,7 +116,7 @@ void ConversationTarget::updateAvatar()
path = d->contact->avatarData().fileName;
}
if(path.isEmpty()) {
if (path.isEmpty()) {
path = QLatin1String("im-user");
}
......
......@@ -26,7 +26,6 @@
#include "channel-delegator.h"
class Conversation::ConversationPrivate
{
public:
......@@ -36,8 +35,8 @@ class Conversation::ConversationPrivate
Tp::AccountPtr account;
};
Conversation::Conversation(const Tp::TextChannelPtr& channel,
const Tp::AccountPtr& account,
Conversation::Conversation(const Tp::TextChannelPtr &channel,
const Tp::AccountPtr &account,
QObject *parent) :
QObject(parent),
d (new ConversationPrivate)
......@@ -77,7 +76,7 @@ bool Conversation::isValid()
return d->valid;
}
void Conversation::onChannelInvalidated(Tp::DBusProxy* proxy, const QString& errorName, const QString& errorMessage)
void Conversation::onChannelInvalidated(Tp::DBusProxy *proxy, const QString &errorName, const QString &errorMessage)
{
kDebug() << proxy << errorName << ":" << errorMessage;
......@@ -102,4 +101,3 @@ Conversation::~Conversation()
kDebug();
delete d;
}
......@@ -36,8 +36,8 @@ class Conversation : public QObject
{
Q_OBJECT
Q_PROPERTY(ConversationTarget* target READ target CONSTANT)
Q_PROPERTY(MessagesModel* messages READ messages CONSTANT)
Q_PROPERTY(ConversationTarget *target READ target CONSTANT)
Q_PROPERTY(MessagesModel *messages READ messages CONSTANT)
Q_PROPERTY(bool valid READ isValid NOTIFY validityChanged)
public:
......
......@@ -50,7 +50,12 @@ ConversationsModel::ConversationsModel(QObject *parent) :
setRoleNames(roles);
}
QVariant ConversationsModel::data(const QModelIndex& index, int role) const
ConversationsModel::~ConversationsModel()
{
delete d;
}
QVariant ConversationsModel::data(const QModelIndex &index, int role) const
{
QVariant result;
if (index.isValid()) {
......@@ -62,7 +67,7 @@ QVariant ConversationsModel::data(const QModelIndex& index, int role) const
return result;
}
int ConversationsModel::rowCount(const QModelIndex& parent) const
int ConversationsModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return d->conversations.count();
......@@ -84,7 +89,7 @@ void ConversationsModel::handleChannels(const Tp::MethodInvocationContextPtr<> &
//check that the channel is of type text
Tp::TextChannelPtr textChannel;
Q_FOREACH(const Tp::ChannelPtr & channel, channels) {
Q_FOREACH(const Tp::ChannelPtr &channel, channels) {
textChannel = Tp::TextChannelPtr::dynamicCast(channel);
if (textChannel) {
break;
......@@ -126,7 +131,7 @@ void ConversationsModel::handleChannels(const Tp::MethodInvocationContextPtr<> &
if (!handled && !shouldDelegate) {
beginInsertRows(QModelIndex(), rowCount(), rowCount());
Conversation* newConvo = new Conversation(textChannel, account, this);
Conversation *newConvo = new Conversation(textChannel, account, this);
d->conversations.append(newConvo);
connect(newConvo, SIGNAL(validityChanged(bool)), SLOT(handleValidityChange(bool)));
endInsertRows();
......@@ -140,7 +145,7 @@ bool ConversationsModel::bypassApproval() const
return true;
}
void ConversationsModel::startChat(const Tp::AccountPtr& account, const Tp::ContactPtr& contact)
void ConversationsModel::startChat(const Tp::AccountPtr &account, const Tp::ContactPtr &contact)
{
Q_ASSERT(account);
account->ensureTextChat(contact, QDateTime::currentDateTime(),
......@@ -149,12 +154,11 @@ void ConversationsModel::startChat(const Tp::AccountPtr& account, const Tp::Cont
void ConversationsModel::handleValidityChange(bool valid)
{
if(!valid) {
Conversation* sender = qobject_cast<Conversation*>(QObject::sender());
if (!valid) {
Conversation *sender = qobject_cast<Conversation*>(QObject::sender());
int index = d->conversations.indexOf(sender);
if(index != -1) {
if (index != -1) {
beginRemoveRows(QModelIndex(), index, index);
d->conversations.removeAt(index);
sender->deleteLater();
endRemoveRows();
......@@ -163,8 +167,3 @@ void ConversationsModel::handleValidityChange(bool valid)
}
}
}
ConversationsModel::~ConversationsModel()
{
delete d;
}
......@@ -34,8 +34,8 @@ class ConversationsModel : public QAbstractListModel, public Tp::AbstractClientH
explicit ConversationsModel(QObject *parent);
virtual ~ConversationsModel();
virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const;
virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const;
virtual QVariant data ( const QModelIndex &index, int role = Qt::DisplayRole ) const;
virtual int rowCount ( const QModelIndex &parent = QModelIndex() ) const;
enum role {
ConversationRole = Qt::UserRole
......@@ -51,7 +51,7 @@ class ConversationsModel : public QAbstractListModel, public Tp::AbstractClientH
bool bypassApproval() const;
public Q_SLOTS:
void startChat(const Tp::AccountPtr& account, const Tp::ContactPtr& contact);
void startChat(const Tp::AccountPtr &account, const Tp::ContactPtr &contact);
private:
class ConversationsModelPrivate;
......
......@@ -17,12 +17,13 @@
*/
#include "hide-window-component.h"
#include <kwindowsystem.h>
#include <QDebug>
HideWindowComponent::HideWindowComponent(QObject* parent)
#include <KWindowSystem>
HideWindowComponent::HideWindowComponent(QObject *parent)
: QObject(parent)
{}
{
}
void HideWindowComponent::hideWindowFromTaskbar(qulonglong winId)
{
......
......@@ -30,7 +30,7 @@ class HideWindowComponent : public QObject
{
Q_OBJECT
public:
explicit HideWindowComponent(QObject* parent = 0);
explicit HideWindowComponent(QObject *parent = 0);
Q_SCRIPTABLE void hideWindowFromTaskbar(qulonglong winId);
};
......
......@@ -183,7 +183,7 @@ void MessagesModel::onPendingMessageRemoved()
Q_EMIT unreadCountChanged(unreadCount());
}
QVariant MessagesModel::data(const QModelIndex& index, int role) const
QVariant MessagesModel::data(const QModelIndex &index, int role) const
{
QVariant result;
......@@ -211,7 +211,7 @@ QVariant MessagesModel::data(const QModelIndex& index, int role) const
return result;
}
int MessagesModel::rowCount(const QModelIndex& parent) const
int MessagesModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return d->messages.size();
......
......@@ -51,8 +51,8 @@ class MessagesModel : public QAbstractListModel, public Queueable
MessageTypeNotice
};
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
Tp::TextChannelPtr textChannel() const;
void setTextChannel(Tp::TextChannelPtr channel);
......@@ -72,7 +72,7 @@ class MessagesModel : public QAbstractListModel, public Queueable
void popoutRequested();
public Q_SLOTS:
void sendNewMessage(const QString& message);
void sendNewMessage(const QString &message);
private Q_SLOTS:
void onMessageReceived(const Tp::ReceivedMessage &message);
......
/*
Copyright (C) 2012 Aleix Pol <aleixpol@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
......@@ -19,6 +19,7 @@
#include "pinned-contacts-model.h"
#include "conversations-model.h"
#include "conversation.h"
#include <TelepathyQt/Types>
#include <TelepathyQt/Contact>
#include <TelepathyQt/AvatarData>
......@@ -28,12 +29,14 @@
#include <TelepathyQt/PendingReady>
#include <TelepathyQt/ContactManager>
#include <TelepathyQt/PendingContacts>
#include <KIcon>
#include <KGlobal>
#include <KComponentData>
#include <KConfigGroup>
#include <KStandardDirs>
#include <KDebug>
#include <KTp/presence.h>
struct Pin {
......@@ -45,11 +48,11 @@ class PinnedContactsModelPrivate {
public:
QVector<Pin> m_pins;
Tp::AccountManagerPtr accountManager;
ConversationsModel* convesations;
ConversationsModel *convesations;
QStringList pinsToString() const {
QStringList ret;
Q_FOREACH(const Pin& p, m_pins) {
Q_FOREACH(const Pin &p, m_pins) {
ret += p.account->uniqueIdentifier();
ret += p.contact->id();
}
......@@ -57,18 +60,19 @@ public:
}
};
static Tp::AccountPtr findAccountByUniqueId(Tp::AccountManagerPtr manager, const QString& id)
static Tp::AccountPtr findAccountByUniqueId(Tp::AccountManagerPtr manager, const QString &id)
{
QList<Tp::AccountPtr> accounts = manager->allAccounts();
Q_FOREACH(const Tp::AccountPtr account, accounts) {
if (account->uniqueIdentifier()==id)
if (account->uniqueIdentifier() == id) {
return account;
}
}
Q_ASSERT(false && "account not found");
return Tp::AccountPtr();
}
PinnedContactsModel::PinnedContactsModel(QObject* parent)
PinnedContactsModel::PinnedContactsModel(QObject *parent)
: QAbstractListModel(parent)
, d(new PinnedContactsModelPrivate)
{
......@@ -94,19 +98,19 @@ QStringList PinnedContactsModel::state() const
return d->pinsToString();
}
void PinnedContactsModel::setState(const QStringList& pins)
void PinnedContactsModel::setState(const QStringList &pins)
{
Q_ASSERT(pins.size()%2==0 && "the state should be a pair number of account id and contact name");
Q_ASSERT(pins.size() % 2 == 0 && "the state should be a pair number of account id and contact name");
if(!d->accountManager->isReady()) {
Tp::PendingReady* r = d->accountManager->becomeReady();
Tp::PendingReady *r = d->accountManager->becomeReady();
r->setProperty("newState", pins);
connect(r, SIGNAL(finished(Tp::PendingOperation*)), SLOT(initializeState(Tp::PendingOperation*)));
} else {
kDebug() << "loading pinned...." << pins;
for (int i=0; i<pins.count(); i+=2) {
for (int i = 0; i < pins.count(); i += 2) {
Tp::AccountPtr account = findAccountByUniqueId(d->accountManager, pins[i]);
if (account->connection()) {
Tp::PendingContacts* pending = account->connection()->contactManager()->contactsForIdentifiers(QStringList(pins[i+1]));
Tp::PendingContacts *pending = account->connection()->contactManager()->contactsForIdentifiers(QStringList(pins[i+1]));
pending->setProperty("account", qVariantFromValue<Tp::AccountPtr>(account));
connect(pending, SIGNAL(finished(Tp::PendingOperation*)), SLOT(pinPendingContacts(Tp::PendingOperation*)));
}
......@@ -117,7 +121,7 @@ void PinnedContactsModel::setState(const QStringList& pins)
void PinnedContactsModel::pinPendingContacts(Tp::PendingOperation* j)
{
if (j->isValid()) {
Tp::PendingContacts* job = qobject_cast<Tp::PendingContacts*>(j);
Tp::PendingContacts *job = qobject_cast<Tp::PendingContacts*>(j);
Tp::AccountPtr account = job->property("account").value<Tp::AccountPtr>();
Tp::ContactPtr contact = job->contacts().first();
setPinning(account, contact, true);
......@@ -128,19 +132,20 @@ void PinnedContactsModel::pinPendingContacts(Tp::PendingOperation* j)
QModelIndex PinnedContactsModel::indexForContact(Tp::AccountPtr account, Tp::ContactPtr contact) const
{
int i = 0;
Q_FOREACH(const Pin& p, d->m_pins) {
if (p.account->uniqueIdentifier()==account->uniqueIdentifier() && p.contact->id()==contact->id()) {
Q_FOREACH(const Pin &p, d->m_pins) {
if (p.account->uniqueIdentifier() == account->uniqueIdentifier() && p.contact->id() == contact->id()) {
break;
}
i++;
}
if (i<d->m_pins.count())
if (i < d->m_pins.count()) {
return index(i);
else
} else {
return QModelIndex();
}
}
void PinnedContactsModel::setPinning(const Tp::AccountPtr& account, const Tp::ContactPtr& contact, bool newState)
void PinnedContactsModel::setPinning(const Tp::AccountPtr &account, const Tp::ContactPtr &contact, bool newState)
{
QModelIndex idx = indexForContact(account, contact);
bool found = idx.isValid();
......@@ -154,10 +159,10 @@ void PinnedContactsModel::setPinning(const Tp::AccountPtr& account, const Tp::Co
}
}
QVariant PinnedContactsModel::data(const QModelIndex& index, int role) const
QVariant PinnedContactsModel::data(const QModelIndex &index, int role) const
{
if (index.isValid()) {
const Pin& p = d->m_pins[index.row()];
const Pin &p = d->m_pins[index.row()];
switch(role) {
case Qt::DisplayRole:
return p.contact->alias();
......@@ -174,7 +179,7 @@ QVariant PinnedContactsModel::data(const QModelIndex& index, int role) const
return QVariant::fromValue<Tp::AccountPtr>(p.account);
case AlreadyChattingRole: {
bool found = false;
for(int i=0; !found && i<d->convesations->rowCount(); i++) {
for (int i = 0; !found && i < d->convesations->rowCount(); i++) {
QModelIndex idx = d->convesations->index(i, 0);
Tp::ContactPtr contact = idx.data(ConversationsModel::ConversationRole).value<Conversation*>()->target()->contact();
found |= contact->id() == p.contact->id();
......@@ -196,7 +201,7 @@ QVariant PinnedContactsModel::data(const QModelIndex& index, int role) const
return QVariant();
}
int PinnedContactsModel::rowCount(const QModelIndex& parent) const
int PinnedContactsModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid()) {
return 0;
......@@ -204,24 +209,24 @@ int PinnedContactsModel::rowCount(const QModelIndex& parent) const
return d->m_pins.count();
}
bool PinnedContactsModel::removeRows(int row, int count, const QModelIndex& parent)
bool PinnedContactsModel::removeRows(int row, int count, const QModelIndex &parent)
{
if (parent.isValid() || (row+count)>d->m_pins.count()) {
if (parent.isValid() || (row + count) > d->m_pins.count()) {
return false;
}
beginRemoveRows(parent, row, row+count-1);
beginRemoveRows(parent, row, row + count - 1);
d->m_pins.remove(row, count);
endRemoveRows();
return true;
}
void PinnedContactsModel::appendContact(const Pin& p)
void PinnedContactsModel::appendContact(const Pin &p)
{
int s = d->m_pins.size();
beginInsertRows(QModelIndex(), s, s);
d->m_pins += p;
endInsertRows();
connect(p.contact.data(),
SIGNAL(avatarDataChanged(Tp::AvatarData)),
SLOT(contactDataChanged()));
......@@ -235,10 +240,10 @@ void PinnedContactsModel::appendContact(const Pin& p)
void PinnedContactsModel::contactDataChanged()
{
Tp::Contact* c = qobject_cast<Tp::Contact*>(sender());
int i=0;
Q_FOREACH(const Pin& p, d->m_pins) {
if (p.contact==c) {
Tp::Contact *c = qobject_cast<Tp::Contact*>(sender());
int i = 0;
Q_FOREACH(const Pin &p, d->m_pins) {
if (p.contact == c) {
QModelIndex idx = index(i);
Q_EMIT dataChanged(idx, idx);
return;
......@@ -247,7 +252,7 @@ void PinnedContactsModel::contactDataChanged()
}
}
void PinnedContactsModel::setConversationsModel(ConversationsModel* model)
void PinnedContactsModel::setConversationsModel(ConversationsModel *model)
{
beginResetModel();
d->convesations = model;
......@@ -256,13 +261,13 @@ void PinnedContactsModel::setConversationsModel(ConversationsModel* model)
endResetModel();
}
void PinnedContactsModel::conversationsStateChanged(const QModelIndex& parent, int start, int end)
void PinnedContactsModel::conversationsStateChanged(const QModelIndex &parent, int start, int end)
{
for(int i=start; i<=end; i++) {
for (int i = start; i <= end; i++) {
QModelIndex idx = d->convesations->index(i, 0, parent);
Tp::ContactPtr contact = idx.data(ConversationsModel::ConversationRole).value<Conversation*>()->target()->contact();
Q_FOREACH(const Pin& p, d->m_pins) {
if (p.contact->id()==contact->id())
Q_FOREACH(const Pin &p, d->m_pins) {
if (p.contact->id() == contact->id())
QMetaObject::invokeMethod(this, "dataChanged", Qt::QueuedConnection, Q_ARG(QModelIndex, idx), Q_ARG(QModelIndex, idx));
}
}
......@@ -278,13 +283,13 @@ Tp::AccountManagerPtr PinnedContactsModel::accountManager() const
return d->accountManager;
}
void PinnedContactsModel::setAccountManager(const Tp::AccountManagerPtr& accounts)
void PinnedContactsModel::setAccountManager(const Tp::AccountManagerPtr &accounts)
{
accounts->becomeReady();
d->accountManager = accounts;
}
void PinnedContactsModel::initializeState(Tp::PendingOperation* op)
void PinnedContactsModel::initializeState(Tp::PendingOperation *op)
{
setState(op->property("newState").toStringList());
}
......@@ -30,49 +30,49 @@ class PinnedContactsModelPrivate;
class PinnedContactsModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(ConversationsModel* conversations READ conversationsModel WRITE setConversationsModel)
Q_PROPERTY(ConversationsModel *conversations READ conversationsModel WRITE setConversationsModel)
Q_PROPERTY(Tp::AccountManagerPtr accountManager READ accountManager WRITE setAccountManager)
Q_PROPERTY(QStringList state READ state WRITE setState)
Q_PROPERTY(int count READ rowCount NOTIFY countChanged);
public:
explicit PinnedContactsModel(QObject* parent = 0);
explicit PinnedContactsModel(QObject *parent = 0);
virtual ~PinnedContactsModel();
enum role {
PresenceIconRole = Qt::UserRole+1,
PresenceIconRole = Qt::UserRole + 1,
AvailabilityRole,
ContactRole,
AccountRole,
AlreadyChattingRole
};
virtual QVariant data(const QModelIndex& index, int role) const;