Commit f8de2ffb authored by Shashwat Jolly's avatar Shashwat Jolly
Browse files

Implement EteSync account initialisation

Also added "Advanced Settings" option in config dialog
parent ee7555ae
set(etesyncresource_common_SRCS)
set(etesyncresource_common_SRCS
etesyncadapter.cpp
)
kconfig_add_kcfg_files(etesyncresource_common_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/settings.kcfgc
)
set(etesyncconfig_SRCS
setupwizard.cpp
${etesyncresource_common_SRCS}
)
set(etesyncresource_SRCS
etesyncresource.cpp
etesyncclientstate.cpp
......@@ -11,10 +19,10 @@ set(etesyncresource_SRCS
contacthandler.cpp
calendartaskbasehandler.cpp
calendarhandler.cpp
taskhandler.cpp
etesyncadapter.cpp
taskhandler.cpp
setupwizard.cpp
${etesyncconfig_SRCS}
${etesyncresource_common_SRCS}
)
......@@ -71,34 +79,3 @@ install(TARGETS akonadi_etesync_resource ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES etesyncresource.desktop
DESTINATION ${KDE_INSTALL_DATAROOTDIR}/akonadi/agents
)
################################### Config plugin ############################
set(etesyncconfig_SRCS
etesyncconfig.cpp
${etesyncresource_common_SRCS}
)
ecm_qt_declare_logging_category(etesyncconfig_SRCS
HEADER etesyncconfig_debug.h
IDENTIFIER ETESYNC_CONFIG_LOG
CATEGORY_NAME org.kde.pim.etesync.config
DESCRIPTION "resource etesync (kdepim-runtime)"
EXPORT KDEPIMRUNTIME
)
ki18n_wrap_ui(etesyncconfig_SRCS etesyncconfigwidget.ui)
kcoreaddons_add_plugin(etesyncconfig
SOURCES ${etesyncconfig_SRCS}
JSON "etesyncconfig.json"
INSTALL_NAMESPACE "akonadi/config"
)
target_link_libraries(etesyncconfig
KF5::AkonadiCore
KF5::I18n
KF5::Completion
KF5::ConfigWidgets
KF5::KIOCore
)
\ No newline at end of file
......@@ -134,3 +134,8 @@ EteSyncUserInfo *etesync_user_info_manager_fetch(const EteSyncUserInfoManager *u
{
return etesync_user_info_manager_fetch(user_info_manager, charArrFromQString(owner));
}
EteSyncUserInfo *etesync_user_info_new(const QString &owner, uint8_t version)
{
return etesync_user_info_new(charArrFromQString(owner), version);
}
......@@ -146,4 +146,6 @@ EteSyncCryptoManager *etesync_user_info_get_crypto_manager(const EteSyncUserInfo
EteSyncUserInfo *etesync_user_info_manager_fetch(const EteSyncUserInfoManager *user_info_manager,
const QString &owner);
EteSyncUserInfo *etesync_user_info_new(const QString &owner, uint8_t version);
#endif
\ No newline at end of file
......@@ -92,21 +92,26 @@ bool EteSyncClientState::initToken(QString &serverUrl, QString &username, QStrin
return true;
}
bool EteSyncClientState::initKeypair(const QString &encryptionPassword)
bool EteSyncClientState::initUserInfo()
{
mEncryptionPassword = encryptionPassword;
mJournalManager = EteSyncJournalManagerPtr(etesync_journal_manager_new(mClient.get()));
mDerived = etesync_crypto_derive_key(mClient.get(), mUsername, mEncryptionPassword);
// Get user keypair
EteSyncUserInfoManagerPtr userInfoManager(etesync_user_info_manager_new(mClient.get()));
EteSyncUserInfoPtr userInfo(etesync_user_info_manager_fetch(userInfoManager.get(), mUsername));
if (!userInfo) {
mUserInfo = EteSyncUserInfoPtr(etesync_user_info_manager_fetch(userInfoManager.get(), mUsername));
if (!mUserInfo) {
qCWarning(ETESYNC_LOG) << "User info obtained from server is NULL";
return false;
}
EteSyncCryptoManagerPtr userInfoCryptoManager(etesync_user_info_get_crypto_manager(userInfo.get(), mDerived));
mKeypair = EteSyncAsymmetricKeyPairPtr(etesync_user_info_get_keypair(userInfo.get(), userInfoCryptoManager.get()));
return true;
}
bool EteSyncClientState::initKeypair(const QString &encryptionPassword)
{
mEncryptionPassword = encryptionPassword;
mDerived = etesync_crypto_derive_key(mClient.get(), mUsername, mEncryptionPassword);
EteSyncCryptoManagerPtr userInfoCryptoManager(etesync_user_info_get_crypto_manager(mUserInfo.get(), mDerived));
mKeypair = EteSyncAsymmetricKeyPairPtr(etesync_user_info_get_keypair(mUserInfo.get(), userInfoCryptoManager.get()));
if (!mKeypair) {
qCDebug(ETESYNC_LOG) << "Empty keypair";
return false;
......@@ -115,7 +120,19 @@ bool EteSyncClientState::initKeypair(const QString &encryptionPassword)
return true;
}
void EteSyncClientState::saveCredentials()
void EteSyncClientState::initAccount(const QString &encryptionPassword)
{
mEncryptionPassword = encryptionPassword;
mDerived = etesync_crypto_derive_key(mClient.get(), mUsername, mEncryptionPassword);
mUserInfo = EteSyncUserInfoPtr(etesync_user_info_new(mUsername, ETESYNC_CURRENT_VERSION));
mKeypair = EteSyncAsymmetricKeyPairPtr(etesync_crypto_generate_keypair(mClient.get()));
EteSyncCryptoManagerPtr userInfoCryptoManager(etesync_user_info_get_crypto_manager(mUserInfo.get(), mDerived));
etesync_user_info_set_keypair(mUserInfo.get(), userInfoCryptoManager.get(), mKeypair.get());
EteSyncUserInfoManagerPtr userInfoManager(etesync_user_info_manager_new(mClient.get()));
etesync_user_info_manager_create(userInfoManager.get(), mUserInfo.get());
}
void EteSyncClientState::saveSettings()
{
Settings::self()->setBaseUrl(mServerUrl);
Settings::self()->setUsername(mUsername);
......
......@@ -30,8 +30,10 @@ public:
void init();
bool initToken(QString &serverUrl, QString &username, QString &password);
bool initUserInfo();
bool initKeypair(const QString &encryptionPassword);
void saveCredentials();
void initAccount(const QString &encryptionPassword);
void saveSettings();
EteSync *client()
{
......@@ -66,6 +68,7 @@ private:
QString mDerived;
QString mToken;
EteSyncJournalManagerPtr mJournalManager = nullptr;
EteSyncUserInfoPtr mUserInfo = nullptr;
EteSyncAsymmetricKeyPairPtr mKeypair = nullptr;
QString mUsername, mPassword, mServerUrl, mEncryptionPassword;
};
......
/*
* Copyright (C) 2020 by Shashwat Jolly <shashwat.jolly@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "etesyncconfig.h"
#include <KConfigDialogManager>
#include <KSharedConfig>
#include "settings.h"
namespace {
static const char myConfigGroupName[] = "EteSyncConfigDialog";
}
EteSyncConfig::EteSyncConfig(const KSharedConfigPtr &config, QWidget *parent, const QVariantList &args)
: Akonadi::AgentConfigurationBase(config, parent, args)
{
Settings::instance(config);
QWidget *mainWidget = new QWidget(parent);
ui.setupUi(mainWidget);
parent->layout()->addWidget(mainWidget);
mManager = new KConfigDialogManager(mainWidget, Settings::self());
mManager->updateWidgets();
}
bool EteSyncConfig::save() const
{
mManager->updateSettings();
return Akonadi::AgentConfigurationBase::save();
}
QSize EteSyncConfig::restoreDialogSize() const
{
auto group = config()->group(myConfigGroupName);
const QSize size = group.readEntry("Size", QSize(380, 180));
return size;
}
void EteSyncConfig::saveDialogSize(const QSize &size)
{
auto group = config()->group(myConfigGroupName);
group.writeEntry("Size", size);
}
/*
* Copyright (C) 2020 by Shashwat Jolly <shashwat.jolly@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef ETESYNCCONFIG_H
#define ETESYNCCONFIG_H
#include <AkonadiCore/AgentConfigurationBase>
#include "ui_etesyncconfigwidget.h"
class KConfigDialogManager;
class EteSyncConfig : public Akonadi::AgentConfigurationBase
{
Q_OBJECT
public:
explicit EteSyncConfig(const KSharedConfigPtr &config, QWidget *parent, const QVariantList &args);
bool save() const override;
QSize restoreDialogSize() const override;
void saveDialogSize(const QSize &size) override;
private:
Ui::EteSyncConfigWidget ui;
KConfigDialogManager *mManager = nullptr;
};
AKONADI_AGENTCONFIG_FACTORY(EteSyncConfigFactory, "etesyncconfig.json", EteSyncConfig)
#endif
{
"X-Akonadi-PluginType": "AgentConfig",
"X-Akonadi-Library": "etesyncconfig",
"X-Akonadi-AgentConfig-Type": "akonadi_etesync_resource"
}
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EteSyncConfigWidget</class>
<widget class="QWidget" name="EteSyncConfigWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>401</width>
<height>484</height>
</rect>
</property>
<property name="windowTitle">
<string>Configuration</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Account</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="loginStatusLbl">
<property name="text">
<string>Login status: unknown</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="loginBtn">
<property name="text">
<string>Login with Facebook</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="logoutBtn">
<property name="text">
<string>Logout</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Reminders</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="attendingReminderChkBox">
<property name="text">
<string>Show reminders for events I'm attending</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="maybeAttendingReminderChkBox">
<property name="text">
<string>Show reminders for events I may be attending</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="notAttendingReminderChkBox">
<property name="text">
<string>Show reminders for events I'm not attending</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="notRespondedReminderChkBox">
<property name="text">
<string>Show reminders for events I have not responded to</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="birthdayReminderChkBox">
<property name="text">
<string>Show reminders for friends' birthdays</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Show event reminders</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="eventReminderHoursSpinBox">
<property name="suffix">
<string/>
</property>
<property name="value">
<number>1</number>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>hour(s) before</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Show birthday reminders</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="birthdayReminderDaysSpinBox"/>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_6">
<property name="text">
<string>day(s) before</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -95,6 +95,7 @@ void EteSyncResource::configure(WId windowId)
const int result = wizard.exec();
if (result == QDialog::Accepted) {
synchronize();
mClientState->saveSettings();
Q_EMIT configurationDialogAccepted();
} else {
Q_EMIT configurationDialogRejected();
......
......@@ -20,6 +20,7 @@
#include <KLocalizedString>
#include <KPasswordLineEdit>
#include <QCheckBox>
#include <QFormLayout>
#include <QIcon>
#include <QLabel>
......@@ -46,15 +47,29 @@ LoginPage::LoginPage(QWidget *parent)
QFormLayout *layout = new QFormLayout(this);
mLoginLabel = new QLabel;
mLoginLabel->setWordWrap(true);
layout->addWidget(mLoginLabel);
mUserName = new QLineEdit;
layout->addRow(i18n("User:"), mUserName);
layout->addRow(i18n("Email:"), mUserName);
registerField(QStringLiteral("credentialsUserName*"), mUserName);
mPassword = new KPasswordLineEdit;
layout->addRow(i18n("Password:"), mPassword);
registerField(QStringLiteral("credentialsPassword*"), mPassword, "password", SIGNAL(passwordChanged(QString)));
mAdvancedSettings = new QCheckBox(i18n("Advanced settings"), this);
layout->addWidget(mAdvancedSettings);
mServerUrl = new QLineEdit;
mServerUrl->setVisible(false);
layout->addRow(i18n("Server:"), mServerUrl);
registerField(QStringLiteral("credentialsServerUrl"), mServerUrl);
layout->labelForField(mServerUrl)->setVisible(false);
connect(mAdvancedSettings, SIGNAL(toggled(bool)), mServerUrl, SLOT(setVisible(bool)));
connect(mAdvancedSettings, SIGNAL(toggled(bool)), layout->labelForField(mServerUrl), SLOT(setVisible(bool)));
}
int LoginPage::nextId() const
......@@ -68,7 +83,11 @@ bool LoginPage::validatePage()
qCDebug(ETESYNC_LOG) << "validate login page";
QString username = field(QStringLiteral("credentialsUserName")).toString();
QString password = field(QStringLiteral("credentialsPassword")).toString();
QString serverUrl = QStringLiteral("http://0.0.0.0:9966");
QString advancedServerUrl = field(QStringLiteral("credentialsServerUrl")).toString();
QString serverUrl = QStringLiteral("https://api.etesync.com");
if (!advancedServerUrl.isNull() && !advancedServerUrl.isEmpty()) {
serverUrl = advancedServerUrl;
}
// return true;
bool loginResult = static_cast<SetupWizard *>(wizard())->mClientState->initToken(serverUrl, username, password);
if (!loginResult) {
......@@ -86,6 +105,7 @@ EncryptionPasswordPage::EncryptionPasswordPage(QWidget *parent)
QFormLayout *layout = new QFormLayout(this);
mEncryptionPasswordLabel = new QLabel;
mEncryptionPasswordLabel->setWordWrap(true);
layout->addWidget(mEncryptionPasswordLabel);
mEncryptionPassword = new KPasswordLineEdit;
......@@ -99,10 +119,23 @@ int EncryptionPasswordPage::nextId() const
return -1;
}
void EncryptionPasswordPage::initializePage()
{
bool userInfoResult = static_cast<SetupWizard *>(wizard())->mClientState->initUserInfo();
if (!userInfoResult) {
setSubTitle(i18n("Please set your encryption password below, and make sure you got it right, as it can't be recovered if lost!"));
mInitAccount = true;
}
}
bool EncryptionPasswordPage::validatePage()
{
qCDebug(ETESYNC_LOG) << "validate encryptionpassword page";
QString encryptionPassword = field(QStringLiteral("credentialsEncryptionPassword")).toString();
if (mInitAccount) {
static_cast<SetupWizard *>(wizard())->mClientState->initAccount(encryptionPassword);
return true;
}
// return true;
bool keypairResult = static_cast<SetupWizard *>(wizard())->mClientState->initKeypair(encryptionPassword);
if (!keypairResult) {
......
......@@ -63,6 +63,8 @@ public:
private:
QLineEdit *mUserName = nullptr;
KPasswordLineEdit *mPassword = nullptr;
QCheckBox *mAdvancedSettings = nullptr;
QLineEdit *mServerUrl = nullptr;
QLabel *mLoginLabel = nullptr;
};
......@@ -71,11 +73,13 @@ class EncryptionPasswordPage : public QWizardPage
public:
explicit EncryptionPasswordPage(QWidget *parent = nullptr);
int nextId() const override;
void initializePage() override;
bool validatePage() override;
private:
KPasswordLineEdit *mEncryptionPassword = nullptr;
QLabel *mEncryptionPasswordLabel = nullptr;
bool mInitAccount = false;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment