apm.cpp 2.62 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)
Lisa's avatar
Lisa committed
26 27 28 29 30
    : QObject(parent),
      m_type(type),
      m_operation(operation),
      m_options(options),
      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;
Lisa's avatar
Lisa committed
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];
    }
Lisa's avatar
Lisa committed
49

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

#include "apm.moc"