summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-07-17 00:38:43 (UTC)
committer ulf69 <ulf69>2004-07-17 00:38:43 (UTC)
commit01570860c92be8977a1ba558ae7c5f15d4635851 (patch) (unidiff)
tree2f3fead3ad0d2b0185d032fb3982c32c4fa15904
parent2439711b1ac7ee38269baff704293eb37a27f6c9 (diff)
downloadkdepimpi-01570860c92be8977a1ba558ae7c5f15d4635851.zip
kdepimpi-01570860c92be8977a1ba558ae7c5f15d4635851.tar.gz
kdepimpi-01570860c92be8977a1ba558ae7c5f15d4635851.tar.bz2
implementation of sharp import/export resourcehandling
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.h10
-rw-r--r--kabc/plugins/sharpdtm/sharpdtmE.pro2
-rw-r--r--kaddressbook/xxport/qtopia/qtopia_xxport.cpp49
3 files changed, 30 insertions, 31 deletions
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.h b/kabc/plugins/sharpdtm/resourcesharpdtm.h
index 32d0be1..d2e2a52 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.h
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.h
@@ -19,92 +19,92 @@
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28 28
29#ifndef KABC_RESOURCESHARPDTM_H 29#ifndef KABC_RESOURCESHARPDTM_H
30#define KABC_RESOURCESHARPDTM_H 30#define KABC_RESOURCESHARPDTM_H
31 31
32#include <kconfig.h> 32#include <kconfig.h>
33#include <kdirwatch.h> 33#include <kdirwatch.h>
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36 36
37#include "resource.h" 37#include "resource.h"
38 38
39 39
40namespace KABC { 40namespace KABC {
41 41
42class ResourceConfigWidget; 42class ResourceConfigWidget;
43class QtopiaConverter; 43class SharpDTMConverter;
44 44
45/** 45/**
46 @internal 46 @internal
47*/ 47*/
48class ResourceSharpDTM : public Resource 48class ResourceSharpDTM : public Resource
49{ 49{
50 Q_OBJECT 50 Q_OBJECT
51 51
52public: 52public:
53 53
54 /** 54 /**
55 Constructor. 55 Constructor.
56 56
57 @param cfg The config object where custom resource settings are stored. 57 @param cfg The config object where custom resource settings are stored.
58 */ 58 */
59 ResourceSharpDTM( const KConfig *cfg ); 59 ResourceSharpDTM( const KConfig *cfg );
60 60
61 /** 61 /**
62 Construct file resource on file @arg fileName using format @arg formatName. 62 Construct file resource on file @arg fileName using format @arg formatName.
63 */ 63 */
64 ResourceSharpDTM( const QString &fileName ); 64 ResourceSharpDTM( const QString &fileName );
65 65
66 /** 66 /**
67 * Destructor. 67 * Destructor.
68 */ 68 */
69 ~ResourceSharpDTM(); 69 ~ResourceSharpDTM();
70 70
71 /** 71 /**
72 Writes the config back. 72 Writes the config back.
73 */ 73 */
74 virtual void writeConfig( KConfig *cfg ); 74 virtual void writeConfig( KConfig *cfg );
75 75
76 /** 76 /**
77 * Tries to open the file and checks for the proper format. 77 * Tries to open the file and checks for the proper format.
78 * This method should be called before @ref load(). 78 * This method should be called before @ref load().
79 */ 79 */
80 virtual bool doOpen(); 80 virtual bool doOpen();
81 81
82 /** 82 /**
83 * Closes the file again. 83 * Closes the file again.
84 */ 84 */
85 virtual void doClose(); 85 virtual void doClose();
86 86
87 /** 87 /**
88 * Requests a save ticket, that is used by @ref save() 88 * Requests a save ticket, that is used by @ref save()
89 */ 89 */
90 virtual Ticket *requestSaveTicket(); 90 virtual Ticket *requestSaveTicket();
91 91
92 /** 92 /**
93 * Loads all addressees from file to the address book. 93 * Loads all addressees from file to the address book.
94 * Returns true if all addressees could be loaded otherwise false. 94 * Returns true if all addressees could be loaded otherwise false.
95 */ 95 */
96 virtual bool load(); 96 virtual bool load();
97 97
98 /** 98 /**
99 * Saves all addresses from address book to file. 99 * Saves all addresses from address book to file.
100 * Returns true if all addressees could be saved otherwise false. 100 * Returns true if all addressees could be saved otherwise false.
101 * 101 *
102 * @param ticket The ticket returned by @ref requestSaveTicket() 102 * @param ticket The ticket returned by @ref requestSaveTicket()
103 */ 103 */
104 virtual bool save( Ticket *ticket ); 104 virtual bool save( Ticket *ticket );
105 105
106 /** 106 /**
107 * Set name of file to be used for saving. 107 * Set name of file to be used for saving.
108 */ 108 */
109 void setFileName( const QString & ); 109 void setFileName( const QString & );
110 110
@@ -114,36 +114,36 @@ public:
114 QString fileName() const; 114 QString fileName() const;
115 115
116 /** 116 /**
117 * Remove a addressee from its source. 117 * Remove a addressee from its source.
118 * This method is mainly called by KABC::AddressBook. 118 * This method is mainly called by KABC::AddressBook.
119 */ 119 */
120 virtual void removeAddressee( const Addressee& addr ); 120 virtual void removeAddressee( const Addressee& addr );
121 121
122 /** 122 /**
123 * This method is called by an error handler if the application 123 * This method is called by an error handler if the application
124 * crashed 124 * crashed
125 */ 125 */
126 virtual void cleanUp(); 126 virtual void cleanUp();
127 127
128protected slots: 128protected slots:
129 void fileChanged(); 129 void fileChanged();
130 130
131protected: 131protected:
132 void init( const QString &fileName ); 132 void init( const QString &fileName );
133 133
134 bool lock( const QString &fileName ); 134 bool lock( const QString &fileName );
135 void unlock( const QString &fileName ); 135 void unlock( const QString &fileName );
136 136
137private: 137private:
138 QtopiaConverter* mConverter; 138 SharpDTMConverter* mConverter;
139 139
140 QString mFileName; 140 QString mFileName;
141 141
142 QString mLockUniqueName; 142 QString mLockUniqueName;
143 143
144 KDirWatch mDirWatch; 144 KDirWatch mDirWatch;
145}; 145};
146 146
147} 147}
148 148
149#endif 149#endif
diff --git a/kabc/plugins/sharpdtm/sharpdtmE.pro b/kabc/plugins/sharpdtm/sharpdtmE.pro
index f29be2f..7c7a6d5 100644
--- a/kabc/plugins/sharpdtm/sharpdtmE.pro
+++ b/kabc/plugins/sharpdtm/sharpdtmE.pro
@@ -1,30 +1,30 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2CONFIG += qt warn_on 2CONFIG += qt warn_on
3#release debug 3#release debug
4TARGET = microkabc_sharpdtm 4TARGET = microkabc_sharpdtm
5 5
6INCLUDEPATH += ../.. ../../../external/sharpdtm/include ../../converter/qtopia ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../qtcompat $(QPEDIR)/include 6INCLUDEPATH += ../.. ../../../external/sharpdtm/include ../../converter/sharpdtm ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../qtcompat $(QPEDIR)/include
7 7
8 8
9OBJECTS_DIR = obj/$(PLATFORM) 9OBJECTS_DIR = obj/$(PLATFORM)
10MOC_DIR = moc/$(PLATFORM) 10MOC_DIR = moc/$(PLATFORM)
11DESTDIR = $(QPEDIR)/lib 11DESTDIR = $(QPEDIR)/lib
12LIBS += -lmicrokde 12LIBS += -lmicrokde
13LIBS += -lmicrokabc 13LIBS += -lmicrokabc
14LIBS += -L$(QPEDIR)/lib 14LIBS += -L$(QPEDIR)/lib
15LIBS += -lqpe 15LIBS += -lqpe
16LIBS += -lqte 16LIBS += -lqte
17LIBS += -lzdtm 17LIBS += -lzdtm
18LIBS += -lmicrokabc_sharpdtmconverter 18LIBS += -lmicrokabc_sharpdtmconverter
19#LIBS += -L../../lib/$(PLATFORM) 19#LIBS += -L../../lib/$(PLATFORM)
20 20
21 21
22INTERFACES = \ 22INTERFACES = \
23 23
24HEADERS = \ 24HEADERS = \
25 resourcesharpdtm.h \ 25 resourcesharpdtm.h \
26 resourcesharpdtmconfig.h \ 26 resourcesharpdtmconfig.h \
27 27
28SOURCES = \ 28SOURCES = \
29 resourcesharpdtm.cpp \ 29 resourcesharpdtm.cpp \
30 resourcesharpdtmconfig.cpp \ 30 resourcesharpdtmconfig.cpp \
diff --git a/kaddressbook/xxport/qtopia/qtopia_xxport.cpp b/kaddressbook/xxport/qtopia/qtopia_xxport.cpp
index bf39fdb..c1ed03e 100644
--- a/kaddressbook/xxport/qtopia/qtopia_xxport.cpp
+++ b/kaddressbook/xxport/qtopia/qtopia_xxport.cpp
@@ -67,135 +67,134 @@ class QtopiaXXPortFactory : public XXPortFactory
67 } 67 }
68}; 68};
69 69
70 70
71extern "C" 71extern "C"
72{ 72{
73 void *init_microkaddrbk_qtopia_xxport() 73 void *init_microkaddrbk_qtopia_xxport()
74 { 74 {
75 return ( new QtopiaXXPortFactory() ); 75 return ( new QtopiaXXPortFactory() );
76 } 76 }
77} 77}
78 78
79 79
80QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 80QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
81 : XXPortObject( ab, parent, name ) 81 : XXPortObject( ab, parent, name )
82{ 82{
83 createImportAction( i18n( "Import Qtopia..." ) ); 83 createImportAction( i18n( "Import Qtopia..." ) );
84 createExportAction( i18n( "Export Qtopia..." ) ); 84 createExportAction( i18n( "Export Qtopia..." ) );
85} 85}
86 86
87bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) 87bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
88{ 88{
89 // we can not choose the filename. Therefore use the default to display 89 // we can not choose the filename. Therefore use the default to display
90 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 90 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
91 91
92 AddressBookAccess* access = new AddressBookAccess(); 92 AddressBookAccess* access = new AddressBookAccess();
93 93
94 if ( !access ) { 94 if ( !access ) {
95 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) ); 95 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
96 qDebug(text.latin1()); 96 qDebug(text.latin1());
97 KMessageBox::error( parentWidget(), text ); 97 KMessageBox::error( parentWidget(), text );
98 addressBook()->error( text ); 98 addressBook()->error( text );
99 return false; 99 return false;
100 } 100 }
101 101
102 KABC::QtopiaConverter mConverter; 102 KABC::QtopiaConverter mConverter;
103 103
104 bool res = mConverter.init(); 104 bool res = mConverter.init();
105 if (!res) 105 if (!res)
106 { 106 {
107 QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) ); 107 QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) );
108 qDebug(text); 108 qDebug(text);
109 KMessageBox::error( parentWidget(), text ); 109 KMessageBox::error( parentWidget(), text );
110 delete access; 110 delete access;
111 return false; 111 return false;
112 } 112 }
113 113
114 //Now check if the file has already entries, and ask the user if he wants to delete them first. 114 //Now check if the file has already entries, and ask the user if he wants to delete them first.
115 { //create a new scope 115 { //create a new scope
116 AddressBookIterator it(*access); 116 AddressBookIterator it(*access);
117 const PimContact* firstcontact = it.toFirst(); 117 const PimContact* firstcontact = it.toFirst();
118 if (firstcontact) 118 if (firstcontact)
119 { 119 {
120 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) ); 120 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
121 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { 121 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
122 // Clean the database.. 122 // Clean the database..
123 123
124 AddressBookIterator it2(*access); 124 AddressBookIterator it2(*access);
125 for (it2.toFirst(); it2.current(); ++it2) { 125 for (it2.toFirst(); it2.current(); ++it2) {
126 access->removeContact(*it2.current()); 126 access->removeContact(*it2.current());
127 } 127 }
128 } 128 }
129 } 129 }
130 } 130 }
131 131
132 KABC::Addressee::List::ConstIterator it; 132 KABC::Addressee::List::ConstIterator it;
133 for ( it = list.begin(); it != list.end(); ++it ) { 133 for ( it = list.begin(); it != list.end(); ++it ) {
134 PimContact c; 134 PimContact c;
135 KABC::Addressee addressee = (*it); 135
136
137 res = mConverter.addresseeToQtopia( *it, c ); 136 res = mConverter.addresseeToQtopia( *it, c );
138 if (res == true) 137 if (res == true)
139 { 138 {
140 access->addContact(c); 139 access->addContact(c);
141 } 140 }
142 } 141 }
143 142
144 delete access; 143 delete access;
145 144
146 return true; 145 return true;
147} 146}
148 147
149KABC::AddresseeList QtopiaXXPort::importContacts( const QString& ) const 148KABC::AddresseeList QtopiaXXPort::importContacts( const QString& ) const
150{ 149{
151 KABC::AddresseeList adrlst; 150 KABC::AddresseeList adrlst;
152 151
153 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 152 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
154 153
155 AddressBookAccess* access = new AddressBookAccess(); 154 AddressBookAccess* access = new AddressBookAccess();
156 155
157 if ( !access ) { 156 if ( !access ) {
158 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) ); 157 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
159 qDebug(text.latin1()); 158 qDebug(text.latin1());
160 addressBook()->error( text ); 159 addressBook()->error( text );
161 KMessageBox::error( parentWidget(), text ); 160 KMessageBox::error( parentWidget(), text );
162 return KABC::AddresseeList(); 161 return KABC::AddresseeList();
163 } 162 }
164 163
165 KABC::QtopiaConverter mConverter; 164 KABC::QtopiaConverter mConverter;
166 165
167 bool res = mConverter.init(); 166 bool res = mConverter.init();
168 if (!res) 167 if (!res)
169 { 168 {
170 QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) ); 169 QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) );
171 qDebug(text); 170 qDebug(text);
172 KMessageBox::error( parentWidget(), text ); 171 KMessageBox::error( parentWidget(), text );
173 delete access; 172 delete access;
174 return KABC::AddresseeList(); 173 return KABC::AddresseeList();
175 } 174 }
176 175
177 176
178 177
179 { //create a new scope 178 { //create a new scope
180 AddressBookIterator it(*access); 179 AddressBookIterator it(*access);
181 180
182 for (it.toFirst(); it.current(); ++it) { 181 for (it.toFirst(); it.current(); ++it) {
183 const PimContact*contact = it.current(); 182 const PimContact*contact = it.current();
184 183
185 KABC::Addressee addressee; 184 KABC::Addressee addressee;
186 185
187 res = mConverter.qtopiaToAddressee( (*contact), addressee ); 186 res = mConverter.qtopiaToAddressee( (*contact), addressee );
188 187
189 if ( !addressee.isEmpty() && res ) 188 if ( !addressee.isEmpty() && res )
190 { 189 {
191 adrlst.append( addressee ); 190 adrlst.append( addressee );
192 } 191 }
193 } 192 }
194 } 193 }
195 194
196 delete access; 195 delete access;
197//US the deletion of the access object deletes the backend object as well. 196//US the deletion of the access object deletes the backend object as well.
198 197
199 return adrlst; 198 return adrlst;
200 199
201} 200}