File: qim-client.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 (141 lines) | stat: -rw-r--r-- 4,175 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * Port of im-client.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 <QDateTime>
#include <QImage>
#include <QTimer>

#include <qindicateserver.h>
#include <qindicateindicator.h>

#include "qim-client.h"

void Controller::slotServerDisplay()
{
    qDebug() << "A listener wants us to display the server";
    if (mAttentionIndicator) {
        delete mAttentionIndicator;
        mAttentionIndicator = 0;
        QTimer::singleShot(2000, this, SLOT(createAttentionIndicator()));
    }
    if (mCountIndicator) {
        delete mCountIndicator;
        mCountIndicator = 0;
        QTimer::singleShot(2000, this, SLOT(createCountIndicator()));
    }
}

void Controller::slotInterestAdded(QIndicate::Interest interest)
{
    qDebug() << __FUNCTION__ << interest;
}

void Controller::slotInterestRemoved(QIndicate::Interest interest)
{
    qDebug() << __FUNCTION__ << interest;
}

void Controller::createAttentionIndicator()
{
    qDebug() << "Creating an attention indicator";
    mAttentionIndicator = new QIndicate::Indicator(this);

    mPos = (mPos + 1) % mUserList.count();
    mAttentionIndicator->setNameProperty(mUserList[mPos]);

    mAttentionIndicator->setTimeProperty(QDateTime::currentDateTime());

    QImage image(SOURCE_DIR "/test.png");
    mAttentionIndicator->setIconProperty(image);

    QObject::connect(mAttentionIndicator, SIGNAL(display(QIndicate::Indicator*)),
                     SLOT(slotIndicatorDisplay(QIndicate::Indicator*)));

    mAttentionIndicator->show();

    QTimer::singleShot(1000, this, SLOT(modifyAttentionIndicator()));
}

void Controller::createCountIndicator()
{
    qDebug() << "Creating a count indicator";
    mCountIndicator = new QIndicate::Indicator(this);

    mCountIndicator->setNameProperty("Inbox");
    mCountIndicator->setCountProperty(5);

    QObject::connect(mCountIndicator, SIGNAL(display(QIndicate::Indicator*)),
                     SLOT(slotIndicatorDisplay(QIndicate::Indicator*)));

    mCountIndicator->show();
}

void Controller::modifyAttentionIndicator()
{
    if (!mAttentionIndicator) {
        return;
    }

    qDebug() << __FUNCTION__;
    bool attention = !mAttentionIndicator->drawAttentionProperty();
    QString message = attention
                      ? " wants to talk to you now!"
                      : " does not want to talk anymore";
    mAttentionIndicator->setNameProperty(mUserList[mPos] + message);
    mAttentionIndicator->setDrawAttentionProperty(attention);

    QTimer::singleShot(2000, this, SLOT(modifyAttentionIndicator()));
}

void Controller::slotIndicatorDisplay(QIndicate::Indicator* indicator)
{
    qDebug() << "A listener wants us to display an indicator";
    Q_ASSERT(indicator);
    if (indicator == mCountIndicator) {
        delete mCountIndicator;
        mCountIndicator = 0;
        QTimer::singleShot(2000, this, SLOT(createCountIndicator()));
    } else {
        delete mAttentionIndicator;
        mAttentionIndicator = 0;
        QTimer::singleShot(2000, this, SLOT(createAttentionIndicator()));
    }
}

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

    if (argc != 3) {
        qCritical("Syntax: %s <desktop/file> <serverType>", argv[0]);
        return 1;
    }

    QString desktopFile = QString::fromLocal8Bit(argv[1]);
    QString serverType = QString::fromLocal8Bit(argv[2]);

    QIndicate::Server* server = QIndicate::Server::defaultInstance();

    Controller controller;

    server->setType(serverType);
    server->setDesktopFile(desktopFile);
    server->show();
    QObject::connect(server, SIGNAL(serverDisplay()), &controller, SLOT(slotServerDisplay()));
    QObject::connect(server, SIGNAL(interestAdded(QIndicate::Interest)), &controller, SLOT(slotInterestAdded(QIndicate::Interest)));
    QObject::connect(server, SIGNAL(interestRemoved(QIndicate::Interest)), &controller, SLOT(slotInterestRemoved(QIndicate::Interest)));

    controller.createAttentionIndicator();
    controller.createCountIndicator();
    return app.exec();
}

#include "qim-client.moc"