Skip to content

Commit

Permalink
Support raspberry pi 2
Browse files Browse the repository at this point in the history
  • Loading branch information
dalehamel committed Feb 12, 2015
1 parent 0f2eff9 commit 1ec9cab
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 26 deletions.
56 changes: 47 additions & 9 deletions installer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#endif
#include "linkparser.h"

const QString Installer::m_serverUrl = "updater.rasplex.com";
//const QString Installer::m_serverUrl = "localhost:8080"; // for testing

// TODO: Get chunk size from server, or whatever
#define CHUNKSIZE 1*1024*1024

Expand Down Expand Up @@ -61,7 +64,7 @@ Installer::Installer(QWidget *parent) :
connect(manager, SIGNAL(downloadComplete(QByteArray)), this, SLOT(handleFinishedDownload(QByteArray)));
connect(manager, SIGNAL(partialData(QByteArray,qlonglong)),
this, SLOT(handlePartialData(QByteArray,qlonglong)));
connect(ui->linksButton, SIGNAL(clicked()), this, SLOT(updateLinks()));
connect(ui->linksButton, SIGNAL(clicked()), this, SLOT(updateDevices()));
connect(ui->downloadButton, SIGNAL(clicked()), this, SLOT(downloadImage()));
connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
connect(ui->cancelButton, SIGNAL(clicked()), manager, SLOT(cancelDownload()));
Expand All @@ -78,10 +81,12 @@ Installer::Installer(QWidget *parent) :
connect(ui->sdtvMode_3, SIGNAL(clicked()), this, SLOT(selectVideoOutput()));

connect(ui->releaseLinks, SIGNAL(currentIndexChanged(int)), ui->releaseNotes, SLOT(setCurrentIndex(int)));
connect(ui->deviceSelectBox, SIGNAL(currentIndexChanged(int)), this, SLOT(getDeviceReleases(int)));




ui->videoGroupBox->setVisible(configHandler->implemented());
ui->upgradeLabel->setVisible(false);
ui->upgradeLinks->setVisible(false);
adjustSize();

ui->hdmiOutputButton->setChecked(true);
Expand All @@ -91,7 +96,7 @@ Installer::Installer(QWidget *parent) :
setImageFileName("");
ui->writeButton->setEnabled(false);

updateLinks();
updateDevices();
}

Installer::~Installer()
Expand Down Expand Up @@ -130,13 +135,30 @@ void Installer::cancel()
reset();
}

void Installer::getSupportedDevices(const QByteArray &data)
{
DeviceParser deviceParser(data);

ui->deviceSelectBox->clear();

QList<DeviceData> devices = deviceParser.devices();
for (QList<DeviceData>::const_iterator it = devices.constBegin();
it != devices.constEnd(); it++) {
QString deviceName = (*it)["name"];
QString deviceId = (*it)["id"];
ui->deviceSelectBox->insertItem(0, deviceName ,deviceId);
}

reset();
getDeviceReleases(ui->deviceSelectBox->currentIndex());
}

