apm.cpp 2.25 KB
Newer Older
Lukas Appelhans's avatar
Lukas Appelhans committed
1 2 3 4 5 6 7 8 9 10 11
/* This file is part of the Chakra project

   Copyright (C) 2011 Lukas Appelhans <l.appelhans@gmx.de>

   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 2 of the License, or (at your option) any later version.
*/
#include "apm.h"

Lukas Appelhans's avatar
Lukas Appelhans committed
12
#include "queryoperation.h"
Lukas Appelhans's avatar
Lukas Appelhans committed
13
#include "syncoperation.h"
14
#include "removeoperation.h"
15
#include "upgradeoperation.h"
Lukas Appelhans's avatar
Lukas Appelhans committed
16

17 18
#include <akabeiclient/akabeiclientbackend.h>

Lukas Appelhans's avatar
Lukas Appelhans committed
19 20 21
#include <kdebug.h>
#include <QStringList>
#include <QTextStream>
22 23
#include <QCoreApplication>
#include <QTimer>
Lukas Appelhans's avatar
Lukas Appelhans committed
24

25
APM::APM(OperationType type, QList<Operation> operations, QMultiHash<Operation, QString> options, QStringList args, QObject * parent)
26 27 28
  : QObject(parent),
    m_operationType(type),
    m_operations(operations),
29
    m_options(options),
30
    m_args(args)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
{

    //QTimer::singleShot(0, AkabeiClient::Backend::instance(), SLOT(initialize()));
    //QCoreApplication::instance()->quit();
    //QTimer::singleShot(0, QCoreApplication::instance(), SLOT(quit()));
    connect(AkabeiClient::Backend::instance(), SIGNAL(statusChanged(Akabei::Backend::Status)), SLOT(statusChanged(Akabei::Backend::Status)));
    AkabeiClient::Backend::instance()->initialize();
}

APM::~APM()
{}

void APM::statusChanged(Akabei::Backend::Status status)
{
    if (status == Akabei::Backend::StatusReady)
        start();
}

void APM::start()
Lukas Appelhans's avatar
Lukas Appelhans committed
50
{
Lukas Appelhans's avatar
Lukas Appelhans committed
51 52 53 54 55 56
    switch (m_operationType) {
        case QueryOperationType: {
            QueryOperation * query = new QueryOperation(this);
            query->start(m_operations, m_args);
            break;
        }
57 58 59 60 61
        case RemoveOperationType: {
            RemoveOperation * remove = new RemoveOperation(this);
            remove->start(m_operations, m_options, m_args);
            break;
        }
Lukas Appelhans's avatar
Lukas Appelhans committed
62 63 64 65 66
        case SyncOperationType: {
            SyncOperation * sync = new SyncOperation(this);
            sync->start(m_operations, m_options, m_args);
            break;
        }
67 68 69 70 71
        case UpgradeOperationType: {
            UpgradeOperation * upgrade = new UpgradeOperation(this);
            upgrade->start(m_operations, m_options, m_args);
            break;
        }
Lukas Appelhans's avatar
Lukas Appelhans committed
72 73 74
        default:
            break;
    } 
Lukas Appelhans's avatar
Lukas Appelhans committed
75 76 77
}

#include "apm.moc"