00001 #include "ConfigEx.h" 00002 00003 ConfigEx::ConfigEx(const QString& name, Domain domain) 00004 : Config(name, domain) 00005 { 00006 m_charset = "utf8"; 00007 decode(); 00008 m_lastRead = QDateTime::currentDateTime(); 00009 } 00010 00011 #if 0 00012 void ConfigEx::removeComment() 00013 { 00014 for(QMap<QString,ConfigGroup>::Iterator it=groups.begin(); 00015 it!=groups.end(); ++it){ 00016 QStringList removeList; 00017 for(ConfigGroup::Iterator it2=(*it).begin(); 00018 it2!=(*it).end(); ++it2){ 00019 if(it2.key()[0] == '#'){ 00020 QString key = it2.key(); 00021 removeList.append(it2.key()); 00022 } 00023 } 00024 for(QStringList::Iterator it3=removeList.begin(); 00025 it3!=removeList.end(); ++it3){ 00026 (*it).remove(*it3); 00027 } 00028 } 00029 } 00030 #endif 00031 00032 void ConfigEx::decode() 00033 { 00034 QString group = getGroup(); 00035 setGroup("Global"); 00036 QString charset = readEntry("CharSet", "utf8"); 00037 qWarning("ConfigEx::decode()[%s][%s]", charset.latin1(), m_charset.latin1()); 00038 setGroup(group); 00039 if(charset != m_charset){ 00040 m_charset = charset; 00041 read(); 00042 } 00043 //removeComment(); 00044 } 00045 00046 void ConfigEx::read() 00047 { 00048 qWarning("ConfigEx::read()"); 00049 groups.clear(); 00050 changed = FALSE; 00051 00052 if ( !QFileInfo( filename ).exists() ) { 00053 git = groups.end(); 00054 return; 00055 } 00056 00057 QFile f( filename ); 00058 if ( !f.open( IO_ReadOnly ) ) { 00059 git = groups.end(); 00060 return; 00061 } 00062 00063 QTextStream s( &f ); 00064 #ifdef CONFIG_MULTICODEC 00065 QTextCodec* codec = QTextCodec::codecForName(m_charset); 00066 if(codec == NULL){ 00067 codec = QTextCodec::codecForName("utf8"); 00068 qWarning("Config CharSet[utf8]"); 00069 } else { 00070 qWarning("Config CharSet[%s]", m_charset.latin1()); 00071 } 00072 s.setCodec(codec); 00073 #else /* CONFIG_MULTICODEC */ 00074 #if QT_VERSION <= 230 && defined(QT_NO_CODECS) 00075 // The below should work, but doesn't in Qt 2.3.0 00076 s.setCodec( QTextCodec::codecForMib( 106 ) ); 00077 #else 00078 s.setEncoding( QTextStream::UnicodeUTF8 ); 00079 #endif 00080 #endif /* CONFIG_MULTICODEC */ 00081 00082 QStringList list = QStringList::split('\n', s.read() ); 00083 00084 f.close(); 00085 00086 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 00087 if ( !parse( *it ) ) { 00088 git = groups.end(); 00089 return; 00090 } 00091 } 00092 } 00093 00094 QStringList ConfigEx::getKeys() 00095 { 00096 QStringList keys; 00097 if(groups.end() != git){ 00098 for(ConfigGroup::ConstIterator it=(*git).begin(); 00099 it!=(*git).end(); ++it){ 00100 if(it.key()[0] != '#'){ 00101 keys.append(it.key()); 00102 } 00103 } 00104 } 00105 return(keys); 00106 } 00107 00108 QDateTime ConfigEx::lastModified() 00109 { 00110 QFileInfo info(filename); 00111 return(info.lastModified()); 00112 }
1.4.2