Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Dec 21, 2012
0 parents commit 46fe87d
Show file tree
Hide file tree
Showing 31 changed files with 1,688 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Mac OS X
.DS_Store

# C++
*.o
*.a
*.dylib

# Qt
*.prl
Makefile
Makefile.*
moc_*
15 changes: 15 additions & 0 deletions include/QtxUpdate
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef QTXUPDATE_MODULE_H
#define QTXUPDATE_MODULE_H

#include "../src/update/abstractupdatechecker.h"
#include "../src/update/abstractupdatefilter.h"
#include "../src/update/abstractversioncomparator.h"
#include "../src/update/appcastsysupdatefilter.h"
#include "../src/update/appcastupdatechecker.h"
#include "../src/update/semversortupdatefilter.h"
#include "../src/update/semverversioncomparator.h"
#include "../src/update/update.h"
#include "../src/update/updatedialog.h"
#include "../src/update/updateresolver.h"

#endif
3 changes: 3 additions & 0 deletions qtxupdate.pri
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include(src/update/update.pri)

INCLUDEPATH += $$PWD/include
21 changes: 21 additions & 0 deletions src/update/abstractupdatechecker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "abstractupdatechecker.h"


AbstractUpdateChecker::AbstractUpdateChecker(QObject *parent /* = 0 */)
: QObject(parent)
{
}

AbstractUpdateChecker::~AbstractUpdateChecker()
{
}

QString AbstractUpdateChecker::errorString() const
{
return mErrorString;
}

void AbstractUpdateChecker::setErrorString(const QString & str)
{
mErrorString = str;
}
34 changes: 34 additions & 0 deletions src/update/abstractupdatechecker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef ABSTRACTUPDATECHECKER_H
#define ABSTRACTUPDATECHECKER_H

#include <QtCore>


class Update;

class AbstractUpdateChecker : public QObject
{
Q_OBJECT

public:
AbstractUpdateChecker(QObject *parent = 0);
virtual ~AbstractUpdateChecker();

virtual void check() = 0;

virtual QList<Update *> updates() = 0;

QString errorString() const;

signals:
void finished();
void error(qint32 code);

protected:
void setErrorString(const QString & str);

private:
QString mErrorString;
};

#endif // ABSTRACTUPDATECHECKER_H
11 changes: 11 additions & 0 deletions src/update/abstractupdatefilter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "abstractupdatefilter.h"


AbstractUpdateFilter::AbstractUpdateFilter(QObject *parent /* = 0 */)
: QObject(parent)
{
}

AbstractUpdateFilter::~AbstractUpdateFilter()
{
}
20 changes: 20 additions & 0 deletions src/update/abstractupdatefilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef ABSTRACTUPDATEFILTER_H
#define ABSTRACTUPDATEFILTER_H

#include <QtCore>


class Update;

class AbstractUpdateFilter : public QObject
{
Q_OBJECT

public:
AbstractUpdateFilter(QObject *parent = 0);
virtual ~AbstractUpdateFilter();

virtual QList<Update *> filter(const QList<Update *> candidates) = 0;
};

#endif // ABSTRACTUPDATEFILTER_H
11 changes: 11 additions & 0 deletions src/update/abstractversioncomparator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "abstractversioncomparator.h"


AbstractVersionComparator::AbstractVersionComparator(QObject *parent /* = 0 */)
: QObject(parent)
{
}

AbstractVersionComparator::~AbstractVersionComparator()
{
}
18 changes: 18 additions & 0 deletions src/update/abstractversioncomparator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef ABSTRACTVERSIONCOMPARATOR_H
#define ABSTRACTVERSIONCOMPARATOR_H

#include <QtCore>


class AbstractVersionComparator : public QObject
{
Q_OBJECT

public:
AbstractVersionComparator(QObject *parent = 0);
virtual ~AbstractVersionComparator();

virtual int compare(const QString & lhs, const QString & rhs) = 0;
};

#endif // ABSTRACTVERSIONCOMPARATOR_H
74 changes: 74 additions & 0 deletions src/update/appcastenclosure.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "appcastenclosure.h"
#include "appcastitem.h"


const char AppcastEnclosure::kXmlElementName[] = "enclosure";
const char AppcastEnclosure::kVersionXmlElementName[] = "version";
const char AppcastEnclosure::kUrlXmlElementName[] = "url";
const char AppcastEnclosure::kTypeXmlElementName[] = "type";

AppcastEnclosure::AppcastEnclosure(QObject *parent /* = 0 */)
: QObject(parent),
mDepth(0)
{
}

AppcastEnclosure::~AppcastEnclosure()
{
}

QString AppcastEnclosure::version() const
{
return mVersion;
}

QUrl AppcastEnclosure::url() const
{
return mUrl;
}

QString AppcastEnclosure::mimeType() const
{
return mMimeType;
}

IXmlDeserializer* AppcastEnclosure::deserializeXmlStartElement(XmlReader* reader, const QStringRef & namespaceUri, const QStringRef & name, const QXmlStreamAttributes & attributes)
{
Q_UNUSED(reader)
Q_UNUSED(namespaceUri)
Q_UNUSED(name)
Q_UNUSED(attributes)

mDepth++;
return this;
}

void AppcastEnclosure::deserializeXmlEndElement(XmlReader* reader, const QStringRef & namespaceUri, const QStringRef & name)
{
Q_UNUSED(reader)
Q_UNUSED(namespaceUri)
Q_UNUSED(name)

if (!mDepth) {
emit parsed();
return;
}

mDepth--;
}

