/***************************************************************************** * Copyright (C) 2012 by Eike Hein * * Copyright (C) 2011 by Shaun Reich * * Copyright (C) 2008 by Montel Laurent * * * * 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; either version 2 of * * the License, or (at your option) any later version. * * * * 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. If not, see . * *****************************************************************************/ #include "kdevelopsessionsengine.h" #include "kdevelopsessionsservice.h" #include #include #include #include KDevelopSessionsEngine::KDevelopSessionsEngine(QObject *parent, const QVariantList &args) : Plasma::DataEngine(parent, args), m_dirWatch(0) { } KDevelopSessionsEngine::~KDevelopSessionsEngine() { } void KDevelopSessionsEngine::init() { m_dirWatch = new KDirWatch( this ); const QStringList sessionDirs = KGlobal::dirs()->findDirs( "data", "kdevelop/sessions/" ); for ( int i = 0; i < sessionDirs.count(); ++i ) m_dirWatch->addDir( sessionDirs[i], KDirWatch::WatchSubDirs ); connect(m_dirWatch, SIGNAL(dirty(QString)), this, SLOT(updateSessions())); updateSessions(); } Plasma::Service *KDevelopSessionsEngine::serviceForSource(const QString &source) { return new KDevelopSessionsService( this, source ); } void KDevelopSessionsEngine::updateSessions() { const QStringList sessionrcs = KGlobal::dirs()->findAllResources( "data", "kdevelop/sessions/*/sessionrc", KStandardDirs::NoDuplicates ); QHash sessions; QStringList::const_iterator it; for (it = sessionrcs.constBegin(); it != sessionrcs.constEnd(); ++it) { KConfig cfg( *it, KConfig::SimpleConfig ); // Only consider sessions that have open projects. if ( cfg.hasGroup( "General Options" ) && !cfg.group( "General Options" ).readEntry( "Open Projects", "" ).isEmpty() ) { Session session; session.hash = QFileInfo( *it ).dir().dirName(); session.name = cfg.group( "" ).readEntry( "SessionName", "" ); session.description = cfg.group( "" ).readEntry( "SessionPrettyContents", "" ); sessions.insert(session.hash, session); } } QHash::const_iterator it2; for (it2 = sessions.constBegin(); it2 != sessions.constEnd(); ++it2) { const Session& session = it2.value(); if ( !m_currentSessions.contains( session.hash ) ) { // Publish new session. m_currentSessions.insert( session.hash, session ); setData( session.hash, "sessionName", session.name ); setData( session.hash, "sessionString", session.description ); } else { // Publish data changes for older sessions. Session oldSession( m_currentSessions.value(session.hash) ); bool modified = false; if ( session.name != oldSession.name ) { oldSession.name = session.name; modified = true; setData( session.hash, "sessionName", session.name ); } if ( session.description != oldSession.description ) { oldSession.description = session.description; modified = true; setData( session.hash, "sessionString", session.description ); } if ( modified ) m_currentSessions.insert( oldSession.hash, oldSession ); } } QHash::iterator it3 = m_currentSessions.begin(); while ( it3 != m_currentSessions.end() ) { const Session& session = it3.value(); if ( !sessions.contains( session.hash ) ) { removeSource( session.hash ); it3 = m_currentSessions.erase( it3 ); } else ++it3; } } K_EXPORT_PLASMA_DATAENGINE(kdevelopsessionsengine, KDevelopSessionsEngine) #include "moc_kdevelopsessionsengine.cpp"