summaryrefslogtreecommitdiffabout
path: root/plugindtmkabc
authorzautrix <zautrix>2004-07-01 19:28:46 (UTC)
committer zautrix <zautrix>2004-07-01 19:28:46 (UTC)
commitdf5b4df6bc00ea8acfee0b11a335a9d2f39d04dc (patch) (unidiff)
tree34a8459c68c1fdd849006452c45f34a5ad38eaab /plugindtmkabc
parent574570db1963fd729bb40a778ae3fc6a71ffc221 (diff)
downloadkdepimpi-df5b4df6bc00ea8acfee0b11a335a9d2f39d04dc.zip
kdepimpi-df5b4df6bc00ea8acfee0b11a335a9d2f39d04dc.tar.gz
kdepimpi-df5b4df6bc00ea8acfee0b11a335a9d2f39d04dc.tar.bz2
Added missing DTM plugin
Diffstat (limited to 'plugindtmkabc') (more/less context) (show whitespace changes)
-rw-r--r--plugindtmkabc/plugindtmkabcE.pro20
-rw-r--r--plugindtmkabc/qtopiaaddressbookplugin.cpp167
-rw-r--r--plugindtmkabc/qtopiaaddressbookplugin.h24
-rw-r--r--plugindtmkabc/qtopiaaddressee.cpp26
-rw-r--r--plugindtmkabc/qtopiaaddressee.h20
5 files changed, 257 insertions, 0 deletions
diff --git a/plugindtmkabc/plugindtmkabcE.pro b/plugindtmkabc/plugindtmkabcE.pro
new file mode 100644
index 0000000..56c08fa
--- a/dev/null
+++ b/plugindtmkabc/plugindtmkabcE.pro
@@ -0,0 +1,20 @@
1 TEMPLATE= lib
2 #TEMPLATE= app
3 CONFIG = qt warn_on release
4
5 TARGET = dtmkabc
6OBJECTS_DIR = obj/$(PLATFORM)
7MOC_DIR = moc
8DESTDIR=$(QPEDIR)/plugins/korganizer
9#DESTDIR=.
10INCLUDEPATH += ../libkabcwrap $(QPEDIR)/include
11DEFINES +=
12LIBS += -lmicrokabc
13
14HEADERS = \
15 qtopiaaddressbookplugin.h \
16 qtopiaaddressee.h
17
18SOURCES = \
19 qtopiaaddressbookplugin.cpp \
20 qtopiaaddressee.cpp
diff --git a/plugindtmkabc/qtopiaaddressbookplugin.cpp b/plugindtmkabc/qtopiaaddressbookplugin.cpp
new file mode 100644
index 0000000..37dd4e2
--- a/dev/null
+++ b/plugindtmkabc/qtopiaaddressbookplugin.cpp
@@ -0,0 +1,167 @@
1#include <qwidget.h>
2#include <qlayout.h>
3#include <qlistbox.h>
4#include <qstring.h>
5#include <qfile.h>
6#include <qtextstream.h>
7#include <qtextcodec.h>
8#include <stdlib.h>
9#include "qtopiaaddressbookplugin.h"
10#include "qtopiaaddressee.h"
11
12QtopiaAddressBookPlugin::QtopiaAddressBookPlugin() : ref(0) {
13 qDebug("DTMAddressBookPlugin::DTMAddressBookPlugin");
14 QString command ="db2file address -r -c utf8 > /tmp/addressDTM.txt";
15 system ( command.latin1() );
16}
17
18QtopiaAddressBookPlugin::~QtopiaAddressBookPlugin() {
19}
20
21KABC::Addressee::List QtopiaAddressBookPlugin::getAddressees() {
22
23 qDebug("Start: DTMAddressBookPlugin::getAddressees");
24
25 KABC::Addressee::List result;
26 QString text;
27 QString fileName = "/tmp/addressDTM.txt";
28 QFile file( fileName );
29 if (!file.open( IO_ReadOnly ) ) {
30 return result;
31 }
32 QTextStream ts( &file );
33 ts.setCodec( QTextCodec::codecForName("utf8") );
34 text = ts.read();
35 file.close();
36
37 QStringList templist;
38 QString tempString;
39 int start = 0;
40 int len = text.length();
41 int end = text.find ("\n",start)+1;
42 bool ok = true;
43 start = end;
44 int lastStart1 = -1;
45 int lastStart2 = -1;
46 while ( start > 0 ) {
47 //qDebug("while start %d ", start);
48 if ( lastStart1 == start )
49 break;
50 lastStart1 =start;
51 templist.clear();
52 ok = true;
53 int iii = 0;
54 while ( ok ) {
55
56 // qDebug("while ok %d ", start);
57
58 if ( lastStart2 == start )
59 break;
60 lastStart2 =start;
61 tempString = getPart( text, ok, start );
62 //if ( ! tempString.isEmpty() )
63 //qDebug("tempString %s %d",tempString.latin1(), iii);
64 iii++;
65 if ( start >= len || start == 0 ) {
66 start = 0;
67 ok = false;
68 }
69 if ( tempString.right(1) =="\n" )
70 tempString = tempString.left( tempString.length()-1);
71 //if ( ok )
72 templist.append( tempString );
73 //qDebug("%d ---%s---", templist.count(),tempString.latin1() );
74 }
75 result.append(QtopiaAddressee(templist));
76 //qDebug("name %s ",templist[2].latin1() );
77 //qDebug("name %s ",templist[4].latin1() );
78 //qDebug("name %s ",templist[5].latin1() );
79 //qDebug("name %s ",templist[40].latin1() );
80 }
81
82
83 qDebug("End: DTMAddressBookPlugin::getAddressees");
84
85 return result;
86}
87
88QString QtopiaAddressBookPlugin::getPart( const QString& text , bool &ok, int &start )
89{
90 //qDebug("start %d ", start);
91
92 QString retval ="";
93 if ( text.at(start) == '"' ) {
94 if ( text.mid( start,2) == "\"\"" && !( text.mid( start+2,1) == "\"")) {
95 start = start +2;
96 if ( text.mid( start,1) == "," ) {
97 start += 1;
98 }
99 retval = "";
100 if ( text.mid( start,1) == "\n" ) {
101 start += 1;
102 ok = false;
103 }
104 return retval;
105 }
106 int hk = start+1;
107 hk = text.find ('"',hk);
108 while ( text.at(hk+1) == '"' )
109 hk = text.find ('"',hk+2);
110 retval = text.mid( start+1, hk-start-1);
111 start = hk+1;
112 retval.replace( QRegExp("\"\""), "\"");
113 if ( text.mid( start,1) == "," ) {
114 start += 1;
115 }
116 if ( text.mid( start,1) == "\n" ) {
117 start += 1;
118 ok = false;
119 }
120 //qDebug("retval***%s*** ",retval.latin1() );
121 return retval;
122
123 } else {
124 int nl = text.find ("\n",start);
125 int kom = text.find (',',start);
126 if ( kom < nl ) {
127 // qDebug("kom < nl %d ", kom);
128 retval = text.mid(start, kom-start);
129 start = kom+1;
130 return retval;
131 } else {
132 if ( nl == kom ) {
133 // qDebug(" nl == kom ");
134 start = 0;
135 ok = false;
136 return "0";
137 }
138 // qDebug(" nl < kom ", nl);
139 retval = text.mid( start, nl-start);
140 ok = false;
141 start = nl+1;
142 return retval;
143 }
144 }
145
146}
147QString QtopiaAddressBookPlugin::name() {
148 return "DTM addressbook plugin";
149}
150
151QRESULT QtopiaAddressBookPlugin::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
152{
153 *iface = 0;
154 if ( uuid == IID_QUnknown )
155 *iface = this;
156 else if ( uuid == IID_KOAddressBookInterface )
157 *iface = this;
158 if ( *iface )
159 (*iface)->addRef();
160 return QS_OK;
161}
162
163Q_EXPORT_INTERFACE()
164{
165 Q_CREATE_INSTANCE( QtopiaAddressBookPlugin )
166}
167
diff --git a/plugindtmkabc/qtopiaaddressbookplugin.h b/plugindtmkabc/qtopiaaddressbookplugin.h
new file mode 100644
index 0000000..abedf73
--- a/dev/null
+++ b/plugindtmkabc/qtopiaaddressbookplugin.h
@@ -0,0 +1,24 @@
1#ifndef QTOPIA_ADDRESS_BOOK_PLUGIN_H
2#define QTOPIA_ADDRESS_BOOK_PLUGIN_H
3#include <kabc/koaddressbookinterface.h>
4#include <kabc/addressee.h>
5#include <qstring.h>
6
7
8class QtopiaAddressBookPlugin : public KOAddressBookInterface {
9
10 public:
11 QtopiaAddressBookPlugin();
12 virtual ~QtopiaAddressBookPlugin();
13 QString name();
14 KABC::Addressee::List getAddressees();
15 QRESULT queryInterface( const QUuid&, QUnknownInterface** );
16 Q_REFCOUNT
17
18 protected:
19 ulong ref;
20 QString getPart( const QString & , bool& , int &start );
21 private:
22};
23#endif
24
diff --git a/plugindtmkabc/qtopiaaddressee.cpp b/plugindtmkabc/qtopiaaddressee.cpp
new file mode 100644
index 0000000..e8e49f5
--- a/dev/null
+++ b/plugindtmkabc/qtopiaaddressee.cpp
@@ -0,0 +1,26 @@
1#include "qtopiaaddressee.h"
2
3QtopiaAddressee::QtopiaAddressee(const QStringList& contact) {
4 setPimContact(contact);
5}
6
7QtopiaAddressee::QtopiaAddressee() {
8 empty = true;
9}
10
11void QtopiaAddressee::setPimContact(const QStringList& contact) {
12 if ( contact[40].isEmpty() )
13 id = contact[0];
14 else
15 id = contact[40];
16 fName = contact[2];
17 rName = contact[2];
18 pEmail = contact[40];
19 empty = false;
20 mails.clear();
21 mobilehomephone = contact[30] ;
22 workphone = contact[16];
23 homephone = contact[31];
24 //mails = pimContact.emailList();
25}
26
diff --git a/plugindtmkabc/qtopiaaddressee.h b/plugindtmkabc/qtopiaaddressee.h
new file mode 100644
index 0000000..f7d18a3
--- a/dev/null
+++ b/plugindtmkabc/qtopiaaddressee.h
@@ -0,0 +1,20 @@
1#include <qstringlist.h>
2#include <kabc/addressee.h>
3
4#ifndef QTOPIA_ADDRESSE_H
5#define QTOPIA_ADDRESSE_H
6
7class QtopiaAddressee : public KABC::Addressee {
8
9 public:
10
11 QtopiaAddressee(const QStringList& contact);
12 QtopiaAddressee();
13 void setPimContact(const QStringList& contact);
14
15 private:
16
17};
18
19#endif
20