Skip to content

Commit

Permalink
main infrastructure + sample
Browse files Browse the repository at this point in the history
  • Loading branch information
pypt committed May 31, 2012
1 parent 1c69bec commit 288acc5
Show file tree
Hide file tree
Showing 14 changed files with 349 additions and 47 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ fvupdateconfig.h

# Qt
*.pro.user
*.qm
Sample-build-*
31 changes: 31 additions & 0 deletions Fervor.pri
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
QT += core gui webkit

DEFINES += FV_APP_NAME=\\\"$$TARGET\\\"
DEFINES += FV_APP_VERSION=\\\"$$VERSION\\\"

# FIXME unit tests
DEFINES += FV_DEBUG=1
DEPENDPATH += "$$PWD/tests/"
INCLUDEPATH += "$$PWD/tests/"
CONFIG += qtestlib



DEPENDPATH += "$$PWD"
INCLUDEPATH += "$$PWD"

SOURCES += fvupdatewindow.cpp \
fvupdater.cpp \
fvversioncomparator.cpp \
tests/fvversioncomparatortest.cpp

HEADERS += fvupdatewindow.h \
fvupdateconfig.h \
fvupdater.h \
fvversioncomparator.h \
tests/fvversioncomparatortest.h

FORMS += fvupdatewindow.ui

TRANSLATIONS += fervor_lt.ts
CODECFORTR = UTF-8
24 changes: 0 additions & 24 deletions Fervor.pro

This file was deleted.

50 changes: 50 additions & 0 deletions fervor_lt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="lt_LT">
<defaultcodec>UTF-8</defaultcodec>
<context>
<name>FvUpdateWindow</name>
<message>
<location filename="fvupdatewindow.ui" line="14"/>
<source>Software Update</source>
<translation>Programos atnaujinimas</translation>
</message>
<message>
<location filename="fvupdatewindow.ui" line="53"/>
<source>A new version of %1 is available!</source>
<oldsource>A new version of %s is available!</oldsource>
<translation>Išleista nauja programos „%1“ versija!</translation>
</message>
<message>
<location filename="fvupdatewindow.ui" line="60"/>
<source>%1 %2 is now available - you have %3. Would you like to download it now?</source>
<oldsource>%s %s is now available - you have %s. Would you like to download it now?</oldsource>
<translation>Išleista programos „%1“ versija %2 - Jūs naudojate %3. Ar norėtumėte atnaujinti? </translation>
</message>
<message>
<location filename="fvupdatewindow.ui" line="73"/>
<source>Release Notes:</source>
<translation>Naujojo leidimo pastabos:</translation>
</message>
<message>
<location filename="fvupdatewindow.ui" line="80"/>
<source>about:blank</source>
<translation>about:blank</translation>
</message>
<message>
<location filename="fvupdatewindow.ui" line="93"/>
<source>Skip This Version</source>
<translation>Praleisti šią versiją</translation>
</message>
<message>
<location filename="fvupdatewindow.ui" line="102"/>
<source>Remind Me Later</source>
<translation>Priminti vėliau</translation>
</message>
<message>
<location filename="fvupdatewindow.ui" line="109"/>
<source>Install Update</source>
<translation>Įdiegti atnaujinimą</translation>
</message>
</context>
</TS>
74 changes: 74 additions & 0 deletions fvupdater.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "fvupdater.h"
#include "fvupdatewindow.h"

#ifdef FV_DEBUG
// Unit tests
#include "fvversioncomparatortest.h"
#endif


FvUpdater* FvUpdater::m_Instance = 0;


FvUpdater* FvUpdater::sharedUpdater()
{
static QMutex mutex;
if (! m_Instance) {
mutex.lock();

if (! m_Instance) {
m_Instance = new FvUpdater;
}

mutex.unlock();
}

return m_Instance;
}

void FvUpdater::drop()
{
static QMutex mutex;
mutex.lock();
delete m_Instance;
m_Instance = 0;
mutex.unlock();
}

FvUpdater::FvUpdater() : QObject(0)
{
m_updaterWindow = 0;

#ifdef FV_DEBUG
// Unit tests
FvVersionComparatorTest* test = new FvVersionComparatorTest();
test->runAll();
delete test;
#endif

}

FvUpdater::~FvUpdater()
{
destroyUpdaterWindow();
}

void FvUpdater::destroyUpdaterWindow()
{
if (m_updaterWindow) {
m_updaterWindow->hide();
delete m_updaterWindow;
m_updaterWindow = 0;
}
}


bool FvUpdater::CheckForUpdates(bool notifyAboutUpToDateApplication)
{
destroyUpdaterWindow();

m_updaterWindow = new FvUpdateWindow();
m_updaterWindow->show();

return true;
}
48 changes: 48 additions & 0 deletions fvupdater.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef FVUPDATER_H
#define FVUPDATER_H

#include <QObject>
#include <QMutex>
class FvUpdateWindow;


