~ubuntu-branches/debian/stretch/knewstuff/stretch

« back to all changes in this revision

Viewing changes to tests/knewstuff2_cache.cpp

  • Committer: Package Import Robot
  • Author(s): Scarlett Clark
  • Date: 2014-07-15 16:22:19 UTC
  • Revision ID: package-import@ubuntu.com-20140715162219-y23ejdtgskj0wwzq
Tags: upstream-5.0.0
ImportĀ upstreamĀ versionĀ 5.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This file is part of KNewStuff2.
 
3
    Copyright (c) 2007 Josef Spillner <spillner@kde.org>
 
4
 
 
5
    This library is free software; you can redistribute it and/or
 
6
    modify it under the terms of the GNU Lesser General Public
 
7
    License as published by the Free Software Foundation; either
 
8
    version 2.1 of the License, or (at your option) any later version.
 
9
 
 
10
    This library is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
    Lesser General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU Lesser General Public
 
16
    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
17
*/
 
18
 
 
19
#include "knewstuff2_cache.h"
 
20
 
 
21
#include <knewstuff2/core/entryhandler.h>
 
22
#include <knewstuff2/core/coreengine.h>
 
23
 
 
24
#include <kstandarddirs.h>
 
25
#include <qapplication.h>
 
26
#include <QDebug>
 
27
 
 
28
#include <QtCore/QFile>
 
29
 
 
30
#include <unistd.h> // for exit()
 
31
 
 
32
KNewStuff2Cache::KNewStuff2Cache()
 
33
    : QObject()
 
34
{
 
35
    m_engine = NULL;
 
36
}
 
37
 
 
38
void KNewStuff2Cache::run()
 
39
{
 
40
    // qDebug() << "-- start the engine";
 
41
 
 
42
    m_engine = new KNS::CoreEngine(0);
 
43
    m_engine->setCachePolicy(KNS::CoreEngine::CacheOnly);
 
44
    bool ret = m_engine->init("knewstuff2_test.knsrc");
 
45
 
 
46
    // qDebug() << "-- engine initialisation result: " << ret;
 
47
 
 
48
    if (ret) {
 
49
        connect(m_engine,
 
50
                SIGNAL(signalEntryLoaded(KNS::Entry*,const KNS::Feed*,const KNS::Provider*)),
 
51
                SLOT(slotEntryLoaded(KNS::Entry*,const KNS::Feed*,const KNS::Provider*)));
 
52
        connect(m_engine,
 
53
                SIGNAL(signalEntriesFailed()),
 
54
                SLOT(slotEntriesFailed()));
 
55
        connect(m_engine,
 
56
                SIGNAL(signalEntriesFinished()),
 
57
                SLOT(slotEntriesFinished()));
 
58
 
 
59
        m_engine->start();
 
60
    } else {
 
61
        qWarning() << "ACHTUNG: you probably need to 'make install' the knsrc file first.";
 
62
        qWarning() << "Although this is not required anymore, so something went really wrong.";
 
63
        quitTest();
 
64
    }
 
65
}
 
66
 
 
67
void KNewStuff2Cache::slotEntryLoaded(KNS::Entry *entry, const KNS::Feed *feed, const KNS::Provider *provider)
 
68
{
 
69
    Q_UNUSED(feed);
 
70
    Q_UNUSED(provider);
 
71
 
 
72
    // qDebug() << "SLOT: slotEntryLoaded";
 
73
    // qDebug() << "-- entry: " << entry->name().representation();
 
74
}
 
75
 
 
76
void KNewStuff2Cache::slotEntriesFailed()
 
77
{
 
78
    // qDebug() << "SLOT: slotEntriesFailed";
 
79
    quitTest();
 
80
}
 
81
 
 
82
void KNewStuff2Cache::slotEntriesFinished()
 
83
{
 
84
    // qDebug() << "SLOT: slotEntriesFinished";
 
85
    quitTest();
 
86
}
 
87
 
 
88
void KNewStuff2Cache::quitTest()
 
89
{
 
90
    // qDebug() << "-- quitting now...";
 
91
    if (1 == 0) {
 
92
        // this would be the soft way out...
 
93
        delete m_engine;
 
94
        deleteLater();
 
95
        qApp->quit();
 
96
    } else {
 
97
        exit(1);
 
98
    }
 
99
}
 
100
 
 
101
int main(int argc, char **argv)
 
102
{
 
103
    QApplication::setApplicationName("knewstuff2_cache");
 
104
    QApplication app(argc, argv);
 
105
 
 
106
    // Take source directory into account
 
107
    // qDebug() << "-- adding source directory " << KNSSRCDIR;
 
108
    // qDebug() << "-- adding build directory " << KNSBUILDDIR;
 
109
    KGlobal::dirs()->addResourceDir("config", KNSSRCDIR);
 
110
    KGlobal::dirs()->addResourceDir("config", KNSBUILDDIR);
 
111
 
 
112
    KNewStuff2Cache *test = new KNewStuff2Cache();
 
113
    test->run();
 
114
 
 
115
    return app.exec();
 
116
}
 
117