void Installer::parseAndSetLinks(const QByteArray &data)
{
LinkParser linkParser(data);
qDebug()<< data;

ui->releaseLinks->clear();
ui->upgradeLinks->clear();

/* Clear all release notes */
while (ui->releaseNotes->count()) {
Expand All @@ -151,7 +173,6 @@ void Installer::parseAndSetLinks(const QByteArray &data)
QString releaseName = (*it)["version"];
QString url = (*it)["install_url"];
QString notes = (*it)["notes"];
QString foo = (*it)["baoesae"];
QString localchecksum = (*it)["install_sum"];

checksumMap[releaseName] = localchecksum;
Expand Down Expand Up @@ -283,6 +304,10 @@ void Installer::setImageFileName(QString filename)
void Installer::handleFinishedDownload(const QByteArray &data)
{
switch (state) {
case STATE_GET_SUPPORTED_DEVICES:
getSupportedDevices(data);
break;

case STATE_GETTING_LINKS:
parseAndSetLinks(data);
break;
Expand Down Expand Up @@ -347,11 +372,22 @@ void Installer::handlePartialData(const QByteArray &data, qlonglong total)
}
}

void Installer::updateLinks()
void Installer::updateDevices()
{
state = STATE_GET_SUPPORTED_DEVICES;
disableControls();

ui->messageBar->setText("Getting supported RasPlex devices");
QUrl url("http://"+m_serverUrl+"/devices");
manager->get(url);
}

void Installer::getDeviceReleases(int index)
{
state = STATE_GETTING_LINKS;
disableControls();


#if defined( Q_OS_WIN)
QString PLATFORM = "windows";
#elif defined(Q_OS_LINUX)
Expand All @@ -360,8 +396,10 @@ void Installer::updateLinks()
QString PLATFORM = "osx";
#endif

ui->messageBar->setText("Getting latest releases from GitHub.");
QUrl url("http://updater.rasplex.com/install?platform="+PLATFORM);
QString deviceName = ui->deviceSelectBox->itemText(index);
QString deviceId = ui->deviceSelectBox->itemData(index).toString();
ui->messageBar->setText("Getting releases for "+deviceName);
QUrl url("http://"+m_serverUrl+"/install?platform="+PLATFORM+"&device="+deviceId);
manager->get(url);
}

Expand Down
6 changes: 5 additions & 1 deletion installer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Installer : public QDialog
};
enum {
STATE_IDLE,
STATE_GET_SUPPORTED_DEVICES,
STATE_GETTING_LINKS,
STATE_GETTING_URL,
STATE_DOWNLOADING_IMAGE,
Expand All @@ -70,6 +71,7 @@ class Installer : public QDialog
DeviceEnumerator* devEnumerator;
ConfigHandler *configHandler;
bool isCancelled;
static const QString m_serverUrl;

signals:
void proceedToWriteImageToDevice(const QString& image, const QString& device);
Expand All @@ -78,7 +80,9 @@ private slots:
void handleFinishedDownload(const QByteArray& data);
void handlePartialData(const QByteArray& data, qlonglong total);
void cancel();
void updateLinks();
void updateDevices();
void getSupportedDevices(const QByteArray &data);
void getDeviceReleases(int index);
void refreshDeviceList();
void downloadImage();
void getImageFileNameFromUser();
Expand Down
25 changes: 9 additions & 16 deletions installer.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>555</width>
<height>717</height>
<height>758</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -57,36 +57,29 @@
</layout>
</item>
<item>
<widget class="QLabel" name="releaseLabel">
<widget class="QLabel" name="deviceSelectText">
<property name="text">
<string>Step 1: Select Version</string>
<string>Step 1: Select your Device</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="releaseLinks"/>
<widget class="QComboBox" name="deviceSelectBox"/>
</item>
<item>
<widget class="QLabel" name="upgradeLabel">
<property name="enabled">
<bool>false</bool>
</property>
<widget class="QLabel" name="releaseLabel">
<property name="text">
<string>Auto-updates</string>
<string>Step 2: Select Version</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="upgradeLinks">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
<widget class="QComboBox" name="releaseLinks"/>
</item>
<item>
<widget class="QLabel" name="removableDevicesLabel">
<property name="text">
<string>Step 2: Select Device to flash</string>
<string>Step 3: Select Device to flash</string>
</property>
</widget>
</item>
Expand All @@ -96,7 +89,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Step 3: Download Image or select local image file</string>
<string>Step 4: Download Image or select local image file</string>
</property>
</widget>
</item>
Expand Down
25 changes: 25 additions & 0 deletions linkparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,31 @@ LinkParser::LinkParser(const QByteArray &data)
}
}

DeviceParser::DeviceParser(const QByteArray &data)
{
QVariantList deviceList;
bool ok;

#if QT_VERSION >= 0x050000
deviceList = QJsonDocument::fromJson(data).toVariant().toList();
#else
QJson::Parser parser;

deviceList = parser.parse(data, &ok).toList();
Q_ASSERT(ok);
#endif

foreach (const QVariant &device, deviceList) {
ok = device.canConvert<QVariantMap>();
Q_ASSERT(ok);
deviceData.append(device.toMap());
}
}

QList<DeviceData> DeviceParser::devices() const
{
return deviceData;
}

QList<ReleaseData> LinkParser::releases() const
{
Expand Down
19 changes: 19 additions & 0 deletions linkparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ struct ReleaseData {
QMap<QString, QVariant> values;
};

struct DeviceData {
DeviceData(QMap<QString, QVariant> data) : values(data) {}
QString operator[] (const QString &key) const
{ return values[key].toString(); }

QMap<QString, QVariant> values;
};

class LinkParser
{
public:
Expand All @@ -28,4 +36,15 @@ class LinkParser
QList<ReleaseData> releaseData;
};

class DeviceParser
{
public:
DeviceParser(const QByteArray &data);
QList<DeviceData> devices() const;

private:
QList<DeviceData> deviceData;
};


#endif // LINKPARSER_H

0 comments on commit 1ec9cab

Please sign in to comment.