void AppcastEnclosure::deserializeXmlAttributes(XmlReader* reader, const QXmlStreamAttributes & attributes)
{
Q_UNUSED(reader)
Q_UNUSED(attributes)

mVersion = attributes.value(AppcastItem::kSparkleXmlNamespace, kVersionXmlElementName).toString();
mUrl = QUrl(attributes.value("", kUrlXmlElementName).toString());
mMimeType = attributes.value("", kTypeXmlElementName).toString();
}

void AppcastEnclosure::deserializeXmlCharacters(XmlReader* reader, const QStringRef & text)
{
Q_UNUSED(reader)
Q_UNUSED(text)
}
45 changes: 45 additions & 0 deletions src/update/appcastenclosure.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef APPCASTENCLOSURE_H
#define APPCASTENCLOSURE_H

#include <QtCore>
#include "../../../src/xml/xml.h"


class AppcastEnclosure : public QObject,
public IXmlDeserializer
{
Q_OBJECT

public:
AppcastEnclosure(QObject *parent = 0);
virtual ~AppcastEnclosure();

QString version() const;
QUrl url() const;
QString mimeType() const;

signals:
void parsed();

private:
IXmlDeserializer* deserializeXmlStartElement(XmlReader* reader, const QStringRef & namespaceUri, const QStringRef & name, const QXmlStreamAttributes & attributes);
void deserializeXmlEndElement(XmlReader* reader, const QStringRef & namespaceUri, const QStringRef & name);
void deserializeXmlAttributes(XmlReader* reader, const QXmlStreamAttributes & attributes);
void deserializeXmlCharacters(XmlReader* reader, const QStringRef & text);

private:
QString mVersion;
QUrl mUrl;
QString mMimeType;

quint32 mDepth;

public:
static const char kXmlElementName[];
private:
static const char kVersionXmlElementName[];
static const char kUrlXmlElementName[];
static const char kTypeXmlElementName[];
};

#endif // APPCASTENCLOSURE_H
119 changes: 119 additions & 0 deletions src/update/appcastitem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#include "appcastitem.h"
#include "appcastenclosure.h"


const char AppcastItem::kSparkleXmlNamespace[] = "http://www.andymatuschak.org/xml-namespaces/sparkle";
const char AppcastItem::kXmlElementName[] = "item";
const char AppcastItem::kTitleXmlElementName[] = "title";
const char AppcastItem::kLinkXmlElementName[] = "link";
const char AppcastItem::kMinimumSystemVersionXmlElementName[] = "minimumSystemVersion";

AppcastItem::AppcastItem(QObject *parent /* = 0 */)
: QObject(parent),
mParsingEnclosure(0),
mDepth(0)
{
}

AppcastItem::~AppcastItem()
{
}

QString AppcastItem::title() const
{
return mTitle;
}

QString AppcastItem::version() const
{
return mVersion;
}

QUrl AppcastItem::linkUrl() const
{
return mLinkUrl;
}

const AppcastEnclosure *AppcastItem::enclosure() const
{
if (mEnclosures.isEmpty()) {
return 0;
}

return mEnclosures.at(0);
}

QString AppcastItem::minSystemVersion() const
{
return mMinSystemVersion;
}

void AppcastItem::onEnclosureParsed()
{
mParsingEnclosure->disconnect(this);

mEnclosures.append(mParsingEnclosure);
if (mEnclosures.size() == 1) {
// Sparkle's RSS extension is rather poorly specified. The version is
// logically associated with the item, but is indicated as an attribute
// of the enclosure (of which there can be many, in the case of
// per-platform enclosures). The version of the first enclosure will be
// treated as the item's version. For consistency, it is recommended
// that any item containing multiple enclosures indicates an identical
// version for each.
mVersion = mParsingEnclosure->version();
}

mParsingEnclosure = 0;
}

IXmlDeserializer* AppcastItem::deserializeXmlStartElement(XmlReader* reader, const QStringRef & namespaceUri, const QStringRef & name, const QXmlStreamAttributes & attributes)
{
Q_UNUSED(reader)
Q_UNUSED(namespaceUri)
Q_UNUSED(name)
Q_UNUSED(attributes)

if (AppcastEnclosure::kXmlElementName == name) {
mParsingEnclosure = new AppcastEnclosure(this);
connect(mParsingEnclosure, SIGNAL(parsed()), SLOT(onEnclosureParsed()));
return mParsingEnclosure;
}

mDepth++;
return this;
}

void AppcastItem::deserializeXmlEndElement(XmlReader* reader, const QStringRef & namespaceUri, const QStringRef & name)
{
Q_UNUSED(reader)

if (!mDepth) {
emit parsed();
return;
}

if (kTitleXmlElementName == name) {
mTitle = mCharacters.trimmed();
} else if (kLinkXmlElementName == name) {
mLinkUrl = QUrl(mCharacters.trimmed());
} else if (namespaceUri == kSparkleXmlNamespace && kMinimumSystemVersionXmlElementName == name) {
mMinSystemVersion = mCharacters.trimmed();
}

mDepth--;
mCharacters.clear();
}

void AppcastItem::deserializeXmlAttributes(XmlReader* reader, const QXmlStreamAttributes & attributes)
{
Q_UNUSED(reader)
Q_UNUSED(attributes)
}

void AppcastItem::deserializeXmlCharacters(XmlReader* reader, const QStringRef & text)
{
Q_UNUSED(reader)

mCharacters.append(text);
}
Loading

0 comments on commit 46fe87d

Please sign in to comment.