mirror of
https://gitlab.com/niansa/qcommsy.git
synced 2025-03-06 20:53:33 +01:00
Improved UI and fixed caching bug in libcommsy
This commit is contained in:
parent
f692d1fd15
commit
ab3649739a
3 changed files with 83 additions and 13 deletions
|
@ -1,4 +1,4 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -31,6 +31,10 @@ static std::string server_url;
|
||||||
static std::string server_sid;
|
static std::string server_sid;
|
||||||
static std::string room;
|
static std::string room;
|
||||||
|
|
||||||
|
namespace taskState {
|
||||||
|
enum type {none, done, inProgress, todo};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string ltrim(const std::string& s) {
|
std::string ltrim(const std::string& s) {
|
||||||
static const std::regex lws{"^[[:space:]]*", std::regex_constants::extended};
|
static const std::regex lws{"^[[:space:]]*", std::regex_constants::extended};
|
||||||
|
@ -240,6 +244,25 @@ bool get_post_unread(GumboNode *node) {
|
||||||
return !elems.empty();
|
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<std::string> 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<std::map<std::string, std::string>> get_post_files(GumboNode *node) {
|
std::vector<std::map<std::string, std::string>> get_post_files(GumboNode *node) {
|
||||||
std::vector<GumboNode *> metanodes;
|
std::vector<GumboNode *> metanodes;
|
||||||
std::vector<std::string> fileurls;
|
std::vector<std::string> fileurls;
|
||||||
|
@ -317,16 +340,17 @@ struct commsyFile {
|
||||||
struct commsyPost {
|
struct commsyPost {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string id;
|
std::string id;
|
||||||
std::string description;
|
std::string description = "\xFF";
|
||||||
std::string meta;
|
std::string meta;
|
||||||
std::string url;
|
std::string url;
|
||||||
bool unread;
|
bool unread;
|
||||||
|
taskState::type taskState;
|
||||||
std::vector<commsyFile> files;
|
std::vector<commsyFile> files;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define libCommsy_NAME "libcommsy"
|
#define libCommsy_NAME "libcommsy"
|
||||||
#define libCommsy_VERSION "1.2-stable"
|
#define libCommsy_VERSION "1.3-stable"
|
||||||
class libCommsy {
|
class libCommsy {
|
||||||
public:
|
public:
|
||||||
std::vector<commsyPost> posts;
|
std::vector<commsyPost> posts;
|
||||||
|
@ -351,10 +375,11 @@ public:
|
||||||
commsyPost *thispost = getPost(postID);
|
commsyPost *thispost = getPost(postID);
|
||||||
|
|
||||||
// Check if post description was downloaded already
|
// Check if post description was downloaded already
|
||||||
if (thispost->description.empty()) {
|
if (thispost->description == "\xFF") {
|
||||||
// Download post
|
// Download post
|
||||||
thispost->description = get_post_desc(server_url + thispost->url);
|
thispost->description = get_post_desc(server_url + thispost->url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return it
|
// Return it
|
||||||
return &thispost->description;
|
return &thispost->description;
|
||||||
}
|
}
|
||||||
|
@ -411,6 +436,8 @@ public:
|
||||||
thispost.meta = get_post_meta(*it);
|
thispost.meta = get_post_meta(*it);
|
||||||
// Get if post is unread
|
// Get if post is unread
|
||||||
thispost.unread = get_post_unread(*it);
|
thispost.unread = get_post_unread(*it);
|
||||||
|
// Get posts task state
|
||||||
|
thispost.taskState = get_post_taskState(*it);
|
||||||
// Get posts URL
|
// Get posts URL
|
||||||
thispost.url = get_post_url(*it);
|
thispost.url = get_post_url(*it);
|
||||||
// Get posts files
|
// Get posts files
|
||||||
|
|
48
main.cpp
48
main.cpp
|
@ -21,6 +21,8 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QListWidgetItem>
|
||||||
|
#include <QFont>
|
||||||
#include <QStyleFactory>
|
#include <QStyleFactory>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
@ -48,7 +50,7 @@ public:
|
||||||
void overviewWindow(bool catchInvalidRoomError = true);
|
void overviewWindow(bool catchInvalidRoomError = true);
|
||||||
void loginWindow(const QString& failure = "");
|
void loginWindow(const QString& failure = "");
|
||||||
void infoWindow();
|
void infoWindow();
|
||||||
void postViewWindow(commsyPost *thispost, const QString& description);
|
void postViewWindow(commsyPost *thispost, QString description);
|
||||||
void offlineWindow();
|
void offlineWindow();
|
||||||
|
|
||||||
_UILoader () {
|
_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;
|
Ui::postViewWindow *thisui = new Ui::postViewWindow;
|
||||||
|
|
||||||
// Show initial UI
|
// Show initial UI
|
||||||
|
@ -245,14 +247,24 @@ void _UILoader::postViewWindow(commsyPost *thispost, const QString& description)
|
||||||
w->show();
|
w->show();
|
||||||
thisui->statusText->setVisible(false);
|
thisui->statusText->setVisible(false);
|
||||||
|
|
||||||
|
// Remove trailing space from description
|
||||||
|
if (description.size() != 0 and description.back() == '\n') {
|
||||||
|
description.chop(1);
|
||||||
|
}
|
||||||
|
|
||||||
// Update informations
|
// Update informations
|
||||||
thisui->titleText->setText(QString::fromStdString(thispost->name));
|
thisui->titleText->setText(QString::fromStdString(thispost->name));
|
||||||
thisui->metaText->setText(QString::fromStdString(thispost->meta));
|
thisui->metaText->setText(QString::fromStdString(thispost->meta));
|
||||||
thisui->descriptionText->setText(description);
|
thisui->descriptionText->setText(description);
|
||||||
|
|
||||||
// Update file list
|
// Update file list if required
|
||||||
for (const auto& thisfile : thispost->files) {
|
if (thispost->files.size() != 0) {
|
||||||
thisui->fileList->addItem(QString::fromStdString(thisfile.name));
|
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
|
// Add button handlers
|
||||||
|
@ -317,18 +329,36 @@ void _UILoader::overviewWindow(bool catchInvalidRoomError) {
|
||||||
return failureWindow();
|
return failureWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get font used for unread posts
|
||||||
|
QFont unreadFont = QFont();
|
||||||
|
unreadFont.setBold(true);
|
||||||
|
|
||||||
// Refresh view
|
// Refresh view
|
||||||
thisui->postCounter->setText(QString::number(connector->numposts) + " Einträge");
|
thisui->postCounter->setText(QString::number(connector->numposts) + " Einträge");
|
||||||
thisui->postList->clear();
|
thisui->postList->clear();
|
||||||
for (const auto& thispost : connector->posts) {
|
for (const auto& thispost : connector->posts) {
|
||||||
QString displayName;
|
QListWidgetItem *thisitem = new QListWidgetItem(QString::fromStdString(thispost.name), thisui->postList);
|
||||||
|
|
||||||
if (thispost.unread) {
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
postView.ui
13
postView.ui
|
@ -80,6 +80,19 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="filesInfo">
|
<widget class="QLabel" name="filesInfo">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
Loading…
Add table
Reference in a new issue