summaryrefslogtreecommitdiffstats
path: root/examples/testapp/updateagent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/testapp/updateagent.cpp')
-rw-r--r--examples/testapp/updateagent.cpp105
1 files changed, 45 insertions, 60 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"