Back to index

kdeartwork  4.3.2
main.cpp
Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //
00003 // Screen savers for KDE
00004 //
00005 // Copyright (c)  Martin R. Jones 1999
00006 //
00007 
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <signal.h>
00011 
00012 #include <qcolor.h>
00013 
00014 #include <klocale.h>
00015 #include <kconfig.h>
00016 #include <kstandarddirs.h>
00017 #include <kdebug.h>
00018 #include <kapplication.h>
00019 #include <kcmdlineargs.h>
00020 #include <kcrash.h>
00021 #include <QDesktopWidget>
00022 #include "demowin.h"
00023 #include "saver.h"
00024 
00025 static const char appName[] = "klock";
00026 static const char description[] = I18N_NOOP("KDE Screen Lock/Saver");
00027 static const char version[] = "2.0.0";
00028 
00029 static void crashHandler( int /*sig*/ )
00030 {
00031 #ifdef SIGABRT
00032     signal ( SIGABRT, SIG_DFL );
00033 #endif
00034     abort();
00035 }
00036 
00037 //----------------------------------------------------------------------------
00038 
00039 int main(int argc, char *argv[])
00040 {
00041     KCmdLineArgs::init(argc, argv, appName, 0, ki18n("KLock"), version, ki18n(description));
00042 
00043 
00044     KCmdLineOptions options;
00045 
00046     options.add("setup", ki18n("Setup screen saver"));
00047 
00048     options.add("window-id wid", ki18n("Run in the specified XWindow"));
00049 
00050     options.add("root", ki18n("Run in the root XWindow"));
00051 
00052     options.add("demo", ki18n("Start screen saver in demo mode"), "default");
00053 
00054     KCmdLineArgs::addCmdLineOptions(options);
00055 
00056     KApplication app;
00057 
00058     KCrash::setCrashHandler( crashHandler );
00059 
00060     DemoWindow *demoWidget = 0;
00061     Window saveWin = 0;
00062 
00063     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00064 
00065     if (args->isSet("setup"))
00066     {
00067        setupScreenSaver();
00068        exit(0);
00069     }
00070 
00071     if (args->isSet("window-id"))
00072     {
00073         saveWin = args->getOption("window-id").toInt();
00074     }
00075 
00076     if (args->isSet("root"))
00077     {
00078         saveWin = QApplication::desktop()->handle();
00079     }
00080 
00081     if (args->isSet("demo"))
00082     {
00083         saveWin = 0;
00084     }
00085 
00086     if (saveWin == 0)
00087     {
00088         demoWidget = new DemoWindow();
00089         demoWidget->setAttribute(Qt::WA_NoSystemBackground, true);
00090         demoWidget->show();
00091         saveWin = demoWidget->winId();
00092         app.processEvents();
00093     }
00094 
00095     startScreenSaver(saveWin);
00096     app.exec();
00097     stopScreenSaver();
00098 
00099     if (demoWidget)
00100     {
00101         delete demoWidget;
00102     }
00103 
00104     return 0;
00105 }
00106