| # arts Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# artsmessage.cc

    00001 /*
    00002         Copyright (C) 2001 Jeff Tranter
    00003                            tranter@kde.org
    00004
    00005     This program is free software; you can redistribute it and/or modify
    00006     it under the terms of the GNU General Public License as published by
    00007     the Free Software Foundation; either version 2 of the License, or
    00008     (at your option) any later version.
    00009
    00010     This program is distributed in the hope that it will be useful,
    00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00013     GNU General Public License for more details.
    00014
    00015     You should have received a copy of the GNU General Public License
    00016     along with this program; if not, write to the Free Software
    00017     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    00018
    00019
    00020 ------------------------------------------------------------------------
    00021
    00022 This application displays an error, warning, or informational message
    00023 in a dialog. It is normally used by artsd in conjunction with the -m
    00024 option.  By abstracting this out of artsd, we keep it independent of
    00025 any particular graphics toolkit.
    00026
    00027 This version uses KDE. Equivalent versions could be written using Qt,
    00028 Gnome, etc. and used instead.
    00029
    00030 */
    00031
    00032 #include <qregexp.h>
    00033
    00034 #include <klocale.h>
    00035 #include <kglobal.h>
    00036 #include <kapplication.h>
    00037 #include <kaboutdata.h>
    00038 #include <kmessagebox.h>
    00039 #include <kcmdlineargs.h>
    00040
    00041 // command line options
    00042 static KCmdLineOptions options[] =
    00043   {
    00044       { "e", 0,0 },
    00045       { "error", I18N_NOOP("Display error message (default)"), 0 },
    00046       { "w", 0, 0},
    00047       { "warning", I18N_NOOP("Display warning message"), 0 },
    00048       { "i", 0, 0 },
    00049       { "info", I18N_NOOP("Display informational message"), 0 },
    00050       { "+message", I18N_NOOP("Message string to be displayed"), 0 },
    00051       KCmdLineLastOption // End of options.
    00052   };
    00053
    00054 KAboutData aboutData("artsmessage", I18N_NOOP("artsmessage"), "0.1",
    00055                      I18N_NOOP("Utility to display aRts error messages"),
    00056                      KAboutData::License_GPL, "(c) 2001, Jeff Tranter", 0, 0, "tranter@kde.org");
    00057
    00058 int main(int argc, char **argv) {
    00059     aboutData.addAuthor("Jeff Tranter", 0, "tranter@kde.org");
    00060     KGlobal::locale()->setMainCatalogue("kdelibs");
    00061     KCmdLineArgs::init(argc, argv, &aboutData);
    00062     KCmdLineArgs::addCmdLineOptions(options);
    00063     KApplication app;
    00064
    00065     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    00066     QString msg;
    00067
    00068     // must be at least one argument
    00069     if (args->count() == 0) {
    00070         args->usage();
    00071     }
    00072
    00073     // build up message string from remaining arguments
    00074     for (int i = 0; i < args->count(); i++) {
    00075         if (i == 0)
    00076             msg = args->arg(i);
    00077         else
    00078             msg += QString(" ") + args->arg(i);
    00079     }
    00080
    00081     const int notifyOptions = 0; // never activate KNotify
    00082     if (args->isSet("w")) {
    00083         KMessageBox::sorry(0, msg, i18n("Warning"), notifyOptions);
    00084     } else if (args->isSet("i")) {
    00085         QString id = msg;
    00086         id.replace(QRegExp("[\\[\\]\\s=]"), "_");
    00087         KMessageBox::information(0, msg, i18n("Informational"), id, notifyOptions);
    00088     } else {
    00089         KMessageBox::error(0, msg, i18n("Error"), notifyOptions);
    00090     }
    00091
    00092     return 0;
    00093 }

This file is part of the documentation for arts Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:27:55 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003