-rw-r--r-- | kabc/addressbook.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 4c4ae09..8487ff3 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1115,96 +1115,107 @@ Field::List AddressBook::fields( int category ) | |||
1115 | bool AddressBook::addCustomField( const QString &label, int category, | 1115 | bool AddressBook::addCustomField( const QString &label, int category, |
1116 | const QString &key, const QString &app ) | 1116 | const QString &key, const QString &app ) |
1117 | { | 1117 | { |
1118 | if ( d->mAllFields.isEmpty() ) { | 1118 | if ( d->mAllFields.isEmpty() ) { |
1119 | d->mAllFields = Field::allFields(); | 1119 | d->mAllFields = Field::allFields(); |
1120 | } | 1120 | } |
1121 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 1121 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
1122 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 1122 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
1123 | 1123 | ||
1124 | QString k = key.isNull() ? label : key; | 1124 | QString k = key.isNull() ? label : key; |
1125 | 1125 | ||
1126 | Field *field = Field::createCustomField( label, category, k, a ); | 1126 | Field *field = Field::createCustomField( label, category, k, a ); |
1127 | 1127 | ||
1128 | if ( !field ) return false; | 1128 | if ( !field ) return false; |
1129 | 1129 | ||
1130 | d->mAllFields.append( field ); | 1130 | d->mAllFields.append( field ); |
1131 | 1131 | ||
1132 | return true; | 1132 | return true; |
1133 | } | 1133 | } |
1134 | 1134 | ||
1135 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 1135 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
1136 | { | 1136 | { |
1137 | if (!ab.d) return s; | 1137 | if (!ab.d) return s; |
1138 | 1138 | ||
1139 | return s << ab.d->mAddressees; | 1139 | return s << ab.d->mAddressees; |
1140 | } | 1140 | } |
1141 | 1141 | ||
1142 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 1142 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
1143 | { | 1143 | { |
1144 | if (!ab.d) return s; | 1144 | if (!ab.d) return s; |
1145 | 1145 | ||
1146 | s >> ab.d->mAddressees; | 1146 | s >> ab.d->mAddressees; |
1147 | 1147 | ||
1148 | return s; | 1148 | return s; |
1149 | } | 1149 | } |
1150 | 1150 | ||
1151 | bool AddressBook::addResource( Resource *resource ) | 1151 | bool AddressBook::addResource( Resource *resource ) |
1152 | { | 1152 | { |
1153 | if ( !resource->open() ) { | 1153 | if ( !resource->open() ) { |
1154 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 1154 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
1155 | return false; | 1155 | return false; |
1156 | } | 1156 | } |
1157 | 1157 | ||
1158 | resource->setAddressBook( this ); | 1158 | resource->setAddressBook( this ); |
1159 | 1159 | ||
1160 | d->mManager->add( resource ); | 1160 | d->mManager->add( resource ); |
1161 | return true; | 1161 | return true; |
1162 | } | 1162 | } |
1163 | void AddressBook::removeResources() | ||
1164 | { | ||
1165 | //remove all possible resources. This should cleanup the configfile. | ||
1166 | QPtrList<KABC::Resource> mResources = resources(); | ||
1167 | |||
1168 | QPtrListIterator<KABC::Resource> it(mResources); | ||
1169 | for ( ; it.current(); ++it ) { | ||
1170 | KABC::Resource *res = it.current(); | ||
1171 | removeResource(res); | ||
1172 | } | ||
1173 | } | ||
1163 | 1174 | ||
1164 | bool AddressBook::removeResource( Resource *resource ) | 1175 | bool AddressBook::removeResource( Resource *resource ) |
1165 | { | 1176 | { |
1166 | resource->close(); | 1177 | resource->close(); |
1167 | 1178 | ||
1168 | if ( resource == standardResource() ) | 1179 | if ( resource == standardResource() ) |
1169 | d->mManager->setStandardResource( 0 ); | 1180 | d->mManager->setStandardResource( 0 ); |
1170 | 1181 | ||
1171 | resource->setAddressBook( 0 ); | 1182 | resource->setAddressBook( 0 ); |
1172 | 1183 | ||
1173 | d->mManager->remove( resource ); | 1184 | d->mManager->remove( resource ); |
1174 | return true; | 1185 | return true; |
1175 | } | 1186 | } |
1176 | 1187 | ||
1177 | QPtrList<Resource> AddressBook::resources() | 1188 | QPtrList<Resource> AddressBook::resources() |
1178 | { | 1189 | { |
1179 | QPtrList<Resource> list; | 1190 | QPtrList<Resource> list; |
1180 | 1191 | ||
1181 | // qDebug("AddressBook::resources() 1"); | 1192 | // qDebug("AddressBook::resources() 1"); |
1182 | 1193 | ||
1183 | KRES::Manager<Resource>::ActiveIterator it; | 1194 | KRES::Manager<Resource>::ActiveIterator it; |
1184 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 1195 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
1185 | list.append( *it ); | 1196 | list.append( *it ); |
1186 | 1197 | ||
1187 | return list; | 1198 | return list; |
1188 | } | 1199 | } |
1189 | 1200 | ||
1190 | /*US | 1201 | /*US |
1191 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 1202 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
1192 | { | 1203 | { |
1193 | delete d->mErrorHandler; | 1204 | delete d->mErrorHandler; |
1194 | d->mErrorHandler = handler; | 1205 | d->mErrorHandler = handler; |
1195 | } | 1206 | } |
1196 | */ | 1207 | */ |
1197 | 1208 | ||
1198 | void AddressBook::error( const QString& msg ) | 1209 | void AddressBook::error( const QString& msg ) |
1199 | { | 1210 | { |
1200 | /*US | 1211 | /*US |
1201 | if ( !d->mErrorHandler ) // create default error handler | 1212 | if ( !d->mErrorHandler ) // create default error handler |
1202 | d->mErrorHandler = new ConsoleErrorHandler; | 1213 | d->mErrorHandler = new ConsoleErrorHandler; |
1203 | 1214 | ||
1204 | if ( d->mErrorHandler ) | 1215 | if ( d->mErrorHandler ) |
1205 | d->mErrorHandler->error( msg ); | 1216 | d->mErrorHandler->error( msg ); |
1206 | else | 1217 | else |
1207 | kdError(5700) << "no error handler defined" << endl; | 1218 | kdError(5700) << "no error handler defined" << endl; |
1208 | */ | 1219 | */ |
1209 | kdDebug(5700) << "msg" << endl; | 1220 | kdDebug(5700) << "msg" << endl; |
1210 | qDebug(msg); | 1221 | qDebug(msg); |