forked from blue/squawk
file progress events delivery methonds
This commit is contained in:
parent
85555da81f
commit
a0348b8fd2
@ -30,6 +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);
|
||||
|
||||
QMap<QString, QVariant>::const_iterator itr = data.find("avatarState");
|
||||
if (itr != data.end()) {
|
||||
@ -154,3 +155,9 @@ bool Models::Element::isRoom() const
|
||||
{
|
||||
return type != contact;
|
||||
}
|
||||
|
||||
void Models::Element::fileProgress(const QString& messageId, qreal value)
|
||||
{
|
||||
feed->fileProgress(messageId, value);
|
||||
}
|
||||
|
||||
|
@ -43,9 +43,11 @@ 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);
|
||||
|
||||
signals:
|
||||
void requestArchive(const QString& before);
|
||||
void fileLocalPathRequest(const QString& messageId, const QString& url);
|
||||
|
||||
protected:
|
||||
void setJid(const QString& p_jid);
|
||||
|
@ -299,10 +299,46 @@ Models::Attachment Models::MessageFeed::fillAttach(const Shared::Message& msg) c
|
||||
|
||||
void Models::MessageFeed::downloadAttachment(const QString& messageId)
|
||||
{
|
||||
qDebug() << "request to download attachment of the message" << messageId;
|
||||
QModelIndex ind = modelIndexById(messageId);
|
||||
if (ind.isValid()) {
|
||||
std::pair<Progress::iterator, bool> progressPair = downloads.insert(std::make_pair(messageId, 0));
|
||||
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());
|
||||
} else {
|
||||
qDebug() << "Attachment download for message with id" << messageId << "is already in progress, skipping";
|
||||
}
|
||||
} else {
|
||||
qDebug() << "An attempt to download an attachment for the message that doesn't exist. ID:" << messageId;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Progress::iterator itr = downloads.find(messageId);
|
||||
if (itr != downloads.end()) {
|
||||
itr->second = value;
|
||||
QModelIndex ind = modelIndexById(messageId);
|
||||
emit dataChanged(ind, ind);
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex Models::MessageFeed::modelIndexById(const QString& id) const
|
||||
{
|
||||
StorageById::const_iterator itr = indexById.find(id);
|
||||
if (itr != indexById.end()) {
|
||||
Shared::Message* msg = *itr;
|
||||
StorageByTime::const_iterator tItr = indexByTime.upper_bound(msg->getTime());
|
||||
int position = indexByTime.rank(tItr);
|
||||
return createIndex(position, 0, msg);
|
||||
} else {
|
||||
return QModelIndex();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,14 +59,17 @@ public:
|
||||
void uploadAttachment(const QString& messageId);
|
||||
|
||||
unsigned int unreadMessagesCount() const;
|
||||
void fileProgress(const QString& messageId, qreal value);
|
||||
|
||||
signals:
|
||||
void requestArchive(const QString& before);
|
||||
void requestStateChange(bool requesting);
|
||||
void fileLocalPathRequest(const QString& messageId, const QString& url);
|
||||
|
||||
protected:
|
||||
bool sentByMe(const Shared::Message& msg) const;
|
||||
Attachment fillAttach(const Shared::Message& msg) const;
|
||||
QModelIndex modelIndexById(const QString& id) const;
|
||||
|
||||
public:
|
||||
enum MessageRoles {
|
||||
|
@ -27,7 +27,8 @@ Models::Roster::Roster(QObject* parent):
|
||||
root(new Item(Item::root, {{"name", "root"}})),
|
||||
accounts(),
|
||||
groups(),
|
||||
contacts()
|
||||
contacts(),
|
||||
requestedFiles()
|
||||
{
|
||||
connect(accountsModel, &Accounts::dataChanged, this, &Roster::onAccountDataChanged);
|
||||
connect(root, &Item::childChanged, this, &Roster::onChildChanged);
|
||||
@ -447,6 +448,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);
|
||||
contacts.insert(std::make_pair(id, contact));
|
||||
} else {
|
||||
contact = itr->second;
|
||||
@ -806,6 +808,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);
|
||||
rooms.insert(std::make_pair(id, room));
|
||||
acc->appendChild(room);
|
||||
}
|
||||
@ -978,3 +981,41 @@ void Models::Roster::responseArchive(const QString& account, const QString& jid,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,11 +81,13 @@ 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);
|
||||
|
||||
Accounts* accountsModel;
|
||||
|
||||
signals:
|
||||
void requestArchive(const QString& account, const QString& jid, const QString& before);
|
||||
void fileLocalPathRequest(const QString& messageId, const QString& url);
|
||||
|
||||
private:
|
||||
Item* root;
|
||||
@ -93,6 +95,7 @@ private:
|
||||
std::map<ElId, Group*> groups;
|
||||
std::map<ElId, Contact*> contacts;
|
||||
std::map<ElId, Room*> rooms;
|
||||
std::map<QString, std::set<Models::Roster::ElId>> requestedFiles;
|
||||
|
||||
private slots:
|
||||
void onAccountDataChanged(const QModelIndex& tl, const QModelIndex& br, const QVector<int>& roles);
|
||||
@ -104,6 +107,7 @@ 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);
|
||||
|
||||
public:
|
||||
class ElId {
|
||||
|
@ -63,6 +63,7 @@ Squawk::Squawk(QWidget *parent) :
|
||||
|
||||
connect(rosterModel.accountsModel, &Models::Accounts::sizeChanged, this, &Squawk::onAccountsSizeChanged);
|
||||
connect(&rosterModel, &Models::Roster::requestArchive, this, &Squawk::onConversationRequestArchive);
|
||||
connect(&rosterModel, &Models::Roster::fileLocalPathRequest, this, &Squawk::fileLocalPathRequest);
|
||||
connect(contextMenu, &QMenu::aboutToHide, this, &Squawk::onContextAboutToHide);
|
||||
//m_ui->mainToolBar->addWidget(m_ui->comboBox);
|
||||
|
||||
@ -405,23 +406,7 @@ void Squawk::onConversationDownloadFile(const QString& messageId, const QString&
|
||||
|
||||
void Squawk::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 Squawk but there is nobody waiting for that id" << messageId << ", skipping";
|
||||
return;
|
||||
} else {
|
||||
const std::set<Models::Roster::ElId>& convs = itr->second;
|
||||
for (std::set<Models::Roster::ElId>::const_iterator cItr = convs.begin(), cEnd = convs.end(); cItr != cEnd; ++cItr) {
|
||||
const Models::Roster::ElId& id = *cItr;
|
||||
Conversations::const_iterator c = conversations.find(id);
|
||||
if (c != conversations.end()) {
|
||||
c->second->responseFileProgress(messageId, value);
|
||||
}
|
||||
if (currentConversation != 0 && currentConversation->getId() == id) {
|
||||
currentConversation->responseFileProgress(messageId, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
rosterModel.fileProgress(messageId, value);
|
||||
}
|
||||
|
||||
void Squawk::fileError(const QString& messageId, const QString& error)
|
||||
|
Loading…
Reference in New Issue
Block a user