28 #include <hblistview.h> |
28 #include <hblistview.h> |
29 #include <qversitreader.h> |
29 #include <qversitreader.h> |
30 #include <qversitcontactimporter.h> |
30 #include <qversitcontactimporter.h> |
31 #include <qversitdocument.h> |
31 #include <qversitdocument.h> |
32 #include <xqserviceprovider.h> |
32 #include <xqserviceprovider.h> |
|
33 #include <cntabstractengine.h> |
33 |
34 |
34 #include <QApplication> |
35 #include <QApplication> |
35 #include <QPixmap> |
36 #include <QPixmap> |
36 #include <QFile> |
37 #include <QFile> |
37 #include <QUrl> |
38 #include <QUrl> |
|
39 #include <QTextCodec> |
|
40 |
|
41 const int Latin1CharSetMIB = 4; |
38 |
42 |
39 CntServices::CntServices() : |
43 CntServices::CntServices() : |
40 mViewManager(NULL), |
44 mViewManager(NULL), |
41 mCurrentProvider(NULL), |
45 mCurrentProvider(NULL), |
42 mIsQuittable(true) |
46 mIsQuittable(true) |
69 { |
73 { |
70 CNT_LOG |
74 CNT_LOG |
71 } |
75 } |
72 |
76 |
73 |
77 |
|
78 void CntServices::setEngine( CntAbstractEngine& aEngine ) |
|
79 { |
|
80 CNT_LOG |
|
81 mEngine = &aEngine; |
|
82 mViewManager = &mEngine->viewManager(); |
|
83 CntServiceViewManager* srvMng = static_cast<CntServiceViewManager*>(mViewManager); |
|
84 connect(srvMng, SIGNAL(applicationClosed()), this, SLOT(terminateService())); |
|
85 } |
|
86 /* |
74 void CntServices::setViewManager( CntAbstractViewManager& aViewManager ) |
87 void CntServices::setViewManager( CntAbstractViewManager& aViewManager ) |
75 { |
88 { |
76 CNT_LOG |
89 CNT_LOG |
77 mViewManager = &aViewManager; |
90 mViewManager = &aViewManager; |
78 CntServiceViewManager* srvMng = static_cast<CntServiceViewManager*>(mViewManager); |
91 CntServiceViewManager* srvMng = static_cast<CntServiceViewManager*>(mViewManager); |
79 connect(srvMng, SIGNAL(applicationClosed()), this, SLOT(terminateService())); |
92 connect(srvMng, SIGNAL(applicationClosed()), this, SLOT(terminateService())); |
80 } |
93 } |
81 |
94 */ |
82 |
95 |
83 void CntServices::singleFetch( |
96 void CntServices::singleFetch( |
84 const QString &title, const QString &action, |
97 const QString &title, const QString &action, |
85 CntAbstractServiceProvider& aServiceProvider ) |
98 CntAbstractServiceProvider& aServiceProvider ) |
86 { |
99 { |
169 mViewManager->changeView(params); |
182 mViewManager->changeView(params); |
170 CNT_EXIT |
183 CNT_EXIT |
171 } |
184 } |
172 |
185 |
173 |
186 |
174 void CntServices::editCreateNewFromVCard(const QString &vCardFile, |
187 void CntServices::editCreateNewFromVCard(const QString &fileName, |
175 CntAbstractServiceProvider& aServiceProvider ) |
188 CntAbstractServiceProvider& aServiceProvider ) |
176 { |
189 { |
177 CNT_ENTRY |
190 CNT_ENTRY |
178 mCurrentProvider = &aServiceProvider; |
191 mCurrentProvider = &aServiceProvider; |
179 |
192 |
180 CntImageUtility imageUtility; |
193 CntImageUtility imageUtility; |
181 QContact contact; |
194 QContact contact; |
182 QVersitReader reader; |
195 QVersitReader reader; |
183 QFile file(vCardFile); |
196 QFile inputFile(fileName); |
184 if (!file.open(QIODevice::ReadOnly)) |
197 if (!inputFile.open(QIODevice::ReadOnly)) |
185 return; |
198 return; |
186 reader.setDevice(&file); |
199 |
187 |
200 // Versit parser default codec is UTF-8 |
|
201 // Check if decoding text to unicode is possible, else use Latin-1 text codec |
|
202 QByteArray ba = inputFile.readAll(); |
|
203 if(!ba.isEmpty()) |
|
204 { |
|
205 QTextCodec *c = QTextCodec::codecForUtfText(ba); |
|
206 // Text codec returned is Latin-1, set default to Latin-1 |
|
207 if(c->mibEnum()==Latin1CharSetMIB) |
|
208 reader.setDefaultCodec(QTextCodec::codecForName("ISO 8859-1")); |
|
209 } |
|
210 inputFile.close(); |
|
211 |
|
212 QFile vCardFile(fileName); |
|
213 if (!vCardFile.open(QIODevice::ReadOnly)) |
|
214 return; |
|
215 reader.setDevice(&vCardFile); |
188 reader.startReading(); |
216 reader.startReading(); |
189 reader.waitForFinished(); |
217 reader.waitForFinished(); |
190 // Use the resulting document(s)... |
218 // Use the resulting document(s)... |
191 QVersitContactImporter importer; |
219 QVersitContactImporter importer; |
192 QList<QVersitDocument> versitDocuments = reader.results(); |
220 QList<QVersitDocument> versitDocuments = reader.results(); |
195 { |
223 { |
196 QList<QContact> contacts = importer.contacts(); |
224 QList<QContact> contacts = importer.contacts(); |
197 if(contacts.count() > 0) |
225 if(contacts.count() > 0) |
198 contact = contacts.first(); |
226 contact = contacts.first(); |
199 } |
227 } |
200 file.close(); |
228 vCardFile.close(); |
201 |
229 |
202 // Save thumbnail images |
230 // Save thumbnail images |
203 QList<QContactThumbnail> details = contact.details<QContactThumbnail>(); |
231 QList<QContactThumbnail> details = contact.details<QContactThumbnail>(); |
204 for (int i = 0;i < details.count();i++) |
232 for (int i = 0;i < details.count();i++) |
205 { |
233 { |
531 mCurrentProvider->CompleteServiceAndCloseApp( retValue ); |
559 mCurrentProvider->CompleteServiceAndCloseApp( retValue ); |
532 } |
560 } |
533 CNT_EXIT |
561 CNT_EXIT |
534 } |
562 } |
535 |
563 |
|
564 // This method is inherited from CntAbstractServiceProvider |
|
565 void CntServices::overrideReturnValue(const QVariant& retValue) |
|
566 { |
|
567 CNT_ENTRY |
|
568 if ( mCurrentProvider ) |
|
569 { |
|
570 mCurrentProvider->overrideReturnValue( retValue ); |
|
571 } |
|
572 CNT_EXIT |
|
573 } |
|
574 |
|
575 // This method is inherited from CntAbstractServiceProvider |
|
576 bool CntServices::allowSubViewsExit() |
|
577 { |
|
578 bool allow = true; |
|
579 if ( mCurrentProvider ) |
|
580 { |
|
581 allow = mCurrentProvider->allowSubViewsExit(); |
|
582 } |
|
583 |
|
584 return allow; |
|
585 } |
|
586 |
536 void CntServices::terminateService() |
587 void CntServices::terminateService() |
537 { |
588 { |
538 CNT_ENTRY |
589 CNT_ENTRY |
539 if ( mCurrentProvider ) |
590 if ( mCurrentProvider ) |
540 { |
591 { |