Skip to content
This repository was archived by the owner on Aug 3, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions OWNCLOUD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ set( MAC_INSTALLER_BACKGROUND_FILE "${CMAKE_SOURCE_DIR}/admin/osx/installer-back
# set( THEME_INCLUDE "${OEM_THEME_DIR}/mytheme.h" )
# set( APPLICATION_LICENSE "${OEM_THEME_DIR}/license.txt )

# set( APPLICATION_PROVIDERS "https://bitgrid.net/~jus/providers.json.1" )
# set( APPLICATION_SERVERSETUP "https://nextcloud.com/install/#instructions-server" )

option( WITH_CRASHREPORTER "Build crashreporter" OFF )
set( CRASHREPORTER_SUBMIT_URL "https://crash-reports.owncloud.com/submit" CACHE string "URL for crash reporter" )
set( CRASHREPORTER_ICON ":/owncloud-icon.png" )
2 changes: 2 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#cmakedefine APPLICATION_EXECUTABLE "@APPLICATION_EXECUTABLE@"
#cmakedefine APPLICATION_UPDATE_URL "@APPLICATION_UPDATE_URL@"
#cmakedefine APPLICATION_ICON_NAME "@APPLICATION_ICON_NAME@"
#cmakedefine APPLICATION_PROVIDERS "@APPLICATION_PROVIDERS@"
#cmakedefine APPLICATION_SERVERSETUP "@APPLICATION_SERVERSETUP@"

#cmakedefine ZLIB_FOUND @ZLIB_FOUND@

Expand Down
14 changes: 14 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ set(client_UI
wizard/owncloudsetupnocredspage.ui
wizard/owncloudwizardresultpage.ui
)
if(APPLICATION_PROVIDERS)
list(APPEND client_UI
wizard/owncloudproviderlistpage.ui
wizard/providerwidget.ui
)
endif()

qt_wrap_ui(client_UI_SRCS ${client_UI})

Expand Down Expand Up @@ -105,6 +111,7 @@ set(client_SRCS
wizard/owncloudwizardcommon.cpp
wizard/owncloudwizard.cpp
wizard/owncloudwizardresultpage.cpp
wizard/owncloudprovidermodel.cpp
)

IF(NOT NO_SHIBBOLETH)
Expand All @@ -116,6 +123,13 @@ IF(NOT NO_SHIBBOLETH)
)
endif()

if(APPLICATION_PROVIDERS)
list(APPEND client_SRCS
wizard/owncloudproviderlistpage.cpp
wizard/providerwidget.cpp
)
endif()

