Gerrit: Make sure there's only one GerritParameters object

Later to be renamed to GerritSettings, and possibly using aspects.

Change-Id: Idd3d9d3de4f9827478129fe210abfa7b80cff84d
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
hjk
2024-07-16 10:42:05 +02:00
parent d8ccc0479d
commit b5094f7da3
3 changed files with 25 additions and 30 deletions

View File

@@ -18,6 +18,8 @@
#include <QCheckBox>
#include <QFormLayout>
using namespace Utils;
namespace Gerrit::Internal {
class GerritOptionsWidget : public Core::IOptionsPageWidget
@@ -70,24 +72,26 @@ public:
httpsCheckBox,
onChanged] {
GerritParameters &s = gerritSettings();
GerritParameters newParameters;
newParameters.server = GerritServer(hostLineEdit->text().trimmed(),
GerritServer server(hostLineEdit->text().trimmed(),
static_cast<unsigned short>(portSpinBox->value()),
userLineEdit->text().trimmed(),
GerritServer::Ssh);
newParameters.ssh = sshChooser->filePath();
newParameters.curl = curlChooser->filePath();
newParameters.https = httpsCheckBox->isChecked();
FilePath ssh = sshChooser->filePath();
FilePath curl = curlChooser->filePath();
bool https = httpsCheckBox->isChecked();
if (newParameters != s) {
if (s.ssh == newParameters.ssh)
newParameters.portFlag = s.portFlag;
else
newParameters.setPortFlagBySshType();
s = newParameters;
if (server == s.server && ssh == s.ssh && curl == s.curl && https == s.https)
return;
s.server = server;
s.ssh = ssh;
s.curl = curl;
s.https = https;
if (s.ssh != ssh)
s.setPortFlagBySshType();
s.toSettings();
emit onChanged();
}
});
}
};

View File

@@ -89,11 +89,6 @@ GerritParameters::GerritParameters()
{
}
bool GerritParameters::equals(const GerritParameters &rhs) const
{
return server == rhs.server && ssh == rhs.ssh && curl == rhs.curl && https == rhs.https;
}
void GerritParameters::toSettings() const
{
QtcSettings *s = ICore::settings();

View File

@@ -12,26 +12,22 @@ namespace Gerrit::Internal {
class GerritParameters
{
public:
GerritParameters();
bool isValid() const;
bool equals(const GerritParameters &rhs) const;
void toSettings() const;
void saveQueries() const;
void fromSettings();
void setPortFlagBySshType();
friend bool operator==(const GerritParameters &p1, const GerritParameters &p2)
{ return p1.equals(p2); }
friend bool operator!=(const GerritParameters &p1, const GerritParameters &p2)
{ return !p1.equals(p2); }
GerritServer server;
Utils::FilePath ssh;
Utils::FilePath curl;
QStringList savedQueries;
bool https = true;
QString portFlag;
private:
friend GerritParameters &gerritSettings();
GerritParameters();
};
GerritParameters &gerritSettings();