• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdenetwork
  • Sitemap
  • Contact Us
 

kopete/kopete

kopete-account-kconf_update.cpp

Go to the documentation of this file.
00001 /*
00002     kconf_update app for migrating kopete 0.6.x accounts to 0.7. Code is
00003     not up to my normal standards, but it does the job, and since it's
00004     supposed to run exactly once on each system that's good enough for me :)
00005 
00006     Copyright (c) 2003      by Martijn Klingens <klingens@kde.org>
00007 
00008     Kopete    (c) 2002-2003 by the Kopete developers  <kopete-devel@kde.org>
00009 
00010     *************************************************************************
00011     *                                                                       *
00012     * This library is free software; you can redistribute it and/or         *
00013     * modify it under the terms of the GNU Lesser General Public            *
00014     * License as published by the Free Software Foundation; either          *
00015     * version 2 of the License, or (at your option) any later version.      *
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 // Group cache. Yes, I know global vars are ugly :)
00030 bool needFlush = false;
00031 QString accountId;
00032 QString password;
00033 QString autoConnect;
00034 QString protocol;
00035 QMap<QString, QString> pluginData;
00036 
00037 // Global vars to hold separate IRC vars until we have read all of them
00038 QString ircNick;
00039 QString ircServer;
00040 QString ircPort;
00041 
00042 /*
00043  * Function for (en/de)crypting strings for config file, taken from KMail
00044  * Author: Stefan Taferner <taferner@alpin.or.at>
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     // Groups that are converted can almost certainly be removed entirely
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         // Groups we don't convert. Output the raw line instead.
00079         qcout << rawLine << endl;
00080     }
00081 }
00082 
00083 void parseKey( const QString &group, const QString &key, const QString &value, const QString &rawLine )
00084 {
00085     //qcerr << "*** group='" << group << "'" << endl;
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         // All other keys are ignored for MSN, as these apply to stuff that's
00098         // now in libkopete (and the main app) instead.
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         fixme: insert all other plugins here - martijn
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         // groups we don't convert. output the raw line instead.
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             // We found a comment, leave unchanged
00214             qcout << line << endl;
00215         }
00216         else if ( groupRegExp.exactMatch( line ) )
00217         {
00218             // We found the start of a group, parse it
00219             if ( needFlush )
00220             {
00221                 // ... but we were already working on a group, so finish what
00222                 // we were doing - flush existing group first
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             // We found the a key line
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 // vim: set noet ts=4 sts=4 sw=4:
00248 

kopete/kopete

Skip menu "kopete/kopete"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal