Skip to content

Commit

Permalink
Add support for source login
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Nov 6, 2020
1 parent 55f81d7 commit 7354614
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 1 deletion.
49 changes: 49 additions & 0 deletions src/gui-qml/src/components/settings/SourceSettingsScreen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,55 @@ Page {
Layout.fillWidth: true
}

SettingTitle {
Layout.fillWidth: true
text: qsTr("Login")
}
Setting {
id: loginTypeSetting
key: "login/type"
def: "url"
obj: root.site.settings
}
ComboSetting {
name: qsTr("Type")
options: root.site.authFields.map(f => globals.authTypes[f.type] || f.type)
values: root.site.authFields.map(f => f.type)
setting: loginTypeSetting
Layout.fillWidth: true
}
Repeater {
model: root.site.authFields
Layout.fillWidth: true

delegate: Item {
height: 100
width: parent.width
visible: modelData.type === loginTypeSetting.value

Column {
spacing: 0
width: parent.width

Repeater {
model: modelData.fields
width: parent.width

delegate: TextFieldSetting {
name: globals.authFieldLabels[modelData.id] || modelData.id
setting: Setting {
key: "auth/" + modelData.id
def: modelData.def
obj: root.site.settings
}
echoMode: modelData.isPassword ? TextInput.Password : TextInput.Normal
width: parent.width
}
}
}
}
}

SettingTitle {
Layout.fillWidth: true
text: qsTr("API order")
Expand Down
16 changes: 16 additions & 0 deletions src/gui-qml/src/main-screen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ ApplicationWindow {

property var apiTypes: ["XML", "JSON", "Regex", "RSS"]
property var apiTypesKeys: ["xml", "json", "regex", "rss"]

property var authTypes: {
"url": qsTr("Through URL"),
"http_basic": qsTr("HTTP Basic"),
"get": qsTr("GET"),
"post": qsTr("POST"),
"oauth1": qsTr("OAuth 1"),
"oauth2": qsTr("OAuth 2")
}
property var authFieldLabels: {
"pseudo": qsTr("Username"),
"userId": qsTr("User ID"),
"password": qsTr("Password"),
"salt": qsTr("Salt"),
"apiKey": qsTr("API key")
}
}

MainDrawer {
Expand Down
4 changes: 4 additions & 0 deletions src/gui-qml/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "main-screen.h"
#include "models/image.h"
#include "models/profile.h"
#include "models/qml-auth.h"
#include "models/qml-auth-setting-field.h"
#include "models/qml-image.h"
#include "models/qml-site.h"
#include "settings.h"
Expand Down Expand Up @@ -51,6 +53,8 @@ int main(int argc, char *argv[])
qRegisterMetaType<QList<QmlImage*>>("QList>QmlImage*>");
qRegisterMetaType<QmlSite*>("QmlSite*");
qRegisterMetaType<QList<QmlSite*>>("QList<QmlSite*>");
qRegisterMetaType<QList<QmlAuth*>>("QList<QmlAuth*>");
qRegisterMetaType<QList<QmlAuthSettingField*>>("QList<QmlAuthSettingField*>");

// Copy settings files to writable directory
const QStringList toCopy { "sites/", "themes/", "webservices/" };
Expand Down
31 changes: 31 additions & 0 deletions src/gui-qml/src/models/qml-auth-setting-field.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef QML_AUTH_SETTING_FIELD_H
#define QML_AUTH_SETTING_FIELD_H

#include <QObject>
#include <QString>
#include "auth/auth.h"


class QmlAuthSettingField : public QObject
{
Q_OBJECT

Q_PROPERTY(QString id READ id CONSTANT)
Q_PROPERTY(QString def READ def CONSTANT)
Q_PROPERTY(bool isPassword READ isPassword CONSTANT)

public:
explicit QmlAuthSettingField(const AuthSettingField &field, QObject *parent = nullptr)
: QObject(parent), m_id(field.id), m_def(field.def), m_isPassword(field.isPassword) {}

QString id() const { return m_id; }
QString def() const { return m_def; }
bool isPassword() const { return m_isPassword; }

private:
QString m_id;
QString m_def;
bool m_isPassword;
};

#endif // QML_AUTH_SETTING_FIELD_H
35 changes: 35 additions & 0 deletions src/gui-qml/src/models/qml-auth.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef QML_AUTH_H
#define QML_AUTH_H

#include <QList>
#include <QObject>
#include <QString>
#include "auth/auth.h"
#include "models/qml-auth-setting-field.h"


class QmlAuth : public QObject
{
Q_OBJECT

Q_PROPERTY(QString type READ type CONSTANT)
Q_PROPERTY(QList<QmlAuthSettingField*> fields READ fields CONSTANT)

public:
explicit QmlAuth(Auth *auth, QObject *parent = nullptr)
: QObject(parent), m_type(auth->type())
{
for (const auto &field : auth->settingFields()) {
m_fields.append(new QmlAuthSettingField(field, this));
}
}

QString type() const { return m_type; }
QList<QmlAuthSettingField*> fields() const { return m_fields; }

private:
QString m_type;
QList<QmlAuthSettingField*> m_fields;
};

#endif // QML_AUTH_H
13 changes: 12 additions & 1 deletion src/gui-qml/src/models/qml-site.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#define QML_SITE_H

#include <QObject>
#include "models/qml-auth.h"
#include "models/site.h"
#include "models/source.h"
#include "settings.h"


Expand All @@ -13,18 +15,27 @@ class QmlSite : public QObject
Q_PROPERTY(QString url READ url CONSTANT)
Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(Settings* settings READ settings CONSTANT)
Q_PROPERTY(QList<QmlAuth*> authFields READ authFields CONSTANT)

public:
explicit QmlSite(Site *site, QObject *parent = nullptr)
: QObject(parent), m_site(site), m_settings(new Settings(site->settings(), this)) {}
: QObject(parent), m_site(site), m_settings(new Settings(site->settings(), this))
{
auto auths = m_site->getSource()->getAuths();
for (auto it = auths.constBegin(); it != auths.constEnd(); ++it) {
m_fields.append(new QmlAuth(it.value(), this));
}
}

QString url() const { return m_site->url(); }
QString name() const { return m_site->name(); }
Settings *settings() const { return m_settings; }
QList<QmlAuth*> authFields() const { return m_fields; }

private:
Site *m_site;
Settings *m_settings;
QList<QmlAuth*> m_fields;
};

#endif // QML_SITE_H

0 comments on commit 7354614

Please sign in to comment.