-rw-r--r-- | kabc/stdaddressbook.cpp | 5 | ||||
-rw-r--r-- | kabc/stdaddressbook.h | 2 |
2 files changed, 4 insertions, 3 deletions
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp index f17f366..a14ae20 100644 --- a/kabc/stdaddressbook.cpp +++ b/kabc/stdaddressbook.cpp | |||
@@ -68,104 +68,105 @@ StdAddressBook *StdAddressBook::self() | |||
68 | mSelf = addressBookDeleter.setObject( new StdAddressBook ); | 68 | mSelf = addressBookDeleter.setObject( new StdAddressBook ); |
69 | #else //KAB_EMBEDDED | 69 | #else //KAB_EMBEDDED |
70 | addressBookDeleter.setObject( mSelf, new StdAddressBook ); | 70 | addressBookDeleter.setObject( mSelf, new StdAddressBook ); |
71 | #endif //KAB_EMBEDDED | 71 | #endif //KAB_EMBEDDED |
72 | KStandardDirs::setAppDir( appdir ); | 72 | KStandardDirs::setAppDir( appdir ); |
73 | } | 73 | } |
74 | 74 | ||
75 | return mSelf; | 75 | return mSelf; |
76 | } | 76 | } |
77 | 77 | ||
78 | QString StdAddressBook::setTempAppDir() | 78 | QString StdAddressBook::setTempAppDir() |
79 | { | 79 | { |
80 | QString appDIR = KStandardDirs::appDir(); | 80 | QString appDIR = KStandardDirs::appDir(); |
81 | #ifdef DESKTOP_VERSION | 81 | #ifdef DESKTOP_VERSION |
82 | QString appdir = QDir::homeDirPath(); | 82 | QString appdir = QDir::homeDirPath(); |
83 | if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) | 83 | if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) |
84 | appdir += "kaddressbook/"; | 84 | appdir += "kaddressbook/"; |
85 | else | 85 | else |
86 | appdir += "/kaddressbook/"; | 86 | appdir += "/kaddressbook/"; |
87 | KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); | 87 | KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); |
88 | #else | 88 | #else |
89 | QString appdir = QDir::homeDirPath() + "/kdepim/apps/kaddressbook"; | 89 | QString appdir = QDir::homeDirPath() + "/kdepim/apps/kaddressbook"; |
90 | 90 | ||
91 | KStandardDirs::setAppDir( appdir ); | 91 | KStandardDirs::setAppDir( appdir ); |
92 | #endif | 92 | #endif |
93 | 93 | ||
94 | return appDIR; | 94 | return appDIR; |
95 | } | 95 | } |
96 | StdAddressBook *StdAddressBook::self( bool onlyFastResources ) | 96 | StdAddressBook *StdAddressBook::self( bool onlyFastResources ) |
97 | { | 97 | { |
98 | 98 | ||
99 | if ( !mSelf ) | 99 | if ( !mSelf ) |
100 | { | 100 | { |
101 | QString appdir =StdAddressBook::setTempAppDir(); | 101 | QString appdir =StdAddressBook::setTempAppDir(); |
102 | #ifdef KAB_EMBEDDED | 102 | #ifdef KAB_EMBEDDED |
103 | mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); | 103 | mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); |
104 | #else //KAB_EMBEDDED | 104 | #else //KAB_EMBEDDED |
105 | addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); | 105 | addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); |
106 | #endif //KAB_EMBEDDED | 106 | #endif //KAB_EMBEDDED |
107 | KStandardDirs::setAppDir( appdir ); | 107 | KStandardDirs::setAppDir( appdir ); |
108 | } | 108 | } |
109 | return mSelf; | 109 | return mSelf; |
110 | } | 110 | } |
111 | 111 | ||
112 | StdAddressBook::StdAddressBook() | 112 | StdAddressBook::StdAddressBook() |
113 | : AddressBook( "kabcrc" ) | 113 | : AddressBook( "kabcrc" ) |
114 | { | 114 | { |
115 | 115 | ||
116 | init( false ); | 116 | //init( false ); |
117 | } | 117 | } |
118 | 118 | ||
119 | StdAddressBook::StdAddressBook( bool onlyFastResources ) | 119 | StdAddressBook::StdAddressBook( bool onlyFastResources ) |
120 | : AddressBook( "kabcrc" ) | 120 | : AddressBook( "kabcrc" ) |
121 | { | 121 | { |
122 | 122 | ||
123 | init( onlyFastResources ); | 123 | if ( onlyFastResources ) |
124 | init( onlyFastResources ); | ||
124 | } | 125 | } |
125 | 126 | ||
126 | StdAddressBook::~StdAddressBook() | 127 | StdAddressBook::~StdAddressBook() |
127 | { | 128 | { |
128 | if ( mAutomaticSave ) | 129 | if ( mAutomaticSave ) |
129 | save(); | 130 | save(); |
130 | } | 131 | } |
131 | 132 | ||
132 | void StdAddressBook::init( bool ) | 133 | void StdAddressBook::init( bool ) |
133 | { | 134 | { |
134 | KRES::Manager<Resource> *manager = resourceManager(); | 135 | KRES::Manager<Resource> *manager = resourceManager(); |
135 | KRES::Manager<Resource>::ActiveIterator it; | 136 | KRES::Manager<Resource>::ActiveIterator it; |
136 | 137 | ||
137 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 138 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
138 | (*it)->setAddressBook( this ); | 139 | (*it)->setAddressBook( this ); |
139 | if ( !(*it)->open() ) | 140 | if ( !(*it)->open() ) |
140 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 141 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
141 | } | 142 | } |
142 | 143 | ||
143 | Resource *res = standardResource(); | 144 | Resource *res = standardResource(); |
144 | if ( !res ) { | 145 | if ( !res ) { |
145 | res = manager->createResource( "file" ); | 146 | res = manager->createResource( "file" ); |
146 | if ( res ) | 147 | if ( res ) |
147 | { | 148 | { |
148 | addResource( res ); | 149 | addResource( res ); |
149 | } | 150 | } |
150 | else | 151 | else |
151 | qDebug(" No resource available!!!"); | 152 | qDebug(" No resource available!!!"); |
152 | } | 153 | } |
153 | 154 | ||
154 | setStandardResource( res ); | 155 | setStandardResource( res ); |
155 | manager->writeConfig(); | 156 | manager->writeConfig(); |
156 | 157 | ||
157 | load(); | 158 | load(); |
158 | } | 159 | } |
159 | 160 | ||
160 | bool StdAddressBook::save() | 161 | bool StdAddressBook::save() |
161 | { | 162 | { |
162 | kdDebug(5700) << "StdAddressBook::save()" << endl; | 163 | kdDebug(5700) << "StdAddressBook::save()" << endl; |
163 | 164 | ||
164 | bool ok = true; | 165 | bool ok = true; |
165 | AddressBook *ab = self(); | 166 | AddressBook *ab = self(); |
166 | 167 | ||
167 | ab->deleteRemovedAddressees(); | 168 | ab->deleteRemovedAddressees(); |
168 | Iterator ait; | 169 | Iterator ait; |
169 | for ( ait = ab->begin(); ait != ab->end(); ++ait ) { | 170 | for ( ait = ab->begin(); ait != ab->end(); ++ait ) { |
170 | if ( !(*ait).IDStr().isEmpty() ) { | 171 | if ( !(*ait).IDStr().isEmpty() ) { |
171 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 172 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
diff --git a/kabc/stdaddressbook.h b/kabc/stdaddressbook.h index 9ec53b0..cf130b3 100644 --- a/kabc/stdaddressbook.h +++ b/kabc/stdaddressbook.h | |||
@@ -89,63 +89,63 @@ class StdAddressBook : public AddressBook | |||
89 | Call this method in your crash handler to allow the library clean up | 89 | Call this method in your crash handler to allow the library clean up |
90 | possible locks. | 90 | possible locks. |
91 | */ | 91 | */ |
92 | static void handleCrash(); | 92 | static void handleCrash(); |
93 | 93 | ||
94 | /** | 94 | /** |
95 | Returns the default file name for vcard-based addressbook | 95 | Returns the default file name for vcard-based addressbook |
96 | */ | 96 | */ |
97 | static QString fileName(); | 97 | static QString fileName(); |
98 | 98 | ||
99 | /** | 99 | /** |
100 | Returns the default directory name for vcard-based addressbook | 100 | Returns the default directory name for vcard-based addressbook |
101 | */ | 101 | */ |
102 | static QString directoryName(); | 102 | static QString directoryName(); |
103 | 103 | ||
104 | /** | 104 | /** |
105 | Set the automatic save property of the address book. | 105 | Set the automatic save property of the address book. |
106 | If @p enable is TRUE (default) the address book is saved at | 106 | If @p enable is TRUE (default) the address book is saved at |
107 | destruction time otherwise you have to call @ref save() to | 107 | destruction time otherwise you have to call @ref save() to |
108 | explicitely save it. | 108 | explicitely save it. |
109 | */ | 109 | */ |
110 | static void setAutomaticSave( bool enable ); | 110 | static void setAutomaticSave( bool enable ); |
111 | 111 | ||
112 | /** | 112 | /** |
113 | Closes the address book. Depending on @ref automaticSave() it will | 113 | Closes the address book. Depending on @ref automaticSave() it will |
114 | save the address book first. | 114 | save the address book first. |
115 | */ | 115 | */ |
116 | static void close(); | 116 | static void close(); |
117 | 117 | ||
118 | /** | 118 | /** |
119 | Returns whether the address book is saved at destruction time. | 119 | Returns whether the address book is saved at destruction time. |
120 | See also @ref setAutomaticSave(). | 120 | See also @ref setAutomaticSave(). |
121 | */ | 121 | */ |
122 | static bool automaticSave(); | 122 | static bool automaticSave(); |
123 | 123 | ||
124 | /** | 124 | /** |
125 | Returns the contact, that is associated with the owner of the | 125 | Returns the contact, that is associated with the owner of the |
126 | address book. This contact should be used by other programs | 126 | address book. This contact should be used by other programs |
127 | to access user specific data. | 127 | to access user specific data. |
128 | */ | 128 | */ |
129 | Addressee whoAmI(); | 129 | Addressee whoAmI(); |
130 | 130 | ||
131 | /** | 131 | /** |
132 | Sets the users contact. See @ref whoAmI() for more information. | 132 | Sets the users contact. See @ref whoAmI() for more information. |
133 | 133 | ||
134 | @param uid The uid of the users contact. | 134 | @param uid The uid of the users contact. |
135 | */ | 135 | */ |
136 | void setWhoAmI( const Addressee &addr ); | 136 | void setWhoAmI( const Addressee &addr ); |
137 | void init( bool onlyFastResources ); | ||
137 | 138 | ||
138 | protected: | 139 | protected: |
139 | StdAddressBook(); | 140 | StdAddressBook(); |
140 | StdAddressBook( bool onlyFastResources ); | 141 | StdAddressBook( bool onlyFastResources ); |
141 | 142 | ||
142 | void init( bool onlyFastResources ); | ||
143 | 143 | ||
144 | private: | 144 | private: |
145 | static QString setTempAppDir(); | 145 | static QString setTempAppDir(); |
146 | static StdAddressBook *mSelf; | 146 | static StdAddressBook *mSelf; |
147 | static bool mAutomaticSave; | 147 | static bool mAutomaticSave; |
148 | }; | 148 | }; |
149 | 149 | ||
150 | } | 150 | } |
151 | #endif | 151 | #endif |