summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmlibrarymanager.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit47d455dd55be855e4cc691c32f687f723d9247ee (patch)
tree52e236aaa2576bdb3840ebede26619692fed6d7d /kpovmodeler/pmlibrarymanager.cpp
downloadtdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.tar.gz
tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kpovmodeler/pmlibrarymanager.cpp')
-rw-r--r--kpovmodeler/pmlibrarymanager.cpp121
1 files changed, 121 insertions, 0 deletions
diff --git a/kpovmodeler/pmlibrarymanager.cpp b/kpovmodeler/pmlibrarymanager.cpp
new file mode 100644
index 00000000..2caeb6e3
--- /dev/null
+++ b/kpovmodeler/pmlibrarymanager.cpp
@@ -0,0 +1,121 @@
+/*
+**************************************************************************
+ description
+ --------------------
+ copyright : (C) 2003 by Luis Carvalho
+ email : lpassos@oninetspeed.pt
+**************************************************************************
+
+**************************************************************************
+* *
+* 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. *
+* *
+**************************************************************************/
+
+#include "pmlibrarymanager.h"
+
+#include <kconfig.h>
+#include <kstandarddirs.h>
+#include <kglobal.h>
+
+#include <qfile.h>
+#include <qdir.h>
+
+#include "pmdebug.h"
+
+PMLibraryManager* PMLibraryManager::s_pInstance = 0;
+KStaticDeleter<PMLibraryManager> PMLibraryManager::s_staticDeleter;
+
+PMLibraryHandle* PMLibraryManager::getLibraryHandle( const QString& libraryName )
+{
+ QPtrListIterator<PMLibraryHandle> it( m_libraries );
+
+ for( ; it.current( ); ++it )
+ if( it.current( )->name( ) == libraryName )
+ return it.current( );
+
+ return NULL;
+}
+
+PMLibraryManager::PMLibraryManager( )
+{
+ m_libraries.setAutoDelete( true );
+ scanLibraries( );
+}
+
+PMLibraryManager::~PMLibraryManager( )
+{
+ m_libraries.clear( );
+}
+
+void PMLibraryManager::saveConfig( KConfig* /*cfg*/ )
+{
+}
+
+void PMLibraryManager::restoreConfig( KConfig* /*cfg*/ )
+{
+}
+
+QValueList<QString> PMLibraryManager::availableLibraries( )
+{
+ QValueList<QString> result;
+ QPtrListIterator<PMLibraryHandle> it( m_libraries );
+
+ for( ; it.current( ); ++it )
+ result.push_back( it.current( )->name( ) );
+
+ return result;
+}
+
+PMLibraryManager* PMLibraryManager::theManager( )
+{
+ if( !s_pInstance )
+ s_staticDeleter.setObject( s_pInstance, new PMLibraryManager( ) );
+ return s_pInstance;
+}
+
+void PMLibraryManager::scanLibraries( )
+{
+ QStringList libraryDirectories;
+
+ // Search for sub directories in /usr/share/kpovmodeler/library
+ libraryDirectories = KGlobal::dirs( )->findDirs( "data", "kpovmodeler/library" );
+
+ for( QStringList::Iterator i = libraryDirectories.begin( ); i != libraryDirectories.end( ); ++i )
+ {
+ QDir curDir( *i );
+ curDir.setFilter( QDir::Dirs );
+ QFileInfoListIterator it( *( curDir.entryInfoList( ) ) );
+
+ // For each sub directory
+ QFileInfo* fi;
+ for( ; ( fi = it.current( ) ) != NULL; ++it )
+ {
+ // check for the existance of library_index.xml
+ // If it's there it's a library
+ if( QFile::exists( fi->absFilePath( ) + "/library_index.xml" ) )
+ {
+ // Create the corresponding PMLibraryHandle
+ PMLibraryHandle* h;
+
+ h = new PMLibraryHandle( fi->absFilePath( ) );
+ if( !getLibraryHandle( h->name( ) ) )
+ m_libraries.append( h );
+ else
+ // a library with that name already exists
+ delete h;
+ }
+ }
+ }
+}
+
+void PMLibraryManager::refresh( )
+{
+ // TODO: Manage the list incrementaly so that previouly handed out
+ // PMLibraryHandle pointers are kept valid
+ m_libraries.clear( );
+ scanLibraries( );
+}