kalarm Library API Documentation

main.cpp

00001 /*
00002  *  main.cpp
00003  *  Program:  kalarm
00004  *  (C) 2001, 2002 by David Jarvie  software@astrojar.org.uk
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #include "kalarm.h"
00022 
00023 #include <stdlib.h>
00024 
00025 #include <kcmdlineargs.h>
00026 #include <kaboutdata.h>
00027 #include <klocale.h>
00028 #include <kdebug.h>
00029 
00030 #include "kalarmapp.h"
00031 
00032 #define PROGRAM_NAME "kalarm"
00033 
00034 QCString execArguments;    // argument to --exec option
00035 
00036 static KCmdLineOptions options[] =
00037 {
00038         { "a", 0L, 0L },
00039         { "ack-confirm", I18N_NOOP("Prompt for confirmation when alarm is acknowledged"), 0L },
00040 #ifdef KALARM_EMAIL
00041         { "bcc", I18N_NOOP("Blind copy email to self"), 0L },
00042 #endif
00043         { "b", 0L, 0L },
00044         { "beep", I18N_NOOP("Beep when message is displayed"), 0L },
00045         { "colour", 0L, 0L },
00046         { "c", 0L, 0L },
00047         { "color <color>", I18N_NOOP("Message background color (name or hex 0xRRGGBB)"), 0L },
00048         { "calendarURL <url>", I18N_NOOP("URL of calendar file"), 0L },
00049         { "cancelEvent <eventID>", I18N_NOOP("Cancel alarm with the specified event ID"), 0L },
00050         { "e", 0L, 0L },
00051         { "exec <commandline>", I18N_NOOP("Execute a shell command line"), 0L },
00052         { "f", 0L, 0L },
00053         { "file <url>", I18N_NOOP("File to display"), 0L },
00054         { "handleEvent <eventID>", I18N_NOOP("Trigger or cancel alarm with the specified event ID"), 0L },
00055         { "i", 0L, 0L },
00056         { "interval <period>", I18N_NOOP("Interval between alarm recurrences"), 0L },
00057         { "l", 0L, 0L },
00058         { "late-cancel", I18N_NOOP("Cancel alarm if it cannot be triggered on time"), 0L },
00059         { "L", 0L, 0L },
00060         { "login", I18N_NOOP("Repeat alarm at every login"), 0L },
00061 #ifdef KALARM_EMAIL
00062         { "m", 0L, 0L },
00063         { "mail <address>", I18N_NOOP("Send an email to the given address (repeat as needed)"), 0L },
00064 #endif
00065         { "r", 0L, 0L },
00066         { "repeat <count>", I18N_NOOP("Number of times to repeat alarm (after the initial occasion)"), 0L },
00067         { "reset", I18N_NOOP("Reset the alarm scheduling daemon"), 0L },
00068         { "s", 0L, 0L },
00069         { "sound <url>", I18N_NOOP("Audio file to play"), 0L },
00070         { "stop", I18N_NOOP("Stop the alarm scheduling daemon"), 0L },
00071 #ifdef KALARM_EMAIL
00072         { "S", 0L, 0L },
00073         { "subject ", I18N_NOOP("Email subject line"), 0L },
00074 #endif
00075         { "t", 0L, 0L },
00076         { "time <time>", I18N_NOOP("Trigger alarm at time [[[yyyy-]mm-]dd-]hh:mm, or date yyyy-mm-dd"), 0L },
00077         { "tray", I18N_NOOP("Display system tray icon"), 0L },
00078         { "u", 0L, 0L },
00079         { "until <time>", I18N_NOOP("Repeat until time [[[yyyy-]mm-]dd-]hh:mm, or date yyyy-mm-dd"), 0L },
00080         { "displayEvent <eventID>", I18N_NOOP("Obsolete: use --triggerEvent instead"), 0L },
00081         { "triggerEvent <eventID>", I18N_NOOP("Trigger alarm with the specified event ID"), 0L },
00082         { "+[message]", I18N_NOOP("Message text to display"), 0L },
00083         { 0L, 0L, 0L }
00084 };
00085 
00086 
00087 int main(int argc, char *argv[])
00088 {
00089         KAboutData aboutData(PROGRAM_NAME, I18N_NOOP("KAlarm"),
00090                 KALARM_VERSION, I18N_NOOP("       " PROGRAM_NAME "\n"
00091                 "       " PROGRAM_NAME " [-bcilLrstu] -f URL\n"
00092                 "       " PROGRAM_NAME " [-bcilLrstu] message\n"
00093                 "       " PROGRAM_NAME " [-ilLrtu] -e commandline\n"
00094                 "       " PROGRAM_NAME " --tray | --reset | --stop\n"
00095                 "       " PROGRAM_NAME " --cancelEvent eventID [--calendarURL url]\n"
00096                 "       " PROGRAM_NAME " --triggerEvent eventID [--calendarURL url]\n"
00097                 "       " PROGRAM_NAME " --handleEvent eventID [--calendarURL url]\n"
00098                 "       " PROGRAM_NAME " [generic_options]\n\n"
00099                 "KDE personal alarm message and command scheduler"),
00100                 KAboutData::License_GPL,
00101                 "(c) 2001, 2002, David Jarvie", 0L, "http://www.astrojar.org.uk/linux/kalarm.html");
00102         aboutData.addAuthor("David Jarvie", 0L, "software@astrojar.org.uk");
00103 
00104         // Fetch all command line options/arguments after --exec and concatenate
00105         // them into a single argument. Then change the leading '-'.
00106         // This is necessary because the "!" indicator in the 'options'
00107         // array above doesn't work (on KDE2, at least)
00108         for (int i = 0;  i < argc;  ++i)
00109         {
00110                 if (!strcmp(argv[i], "-e") || !strcmp(argv[i], "--exec"))
00111                 {
00112                         while (++i < argc)
00113                         {
00114                                 execArguments += argv[i];
00115                                 if (i < argc - 1)
00116                                         execArguments += ' ';
00117                                 argv[i][0] = 'x';     // in case it's an option
00118                         }
00119                         break;
00120                 }
00121         }
00122         KCmdLineArgs::init(argc, argv, &aboutData);
00123         KCmdLineArgs::addCmdLineOptions(options);
00124         KUniqueApplication::addCmdLineOptions();
00125 
00126         if (!KAlarmApp::start())
00127         {
00128                 // An instance of the application is already running
00129                 exit(0);
00130         }
00131 
00132         // This is the first time through
00133         kdDebug(5950) << "main(): initialising\n";
00134         KAlarmApp* app = KAlarmApp::getInstance();
00135         app->restoreSession();
00136         return app->exec();
00137 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:41:02 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001