You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
389 lines
11 KiB
389 lines
11 KiB
15 years ago
|
//-----------------------------------------------------------------------------
|
||
|
//
|
||
|
// KDE xscreensaver configuration dialog
|
||
|
//
|
||
|
// Copyright (c) Martin R. Jones <mjones@kde.org> 1999
|
||
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public
|
||
|
// License as published by the Free Software Foundation;
|
||
|
// version 2 of the License.
|
||
|
//
|
||
|
// This program 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
|
||
|
// General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with this program; see the file COPYING. If not, write to
|
||
|
// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
// Boston, MA 02110-1301, USA.
|
||
|
|
||
|
// This file contains code copied from xscreensaver. The xscreensaver
|
||
|
// copyright notice follows.
|
||
|
|
||
|
/*
|
||
|
* xscreensaver, Copyright (c) 1993-2002 Jamie Zawinski <jwz@jwz.org>
|
||
|
*
|
||
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
||
|
* documentation for any purpose is hereby granted without fee, provided that
|
||
|
* the above copyright notice appear in all copies and that both that
|
||
|
* copyright notice and this permission notice appear in supporting
|
||
|
* documentation. No representations are made about the suitability of this
|
||
|
* software for any purpose. It is provided "as is" without express or
|
||
|
* implied warranty.
|
||
|
*/
|
||
|
|
||
|
#include <config.h>
|
||
|
|
||
|
#include <stdlib.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqtimer.h>
|
||
|
#include <tqvbox.h>
|
||
|
#include <tqlabel.h>
|
||
|
#include <tqfileinfo.h>
|
||
15 years ago
|
|
||
|
#include <kdebug.h>
|
||
|
#include <kapplication.h>
|
||
|
#include <kconfig.h>
|
||
|
#include <kdialogbase.h>
|
||
|
#include <kprocess.h>
|
||
|
#include <kstandarddirs.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kcmdlineargs.h>
|
||
|
#include <kmessagebox.h>
|
||
|
|
||
|
#include "kxsconfig.h"
|
||
|
#include "kxscontrol.h"
|
||
|
#include "kxsxml.h"
|
||
|
|
||
15 years ago
|
template class TQPtrList<KXSConfigItem>;
|
||
15 years ago
|
|
||
|
#include <X11/Xlib.h>
|
||
|
#include <X11/Xatom.h>
|
||
|
#include <X11/IntrinsicP.h>
|
||
|
#include <X11/ShellP.h>
|
||
|
|
||
|
int ignoreXError(Display *, XErrorEvent *);
|
||
|
|
||
|
//===========================================================================
|
||
|
|
||
|
const uint widgetEventMask = // X event mask
|
||
|
(uint)(
|
||
|
ExposureMask |
|
||
|
PropertyChangeMask |
|
||
|
StructureNotifyMask
|
||
|
);
|
||
|
|
||
15 years ago
|
KXSConfigDialog::KXSConfigDialog(const TQString &filename, const TQString &name)
|
||
15 years ago
|
: KDialogBase(Plain, name, Ok| Cancel, Ok, 0, 0, false),
|
||
|
mFilename(filename), mPreviewProc(0), mKilled(true)
|
||
|
{
|
||
|
int slash = filename.findRev('/');
|
||
|
if (slash >= 0)
|
||
|
mConfigFile = filename.mid(slash+1);
|
||
|
else
|
||
|
mConfigFile = filename;
|
||
|
|
||
|
mExeName = mConfigFile;
|
||
|
mConfigFile += "rc";
|
||
|
}
|
||
|
|
||
|
bool KXSConfigDialog::create()
|
||
|
{
|
||
15 years ago
|
TQVBoxLayout *topLayout = new TQVBoxLayout(plainPage(), spacingHint());
|
||
13 years ago
|
TQHBoxLayout *layout = new TQHBoxLayout(topLayout, spacingHint());
|
||
15 years ago
|
TQVBox *controlLayout = new TQVBox(plainPage());
|
||
15 years ago
|
controlLayout->setSpacing(spacingHint());
|
||
13 years ago
|
layout->addWidget(controlLayout);
|
||
|
((TQBoxLayout*)controlLayout->layout())->addStrut(120);
|
||
15 years ago
|
|
||
12 years ago
|
TDEConfig config(mConfigFile);
|
||
15 years ago
|
|
||
15 years ago
|
TQString xmlFile = "/doesntexist";
|
||
15 years ago
|
#ifdef XSCREENSAVER_CONFIG_DIR
|
||
|
xmlFile = XSCREENSAVER_CONFIG_DIR;
|
||
|
#endif
|
||
|
|
||
|
xmlFile += "/" + mExeName + ".xml";
|
||
15 years ago
|
if ( TQFile::exists( xmlFile ) ) {
|
||
15 years ago
|
// We can use the xscreensaver xml config files.
|
||
|
KXSXml xmlParser(controlLayout);
|
||
|
xmlParser.parse( xmlFile );
|
||
|
mConfigItemList = *xmlParser.items();
|
||
15 years ago
|
TQWidget *spacer = new TQWidget(controlLayout);
|
||
15 years ago
|
controlLayout->setStretchFactor(spacer, 1 );
|
||
15 years ago
|
TQString descr = xmlParser.description();
|
||
15 years ago
|
if ( !descr.isEmpty() ) {
|
||
|
descr.replace('\n',' ');
|
||
|
descr = descr.simplifyWhiteSpace();
|
||
15 years ago
|
TQLabel *l = new TQLabel( i18n( descr.utf8() ), plainPage() );
|
||
13 years ago
|
l->setAlignment ( WordBreak );
|
||
15 years ago
|
topLayout->addWidget( l );
|
||
|
}
|
||
|
} else {
|
||
|
// fall back to KDE's old config files.
|
||
|
int idx = 0;
|
||
|
while (true) {
|
||
13 years ago
|
TQString group = TQString("Arg%1").arg(idx);
|
||
15 years ago
|
if (config.hasGroup(group)) {
|
||
|
config.setGroup(group);
|
||
15 years ago
|
TQString type = config.readEntry("Type");
|
||
15 years ago
|
if (type == "Range") {
|
||
|
KXSRangeControl *rc = new KXSRangeControl(controlLayout, group, config);
|
||
|
mConfigItemList.append(rc);
|
||
|
} else if (type == "DoubleRange") {
|
||
|
KXSDoubleRangeControl *rc =
|
||
|
new KXSDoubleRangeControl(controlLayout, group, config);
|
||
|
mConfigItemList.append(rc);
|
||
|
} else if (type == "Check") {
|
||
|
KXSCheckBoxControl *cc = new KXSCheckBoxControl(controlLayout, group,
|
||
|
config);
|
||
|
mConfigItemList.append(cc);
|
||
|
} else if (type == "DropList") {
|
||
|
KXSDropListControl *dl = new KXSDropListControl(controlLayout, group,
|
||
|
config);
|
||
|
mConfigItemList.append(dl);
|
||
|
}
|
||
|
} else {
|
||
|
break;
|
||
|
}
|
||
|
idx++;
|
||
|
}
|
||
|
if ( idx == 0 )
|
||
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQPtrListIterator<KXSConfigItem> it( mConfigItemList );
|
||
15 years ago
|
KXSConfigItem *item;
|
||
|
while ( (item = it.current()) != 0 ) {
|
||
|
++it;
|
||
|
item->read( config );
|
||
15 years ago
|
TQWidget *i = dynamic_cast<TQWidget*>(item);
|
||
15 years ago
|
if (i) {
|
||
15 years ago
|
connect( i, TQT_SIGNAL(changed()), TQT_SLOT(slotChanged()) );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
mPreviewProc = new TDEProcess;
|
||
|
connect(mPreviewProc, TQT_SIGNAL(processExited(TDEProcess *)),
|
||
|
TQT_SLOT(slotPreviewExited(TDEProcess *)));
|
||
15 years ago
|
|
||
15 years ago
|
mPreviewTimer = new TQTimer(this);
|
||
|
connect(mPreviewTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotNewPreview()));
|
||
15 years ago
|
|
||
15 years ago
|
mPreview = new TQWidget(plainPage());
|
||
15 years ago
|
mPreview->setFixedSize(250, 200);
|
||
15 years ago
|
// mPreview->setBackgroundMode(TQWidget::NoBackground);
|
||
13 years ago
|
mPreview->setBackgroundColor(TQt::black);
|
||
15 years ago
|
|
||
13 years ago
|
layout->add(mPreview);
|
||
15 years ago
|
show();
|
||
|
|
||
|
// So that hacks can XSelectInput ButtonPressMask
|
||
13 years ago
|
XSelectInput(tqt_xdisplay(), mPreview->winId(), widgetEventMask );
|
||
15 years ago
|
|
||
|
slotPreviewExited(0);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
KXSConfigDialog::~KXSConfigDialog()
|
||
|
{
|
||
|
if (mPreviewProc && mPreviewProc->isRunning()) {
|
||
|
int pid = mPreviewProc->pid();
|
||
|
mPreviewProc->kill();
|
||
|
waitpid(pid, (int *)0, 0);
|
||
|
delete mPreviewProc;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
15 years ago
|
TQString KXSConfigDialog::command()
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString cmd;
|
||
15 years ago
|
KXSConfigItem *item;
|
||
|
|
||
|
for (item = mConfigItemList.first(); item != 0; item = mConfigItemList.next())
|
||
|
{
|
||
|
cmd += " " + item->command();
|
||
|
}
|
||
|
|
||
|
return cmd;
|
||
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
12 years ago
|
void KXSConfigDialog::slotPreviewExited(TDEProcess *)
|
||
15 years ago
|
{
|
||
|
if ( mKilled ) {
|
||
|
mKilled = false;
|
||
|
mPreviewProc->clearArguments();
|
||
15 years ago
|
TQString saver;
|
||
15 years ago
|
saver.sprintf( "%s -window-id 0x%lX", mFilename.latin1(), long(mPreview->winId()) );
|
||
|
saver += command();
|
||
|
kdDebug() << "Command: " << saver << endl;
|
||
|
|
||
|
unsigned int i = 0;
|
||
15 years ago
|
TQString word;
|
||
15 years ago
|
saver = saver.stripWhiteSpace();
|
||
|
while ( !saver[i].isSpace() ) word += saver[i++];
|
||
13 years ago
|
//work around a KStandarDirs::findExe() "feature" where it looks in $TDEDIR/bin first no matter what and sometimes finds the wrong executable
|
||
15 years ago
|
TQFileInfo checkExe;
|
||
13 years ago
|
TQString saverdir = TQString("%1/%2").arg(XSCREENSAVER_HACKS_DIR).arg(word);
|
||
15 years ago
|
TQString path;
|
||
15 years ago
|
checkExe.setFile(saverdir);
|
||
|
if (checkExe.exists() && checkExe.isExecutable() && checkExe.isFile())
|
||
|
{
|
||
|
path = saverdir;
|
||
|
}
|
||
|
if (!path.isEmpty()) {
|
||
|
(*mPreviewProc) << path;
|
||
|
|
||
|
bool inQuotes = false;
|
||
|
while ( i < saver.length() ) {
|
||
|
word = "";
|
||
|
while ( saver[i].isSpace() && i < saver.length() ) i++;
|
||
|
while ( (!saver[i].isSpace() || inQuotes) && i < saver.length() ) {
|
||
|
if ( saver[i] == '\"' ) {
|
||
|
inQuotes = !inQuotes;
|
||
|
} else {
|
||
|
word += saver[i];
|
||
|
}
|
||
|
i++;
|
||
|
}
|
||
|
if (!word.isEmpty()) {
|
||
|
(*mPreviewProc) << word;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
mPreviewProc->start();
|
||
|
}
|
||
|
} else {
|
||
|
// stops us from spawning the hack really fast, but still not the best
|
||
15 years ago
|
TQString path = KStandardDirs::findExe(mFilename, XSCREENSAVER_HACKS_DIR);
|
||
|
if ( TQFile::exists(path) ) {
|
||
15 years ago
|
mKilled = true;
|
||
|
slotChanged();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
void KXSConfigDialog::slotNewPreview()
|
||
|
{
|
||
|
if (mPreviewProc->isRunning()) {
|
||
|
mKilled = true;
|
||
|
mPreviewProc->kill(); // restarted in slotPreviewExited()
|
||
|
} else {
|
||
|
slotPreviewExited(0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
void KXSConfigDialog::slotChanged()
|
||
|
{
|
||
|
if (mPreviewTimer->isActive())
|
||
|
mPreviewTimer->changeInterval(1000);
|
||
|
else
|
||
|
mPreviewTimer->start(1000, true);
|
||
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
void KXSConfigDialog::slotOk()
|
||
|
{
|
||
|
KXSConfigItem *item;
|
||
12 years ago
|
TDEConfig config(mConfigFile);
|
||
15 years ago
|
|
||
|
for (item = mConfigItemList.first(); item != 0; item = mConfigItemList.next())
|
||
|
{
|
||
|
item->save(config);
|
||
|
}
|
||
|
|
||
|
kapp->quit();
|
||
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
void KXSConfigDialog::slotCancel()
|
||
|
{
|
||
|
kapp->quit();
|
||
|
}
|
||
|
|
||
|
|
||
|
//===========================================================================
|
||
|
|
||
|
static const char appName[] = "kxsconfig";
|
||
|
|
||
13 years ago
|
static const char description[] = I18N_NOOP("TDE X Screen Saver Configuration tool");
|
||
15 years ago
|
|
||
|
static const char version[] = "3.0.0";
|
||
|
|
||
|
static const KCmdLineOptions options[] =
|
||
|
{
|
||
|
{"+screensaver", I18N_NOOP("Filename of the screen saver to configure"), 0},
|
||
|
{"+[savername]", I18N_NOOP("Optional screen saver name used in messages"), 0},
|
||
|
KCmdLineLastOption
|
||
|
};
|
||
|
|
||
|
static const char *defaults[] = {
|
||
|
#include "XScreenSaver_ad.h"
|
||
|
0
|
||
|
};
|
||
|
|
||
|
const char *progname = 0;
|
||
|
const char *progclass = "XScreenSaver";
|
||
|
XrmDatabase db;
|
||
|
|
||
|
int main(int argc, char *argv[])
|
||
|
{
|
||
12 years ago
|
TDECmdLineArgs::init(argc, argv, appName, I18N_NOOP("KXSConfig"), description, version);
|
||
15 years ago
|
|
||
12 years ago
|
TDECmdLineArgs::addCmdLineOptions(options);
|
||
15 years ago
|
|
||
12 years ago
|
TDEApplication app;
|
||
15 years ago
|
|
||
12 years ago
|
TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
|
||
15 years ago
|
if(args->count()==0)
|
||
|
exit(1);
|
||
|
|
||
|
/* We must read exactly the same resources as xscreensaver.
|
||
|
That means we must have both the same progclass *and* progname,
|
||
|
at least as far as the resource database is concerned. So,
|
||
|
put "xscreensaver" in argv[0] while initializing Xt.
|
||
|
*/
|
||
|
const char *dummyargs[] = { "xscreensaver" };
|
||
|
int dummyargc = 1;
|
||
|
progname = dummyargs[0];
|
||
|
|
||
13 years ago
|
// Teach Xt to use the Display that TQt has already opened.
|
||
15 years ago
|
XtToolkitInitialize ();
|
||
|
XtAppContext xtApp = XtCreateApplicationContext ();
|
||
13 years ago
|
Display *dpy = tqt_xdisplay();
|
||
15 years ago
|
XtAppSetFallbackResources (xtApp, const_cast<char**>(defaults));
|
||
|
XtDisplayInitialize (xtApp, dpy, progname, progclass, 0, 0,
|
||
|
&dummyargc,
|
||
|
const_cast<char**>(dummyargs));
|
||
|
Widget toplevel_shell = XtAppCreateShell (progname, progclass,
|
||
|
applicationShellWidgetClass,
|
||
|
dpy, 0, 0);
|
||
|
dpy = XtDisplay (toplevel_shell);
|
||
|
db = XtDatabase (dpy);
|
||
|
XtGetApplicationNameAndClass (dpy, const_cast<char**>(&progname),
|
||
|
const_cast<char**>(&progclass));
|
||
|
|
||
15 years ago
|
TQString name = TQString::fromLocal8Bit(args->arg(args->count() - 1));
|
||
15 years ago
|
KXSConfigDialog *dialog=new KXSConfigDialog(args->arg(0), name);
|
||
|
if ( dialog->create() ) {
|
||
|
dialog->show();
|
||
|
app.setMainWidget(dialog);
|
||
|
app.exec();
|
||
|
} else {
|
||
|
KMessageBox::sorry(0,
|
||
13 years ago
|
i18n("No configuration available for %1").arg(name),
|
||
15 years ago
|
name );
|
||
|
}
|
||
|
|
||
|
delete dialog;
|
||
|
}
|
||
|
|
||
|
#include "kxsconfig.moc"
|