Skip to content

Commit

Permalink
Rework chats list
Browse files Browse the repository at this point in the history
  • Loading branch information
ksiazkowicz committed Dec 13, 2013
1 parent 0445091 commit 6b63a67
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 17 deletions.
15 changes: 8 additions & 7 deletions qml/Dialogs/Chats.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ CommonDialog {
Rectangle {
id: wrapper
width: listViewChats.width
gradient: unreadMsg > 0 ? incomingMsg : nihilNovi
gradient: txtJid.unreadMsg > 0 ? incomingMsg : nihilNovi

Gradient {
id: incomingMsg
Expand All @@ -47,7 +47,7 @@ CommonDialog {

Image {
id: imgPresence
source: rosterLayoutAvatar ? (avatarPath == "" ? "qrc:/avatar" : avatarPath) : presence
source: rosterLayoutAvatar ? xmppClient.getAvatarByJid(jid) : xmppClient.getPropertyByJid(jid,"presence")
sourceSize.height: rosterItemHeight-4
sourceSize.width: rosterItemHeight-4
anchors { verticalCenter: parent.verticalCenter; left: parent.left; leftMargin: 10 }
Expand All @@ -56,11 +56,12 @@ CommonDialog {
} //imgPresence
Text {
id: txtJid
property string contact: name
property string contact: xmppClient.getPropertyByJid(jid,"name")
property int unreadMsg: parseInt(xmppClient.getPropertyByJid(jid,"unreadMsg"))
anchors { left: imgPresence.right; right: imgPresenceR.left; leftMargin: 10; rightMargin: 10; verticalCenter: parent.verticalCenter }
width: parent.width
maximumLineCount: (rosterItemHeight/22) > 1 ? (rosterItemHeight/22) : 1
text: (name === "" ? jid : name) + (unreadMsg > 0 ? " [" + unreadMsg + "]" : "")
text: (contact === "" ? jid : contact) + (unreadMsg > 0 ? " [" + unreadMsg + "]" : "")
onLinkActivated: { main.url=link; linkContextMenu.open()}
wrapMode: Text.Wrap
font.pixelSize: 16
Expand All @@ -74,8 +75,8 @@ CommonDialog {
onClicked: {
listViewChats.currentIndex = index
xmppClient.chatJid = jid
xmppClient.contactName = name
main.globalUnreadCount = main.globalUnreadCount - unreadMsg
xmppClient.contactName = txtJid.contact
main.globalUnreadCount = main.globalUnreadCount - txtJid.unreadMsg
xmppClient.resetUnreadMessages( jid )
if (settings.gBool("behavior","enableHsWidget")) {
notify.postHSWidget()
Expand All @@ -85,7 +86,7 @@ CommonDialog {
}
Image {
id: imgPresenceR
source: rosterLayoutAvatar ? presence : ""
source: rosterLayoutAvatar ? xmppClient.getPropertyByJid(jid,"presence") : ""
sourceSize.height: (wrapper.height/3) - 4
sourceSize.width: (wrapper.height/3) - 4
anchors { verticalCenter: parent.verticalCenter; right: parent.right; rightMargin: rosterLayoutAvatar ? 10 : 0 }
Expand Down
9 changes: 5 additions & 4 deletions qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ PageStackWindow {
if (!isActive && settings.gBool("notifications", "wibblyWobblyTimeyWimeyStuff")) { blinker.running = true }
if (settings.gBool("notifications", "usePopupRecv") == true && (xmppClient.chatJid !== bareJidLastMsg || !isActive)) {
if (settings.gBool("behavior","msgInDiscrPopup")) {
avkon.showPopup(getNameByJid(bareJidLastMsg), getLastSqlMessage(),settings.gBool("behavior","linkInDiscrPopup"))
avkon.showPopup(getPropertyByJid(bareJidLastMsg,"name"), getLastSqlMessage(),settings.gBool("behavior","linkInDiscrPopup"))
} else {
avkon.showPopup(globalUnreadCount + " unread messages", "New message from "+ getNameByJid(bareJidLastMsg) + ".",settings.gBool("behavior","linkInDiscrPopup"))
avkon.showPopup(globalUnreadCount + " unread messages", "New message from "+ getPropertyByJid(bareJidLastMsg,"name") + ".",settings.gBool("behavior","linkInDiscrPopup"))
}
}
notifySndVibr("MsgRecv")
Expand Down Expand Up @@ -144,8 +144,8 @@ PageStackWindow {
onTypingChanged: {
if (settings.gBool("notifications", "notifyTyping") == true && (xmppClient.chatJid !== bareJid || !isActive) && xmppClient.myBareJid !== bareJid) {
if (isTyping) {
avkon.showPopup(getNameByJid(bareJid),"is typing a message...",settings.gBool("behavior","linkInDiscrPopup"))
} else { avkon.showPopup(getNameByJid(bareJid),"stopped typing.",settings.gBool("behavior","linkInDiscrPopup")) }
avkon.showPopup(getPropertyByJid(bareJid,"name"),"is typing a message...",settings.gBool("behavior","linkInDiscrPopup"))
} else { avkon.showPopup(getPropertyByJid(bareJid,"name"),"stopped typing.",settings.gBool("behavior","linkInDiscrPopup")) }
}
}
} //XmppClient
Expand Down Expand Up @@ -208,6 +208,7 @@ PageStackWindow {
globalUnreadCount = xmppClient.getUnreadCount()

console.log("QML: main::initAccount():" + xmppClient.myBareJid + "/" + xmppClient.resource);
xmppClient.updateChats()
} else {
_existDefaultAccount = true
accc++
Expand Down
2 changes: 1 addition & 1 deletion src/database/DatabaseManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ bool DatabaseManager::setChatInProgress()
queryStr += params.at(0);
ret = query.exec(queryStr);
emit finished();
emit rosterChanged();
emit chatsChanged();
return ret;
}

Expand Down
12 changes: 8 additions & 4 deletions src/database/DatabaseWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ DatabaseWorker::DatabaseWorker(QObject *parent) :
connect(database,SIGNAL(finished()), this, SIGNAL(finished()));
connect(database,SIGNAL(messagesChanged()), this, SIGNAL(messagesChanged()));
connect(database,SIGNAL(rosterChanged()), this, SIGNAL(rosterChanged()));
connect(database,SIGNAL(chatsChanged()), this, SLOT(chatsMustBeUpdated()));

//initialize SqlQueryModels
sqlRoster = new SqlQueryModel( 0 );
this->updateRoster(1);
sqlMessages = new SqlQueryModel( 0 );
this->updateMessages(1,"",1);
sqlChats = new SqlQueryModel( 0 );
this->updateChats(1);

// populates queryType list so I could use switch with QStrings. I like switches.
queryType << "begin" << "end" << "insertMessage" << "insertContact" << "deleteContact" <<
Expand Down Expand Up @@ -82,20 +81,25 @@ void DatabaseWorker::executeQuery(QStringList& query) {
}
}

void DatabaseWorker::chatsMustBeUpdated() {
this->updateChats(accountId);
}

void DatabaseWorker::updateChats(int m_accountId) {
qDebug() << "DatabaseWorker::updateChats(): updating chats list.";
sqlChats->setQuery("select * from roster where isChatInProgress=1 and id_account=" + QString::number(m_accountId)+" order by unreadMsg desc",database->db);
if (!sqlChats->lastError().NoError) qDebug() << sqlChats->lastError();
sqlChats->setQuery("select jid from roster where isChatInProgress=1 and id_account=" + QString::number(m_accountId),database->db);
emit sqlChatsUpdated();
}

void DatabaseWorker::updateRoster(int m_accountId) {
if (accountId != m_accountId) accountId = m_accountId;
qDebug() << "DatabaseWorker::updateRoster(): updating contact list.";
sqlRoster->setQuery("select * from roster where id_account="+QString::number(m_accountId), database->db);
emit sqlRosterUpdated();
}

void DatabaseWorker::updateMessages(int m_accountId, QString bareJid, int page) {
if (accountId != m_accountId) accountId = m_accountId;
qDebug() << "DatabaseWorker::updateMessages(): updating messages query model.";
int border = page*20;
sqlMessages = new SqlQueryModel( 0 );
Expand Down
4 changes: 4 additions & 0 deletions src/database/DatabaseWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ public slots:
void updateRoster(int m_accountId);
void updateMessages(int m_accountId, QString bareJid, int page);

private slots:
void chatsMustBeUpdated();

private:
DatabaseManager* database;
QStringList queryType;
int accountId;
};

#endif // DATABASEWORKER_H
1 change: 1 addition & 0 deletions src/database/databasemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class DatabaseManager: public QObject
void finished();
void rosterChanged();
void messagesChanged();
void chatsChanged();

public:
bool deleteDB();
Expand Down
3 changes: 2 additions & 1 deletion src/xmpp/MyXmppClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public :
Q_INVOKABLE bool sendMyMessage( QString bareJid, QString resource, QString msgBody );

/*--- info by jid ---*/
Q_INVOKABLE QString getNameByJid( QString bareJid ) { return dbWorker->sqlRoster->record(dbWorker->getRecordIDbyJid(bareJid)).value("name").toString(); }
Q_INVOKABLE QString getPropertyByJid( QString bareJid, QString property ) { return dbWorker->sqlRoster->record(dbWorker->getRecordIDbyJid(bareJid)).value(property).toString(); }
Q_INVOKABLE QStringList getResourcesByJid( QString bareJid ) { return rosterManager->getResources(bareJid); }

/*--- add/remove contact ---*/
Expand Down Expand Up @@ -325,6 +325,7 @@ public slots:
Q_INVOKABLE void closeChat( QString jid ) { this->resetUnreadMessages( jid ); dbWorker->executeQuery(QStringList() << "setChatInProgress" << QString::number(m_accountId) << jid << "0"); rosterNeedsUpdate = true; emit chatClosed( jid ); }

Q_INVOKABLE void updateMessages() { dbWorker->updateMessages(m_accountId,m_chatJid,page); }
Q_INVOKABLE void updateChats() { dbWorker->updateChats(m_accountId); }

private slots:
void initRoster();
Expand Down

0 comments on commit 6b63a67

Please sign in to comment.