apm.cpp 2.7 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
OperationManager::OperationManager(APM::OperationType type, APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject * parent)
26
  : QObject(parent),
27 28
    m_type(type),
    m_operation(operation),
29
    m_options(options),
30
    m_args(args)
31 32 33 34 35
{
    //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)));
Lisa's avatar
Lisa committed
36 37 38
    QString root;
    QString cache;
    QString dbs;
39 40 41 42 43 44 45 46 47 48
    
    if (options.contains(APM::RootDir)) {
        root = options[APM::RootDir].args[0];
    }
    if (options.contains(APM::CacheDir)) {
        cache = options[APM::CacheDir].args[0];
    }
    if (options.contains(APM::DBPath)) {
        dbs = options[APM::DBPath].args[0];
    }
Lukas Appelhans's avatar
Lukas Appelhans committed
49 50
    
    AkabeiClient::Backend::instance()->initialize(root, cache, dbs);
51 52
}

53 54 55 56
OperationManager::~OperationManager()
{
}

57

58
void OperationManager::statusChanged(Akabei::Backend::Status status)
59 60 61 62 63
{
    if (status == Akabei::Backend::StatusReady)
        start();
}

64
void OperationManager::start()
Lukas Appelhans's avatar
Lukas Appelhans committed
65
{
66 67
    switch (m_type) {
        case APM::QueryOperationType: {
Lukas Appelhans's avatar
Lukas Appelhans committed
68
            QueryOperation * query = new QueryOperation(this);
69
            query->start(m_operation, m_options, m_args);
Lukas Appelhans's avatar
Lukas Appelhans committed
70 71
            break;
        }
72
        case APM::RemoveOperationType: {
73
            RemoveOperation * remove = new RemoveOperation(this);
74
            remove->start(m_operation, m_options, m_args);
75 76
            break;
        }
77
        case APM::SyncOperationType: {
Lukas Appelhans's avatar
Lukas Appelhans committed
78
            SyncOperation * sync = new SyncOperation(this);
79
            sync->start(m_operation, m_options, m_args);
Lukas Appelhans's avatar
Lukas Appelhans committed
80 81
            break;
        }
82
        case APM::UpgradeOperationType: {
83
            UpgradeOperation * upgrade = new UpgradeOperation(this);
84
            upgrade->start(m_operation, m_options, m_args);
85 86
            break;
        }
Lukas Appelhans's avatar
Lukas Appelhans committed
87 88
        default:
            break;
Lisa's avatar
Lisa committed
89
    }
Lukas Appelhans's avatar
Lukas Appelhans committed
90 91 92
}

#include "apm.moc"