Commit cf4fac5c authored by Martin Klapetek's avatar Martin Klapetek Committed by Alexander Akulich

[declarative] Various style fixes that have accumulated here through time

Reviewed-by: Alexander Akulich's avatarAlexandr Akulich <akulichalexander@gmail.com>
parent 769e7a06
......@@ -81,7 +81,7 @@ Conversation::Conversation(QObject *parent)
{
}
void Conversation::setTextChannel(const Tp::TextChannelPtr& channel)
void Conversation::setTextChannel(const Tp::TextChannelPtr &channel)
{
if (!d->messages) {
d->messages = new MessagesModel(d->account, this);
......@@ -161,7 +161,8 @@ QIcon Conversation::avatar() const
}
}
KTp::ContactPtr Conversation::targetContact() const {
KTp::ContactPtr Conversation::targetContact() const
{
if (d->isGroupChat) {
return KTp::ContactPtr();
} else {
......@@ -169,7 +170,8 @@ KTp::ContactPtr Conversation::targetContact() const {
}
}
Tp::AccountPtr Conversation::account() const {
Tp::AccountPtr Conversation::account() const
{
return d->account;
}
......
......@@ -40,9 +40,9 @@ class ConversationsModel::ConversationsModelPrivate
};
ConversationsModel::ConversationsModel(QObject *parent) :
QAbstractListModel(parent),
Tp::AbstractClientHandler(channelClassList()),
d(new ConversationsModelPrivate)
QAbstractListModel(parent),
Tp::AbstractClientHandler(channelClassList()),
d(new ConversationsModelPrivate)
{
d->activeChatIndex = -1;
connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)), SIGNAL(totalUnreadCountChanged()));
......@@ -65,10 +65,8 @@ QHash<int, QByteArray> ConversationsModel::roleNames() const
QVariant ConversationsModel::data(const QModelIndex &index, int role) const
{
QVariant result;
if (index.isValid()) {
if (role == ConversationRole) {
result = QVariant::fromValue<Conversation*>(d->conversations[index.row()]);
}
if (index.isValid() && role == ConversationRole) {
result = QVariant::fromValue<Conversation*>(d->conversations[index.row()]);
}
return result;
}
......@@ -96,7 +94,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;
......@@ -106,9 +104,10 @@ void ConversationsModel::handleChannels(const Tp::MethodInvocationContextPtr<> &
Q_ASSERT(textChannel);
//find the relevant channelRequest
Q_FOREACH(const Tp::ChannelRequestPtr channelRequest, channelRequests) {
Q_FOREACH (const Tp::ChannelRequestPtr channelRequest, channelRequests) {
qCDebug(KTP_DECLARATIVE) << channelRequest->hints().allHints();
shouldDelegate = channelRequest->hints().hint(QLatin1String("org.freedesktop.Telepathy.ChannelRequest"), QLatin1String("DelegateToPreferredHandler")).toBool();
shouldDelegate = channelRequest->hints().hint(QLatin1String("org.freedesktop.Telepathy.ChannelRequest"),
QLatin1String("DelegateToPreferredHandler")).toBool();
}
//loop through all conversations checking for matches
......@@ -116,18 +115,18 @@ void ConversationsModel::handleChannels(const Tp::MethodInvocationContextPtr<> &
//if we are handling and we're not told to delegate it, update the text channel
//if we are handling but should delegate, call delegate channel
int i = 0;
Q_FOREACH(Conversation *convo, d->conversations) {
if (convo->textChannel()->targetId() == textChannel->targetId() &&
convo->textChannel()->targetHandleType() == textChannel->targetHandleType())
Q_FOREACH (Conversation *conversation, d->conversations) {
if (conversation->textChannel()->targetId() == textChannel->targetId()
&& conversation->textChannel()->targetHandleType() == textChannel->targetHandleType())
{
if (!shouldDelegate) {
convo->setTextChannel(textChannel);
conversation->setTextChannel(textChannel);
//Update the active chat index to this channel
d->activeChatIndex = i;
Q_EMIT activeChatIndexChanged();
} else {
if (convo->textChannel() == textChannel) {
convo->delegateToProperClient();
if (conversation->textChannel() == textChannel) {
conversation->delegateToProperClient();
}
}
handled = true;
......@@ -148,7 +147,7 @@ void ConversationsModel::handleChannels(const Tp::MethodInvocationContextPtr<> &
//If this is a locally generated request or there is no active chat, the index of the newly inserted conversation is saved as the active chat
//The model is reset to load the newly created chat channel
if(textChannel->isRequested() || d->activeChatIndex == -1) {
if (textChannel->isRequested() || d->activeChatIndex == -1) {
d->activeChatIndex = rowCount() - 1;
Q_EMIT activeChatIndexChanged();
}
......@@ -181,14 +180,14 @@ void ConversationsModel::removeConversation(Conversation* conv)
int ConversationsModel::nextActiveConversation(int fromRow)
{
if(d->conversations.isEmpty()) {
if (d->conversations.isEmpty()) {
return -1;
}
Q_ASSERT(qBound(0, fromRow, d->conversations.count()-1) == fromRow);
Q_ASSERT(qBound(0, fromRow, d->conversations.count() - 1) == fromRow);
bool first = true; //let first be checked on the first loop
for(int i = fromRow; i != fromRow || first; i = (i + 1) % d->conversations.count()) {
if(d->conversations[i]->messages()->unreadCount() > 0) {
for (int i = fromRow; i != fromRow || first; i = (i + 1) % d->conversations.count()) {
if (d->conversations[i]->messages()->unreadCount() > 0) {
return i;
}
first = false;
......
......@@ -33,13 +33,13 @@ class ConversationsModel : public QAbstractListModel, public Tp::AbstractClientH
Q_PROPERTY(int totalUnreadCount READ totalUnreadCount NOTIFY totalUnreadCountChanged)
Q_PROPERTY(int activeChatIndex READ activeChatIndex NOTIFY activeChatIndexChanged)
public:
explicit ConversationsModel(QObject *parent=0);
public:
explicit ConversationsModel(QObject *parent = 0);
virtual ~ConversationsModel();
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
virtual QVariant data ( const QModelIndex &index, int role = Qt::DisplayRole ) const Q_DECL_OVERRIDE;
virtual int rowCount ( const QModelIndex &parent = QModelIndex() ) const Q_DECL_OVERRIDE;
virtual QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
virtual int rowCount (const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
/** @returns the sum of all unread messages among all conversations */
int totalUnreadCount() const;
......@@ -62,21 +62,21 @@ class ConversationsModel : public QAbstractListModel, public Tp::AbstractClientH
const HandlerInfo &handlerInfo);
bool bypassApproval() const;
public Q_SLOTS:
public Q_SLOTS:
int nextActiveConversation(int first);
private:
void removeConversation(Conversation* conversation);
private:
void removeConversation(Conversation *conversation);
class ConversationsModelPrivate;
ConversationsModelPrivate *d;
private Q_SLOTS:
private Q_SLOTS:
void onConversationCloseRequested();
Q_SIGNALS:
void totalUnreadCountChanged();
void activeChatIndexChanged();
Q_SIGNALS:
void totalUnreadCountChanged();
void activeChatIndexChanged();
};
#endif // CONVERSATIONS_MODEL_H
......@@ -195,22 +195,22 @@ void MessagesModel::onMessageReceived(const Tp::ReceivedMessage &message)
MessagePrivate &originalMessage = d->messages[originalMessageIndex.row()];
originalMessage.deliveryReportReceiveTime = message.received();
switch(deliveryDetails.status()) {
case Tp::DeliveryStatusPermanentlyFailed:
case Tp::DeliveryStatusTemporarilyFailed:
originalMessage.deliveryStatus = DeliveryStatusFailed;
if (deliveryDetails.hasDebugMessage()) {
qCDebug(KTP_DECLARATIVE) << "Delivery failure debug message:" << deliveryDetails.debugMessage();
}
break;
case Tp::DeliveryStatusDelivered:
originalMessage.deliveryStatus = DeliveryStatusDelivered;
break;
case Tp::DeliveryStatusRead:
originalMessage.deliveryStatus = DeliveryStatusRead;
break;
default:
originalMessage.deliveryStatus = DeliveryStatusUnknown;
break;
case Tp::DeliveryStatusPermanentlyFailed:
case Tp::DeliveryStatusTemporarilyFailed:
originalMessage.deliveryStatus = DeliveryStatusFailed;
if (deliveryDetails.hasDebugMessage()) {
qCDebug(KTP_DECLARATIVE) << "Delivery failure debug message:" << deliveryDetails.debugMessage();
}
break;
case Tp::DeliveryStatusDelivered:
originalMessage.deliveryStatus = DeliveryStatusDelivered;
break;
case Tp::DeliveryStatusRead:
originalMessage.deliveryStatus = DeliveryStatusRead;
break;
default:
originalMessage.deliveryStatus = DeliveryStatusUnknown;
break;
}
Q_EMIT dataChanged(originalMessageIndex, originalMessageIndex);
} else {
......
......@@ -92,7 +92,7 @@ void PinnedContactsModel::setState(const QStringList &pins)
QModelIndex PinnedContactsModel::indexForContact(const KTp::ContactPtr &contact) const
{
for (int i=0; i<d->m_pins.size() && contact; i++) {
for (int i = 0; i < d->m_pins.size() && contact; i++) {
if (d->m_pins[i]->contactId() == contact->id()) {
return index(i);
}
......@@ -132,12 +132,11 @@ QVariant PinnedContactsModel::data(const QModelIndex &index, int role) const
case AvailabilityRole:
if (!p->contact()) {
return false;
}
else {
return p->contact()->presence().type()!=Tp::ConnectionPresenceTypeOffline
&& p->contact()->presence().type()!=Tp::ConnectionPresenceTypeError
&& p->contact()->presence().type()!=Tp::ConnectionPresenceTypeUnset
&& p->contact()->presence().type()!=Tp::ConnectionPresenceTypeUnknown;
} else {
return p->contact()->presence().type() != Tp::ConnectionPresenceTypeOffline
&& p->contact()->presence().type() != Tp::ConnectionPresenceTypeError
&& p->contact()->presence().type() != Tp::ConnectionPresenceTypeUnset
&& p->contact()->presence().type() != Tp::ConnectionPresenceTypeUnknown;
}
case ContactRole:
return QVariant::fromValue<KTp::ContactPtr>(p->contact());
......@@ -184,7 +183,7 @@ int PinnedContactsModel::rowCount(const QModelIndex &parent) const
void PinnedContactsModel::removeContactPin(const KTp::PersistentContactPtr &pin)
{
int row = d->m_pins.indexOf(pin);
if (row>=0) {
if (row >= 0) {
beginRemoveRows(QModelIndex(), row, row);
d->m_pins.removeAt(row);
endRemoveRows();
......@@ -259,10 +258,10 @@ void PinnedContactsModel::conversationsStateChanged(const QModelIndex &parent, i
{
for (int i = start; i <= end; i++) {
QModelIndex idx = d->conversations->index(i, 0, parent);
Conversation* conv = idx.data(ConversationsModel::ConversationRole).value<Conversation*>();
Conversation *conv = idx.data(ConversationsModel::ConversationRole).value<Conversation*>();
QString contactId = conv->targetContact()->id();
Q_FOREACH(const KTp::PersistentContactPtr &p, d->m_pins) {
Q_FOREACH (const KTp::PersistentContactPtr &p, d->m_pins) {
if (p->contactId() == contactId) {
QModelIndex contactIdx = indexForContact(p->contact());
//We need to delay the dataChanged until the next event loop, when endRowsRemoved has been called
......
......@@ -60,7 +60,7 @@ class PinnedContactsModel : public QAbstractListModel
void setConversationsModel(ConversationsModel *model);
QStringList state() const;
void setState(const QStringList &s);
void setState(const QStringList &state);
private Q_SLOTS:
void contactDataChanged();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment