File indexing completed on 2024-04-21 15:02:36

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     connect(view.b_confC, SIGNAL(clicked()), this, SLOT(slotConfigureC()));
0046 }
0047 
0048 void KNotifyTestWindow::slotSendOnlineEvent()
0049 {
0050     KNotification::ContextList contexts;
0051     contexts.append(qMakePair(QString("group"), view.c_group->currentText()));
0052     KNotification *n = new KNotification("online");
0053     n->setWidget(this);
0054     n->setText(i18n("the contact %1 is now online", view.c_name->text()));
0055     n->setContexts(contexts);
0056     n->sendEvent();
0057 }
0058 
0059 void KNotifyTestWindow::slotSendMessageEvent()
0060 {
0061     m_nbNewMessage++;
0062     if (!m_readNotif) {
0063         KNotification *n = new KNotification("message", KNotification::Persistent);
0064         n->setWidget(this);
0065         n->setText(i18n("new message : %1", view.c_text->toPlainText()));
0066         n->setActions(QStringList(i18n("Read")));
0067         connect(n, SIGNAL(activated(uint)), this, SLOT(slotMessageRead()));
0068 
0069         m_readNotif = n;
0070     } else {
0071         m_readNotif->setText(i18n("%1 new messages", m_nbNewMessage));
0072     }
0073 
0074     KNotification::ContextList cl;
0075     cl << qMakePair(QString("group"), view.c_group->currentText());
0076     m_readNotif->setContexts(cl);
0077     m_readNotif->sendEvent();
0078 }
0079 
0080 void KNotifyTestWindow::slotMessageRead()
0081 {
0082     m_nbNewMessage = 0;
0083     if (m_readNotif) {
0084         m_readNotif->close();
0085     }
0086     KMessageBox::information(this, view.c_text->toPlainText(), i18n("reading message"));
0087 }
0088 
0089 void KNotifyTestWindow::slotConfigureG()
0090 {
0091     KNotifyConfigWidget::configure(this);
0092 }
0093 
0094 void KNotifyTestWindow::slotConfigureC()
0095 {
0096     QDialog dialog(this);
0097 
0098     KNotifyConfigWidget *w = new KNotifyConfigWidget(&dialog);
0099     w->setApplication(QString(), "group", view.c_group->currentText());
0100 
0101     QDialogButtonBox *buttonBox = new QDialogButtonBox(&dialog);
0102     buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0103     connect(buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
0104     connect(buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
0105 
0106     QVBoxLayout *layout = new QVBoxLayout(&dialog);
0107     layout->addWidget(w);
0108     layout->addWidget(buttonBox);
0109 
0110     if (dialog.exec()) {
0111         w->save();
0112     }
0113 }
0114 
0115 #include "moc_knotifytestwindow.cpp"