Diffstat (limited to 'plugindtmkabc/qtopiaaddressbookplugin.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | plugindtmkabc/qtopiaaddressbookplugin.cpp | 167 |
1 files changed, 0 insertions, 167 deletions
diff --git a/plugindtmkabc/qtopiaaddressbookplugin.cpp b/plugindtmkabc/qtopiaaddressbookplugin.cpp deleted file mode 100644 index 37dd4e2..0000000 --- a/plugindtmkabc/qtopiaaddressbookplugin.cpp +++ b/dev/null | |||
@@ -1,167 +0,0 @@ | |||
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 | |||
12 | QtopiaAddressBookPlugin::QtopiaAddressBookPlugin() : ref(0) { | ||
13 | qDebug("DTMAddressBookPlugin::DTMAddressBookPlugin"); | ||
14 | QString command ="db2file address -r -c utf8 > /tmp/addressDTM.txt"; | ||
15 | system ( command.latin1() ); | ||
16 | } | ||
17 | |||
18 | QtopiaAddressBookPlugin::~QtopiaAddressBookPlugin() { | ||
19 | } | ||
20 | |||
21 | KABC::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 | |||
88 | QString 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 | } | ||
147 | QString QtopiaAddressBookPlugin::name() { | ||
148 | return "DTM addressbook plugin"; | ||
149 | } | ||
150 | |||
151 | QRESULT 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 | |||
163 | Q_EXPORT_INTERFACE() | ||
164 | { | ||
165 | Q_CREATE_INSTANCE( QtopiaAddressBookPlugin ) | ||
166 | } | ||
167 | |||