diff --git a/libcommsy.hpp b/libcommsy.hpp index 7986195..7fc3acc 100644 --- a/libcommsy.hpp +++ b/libcommsy.hpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -31,6 +31,10 @@ static std::string server_url; static std::string server_sid; static std::string room; +namespace taskState { + enum type {none, done, inProgress, todo}; +} + std::string ltrim(const std::string& s) { static const std::regex lws{"^[[:space:]]*", std::regex_constants::extended}; @@ -240,6 +244,25 @@ bool get_post_unread(GumboNode *node) { return !elems.empty(); } +taskState::type get_post_taskState(GumboNode *node) { + // Find all elements that could contain the information we need and grab their "class" attribute + std::vector divClassAttrs; + divClassAttrs = gumbo_get_attr(node, "class", GUMBO_TAG_I); + + // Try to find the information we need + for (const auto& classAttr : divClassAttrs) { + if (classAttr.find("todo") != std::string::npos) { + return taskState::todo; + } else if (classAttr.find("inProgress") != std::string::npos) { + return taskState::inProgress; + } else if (classAttr.find("DONE(?)") != std::string::npos) { // TODO + return taskState::done; + } + } + + return taskState::none; +} + std::vector> get_post_files(GumboNode *node) { std::vector metanodes; std::vector fileurls; @@ -317,16 +340,17 @@ struct commsyFile { struct commsyPost { std::string name; std::string id; - std::string description; + std::string description = "\xFF"; std::string meta; std::string url; bool unread; + taskState::type taskState; std::vector files; }; #define libCommsy_NAME "libcommsy" -#define libCommsy_VERSION "1.2-stable" +#define libCommsy_VERSION "1.3-stable" class libCommsy { public: std::vector posts; @@ -351,10 +375,11 @@ public: commsyPost *thispost = getPost(postID); // Check if post description was downloaded already - if (thispost->description.empty()) { + if (thispost->description == "\xFF") { // Download post thispost->description = get_post_desc(server_url + thispost->url); } + // Return it return &thispost->description; } @@ -411,6 +436,8 @@ public: thispost.meta = get_post_meta(*it); // Get if post is unread thispost.unread = get_post_unread(*it); + // Get posts task state + thispost.taskState = get_post_taskState(*it); // Get posts URL thispost.url = get_post_url(*it); // Get posts files diff --git a/main.cpp b/main.cpp index 687c2e9..9cecbfc 100644 --- a/main.cpp +++ b/main.cpp @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include #include @@ -48,7 +50,7 @@ public: void overviewWindow(bool catchInvalidRoomError = true); void loginWindow(const QString& failure = ""); void infoWindow(); - void postViewWindow(commsyPost *thispost, const QString& description); + void postViewWindow(commsyPost *thispost, QString description); void offlineWindow(); _UILoader () { @@ -237,7 +239,7 @@ void _UILoader::loginWindow(const QString& failure) { }); } -void _UILoader::postViewWindow(commsyPost *thispost, const QString& description) { +void _UILoader::postViewWindow(commsyPost *thispost, QString description) { Ui::postViewWindow *thisui = new Ui::postViewWindow; // Show initial UI @@ -245,14 +247,24 @@ void _UILoader::postViewWindow(commsyPost *thispost, const QString& description) w->show(); thisui->statusText->setVisible(false); + // Remove trailing space from description + if (description.size() != 0 and description.back() == '\n') { + description.chop(1); + } + // Update informations thisui->titleText->setText(QString::fromStdString(thispost->name)); thisui->metaText->setText(QString::fromStdString(thispost->meta)); thisui->descriptionText->setText(description); - // Update file list - for (const auto& thisfile : thispost->files) { - thisui->fileList->addItem(QString::fromStdString(thisfile.name)); + // Update file list if required + if (thispost->files.size() != 0) { + for (const auto& thisfile : thispost->files) { + thisui->fileList->addItem(QString::fromStdString(thisfile.name)); + } + } else { // If no files exist, hide the list + thisui->filesInfo->setHidden(true); + thisui->fileList->setHidden(true); } // Add button handlers @@ -317,18 +329,36 @@ void _UILoader::overviewWindow(bool catchInvalidRoomError) { return failureWindow(); } + // Get font used for unread posts + QFont unreadFont = QFont(); + unreadFont.setBold(true); + // Refresh view thisui->postCounter->setText(QString::number(connector->numposts) + " Einträge"); thisui->postList->clear(); for (const auto& thispost : connector->posts) { - QString displayName; + QListWidgetItem *thisitem = new QListWidgetItem(QString::fromStdString(thispost.name), thisui->postList); if (thispost.unread) { - displayName.append("(NEU) "); + thisitem->setFont(unreadFont); } - displayName.append(QString::fromStdString(thispost.name)); - thisui->postList->addItem(displayName); + QString postIcon; + switch(thispost.taskState) { + case taskState::done: + postIcon = "checkbox-checked-symbolic"; + break; + case taskState::inProgress: + postIcon = "clock"; + break; + case taskState::todo: + postIcon = "emblem-important-symbolic"; + break; + default: + postIcon = "arrow-right"; + break; + } + thisitem->setIcon(QIcon::fromTheme(postIcon)); } } } diff --git a/postView.ui b/postView.ui index 91883cb..a67ce20 100644 --- a/postView.ui +++ b/postView.ui @@ -80,6 +80,19 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + +