1 /***************************************************************************
2 * copyright : (C) 2003-2017 by Pascal Brachet *
3 * http://www.xm1math.net/texmaker/ *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 ***************************************************************************/
11
12 #include "versiondialog.h"
13
14 #include <QtCore/QUrl>
15 #include <QDesktopServices>
16 #define STRINGIFY_INTERNAL(x) #x
17 #define STRINGIFY(x) STRINGIFY_INTERNAL(x)
18
19 #define VERSION_STR STRINGIFY(TEXMAKERVERSION)
20
VersionDialog(QWidget * parent)21 VersionDialog::VersionDialog(QWidget *parent)
22 :QDialog( parent)
23 {
24 ui.setupUi(this);
25 timer.setSingleShot(true);
26 connect(&timer, SIGNAL(timeout()), this, SLOT(stopChecker()));
27 ui.lineEditCurrent->setText(QLatin1String(VERSION_STR));
28 ui.lineEditAvailable->setText(QString::fromUtf8("?.?.?"));
29 connect(ui.pushButtonDownload, SIGNAL( clicked() ), this, SLOT( gotoDownloadPage() ) );
30 connect(ui.pushButtonCheck, SIGNAL( clicked() ), this, SLOT( launchChecker() ) );
31 }
32
~VersionDialog()33 VersionDialog::~VersionDialog(){
34 }
35
gotoDownloadPage()36 void VersionDialog::gotoDownloadPage()
37 {
38 QDesktopServices::openUrl(QUrl("http://www.xm1math.net/texmaker/download.html"));
39 }
40
launchChecker()41 void VersionDialog::launchChecker()
42 {
43 ui.pushButtonCheck->setEnabled(false);
44 timer.start(10000);
45 reply = manager.get ( QNetworkRequest(QUrl("http://www.xm1math.net/texmaker/version.txt")) );
46 QObject::connect (reply, SIGNAL (finished()),this, SLOT(showResultChecker()));
47 }
48
showResultChecker()49 void VersionDialog::showResultChecker()
50 {
51 timer.stop();
52 if (reply->error()) ui.lineEditAvailable->setText(tr("Error"));
53 else ui.lineEditAvailable->setText(QString(reply->readAll()));
54 ui.pushButtonCheck->setEnabled(true);
55 }
56
stopChecker()57 void VersionDialog::stopChecker()
58 {
59 ui.lineEditAvailable->setText(tr("Error"));
60 QObject::disconnect (reply, SIGNAL (finished()),this, SLOT(showResultChecker()));
61 reply->abort();
62 ui.pushButtonCheck->setEnabled(true);
63 }
64