Commit ec0c4bb0 authored by Jan Möbius's avatar Jan Möbius

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 359c2dde
......@@ -52,6 +52,8 @@ OptionsWidget::OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyB
connect(applyButton,SIGNAL(clicked()),this,SLOT(slotApply()));
connect(cancelButton,SIGNAL(clicked()),this,SLOT(slotCancel()));
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)) );
uint mode = 2;
for (uint i=1; i < 22; i++) {
......@@ -95,7 +97,7 @@ OptionsWidget::OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyB
void OptionsWidget::getBackgroundColor(){
QColor newColor = QColorDialog::getColor (QColor(OpenFlipper::Options::defaultBackgroundColor()));
OpenFlipper::Options::defaultBackgroundColor( newColor.rgb() );
QPixmap color(16,16);
......@@ -218,6 +220,8 @@ void OptionsWidget::showEvent ( QShowEvent * /*event*/ ) {
void OptionsWidget::updateVersionsTable() {
updatedPlugins_.clear();
QString fileName = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() +
".OpenFlipper" + OpenFlipper::Options::dirSeparator() + "Versions.ini" ;
......@@ -254,9 +258,10 @@ void OptionsWidget::updateVersionsTable() {
if ( ini.is_connected() && ini.get_entry(coreVersion, "Core" , systemString ) ) {
// Newer Version available
if ( isNewer(OpenFlipper::Options::coreVersion(),coreVersion) )
if ( isNewer(OpenFlipper::Options::coreVersion(),coreVersion) ) {
currentBrush.setColor(Qt::red);
else if ( isNewer(coreVersion , OpenFlipper::Options::coreVersion()) )
updatedPlugins_ << "Core";
} else if ( isNewer(coreVersion , OpenFlipper::Options::coreVersion()) )
currentBrush.setColor(Qt::blue);
else
currentBrush.setColor(Qt::green);
......@@ -290,9 +295,11 @@ void OptionsWidget::updateVersionsTable() {
// Newer Version available
if ( isNewer(plugins_[i].version,latestVersion) )
if ( isNewer(plugins_[i].version,latestVersion) ) {
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);
else
currentBrush.setColor(Qt::green);
......@@ -321,6 +328,8 @@ void OptionsWidget::updateVersionsTable() {
updateList->resizeColumnsToContents();
updateButton->setEnabled(!updatedPlugins_.empty());
}
void OptionsWidget::slotApply() {
......@@ -395,7 +404,7 @@ void OptionsWidget::startDownload( QString _url ) {
file = new QFile(fileName);
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;
file = 0;
} else {
......@@ -436,6 +445,65 @@ void OptionsWidget::slotCheckUpdates() {
}
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) {
......@@ -561,7 +629,9 @@ void OptionsWidget::httpRequestFinished(int requestId, bool error)
if ( !error ) {
if ( downloadType == VERSIONS_FILE )
compareVersions();
compareVersions();
if ( downloadType == COMPONENT )
updateComponent();
}
}
......
......@@ -45,86 +45,105 @@
class OptionsWidget : public QWidget, public Ui::OptionsWidget
{
Q_OBJECT
public:
OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyBinding>& _core, QWidget *parent = 0 );
Q_OBJECT
signals:
void applyOptions();
void saveOptions();
public:
OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyBinding>& _core, QWidget *parent = 0 );
private slots:
/// Hide widget, Update Options and tell others about changed Options
void slotApply();
signals:
void applyOptions();
void saveOptions();
/// Only hide widget
void slotCancel();
private slots:
/// Hide widget, Update Options and tell others about changed Options
void slotApply();
/// Checks for updates
void slotCheckUpdates();
/// Only hide widget
void slotCancel();
/// Download updates
void slotGetUpdates();
/// Checks for updates
void slotCheckUpdates();
/// open a dialog to determine the color
void getBackgroundColor();
/// Download updates
void slotGetUpdates();
/// open a dialog to determine the color
void getBackgroundColor();
protected:
void showEvent ( QShowEvent * event );
protected:
void showEvent ( QShowEvent * event );
private:
//key-bindings
std::vector<PluginInfo>& plugins_;
std::vector<KeyBinding>& coreKeys_;
private:
//key-bindings
std::vector<PluginInfo>& plugins_;
std::vector<KeyBinding>& coreKeys_;
// flag indicating if something went wrong and the request has to be aborted
bool httpRequestAborted;
// flag indicating if something went wrong and the request has to be aborted
bool httpRequestAborted;
// Id of the current request
int httpGetId;
// Id of the current request
int httpGetId;
// Request variable
QHttp *http;
// Request variable
QHttp *http;
// File for http downloads
QFile *file;
// File for http downloads
QFile *file;
// ProgressDialog for Downloads
QProgressDialog *progressDialog;
// ProgressDialog for Downloads
QProgressDialog *progressDialog;
// What type of download is currently active
enum DOWNLOAD {
// What type of download is currently active
enum DOWNLOAD {
NONE,
VERSIONS_FILE,
COMPONENT,
WINDOWS_SETUP
} downloadType;
} downloadType;
private:
/// Starts the download of the given file
void startDownload( QString _url );
private:
/// Starts the download of the given file
void startDownload( QString _url );
/// Compares the versions from the downloaded Versions file with the current versions
void compareVersions();
/// Compares the versions from the downloaded Versions file with the current versions
void compareVersions();
/// Compares two version strings and returns if a newer Version is available
bool isNewer(QString _current, QString _latest);
/// Compares two version strings and returns if a newer Version is available
bool isNewer(QString _current, QString _latest);
/// Redraws the version table
void updateVersionsTable();
/// Redraws the version table
void updateVersionsTable();
private slots:
private slots:
// This slot is called when a http request has been finished
void httpRequestFinished(int requestId, bool error);
// This slot is called when a http request has been finished
void httpRequestFinished(int requestId, bool error);
// Parses the response and gives feedback
void readResponseHeader(const QHttpResponseHeader &responseHeader);
// Parses the response and gives feedback
void readResponseHeader(const QHttpResponseHeader &responseHeader);
// Updates the progress Dialog while downloading
void updateDataReadProgress(int bytesRead, int totalBytes);
// Updates the progress Dialog while downloading
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>
<string/>
</property>
<property name="currentIndex" >
<number>2</number>
<number>4</number>
</property>
<property name="usesScrollButtons" >
<bool>true</bool>
......@@ -166,7 +166,7 @@ You can select multiple modes at the same time.</string>
<x>0</x>
<y>0</y>
<width>462</width>
<height>685</height>
<height>677</height>
</rect>
</property>
<attribute name="title" >
......@@ -400,7 +400,7 @@ You can select multiple modes at the same time.</string>
<x>0</x>
<y>0</y>
<width>462</width>
<height>685</height>
<height>677</height>
</rect>
</property>
<attribute name="title" >
......@@ -424,7 +424,7 @@ You can select multiple modes at the same time.</string>
<x>0</x>
<y>0</y>
<width>462</width>
<height>685</height>
<height>677</height>
</rect>
</property>
<attribute name="title" >
......@@ -474,13 +474,24 @@ You can select multiple modes at the same time.</string>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4" >
<layout class="QHBoxLayout" name="horizontalLayout_8" >
<item>
<widget class="QPushButton" name="checkUpdateButton" >
<property name="text" >
<string>Check</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_4" >
<item>
<widget class="QPushButton" name="checkUpdateButton" >
<property name="text" >
<string>Check</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="updateButton" >
<property name="text" >
<string>Update</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<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