1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
/***************************************************************************
* *
* This file is part of the Fotowall project, *
* http://www.enricoros.com/opensource/fotowall *
* *
* Copyright (C) 2009 by Enrico Ros <enrico.ros@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "VersionCheckDialog.h"
#include <QCoreApplication>
#include <QDesktopServices>
#include <QPushButton>
#include <QUrl>
#include "ui_VersionCheckDialog.h"
VersionCheckDialog::VersionCheckDialog(QWidget * parent)
: QDialog(parent)
, ui(new Ui::VersionCheckDialog)
, m_connector(0)
{
// inject ui
ui->setupUi(this);
ui->currVersion->setText(QCoreApplication::applicationVersion());
ui->nextVersion->setText(tr("checking"));
// start the network request
m_connector = new MetaXml::Connector();
connect(m_connector, SIGNAL(fetched()), this, SLOT(slotFetched()));
connect(m_connector, SIGNAL(fetchError(const QString &)), this, SLOT(slotError(const QString &)));
}
VersionCheckDialog::~VersionCheckDialog()
{
delete m_connector;
delete ui;
}
void VersionCheckDialog::slotFetched()
{
// parse the xml for the data
const MetaXml::Reader_1 * reader = m_connector->reader();
if (!reader || reader->releases.isEmpty()) {
slotError(tr("XML Error"));
return;
}
ui->progressBar->hide();
// show version
m_release = reader->releases.first();
ui->nextVersion->setText(tr("%1 (%2)").arg(m_release.version).arg(m_release.name));
// show download button
if (m_release.version.compare(QCoreApplication::applicationVersion(), Qt::CaseInsensitive)) {
QPushButton * dlButton = ui->buttonBox->addButton(tr("Download"), QDialogButtonBox::NoRole);
connect(dlButton, SIGNAL(clicked()), this, SLOT(slotDownload()));
}
}
void VersionCheckDialog::slotError(const QString & error)
{
ui->progressBar->hide();
ui->nextVersion->setText(error);
}
void VersionCheckDialog::slotDownload()
{
QDesktopServices::openUrl(QUrl(m_release.url));
}
|