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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
#include "tab_activity_list.h"
#include "./ui_tab_activity_list.h"
#include "src/activitypub/apactivity.h"
#include "status_info.h"
#include "src/net/instance.h"
#include <QInputDialog>
#include <QAction>
#include <QListWidget>
#include <QRandomGenerator>
#include <QClipboard>
#include <QMimeData>
#include <QMessageBox>
TabActivityList::TabActivityList(Archive** archive, QWidget* parent)
: data_archive(archive), QWidget(parent), ui(new Ui::TabActivityList)
{
ui->setupUi(this);
// QGridLayouts have margins around each element, but here we already have margins outside of the element, so these ones are not welcome
ui->gridLayout->setContentsMargins(0, 0, 0, 0);
status_info_widget = new StatusInfoWidget(this);
ui->gridLayout->addWidget(status_info_widget, 1, 1);
}
TabActivityList::~TabActivityList() {
delete ui;
}
void TabActivityList::on_listWidget_itemActivated(QListWidgetItem *item) {
StatusListItem* status = dynamic_cast<StatusListItem*>(item);
if (status != nullptr) {
status_info_widget->show_list_item(status);
}
}
void TabActivityList::on_buttonRandom_clicked() {
if ((*data_archive) == nullptr) return; // No archive open, avoids crashing
int index = QRandomGenerator::global()->bounded(ui->listWidget->count());
QListWidgetItem* item = ui->listWidget->item(index);
on_listWidget_itemActivated(item);
ui->listWidget->setCurrentItem(item);
}
void TabActivityList::on_buttonCopy_clicked() {
if ((*data_archive) == nullptr or ui->listWidget->selectedItems().isEmpty()) return;
StatusListItem* item = dynamic_cast<StatusListItem*>(ui->listWidget->selectedItems()[0]);
if (item != nullptr) {
QString status_text = (*data_archive)->get_html_status_text(item->get_status_index());
QMimeData* clipboard_data = new QMimeData;
clipboard_data->setHtml(status_text);
QGuiApplication::clipboard()->setMimeData(clipboard_data);
}
}
void TabActivityList::on_buttonSearch_clicked() {
if (!find_dialog) {
find_dialog = new FindDialog(this);
find_dialog->set_qlist_widget(ui->listWidget);
connect(find_dialog, &FindDialog::item_selected, this, &TabActivityList::select_list_item);
connect(this, &TabActivityList::search_text_changed, find_dialog, &FindDialog::set_search_text);
connect(find_dialog, &FindDialog::search_text_changed, this, &TabActivityList::set_search_text);
if (not ui->textInputSearch->text().isEmpty())
emit search_text_changed(ui->textInputSearch->text(), true);
}
find_dialog->show();
find_dialog->raise();
find_dialog->activateWindow();
}
void TabActivityList::select_list_item(QListWidgetItem* item) {
on_listWidget_itemActivated(item);
}
void TabActivityList::on_textInputSearch_textEdited(const QString &text) {
emit search_text_changed(text);
}
void TabActivityList::set_search_text(const QString &text) {
ui->textInputSearch->setText(text);
}
void TabActivityList::actionOpen_URL_triggered(bool checked) {
bool ok;
QString url = QInputDialog::getText(this, tr("Open status from URL"), tr("Status URL:"), QLineEdit::Normal, QStringLiteral("https://…"), &ok);
// TODO: Move all of this to another thread
// TODO: Reuse the Instance object
// Really hacky code but works as a PoC and allows testing
if (ok and not url.isEmpty()) {
InstancePtr instance = Instance::create_instance();
if (instance) {
APPostPtr post = instance->get_post_from_url(url);
// Activity will be freed by StatusInfoWidget
auto activity = std::make_shared<APActivity>(APActivityFields {.object = post});
status_info_widget->do_process_activity(activity);
} else
// Best is to remove option from menu, should be douable if the preprocessor touches .ui files
QMessageBox::critical(this, tr("Open status from URL"), tr("Could not create Instance object.\nPerhaps network support was disabled at compile time?"));
}
}
void TabActivityList::relist_statuses(bool new_archive_opened) {
if (*data_archive) {
ui->listWidget->clear();
(*data_archive)->update_status_list(view_filters, ui->listWidget);
view_filters_changed = false;
}
if (new_archive_opened) {
if (QApplication::overrideCursor())
QApplication::restoreOverrideCursor();
if (find_dialog)
find_dialog->force_research();
}
}
void TabActivityList::clear_list() {
ui->listWidget->clear();
}
// Function used to reset filters when we have detected that the "All toots" toggle has been toggled on or shouldn't be toggled anymore
void TabActivityList::reset_view_filters() {
if (view_actions.actionAll_toots->isChecked())
view_filters = {true, true, true, true, view_filters.includeReblogs, view_filters.onlyWithAttachment};
else
view_filters = {false, false, false, false, view_filters.includeReblogs, view_filters.onlyWithAttachment};
}
void TabActivityList::actionAll_toots_triggered(bool checked) {
view_actions.actionAll_toots->setChecked(true);
view_actions.actionPublic_toots->setChecked(false);
view_actions.actionUnlisted_toots->setChecked(false);
view_actions.actionPrivate_toots->setChecked(false);
view_actions.actionDirect_messages->setChecked(false);
view_actions.actionOnly_with_attachment->setChecked(false);
reset_view_filters();
relist_statuses();
}
void TabActivityList::actionPublic_toots_triggered(bool checked) {
if (view_actions.actionAll_toots->isChecked()) {
view_actions.actionAll_toots->setChecked(false);
reset_view_filters();
}
view_filters.includePublic = checked;
view_filters_changed = true;
}
void TabActivityList::actionUnlisted_toots_triggered(bool checked) {
if (view_actions.actionAll_toots->isChecked()) {
view_actions.actionAll_toots->setChecked(false);
reset_view_filters();
}
view_filters.includeUnlisted = checked;
view_filters_changed = true;
}
void TabActivityList::actionPrivate_toots_triggered(bool checked) {
if (view_actions.actionAll_toots->isChecked()) {
view_actions.actionAll_toots->setChecked(false);
reset_view_filters();
}
view_filters.includePrivate = checked;
view_filters_changed = true;
}
void TabActivityList::actionDirect_messages_triggered(bool checked) {
if (view_actions.actionAll_toots->isChecked()) {
view_actions.actionAll_toots->setChecked(false);
reset_view_filters();
}
view_filters.includeDirect = checked;
view_filters_changed = true;
}
void TabActivityList::actionOnly_with_attachment_triggered(bool checked) {
view_filters.onlyWithAttachment = checked;
view_filters_changed = true;
}
void TabActivityList::actionReblogs_triggered(bool checked) {
view_filters.includeReblogs = checked;
view_filters_changed = true;
}
void TabActivityList::menuView_aboutToHide() {
if (view_filters_changed)
relist_statuses();
}
|