From kde-commits Fri Apr 30 22:28:33 2004 From: David Faure Date: Fri, 30 Apr 2004 22:28:33 +0000 To: kde-commits Subject: kdenonbeta/applets/kstatusapplet Message-Id: <20040430222833.205A39A75 () office ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=108336411723252 CVS commit by faure: OK, you got the last feature for free due to a misunderstanding, but what we really need is file-triggered status-app launching. Fixed the icon loading to be able to use standard icons too. M +8 -0 README 1.5 M +25 -8 kstatusapplet.cpp 1.8 M +1 -0 kstatusapplet.h 1.7 --- kdenonbeta/applets/kstatusapplet/README #1.4:1.5 @@ -31,4 +31,12 @@ The Interval is specified in milliseconds. +To trigger the status application when a file was changed, +in addition to the periodic interval, you can add this to the [Status] group: +StatusFile=/var/log/somefile + +Basically this allows to update the icon when something changes in a file +(in such a case, the StatusApp will usually be a script parsing the StatusFile +and returning different exit codes depending on the contents of the file) + File Watching ------------- --- kdenonbeta/applets/kstatusapplet/kstatusapplet.cpp #1.7:1.8 @@ -135,5 +135,8 @@ void KStatusApplet::readGroup( const QSt QString iconname = c->readEntry("Pixmap", QString::null ); if( !iconname.isNull() ) { - pix = m_pInstance->iconLoader()->loadIcon( iconname, KIcon::User ); + // Look for a "User" icon first. + pix = m_pInstance->iconLoader()->loadIcon( iconname, KIcon::User, 0, KIcon::DefaultState, 0, true /*canReturnNull*/ ); + if ( pix.isNull() ) + pix = m_pInstance->iconLoader()->loadIcon( iconname, KIcon::Panel ); } else { pix = KIconLoader::unknown(); @@ -142,4 +145,12 @@ void KStatusApplet::readGroup( const QSt } +void KStatusApplet::watchFile( const QString& path ) +{ + kdDebug() << "watching " << path << endl; + KDirWatch::self()->addFile( path ); + connect( KDirWatch::self(), SIGNAL( dirty( const QString& ) ), + this, SLOT( slotFileModified( const QString& ) ) ); +} + void KStatusApplet::readConfiguration() { @@ -147,4 +158,5 @@ void KStatusApplet::readConfiguration() c->setGroup("Status"); m_statusApp = c->readEntry("StatusApp"); + QString path = c->readEntry("StatusFile"); if ( watchingApp() ) // i.e. !m_statusApp.isEmpty() m_interval = c->readNumEntry( "Interval", 5000 ); @@ -167,4 +179,6 @@ void KStatusApplet::readConfiguration() } } + if ( !path.isEmpty() ) + watchFile( path ); } else // watching a file, not an app @@ -176,8 +190,5 @@ void KStatusApplet::readConfiguration() readGroup( "FileModified", CODE_FILEMODIFIED ); if ( !m_status.isEmpty() && !path.isEmpty() ) { - kdDebug() << "watching " << path << endl; - KDirWatch::self()->addFile( path ); - connect( KDirWatch::self(), SIGNAL( dirty( const QString& ) ), - this, SLOT( slotFileModified( const QString& ) ) ); + watchFile( path ); } else kdWarning() << "Nothing configured...." << endl; @@ -187,7 +198,13 @@ void KStatusApplet::readConfiguration() void KStatusApplet::slotFileModified( const QString& ) { + kdDebug() << k_funcinfo << endl; + if ( watchingApp() ) + startStatusApp(); + else + { setCode( CODE_FILEMODIFIED ); if ( m_interval ) m_pTimer->start( m_interval, true ); + } } --- kdenonbeta/applets/kstatusapplet/kstatusapplet.h #1.6:1.7 @@ -75,4 +75,5 @@ private: void readGroup( const QString& group, int code ); void setCode( int code ); + void watchFile( const QString& path ); bool watchingApp() const { return !m_statusApp.isEmpty(); }