File indexing completed on 2024-04-28 11:43:49

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2009 Marco Martin <notmart@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "kstatusnotifieritemtest.h"
0009 
0010 #include "kstatusnotifieritem.h"
0011 #include <QApplication>
0012 #include <QLabel>
0013 #include <QMenu>
0014 
0015 #include <QCommandLineParser>
0016 
0017 #include <QDebug>
0018 
0019 KStatusNotifierItemTest::KStatusNotifierItemTest(QObject *parent, KStatusNotifierItem *tray)
0020     : QObject(parent)
0021 {
0022     QMenu *menu = tray->contextMenu();
0023     m_tray = tray;
0024 
0025     QAction *needsAttention = new QAction(QStringLiteral("Set needs attention"), menu);
0026     QAction *active = new QAction(QStringLiteral("Set active"), menu);
0027     QAction *passive = new QAction(QStringLiteral("Set passive"), menu);
0028 
0029     menu->addAction(needsAttention);
0030     menu->addAction(active);
0031     menu->addAction(passive);
0032 
0033     connect(needsAttention, &QAction::triggered, this, &KStatusNotifierItemTest::setNeedsAttention);
0034     connect(active, &QAction::triggered, this, &KStatusNotifierItemTest::setActive);
0035     connect(passive, &QAction::triggered, this, &KStatusNotifierItemTest::setPassive);
0036 }
0037 
0038 void KStatusNotifierItemTest::setNeedsAttention()
0039 {
0040     qDebug() << "Asking for attention";
0041     m_tray->showMessage(QStringLiteral("message test"), QStringLiteral("Test of the new systemtray notifications wrapper"), QStringLiteral("konqueror"), 3000);
0042     m_tray->setStatus(KStatusNotifierItem::NeedsAttention);
0043 }
0044 
0045 void KStatusNotifierItemTest::setActive()
0046 {
0047     qDebug() << "Systray icon in active state";
0048     m_tray->setStatus(KStatusNotifierItem::Active);
0049 }
0050 
0051 void KStatusNotifierItemTest::setPassive()
0052 {
0053     qDebug() << "Systray icon in passive state";
0054     m_tray->setStatus(KStatusNotifierItem::Passive);
0055 }
0056 
0057 int main(int argc, char **argv)
0058 {
0059     QApplication app(argc, argv);
0060 
0061     int ksniCount;
0062     QString iconName;
0063     {
0064         QCommandLineParser parser;
0065         parser.setApplicationDescription(QCoreApplication::translate("main", "KStatusNotifierItemtest"));
0066         parser.addHelpOption();
0067         parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("active-icon"),
0068                                             QCoreApplication::translate("main", "Name of active icon"),
0069                                             QStringLiteral("name"),
0070                                             QStringLiteral("konqueror")));
0071         parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("ksni-count"),
0072                                             QCoreApplication::translate("main", "How many instances of KStatusNotifierItem to create"),
0073                                             QStringLiteral("count"),
0074                                             QStringLiteral("1")));
0075         parser.process(app);
0076 
0077         if (parser.positionalArguments().count() != 0) {
0078             parser.showHelp();
0079             return (1);
0080         }
0081         ksniCount = parser.value(QStringLiteral("ksni-count")).toInt();
0082         iconName = parser.value(QStringLiteral("active-icon"));
0083     }
0084 
0085     if (!iconName.isEmpty()) {
0086         app.setWindowIcon(QIcon::fromTheme(iconName));
0087     }
0088 
0089     QLabel *l = new QLabel(QStringLiteral("System Tray Main Window"), nullptr);
0090     for (int x = 0; x < ksniCount; ++x) {
0091         KStatusNotifierItem *tray = new KStatusNotifierItem(l);
0092 
0093         new KStatusNotifierItemTest(nullptr, tray);
0094 
0095         tray->setTitle(QStringLiteral("DBus System tray test"));
0096         tray->setIconByName(iconName);
0097         // tray->setIconByPixmap(QIcon::fromTheme("konqueror"));
0098         // tray->setAttentionIconByName("kmail");
0099         tray->setOverlayIconByName(QStringLiteral("emblem-important"));
0100         tray->setStatus(KStatusNotifierItem::Active);
0101 
0102         tray->setToolTipIconByName(QStringLiteral("konqueror"));
0103         tray->setToolTipTitle(QStringLiteral("DBus System tray test"));
0104         tray->setToolTipSubTitle(QStringLiteral("This is a test of the new systemtray specification"));
0105 
0106         tray->setToolTip(QStringLiteral("konqueror"),
0107                          QStringLiteral("DBus System tray test #%1").arg(x + 1),
0108                          QStringLiteral("This is a test of the new systemtray specification"));
0109 
0110         tray->showMessage(QStringLiteral("message test"),
0111                           QStringLiteral("Test of the new systemtray notifications wrapper"),
0112                           QStringLiteral("konqueror"),
0113                           3000);
0114         // tray->setStandardActionsEnabled(false);
0115     }
0116 
0117     return app.exec();
0118 }
0119 
0120 #include "moc_kstatusnotifieritemtest.cpp"