class FvUpdater : public QObject
{
Q_OBJECT

public:

// Singleton
static FvUpdater* sharedUpdater();
static void drop();

public slots:

// Check for updates
bool CheckForUpdates(bool notifyAboutUpToDateApplication = false);

private:

// Hide main constructor
FvUpdater();
~FvUpdater();

// Hide copy constructor
FvUpdater(const FvUpdater&);

// Hide assign op
// we leave just the declarations, so the compiler will warn us
// if we try to use those two functions by accident
FvUpdater& operator=(const FvUpdater&);

// Singleton instance
static FvUpdater* m_Instance;

// Updater window
FvUpdateWindow* m_updaterWindow;

void destroyUpdaterWindow();

};

#endif // FVUPDATER_H
56 changes: 53 additions & 3 deletions fvupdatewindow.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,66 @@
#include "fvupdatewindow.h"
#include "ui_fvupdatewindow.h"
#include "fvupdateconfig.h"
#include <QTranslator>
#include <QTextCodec>
#include <QApplication>
#include <QLibraryInfo>
#include <QDebug>
#include <QIcon>
#include <QGraphicsScene>


#ifndef FV_APP_NAME
# error "FV_APP_NAME is undefined (must have been defined by Fervor.pri)"
#endif
#ifndef FV_APP_VERSION
# error "FV_APP_VERSION is undefined (must have been defined by Fervor.pri)"
#endif


FvUpdateWindow::FvUpdateWindow(QWidget *parent) :
QWidget(parent),
ui(new Ui::FvUpdateWindow)
m_ui(new Ui::FvUpdateWindow)
{
ui->setupUi(this);
m_ui->setupUi(this);

// Initialize translation
installTranslator();

// Set application name / version is not set yet
if (QApplication::applicationName().isEmpty()) {
QString appName = QString::fromUtf8(FV_APP_NAME);
qWarning() << "QApplication::applicationName is not set, setting it to '" << appName << "'";
QApplication::setApplicationName(appName);
}
if (QApplication::applicationVersion().isEmpty()) {
QString appVersion = QString::fromUtf8(FV_APP_VERSION);
qWarning() << "QApplication::applicationVersion is not set, setting it to '" << appVersion << "'";
QApplication::setApplicationVersion(appVersion);
}

// Set application icon
QIcon appIcon = QApplication::windowIcon();
QGraphicsScene appIconScene;
appIconScene.addPixmap(appIcon.pixmap(m_ui->appIconGraphicsView->size()));

QString newVersString = m_ui->newVersionIsAvailableLabel->text().arg(QApplication::applicationName());
m_ui->newVersionIsAvailableLabel->setText(newVersString);

QString downloadString = m_ui->wouldYouLikeToDownloadLabel->text().arg(QApplication::applicationName(), "newvers", QApplication::applicationVersion());
m_ui->wouldYouLikeToDownloadLabel->setText(downloadString);
}

FvUpdateWindow::~FvUpdateWindow()
{
delete ui;
delete m_ui;
}

void FvUpdateWindow::installTranslator()
{
QTranslator translator;
QString locale = QLocale::system().name();
translator.load(QString("fervor_") + locale);
QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));
qApp->installTranslator(&translator);
}
7 changes: 5 additions & 2 deletions fvupdatewindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ class FvUpdateWindow : public QWidget
public:
explicit FvUpdateWindow(QWidget *parent = 0);
~FvUpdateWindow();

private:
Ui::FvUpdateWindow *ui;
Ui::FvUpdateWindow* m_ui;

// Helpers
void installTranslator();
};

#endif // FVUPDATEWINDOW_H
18 changes: 9 additions & 9 deletions fvupdatewindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QGraphicsView" name="graphicsView">
<widget class="QGraphicsView" name="appIconGraphicsView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand All @@ -42,22 +42,22 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<widget class="QLabel" name="newVersionIsAvailableLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>A new version of %s is available!</string>
<string>A new version of %1 is available!</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="wouldYouLikeToDownloadLabel">
<property name="text">
<string>%s %s is now available - you have %s. Would you like to download it now?</string>
<string>%1 %2 is now available - you have %3. Would you like to download it now?</string>
</property>
</widget>
</item>
Expand All @@ -74,7 +74,7 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QWebView" name="webView">
<widget class="QWebView" name="releaseNotesWebView">
<property name="url">
<url>
<string>about:blank</string>
Expand All @@ -88,7 +88,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="skipThisVersionButton">
<property name="text">
<string>Skip This Version</string>
</property>
Expand All @@ -97,14 +97,14 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QPushButton" name="pushButton_2">
<widget class="QPushButton" name="remindMeLaterButton">
<property name="text">
<string>Remind Me Later</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_3">
<widget class="QPushButton" name="installUpdateButton">
<property name="text">
<string>Install Update</string>
</property>
Expand Down
Loading

0 comments on commit 288acc5

Please sign in to comment.