Back to index

kdeartwork  4.3.2
Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes
KXSConfigDialog Class Reference

#include <kxsconfig.h>

List of all members.

Public Member Functions

 KXSConfigDialog (const QString &file, const QString &name)
 ~KXSConfigDialog ()
bool create ()
QString command ()

Protected Slots

void slotPreviewProcFinished (int exitCode, QProcess::ExitStatus exitStatus)
void slotNewPreview ()
void slotChanged ()
virtual void slotOk ()
virtual void slotCancel ()

Protected Member Functions

void startProcess ()

Protected Attributes

QString mFilename
QString mExeName
QString mConfigFile
KProcess * mPreviewProc
QWidget * mPreview
QTimer * mPreviewTimer
QList< KXSConfigItem * > mConfigItemList
bool mKilled

Detailed Description

Definition at line 34 of file kxsconfig.h.


Constructor & Destructor Documentation

KXSConfigDialog::KXSConfigDialog ( const QString &  file,
const QString &  name 
)

Definition at line 77 of file kxsconfig.cpp.

  : KDialog(0),
    mFilename(filename), mPreviewProc(0), mKilled(false)
{
    Q_UNUSED(name)

    setButtons(Ok| Cancel);
    setDefaultButton( Ok);
    setModal(false);
    int slash = filename.lastIndexOf('/');
    if (slash >= 0)
       mConfigFile = filename.mid(slash+1);
    else
       mConfigFile = filename;

    mExeName = mConfigFile;
    mConfigFile += "rc";
    connect( this,SIGNAL(okClicked()),this,SLOT(slotOk()));
    connect( this,SIGNAL(cancelClicked()),this,SLOT(slotCancel()));
}

Here is the call graph for this function:

Definition at line 204 of file kxsconfig.cpp.

{
  if (mPreviewProc && mPreviewProc->state() == QProcess::Running) {
    mPreviewProc->kill();
    mPreviewProc->waitForFinished(5000);
    delete mPreviewProc;
  }
}

Member Function Documentation

Definition at line 214 of file kxsconfig.cpp.

{
  QString cmd;

  for (int i = 0; i < mConfigItemList.size(); i++)
  {
    if (mConfigItemList[i]) {
      cmd += " " + mConfigItemList[i]->command();
    }
  }

  return cmd;
}

Here is the caller graph for this function:

Definition at line 98 of file kxsconfig.cpp.

