Commit 8d5983d4 authored by Jan Möbius's avatar Jan Möbius
Browse files

Updater works up to download..

Todos: 
move file to correct position
download next file after success

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@3536 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 2302afb4
...@@ -52,6 +52,8 @@ OptionsWidget::OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyB ...@@ -52,6 +52,8 @@ OptionsWidget::OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyB
connect(applyButton,SIGNAL(clicked()),this,SLOT(slotApply())); connect(applyButton,SIGNAL(clicked()),this,SLOT(slotApply()));
connect(cancelButton,SIGNAL(clicked()),this,SLOT(slotCancel())); connect(cancelButton,SIGNAL(clicked()),this,SLOT(slotCancel()));
connect(checkUpdateButton,SIGNAL(clicked()),this,SLOT(slotCheckUpdates())); connect(checkUpdateButton,SIGNAL(clicked()),this,SLOT(slotCheckUpdates()));
connect(updateButton,SIGNAL(clicked()),this,SLOT(slotGetUpdates()));
updateButton->setEnabled(false);
connect( restrictFPS, SIGNAL(toggled(bool)), FPS, SLOT(setEnabled(bool)) ); connect( restrictFPS, SIGNAL(toggled(bool)), FPS, SLOT(setEnabled(bool)) );
uint mode = 2; uint mode = 2;
for (uint i=1; i < 22; i++) { for (uint i=1; i < 22; i++) {
...@@ -95,7 +97,7 @@ OptionsWidget::OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyB ...@@ -95,7 +97,7 @@ OptionsWidget::OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyB
void OptionsWidget::getBackgroundColor(){ void OptionsWidget::getBackgroundColor(){
QColor newColor = QColorDialog::getColor (QColor(OpenFlipper::Options::defaultBackgroundColor())); QColor newColor = QColorDialog::getColor (QColor(OpenFlipper::Options::defaultBackgroundColor()));
OpenFlipper::Options::defaultBackgroundColor( newColor.rgb() ); OpenFlipper::Options::defaultBackgroundColor( newColor.rgb() );
QPixmap color(16,16); QPixmap color(16,16);
...@@ -218,6 +220,8 @@ void OptionsWidget::showEvent ( QShowEvent * /*event*/ ) { ...@@ -218,6 +220,8 @@ void OptionsWidget::showEvent ( QShowEvent * /*event*/ ) {
void OptionsWidget::updateVersionsTable() { void OptionsWidget::updateVersionsTable() {
updatedPlugins_.clear();
QString fileName = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + QString fileName = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() +
".OpenFlipper" + OpenFlipper::Options::dirSeparator() + "Versions.ini" ; ".OpenFlipper" + OpenFlipper::Options::dirSeparator() + "Versions.ini" ;
...@@ -254,9 +258,10 @@ void OptionsWidget::updateVersionsTable() { ...@@ -254,9 +258,10 @@ void OptionsWidget::updateVersionsTable() {
if ( ini.is_connected() && ini.get_entry(coreVersion, "Core" , systemString ) ) { if ( ini.is_connected() && ini.get_entry(coreVersion, "Core" , systemString ) ) {
// Newer Version available // Newer Version available
if ( isNewer(OpenFlipper::Options::coreVersion(),coreVersion) ) if ( isNewer(OpenFlipper::Options::coreVersion(),coreVersion) ) {
currentBrush.setColor(Qt::red); currentBrush.setColor(Qt::red);
else if ( isNewer(coreVersion , OpenFlipper::Options::coreVersion()) ) updatedPlugins_ << "Core";
} else if ( isNewer(coreVersion , OpenFlipper::Options::coreVersion()) )
currentBrush.setColor(Qt::blue); currentBrush.setColor(Qt::blue);
else else
currentBrush.setColor(Qt::green); currentBrush.setColor(Qt::green);
...@@ -290,9 +295,11 @@ void OptionsWidget::updateVersionsTable() { ...@@ -290,9 +295,11 @@ void OptionsWidget::updateVersionsTable() {
// Newer Version available // Newer Version available
if ( isNewer(plugins_[i].version,latestVersion) ) if ( isNewer(plugins_[i].version,latestVersion) ) {
currentBrush.setColor(Qt::red); currentBrush.setColor(Qt::red);
else if ( isNewer(latestVersion,plugins_[i].version) ) QFileInfo pluginFile(plugins_[i].path );
updatedPlugins_ << pluginFile.fileName();
} else if ( isNewer(latestVersion,plugins_[i].version) )
currentBrush.setColor(Qt::blue); currentBrush.setColor(Qt::blue);
else else
currentBrush.setColor(Qt::green); currentBrush.setColor(Qt::green);
...@@ -321,6 +328,8 @@ void OptionsWidget::updateVersionsTable() { ...@@ -321,6 +328,8 @@ void OptionsWidget::updateVersionsTable() {
updateList->resizeColumnsToContents(); updateList->resizeColumnsToContents();
updateButton->setEnabled(!updatedPlugins_.empty());
} }
void OptionsWidget::slotApply() { void OptionsWidget::slotApply() {
...@@ -395,7 +404,7 @@ void OptionsWidget::startDownload( QString _url ) { ...@@ -395,7 +404,7 @@ void OptionsWidget::startDownload( QString _url ) {
file = new QFile(fileName); file = new QFile(fileName);
if (!file->open(QIODevice::WriteOnly)) { if (!file->open(QIODevice::WriteOnly)) {
std::cerr << "Unable to Open local file for writing" << std::endl; std::cerr << "Unable to Open local file " + fileName.toStdString() + " for writing" << std::endl;
delete file; delete file;
file = 0; file = 0;
} else { } else {
...@@ -436,6 +445,65 @@ void OptionsWidget::slotCheckUpdates() { ...@@ -436,6 +445,65 @@ void OptionsWidget::slotCheckUpdates() {
} }
void OptionsWidget::slotGetUpdates() { void OptionsWidget::slotGetUpdates() {
std::cerr << "Not implemented yet: Get updates" << std::endl;
QString url = updateURL->text();
if ( !url.endsWith("/") )
url += "/";
pluginPath_.clear();
pluginPath_ = "Plugins";
if ( OpenFlipper::Options::isWindows() ) {
pluginPath_ += "Windows/";
} else if ( OpenFlipper::Options::isLinux() ) {
pluginPath_ += "Linux/";
} else {
std::cerr << "Unknown operating system type, aborting update" << std::endl;
return;
}
if ( OpenFlipper::Options::is64bit() ) {
pluginPath_ += "64/";
} else if ( OpenFlipper::Options::is32bit() ) {
pluginPath_ += "32/";
} else {
std::cerr << "Unknown architecture type, aborting update" << std::endl;
return;
}
pluginPath_ += "Release/";
if ( !updatedPlugins_.empty() && updatedPlugins_[0] == "Core" ) {
std::cerr << "Core update not supported!" << std::endl;
return;
}
if ( !updatedPlugins_.empty() ) {
currentUpdateName_ = updatedPlugins_[0];
std::cerr << "Downloading " << (url + pluginPath_ + currentUpdateName_).toStdString() << std::endl;
updatedPlugins_.pop_front();
downloadType = COMPONENT;
startDownload(url + pluginPath_ + currentUpdateName_);
}
}
void OptionsWidget::updateComponent() {
std::cerr << "Todo : Update component" << std::endl;
QFileInfo updateFileInfo (QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() +
".OpenFlipper" + OpenFlipper::Options::dirSeparator() + currentUpdateName_);
if ( ! updateFileInfo.exists() ) {
std::cerr << "Download failed?! " << std::endl;
} else {
}
// QString pluginPath_;
} }
bool OptionsWidget::isNewer(QString _current, QString _latest) { bool OptionsWidget::isNewer(QString _current, QString _latest) {
...@@ -561,7 +629,9 @@ void OptionsWidget::httpRequestFinished(int requestId, bool error) ...@@ -561,7 +629,9 @@ void OptionsWidget::httpRequestFinished(int requestId, bool error)
if ( !error ) { if ( !error ) {
if ( downloadType == VERSIONS_FILE ) if ( downloadType == VERSIONS_FILE )
compareVersions(); compareVersions();
if ( downloadType == COMPONENT )
updateComponent();
} }
} }
......
...@@ -45,86 +45,105 @@ ...@@ -45,86 +45,105 @@
class OptionsWidget : public QWidget, public Ui::OptionsWidget class OptionsWidget : public QWidget, public Ui::OptionsWidget
{ {
Q_OBJECT Q_OBJECT
public:
OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyBinding>& _core, QWidget *parent = 0 );
signals: public:
void applyOptions(); OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyBinding>& _core, QWidget *parent = 0 );
void saveOptions();
private slots: signals:
/// Hide widget, Update Options and tell others about changed Options void applyOptions();
void slotApply(); void saveOptions();
/// Only hide widget private slots:
void slotCancel(); /// Hide widget, Update Options and tell others about changed Options
void slotApply();
/// Checks for updates /// Only hide widget
void slotCheckUpdates(); void slotCancel();
/// Download updates /// Checks for updates
void slotGetUpdates(); void slotCheckUpdates();
/// open a dialog to determine the color /// Download updates
void getBackgroundColor(); void slotGetUpdates();
/// open a dialog to determine the color
void getBackgroundColor();
protected: protected:
void showEvent ( QShowEvent * event ); void showEvent ( QShowEvent * event );
private: private:
//key-bindings //key-bindings
std::vector<PluginInfo>& plugins_; std::vector<PluginInfo>& plugins_;
std::vector<KeyBinding>& coreKeys_; std::vector<KeyBinding>& coreKeys_;
// flag indicating if something went wrong and the request has to be aborted // flag indicating if something went wrong and the request has to be aborted
bool httpRequestAborted; bool httpRequestAborted;
// Id of the current request // Id of the current request
int httpGetId; int httpGetId;
// Request variable // Request variable
QHttp *http; QHttp *http;
// File for http downloads // File for http downloads
QFile *file; QFile *file;
// ProgressDialog for Downloads // ProgressDialog for Downloads
QProgressDialog *progressDialog; QProgressDialog *progressDialog;
// What type of download is currently active // What type of download is currently active
enum DOWNLOAD { enum DOWNLOAD {
NONE, NONE,
VERSIONS_FILE, VERSIONS_FILE,
COMPONENT,
WINDOWS_SETUP WINDOWS_SETUP
} downloadType; } downloadType;
private: private:
/// Starts the download of the given file /// Starts the download of the given file
void startDownload( QString _url ); void startDownload( QString _url );
/// Compares the versions from the downloaded Versions file with the current versions /// Compares the versions from the downloaded Versions file with the current versions
void compareVersions(); void compareVersions();
/// Compares two version strings and returns if a newer Version is available /// Compares two version strings and returns if a newer Version is available
bool isNewer(QString _current, QString _latest); bool isNewer(QString _current, QString _latest);
/// Redraws the version table /// Redraws the version table
void updateVersionsTable(); void updateVersionsTable();
private slots: private slots:
// This slot is called when a http request has been finished // This slot is called when a http request has been finished
void httpRequestFinished(int requestId, bool error); void httpRequestFinished(int requestId, bool error);
// Parses the response and gives feedback // Parses the response and gives feedback
void readResponseHeader(const QHttpResponseHeader &responseHeader); void readResponseHeader(const QHttpResponseHeader &responseHeader);
// Updates the progress Dialog while downloading // Updates the progress Dialog while downloading
void updateDataReadProgress(int bytesRead, int totalBytes); void updateDataReadProgress(int bytesRead, int totalBytes);
// Progress dialog callback for cancel
void cancelDownload();
// Update component of OpenFlipper
void updateComponent();
private:
/** After checking for updates this variable will contain a list of filenames for which updates are available
*/
QStringList updatedPlugins_;
/** Here the architecture specific path for plugins will be created
*/
QString pluginPath_;
/** Current filename of the plugin to be updated
*/
QString currentUpdateName_;
// Progress dialog callback for cancel
void cancelDownload();
}; };
......
...@@ -23,7 +23,7 @@ You can select multiple modes at the same time.</string> ...@@ -23,7 +23,7 @@ You can select multiple modes at the same time.</string>
<string/> <string/>
</property> </property>
<property name="currentIndex" > <property name="currentIndex" >
<number>2</number> <number>4</number>
</property> </property>
<property name="usesScrollButtons" > <property name="usesScrollButtons" >
<bool>true</bool> <bool>true</bool>
...@@ -166,7 +166,7 @@ You can select multiple modes at the same time.</string> ...@@ -166,7 +166,7 @@ You can select multiple modes at the same time.</string>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>462</width> <width>462</width>
<height>685</height> <height>677</height>
</rect> </rect>
</property> </property>
<attribute name="title" > <attribute name="title" >
...@@ -400,7 +400,7 @@ You can select multiple modes at the same time.</string> ...@@ -400,7 +400,7 @@ You can select multiple modes at the same time.</string>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>462</width> <width>462</width>
<height>685</height> <height>677</height>
</rect> </rect>
</property> </property>
<attribute name="title" > <attribute name="title" >
...@@ -424,7 +424,7 @@ You can select multiple modes at the same time.</string> ...@@ -424,7 +424,7 @@ You can select multiple modes at the same time.</string>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>462</width> <width>462</width>
<height>685</height> <height>677</height>
</rect> </rect>
</property> </property>
<attribute name="title" > <attribute name="title" >
...@@ -474,13 +474,24 @@ You can select multiple modes at the same time.</string> ...@@ -474,13 +474,24 @@ You can select multiple modes at the same time.</string>
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_4" > <layout class="QHBoxLayout" name="horizontalLayout_8" >
<item> <item>
<widget class="QPushButton" name="checkUpdateButton" > <layout class="QHBoxLayout" name="horizontalLayout_4" >
<property name="text" > <item>
<string>Check</string> <widget class="QPushButton" name="checkUpdateButton" >
</property> <property name="text" >
</widget> <string>Check</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="updateButton" >
<property name="text" >
<string>Update</string>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer_2" > <spacer name="horizontalSpacer_2" >
......
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