minor bugfix, start account editing feature

This commit is contained in:
Blue 2019-05-23 23:19:53 +03:00
parent 3c3e28b688
commit 16f96c4f2b
10 changed files with 102 additions and 23 deletions

View File

@ -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);

View File

@ -150,6 +150,19 @@ void Core::Squawk::onAccountConnectionStateChanged(int state)
{
Account* acc = static_cast<Account*>(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<QString, QVariant>& data)

View File

@ -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)

View File

@ -22,3 +22,17 @@ QMap<QString, QVariant> Account::value() const
return map;
}
void Account::lockId()
{
m_ui->name->setReadOnly(true);;
}
void Account::setData(const QMap<QString, QVariant>& 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());
}

View File

@ -21,6 +21,8 @@ public:
~Account();
QMap<QString, QVariant> value() const;
void setData(const QMap<QString, QVariant>& data);
void lockId();
private:
QScopedPointer<Ui::Account> m_ui;

View File

@ -3,13 +3,18 @@
#include <QDebug>
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<Account*>(sender());
QMap<QString, QVariant> map = acc->value();
if (editing) {
emit changeAccount(map);
} else {
emit newAccount(map);
}
emit newAccount(map);
editing = false;
}
void Accounts::onAccountRejected()
{
Account* acc = static_cast<Account*>(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);
}
}

View File

@ -3,6 +3,7 @@
#include <QWidget>
#include <QScopedPointer>
#include <QItemSelection>
#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<QString, QVariant>&);
void changeAccount(const QMap<QString, QVariant>&);
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<Ui::Accounts> m_ui;
Models::Accounts* model;
bool editing;
};
#endif // ACCOUNTS_H

View File

@ -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();

View File

@ -25,7 +25,6 @@
#include <QLabel>
#include <QResizeEvent>
#include "../global.h"
#include <QtQuickWidgets/QQuickWidget>
class MessageLine : public QWidget
{
@ -71,7 +70,6 @@ private:
QString myName;
std::map<QString, QString> palNames;
std::deque<QHBoxLayout*> views;
QQuickWidget busy;
};
#endif // MESSAGELINE_H

View File

@ -76,17 +76,15 @@
</property>
<addaction name="actionAccounts"/>
</widget>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionQuit"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuSettings"/>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionAccounts"/>
</widget>
<action name="actionAccounts">
<property name="icon">
<iconset theme="system-users">
@ -96,6 +94,14 @@
<string>Accounts</string>
</property>
</action>
<action name="actionQuit">
<property name="icon">
<iconset theme="application-exit"/>
</property>
<property name="text">
<string>Quit</string>
</property>
</action>
</widget>
<resources/>
<connections/>