From 16f96c4f2b0a540e844d7bbfb743d43d6af839cc Mon Sep 17 00:00:00 2001 From: blue Date: Thu, 23 May 2019 23:19:53 +0300 Subject: [PATCH] minor bugfix, start account editing feature --- core/contact.cpp | 6 +++++- core/squawk.cpp | 13 +++++++++++++ ui/CMakeLists.txt | 7 ------- ui/account.cpp | 14 ++++++++++++++ ui/account.h | 2 ++ ui/accounts.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++--- ui/accounts.h | 8 +++++++- ui/messageline.cpp | 1 + ui/messageline.h | 2 -- ui/squawk.ui | 24 ++++++++++++++--------- 10 files changed, 102 insertions(+), 23 deletions(-) diff --git a/core/contact.cpp b/core/contact.cpp index 1a1203a..e60903c 100644 --- a/core/contact.cpp +++ b/core/contact.cpp @@ -259,17 +259,21 @@ void Core::Contact::flushMessagesToArchive(bool finished, const QString& firstId } switch (archiveState) { - break; case beginning: if (finished) { archiveState = complete; + archive->addElements(appendCache); + appendCache.clear(); nextRequest(); } else { emit needHistory("", lastId); } + break; case chunk: if (finished) { archiveState = end; + archive->addElements(appendCache); + appendCache.clear(); nextRequest(); } else { emit needHistory("", lastId); diff --git a/core/squawk.cpp b/core/squawk.cpp index 2d20941..1059c9a 100644 --- a/core/squawk.cpp +++ b/core/squawk.cpp @@ -150,6 +150,19 @@ void Core::Squawk::onAccountConnectionStateChanged(int state) { Account* acc = static_cast(sender()); emit accountConnectionStateChanged(acc->getName(), state); + + if (state == Shared::disconnected) { + bool equals = true; + for (Accounts::const_iterator itr = accounts.begin(), end = accounts.end(); itr != end; itr++) { + if ((*itr)->getState() != Shared::disconnected) { + equals = false; + } + } + if (equals) { + state = Shared::offline; + emit stateChanged(state); + } + } } void Core::Squawk::onAccountAddContact(const QString& jid, const QString& group, const QMap& data) diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index e2fbf4c..c5f7a42 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -8,10 +8,6 @@ set(CMAKE_AUTOUIC ON) # Find the QtWidgets library find_package(Qt5Widgets CONFIG REQUIRED) -find_package(Qt5Qml CONFIG REQUIRED) -find_package(Qt5QuickCompiler) -find_package(Qt5Quick CONFIG REQUIRED) -find_package(Qt5QuickWidgets CONFIG REQUIRED) set(squawkUI_SRC squawk.cpp @@ -32,9 +28,6 @@ add_library(squawkUI ${squawkUI_SRC}) # Use the Widgets module from Qt 5. target_link_libraries(squawkUI Qt5::Widgets) -target_link_libraries(squawkUI Qt5::Quick) -target_link_libraries(squawkUI Qt5::Qml) -target_link_libraries(squawkUI Qt5::QuickWidgets) # Install the executable install(TARGETS squawkUI DESTINATION lib) diff --git a/ui/account.cpp b/ui/account.cpp index 93ba878..8e736c1 100644 --- a/ui/account.cpp +++ b/ui/account.cpp @@ -22,3 +22,17 @@ QMap Account::value() const return map; } + +void Account::lockId() +{ + m_ui->name->setReadOnly(true);; +} + +void Account::setData(const QMap& data) +{ + m_ui->login->setText(data.value("login").toString()); + m_ui->password->setText(data.value("password").toString()); + m_ui->server->setText(data.value("server").toString()); + m_ui->name->setText(data.value("name").toString()); + m_ui->resource->setText(data.value("resource").toString()); +} diff --git a/ui/account.h b/ui/account.h index ee8850d..fc3f5a3 100644 --- a/ui/account.h +++ b/ui/account.h @@ -21,6 +21,8 @@ public: ~Account(); QMap value() const; + void setData(const QMap& data); + void lockId(); private: QScopedPointer m_ui; diff --git a/ui/accounts.cpp b/ui/accounts.cpp index 82327d9..d5743f6 100644 --- a/ui/accounts.cpp +++ b/ui/accounts.cpp @@ -3,13 +3,18 @@ #include -Accounts::Accounts(Models::Accounts* model, QWidget *parent) : - m_ui(new Ui::Accounts) +Accounts::Accounts(Models::Accounts* p_model, QWidget *parent) : + m_ui(new Ui::Accounts), + model(p_model), + editing(false) { m_ui->setupUi(this); connect(m_ui->addButton, SIGNAL(clicked(bool)), this, SLOT(onAddButton(bool))); + connect(m_ui->editButton, SIGNAL(clicked(bool)), this, SLOT(onEditButton(bool))); m_ui->tableView->setModel(model); + connect(m_ui->tableView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), + this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&))); } Accounts::~Accounts() = default; @@ -26,12 +31,49 @@ void Accounts::onAccountAccepted() { Account* acc = static_cast(sender()); QMap map = acc->value(); + if (editing) { + emit changeAccount(map); + } else { + emit newAccount(map); + } - emit newAccount(map); + editing = false; } void Accounts::onAccountRejected() { Account* acc = static_cast(sender()); acc->deleteLater(); + editing = false; +} + +void Accounts::onEditButton(bool clicked) +{ + Account* acc = new Account(); + + const Models::Account* mAcc = model->getAccount(m_ui->tableView->selectionModel()->selectedRows().at(0).row()); + acc->setData({ + {"login", mAcc->getLogin()}, + {"password", mAcc->getPassword()}, + {"server", mAcc->getServer()}, + {"name", mAcc->getName()}, + {"resource", mAcc->getResource()} + }); + acc->lockId(); + connect(acc, SIGNAL(accepted()), this, SLOT(onAccountAccepted())); + connect(acc, SIGNAL(rejected()), this, SLOT(onAccountRejected())); + editing = true; + acc->exec(); +} + +void Accounts::onSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected) +{ + const QItemSelection& selection = m_ui->tableView->selectionModel()->selection(); + if (selection.size() == 0) { + m_ui->editButton->setEnabled(false); + } else if (selection.size() == 1) { + m_ui->editButton->setEnabled(true); + } else { + m_ui->editButton->setEnabled(false); + } } diff --git a/ui/accounts.h b/ui/accounts.h index a5d2be2..95b8fd6 100644 --- a/ui/accounts.h +++ b/ui/accounts.h @@ -3,6 +3,7 @@ #include #include +#include #include "account.h" #include "models/accounts.h" @@ -16,19 +17,24 @@ class Accounts : public QWidget { Q_OBJECT public: - explicit Accounts(Models::Accounts* model, QWidget *parent = nullptr); + explicit Accounts(Models::Accounts* p_model, QWidget *parent = nullptr); ~Accounts() override; signals: void newAccount(const QMap&); + void changeAccount(const QMap&); private slots: void onAddButton(bool clicked = 0); + void onEditButton(bool clicked = 0); void onAccountAccepted(); void onAccountRejected(); + void onSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected); private: QScopedPointer m_ui; + Models::Accounts* model; + bool editing; }; #endif // ACCOUNTS_H diff --git a/ui/messageline.cpp b/ui/messageline.cpp index 7cb53bb..6920ee0 100644 --- a/ui/messageline.cpp +++ b/ui/messageline.cpp @@ -75,6 +75,7 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg) message->setAutoFillBackground(true);; QLabel* body = new QLabel(msg.getBody()); + body->setTextInteractionFlags(body->textInteractionFlags() | Qt::TextSelectableByMouse); QLabel* sender = new QLabel(); QLabel* time = new QLabel(msg.getTime().toLocalTime().toString()); QFont dFont = time->font(); diff --git a/ui/messageline.h b/ui/messageline.h index 9dbc192..a4d3c5f 100644 --- a/ui/messageline.h +++ b/ui/messageline.h @@ -25,7 +25,6 @@ #include #include #include "../global.h" -#include class MessageLine : public QWidget { @@ -71,7 +70,6 @@ private: QString myName; std::map palNames; std::deque views; - QQuickWidget busy; }; #endif // MESSAGELINE_H diff --git a/ui/squawk.ui b/ui/squawk.ui index 8d0f0d4..cf51038 100644 --- a/ui/squawk.ui +++ b/ui/squawk.ui @@ -76,17 +76,15 @@ + + + File + + + + - - - TopToolBarArea - - - false - - - @@ -96,6 +94,14 @@ Accounts + + + + + + Quit + +