summaryrefslogtreecommitdiffstats
path: root/examples/testapp
diff options
context:
space:
mode:
authorkh1 <qt-info@nokia.com>2011-06-01 14:02:59 +0200
committerkh1 <qt-info@nokia.com>2011-06-01 14:02:59 +0200
commit3023e6c7bb5e5da19f769daeea56e988590f2214 (patch)
treed2cb431513d7981740424ffa6e82e16507543145 /examples/testapp
parentfeba978e1a5f07b295ea4c3aefc650d1b1f920c8 (diff)
Cleanup. Style changes. Adjust to new fetch updates code.
Diffstat (limited to 'examples/testapp')
-rw-r--r--examples/testapp/updateagent.cpp105
-rw-r--r--examples/testapp/updateagent.h8
2 files changed, 49 insertions, 64 deletions
diff --git a/examples/testapp/updateagent.cpp b/examples/testapp/updateagent.cpp
index 52d299785..7f0e860fe 100644
--- a/examples/testapp/updateagent.cpp
+++ b/examples/testapp/updateagent.cpp
@@ -32,19 +32,18 @@
**************************************************************************/
#include "updateagent.h"
-#include "updatesettings.h"
+#include <common/binaryformatenginehandler.h>
+#include <common/binaryformat.h>
+#include <common/errors.h>
+#include <qinstaller.h>
+#include <qinstallercomponent.h>
+#include <updatesettings.h>
-#include <QDateTime>
-#include <QTimer>
+#include <QtCore/QDateTime>
+#include <QtCore/QTimer>
#include <KDUpdater/Application>
-#include "qinstaller.h"
-#include "qinstallercomponent.h"
-
-#include "common/binaryformatenginehandler.h"
-#include "common/binaryformat.h"
-
using namespace QInstaller;
using QInstallerCreator::ComponentIndex;
using QInstallerCreator::BinaryFormatEngineHandler;
@@ -52,78 +51,64 @@ using QInstallerCreator::BinaryFormatEngineHandler;
class UpdateAgent::Private
{
public:
- Private( UpdateAgent* qq )
- : q( qq )
+ Private(UpdateAgent *qq)
+ : q(qq)
{
- connect( &checkTimer, SIGNAL( timeout() ), q, SLOT( maybeCheck() ) );
- checkTimer.start( 1000 );
+ connect(&checkTimer, SIGNAL(timeout()), q, SLOT(maybeCheck()));
+ checkTimer.start(1000);
}
private:
- UpdateAgent* const q;
+ QTimer checkTimer;
+ UpdateAgent *const q;
public:
void maybeCheck()
{
checkTimer.stop();
-
- UpdateSettings settings;
-
- try
- {
- if( settings.updateInterval() > 0 && settings.lastCheck().secsTo( QDateTime::currentDateTime() ) >= settings.updateInterval() )
- {
- QScopedPointer<BinaryFormatEngineHandler> handler( new BinaryFormatEngineHandler( ComponentIndex() ) );
- handler->setComponentIndex( QInstallerCreator::ComponentIndex() );
-
- settings.setLastCheck( QDateTime::currentDateTime() );
-
- KDUpdater::Application app;
- Installer installer(QInstaller::MagicUpdaterMarker);
- installer.setUpdaterApplication(&app);
- installer.setTemporaryRepositories( settings.repositories() );
- installer.fetchUpdaterPackages();
- QList<Component* > components = installer.components(false, UpdaterMode);
-
- // remove all unimportant updates
- if( settings.checkOnlyImportantUpdates() )
- {
- for( int i = components.count() - 1; i >= 0; --i )
- {
- const Component* const comp = components[ i ];
- if( comp->value( QLatin1String( "Important" ) ).toLower() != QLatin1String( "true" ) )
- components.removeAt( i );
- }
- }
-
- settings.setLastResult( tr( "Software Update run successfully." ) );
-
- // no updates available
- if( components.isEmpty() )
- return;
- emit q->updatesAvailable();
+ UpdateSettings settings;
+ try {
+ if (settings.updateInterval() > 0
+ && settings.lastCheck().secsTo(QDateTime::currentDateTime()) >= settings.updateInterval()) {
+ // update the time we last checked for updates
+ settings.setLastCheck(QDateTime::currentDateTime());
+
+ QScopedPointer<BinaryFormatEngineHandler> handler;
+ handler.reset(new BinaryFormatEngineHandler(ComponentIndex()));
+ handler->setComponentIndex(QInstallerCreator::ComponentIndex());
+
+ KDUpdater::Application app;
+ Installer installer(QInstaller::MagicUpdaterMarker);
+ installer.setUpdaterApplication(&app);
+ installer.setTemporaryRepositories(settings.repositories());
+ if (!installer.fetchUpdaterPackages())
+ throw Error(tr("Software Update failed."));
+ settings.setLastResult(tr("Software Update run successfully."));
+
+ QList<Component*> components = installer.components(false, UpdaterMode);
+ // no updates available
+ if(components.isEmpty())
+ return;
+ emit q->updatesAvailable();
}
+ } catch (...) {
+ settings.setLastResult(tr("Software Update failed."));
+ return;
}
- catch( ... )
- {
- settings.setLastResult( tr( "Software Update failed." ) );
- }
-
checkTimer.start();
}
-
- QTimer checkTimer;
};
-UpdateAgent::UpdateAgent( QObject* parent )
- : QObject( parent ),
- d( new Private( this ) )
+UpdateAgent::UpdateAgent(QObject *parent)
+ : QObject(parent),
+ d(new Private(this))
{
}
UpdateAgent::~UpdateAgent()
{
+ delete d;
}
#include "moc_updateagent.cpp"
diff --git a/examples/testapp/updateagent.h b/examples/testapp/updateagent.h
index 7f7840739..b4b245586 100644
--- a/examples/testapp/updateagent.h
+++ b/examples/testapp/updateagent.h
@@ -27,23 +27,23 @@
#define UPDATEAGENT_H
#include <QtCore/QObject>
-#include <KDToolsCore/pimpl_ptr.h>
class UpdateAgent : public QObject
{
Q_OBJECT
public:
- explicit UpdateAgent( QObject* parent = 0 );
+ explicit UpdateAgent(QObject *parent = 0);
~UpdateAgent();
Q_SIGNALS:
void updatesAvailable();
private:
- Q_PRIVATE_SLOT( d, void maybeCheck() );
+ Q_PRIVATE_SLOT(d, void maybeCheck());
+private:
class Private;
- kdtools::pimpl_ptr< Private > d;
+ Private *const d;
};
#endif