Client OPDS per Calibre Web (Sailfish OS): core C++ testato, UI Silica, packaging RPM
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
#include "settings.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
|
||||
Settings::Settings(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_settings(QStringLiteral("harbour"), QStringLiteral("calibreweb"))
|
||||
{
|
||||
}
|
||||
|
||||
QString Settings::serverUrl() const
|
||||
{
|
||||
return m_settings.value(QStringLiteral("serverUrl")).toString();
|
||||
}
|
||||
|
||||
void Settings::setServerUrl(const QString &value)
|
||||
{
|
||||
if (value == serverUrl())
|
||||
return;
|
||||
m_settings.setValue(QStringLiteral("serverUrl"), value);
|
||||
emit serverUrlChanged();
|
||||
}
|
||||
|
||||
QString Settings::username() const
|
||||
{
|
||||
return m_settings.value(QStringLiteral("username")).toString();
|
||||
}
|
||||
|
||||
void Settings::setUsername(const QString &value)
|
||||
{
|
||||
if (value == username())
|
||||
return;
|
||||
m_settings.setValue(QStringLiteral("username"), value);
|
||||
emit usernameChanged();
|
||||
}
|
||||
|
||||
QString Settings::password() const
|
||||
{
|
||||
return m_settings.value(QStringLiteral("password")).toString();
|
||||
}
|
||||
|
||||
void Settings::setPassword(const QString &value)
|
||||
{
|
||||
if (value == password())
|
||||
return;
|
||||
m_settings.setValue(QStringLiteral("password"), value);
|
||||
emit passwordChanged();
|
||||
}
|
||||
|
||||
bool Settings::ignoreSslErrors() const
|
||||
{
|
||||
return m_settings.value(QStringLiteral("ignoreSslErrors"), false).toBool();
|
||||
}
|
||||
|
||||
void Settings::setIgnoreSslErrors(bool value)
|
||||
{
|
||||
if (value == ignoreSslErrors())
|
||||
return;
|
||||
m_settings.setValue(QStringLiteral("ignoreSslErrors"), value);
|
||||
emit ignoreSslErrorsChanged();
|
||||
}
|
||||
|
||||
QString Settings::downloadDir() const
|
||||
{
|
||||
QString dir = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
||||
if (dir.isEmpty())
|
||||
dir = QStringLiteral("/home/nemo/Downloads");
|
||||
QDir().mkpath(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
QString Settings::authHeader() const
|
||||
{
|
||||
const QString user = username();
|
||||
if (user.isEmpty())
|
||||
return QString();
|
||||
const QString credentials = user + QLatin1Char(':') + password();
|
||||
return QStringLiteral("Basic ") + QString::fromLatin1(credentials.toUtf8().toBase64());
|
||||
}
|
||||
|
||||
QString Settings::baseUrl() const
|
||||
{
|
||||
QString url = serverUrl().trimmed();
|
||||
while (url.endsWith(QLatin1Char('/')))
|
||||
url.chop(1);
|
||||
return url;
|
||||
}
|
||||
Reference in New Issue
Block a user