name=QHiMDTransfer version=0.0.9 ver-url=http://users.physik.fu-berlin.de/~pneuser/updater.txt download-url=http://users.physik.fu-berlin.de/~glaubitz/linux-minidisc/qhimdtransfer-win.exe download-file-name=qhimdtransfer-win.exe exec-update=qhimdtransfer-win.exe restart-app= --- inet-updater/main.cpp | 10 ++ inet-updater/update.cpp | 192 +++++++++++++++++++++++++++++++++++++ inet-updater/update.h | 37 +++++++ inet-updater/update.ui | 113 ++++++++++++++++++++++ inet-updater/updater.pro | 19 ++++ qhimdtransfer/qhimdmainwindow.cpp | 6 + qhimdtransfer/qhimdmainwindow.h | 1 + qhimdtransfer/qhimdmainwindow.ui | 36 ++++--- 8 files changed, 398 insertions(+), 16 deletions(-) create mode 100644 inet-updater/main.cpp create mode 100644 inet-updater/update.cpp create mode 100644 inet-updater/update.h create mode 100644 inet-updater/update.ui create mode 100644 inet-updater/updater.pro diff --git a/inet-updater/main.cpp b/inet-updater/main.cpp new file mode 100644 index 0000000..d85ef55 --- /dev/null +++ b/inet-updater/main.cpp @@ -0,0 +1,10 @@ +#include <QtGui/QApplication> +#include "update.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Update w; + w.show(); + return a.exec(); +} diff --git a/inet-updater/update.cpp b/inet-updater/update.cpp new file mode 100644 index 0000000..dfd02bd --- /dev/null +++ b/inet-updater/update.cpp @@ -0,0 +1,192 @@ +#include "update.h" +#include "ui_update.h" +#include <QFile> +#include <QMessageBox> +#include <QHttp> +#include <QUrl> +#include <QProcess> + +Update::Update(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::Update) +{ + //ui->pushButton->setEnabled(false); + + ui->setupUi(this); + checkForUpdate(); + +} + + +/* +void checkForUpdate() +Downloads the new Updater-File from the Internet, URL given in the updater.txt and compares the versions. + + */ + +void Update::checkForUpdate(){ + http = new QHttp(); + QString cline; + + //Begin reading the config from updater.txt + QFile fconf(QString("updater.txt")); + if(fconf.open(QIODevice::ReadOnly | QIODevice::Text)){ + while(!fconf.atEnd()){ + cline = fconf.readLine(); + if(cline.left(8)=="ver-url="){ + conf.insert("ver-url",cline.mid(8,cline.length()-9)); + } + if(cline.left(8)=="version="){ + conf.insert("local-version",cline.mid(8,cline.length()-9)); + ui->lblversion->setText(conf["local-version"]); + } + if(cline.left(5)=="name="){ + conf.insert("name",cline.mid(5,cline.length()-6)); + ui->lblname->setText(conf["name"]); + } + if(cline.left(12)=="restart-app="){ + conf.insert("restart-app",cline.mid(12,cline.length()-13)); + } + } + + //End reading config + + + //Starting the download of the possibly updated updater.txt from the internet + down_phase="conf"; + + QObject::connect(http,SIGNAL(dataReadProgress(int,int)),this,SLOT(setProgress(int,int))); + QObject::connect(http,SIGNAL(done(bool)),this,SLOT(downloaded(bool))); + + + if(conf["ver-url"].length() != 0){ + QUrl url(conf["ver-url"]); + http->setHost(url.host()); + + down_fp = new QFile("updater-new.txt"); + if(down_fp->open(QIODevice::WriteOnly)){ + id_phase = http->get(url.path(),down_fp); + }else{ + QMessageBox::warning(this,QString(tr("Version File")),QString(tr("Couldn't open new-conf-file!"))); + } + + + }else{ + QMessageBox::warning(this,QString(tr("Version File")),QString(tr("No Version-File-Url found!"))); + } + + fconf.close(); + }else{ + QMessageBox::warning(this,QString(tr("No Config")),QString(tr("No Config-File found!"))); + } + + //End starting the download an error-handling. +} + +Update::~Update() +{ + delete ui; +} + +void Update::changeEvent(QEvent *e) +{ + QMainWindow::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + +/* + void setProgress(int done, int total) + Sets the download status to the Progressbar, for some visual feedback + */ + +void Update::setProgress(int done, int total){ + ui->progressBar->setMinimum(0); + ui->progressBar->setMaximum(total); + ui->progressBar->setValue(done); +} + + +/* + void downloaded(bool error) + is called, when a download has finished, updater.txt or the update itself. + */ + +void Update::downloaded(bool error){ + if(down_phase=="conf" && !error){ + down_fp->close(); + //start reading the new updater.txt from the internet an compare versions + QString cline; + QFile newconf("updater-new.txt"); + if(newconf.open(QIODevice::ReadOnly | QIODevice::Text)){ + while(!newconf.atEnd()){ + cline = newconf.readLine(); + if(cline.left(13)=="download-url="){ + conf.insert("download-url",cline.mid(13,cline.length()-14)); + } + if(cline.left(8)=="version="){ + conf.insert("remote-version",cline.mid(8,cline.length()-9)); + ui->lblnewversion->setText(conf["remote-version"]); + } + if(cline.left(5)=="name="){ + conf.insert("new-name",cline.mid(5,cline.length()-6)); + } + if(cline.left(19)=="download-file-name="){ + conf.insert("download-file-name",cline.mid(19,cline.length()-20)); + } + if(cline.left(12)=="exec-update="){ + conf.insert("exec-update",cline.mid(12,cline.length()-13)); + } + } + if(conf["local-version"] != conf["remote-version"]){ + ui->pushButton->setEnabled(true); + //QMessageBox::warning(this,"IOError",conf["local-version"]+" "+conf["remote-version"]); + } + else{ + ui->pushButton->setEnabled(false); + QMessageBox::information(this,tr("Update"),tr("Already the newest Version is installed!")); + if(conf["restart-app"].length() != 0) + QProcess::startDetached(conf["restart-app"]); //Only start if value is given + this->close(); + } + } + newconf.close(); + //end progressing new updater.txt + } + //start processing the update, simply downloads and starts it, with the given parameters + if(down_phase=="update" && !error){ + down_fp->close(); + http->close(); + QProcess::startDetached(conf["exec-update"]); + //QMessageBox::warning(this,"IOError",conf["exec-update"]); + down_phase="ready"; + this->close(); + } + //end processing the update + if(error){ + QMessageBox::warning(this,tr("IOError"),tr("URL not found!")); + } +} + +/* + void do_update() + simply a slot for a the "do_update" button + */ + +void Update::do_update(){ + QUrl url(conf["download-url"]); + down_phase="update"; + down_fp = new QFile(conf["download-file-name"]); + http->setHost(url.host()); + if(down_fp->open(QIODevice::WriteOnly)){ + http->get(url.path(),down_fp); + }else{ + QMessageBox::warning(this,tr("IOError"),tr("Couldn't create download-file!")); + } + +} diff --git a/inet-updater/update.h b/inet-updater/update.h new file mode 100644 index 0000000..c70f51c --- /dev/null +++ b/inet-updater/update.h @@ -0,0 +1,37 @@ +#ifndef UPDATE_H +#define UPDATE_H + +#include <QMainWindow> +#include <QMap> +#include <QFile> +#include <QHttp> + +namespace Ui { + class Update; +} + +class Update : public QMainWindow { + Q_OBJECT +public: + Update(QWidget *parent = 0); + ~Update(); + +protected: + void changeEvent(QEvent *e); + +private: + Ui::Update *ui; + QMap<QString,QString> conf; + QMap<QString,QString> cnew; + QString down_phase; + int id_phase; + QHttp* http; + QFile* down_fp; +public slots: + void setProgress(int done, int total); + void downloaded(bool); + void do_update(); + void checkForUpdate(); +}; + +#endif // UPDATE_H diff --git a/inet-updater/update.ui b/inet-updater/update.ui new file mode 100644 index 0000000..c0cc09a --- /dev/null +++ b/inet-updater/update.ui @@ -0,0 +1,113 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Update</class> + <widget class="QMainWindow" name="Update"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>349</width> + <height>151</height> + </rect> + </property> + <property name="windowTitle"> + <string>Update</string> + </property> + <widget class="QWidget" name="centralWidget"> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Name:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="lblname"> + <property name="text"> + <string>TextLabel</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Local-Version:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="lblversion"> + <property name="text"> + <string>TextLabel</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Current-Version:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="lblnewversion"> + <property name="text"> + <string>lblnewversion</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QProgressBar" name="progressBar"> + <property name="value"> + <number>0</number> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton"> + <property name="text"> + <string>Start</string> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QStatusBar" name="statusBar"/> + </widget> + <layoutdefault spacing="6" margin="11"/> + <resources/> + <connections> + <connection> + <sender>pushButton</sender> + <signal>clicked()</signal> + <receiver>Update</receiver> + <slot>do_update()</slot> + <hints> + <hint type="sourcelabel"> + <x>153</x> + <y>114</y> + </hint> + <hint type="destinationlabel"> + <x>147</x> + <y>126</y> + </hint> + </hints> + </connection> + </connections> + <slots> + <slot>do_update()</slot> + </slots> +</ui> diff --git a/inet-updater/updater.pro b/inet-updater/updater.pro new file mode 100644 index 0000000..2c0db33 --- /dev/null +++ b/inet-updater/updater.pro @@ -0,0 +1,19 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2009-12-22T21:34:54 +# +#------------------------------------------------- + +QT += network + +TARGET = qhimd-updater +TEMPLATE = app + + +SOURCES += main.cpp\ + update.cpp + +HEADERS += update.h + +FORMS += update.ui + diff --git a/qhimdtransfer/qhimdmainwindow.cpp b/qhimdtransfer/qhimdmainwindow.cpp index 359c91e..09e3886 100644 --- a/qhimdtransfer/qhimdmainwindow.cpp +++ b/qhimdtransfer/qhimdmainwindow.cpp @@ -4,6 +4,7 @@ #include "qhimduploaddialog.h" #include <QtGui/QMessageBox> #include <QtGui/QApplication> +#include <QProcess> #include <QtCore/QDebug> @@ -533,3 +534,8 @@ void QHiMDMainWindow::on_himd_devices_activated(QString device) { open_himd_at(device); } + +void QHiMDMainWindow::on_actionCheck_for_updates_triggered() +{ + QProcess::startDetached("qhimd-updater"); +} diff --git a/qhimdtransfer/qhimdmainwindow.h b/qhimdtransfer/qhimdmainwindow.h index 694622a..df4e4e9 100644 --- a/qhimdtransfer/qhimdmainwindow.h +++ b/qhimdtransfer/qhimdmainwindow.h @@ -54,6 +54,7 @@ private: void upload_to(const QString & path); private slots: + void on_actionCheck_for_updates_triggered(); void on_action_Connect_triggered(); void on_action_Format_triggered(); void on_action_Upload_triggered(); diff --git a/qhimdtransfer/qhimdmainwindow.ui b/qhimdtransfer/qhimdmainwindow.ui index 149bd77..bf4c4a2 100644 --- a/qhimdtransfer/qhimdmainwindow.ui +++ b/qhimdtransfer/qhimdmainwindow.ui @@ -14,7 +14,7 @@ <string>QHiMDTransfer</string> </property> <property name="windowIcon"> - <iconset resource="icons.qrc"> + <iconset> <normaloff>:/icons/qhimdtransfer_24.png</normaloff>:/icons/qhimdtransfer_24.png</iconset> </property> <widget class="QWidget" name="centralWidget"> @@ -86,7 +86,7 @@ <string/> </property> <property name="icon"> - <iconset resource="icons.qrc"> + <iconset> <normaloff>:/icons/arrow_upload.png</normaloff>:/icons/arrow_upload.png</iconset> </property> <property name="iconSize"> @@ -109,7 +109,7 @@ <string/> </property> <property name="icon"> - <iconset resource="icons.qrc"> + <iconset> <normaloff>:/icons/arrow_download.png</normaloff>:/icons/arrow_download.png</iconset> </property> <property name="iconSize"> @@ -168,7 +168,7 @@ <x>0</x> <y>0</y> <width>784</width> - <height>18</height> + <height>21</height> </rect> </property> <widget class="QMenu" name="menu_Action"> @@ -193,6 +193,7 @@ </property> <addaction name="action_Help"/> <addaction name="action_About"/> + <addaction name="actionCheck_for_updates"/> </widget> <addaction name="menu_Action"/> <addaction name="menu"/> @@ -222,7 +223,7 @@ </widget> <action name="action_Download"> <property name="icon"> - <iconset resource="icons.qrc"> + <iconset> <normaloff>:/icons/download_to_md.png</normaloff>:/icons/download_to_md.png</iconset> </property> <property name="text"> @@ -231,7 +232,7 @@ </action> <action name="action_Upload"> <property name="icon"> - <iconset resource="icons.qrc"> + <iconset> <normaloff>:/icons/upload_from_md.png</normaloff>:/icons/upload_from_md.png</iconset> </property> <property name="text"> @@ -240,7 +241,7 @@ </action> <action name="action_Rename"> <property name="icon"> - <iconset resource="icons.qrc"> + <iconset> <normaloff>:/icons/rename.png</normaloff>:/icons/rename.png</iconset> </property> <property name="text"> @@ -252,7 +253,7 @@ </action> <action name="action_Delete"> <property name="icon"> - <iconset resource="icons.qrc"> + <iconset> <normaloff>:/icons/delete.png</normaloff>:/icons/delete.png</iconset> </property> <property name="text"> @@ -261,7 +262,7 @@ </action> <action name="action_Help"> <property name="icon"> - <iconset resource="icons.qrc"> + <iconset> <normaloff>:/icons/help.png</normaloff>:/icons/help.png</iconset> </property> <property name="text"> @@ -270,7 +271,7 @@ </action> <action name="action_About"> <property name="icon"> - <iconset resource="icons.qrc"> + <iconset> <normaloff>:/icons/info.png</normaloff>:/icons/info.png</iconset> </property> <property name="text"> @@ -279,7 +280,7 @@ </action> <action name="action_Format"> <property name="icon"> - <iconset resource="icons.qrc"> + <iconset> <normaloff>:/icons/format.png</normaloff>:/icons/format.png</iconset> </property> <property name="text"> @@ -291,7 +292,7 @@ </action> <action name="action_Quit"> <property name="icon"> - <iconset resource="icons.qrc"> + <iconset> <normaloff>:/icons/quit.png</normaloff>:/icons/quit.png</iconset> </property> <property name="text"> @@ -300,18 +301,21 @@ </action> <action name="action_Connect"> <property name="icon"> - <iconset resource="icons.qrc"> + <iconset> <normaloff>:/icons/connect.png</normaloff>:/icons/connect.png</iconset> </property> <property name="text"> <string>&Connect</string> </property> </action> + <action name="actionCheck_for_updates"> + <property name="text"> + <string>Check for updates</string> + </property> + </action> </widget> <layoutdefault spacing="6" margin="11"/> - <resources> - <include location="icons.qrc"/> - </resources> + <resources/> <connections/> <slots> <slot>on_trigger_Format()</slot> -- 1.7.0.2.msysgit.0