File indexing completed on 2024-05-05 03:57:02

0001 /*
0002     SPDX-FileCopyrightText: 2005-2006 Olivier Goffart <ogoffart at kde.org>
0003 */
0004 
0005 #include "knotifytestwindow.h"
0006 #include "knotification.h"
0007 #include "knotifyconfigwidget.h"
0008 
0009 #include <KActionCollection>
0010 #include <KLocalizedString>
0011 #include <KMessageBox>
0012 #include <KStandardAction>
0013 #include <KXMLGUIFactory>
0014 
0015 #include <QDialog>
0016 #include <QDialogButtonBox>
0017 #include <QStatusBar>
0018 #include <QTest>
0019 #include <QVBoxLayout>
0020 
0021 // ------------------------------------------------------------------------
0022 
0023 KNotifyTestWindow::KNotifyTestWindow(QWidget *parent)
0024     : KXmlGuiWindow(parent)
0025     , m_nbNewMessage(0)
0026 {
0027     QWidget *w = new QWidget(this);
0028     view.setupUi(w);
0029     //  statusBar()->message(i18n("Test program for KNotify"));
0030     setCaption(i18n("Test program for KNotify"));
0031 
0032     setCentralWidget(w);
0033 
0034     // set up the actions
0035     actionCollection()->addAction(KStandardAction::Quit, this, SLOT(close()));
0036 
0037     KStandardAction::keyBindings(guiFactory(), &KXMLGUIFactory::showConfigureShortcutsDialog, actionCollection());
0038 
0039     createGUI(QFINDTESTDATA("knotifytestui.rc"));
0040 
0041     connect(view.b_online, SIGNAL(clicked()), this, SLOT(slotSendOnlineEvent()));
0042     connect(view.b_message, SIGNAL(clicked()), this, SLOT(slotSendMessageEvent()));
0043     connect(view.b_read, SIGNAL(clicked()), this, SLOT(slotMessageRead()));
0044     connect(view.b_confG, SIGNAL(clicked()), this, SLOT(slotConfigureG()));
0045 }
0046 
0047 void KNotifyTestWindow::slotSendOnlineEvent()
0048 {
0049     KNotification *n = new KNotification("online");
0050     n->setText(i18n("the contact %1 is now online", view.c_name->text()));
0051     n->sendEvent();
0052 }
0053 
0054 void KNotifyTestWindow::slotSendMessageEvent()
0055 {
0056     m_nbNewMessage++;
0057     if (!m_readNotif) {
0058         KNotification *n = new KNotification("message", KNotification::Persistent);
0059         n->setText(i18n("new message : %1", view.c_text->toPlainText()));
0060         auto action = n->addAction(i18n("Read"));
0061         connect(action, &KNotificationAction::activated, this, &KNotifyTestWindow::slotMessageRead);
0062 
0063         m_readNotif = n;
0064     } else {
0065         m_readNotif->setText(i18n("%1 new messages", m_nbNewMessage));
0066     }
0067 
0068     m_readNotif->sendEvent();
0069 }
0070 
0071 void KNotifyTestWindow::slotMessageRead()
0072 {
0073     m_nbNewMessage = 0;
0074     if (m_readNotif) {
0075         m_readNotif->close();
0076     }
0077     KMessageBox::information(this, view.c_text->toPlainText(), i18n("reading message"));
0078 }
0079 
0080 void KNotifyTestWindow::slotConfigureG()
0081 {
0082     KNotifyConfigWidget::configure(this);
0083 }
0084 
0085 #include "moc_knotifytestwindow.cpp"