18 #include <qtextstream.h>
21 #include <kstandarddirs.h>
22 #include <kcomponentdata.h>
24 static QTextStream
qcerr( stderr, QIODevice::WriteOnly );
28 KComponentData inst(
"Update script" );
29 QString filename = KStandardDirs::locateLocal(
"data", QLatin1String(
"kopete/contactlist.xml" ) );
32 QFile contactListFile( filename );
33 contactListFile.open( QIODevice::ReadOnly );
34 QDomDocument contactList;
35 contactList.setContent( &contactListFile );
36 contactListFile.close();
37 QDir().rename( filename, filename + QLatin1String(
".bak" ) );
40 QDomElement list = contactList.documentElement();
41 QDomElement mcElement = list.firstChild().toElement();
43 while( !mcElement.isNull() )
47 if( mcElement.tagName() == QLatin1String(
"meta-contact") )
49 QDomElement displayName;
50 QDomElement subcontact;
52 QDomElement elem = mcElement.firstChild().toElement();
53 while( !elem.isNull() )
55 if( elem.tagName() == QLatin1String(
"display-name" ) )
57 if( elem.tagName() == QLatin1String(
"plugin-data" ) )
61 QString pluginId = elem.attribute( QLatin1String(
"plugin-id" ) );
62 bool isProtocol = ( pluginId.contains(
"protocol",
false ) > 0 );
63 bool hasContactId =
false;
64 QDomNode field = elem.firstChild();
65 while( !field.isNull() )
67 QDomElement fieldElem = field.toElement();
69 if( !fieldElem.isNull() &&
70 fieldElem.tagName() == QLatin1String(
"plugin-data-field" ) &&
71 fieldElem.attribute( QLatin1String(
"key" ) ) == QLatin1String(
"contactId" ) )
76 field = field.nextSibling();
79 if( isProtocol && hasContactId )
83 elem = elem.nextSibling().toElement();
89 ( displayName.attribute( QLatin1String(
"trackChildNameChanges" ),
90 QLatin1String(
"0" ) ) == QLatin1String(
"1" ) );
91 if( !displayName.isNull() && !subcontact.isNull() && tracking )
98 nsPID = subcontact.attribute( QLatin1String(
"plugin-id" ) );
99 QDomNode field = subcontact.firstChild();
100 while( !field.isNull() )
102 QDomElement fieldElem = field.toElement();
104 if( !fieldElem.isNull() && fieldElem.tagName() == QLatin1String(
"plugin-data-field" ) )
106 if( fieldElem.attribute( QLatin1String(
"key" ) ) == QLatin1String(
"contactId" ) )
107 nsCID = fieldElem.text();
108 if( fieldElem.attribute( QLatin1String(
"key" ) ) == QLatin1String(
"accountId" ) )
109 nsAID = fieldElem.text();
111 field = field.nextSibling();
115 displayName.setAttribute( QLatin1String(
"nameSourceContactId" ), nsCID );
116 displayName.setAttribute( QLatin1String(
"nameSourcePluginId" ), nsPID );
117 displayName.setAttribute( QLatin1String(
"nameSourceAccountId" ), nsAID );
121 mcElement = mcElement.nextSibling().toElement();
125 contactListFile.open( QIODevice::WriteOnly );
126 QTextStream stream( &contactListFile );
127 stream.setCodec(QTextCodec::codecForName(
"UTF-8"));
128 stream << contactList.toString( 4 );
129 contactListFile.flush();
130 contactListFile.close();
static QTextStream qcerr(stderr, QIODevice::WriteOnly)