main.cpp
00001 /* This file is part of the KDE libraries 00002 00003 Copyright (c) 2001 Martin R. Jones <mjones@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library 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 GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 #include <config.h> 00021 00022 #include <stdlib.h> 00023 #include <stdio.h> 00024 #include <signal.h> 00025 00026 #include <qdialog.h> 00027 #include <klocale.h> 00028 #include <kglobal.h> 00029 #include <kdebug.h> 00030 #include <kcmdlineargs.h> 00031 #include <kapplication.h> 00032 #include <kcrash.h> 00033 00034 #include "kscreensaver.h" 00035 #include "kscreensaver_vroot.h" 00036 00037 extern "C" 00038 { 00039 extern const char *kss_applicationName; 00040 extern const char *kss_description; 00041 extern const char *kss_version; 00042 KScreenSaver *kss_create( WId d ); 00043 QDialog *kss_setup(); 00044 } 00045 00046 static const KCmdLineOptions options[] = 00047 { 00048 { "setup", I18N_NOOP("Setup screen saver"), 0 }, 00049 { "window-id wid", I18N_NOOP("Run in the specified XWindow"), 0 }, 00050 { "root", I18N_NOOP("Run in the root XWindow"), 0 }, 00051 { "demo", I18N_NOOP("Start screen saver in demo mode"), "default"}, 00052 KCmdLineLastOption 00053 }; 00054 00055 static void crashHandler( int ) 00056 { 00057 #ifdef SIGABRT 00058 signal (SIGABRT, SIG_DFL); 00059 #endif 00060 abort(); 00061 } 00062 00063 //---------------------------------------------------------------------------- 00064 00065 class DemoWindow : public QWidget 00066 { 00067 public: 00068 DemoWindow() : QWidget() 00069 { 00070 setFixedSize(600, 420); 00071 } 00072 00073 protected: 00074 virtual void keyPressEvent(QKeyEvent *e) 00075 { 00076 if (e->ascii() == 'q') 00077 { 00078 kapp->quit(); 00079 } 00080 } 00081 00082 virtual void closeEvent( QCloseEvent * ) 00083 { 00084 kapp->quit(); 00085 } 00086 }; 00087 00088 00089 //---------------------------------------------------------------------------- 00090 #if defined(Q_WS_QWS) || defined(Q_WS_MACX) 00091 typedef WId Window; 00092 #endif 00093 00094 KDE_EXPORT int main(int argc, char *argv[]) 00095 { 00096 KLocale::setMainCatalogue("libkscreensaver"); 00097 KCmdLineArgs::init(argc, argv, kss_applicationName, kss_description, kss_version); 00098 00099 KCmdLineArgs::addCmdLineOptions(options); 00100 00101 KApplication app; 00102 00103 KCrash::setCrashHandler( crashHandler ); 00104 KGlobal::locale()->insertCatalogue("klock"); 00105 KGlobal::locale()->insertCatalogue("kscreensaver"); 00106 00107 DemoWindow *demoWidget = 0; 00108 Window saveWin = 0; 00109 KScreenSaver *target; 00110 00111 KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); 00112 00113 if (args->isSet("setup")) 00114 { 00115 QDialog *dlg = kss_setup(); 00116 args->clear(); 00117 dlg->exec(); 00118 delete dlg; 00119 exit(0); 00120 } 00121 00122 if (args->isSet("window-id")) 00123 { 00124 saveWin = atol(args->getOption("window-id")); 00125 } 00126 00127 #ifdef Q_WS_X11 //FIXME 00128 if (args->isSet("root")) 00129 { 00130 saveWin = RootWindow(qt_xdisplay(), qt_xscreen()); 00131 } 00132 #endif 00133 00134 if (args->isSet("demo")) 00135 { 00136 saveWin = 0; 00137 } 00138 00139 if (saveWin == 0) 00140 { 00141 demoWidget = new DemoWindow(); 00142 demoWidget->setBackgroundMode(QWidget::NoBackground); 00143 saveWin = demoWidget->winId(); 00144 app.setMainWidget(demoWidget); 00145 app.processEvents(); 00146 } 00147 00148 target = kss_create( saveWin ); 00149 00150 if ( demoWidget ) 00151 { 00152 demoWidget->setFixedSize( 600, 420 ); 00153 demoWidget->show(); 00154 } 00155 args->clear(); 00156 app.exec(); 00157 00158 delete target; 00159 delete demoWidget; 00160 00161 return 0; 00162 } 00163