diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/archive_parser.cpp | 15 | ||||
-rw-r--r-- | src/archive_parser.h | 3 | ||||
-rw-r--r-- | src/list_item.cpp | 12 | ||||
-rw-r--r-- | src/list_item.h | 18 | ||||
-rw-r--r-- | src/mainwindow.cpp | 4 | ||||
-rw-r--r-- | src/types.h | 7 |
7 files changed, 51 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index f2bbe92..7360a52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,8 @@ set(PROJECT_SOURCES src/archive_parser.cpp src/archive_parser.h src/types.h + src/list_item.cpp + src/list_item.h ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) diff --git a/src/archive_parser.cpp b/src/archive_parser.cpp index e370bcd..62edfd9 100644 --- a/src/archive_parser.cpp +++ b/src/archive_parser.cpp @@ -1,4 +1,5 @@ #include "archive_parser.h" +#include "src/list_item.h" #include "src/types.h" #include <QFile> @@ -47,14 +48,14 @@ Archive::~Archive() { delete outbox_items; outbox_items = nullptr; } -QStringList Archive::get_status_list(ViewStatusTypes types) { - QStringList statuses; - +void Archive::update_status_list(ViewStatusTypes allowed_types, QListWidget *parent) { + int i = 0; for (auto&& item : *outbox_items) { if (item.isObject()){ QJsonObject obj = item.toObject(); - // TODO: check the status type + // TODO: check the status type by looking at cc field + StatusType status_type = PUBLIC; if (obj.value("object").isObject()) { QJsonObject activity = obj.value("object").toObject(); @@ -63,11 +64,11 @@ QStringList Archive::get_status_list(ViewStatusTypes types) { // Strip HTML for display in list, according to https://stackoverflow.com/a/12157835 QTextDocument strip_html; strip_html.setHtml(activity.value("content").toString()); - statuses.append(strip_html.toPlainText()); + + ListItem *item = new ListItem(strip_html.toPlainText(), status_type, parent, i); } } } + ++i; } - - return statuses; } diff --git a/src/archive_parser.h b/src/archive_parser.h index 47c7ea4..73adb2c 100644 --- a/src/archive_parser.h +++ b/src/archive_parser.h @@ -5,6 +5,7 @@ #include <QJsonDocument> #include <QJsonObject> #include <QJsonArray> +#include <QListWidget> #include "types.h" @@ -28,7 +29,7 @@ public: ~Archive(); InitError init(); - QStringList get_status_list(ViewStatusTypes types); + void update_status_list(ViewStatusTypes allowed_types, QListWidget *parent); private: QString outbox_filename; ArchiveType archive_type; diff --git a/src/list_item.cpp b/src/list_item.cpp new file mode 100644 index 0000000..6409169 --- /dev/null +++ b/src/list_item.cpp @@ -0,0 +1,12 @@ +#include "list_item.h" +#include "types.h" + +QIcon* choose_icon(StatusType status_type) { + return new QIcon(); // TODO: null icon for the moment +} + +ListItem::ListItem(const QString &text, StatusType status_type, QListWidget *parent, int index) : + QListWidgetItem(*choose_icon(status_type), text, parent, ArchiveListItemType), status_index(index) +{ + +} diff --git a/src/list_item.h b/src/list_item.h new file mode 100644 index 0000000..e2b3c3f --- /dev/null +++ b/src/list_item.h @@ -0,0 +1,18 @@ +#pragma once + +#include <QListWidgetItem> +#include "types.h" + +class ListItem : QListWidgetItem { +public: + enum ItemType { + ArchiveListItemType = QListWidgetItem::UserType + }; + + ListItem(const QString &text, StatusType status_type, QListWidget *parent = nullptr, int index = 0); + +private: + int status_index; + StatusType status_type; + bool has_attachement; +}; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1424ff5..0b77012 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -54,7 +54,7 @@ void MainWindow::on_actionOpen_triggered(bool checked) { ui->listWidget->clear(); if (parse_error == Archive::NoError) { - ui->listWidget->addItems(data_archive->get_status_list(view_filters)); + data_archive->update_status_list(view_filters, ui->listWidget); } QApplication::restoreOverrideCursor(); @@ -71,7 +71,7 @@ void MainWindow::on_actionAbout_triggered(bool checked) { void MainWindow::relist_statuses() { if (data_archive) { ui->listWidget->clear(); - ui->listWidget->addItems(data_archive->get_status_list(view_filters)); + data_archive->update_status_list(view_filters, ui->listWidget); view_filters_changed = false; } } diff --git a/src/types.h b/src/types.h index 632d8ff..b78c564 100644 --- a/src/types.h +++ b/src/types.h @@ -7,3 +7,10 @@ struct ViewStatusTypes { bool includeDirect = true; bool onlyWithAttachment = false; }; + +enum StatusType { + PUBLIC, + UNLISTED, + PRIVATE, + DIRECT +}; |