{
    QWidget *main = new QWidget(this);
    setMainWidget(main);
    QVBoxLayout *topLayout = new QVBoxLayout(main);
    topLayout->setSpacing(spacingHint());
    QHBoxLayout *layout = new QHBoxLayout();
    topLayout->addLayout(layout);
    layout->setSpacing(spacingHint());
    KVBox *controlLayout = new KVBox(main);
    controlLayout->setSpacing(spacingHint());
    layout->addWidget(controlLayout);
    ((QBoxLayout*)controlLayout->layout())->addStrut(120);

    KConfig config(mConfigFile);

    QString xmlFile = "/doesntexist";
#ifdef XSCREENSAVER_CONFIG_DIR
    xmlFile = XSCREENSAVER_CONFIG_DIR;
#endif

    xmlFile += '/' + mExeName + ".xml";
    if ( QFile::exists( xmlFile ) ) {
       // We can use the xscreensaver xml config files.
       KXSXml xmlParser(controlLayout);
       xmlParser.parse( xmlFile );
       mConfigItemList = xmlParser.items();
       QWidget *spacer = new QWidget(controlLayout);
       controlLayout->setStretchFactor(spacer, 1 );
       QString descr = xmlParser.description();
       if ( !descr.isEmpty() ) {
           descr = descr.replace('\n', ' ').simplified();
           QLabel *l = new QLabel( i18n( descr.toUtf8() ), main );
           l->setWordWrap( 1 );
           topLayout->addWidget( l );
       }
    } else {
        // fall back to KDE's old config files.
       int idx = 0;
       while (true) {
           QString group = QString("Arg%1").arg(idx);
           if (config.hasGroup(group)) {
              KConfigGroup grp = config.group(group);
              QString type = grp.readEntry("Type");
              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;
    }

    for ( int i = 0; i < mConfigItemList.size(); i++ ) {
        KXSConfigItem *item = mConfigItemList[i];
        item->read( config );
        QWidget *widget = dynamic_cast<QWidget*>( item );
        if ( widget ) {
            connect( widget, SIGNAL(changed()), SLOT(slotChanged()) );
        }
    }

    mPreviewProc = new KProcess;
    connect(mPreviewProc, SIGNAL(finished(int,QProcess::ExitStatus)),
           SLOT(slotPreviewProcFinished(int,QProcess::ExitStatus)));

    mPreviewTimer = new QTimer(this);
    mPreviewTimer->setSingleShot(true);
    connect(mPreviewTimer, SIGNAL(timeout()), SLOT(slotNewPreview()));

    mPreview = new QWidget(main);
    mPreview->setFixedSize(250, 200);
    {
        QPalette palette;
        palette.setColor(mPreview->backgroundRole(), Qt::black);
        mPreview->setPalette(palette);
       mPreview->setAutoFillBackground(true);
    }

    layout->addWidget(mPreview);
    show();

    // So that hacks can XSelectInput ButtonPressMask
    XSelectInput(QX11Info::display(), mPreview->winId(), widgetEventMask );

    startProcess();
    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void KXSConfigDialog::slotCancel ( ) [protected, virtual, slot]

Definition at line 316 of file kxsconfig.cpp.

{
  kapp->quit();
}

Here is the caller graph for this function:

void KXSConfigDialog::slotChanged ( ) [protected, slot]

Definition at line 295 of file kxsconfig.cpp.

{
    mPreviewTimer->start(1000);
}

Here is the caller graph for this function:

void KXSConfigDialog::slotNewPreview ( ) [protected, slot]

Definition at line 284 of file kxsconfig.cpp.

{
  if (mPreviewProc->state() == QProcess::Running) {
    mKilled = true;
    mPreviewProc->kill(); // restarted in slotPreviewExited()
  } else {
    startProcess();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void KXSConfigDialog::slotOk ( ) [protected, virtual, slot]

Definition at line 301 of file kxsconfig.cpp.

{
  KConfig config(mConfigFile);

  for (int i = 0; i < mConfigItemList.size(); i++)
  {
    if (mConfigItemList[i]) {
      mConfigItemList[i]->save(config);
    }
  }

  kapp->quit();
}

Here is the caller graph for this function:

void KXSConfigDialog::slotPreviewProcFinished ( int  exitCode,
QProcess::ExitStatus  exitStatus 
) [protected, slot]

Definition at line 266 of file kxsconfig.cpp.

{
    Q_UNUSED(exitCode)
    Q_UNUSED(exitStatus)

    if ( mKilled ) {
        startProcess();
    } else {
       // stops us from spawning the hack really fast, but still not the best
       QString path = KStandardDirs::findExe(mFilename, XSCREENSAVER_HACKS_DIR);
       if ( QFile::exists(path) ) {
           mKilled = true;
           slotChanged();
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void KXSConfigDialog::startProcess ( ) [protected]

Definition at line 229 of file kxsconfig.cpp.

{
    mKilled = false;
    mPreviewProc->clearProgram();
    QString saver = QString( "%1 -window-id 0x%2" )
        .arg( mFilename )
        .arg( long(mPreview->winId()), 0, 16 );
    saver += command();
    saver = saver.trimmed();

    kDebug() << "Command: " <<  saver;

    int i = 0;
    QString exe;
    while ( !saver[i].isSpace() ) {
        exe += saver[i++];
    }
    // work around a KStandarDirs::findExe() "feature" where it looks in
    // $KDEDIR/bin first no matter what and sometimes finds the wrong executable
    QFileInfo checkExe;
    QString saverdir = QString(XSCREENSAVER_HACKS_DIR "/") + exe;
    QString path;
    checkExe.setFile(saverdir);
    if (checkExe.exists() && checkExe.isExecutable() && checkExe.isFile())
    {
        path = saverdir;
    }
    if (!path.isEmpty()) {
        (*mPreviewProc) << path;

        (*mPreviewProc) << KShell::splitArgs(saver.mid(i));

        mPreviewProc->start();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

QString KXSConfigDialog::mConfigFile [protected]

Definition at line 56 of file kxsconfig.h.

Definition at line 60 of file kxsconfig.h.

QString KXSConfigDialog::mExeName [protected]

Definition at line 55 of file kxsconfig.h.

QString KXSConfigDialog::mFilename [protected]

Definition at line 54 of file kxsconfig.h.

bool KXSConfigDialog::mKilled [protected]

Definition at line 61 of file kxsconfig.h.

QWidget* KXSConfigDialog::mPreview [protected]

Definition at line 58 of file kxsconfig.h.

KProcess* KXSConfigDialog::mPreviewProc [protected]

Definition at line 57 of file kxsconfig.h.

QTimer* KXSConfigDialog::mPreviewTimer [protected]

Definition at line 59 of file kxsconfig.h.


The documentation for this class was generated from the following files: