summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-27 10:27:34 (UTC)
committer zautrix <zautrix>2004-10-27 10:27:34 (UTC)
commit835411009ea43a8182b16b78c03b11616f989f50 (patch) (unidiff)
tree451ba042a06173d4aa54fa0ef177fb80bd7fa1da
parent4efb020e137fbb8b94d845a2aa0ffc894561aea9 (diff)
downloadkdepimpi-835411009ea43a8182b16b78c03b11616f989f50.zip
kdepimpi-835411009ea43a8182b16b78c03b11616f989f50.tar.gz
kdepimpi-835411009ea43a8182b16b78c03b11616f989f50.tar.bz2
added kde AB sync cl prog
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--desktop/Makefile1
-rw-r--r--kde2file/abdump/abdump.pro13
-rw-r--r--kde2file/abdump/main.cpp193
3 files changed, 207 insertions, 0 deletions
diff --git a/desktop/Makefile b/desktop/Makefile
index bf83377..752af12 100644
--- a/desktop/Makefile
+++ b/desktop/Makefile
@@ -2,12 +2,13 @@ export KDEPIMDIR = $(shell pwd)
2 2
3export KDEPIM_VERSION=$(shell sed -e 's/.*\"\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/' < ../version) 3export KDEPIM_VERSION=$(shell sed -e 's/.*\"\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/' < ../version)
4export KDEDIR=/kde_dev/kde 4export KDEDIR=/kde_dev/kde
5export KDE_DEV_DIR=/kde_dev/kde32/build/kdepim33_proko2_new/ 5export KDE_DEV_DIR=/kde_dev/kde32/build/kdepim33_proko2_new/
6all: 6all:
7 cd ../kde2file/caldump;qmake;make 7 cd ../kde2file/caldump;qmake;make
8 cd ../kde2file/abdump;qmake;make
8 9
9 install: 10 install:
10 mkdir -p /opt/kdepimpi 11 mkdir -p /opt/kdepimpi
11 mkdir -p /opt/kde3/share/applnk/PIM-pi 12 mkdir -p /opt/kde3/share/applnk/PIM-pi
12 rm -rf /opt/kdepimpi/* 13 rm -rf /opt/kdepimpi/*
13 rm -f /usr/lib/libmicro* 14 rm -f /usr/lib/libmicro*
diff --git a/kde2file/abdump/abdump.pro b/kde2file/abdump/abdump.pro
new file mode 100644
index 0000000..b6b6374
--- a/dev/null
+++ b/kde2file/abdump/abdump.pro
@@ -0,0 +1,13 @@
1
2TEMPLATE = app
3CONFIG += qt
4include( ../../variables.pri )
5DESTDIR= ../../bin
6 TARGET = kdeabdump
7INCLUDEPATH += . $(KDEDIR)/include $(KDE_DEV_DIR)/libkdepim
8#LIBS += $(KDEDIR)/lib/libkcal.so
9LIBS += $(KDEDIR)/lib/libkabc.so
10LIBS += $(KDEDIR)/lib/libkdepim.so
11HEADERS +=
12
13SOURCES += main.cpp
diff --git a/kde2file/abdump/main.cpp b/kde2file/abdump/main.cpp
new file mode 100644
index 0000000..d452ee9
--- a/dev/null
+++ b/kde2file/abdump/main.cpp
@@ -0,0 +1,193 @@
1/*******************************************************************************
2 * main.cpp *
3 * *
4 *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 * *
20 * As a special exception, permission is given to link this program *
21 * with any edition of Qt, and distribute the resulting executable, *
22 * without including the source code for Qt in the source distribution. *
23 * *
24 ******************************************************************************/
25
26#include <kcmdlineargs.h>
27#include <kaboutdata.h>
28#include <klocale.h>
29#include <kglobal.h>
30#include <kconfig.h>
31#include <kstandarddirs.h>
32#include <kdebug.h>
33
34#include <kabc/addressbook.h>
35#include <kabc/stdaddressbook.h>
36#include <kabc/resource.h>
37#include <kabc/vcardconverter.h>
38
39#include <qdatetime.h>
40#include <qfile.h>
41#include <qdir.h>
42#include <qapplication.h>
43
44#include <stdlib.h>
45#include <iostream>
46
47using namespace std;
48
49static const char progName[] = "kdecalendar";
50static const char progDisplay[] = "KDE_Addressbook";
51static const char progVersion[] = "33.1/3";
52static const char progDesc[] = "A command line interface to KDE addressbooks";
53
54
55static KCmdLineOptions options[] =
56 {
57 { "dump",
58 I18N_NOOP( "Dumps addressbook" ), 0 },
59 { "read",
60 I18N_NOOP( "Reads addressbook" ), 0 },
61 KCmdLineLastOption
62 };
63
64int main( int argc, char *argv[] )
65{
66 KAboutData aboutData(
67 progName, // internal program name
68 I18N_NOOP( progDisplay ), // displayable program name.
69 progVersion, // version string
70 I18N_NOOP( progDesc ), // short porgram description
71 KAboutData::License_GPL, // license type
72 "(c) 2004, Lutz Rogowski", // copyright statement
73 0, // any free form text
74 "", // program home page address
75 "bugs.kde.org" // bug report email address
76 );
77
78
79 // KCmdLineArgs::init() final 'true' argument indicates no commandline options
80 // for QApplication/KApplication (no KDE or Qt options)
81 KCmdLineArgs::init( argc, argv, &aboutData, true );
82 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
83
84 KInstance ins ( progName );
85
86 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
87
88 bool read = false;
89 if ( args->isSet( "read" ) ) {
90 read = true;
91 qDebug("read ");
92 }
93 QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf";
94
95 KABC::StdAddressBook* standardAddressBook = KABC::StdAddressBook::self();
96 standardAddressBook->setAutomaticSave( false );
97 qDebug("************************************* ");
98 qDebug("***************kdeABdump************* ");
99 qDebug("************************************* ");
100 if ( !read ) {
101 KABC::AddressBook::Iterator it;
102 KABC::VCardConverter converter;
103 QString datastream;
104 for( it = standardAddressBook->begin(); it != standardAddressBook->end(); ++it ) {
105 if ( (*it).isEmpty() || ! (*it).resource() )
106 continue;
107 if ( (*it).resource()->readOnly() )
108 continue;
109 KABC::Addressee a = ( *it );
110 QString vcard = converter.createVCard( a );
111 vcard += QString("\r\n");
112 datastream += vcard;
113 }
114 QFile outFile(fileName);
115 if ( outFile.open(IO_WriteOnly) ) {
116 QTextStream t( &outFile ); // use a text stream
117 t.setEncoding( QTextStream::UnicodeUTF8 );
118 t <<datastream;
119 t << "\r\n\r\n";
120 outFile.close();
121 }
122 } else {
123 //Addressee::List aList;//parseVCards( const QString& vcard );
124 KABC::Addressee::List list;
125 int added = 0, changedC = 0, deleted = 0;
126 QFile file( fileName );
127 if ( file.open( IO_ReadOnly ) ) {
128 QTextStream t( &file ); // use a text stream
129 t.setEncoding( QTextStream::UnicodeUTF8 );
130 QString data;
131 data = t.read();
132 file.close();
133 KABC::VCardConverter converter;
134 list = converter.parseVCards( data );
135 qDebug("kdeABdump::file has %d entries", list.count());
136
137 KABC::Addressee::List::Iterator it;
138 for ( it = list.begin();it != list.end();++it) {
139 bool changed = ((*it).custom( "KADDRESSBOOK", "X-ExternalID" ) == "changed");
140 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
141 //qDebug("ext %s ", (*it).custom( "KADDRESSBOOK", "X-ExternalID" ).latin1());
142 if ( changed ) {
143 //qDebug("changed Addressee found! ");
144 KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() );
145 if ( ! std.isEmpty() )
146 (*it).setResource(std.resource());
147 standardAddressBook->insertAddressee( (*it) );
148 ++changedC;
149 } else {
150 //maybe added?
151 KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() );
152 if ( std.isEmpty() ) {
153 standardAddressBook->insertAddressee( (*it) );
154 ++added;
155 }
156 }
157 }
158 KABC::AddressBook::Iterator itA = standardAddressBook->begin();
159 KABC::AddressBook::Iterator it2 ;
160 while ( itA != standardAddressBook->end() ) {
161 bool found = false;
162 KABC::Addressee::List::Iterator itL;
163 for ( itL = list.begin();itL != list.end();++itL) {
164 if ( (*itL).uid() == (*itA).uid() ) {
165 found = true;
166 break;
167 }
168 }
169 if ( !found ) {
170 it2 = itA;
171 ++itA;
172 standardAddressBook->removeAddressee( it2 );
173 ++deleted;
174 } else {
175 ++itA;
176 }
177 }
178
179 //standardAddressBook->saveAll();
180 standardAddressBook->setAutomaticSave( true );
181 qDebug("************************************* ");
182 qDebug("*************kdeABdump*************** ");
183 qDebug("************************************* ");
184 qDebug("Addressbook entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", changedC,deleted, added, fileName.latin1());
185 } else
186 qDebug("error open file ");
187 }
188
189 KABC::StdAddressBook::close();
190
191 qDebug("ente ");
192 return 0;
193}