mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
queue for erase/set credentials
This commit is contained in:
parent
13d1fab303
commit
9bbc4f8a5e
8 changed files with 122 additions and 18 deletions
|
@ -346,6 +346,7 @@ HEADERS += \
|
||||||
src/util/IsBigEndian.hpp \
|
src/util/IsBigEndian.hpp \
|
||||||
src/util/JsonQuery.hpp \
|
src/util/JsonQuery.hpp \
|
||||||
src/util/LayoutCreator.hpp \
|
src/util/LayoutCreator.hpp \
|
||||||
|
src/util/Overloaded.hpp \
|
||||||
src/util/QObjectRef.hpp \
|
src/util/QObjectRef.hpp \
|
||||||
src/util/QStringHash.hpp \
|
src/util/QStringHash.hpp \
|
||||||
src/util/rangealgorithm.hpp \
|
src/util/rangealgorithm.hpp \
|
||||||
|
|
|
@ -5,8 +5,10 @@
|
||||||
#include "singletons/Paths.hpp"
|
#include "singletons/Paths.hpp"
|
||||||
#include "singletons/Settings.hpp"
|
#include "singletons/Settings.hpp"
|
||||||
#include "util/CombinePath.hpp"
|
#include "util/CombinePath.hpp"
|
||||||
|
#include "util/Overloaded.hpp"
|
||||||
|
|
||||||
#include <QSaveFile>
|
#include <QSaveFile>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
#define FORMAT_NAME \
|
#define FORMAT_NAME \
|
||||||
([&] { \
|
([&] { \
|
||||||
|
@ -73,6 +75,70 @@ namespace {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QKeychain runs jobs asyncronously, so we have to assure that set/erase
|
||||||
|
// jobs gets executed in order.
|
||||||
|
struct SetJob {
|
||||||
|
QString name;
|
||||||
|
QString credential;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct EraseJob {
|
||||||
|
QString name;
|
||||||
|
};
|
||||||
|
|
||||||
|
using Job = std::variant<SetJob, EraseJob>;
|
||||||
|
|
||||||
|
static std::queue<Job> &jobQueue()
|
||||||
|
{
|
||||||
|
static std::queue<Job> jobs;
|
||||||
|
return jobs;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void runNextJob()
|
||||||
|
{
|
||||||
|
auto &&queue = jobQueue();
|
||||||
|
|
||||||
|
if (!queue.empty())
|
||||||
|
{
|
||||||
|
std::visit(
|
||||||
|
Overloaded{
|
||||||
|
[](const SetJob &set) {
|
||||||
|
qDebug() << "set";
|
||||||
|
auto job =
|
||||||
|
new QKeychain::WritePasswordJob("chatterino");
|
||||||
|
job->setAutoDelete(true);
|
||||||
|
job->setKey(set.name);
|
||||||
|
job->setTextData(set.credential);
|
||||||
|
QObject::connect(job, &QKeychain::Job::finished, qApp,
|
||||||
|
[](auto) { runNextJob(); });
|
||||||
|
job->start();
|
||||||
|
},
|
||||||
|
[](const EraseJob &erase) {
|
||||||
|
qDebug() << "erase";
|
||||||
|
auto job =
|
||||||
|
new QKeychain::DeletePasswordJob("chatterino");
|
||||||
|
job->setAutoDelete(true);
|
||||||
|
job->setKey(erase.name);
|
||||||
|
QObject::connect(job, &QKeychain::Job::finished, qApp,
|
||||||
|
[](auto) { runNextJob(); });
|
||||||
|
job->start();
|
||||||
|
}},
|
||||||
|
queue.front());
|
||||||
|
queue.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void queueJob(Job &&job)
|
||||||
|
{
|
||||||
|
auto &&queue = jobQueue();
|
||||||
|
|
||||||
|
queue.push(std::move(job));
|
||||||
|
if (queue.size() == 1)
|
||||||
|
{
|
||||||
|
runNextJob();
|
||||||
|
}
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Credentials &Credentials::getInstance()
|
Credentials &Credentials::getInstance()
|
||||||
|
@ -125,12 +191,8 @@ void Credentials::set(const QString &provider, const QString &name_,
|
||||||
|
|
||||||
if (useKeyring())
|
if (useKeyring())
|
||||||
{
|
{
|
||||||
auto job = new QKeychain::WritePasswordJob("chatterino");
|
qDebug() << "queue set";
|
||||||
job->setAutoDelete(true);
|
queueJob(SetJob{name, credential});
|
||||||
job->setKey(name);
|
|
||||||
job->setTextData(credential);
|
|
||||||
//QObject::connect(job, &QKeychain::Job::finished, qApp, [](auto) {});
|
|
||||||
job->start();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -150,11 +212,8 @@ void Credentials::erase(const QString &provider, const QString &name_)
|
||||||
|
|
||||||
if (useKeyring())
|
if (useKeyring())
|
||||||
{
|
{
|
||||||
auto job = new QKeychain::DeletePasswordJob("chatterino");
|
qDebug() << "queue erase";
|
||||||
job->setAutoDelete(true);
|
queueJob(EraseJob{name});
|
||||||
job->setKey(name);
|
|
||||||
//QObject::connect(job, &QKeychain::Job::finished, qApp, [](auto) {});
|
|
||||||
job->start();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -128,8 +128,10 @@ Irc::Irc()
|
||||||
|
|
||||||
this->abandonedChannels_[args.item.id] = abandoned;
|
this->abandonedChannels_[args.item.id] = abandoned;
|
||||||
this->servers_.erase(server);
|
this->servers_.erase(server);
|
||||||
|
}
|
||||||
|
|
||||||
// delete password
|
if (args.caller != Irc::noEraseCredentialCaller)
|
||||||
|
{
|
||||||
Credentials::getInstance().erase("irc",
|
Credentials::getInstance().erase("irc",
|
||||||
getCredentialName(args.item));
|
getCredentialName(args.item));
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ class QAbstractTableModel;
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
//enum IrcAuthType { Anonymous, /*Sals,*/ Pass, MsgNickServ, NickServ };
|
enum class IrcAuthType { Anonymous, Custom, Pass };
|
||||||
|
|
||||||
struct IrcServerData {
|
struct IrcServerData {
|
||||||
QString host;
|
QString host;
|
||||||
|
@ -38,6 +38,9 @@ public:
|
||||||
|
|
||||||
static Irc &getInstance();
|
static Irc &getInstance();
|
||||||
|
|
||||||
|
static inline void *const noEraseCredentialCaller =
|
||||||
|
reinterpret_cast<void *>(1);
|
||||||
|
|
||||||
UnsortedSignalVector<IrcServerData> connections;
|
UnsortedSignalVector<IrcServerData> connections;
|
||||||
QAbstractTableModel *newConnectionModel(QObject *parent);
|
QAbstractTableModel *newConnectionModel(QObject *parent);
|
||||||
|
|
||||||
|
|
13
src/util/Overloaded.hpp
Normal file
13
src/util/Overloaded.hpp
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
template <class... Ts>
|
||||||
|
struct Overloaded : Ts... {
|
||||||
|
using Ts::operator()...;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class... Ts>
|
||||||
|
Overloaded(Ts...)->Overloaded<Ts...>;
|
||||||
|
|
||||||
|
} // namespace chatterino
|
|
@ -33,10 +33,30 @@ IrcConnectionEditor::IrcConnectionEditor(const IrcServerData &data, bool isAdd,
|
||||||
this->ui_->passwordLineEdit->setText(password);
|
this->ui_->passwordLineEdit->setText(password);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QObject::connect(this->ui_->loginMethodComboBox,
|
||||||
|
qOverload<int>(&QComboBox::currentIndexChanged), this,
|
||||||
|
[this](int index) {
|
||||||
|
IrcAuthType type;
|
||||||
|
|
||||||
|
switch (index)
|
||||||
|
{
|
||||||
|
case 0: // anonymous
|
||||||
|
type = IrcAuthType::Anonymous;
|
||||||
|
break;
|
||||||
|
case 1: // custom
|
||||||
|
this->ui_->connectCommandsEditor->setFocus();
|
||||||
|
type = IrcAuthType::Custom;
|
||||||
|
break;
|
||||||
|
case 2: // PASS
|
||||||
|
type = IrcAuthType::Pass;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
QFont font("Monospace");
|
QFont font("Monospace");
|
||||||
font.setStyleHint(QFont::TypeWriter);
|
font.setStyleHint(QFont::TypeWriter);
|
||||||
this->ui_->connectCommandsEditor->setFont(font);
|
this->ui_->connectCommandsEditor->setFont(font);
|
||||||
} // namespace chatterino
|
}
|
||||||
|
|
||||||
IrcConnectionEditor::~IrcConnectionEditor()
|
IrcConnectionEditor::~IrcConnectionEditor()
|
||||||
{
|
{
|
||||||
|
|
|
@ -142,7 +142,7 @@
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="8" column="1">
|
<item row="8" column="1">
|
||||||
<widget class="QComboBox" name="comboBox">
|
<widget class="QComboBox" name="loginMethodComboBox">
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Anonymous</string>
|
<string>Anonymous</string>
|
||||||
|
@ -150,7 +150,12 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>PASS</string>
|
<string>Custom</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Server Password (/PASS $password)</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -210,7 +215,7 @@ on connect:</string>
|
||||||
<tabstop>userNameLineEdit</tabstop>
|
<tabstop>userNameLineEdit</tabstop>
|
||||||
<tabstop>nickNameLineEdit</tabstop>
|
<tabstop>nickNameLineEdit</tabstop>
|
||||||
<tabstop>realNameLineEdit</tabstop>
|
<tabstop>realNameLineEdit</tabstop>
|
||||||
<tabstop>comboBox</tabstop>
|
<tabstop>loginMethodComboBox</tabstop>
|
||||||
<tabstop>passwordLineEdit</tabstop>
|
<tabstop>passwordLineEdit</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
|
@ -174,7 +174,8 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent)
|
||||||
{
|
{
|
||||||
if (conn.id == data.id)
|
if (conn.id == data.id)
|
||||||
{
|
{
|
||||||
Irc::getInstance().connections.removeItem(i);
|
Irc::getInstance().connections.removeItem(
|
||||||
|
i, Irc::noEraseCredentialCaller);
|
||||||
Irc::getInstance().connections.insertItem(data,
|
Irc::getInstance().connections.insertItem(data,
|
||||||
i);
|
i);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue