00001 00002 #include "osqlbackendmanager.h" 00003 00004 /* OPIE */ 00005 #include <opie2/odebug.h> 00006 00007 /* QT */ 00008 #include <qdir.h> 00009 #include <qmap.h> 00010 00011 00016 namespace { 00017 class Config { 00018 typedef QMap<QString, QString> List; 00019 public: 00020 Config( const QString& fileName ); 00026 bool load(); 00027 QString value( const QString& key ); 00028 private: 00029 List m_list; 00030 QString m_fileName; 00031 }; 00032 Config::Config( const QString& fileName ) 00033 : m_fileName( fileName ) { 00034 } 00035 00036 bool Config::load() { 00037 if (!QFile::exists( m_fileName ) ) 00038 return false; 00039 QFile file( m_fileName ); 00040 if (!file.open(IO_ReadOnly ) ) 00041 return false; 00042 QStringList list = QStringList::split( '\n', file.readAll() ); 00043 QStringList::Iterator it; 00044 QString line; 00045 for (it = list.begin(); it != list.end(); ++it ) { 00046 line = (*it).stripWhiteSpace(); 00047 owarn << "Anonymous::Config:" + line << oendl; 00048 QStringList test = QStringList::split(' ', line ); 00049 m_list.insert( test[0], test[2] ); 00050 } 00051 return true; 00052 } 00053 QString Config::value( const QString& key ) { 00054 return m_list[key]; 00055 } 00056 }; 00057 00058 00059 using namespace Opie::DB; 00060 00061 OSQLBackEndManager::OSQLBackEndManager( const QStringList& path ) 00062 :m_path( path ) 00063 { 00064 } 00065 OSQLBackEndManager::~OSQLBackEndManager() { 00066 } 00070 OSQLBackEnd::ValueList OSQLBackEndManager::scan() { 00071 OSQLBackEnd::ValueList list; 00072 if (!m_path.isEmpty() ) { 00073 QStringList::Iterator it; 00074 for ( it = m_path.begin(); it != m_path.end(); ++it ) { 00075 list += scanDir( (*it) ); 00076 } 00077 } 00078 return list; 00079 } 00083 OSQLBackEnd::ValueList OSQLBackEndManager::scanDir( const QString& dirName ) { 00084 OSQLBackEnd::ValueList list; 00085 QDir dir( dirName ); 00086 if (dir.exists() ) { 00087 QStringList files = dir.entryList( "*.osql" ); 00088 QStringList::Iterator it; 00089 for ( it = files.begin(); it != files.end(); ++it ) { 00090 list.append( file2backend( (*it) ) ); 00091 } 00092 } 00093 return list; 00094 } 00095 00099 OSQLBackEnd OSQLBackEndManager::file2backend( const QString& file ) { 00100 OSQLBackEnd end; 00101 owarn << "fileName: " + file << oendl; 00102 Config cfg( file ); 00103 if (cfg.load() ) { 00104 end.setName( cfg.value( "Name") ); 00105 end.setVendor( cfg.value("Vendor") ); 00106 end.setLicense( cfg.value("License") ); 00107 end.setLibrary( cfg.value("Library").local8Bit() ); 00108 end.setDefault( cfg.value("Default").toInt() ); 00109 end.setPreference( cfg.value("Preference").toInt() ); 00110 } 00111 return end; 00112 }
1.4.2