apm.cpp 3.43 KB
Newer Older
Lukas Appelhans's avatar
Lukas Appelhans committed
1 2 3 4 5 6 7 8 9 10
/* 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"
11
#include "akabeioptions.h"
Lukas Appelhans's avatar
Lukas Appelhans committed
12

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

19 20
#include <akabeiclient/akabeiclientbackend.h>

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

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

55 56 57 58
OperationManager::~OperationManager()
{
}

59

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

66
void OperationManager::start()
Lukas Appelhans's avatar
Lukas Appelhans committed
67
{
68
    switch (m_type) {
69
        case APM::QueryOperationType: {
Lisa's avatar
Lisa committed
70
            QueryOperation * query = new QueryOperation(m_operations, m_options, m_args, this);
71
            connect(query, SIGNAL(queryFinished()), QCoreApplication::instance(), SLOT(quit()));
Lisa's avatar
Lisa committed
72
            query->start();
73 74 75
            break;
        }
        case APM::RemoveOperationType: {
Lisa's avatar
Lisa committed
76
            RemoveOperation * remove = new RemoveOperation(m_operations, m_options, m_args, this);
77
            connect(remove, SIGNAL(removeFinished()), QCoreApplication::instance(), SLOT(quit()));
Lisa's avatar
Lisa committed
78
            remove->start();
79 80 81
            break;
        }
        case APM::SyncOperationType: {
Lisa's avatar
Lisa committed
82
            SyncOperation * sync = new SyncOperation(m_operations, m_options, m_args, this);
83
            connect(sync, SIGNAL(syncFinished()), QCoreApplication::instance(), SLOT(quit()));
Lisa's avatar
Lisa committed
84
            sync->start();
85 86 87 88
            break;
        }
        case APM::UpgradeOperationType: {
            UpgradeOperation * upgrade = new UpgradeOperation(this);
89
            connect(upgrade, SIGNAL(upgradeFinished()), QCoreApplication::instance(), SLOT(quit()));
Lisa's avatar
Lisa committed
90
            upgrade->start(m_operations, m_options, m_args);
91 92
            break;
        }
93 94 95 96 97 98
        case APM::PerformOperationType: {
            PerformOperation * perform = new PerformOperation(this);
            connect(perform, SIGNAL(performFinished()), QCoreApplication::instance(), SLOT(quit()));
            perform->start(m_options, m_args);
            break;
        }
99 100
        default:
            break;
Lisa's avatar
Lisa committed
101
    }
Lukas Appelhans's avatar
Lukas Appelhans committed
102 103 104
}

#include "apm.moc"