diff --git a/framework/application/mainformimpl.cpp b/framework/application/mainformimpl.cpp index bacf2894..7e32b77a 100644 --- a/framework/application/mainformimpl.cpp +++ b/framework/application/mainformimpl.cpp @@ -50,6 +50,7 @@ #include #include #include +#include // Qt header #include @@ -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(); diff --git a/framework/application/version.cpp b/framework/application/version.cpp new file mode 100644 index 00000000..bcf6180f --- /dev/null +++ b/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 . +*/ + +#include "version_p.h" +#include + +/* 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); +} + diff --git a/framework/application/version.h b/framework/application/version.h new file mode 100644 index 00000000..7774a4a5 --- /dev/null +++ b/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 . +*/ + +#ifndef VERSION_H +#define VERSION_H + +#include +#include + +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 d; +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(Version::VersionNumberFlags) + +#endif // VERSION_H diff --git a/framework/application/version_p.h b/framework/application/version_p.h new file mode 100644 index 00000000..f74d5796 --- /dev/null +++ b/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 . +*/ + +#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; +}; \ No newline at end of file diff --git a/framework/application/versionlabel.cpp b/framework/application/versionlabel.cpp new file mode 100644 index 00000000..6a84038f --- /dev/null +++ b/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 . +*/ + +#include "versionlabel_p.h" +#include +#include + +/* 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
" + stableText; + } else if (_current < _unstable) + { + stableText = tr("!!! New snapshot released !!!") + "\n
" + stableText; + } + + _label->setText(QString("%2").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; +} diff --git a/framework/application/versionlabel.h b/framework/application/versionlabel.h new file mode 100644 index 00000000..334d5948 --- /dev/null +++ b/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 . +*/ + +#ifndef VERSIONLABEL_H +#define VERSIONLABEL_H + +#include +#include + +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 d; +}; + +#endif // VERSIONLABEL_H diff --git a/framework/application/versionlabel_p.h b/framework/application/versionlabel_p.h new file mode 100644 index 00000000..ef48df3e --- /dev/null +++ b/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 . +*/ + +#ifndef VERSIONLABEL_P_H +#define VERSIONLABEL_P_H + +#include "versionlabel.h" +#include + +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