File: qlisten-and-print.cpp

package info (click to toggle)
libindicate-qt 0.2.5.91-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 388 kB
  • ctags: 262
  • sloc: cpp: 1,655; makefile: 6
file content (101 lines) | stat: -rw-r--r-- 3,493 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 * Port of listen-and-print.c using libindicate-qt
 *
 * Copyright 2009 Canonical Ltd.
 *
 * Authors:
 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
 *
 * License: LGPL v2.1 or LGPL v3
 */
#include <QDebug>
#include <QImage>
#include <QTime>

#include "qindicatedecode.h"

#include "qlisten-and-print.h"

void Controller::slotServerAdded(QIndicate::Listener::Server* server, const QString& type)
{
    qDebug() << __FUNCTION__ << type;
}

void Controller::slotServerRemoved(QIndicate::Listener::Server* server, const QString& type)
{
    qDebug() << __FUNCTION__ << type;
}

void Controller::slotIndicatorAdded(QIndicate::Listener::Server* server, QIndicate::Listener::Indicator* indicator)
{
    qDebug() << __FUNCTION__;
}

void Controller::slotIndicatorRemoved(QIndicate::Listener::Server* server, QIndicate::Listener::Indicator* indicator)
{
    qDebug() << __FUNCTION__;
}

void Controller::slotIndicatorModified(QIndicate::Listener::Server* server, QIndicate::Listener::Indicator* indicator, const QString& key)
{
    qDebug() << __FUNCTION__ << key;
    showProperty(server, indicator, key);
}

void Controller::showProperty(QIndicate::Listener::Server* server, QIndicate::Listener::Indicator* indicator, const QString& key)
{
    mListener->getIndicatorProperty(server, indicator, key,
        this,
        SLOT(doShowProperty(QIndicate::Listener::Server*, QIndicate::Listener::Indicator*, const QString&, const QByteArray&))
        );
}

void Controller::doShowProperty(QIndicate::Listener::Server* server, QIndicate::Listener::Indicator* indicator, const QString& key, const QByteArray& value)
{
    qDebug() << "Property" << key;
    if (key == "time") {
        qDebug() << "  " << QIndicate::Decode::dateTimeFromValue(value);
    } else if (key == "icon") {
        QImage image = QIndicate::Decode::imageFromValue(value);
        qDebug() << "  size:" << image.size() << "depth:" << image.depth();
    } else {
        qDebug() << "  " << QIndicate::Decode::stringFromValue(value);
    }
}

int main(int argc, char ** argv)
{
    QApplication app(argc, argv);

    Controller controller;

    QIndicate::Listener* listener = QIndicate::Listener::defaultInstance();
    controller.mListener = listener;

    QObject::connect(
        listener, SIGNAL(indicatorAdded(QIndicate::Listener::Server*, QIndicate::Listener::Indicator*)),
        &controller, SLOT(slotIndicatorAdded(QIndicate::Listener::Server*, QIndicate::Listener::Indicator*))
        );
    QObject::connect(
        listener, SIGNAL(indicatorRemoved(QIndicate::Listener::Server*, QIndicate::Listener::Indicator*)),
        &controller, SLOT(slotIndicatorRemoved(QIndicate::Listener::Server*, QIndicate::Listener::Indicator*))
        );
    QObject::connect(
        listener, SIGNAL(indicatorModified(QIndicate::Listener::Server*, QIndicate::Listener::Indicator*, const QString&)),
        &controller, SLOT(slotIndicatorModified(QIndicate::Listener::Server*, QIndicate::Listener::Indicator*, const QString&))
        );

    QObject::connect(
        listener, SIGNAL(serverAdded(QIndicate::Listener::Server*, const QString&)),
        &controller, SLOT(slotServerAdded(QIndicate::Listener::Server*, const QString&))
        );

    QObject::connect(
        listener, SIGNAL(serverRemoved(QIndicate::Listener::Server*, const QString&)),
        &controller, SLOT(slotServerRemoved(QIndicate::Listener::Server*, const QString&))
        );

    return app.exec();
}

#include "qlisten-and-print.moc"