forked from blue/squawk
some debug, message changing in messageFeed
This commit is contained in:
parent
3a7735b192
commit
48e498be25
@ -479,11 +479,11 @@ QString Core::NetworkAccess::checkFileName(const QString& name, const QString& p
|
||||
suffix += "." + (*sItr);
|
||||
}
|
||||
QString postfix("");
|
||||
QFileInfo proposedName(path + realName + suffix);
|
||||
QFileInfo proposedName(path + "/" + realName + suffix);
|
||||
int counter = 0;
|
||||
while (proposedName.exists()) {
|
||||
QString count = QString("(") + std::to_string(++counter).c_str() + ")";
|
||||
proposedName = QFileInfo(path + realName + count + suffix);
|
||||
proposedName = QFileInfo(path + "/" + realName + count + suffix);
|
||||
}
|
||||
|
||||
return proposedName.absoluteFilePath();
|
||||
|
@ -456,3 +456,23 @@ void Shared::Message::setAttachPath(const QString& path)
|
||||
{
|
||||
attachPath = path;
|
||||
}
|
||||
|
||||
Shared::Message::Change::Change(const QMap<QString, QVariant>& _data):
|
||||
data(_data),
|
||||
idModified(false) {}
|
||||
|
||||
void Shared::Message::Change::operator()(Shared::Message& msg)
|
||||
{
|
||||
idModified = msg.change(data);
|
||||
}
|
||||
|
||||
void Shared::Message::Change::operator()(Shared::Message* msg)
|
||||
{
|
||||
idModified = msg->change(data);
|
||||
}
|
||||
|
||||
bool Shared::Message::Change::hasIdBeenModified() const
|
||||
{
|
||||
return idModified;
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,18 @@ public:
|
||||
static const State StateHighest = State::error;
|
||||
static const State StateLowest = State::pending;
|
||||
|
||||
struct Change //change functor, stores in idModified if ID has been modified during change
|
||||
{
|
||||
Change(const QMap<QString, QVariant>& _data);
|
||||
void operator() (Message& msg);
|
||||
void operator() (Message* msg);
|
||||
bool hasIdBeenModified() const;
|
||||
|
||||
private:
|
||||
const QMap<QString, QVariant>& data;
|
||||
bool idModified;
|
||||
};
|
||||
|
||||
Message(Type p_type);
|
||||
Message();
|
||||
|
||||
|
@ -143,7 +143,7 @@ void Models::Element::addMessage(const Shared::Message& data)
|
||||
|
||||
void Models::Element::changeMessage(const QString& id, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
|
||||
feed->changeMessage(id, data);
|
||||
}
|
||||
|
||||
void Models::Element::responseArchive(const std::list<Shared::Message> list, bool last)
|
||||
|
@ -76,8 +76,44 @@ void Models::MessageFeed::addMessage(const Shared::Message& msg)
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void Models::MessageFeed::changeMessage(const QString& id, const Shared::Message& msg)
|
||||
void Models::MessageFeed::changeMessage(const QString& id, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
StorageById::iterator itr = indexById.find(id);
|
||||
if (itr == indexById.end()) {
|
||||
qDebug() << "received a command to change a message, but the message couldn't be found, skipping";
|
||||
return;
|
||||
}
|
||||
|
||||
Shared::Message* msg = *itr;
|
||||
QModelIndex index = modelIndexByTime(id, msg->getTime());
|
||||
Shared::Message::Change functor(data);
|
||||
bool success = indexById.modify(itr, functor);
|
||||
if (!success) {
|
||||
qDebug() << "received a command to change a message, but something went wrong modifying message in the feed, throwing error";
|
||||
throw 872;
|
||||
}
|
||||
|
||||
if (functor.hasIdBeenModified()) {
|
||||
|
||||
}
|
||||
|
||||
//change message is a final event in download/upload event train
|
||||
//only after changeMessage we can consider the download is done
|
||||
Progress::const_iterator dItr = downloads.find(id);
|
||||
if (dItr != downloads.end()) {
|
||||
if (dItr->second == 1) {
|
||||
downloads.erase(dItr);
|
||||
}
|
||||
} else {
|
||||
dItr = uploads.find(id);
|
||||
if (dItr != uploads.end()) {
|
||||
if (dItr->second == 1) {
|
||||
uploads.erase(dItr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
emit dataChanged(index, index);
|
||||
}
|
||||
|
||||
void Models::MessageFeed::removeMessage(const QString& id)
|
||||
@ -338,7 +374,7 @@ void Models::MessageFeed::fileProgress(const QString& messageId, qreal value, bo
|
||||
|
||||
void Models::MessageFeed::fileComplete(const QString& messageId, bool up)
|
||||
{
|
||||
//TODO
|
||||
fileProgress(messageId, 1, up);
|
||||
}
|
||||
|
||||
void Models::MessageFeed::fileError(const QString& messageId, const QString& error, bool up)
|
||||
@ -352,11 +388,29 @@ 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();
|
||||
return modelIndexByTime(id, msg->getTime());
|
||||
}
|
||||
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QModelIndex Models::MessageFeed::modelIndexByTime(const QString& id, const QDateTime& time) const
|
||||
{
|
||||
StorageByTime::const_iterator tItr = indexByTime.upper_bound(time);
|
||||
StorageByTime::const_iterator tBeg = indexByTime.begin();
|
||||
bool found = false;
|
||||
while (tItr != tBeg) {
|
||||
if (id == (*tItr)->getId()) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
--tItr;
|
||||
}
|
||||
|
||||
if (found) {
|
||||
int position = indexByTime.rank(tItr);
|
||||
return createIndex(position, 0, *tItr);
|
||||
}
|
||||
|
||||
return QModelIndex();
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
~MessageFeed();
|
||||
|
||||
void addMessage(const Shared::Message& msg);
|
||||
void changeMessage(const QString& id, const Shared::Message& msg);
|
||||
void changeMessage(const QString& id, const QMap<QString, QVariant>& data);
|
||||
void removeMessage(const QString& id);
|
||||
|
||||
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
|
||||
@ -72,6 +72,7 @@ protected:
|
||||
bool sentByMe(const Shared::Message& msg) const;
|
||||
Attachment fillAttach(const Shared::Message& msg) const;
|
||||
QModelIndex modelIndexById(const QString& id) const;
|
||||
QModelIndex modelIndexByTime(const QString& id, const QDateTime& time) const;
|
||||
|
||||
public:
|
||||
enum MessageRoles {
|
||||
|
@ -444,28 +444,7 @@ void Squawk::accountMessage(const QString& account, const Shared::Message& data)
|
||||
|
||||
void Squawk::changeMessage(const QString& account, const QString& jid, const QString& id, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
Models::Roster::ElId eid({account, jid});
|
||||
bool found = false;
|
||||
|
||||
if (currentConversation != 0 && currentConversation->getId() == eid) {
|
||||
currentConversation->changeMessage(id, data);
|
||||
QApplication::alert(this);
|
||||
found = true;
|
||||
}
|
||||
|
||||
Conversations::iterator itr = conversations.find(eid);
|
||||
if (itr != conversations.end()) {
|
||||
Conversation* conv = itr->second;
|
||||
conv->changeMessage(id, data);
|
||||
if (!found && conv->isMinimized()) {
|
||||
rosterModel.changeMessage(account, jid, id, data);
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
rosterModel.changeMessage(account, jid, id, data);
|
||||
}
|
||||
rosterModel.changeMessage(account, jid, id, data);
|
||||
}
|
||||
|
||||
void Squawk::notify(const QString& account, const Shared::Message& msg)
|
||||
|
@ -37,7 +37,7 @@ QWidget* ComboboxDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
|
||||
{
|
||||
QComboBox *cb = new QComboBox(parent);
|
||||
|
||||
for (const std::pair<QString, QIcon> pair : entries) {
|
||||
for (const std::pair<QString, QIcon>& pair : entries) {
|
||||
cb->addItem(pair.second, pair.first);
|
||||
}
|
||||
|
||||
|
@ -179,6 +179,9 @@ QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModel
|
||||
break;
|
||||
case Models::ready:
|
||||
break;
|
||||
case Models::errorDownload:
|
||||
case Models::errorUpload:
|
||||
break;
|
||||
}
|
||||
|
||||
messageSize.rheight() += nickMetrics.lineSpacing();
|
||||
@ -306,10 +309,11 @@ QProgressBar * MessageDelegate::getBar(const Models::FeedItem& data) const
|
||||
|
||||
if (result == 0) {
|
||||
result = new QProgressBar();
|
||||
result->setRange(0, 100);
|
||||
bars->insert(std::make_pair(data.id, result));
|
||||
}
|
||||
|
||||
result->setValue(data.attach.progress);
|
||||
result->setValue(data.attach.progress * 100);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -85,6 +85,8 @@ private:
|
||||
std::map<QString, QProgressBar*>* bars;
|
||||
std::set<QString>* idsToKeep;
|
||||
bool clearingWidgets;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // MESSAGEDELEGATE_H
|
||||
|
Loading…
Reference in New Issue
Block a user