• 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-nameTracking.cpp
Go to the documentation of this file.
1 /*
2  kconf_update app for updating the contact list format ( <= 0.9.0) for MetaContacts to
3  track the name of a subcontact.
4 
5  Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
6 
7  *************************************************************************
8  * *
9  * This library is free software; you can redistribute it and/or *
10  * modify it under the terms of the GNU Lesser General Public *
11  * License as published by the Free Software Foundation; either *
12  * version 2 of the License, or (at your option) any later version. *
13  * *
14  *************************************************************************
15 */
16 
17 #include <qdir.h>
18 #include <qtextstream.h>
19 #include <qdom.h>
20 
21 #include <kstandarddirs.h>
22 #include <kcomponentdata.h>
23 
24 static QTextStream qcerr( stderr, QIODevice::WriteOnly );
25 
26 int main()
27 {
28  KComponentData inst( "Update script" );
29  QString filename = KStandardDirs::locateLocal( "data", QLatin1String( "kopete/contactlist.xml" ) );
30 
31  // Load contact list & save backup.
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" ) );
38 
39  // parse the XML file
40  QDomElement list = contactList.documentElement();
41  QDomElement mcElement = list.firstChild().toElement();
42 
43  while( !mcElement.isNull() )
44  {
45 
46  // update all the MetaContacts
47  if( mcElement.tagName() == QLatin1String("meta-contact") )
48  {
49  QDomElement displayName;
50  QDomElement subcontact;
51 
52  QDomElement elem = mcElement.firstChild().toElement();
53  while( !elem.isNull() )
54  {
55  if( elem.tagName() == QLatin1String( "display-name" ) )
56  displayName = elem;
57  if( elem.tagName() == QLatin1String( "plugin-data" ) )
58  {
59  // check if it's a contact by checking for "protocol" substring in the tag,
60  // and the presence of a contactId child element.
61  QString pluginId = elem.attribute( QLatin1String( "plugin-id" ) );
62  bool isProtocol = ( pluginId.contains( "protocol", false ) > 0 ); // case-insensitive search
63  bool hasContactId = false;
64  QDomNode field = elem.firstChild();
65  while( !field.isNull() )
66  {
67  QDomElement fieldElem = field.toElement();
68 
69  if( !fieldElem.isNull() &&
70  fieldElem.tagName() == QLatin1String( "plugin-data-field" ) &&
71  fieldElem.attribute( QLatin1String( "key" ) ) == QLatin1String( "contactId" ) )
72  {
73  hasContactId = true;
74  break;
75  }
76  field = field.nextSibling();
77  }
78 
79  if( isProtocol && hasContactId )
80  subcontact = elem;
81  }
82 
83  elem = elem.nextSibling().toElement();
84  } // end while
85 
86  // check if we're even tracking the subcontact's name
87  // if displayName.isNull(), it simply won't find the attribute; no harm done
88  bool tracking =
89  ( displayName.attribute( QLatin1String( "trackChildNameChanges" ),
90  QLatin1String( "0" ) ) == QLatin1String( "1" ) );
91  if( !displayName.isNull() && !subcontact.isNull() && tracking )
92  {
93  // collect info
94  QString nsCID;
95  QString nsPID;
96  QString nsAID;
97 
98  nsPID = subcontact.attribute( QLatin1String( "plugin-id" ) );
99  QDomNode field = subcontact.firstChild();
100  while( !field.isNull() )
101  {
102  QDomElement fieldElem = field.toElement();
103 
104  if( !fieldElem.isNull() && fieldElem.tagName() == QLatin1String( "plugin-data-field" ) )
105  {
106  if( fieldElem.attribute( QLatin1String( "key" ) ) == QLatin1String( "contactId" ) )
107  nsCID = fieldElem.text();
108  if( fieldElem.attribute( QLatin1String( "key" ) ) == QLatin1String( "accountId" ) )
109  nsAID = fieldElem.text();
110  }
111  field = field.nextSibling();
112  }
113 
114  // create the tracking info
115  displayName.setAttribute( QLatin1String( "nameSourceContactId" ), nsCID );
116  displayName.setAttribute( QLatin1String( "nameSourcePluginId" ), nsPID );
117  displayName.setAttribute( QLatin1String( "nameSourceAccountId" ), nsAID );
118  }
119  }
120 
121  mcElement = mcElement.nextSibling().toElement();
122  }
123 
124  // Save converted contact list
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();
131 
132  return 0;
133 }
134 
135 // vim: set noet ts=4 sts=4 sw=4:
136 
main
int main()
Definition: kopete-nameTracking.cpp:26
qcerr
static QTextStream qcerr(stderr, QIODevice::WriteOnly)
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