File: kstatusnotifieritemtest.cpp

package info (click to toggle)
knotifications 5.78.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,244 kB
  • sloc: cpp: 5,507; java: 260; xml: 132; sh: 14; makefile: 12
file content (108 lines) | stat: -rw-r--r-- 4,107 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
/*
    This file is part of the KDE libraries
    SPDX-FileCopyrightText: 2009 Marco Martin <notmart@gmail.com>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#include "kstatusnotifieritemtest.h"

#include "kstatusnotifieritem.h"
#include <QLabel>
#include <QMenu>
#include <QApplication>

#include <QCommandLineParser>

#include <QDebug>

KStatusNotifierItemTest::KStatusNotifierItemTest(QObject *parent, KStatusNotifierItem *tray)
    : QObject(parent)
{
    QMenu *menu = tray->contextMenu();
    m_tray = tray;

    QAction *needsAttention = new QAction(QStringLiteral("Set needs attention"), menu);
    QAction *active = new QAction(QStringLiteral("Set active"), menu);
    QAction *passive = new QAction(QStringLiteral("Set passive"), menu);

    menu->addAction(needsAttention);
    menu->addAction(active);
    menu->addAction(passive);

    connect(needsAttention, &QAction::triggered, this, &KStatusNotifierItemTest::setNeedsAttention);
    connect(active, &QAction::triggered, this, &KStatusNotifierItemTest::setActive);
    connect(passive, &QAction::triggered, this, &KStatusNotifierItemTest::setPassive);
}

void KStatusNotifierItemTest::setNeedsAttention()
{
    qDebug() << "Asking for attention";
    m_tray->showMessage(QStringLiteral("message test"), QStringLiteral("Test of the new systemtray notifications wrapper"), QStringLiteral("konqueror"), 3000);
    m_tray->setStatus(KStatusNotifierItem::NeedsAttention);
}

void KStatusNotifierItemTest::setActive()
{
    qDebug() << "Systray icon in active state";
    m_tray->setStatus(KStatusNotifierItem::Active);
}

void KStatusNotifierItemTest::setPassive()
{
    qDebug() << "Systray icon in passive state";
    m_tray->setStatus(KStatusNotifierItem::Passive);
}

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

    int ksniCount;
    QString iconName;
    {
        QCommandLineParser parser;
        parser.setApplicationDescription(QCoreApplication::translate("main", "KStatusNotifierItemtest"));
        parser.addHelpOption();
        parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("active-icon"), QCoreApplication::translate("main", "Name of active icon"), QStringLiteral("name"), QStringLiteral("konqueror")));
        parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("ksni-count"), QCoreApplication::translate("main", "How many instances of KStatusNotifierItem to create"), QStringLiteral("count"), QStringLiteral("1")));
        parser.process(app);

        if (parser.positionalArguments().count() != 0) {
            parser.showHelp();
            return (1);
        }
        ksniCount = parser.value(QStringLiteral("ksni-count")).toInt();
        iconName = parser.value(QStringLiteral("active-icon"));
    }

    if (!iconName.isEmpty()) {
        app.setWindowIcon(QIcon::fromTheme(iconName));
    }

    QLabel *l = new QLabel(QStringLiteral("System Tray Main Window"), nullptr);
    for (int x = 0; x < ksniCount; ++x) {
        KStatusNotifierItem *tray = new KStatusNotifierItem(l);

        new KStatusNotifierItemTest(nullptr, tray);

        tray->setTitle(QStringLiteral("DBus System tray test"));
        tray->setIconByName(iconName);
        //tray->setIconByPixmap(QIcon::fromTheme("konqueror"));
        //tray->setAttentionIconByName("kmail");
        tray->setOverlayIconByName(QStringLiteral("emblem-important"));
        tray->setStatus(KStatusNotifierItem::Active);

        tray->setToolTipIconByName(QStringLiteral("konqueror"));
        tray->setToolTipTitle(QStringLiteral("DBus System tray test"));
        tray->setToolTipSubTitle(QStringLiteral("This is a test of the new systemtray specification"));

        tray->setToolTip(QStringLiteral("konqueror"), QStringLiteral("DBus System tray test #%1").arg(x + 1), QStringLiteral("This is a test of the new systemtray specification"));

        tray->showMessage(QStringLiteral("message test"), QStringLiteral("Test of the new systemtray notifications wrapper"), QStringLiteral("konqueror"), 3000);
        //tray->setStandardActionsEnabled(false);
    }

    return app.exec();
}