File: knotifytestwindow.cpp

package info (click to toggle)
knotifyconfig 5.116.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,184 kB
  • sloc: cpp: 777; sh: 21; makefile: 5
file content (115 lines) | stat: -rw-r--r-- 3,542 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
/*
    SPDX-FileCopyrightText: 2005-2006 Olivier Goffart <ogoffart at kde.org>
*/

#include "knotifytestwindow.h"
#include "knotification.h"
#include "knotifyconfigwidget.h"

#include <KActionCollection>
#include <KLocalizedString>
#include <KMessageBox>
#include <KStandardAction>
#include <KXMLGUIFactory>

#include <QDialog>
#include <QDialogButtonBox>
#include <QStatusBar>
#include <QTest>
#include <QVBoxLayout>

// ------------------------------------------------------------------------

KNotifyTestWindow::KNotifyTestWindow(QWidget *parent)
    : KXmlGuiWindow(parent)
    , m_nbNewMessage(0)
{
    QWidget *w = new QWidget(this);
    view.setupUi(w);
    //  statusBar()->message(i18n("Test program for KNotify"));
    setCaption(i18n("Test program for KNotify"));

    setCentralWidget(w);

    // set up the actions
    actionCollection()->addAction(KStandardAction::Quit, this, SLOT(close()));

    KStandardAction::keyBindings(guiFactory(), &KXMLGUIFactory::showConfigureShortcutsDialog, actionCollection());

    createGUI(QFINDTESTDATA("knotifytestui.rc"));

    connect(view.b_online, SIGNAL(clicked()), this, SLOT(slotSendOnlineEvent()));
    connect(view.b_message, SIGNAL(clicked()), this, SLOT(slotSendMessageEvent()));
    connect(view.b_read, SIGNAL(clicked()), this, SLOT(slotMessageRead()));
    connect(view.b_confG, SIGNAL(clicked()), this, SLOT(slotConfigureG()));
    connect(view.b_confC, SIGNAL(clicked()), this, SLOT(slotConfigureC()));
}

void KNotifyTestWindow::slotSendOnlineEvent()
{
    KNotification::ContextList contexts;
    contexts.append(qMakePair(QString("group"), view.c_group->currentText()));
    KNotification *n = new KNotification("online");
    n->setWidget(this);
    n->setText(i18n("the contact %1 is now online", view.c_name->text()));
    n->setContexts(contexts);
    n->sendEvent();
}

void KNotifyTestWindow::slotSendMessageEvent()
{
    m_nbNewMessage++;
    if (!m_readNotif) {
        KNotification *n = new KNotification("message", KNotification::Persistent);
        n->setWidget(this);
        n->setText(i18n("new message : %1", view.c_text->toPlainText()));
        n->setActions(QStringList(i18n("Read")));
        connect(n, SIGNAL(activated(uint)), this, SLOT(slotMessageRead()));

        m_readNotif = n;
    } else {
        m_readNotif->setText(i18n("%1 new messages", m_nbNewMessage));
    }

    KNotification::ContextList cl;
    cl << qMakePair(QString("group"), view.c_group->currentText());
    m_readNotif->setContexts(cl);
    m_readNotif->sendEvent();
}

void KNotifyTestWindow::slotMessageRead()
{
    m_nbNewMessage = 0;
    if (m_readNotif) {
        m_readNotif->close();
    }
    KMessageBox::information(this, view.c_text->toPlainText(), i18n("reading message"));
}

void KNotifyTestWindow::slotConfigureG()
{
    KNotifyConfigWidget::configure(this);
}

void KNotifyTestWindow::slotConfigureC()
{
    QDialog dialog(this);

    KNotifyConfigWidget *w = new KNotifyConfigWidget(&dialog);
    w->setApplication(QString(), "group", view.c_group->currentText());

    QDialogButtonBox *buttonBox = new QDialogButtonBox(&dialog);
    buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
    connect(buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
    connect(buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));

    QVBoxLayout *layout = new QVBoxLayout(&dialog);
    layout->addWidget(w);
    layout->addWidget(buttonBox);

    if (dialog.exec()) {
        w->save();
    }
}

#include "moc_knotifytestwindow.cpp"