@ -29,6 +29,7 @@
# include <QMessageBox>
# include <QMessageBox>
# include <QProcess>
# include <QProcess>
# include <QTemporaryDir>
# include <QTemporaryDir>
# include <QTimer>
// KDE
// KDE
# include <KDirWatch>
# include <KDirWatch>
@ -49,23 +50,32 @@ Factory::Factory(QObject *parent)
{
{
m_parentWidget = new QWidget ( ) ;
m_parentWidget = new QWidget ( ) ;
m_ watched Paths = Latte : : Layouts : : Importer : : standardPaths ( ) ;
m_ main Paths = Latte : : Layouts : : Importer : : standardPaths ( ) ;
for ( int i = 0 ; i < m_watchedPaths . count ( ) ; + + i ) {
for ( int i = 0 ; i < m_mainPaths . count ( ) ; + + i ) {
m_watchedPaths [ i ] = m_watchedPaths [ i ] + " /latte/indicators " ;
m_mainPaths [ i ] = m_mainPaths [ i ] + " /latte/indicators " ;
discoverNewIndicators ( m_mainPaths [ i ] ) ;
}
}
reload ( ) ;
//! track paths for changes
//! track paths for changes
for ( const auto & dir : m_ watched Paths) {
for ( const auto & dir : m_mainPaths ) {
KDirWatch : : self ( ) - > addDir ( dir ) ;
KDirWatch : : self ( ) - > addDir ( dir ) ;
}
}
connect ( KDirWatch : : self ( ) , & KDirWatch : : dirty , this , [ & ] ( const QString & path ) {
connect ( KDirWatch : : self ( ) , & KDirWatch : : dirty , this , [ & ] ( const QString & path ) {
if ( m_watchedPaths . contains ( path ) ) {
if ( m_indicatorsPaths . contains ( path ) ) {
reload ( ) ;
//! indicator updated
emit pluginsUpdated ( ) ;
reload ( path ) ;
} else if ( m_mainPaths . contains ( path ) ) {
//! consider indicator addition
discoverNewIndicators ( path ) ;
}
} ) ;
connect ( KDirWatch : : self ( ) , & KDirWatch : : deleted , this , [ & ] ( const QString & path ) {
if ( m_indicatorsPaths . contains ( path ) ) {
//! indicator removed
removeIndicatorRecords ( path ) ;
}
}
} ) ;
} ) ;
@ -111,62 +121,109 @@ KPluginMetaData Factory::metadata(QString pluginId)
return KPluginMetaData ( ) ;
return KPluginMetaData ( ) ;
}
}
void Factory : : reload ( )
void Factory : : reload ( const QString & indicatorPath )
{
{
m_plugins . clear ( ) ;
QString pluginChangedId ;
m_pluginUiPaths . clear ( ) ;
m_customPluginIds . clear ( ) ;
m_customPluginNames . clear ( ) ;
m_customLocalPluginIds . clear ( ) ;
for( const auto & path : m_watchedPaths ) {
if ( ! indicatorPath . isEmpty ( ) & & indicatorPath ! = " . " & & indicatorPath ! = " .. " ) {
Q Dir standard ( path ) ;
QString metadataFile = indicatorPath + " /metadata.desktop " ;
if ( standard . exists ( ) ) {
if ( QFileInfo ( metadataFile ) . exists ( ) ) {
QStringList pluginDirs = standard . entryList ( QStringList ( ) , QDir : : AllDirs | QDir : : NoSymLinks ) ;
KPluginMetaData metadata = KPluginMetaData : : fromDesktopFile ( metadataFile ) ;
for ( const auto & pluginDir : pluginDirs ) {
if ( metadataAreValid ( metadata ) ) {
if ( pluginDir ! = " . " & & pluginDir ! = " .. " ) {
pluginChangedId = metadata . pluginId ( ) ;
QString metadataFile = standard . absolutePath ( ) + " / " + pluginDir + " /metadata.desktop " ;
QString uiFile = indicatorPath + " /package/ " + metadata . value ( " X-Latte-MainScript " ) ;
if ( QFileInfo ( metadataFile ) . exists ( ) ) {
if ( ! m_plugins . contains ( metadata . pluginId ( ) ) ) {
KPluginMetaData metadata = KPluginMetaData : : fromDesktopFile ( metadataFile ) ;
m_plugins [ metadata . pluginId ( ) ] = metadata ;
}
if ( metadataAreValid ( metadata ) ) {
if ( QFileInfo ( uiFile ) . exists ( ) ) {
QString uiFile = standard . absolutePath ( ) + " / " + pluginDir + " /package/ " + metadata . value ( " X-Latte-MainScript " ) ;
m_pluginUiPaths [ metadata . pluginId ( ) ] = QFileInfo ( uiFile ) . absolutePath ( ) ;
}
if ( QFileInfo ( uiFile ) . exists ( ) & & ! m_plugins . contains ( metadata . pluginId ( ) ) ) {
if ( ( metadata . pluginId ( ) ! = " org.kde.latte.default " )
m_plugins [ metadata . pluginId ( ) ] = metadata ;
& & ( metadata . pluginId ( ) ! = " org.kde.latte.plasma " ) ) {
if ( ( metadata . pluginId ( ) ! = " org.kde.latte.default " )
if ( ! m_customPluginIds . contains ( metadata . pluginId ( ) ) ) {
& & ( metadata . pluginId ( ) ! = " org.kde.latte.plasma " ) ) {
m_customPluginIds < < metadata . pluginId ( ) ;
m_customPluginIds < < metadata . pluginId ( ) ;
}
m_customPluginNames < < metadata . name ( ) ;
}
if ( standard . absolutePath ( ) . startsWith ( QDir : : homePath ( ) ) ) {
if ( ! m_customPluginNames . contains ( metadata . name ( ) ) ) {
m_customLocalPluginIds < < metadata . pluginId ( ) ;
m_customPluginNames < < metadata . name ( ) ;
}
}
}
m_pluginUiPaths [ metadata . pluginId ( ) ] = QFileInfo ( uiFile ) . absolutePath ( ) ;
if ( indicatorPath . startsWith ( QDir : : homePath ( ) ) ) {
m_customLocalPluginIds < < metadata . pluginId ( ) ;
}
}
QString pluginPath = metadata . fileName ( ) . remove ( " metadata.desktop " ) ;
qDebug ( ) < < " Indicator Package Loaded ::: " < < metadata . name ( ) < < " [ " < < metadata . pluginId ( ) < < " ] " < < " - [ " < < indicatorPath < < " ] " ;
qDebug ( ) < < " Indicator Package Loaded ::: " < < metadata . name ( ) < < " [ " < < metadata . pluginId ( ) < < " ] " < < " - [ " < < pluginPath < < " ] " ;
/*qDebug() << " Indicator value ::: " << metadata.pluginId();
/*qDebug() << " Indicator value ::: " << metadata.pluginId();
qDebug ( ) < < " Indicator value ::: " < < metadata . fileName ( ) ;
qDebug ( ) < < " Indicator value ::: " < < metadata . fileName ( ) ;
qDebug ( ) < < " Indicator value ::: " < < metadata . value ( " X-Latte-MainScript " ) ;
qDebug ( ) < < " Indicator value ::: " < < metadata . value ( " X-Latte-MainScript " ) ;
qDebug ( ) < < " Indicator value ::: " < < metadata . value ( " X-Latte-ConfigUi " ) ;
qDebug ( ) < < " Indicator value ::: " < < metadata . value ( " X-Latte-ConfigUi " ) ;
qDebug ( ) < < " Indicator value ::: " < < metadata . value ( " X-Latte-ConfigXml " ) ; */
qDebug ( ) < < " Indicator value ::: " < < metadata . value ( " X-Latte-ConfigXml " ) ; */
}
}
}
}
}
}
}
}
}
emit customPluginsChanged ( ) ;
if ( ! pluginChangedId . isEmpty ( ) ) {
emit indicatorChanged ( pluginChangedId ) ;
}
}
void Factory : : discoverNewIndicators ( const QString & main )
{
if ( ! m_mainPaths . contains ( main ) ) {
return ;
}
QDirIterator indicatorsDirs ( main , QDir : : Dirs | QDir : : NoSymLinks | QDir : : NoDotAndDotDot , QDirIterator : : NoIteratorFlags ) ;
while ( indicatorsDirs . hasNext ( ) ) {
indicatorsDirs . next ( ) ;
QString iPath = indicatorsDirs . filePath ( ) ;
if ( ! m_indicatorsPaths . contains ( iPath ) ) {
m_indicatorsPaths < < iPath ;
KDirWatch : : self ( ) - > addDir ( iPath ) ;
reload ( iPath ) ;
}
}
}
void Factory : : removeIndicatorRecords ( const QString & path )
{
if ( m_indicatorsPaths . contains ( path ) ) {
QString pluginId = path . section ( ' / ' , - 1 ) ;
m_plugins . remove ( pluginId ) ;
m_pluginUiPaths . remove ( pluginId ) ;
int pos = m_customPluginIds . indexOf ( pluginId ) ;
m_customPluginIds . removeAt ( pos ) ;
m_customPluginNames . removeAt ( pos ) ;
m_customLocalPluginIds . removeAll ( pluginId ) ;
m_indicatorsPaths . removeAll ( path ) ;
qDebug ( ) < < " indicator removed 1 :: " < < pluginId ;
KDirWatch : : self ( ) - > removeDir ( path ) ;
//! delay informing the removal in case it is just an update
QTimer : : singleShot ( 1000 , [ this , pluginId ] ( ) {
emit indicatorRemoved ( pluginId ) ;
} ) ;
}
}
bool Factory : : isCustomType ( const QString & id ) const
{
return ( ( id ! = " org.kde.latte.default " ) & & ( id ! = " org.kde.latte.plasma " ) ) ;
}
}
bool Factory : : metadataAreValid ( KPluginMetaData & metadata )
bool Factory : : metadataAreValid ( KPluginMetaData & metadata )