apm.cpp 2.03 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"
Lukas Appelhans's avatar
Lukas Appelhans committed
15

16 17
#include <akabeiclient/akabeiclientbackend.h>

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

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

    //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
49
{
Lukas Appelhans's avatar
Lukas Appelhans committed
50 51 52 53 54 55
    switch (m_operationType) {
        case QueryOperationType: {
            QueryOperation * query = new QueryOperation(this);
            query->start(m_operations, m_args);
            break;
        }
56 57 58 59 60
        case RemoveOperationType: {
            RemoveOperation * remove = new RemoveOperation(this);
            remove->start(m_operations, m_options, m_args);
            break;
        }
Lukas Appelhans's avatar
Lukas Appelhans committed
61 62 63 64 65 66 67 68
        case SyncOperationType: {
            SyncOperation * sync = new SyncOperation(this);
            sync->start(m_operations, m_options, m_args);
            break;
        }
        default:
            break;
    } 
Lukas Appelhans's avatar
Lukas Appelhans committed
69 70 71
}

#include "apm.moc"