Added Help->Check for Updates

This commit is contained in:
Mark Watkins 2011-09-06 17:33:34 +10:00
parent dfdba127c9
commit afbcee1a89
5 changed files with 47 additions and 3 deletions

View File

@ -1880,7 +1880,7 @@ void gGraphView::keyPressEvent(QKeyEvent * event)
if (event->modifiers() & Qt::ControlModifier) zoom*=1.5; if (event->modifiers() & Qt::ControlModifier) zoom*=1.5;
g->ZoomX(zoom,0); // Zoom out g->ZoomX(zoom,0); // Zoom out
} }
qDebug() << "Keypress??"; //qDebug() << "Keypress??";
} }
void gGraphView::setDay(Day * day) void gGraphView::setDay(Day * day)
{ {

View File

@ -4,7 +4,7 @@
# #
#------------------------------------------------- #-------------------------------------------------
QT += core gui webkit opengl xml QT += core gui webkit opengl network xml
CONFIG += rtti CONFIG += rtti

View File

@ -10,6 +10,8 @@
#include <QResource> #include <QResource>
#include <QProgressBar> #include <QProgressBar>
#include <QWebHistory> #include <QWebHistory>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QTimer> #include <QTimer>
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
@ -137,6 +139,8 @@ MainWindow::MainWindow(QWidget *parent) :
ui->tabWidget->setCurrentWidget(ui->welcome); ui->tabWidget->setCurrentWidget(ui->welcome);
netmanager = new QNetworkAccessManager(this);
connect(netmanager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
} }
extern MainWindow *mainwin; extern MainWindow *mainwin;
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -397,3 +401,32 @@ void MainWindow::on_actionEnable_Multithreading_toggled(bool checked)
{ {
pref["EnableMultithreading"]=checked; pref["EnableMultithreading"]=checked;
} }
void MainWindow::on_actionCheck_for_Updates_triggered()
{
netmanager->get(QNetworkRequest(QUrl("http://sleepyhead.sourceforge.net/current_version.txt")));
}
void MainWindow::replyFinished(QNetworkReply * reply)
{
if (reply->error()==QNetworkReply::NoError) {
// Wrap this crap in XML/JSON so can do other stuff.
if (reply->size()>20) {
qDebug() << "Doesn't look like a version file... :(";
} else {
// check in size
QByteArray data=reply->readAll();
QString a=data;
a=a.trimmed();
if (a>pref["VersionString"].toString()) {
if (QMessageBox::question(this,"New Version","A newer version of SleepyHead is available, v"+a+".\nWould you like to update?",QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes) {
QMessageBox::information(this,"Laziness Warning","I'd love to do it for you automatically, but it's not implemented yet.. :)",QMessageBox::Ok);
}
} else {
QMessageBox::information(this,"SleepyHead v"+a,"Your already up to date!",QMessageBox::Ok);
}
}
} else {
qDebug() << "Network Error:" << reply->errorString();
}
reply->deleteLater();
}

View File

@ -9,7 +9,8 @@
#include <QMainWindow> #include <QMainWindow>
#include <QGLContext> #include <QGLContext>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include "daily.h" #include "daily.h"
#include "overview.h" #include "overview.h"
#include "oximetry.h" #include "oximetry.h"
@ -82,6 +83,9 @@ private slots:
void on_actionEnable_Multithreading_toggled(bool arg1); void on_actionEnable_Multithreading_toggled(bool arg1);
void on_actionCheck_for_Updates_triggered();
void replyFinished(QNetworkReply*);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
Daily * daily; Daily * daily;
@ -89,6 +93,7 @@ private:
Oximetry * oximetry; Oximetry * oximetry;
bool first_load; bool first_load;
Profile *profile; Profile *profile;
QNetworkAccessManager *netmanager;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -605,6 +605,7 @@
<string>&amp;Help</string> <string>&amp;Help</string>
</property> </property>
<addaction name="actionDebug"/> <addaction name="actionDebug"/>
<addaction name="actionCheck_for_Updates"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="action_About"/> <addaction name="action_About"/>
</widget> </widget>
@ -746,6 +747,11 @@
</string> </string>
</property> </property>
</action> </action>
<action name="actionCheck_for_Updates">
<property name="text">
<string>Check for &amp;Updates</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>