forked from blue/squawk
First steps on the new idea of file up/downloading
This commit is contained in:
parent
8f914c02a7
commit
3a7735b192
23 changed files with 650 additions and 525 deletions
|
@ -30,7 +30,7 @@ Models::Element::Element(Type p_type, const Models::Account* acc, const QString&
|
|||
feed(new MessageFeed(this))
|
||||
{
|
||||
connect(feed, &MessageFeed::requestArchive, this, &Element::requestArchive);
|
||||
connect(feed, &MessageFeed::fileLocalPathRequest, this, &Element::fileLocalPathRequest);
|
||||
connect(feed, &MessageFeed::fileDownloadRequest, this, &Element::fileDownloadRequest);
|
||||
|
||||
QMap<QString, QVariant>::const_iterator itr = data.find("avatarState");
|
||||
if (itr != data.end()) {
|
||||
|
@ -156,8 +156,17 @@ bool Models::Element::isRoom() const
|
|||
return type != contact;
|
||||
}
|
||||
|
||||
void Models::Element::fileProgress(const QString& messageId, qreal value)
|
||||
void Models::Element::fileProgress(const QString& messageId, qreal value, bool up)
|
||||
{
|
||||
feed->fileProgress(messageId, value);
|
||||
feed->fileProgress(messageId, value, up);
|
||||
}
|
||||
|
||||
void Models::Element::fileComplete(const QString& messageId, bool up)
|
||||
{
|
||||
feed->fileComplete(messageId, up);
|
||||
}
|
||||
|
||||
void Models::Element::fileError(const QString& messageId, const QString& error, bool up)
|
||||
{
|
||||
feed->fileError(messageId, error, up);
|
||||
}
|
||||
|
|
|
@ -43,11 +43,13 @@ public:
|
|||
unsigned int getMessagesCount() const;
|
||||
void responseArchive(const std::list<Shared::Message> list, bool last);
|
||||
bool isRoom() const;
|
||||
void fileProgress(const QString& messageId, qreal value);
|
||||
void fileProgress(const QString& messageId, qreal value, bool up);
|
||||
void fileError(const QString& messageId, const QString& error, bool up);
|
||||
void fileComplete(const QString& messageId, bool up);
|
||||
|
||||
signals:
|
||||
void requestArchive(const QString& before);
|
||||
void fileLocalPathRequest(const QString& messageId, const QString& url);
|
||||
void fileDownloadRequest(const QString& url);
|
||||
|
||||
protected:
|
||||
void setJid(const QString& p_jid);
|
||||
|
|
|
@ -305,7 +305,7 @@ void Models::MessageFeed::downloadAttachment(const QString& messageId)
|
|||
if (progressPair.second) { //Only to take action if we weren't already downloading it
|
||||
Shared::Message* msg = static_cast<Shared::Message*>(ind.internalPointer());
|
||||
emit dataChanged(ind, ind);
|
||||
emit fileLocalPathRequest(messageId, msg->getOutOfBandUrl());
|
||||
emit fileDownloadRequest(msg->getOutOfBandUrl());
|
||||
} else {
|
||||
qDebug() << "Attachment download for message with id" << messageId << "is already in progress, skipping";
|
||||
}
|
||||
|
@ -319,16 +319,34 @@ void Models::MessageFeed::uploadAttachment(const QString& messageId)
|
|||
qDebug() << "request to upload attachment of the message" << messageId;
|
||||
}
|
||||
|
||||
void Models::MessageFeed::fileProgress(const QString& messageId, qreal value)
|
||||
void Models::MessageFeed::fileProgress(const QString& messageId, qreal value, bool up)
|
||||
{
|
||||
Progress::iterator itr = downloads.find(messageId);
|
||||
if (itr != downloads.end()) {
|
||||
Progress* pr = 0;
|
||||
if (up) {
|
||||
pr = &uploads;
|
||||
} else {
|
||||
pr = &downloads;
|
||||
}
|
||||
|
||||
Progress::iterator itr = pr->find(messageId);
|
||||
if (itr != pr->end()) {
|
||||
itr->second = value;
|
||||
QModelIndex ind = modelIndexById(messageId);
|
||||
emit dataChanged(ind, ind);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::MessageFeed::fileComplete(const QString& messageId, bool up)
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
void Models::MessageFeed::fileError(const QString& messageId, const QString& error, bool up)
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
|
||||
QModelIndex Models::MessageFeed::modelIndexById(const QString& id) const
|
||||
{
|
||||
StorageById::const_iterator itr = indexById.find(id);
|
||||
|
|
|
@ -59,12 +59,14 @@ public:
|
|||
void uploadAttachment(const QString& messageId);
|
||||
|
||||
unsigned int unreadMessagesCount() const;
|
||||
void fileProgress(const QString& messageId, qreal value);
|
||||
void fileProgress(const QString& messageId, qreal value, bool up);
|
||||
void fileError(const QString& messageId, const QString& error, bool up);
|
||||
void fileComplete(const QString& messageId, bool up);
|
||||
|
||||
signals:
|
||||
void requestArchive(const QString& before);
|
||||
void requestStateChange(bool requesting);
|
||||
void fileLocalPathRequest(const QString& messageId, const QString& url);
|
||||
void fileDownloadRequest(const QString& url);
|
||||
|
||||
protected:
|
||||
bool sentByMe(const Shared::Message& msg) const;
|
||||
|
@ -141,6 +143,8 @@ enum AttachmentType {
|
|||
local,
|
||||
downloading,
|
||||
uploading,
|
||||
errorDownload,
|
||||
errorUpload,
|
||||
ready
|
||||
};
|
||||
|
||||
|
|
|
@ -27,8 +27,7 @@ Models::Roster::Roster(QObject* parent):
|
|||
root(new Item(Item::root, {{"name", "root"}})),
|
||||
accounts(),
|
||||
groups(),
|
||||
contacts(),
|
||||
requestedFiles()
|
||||
contacts()
|
||||
{
|
||||
connect(accountsModel, &Accounts::dataChanged, this, &Roster::onAccountDataChanged);
|
||||
connect(root, &Item::childChanged, this, &Roster::onChildChanged);
|
||||
|
@ -448,7 +447,7 @@ void Models::Roster::addContact(const QString& account, const QString& jid, cons
|
|||
if (itr == contacts.end()) {
|
||||
contact = new Contact(acc, jid, data);
|
||||
connect(contact, &Contact::requestArchive, this, &Roster::onElementRequestArchive);
|
||||
connect(contact, &Contact::fileLocalPathRequest, this, &Roster::onElementFileLocalPathRequest);
|
||||
connect(contact, &Contact::fileDownloadRequest, this, &Roster::fileDownloadRequest);
|
||||
contacts.insert(std::make_pair(id, contact));
|
||||
} else {
|
||||
contact = itr->second;
|
||||
|
@ -534,35 +533,19 @@ void Models::Roster::removeGroup(const QString& account, const QString& name)
|
|||
|
||||
void Models::Roster::changeContact(const QString& account, const QString& jid, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
ElId id(account, jid);
|
||||
std::map<ElId, Contact*>::iterator cItr = contacts.find(id);
|
||||
|
||||
if (cItr != contacts.end()) {
|
||||
Element* el = getElement({account, jid});
|
||||
if (el != NULL) {
|
||||
for (QMap<QString, QVariant>::const_iterator itr = data.begin(), end = data.end(); itr != end; ++itr) {
|
||||
cItr->second->update(itr.key(), itr.value());
|
||||
}
|
||||
} else {
|
||||
std::map<ElId, Room*>::iterator rItr = rooms.find(id);
|
||||
if (rItr != rooms.end()) {
|
||||
for (QMap<QString, QVariant>::const_iterator itr = data.begin(), end = data.end(); itr != end; ++itr) {
|
||||
rItr->second->update(itr.key(), itr.value());
|
||||
}
|
||||
el->update(itr.key(), itr.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::changeMessage(const QString& account, const QString& jid, const QString& id, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
ElId elid(account, jid);
|
||||
std::map<ElId, Contact*>::iterator cItr = contacts.find(elid);
|
||||
|
||||
if (cItr != contacts.end()) {
|
||||
cItr->second->changeMessage(id, data);
|
||||
} else {
|
||||
std::map<ElId, Room*>::iterator rItr = rooms.find(elid);
|
||||
if (rItr != rooms.end()) {
|
||||
rItr->second->changeMessage(id, data);
|
||||
}
|
||||
Element* el = getElement({account, jid});
|
||||
if (el != NULL) {
|
||||
el->changeMessage(id, data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -626,7 +609,6 @@ void Models::Roster::removeContact(const QString& account, const QString& jid, c
|
|||
} else {
|
||||
delete ref;
|
||||
}
|
||||
|
||||
if (gr->childCount() == 0) {
|
||||
removeGroup(account, group);
|
||||
}
|
||||
|
@ -707,15 +689,9 @@ void Models::Roster::removePresence(const QString& account, const QString& jid,
|
|||
|
||||
void Models::Roster::addMessage(const QString& account, const Shared::Message& data)
|
||||
{
|
||||
ElId id(account, data.getPenPalJid());
|
||||
std::map<ElId, Contact*>::iterator itr = contacts.find(id);
|
||||
if (itr != contacts.end()) {
|
||||
itr->second->addMessage(data);
|
||||
} else {
|
||||
std::map<ElId, Room*>::const_iterator rItr = rooms.find(id);
|
||||
if (rItr != rooms.end()) {
|
||||
rItr->second->addMessage(data);
|
||||
}
|
||||
Element* el = getElement({account, data.getPenPalJid()});
|
||||
if (el != NULL) {
|
||||
el->addMessage(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -808,7 +784,7 @@ void Models::Roster::addRoom(const QString& account, const QString jid, const QM
|
|||
|
||||
Room* room = new Room(acc, jid, data);
|
||||
connect(room, &Contact::requestArchive, this, &Roster::onElementRequestArchive);
|
||||
connect(room, &Contact::fileLocalPathRequest, this, &Roster::onElementFileLocalPathRequest);
|
||||
connect(room, &Contact::fileDownloadRequest, this, &Roster::fileDownloadRequest);
|
||||
rooms.insert(std::make_pair(id, room));
|
||||
acc->appendChild(room);
|
||||
}
|
||||
|
@ -971,51 +947,55 @@ void Models::Roster::onElementRequestArchive(const QString& before)
|
|||
void Models::Roster::responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list, bool last)
|
||||
{
|
||||
ElId id(account, jid);
|
||||
std::map<ElId, Contact*>::iterator itr = contacts.find(id);
|
||||
if (itr != contacts.end()) {
|
||||
itr->second->responseArchive(list, last);
|
||||
Element* el = getElement(id);
|
||||
if (el != NULL) {
|
||||
el->responseArchive(list, last);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::fileProgress(const std::list<Shared::MessageInfo>& msgs, qreal value, bool up)
|
||||
{
|
||||
for (const Shared::MessageInfo& info : msgs) {
|
||||
Element* el = getElement({info.account, info.jid});
|
||||
if (el != NULL) {
|
||||
el->fileProgress(info.messageId, value, up);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::fileComplete(const std::list<Shared::MessageInfo>& msgs, bool up)
|
||||
{
|
||||
for (const Shared::MessageInfo& info : msgs) {
|
||||
Element* el = getElement({info.account, info.jid});
|
||||
if (el != NULL) {
|
||||
el->fileComplete(info.messageId, up);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::fileError(const std::list<Shared::MessageInfo>& msgs, const QString& err, bool up)
|
||||
{
|
||||
for (const Shared::MessageInfo& info : msgs) {
|
||||
Element* el = getElement({info.account, info.jid});
|
||||
if (el != NULL) {
|
||||
el->fileError(info.messageId, err, up);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Models::Element * Models::Roster::getElement(const Models::Roster::ElId& id)
|
||||
{
|
||||
std::map<ElId, Contact*>::iterator cItr = contacts.find(id);
|
||||
|
||||
if (cItr != contacts.end()) {
|
||||
return cItr->second;
|
||||
} else {
|
||||
std::map<ElId, Room*>::const_iterator rItr = rooms.find(id);
|
||||
std::map<ElId, Room*>::iterator rItr = rooms.find(id);
|
||||
if (rItr != rooms.end()) {
|
||||
rItr->second->responseArchive(list, last);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::onElementFileLocalPathRequest(const QString& messageId, const QString& url)
|
||||
{
|
||||
Element* el = static_cast<Element*>(sender());
|
||||
std::map<QString, std::set<Models::Roster::ElId>>::iterator itr = requestedFiles.find(messageId);
|
||||
bool created = false;
|
||||
if (itr == requestedFiles.end()) {
|
||||
itr = requestedFiles.insert(std::make_pair(messageId, std::set<Models::Roster::ElId>())).first;
|
||||
created = true;
|
||||
}
|
||||
itr->second.insert(Models::Roster::ElId(el->getAccountName(), el->getJid()));
|
||||
if (created) {
|
||||
emit fileLocalPathRequest(messageId, url);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::fileProgress(const QString& messageId, qreal value)
|
||||
{
|
||||
std::map<QString, std::set<Models::Roster::ElId>>::const_iterator itr = requestedFiles.find(messageId);
|
||||
if (itr == requestedFiles.end()) {
|
||||
qDebug() << "fileProgress in UI but there is nobody waiting for that id:" << messageId << ", skipping";
|
||||
return;
|
||||
} else {
|
||||
const std::set<Models::Roster::ElId>& convs = itr->second;
|
||||
for (const Models::Roster::ElId& id : convs) {
|
||||
std::map<ElId, Contact*>::const_iterator cItr = contacts.find(id);
|
||||
if (cItr != contacts.end()) {
|
||||
cItr->second->fileProgress(messageId, value);
|
||||
} else {
|
||||
std::map<ElId, Room*>::const_iterator rItr = rooms.find(id);
|
||||
if (rItr != rooms.end()) {
|
||||
rItr->second->fileProgress(messageId, value);
|
||||
}
|
||||
}
|
||||
return rItr->second;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include "shared/message.h"
|
||||
#include "shared/global.h"
|
||||
#include "shared/messageinfo.h"
|
||||
#include "accounts.h"
|
||||
#include "item.h"
|
||||
#include "account.h"
|
||||
|
@ -81,21 +82,19 @@ public:
|
|||
QModelIndex getAccountIndex(const QString& name);
|
||||
QModelIndex getGroupIndex(const QString& account, const QString& name);
|
||||
void responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list, bool last);
|
||||
void fileProgress(const QString& messageId, qreal value);
|
||||
|
||||
void fileProgress(const std::list<Shared::MessageInfo>& msgs, qreal value, bool up);
|
||||
void fileError(const std::list<Shared::MessageInfo>& msgs, const QString& err, bool up);
|
||||
void fileComplete(const std::list<Shared::MessageInfo>& msgs, bool up);
|
||||
|
||||
Accounts* accountsModel;
|
||||
|
||||
signals:
|
||||
void requestArchive(const QString& account, const QString& jid, const QString& before);
|
||||
void fileLocalPathRequest(const QString& messageId, const QString& url);
|
||||
void fileDownloadRequest(const QString& url);
|
||||
|
||||
private:
|
||||
Item* root;
|
||||
std::map<QString, Account*> accounts;
|
||||
std::map<ElId, Group*> groups;
|
||||
std::map<ElId, Contact*> contacts;
|
||||
std::map<ElId, Room*> rooms;
|
||||
std::map<QString, std::set<Models::Roster::ElId>> requestedFiles;
|
||||
Element* getElement(const ElId& id);
|
||||
|
||||
private slots:
|
||||
void onAccountDataChanged(const QModelIndex& tl, const QModelIndex& br, const QVector<int>& roles);
|
||||
|
@ -107,7 +106,13 @@ private slots:
|
|||
void onChildIsAboutToBeMoved(Item* source, int first, int last, Item* destination, int newIndex);
|
||||
void onChildMoved();
|
||||
void onElementRequestArchive(const QString& before);
|
||||
void onElementFileLocalPathRequest(const QString& messageId, const QString& url);
|
||||
|
||||
private:
|
||||
Item* root;
|
||||
std::map<QString, Account*> accounts;
|
||||
std::map<ElId, Group*> groups;
|
||||
std::map<ElId, Contact*> contacts;
|
||||
std::map<ElId, Room*> rooms;
|
||||
|
||||
public:
|
||||
class ElId {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue