2017-12-31 00:50:07 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-06-26 15:33:51 +02:00
|
|
|
#include "common/Common.hpp"
|
2018-03-24 12:02:07 +01:00
|
|
|
|
2017-12-31 00:50:07 +01:00
|
|
|
#include <QAbstractListModel>
|
|
|
|
|
2018-03-30 13:50:43 +02:00
|
|
|
#include <chrono>
|
|
|
|
#include <mutex>
|
2018-03-24 12:02:07 +01:00
|
|
|
#include <set>
|
2017-12-31 00:50:07 +01:00
|
|
|
|
|
|
|
namespace chatterino {
|
2018-03-24 12:02:07 +01:00
|
|
|
|
2017-12-31 00:50:07 +01:00
|
|
|
class CompletionModel : public QAbstractListModel
|
|
|
|
{
|
2018-03-30 12:06:02 +02:00
|
|
|
struct TaggedString {
|
|
|
|
enum Type {
|
|
|
|
Username,
|
2017-12-31 00:50:07 +01:00
|
|
|
|
2018-07-06 17:42:00 +02:00
|
|
|
// emotes
|
|
|
|
EmoteStart,
|
|
|
|
FFZGlobalEmote,
|
2018-03-30 12:06:02 +02:00
|
|
|
FFZChannelEmote,
|
|
|
|
BTTVGlobalEmote,
|
|
|
|
BTTVChannelEmote,
|
|
|
|
TwitchGlobalEmote,
|
|
|
|
TwitchSubscriberEmote,
|
|
|
|
Emoji,
|
2018-07-06 17:42:00 +02:00
|
|
|
EmoteEnd,
|
|
|
|
// end emotes
|
|
|
|
|
2018-06-24 11:24:21 +02:00
|
|
|
Command,
|
2018-03-30 13:50:43 +02:00
|
|
|
};
|
|
|
|
|
2018-07-06 17:42:00 +02:00
|
|
|
TaggedString(const QString &_str, Type _type);
|
2018-03-30 13:50:43 +02:00
|
|
|
|
2018-07-06 17:42:00 +02:00
|
|
|
bool isExpired(const std::chrono::steady_clock::time_point &now) const;
|
|
|
|
bool isEmote() const;
|
|
|
|
bool operator<(const TaggedString &that) const;
|
2018-03-30 13:50:43 +02:00
|
|
|
|
2018-07-06 17:42:00 +02:00
|
|
|
QString str;
|
2018-03-30 13:50:43 +02:00
|
|
|
// Type will help decide the lifetime of the tagged strings
|
|
|
|
Type type;
|
|
|
|
|
2018-03-30 15:58:05 +02:00
|
|
|
mutable std::chrono::steady_clock::time_point timeAdded;
|
2018-03-24 11:12:24 +01:00
|
|
|
};
|
2018-03-30 12:06:02 +02:00
|
|
|
|
|
|
|
public:
|
2018-07-06 18:10:21 +02:00
|
|
|
CompletionModel(const QString &channelName);
|
2018-03-30 12:06:02 +02:00
|
|
|
|
2018-07-06 17:42:00 +02:00
|
|
|
virtual int columnCount(const QModelIndex &) const override;
|
|
|
|
virtual QVariant data(const QModelIndex &index, int) const override;
|
|
|
|
virtual int rowCount(const QModelIndex &) const override;
|
2018-03-30 12:06:02 +02:00
|
|
|
|
|
|
|
void refresh();
|
|
|
|
void addString(const QString &str, TaggedString::Type type);
|
|
|
|
void addUser(const QString &str);
|
|
|
|
|
2018-07-06 17:42:00 +02:00
|
|
|
void clearExpiredStrings();
|
2018-03-30 13:50:43 +02:00
|
|
|
|
2018-03-30 12:06:02 +02:00
|
|
|
private:
|
2018-07-06 17:42:00 +02:00
|
|
|
TaggedString createUser(const QString &str);
|
2018-03-30 12:06:02 +02:00
|
|
|
|
2018-07-06 17:42:00 +02:00
|
|
|
mutable std::mutex emotesMutex_;
|
|
|
|
std::set<TaggedString> emotes_;
|
2017-12-31 00:50:07 +01:00
|
|
|
|
2018-07-06 17:42:00 +02:00
|
|
|
QString channelName_;
|
2017-12-31 00:50:07 +01:00
|
|
|
};
|
2018-03-24 12:02:07 +01:00
|
|
|
|
2018-03-24 11:12:24 +01:00
|
|
|
} // namespace chatterino
|