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

kopete/kopete

  • sources
  • kde-4.12
  • kdenetwork
  • kopete
  • kopete
  • kconf_update
kopete-account-kconf_update.cpp
Go to the documentation of this file.
1 /*
2  kconf_update app for migrating kopete 0.6.x accounts to 0.7. Code is
3  not up to my normal standards, but it does the job, and since it's
4  supposed to run exactly once on each system that's good enough for me :)
5 
6  Copyright (c) 2003 by Martijn Klingens <klingens@kde.org>
7 
8  Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
9 
10  *************************************************************************
11  * *
12  * This library is free software; you can redistribute it and/or *
13  * modify it under the terms of the GNU Lesser General Public *
14  * License as published by the Free Software Foundation; either *
15  * version 2 of the License, or (at your option) any later version. *
16  * *
17  *************************************************************************
18 */
19 
20 #include <qmap.h>
21 #include <qtextstream.h>
22 #include <qregexp.h>
23 #include <QStringList>
24 
25 static QTextStream qcin ( stdin, QIODevice::ReadOnly );
26 static QTextStream qcout( stdout, QIODevice::WriteOnly );
27 static QTextStream qcerr( stderr, QIODevice::WriteOnly );
28 
29 // Group cache. Yes, I know global vars are ugly :)
30 bool needFlush = false;
31 QString accountId;
32 QString password;
33 QString autoConnect;
34 QString protocol;
35 QMap<QString, QString> pluginData;
36 
37 // Global vars to hold separate IRC vars until we have read all of them
38 QString ircNick;
39 QString ircServer;
40 QString ircPort;
41 
42 /*
43  * Function for (en/de)crypting strings for config file, taken from KMail
44  * Author: Stefan Taferner <taferner@alpin.or.at>
45  */
46 QString cryptStr(const QString &aStr)
47 {
48  QString result;
49  for (unsigned int i = 0; i < aStr.length(); i++)
50  result += (aStr[i].unicode() < 0x20) ? aStr[i] :
51  QChar(0x1001F - aStr[i].unicode());
52  return result;
53 }
54 
55 void parseGroup( const QString &group, const QString &rawLine )
56 {
57  // Groups that are converted can almost certainly be removed entirely
58 
59  if ( group == "MSN" || group == "ICQ" || group == "Oscar" || group == "Gadu" || group == "Jabber" || group == "IRC" )
60  {
61  accountId = "EMPTY";
62  autoConnect = "true";
63 
64  if ( group == "Oscar" )
65  protocol = "AIMProtocol";
66  else
67  protocol = group + "Protocol";
68 
69  password.clear();
70  pluginData.clear();
71 
72  needFlush = true;
73 
74  qcout << "# DELETEGROUP [" << group << "]" << endl;
75  }
76  else
77  {
78  // Groups we don't convert. Output the raw line instead.
79  qcout << rawLine << endl;
80  }
81 }
82 
83 void parseKey( const QString &group, const QString &key, const QString &value, const QString &rawLine )
84 {
85  //qcerr << "*** group='" << group << "'" << endl;
86  if ( group == "MSN" )
87  {
88  if ( key == "UserID" )
89  accountId = value;
90  else if ( key == "Password" )
91  password = value;
92  else if ( key == "AutoConnect" )
93  autoConnect = value;
94  else if ( key == "Nick" )
95  pluginData[ "displayName" ] = value;
96 
97  // All other keys are ignored for MSN, as these apply to stuff that's
98  // now in libkopete (and the main app) instead.
99  }
100  else if ( group == "ICQ" )
101  {
102  if ( key == "UIN" )
103  accountId = value;
104  else if ( key == "Password" )
105  password = value;
106  else if ( key == "AutoConnect" )
107  autoConnect = value;
108  else if ( key == "Nick" )
109  pluginData[ "NickName" ] = value;
110  else if ( key == "Server" )
111  pluginData[ key ] = value;
112  else if ( key == "Port" )
113  pluginData[ key ] = value;
114  }
115  else if ( group == "Oscar" )
116  {
117  if ( key == "ScreenName" )
118  accountId = value;
119  else if ( key == "Password" )
120  password = value;
121  else if ( key == "Server" )
122  pluginData[ key ] = value;
123  else if ( key == "Port" )
124  pluginData[ key ] = value;
125  }
126  else if ( group == "Jabber" )
127  {
128  if ( key == "UserID" )
129  accountId = value;
130  else if ( key == "Password" )
131  password = value;
132  if ( key == "Server" ||
133  key == "Port" || key == "UseSSL" || key == "Resource" )
134  pluginData[ key ] = value;
135  }
136  else if ( group == "Gadu" )
137  {
138  if ( key == "UIN" )
139  accountId = value;
140  else if ( key == "Password" )
141  password = value;
142  else if ( key == "Nick" )
143  pluginData[ "displayName" ] = value;
144  }
145  else if ( group == "IRC" )
146  {
147  if ( key == "Nickname" )
148  ircNick = value;
149  if ( key == "Server" )
150  ircServer = value;
151  if ( key == "Port" )
152  ircPort = value;
153  if ( accountId == "EMPTY" &&
154  !ircNick.isEmpty( ) && !ircServer.isEmpty() &&
155  !ircPort.isEmpty() )
156  {
157  accountId = QString::fromLatin1( "%1@%2:%3" ).arg( ircNick, ircServer, ircPort );
158  }
159  }
160  /*
161  fixme: insert all other plugins here - martijn
162  */
163  else if ( key == "Modules" )
164  {
165  QString newValue = value;
166  newValue.replace ( ".plugin", ".desktop" );
167  qcout << "Plugins=" << newValue;
168  }
169  else
170  {
171  // groups we don't convert. output the raw line instead.
172  qcout << rawLine << endl;
173  }
174 }
175 
176 void flushData( const QString &group )
177 {
178 
179  qcout << "[Account_" << protocol << "_" << accountId << "]" << endl;
180  qcout << "Protocol=" << protocol << endl;
181 
182  if( group == "Jabber" )
183  qcout << "AccountId=" << accountId << "@" << pluginData["Server"] << endl;
184  else
185  qcout << "AccountId=" << accountId << endl;
186 
187  qcout << "Password=" << cryptStr( password ) << endl;
188  qcout << "AutoConnect=" << autoConnect << endl;
189 
190  QMap<QString, QString>::ConstIterator it;
191  for ( it = pluginData.begin(); it != pluginData.end(); ++it )
192  qcout << "PluginData_" << protocol << "_" << it.key() << "=" << it.value() << endl;
193 
194 }
195 
196 int main()
197 {
198  qcin.setCodec(QTextCodec::codecForName("UTF-8"));
199  qcout.setCodec(QTextCodec::codecForName("UTF-8"));
200 
201  QString curGroup;
202 
203  QRegExp groupRegExp( "^\\[(.*)\\]" );
204  QRegExp keyRegExp( "^([a-zA-Z0-9:, _-]*)\\s*=\\s*(.*)\\s*" );
205  QRegExp commentRegExp( "^(#.*)?$" );
206 
207  while ( !qcin.atEnd() )
208  {
209  QString line = qcin.readLine();
210 
211  if ( commentRegExp.exactMatch( line ) )
212  {
213  // We found a comment, leave unchanged
214  qcout << line << endl;
215  }
216  else if ( groupRegExp.exactMatch( line ) )
217  {
218  // We found the start of a group, parse it
219  if ( needFlush )
220  {
221  // ... but we were already working on a group, so finish what
222  // we were doing - flush existing group first
223  flushData ( curGroup );
224  needFlush = false;
225  }
226 
227  curGroup = groupRegExp.capturedTexts()[ 1 ];
228  parseGroup( curGroup, line );
229  }
230  else if ( keyRegExp.exactMatch( line ) )
231  {
232  // We found the a key line
233  parseKey( curGroup, keyRegExp.capturedTexts()[ 1 ], keyRegExp.capturedTexts()[ 2 ], line );
234  }
235  else
236  {
237  qcerr << "** Unknown input line: " << line << endl;
238  }
239  }
240 
241  if ( needFlush )
242  flushData ( curGroup );
243 
244  return 0;
245 }
246 
247 // vim: set noet ts=4 sts=4 sw=4:
248 
qcin
static QTextStream qcin(stdin, QIODevice::ReadOnly)
ircServer
QString ircServer
Definition: kopete-account-kconf_update.cpp:39
qcout
static QTextStream qcout(stdout, QIODevice::WriteOnly)
parseGroup
void parseGroup(const QString &group, const QString &rawLine)
Definition: kopete-account-kconf_update.cpp:55
pluginData
QMap< QString, QString > pluginData
Definition: kopete-account-kconf_update.cpp:35
accountId
QString accountId
Definition: kopete-account-kconf_update.cpp:31
autoConnect
QString autoConnect
Definition: kopete-account-kconf_update.cpp:33
password
QString password
Definition: kopete-account-kconf_update.cpp:32
main
int main()
Definition: kopete-account-kconf_update.cpp:196
flushData
void flushData(const QString &group)
Definition: kopete-account-kconf_update.cpp:176
ircPort
QString ircPort
Definition: kopete-account-kconf_update.cpp:40
ircNick
QString ircNick
Definition: kopete-account-kconf_update.cpp:38
parseKey
void parseKey(const QString &group, const QString &key, const QString &value, const QString &rawLine)
Definition: kopete-account-kconf_update.cpp:83
protocol
QString protocol
Definition: kopete-account-kconf_update.cpp:34
needFlush
bool needFlush
Definition: kopete-account-kconf_update.cpp:30
qcerr
static QTextStream qcerr(stderr, QIODevice::WriteOnly)
cryptStr
QString cryptStr(const QString &aStr)
Definition: kopete-account-kconf_update.cpp:46
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/kopete

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

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal