artsmessage.cc
/*
Copyright (C) 2001 Jeff Tranter
tranter@kde.org
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
------------------------------------------------------------------------
This application displays an error, warning, or informational message
in a dialog. It is normally used by artsd in conjunction with the -m
option. By abstracting this out of artsd, we keep it independent of
any particular graphics toolkit.
This version uses KDE. Equivalent versions could be written using Qt,
Gnome, etc. and used instead.
*/
#include <qregexp.h>
#include <klocale.h>
#include <kglobal.h>
#include <kapplication.h>
#include <kaboutdata.h>
#include <kmessagebox.h>
#include <kcmdlineargs.h>
// command line options
static KCmdLineOptions options[] =
{
{ "e", 0,0 },
{ "error", I18N_NOOP("Display error message (default)"), 0 },
{ "w", 0, 0},
{ "warning", I18N_NOOP("Display warning message"), 0 },
{ "i", 0, 0 },
{ "info", I18N_NOOP("Display informational message"), 0 },
{ "+message", I18N_NOOP("Message string to be displayed"), 0 },
KCmdLineLastOption // End of options.
};
KAboutData aboutData("artsmessage", I18N_NOOP("artsmessage"), "0.1",
I18N_NOOP("Utility to display aRts error messages"),
KAboutData::License_GPL, "(c) 2001, Jeff Tranter", 0, 0, "tranter@kde.org");
int main(int argc, char **argv) {
aboutData.addAuthor("Jeff Tranter", 0, "tranter@kde.org");
KGlobal::locale()->setMainCatalogue("kdelibs");
KCmdLineArgs::init(argc, argv, &aboutData);
KCmdLineArgs::addCmdLineOptions(options);
KApplication app;
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
QString msg;
// must be at least one argument
if (args->count() == 0) {
args->usage();
}
// build up message string from remaining arguments
for (int i = 0; i < args->count(); i++) {
if (i == 0)
msg = args->arg(i);
else
msg += QString(" ") + args->arg(i);
}
const int notifyOptions = 0; // never activate KNotify
if (args->isSet("w")) {
KMessageBox::sorry(0, msg, i18n("Warning"), notifyOptions);
} else if (args->isSet("i")) {
QString id = msg;
id.replace(QRegExp("[\\[\\]\\s=]"), "_");
KMessageBox::information(0, msg, i18n("Informational"), id, notifyOptions);
} else {
KMessageBox::error(0, msg, i18n("Error"), notifyOptions);
}
return 0;
}
KApplication
KGlobal::locale
static KLocale * locale()
KCmdLineArgs::usage
static void usage(const char *id=0)
KCmdLineArgs
KCmdLineArgs::parsedArgs
static KCmdLineArgs * parsedArgs(const char *id=0)
klocale.h
KCmdLineArgs::count
int count() const
KMessageBox::sorry
static void sorry(QWidget *parent, const QString &text, const QString &caption=QString::null, int options=Notify)
KCmdLineOptions
KCmdLineArgs::isSet
bool isSet(const char *option) const
I18N_NOOP
#define I18N_NOOP(x)
KAboutData
KMessageBox::error
static void error(QWidget *parent, const QString &text, const QString &caption=QString::null, int options=Notify)
KMessageBox::information
static void information(QWidget *parent, const QString &text, const QString &caption=QString::null, const QString &dontShowAgainName=QString::null, int options=Notify)
KAboutData::addAuthor
void addAuthor(const char *name, const char *task=0, const char *emailAddress=0, const char *webAddress=0)
KCmdLineArgs::init
static void init(int _argc, char **_argv, const char *_appname, const char *programName, const char *_description, const char *_version, bool noKApp=false)
KLocale::setMainCatalogue
static void setMainCatalogue(const char *catalog)
KCmdLineArgs::addCmdLineOptions
static void addCmdLineOptions(const KCmdLineOptions *options, const char *name=0, const char *id=0, const char *afterId=0)
KCmdLineArgs::arg
const char * arg(int n) const

KDE Home | KDE Accessibility Home | Description of Access Keys