set(updater_SRCS
updater/ocupdater.cpp
updater/updateinfo.cpp
Expand Down
187 changes: 187 additions & 0 deletions src/gui/wizard/owncloudproviderlistpage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QUrl>
#include <QDebug>
#include <QStringListModel>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QListWidgetItem>
#include <QObject>
#include <QLocale>

#include "owncloudproviderlistpage.h"
#include "ui_owncloudproviderlistpage.h"
#include "theme.h"
#include "config.h"
#include "wizard/owncloudwizardcommon.h"
#include "QProgressIndicator.h"
#include "ui_providerwidget.h"
#include "providerwidget.h"

namespace OCC
{
OwncloudProviderListPage::OwncloudProviderListPage(QWidget *parent) :
QWizardPage(parent),
ui(new Ui_OwncloudProviderListPage),
countryModel(new QStringListModel(this)),
_progressIndicator(new QProgressIndicator(this)),
showFreeOnly(true)
{
ui->setupUi(this);
setTitle(WizardCommon::titleTemplate().arg(tr("Hosting providers")));
setSubTitle(WizardCommon::subTitleTemplate().arg(tr("find a provider to create a new account")));
setupCustomization();
}

OwncloudProviderListPage::~OwncloudProviderListPage()
{
delete countryModel;
}

void OwncloudProviderListPage::setupCustomization()
{
ui->horizontalLayout->addWidget(_progressIndicator, 0, Qt::AlignLeft);
this->setLayout(ui->verticalLayout);
ui->listWidget->setAlternatingRowColors(true);
startSpinner();
}

void OwncloudProviderListPage::initializePage() {
loadProviders();
filterProviders();
}

void OwncloudProviderListPage::startSpinner()
{
_progressIndicator->setVisible(true);
_progressIndicator->startAnimation();
ui->country->setVisible(false);
}

void OwncloudProviderListPage::stopSpinner()
{
ui->bottomLabel->setText("");
ui->country->setVisible(true);
_progressIndicator->setVisible(false);
_progressIndicator->stopAnimation();
}
void OwncloudProviderListPage::toggleFreePlans(bool state)
{
showFreeOnly = state;
filterProviders();
}

void OwncloudProviderListPage::setCountry(QString current)
{
showCountryOnly = new QString(current);
filterProviders();
}

void OwncloudProviderListPage::loadProviders()
{

_nam = new QNetworkAccessManager(this);
QObject::connect(_nam, SIGNAL(finished(QNetworkReply*)),
this,
SLOT(serviceRequestFinished(QNetworkReply*)));
QUrl url(APPLICATION_PROVIDERS);
_nam->get(QNetworkRequest(url));
qDebug() << "Loading providers from" << url;

}

void OwncloudProviderListPage::filterProviders()
{
const int itemCount = ui->listWidget->count();
for ( int index = 0; index < itemCount; index++)
{
QListWidgetItem *item = ui->listWidget->item(index);
OwncloudProviderModel *provider = qvariant_cast<OwncloudProviderModel*>(item->data(Qt::UserRole));
QJsonArray countries = provider->flags();
bool free = provider->free();
bool countryMatches = false;
foreach (const QJsonValue & value, countries) {
QString country = value.toString();
if(country.contains(ui->country->currentData().toString())) {
countryMatches = true;
}
}

if((showFreeOnly && !free) || !countryMatches) {
item->setHidden(true);
} else {
item->setHidden(false);
}
}
}

void OwncloudProviderListPage::serviceRequestFinished(QNetworkReply* reply)
{
QString currentCountry = QLocale::system().name().split('_').at(1).toLower();
if(reply->error() == QNetworkReply::NoError) {
QString strReply = (QString)reply->readAll();
QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());

QStringList countryList;
if (!jsonResponse.isArray())
return;
foreach (const QJsonValue & value, jsonResponse.array()) {
QJsonObject object = value.toObject();
foreach(const QJsonValue & flag, object["flags"].toArray()) {
countryList << flag.toString();
}
OwncloudProviderModel *model = new OwncloudProviderModel(this);
model->setJsonObject(object);
ProviderWidget *widget = new ProviderWidget(this);
QListWidgetItem *witem = new QListWidgetItem();
QVariant v = QVariant::fromValue(model);
witem->setData(Qt::UserRole, v);

ui->listWidget->addItem(witem);
ui->listWidget->setItemWidget(witem, qobject_cast<QWidget*>(widget));
widget->updateProvider(witem);
witem->setSizeHint(QSize(ui->listWidget->sizeHint().width(), widget->sizeHint().height()));
}

// Build country list
countryList.removeDuplicates();
ui->country->addItem(tr("All countries"), QVariant("all"));
QList<QLocale> cnt = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
std::sort(cnt.begin(), cnt.end(), [ ]( const QLocale& l1, const QLocale& l2 )
{
return QLocale::countryToString(l1.country()) < QLocale::countryToString(l2.country());
});
foreach (const QLocale countryCode, cnt) {
QLocale::Country country = countryCode.country();
if(countryCode.name() == "C")
continue;

QString countryIdentifier = countryCode.name().split('_').at(1).toLower();
if(countryList.contains(countryIdentifier) && ui->country->findData(QVariant(countryIdentifier)) == -1) {
ui->country->addItem(QLocale::countryToString(country), QVariant(countryIdentifier));
}
}

reply->deleteLater();
stopSpinner();
} else {
ui->bottomLabel->setText(tr("Failed to fetch provider list."));
}



int index = ui->country->findData(QVariant(currentCountry));
if ( index != -1 ) {
ui->country->setCurrentIndex(index);
} else {
ui->country->setCurrentIndex(ui->country->findData(QVariant("all")));
}
}

int OwncloudProviderListPage::nextId()
{
return -1;
}

}
48 changes: 48 additions & 0 deletions src/gui/wizard/owncloudproviderlistpage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef OWNCLOUDPROVIDERLISTPAGE_H
#define OWNCLOUDPROVIDERLISTPAGE_H

#include <QWizardPage>
#include <QNetworkReply>
#include <QStringListModel>
#include "ui_owncloudproviderlistpage.h"

class QProgressIndicator;


namespace OCC {

class OwncloudProviderListPage : public QWizardPage
{
Q_OBJECT
public:
OwncloudProviderListPage(QWidget *parent);
~OwncloudProviderListPage();
int nextId();
void initializePage();
public slots:
void toggleFreePlans(bool state);
void setCountry(QString current);

protected slots:
void setupCustomization();
void serviceRequestFinished(QNetworkReply* reply);
void startSpinner();
void stopSpinner();
#ifdef APPLICATION_SERVERSETUP
void openSetupInstructions();
#endif

private:
void loadProviders();
void filterProviders();

Ui_OwncloudProviderListPage *ui;
QNetworkAccessManager *_nam;
QStringListModel *countryModel;
QProgressIndicator *_progressIndicator;
bool showFreeOnly;
QString *showCountryOnly;
};

}
#endif // OWNCLOUDPROVIDERLISTPAGE_H
Loading