forked from blue/squawk
initial attempt to paint buttons in the messagefeed
This commit is contained in:
parent
ff4124d1f0
commit
00ffbac6b0
8 changed files with 156 additions and 18 deletions
|
@ -40,7 +40,9 @@ Models::MessageFeed::MessageFeed(const Element* ri, QObject* parent):
|
|||
indexById(storage.get<id>()),
|
||||
indexByTime(storage.get<time>()),
|
||||
rosterItem(ri),
|
||||
syncState(incomplete)
|
||||
syncState(incomplete),
|
||||
uploads(),
|
||||
downloads()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -138,11 +140,8 @@ QVariant Models::MessageFeed::data(const QModelIndex& index, int role) const
|
|||
}
|
||||
}
|
||||
break;
|
||||
case Attach: {
|
||||
::Models::Attach att;
|
||||
|
||||
answer.setValue(att);
|
||||
}
|
||||
case Attach:
|
||||
answer.setValue(fillAttach(*msg));
|
||||
break;
|
||||
case Bulk: {
|
||||
FeedItem item;
|
||||
|
@ -171,6 +170,7 @@ QVariant Models::MessageFeed::data(const QModelIndex& index, int role) const
|
|||
if (item.avatar.size() == 0) {
|
||||
item.avatar = Shared::iconPath("user", true);
|
||||
}
|
||||
item.attach = fillAttach(*msg);
|
||||
answer.setValue(item);
|
||||
}
|
||||
break;
|
||||
|
@ -246,3 +246,39 @@ bool Models::MessageFeed::sentByMe(const Shared::Message& msg) const
|
|||
return msg.getOutgoing();
|
||||
}
|
||||
}
|
||||
|
||||
Models::Attachment Models::MessageFeed::fillAttach(const Shared::Message& msg) const
|
||||
{
|
||||
::Models::Attachment att;
|
||||
|
||||
att.localPath = msg.getAttachPath();
|
||||
att.remotePath = msg.getOutOfBandUrl();
|
||||
|
||||
if (att.remotePath.size() == 0) {
|
||||
if (att.localPath.size() == 0) {
|
||||
att.state = none;
|
||||
} else {
|
||||
Progress::const_iterator itr = uploads.find(msg.getId());
|
||||
if (itr == uploads.end()) {
|
||||
att.state = local;
|
||||
} else {
|
||||
att.state = uploading;
|
||||
att.progress = itr->second;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (att.localPath.size() == 0) {
|
||||
Progress::const_iterator itr = downloads.find(msg.getId());
|
||||
if (itr == downloads.end()) {
|
||||
att.state = remote;
|
||||
} else {
|
||||
att.state = downloading;
|
||||
att.progress = itr->second;
|
||||
}
|
||||
} else {
|
||||
att.state = ready;
|
||||
}
|
||||
}
|
||||
|
||||
return att;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
namespace Models {
|
||||
class Element;
|
||||
struct Attachment;
|
||||
|
||||
class MessageFeed : public QAbstractListModel
|
||||
{
|
||||
|
@ -63,6 +64,7 @@ signals:
|
|||
|
||||
protected:
|
||||
bool sentByMe(const Shared::Message& msg) const;
|
||||
Attachment fillAttach(const Shared::Message& msg) const;
|
||||
|
||||
public:
|
||||
enum MessageRoles {
|
||||
|
@ -120,21 +122,27 @@ private:
|
|||
const Element* rosterItem;
|
||||
SyncState syncState;
|
||||
|
||||
typedef std::map<QString, qreal> Progress;
|
||||
Progress uploads;
|
||||
Progress downloads;
|
||||
|
||||
static const QHash<int, QByteArray> roles;
|
||||
};
|
||||
|
||||
enum Attachment {
|
||||
enum AttachmentType {
|
||||
none,
|
||||
remote,
|
||||
local,
|
||||
downloading,
|
||||
uploading,
|
||||
ready
|
||||
};
|
||||
|
||||
struct Attach {
|
||||
Attachment state;
|
||||
struct Attachment {
|
||||
AttachmentType state;
|
||||
qreal progress;
|
||||
QString localPath;
|
||||
QString remotePath;
|
||||
};
|
||||
|
||||
struct FeedItem {
|
||||
|
@ -145,11 +153,11 @@ struct FeedItem {
|
|||
bool correction;
|
||||
QDateTime date;
|
||||
Shared::Message::State state;
|
||||
Attach attach;
|
||||
Attachment attach;
|
||||
};
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(Models::Attach);
|
||||
Q_DECLARE_METATYPE(Models::Attachment);
|
||||
Q_DECLARE_METATYPE(Models::FeedItem);
|
||||
|
||||
#endif // MESSAGEFEED_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue