Browse Source

[COR] Add some Version information

master
Ulrich Van Den Hekke 11 years ago
parent
commit
378890ca7c
  1. 10
      framework/application/mainformimpl.cpp
  2. 194
      framework/application/version.cpp
  3. 67
      framework/application/version.h
  4. 32
      framework/application/version_p.h
  5. 121
      framework/application/versionlabel.cpp
  6. 43
      framework/application/versionlabel.h
  7. 40
      framework/application/versionlabel_p.h

10
framework/application/mainformimpl.cpp

@ -50,6 +50,7 @@
#include <jobs/xinxjobprogressbar.h>
#include <session/sessionmanager.h>
#include <jobs/xinxjobprogressdock.h>
#include <application/versionlabel.h>
// Qt header
#include <QObject>
@ -128,7 +129,7 @@ void MainformImpl::createMainForm()
void MainformImpl::createMenus()
{
QMenu * sessionMenu, *projectMenu, * fileMenu, * editMenu, *searchMenu, *bookmarkMenu, *windowsMenu, *toolsMenu, *helpMenu;
QToolBar * fileToolBar, * editToolBar, * searchToolBar;
QToolBar * fileToolBar, * editToolBar, * searchToolBar, * versionToolBar;
m_menuBar = new QMenuBar(this);
setMenuBar(m_menuBar);
m_menus.insert("session", sessionMenu = new QMenu(tr("Sess&ion"), m_menuBar));
@ -147,10 +148,12 @@ void MainformImpl::createMenus()
m_toolBars.insert("file", fileToolBar = new QToolBar(this));
m_toolBars.insert("edit", editToolBar = new QToolBar(this));
m_toolBars.insert("search", searchToolBar = new QToolBar(this));
m_toolBars.insert("version", versionToolBar = new QToolBar(this));
fileToolBar->setWindowTitle(tr("&File"));
editToolBar->setWindowTitle(tr("&Edit"));
searchToolBar->setWindowTitle(tr("&Search"));
versionToolBar->setWindowTitle(tr("&Version"));
createActions();
@ -243,6 +246,11 @@ void MainformImpl::createMenus()
searchToolBar->setObjectName("searchToolBar");
addToolBar(Qt::TopToolBarArea, searchToolBar);
versionToolBar->addWidget(new VersionLabel(this));
versionToolBar->setOrientation(Qt::Horizontal);
versionToolBar->setObjectName("versionToolBar");
addToolBar(Qt::TopToolBarArea, versionToolBar);
connect(XinxAction::ActionManager::self(), SIGNAL(changed()), this, SLOT(createPluginsActions()));
XinxAction::ActionManager::self()->generateMenu();

194
framework/application/version.cpp

@ -0,0 +1,194 @@
/*
XINX
Copyright (C) 2007-2011 by Ulrich Van Den Hekke
xinx@shadoware.org
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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful.
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "version_p.h"
#include <QStringList>
/* VersionData */
void VersionData::updateFromString(const QString & version, const QLatin1Char & separator)
{
int indice = 1;
QStringList versionNumberStr = version.split(separator);
foreach(const QString & numberStr, versionNumberStr)
{
int number = numberStr.toInt();
switch(indice)
{
case 1:
_major = number;
break;
case 2:
_minor = number;
break;
case 3:
_micro = number;
break;
case 4:
_build = number;
break;
};
indice++;
}
}
/* Version */
Version::Version() : d(new VersionData)
{
}
Version::Version(int major, int minor, int micro, int build) : d(new VersionData)
{
d->_major = major;
d->_minor = minor;
d->_micro = micro;
d->_build = build;
}
Version::Version(const Version& version) : d(version.d)
{
}
Version::Version(const QString& version, const QLatin1Char& separator)
{
d->updateFromString(version, separator);
}
Version::~Version()
{
}
bool Version::isValid() const
{
return Version().operator!=(*this);
}
Version Version::fromString(const QString& version, const QLatin1Char& separator)
{
return Version(version, separator);
}
QString Version::toString(const Version::VersionNumberFlags& flags, const QLatin1Char& separator)
{
QStringList versionStr;
if (flags.testFlag(Version::MAJOR_NUMBER))
{
versionStr << QString::number(d->_major);
}
if (flags.testFlag(Version::MINOR_NUMBER))
{
versionStr << QString::number(d->_minor);
}
if (flags.testFlag(Version::MICRO_NUMBER))
{
versionStr << QString::number(d->_micro);
}
if (flags.testFlag(Version::BUILD_NUMBER))
{
versionStr << QString::number(d->_build);
}
return versionStr.join(QString(separator));
}
Version& Version::operator=(const QString& version)
{
d->updateFromString(version);
return *this;
}
bool Version::operator!=(const Version& version) const
{
return (d->_major != version.d->_major) && (d->_minor != version.d->_minor) && (d->_micro != version.d->_micro) && (d->_build != version.d->_build);
}
bool Version::operator==(const Version& version) const
{
return (d->_major == version.d->_major) && (d->_minor == version.d->_minor) && (d->_micro == version.d->_micro) && (d->_build == version.d->_build);
}
bool Version::operator<(const Version& version) const
{
if (d->_major < version.d->_major)
{
return true;
}
else if (d->_major == version.d->_major)
{
if (d->_minor < version.d->_minor)
{
return true;
}
else if (d->_minor == version.d->_minor)
{
if (d->_micro < version.d->_micro)
{
return true;
}
else if ((d->_micro == version.d->_micro) && (d->_build < version.d->_build))
{
return true;
}
}
}
return false;
}
bool Version::operator<=(const Version& version) const
{
return operator<(version) || operator==(version);
}
bool Version::operator>(const Version& version) const
{
if (d->_major > version.d->_major)
{
return true;
}
else if (d->_major == version.d->_major)
{
if (d->_minor > version.d->_minor)
{
return true;
}
else if (d->_minor == version.d->_minor)
{
if (d->_micro > version.d->_micro)
{
return true;
}
else if ((d->_micro == version.d->_micro) && (d->_build > version.d->_build))
{
return true;
}
}
}
return false;
}
bool Version::operator>=(const Version& version) const
{
return operator>(version) || operator==(version);
}

67
framework/application/version.h

@ -0,0 +1,67 @@
/*
XINX
Copyright (C) 2007-2011 by Ulrich Van Den Hekke
xinx@shadoware.org
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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful.
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef VERSION_H
#define VERSION_H
#include <QString>
#include <QSharedDataPointer>
class VersionData;
class Version
{
public:
enum VersionNumber
{
MAJOR_NUMBER = 0x1,
MINOR_NUMBER = 0x2,
MICRO_NUMBER = 0x4,
BUILD_NUMBER = 0x8,
ALL_NUMBER = 0xF
};
Q_DECLARE_FLAGS(VersionNumberFlags, VersionNumber)
Version();
Version(int major, int minor, int micro, int build);
Version(const Version & version);
Version(const QString & version, const QLatin1Char & separator = QLatin1Char('.'));
~Version();
bool isValid() const;
static Version fromString(const QString & version, const QLatin1Char & separator = QLatin1Char('.'));
QString toString(const VersionNumberFlags & flags = Version::ALL_NUMBER, const QLatin1Char & separator = QLatin1Char('.'));
Version & operator=(const QString & version);
bool operator==(const Version & version) const;
bool operator!=(const Version & version) const;
bool operator<(const Version & version) const;
bool operator<=(const Version & version) const;
bool operator>(const Version & version) const;
bool operator>=(const Version & version) const;
private:
QSharedDataPointer<VersionData> d;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Version::VersionNumberFlags)
#endif // VERSION_H

32
framework/application/version_p.h

@ -0,0 +1,32 @@
/*
XINX
Copyright (C) 2007-2011 by Ulrich Van Den Hekke
xinx@shadoware.org
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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful.
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "version.h"
class VersionData : public QSharedData
{
public:
VersionData() : _major(-1), _minor(-1), _micro(-1), _build(-1) { }
VersionData(const VersionData &other) : QSharedData(other), _major(other._major), _minor(other._minor), _micro(other._micro), _build(other._build) { }
~VersionData() { }
void updateFromString(const QString & version, const QLatin1Char & separator = QLatin1Char('.'));
int _major, _minor, _micro, _build;
};

121
framework/application/versionlabel.cpp

@ -0,0 +1,121 @@
/*
XINX
Copyright (C) 2007-2011 by Ulrich Van Den Hekke
xinx@shadoware.org
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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful.
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "versionlabel_p.h"
#include <QDomDocument>
#include <core/version.h>
/* VersionLabelPrivate */
void VersionLabelPrivate::finished(QNetworkReply * reply)
{
QDomDocument document;
document.setContent(reply);
QDomNodeList homepageList = document.elementsByTagName("homepage");
QDomNodeList stableList = document.elementsByTagName("stable_version");
QDomNodeList unstableList = document.elementsByTagName("unstable_version");
QString stable, unstable;
if (stableList.length())
{
stable = stableList.at(0).toElement().text();
}
if (unstableList.length())
{
unstable = unstableList.at(0).toElement().text();
}
if (homepageList.length())
{
_homepage = homepageList.at(0).toElement().text();
}
_stable = stable;
_unstable = unstable;
updateText();
}
void VersionLabelPrivate::updateText()
{
QStringList versionInfo;
if (_current.isValid())
{
versionInfo << tr("Current Version : %1").arg(_current.toString());
}
if (_stable.isValid())
{
QString stableText = tr("Stable Version : %1").arg(_stable.toString());
versionInfo << stableText;
if (_current < _stable)
{
stableText = tr("!!! New version released !!!") + "\n<br/>" + stableText;
} else if (_current < _unstable)
{
stableText = tr("!!! New snapshot released !!!") + "\n<br/>" + stableText;
}
_label->setText(QString("<a href=\"%1\">%2</a>").arg(_homepage).arg(stableText));
}
if (_unstable.isValid())
{
versionInfo << tr("Unstable Version : %1").arg(_unstable.toString());
}
_label->setToolTip(versionInfo.join("\n"));
}
/* VersionLabel */
VersionLabel::VersionLabel(QWidget* parent, Qt::WindowFlags f): QLabel(parent, f), d(new VersionLabelPrivate)
{
setOpenExternalLinks(true);
d->_label = this;
d->_current = VERSION;
d->_manager = new QNetworkAccessManager(d.data());
connect(d->_manager, SIGNAL(finished(QNetworkReply*)), d.data(), SLOT(finished(QNetworkReply*)));
QNetworkRequest request(QUrl("http://xinx.shadoware.org/files/release.xml"));
d->_manager->get(request);
d->updateText();
}
VersionLabel::~VersionLabel()
{
}
const Version& VersionLabel::currentVersion() const
{
return d->_current;
}
const Version& VersionLabel::stableVersion() const
{
return d->_stable;
}
const Version& VersionLabel::unstableVersion() const
{
return d->_unstable;
}

43
framework/application/versionlabel.h

@ -0,0 +1,43 @@
/*
XINX
Copyright (C) 2007-2011 by Ulrich Van Den Hekke
xinx@shadoware.org
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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful.
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef VERSIONLABEL_H
#define VERSIONLABEL_H
#include <QLabel>
#include <application/version.h>
class VersionLabelPrivate;
class VersionLabel : public QLabel
{
Q_OBJECT
public:
VersionLabel(QWidget* parent = 0, Qt::WindowFlags f = 0);
virtual ~VersionLabel();
const Version & currentVersion() const;
const Version & stableVersion() const;
const Version & unstableVersion() const;
private:
QScopedPointer<VersionLabelPrivate> d;
};
#endif // VERSIONLABEL_H

40
framework/application/versionlabel_p.h

@ -0,0 +1,40 @@
/*
XINX
Copyright (C) 2007-2011 by Ulrich Van Den Hekke
xinx@shadoware.org
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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful.
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef VERSIONLABEL_P_H
#define VERSIONLABEL_P_H
#include "versionlabel.h"
#include <QNetworkReply>
class VersionLabelPrivate : public QObject
{
Q_OBJECT
public:
VersionLabel * _label;
QString _homepage;
Version _current, _stable, _unstable;
QNetworkAccessManager * _manager;
void updateText();
public slots:
void finished(QNetworkReply * reply);
};
#endif // VERSIONLABEL_P_H
Loading…
Cancel
Save