File indexing completed on 2022-11-29 18:26:11

0001 /*  This file is part of the KDE libraries
0002     Copyright (C) 2006 Michaƫl Larouche <michael.larouche@kdemail.net>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Library General Public
0006     License as published by the Free Software Foundation; version 2
0007     of the License.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Library General Public License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to
0016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017     Boston, MA 02110-1301, USA.
0018 */
0019 #include "kmessagetest.h"
0020 
0021 #include <QApplication>
0022 #include <QString>
0023 #include <QMessageBox>
0024 #include <QPushButton>
0025 #include <QBoxLayout>
0026 
0027 #include <kmessage.h>
0028 #include <kpassivepopupmessagehandler.h>
0029 
0030 KMessage_Test::KMessage_Test(QWidget *parent)
0031     : QWidget(parent)
0032 {
0033     QVBoxLayout *mainLayout = new QVBoxLayout(this);
0034 
0035     QPushButton *buttonError = new QPushButton(QLatin1String("Show error"), this);
0036     connect(buttonError, SIGNAL(clicked()), this, SLOT(showError()));
0037 
0038     QPushButton *buttonFatal = new QPushButton(QLatin1String("Show fatal"), this);
0039     connect(buttonFatal, SIGNAL(clicked()), this, SLOT(showFatal()));
0040 
0041     QPushButton *buttonInformation = new QPushButton(QLatin1String("Show information"), this);
0042     connect(buttonInformation, SIGNAL(clicked()), this, SLOT(showInformation()));
0043 
0044     QPushButton *buttonSorry = new QPushButton(QLatin1String("Show sorry"), this);
0045     connect(buttonSorry, SIGNAL(clicked()), this, SLOT(showSorry()));
0046 
0047     QPushButton *buttonWarning = new QPushButton(QLatin1String("Show warning"), this);
0048     connect(buttonWarning, SIGNAL(clicked()), this, SLOT(showWarning()));
0049 
0050     mainLayout->addWidget(buttonError);
0051     mainLayout->addWidget(buttonFatal);
0052     mainLayout->addWidget(buttonInformation);
0053     mainLayout->addWidget(buttonSorry);
0054     mainLayout->addWidget(buttonWarning);
0055 }
0056 
0057 void KMessage_Test::showError()
0058 {
0059     KMessage::message(KMessage::Error, QLatin1String("Error: Destruction of the Death Star failed."), QLatin1String("KMessage_Test"));
0060 }
0061 
0062 void KMessage_Test::showFatal()
0063 {
0064     KMessage::message(KMessage::Fatal, QLatin1String("Fatal: You have turn to the dark side of the Force."), QLatin1String("KMessage_Test"));
0065 }
0066 
0067 void KMessage_Test::showInformation()
0068 {
0069     KMessage::message(KMessage::Information, QLatin1String("Info: This is a demonstration of the new KMessage API for kdelibs. It abstract the display of message and you can develop custom message handle for your application"), QLatin1String("KMessage_Test"));
0070 }
0071 
0072 void KMessage_Test::showSorry()
0073 {
0074     KMessage::message(KMessage::Sorry, QLatin1String("Sorry but our princess is in another castle."), QLatin1String("KMessage_Test"));
0075 }
0076 
0077 void KMessage_Test::showWarning()
0078 {
0079     KMessage::message(KMessage::Warning, QLatin1String("Warning: Loading failed. Your user experience will be affected."), QLatin1String("KMessage_Test"));
0080 }
0081 
0082 int main(int argc, char **argv)
0083 {
0084     QApplication::setApplicationName("kmessagetest");
0085 
0086     QApplication app(argc, argv);
0087     app.setQuitOnLastWindowClosed(false);
0088 
0089     KMessage_Test *mainWidget = new KMessage_Test;
0090     mainWidget->setAttribute(static_cast<Qt::WidgetAttribute>(Qt::WA_DeleteOnClose | Qt::WA_QuitOnClose));
0091     KMessage::setMessageHandler(new KPassivePopupMessageHandler(mainWidget));
0092 
0093     mainWidget->show();
0094 
0095     return app.exec();
0096 }
0097