Back to index

kdeartwork  4.3.2
Classes | Public Slots | Public Member Functions | Protected Member Functions | Protected Attributes
KPartSaver Class Reference

#include <kpartsaver.h>

List of all members.

Classes

struct  Medium

Public Slots

void next (bool random)
void queue (const KUrl &url)
void timeout ()
void closeUrl ()

Public Member Functions

 KPartSaver (WId id=0)
virtual ~KPartSaver ()

Protected Member Functions

bool openUrl (const KUrl &url)

Protected Attributes

QList< Mediumm_media
QTimer * m_timer
KParts::ReadOnlyPart * m_part
int m_current
bool m_single
bool m_random
int m_delay
QStringList m_files
QLabel * m_back

Detailed Description

Definition at line 56 of file kpartsaver.h.


Constructor & Destructor Documentation

KPartSaver::KPartSaver ( WId  id = 0)

Definition at line 99 of file kpartsaver.cpp.

    : KScreenSaver( id ), m_timer(), m_part(0), m_current(-1), m_back(0)
{
    // install signal handlers to make sure that nspluginviewer is shutdown correctly
    // move this into the nspluginviewer kpart code
    if( !g_inited ) {
        g_inited = true;

        srand( time(0) );

        // install signal handler
        signal( SIGINT, exitHandler );    // Ctrl-C will cause a clean exit...
        signal( SIGTERM, exitHandler );   // "kill"...
        signal( SIGHUP, exitHandler );    // "kill -HUP" (hangup)...
        signal( SIGKILL, exitHandler );    // "kill -KILL"
        //atexit( ( void (*)(void) ) exitHandler );
    }

    g_savers.append( this );

    closeUrl();

    // load config
    KConfigGroup cfg(KGlobal::config(), "Misc");

    m_single = cfg.readEntry( "Single", true );
    m_delay = cfg.readEntry( "Delay", 60 );
    m_random = cfg.readEntry( "Random", false );
    m_files = cfg.readEntry( "Files",QStringList() );

    if( m_files.count()==0 ) {

        // create background widget
        m_back = new QLabel( i18n("The screen saver is not configured yet."), this );
        m_back->setWordWrap( true );
        m_back->setAlignment( Qt::AlignCenter );
        embed( m_back );
        m_back->show();

    } else {

        // queue files
        for( int n=0; n<m_files.count(); n++ )
            queue( KUrl( m_files[n] ) );

        // play files
        if( m_single )
            next( m_random );
        else {
            next( m_random );
            QTimer::singleShot( m_delay*1000, this, SLOT(timeout()) );
        }
    }
}

Here is the call graph for this function:

KPartSaver::~KPartSaver ( ) [virtual]

Definition at line 155 of file kpartsaver.cpp.

{
    g_savers.removeAll( this );
    closeUrl();
}

Here is the call graph for this function:


Member Function Documentation

void KPartSaver::closeUrl ( ) [slot]

Definition at line 162 of file kpartsaver.cpp.

{
    if( m_part ) {
        m_part->closeUrl();
        delete m_part;
        m_part = 0;
    }
}

Here is the caller graph for this function:

void KPartSaver::next ( bool  random) [slot]

Definition at line 227 of file kpartsaver.cpp.

{
    // try to find working media
    while( m_media.count()>0 ) {

        if( random )
            m_current = rand() % m_media.count();
        else
            m_current++;

        if( m_current>=(int)m_media.count() )
            m_current = 0;

        kDebug() << "Trying medium " << m_media[m_current].url.url();

        // either start immediately or start mimejob first
        if( !openUrl( m_media[m_current].url ) ) {
            m_media.removeAll( m_media.at(m_current) );
            m_current--;
        } else
            return;

    }

    // create background widget
    m_back = new QLabel( i18n("All of your files are unsupported"), this );
    m_back->setWordWrap( true );
    m_back->setAlignment( Qt::AlignCenter );
    embed( m_back );
    m_back->show();

    // nothing found, set to invalid
    m_current = -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool KPartSaver::openUrl ( const KUrl &  url) [protected]

Definition at line 172 of file kpartsaver.cpp.

{
    if( m_part )
        closeUrl();

    // find mime type
    QString mime = KMimeType::findByUrl( url )->name();

    // load part
    m_part = KMimeTypeTrader::createPartInstanceFromQuery<KParts::ReadOnlyPart>(
        mime, this, this, QString() );

    if( !m_part ) {
        kDebug() << "Part for " << url << " can't be constructed";
        closeUrl();
        return false;
    } else
        embed( m_part->widget() );

    // show kpart
    delete m_back;
    m_back = 0;

    show();
    m_part->widget()->show();

    // load url
    if( !m_part->openUrl( url ) ) {
        kDebug() << "Can't load " << url.url();
        delete m_part;
        m_part = 0;
        closeUrl();
        return false;
    }

    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void KPartSaver::queue ( const KUrl &  url) [slot]

Definition at line 211 of file kpartsaver.cpp.

{
    Medium medium;
    medium.url = url;
    medium.failed = false;
    m_media.append( medium );
}

Here is the caller graph for this function:

void KPartSaver::timeout ( ) [slot]

Definition at line 220 of file kpartsaver.cpp.

{
    next( m_random );
    QTimer::singleShot( m_delay*1000, this, SLOT(timeout()) );
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

QLabel* KPartSaver::m_back [protected]

Definition at line 88 of file kpartsaver.h.

int KPartSaver::m_current [protected]

Definition at line 82 of file kpartsaver.h.

int KPartSaver::m_delay [protected]

Definition at line 86 of file kpartsaver.h.

QStringList KPartSaver::m_files [protected]

Definition at line 87 of file kpartsaver.h.

QList<Medium> KPartSaver::m_media [protected]

Definition at line 79 of file kpartsaver.h.

KParts::ReadOnlyPart* KPartSaver::m_part [protected]

Definition at line 81 of file kpartsaver.h.

bool KPartSaver::m_random [protected]

Definition at line 85 of file kpartsaver.h.

bool KPartSaver::m_single [protected]

Definition at line 84 of file kpartsaver.h.

QTimer* KPartSaver::m_timer [protected]

Definition at line 80 of file kpartsaver.h.


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