aboutsummaryrefslogtreecommitdiffstats
path: root/src/list_item.cpp
blob: 16eb9e80661ad7054c97393630b72de7ec82171f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "list_item.h"
#include "src/activitypub/apactivity.h"
#include "src/types.h"
#include <QObject>

#define ICON_PATH_PREFIX "res/icons"
QIcon& choose_icon(StatusType status_type) {
    // via the use of `static' in the following switch block, the idea is to only initialize each QIcon type once in the program's lifetime.
    switch (status_type) {
        case StatusType::PUBLIC:
            static QIcon public_icon(ICON_PATH_PREFIX"/globe.png"); return public_icon;
        case StatusType::UNLISTED:
            static QIcon unlisted_icon(ICON_PATH_PREFIX"/unlisted.png"); return unlisted_icon;
        case StatusType::PRIVATE:
            static QIcon private_icon(ICON_PATH_PREFIX"/padlock-locked.png"); return private_icon;
        case StatusType::DIRECT:
            static QIcon direct_icon(ICON_PATH_PREFIX"/letter.png"); return direct_icon;
        case StatusType::REBLOG:
            static QIcon reblog_icon(ICON_PATH_PREFIX"/repeat.png"); return reblog_icon;
        case StatusType::UNKNOWN:
	default:
            static QIcon unknown_icon(ICON_PATH_PREFIX"/question.png"); return unknown_icon;
    }
}
#undef ICON_PATH_PREFIX

StatusListItem::StatusListItem(const QString &text, StatusType status_type, bool has_attachement, Archive* data_archive, QListWidget *parent, int index) :
    status_index(index), has_attachement(has_attachement), status_type(status_type), data_archive(data_archive)
{
    setText(text);
    setIcon(choose_icon(status_type));
    parent->addItem(this);
    QString tool_tip;
    switch (status_type) {
        case PUBLIC: tool_tip = QObject::tr("Public"); break;
        case UNLISTED: tool_tip = QObject::tr("Unlisted"); break;
        case PRIVATE: tool_tip = QObject::tr("Private"); break;
        case DIRECT: tool_tip = QObject::tr("Direct"); break;
        case UNKNOWN: tool_tip = QObject::tr("Unknown"); break;
        case REBLOG: tool_tip = QObject::tr("Reblog"); break;
    }
    setToolTip(tool_tip);
}

int StatusListItem::get_status_index() {
    return status_index;
}

StatusType StatusListItem::get_status_type() {
    return status_type;
}

APActivityPtr StatusListItem::get_activity() {
    return data_archive->get_activity(status_index, {status_type});
}

const QString StatusListItem::get_info_html(int text_zone_width, QLocale* locale) {
    APActivityPtr activity = data_archive->get_activity(status_index, {status_type});
    QString html = activity->get_html_render({text_zone_width, locale});
    return html;
}