main.cpp

00001 /*
00002 This file is part of KDE
00003 
00004   Copyright (C) 1998-2000 Waldo Bastian (bastian@kde.org)
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a copy
00007 of this software and associated documentation files (the "Software"), to deal
00008 in the Software without restriction, including without limitation the rights
00009 to use, copy, modify, merge, publish, distribute, and/or sell
00010 copies of the Software, and to permit persons to whom the Software is
00011 furnished to do so, subject to the following conditions:
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00019 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 */
00023 
00024 /*
00025  * To debug add "--nofork" to the commandline!
00026  */
00027 
00028 #include <dcopclient.h>
00029 #include <kcmdlineargs.h>
00030 #include <klocale.h>
00031 #include <kapplication.h>
00032 
00033 static const char description[] =
00034     I18N_NOOP("HTTP Cookie Daemon");
00035 
00036 static const char version[] = "1.0";
00037 
00038 static const KCmdLineOptions options[] =
00039 {
00040  { "shutdown", I18N_NOOP("Shut down cookie jar"), 0 },
00041  { "remove <domain>", I18N_NOOP("Remove cookies for domain"), 0 },
00042  { "remove-all", I18N_NOOP("Remove all cookies"), 0 },
00043  { "reload-config", I18N_NOOP("Reload configuration file"), 0 },
00044  KCmdLineLastOption
00045 };
00046 
00047 extern "C" KDE_EXPORT int kdemain(int argc, char *argv[])
00048 {
00049    KLocale::setMainCatalogue("kdelibs");
00050    KCmdLineArgs::init(argc, argv, "kcookiejar", I18N_NOOP("HTTP cookie daemon"),
00051               description, version);
00052 
00053    KCmdLineArgs::addCmdLineOptions( options );
00054 
00055    KInstance a("kcookiejar");
00056    
00057    kapp->dcopClient()->attach();
00058 
00059    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00060    QCString replyType;
00061    QByteArray replyData;
00062    if (args->isSet("remove-all"))
00063    {
00064       kapp->dcopClient()->call( "kded", "kcookiejar", "deleteAllCookies()", QByteArray(), replyType, replyData);
00065    }
00066    if (args->isSet("remove"))
00067    {
00068       QString domain = args->getOption("remove");
00069       QByteArray params;
00070       QDataStream stream(params, IO_WriteOnly);
00071       stream << domain;
00072       kapp->dcopClient()->call( "kded", "kcookiejar", "deleteCookiesFromDomain(QString)", params, replyType, replyData);
00073    }
00074    if (args->isSet("shutdown"))
00075    {
00076       QCString module = "kcookiejar";
00077       QByteArray params;
00078       QDataStream stream(params, IO_WriteOnly);
00079       stream << module;
00080       kapp->dcopClient()->call( "kded", "kded", "unloadModule(QCString)", params, replyType, replyData);
00081    }
00082    else if(args->isSet("reload-config"))
00083    {
00084       kapp->dcopClient()->call( "kded", "kcookiejar", "reloadPolicy()", QByteArray(), replyType, replyData);
00085    }
00086    else
00087    {
00088       QCString module = "kcookiejar";
00089       QByteArray params;
00090       QDataStream stream(params, IO_WriteOnly);
00091       stream << module;
00092       kapp->dcopClient()->call( "kded", "kded", "loadModule(QCString)", params, replyType, replyData);
00093    }
00094 
00095    return 0;
00096 }
KDE Home | KDE Accessibility Home | Description of Access Keys