1 #pragma once
2 
3 #include <QAbstractListModel>
4 
5 #include <chrono>
6 #include <mutex>
7 #include <set>
8 
9 namespace chatterino {
10 
11 class Channel;
12 
13 class CompletionModel : public QAbstractListModel
14 {
15     struct TaggedString {
16         enum Type {
17             Username,
18 
19             // emotes
20             EmoteStart,
21             FFZGlobalEmote,
22             FFZChannelEmote,
23             BTTVGlobalEmote,
24             BTTVChannelEmote,
25             TwitchGlobalEmote,
26             TwitchLocalEmote,
27             TwitchSubscriberEmote,
28             Emoji,
29             EmoteEnd,
30             // end emotes
31 
32             Command,
33         };
34 
35         TaggedString(const QString &string, Type type);
36 
37         bool isEmote() const;
38         bool operator<(const TaggedString &that) const;
39 
40         QString string;
41         Type type;
42     };
43 
44 public:
45     CompletionModel(Channel &channel);
46 
47     virtual int columnCount(const QModelIndex &) const override;
48     virtual QVariant data(const QModelIndex &index, int) const override;
49     virtual int rowCount(const QModelIndex &) const override;
50 
51     void refresh(const QString &prefix, bool isFirstWord = false);
52 
53     static bool compareStrings(const QString &a, const QString &b);
54 
55 private:
56     std::set<TaggedString> items_;
57     mutable std::mutex itemsMutex_;
58     Channel &channel_;
59 };
60 
61 }  // namespace chatterino
62