kopete/kopete
kopete-account-kconf_update.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qmap.h>
00021 #include <qtextstream.h>
00022 #include <qregexp.h>
00023 #include <QStringList>
00024
00025 static QTextStream qcin ( stdin, QIODevice::ReadOnly );
00026 static QTextStream qcout( stdout, QIODevice::WriteOnly );
00027 static QTextStream qcerr( stderr, QIODevice::WriteOnly );
00028
00029
00030 bool needFlush = false;
00031 QString accountId;
00032 QString password;
00033 QString autoConnect;
00034 QString protocol;
00035 QMap<QString, QString> pluginData;
00036
00037
00038 QString ircNick;
00039 QString ircServer;
00040 QString ircPort;
00041
00042
00043
00044
00045
00046 QString cryptStr(const QString &aStr)
00047 {
00048 QString result;
00049 for (unsigned int i = 0; i < aStr.length(); i++)
00050 result += (aStr[i].unicode() < 0x20) ? aStr[i] :
00051 QChar(0x1001F - aStr[i].unicode());
00052 return result;
00053 }
00054
00055 void parseGroup( const QString &group, const QString &rawLine )
00056 {
00057
00058
00059 if ( group == "MSN" || group == "ICQ" || group == "Oscar" || group == "Gadu" || group == "Jabber" || group == "IRC" )
00060 {
00061 accountId = "EMPTY";
00062 autoConnect = "true";
00063
00064 if ( group == "Oscar" )
00065 protocol = "AIMProtocol";
00066 else
00067 protocol = group + "Protocol";
00068
00069 password.clear();
00070 pluginData.clear();
00071
00072 needFlush = true;
00073
00074 qcout << "# DELETEGROUP [" << group << "]" << endl;
00075 }
00076 else
00077 {
00078
00079 qcout << rawLine << endl;
00080 }
00081 }
00082
00083 void parseKey( const QString &group, const QString &key, const QString &value, const QString &rawLine )
00084 {
00085
00086 if ( group == "MSN" )
00087 {
00088 if ( key == "UserID" )
00089 accountId = value;
00090 else if ( key == "Password" )
00091 password = value;
00092 else if ( key == "AutoConnect" )
00093 autoConnect = value;
00094 else if ( key == "Nick" )
00095 pluginData[ "displayName" ] = value;
00096
00097
00098
00099 }
00100 else if ( group == "ICQ" )
00101 {
00102 if ( key == "UIN" )
00103 accountId = value;
00104 else if ( key == "Password" )
00105 password = value;
00106 else if ( key == "AutoConnect" )
00107 autoConnect = value;
00108 else if ( key == "Nick" )
00109 pluginData[ "NickName" ] = value;
00110 else if ( key == "Server" )
00111 pluginData[ key ] = value;
00112 else if ( key == "Port" )
00113 pluginData[ key ] = value;
00114 }
00115 else if ( group == "Oscar" )
00116 {
00117 if ( key == "ScreenName" )
00118 accountId = value;
00119 else if ( key == "Password" )
00120 password = value;
00121 else if ( key == "Server" )
00122 pluginData[ key ] = value;
00123 else if ( key == "Port" )
00124 pluginData[ key ] = value;
00125 }
00126 else if ( group == "Jabber" )
00127 {
00128 if ( key == "UserID" )
00129 accountId = value;
00130 else if ( key == "Password" )
00131 password = value;
00132 if ( key == "Server" ||
00133 key == "Port" || key == "UseSSL" || key == "Resource" )
00134 pluginData[ key ] = value;
00135 }
00136 else if ( group == "Gadu" )
00137 {
00138 if ( key == "UIN" )
00139 accountId = value;
00140 else if ( key == "Password" )
00141 password = value;
00142 else if ( key == "Nick" )
00143 pluginData[ "displayName" ] = value;
00144 }
00145 else if ( group == "IRC" )
00146 {
00147 if ( key == "Nickname" )
00148 ircNick = value;
00149 if ( key == "Server" )
00150 ircServer = value;
00151 if ( key == "Port" )
00152 ircPort = value;
00153 if ( accountId == "EMPTY" &&
00154 !ircNick.isEmpty( ) && !ircServer.isEmpty() &&
00155 !ircPort.isEmpty() )
00156 {
00157 accountId = QString::fromLatin1( "%1@%2:%3" ).arg( ircNick, ircServer, ircPort );
00158 }
00159 }
00160
00161
00162
00163 else if ( key == "Modules" )
00164 {
00165 QString newValue = value;
00166 newValue.replace ( ".plugin", ".desktop" );
00167 qcout << "Plugins=" << newValue;
00168 }
00169 else
00170 {
00171
00172 qcout << rawLine << endl;
00173 }
00174 }
00175
00176 void flushData( const QString &group )
00177 {
00178
00179 qcout << "[Account_" << protocol << "_" << accountId << "]" << endl;
00180 qcout << "Protocol=" << protocol << endl;
00181
00182 if( group == "Jabber" )
00183 qcout << "AccountId=" << accountId << "@" << pluginData["Server"] << endl;
00184 else
00185 qcout << "AccountId=" << accountId << endl;
00186
00187 qcout << "Password=" << cryptStr( password ) << endl;
00188 qcout << "AutoConnect=" << autoConnect << endl;
00189
00190 QMap<QString, QString>::ConstIterator it;
00191 for ( it = pluginData.begin(); it != pluginData.end(); ++it )
00192 qcout << "PluginData_" << protocol << "_" << it.key() << "=" << it.value() << endl;
00193
00194 }
00195
00196 int main()
00197 {
00198 qcin.setCodec(QTextCodec::codecForName("UTF-8"));
00199 qcout.setCodec(QTextCodec::codecForName("UTF-8"));
00200
00201 QString curGroup;
00202
00203 QRegExp groupRegExp( "^\\[(.*)\\]" );
00204 QRegExp keyRegExp( "^([a-zA-Z0-9:, _-]*)\\s*=\\s*(.*)\\s*" );
00205 QRegExp commentRegExp( "^(#.*)?$" );
00206
00207 while ( !qcin.atEnd() )
00208 {
00209 QString line = qcin.readLine();
00210
00211 if ( commentRegExp.exactMatch( line ) )
00212 {
00213
00214 qcout << line << endl;
00215 }
00216 else if ( groupRegExp.exactMatch( line ) )
00217 {
00218
00219 if ( needFlush )
00220 {
00221
00222
00223 flushData ( curGroup );
00224 needFlush = false;
00225 }
00226
00227 curGroup = groupRegExp.capturedTexts()[ 1 ];
00228 parseGroup( curGroup, line );
00229 }
00230 else if ( keyRegExp.exactMatch( line ) )
00231 {
00232
00233 parseKey( curGroup, keyRegExp.capturedTexts()[ 1 ], keyRegExp.capturedTexts()[ 2 ], line );
00234 }
00235 else
00236 {
00237 qcerr << "** Unknown input line: " << line << endl;
00238 }
00239 }
00240
00241 if ( needFlush )
00242 flushData ( curGroup );
00243
00244 return 0;
00245 }
00246
00247
00248