summaryrefslogtreecommitdiffstats
path: root/libtdescreensaver/main.cpp
blob: 2260f25fda09c6843f9e41f5cd26a4447a63aaef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* This file is part of the KDE libraries

    Copyright (c) 2001  Martin R. Jones <mjones@kde.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/
#include <config.h>

#include <stdlib.h>
#include <stdio.h>
#include <signal.h>

#include <tqdialog.h>
#include <tdelocale.h>
#include <tdeglobal.h>
#include <kdebug.h>
#include <tdecmdlineargs.h>
#include <tdeapplication.h>
#include <kcrash.h>

#include "tdescreensaver.h"
#include "tdescreensaver_vroot.h"

bool argb_visual = FALSE;

extern "C"
{
    extern const char *kss_applicationName;
    extern const char *kss_description;
    extern const char *kss_version;
    KScreenSaver *kss_create( WId d );
    TQDialog *kss_setup();
}

static const TDECmdLineOptions options[] =
{
  { "setup", I18N_NOOP("Setup screen saver"), 0 },
  { "window-id wid", I18N_NOOP("Run in the specified XWindow"), 0 },
  { "root", I18N_NOOP("Run in the root XWindow"), 0 },
  { "demo", I18N_NOOP("Start screen saver in demo mode"), "default"},
  TDECmdLineLastOption
};

static void crashHandler( int  )
{
#ifdef SIGABRT
    signal (SIGABRT, SIG_DFL);
#endif
    abort();
}

//----------------------------------------------------------------------------

class DemoWindow : public TQWidget
{
public:
    DemoWindow() : TQWidget()
    {
	setFixedSize(600, 420);
    }

protected:
    virtual void keyPressEvent(TQKeyEvent *e)
    {
        if (e->ascii() == 'q')
        {
            kapp->quit();
        }
    }

    virtual void closeEvent( TQCloseEvent * )
    {
        kapp->quit();
    }
};


//----------------------------------------------------------------------------
#if defined(Q_WS_QWS) || defined(Q_WS_MACX)
typedef WId Window;
#endif

KDE_EXPORT int main(int argc, char *argv[])
{
    TDELocale::setMainCatalogue("libtdescreensaver");
    TDECmdLineArgs::init(argc, argv, kss_applicationName, kss_description, kss_version);

    TDECmdLineArgs::addCmdLineOptions(options);

#ifdef HAVE_XCOMPOSITE
    TDEApplication app(TDEApplication::openX11RGBADisplay());
    argb_visual = app.isX11CompositionAvailable();
#else
    TDEApplication app;
#endif

    TDECrash::setCrashHandler( crashHandler );
    TDEGlobal::locale()->insertCatalogue("klock");
    TDEGlobal::locale()->insertCatalogue("tdescreensaver");

    DemoWindow *demoWidget = 0;
    Window saveWin = 0;
    KScreenSaver *target;

    TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();

    if (args->isSet("setup"))
    {
       TQDialog *dlg = kss_setup();
       args->clear();
       dlg->exec();
       delete dlg;
       exit(0);
    }

    if (args->isSet("window-id"))
    {
        saveWin = atol(args->getOption("window-id"));
    }

#ifdef Q_WS_X11 //FIXME
    if (args->isSet("root"))
    {
        saveWin = RootWindow(tqt_xdisplay(), tqt_xscreen());
    }
#endif

    if (args->isSet("demo"))
    {
        saveWin = 0;
    }

    if (saveWin == 0)
    {
        demoWidget = new DemoWindow();
        demoWidget->setBackgroundMode(TQWidget::NoBackground);
        saveWin = demoWidget->winId();
        app.setMainWidget(demoWidget);
        app.processEvents();
    }

    target = kss_create( saveWin );

    if ( demoWidget )
    {
        demoWidget->setFixedSize( 600, 420 );
        demoWidget->show();
    }
    args->clear();
    app.exec();

    delete target;
    delete demoWidget;

    return 0;
}