-rw-r--r-- | kaddressbook/kabcore.cpp | 2 | ||||
-rw-r--r-- | kaddressbook/views/cardview.cpp | 10 |
2 files changed, 6 insertions, 6 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index d651224..c339244 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -1,3096 +1,3096 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressbook. | 2 | This file is part of KAddressbook. |
3 | Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | /*s | 24 | /*s |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (c) 2004 Ulf Schenk |
27 | 27 | ||
28 | $Id$ | 28 | $Id$ |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include "kabcore.h" | 31 | #include "kabcore.h" |
32 | 32 | ||
33 | #include <stdaddressbook.h> | 33 | #include <stdaddressbook.h> |
34 | #include <klocale.h> | 34 | #include <klocale.h> |
35 | #include <kfiledialog.h> | 35 | #include <kfiledialog.h> |
36 | #include <qtimer.h> | 36 | #include <qtimer.h> |
37 | #include <qlabel.h> | 37 | #include <qlabel.h> |
38 | #include <qregexp.h> | 38 | #include <qregexp.h> |
39 | #include <qlineedit.h> | 39 | #include <qlineedit.h> |
40 | #include <qcheckbox.h> | 40 | #include <qcheckbox.h> |
41 | #include <qpushbutton.h> | 41 | #include <qpushbutton.h> |
42 | #include <qprogressbar.h> | 42 | #include <qprogressbar.h> |
43 | #include <libkdepim/phoneaccess.h> | 43 | #include <libkdepim/phoneaccess.h> |
44 | 44 | ||
45 | #ifndef KAB_EMBEDDED | 45 | #ifndef KAB_EMBEDDED |
46 | #include <qclipboard.h> | 46 | #include <qclipboard.h> |
47 | #include <qdir.h> | 47 | #include <qdir.h> |
48 | #include <qfile.h> | 48 | #include <qfile.h> |
49 | #include <qapplicaton.h> | 49 | #include <qapplicaton.h> |
50 | #include <qprogressbar.h> | 50 | #include <qprogressbar.h> |
51 | #include <qlayout.h> | 51 | #include <qlayout.h> |
52 | #include <qregexp.h> | 52 | #include <qregexp.h> |
53 | #include <qvbox.h> | 53 | #include <qvbox.h> |
54 | #include <kabc/addresseelist.h> | 54 | #include <kabc/addresseelist.h> |
55 | #include <kabc/errorhandler.h> | 55 | #include <kabc/errorhandler.h> |
56 | #include <kabc/resource.h> | 56 | #include <kabc/resource.h> |
57 | #include <kabc/vcardconverter.h> | 57 | #include <kabc/vcardconverter.h> |
58 | #include <kapplication.h> | 58 | #include <kapplication.h> |
59 | #include <kactionclasses.h> | 59 | #include <kactionclasses.h> |
60 | #include <kcmultidialog.h> | 60 | #include <kcmultidialog.h> |
61 | #include <kdebug.h> | 61 | #include <kdebug.h> |
62 | #include <kdeversion.h> | 62 | #include <kdeversion.h> |
63 | #include <kkeydialog.h> | 63 | #include <kkeydialog.h> |
64 | #include <kmessagebox.h> | 64 | #include <kmessagebox.h> |
65 | #include <kprinter.h> | 65 | #include <kprinter.h> |
66 | #include <kprotocolinfo.h> | 66 | #include <kprotocolinfo.h> |
67 | #include <kresources/selectdialog.h> | 67 | #include <kresources/selectdialog.h> |
68 | #include <kstandarddirs.h> | 68 | #include <kstandarddirs.h> |
69 | #include <ktempfile.h> | 69 | #include <ktempfile.h> |
70 | #include <kxmlguiclient.h> | 70 | #include <kxmlguiclient.h> |
71 | #include <kaboutdata.h> | 71 | #include <kaboutdata.h> |
72 | #include <libkdepim/categoryselectdialog.h> | 72 | #include <libkdepim/categoryselectdialog.h> |
73 | 73 | ||
74 | #include "addresseeutil.h" | 74 | #include "addresseeutil.h" |
75 | #include "addresseeeditordialog.h" | 75 | #include "addresseeeditordialog.h" |
76 | #include "extensionmanager.h" | 76 | #include "extensionmanager.h" |
77 | #include "kstdaction.h" | 77 | #include "kstdaction.h" |
78 | #include "kaddressbookservice.h" | 78 | #include "kaddressbookservice.h" |
79 | #include "ldapsearchdialog.h" | 79 | #include "ldapsearchdialog.h" |
80 | #include "printing/printingwizard.h" | 80 | #include "printing/printingwizard.h" |
81 | #else // KAB_EMBEDDED | 81 | #else // KAB_EMBEDDED |
82 | 82 | ||
83 | #include <kapplication.h> | 83 | #include <kapplication.h> |
84 | #include "KDGanttMinimizeSplitter.h" | 84 | #include "KDGanttMinimizeSplitter.h" |
85 | #include "kaddressbookmain.h" | 85 | #include "kaddressbookmain.h" |
86 | #include "kactioncollection.h" | 86 | #include "kactioncollection.h" |
87 | #include "addresseedialog.h" | 87 | #include "addresseedialog.h" |
88 | //US | 88 | //US |
89 | #include <addresseeview.h> | 89 | #include <addresseeview.h> |
90 | 90 | ||
91 | #include <qapp.h> | 91 | #include <qapp.h> |
92 | #include <qmenubar.h> | 92 | #include <qmenubar.h> |
93 | //#include <qtoolbar.h> | 93 | //#include <qtoolbar.h> |
94 | #include <qmessagebox.h> | 94 | #include <qmessagebox.h> |
95 | #include <kdebug.h> | 95 | #include <kdebug.h> |
96 | #include <kiconloader.h> // needed for SmallIcon | 96 | #include <kiconloader.h> // needed for SmallIcon |
97 | #include <kresources/kcmkresources.h> | 97 | #include <kresources/kcmkresources.h> |
98 | #include <ktoolbar.h> | 98 | #include <ktoolbar.h> |
99 | 99 | ||
100 | 100 | ||
101 | //#include <qlabel.h> | 101 | //#include <qlabel.h> |
102 | 102 | ||
103 | 103 | ||
104 | #ifndef DESKTOP_VERSION | 104 | #ifndef DESKTOP_VERSION |
105 | #include <qpe/ir.h> | 105 | #include <qpe/ir.h> |
106 | #include <qpe/qpemenubar.h> | 106 | #include <qpe/qpemenubar.h> |
107 | #include <qtopia/qcopenvelope_qws.h> | 107 | #include <qtopia/qcopenvelope_qws.h> |
108 | #else | 108 | #else |
109 | 109 | ||
110 | #include <qmenubar.h> | 110 | #include <qmenubar.h> |
111 | #endif | 111 | #endif |
112 | 112 | ||
113 | #endif // KAB_EMBEDDED | 113 | #endif // KAB_EMBEDDED |
114 | #include "kcmconfigs/kcmkabconfig.h" | 114 | #include "kcmconfigs/kcmkabconfig.h" |
115 | #include "kcmconfigs/kcmkdepimconfig.h" | 115 | #include "kcmconfigs/kcmkdepimconfig.h" |
116 | #include "kpimglobalprefs.h" | 116 | #include "kpimglobalprefs.h" |
117 | #include "externalapphandler.h" | 117 | #include "externalapphandler.h" |
118 | 118 | ||
119 | 119 | ||
120 | #include <kresources/selectdialog.h> | 120 | #include <kresources/selectdialog.h> |
121 | #include <kmessagebox.h> | 121 | #include <kmessagebox.h> |
122 | 122 | ||
123 | #include <picture.h> | 123 | #include <picture.h> |
124 | #include <resource.h> | 124 | #include <resource.h> |
125 | 125 | ||
126 | //US#include <qsplitter.h> | 126 | //US#include <qsplitter.h> |
127 | #include <qmap.h> | 127 | #include <qmap.h> |
128 | #include <qdir.h> | 128 | #include <qdir.h> |
129 | #include <qfile.h> | 129 | #include <qfile.h> |
130 | #include <qvbox.h> | 130 | #include <qvbox.h> |
131 | #include <qlayout.h> | 131 | #include <qlayout.h> |
132 | #include <qclipboard.h> | 132 | #include <qclipboard.h> |
133 | #include <qtextstream.h> | 133 | #include <qtextstream.h> |
134 | #include <qradiobutton.h> | 134 | #include <qradiobutton.h> |
135 | #include <qbuttongroup.h> | 135 | #include <qbuttongroup.h> |
136 | 136 | ||
137 | #include <libkdepim/categoryselectdialog.h> | 137 | #include <libkdepim/categoryselectdialog.h> |
138 | #include <libkdepim/categoryeditdialog.h> | 138 | #include <libkdepim/categoryeditdialog.h> |
139 | #include <kabc/vcardconverter.h> | 139 | #include <kabc/vcardconverter.h> |
140 | 140 | ||
141 | 141 | ||
142 | #include "addresseeutil.h" | 142 | #include "addresseeutil.h" |
143 | #include "undocmds.h" | 143 | #include "undocmds.h" |
144 | #include "addresseeeditordialog.h" | 144 | #include "addresseeeditordialog.h" |
145 | #include "viewmanager.h" | 145 | #include "viewmanager.h" |
146 | #include "details/detailsviewcontainer.h" | 146 | #include "details/detailsviewcontainer.h" |
147 | #include "kabprefs.h" | 147 | #include "kabprefs.h" |
148 | #include "xxportmanager.h" | 148 | #include "xxportmanager.h" |
149 | #include "incsearchwidget.h" | 149 | #include "incsearchwidget.h" |
150 | #include "jumpbuttonbar.h" | 150 | #include "jumpbuttonbar.h" |
151 | #include "extensionmanager.h" | 151 | #include "extensionmanager.h" |
152 | #include "addresseeconfig.h" | 152 | #include "addresseeconfig.h" |
153 | #include <kcmultidialog.h> | 153 | #include <kcmultidialog.h> |
154 | 154 | ||
155 | #ifdef _WIN32_ | 155 | #ifdef _WIN32_ |
156 | 156 | ||
157 | #include "kaimportoldialog.h" | 157 | #include "kaimportoldialog.h" |
158 | #else | 158 | #else |
159 | #include <unistd.h> | 159 | #include <unistd.h> |
160 | #endif | 160 | #endif |
161 | // sync includes | 161 | // sync includes |
162 | #include <libkdepim/ksyncprofile.h> | 162 | #include <libkdepim/ksyncprofile.h> |
163 | #include <libkdepim/ksyncprefsdialog.h> | 163 | #include <libkdepim/ksyncprefsdialog.h> |
164 | 164 | ||
165 | 165 | ||
166 | class KABCatPrefs : public QDialog | 166 | class KABCatPrefs : public QDialog |
167 | { | 167 | { |
168 | public: | 168 | public: |
169 | KABCatPrefs( QWidget *parent=0, const char *name=0 ) : | 169 | KABCatPrefs( QWidget *parent=0, const char *name=0 ) : |
170 | QDialog( parent, name, true ) | 170 | QDialog( parent, name, true ) |
171 | { | 171 | { |
172 | setCaption( i18n("Manage new Categories") ); | 172 | setCaption( i18n("Manage new Categories") ); |
173 | QVBoxLayout* lay = new QVBoxLayout( this ); | 173 | QVBoxLayout* lay = new QVBoxLayout( this ); |
174 | lay->setSpacing( 3 ); | 174 | lay->setSpacing( 3 ); |
175 | lay->setMargin( 3 ); | 175 | lay->setMargin( 3 ); |
176 | QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\naddressees\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); | 176 | QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\naddressees\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); |
177 | lay->addWidget( lab ); | 177 | lay->addWidget( lab ); |
178 | QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); | 178 | QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); |
179 | lay->addWidget( format ); | 179 | lay->addWidget( format ); |
180 | format->setExclusive ( true ) ; | 180 | format->setExclusive ( true ) ; |
181 | addCatBut = new QRadioButton(i18n("Add to category list"), format ); | 181 | addCatBut = new QRadioButton(i18n("Add to category list"), format ); |
182 | new QRadioButton(i18n("Remove from addressees"), format ); | 182 | new QRadioButton(i18n("Remove from addressees"), format ); |
183 | addCatBut->setChecked( true ); | 183 | addCatBut->setChecked( true ); |
184 | QPushButton * ok = new QPushButton( i18n("OK"), this ); | 184 | QPushButton * ok = new QPushButton( i18n("OK"), this ); |
185 | lay->addWidget( ok ); | 185 | lay->addWidget( ok ); |
186 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); | 186 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); |
187 | lay->addWidget( cancel ); | 187 | lay->addWidget( cancel ); |
188 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); | 188 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); |
189 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); | 189 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); |
190 | resize( 200, 200 ); | 190 | resize( 200, 200 ); |
191 | } | 191 | } |
192 | 192 | ||
193 | bool addCat() { return addCatBut->isChecked(); } | 193 | bool addCat() { return addCatBut->isChecked(); } |
194 | private: | 194 | private: |
195 | QRadioButton* addCatBut; | 195 | QRadioButton* addCatBut; |
196 | }; | 196 | }; |
197 | 197 | ||
198 | 198 | ||
199 | 199 | ||
200 | class KAex2phonePrefs : public QDialog | 200 | class KAex2phonePrefs : public QDialog |
201 | { | 201 | { |
202 | public: | 202 | public: |
203 | KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) : | 203 | KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) : |
204 | QDialog( parent, name, true ) | 204 | QDialog( parent, name, true ) |
205 | { | 205 | { |
206 | setCaption( i18n("Export to phone options") ); | 206 | setCaption( i18n("Export to phone options") ); |
207 | QVBoxLayout* lay = new QVBoxLayout( this ); | 207 | QVBoxLayout* lay = new QVBoxLayout( this ); |
208 | lay->setSpacing( 3 ); | 208 | lay->setSpacing( 3 ); |
209 | lay->setMargin( 3 ); | 209 | lay->setMargin( 3 ); |
210 | QLabel *lab; | 210 | QLabel *lab; |
211 | lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) ); | 211 | lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) ); |
212 | lab->setAlignment (AlignHCenter ); | 212 | lab->setAlignment (AlignHCenter ); |
213 | QHBox* temphb; | 213 | QHBox* temphb; |
214 | temphb = new QHBox( this ); | 214 | temphb = new QHBox( this ); |
215 | new QLabel( i18n("I/O device: "), temphb ); | 215 | new QLabel( i18n("I/O device: "), temphb ); |
216 | mPhoneDevice = new QLineEdit( temphb); | 216 | mPhoneDevice = new QLineEdit( temphb); |
217 | lay->addWidget( temphb ); | 217 | lay->addWidget( temphb ); |
218 | temphb = new QHBox( this ); | 218 | temphb = new QHBox( this ); |
219 | new QLabel( i18n("Connection: "), temphb ); | 219 | new QLabel( i18n("Connection: "), temphb ); |
220 | mPhoneConnection = new QLineEdit( temphb); | 220 | mPhoneConnection = new QLineEdit( temphb); |
221 | lay->addWidget( temphb ); | 221 | lay->addWidget( temphb ); |
222 | temphb = new QHBox( this ); | 222 | temphb = new QHBox( this ); |
223 | new QLabel( i18n("Model(opt.): "), temphb ); | 223 | new QLabel( i18n("Model(opt.): "), temphb ); |
224 | mPhoneModel = new QLineEdit( temphb); | 224 | mPhoneModel = new QLineEdit( temphb); |
225 | lay->addWidget( temphb ); | 225 | lay->addWidget( temphb ); |
226 | // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this ); | 226 | // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this ); |
227 | // lay->addWidget( mWriteToSim ); | 227 | // lay->addWidget( mWriteToSim ); |
228 | lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) ); | 228 | lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) ); |
229 | lab->setAlignment (AlignHCenter ); | 229 | lab->setAlignment (AlignHCenter ); |
230 | QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); | 230 | QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); |
231 | lay->addWidget( ok ); | 231 | lay->addWidget( ok ); |
232 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); | 232 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); |
233 | lay->addWidget( cancel ); | 233 | lay->addWidget( cancel ); |
234 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); | 234 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); |
235 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); | 235 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); |
236 | resize( 220, 240 ); | 236 | resize( 220, 240 ); |
237 | 237 | ||
238 | } | 238 | } |
239 | 239 | ||
240 | public: | 240 | public: |
241 | QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel; | 241 | QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel; |
242 | QCheckBox* mWriteToSim; | 242 | QCheckBox* mWriteToSim; |
243 | }; | 243 | }; |
244 | 244 | ||
245 | 245 | ||
246 | bool pasteWithNewUid = true; | 246 | bool pasteWithNewUid = true; |
247 | 247 | ||
248 | #ifdef KAB_EMBEDDED | 248 | #ifdef KAB_EMBEDDED |
249 | KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) | 249 | KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) |
250 | : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), | 250 | : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), |
251 | mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ | 251 | mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ |
252 | mReadWrite( readWrite ), mModified( false ), mMainWindow(client) | 252 | mReadWrite( readWrite ), mModified( false ), mMainWindow(client) |
253 | #else //KAB_EMBEDDED | 253 | #else //KAB_EMBEDDED |
254 | KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) | 254 | KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) |
255 | : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), | 255 | : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), |
256 | mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), | 256 | mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), |
257 | mReadWrite( readWrite ), mModified( false ) | 257 | mReadWrite( readWrite ), mModified( false ) |
258 | #endif //KAB_EMBEDDED | 258 | #endif //KAB_EMBEDDED |
259 | { | 259 | { |
260 | // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); | 260 | // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); |
261 | // syncManager->setBlockSave(false); | 261 | // syncManager->setBlockSave(false); |
262 | mExtensionBarSplitter = 0; | 262 | mExtensionBarSplitter = 0; |
263 | mIsPart = !parent->inherits( "KAddressBookMain" ); | 263 | mIsPart = !parent->inherits( "KAddressBookMain" ); |
264 | mAddressBook = KABC::StdAddressBook::self(); | 264 | mAddressBook = KABC::StdAddressBook::self(); |
265 | KABC::StdAddressBook::setAutomaticSave( false ); | 265 | KABC::StdAddressBook::setAutomaticSave( false ); |
266 | 266 | ||
267 | #ifndef KAB_EMBEDDED | 267 | #ifndef KAB_EMBEDDED |
268 | mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); | 268 | mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); |
269 | #endif //KAB_EMBEDDED | 269 | #endif //KAB_EMBEDDED |
270 | 270 | ||
271 | connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), | 271 | connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), |
272 | SLOT( addressBookChanged() ) ); | 272 | SLOT( addressBookChanged() ) ); |
273 | 273 | ||
274 | #if 0 | 274 | #if 0 |
275 | // LP moved to addressbook init method | 275 | // LP moved to addressbook init method |
276 | mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, | 276 | mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, |
277 | "X-Department", "KADDRESSBOOK" ); | 277 | "X-Department", "KADDRESSBOOK" ); |
278 | mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 278 | mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
279 | "X-Profession", "KADDRESSBOOK" ); | 279 | "X-Profession", "KADDRESSBOOK" ); |
280 | mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 280 | mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
281 | "X-AssistantsName", "KADDRESSBOOK" ); | 281 | "X-AssistantsName", "KADDRESSBOOK" ); |
282 | mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 282 | mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
283 | "X-ManagersName", "KADDRESSBOOK" ); | 283 | "X-ManagersName", "KADDRESSBOOK" ); |
284 | mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 284 | mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
285 | "X-SpousesName", "KADDRESSBOOK" ); | 285 | "X-SpousesName", "KADDRESSBOOK" ); |
286 | mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal, | 286 | mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal, |
287 | "X-Office", "KADDRESSBOOK" ); | 287 | "X-Office", "KADDRESSBOOK" ); |
288 | mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 288 | mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
289 | "X-IMAddress", "KADDRESSBOOK" ); | 289 | "X-IMAddress", "KADDRESSBOOK" ); |
290 | mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 290 | mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
291 | "X-Anniversary", "KADDRESSBOOK" ); | 291 | "X-Anniversary", "KADDRESSBOOK" ); |
292 | 292 | ||
293 | //US added this field to become compatible with Opie/qtopia addressbook | 293 | //US added this field to become compatible with Opie/qtopia addressbook |
294 | // values can be "female" or "male" or "". An empty field represents undefined. | 294 | // values can be "female" or "male" or "". An empty field represents undefined. |
295 | mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 295 | mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
296 | "X-Gender", "KADDRESSBOOK" ); | 296 | "X-Gender", "KADDRESSBOOK" ); |
297 | mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal, | 297 | mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal, |
298 | "X-Children", "KADDRESSBOOK" ); | 298 | "X-Children", "KADDRESSBOOK" ); |
299 | mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 299 | mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
300 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 300 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
301 | #endif | 301 | #endif |
302 | initGUI(); | 302 | initGUI(); |
303 | 303 | ||
304 | mIncSearchWidget->setFocus(); | 304 | mIncSearchWidget->setFocus(); |
305 | 305 | ||
306 | 306 | ||
307 | connect( mViewManager, SIGNAL( selected( const QString& ) ), | 307 | connect( mViewManager, SIGNAL( selected( const QString& ) ), |
308 | SLOT( setContactSelected( const QString& ) ) ); | 308 | SLOT( setContactSelected( const QString& ) ) ); |
309 | connect( mViewManager, SIGNAL( executed( const QString& ) ), | 309 | connect( mViewManager, SIGNAL( executed( const QString& ) ), |
310 | SLOT( executeContact( const QString& ) ) ); | 310 | SLOT( executeContact( const QString& ) ) ); |
311 | 311 | ||
312 | connect( mViewManager, SIGNAL( deleteRequest( ) ), | 312 | connect( mViewManager, SIGNAL( deleteRequest( ) ), |
313 | SLOT( deleteContacts( ) ) ); | 313 | SLOT( deleteContacts( ) ) ); |
314 | connect( mViewManager, SIGNAL( modified() ), | 314 | connect( mViewManager, SIGNAL( modified() ), |
315 | SLOT( setModified() ) ); | 315 | SLOT( setModified() ) ); |
316 | 316 | ||
317 | connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) ); | 317 | connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) ); |
318 | connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) ); | 318 | connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) ); |
319 | 319 | ||
320 | connect( mXXPortManager, SIGNAL( modified() ), | 320 | connect( mXXPortManager, SIGNAL( modified() ), |
321 | SLOT( setModified() ) ); | 321 | SLOT( setModified() ) ); |
322 | 322 | ||
323 | connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ), | 323 | connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ), |
324 | SLOT( incrementalSearch( const QString& ) ) ); | 324 | SLOT( incrementalSearch( const QString& ) ) ); |
325 | connect( mIncSearchWidget, SIGNAL( fieldChanged() ), | 325 | connect( mIncSearchWidget, SIGNAL( fieldChanged() ), |
326 | mJumpButtonBar, SLOT( recreateButtons() ) ); | 326 | mJumpButtonBar, SLOT( recreateButtons() ) ); |
327 | 327 | ||
328 | connect( mDetails, SIGNAL( sendEmail( const QString& ) ), | 328 | connect( mDetails, SIGNAL( sendEmail( const QString& ) ), |
329 | SLOT( sendMail( const QString& ) ) ); | 329 | SLOT( sendMail( const QString& ) ) ); |
330 | 330 | ||
331 | 331 | ||
332 | connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&))); | 332 | connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&))); |
333 | connect( ExternalAppHandler::instance(), SIGNAL (requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)),this, SLOT(requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&))); | 333 | connect( ExternalAppHandler::instance(), SIGNAL (requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)),this, SLOT(requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&))); |
334 | connect( ExternalAppHandler::instance(), SIGNAL (requestForBirthdayList(const QString&, const QString&)),this, SLOT(requestForBirthdayList(const QString&, const QString&))); | 334 | connect( ExternalAppHandler::instance(), SIGNAL (requestForBirthdayList(const QString&, const QString&)),this, SLOT(requestForBirthdayList(const QString&, const QString&))); |
335 | connect( ExternalAppHandler::instance(), SIGNAL (nextView()),this, SLOT(setDetailsToggle())); | 335 | connect( ExternalAppHandler::instance(), SIGNAL (nextView()),this, SLOT(setDetailsToggle())); |
336 | 336 | ||
337 | 337 | ||
338 | #ifndef KAB_EMBEDDED | 338 | #ifndef KAB_EMBEDDED |
339 | connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ), | 339 | connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ), |
340 | mXXPortManager, SLOT( importVCard( const KURL& ) ) ); | 340 | mXXPortManager, SLOT( importVCard( const KURL& ) ) ); |
341 | 341 | ||
342 | connect( mDetails, SIGNAL( browse( const QString& ) ), | 342 | connect( mDetails, SIGNAL( browse( const QString& ) ), |
343 | SLOT( browse( const QString& ) ) ); | 343 | SLOT( browse( const QString& ) ) ); |
344 | 344 | ||
345 | 345 | ||
346 | mAddressBookService = new KAddressBookService( this ); | 346 | mAddressBookService = new KAddressBookService( this ); |
347 | 347 | ||
348 | #endif //KAB_EMBEDDED | 348 | #endif //KAB_EMBEDDED |
349 | 349 | ||
350 | mMessageTimer = new QTimer( this ); | 350 | mMessageTimer = new QTimer( this ); |
351 | connect( mMessageTimer, SIGNAL( timeout() ), this, SLOT( setCaptionBack() ) ); | 351 | connect( mMessageTimer, SIGNAL( timeout() ), this, SLOT( setCaptionBack() ) ); |
352 | mEditorDialog = 0; | 352 | mEditorDialog = 0; |
353 | createAddresseeEditorDialog( this ); | 353 | createAddresseeEditorDialog( this ); |
354 | setModified( false ); | 354 | setModified( false ); |
355 | mBRdisabled = false; | 355 | mBRdisabled = false; |
356 | #ifndef DESKTOP_VERSION | 356 | #ifndef DESKTOP_VERSION |
357 | infrared = 0; | 357 | infrared = 0; |
358 | #endif | 358 | #endif |
359 | //toggleBeamReceive( ); | 359 | //toggleBeamReceive( ); |
360 | 360 | ||
361 | // we have a toolbar repainting error on the Zaurus when starting KA/Pi | 361 | // we have a toolbar repainting error on the Zaurus when starting KA/Pi |
362 | QTimer::singleShot( 1, this , SLOT ( updateToolBar())); | 362 | QTimer::singleShot( 1, this , SLOT ( updateToolBar())); |
363 | } | 363 | } |
364 | 364 | ||
365 | void KABCore::updateToolBar() | 365 | void KABCore::updateToolBar() |
366 | { | 366 | { |
367 | mMainWindow->toolBar()->repaint(); | 367 | mMainWindow->toolBar()->repaint(); |
368 | } | 368 | } |
369 | KABCore::~KABCore() | 369 | KABCore::~KABCore() |
370 | { | 370 | { |
371 | // save(); | 371 | // save(); |
372 | //saveSettings(); | 372 | //saveSettings(); |
373 | //KABPrefs::instance()->writeConfig(); | 373 | //KABPrefs::instance()->writeConfig(); |
374 | delete AddresseeConfig::instance(); | 374 | delete AddresseeConfig::instance(); |
375 | mAddressBook = 0; | 375 | mAddressBook = 0; |
376 | KABC::StdAddressBook::close(); | 376 | KABC::StdAddressBook::close(); |
377 | 377 | ||
378 | delete syncManager; | 378 | delete syncManager; |
379 | #ifndef DESKTOP_VERSION | 379 | #ifndef DESKTOP_VERSION |
380 | if ( infrared ) | 380 | if ( infrared ) |
381 | delete infrared; | 381 | delete infrared; |
382 | #endif | 382 | #endif |
383 | } | 383 | } |
384 | void KABCore::receive( const QCString& cmsg, const QByteArray& data ) | 384 | void KABCore::receive( const QCString& cmsg, const QByteArray& data ) |
385 | { | 385 | { |
386 | qDebug("KA: QCOP message received: %s ", cmsg.data() ); | 386 | qDebug("KA: QCOP message received: %s ", cmsg.data() ); |
387 | if ( cmsg == "setDocument(QString)" ) { | 387 | if ( cmsg == "setDocument(QString)" ) { |
388 | QDataStream stream( data, IO_ReadOnly ); | 388 | QDataStream stream( data, IO_ReadOnly ); |
389 | QString fileName; | 389 | QString fileName; |
390 | stream >> fileName; | 390 | stream >> fileName; |
391 | recieve( fileName ); | 391 | recieve( fileName ); |
392 | return; | 392 | return; |
393 | } | 393 | } |
394 | } | 394 | } |
395 | void KABCore::toggleBeamReceive( ) | 395 | void KABCore::toggleBeamReceive( ) |
396 | { | 396 | { |
397 | if ( mBRdisabled ) | 397 | if ( mBRdisabled ) |
398 | return; | 398 | return; |
399 | #ifndef DESKTOP_VERSION | 399 | #ifndef DESKTOP_VERSION |
400 | if ( infrared ) { | 400 | if ( infrared ) { |
401 | qDebug("AB disable BeamReceive "); | 401 | qDebug("AB disable BeamReceive "); |
402 | delete infrared; | 402 | delete infrared; |
403 | infrared = 0; | 403 | infrared = 0; |
404 | mActionBR->setChecked(false); | 404 | mActionBR->setChecked(false); |
405 | return; | 405 | return; |
406 | } | 406 | } |
407 | qDebug("AB enable BeamReceive "); | 407 | qDebug("AB enable BeamReceive "); |
408 | mActionBR->setChecked(true); | 408 | mActionBR->setChecked(true); |
409 | 409 | ||
410 | infrared = new QCopChannel("QPE/Application/addressbook",this, "channelAB" ) ; | 410 | infrared = new QCopChannel("QPE/Application/addressbook",this, "channelAB" ) ; |
411 | QObject::connect( infrared, SIGNAL (received ( const QCString &, const QByteArray & )),this, SLOT(receive( const QCString&, const QByteArray& ))); | 411 | QObject::connect( infrared, SIGNAL (received ( const QCString &, const QByteArray & )),this, SLOT(receive( const QCString&, const QByteArray& ))); |
412 | #endif | 412 | #endif |
413 | } | 413 | } |
414 | 414 | ||
415 | 415 | ||
416 | void KABCore::disableBR(bool b) | 416 | void KABCore::disableBR(bool b) |
417 | { | 417 | { |
418 | #ifndef DESKTOP_VERSION | 418 | #ifndef DESKTOP_VERSION |
419 | if ( b ) { | 419 | if ( b ) { |
420 | if ( infrared ) { | 420 | if ( infrared ) { |
421 | toggleBeamReceive( ); | 421 | toggleBeamReceive( ); |
422 | } | 422 | } |
423 | mBRdisabled = true; | 423 | mBRdisabled = true; |
424 | } else { | 424 | } else { |
425 | if ( mBRdisabled ) { | 425 | if ( mBRdisabled ) { |
426 | mBRdisabled = false; | 426 | mBRdisabled = false; |
427 | //toggleBeamReceive( ); | 427 | //toggleBeamReceive( ); |
428 | } | 428 | } |
429 | } | 429 | } |
430 | #endif | 430 | #endif |
431 | 431 | ||
432 | } | 432 | } |
433 | void KABCore::recieve( QString fn ) | 433 | void KABCore::recieve( QString fn ) |
434 | { | 434 | { |
435 | //qDebug("KABCore::recieve "); | 435 | //qDebug("KABCore::recieve "); |
436 | int count = mAddressBook->importFromFile( fn, true ); | 436 | int count = mAddressBook->importFromFile( fn, true ); |
437 | if ( count ) | 437 | if ( count ) |
438 | setModified( true ); | 438 | setModified( true ); |
439 | mViewManager->refreshView(); | 439 | mViewManager->refreshView(); |
440 | message(i18n("%1 contact(s) received!").arg( count )); | 440 | message(i18n("%1 contact(s) received!").arg( count )); |
441 | topLevelWidget()->showMaximized(); | 441 | topLevelWidget()->showMaximized(); |
442 | topLevelWidget()->raise(); | 442 | topLevelWidget()->raise(); |
443 | } | 443 | } |
444 | void KABCore::restoreSettings() | 444 | void KABCore::restoreSettings() |
445 | { | 445 | { |
446 | mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce; | 446 | mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce; |
447 | 447 | ||
448 | bool state; | 448 | bool state; |
449 | 449 | ||
450 | if (mMultipleViewsAtOnce) | 450 | if (mMultipleViewsAtOnce) |
451 | state = KABPrefs::instance()->mDetailsPageVisible; | 451 | state = KABPrefs::instance()->mDetailsPageVisible; |
452 | else | 452 | else |
453 | state = false; | 453 | state = false; |
454 | 454 | ||
455 | mActionDetails->setChecked( state ); | 455 | mActionDetails->setChecked( state ); |
456 | setDetailsVisible( state ); | 456 | setDetailsVisible( state ); |
457 | 457 | ||
458 | state = KABPrefs::instance()->mJumpButtonBarVisible; | 458 | state = KABPrefs::instance()->mJumpButtonBarVisible; |
459 | 459 | ||
460 | mActionJumpBar->setChecked( state ); | 460 | mActionJumpBar->setChecked( state ); |
461 | setJumpButtonBarVisible( state ); | 461 | setJumpButtonBarVisible( state ); |
462 | /*US | 462 | /*US |
463 | QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter; | 463 | QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter; |
464 | if ( splitterSize.count() == 0 ) { | 464 | if ( splitterSize.count() == 0 ) { |
465 | splitterSize.append( width() / 2 ); | 465 | splitterSize.append( width() / 2 ); |
466 | splitterSize.append( width() / 2 ); | 466 | splitterSize.append( width() / 2 ); |
467 | } | 467 | } |
468 | mMiniSplitter->setSizes( splitterSize ); | 468 | mMiniSplitter->setSizes( splitterSize ); |
469 | if ( mExtensionBarSplitter ) { | 469 | if ( mExtensionBarSplitter ) { |
470 | splitterSize = KABPrefs::instance()->mExtensionsSplitter; | 470 | splitterSize = KABPrefs::instance()->mExtensionsSplitter; |
471 | if ( splitterSize.count() == 0 ) { | 471 | if ( splitterSize.count() == 0 ) { |
472 | splitterSize.append( width() / 2 ); | 472 | splitterSize.append( width() / 2 ); |
473 | splitterSize.append( width() / 2 ); | 473 | splitterSize.append( width() / 2 ); |
474 | } | 474 | } |
475 | mExtensionBarSplitter->setSizes( splitterSize ); | 475 | mExtensionBarSplitter->setSizes( splitterSize ); |
476 | 476 | ||
477 | } | 477 | } |
478 | */ | 478 | */ |
479 | mViewManager->restoreSettings(); | 479 | mViewManager->restoreSettings(); |
480 | mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField ); | 480 | mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField ); |
481 | mExtensionManager->restoreSettings(); | 481 | mExtensionManager->restoreSettings(); |
482 | #ifdef DESKTOP_VERSION | 482 | #ifdef DESKTOP_VERSION |
483 | int wid = width(); | 483 | int wid = width(); |
484 | if ( wid < 10 ) | 484 | if ( wid < 10 ) |
485 | wid = 400; | 485 | wid = 400; |
486 | #else | 486 | #else |
487 | int wid = QApplication::desktop()->width(); | 487 | int wid = QApplication::desktop()->width(); |
488 | if ( wid < 640 ) | 488 | if ( wid < 640 ) |
489 | wid = QApplication::desktop()->height(); | 489 | wid = QApplication::desktop()->height(); |
490 | #endif | 490 | #endif |
491 | QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter; | 491 | QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter; |
492 | if ( true /*splitterSize.count() == 0*/ ) { | 492 | if ( true /*splitterSize.count() == 0*/ ) { |
493 | splitterSize.append( wid / 2 ); | 493 | splitterSize.append( wid / 2 ); |
494 | splitterSize.append( wid / 2 ); | 494 | splitterSize.append( wid / 2 ); |
495 | } | 495 | } |
496 | mMiniSplitter->setSizes( splitterSize ); | 496 | mMiniSplitter->setSizes( splitterSize ); |
497 | if ( mExtensionBarSplitter ) { | 497 | if ( mExtensionBarSplitter ) { |
498 | //splitterSize = KABPrefs::instance()->mExtensionsSplitter; | 498 | //splitterSize = KABPrefs::instance()->mExtensionsSplitter; |
499 | if ( true /*splitterSize.count() == 0*/ ) { | 499 | if ( true /*splitterSize.count() == 0*/ ) { |
500 | splitterSize.append( wid / 2 ); | 500 | splitterSize.append( wid / 2 ); |
501 | splitterSize.append( wid / 2 ); | 501 | splitterSize.append( wid / 2 ); |
502 | } | 502 | } |
503 | mExtensionBarSplitter->setSizes( splitterSize ); | 503 | mExtensionBarSplitter->setSizes( splitterSize ); |
504 | 504 | ||
505 | } | 505 | } |
506 | 506 | ||
507 | 507 | ||
508 | } | 508 | } |
509 | 509 | ||
510 | void KABCore::saveSettings() | 510 | void KABCore::saveSettings() |
511 | { | 511 | { |
512 | KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked(); | 512 | KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked(); |
513 | if ( mExtensionBarSplitter ) | 513 | if ( mExtensionBarSplitter ) |
514 | KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); | 514 | KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); |
515 | KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked(); | 515 | KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked(); |
516 | KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes(); | 516 | KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes(); |
517 | #ifndef KAB_EMBEDDED | 517 | #ifndef KAB_EMBEDDED |
518 | 518 | ||
519 | KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); | 519 | KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); |
520 | KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes(); | 520 | KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes(); |
521 | #endif //KAB_EMBEDDED | 521 | #endif //KAB_EMBEDDED |
522 | mExtensionManager->saveSettings(); | 522 | mExtensionManager->saveSettings(); |
523 | mViewManager->saveSettings(); | 523 | mViewManager->saveSettings(); |
524 | 524 | ||
525 | KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem(); | 525 | KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem(); |
526 | } | 526 | } |
527 | 527 | ||
528 | KABC::AddressBook *KABCore::addressBook() const | 528 | KABC::AddressBook *KABCore::addressBook() const |
529 | { | 529 | { |
530 | return mAddressBook; | 530 | return mAddressBook; |
531 | } | 531 | } |
532 | 532 | ||
533 | KConfig *KABCore::config() | 533 | KConfig *KABCore::config() |
534 | { | 534 | { |
535 | #ifndef KAB_EMBEDDED | 535 | #ifndef KAB_EMBEDDED |
536 | return KABPrefs::instance()->config(); | 536 | return KABPrefs::instance()->config(); |
537 | #else //KAB_EMBEDDED | 537 | #else //KAB_EMBEDDED |
538 | return KABPrefs::instance()->getConfig(); | 538 | return KABPrefs::instance()->getConfig(); |
539 | #endif //KAB_EMBEDDED | 539 | #endif //KAB_EMBEDDED |
540 | } | 540 | } |
541 | 541 | ||
542 | KActionCollection *KABCore::actionCollection() const | 542 | KActionCollection *KABCore::actionCollection() const |
543 | { | 543 | { |
544 | return mGUIClient->actionCollection(); | 544 | return mGUIClient->actionCollection(); |
545 | } | 545 | } |
546 | 546 | ||
547 | KABC::Field *KABCore::currentSearchField() const | 547 | KABC::Field *KABCore::currentSearchField() const |
548 | { | 548 | { |
549 | if (mIncSearchWidget) | 549 | if (mIncSearchWidget) |
550 | return mIncSearchWidget->currentField(); | 550 | return mIncSearchWidget->currentField(); |
551 | else | 551 | else |
552 | return 0; | 552 | return 0; |
553 | } | 553 | } |
554 | 554 | ||
555 | QStringList KABCore::selectedUIDs() const | 555 | QStringList KABCore::selectedUIDs() const |
556 | { | 556 | { |
557 | return mViewManager->selectedUids(); | 557 | return mViewManager->selectedUids(); |
558 | } | 558 | } |
559 | 559 | ||
560 | KABC::Resource *KABCore::requestResource( QWidget *parent ) | 560 | KABC::Resource *KABCore::requestResource( QWidget *parent ) |
561 | { | 561 | { |
562 | QPtrList<KABC::Resource> kabcResources = addressBook()->resources(); | 562 | QPtrList<KABC::Resource> kabcResources = addressBook()->resources(); |
563 | 563 | ||
564 | QPtrList<KRES::Resource> kresResources; | 564 | QPtrList<KRES::Resource> kresResources; |
565 | QPtrListIterator<KABC::Resource> resIt( kabcResources ); | 565 | QPtrListIterator<KABC::Resource> resIt( kabcResources ); |
566 | KABC::Resource *resource; | 566 | KABC::Resource *resource; |
567 | while ( ( resource = resIt.current() ) != 0 ) { | 567 | while ( ( resource = resIt.current() ) != 0 ) { |
568 | ++resIt; | 568 | ++resIt; |
569 | if ( !resource->readOnly() ) { | 569 | if ( !resource->readOnly() ) { |
570 | KRES::Resource *res = static_cast<KRES::Resource*>( resource ); | 570 | KRES::Resource *res = static_cast<KRES::Resource*>( resource ); |
571 | if ( res ) | 571 | if ( res ) |
572 | kresResources.append( res ); | 572 | kresResources.append( res ); |
573 | } | 573 | } |
574 | } | 574 | } |
575 | 575 | ||
576 | KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent ); | 576 | KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent ); |
577 | return static_cast<KABC::Resource*>( res ); | 577 | return static_cast<KABC::Resource*>( res ); |
578 | } | 578 | } |
579 | 579 | ||
580 | #ifndef KAB_EMBEDDED | 580 | #ifndef KAB_EMBEDDED |
581 | KAboutData *KABCore::createAboutData() | 581 | KAboutData *KABCore::createAboutData() |
582 | #else //KAB_EMBEDDED | 582 | #else //KAB_EMBEDDED |
583 | void KABCore::createAboutData() | 583 | void KABCore::createAboutData() |
584 | #endif //KAB_EMBEDDED | 584 | #endif //KAB_EMBEDDED |
585 | { | 585 | { |
586 | #ifndef KAB_EMBEDDED | 586 | #ifndef KAB_EMBEDDED |
587 | KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ), | 587 | KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ), |
588 | "3.1", I18N_NOOP( "The KDE Address Book" ), | 588 | "3.1", I18N_NOOP( "The KDE Address Book" ), |
589 | KAboutData::License_GPL_V2, | 589 | KAboutData::License_GPL_V2, |
590 | I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) ); | 590 | I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) ); |
591 | about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" ); | 591 | about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" ); |
592 | about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) ); | 592 | about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) ); |
593 | about->addAuthor( "Cornelius Schumacher", | 593 | about->addAuthor( "Cornelius Schumacher", |
594 | I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ), | 594 | I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ), |
595 | "schumacher@kde.org" ); | 595 | "schumacher@kde.org" ); |
596 | about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ), | 596 | about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ), |
597 | "mpilone@slac.com" ); | 597 | "mpilone@slac.com" ); |
598 | about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) ); | 598 | about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) ); |
599 | about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) ); | 599 | about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) ); |
600 | about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ), | 600 | about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ), |
601 | "michel@klaralvdalens-datakonsult.se" ); | 601 | "michel@klaralvdalens-datakonsult.se" ); |
602 | about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ), | 602 | about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ), |
603 | "hansen@kde.org" ); | 603 | "hansen@kde.org" ); |
604 | 604 | ||
605 | return about; | 605 | return about; |
606 | #endif //KAB_EMBEDDED | 606 | #endif //KAB_EMBEDDED |
607 | 607 | ||
608 | QString version; | 608 | QString version; |
609 | #include <../version> | 609 | #include <../version> |
610 | QMessageBox::about( this, "About KAddressbook/Pi", | 610 | QMessageBox::about( this, "About KAddressbook/Pi", |
611 | "KAddressbook/Platform-independent\n" | 611 | "KAddressbook/Platform-independent\n" |
612 | "(KA/Pi) " +version + " - " + | 612 | "(KA/Pi) " +version + " - " + |
613 | #ifdef DESKTOP_VERSION | 613 | #ifdef DESKTOP_VERSION |
614 | "Desktop Edition\n" | 614 | "Desktop Edition\n" |
615 | #else | 615 | #else |
616 | "PDA-Edition\n" | 616 | "PDA-Edition\n" |
617 | "for: Zaurus 5500 / 7x0 / 8x0\n" | 617 | "for: Zaurus 5500 / 7x0 / 8x0\n" |
618 | #endif | 618 | #endif |
619 | 619 | ||
620 | "(c) 2004 Ulf Schenk\n" | 620 | "(c) 2004 Ulf Schenk\n" |
621 | "(c) 2004 Lutz Rogowski\n" | 621 | "(c) 2004 Lutz Rogowski\n" |
622 | "(c) 1997-2003, The KDE PIM Team\n" | 622 | "(c) 1997-2003, The KDE PIM Team\n" |
623 | "Tobias Koenig Current maintainer\ntokoe@kde.org\n" | 623 | "Tobias Koenig Current maintainer\ntokoe@kde.org\n" |
624 | "Don Sanders Original author\n" | 624 | "Don Sanders Original author\n" |
625 | "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n" | 625 | "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n" |
626 | "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n" | 626 | "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n" |
627 | "Greg Stern DCOP interface\n" | 627 | "Greg Stern DCOP interface\n" |
628 | "Mark Westcot Contact pinning\n" | 628 | "Mark Westcot Contact pinning\n" |
629 | "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n" | 629 | "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n" |
630 | "Steffen Hansen LDAP Lookup\nhansen@kde.org\n" | 630 | "Steffen Hansen LDAP Lookup\nhansen@kde.org\n" |
631 | #ifdef _WIN32_ | 631 | #ifdef _WIN32_ |
632 | "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n" | 632 | "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n" |
633 | #endif | 633 | #endif |
634 | ); | 634 | ); |
635 | } | 635 | } |
636 | 636 | ||
637 | void KABCore::setContactSelected( const QString &uid ) | 637 | void KABCore::setContactSelected( const QString &uid ) |
638 | { | 638 | { |
639 | KABC::Addressee addr = mAddressBook->findByUid( uid ); | 639 | KABC::Addressee addr = mAddressBook->findByUid( uid ); |
640 | if ( !mDetails->isHidden() ) | 640 | if ( !mDetails->isHidden() ) |
641 | mDetails->setAddressee( addr ); | 641 | mDetails->setAddressee( addr ); |
642 | 642 | ||
643 | if ( !addr.isEmpty() ) { | 643 | if ( !addr.isEmpty() ) { |
644 | emit contactSelected( addr.formattedName() ); | 644 | emit contactSelected( addr.formattedName() ); |
645 | KABC::Picture pic = addr.photo(); | 645 | KABC::Picture pic = addr.photo(); |
646 | if ( pic.isIntern() ) { | 646 | if ( pic.isIntern() ) { |
647 | //US emit contactSelected( pic.data() ); | 647 | //US emit contactSelected( pic.data() ); |
648 | //US instead use: | 648 | //US instead use: |
649 | QPixmap px; | 649 | QPixmap px; |
650 | if (pic.data().isNull() != true) | 650 | if (pic.data().isNull() != true) |
651 | { | 651 | { |
652 | px.convertFromImage(pic.data()); | 652 | px.convertFromImage(pic.data()); |
653 | } | 653 | } |
654 | 654 | ||
655 | emit contactSelected( px ); | 655 | emit contactSelected( px ); |
656 | } | 656 | } |
657 | } | 657 | } |
658 | 658 | ||
659 | 659 | ||
660 | mExtensionManager->setSelectionChanged(); | 660 | mExtensionManager->setSelectionChanged(); |
661 | 661 | ||
662 | // update the actions | 662 | // update the actions |
663 | bool selected = !uid.isEmpty(); | 663 | bool selected = !uid.isEmpty(); |
664 | 664 | ||
665 | if ( mReadWrite ) { | 665 | if ( mReadWrite ) { |
666 | mActionCut->setEnabled( selected ); | 666 | mActionCut->setEnabled( selected ); |
667 | mActionPaste->setEnabled( selected ); | 667 | mActionPaste->setEnabled( selected ); |
668 | } | 668 | } |
669 | 669 | ||
670 | mActionCopy->setEnabled( selected ); | 670 | mActionCopy->setEnabled( selected ); |
671 | mActionDelete->setEnabled( selected ); | 671 | mActionDelete->setEnabled( selected ); |
672 | mActionEditAddressee->setEnabled( selected ); | 672 | mActionEditAddressee->setEnabled( selected ); |
673 | mActionMail->setEnabled( selected ); | 673 | mActionMail->setEnabled( selected ); |
674 | mActionMailVCard->setEnabled( selected ); | 674 | mActionMailVCard->setEnabled( selected ); |
675 | //if (mActionBeam) | 675 | //if (mActionBeam) |
676 | //mActionBeam->setEnabled( selected ); | 676 | //mActionBeam->setEnabled( selected ); |
677 | 677 | ||
678 | if (mActionBeamVCard) | 678 | if (mActionBeamVCard) |
679 | mActionBeamVCard->setEnabled( selected ); | 679 | mActionBeamVCard->setEnabled( selected ); |
680 | 680 | ||
681 | mActionExport2phone->setEnabled( selected ); | 681 | mActionExport2phone->setEnabled( selected ); |
682 | mActionWhoAmI->setEnabled( selected ); | 682 | mActionWhoAmI->setEnabled( selected ); |
683 | mActionCategories->setEnabled( selected ); | 683 | mActionCategories->setEnabled( selected ); |
684 | } | 684 | } |
685 | 685 | ||
686 | void KABCore::sendMail() | 686 | void KABCore::sendMail() |
687 | { | 687 | { |
688 | sendMail( mViewManager->selectedEmails().join( ", " ) ); | 688 | sendMail( mViewManager->selectedEmails().join( ", " ) ); |
689 | } | 689 | } |
690 | 690 | ||
691 | void KABCore::sendMail( const QString& emaillist ) | 691 | void KABCore::sendMail( const QString& emaillist ) |
692 | { | 692 | { |
693 | // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... " | 693 | // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... " |
694 | if (emaillist.contains(",") > 0) | 694 | if (emaillist.contains(",") > 0) |
695 | ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null ); | 695 | ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null ); |
696 | else | 696 | else |
697 | ExternalAppHandler::instance()->mailToOneContact( emaillist ); | 697 | ExternalAppHandler::instance()->mailToOneContact( emaillist ); |
698 | } | 698 | } |
699 | 699 | ||
700 | 700 | ||
701 | 701 | ||
702 | void KABCore::mailVCard() | 702 | void KABCore::mailVCard() |
703 | { | 703 | { |
704 | QStringList uids = mViewManager->selectedUids(); | 704 | QStringList uids = mViewManager->selectedUids(); |
705 | if ( !uids.isEmpty() ) | 705 | if ( !uids.isEmpty() ) |
706 | mailVCard( uids ); | 706 | mailVCard( uids ); |
707 | } | 707 | } |
708 | 708 | ||
709 | void KABCore::mailVCard( const QStringList& uids ) | 709 | void KABCore::mailVCard( const QStringList& uids ) |
710 | { | 710 | { |
711 | QStringList urls; | 711 | QStringList urls; |
712 | 712 | ||
713 | // QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); | 713 | // QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); |
714 | 714 | ||
715 | QString dirName = "/tmp/" + KApplication::randomString( 8 ); | 715 | QString dirName = "/tmp/" + KApplication::randomString( 8 ); |
716 | 716 | ||
717 | 717 | ||
718 | 718 | ||
719 | QDir().mkdir( dirName, true ); | 719 | QDir().mkdir( dirName, true ); |
720 | 720 | ||
721 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | 721 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { |
722 | KABC::Addressee a = mAddressBook->findByUid( *it ); | 722 | KABC::Addressee a = mAddressBook->findByUid( *it ); |
723 | 723 | ||
724 | if ( a.isEmpty() ) | 724 | if ( a.isEmpty() ) |
725 | continue; | 725 | continue; |
726 | 726 | ||
727 | QString name = a.givenName() + "_" + a.familyName() + ".vcf"; | 727 | QString name = a.givenName() + "_" + a.familyName() + ".vcf"; |
728 | 728 | ||
729 | QString fileName = dirName + "/" + name; | 729 | QString fileName = dirName + "/" + name; |
730 | 730 | ||
731 | QFile outFile(fileName); | 731 | QFile outFile(fileName); |
732 | 732 | ||
733 | if ( outFile.open(IO_WriteOnly) ) { // file opened successfully | 733 | if ( outFile.open(IO_WriteOnly) ) { // file opened successfully |
734 | KABC::VCardConverter converter; | 734 | KABC::VCardConverter converter; |
735 | QString vcard; | 735 | QString vcard; |
736 | 736 | ||
737 | converter.addresseeToVCard( a, vcard ); | 737 | converter.addresseeToVCard( a, vcard ); |
738 | 738 | ||
739 | QTextStream t( &outFile ); // use a text stream | 739 | QTextStream t( &outFile ); // use a text stream |
740 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 740 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
741 | t << vcard; | 741 | t << vcard; |
742 | 742 | ||
743 | outFile.close(); | 743 | outFile.close(); |
744 | 744 | ||
745 | urls.append( fileName ); | 745 | urls.append( fileName ); |
746 | } | 746 | } |
747 | } | 747 | } |
748 | 748 | ||
749 | bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); | 749 | bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); |
750 | 750 | ||
751 | 751 | ||
752 | /*US | 752 | /*US |
753 | kapp->invokeMailer( QString::null, QString::null, QString::null, | 753 | kapp->invokeMailer( QString::null, QString::null, QString::null, |
754 | QString::null, // subject | 754 | QString::null, // subject |
755 | QString::null, // body | 755 | QString::null, // body |
756 | QString::null, | 756 | QString::null, |
757 | urls ); // attachments | 757 | urls ); // attachments |
758 | */ | 758 | */ |
759 | 759 | ||
760 | } | 760 | } |
761 | 761 | ||
762 | /** | 762 | /** |
763 | Beams the "WhoAmI contact. | 763 | Beams the "WhoAmI contact. |
764 | */ | 764 | */ |
765 | void KABCore::beamMySelf() | 765 | void KABCore::beamMySelf() |
766 | { | 766 | { |
767 | KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); | 767 | KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); |
768 | if (!a.isEmpty()) | 768 | if (!a.isEmpty()) |
769 | { | 769 | { |
770 | QStringList uids; | 770 | QStringList uids; |
771 | uids << a.uid(); | 771 | uids << a.uid(); |
772 | 772 | ||
773 | beamVCard(uids); | 773 | beamVCard(uids); |
774 | } else { | 774 | } else { |
775 | KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); | 775 | KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); |
776 | 776 | ||
777 | 777 | ||
778 | } | 778 | } |
779 | } | 779 | } |
780 | 780 | ||
781 | void KABCore::export2phone() | 781 | void KABCore::export2phone() |
782 | { | 782 | { |
783 | 783 | ||
784 | KAex2phonePrefs ex2phone; | 784 | KAex2phonePrefs ex2phone; |
785 | ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection ); | 785 | ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection ); |
786 | ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice ); | 786 | ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice ); |
787 | ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel ); | 787 | ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel ); |
788 | 788 | ||
789 | if ( !ex2phone.exec() ) { | 789 | if ( !ex2phone.exec() ) { |
790 | return; | 790 | return; |
791 | } | 791 | } |
792 | KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text(); | 792 | KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text(); |
793 | KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text(); | 793 | KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text(); |
794 | KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text(); | 794 | KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text(); |
795 | 795 | ||
796 | 796 | ||
797 | PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice, | 797 | PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice, |
798 | KPimGlobalPrefs::instance()->mEx2PhoneConnection, | 798 | KPimGlobalPrefs::instance()->mEx2PhoneConnection, |
799 | KPimGlobalPrefs::instance()->mEx2PhoneModel ); | 799 | KPimGlobalPrefs::instance()->mEx2PhoneModel ); |
800 | 800 | ||
801 | QStringList uids = mViewManager->selectedUids(); | 801 | QStringList uids = mViewManager->selectedUids(); |
802 | if ( uids.isEmpty() ) | 802 | if ( uids.isEmpty() ) |
803 | return; | 803 | return; |
804 | 804 | ||
805 | QString fileName = getPhoneFile(); | 805 | QString fileName = getPhoneFile(); |
806 | if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) ) | 806 | if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) ) |
807 | return; | 807 | return; |
808 | 808 | ||
809 | message(i18n("Exporting to phone...")); | 809 | message(i18n("Exporting to phone...")); |
810 | QTimer::singleShot( 1, this , SLOT ( writeToPhone())); | 810 | QTimer::singleShot( 1, this , SLOT ( writeToPhone())); |
811 | 811 | ||
812 | } | 812 | } |
813 | QString KABCore::getPhoneFile() | 813 | QString KABCore::getPhoneFile() |
814 | { | 814 | { |
815 | #ifdef DESKTOP_VERSION | 815 | #ifdef DESKTOP_VERSION |
816 | return locateLocal("tmp", "phonefile.vcf"); | 816 | return locateLocal("tmp", "phonefile.vcf"); |
817 | #else | 817 | #else |
818 | return "/tmp/phonefile.vcf"; | 818 | return "/tmp/phonefile.vcf"; |
819 | #endif | 819 | #endif |
820 | 820 | ||
821 | } | 821 | } |
822 | void KABCore::writeToPhone( ) | 822 | void KABCore::writeToPhone( ) |
823 | { | 823 | { |
824 | if ( PhoneAccess::writeToPhone( getPhoneFile() ) ) | 824 | if ( PhoneAccess::writeToPhone( getPhoneFile() ) ) |
825 | message(i18n("Export to phone finished!")); | 825 | message(i18n("Export to phone finished!")); |
826 | else | 826 | else |
827 | qDebug(i18n("Error exporting to phone")); | 827 | qDebug(i18n("Error exporting to phone")); |
828 | } | 828 | } |
829 | void KABCore::beamVCard() | 829 | void KABCore::beamVCard() |
830 | { | 830 | { |
831 | QStringList uids = mViewManager->selectedUids(); | 831 | QStringList uids = mViewManager->selectedUids(); |
832 | if ( !uids.isEmpty() ) | 832 | if ( !uids.isEmpty() ) |
833 | beamVCard( uids ); | 833 | beamVCard( uids ); |
834 | } | 834 | } |
835 | 835 | ||
836 | 836 | ||
837 | void KABCore::beamVCard(const QStringList& uids) | 837 | void KABCore::beamVCard(const QStringList& uids) |
838 | { | 838 | { |
839 | 839 | ||
840 | // LR: we should use the /tmp dir on the Zaurus, | 840 | // LR: we should use the /tmp dir on the Zaurus, |
841 | // because: /tmp = RAM, (HOME)/kdepim = flash memory | 841 | // because: /tmp = RAM, (HOME)/kdepim = flash memory |
842 | 842 | ||
843 | #ifdef DESKTOP_VERSION | 843 | #ifdef DESKTOP_VERSION |
844 | QString fileName = locateLocal("tmp", "kapibeamfile.vcf"); | 844 | QString fileName = locateLocal("tmp", "kapibeamfile.vcf"); |
845 | #else | 845 | #else |
846 | QString fileName = "/tmp/kapibeamfile.vcf"; | 846 | QString fileName = "/tmp/kapibeamfile.vcf"; |
847 | #endif | 847 | #endif |
848 | 848 | ||
849 | KABC::VCardConverter converter; | 849 | KABC::VCardConverter converter; |
850 | QString description; | 850 | QString description; |
851 | QString datastream; | 851 | QString datastream; |
852 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | 852 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { |
853 | KABC::Addressee a = mAddressBook->findByUid( *it ); | 853 | KABC::Addressee a = mAddressBook->findByUid( *it ); |
854 | 854 | ||
855 | if ( a.isEmpty() ) | 855 | if ( a.isEmpty() ) |
856 | continue; | 856 | continue; |
857 | 857 | ||
858 | if (description.isEmpty()) | 858 | if (description.isEmpty()) |
859 | description = a.formattedName(); | 859 | description = a.formattedName(); |
860 | 860 | ||
861 | QString vcard; | 861 | QString vcard; |
862 | converter.addresseeToVCard( a, vcard ); | 862 | converter.addresseeToVCard( a, vcard ); |
863 | int start = 0; | 863 | int start = 0; |
864 | int next; | 864 | int next; |
865 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { | 865 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { |
866 | int semi = vcard.find(";", next); | 866 | int semi = vcard.find(";", next); |
867 | int dopp = vcard.find(":", next); | 867 | int dopp = vcard.find(":", next); |
868 | int sep; | 868 | int sep; |
869 | if ( semi < dopp && semi >= 0 ) | 869 | if ( semi < dopp && semi >= 0 ) |
870 | sep = semi ; | 870 | sep = semi ; |
871 | else | 871 | else |
872 | sep = dopp; | 872 | sep = dopp; |
873 | datastream +=vcard.mid( start, next - start); | 873 | datastream +=vcard.mid( start, next - start); |
874 | datastream +=vcard.mid( next+5,sep -next -5 ).upper(); | 874 | datastream +=vcard.mid( next+5,sep -next -5 ).upper(); |
875 | start = sep; | 875 | start = sep; |
876 | } | 876 | } |
877 | datastream += vcard.mid( start,vcard.length() ); | 877 | datastream += vcard.mid( start,vcard.length() ); |
878 | } | 878 | } |
879 | #ifndef DESKTOP_VERSION | 879 | #ifndef DESKTOP_VERSION |
880 | QFile outFile(fileName); | 880 | QFile outFile(fileName); |
881 | if ( outFile.open(IO_WriteOnly) ) { | 881 | if ( outFile.open(IO_WriteOnly) ) { |
882 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); | 882 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); |
883 | QTextStream t( &outFile ); // use a text stream | 883 | QTextStream t( &outFile ); // use a text stream |
884 | //t.setEncoding( QTextStream::UnicodeUTF8 ); | 884 | //t.setEncoding( QTextStream::UnicodeUTF8 ); |
885 | t.setEncoding( QTextStream::Latin1 ); | 885 | t.setEncoding( QTextStream::Latin1 ); |
886 | t <<datastream.latin1(); | 886 | t <<datastream.latin1(); |
887 | outFile.close(); | 887 | outFile.close(); |
888 | Ir *ir = new Ir( this ); | 888 | Ir *ir = new Ir( this ); |
889 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); | 889 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); |
890 | ir->send( fileName, description, "text/x-vCard" ); | 890 | ir->send( fileName, description, "text/x-vCard" ); |
891 | } else { | 891 | } else { |
892 | qDebug("Error open temp beam file "); | 892 | qDebug("Error open temp beam file "); |
893 | return; | 893 | return; |
894 | } | 894 | } |
895 | #endif | 895 | #endif |
896 | 896 | ||
897 | } | 897 | } |
898 | 898 | ||
899 | void KABCore::beamDone( Ir *ir ) | 899 | void KABCore::beamDone( Ir *ir ) |
900 | { | 900 | { |
901 | #ifndef DESKTOP_VERSION | 901 | #ifndef DESKTOP_VERSION |
902 | delete ir; | 902 | delete ir; |
903 | #endif | 903 | #endif |
904 | topLevelWidget()->raise(); | 904 | topLevelWidget()->raise(); |
905 | message( i18n("Beaming finished!") ); | 905 | message( i18n("Beaming finished!") ); |
906 | } | 906 | } |
907 | 907 | ||
908 | 908 | ||
909 | void KABCore::browse( const QString& url ) | 909 | void KABCore::browse( const QString& url ) |
910 | { | 910 | { |
911 | #ifndef KAB_EMBEDDED | 911 | #ifndef KAB_EMBEDDED |
912 | kapp->invokeBrowser( url ); | 912 | kapp->invokeBrowser( url ); |
913 | #else //KAB_EMBEDDED | 913 | #else //KAB_EMBEDDED |
914 | qDebug("KABCore::browse must be fixed"); | 914 | qDebug("KABCore::browse must be fixed"); |
915 | #endif //KAB_EMBEDDED | 915 | #endif //KAB_EMBEDDED |
916 | } | 916 | } |
917 | 917 | ||
918 | void KABCore::selectAllContacts() | 918 | void KABCore::selectAllContacts() |
919 | { | 919 | { |
920 | mViewManager->setSelected( QString::null, true ); | 920 | mViewManager->setSelected( QString::null, true ); |
921 | } | 921 | } |
922 | 922 | ||
923 | void KABCore::deleteContacts() | 923 | void KABCore::deleteContacts() |
924 | { | 924 | { |
925 | QStringList uidList = mViewManager->selectedUids(); | 925 | QStringList uidList = mViewManager->selectedUids(); |
926 | deleteContacts( uidList ); | 926 | deleteContacts( uidList ); |
927 | } | 927 | } |
928 | 928 | ||
929 | void KABCore::deleteContacts( const QStringList &uids ) | 929 | void KABCore::deleteContacts( const QStringList &uids ) |
930 | { | 930 | { |
931 | if ( uids.count() > 0 ) { | 931 | if ( uids.count() > 0 ) { |
932 | PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); | 932 | PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); |
933 | UndoStack::instance()->push( command ); | 933 | UndoStack::instance()->push( command ); |
934 | RedoStack::instance()->clear(); | 934 | RedoStack::instance()->clear(); |
935 | 935 | ||
936 | // now if we deleted anything, refresh | 936 | // now if we deleted anything, refresh |
937 | setContactSelected( QString::null ); | 937 | setContactSelected( QString::null ); |
938 | setModified( true ); | 938 | setModified( true ); |
939 | } | 939 | } |
940 | } | 940 | } |
941 | 941 | ||
942 | void KABCore::copyContacts() | 942 | void KABCore::copyContacts() |
943 | { | 943 | { |
944 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); | 944 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); |
945 | 945 | ||
946 | QString clipText = AddresseeUtil::addresseesToClipboard( addrList ); | 946 | QString clipText = AddresseeUtil::addresseesToClipboard( addrList ); |
947 | 947 | ||
948 | kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl; | 948 | kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl; |
949 | 949 | ||
950 | QClipboard *cb = QApplication::clipboard(); | 950 | QClipboard *cb = QApplication::clipboard(); |
951 | cb->setText( clipText ); | 951 | cb->setText( clipText ); |
952 | } | 952 | } |
953 | 953 | ||
954 | void KABCore::cutContacts() | 954 | void KABCore::cutContacts() |
955 | { | 955 | { |
956 | QStringList uidList = mViewManager->selectedUids(); | 956 | QStringList uidList = mViewManager->selectedUids(); |
957 | 957 | ||
958 | //US if ( uidList.size() > 0 ) { | 958 | //US if ( uidList.size() > 0 ) { |
959 | if ( uidList.count() > 0 ) { | 959 | if ( uidList.count() > 0 ) { |
960 | PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); | 960 | PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); |
961 | UndoStack::instance()->push( command ); | 961 | UndoStack::instance()->push( command ); |
962 | RedoStack::instance()->clear(); | 962 | RedoStack::instance()->clear(); |
963 | 963 | ||
964 | setModified( true ); | 964 | setModified( true ); |
965 | } | 965 | } |
966 | } | 966 | } |
967 | 967 | ||
968 | void KABCore::pasteContacts() | 968 | void KABCore::pasteContacts() |
969 | { | 969 | { |
970 | QClipboard *cb = QApplication::clipboard(); | 970 | QClipboard *cb = QApplication::clipboard(); |
971 | 971 | ||
972 | KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); | 972 | KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); |
973 | 973 | ||
974 | pasteContacts( list ); | 974 | pasteContacts( list ); |
975 | } | 975 | } |
976 | 976 | ||
977 | void KABCore::pasteContacts( KABC::Addressee::List &list ) | 977 | void KABCore::pasteContacts( KABC::Addressee::List &list ) |
978 | { | 978 | { |
979 | KABC::Resource *resource = requestResource( this ); | 979 | KABC::Resource *resource = requestResource( this ); |
980 | KABC::Addressee::List::Iterator it; | 980 | KABC::Addressee::List::Iterator it; |
981 | for ( it = list.begin(); it != list.end(); ++it ) | 981 | for ( it = list.begin(); it != list.end(); ++it ) |
982 | (*it).setResource( resource ); | 982 | (*it).setResource( resource ); |
983 | 983 | ||
984 | PwPasteCommand *command = new PwPasteCommand( this, list ); | 984 | PwPasteCommand *command = new PwPasteCommand( this, list ); |
985 | UndoStack::instance()->push( command ); | 985 | UndoStack::instance()->push( command ); |
986 | RedoStack::instance()->clear(); | 986 | RedoStack::instance()->clear(); |
987 | 987 | ||
988 | setModified( true ); | 988 | setModified( true ); |
989 | } | 989 | } |
990 | 990 | ||
991 | void KABCore::setWhoAmI() | 991 | void KABCore::setWhoAmI() |
992 | { | 992 | { |
993 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); | 993 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); |
994 | 994 | ||
995 | if ( addrList.count() > 1 ) { | 995 | if ( addrList.count() > 1 ) { |
996 | KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); | 996 | KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); |
997 | return; | 997 | return; |
998 | } | 998 | } |
999 | 999 | ||
1000 | QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); | 1000 | QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); |
1001 | if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) | 1001 | if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) |
1002 | static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); | 1002 | static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); |
1003 | } | 1003 | } |
1004 | void KABCore::editCategories() | 1004 | void KABCore::editCategories() |
1005 | { | 1005 | { |
1006 | KPIM::CategoryEditDialog dlg ( KABPrefs::instance(), this, "", true ); | 1006 | KPIM::CategoryEditDialog dlg ( KABPrefs::instance(), this, "", true ); |
1007 | dlg.exec(); | 1007 | dlg.exec(); |
1008 | } | 1008 | } |
1009 | void KABCore::setCategories() | 1009 | void KABCore::setCategories() |
1010 | { | 1010 | { |
1011 | KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); | 1011 | KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); |
1012 | if ( !dlg.exec() ) { | 1012 | if ( !dlg.exec() ) { |
1013 | message( i18n("Setting categories cancelled") ); | 1013 | message( i18n("Setting categories cancelled") ); |
1014 | return; | 1014 | return; |
1015 | } | 1015 | } |
1016 | bool merge = false; | 1016 | bool merge = false; |
1017 | QString msg = i18n( "Merge with existing categories?" ); | 1017 | QString msg = i18n( "Merge with existing categories?" ); |
1018 | if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) | 1018 | if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) |
1019 | merge = true; | 1019 | merge = true; |
1020 | 1020 | ||
1021 | message( i18n("Setting categories ... please wait!") ); | 1021 | message( i18n("Setting categories ... please wait!") ); |
1022 | QStringList categories = dlg.selectedCategories(); | 1022 | QStringList categories = dlg.selectedCategories(); |
1023 | 1023 | ||
1024 | QStringList uids = mViewManager->selectedUids(); | 1024 | QStringList uids = mViewManager->selectedUids(); |
1025 | QStringList::Iterator it; | 1025 | QStringList::Iterator it; |
1026 | for ( it = uids.begin(); it != uids.end(); ++it ) { | 1026 | for ( it = uids.begin(); it != uids.end(); ++it ) { |
1027 | KABC::Addressee addr = mAddressBook->findByUid( *it ); | 1027 | KABC::Addressee addr = mAddressBook->findByUid( *it ); |
1028 | if ( !addr.isEmpty() ) { | 1028 | if ( !addr.isEmpty() ) { |
1029 | if ( !merge ) | 1029 | if ( !merge ) |
1030 | addr.setCategories( categories ); | 1030 | addr.setCategories( categories ); |
1031 | else { | 1031 | else { |
1032 | QStringList addrCategories = addr.categories(); | 1032 | QStringList addrCategories = addr.categories(); |
1033 | QStringList::Iterator catIt; | 1033 | QStringList::Iterator catIt; |
1034 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { | 1034 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { |
1035 | if ( !addrCategories.contains( *catIt ) ) | 1035 | if ( !addrCategories.contains( *catIt ) ) |
1036 | addrCategories.append( *catIt ); | 1036 | addrCategories.append( *catIt ); |
1037 | } | 1037 | } |
1038 | addr.setCategories( addrCategories ); | 1038 | addr.setCategories( addrCategories ); |
1039 | } | 1039 | } |
1040 | mAddressBook->insertAddressee( addr ); | 1040 | mAddressBook->insertAddressee( addr ); |
1041 | } | 1041 | } |
1042 | } | 1042 | } |
1043 | 1043 | ||
1044 | if ( uids.count() > 0 ) | 1044 | if ( uids.count() > 0 ) |
1045 | setModified( true ); | 1045 | setModified( true ); |
1046 | message( i18n("Setting categories completed!") ); | 1046 | message( i18n("Setting categories completed!") ); |
1047 | } | 1047 | } |
1048 | 1048 | ||
1049 | void KABCore::setSearchFields( const KABC::Field::List &fields ) | 1049 | void KABCore::setSearchFields( const KABC::Field::List &fields ) |
1050 | { | 1050 | { |
1051 | mIncSearchWidget->setFields( fields ); | 1051 | mIncSearchWidget->setFields( fields ); |
1052 | } | 1052 | } |
1053 | 1053 | ||
1054 | void KABCore::incrementalSearch( const QString& text ) | 1054 | void KABCore::incrementalSearch( const QString& text ) |
1055 | { | 1055 | { |
1056 | mViewManager->doSearch( text, mIncSearchWidget->currentField() ); | 1056 | mViewManager->doSearch( text, mIncSearchWidget->currentField() ); |
1057 | } | 1057 | } |
1058 | 1058 | ||
1059 | void KABCore::setModified() | 1059 | void KABCore::setModified() |
1060 | { | 1060 | { |
1061 | setModified( true ); | 1061 | setModified( true ); |
1062 | } | 1062 | } |
1063 | 1063 | ||
1064 | void KABCore::setModifiedWOrefresh() | 1064 | void KABCore::setModifiedWOrefresh() |
1065 | { | 1065 | { |
1066 | // qDebug("KABCore::setModifiedWOrefresh() "); | 1066 | // qDebug("KABCore::setModifiedWOrefresh() "); |
1067 | mModified = true; | 1067 | mModified = true; |
1068 | mActionSave->setEnabled( mModified ); | 1068 | mActionSave->setEnabled( mModified ); |
1069 | #ifdef DESKTOP_VERSION | 1069 | #ifdef DESKTOP_VERSION |
1070 | mDetails->refreshView(); | 1070 | mDetails->refreshView(); |
1071 | #endif | 1071 | #endif |
1072 | 1072 | ||
1073 | } | 1073 | } |
1074 | void KABCore::setModified( bool modified ) | 1074 | void KABCore::setModified( bool modified ) |
1075 | { | 1075 | { |
1076 | mModified = modified; | 1076 | mModified = modified; |
1077 | mActionSave->setEnabled( mModified ); | 1077 | mActionSave->setEnabled( mModified ); |
1078 | 1078 | ||
1079 | if ( modified ) | 1079 | if ( modified ) |
1080 | mJumpButtonBar->recreateButtons(); | 1080 | mJumpButtonBar->recreateButtons(); |
1081 | 1081 | ||
1082 | mViewManager->refreshView(); | 1082 | mViewManager->refreshView(); |
1083 | mDetails->refreshView(); | 1083 | mDetails->refreshView(); |
1084 | 1084 | ||
1085 | } | 1085 | } |
1086 | 1086 | ||
1087 | bool KABCore::modified() const | 1087 | bool KABCore::modified() const |
1088 | { | 1088 | { |
1089 | return mModified; | 1089 | return mModified; |
1090 | } | 1090 | } |
1091 | 1091 | ||
1092 | void KABCore::contactModified( const KABC::Addressee &addr ) | 1092 | void KABCore::contactModified( const KABC::Addressee &addr ) |
1093 | { | 1093 | { |
1094 | 1094 | ||
1095 | Command *command = 0; | 1095 | Command *command = 0; |
1096 | QString uid; | 1096 | QString uid; |
1097 | 1097 | ||
1098 | // check if it exists already | 1098 | // check if it exists already |
1099 | KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); | 1099 | KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); |
1100 | if ( origAddr.isEmpty() ) | 1100 | if ( origAddr.isEmpty() ) |
1101 | command = new PwNewCommand( mAddressBook, addr ); | 1101 | command = new PwNewCommand( mAddressBook, addr ); |
1102 | else { | 1102 | else { |
1103 | command = new PwEditCommand( mAddressBook, origAddr, addr ); | 1103 | command = new PwEditCommand( mAddressBook, origAddr, addr ); |
1104 | uid = addr.uid(); | 1104 | uid = addr.uid(); |
1105 | } | 1105 | } |
1106 | 1106 | ||
1107 | UndoStack::instance()->push( command ); | 1107 | UndoStack::instance()->push( command ); |
1108 | RedoStack::instance()->clear(); | 1108 | RedoStack::instance()->clear(); |
1109 | 1109 | ||
1110 | setModified( true ); | 1110 | setModified( true ); |
1111 | } | 1111 | } |
1112 | 1112 | ||
1113 | void KABCore::newContact() | 1113 | void KABCore::newContact() |
1114 | { | 1114 | { |
1115 | 1115 | ||
1116 | 1116 | ||
1117 | QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); | 1117 | QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); |
1118 | 1118 | ||
1119 | QPtrList<KRES::Resource> kresResources; | 1119 | QPtrList<KRES::Resource> kresResources; |
1120 | QPtrListIterator<KABC::Resource> it( kabcResources ); | 1120 | QPtrListIterator<KABC::Resource> it( kabcResources ); |
1121 | KABC::Resource *resource; | 1121 | KABC::Resource *resource; |
1122 | while ( ( resource = it.current() ) != 0 ) { | 1122 | while ( ( resource = it.current() ) != 0 ) { |
1123 | ++it; | 1123 | ++it; |
1124 | if ( !resource->readOnly() ) { | 1124 | if ( !resource->readOnly() ) { |
1125 | KRES::Resource *res = static_cast<KRES::Resource*>( resource ); | 1125 | KRES::Resource *res = static_cast<KRES::Resource*>( resource ); |
1126 | if ( res ) | 1126 | if ( res ) |
1127 | kresResources.append( res ); | 1127 | kresResources.append( res ); |
1128 | } | 1128 | } |
1129 | } | 1129 | } |
1130 | 1130 | ||
1131 | KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); | 1131 | KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); |
1132 | resource = static_cast<KABC::Resource*>( res ); | 1132 | resource = static_cast<KABC::Resource*>( res ); |
1133 | 1133 | ||
1134 | if ( resource ) { | 1134 | if ( resource ) { |
1135 | KABC::Addressee addr; | 1135 | KABC::Addressee addr; |
1136 | addr.setResource( resource ); | 1136 | addr.setResource( resource ); |
1137 | mEditorDialog->setAddressee( addr ); | 1137 | mEditorDialog->setAddressee( addr ); |
1138 | KApplication::execDialog ( mEditorDialog ); | 1138 | KApplication::execDialog ( mEditorDialog ); |
1139 | 1139 | ||
1140 | } else | 1140 | } else |
1141 | return; | 1141 | return; |
1142 | 1142 | ||
1143 | // mEditorDict.insert( dialog->addressee().uid(), dialog ); | 1143 | // mEditorDict.insert( dialog->addressee().uid(), dialog ); |
1144 | 1144 | ||
1145 | 1145 | ||
1146 | } | 1146 | } |
1147 | 1147 | ||
1148 | void KABCore::addEmail( QString aStr ) | 1148 | void KABCore::addEmail( QString aStr ) |
1149 | { | 1149 | { |
1150 | #ifndef KAB_EMBEDDED | 1150 | #ifndef KAB_EMBEDDED |
1151 | QString fullName, email; | 1151 | QString fullName, email; |
1152 | 1152 | ||
1153 | KABC::Addressee::parseEmailAddress( aStr, fullName, email ); | 1153 | KABC::Addressee::parseEmailAddress( aStr, fullName, email ); |
1154 | 1154 | ||
1155 | // Try to lookup the addressee matching the email address | 1155 | // Try to lookup the addressee matching the email address |
1156 | bool found = false; | 1156 | bool found = false; |
1157 | QStringList emailList; | 1157 | QStringList emailList; |
1158 | KABC::AddressBook::Iterator it; | 1158 | KABC::AddressBook::Iterator it; |
1159 | for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { | 1159 | for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { |
1160 | emailList = (*it).emails(); | 1160 | emailList = (*it).emails(); |
1161 | if ( emailList.contains( email ) > 0 ) { | 1161 | if ( emailList.contains( email ) > 0 ) { |
1162 | found = true; | 1162 | found = true; |
1163 | (*it).setNameFromString( fullName ); | 1163 | (*it).setNameFromString( fullName ); |
1164 | editContact( (*it).uid() ); | 1164 | editContact( (*it).uid() ); |
1165 | } | 1165 | } |
1166 | } | 1166 | } |
1167 | 1167 | ||
1168 | if ( !found ) { | 1168 | if ( !found ) { |
1169 | KABC::Addressee addr; | 1169 | KABC::Addressee addr; |
1170 | addr.setNameFromString( fullName ); | 1170 | addr.setNameFromString( fullName ); |
1171 | addr.insertEmail( email, true ); | 1171 | addr.insertEmail( email, true ); |
1172 | 1172 | ||
1173 | mAddressBook->insertAddressee( addr ); | 1173 | mAddressBook->insertAddressee( addr ); |
1174 | mViewManager->refreshView( addr.uid() ); | 1174 | mViewManager->refreshView( addr.uid() ); |
1175 | editContact( addr.uid() ); | 1175 | editContact( addr.uid() ); |
1176 | } | 1176 | } |
1177 | #else //KAB_EMBEDDED | 1177 | #else //KAB_EMBEDDED |
1178 | qDebug("KABCore::addEmail finsih method"); | 1178 | qDebug("KABCore::addEmail finsih method"); |
1179 | #endif //KAB_EMBEDDED | 1179 | #endif //KAB_EMBEDDED |
1180 | } | 1180 | } |
1181 | 1181 | ||
1182 | void KABCore::importVCard( const KURL &url, bool showPreview ) | 1182 | void KABCore::importVCard( const KURL &url, bool showPreview ) |
1183 | { | 1183 | { |
1184 | mXXPortManager->importVCard( url, showPreview ); | 1184 | mXXPortManager->importVCard( url, showPreview ); |
1185 | } | 1185 | } |
1186 | void KABCore::importFromOL() | 1186 | void KABCore::importFromOL() |
1187 | { | 1187 | { |
1188 | #ifdef _WIN32_ | 1188 | #ifdef _WIN32_ |
1189 | KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); | 1189 | KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); |
1190 | idgl->exec(); | 1190 | idgl->exec(); |
1191 | KABC::Addressee::List list = idgl->getAddressList(); | 1191 | KABC::Addressee::List list = idgl->getAddressList(); |
1192 | if ( list.count() > 0 ) { | 1192 | if ( list.count() > 0 ) { |
1193 | KABC::Addressee::List listNew; | 1193 | KABC::Addressee::List listNew; |
1194 | KABC::Addressee::List listExisting; | 1194 | KABC::Addressee::List listExisting; |
1195 | KABC::Addressee::List::Iterator it; | 1195 | KABC::Addressee::List::Iterator it; |
1196 | KABC::AddressBook::Iterator iter; | 1196 | KABC::AddressBook::Iterator iter; |
1197 | for ( it = list.begin(); it != list.end(); ++it ) { | 1197 | for ( it = list.begin(); it != list.end(); ++it ) { |
1198 | if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) | 1198 | if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) |
1199 | listNew.append( (*it) ); | 1199 | listNew.append( (*it) ); |
1200 | else | 1200 | else |
1201 | listExisting.append( (*it) ); | 1201 | listExisting.append( (*it) ); |
1202 | } | 1202 | } |
1203 | if ( listExisting.count() > 0 ) | 1203 | if ( listExisting.count() > 0 ) |
1204 | KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); | 1204 | KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); |
1205 | if ( listNew.count() > 0 ) { | 1205 | if ( listNew.count() > 0 ) { |
1206 | pasteWithNewUid = false; | 1206 | pasteWithNewUid = false; |
1207 | pasteContacts( listNew ); | 1207 | pasteContacts( listNew ); |
1208 | pasteWithNewUid = true; | 1208 | pasteWithNewUid = true; |
1209 | } | 1209 | } |
1210 | } | 1210 | } |
1211 | delete idgl; | 1211 | delete idgl; |
1212 | #endif | 1212 | #endif |
1213 | } | 1213 | } |
1214 | 1214 | ||
1215 | void KABCore::importVCard( const QString &vCard, bool showPreview ) | 1215 | void KABCore::importVCard( const QString &vCard, bool showPreview ) |
1216 | { | 1216 | { |
1217 | mXXPortManager->importVCard( vCard, showPreview ); | 1217 | mXXPortManager->importVCard( vCard, showPreview ); |
1218 | } | 1218 | } |
1219 | 1219 | ||
1220 | //US added a second method without defaultparameter | 1220 | //US added a second method without defaultparameter |
1221 | void KABCore::editContact2() { | 1221 | void KABCore::editContact2() { |
1222 | editContact( QString::null ); | 1222 | editContact( QString::null ); |
1223 | } | 1223 | } |
1224 | 1224 | ||
1225 | void KABCore::editContact( const QString &uid ) | 1225 | void KABCore::editContact( const QString &uid ) |
1226 | { | 1226 | { |
1227 | 1227 | ||
1228 | if ( mExtensionManager->isQuickEditVisible() ) | 1228 | if ( mExtensionManager->isQuickEditVisible() ) |
1229 | return; | 1229 | return; |
1230 | 1230 | ||
1231 | // First, locate the contact entry | 1231 | // First, locate the contact entry |
1232 | QString localUID = uid; | 1232 | QString localUID = uid; |
1233 | if ( localUID.isNull() ) { | 1233 | if ( localUID.isNull() ) { |
1234 | QStringList uidList = mViewManager->selectedUids(); | 1234 | QStringList uidList = mViewManager->selectedUids(); |
1235 | if ( uidList.count() > 0 ) | 1235 | if ( uidList.count() > 0 ) |
1236 | localUID = *( uidList.at( 0 ) ); | 1236 | localUID = *( uidList.at( 0 ) ); |
1237 | } | 1237 | } |
1238 | 1238 | ||
1239 | KABC::Addressee addr = mAddressBook->findByUid( localUID ); | 1239 | KABC::Addressee addr = mAddressBook->findByUid( localUID ); |
1240 | if ( !addr.isEmpty() ) { | 1240 | if ( !addr.isEmpty() ) { |
1241 | mEditorDialog->setAddressee( addr ); | 1241 | mEditorDialog->setAddressee( addr ); |
1242 | KApplication::execDialog ( mEditorDialog ); | 1242 | KApplication::execDialog ( mEditorDialog ); |
1243 | } | 1243 | } |
1244 | } | 1244 | } |
1245 | 1245 | ||
1246 | /** | 1246 | /** |
1247 | Shows or edits the detail view for the given uid. If the uid is QString::null, | 1247 | Shows or edits the detail view for the given uid. If the uid is QString::null, |
1248 | the method will try to find a selected addressee in the view. | 1248 | the method will try to find a selected addressee in the view. |
1249 | */ | 1249 | */ |
1250 | void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) | 1250 | void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) |
1251 | { | 1251 | { |
1252 | if ( mMultipleViewsAtOnce ) | 1252 | if ( mMultipleViewsAtOnce ) |
1253 | { | 1253 | { |
1254 | editContact( uid ); | 1254 | editContact( uid ); |
1255 | } | 1255 | } |
1256 | else | 1256 | else |
1257 | { | 1257 | { |
1258 | setDetailsVisible( true ); | 1258 | setDetailsVisible( true ); |
1259 | mActionDetails->setChecked(true); | 1259 | mActionDetails->setChecked(true); |
1260 | } | 1260 | } |
1261 | 1261 | ||
1262 | } | 1262 | } |
1263 | 1263 | ||
1264 | void KABCore::save() | 1264 | void KABCore::save() |
1265 | { | 1265 | { |
1266 | if (syncManager->blockSave()) | 1266 | if (syncManager->blockSave()) |
1267 | return; | 1267 | return; |
1268 | if ( !mModified ) | 1268 | if ( !mModified ) |
1269 | return; | 1269 | return; |
1270 | 1270 | ||
1271 | syncManager->setBlockSave(true); | 1271 | syncManager->setBlockSave(true); |
1272 | QString text = i18n( "There was an error while attempting to save\n the " | 1272 | QString text = i18n( "There was an error while attempting to save\n the " |
1273 | "address book. Please check that some \nother application is " | 1273 | "address book. Please check that some \nother application is " |
1274 | "not using it. " ); | 1274 | "not using it. " ); |
1275 | message(i18n("Saving addressbook ... ")); | 1275 | message(i18n("Saving addressbook ... ")); |
1276 | #ifndef KAB_EMBEDDED | 1276 | #ifndef KAB_EMBEDDED |
1277 | KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); | 1277 | KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); |
1278 | if ( !b || !b->save() ) { | 1278 | if ( !b || !b->save() ) { |
1279 | KMessageBox::error( this, text, i18n( "Unable to Save" ) ); | 1279 | KMessageBox::error( this, text, i18n( "Unable to Save" ) ); |
1280 | } | 1280 | } |
1281 | #else //KAB_EMBEDDED | 1281 | #else //KAB_EMBEDDED |
1282 | KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); | 1282 | KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); |
1283 | if ( !b || !b->save() ) { | 1283 | if ( !b || !b->save() ) { |
1284 | QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); | 1284 | QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); |
1285 | } | 1285 | } |
1286 | #endif //KAB_EMBEDDED | 1286 | #endif //KAB_EMBEDDED |
1287 | 1287 | ||
1288 | message(i18n("Addressbook saved!")); | 1288 | message(i18n("Addressbook saved!")); |
1289 | setModified( false ); | 1289 | setModified( false ); |
1290 | syncManager->setBlockSave(false); | 1290 | syncManager->setBlockSave(false); |
1291 | } | 1291 | } |
1292 | 1292 | ||
1293 | 1293 | ||
1294 | void KABCore::undo() | 1294 | void KABCore::undo() |
1295 | { | 1295 | { |
1296 | UndoStack::instance()->undo(); | 1296 | UndoStack::instance()->undo(); |
1297 | 1297 | ||
1298 | // Refresh the view | 1298 | // Refresh the view |
1299 | mViewManager->refreshView(); | 1299 | mViewManager->refreshView(); |
1300 | } | 1300 | } |
1301 | 1301 | ||
1302 | void KABCore::redo() | 1302 | void KABCore::redo() |
1303 | { | 1303 | { |
1304 | RedoStack::instance()->redo(); | 1304 | RedoStack::instance()->redo(); |
1305 | 1305 | ||
1306 | // Refresh the view | 1306 | // Refresh the view |
1307 | mViewManager->refreshView(); | 1307 | mViewManager->refreshView(); |
1308 | } | 1308 | } |
1309 | 1309 | ||
1310 | void KABCore::setJumpButtonBarVisible( bool visible ) | 1310 | void KABCore::setJumpButtonBarVisible( bool visible ) |
1311 | { | 1311 | { |
1312 | if (mMultipleViewsAtOnce) | 1312 | if (mMultipleViewsAtOnce) |
1313 | { | 1313 | { |
1314 | if ( visible ) | 1314 | if ( visible ) |
1315 | mJumpButtonBar->show(); | 1315 | mJumpButtonBar->show(); |
1316 | else | 1316 | else |
1317 | mJumpButtonBar->hide(); | 1317 | mJumpButtonBar->hide(); |
1318 | } | 1318 | } |
1319 | else | 1319 | else |
1320 | { | 1320 | { |
1321 | // show the jumpbar only if "the details are hidden" == "viewmanager are shown" | 1321 | // show the jumpbar only if "the details are hidden" == "viewmanager are shown" |
1322 | if (mViewManager->isVisible()) | 1322 | if (mViewManager->isVisible()) |
1323 | { | 1323 | { |
1324 | if ( visible ) | 1324 | if ( visible ) |
1325 | mJumpButtonBar->show(); | 1325 | mJumpButtonBar->show(); |
1326 | else | 1326 | else |
1327 | mJumpButtonBar->hide(); | 1327 | mJumpButtonBar->hide(); |
1328 | } | 1328 | } |
1329 | else | 1329 | else |
1330 | { | 1330 | { |
1331 | mJumpButtonBar->hide(); | 1331 | mJumpButtonBar->hide(); |
1332 | } | 1332 | } |
1333 | } | 1333 | } |
1334 | } | 1334 | } |
1335 | 1335 | ||
1336 | 1336 | ||
1337 | void KABCore::setDetailsToState() | 1337 | void KABCore::setDetailsToState() |
1338 | { | 1338 | { |
1339 | setDetailsVisible( mActionDetails->isChecked() ); | 1339 | setDetailsVisible( mActionDetails->isChecked() ); |
1340 | } | 1340 | } |
1341 | void KABCore::setDetailsToggle() | 1341 | void KABCore::setDetailsToggle() |
1342 | { | 1342 | { |
1343 | mActionDetails->setChecked( !mActionDetails->isChecked() ); | 1343 | mActionDetails->setChecked( !mActionDetails->isChecked() ); |
1344 | setDetailsToState(); | 1344 | setDetailsToState(); |
1345 | } | 1345 | } |
1346 | 1346 | ||
1347 | 1347 | ||
1348 | 1348 | ||
1349 | void KABCore::setDetailsVisible( bool visible ) | 1349 | void KABCore::setDetailsVisible( bool visible ) |
1350 | { | 1350 | { |
1351 | if (visible && mDetails->isHidden()) | 1351 | if (visible && mDetails->isHidden()) |
1352 | { | 1352 | { |
1353 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); | 1353 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); |
1354 | if ( addrList.count() > 0 ) | 1354 | if ( addrList.count() > 0 ) |
1355 | mDetails->setAddressee( addrList[ 0 ] ); | 1355 | mDetails->setAddressee( addrList[ 0 ] ); |
1356 | } | 1356 | } |
1357 | 1357 | ||
1358 | // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between | 1358 | // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between |
1359 | // the listview and the detailview. We do that by changing the splitbar size. | 1359 | // the listview and the detailview. We do that by changing the splitbar size. |
1360 | if (mMultipleViewsAtOnce) | 1360 | if (mMultipleViewsAtOnce) |
1361 | { | 1361 | { |
1362 | if ( visible ) | 1362 | if ( visible ) |
1363 | mDetails->show(); | 1363 | mDetails->show(); |
1364 | else | 1364 | else |
1365 | mDetails->hide(); | 1365 | mDetails->hide(); |
1366 | } | 1366 | } |
1367 | else | 1367 | else |
1368 | { | 1368 | { |
1369 | if ( visible ) { | 1369 | if ( visible ) { |
1370 | mViewManager->hide(); | 1370 | mViewManager->hide(); |
1371 | mDetails->show(); | 1371 | mDetails->show(); |
1372 | mIncSearchWidget->setFocus(); | 1372 | mIncSearchWidget->setFocus(); |
1373 | } | 1373 | } |
1374 | else { | 1374 | else { |
1375 | mViewManager->show(); | 1375 | mViewManager->show(); |
1376 | mDetails->hide(); | 1376 | mDetails->hide(); |
1377 | mViewManager->setFocusAV(); | 1377 | mViewManager->setFocusAV(); |
1378 | } | 1378 | } |
1379 | setJumpButtonBarVisible( !visible ); | 1379 | setJumpButtonBarVisible( !visible ); |
1380 | } | 1380 | } |
1381 | 1381 | ||
1382 | } | 1382 | } |
1383 | 1383 | ||
1384 | void KABCore::extensionChanged( int id ) | 1384 | void KABCore::extensionChanged( int id ) |
1385 | { | 1385 | { |
1386 | //change the details view only for non desktop systems | 1386 | //change the details view only for non desktop systems |
1387 | #ifndef DESKTOP_VERSION | 1387 | #ifndef DESKTOP_VERSION |
1388 | 1388 | ||
1389 | if (id == 0) | 1389 | if (id == 0) |
1390 | { | 1390 | { |
1391 | //the user disabled the extension. | 1391 | //the user disabled the extension. |
1392 | 1392 | ||
1393 | if (mMultipleViewsAtOnce) | 1393 | if (mMultipleViewsAtOnce) |
1394 | { // enable detailsview again | 1394 | { // enable detailsview again |
1395 | setDetailsVisible( true ); | 1395 | setDetailsVisible( true ); |
1396 | mActionDetails->setChecked( true ); | 1396 | mActionDetails->setChecked( true ); |
1397 | } | 1397 | } |
1398 | else | 1398 | else |
1399 | { //go back to the listview | 1399 | { //go back to the listview |
1400 | setDetailsVisible( false ); | 1400 | setDetailsVisible( false ); |
1401 | mActionDetails->setChecked( false ); | 1401 | mActionDetails->setChecked( false ); |
1402 | mActionDetails->setEnabled(true); | 1402 | mActionDetails->setEnabled(true); |
1403 | } | 1403 | } |
1404 | 1404 | ||
1405 | } | 1405 | } |
1406 | else | 1406 | else |
1407 | { | 1407 | { |
1408 | //the user enabled the extension. | 1408 | //the user enabled the extension. |
1409 | setDetailsVisible( false ); | 1409 | setDetailsVisible( false ); |
1410 | mActionDetails->setChecked( false ); | 1410 | mActionDetails->setChecked( false ); |
1411 | 1411 | ||
1412 | if (!mMultipleViewsAtOnce) | 1412 | if (!mMultipleViewsAtOnce) |
1413 | { | 1413 | { |
1414 | mActionDetails->setEnabled(false); | 1414 | mActionDetails->setEnabled(false); |
1415 | } | 1415 | } |
1416 | 1416 | ||
1417 | mExtensionManager->setSelectionChanged(); | 1417 | mExtensionManager->setSelectionChanged(); |
1418 | 1418 | ||
1419 | } | 1419 | } |
1420 | 1420 | ||
1421 | #endif// DESKTOP_VERSION | 1421 | #endif// DESKTOP_VERSION |
1422 | 1422 | ||
1423 | } | 1423 | } |
1424 | 1424 | ||
1425 | 1425 | ||
1426 | void KABCore::extensionModified( const KABC::Addressee::List &list ) | 1426 | void KABCore::extensionModified( const KABC::Addressee::List &list ) |
1427 | { | 1427 | { |
1428 | 1428 | ||
1429 | if ( list.count() != 0 ) { | 1429 | if ( list.count() != 0 ) { |
1430 | KABC::Addressee::List::ConstIterator it; | 1430 | KABC::Addressee::List::ConstIterator it; |
1431 | for ( it = list.begin(); it != list.end(); ++it ) | 1431 | for ( it = list.begin(); it != list.end(); ++it ) |
1432 | mAddressBook->insertAddressee( *it ); | 1432 | mAddressBook->insertAddressee( *it ); |
1433 | if ( list.count() > 1 ) | 1433 | if ( list.count() > 1 ) |
1434 | setModified(); | 1434 | setModified(); |
1435 | else | 1435 | else |
1436 | setModifiedWOrefresh(); | 1436 | setModifiedWOrefresh(); |
1437 | } | 1437 | } |
1438 | if ( list.count() == 0 ) | 1438 | if ( list.count() == 0 ) |
1439 | mViewManager->refreshView(); | 1439 | mViewManager->refreshView(); |
1440 | else | 1440 | else |
1441 | mViewManager->refreshView( list[ 0 ].uid() ); | 1441 | mViewManager->refreshView( list[ 0 ].uid() ); |
1442 | 1442 | ||
1443 | 1443 | ||
1444 | 1444 | ||
1445 | } | 1445 | } |
1446 | 1446 | ||
1447 | QString KABCore::getNameByPhone( const QString &phone ) | 1447 | QString KABCore::getNameByPhone( const QString &phone ) |
1448 | { | 1448 | { |
1449 | #ifndef KAB_EMBEDDED | 1449 | #ifndef KAB_EMBEDDED |
1450 | QRegExp r( "[/*/-/ ]" ); | 1450 | QRegExp r( "[/*/-/ ]" ); |
1451 | QString localPhone( phone ); | 1451 | QString localPhone( phone ); |
1452 | 1452 | ||
1453 | bool found = false; | 1453 | bool found = false; |
1454 | QString ownerName = ""; | 1454 | QString ownerName = ""; |
1455 | KABC::AddressBook::Iterator iter; | 1455 | KABC::AddressBook::Iterator iter; |
1456 | KABC::PhoneNumber::List::Iterator phoneIter; | 1456 | KABC::PhoneNumber::List::Iterator phoneIter; |
1457 | KABC::PhoneNumber::List phoneList; | 1457 | KABC::PhoneNumber::List phoneList; |
1458 | for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { | 1458 | for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { |
1459 | phoneList = (*iter).phoneNumbers(); | 1459 | phoneList = (*iter).phoneNumbers(); |
1460 | for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); | 1460 | for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); |
1461 | ++phoneIter) { | 1461 | ++phoneIter) { |
1462 | // Get rid of separator chars so just the numbers are compared. | 1462 | // Get rid of separator chars so just the numbers are compared. |
1463 | if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { | 1463 | if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { |
1464 | ownerName = (*iter).formattedName(); | 1464 | ownerName = (*iter).formattedName(); |
1465 | found = true; | 1465 | found = true; |
1466 | } | 1466 | } |
1467 | } | 1467 | } |
1468 | } | 1468 | } |
1469 | 1469 | ||
1470 | return ownerName; | 1470 | return ownerName; |
1471 | #else //KAB_EMBEDDED | 1471 | #else //KAB_EMBEDDED |
1472 | qDebug("KABCore::getNameByPhone finsih method"); | 1472 | qDebug("KABCore::getNameByPhone finsih method"); |
1473 | return ""; | 1473 | return ""; |
1474 | #endif //KAB_EMBEDDED | 1474 | #endif //KAB_EMBEDDED |
1475 | 1475 | ||
1476 | } | 1476 | } |
1477 | 1477 | ||
1478 | void KABCore::openConfigDialog() | 1478 | void KABCore::openConfigDialog() |
1479 | { | 1479 | { |
1480 | KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); | 1480 | KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); |
1481 | KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); | 1481 | KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); |
1482 | ConfigureDialog->addModule(kabcfg ); | 1482 | ConfigureDialog->addModule(kabcfg ); |
1483 | KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); | 1483 | KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); |
1484 | ConfigureDialog->addModule(kdelibcfg ); | 1484 | ConfigureDialog->addModule(kdelibcfg ); |
1485 | 1485 | ||
1486 | connect( ConfigureDialog, SIGNAL( applyClicked() ), | 1486 | connect( ConfigureDialog, SIGNAL( applyClicked() ), |
1487 | this, SLOT( configurationChanged() ) ); | 1487 | this, SLOT( configurationChanged() ) ); |
1488 | connect( ConfigureDialog, SIGNAL( okClicked() ), | 1488 | connect( ConfigureDialog, SIGNAL( okClicked() ), |
1489 | this, SLOT( configurationChanged() ) ); | 1489 | this, SLOT( configurationChanged() ) ); |
1490 | saveSettings(); | 1490 | saveSettings(); |
1491 | #ifndef DESKTOP_VERSION | 1491 | #ifndef DESKTOP_VERSION |
1492 | ConfigureDialog->showMaximized(); | 1492 | ConfigureDialog->showMaximized(); |
1493 | #endif | 1493 | #endif |
1494 | if ( ConfigureDialog->exec() ) | 1494 | if ( ConfigureDialog->exec() ) |
1495 | KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); | 1495 | KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); |
1496 | delete ConfigureDialog; | 1496 | delete ConfigureDialog; |
1497 | } | 1497 | } |
1498 | 1498 | ||
1499 | void KABCore::openLDAPDialog() | 1499 | void KABCore::openLDAPDialog() |
1500 | { | 1500 | { |
1501 | #ifndef KAB_EMBEDDED | 1501 | #ifndef KAB_EMBEDDED |
1502 | if ( !mLdapSearchDialog ) { | 1502 | if ( !mLdapSearchDialog ) { |
1503 | mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); | 1503 | mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); |
1504 | connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, | 1504 | connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, |
1505 | SLOT( refreshView() ) ); | 1505 | SLOT( refreshView() ) ); |
1506 | connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, | 1506 | connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, |
1507 | SLOT( setModified() ) ); | 1507 | SLOT( setModified() ) ); |
1508 | } else | 1508 | } else |
1509 | mLdapSearchDialog->restoreSettings(); | 1509 | mLdapSearchDialog->restoreSettings(); |
1510 | 1510 | ||
1511 | if ( mLdapSearchDialog->isOK() ) | 1511 | if ( mLdapSearchDialog->isOK() ) |
1512 | mLdapSearchDialog->exec(); | 1512 | mLdapSearchDialog->exec(); |
1513 | #else //KAB_EMBEDDED | 1513 | #else //KAB_EMBEDDED |
1514 | qDebug("KABCore::openLDAPDialog() finsih method"); | 1514 | qDebug("KABCore::openLDAPDialog() finsih method"); |
1515 | #endif //KAB_EMBEDDED | 1515 | #endif //KAB_EMBEDDED |
1516 | } | 1516 | } |
1517 | 1517 | ||
1518 | void KABCore::print() | 1518 | void KABCore::print() |
1519 | { | 1519 | { |
1520 | #ifndef KAB_EMBEDDED | 1520 | #ifndef KAB_EMBEDDED |
1521 | KPrinter printer; | 1521 | KPrinter printer; |
1522 | if ( !printer.setup( this ) ) | 1522 | if ( !printer.setup( this ) ) |
1523 | return; | 1523 | return; |
1524 | 1524 | ||
1525 | KABPrinting::PrintingWizard wizard( &printer, mAddressBook, | 1525 | KABPrinting::PrintingWizard wizard( &printer, mAddressBook, |
1526 | mViewManager->selectedUids(), this ); | 1526 | mViewManager->selectedUids(), this ); |
1527 | 1527 | ||
1528 | wizard.exec(); | 1528 | wizard.exec(); |
1529 | #else //KAB_EMBEDDED | 1529 | #else //KAB_EMBEDDED |
1530 | qDebug("KABCore::print() finsih method"); | 1530 | qDebug("KABCore::print() finsih method"); |
1531 | #endif //KAB_EMBEDDED | 1531 | #endif //KAB_EMBEDDED |
1532 | 1532 | ||
1533 | } | 1533 | } |
1534 | 1534 | ||
1535 | 1535 | ||
1536 | void KABCore::addGUIClient( KXMLGUIClient *client ) | 1536 | void KABCore::addGUIClient( KXMLGUIClient *client ) |
1537 | { | 1537 | { |
1538 | if ( mGUIClient ) | 1538 | if ( mGUIClient ) |
1539 | mGUIClient->insertChildClient( client ); | 1539 | mGUIClient->insertChildClient( client ); |
1540 | else | 1540 | else |
1541 | KMessageBox::error( this, "no KXMLGUICLient"); | 1541 | KMessageBox::error( this, "no KXMLGUICLient"); |
1542 | } | 1542 | } |
1543 | 1543 | ||
1544 | 1544 | ||
1545 | void KABCore::configurationChanged() | 1545 | void KABCore::configurationChanged() |
1546 | { | 1546 | { |
1547 | mExtensionManager->reconfigure(); | 1547 | mExtensionManager->reconfigure(); |
1548 | } | 1548 | } |
1549 | 1549 | ||
1550 | void KABCore::addressBookChanged() | 1550 | void KABCore::addressBookChanged() |
1551 | { | 1551 | { |
1552 | /*US | 1552 | /*US |
1553 | QDictIterator<AddresseeEditorDialog> it( mEditorDict ); | 1553 | QDictIterator<AddresseeEditorDialog> it( mEditorDict ); |
1554 | while ( it.current() ) { | 1554 | while ( it.current() ) { |
1555 | if ( it.current()->dirty() ) { | 1555 | if ( it.current()->dirty() ) { |
1556 | QString text = i18n( "Data has been changed externally. Unsaved " | 1556 | QString text = i18n( "Data has been changed externally. Unsaved " |
1557 | "changes will be lost." ); | 1557 | "changes will be lost." ); |
1558 | KMessageBox::information( this, text ); | 1558 | KMessageBox::information( this, text ); |
1559 | } | 1559 | } |
1560 | it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); | 1560 | it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); |
1561 | ++it; | 1561 | ++it; |
1562 | } | 1562 | } |
1563 | */ | 1563 | */ |
1564 | if (mEditorDialog) | 1564 | if (mEditorDialog) |
1565 | { | 1565 | { |
1566 | if (mEditorDialog->dirty()) | 1566 | if (mEditorDialog->dirty()) |
1567 | { | 1567 | { |
1568 | QString text = i18n( "Data has been changed externally. Unsaved " | 1568 | QString text = i18n( "Data has been changed externally. Unsaved " |
1569 | "changes will be lost." ); | 1569 | "changes will be lost." ); |
1570 | KMessageBox::information( this, text ); | 1570 | KMessageBox::information( this, text ); |
1571 | } | 1571 | } |
1572 | QString currentuid = mEditorDialog->addressee().uid(); | 1572 | QString currentuid = mEditorDialog->addressee().uid(); |
1573 | mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); | 1573 | mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); |
1574 | } | 1574 | } |
1575 | mViewManager->refreshView(); | 1575 | mViewManager->refreshView(); |
1576 | // mDetails->refreshView(); | 1576 | // mDetails->refreshView(); |
1577 | 1577 | ||
1578 | 1578 | ||
1579 | } | 1579 | } |
1580 | 1580 | ||
1581 | AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, | 1581 | AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, |
1582 | const char *name ) | 1582 | const char *name ) |
1583 | { | 1583 | { |
1584 | 1584 | ||
1585 | if ( mEditorDialog == 0 ) { | 1585 | if ( mEditorDialog == 0 ) { |
1586 | mEditorDialog = new AddresseeEditorDialog( this, parent, | 1586 | mEditorDialog = new AddresseeEditorDialog( this, parent, |
1587 | name ? name : "editorDialog" ); | 1587 | name ? name : "editorDialog" ); |
1588 | 1588 | ||
1589 | 1589 | ||
1590 | connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), | 1590 | connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), |
1591 | SLOT( contactModified( const KABC::Addressee& ) ) ); | 1591 | SLOT( contactModified( const KABC::Addressee& ) ) ); |
1592 | //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), | 1592 | //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), |
1593 | // SLOT( slotEditorDestroyed( const QString& ) ) ; | 1593 | // SLOT( slotEditorDestroyed( const QString& ) ) ; |
1594 | } | 1594 | } |
1595 | 1595 | ||
1596 | return mEditorDialog; | 1596 | return mEditorDialog; |
1597 | } | 1597 | } |
1598 | 1598 | ||
1599 | void KABCore::slotEditorDestroyed( const QString &uid ) | 1599 | void KABCore::slotEditorDestroyed( const QString &uid ) |
1600 | { | 1600 | { |
1601 | //mEditorDict.remove( uid ); | 1601 | //mEditorDict.remove( uid ); |
1602 | } | 1602 | } |
1603 | 1603 | ||
1604 | void KABCore::initGUI() | 1604 | void KABCore::initGUI() |
1605 | { | 1605 | { |
1606 | #ifndef KAB_EMBEDDED | 1606 | #ifndef KAB_EMBEDDED |
1607 | QHBoxLayout *topLayout = new QHBoxLayout( this ); | 1607 | QHBoxLayout *topLayout = new QHBoxLayout( this ); |
1608 | topLayout->setSpacing( KDialogBase::spacingHint() ); | 1608 | topLayout->setSpacing( KDialogBase::spacingHint() ); |
1609 | 1609 | ||
1610 | mExtensionBarSplitter = new QSplitter( this ); | 1610 | mExtensionBarSplitter = new QSplitter( this ); |
1611 | mExtensionBarSplitter->setOrientation( Qt::Vertical ); | 1611 | mExtensionBarSplitter->setOrientation( Qt::Vertical ); |
1612 | 1612 | ||
1613 | mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); | 1613 | mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); |
1614 | 1614 | ||
1615 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); | 1615 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); |
1616 | mIncSearchWidget = new IncSearchWidget( viewSpace ); | 1616 | mIncSearchWidget = new IncSearchWidget( viewSpace ); |
1617 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), | 1617 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), |
1618 | SLOT( incrementalSearch( const QString& ) ) ); | 1618 | SLOT( incrementalSearch( const QString& ) ) ); |
1619 | 1619 | ||
1620 | mViewManager = new ViewManager( this, viewSpace ); | 1620 | mViewManager = new ViewManager( this, viewSpace ); |
1621 | viewSpace->setStretchFactor( mViewManager, 1 ); | 1621 | viewSpace->setStretchFactor( mViewManager, 1 ); |
1622 | 1622 | ||
1623 | mDetails = new ViewContainer( mDetailsSplitter ); | 1623 | mDetails = new ViewContainer( mDetailsSplitter ); |
1624 | 1624 | ||
1625 | mJumpButtonBar = new JumpButtonBar( this, this ); | 1625 | mJumpButtonBar = new JumpButtonBar( this, this ); |
1626 | 1626 | ||
1627 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); | 1627 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); |
1628 | 1628 | ||
1629 | topLayout->addWidget( mExtensionBarSplitter ); | 1629 | topLayout->addWidget( mExtensionBarSplitter ); |
1630 | topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); | 1630 | topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); |
1631 | topLayout->addWidget( mJumpButtonBar ); | 1631 | topLayout->addWidget( mJumpButtonBar ); |
1632 | topLayout->setStretchFactor( mJumpButtonBar, 1 ); | 1632 | topLayout->setStretchFactor( mJumpButtonBar, 1 ); |
1633 | 1633 | ||
1634 | mXXPortManager = new XXPortManager( this, this ); | 1634 | mXXPortManager = new XXPortManager( this, this ); |
1635 | 1635 | ||
1636 | #else //KAB_EMBEDDED | 1636 | #else //KAB_EMBEDDED |
1637 | //US initialize viewMenu before settingup viewmanager. | 1637 | //US initialize viewMenu before settingup viewmanager. |
1638 | // Viewmanager needs this menu to plugin submenues. | 1638 | // Viewmanager needs this menu to plugin submenues. |
1639 | viewMenu = new QPopupMenu( this ); | 1639 | viewMenu = new QPopupMenu( this ); |
1640 | settingsMenu = new QPopupMenu( this ); | 1640 | settingsMenu = new QPopupMenu( this ); |
1641 | //filterMenu = new QPopupMenu( this ); | 1641 | //filterMenu = new QPopupMenu( this ); |
1642 | ImportMenu = new QPopupMenu( this ); | 1642 | ImportMenu = new QPopupMenu( this ); |
1643 | ExportMenu = new QPopupMenu( this ); | 1643 | ExportMenu = new QPopupMenu( this ); |
1644 | syncMenu = new QPopupMenu( this ); | 1644 | syncMenu = new QPopupMenu( this ); |
1645 | changeMenu= new QPopupMenu( this ); | 1645 | changeMenu= new QPopupMenu( this ); |
1646 | 1646 | ||
1647 | //US since we have no splitter for the embedded system, setup | 1647 | //US since we have no splitter for the embedded system, setup |
1648 | // a layout with two frames. One left and one right. | 1648 | // a layout with two frames. One left and one right. |
1649 | 1649 | ||
1650 | QBoxLayout *topLayout; | 1650 | QBoxLayout *topLayout; |
1651 | 1651 | ||
1652 | // = new QHBoxLayout( this ); | 1652 | // = new QHBoxLayout( this ); |
1653 | // QBoxLayout *topLayout = (QBoxLayout*)layout(); | 1653 | // QBoxLayout *topLayout = (QBoxLayout*)layout(); |
1654 | 1654 | ||
1655 | // QWidget *mainBox = new QWidget( this ); | 1655 | // QWidget *mainBox = new QWidget( this ); |
1656 | // QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); | 1656 | // QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); |
1657 | 1657 | ||
1658 | #ifdef DESKTOP_VERSION | 1658 | #ifdef DESKTOP_VERSION |
1659 | topLayout = new QHBoxLayout( this ); | 1659 | topLayout = new QHBoxLayout( this ); |
1660 | 1660 | ||
1661 | 1661 | ||
1662 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); | 1662 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); |
1663 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); | 1663 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); |
1664 | 1664 | ||
1665 | topLayout->addWidget(mMiniSplitter ); | 1665 | topLayout->addWidget(mMiniSplitter ); |
1666 | 1666 | ||
1667 | mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); | 1667 | mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); |
1668 | mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); | 1668 | mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); |
1669 | mViewManager = new ViewManager( this, mExtensionBarSplitter ); | 1669 | mViewManager = new ViewManager( this, mExtensionBarSplitter ); |
1670 | mDetails = new ViewContainer( mMiniSplitter ); | 1670 | mDetails = new ViewContainer( mMiniSplitter ); |
1671 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); | 1671 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); |
1672 | #else | 1672 | #else |
1673 | if ( QApplication::desktop()->width() > 480 ) { | 1673 | if ( QApplication::desktop()->width() > 480 ) { |
1674 | topLayout = new QHBoxLayout( this ); | 1674 | topLayout = new QHBoxLayout( this ); |
1675 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); | 1675 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); |
1676 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); | 1676 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); |
1677 | } else { | 1677 | } else { |
1678 | 1678 | ||
1679 | topLayout = new QHBoxLayout( this ); | 1679 | topLayout = new QHBoxLayout( this ); |
1680 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); | 1680 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); |
1681 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); | 1681 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); |
1682 | } | 1682 | } |
1683 | 1683 | ||
1684 | topLayout->addWidget(mMiniSplitter ); | 1684 | topLayout->addWidget(mMiniSplitter ); |
1685 | mViewManager = new ViewManager( this, mMiniSplitter ); | 1685 | mViewManager = new ViewManager( this, mMiniSplitter ); |
1686 | mDetails = new ViewContainer( mMiniSplitter ); | 1686 | mDetails = new ViewContainer( mMiniSplitter ); |
1687 | 1687 | ||
1688 | 1688 | ||
1689 | mExtensionManager = new ExtensionManager( this, mMiniSplitter ); | 1689 | mExtensionManager = new ExtensionManager( this, mMiniSplitter ); |
1690 | #endif | 1690 | #endif |
1691 | //eh->hide(); | 1691 | //eh->hide(); |
1692 | // topLayout->addWidget(mExtensionManager ); | 1692 | // topLayout->addWidget(mExtensionManager ); |
1693 | 1693 | ||
1694 | 1694 | ||
1695 | /*US | 1695 | /*US |
1696 | #ifndef KAB_NOSPLITTER | 1696 | #ifndef KAB_NOSPLITTER |
1697 | QHBoxLayout *topLayout = new QHBoxLayout( this ); | 1697 | QHBoxLayout *topLayout = new QHBoxLayout( this ); |
1698 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); | 1698 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); |
1699 | topLayout->setSpacing( 10 ); | 1699 | topLayout->setSpacing( 10 ); |
1700 | 1700 | ||
1701 | mDetailsSplitter = new QSplitter( this ); | 1701 | mDetailsSplitter = new QSplitter( this ); |
1702 | 1702 | ||
1703 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); | 1703 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); |
1704 | 1704 | ||
1705 | mViewManager = new ViewManager( this, viewSpace ); | 1705 | mViewManager = new ViewManager( this, viewSpace ); |
1706 | viewSpace->setStretchFactor( mViewManager, 1 ); | 1706 | viewSpace->setStretchFactor( mViewManager, 1 ); |
1707 | 1707 | ||
1708 | mDetails = new ViewContainer( mDetailsSplitter ); | 1708 | mDetails = new ViewContainer( mDetailsSplitter ); |
1709 | 1709 | ||
1710 | topLayout->addWidget( mDetailsSplitter ); | 1710 | topLayout->addWidget( mDetailsSplitter ); |
1711 | topLayout->setStretchFactor( mDetailsSplitter, 100 ); | 1711 | topLayout->setStretchFactor( mDetailsSplitter, 100 ); |
1712 | #else //KAB_NOSPLITTER | 1712 | #else //KAB_NOSPLITTER |
1713 | QHBoxLayout *topLayout = new QHBoxLayout( this ); | 1713 | QHBoxLayout *topLayout = new QHBoxLayout( this ); |
1714 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); | 1714 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); |
1715 | topLayout->setSpacing( 10 ); | 1715 | topLayout->setSpacing( 10 ); |
1716 | 1716 | ||
1717 | // mDetailsSplitter = new QSplitter( this ); | 1717 | // mDetailsSplitter = new QSplitter( this ); |
1718 | 1718 | ||
1719 | QVBox *viewSpace = new QVBox( this ); | 1719 | QVBox *viewSpace = new QVBox( this ); |
1720 | 1720 | ||
1721 | mViewManager = new ViewManager( this, viewSpace ); | 1721 | mViewManager = new ViewManager( this, viewSpace ); |
1722 | viewSpace->setStretchFactor( mViewManager, 1 ); | 1722 | viewSpace->setStretchFactor( mViewManager, 1 ); |
1723 | 1723 | ||
1724 | mDetails = new ViewContainer( this ); | 1724 | mDetails = new ViewContainer( this ); |
1725 | 1725 | ||
1726 | topLayout->addWidget( viewSpace ); | 1726 | topLayout->addWidget( viewSpace ); |
1727 | // topLayout->setStretchFactor( mDetailsSplitter, 100 ); | 1727 | // topLayout->setStretchFactor( mDetailsSplitter, 100 ); |
1728 | topLayout->addWidget( mDetails ); | 1728 | topLayout->addWidget( mDetails ); |
1729 | #endif //KAB_NOSPLITTER | 1729 | #endif //KAB_NOSPLITTER |
1730 | */ | 1730 | */ |
1731 | 1731 | ||
1732 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); | 1732 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); |
1733 | syncManager->setBlockSave(false); | 1733 | syncManager->setBlockSave(false); |
1734 | 1734 | ||
1735 | connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); | 1735 | connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); |
1736 | connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); | 1736 | connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); |
1737 | syncManager->setDefaultFileName( sentSyncFile()); | 1737 | syncManager->setDefaultFileName( sentSyncFile()); |
1738 | //connect(syncManager , SIGNAL( ), this, SLOT( ) ); | 1738 | //connect(syncManager , SIGNAL( ), this, SLOT( ) ); |
1739 | 1739 | ||
1740 | #endif //KAB_EMBEDDED | 1740 | #endif //KAB_EMBEDDED |
1741 | initActions(); | 1741 | initActions(); |
1742 | 1742 | ||
1743 | #ifdef KAB_EMBEDDED | 1743 | #ifdef KAB_EMBEDDED |
1744 | addActionsManually(); | 1744 | addActionsManually(); |
1745 | //US make sure the export and import menues are initialized before creating the xxPortManager. | 1745 | //US make sure the export and import menues are initialized before creating the xxPortManager. |
1746 | mXXPortManager = new XXPortManager( this, this ); | 1746 | mXXPortManager = new XXPortManager( this, this ); |
1747 | 1747 | ||
1748 | // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); | 1748 | // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); |
1749 | //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); | 1749 | //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); |
1750 | // mActionQuit->plug ( mMainWindow->toolBar()); | 1750 | // mActionQuit->plug ( mMainWindow->toolBar()); |
1751 | //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); | 1751 | //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); |
1752 | //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); | 1752 | //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); |
1753 | // mIncSearchWidget->hide(); | 1753 | // mIncSearchWidget->hide(); |
1754 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), | 1754 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), |
1755 | SLOT( incrementalSearch( const QString& ) ) ); | 1755 | SLOT( incrementalSearch( const QString& ) ) ); |
1756 | connect( mIncSearchWidget, SIGNAL( scrollUP() ),mViewManager, SLOT( scrollUP() ) ); | 1756 | connect( mIncSearchWidget, SIGNAL( scrollUP() ),mViewManager, SLOT( scrollUP() ) ); |
1757 | connect( mIncSearchWidget, SIGNAL( scrollDOWN() ),mViewManager, SLOT( scrollDOWN() ) ); | 1757 | connect( mIncSearchWidget, SIGNAL( scrollDOWN() ),mViewManager, SLOT( scrollDOWN() ) ); |
1758 | 1758 | ||
1759 | mJumpButtonBar = new JumpButtonBar( this, this ); | 1759 | mJumpButtonBar = new JumpButtonBar( this, this ); |
1760 | 1760 | ||
1761 | topLayout->addWidget( mJumpButtonBar ); | 1761 | topLayout->addWidget( mJumpButtonBar ); |
1762 | //US topLayout->setStretchFactor( mJumpButtonBar, 10 ); | 1762 | //US topLayout->setStretchFactor( mJumpButtonBar, 10 ); |
1763 | 1763 | ||
1764 | // mMainWindow->getIconToolBar()->raise(); | 1764 | // mMainWindow->getIconToolBar()->raise(); |
1765 | 1765 | ||
1766 | #endif //KAB_EMBEDDED | 1766 | #endif //KAB_EMBEDDED |
1767 | 1767 | ||
1768 | } | 1768 | } |
1769 | void KABCore::initActions() | 1769 | void KABCore::initActions() |
1770 | { | 1770 | { |
1771 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); | 1771 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); |
1772 | 1772 | ||
1773 | #ifndef KAB_EMBEDDED | 1773 | #ifndef KAB_EMBEDDED |
1774 | connect( QApplication::clipboard(), SIGNAL( dataChanged() ), | 1774 | connect( QApplication::clipboard(), SIGNAL( dataChanged() ), |
1775 | SLOT( clipboardDataChanged() ) ); | 1775 | SLOT( clipboardDataChanged() ) ); |
1776 | #endif //KAB_EMBEDDED | 1776 | #endif //KAB_EMBEDDED |
1777 | 1777 | ||
1778 | // file menu | 1778 | // file menu |
1779 | if ( mIsPart ) { | 1779 | if ( mIsPart ) { |
1780 | mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, | 1780 | mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, |
1781 | SLOT( sendMail() ), actionCollection(), | 1781 | SLOT( sendMail() ), actionCollection(), |
1782 | "kaddressbook_mail" ); | 1782 | "kaddressbook_mail" ); |
1783 | mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, | 1783 | mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, |
1784 | SLOT( print() ), actionCollection(), "kaddressbook_print" ); | 1784 | SLOT( print() ), actionCollection(), "kaddressbook_print" ); |
1785 | 1785 | ||
1786 | } else { | 1786 | } else { |
1787 | mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); | 1787 | mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); |
1788 | mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); | 1788 | mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); |
1789 | } | 1789 | } |
1790 | 1790 | ||
1791 | 1791 | ||
1792 | mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, | 1792 | mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, |
1793 | SLOT( save() ), actionCollection(), "file_sync" ); | 1793 | SLOT( save() ), actionCollection(), "file_sync" ); |
1794 | 1794 | ||
1795 | mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, | 1795 | mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, |
1796 | SLOT( newContact() ), actionCollection(), "file_new_contact" ); | 1796 | SLOT( newContact() ), actionCollection(), "file_new_contact" ); |
1797 | 1797 | ||
1798 | mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, | 1798 | mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, |
1799 | this, SLOT( mailVCard() ), | 1799 | this, SLOT( mailVCard() ), |
1800 | actionCollection(), "file_mail_vcard"); | 1800 | actionCollection(), "file_mail_vcard"); |
1801 | 1801 | ||
1802 | mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this, | 1802 | mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this, |
1803 | SLOT( export2phone() ), actionCollection(), | 1803 | SLOT( export2phone() ), actionCollection(), |
1804 | "kaddressbook_ex2phone" ); | 1804 | "kaddressbook_ex2phone" ); |
1805 | 1805 | ||
1806 | mActionBeamVCard = 0; | 1806 | mActionBeamVCard = 0; |
1807 | mActionBeam = 0; | 1807 | mActionBeam = 0; |
1808 | 1808 | ||
1809 | #ifndef DESKTOP_VERSION | 1809 | #ifndef DESKTOP_VERSION |
1810 | if ( Ir::supported() ) { | 1810 | if ( Ir::supported() ) { |
1811 | mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, | 1811 | mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, |
1812 | SLOT( beamVCard() ), actionCollection(), | 1812 | SLOT( beamVCard() ), actionCollection(), |
1813 | "kaddressbook_beam_vcard" ); | 1813 | "kaddressbook_beam_vcard" ); |
1814 | 1814 | ||
1815 | mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, | 1815 | mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, |
1816 | SLOT( beamMySelf() ), actionCollection(), | 1816 | SLOT( beamMySelf() ), actionCollection(), |
1817 | "kaddressbook_beam_myself" ); | 1817 | "kaddressbook_beam_myself" ); |
1818 | } | 1818 | } |
1819 | #endif | 1819 | #endif |
1820 | 1820 | ||
1821 | mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, | 1821 | mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, |
1822 | this, SLOT( editContact2() ), | 1822 | this, SLOT( editContact2() ), |
1823 | actionCollection(), "file_properties" ); | 1823 | actionCollection(), "file_properties" ); |
1824 | 1824 | ||
1825 | #ifdef KAB_EMBEDDED | 1825 | #ifdef KAB_EMBEDDED |
1826 | // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); | 1826 | // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); |
1827 | mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, | 1827 | mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, |
1828 | mMainWindow, SLOT( exit() ), | 1828 | mMainWindow, SLOT( exit() ), |
1829 | actionCollection(), "quit" ); | 1829 | actionCollection(), "quit" ); |
1830 | #endif //KAB_EMBEDDED | 1830 | #endif //KAB_EMBEDDED |
1831 | 1831 | ||
1832 | // edit menu | 1832 | // edit menu |
1833 | if ( mIsPart ) { | 1833 | if ( mIsPart ) { |
1834 | mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, | 1834 | mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, |
1835 | SLOT( copyContacts() ), actionCollection(), | 1835 | SLOT( copyContacts() ), actionCollection(), |
1836 | "kaddressbook_copy" ); | 1836 | "kaddressbook_copy" ); |
1837 | mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, | 1837 | mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, |
1838 | SLOT( cutContacts() ), actionCollection(), | 1838 | SLOT( cutContacts() ), actionCollection(), |
1839 | "kaddressbook_cut" ); | 1839 | "kaddressbook_cut" ); |
1840 | mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, | 1840 | mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, |
1841 | SLOT( pasteContacts() ), actionCollection(), | 1841 | SLOT( pasteContacts() ), actionCollection(), |
1842 | "kaddressbook_paste" ); | 1842 | "kaddressbook_paste" ); |
1843 | mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, | 1843 | mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, |
1844 | SLOT( selectAllContacts() ), actionCollection(), | 1844 | SLOT( selectAllContacts() ), actionCollection(), |
1845 | "kaddressbook_select_all" ); | 1845 | "kaddressbook_select_all" ); |
1846 | mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, | 1846 | mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, |
1847 | SLOT( undo() ), actionCollection(), | 1847 | SLOT( undo() ), actionCollection(), |
1848 | "kaddressbook_undo" ); | 1848 | "kaddressbook_undo" ); |
1849 | mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, | 1849 | mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, |
1850 | this, SLOT( redo() ), actionCollection(), | 1850 | this, SLOT( redo() ), actionCollection(), |
1851 | "kaddressbook_redo" ); | 1851 | "kaddressbook_redo" ); |
1852 | } else { | 1852 | } else { |
1853 | mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); | 1853 | mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); |
1854 | mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); | 1854 | mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); |
1855 | mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); | 1855 | mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); |
1856 | mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); | 1856 | mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); |
1857 | mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); | 1857 | mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); |
1858 | mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); | 1858 | mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); |
1859 | } | 1859 | } |
1860 | 1860 | ||
1861 | mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", | 1861 | mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", |
1862 | Key_Delete, this, SLOT( deleteContacts() ), | 1862 | Key_Delete, this, SLOT( deleteContacts() ), |
1863 | actionCollection(), "edit_delete" ); | 1863 | actionCollection(), "edit_delete" ); |
1864 | 1864 | ||
1865 | mActionUndo->setEnabled( false ); | 1865 | mActionUndo->setEnabled( false ); |
1866 | mActionRedo->setEnabled( false ); | 1866 | mActionRedo->setEnabled( false ); |
1867 | 1867 | ||
1868 | // settings menu | 1868 | // settings menu |
1869 | #ifdef KAB_EMBEDDED | 1869 | #ifdef KAB_EMBEDDED |
1870 | //US special menuentry to configure the addressbook resources. On KDE | 1870 | //US special menuentry to configure the addressbook resources. On KDE |
1871 | // you do that through the control center !!! | 1871 | // you do that through the control center !!! |
1872 | mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, | 1872 | mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, |
1873 | SLOT( configureResources() ), actionCollection(), | 1873 | SLOT( configureResources() ), actionCollection(), |
1874 | "kaddressbook_configure_resources" ); | 1874 | "kaddressbook_configure_resources" ); |
1875 | #endif //KAB_EMBEDDED | 1875 | #endif //KAB_EMBEDDED |
1876 | 1876 | ||
1877 | if ( mIsPart ) { | 1877 | if ( mIsPart ) { |
1878 | mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, | 1878 | mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, |
1879 | SLOT( openConfigDialog() ), actionCollection(), | 1879 | SLOT( openConfigDialog() ), actionCollection(), |
1880 | "kaddressbook_configure" ); | 1880 | "kaddressbook_configure" ); |
1881 | 1881 | ||
1882 | //US not implemented yet | 1882 | //US not implemented yet |
1883 | //mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, | 1883 | //mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, |
1884 | // this, SLOT( configureKeyBindings() ), actionCollection(), | 1884 | // this, SLOT( configureKeyBindings() ), actionCollection(), |
1885 | // "kaddressbook_configure_shortcuts" ); | 1885 | // "kaddressbook_configure_shortcuts" ); |
1886 | #ifdef KAB_EMBEDDED | 1886 | #ifdef KAB_EMBEDDED |
1887 | mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); | 1887 | mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); |
1888 | mActionConfigureToolbars->setEnabled( false ); | 1888 | mActionConfigureToolbars->setEnabled( false ); |
1889 | #endif //KAB_EMBEDDED | 1889 | #endif //KAB_EMBEDDED |
1890 | 1890 | ||
1891 | } else { | 1891 | } else { |
1892 | mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); | 1892 | mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); |
1893 | 1893 | ||
1894 | //US not implemented yet | 1894 | //US not implemented yet |
1895 | //mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); | 1895 | //mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); |
1896 | } | 1896 | } |
1897 | 1897 | ||
1898 | mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, | 1898 | mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, |
1899 | actionCollection(), "options_show_jump_bar" ); | 1899 | actionCollection(), "options_show_jump_bar" ); |
1900 | connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); | 1900 | connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); |
1901 | 1901 | ||
1902 | mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, | 1902 | mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, |
1903 | actionCollection(), "options_show_details" ); | 1903 | actionCollection(), "options_show_details" ); |
1904 | connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); | 1904 | connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); |
1905 | 1905 | ||
1906 | 1906 | ||
1907 | mActionBR = new KToggleAction( i18n( "Beam receive enabled" ), "beam", 0, this, | 1907 | mActionBR = new KToggleAction( i18n( "Beam receive enabled" ), "beam", 0, this, |
1908 | SLOT( toggleBeamReceive() ), actionCollection(), | 1908 | SLOT( toggleBeamReceive() ), actionCollection(), |
1909 | "kaddressbook_beam_rec" ); | 1909 | "kaddressbook_beam_rec" ); |
1910 | 1910 | ||
1911 | 1911 | ||
1912 | // misc | 1912 | // misc |
1913 | // only enable LDAP lookup if we can handle the protocol | 1913 | // only enable LDAP lookup if we can handle the protocol |
1914 | #ifndef KAB_EMBEDDED | 1914 | #ifndef KAB_EMBEDDED |
1915 | if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { | 1915 | if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { |
1916 | new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, | 1916 | new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, |
1917 | this, SLOT( openLDAPDialog() ), actionCollection(), | 1917 | this, SLOT( openLDAPDialog() ), actionCollection(), |
1918 | "ldap_lookup" ); | 1918 | "ldap_lookup" ); |
1919 | } | 1919 | } |
1920 | #else //KAB_EMBEDDED | 1920 | #else //KAB_EMBEDDED |
1921 | //qDebug("KABCore::initActions() LDAP has to be implemented"); | 1921 | //qDebug("KABCore::initActions() LDAP has to be implemented"); |
1922 | #endif //KAB_EMBEDDED | 1922 | #endif //KAB_EMBEDDED |
1923 | 1923 | ||
1924 | 1924 | ||
1925 | mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, | 1925 | mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, |
1926 | SLOT( setWhoAmI() ), actionCollection(), | 1926 | SLOT( setWhoAmI() ), actionCollection(), |
1927 | "set_personal" ); | 1927 | "set_personal" ); |
1928 | 1928 | ||
1929 | 1929 | ||
1930 | mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, | 1930 | mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, |
1931 | SLOT( setCategories() ), actionCollection(), | 1931 | SLOT( setCategories() ), actionCollection(), |
1932 | "edit_set_categories" ); | 1932 | "edit_set_categories" ); |
1933 | mActionEditCategories = new KAction( i18n( "Edit Categories" ), 0, this, | 1933 | mActionEditCategories = new KAction( i18n( "Edit Categories" ), 0, this, |
1934 | SLOT( editCategories() ), actionCollection(), | 1934 | SLOT( editCategories() ), actionCollection(), |
1935 | "edit__categories" ); | 1935 | "edit__categories" ); |
1936 | 1936 | ||
1937 | mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, | 1937 | mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, |
1938 | SLOT( removeVoice() ), actionCollection(), | 1938 | SLOT( removeVoice() ), actionCollection(), |
1939 | "remove_voice" ); | 1939 | "remove_voice" ); |
1940 | 1940 | ||
1941 | mActionManageCategories= new KAction( i18n( "Manage new categories..." ), 0, this, | 1941 | mActionManageCategories= new KAction( i18n( "Manage new categories..." ), 0, this, |
1942 | SLOT( manageCategories() ), actionCollection(), | 1942 | SLOT( manageCategories() ), actionCollection(), |
1943 | "remove_voice" ); | 1943 | "remove_voice" ); |
1944 | 1944 | ||
1945 | 1945 | ||
1946 | mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this, | 1946 | mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this, |
1947 | SLOT( importFromOL() ), actionCollection(), | 1947 | SLOT( importFromOL() ), actionCollection(), |
1948 | "import_OL" ); | 1948 | "import_OL" ); |
1949 | #ifdef KAB_EMBEDDED | 1949 | #ifdef KAB_EMBEDDED |
1950 | mActionLicence = new KAction( i18n( "Licence" ), 0, | 1950 | mActionLicence = new KAction( i18n( "Licence" ), 0, |
1951 | this, SLOT( showLicence() ), actionCollection(), | 1951 | this, SLOT( showLicence() ), actionCollection(), |
1952 | "licence_about_data" ); | 1952 | "licence_about_data" ); |
1953 | mActionFaq = new KAction( i18n( "Faq" ), 0, | 1953 | mActionFaq = new KAction( i18n( "Faq" ), 0, |
1954 | this, SLOT( faq() ), actionCollection(), | 1954 | this, SLOT( faq() ), actionCollection(), |
1955 | "faq_about_data" ); | 1955 | "faq_about_data" ); |
1956 | mActionWN = new KAction( i18n( "What's New?" ), 0, | 1956 | mActionWN = new KAction( i18n( "What's New?" ), 0, |
1957 | this, SLOT( whatsnew() ), actionCollection(), | 1957 | this, SLOT( whatsnew() ), actionCollection(), |
1958 | "wn" ); | 1958 | "wn" ); |
1959 | mActionSyncHowto = new KAction( i18n( "Sync HowTo" ), 0, | 1959 | mActionSyncHowto = new KAction( i18n( "Sync HowTo" ), 0, |
1960 | this, SLOT( synchowto() ), actionCollection(), | 1960 | this, SLOT( synchowto() ), actionCollection(), |
1961 | "sync" ); | 1961 | "sync" ); |
1962 | mActionKdeSyncHowto = new KAction( i18n( "Kde Sync HowTo" ), 0, | 1962 | mActionKdeSyncHowto = new KAction( i18n( "Kde Sync HowTo" ), 0, |
1963 | this, SLOT( kdesynchowto() ), actionCollection(), | 1963 | this, SLOT( kdesynchowto() ), actionCollection(), |
1964 | "kdesync" ); | 1964 | "kdesync" ); |
1965 | mActionMultiSyncHowto = new KAction( i18n( "Multi Sync HowTo" ), 0, | 1965 | mActionMultiSyncHowto = new KAction( i18n( "Multi Sync HowTo" ), 0, |
1966 | this, SLOT( multisynchowto() ), actionCollection(), | 1966 | this, SLOT( multisynchowto() ), actionCollection(), |
1967 | "multisync" ); | 1967 | "multisync" ); |
1968 | 1968 | ||
1969 | mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, | 1969 | mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, |
1970 | this, SLOT( createAboutData() ), actionCollection(), | 1970 | this, SLOT( createAboutData() ), actionCollection(), |
1971 | "kaddressbook_about_data" ); | 1971 | "kaddressbook_about_data" ); |
1972 | #endif //KAB_EMBEDDED | 1972 | #endif //KAB_EMBEDDED |
1973 | 1973 | ||
1974 | clipboardDataChanged(); | 1974 | clipboardDataChanged(); |
1975 | connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); | 1975 | connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); |
1976 | connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); | 1976 | connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); |
1977 | } | 1977 | } |
1978 | 1978 | ||
1979 | //US we need this function, to plug all actions into the correct menues. | 1979 | //US we need this function, to plug all actions into the correct menues. |
1980 | // KDE uses a XML format to plug the actions, but we work her without this overhead. | 1980 | // KDE uses a XML format to plug the actions, but we work her without this overhead. |
1981 | void KABCore::addActionsManually() | 1981 | void KABCore::addActionsManually() |
1982 | { | 1982 | { |
1983 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); | 1983 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); |
1984 | 1984 | ||
1985 | #ifdef KAB_EMBEDDED | 1985 | #ifdef KAB_EMBEDDED |
1986 | QPopupMenu *fileMenu = new QPopupMenu( this ); | 1986 | QPopupMenu *fileMenu = new QPopupMenu( this ); |
1987 | QPopupMenu *editMenu = new QPopupMenu( this ); | 1987 | QPopupMenu *editMenu = new QPopupMenu( this ); |
1988 | QPopupMenu *helpMenu = new QPopupMenu( this ); | 1988 | QPopupMenu *helpMenu = new QPopupMenu( this ); |
1989 | 1989 | ||
1990 | KToolBar* tb = mMainWindow->toolBar(); | 1990 | KToolBar* tb = mMainWindow->toolBar(); |
1991 | 1991 | ||
1992 | #ifndef DESKTOP_VERSION | 1992 | #ifndef DESKTOP_VERSION |
1993 | if ( KABPrefs::instance()->mFullMenuBarVisible ) { | 1993 | if ( KABPrefs::instance()->mFullMenuBarVisible ) { |
1994 | #endif | 1994 | #endif |
1995 | QMenuBar* mb = mMainWindow->menuBar(); | 1995 | QMenuBar* mb = mMainWindow->menuBar(); |
1996 | 1996 | ||
1997 | //US setup menubar. | 1997 | //US setup menubar. |
1998 | //Disable the following block if you do not want to have a menubar. | 1998 | //Disable the following block if you do not want to have a menubar. |
1999 | mb->insertItem( i18n("&File"), fileMenu ); | 1999 | mb->insertItem( i18n("&File"), fileMenu ); |
2000 | mb->insertItem( i18n("&Edit"), editMenu ); | 2000 | mb->insertItem( i18n("&Edit"), editMenu ); |
2001 | mb->insertItem( i18n("&View"), viewMenu ); | 2001 | mb->insertItem( i18n("&View"), viewMenu ); |
2002 | mb->insertItem( i18n("&Settings"), settingsMenu ); | 2002 | mb->insertItem( i18n("&Settings"), settingsMenu ); |
2003 | mb->insertItem( i18n("Synchronize"), syncMenu ); | 2003 | mb->insertItem( i18n("Synchronize"), syncMenu ); |
2004 | mb->insertItem( i18n("&Change selected"), changeMenu ); | 2004 | mb->insertItem( i18n("&Change selected"), changeMenu ); |
2005 | mb->insertItem( i18n("&Help"), helpMenu ); | 2005 | mb->insertItem( i18n("&Help"), helpMenu ); |
2006 | mIncSearchWidget = new IncSearchWidget( tb ); | 2006 | mIncSearchWidget = new IncSearchWidget( tb ); |
2007 | // tb->insertWidget(-1, 0, mIncSearchWidget); | 2007 | // tb->insertWidget(-1, 0, mIncSearchWidget); |
2008 | #ifndef DESKTOP_VERSION | 2008 | #ifndef DESKTOP_VERSION |
2009 | } else { | 2009 | } else { |
2010 | //US setup toolbar | 2010 | //US setup toolbar |
2011 | QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); | 2011 | QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); |
2012 | QPopupMenu *popupBarTB = new QPopupMenu( this ); | 2012 | QPopupMenu *popupBarTB = new QPopupMenu( this ); |
2013 | menuBarTB->insertItem( "ME", popupBarTB); | 2013 | menuBarTB->insertItem( "ME", popupBarTB); |
2014 | tb->insertWidget(-1, 0, menuBarTB); | 2014 | tb->insertWidget(-1, 0, menuBarTB); |
2015 | mIncSearchWidget = new IncSearchWidget( tb ); | 2015 | mIncSearchWidget = new IncSearchWidget( tb ); |
2016 | 2016 | ||
2017 | tb->enableMoving(false); | 2017 | tb->enableMoving(false); |
2018 | popupBarTB->insertItem( i18n("&File"), fileMenu ); | 2018 | popupBarTB->insertItem( i18n("&File"), fileMenu ); |
2019 | popupBarTB->insertItem( i18n("&Edit"), editMenu ); | 2019 | popupBarTB->insertItem( i18n("&Edit"), editMenu ); |
2020 | popupBarTB->insertItem( i18n("&View"), viewMenu ); | 2020 | popupBarTB->insertItem( i18n("&View"), viewMenu ); |
2021 | popupBarTB->insertItem( i18n("&Settings"), settingsMenu ); | 2021 | popupBarTB->insertItem( i18n("&Settings"), settingsMenu ); |
2022 | popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); | 2022 | popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); |
2023 | mViewManager->getFilterAction()->plug ( popupBarTB); | 2023 | mViewManager->getFilterAction()->plug ( popupBarTB); |
2024 | popupBarTB->insertItem( i18n("&Change selected"), changeMenu ); | 2024 | popupBarTB->insertItem( i18n("&Change selected"), changeMenu ); |
2025 | popupBarTB->insertItem( i18n("&Help"), helpMenu ); | 2025 | popupBarTB->insertItem( i18n("&Help"), helpMenu ); |
2026 | if (QApplication::desktop()->width() > 320 ) { | 2026 | if (QApplication::desktop()->width() > 320 ) { |
2027 | // mViewManager->getFilterAction()->plug ( tb); | 2027 | // mViewManager->getFilterAction()->plug ( tb); |
2028 | } | 2028 | } |
2029 | } | 2029 | } |
2030 | #endif | 2030 | #endif |
2031 | // mActionQuit->plug ( mMainWindow->toolBar()); | 2031 | // mActionQuit->plug ( mMainWindow->toolBar()); |
2032 | 2032 | ||
2033 | 2033 | ||
2034 | 2034 | ||
2035 | //US Now connect the actions with the menue entries. | 2035 | //US Now connect the actions with the menue entries. |
2036 | mActionPrint->plug( fileMenu ); | 2036 | mActionPrint->plug( fileMenu ); |
2037 | mActionMail->plug( fileMenu ); | 2037 | mActionMail->plug( fileMenu ); |
2038 | fileMenu->insertSeparator(); | 2038 | fileMenu->insertSeparator(); |
2039 | 2039 | ||
2040 | mActionNewContact->plug( fileMenu ); | 2040 | mActionNewContact->plug( fileMenu ); |
2041 | mActionNewContact->plug( tb ); | 2041 | mActionNewContact->plug( tb ); |
2042 | 2042 | ||
2043 | mActionEditAddressee->plug( fileMenu ); | 2043 | mActionEditAddressee->plug( fileMenu ); |
2044 | // if ((KGlobal::getDesktopSize() > KGlobal::Small ) || | 2044 | // if ((KGlobal::getDesktopSize() > KGlobal::Small ) || |
2045 | // (!KABPrefs::instance()->mMultipleViewsAtOnce )) | 2045 | // (!KABPrefs::instance()->mMultipleViewsAtOnce )) |
2046 | mActionEditAddressee->plug( tb ); | 2046 | mActionEditAddressee->plug( tb ); |
2047 | 2047 | ||
2048 | fileMenu->insertSeparator(); | 2048 | fileMenu->insertSeparator(); |
2049 | mActionSave->plug( fileMenu ); | 2049 | mActionSave->plug( fileMenu ); |
2050 | fileMenu->insertItem( "&Import", ImportMenu ); | 2050 | fileMenu->insertItem( "&Import", ImportMenu ); |
2051 | fileMenu->insertItem( "&Export", ExportMenu ); | 2051 | fileMenu->insertItem( "&Export", ExportMenu ); |
2052 | fileMenu->insertSeparator(); | 2052 | fileMenu->insertSeparator(); |
2053 | mActionMailVCard->plug( fileMenu ); | 2053 | mActionMailVCard->plug( fileMenu ); |
2054 | #ifndef DESKTOP_VERSION | 2054 | #ifndef DESKTOP_VERSION |
2055 | if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); | 2055 | if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); |
2056 | if ( Ir::supported() ) mActionBeam->plug(fileMenu ); | 2056 | if ( Ir::supported() ) mActionBeam->plug(fileMenu ); |
2057 | #endif | 2057 | #endif |
2058 | fileMenu->insertSeparator(); | 2058 | fileMenu->insertSeparator(); |
2059 | mActionQuit->plug( fileMenu ); | 2059 | mActionQuit->plug( fileMenu ); |
2060 | #ifdef _WIN32_ | 2060 | #ifdef _WIN32_ |
2061 | mActionImportOL->plug( ImportMenu ); | 2061 | mActionImportOL->plug( ImportMenu ); |
2062 | #endif | 2062 | #endif |
2063 | // edit menu | 2063 | // edit menu |
2064 | mActionUndo->plug( editMenu ); | 2064 | mActionUndo->plug( editMenu ); |
2065 | mActionRedo->plug( editMenu ); | 2065 | mActionRedo->plug( editMenu ); |
2066 | editMenu->insertSeparator(); | 2066 | editMenu->insertSeparator(); |
2067 | mActionCut->plug( editMenu ); | 2067 | mActionCut->plug( editMenu ); |
2068 | mActionCopy->plug( editMenu ); | 2068 | mActionCopy->plug( editMenu ); |
2069 | mActionPaste->plug( editMenu ); | 2069 | mActionPaste->plug( editMenu ); |
2070 | mActionDelete->plug( editMenu ); | 2070 | mActionDelete->plug( editMenu ); |
2071 | editMenu->insertSeparator(); | 2071 | editMenu->insertSeparator(); |
2072 | mActionSelectAll->plug( editMenu ); | 2072 | mActionSelectAll->plug( editMenu ); |
2073 | 2073 | ||
2074 | mActionRemoveVoice->plug( changeMenu ); | 2074 | mActionRemoveVoice->plug( changeMenu ); |
2075 | // settings menu | 2075 | // settings menu |
2076 | //US special menuentry to configure the addressbook resources. On KDE | 2076 | //US special menuentry to configure the addressbook resources. On KDE |
2077 | // you do that through the control center !!! | 2077 | // you do that through the control center !!! |
2078 | mActionConfigResources->plug( settingsMenu ); | 2078 | mActionConfigResources->plug( settingsMenu ); |
2079 | settingsMenu->insertSeparator(); | 2079 | settingsMenu->insertSeparator(); |
2080 | 2080 | ||
2081 | mActionConfigKAddressbook->plug( settingsMenu ); | 2081 | mActionConfigKAddressbook->plug( settingsMenu ); |
2082 | 2082 | ||
2083 | if ( mIsPart ) { | 2083 | if ( mIsPart ) { |
2084 | //US not implemented yet | 2084 | //US not implemented yet |
2085 | //mActionConfigShortcuts->plug( settingsMenu ); | 2085 | //mActionConfigShortcuts->plug( settingsMenu ); |
2086 | //mActionConfigureToolbars->plug( settingsMenu ); | 2086 | //mActionConfigureToolbars->plug( settingsMenu ); |
2087 | 2087 | ||
2088 | } else { | 2088 | } else { |
2089 | //US not implemented yet | 2089 | //US not implemented yet |
2090 | //mActionKeyBindings->plug( settingsMenu ); | 2090 | //mActionKeyBindings->plug( settingsMenu ); |
2091 | } | 2091 | } |
2092 | 2092 | ||
2093 | settingsMenu->insertSeparator(); | 2093 | settingsMenu->insertSeparator(); |
2094 | 2094 | ||
2095 | mActionJumpBar->plug( settingsMenu ); | 2095 | mActionJumpBar->plug( settingsMenu ); |
2096 | mActionDetails->plug( settingsMenu ); | 2096 | mActionDetails->plug( settingsMenu ); |
2097 | //if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) | 2097 | //if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) |
2098 | mActionDetails->plug( tb ); | 2098 | mActionDetails->plug( tb ); |
2099 | settingsMenu->insertSeparator(); | 2099 | settingsMenu->insertSeparator(); |
2100 | mActionBR->plug(settingsMenu ); | 2100 | mActionBR->plug(settingsMenu ); |
2101 | settingsMenu->insertSeparator(); | 2101 | settingsMenu->insertSeparator(); |
2102 | 2102 | ||
2103 | mActionWhoAmI->plug( settingsMenu ); | 2103 | mActionWhoAmI->plug( settingsMenu ); |
2104 | mActionEditCategories->plug( settingsMenu ); | 2104 | mActionEditCategories->plug( settingsMenu ); |
2105 | mActionCategories->plug( settingsMenu ); | 2105 | mActionCategories->plug( settingsMenu ); |
2106 | mActionManageCategories->plug( settingsMenu ); | 2106 | mActionManageCategories->plug( settingsMenu ); |
2107 | 2107 | ||
2108 | 2108 | ||
2109 | mActionWN->plug( helpMenu ); | 2109 | mActionWN->plug( helpMenu ); |
2110 | mActionSyncHowto->plug( helpMenu ); | 2110 | mActionSyncHowto->plug( helpMenu ); |
2111 | mActionKdeSyncHowto->plug( helpMenu ); | 2111 | mActionKdeSyncHowto->plug( helpMenu ); |
2112 | mActionMultiSyncHowto->plug( helpMenu ); | 2112 | mActionMultiSyncHowto->plug( helpMenu ); |
2113 | mActionFaq->plug( helpMenu ); | 2113 | mActionFaq->plug( helpMenu ); |
2114 | mActionLicence->plug( helpMenu ); | 2114 | mActionLicence->plug( helpMenu ); |
2115 | mActionAboutKAddressbook->plug( helpMenu ); | 2115 | mActionAboutKAddressbook->plug( helpMenu ); |
2116 | 2116 | ||
2117 | if (KGlobal::getDesktopSize() > KGlobal::Small ) { | 2117 | if (KGlobal::getDesktopSize() > KGlobal::Small ) { |
2118 | 2118 | ||
2119 | mActionSave->plug( tb ); | 2119 | mActionSave->plug( tb ); |
2120 | mViewManager->getFilterAction()->plug ( tb); | 2120 | mViewManager->getFilterAction()->plug ( tb); |
2121 | if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { | 2121 | if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { |
2122 | mActionUndo->plug( tb ); | 2122 | mActionUndo->plug( tb ); |
2123 | mActionDelete->plug( tb ); | 2123 | mActionDelete->plug( tb ); |
2124 | mActionRedo->plug( tb ); | 2124 | mActionRedo->plug( tb ); |
2125 | } | 2125 | } |
2126 | } else { | 2126 | } else { |
2127 | mActionSave->plug( tb ); | 2127 | mActionSave->plug( tb ); |
2128 | tb->enableMoving(false); | 2128 | tb->enableMoving(false); |
2129 | } | 2129 | } |
2130 | //mActionQuit->plug ( tb ); | 2130 | //mActionQuit->plug ( tb ); |
2131 | // tb->insertWidget(-1, 0, mIncSearchWidget, 6); | 2131 | // tb->insertWidget(-1, 0, mIncSearchWidget, 6); |
2132 | 2132 | ||
2133 | //US link the searchwidget first to this. | 2133 | //US link the searchwidget first to this. |
2134 | // The real linkage to the toolbar happens later. | 2134 | // The real linkage to the toolbar happens later. |
2135 | //US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); | 2135 | //US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); |
2136 | //US tb->insertItem( mIncSearchWidget ); | 2136 | //US tb->insertItem( mIncSearchWidget ); |
2137 | /*US | 2137 | /*US |
2138 | mIncSearchWidget = new IncSearchWidget( tb ); | 2138 | mIncSearchWidget = new IncSearchWidget( tb ); |
2139 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), | 2139 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), |
2140 | SLOT( incrementalSearch( const QString& ) ) ); | 2140 | SLOT( incrementalSearch( const QString& ) ) ); |
2141 | 2141 | ||
2142 | mJumpButtonBar = new JumpButtonBar( this, this ); | 2142 | mJumpButtonBar = new JumpButtonBar( this, this ); |
2143 | 2143 | ||
2144 | //US topLayout->addWidget( mJumpButtonBar ); | 2144 | //US topLayout->addWidget( mJumpButtonBar ); |
2145 | this->layout()->add( mJumpButtonBar ); | 2145 | this->layout()->add( mJumpButtonBar ); |
2146 | */ | 2146 | */ |
2147 | 2147 | ||
2148 | #endif //KAB_EMBEDDED | 2148 | #endif //KAB_EMBEDDED |
2149 | 2149 | ||
2150 | mActionExport2phone->plug( ExportMenu ); | 2150 | mActionExport2phone->plug( ExportMenu ); |
2151 | connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); | 2151 | connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); |
2152 | syncManager->fillSyncMenu(); | 2152 | syncManager->fillSyncMenu(); |
2153 | 2153 | ||
2154 | } | 2154 | } |
2155 | void KABCore::showLicence() | 2155 | void KABCore::showLicence() |
2156 | { | 2156 | { |
2157 | KApplication::showLicence(); | 2157 | KApplication::showLicence(); |
2158 | } | 2158 | } |
2159 | 2159 | ||
2160 | void KABCore::manageCategories( ) | 2160 | void KABCore::manageCategories( ) |
2161 | { | 2161 | { |
2162 | KABCatPrefs* cp = new KABCatPrefs(); | 2162 | KABCatPrefs* cp = new KABCatPrefs(); |
2163 | cp->show(); | 2163 | cp->show(); |
2164 | int w =cp->sizeHint().width() ; | 2164 | int w =cp->sizeHint().width() ; |
2165 | int h = cp->sizeHint().height() ; | 2165 | int h = cp->sizeHint().height() ; |
2166 | int dw = QApplication::desktop()->width(); | 2166 | int dw = QApplication::desktop()->width(); |
2167 | int dh = QApplication::desktop()->height(); | 2167 | int dh = QApplication::desktop()->height(); |
2168 | cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2168 | cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2169 | if ( !cp->exec() ) { | 2169 | if ( !cp->exec() ) { |
2170 | delete cp; | 2170 | delete cp; |
2171 | return; | 2171 | return; |
2172 | } | 2172 | } |
2173 | int count = 0; | 2173 | int count = 0; |
2174 | message( i18n("Please wait, processing categories...")); | 2174 | message( i18n("Please wait, processing categories...")); |
2175 | if ( cp->addCat() ) { | 2175 | if ( cp->addCat() ) { |
2176 | KABC::AddressBook::Iterator it; | 2176 | KABC::AddressBook::Iterator it; |
2177 | QStringList catList = KABPrefs::instance()->mCustomCategories; | 2177 | QStringList catList = KABPrefs::instance()->mCustomCategories; |
2178 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { | 2178 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { |
2179 | QStringList catIncList = (*it).categories(); | 2179 | QStringList catIncList = (*it).categories(); |
2180 | int i; | 2180 | int i; |
2181 | for( i = 0; i< catIncList.count(); ++i ) { | 2181 | for( i = 0; i< catIncList.count(); ++i ) { |
2182 | if ( !catList.contains (catIncList[i])) { | 2182 | if ( !catList.contains (catIncList[i])) { |
2183 | catList.append( catIncList[i] ); | 2183 | catList.append( catIncList[i] ); |
2184 | //qDebug("add cat %s ", catIncList[i].latin1()); | 2184 | //qDebug("add cat %s ", catIncList[i].latin1()); |
2185 | ++count; | 2185 | ++count; |
2186 | } | 2186 | } |
2187 | } | 2187 | } |
2188 | } | 2188 | } |
2189 | catList.sort(); | 2189 | catList.sort(); |
2190 | KABPrefs::instance()->mCustomCategories = catList; | 2190 | KABPrefs::instance()->mCustomCategories = catList; |
2191 | KABPrefs::instance()->writeConfig(); | 2191 | KABPrefs::instance()->writeConfig(); |
2192 | message(QString::number( count )+ i18n(" categories added to list! ")); | 2192 | message(QString::number( count )+ i18n(" categories added to list! ")); |
2193 | } else { | 2193 | } else { |
2194 | QStringList catList = KABPrefs::instance()->mCustomCategories; | 2194 | QStringList catList = KABPrefs::instance()->mCustomCategories; |
2195 | QStringList catIncList; | 2195 | QStringList catIncList; |
2196 | QStringList newCatList; | 2196 | QStringList newCatList; |
2197 | KABC::AddressBook::Iterator it; | 2197 | KABC::AddressBook::Iterator it; |
2198 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { | 2198 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { |
2199 | QStringList catIncList = (*it).categories(); | 2199 | QStringList catIncList = (*it).categories(); |
2200 | int i; | 2200 | int i; |
2201 | if ( catIncList.count() ) { | 2201 | if ( catIncList.count() ) { |
2202 | newCatList.clear(); | 2202 | newCatList.clear(); |
2203 | for( i = 0; i< catIncList.count(); ++i ) { | 2203 | for( i = 0; i< catIncList.count(); ++i ) { |
2204 | if ( catList.contains (catIncList[i])) { | 2204 | if ( catList.contains (catIncList[i])) { |
2205 | newCatList.append( catIncList[i] ); | 2205 | newCatList.append( catIncList[i] ); |
2206 | } | 2206 | } |
2207 | } | 2207 | } |
2208 | newCatList.sort(); | 2208 | newCatList.sort(); |
2209 | (*it).setCategories( newCatList ); | 2209 | (*it).setCategories( newCatList ); |
2210 | mAddressBook->insertAddressee( (*it) ); | 2210 | mAddressBook->insertAddressee( (*it) ); |
2211 | } | 2211 | } |
2212 | } | 2212 | } |
2213 | setModified( true ); | 2213 | setModified( true ); |
2214 | mViewManager->refreshView(); | 2214 | mViewManager->refreshView(); |
2215 | mDetails->refreshView(); | 2215 | mDetails->refreshView(); |
2216 | message( i18n("Removing categories done!")); | 2216 | message( i18n("Removing categories done!")); |
2217 | } | 2217 | } |
2218 | delete cp; | 2218 | delete cp; |
2219 | } | 2219 | } |
2220 | void KABCore::removeVoice() | 2220 | void KABCore::removeVoice() |
2221 | { | 2221 | { |
2222 | if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) | 2222 | if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) |
2223 | return; | 2223 | return; |
2224 | KABC::Addressee::List list = mViewManager->selectedAddressees(); | 2224 | KABC::Addressee::List list = mViewManager->selectedAddressees(); |
2225 | KABC::Addressee::List::Iterator it; | 2225 | KABC::Addressee::List::Iterator it; |
2226 | for ( it = list.begin(); it != list.end(); ++it ) { | 2226 | for ( it = list.begin(); it != list.end(); ++it ) { |
2227 | 2227 | ||
2228 | if ( (*it).removeVoice() ) | 2228 | if ( (*it).removeVoice() ) |
2229 | contactModified((*it) ); | 2229 | contactModified((*it) ); |
2230 | } | 2230 | } |
2231 | } | 2231 | } |
2232 | 2232 | ||
2233 | 2233 | ||
2234 | 2234 | ||
2235 | void KABCore::clipboardDataChanged() | 2235 | void KABCore::clipboardDataChanged() |
2236 | { | 2236 | { |
2237 | 2237 | ||
2238 | if ( mReadWrite ) | 2238 | if ( mReadWrite ) |
2239 | mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); | 2239 | mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); |
2240 | 2240 | ||
2241 | } | 2241 | } |
2242 | 2242 | ||
2243 | void KABCore::updateActionMenu() | 2243 | void KABCore::updateActionMenu() |
2244 | { | 2244 | { |
2245 | UndoStack *undo = UndoStack::instance(); | 2245 | UndoStack *undo = UndoStack::instance(); |
2246 | RedoStack *redo = RedoStack::instance(); | 2246 | RedoStack *redo = RedoStack::instance(); |
2247 | 2247 | ||
2248 | if ( undo->isEmpty() ) | 2248 | if ( undo->isEmpty() ) |
2249 | mActionUndo->setText( i18n( "Undo" ) ); | 2249 | mActionUndo->setText( i18n( "Undo" ) ); |
2250 | else | 2250 | else |
2251 | mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); | 2251 | mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); |
2252 | 2252 | ||
2253 | mActionUndo->setEnabled( !undo->isEmpty() ); | 2253 | mActionUndo->setEnabled( !undo->isEmpty() ); |
2254 | 2254 | ||
2255 | if ( !redo->top() ) | 2255 | if ( !redo->top() ) |
2256 | mActionRedo->setText( i18n( "Redo" ) ); | 2256 | mActionRedo->setText( i18n( "Redo" ) ); |
2257 | else | 2257 | else |
2258 | mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); | 2258 | mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); |
2259 | 2259 | ||
2260 | mActionRedo->setEnabled( !redo->isEmpty() ); | 2260 | mActionRedo->setEnabled( !redo->isEmpty() ); |
2261 | } | 2261 | } |
2262 | 2262 | ||
2263 | void KABCore::configureKeyBindings() | 2263 | void KABCore::configureKeyBindings() |
2264 | { | 2264 | { |
2265 | #ifndef KAB_EMBEDDED | 2265 | #ifndef KAB_EMBEDDED |
2266 | KKeyDialog::configure( actionCollection(), true ); | 2266 | KKeyDialog::configure( actionCollection(), true ); |
2267 | #else //KAB_EMBEDDED | 2267 | #else //KAB_EMBEDDED |
2268 | qDebug("KABCore::configureKeyBindings() not implemented"); | 2268 | qDebug("KABCore::configureKeyBindings() not implemented"); |
2269 | #endif //KAB_EMBEDDED | 2269 | #endif //KAB_EMBEDDED |
2270 | } | 2270 | } |
2271 | 2271 | ||
2272 | #ifdef KAB_EMBEDDED | 2272 | #ifdef KAB_EMBEDDED |
2273 | void KABCore::configureResources() | 2273 | void KABCore::configureResources() |
2274 | { | 2274 | { |
2275 | KRES::KCMKResources dlg( this, "" , 0 ); | 2275 | KRES::KCMKResources dlg( this, "" , 0 ); |
2276 | 2276 | ||
2277 | if ( !dlg.exec() ) | 2277 | if ( !dlg.exec() ) |
2278 | return; | 2278 | return; |
2279 | KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); | 2279 | KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); |
2280 | } | 2280 | } |
2281 | #endif //KAB_EMBEDDED | 2281 | #endif //KAB_EMBEDDED |
2282 | 2282 | ||
2283 | 2283 | ||
2284 | /* this method will be called through the QCop interface from Ko/Pi to select addresses | 2284 | /* this method will be called through the QCop interface from Ko/Pi to select addresses |
2285 | * for the attendees list of an event. | 2285 | * for the attendees list of an event. |
2286 | */ | 2286 | */ |
2287 | void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) | 2287 | void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) |
2288 | { | 2288 | { |
2289 | QStringList nameList; | 2289 | QStringList nameList; |
2290 | QStringList emailList; | 2290 | QStringList emailList; |
2291 | QStringList uidList; | 2291 | QStringList uidList; |
2292 | 2292 | ||
2293 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); | 2293 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); |
2294 | uint i=0; | 2294 | uint i=0; |
2295 | for (i=0; i < list.count(); i++) | 2295 | for (i=0; i < list.count(); i++) |
2296 | { | 2296 | { |
2297 | nameList.append(list[i].realName()); | 2297 | nameList.append(list[i].realName()); |
2298 | emailList.append(list[i].preferredEmail()); | 2298 | emailList.append(list[i].preferredEmail()); |
2299 | uidList.append(list[i].uid()); | 2299 | uidList.append(list[i].uid()); |
2300 | } | 2300 | } |
2301 | 2301 | ||
2302 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); | 2302 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); |
2303 | 2303 | ||
2304 | } | 2304 | } |
2305 | 2305 | ||
2306 | /* this method will be called through the QCop interface from Ko/Pi to select birthdays | 2306 | /* this method will be called through the QCop interface from Ko/Pi to select birthdays |
2307 | * to put them into the calendar. | 2307 | * to put them into the calendar. |
2308 | */ | 2308 | */ |
2309 | void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid) | 2309 | void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid) |
2310 | { | 2310 | { |
2311 | // qDebug("KABCore::requestForBirthdayList"); | 2311 | // qDebug("KABCore::requestForBirthdayList"); |
2312 | QStringList birthdayList; | 2312 | QStringList birthdayList; |
2313 | QStringList anniversaryList; | 2313 | QStringList anniversaryList; |
2314 | QStringList realNameList; | 2314 | QStringList realNameList; |
2315 | QStringList preferredEmailList; | 2315 | QStringList preferredEmailList; |
2316 | QStringList assembledNameList; | 2316 | QStringList assembledNameList; |
2317 | QStringList uidList; | 2317 | QStringList uidList; |
2318 | 2318 | ||
2319 | KABC::AddressBook::Iterator it; | 2319 | KABC::AddressBook::Iterator it; |
2320 | 2320 | ||
2321 | int count = 0; | 2321 | int count = 0; |
2322 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { | 2322 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { |
2323 | ++count; | 2323 | ++count; |
2324 | } | 2324 | } |
2325 | QProgressBar bar(count,0 ); | 2325 | QProgressBar bar(count,0 ); |
2326 | int w = 300; | 2326 | int w = 300; |
2327 | if ( QApplication::desktop()->width() < 320 ) | 2327 | if ( QApplication::desktop()->width() < 320 ) |
2328 | w = 220; | 2328 | w = 220; |
2329 | int h = bar.sizeHint().height() ; | 2329 | int h = bar.sizeHint().height() ; |
2330 | int dw = QApplication::desktop()->width(); | 2330 | int dw = QApplication::desktop()->width(); |
2331 | int dh = QApplication::desktop()->height(); | 2331 | int dh = QApplication::desktop()->height(); |
2332 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2332 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2333 | bar.show(); | 2333 | bar.show(); |
2334 | bar.setCaption (i18n("Collecting birthdays - close to abort!") ); | 2334 | bar.setCaption (i18n("Collecting birthdays - close to abort!") ); |
2335 | qApp->processEvents(); | 2335 | qApp->processEvents(); |
2336 | 2336 | ||
2337 | QDate bday; | 2337 | QDate bday; |
2338 | QString anni; | 2338 | QString anni; |
2339 | QString formattedbday; | 2339 | QString formattedbday; |
2340 | 2340 | ||
2341 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) | 2341 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) |
2342 | { | 2342 | { |
2343 | if ( ! bar.isVisible() ) | 2343 | if ( ! bar.isVisible() ) |
2344 | return; | 2344 | return; |
2345 | bar.setProgress( count++ ); | 2345 | bar.setProgress( count++ ); |
2346 | qApp->processEvents(); | 2346 | qApp->processEvents(); |
2347 | bday = (*it).birthday().date(); | 2347 | bday = (*it).birthday().date(); |
2348 | anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" ); | 2348 | anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" ); |
2349 | 2349 | ||
2350 | if ( bday.isValid() || !anni.isEmpty()) | 2350 | if ( bday.isValid() || !anni.isEmpty()) |
2351 | { | 2351 | { |
2352 | if (bday.isValid()) | 2352 | if (bday.isValid()) |
2353 | formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate); | 2353 | formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate); |
2354 | else | 2354 | else |
2355 | formattedbday = "NOTVALID"; | 2355 | formattedbday = "NOTVALID"; |
2356 | if (anni.isEmpty()) | 2356 | if (anni.isEmpty()) |
2357 | anni = "INVALID"; | 2357 | anni = "INVALID"; |
2358 | 2358 | ||
2359 | birthdayList.append(formattedbday); | 2359 | birthdayList.append(formattedbday); |
2360 | anniversaryList.append(anni); //should be ISODate | 2360 | anniversaryList.append(anni); //should be ISODate |
2361 | realNameList.append((*it).realName()); | 2361 | realNameList.append((*it).realName()); |
2362 | preferredEmailList.append((*it).preferredEmail()); | 2362 | preferredEmailList.append((*it).preferredEmail()); |
2363 | assembledNameList.append((*it).assembledName()); | 2363 | assembledNameList.append((*it).assembledName()); |
2364 | uidList.append((*it).uid()); | 2364 | uidList.append((*it).uid()); |
2365 | 2365 | ||
2366 | //qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() ); | 2366 | //qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() ); |
2367 | } | 2367 | } |
2368 | } | 2368 | } |
2369 | 2369 | ||
2370 | bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList); | 2370 | bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList); |
2371 | 2371 | ||
2372 | } | 2372 | } |
2373 | 2373 | ||
2374 | /* this method will be called through the QCop interface from other apps to show details of a contact. | 2374 | /* this method will be called through the QCop interface from other apps to show details of a contact. |
2375 | */ | 2375 | */ |
2376 | void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) | 2376 | void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) |
2377 | { | 2377 | { |
2378 | //qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); | 2378 | //qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); |
2379 | 2379 | ||
2380 | QString foundUid = QString::null; | 2380 | QString foundUid = QString::null; |
2381 | if ( ! uid.isEmpty() ) { | 2381 | if ( ! uid.isEmpty() ) { |
2382 | Addressee adrr = mAddressBook->findByUid( uid ); | 2382 | Addressee adrr = mAddressBook->findByUid( uid ); |
2383 | if ( !adrr.isEmpty() ) { | 2383 | if ( !adrr.isEmpty() ) { |
2384 | foundUid = uid; | 2384 | foundUid = uid; |
2385 | } | 2385 | } |
2386 | if ( email == "sendbacklist" ) { | 2386 | if ( email == "sendbacklist" ) { |
2387 | //qDebug("ssssssssssssssssssssssend "); | 2387 | //qDebug("ssssssssssssssssssssssend "); |
2388 | QStringList nameList; | 2388 | QStringList nameList; |
2389 | QStringList emailList; | 2389 | QStringList emailList; |
2390 | QStringList uidList; | 2390 | QStringList uidList; |
2391 | nameList.append(adrr.realName()); | 2391 | nameList.append(adrr.realName()); |
2392 | emailList = adrr.emails(); | 2392 | emailList = adrr.emails(); |
2393 | uidList.append( adrr.preferredEmail()); | 2393 | uidList.append( adrr.preferredEmail()); |
2394 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); | 2394 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); |
2395 | return; | 2395 | return; |
2396 | } | 2396 | } |
2397 | 2397 | ||
2398 | } | 2398 | } |
2399 | 2399 | ||
2400 | if ( email == "sendbacklist" ) | 2400 | if ( email == "sendbacklist" ) |
2401 | return; | 2401 | return; |
2402 | if (foundUid.isEmpty()) | 2402 | if (foundUid.isEmpty()) |
2403 | { | 2403 | { |
2404 | //find the uid of the person first | 2404 | //find the uid of the person first |
2405 | Addressee::List namelist; | 2405 | Addressee::List namelist; |
2406 | Addressee::List emaillist; | 2406 | Addressee::List emaillist; |
2407 | 2407 | ||
2408 | if (!name.isEmpty()) | 2408 | if (!name.isEmpty()) |
2409 | namelist = mAddressBook->findByName( name ); | 2409 | namelist = mAddressBook->findByName( name ); |
2410 | 2410 | ||
2411 | if (!email.isEmpty()) | 2411 | if (!email.isEmpty()) |
2412 | emaillist = mAddressBook->findByEmail( email ); | 2412 | emaillist = mAddressBook->findByEmail( email ); |
2413 | //qDebug("count %d %d ", namelist.count(),emaillist.count() ); | 2413 | //qDebug("count %d %d ", namelist.count(),emaillist.count() ); |
2414 | //check if we have a match in Namelist and Emaillist | 2414 | //check if we have a match in Namelist and Emaillist |
2415 | if ((namelist.count() == 0) && (emaillist.count() > 0)) { | 2415 | if ((namelist.count() == 0) && (emaillist.count() > 0)) { |
2416 | foundUid = emaillist[0].uid(); | 2416 | foundUid = emaillist[0].uid(); |
2417 | } | 2417 | } |
2418 | else if ((namelist.count() > 0) && (emaillist.count() == 0)) | 2418 | else if ((namelist.count() > 0) && (emaillist.count() == 0)) |
2419 | foundUid = namelist[0].uid(); | 2419 | foundUid = namelist[0].uid(); |
2420 | else | 2420 | else |
2421 | { | 2421 | { |
2422 | for (int i = 0; i < namelist.count(); i++) | 2422 | for (int i = 0; i < namelist.count(); i++) |
2423 | { | 2423 | { |
2424 | for (int j = 0; j < emaillist.count(); j++) | 2424 | for (int j = 0; j < emaillist.count(); j++) |
2425 | { | 2425 | { |
2426 | if (namelist[i] == emaillist[j]) | 2426 | if (namelist[i] == emaillist[j]) |
2427 | { | 2427 | { |
2428 | foundUid = namelist[i].uid(); | 2428 | foundUid = namelist[i].uid(); |
2429 | } | 2429 | } |
2430 | } | 2430 | } |
2431 | } | 2431 | } |
2432 | } | 2432 | } |
2433 | } | 2433 | } |
2434 | else | 2434 | else |
2435 | { | 2435 | { |
2436 | foundUid = uid; | 2436 | foundUid = uid; |
2437 | } | 2437 | } |
2438 | 2438 | ||
2439 | if (!foundUid.isEmpty()) | 2439 | if (!foundUid.isEmpty()) |
2440 | { | 2440 | { |
2441 | 2441 | ||
2442 | // raise Ka/Pi if it is in the background | 2442 | // raise Ka/Pi if it is in the background |
2443 | #ifndef DESKTOP_VERSION | 2443 | #ifndef DESKTOP_VERSION |
2444 | #ifndef KORG_NODCOP | 2444 | #ifndef KORG_NODCOP |
2445 | //QCopEnvelope e("QPE/Application/kapi", "raise()"); | 2445 | //QCopEnvelope e("QPE/Application/kapi", "raise()"); |
2446 | #endif | 2446 | #endif |
2447 | #endif | 2447 | #endif |
2448 | 2448 | ||
2449 | mMainWindow->showMaximized(); | 2449 | mMainWindow->showMaximized(); |
2450 | mMainWindow-> raise(); | 2450 | mMainWindow-> raise(); |
2451 | 2451 | ||
2452 | mViewManager->setSelected( "", false); | 2452 | mViewManager->setSelected( "", false); |
2453 | mViewManager->refreshView( "" ); | 2453 | mViewManager->refreshView( "" ); |
2454 | mViewManager->setSelected( foundUid, true ); | 2454 | mViewManager->setSelected( foundUid, true ); |
2455 | mViewManager->refreshView( foundUid ); | 2455 | mViewManager->refreshView( foundUid ); |
2456 | 2456 | ||
2457 | if ( !mMultipleViewsAtOnce ) | 2457 | if ( !mMultipleViewsAtOnce ) |
2458 | { | 2458 | { |
2459 | setDetailsVisible( true ); | 2459 | setDetailsVisible( true ); |
2460 | mActionDetails->setChecked(true); | 2460 | mActionDetails->setChecked(true); |
2461 | } | 2461 | } |
2462 | } | 2462 | } |
2463 | } | 2463 | } |
2464 | 2464 | ||
2465 | void KABCore::whatsnew() | 2465 | void KABCore::whatsnew() |
2466 | { | 2466 | { |
2467 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); | 2467 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); |
2468 | } | 2468 | } |
2469 | void KABCore::synchowto() | 2469 | void KABCore::synchowto() |
2470 | { | 2470 | { |
2471 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); | 2471 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); |
2472 | } | 2472 | } |
2473 | void KABCore::kdesynchowto() | 2473 | void KABCore::kdesynchowto() |
2474 | { | 2474 | { |
2475 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/Zaurus-KDE_syncHowTo.txt" ); | 2475 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/Zaurus-KDE_syncHowTo.txt" ); |
2476 | } | 2476 | } |
2477 | void KABCore::multisynchowto() | 2477 | void KABCore::multisynchowto() |
2478 | { | 2478 | { |
2479 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/MultiSyncHowTo.txt" ); | 2479 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/MultiSyncHowTo.txt" ); |
2480 | } | 2480 | } |
2481 | void KABCore::faq() | 2481 | void KABCore::faq() |
2482 | { | 2482 | { |
2483 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); | 2483 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); |
2484 | } | 2484 | } |
2485 | 2485 | ||
2486 | #include <libkcal/syncdefines.h> | 2486 | #include <libkcal/syncdefines.h> |
2487 | 2487 | ||
2488 | KABC::Addressee KABCore::getLastSyncAddressee() | 2488 | KABC::Addressee KABCore::getLastSyncAddressee() |
2489 | { | 2489 | { |
2490 | Addressee lse; | 2490 | Addressee lse; |
2491 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2491 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2492 | 2492 | ||
2493 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 2493 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
2494 | lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2494 | lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2495 | if (lse.isEmpty()) { | 2495 | if (lse.isEmpty()) { |
2496 | qDebug("Creating new last-syncAddressee "); | 2496 | qDebug("Creating new last-syncAddressee "); |
2497 | lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2497 | lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2498 | QString sum = ""; | 2498 | QString sum = ""; |
2499 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 2499 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
2500 | sum = "E: "; | 2500 | sum = "E: "; |
2501 | lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); | 2501 | lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); |
2502 | lse.setRevision( mLastAddressbookSync ); | 2502 | lse.setRevision( mLastAddressbookSync ); |
2503 | lse.setCategories( i18n("SyncEvent") ); | 2503 | lse.setCategories( i18n("SyncEvent") ); |
2504 | mAddressBook->insertAddressee( lse ); | 2504 | mAddressBook->insertAddressee( lse ); |
2505 | } | 2505 | } |
2506 | return lse; | 2506 | return lse; |
2507 | } | 2507 | } |
2508 | int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) | 2508 | int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) |
2509 | { | 2509 | { |
2510 | 2510 | ||
2511 | //void setZaurusId(int id); | 2511 | //void setZaurusId(int id); |
2512 | // int zaurusId() const; | 2512 | // int zaurusId() const; |
2513 | // void setZaurusUid(int id); | 2513 | // void setZaurusUid(int id); |
2514 | // int zaurusUid() const; | 2514 | // int zaurusUid() const; |
2515 | // void setZaurusStat(int id); | 2515 | // void setZaurusStat(int id); |
2516 | // int zaurusStat() const; | 2516 | // int zaurusStat() const; |
2517 | // 0 equal | 2517 | // 0 equal |
2518 | // 1 take local | 2518 | // 1 take local |
2519 | // 2 take remote | 2519 | // 2 take remote |
2520 | // 3 cancel | 2520 | // 3 cancel |
2521 | QDateTime lastSync = mLastAddressbookSync; | 2521 | QDateTime lastSync = mLastAddressbookSync; |
2522 | QDateTime localMod = local->revision(); | 2522 | QDateTime localMod = local->revision(); |
2523 | QDateTime remoteMod = remote->revision(); | 2523 | QDateTime remoteMod = remote->revision(); |
2524 | 2524 | ||
2525 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2525 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2526 | 2526 | ||
2527 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2527 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2528 | bool remCh, locCh; | 2528 | bool remCh, locCh; |
2529 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 2529 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
2530 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); | 2530 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); |
2531 | locCh = ( localMod > mLastAddressbookSync ); | 2531 | locCh = ( localMod > mLastAddressbookSync ); |
2532 | if ( !remCh && ! locCh ) { | 2532 | if ( !remCh && ! locCh ) { |
2533 | //qDebug("both not changed "); | 2533 | //qDebug("both not changed "); |
2534 | lastSync = localMod.addDays(1); | 2534 | lastSync = localMod.addDays(1); |
2535 | if ( mode <= SYNC_PREF_ASK ) | 2535 | if ( mode <= SYNC_PREF_ASK ) |
2536 | return 0; | 2536 | return 0; |
2537 | } else { | 2537 | } else { |
2538 | if ( locCh ) { | 2538 | if ( locCh ) { |
2539 | //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); | 2539 | //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); |
2540 | lastSync = localMod.addDays( -1 ); | 2540 | lastSync = localMod.addDays( -1 ); |
2541 | if ( !remCh ) | 2541 | if ( !remCh ) |
2542 | remoteMod =( lastSync.addDays( -1 ) ); | 2542 | remoteMod =( lastSync.addDays( -1 ) ); |
2543 | } else { | 2543 | } else { |
2544 | //qDebug(" not loc changed "); | 2544 | //qDebug(" not loc changed "); |
2545 | lastSync = localMod.addDays( 1 ); | 2545 | lastSync = localMod.addDays( 1 ); |
2546 | if ( remCh ) { | 2546 | if ( remCh ) { |
2547 | //qDebug("rem changed "); | 2547 | //qDebug("rem changed "); |
2548 | remoteMod =( lastSync.addDays( 1 ) ); | 2548 | remoteMod =( lastSync.addDays( 1 ) ); |
2549 | } | 2549 | } |
2550 | 2550 | ||
2551 | } | 2551 | } |
2552 | } | 2552 | } |
2553 | full = true; | 2553 | full = true; |
2554 | if ( mode < SYNC_PREF_ASK ) | 2554 | if ( mode < SYNC_PREF_ASK ) |
2555 | mode = SYNC_PREF_ASK; | 2555 | mode = SYNC_PREF_ASK; |
2556 | } else { | 2556 | } else { |
2557 | if ( localMod == remoteMod ) | 2557 | if ( localMod == remoteMod ) |
2558 | return 0; | 2558 | return 0; |
2559 | 2559 | ||
2560 | } | 2560 | } |
2561 | //qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec()); | 2561 | //qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec()); |
2562 | //qDebug("lastsync %s ", lastSync.toString().latin1() ); | 2562 | //qDebug("lastsync %s ", lastSync.toString().latin1() ); |
2563 | //full = true; //debug only | 2563 | //full = true; //debug only |
2564 | if ( full ) { | 2564 | if ( full ) { |
2565 | bool equ = ( (*local) == (*remote) ); | 2565 | bool equ = ( (*local) == (*remote) ); |
2566 | if ( equ ) { | 2566 | if ( equ ) { |
2567 | //qDebug("equal "); | 2567 | //qDebug("equal "); |
2568 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2568 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2569 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 2569 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
2570 | } | 2570 | } |
2571 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 2571 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
2572 | return 0; | 2572 | return 0; |
2573 | 2573 | ||
2574 | }//else //debug only | 2574 | }//else //debug only |
2575 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 2575 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
2576 | } | 2576 | } |
2577 | int result; | 2577 | int result; |
2578 | bool localIsNew; | 2578 | bool localIsNew; |
2579 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); | 2579 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); |
2580 | 2580 | ||
2581 | if ( full && mode < SYNC_PREF_NEWEST ) | 2581 | if ( full && mode < SYNC_PREF_NEWEST ) |
2582 | mode = SYNC_PREF_ASK; | 2582 | mode = SYNC_PREF_ASK; |
2583 | 2583 | ||
2584 | switch( mode ) { | 2584 | switch( mode ) { |
2585 | case SYNC_PREF_LOCAL: | 2585 | case SYNC_PREF_LOCAL: |
2586 | if ( lastSync > remoteMod ) | 2586 | if ( lastSync > remoteMod ) |
2587 | return 1; | 2587 | return 1; |
2588 | if ( lastSync > localMod ) | 2588 | if ( lastSync > localMod ) |
2589 | return 2; | 2589 | return 2; |
2590 | return 1; | 2590 | return 1; |
2591 | break; | 2591 | break; |
2592 | case SYNC_PREF_REMOTE: | 2592 | case SYNC_PREF_REMOTE: |
2593 | if ( lastSync > remoteMod ) | 2593 | if ( lastSync > remoteMod ) |
2594 | return 1; | 2594 | return 1; |
2595 | if ( lastSync > localMod ) | 2595 | if ( lastSync > localMod ) |
2596 | return 2; | 2596 | return 2; |
2597 | return 2; | 2597 | return 2; |
2598 | break; | 2598 | break; |
2599 | case SYNC_PREF_NEWEST: | 2599 | case SYNC_PREF_NEWEST: |
2600 | if ( localMod > remoteMod ) | 2600 | if ( localMod > remoteMod ) |
2601 | return 1; | 2601 | return 1; |
2602 | else | 2602 | else |
2603 | return 2; | 2603 | return 2; |
2604 | break; | 2604 | break; |
2605 | case SYNC_PREF_ASK: | 2605 | case SYNC_PREF_ASK: |
2606 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 2606 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
2607 | if ( lastSync > remoteMod ) | 2607 | if ( lastSync > remoteMod ) |
2608 | return 1; | 2608 | return 1; |
2609 | if ( lastSync > localMod ) | 2609 | if ( lastSync > localMod ) |
2610 | return 2; | 2610 | return 2; |
2611 | localIsNew = localMod >= remoteMod; | 2611 | localIsNew = localMod >= remoteMod; |
2612 | //qDebug("conflict! ************************************** "); | 2612 | //qDebug("conflict! ************************************** "); |
2613 | { | 2613 | { |
2614 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); | 2614 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); |
2615 | result = acd.executeD(localIsNew); | 2615 | result = acd.executeD(localIsNew); |
2616 | return result; | 2616 | return result; |
2617 | } | 2617 | } |
2618 | break; | 2618 | break; |
2619 | case SYNC_PREF_FORCE_LOCAL: | 2619 | case SYNC_PREF_FORCE_LOCAL: |
2620 | return 1; | 2620 | return 1; |
2621 | break; | 2621 | break; |
2622 | case SYNC_PREF_FORCE_REMOTE: | 2622 | case SYNC_PREF_FORCE_REMOTE: |
2623 | return 2; | 2623 | return 2; |
2624 | break; | 2624 | break; |
2625 | 2625 | ||
2626 | default: | 2626 | default: |
2627 | // SYNC_PREF_TAKE_BOTH not implemented | 2627 | // SYNC_PREF_TAKE_BOTH not implemented |
2628 | break; | 2628 | break; |
2629 | } | 2629 | } |
2630 | return 0; | 2630 | return 0; |
2631 | } | 2631 | } |
2632 | 2632 | ||
2633 | 2633 | ||
2634 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) | 2634 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) |
2635 | { | 2635 | { |
2636 | bool syncOK = true; | 2636 | bool syncOK = true; |
2637 | int addedAddressee = 0; | 2637 | int addedAddressee = 0; |
2638 | int addedAddresseeR = 0; | 2638 | int addedAddresseeR = 0; |
2639 | int deletedAddresseeR = 0; | 2639 | int deletedAddresseeR = 0; |
2640 | int deletedAddresseeL = 0; | 2640 | int deletedAddresseeL = 0; |
2641 | int changedLocal = 0; | 2641 | int changedLocal = 0; |
2642 | int changedRemote = 0; | 2642 | int changedRemote = 0; |
2643 | 2643 | ||
2644 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); | 2644 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); |
2645 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2645 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2646 | 2646 | ||
2647 | //QPtrList<Addressee> el = local->rawAddressees(); | 2647 | //QPtrList<Addressee> el = local->rawAddressees(); |
2648 | Addressee addresseeR; | 2648 | Addressee addresseeR; |
2649 | QString uid; | 2649 | QString uid; |
2650 | int take; | 2650 | int take; |
2651 | Addressee addresseeL; | 2651 | Addressee addresseeL; |
2652 | Addressee addresseeRSync; | 2652 | Addressee addresseeRSync; |
2653 | Addressee addresseeLSync; | 2653 | Addressee addresseeLSync; |
2654 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); | 2654 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); |
2655 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); | 2655 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); |
2656 | bool fullDateRange = false; | 2656 | bool fullDateRange = false; |
2657 | local->resetTempSyncStat(); | 2657 | local->resetTempSyncStat(); |
2658 | mLastAddressbookSync = QDateTime::currentDateTime(); | 2658 | mLastAddressbookSync = QDateTime::currentDateTime(); |
2659 | if ( syncManager->syncWithDesktop() ) { | 2659 | if ( syncManager->syncWithDesktop() ) { |
2660 | // remote->removeSyncInfo( QString());//remove all info | 2660 | // remote->removeSyncInfo( QString());//remove all info |
2661 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 2661 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
2662 | mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; | 2662 | mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; |
2663 | qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); | 2663 | qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); |
2664 | } else { | 2664 | } else { |
2665 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); | 2665 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); |
2666 | } | 2666 | } |
2667 | } | 2667 | } |
2668 | QDateTime modifiedCalendar = mLastAddressbookSync; | 2668 | QDateTime modifiedCalendar = mLastAddressbookSync; |
2669 | addresseeLSync = getLastSyncAddressee(); | 2669 | addresseeLSync = getLastSyncAddressee(); |
2670 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); | 2670 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); |
2671 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); | 2671 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); |
2672 | if ( !addresseeR.isEmpty() ) { | 2672 | if ( !addresseeR.isEmpty() ) { |
2673 | addresseeRSync = addresseeR; | 2673 | addresseeRSync = addresseeR; |
2674 | remote->removeAddressee(addresseeR ); | 2674 | remote->removeAddressee(addresseeR ); |
2675 | 2675 | ||
2676 | } else { | 2676 | } else { |
2677 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2677 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2678 | addresseeRSync = addresseeLSync ; | 2678 | addresseeRSync = addresseeLSync ; |
2679 | } else { | 2679 | } else { |
2680 | //qDebug("FULLDATE 1"); | 2680 | //qDebug("FULLDATE 1"); |
2681 | fullDateRange = true; | 2681 | fullDateRange = true; |
2682 | Addressee newAdd; | 2682 | Addressee newAdd; |
2683 | addresseeRSync = newAdd; | 2683 | addresseeRSync = newAdd; |
2684 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); | 2684 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); |
2685 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); | 2685 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); |
2686 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2686 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2687 | addresseeRSync.setCategories( i18n("SyncAddressee") ); | 2687 | addresseeRSync.setCategories( i18n("SyncAddressee") ); |
2688 | } | 2688 | } |
2689 | } | 2689 | } |
2690 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { | 2690 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { |
2691 | // qDebug("FULLDATE 2"); | 2691 | // qDebug("FULLDATE 2"); |
2692 | fullDateRange = true; | 2692 | fullDateRange = true; |
2693 | } | 2693 | } |
2694 | if ( ! fullDateRange ) { | 2694 | if ( ! fullDateRange ) { |
2695 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { | 2695 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { |
2696 | 2696 | ||
2697 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | 2697 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); |
2698 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | 2698 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); |
2699 | fullDateRange = true; | 2699 | fullDateRange = true; |
2700 | //qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); | 2700 | //qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); |
2701 | } | 2701 | } |
2702 | } | 2702 | } |
2703 | // fullDateRange = true; // debug only! | 2703 | // fullDateRange = true; // debug only! |
2704 | if ( fullDateRange ) | 2704 | if ( fullDateRange ) |
2705 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); | 2705 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); |
2706 | else | 2706 | else |
2707 | mLastAddressbookSync = addresseeLSync.revision(); | 2707 | mLastAddressbookSync = addresseeLSync.revision(); |
2708 | // for resyncing if own file has changed | 2708 | // for resyncing if own file has changed |
2709 | // PENDING fixme later when implemented | 2709 | // PENDING fixme later when implemented |
2710 | #if 0 | 2710 | #if 0 |
2711 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 2711 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
2712 | mLastAddressbookSync = loadedFileVersion; | 2712 | mLastAddressbookSync = loadedFileVersion; |
2713 | qDebug("setting mLastAddressbookSync "); | 2713 | qDebug("setting mLastAddressbookSync "); |
2714 | } | 2714 | } |
2715 | #endif | 2715 | #endif |
2716 | 2716 | ||
2717 | //qDebug("*************************** "); | 2717 | //qDebug("*************************** "); |
2718 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | 2718 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); |
2719 | QStringList er = remote->uidList(); | 2719 | QStringList er = remote->uidList(); |
2720 | Addressee inR ;//= er.first(); | 2720 | Addressee inR ;//= er.first(); |
2721 | Addressee inL; | 2721 | Addressee inL; |
2722 | 2722 | ||
2723 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); | 2723 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); |
2724 | 2724 | ||
2725 | int modulo = (er.count()/10)+1; | 2725 | int modulo = (er.count()/10)+1; |
2726 | int incCounter = 0; | 2726 | int incCounter = 0; |
2727 | while ( incCounter < er.count()) { | 2727 | while ( incCounter < er.count()) { |
2728 | if (syncManager->isProgressBarCanceled()) | 2728 | if (syncManager->isProgressBarCanceled()) |
2729 | return false; | 2729 | return false; |
2730 | if ( incCounter % modulo == 0 ) | 2730 | if ( incCounter % modulo == 0 ) |
2731 | syncManager->showProgressBar(incCounter); | 2731 | syncManager->showProgressBar(incCounter); |
2732 | 2732 | ||
2733 | uid = er[ incCounter ]; | 2733 | uid = er[ incCounter ]; |
2734 | bool skipIncidence = false; | 2734 | bool skipIncidence = false; |
2735 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2735 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2736 | skipIncidence = true; | 2736 | skipIncidence = true; |
2737 | QString idS,OidS; | 2737 | QString idS,OidS; |
2738 | qApp->processEvents(); | 2738 | qApp->processEvents(); |
2739 | if ( !skipIncidence ) { | 2739 | if ( !skipIncidence ) { |
2740 | inL = local->findByUid( uid ); | 2740 | inL = local->findByUid( uid ); |
2741 | inR = remote->findByUid( uid ); | 2741 | inR = remote->findByUid( uid ); |
2742 | //inL.setResource( 0 ); | 2742 | //inL.setResource( 0 ); |
2743 | //inR.setResource( 0 ); | 2743 | //inR.setResource( 0 ); |
2744 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars | 2744 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars |
2745 | if ( !inL.resource() || inL.resource()->includeInSync() ) { | 2745 | if ( !inL.resource() || inL.resource()->includeInSync() ) { |
2746 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { | 2746 | if ( (take = takeAddressee( &inL, &inR, mode, fullDateRange )) ) { |
2747 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 2747 | //qDebug("take %d %s ", take, inL.summary().latin1()); |
2748 | if ( take == 3 ) | 2748 | if ( take == 3 ) |
2749 | return false; | 2749 | return false; |
2750 | if ( take == 1 ) {// take local ********************** | 2750 | if ( take == 1 ) {// take local ********************** |
2751 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2751 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2752 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2752 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2753 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2753 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2754 | local->insertAddressee( inL, false ); | 2754 | local->insertAddressee( inL, false ); |
2755 | idS = inR.externalUID(); | 2755 | idS = inR.externalUID(); |
2756 | OidS = inR.originalExternalUID(); | 2756 | OidS = inR.originalExternalUID(); |
2757 | } | 2757 | } |
2758 | else | 2758 | else |
2759 | idS = inR.IDStr(); | 2759 | idS = inR.IDStr(); |
2760 | remote->removeAddressee( inR ); | 2760 | remote->removeAddressee( inR ); |
2761 | inR = inL; | 2761 | inR = inL; |
2762 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 2762 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
2763 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2763 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2764 | inR.setOriginalExternalUID( OidS ); | 2764 | inR.setOriginalExternalUID( OidS ); |
2765 | inR.setExternalUID( idS ); | 2765 | inR.setExternalUID( idS ); |
2766 | if ( syncManager->syncWithDesktop() ) { | 2766 | if ( syncManager->syncWithDesktop() ) { |
2767 | inR.setIDStr("changed" ); | 2767 | inR.setIDStr("changed" ); |
2768 | } | 2768 | } |
2769 | //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" ); | 2769 | //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" ); |
2770 | } else { | 2770 | } else { |
2771 | inR.setIDStr( idS ); | 2771 | inR.setIDStr( idS ); |
2772 | } | 2772 | } |
2773 | inR.setResource( 0 ); | 2773 | inR.setResource( 0 ); |
2774 | remote->insertAddressee( inR , false); | 2774 | remote->insertAddressee( inR , false); |
2775 | ++changedRemote; | 2775 | ++changedRemote; |
2776 | } else { // take == 2 take remote ********************** | 2776 | } else { // take == 2 take remote ********************** |
2777 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2777 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2778 | if ( inR.revision().date().year() < 2004 ) | 2778 | if ( inR.revision().date().year() < 2004 ) |
2779 | inR.setRevision( modifiedCalendar ); | 2779 | inR.setRevision( modifiedCalendar ); |
2780 | } | 2780 | } |
2781 | idS = inL.IDStr(); | 2781 | idS = inL.IDStr(); |
2782 | local->removeAddressee( inL ); | 2782 | local->removeAddressee( inL ); |
2783 | inL = inR; | 2783 | inL = inR; |
2784 | inL.setIDStr( idS ); | 2784 | inL.setIDStr( idS ); |
2785 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2785 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2786 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2786 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2787 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2787 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2788 | } | 2788 | } |
2789 | inL.setResource( 0 ); | 2789 | inL.setResource( 0 ); |
2790 | local->insertAddressee( inL , false ); | 2790 | local->insertAddressee( inL , false ); |
2791 | ++changedLocal; | 2791 | ++changedLocal; |
2792 | } | 2792 | } |
2793 | } | 2793 | } |
2794 | } | 2794 | } |
2795 | } else { // no conflict ********** add or delete remote | 2795 | } else { // no conflict ********** add or delete remote |
2796 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2796 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2797 | QString des = addresseeLSync.note(); | 2797 | QString des = addresseeLSync.note(); |
2798 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 2798 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
2799 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 2799 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
2800 | remote->insertAddressee( inR, false ); | 2800 | remote->insertAddressee( inR, false ); |
2801 | ++deletedAddresseeR; | 2801 | ++deletedAddresseeR; |
2802 | } else { | 2802 | } else { |
2803 | inR.setRevision( modifiedCalendar ); | 2803 | inR.setRevision( modifiedCalendar ); |
2804 | remote->insertAddressee( inR, false ); | 2804 | remote->insertAddressee( inR, false ); |
2805 | inL = inR; | 2805 | inL = inR; |
2806 | inL.setIDStr( ":" ); | 2806 | inL.setIDStr( ":" ); |
2807 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2807 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2808 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2808 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2809 | inL.setResource( 0 ); | 2809 | inL.setResource( 0 ); |
2810 | local->insertAddressee( inL , false); | 2810 | local->insertAddressee( inL , false); |
2811 | ++addedAddressee; | 2811 | ++addedAddressee; |
2812 | } | 2812 | } |
2813 | } else { | 2813 | } else { |
2814 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { | 2814 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { |
2815 | inR.setRevision( modifiedCalendar ); | 2815 | inR.setRevision( modifiedCalendar ); |
2816 | remote->insertAddressee( inR, false ); | 2816 | remote->insertAddressee( inR, false ); |
2817 | inR.setResource( 0 ); | 2817 | inR.setResource( 0 ); |
2818 | local->insertAddressee( inR, false ); | 2818 | local->insertAddressee( inR, false ); |
2819 | ++addedAddressee; | 2819 | ++addedAddressee; |
2820 | } else { | 2820 | } else { |
2821 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2821 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2822 | remote->removeAddressee( inR ); | 2822 | remote->removeAddressee( inR ); |
2823 | ++deletedAddresseeR; | 2823 | ++deletedAddresseeR; |
2824 | } | 2824 | } |
2825 | } | 2825 | } |
2826 | } | 2826 | } |
2827 | } | 2827 | } |
2828 | ++incCounter; | 2828 | ++incCounter; |
2829 | } | 2829 | } |
2830 | er.clear(); | 2830 | er.clear(); |
2831 | QStringList el = local->uidList(); | 2831 | QStringList el = local->uidList(); |
2832 | modulo = (el.count()/10)+1; | 2832 | modulo = (el.count()/10)+1; |
2833 | 2833 | ||
2834 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 2834 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
2835 | incCounter = 0; | 2835 | incCounter = 0; |
2836 | while ( incCounter < el.count()) { | 2836 | while ( incCounter < el.count()) { |
2837 | qApp->processEvents(); | 2837 | qApp->processEvents(); |
2838 | if (syncManager->isProgressBarCanceled()) | 2838 | if (syncManager->isProgressBarCanceled()) |
2839 | return false; | 2839 | return false; |
2840 | if ( incCounter % modulo == 0 ) | 2840 | if ( incCounter % modulo == 0 ) |
2841 | syncManager->showProgressBar(incCounter); | 2841 | syncManager->showProgressBar(incCounter); |
2842 | uid = el[ incCounter ]; | 2842 | uid = el[ incCounter ]; |
2843 | bool skipIncidence = false; | 2843 | bool skipIncidence = false; |
2844 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2844 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2845 | skipIncidence = true; | 2845 | skipIncidence = true; |
2846 | if ( !skipIncidence ) { | 2846 | if ( !skipIncidence ) { |
2847 | inL = local->findByUid( uid ); | 2847 | inL = local->findByUid( uid ); |
2848 | if ( !inL.resource() || inL.resource()->includeInSync() ) { | 2848 | if ( !inL.resource() || inL.resource()->includeInSync() ) { |
2849 | inR = remote->findByUid( uid ); | 2849 | inR = remote->findByUid( uid ); |
2850 | if ( inR.isEmpty() ) { // no conflict ********** add or delete local | 2850 | if ( inR.isEmpty() ) { // no conflict ********** add or delete local |
2851 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2851 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2852 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 2852 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
2853 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2853 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2854 | local->removeAddressee( inL ); | 2854 | local->removeAddressee( inL ); |
2855 | ++deletedAddresseeL; | 2855 | ++deletedAddresseeL; |
2856 | } else { | 2856 | } else { |
2857 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2857 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2858 | inL.removeID(mCurrentSyncDevice ); | 2858 | inL.removeID(mCurrentSyncDevice ); |
2859 | ++addedAddresseeR; | 2859 | ++addedAddresseeR; |
2860 | inL.setRevision( modifiedCalendar ); | 2860 | inL.setRevision( modifiedCalendar ); |
2861 | local->insertAddressee( inL, false ); | 2861 | local->insertAddressee( inL, false ); |
2862 | inR = inL; | 2862 | inR = inL; |
2863 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); | 2863 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); |
2864 | inR.setResource( 0 ); | 2864 | inR.setResource( 0 ); |
2865 | remote->insertAddressee( inR, false ); | 2865 | remote->insertAddressee( inR, false ); |
2866 | } | 2866 | } |
2867 | } | 2867 | } |
2868 | } else { | 2868 | } else { |
2869 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { | 2869 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { |
2870 | //qDebug("data %s ", inL.revision().toString().latin1()); | 2870 | //qDebug("data %s ", inL.revision().toString().latin1()); |
2871 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2871 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2872 | local->removeAddressee( inL ); | 2872 | local->removeAddressee( inL ); |
2873 | ++deletedAddresseeL; | 2873 | ++deletedAddresseeL; |
2874 | } else { | 2874 | } else { |
2875 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2875 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2876 | ++addedAddresseeR; | 2876 | ++addedAddresseeR; |
2877 | inL.setRevision( modifiedCalendar ); | 2877 | inL.setRevision( modifiedCalendar ); |
2878 | local->insertAddressee( inL, false ); | 2878 | local->insertAddressee( inL, false ); |
2879 | inR = inL; | 2879 | inR = inL; |
2880 | inR.setIDStr( ":" ); | 2880 | inR.setIDStr( ":" ); |
2881 | inR.setResource( 0 ); | 2881 | inR.setResource( 0 ); |
2882 | remote->insertAddressee( inR, false ); | 2882 | remote->insertAddressee( inR, false ); |
2883 | } | 2883 | } |
2884 | } | 2884 | } |
2885 | } | 2885 | } |
2886 | } | 2886 | } |
2887 | } | 2887 | } |
2888 | } | 2888 | } |
2889 | ++incCounter; | 2889 | ++incCounter; |
2890 | } | 2890 | } |
2891 | el.clear(); | 2891 | el.clear(); |
2892 | syncManager->hideProgressBar(); | 2892 | syncManager->hideProgressBar(); |
2893 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); | 2893 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); |
2894 | // get rid of micro seconds | 2894 | // get rid of micro seconds |
2895 | QTime t = mLastAddressbookSync.time(); | 2895 | QTime t = mLastAddressbookSync.time(); |
2896 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2896 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2897 | addresseeLSync.setRevision( mLastAddressbookSync ); | 2897 | addresseeLSync.setRevision( mLastAddressbookSync ); |
2898 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2898 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2899 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 2899 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2900 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 2900 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2901 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; | 2901 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; |
2902 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); | 2902 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); |
2903 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; | 2903 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; |
2904 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); | 2904 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); |
2905 | addresseeRSync.setNote( "" ) ; | 2905 | addresseeRSync.setNote( "" ) ; |
2906 | addresseeLSync.setNote( "" ); | 2906 | addresseeLSync.setNote( "" ); |
2907 | 2907 | ||
2908 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 2908 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
2909 | remote->insertAddressee( addresseeRSync, false ); | 2909 | remote->insertAddressee( addresseeRSync, false ); |
2910 | local->insertAddressee( addresseeLSync, false ); | 2910 | local->insertAddressee( addresseeLSync, false ); |
2911 | QString mes; | 2911 | QString mes; |
2912 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); | 2912 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); |
2913 | qDebug( mes ); | 2913 | qDebug( mes ); |
2914 | mes = i18n("Local addressbook changed!\n") +mes; | 2914 | mes = i18n("Local addressbook changed!\n") +mes; |
2915 | if ( syncManager->mShowSyncSummary ) { | 2915 | if ( syncManager->mShowSyncSummary ) { |
2916 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, | 2916 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, |
2917 | i18n("KA/Pi Synchronization"),i18n("Write back"))) { | 2917 | i18n("KA/Pi Synchronization"),i18n("Write back"))) { |
2918 | qDebug("cancelled "); | 2918 | qDebug("cancelled "); |
2919 | return false; | 2919 | return false; |
2920 | } | 2920 | } |
2921 | } | 2921 | } |
2922 | return syncOK; | 2922 | return syncOK; |
2923 | } | 2923 | } |
2924 | 2924 | ||
2925 | 2925 | ||
2926 | //this is a overwritten callbackmethods from the syncinterface | 2926 | //this is a overwritten callbackmethods from the syncinterface |
2927 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) | 2927 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) |
2928 | { | 2928 | { |
2929 | 2929 | ||
2930 | //pending prepare addresseeview for output | 2930 | //pending prepare addresseeview for output |
2931 | //pending detect, if remote file has REV field. if not switch to external sync | 2931 | //pending detect, if remote file has REV field. if not switch to external sync |
2932 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2932 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2933 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2933 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2934 | 2934 | ||
2935 | AddressBook abLocal(filename,"syncContact"); | 2935 | AddressBook abLocal(filename,"syncContact"); |
2936 | bool syncOK = false; | 2936 | bool syncOK = false; |
2937 | if ( abLocal.load() ) { | 2937 | if ( abLocal.load() ) { |
2938 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); | 2938 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); |
2939 | bool external = false; | 2939 | bool external = false; |
2940 | bool isXML = false; | 2940 | bool isXML = false; |
2941 | if ( filename.right(4) == ".xml") { | 2941 | if ( filename.right(4) == ".xml") { |
2942 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2942 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2943 | isXML = true; | 2943 | isXML = true; |
2944 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); | 2944 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); |
2945 | } else { | 2945 | } else { |
2946 | external = !manager->mIsKapiFile; | 2946 | external = !manager->mIsKapiFile; |
2947 | if ( external ) { | 2947 | if ( external ) { |
2948 | qDebug("Setting vcf mode to external "); | 2948 | qDebug("Setting vcf mode to external "); |
2949 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2949 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2950 | AddressBook::Iterator it; | 2950 | AddressBook::Iterator it; |
2951 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2951 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2952 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); | 2952 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); |
2953 | (*it).computeCsum( mCurrentSyncDevice ); | 2953 | (*it).computeCsum( mCurrentSyncDevice ); |
2954 | } | 2954 | } |
2955 | } | 2955 | } |
2956 | } | 2956 | } |
2957 | //AddressBook::Iterator it; | 2957 | //AddressBook::Iterator it; |
2958 | //QStringList vcards; | 2958 | //QStringList vcards; |
2959 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2959 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2960 | // qDebug("Name %s ", (*it).familyName().latin1()); | 2960 | // qDebug("Name %s ", (*it).familyName().latin1()); |
2961 | //} | 2961 | //} |
2962 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 2962 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
2963 | if ( syncOK ) { | 2963 | if ( syncOK ) { |
2964 | if ( syncManager->mWriteBackFile ) | 2964 | if ( syncManager->mWriteBackFile ) |
2965 | { | 2965 | { |
2966 | if ( external ) | 2966 | if ( external ) |
2967 | abLocal.removeSyncAddressees( !isXML); | 2967 | abLocal.removeSyncAddressees( !isXML); |
2968 | qDebug("Saving remote AB "); | 2968 | qDebug("Saving remote AB "); |
2969 | if ( ! abLocal.saveAB()) | 2969 | if ( ! abLocal.saveAB()) |
2970 | qDebug("Error writing back AB to file "); | 2970 | qDebug("Error writing back AB to file "); |
2971 | if ( external ) { | 2971 | if ( external ) { |
2972 | // afterwrite processing | 2972 | // afterwrite processing |
2973 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML); | 2973 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML); |
2974 | } | 2974 | } |
2975 | } | 2975 | } |
2976 | } | 2976 | } |
2977 | setModified(); | 2977 | setModified(); |
2978 | 2978 | ||
2979 | } | 2979 | } |
2980 | abLocal.removeResources(); | 2980 | abLocal.removeResources(); |
2981 | if ( syncOK ) | 2981 | if ( syncOK ) |
2982 | mViewManager->refreshView(); | 2982 | mViewManager->refreshView(); |
2983 | return syncOK; | 2983 | return syncOK; |
2984 | 2984 | ||
2985 | } | 2985 | } |
2986 | void KABCore::removeSyncInfo( QString syncProfile) | 2986 | void KABCore::removeSyncInfo( QString syncProfile) |
2987 | { | 2987 | { |
2988 | qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); | 2988 | qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); |
2989 | mAddressBook->removeSyncInfo( syncProfile ); | 2989 | mAddressBook->removeSyncInfo( syncProfile ); |
2990 | setModified(); | 2990 | setModified(); |
2991 | } | 2991 | } |
2992 | 2992 | ||
2993 | 2993 | ||
2994 | //this is a overwritten callbackmethods from the syncinterface | 2994 | //this is a overwritten callbackmethods from the syncinterface |
2995 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) | 2995 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) |
2996 | { | 2996 | { |
2997 | if ( resource == "phone" ) | 2997 | if ( resource == "phone" ) |
2998 | return syncPhone(); | 2998 | return syncPhone(); |
2999 | disableBR( true ); | 2999 | disableBR( true ); |
3000 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 3000 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
3001 | 3001 | ||
3002 | AddressBook abLocal( resource,"syncContact"); | 3002 | AddressBook abLocal( resource,"syncContact"); |
3003 | bool syncOK = false; | 3003 | bool syncOK = false; |
3004 | if ( abLocal.load() ) { | 3004 | if ( abLocal.load() ) { |
3005 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 3005 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
3006 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 3006 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
3007 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); | 3007 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); |
3008 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 3008 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
3009 | if ( syncOK ) { | 3009 | if ( syncOK ) { |
3010 | if ( syncManager->mWriteBackFile ) { | 3010 | if ( syncManager->mWriteBackFile ) { |
3011 | abLocal.removeSyncAddressees( false ); | 3011 | abLocal.removeSyncAddressees( false ); |
3012 | abLocal.saveAB(); | 3012 | abLocal.saveAB(); |
3013 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); | 3013 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); |
3014 | } | 3014 | } |
3015 | } else | 3015 | } else |
3016 | message( i18n("Sync cancelled or failed.") ); | 3016 | message( i18n("Sync cancelled or failed.") ); |
3017 | setModified(); | 3017 | setModified(); |
3018 | } | 3018 | } |
3019 | abLocal.removeResources(); | 3019 | abLocal.removeResources(); |
3020 | if ( syncOK ) | 3020 | if ( syncOK ) |
3021 | mViewManager->refreshView(); | 3021 | mViewManager->refreshView(); |
3022 | disableBR( false ); | 3022 | disableBR( false ); |
3023 | return syncOK; | 3023 | return syncOK; |
3024 | 3024 | ||
3025 | } | 3025 | } |
3026 | void KABCore::message( QString m ) | 3026 | void KABCore::message( QString m ) |
3027 | { | 3027 | { |
3028 | topLevelWidget()->setCaption( m ); | 3028 | topLevelWidget()->setCaption( m ); |
3029 | mMessageTimer->start( 15000, true ); | 3029 | mMessageTimer->start( 15000, true ); |
3030 | } | 3030 | } |
3031 | bool KABCore::syncPhone() | 3031 | bool KABCore::syncPhone() |
3032 | { | 3032 | { |
3033 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 3033 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
3034 | QString fileName = getPhoneFile(); | 3034 | QString fileName = getPhoneFile(); |
3035 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 3035 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
3036 | message(i18n("Phone access failed!")); | 3036 | message(i18n("Phone access failed!")); |
3037 | return false; | 3037 | return false; |
3038 | } | 3038 | } |
3039 | AddressBook abLocal( fileName,"syncContact"); | 3039 | AddressBook abLocal( fileName,"syncContact"); |
3040 | bool syncOK = false; | 3040 | bool syncOK = false; |
3041 | { | 3041 | { |
3042 | abLocal.importFromFile( fileName ); | 3042 | abLocal.importFromFile( fileName ); |
3043 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 3043 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
3044 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 3044 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
3045 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); | 3045 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); |
3046 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); | 3046 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); |
3047 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 3047 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
3048 | if ( syncOK ) { | 3048 | if ( syncOK ) { |
3049 | if ( syncManager->mWriteBackFile ) { | 3049 | if ( syncManager->mWriteBackFile ) { |
3050 | abLocal.removeSyncAddressees( true ); | 3050 | abLocal.removeSyncAddressees( true ); |
3051 | abLocal.saveABphone( fileName ); | 3051 | abLocal.saveABphone( fileName ); |
3052 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); | 3052 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); |
3053 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); | 3053 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); |
3054 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); | 3054 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); |
3055 | } | 3055 | } |
3056 | } | 3056 | } |
3057 | setModified(); | 3057 | setModified(); |
3058 | } | 3058 | } |
3059 | abLocal.removeResources(); | 3059 | abLocal.removeResources(); |
3060 | if ( syncOK ) | 3060 | if ( syncOK ) |
3061 | mViewManager->refreshView(); | 3061 | mViewManager->refreshView(); |
3062 | return syncOK; | 3062 | return syncOK; |
3063 | } | 3063 | } |
3064 | void KABCore::getFile( bool success ) | 3064 | void KABCore::getFile( bool success ) |
3065 | { | 3065 | { |
3066 | if ( ! success ) { | 3066 | if ( ! success ) { |
3067 | message( i18n("Error receiving file. Nothing changed!") ); | 3067 | message( i18n("Error receiving file. Nothing changed!") ); |
3068 | return; | 3068 | return; |
3069 | } | 3069 | } |
3070 | int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); | 3070 | int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); |
3071 | if ( count ) | 3071 | if ( count ) |
3072 | setModified( true ); | 3072 | setModified( true ); |
3073 | message( i18n("Pi-Sync successful!") ); | 3073 | message( i18n("Pi-Sync successful!") ); |
3074 | mViewManager->refreshView(); | 3074 | mViewManager->refreshView(); |
3075 | } | 3075 | } |
3076 | void KABCore::syncFileRequest() | 3076 | void KABCore::syncFileRequest() |
3077 | { | 3077 | { |
3078 | if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) { | 3078 | if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) { |
3079 | syncManager->slotSyncMenu( 999 ); | 3079 | syncManager->slotSyncMenu( 999 ); |
3080 | } | 3080 | } |
3081 | mAddressBook->export2File( sentSyncFile() ); | 3081 | mAddressBook->export2File( sentSyncFile() ); |
3082 | } | 3082 | } |
3083 | QString KABCore::sentSyncFile() | 3083 | QString KABCore::sentSyncFile() |
3084 | { | 3084 | { |
3085 | #ifdef DESKTOP_VERSION | 3085 | #ifdef DESKTOP_VERSION |
3086 | return locateLocal( "tmp", "copysyncab.vcf" ); | 3086 | return locateLocal( "tmp", "copysyncab.vcf" ); |
3087 | #else | 3087 | #else |
3088 | return QString( "/tmp/copysyncab.vcf" ); | 3088 | return QString( "/tmp/copysyncab.vcf" ); |
3089 | #endif | 3089 | #endif |
3090 | } | 3090 | } |
3091 | 3091 | ||
3092 | void KABCore::setCaptionBack() | 3092 | void KABCore::setCaptionBack() |
3093 | { | 3093 | { |
3094 | mMessageTimer->stop(); | 3094 | mMessageTimer->stop(); |
3095 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); | 3095 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); |
3096 | } | 3096 | } |
diff --git a/kaddressbook/views/cardview.cpp b/kaddressbook/views/cardview.cpp index da552c3..03df444 100644 --- a/kaddressbook/views/cardview.cpp +++ b/kaddressbook/views/cardview.cpp | |||
@@ -1,1722 +1,1722 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> | 3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | //BEGIN Includes | 24 | //BEGIN Includes |
25 | #include "cardview.h" | 25 | #include "cardview.h" |
26 | 26 | ||
27 | #include <limits.h> | 27 | #include <limits.h> |
28 | 28 | ||
29 | #include <qpainter.h> | 29 | #include <qpainter.h> |
30 | #include <qtimer.h> | 30 | #include <qtimer.h> |
31 | #include <qdatetime.h> | 31 | #include <qdatetime.h> |
32 | #include <qlabel.h> | 32 | #include <qlabel.h> |
33 | #include <qstyle.h> | 33 | #include <qstyle.h> |
34 | #include <qcursor.h> | 34 | #include <qcursor.h> |
35 | #include <qtooltip.h> | 35 | #include <qtooltip.h> |
36 | 36 | ||
37 | #include "kabprefs.h" | 37 | #include "kabprefs.h" |
38 | #include <kdebug.h> | 38 | #include <kdebug.h> |
39 | #include <kglobalsettings.h> | 39 | #include <kglobalsettings.h> |
40 | //END includes | 40 | //END includes |
41 | 41 | ||
42 | #define MIN_ITEM_WIDTH 80 | 42 | #define MIN_ITEM_WIDTH 80 |
43 | 43 | ||
44 | //BEGIN Helpers | 44 | //BEGIN Helpers |
45 | ////////////////////////////////////// | 45 | ////////////////////////////////////// |
46 | // CardViewTip | 46 | // CardViewTip |
47 | class CardViewTip : public QLabel { | 47 | class CardViewTip : public QLabel { |
48 | public: | 48 | public: |
49 | CardViewTip(QWidget *parent=0, const char *name=0) : QLabel( parent, name ) | 49 | CardViewTip(QWidget *parent=0, const char *name=0) : QLabel( parent, name ) |
50 | { | 50 | { |
51 | setPalette( QToolTip::palette() ); | 51 | setPalette( QToolTip::palette() ); |
52 | setFrameStyle( Panel|Plain ); | 52 | setFrameStyle( Panel|Plain ); |
53 | setMidLineWidth(0); | 53 | setMidLineWidth(0); |
54 | setIndent(1); | 54 | setIndent(1); |
55 | } | 55 | } |
56 | 56 | ||
57 | ~CardViewTip() {}; | 57 | ~CardViewTip() {}; |
58 | protected: | 58 | protected: |
59 | void leaveEvent( QEvent * ) | 59 | void leaveEvent( QEvent * ) |
60 | { | 60 | { |
61 | hide(); | 61 | hide(); |
62 | } | 62 | } |
63 | }; | 63 | }; |
64 | 64 | ||
65 | ////////////////////////////////////// | 65 | ////////////////////////////////////// |
66 | // CardViewItemList | 66 | // CardViewItemList |
67 | 67 | ||
68 | 68 | ||
69 | // | 69 | // |
70 | // Warning: make sure you use findRef() instead of find() to find an | 70 | // Warning: make sure you use findRef() instead of find() to find an |
71 | // item! Only the pointer value is unique in the list. | 71 | // item! Only the pointer value is unique in the list. |
72 | // | 72 | // |
73 | class CardViewItemList : public QPtrList<CardViewItem> | 73 | class CardViewItemList : public QPtrList<CardViewItem> |
74 | { | 74 | { |
75 | protected: | 75 | protected: |
76 | virtual int compareItems(QPtrCollection::Item item1, | 76 | virtual int compareItems(QPtrCollection::Item item1, |
77 | QPtrCollection::Item item2) | 77 | QPtrCollection::Item item2) |
78 | { | 78 | { |
79 | CardViewItem *cItem1 = (CardViewItem*)item1; | 79 | CardViewItem *cItem1 = (CardViewItem*)item1; |
80 | CardViewItem *cItem2 = (CardViewItem*)item2; | 80 | CardViewItem *cItem2 = (CardViewItem*)item2; |
81 | 81 | ||
82 | if ( cItem1 == cItem2 ) | 82 | if ( cItem1 == cItem2 ) |
83 | return 0; | 83 | return 0; |
84 | 84 | ||
85 | if ((cItem1 == 0) || (cItem2 == 0)) | 85 | if ((cItem1 == 0) || (cItem2 == 0)) |
86 | return cItem1 ? -1 : 1; | 86 | return cItem1 ? -1 : 1; |
87 | 87 | ||
88 | if (cItem1->caption() < cItem2->caption()) | 88 | if (cItem1->caption() < cItem2->caption()) |
89 | return -1; | 89 | return -1; |
90 | 90 | ||
91 | else if (cItem1->caption() > cItem2->caption()) | 91 | else if (cItem1->caption() > cItem2->caption()) |
92 | return 1; | 92 | return 1; |
93 | 93 | ||
94 | return 0; | 94 | return 0; |
95 | } | 95 | } |
96 | 96 | ||
97 | private: | 97 | private: |
98 | /*int find( const CardViewItem * ) | 98 | /*int find( const CardViewItem * ) |
99 | { | 99 | { |
100 | qDebug("DON'T USE CardViewItemList::find( item )! Use findRef( item )!"); | 100 | qDebug("DON'T USE CardViewItemList::find( item )! Use findRef( item )!"); |
101 | }*/ | 101 | }*/ |
102 | }; | 102 | }; |
103 | 103 | ||
104 | ////////////////////////////////////// | 104 | ////////////////////////////////////// |
105 | // CardViewSeparator | 105 | // CardViewSeparator |
106 | class CardViewSeparator | 106 | class CardViewSeparator |
107 | { | 107 | { |
108 | friend class CardView; | 108 | friend class CardView; |
109 | 109 | ||
110 | public: | 110 | public: |
111 | CardViewSeparator(CardView *view) | 111 | CardViewSeparator(CardView *view) |
112 | : mView(view) | 112 | : mView(view) |
113 | { | 113 | { |
114 | mRect = QRect(0, 0, view->separatorWidth(), 0); | 114 | mRect = QRect(0, 0, view->separatorWidth(), 0); |
115 | } | 115 | } |
116 | 116 | ||
117 | ~CardViewSeparator() {} | 117 | ~CardViewSeparator() {} |
118 | 118 | ||
119 | void paintSeparator(QPainter *p, QColorGroup &cg) | 119 | void paintSeparator(QPainter *p, QColorGroup &cg) |
120 | { | 120 | { |
121 | p->fillRect(0, 0, mRect.width(), mRect.height(), | 121 | p->fillRect(0, 0, mRect.width(), mRect.height(), |
122 | cg.brush(QColorGroup::Button)); | 122 | cg.brush(QColorGroup::Button)); |
123 | } | 123 | } |
124 | 124 | ||
125 | void repaintSeparator() | 125 | void repaintSeparator() |
126 | { | 126 | { |
127 | mView->repaintContents(mRect); | 127 | mView->repaintContents(mRect); |
128 | } | 128 | } |
129 | 129 | ||
130 | private: | 130 | private: |
131 | CardView *mView; | 131 | CardView *mView; |
132 | QRect mRect; | 132 | QRect mRect; |
133 | }; | 133 | }; |
134 | 134 | ||
135 | //END Helpers | 135 | //END Helpers |
136 | 136 | ||
137 | //BEGIN Private Data | 137 | //BEGIN Private Data |
138 | 138 | ||
139 | class CardViewPrivate | 139 | class CardViewPrivate |
140 | { | 140 | { |
141 | public: | 141 | public: |
142 | CardViewPrivate() | 142 | CardViewPrivate() |
143 | : mSelectionMode( CardView::Multi ), | 143 | : mSelectionMode( CardView::Multi ), |
144 | mDrawCardBorder( true ), | 144 | mDrawCardBorder( true ), |
145 | mDrawFieldLabels( true ), | 145 | mDrawFieldLabels( true ), |
146 | mDrawSeparators( true), | 146 | mDrawSeparators( true), |
147 | mSepWidth( 2 ), | 147 | mSepWidth( 2 ), |
148 | mShowEmptyFields( false ), | 148 | mShowEmptyFields( false ), |
149 | mLayoutDirty( true ), | 149 | mLayoutDirty( true ), |
150 | mLastClickOnItem( false ), | 150 | mLastClickOnItem( false ), |
151 | mItemMargin( 0 ), | 151 | mItemMargin( 0 ), |
152 | mItemSpacing( 10 ), | 152 | mItemSpacing( 10 ), |
153 | mItemWidth( 200 ), | 153 | mItemWidth( 200 ), |
154 | mMaxFieldLines( INT_MAX ), | 154 | mMaxFieldLines( INT_MAX ), |
155 | mCurrentItem( 0L ), | 155 | mCurrentItem( 0L ), |
156 | mLastClickPos( QPoint(0, 0) ), | 156 | mLastClickPos( QPoint(0, 0) ), |
157 | mResizeAnchor(0), | ||
157 | mRubberBandAnchor( 0 ), | 158 | mRubberBandAnchor( 0 ), |
158 | mCompText( QString::null ), | 159 | mCompText( QString::null ) |
159 | mResizeAnchor(0) | ||
160 | {}; | 160 | {}; |
161 | 161 | ||
162 | CardViewItemList mItemList; | 162 | CardViewItemList mItemList; |
163 | QPtrList<CardViewSeparator> mSeparatorList; | 163 | QPtrList<CardViewSeparator> mSeparatorList; |
164 | QFontMetrics *mFm; | 164 | QFontMetrics *mFm; |
165 | QFontMetrics *mBFm; // bold font | 165 | QFontMetrics *mBFm; // bold font |
166 | QFont mHeaderFont; // custom header font | 166 | QFont mHeaderFont; // custom header font |
167 | CardView::SelectionMode mSelectionMode; | 167 | CardView::SelectionMode mSelectionMode; |
168 | bool mDrawCardBorder; | 168 | bool mDrawCardBorder; |
169 | bool mDrawFieldLabels; | 169 | bool mDrawFieldLabels; |
170 | bool mDrawSeparators; | 170 | bool mDrawSeparators; |
171 | int mSepWidth; | 171 | int mSepWidth; |
172 | bool mShowEmptyFields; | 172 | bool mShowEmptyFields; |
173 | bool mLayoutDirty; | 173 | bool mLayoutDirty; |
174 | bool mLastClickOnItem; | 174 | bool mLastClickOnItem; |
175 | uint mItemMargin; // internal margin in items | 175 | uint mItemMargin; // internal margin in items |
176 | uint mItemSpacing; // spacing between items, column seperators and border | 176 | uint mItemSpacing; // spacing between items, column seperators and border |
177 | int mItemWidth; // width of all items | 177 | int mItemWidth; // width of all items |
178 | uint mMaxFieldLines; // Max lines to dispaly pr field | 178 | uint mMaxFieldLines; // Max lines to dispaly pr field |
179 | CardViewItem *mCurrentItem; | 179 | CardViewItem *mCurrentItem; |
180 | QPoint mLastClickPos; | 180 | QPoint mLastClickPos; |
181 | QTimer *mTimer; // times out if mouse rests for more than 500 msecs | 181 | QTimer *mTimer; // times out if mouse rests for more than 500 msecs |
182 | CardViewTip *mTip; // passed to the item under a resting cursor to display full text | 182 | CardViewTip *mTip; // passed to the item under a resting cursor to display full text |
183 | bool mOnSeparator; // set/reset on mouse movement | 183 | bool mOnSeparator; // set/reset on mouse movement |
184 | // for resizing by dragging the separators | 184 | // for resizing by dragging the separators |
185 | int mResizeAnchor; // uint, ulong? the mouse down separator left | 185 | int mResizeAnchor; // uint, ulong? the mouse down separator left |
186 | int mRubberBandAnchor; // for erasing rubber bands | 186 | int mRubberBandAnchor; // for erasing rubber bands |
187 | // data used for resizing. | 187 | // data used for resizing. |
188 | // as they are beeded by each mouse move while resizing, we store them here, | 188 | // as they are beeded by each mouse move while resizing, we store them here, |
189 | // saving 8 calculations in each mouse move. | 189 | // saving 8 calculations in each mouse move. |
190 | int colspace; // amount of space between items pr column | 190 | int colspace; // amount of space between items pr column |
191 | uint first; // the first col to anchor at for painting rubber bands | 191 | uint first; // the first col to anchor at for painting rubber bands |
192 | int firstX; // X position of first in pixel | 192 | int firstX; // X position of first in pixel |
193 | int pressed; // the colummn that was pressed on at resizing start | 193 | int pressed; // the colummn that was pressed on at resizing start |
194 | int span; // pressed - first | 194 | int span; // pressed - first |
195 | // key completion | 195 | // key completion |
196 | QString mCompText; // current completion string | 196 | QString mCompText; // current completion string |
197 | QDateTime mCompUpdated; // ...was updated at this time | 197 | QDateTime mCompUpdated; // ...was updated at this time |
198 | }; | 198 | }; |
199 | 199 | ||
200 | class CardViewItemPrivate | 200 | class CardViewItemPrivate |
201 | { | 201 | { |
202 | public: | 202 | public: |
203 | CardViewItemPrivate() : | 203 | CardViewItemPrivate() : |
204 | x( 0 ), | 204 | mSelected( false ), |
205 | y( 0 ), | 205 | x( 0 ), |
206 | mSelected( false ){}; | 206 | y( 0 ){}; |
207 | 207 | ||
208 | 208 | ||
209 | QString mCaption; | 209 | QString mCaption; |
210 | QPtrList< CardViewItem::Field > mFieldList; | 210 | QPtrList< CardViewItem::Field > mFieldList; |
211 | bool mSelected; | 211 | bool mSelected; |
212 | int x; // horizontal position, set by the view | 212 | int x; // horizontal position, set by the view |
213 | int y; // vertical position, set by the view | 213 | int y; // vertical position, set by the view |
214 | int maxLabelWidth; // the width of the widest label, according to the view font. | 214 | int maxLabelWidth; // the width of the widest label, according to the view font. |
215 | int hcache; // height cache | 215 | int hcache; // height cache |
216 | }; | 216 | }; |
217 | //END Private Data | 217 | //END Private Data |
218 | 218 | ||
219 | //BEGIN CardViewItem | 219 | //BEGIN CardViewItem |
220 | 220 | ||
221 | CardViewItem::CardViewItem(CardView *parent, QString caption) | 221 | CardViewItem::CardViewItem(CardView *parent, QString caption) |
222 | : d(new CardViewItemPrivate()), mView(parent) | 222 | : d(new CardViewItemPrivate()), mView(parent) |
223 | { | 223 | { |
224 | d->mCaption = caption; | 224 | d->mCaption = caption; |
225 | 225 | ||
226 | initialize(); | 226 | initialize(); |
227 | } | 227 | } |
228 | 228 | ||
229 | CardViewItem::~CardViewItem() | 229 | CardViewItem::~CardViewItem() |
230 | { | 230 | { |
231 | // Remove ourself from the view | 231 | // Remove ourself from the view |
232 | if (mView != 0) | 232 | if (mView != 0) |
233 | mView->takeItem(this); | 233 | mView->takeItem(this); |
234 | 234 | ||
235 | delete d; | 235 | delete d; |
236 | d = 0; | 236 | d = 0; |
237 | } | 237 | } |
238 | 238 | ||
239 | void CardViewItem::initialize() | 239 | void CardViewItem::initialize() |
240 | { | 240 | { |
241 | d->mSelected = false; | 241 | d->mSelected = false; |
242 | d->mFieldList.setAutoDelete(true); | 242 | d->mFieldList.setAutoDelete(true); |
243 | d->maxLabelWidth = 0; | 243 | d->maxLabelWidth = 0; |
244 | d->hcache=0; | 244 | d->hcache=0; |
245 | 245 | ||
246 | //calcRect(); | 246 | //calcRect(); |
247 | 247 | ||
248 | // Add ourself to the view | 248 | // Add ourself to the view |
249 | if (mView != 0) | 249 | if (mView != 0) |
250 | mView->insertItem(this); | 250 | mView->insertItem(this); |
251 | } | 251 | } |
252 | 252 | ||
253 | void CardViewItem::paintCard(QPainter *p, QColorGroup &cg) | 253 | void CardViewItem::paintCard(QPainter *p, QColorGroup &cg) |
254 | { | 254 | { |
255 | 255 | ||
256 | if (!mView) | 256 | if (!mView) |
257 | return; | 257 | return; |
258 | 258 | ||
259 | QPen pen; | 259 | QPen pen; |
260 | QBrush brush; | 260 | QBrush brush; |
261 | QFontMetrics fm = *(mView->d->mFm); | 261 | QFontMetrics fm = *(mView->d->mFm); |
262 | QFontMetrics bFm = *(mView->d->mBFm); | 262 | QFontMetrics bFm = *(mView->d->mBFm); |
263 | bool drawLabels = mView->d->mDrawFieldLabels; | 263 | bool drawLabels = mView->d->mDrawFieldLabels; |
264 | bool drawBorder = mView->d->mDrawCardBorder; | 264 | bool drawBorder = mView->d->mDrawCardBorder; |
265 | int mg = mView->itemMargin(); | 265 | int mg = mView->itemMargin(); |
266 | int w = mView->itemWidth() - (mg*2); | 266 | int w = mView->itemWidth() - (mg*2); |
267 | int h = height() - (mg*2); | 267 | int h = height() - (mg*2); |
268 | const int colonWidth( fm.width(":") ); | 268 | const int colonWidth( fm.width(":") ); |
269 | int labelXPos = 2 + mg; | 269 | int labelXPos = 2 + mg; |
270 | int labelWidth = QMIN( w/2 - 4 - mg, d->maxLabelWidth + colonWidth + 4 ); | 270 | int labelWidth = QMIN( w/2 - 4 - mg, d->maxLabelWidth + colonWidth + 4 ); |
271 | int valueXPos = labelWidth + 4 + mg; | 271 | int valueXPos = labelWidth + 4 + mg; |
272 | int valueWidth = w - labelWidth - 4 - mg; | 272 | int valueWidth = w - labelWidth - 4 - mg; |
273 | 273 | ||
274 | p->setFont( mView->font() ); | 274 | p->setFont( mView->font() ); |
275 | labelWidth -= colonWidth; // extra space for the colon | 275 | labelWidth -= colonWidth; // extra space for the colon |
276 | 276 | ||
277 | if (!drawLabels) | 277 | if (!drawLabels) |
278 | { | 278 | { |
279 | valueXPos = labelXPos; | 279 | valueXPos = labelXPos; |
280 | valueWidth = w - 4; | 280 | valueWidth = w - 4; |
281 | } | 281 | } |
282 | 282 | ||
283 | // Draw a simple box | 283 | // Draw a simple box |
284 | if (isSelected()) | 284 | if (isSelected()) |
285 | pen = QPen(cg.highlight(), 1); | 285 | pen = QPen(cg.highlight(), 1); |
286 | else | 286 | else |
287 | pen = QPen(cg.button(), 1); | 287 | pen = QPen(cg.button(), 1); |
288 | p->setPen(pen); | 288 | p->setPen(pen); |
289 | 289 | ||
290 | // Draw the border - this is only draw if the user asks for it. | 290 | // Draw the border - this is only draw if the user asks for it. |
291 | if (drawBorder) | 291 | if (drawBorder) |
292 | p->drawRect( mg, mg, w, h ); | 292 | p->drawRect( mg, mg, w, h ); |
293 | 293 | ||
294 | // set the proper pen color for the caption box | 294 | // set the proper pen color for the caption box |
295 | if (isSelected()) | 295 | if (isSelected()) |
296 | brush = cg.brush(QColorGroup::Highlight); | 296 | brush = cg.brush(QColorGroup::Highlight); |
297 | else | 297 | else |
298 | brush = cg.brush(QColorGroup::Button); | 298 | brush = cg.brush(QColorGroup::Button); |
299 | 299 | ||
300 | p->fillRect(mg, mg, w, 4 + bFm.height(), brush); | 300 | p->fillRect(mg, mg, w, 4 + bFm.height(), brush); |
301 | 301 | ||
302 | // Now paint the caption | 302 | // Now paint the caption |
303 | p->save(); | 303 | p->save(); |
304 | QFont bFont = mView->headerFont(); | 304 | QFont bFont = mView->headerFont(); |
305 | //bFont.setBold(true); | 305 | //bFont.setBold(true); |
306 | p->setFont(bFont); | 306 | p->setFont(bFont); |
307 | if (isSelected()) | 307 | if (isSelected()) |
308 | p->setPen(cg.highlightedText()); | 308 | p->setPen(cg.highlightedText()); |
309 | else | 309 | else |
310 | p->setPen(cg.buttonText()); | 310 | p->setPen(cg.buttonText()); |
311 | p->drawText(2+mg, 2+mg + bFm.ascent()/*bFm.height()*//*-bFm.descent()*//*-bFm.leading()*/, trimString(d->mCaption, w-4, bFm)); | 311 | p->drawText(2+mg, 2+mg + bFm.ascent()/*bFm.height()*//*-bFm.descent()*//*-bFm.leading()*/, trimString(d->mCaption, w-4, bFm)); |
312 | p->restore(); | 312 | p->restore(); |
313 | 313 | ||
314 | // Go through the fields and draw them | 314 | // Go through the fields and draw them |
315 | QPtrListIterator< CardViewItem::Field > iter(d->mFieldList); | 315 | QPtrListIterator< CardViewItem::Field > iter(d->mFieldList); |
316 | QString label, value; | 316 | QString label, value; |
317 | int yPos = mg + 4 + bFm.height()/* + 1*/ + fm.height(); // why the + 1 ??? (anders) | 317 | int yPos = mg + 4 + bFm.height()/* + 1*/ + fm.height(); // why the + 1 ??? (anders) |
318 | p->setPen(cg.text()); | 318 | p->setPen(cg.text()); |
319 | 319 | ||
320 | int fh = fm.height(); | 320 | int fh = fm.height(); |
321 | int cln( 0 ); | 321 | int cln( 0 ); |
322 | QString tmp; | 322 | QString tmp; |
323 | int maxLines = mView->maxFieldLines(); | 323 | int maxLines = mView->maxFieldLines(); |
324 | for (iter.toFirst(); iter.current(); ++iter) | 324 | for (iter.toFirst(); iter.current(); ++iter) |
325 | { | 325 | { |
326 | value = (*iter)->second; | 326 | value = (*iter)->second; |
327 | if ( value.isEmpty() && ! mView->d->mShowEmptyFields ) | 327 | if ( value.isEmpty() && ! mView->d->mShowEmptyFields ) |
328 | continue; | 328 | continue; |
329 | 329 | ||
330 | if (drawLabels) | 330 | if (drawLabels) |
331 | { | 331 | { |
332 | label = trimString((*iter)->first, labelWidth, fm); | 332 | label = trimString((*iter)->first, labelWidth, fm); |
333 | p->drawText(labelXPos, yPos, label + ":"); | 333 | p->drawText(labelXPos, yPos, label + ":"); |
334 | } | 334 | } |
335 | /* US original | 335 | /* US original |
336 | for (cln=0; cln <= maxLines; cln++) | 336 | for (cln=0; cln <= maxLines; cln++) |
337 | { | 337 | { |
338 | tmp = value.section('\n',cln,cln); | 338 | tmp = value.section('\n',cln,cln); |
339 | if ( !tmp.isEmpty() ) p->drawText( valueXPos, yPos + cln*fh, trimString( tmp, valueWidth, fm ) ); | 339 | if ( !tmp.isEmpty() ) p->drawText( valueXPos, yPos + cln*fh, trimString( tmp, valueWidth, fm ) ); |
340 | else break; | 340 | else break; |
341 | } | 341 | } |
342 | */ | 342 | */ |
343 | 343 | ||
344 | //US new implementation | 344 | //US new implementation |
345 | QStringList strlst = QStringList::split('\n', value, true); | 345 | QStringList strlst = QStringList::split('\n', value, true); |
346 | 346 | ||
347 | for (cln=0; cln <= maxLines && cln <= (int)strlst.count(); cln++) | 347 | for (cln=0; cln <= maxLines && cln <= (int)strlst.count(); cln++) |
348 | { | 348 | { |
349 | tmp = strlst[cln]; | 349 | tmp = strlst[cln]; |
350 | 350 | ||
351 | if ( !tmp.isEmpty() ) | 351 | if ( !tmp.isEmpty() ) |
352 | p->drawText( valueXPos, yPos + cln*fh, trimString( tmp, valueWidth, fm ) ); | 352 | p->drawText( valueXPos, yPos + cln*fh, trimString( tmp, valueWidth, fm ) ); |
353 | else | 353 | else |
354 | break; | 354 | break; |
355 | 355 | ||
356 | } | 356 | } |
357 | 357 | ||
358 | if ( cln == 0 ) cln = 1; | 358 | if ( cln == 0 ) cln = 1; |
359 | yPos += cln * fh + 2; | 359 | yPos += cln * fh + 2; |
360 | } | 360 | } |
361 | 361 | ||
362 | // if we are the current item and the view has focus, draw focus rect | 362 | // if we are the current item and the view has focus, draw focus rect |
363 | if ( mView->currentItem() == this && mView->hasFocus() ) | 363 | if ( mView->currentItem() == this && mView->hasFocus() ) |
364 | { | 364 | { |
365 | /*US | 365 | /*US |
366 | mView->style().drawPrimitive( QStyle::PE_FocusRect, p, | 366 | mView->style().drawPrimitive( QStyle::PE_FocusRect, p, |
367 | QRect(0, 0, mView->itemWidth(), h+(2*mg)), cg, | 367 | QRect(0, 0, mView->itemWidth(), h+(2*mg)), cg, |
368 | QStyle::Style_FocusAtBorder, | 368 | QStyle::Style_FocusAtBorder, |
369 | QStyleOption( isSelected() ? cg.highlight() : cg.base() ) ); | 369 | QStyleOption( isSelected() ? cg.highlight() : cg.base() ) ); |
370 | */ | 370 | */ |
371 | 371 | ||
372 | const QColor pHighl = isSelected() ? cg.highlight() : cg.base(); | 372 | const QColor pHighl = isSelected() ? cg.highlight() : cg.base(); |
373 | const QRect r(0, 0, mView->itemWidth(), h+(2*mg)); | 373 | const QRect r(0, 0, mView->itemWidth(), h+(2*mg)); |
374 | #ifndef DESKTOP_VERSION | 374 | #ifndef DESKTOP_VERSION |
375 | mView->style().drawFocusRect(p, r, cg, &pHighl, true); | 375 | mView->style().drawFocusRect(p, r, cg, &pHighl, true); |
376 | #endif | 376 | #endif |
377 | } | 377 | } |
378 | } | 378 | } |
379 | 379 | ||
380 | const QString &CardViewItem::caption() const | 380 | const QString &CardViewItem::caption() const |
381 | { | 381 | { |
382 | return d->mCaption; | 382 | return d->mCaption; |
383 | } | 383 | } |
384 | 384 | ||
385 | 385 | ||
386 | int CardViewItem::height( bool allowCache ) const | 386 | int CardViewItem::height( bool allowCache ) const |
387 | { | 387 | { |
388 | // use cache | 388 | // use cache |
389 | if ( allowCache && d->hcache ) | 389 | if ( allowCache && d->hcache ) |
390 | return d->hcache; | 390 | return d->hcache; |
391 | 391 | ||
392 | // Base height: | 392 | // Base height: |
393 | // 2 for line width | 393 | // 2 for line width |
394 | // 2 for top caption pad | 394 | // 2 for top caption pad |
395 | // 2 for bottom caption pad | 395 | // 2 for bottom caption pad |
396 | // 2 pad for the end | 396 | // 2 pad for the end |
397 | // + 2 times the advised margin | 397 | // + 2 times the advised margin |
398 | int baseHeight = 8 + ( 2 * mView->itemMargin() ); | 398 | int baseHeight = 8 + ( 2 * mView->itemMargin() ); |
399 | 399 | ||
400 | // size of font for each field | 400 | // size of font for each field |
401 | // 2 pad for each field | 401 | // 2 pad for each field |
402 | 402 | ||
403 | // anders: if the view does not show empty fields, check for value | 403 | // anders: if the view does not show empty fields, check for value |
404 | bool sef = mView->showEmptyFields(); | 404 | bool sef = mView->showEmptyFields(); |
405 | int fh = mView->d->mFm->height();//lineSpacing(); // font height | 405 | int fh = mView->d->mFm->height();//lineSpacing(); // font height |
406 | //int sp = QMAX( 0, 2- mView->d->mFm->leading() ); // field spacing NOTE make a property | 406 | //int sp = QMAX( 0, 2- mView->d->mFm->leading() ); // field spacing NOTE make a property |
407 | int fieldHeight = 0; | 407 | int fieldHeight = 0; |
408 | int lines; | 408 | int lines; |
409 | int maxLines( mView->maxFieldLines() ); | 409 | int maxLines( mView->maxFieldLines() ); |
410 | QPtrListIterator< CardViewItem::Field > iter(d->mFieldList); | 410 | QPtrListIterator< CardViewItem::Field > iter(d->mFieldList); |
411 | for (iter.toFirst(); iter.current(); ++iter) | 411 | for (iter.toFirst(); iter.current(); ++iter) |
412 | { | 412 | { |
413 | if ( !sef && (*iter)->second.isEmpty() ) | 413 | if ( !sef && (*iter)->second.isEmpty() ) |
414 | continue; | 414 | continue; |
415 | lines = QMIN( (*iter)->second.contains('\n') + 1, maxLines ); | 415 | lines = QMIN( (*iter)->second.contains('\n') + 1, maxLines ); |
416 | fieldHeight += ( lines * fh ) + 2;//sp; | 416 | fieldHeight += ( lines * fh ) + 2;//sp; |
417 | } | 417 | } |
418 | 418 | ||
419 | // height of caption font (bold) | 419 | // height of caption font (bold) |
420 | fieldHeight += mView->d->mBFm->height(); | 420 | fieldHeight += mView->d->mBFm->height(); |
421 | d->hcache = baseHeight + fieldHeight; | 421 | d->hcache = baseHeight + fieldHeight; |
422 | return d->hcache; | 422 | return d->hcache; |
423 | } | 423 | } |
424 | 424 | ||
425 | bool CardViewItem::isSelected() const | 425 | bool CardViewItem::isSelected() const |
426 | { | 426 | { |
427 | return d->mSelected; | 427 | return d->mSelected; |
428 | } | 428 | } |
429 | 429 | ||
430 | void CardViewItem::setSelected(bool selected) | 430 | void CardViewItem::setSelected(bool selected) |
431 | { | 431 | { |
432 | d->mSelected = selected; | 432 | d->mSelected = selected; |
433 | } | 433 | } |
434 | 434 | ||
435 | void CardViewItem::insertField(const QString &label, const QString &value) | 435 | void CardViewItem::insertField(const QString &label, const QString &value) |
436 | { | 436 | { |
437 | CardViewItem::Field *f = new CardViewItem::Field(label, value); | 437 | CardViewItem::Field *f = new CardViewItem::Field(label, value); |
438 | d->mFieldList.append(f); | 438 | d->mFieldList.append(f); |
439 | d->hcache=0; | 439 | d->hcache=0; |
440 | 440 | ||
441 | if (mView) | 441 | if (mView) |
442 | { | 442 | { |
443 | mView->setLayoutDirty(true); | 443 | mView->setLayoutDirty(true); |
444 | d->maxLabelWidth = QMAX( mView->d->mFm->width( label ), d->maxLabelWidth ); | 444 | d->maxLabelWidth = QMAX( mView->d->mFm->width( label ), d->maxLabelWidth ); |
445 | } | 445 | } |
446 | } | 446 | } |
447 | 447 | ||
448 | void CardViewItem::removeField(const QString &label) | 448 | void CardViewItem::removeField(const QString &label) |
449 | { | 449 | { |
450 | CardViewItem::Field *f; | 450 | CardViewItem::Field *f; |
451 | 451 | ||
452 | QPtrListIterator< CardViewItem::Field > iter(d->mFieldList); | 452 | QPtrListIterator< CardViewItem::Field > iter(d->mFieldList); |
453 | for (iter.toFirst(); iter.current(); ++iter) | 453 | for (iter.toFirst(); iter.current(); ++iter) |
454 | { | 454 | { |
455 | f = *iter; | 455 | f = *iter; |
456 | if (f->first == label) | 456 | if (f->first == label) |
457 | break; | 457 | break; |
458 | } | 458 | } |
459 | 459 | ||
460 | if (*iter) | 460 | if (*iter) |
461 | d->mFieldList.remove(*iter); | 461 | d->mFieldList.remove(*iter); |
462 | d->hcache = 0; | 462 | d->hcache = 0; |
463 | 463 | ||
464 | if (mView) | 464 | if (mView) |
465 | mView->setLayoutDirty(true); | 465 | mView->setLayoutDirty(true); |
466 | } | 466 | } |
467 | 467 | ||
468 | void CardViewItem::clearFields() | 468 | void CardViewItem::clearFields() |
469 | { | 469 | { |
470 | d->mFieldList.clear(); | 470 | d->mFieldList.clear(); |
471 | d->hcache = 0; | 471 | d->hcache = 0; |
472 | 472 | ||
473 | if (mView) | 473 | if (mView) |
474 | mView->setLayoutDirty(true); | 474 | mView->setLayoutDirty(true); |
475 | } | 475 | } |
476 | 476 | ||
477 | QString CardViewItem::trimString(const QString &text, int width, | 477 | QString CardViewItem::trimString(const QString &text, int width, |
478 | QFontMetrics &fm) | 478 | QFontMetrics &fm) |
479 | { | 479 | { |
480 | if (fm.width(text) <= width) | 480 | if (fm.width(text) <= width) |
481 | return text; | 481 | return text; |
482 | 482 | ||
483 | QString dots = "..."; | 483 | QString dots = "..."; |
484 | int dotWidth = fm.width(dots); | 484 | int dotWidth = fm.width(dots); |
485 | QString trimmed; | 485 | QString trimmed; |
486 | int charNum = 0; | 486 | int charNum = 0; |
487 | 487 | ||
488 | while (fm.width(trimmed) + dotWidth < width) | 488 | while (fm.width(trimmed) + dotWidth < width) |
489 | { | 489 | { |
490 | trimmed += text[charNum]; | 490 | trimmed += text[charNum]; |
491 | charNum++; | 491 | charNum++; |
492 | } | 492 | } |
493 | 493 | ||
494 | // Now trim the last char, since it put the width over the top | 494 | // Now trim the last char, since it put the width over the top |
495 | trimmed = trimmed.left(trimmed.length()-1); | 495 | trimmed = trimmed.left(trimmed.length()-1); |
496 | trimmed += dots; | 496 | trimmed += dots; |
497 | 497 | ||
498 | return trimmed; | 498 | return trimmed; |
499 | } | 499 | } |
500 | 500 | ||
501 | CardViewItem *CardViewItem::nextItem() | 501 | CardViewItem *CardViewItem::nextItem() |
502 | { | 502 | { |
503 | CardViewItem *item = 0; | 503 | CardViewItem *item = 0; |
504 | 504 | ||
505 | if (mView) | 505 | if (mView) |
506 | item = mView->itemAfter(this); | 506 | item = mView->itemAfter(this); |
507 | 507 | ||
508 | return item; | 508 | return item; |
509 | } | 509 | } |
510 | 510 | ||
511 | void CardViewItem::repaintCard() | 511 | void CardViewItem::repaintCard() |
512 | { | 512 | { |
513 | if (mView) | 513 | if (mView) |
514 | mView->repaintItem(this); | 514 | mView->repaintItem(this); |
515 | } | 515 | } |
516 | 516 | ||
517 | void CardViewItem::setCaption(const QString &caption) | 517 | void CardViewItem::setCaption(const QString &caption) |
518 | { | 518 | { |
519 | d->mCaption = caption; | 519 | d->mCaption = caption; |
520 | repaintCard(); | 520 | repaintCard(); |
521 | } | 521 | } |
522 | 522 | ||
523 | QString CardViewItem::fieldValue(const QString &label) | 523 | QString CardViewItem::fieldValue(const QString &label) |
524 | { | 524 | { |
525 | QPtrListIterator< CardViewItem::Field > iter(d->mFieldList); | 525 | QPtrListIterator< CardViewItem::Field > iter(d->mFieldList); |
526 | for (iter.toFirst(); iter.current(); ++iter) | 526 | for (iter.toFirst(); iter.current(); ++iter) |
527 | if ((*iter)->first == label) | 527 | if ((*iter)->first == label) |
528 | return (*iter)->second; | 528 | return (*iter)->second; |
529 | 529 | ||
530 | return QString(); | 530 | return QString(); |
531 | } | 531 | } |
532 | 532 | ||
533 | 533 | ||
534 | void CardViewItem::showFullString( const QPoint &itempos, CardViewTip *tip ) | 534 | void CardViewItem::showFullString( const QPoint &itempos, CardViewTip *tip ) |
535 | { | 535 | { |
536 | bool trimmed( false ); | 536 | bool trimmed( false ); |
537 | QString s; | 537 | QString s; |
538 | int mrg = mView->itemMargin(); | 538 | int mrg = mView->itemMargin(); |
539 | int y = mView->d->mBFm->height() + 6 + mrg; | 539 | int y = mView->d->mBFm->height() + 6 + mrg; |
540 | int w = mView->itemWidth() - (2*mrg); | 540 | int w = mView->itemWidth() - (2*mrg); |
541 | int lw; | 541 | int lw; |
542 | bool drawLabels = mView->drawFieldLabels(); | 542 | bool drawLabels = mView->drawFieldLabels(); |
543 | bool isLabel = drawLabels && itempos.x() < w/2 ? true : false; | 543 | bool isLabel = drawLabels && itempos.x() < w/2 ? true : false; |
544 | 544 | ||
545 | if ( itempos.y() < y ) | 545 | if ( itempos.y() < y ) |
546 | { | 546 | { |
547 | if ( itempos.y() < 8 + mrg || itempos.y() > y - 4 ) | 547 | if ( itempos.y() < 8 + mrg || itempos.y() > y - 4 ) |
548 | return; | 548 | return; |
549 | // this is the caption | 549 | // this is the caption |
550 | s = caption(); | 550 | s = caption(); |
551 | trimmed = mView->d->mBFm->width( s ) > w - 4; | 551 | trimmed = mView->d->mBFm->width( s ) > w - 4; |
552 | y = 2 + mrg; | 552 | y = 2 + mrg; |
553 | lw = 0; | 553 | lw = 0; |
554 | isLabel=true; | 554 | isLabel=true; |
555 | } else { | 555 | } else { |
556 | // find the field | 556 | // find the field |
557 | Field *f = fieldAt( itempos ); | 557 | Field *f = fieldAt( itempos ); |
558 | if ( !f || ( !mView->showEmptyFields() && f->second.isEmpty() ) ) | 558 | if ( !f || ( !mView->showEmptyFields() && f->second.isEmpty() ) ) |
559 | return; | 559 | return; |
560 | 560 | ||
561 | // y position: | 561 | // y position: |
562 | // header font height + 4px hader margin + 2px leading + item margin | 562 | // header font height + 4px hader margin + 2px leading + item margin |
563 | // + actual field index * (fontheight + 2px leading) | 563 | // + actual field index * (fontheight + 2px leading) |
564 | int maxLines = mView->maxFieldLines(); | 564 | int maxLines = mView->maxFieldLines(); |
565 | bool se = mView->showEmptyFields(); | 565 | bool se = mView->showEmptyFields(); |
566 | int fh = mView->d->mFm->height(); | 566 | int fh = mView->d->mFm->height(); |
567 | // { | 567 | // { |
568 | Field *_f; | 568 | Field *_f; |
569 | for (_f = d->mFieldList.first(); _f != f; _f = d->mFieldList.next()) | 569 | for (_f = d->mFieldList.first(); _f != f; _f = d->mFieldList.next()) |
570 | if ( se || ! _f->second.isEmpty() ) | 570 | if ( se || ! _f->second.isEmpty() ) |
571 | y += ( QMIN(_f->second.contains('\n')+1, maxLines) * fh ) + 2; | 571 | y += ( QMIN(_f->second.contains('\n')+1, maxLines) * fh ) + 2; |
572 | // } | 572 | // } |
573 | if ( isLabel && itempos.y() > y + fh ) | 573 | if ( isLabel && itempos.y() > y + fh ) |
574 | return; | 574 | return; |
575 | // label or data? | 575 | // label or data? |
576 | s = isLabel ? f->first : f->second; | 576 | s = isLabel ? f->first : f->second; |
577 | // trimmed? | 577 | // trimmed? |
578 | int colonWidth = mView->d->mFm->width(":"); | 578 | int colonWidth = mView->d->mFm->width(":"); |
579 | lw = drawLabels ? // label width | 579 | lw = drawLabels ? // label width |
580 | QMIN( w/2 - 4 - mrg, d->maxLabelWidth + colonWidth + 4 ) : | 580 | QMIN( w/2 - 4 - mrg, d->maxLabelWidth + colonWidth + 4 ) : |
581 | 0; | 581 | 0; |
582 | int mw = isLabel ? lw - colonWidth : w - lw - (mrg*2); // max width for string | 582 | int mw = isLabel ? lw - colonWidth : w - lw - (mrg*2); // max width for string |
583 | if ( isLabel ) | 583 | if ( isLabel ) |
584 | { | 584 | { |
585 | trimmed = mView->d->mFm->width( s ) > mw - colonWidth; | 585 | trimmed = mView->d->mFm->width( s ) > mw - colonWidth; |
586 | } else { | 586 | } else { |
587 | QRect r( mView->d->mFm->boundingRect( 0, 0, INT_MAX, INT_MAX, Qt::AlignTop|Qt::AlignLeft, s ) ); | 587 | QRect r( mView->d->mFm->boundingRect( 0, 0, INT_MAX, INT_MAX, Qt::AlignTop|Qt::AlignLeft, s ) ); |
588 | trimmed = r.width() > mw || r.height()/fh > QMIN(s.contains('\n') + 1, maxLines); | 588 | trimmed = r.width() > mw || r.height()/fh > QMIN(s.contains('\n') + 1, maxLines); |
589 | } | 589 | } |
590 | } | 590 | } |
591 | if ( trimmed ) | 591 | if ( trimmed ) |
592 | { | 592 | { |
593 | tip->setFont( (isLabel && !lw) ? mView->headerFont() : mView->font() ); // if condition is true, a header | 593 | tip->setFont( (isLabel && !lw) ? mView->headerFont() : mView->font() ); // if condition is true, a header |
594 | tip->setText( s ); | 594 | tip->setText( s ); |
595 | tip->adjustSize(); | 595 | tip->adjustSize(); |
596 | // find a proper position | 596 | // find a proper position |
597 | int lx; | 597 | int lx; |
598 | lx = isLabel || !drawLabels ? mrg : lw + mrg + 2 /*-1*/; | 598 | lx = isLabel || !drawLabels ? mrg : lw + mrg + 2 /*-1*/; |
599 | QPoint pnt(mView->contentsToViewport( QPoint(d->x, d->y) )); | 599 | QPoint pnt(mView->contentsToViewport( QPoint(d->x, d->y) )); |
600 | pnt += QPoint(lx, y); | 600 | pnt += QPoint(lx, y); |
601 | if ( pnt.x() < 0 ) | 601 | if ( pnt.x() < 0 ) |
602 | pnt.setX( 0 ); | 602 | pnt.setX( 0 ); |
603 | if ( pnt.x() + tip->width() > mView->visibleWidth() ) | 603 | if ( pnt.x() + tip->width() > mView->visibleWidth() ) |
604 | pnt.setX( mView->visibleWidth() - tip->width() ); | 604 | pnt.setX( mView->visibleWidth() - tip->width() ); |
605 | if ( pnt.y() + tip->height() > mView->visibleHeight() ) | 605 | if ( pnt.y() + tip->height() > mView->visibleHeight() ) |
606 | pnt.setY( QMAX( 0, mView->visibleHeight() - tip->height() ) ); | 606 | pnt.setY( QMAX( 0, mView->visibleHeight() - tip->height() ) ); |
607 | // show | 607 | // show |
608 | tip->move( pnt ); | 608 | tip->move( pnt ); |
609 | tip->show(); | 609 | tip->show(); |
610 | } | 610 | } |
611 | } | 611 | } |
612 | 612 | ||
613 | CardViewItem::Field *CardViewItem::fieldAt( const QPoint & itempos ) const | 613 | CardViewItem::Field *CardViewItem::fieldAt( const QPoint & itempos ) const |
614 | { | 614 | { |
615 | int ypos = mView->d->mBFm->height() + 7 + mView->d->mItemMargin; | 615 | int ypos = mView->d->mBFm->height() + 7 + mView->d->mItemMargin; |
616 | int iy = itempos.y(); | 616 | int iy = itempos.y(); |
617 | // skip below caption | 617 | // skip below caption |
618 | if ( iy <= ypos ) | 618 | if ( iy <= ypos ) |
619 | return 0; | 619 | return 0; |
620 | // try find a field | 620 | // try find a field |
621 | bool showEmpty = mView->showEmptyFields(); | 621 | bool showEmpty = mView->showEmptyFields(); |
622 | int fh = mView->d->mFm->height(); | 622 | int fh = mView->d->mFm->height(); |
623 | int maxLines = mView->maxFieldLines(); | 623 | int maxLines = mView->maxFieldLines(); |
624 | Field *f; | 624 | Field *f; |
625 | for ( f = d->mFieldList.first(); f; f = d->mFieldList.next() ) | 625 | for ( f = d->mFieldList.first(); f; f = d->mFieldList.next() ) |
626 | { | 626 | { |
627 | if ( showEmpty || !f->second.isEmpty() ) | 627 | if ( showEmpty || !f->second.isEmpty() ) |
628 | ypos += ( QMIN( f->second.contains('\n')+1, maxLines ) *fh)+2; | 628 | ypos += ( QMIN( f->second.contains('\n')+1, maxLines ) *fh)+2; |
629 | if ( iy <= ypos ) | 629 | if ( iy <= ypos ) |
630 | break; | 630 | break; |
631 | } | 631 | } |
632 | return f ? f : 0; | 632 | return f ? f : 0; |
633 | } | 633 | } |
634 | //END CardViewItem | 634 | //END CardViewItem |
635 | 635 | ||
636 | //BEGIN CardView | 636 | //BEGIN CardView |
637 | 637 | ||
638 | CardView::CardView(QWidget *parent, const char *name) | 638 | CardView::CardView(QWidget *parent, const char *name) |
639 | : QScrollView(parent, name), | 639 | : QScrollView(parent, name), |
640 | d(new CardViewPrivate()) | 640 | d(new CardViewPrivate()) |
641 | { | 641 | { |
642 | d->mItemList.setAutoDelete(true); | 642 | d->mItemList.setAutoDelete(true); |
643 | d->mSeparatorList.setAutoDelete(true); | 643 | d->mSeparatorList.setAutoDelete(true); |
644 | 644 | ||
645 | QFont f = font(); | 645 | QFont f = font(); |
646 | d->mFm = new QFontMetrics(f); | 646 | d->mFm = new QFontMetrics(f); |
647 | f.setBold(true); | 647 | f.setBold(true); |
648 | d->mHeaderFont = f; | 648 | d->mHeaderFont = f; |
649 | d->mBFm = new QFontMetrics(f); | 649 | d->mBFm = new QFontMetrics(f); |
650 | d->mTip = ( new CardViewTip( viewport() ) ), | 650 | d->mTip = ( new CardViewTip( viewport() ) ), |
651 | d->mTip->hide(); | 651 | d->mTip->hide(); |
652 | d->mTimer = ( new QTimer(this, "mouseTimer") ), | 652 | d->mTimer = ( new QTimer(this, "mouseTimer") ), |
653 | 653 | ||
654 | viewport()->setMouseTracking( true ); | 654 | viewport()->setMouseTracking( true ); |
655 | viewport()->setFocusProxy(this); | 655 | viewport()->setFocusProxy(this); |
656 | viewport()->setFocusPolicy(WheelFocus); | 656 | viewport()->setFocusPolicy(WheelFocus); |
657 | viewport()->setBackgroundMode(PaletteBase); | 657 | viewport()->setBackgroundMode(PaletteBase); |
658 | 658 | ||
659 | connect( d->mTimer, SIGNAL(timeout()), this, SLOT(tryShowFullText()) ); | 659 | connect( d->mTimer, SIGNAL(timeout()), this, SLOT(tryShowFullText()) ); |
660 | 660 | ||
661 | //US setBackgroundMode(PaletteBackground, PaletteBase); | 661 | //US setBackgroundMode(PaletteBackground, PaletteBase); |
662 | setBackgroundMode(PaletteBackground); | 662 | setBackgroundMode(PaletteBackground); |
663 | 663 | ||
664 | // no reason for a vertical scrollbar | 664 | // no reason for a vertical scrollbar |
665 | setVScrollBarMode(AlwaysOff); | 665 | setVScrollBarMode(AlwaysOff); |
666 | } | 666 | } |
667 | 667 | ||
668 | CardView::~CardView() | 668 | CardView::~CardView() |
669 | { | 669 | { |
670 | delete d->mFm; | 670 | delete d->mFm; |
671 | delete d->mBFm; | 671 | delete d->mBFm; |
672 | delete d; | 672 | delete d; |
673 | d = 0; | 673 | d = 0; |
674 | } | 674 | } |
675 | 675 | ||
676 | void CardView::insertItem(CardViewItem *item) | 676 | void CardView::insertItem(CardViewItem *item) |
677 | { | 677 | { |
678 | d->mItemList.inSort(item); | 678 | d->mItemList.inSort(item); |
679 | setLayoutDirty(true); | 679 | setLayoutDirty(true); |
680 | } | 680 | } |
681 | 681 | ||
682 | void CardView::takeItem(CardViewItem *item) | 682 | void CardView::takeItem(CardViewItem *item) |
683 | { | 683 | { |
684 | if ( d->mCurrentItem == item ) | 684 | if ( d->mCurrentItem == item ) |
685 | d->mCurrentItem = item->nextItem(); | 685 | d->mCurrentItem = item->nextItem(); |
686 | d->mItemList.take(d->mItemList.findRef(item)); | 686 | d->mItemList.take(d->mItemList.findRef(item)); |
687 | 687 | ||
688 | setLayoutDirty(true); | 688 | setLayoutDirty(true); |
689 | } | 689 | } |
690 | 690 | ||
691 | void CardView::clear() | 691 | void CardView::clear() |
692 | { | 692 | { |
693 | d->mItemList.clear(); | 693 | d->mItemList.clear(); |
694 | 694 | ||
695 | setLayoutDirty(true); | 695 | setLayoutDirty(true); |
696 | } | 696 | } |
697 | 697 | ||
698 | CardViewItem *CardView::currentItem() | 698 | CardViewItem *CardView::currentItem() |
699 | { | 699 | { |
700 | if ( ! d->mCurrentItem && d->mItemList.count() ) | 700 | if ( ! d->mCurrentItem && d->mItemList.count() ) |
701 | d->mCurrentItem = d->mItemList.first(); | 701 | d->mCurrentItem = d->mItemList.first(); |
702 | return d->mCurrentItem; | 702 | return d->mCurrentItem; |
703 | } | 703 | } |
704 | 704 | ||
705 | void CardView::setCurrentItem( CardViewItem *item ) | 705 | void CardView::setCurrentItem( CardViewItem *item ) |
706 | { | 706 | { |
707 | if ( !item ) | 707 | if ( !item ) |
708 | return; | 708 | return; |
709 | else if ( item->cardView() != this ) | 709 | else if ( item->cardView() != this ) |
710 | { | 710 | { |
711 | kdDebug(5720)<<"CardView::setCurrentItem: Item ("<<item<<") not owned! Backing out.."<<endl; | 711 | kdDebug(5720)<<"CardView::setCurrentItem: Item ("<<item<<") not owned! Backing out.."<<endl; |
712 | return; | 712 | return; |
713 | } | 713 | } |
714 | else if ( item == currentItem() ) | 714 | else if ( item == currentItem() ) |
715 | { | 715 | { |
716 | return; | 716 | return; |
717 | } | 717 | } |
718 | 718 | ||
719 | if ( d->mSelectionMode == Single ) | 719 | if ( d->mSelectionMode == Single ) |
720 | { | 720 | { |
721 | setSelected( item, true ); | 721 | setSelected( item, true ); |
722 | } | 722 | } |
723 | else | 723 | else |
724 | { | 724 | { |
725 | CardViewItem *it = d->mCurrentItem; | 725 | CardViewItem *it = d->mCurrentItem; |
726 | d->mCurrentItem = item; | 726 | d->mCurrentItem = item; |
727 | if ( it ) | 727 | if ( it ) |
728 | it->repaintCard(); | 728 | it->repaintCard(); |
729 | item->repaintCard(); | 729 | item->repaintCard(); |
730 | } | 730 | } |
731 | if ( ! d->mOnSeparator ) | 731 | if ( ! d->mOnSeparator ) |
732 | ensureItemVisible( item ); | 732 | ensureItemVisible( item ); |
733 | emit currentChanged( item ); | 733 | emit currentChanged( item ); |
734 | } | 734 | } |
735 | 735 | ||
736 | CardViewItem *CardView::itemAt(const QPoint &viewPos) | 736 | CardViewItem *CardView::itemAt(const QPoint &viewPos) |
737 | { | 737 | { |
738 | CardViewItem *item = 0; | 738 | CardViewItem *item = 0; |
739 | QPtrListIterator<CardViewItem> iter(d->mItemList); | 739 | QPtrListIterator<CardViewItem> iter(d->mItemList); |
740 | bool found = false; | 740 | bool found = false; |
741 | for (iter.toFirst(); iter.current() && !found; ++iter) | 741 | for (iter.toFirst(); iter.current() && !found; ++iter) |
742 | { | 742 | { |
743 | item = *iter; | 743 | item = *iter; |
744 | //if (item->d->mRect.contains(viewPos)) | 744 | //if (item->d->mRect.contains(viewPos)) |
745 | if (QRect(item->d->x, item->d->y, d->mItemWidth, item->height()).contains(viewPos)) | 745 | if (QRect(item->d->x, item->d->y, d->mItemWidth, item->height()).contains(viewPos)) |
746 | found = true; | 746 | found = true; |
747 | } | 747 | } |
748 | 748 | ||
749 | if (found) | 749 | if (found) |
750 | return item; | 750 | return item; |
751 | 751 | ||
752 | return 0; | 752 | return 0; |
753 | } | 753 | } |
754 | 754 | ||
755 | QRect CardView::itemRect(const CardViewItem *item) | 755 | QRect CardView::itemRect(const CardViewItem *item) |
756 | { | 756 | { |
757 | //return item->d->mRect; | 757 | //return item->d->mRect; |
758 | return QRect(item->d->x, item->d->y, d->mItemWidth, item->height()); | 758 | return QRect(item->d->x, item->d->y, d->mItemWidth, item->height()); |
759 | } | 759 | } |
760 | 760 | ||
761 | void CardView::ensureItemVisible(const CardViewItem *item) | 761 | void CardView::ensureItemVisible(const CardViewItem *item) |
762 | { | 762 | { |
763 | ensureVisible(item->d->x , item->d->y, d->mItemSpacing, 0); | 763 | ensureVisible(item->d->x , item->d->y, d->mItemSpacing, 0); |
764 | ensureVisible(item->d->x + d->mItemWidth, item->d->y, d->mItemSpacing, 0); | 764 | ensureVisible(item->d->x + d->mItemWidth, item->d->y, d->mItemSpacing, 0); |
765 | } | 765 | } |
766 | 766 | ||
767 | void CardView::repaintItem(const CardViewItem *item) | 767 | void CardView::repaintItem(const CardViewItem *item) |
768 | { | 768 | { |
769 | //repaintContents(item->d->mRect); | 769 | //repaintContents(item->d->mRect); |
770 | repaintContents( QRect(item->d->x, item->d->y, d->mItemWidth, item->height()) ); | 770 | repaintContents( QRect(item->d->x, item->d->y, d->mItemWidth, item->height()) ); |
771 | } | 771 | } |
772 | 772 | ||
773 | void CardView::setSelectionMode(CardView::SelectionMode mode) | 773 | void CardView::setSelectionMode(CardView::SelectionMode mode) |
774 | { | 774 | { |
775 | selectAll(false); | 775 | selectAll(false); |
776 | 776 | ||
777 | d->mSelectionMode = mode; | 777 | d->mSelectionMode = mode; |
778 | } | 778 | } |
779 | 779 | ||
780 | CardView::SelectionMode CardView::selectionMode() const | 780 | CardView::SelectionMode CardView::selectionMode() const |
781 | { | 781 | { |
782 | return d->mSelectionMode; | 782 | return d->mSelectionMode; |
783 | } | 783 | } |
784 | 784 | ||
785 | void CardView::selectAll(bool state) | 785 | void CardView::selectAll(bool state) |
786 | { | 786 | { |
787 | QPtrListIterator<CardViewItem> iter(d->mItemList); | 787 | QPtrListIterator<CardViewItem> iter(d->mItemList); |
788 | if (!state) | 788 | if (!state) |
789 | { | 789 | { |
790 | for (iter.toFirst(); iter.current(); ++iter) | 790 | for (iter.toFirst(); iter.current(); ++iter) |
791 | { | 791 | { |
792 | if ((*iter)->isSelected()) | 792 | if ((*iter)->isSelected()) |
793 | { | 793 | { |
794 | (*iter)->setSelected(false); | 794 | (*iter)->setSelected(false); |
795 | (*iter)->repaintCard(); | 795 | (*iter)->repaintCard(); |
796 | } | 796 | } |
797 | } | 797 | } |
798 | //emit selectionChanged(); // WARNING FIXME | 798 | //emit selectionChanged(); // WARNING FIXME |
799 | emit selectionChanged(0); | 799 | emit selectionChanged(0); |
800 | } | 800 | } |
801 | else if (d->mSelectionMode != CardView::Single) | 801 | else if (d->mSelectionMode != CardView::Single) |
802 | { | 802 | { |
803 | for (iter.toFirst(); iter.current(); ++iter) | 803 | for (iter.toFirst(); iter.current(); ++iter) |
804 | { | 804 | { |
805 | (*iter)->setSelected(true); | 805 | (*iter)->setSelected(true); |
806 | } | 806 | } |
807 | 807 | ||
808 | if (d->mItemList.count() > 0) | 808 | if (d->mItemList.count() > 0) |
809 | { | 809 | { |
810 | // emit, since there must have been at least one selected | 810 | // emit, since there must have been at least one selected |
811 | emit selectionChanged(); | 811 | emit selectionChanged(); |
812 | //repaint();//??? | 812 | //repaint();//??? |
813 | viewport()->update(); | 813 | viewport()->update(); |
814 | } | 814 | } |
815 | } | 815 | } |
816 | } | 816 | } |
817 | 817 | ||
818 | void CardView::setSelected(CardViewItem *item, bool selected) | 818 | void CardView::setSelected(CardViewItem *item, bool selected) |
819 | { | 819 | { |
820 | if ((item == 0) || (item->isSelected() == selected)) | 820 | if ((item == 0) || (item->isSelected() == selected)) |
821 | return; | 821 | return; |
822 | 822 | ||
823 | if ( selected && d->mCurrentItem != item ) | 823 | if ( selected && d->mCurrentItem != item ) |
824 | { | 824 | { |
825 | CardViewItem *it = d->mCurrentItem; | 825 | CardViewItem *it = d->mCurrentItem; |
826 | d->mCurrentItem = item; | 826 | d->mCurrentItem = item; |
827 | if ( it ) | 827 | if ( it ) |
828 | it->repaintCard(); | 828 | it->repaintCard(); |
829 | } | 829 | } |
830 | 830 | ||
831 | if (d->mSelectionMode == CardView::Single) | 831 | if (d->mSelectionMode == CardView::Single) |
832 | { | 832 | { |
833 | bool b = signalsBlocked(); | 833 | bool b = signalsBlocked(); |
834 | blockSignals(true); | 834 | blockSignals(true); |
835 | selectAll(false); | 835 | selectAll(false); |
836 | blockSignals(b); | 836 | blockSignals(b); |
837 | 837 | ||
838 | if (selected) | 838 | if (selected) |
839 | { | 839 | { |
840 | item->setSelected(selected); | 840 | item->setSelected(selected); |
841 | item->repaintCard(); | 841 | item->repaintCard(); |
842 | emit selectionChanged(); | 842 | emit selectionChanged(); |
843 | emit selectionChanged(item); | 843 | emit selectionChanged(item); |
844 | } | 844 | } |
845 | else | 845 | else |
846 | { | 846 | { |
847 | emit selectionChanged(); | 847 | emit selectionChanged(); |
848 | emit selectionChanged(0); | 848 | emit selectionChanged(0); |
849 | } | 849 | } |
850 | } | 850 | } |
851 | else if (d->mSelectionMode == CardView::Multi) | 851 | else if (d->mSelectionMode == CardView::Multi) |
852 | { | 852 | { |
853 | item->setSelected(selected); | 853 | item->setSelected(selected); |
854 | item->repaintCard(); | 854 | item->repaintCard(); |
855 | emit selectionChanged(); | 855 | emit selectionChanged(); |
856 | } | 856 | } |
857 | else if (d->mSelectionMode == CardView::Extended) | 857 | else if (d->mSelectionMode == CardView::Extended) |
858 | { | 858 | { |
859 | bool b = signalsBlocked(); | 859 | bool b = signalsBlocked(); |
860 | blockSignals(true); | 860 | blockSignals(true); |
861 | selectAll(false); | 861 | selectAll(false); |
862 | blockSignals(b); | 862 | blockSignals(b); |
863 | 863 | ||
864 | item->setSelected(selected); | 864 | item->setSelected(selected); |
865 | item->repaintCard(); | 865 | item->repaintCard(); |
866 | emit selectionChanged(); | 866 | emit selectionChanged(); |
867 | } | 867 | } |
868 | } | 868 | } |
869 | 869 | ||
870 | bool CardView::isSelected(CardViewItem *item) const | 870 | bool CardView::isSelected(CardViewItem *item) const |
871 | { | 871 | { |
872 | return (item && item->isSelected()); | 872 | return (item && item->isSelected()); |
873 | } | 873 | } |
874 | 874 | ||
875 | CardViewItem *CardView::selectedItem() const | 875 | CardViewItem *CardView::selectedItem() const |
876 | { | 876 | { |
877 | // find the first selected item | 877 | // find the first selected item |
878 | QPtrListIterator<CardViewItem> iter(d->mItemList); | 878 | QPtrListIterator<CardViewItem> iter(d->mItemList); |
879 | for (iter.toFirst(); iter.current(); ++iter) | 879 | for (iter.toFirst(); iter.current(); ++iter) |
880 | { | 880 | { |
881 | if ((*iter)->isSelected()) | 881 | if ((*iter)->isSelected()) |
882 | return *iter; | 882 | return *iter; |
883 | } | 883 | } |
884 | 884 | ||
885 | return 0; | 885 | return 0; |
886 | } | 886 | } |
887 | 887 | ||
888 | CardViewItem *CardView::firstItem() const | 888 | CardViewItem *CardView::firstItem() const |
889 | { | 889 | { |
890 | return d->mItemList.first(); | 890 | return d->mItemList.first(); |
891 | } | 891 | } |
892 | 892 | ||
893 | int CardView::childCount() const | 893 | int CardView::childCount() const |
894 | { | 894 | { |
895 | return d->mItemList.count(); | 895 | return d->mItemList.count(); |
896 | } | 896 | } |
897 | /*US | 897 | /*US |
898 | CardViewItem *CardView::findItem(const QString &text, const QString &label, | 898 | CardViewItem *CardView::findItem(const QString &text, const QString &label, |
899 | Qt::StringComparisonMode compare) | 899 | Qt::StringComparisonMode compare) |
900 | { | 900 | { |
901 | // IF the text is empty, we will return null, since empty text will | 901 | // IF the text is empty, we will return null, since empty text will |
902 | // match anything! | 902 | // match anything! |
903 | if (text.isEmpty()) | 903 | if (text.isEmpty()) |
904 | return 0; | 904 | return 0; |
905 | 905 | ||
906 | QPtrListIterator<CardViewItem> iter(d->mItemList); | 906 | QPtrListIterator<CardViewItem> iter(d->mItemList); |
907 | if (compare & Qt::BeginsWith) | 907 | if (compare & Qt::BeginsWith) |
908 | { | 908 | { |
909 | QString value; | 909 | QString value; |
910 | for (iter.toFirst(); iter.current(); ++iter) | 910 | for (iter.toFirst(); iter.current(); ++iter) |
911 | { | 911 | { |
912 | value = (*iter)->fieldValue(label).upper(); | 912 | value = (*iter)->fieldValue(label).upper(); |
913 | if (value.startsWith(text.upper())) | 913 | if (value.startsWith(text.upper())) |
914 | return *iter; | 914 | return *iter; |
915 | } | 915 | } |
916 | } | 916 | } |
917 | else | 917 | else |
918 | { | 918 | { |
919 | kdDebug(5720) << "CardView::findItem: search method not implemented" << endl; | 919 | kdDebug(5720) << "CardView::findItem: search method not implemented" << endl; |
920 | } | 920 | } |
921 | 921 | ||
922 | return 0; | 922 | return 0; |
923 | } | 923 | } |
924 | */ | 924 | */ |
925 | 925 | ||
926 | uint CardView::columnWidth() | 926 | uint CardView::columnWidth() |
927 | { | 927 | { |
928 | return d->mDrawSeparators ? | 928 | return d->mDrawSeparators ? |
929 | d->mItemWidth + ( 2 * d->mItemSpacing ) + d->mSepWidth : | 929 | d->mItemWidth + ( 2 * d->mItemSpacing ) + d->mSepWidth : |
930 | d->mItemWidth + d->mItemSpacing; | 930 | d->mItemWidth + d->mItemSpacing; |
931 | } | 931 | } |
932 | 932 | ||
933 | void CardView::drawContents(QPainter *p, int clipx, int clipy, | 933 | void CardView::drawContents(QPainter *p, int clipx, int clipy, |
934 | int clipw, int cliph) | 934 | int clipw, int cliph) |
935 | { | 935 | { |
936 | QScrollView::drawContents(p, clipx, clipy, clipw, cliph); | 936 | QScrollView::drawContents(p, clipx, clipy, clipw, cliph); |
937 | 937 | ||
938 | if (d->mLayoutDirty) | 938 | if (d->mLayoutDirty) |
939 | calcLayout(); | 939 | calcLayout(); |
940 | 940 | ||
941 | //kdDebug() << "CardView::drawContents: " << clipx << ", " << clipy | 941 | //kdDebug() << "CardView::drawContents: " << clipx << ", " << clipy |
942 | // << ", " << clipw << ", " << cliph << endl; | 942 | // << ", " << clipw << ", " << cliph << endl; |
943 | 943 | ||
944 | QColorGroup cg = viewport()->palette().active(); // allow setting costum colors in the viewport pale | 944 | QColorGroup cg = viewport()->palette().active(); // allow setting costum colors in the viewport pale |
945 | 945 | ||
946 | QRect clipRect(clipx, clipy, clipw, cliph); | 946 | QRect clipRect(clipx, clipy, clipw, cliph); |
947 | QRect cardRect; | 947 | QRect cardRect; |
948 | QRect sepRect; | 948 | QRect sepRect; |
949 | CardViewItem *item; | 949 | CardViewItem *item; |
950 | CardViewSeparator *sep; | 950 | CardViewSeparator *sep; |
951 | 951 | ||
952 | // make sure the viewport is a pure background | 952 | // make sure the viewport is a pure background |
953 | viewport()->erase(clipRect); | 953 | viewport()->erase(clipRect); |
954 | 954 | ||
955 | // Now tell the cards to draw, if they are in the clip region | 955 | // Now tell the cards to draw, if they are in the clip region |
956 | QPtrListIterator<CardViewItem> iter(d->mItemList); | 956 | QPtrListIterator<CardViewItem> iter(d->mItemList); |
957 | for (iter.toFirst(); iter.current(); ++iter) | 957 | for (iter.toFirst(); iter.current(); ++iter) |
958 | { | 958 | { |
959 | item = *iter; | 959 | item = *iter; |
960 | cardRect.setRect( item->d->x, item->d->y, d->mItemWidth, item->height() ); | 960 | cardRect.setRect( item->d->x, item->d->y, d->mItemWidth, item->height() ); |
961 | 961 | ||
962 | if (clipRect.intersects(cardRect) || clipRect.contains(cardRect)) | 962 | if (clipRect.intersects(cardRect) || clipRect.contains(cardRect)) |
963 | { | 963 | { |
964 | //kdDebug() << "\trepainting card at: " << cardRect.x() << ", " | 964 | //kdDebug() << "\trepainting card at: " << cardRect.x() << ", " |
965 | // << cardRect.y() << endl; | 965 | // << cardRect.y() << endl; |
966 | 966 | ||
967 | // Tell the card to paint | 967 | // Tell the card to paint |
968 | p->save(); | 968 | p->save(); |
969 | p->translate(cardRect.x(), cardRect.y()); | 969 | p->translate(cardRect.x(), cardRect.y()); |
970 | item->paintCard(p, cg); | 970 | item->paintCard(p, cg); |
971 | p->restore(); | 971 | p->restore(); |
972 | } | 972 | } |
973 | } | 973 | } |
974 | 974 | ||
975 | // Followed by the separators if they are in the clip region | 975 | // Followed by the separators if they are in the clip region |
976 | QPtrListIterator<CardViewSeparator> sepIter(d->mSeparatorList); | 976 | QPtrListIterator<CardViewSeparator> sepIter(d->mSeparatorList); |
977 | for (sepIter.toFirst(); sepIter.current(); ++sepIter) | 977 | for (sepIter.toFirst(); sepIter.current(); ++sepIter) |
978 | { | 978 | { |
979 | sep = *sepIter; | 979 | sep = *sepIter; |
980 | sepRect = sep->mRect; | 980 | sepRect = sep->mRect; |
981 | 981 | ||
982 | if (clipRect.intersects(sepRect) || clipRect.contains(sepRect)) | 982 | if (clipRect.intersects(sepRect) || clipRect.contains(sepRect)) |
983 | { | 983 | { |
984 | p->save(); | 984 | p->save(); |
985 | p->translate(sepRect.x(), sepRect.y()); | 985 | p->translate(sepRect.x(), sepRect.y()); |
986 | sep->paintSeparator(p, cg); | 986 | sep->paintSeparator(p, cg); |
987 | p->restore(); | 987 | p->restore(); |
988 | } | 988 | } |
989 | } | 989 | } |
990 | } | 990 | } |
991 | 991 | ||
992 | void CardView::resizeEvent(QResizeEvent *e) | 992 | void CardView::resizeEvent(QResizeEvent *e) |
993 | { | 993 | { |
994 | QScrollView::resizeEvent(e); | 994 | QScrollView::resizeEvent(e); |
995 | 995 | ||
996 | setLayoutDirty(true); | 996 | setLayoutDirty(true); |
997 | } | 997 | } |
998 | 998 | ||
999 | void CardView::calcLayout() | 999 | void CardView::calcLayout() |
1000 | { | 1000 | { |
1001 | //kdDebug() << "CardView::calcLayout:" << endl; | 1001 | //kdDebug() << "CardView::calcLayout:" << endl; |
1002 | 1002 | ||
1003 | // Start in the upper left corner and layout all the | 1003 | // Start in the upper left corner and layout all the |
1004 | // cars using their height and width | 1004 | // cars using their height and width |
1005 | int maxWidth = 0; | 1005 | int maxWidth = 0; |
1006 | int maxHeight = 0; | 1006 | int maxHeight = 0; |
1007 | int xPos = 0; | 1007 | int xPos = 0; |
1008 | int yPos = 0; | 1008 | int yPos = 0; |
1009 | int cardSpacing = d->mItemSpacing; | 1009 | int cardSpacing = d->mItemSpacing; |
1010 | 1010 | ||
1011 | // delete the old separators | 1011 | // delete the old separators |
1012 | d->mSeparatorList.clear(); | 1012 | d->mSeparatorList.clear(); |
1013 | 1013 | ||
1014 | QPtrListIterator<CardViewItem> iter(d->mItemList); | 1014 | QPtrListIterator<CardViewItem> iter(d->mItemList); |
1015 | CardViewItem *item = 0; | 1015 | CardViewItem *item = 0; |
1016 | CardViewSeparator *sep = 0; | 1016 | CardViewSeparator *sep = 0; |
1017 | xPos += cardSpacing; | 1017 | xPos += cardSpacing; |
1018 | 1018 | ||
1019 | for (iter.toFirst(); iter.current(); ++iter) | 1019 | for (iter.toFirst(); iter.current(); ++iter) |
1020 | { | 1020 | { |
1021 | item = *iter; | 1021 | item = *iter; |
1022 | 1022 | ||
1023 | yPos += cardSpacing; | 1023 | yPos += cardSpacing; |
1024 | 1024 | ||
1025 | if (yPos + item->height() + cardSpacing >= height() - horizontalScrollBar()->height()) | 1025 | if (yPos + item->height() + cardSpacing >= height() - horizontalScrollBar()->height()) |
1026 | { | 1026 | { |
1027 | maxHeight = QMAX(maxHeight, yPos); | 1027 | maxHeight = QMAX(maxHeight, yPos); |
1028 | 1028 | ||
1029 | // Drawing in this column would be greater than the height | 1029 | // Drawing in this column would be greater than the height |
1030 | // of the scroll view, so move to next column | 1030 | // of the scroll view, so move to next column |
1031 | yPos = cardSpacing; | 1031 | yPos = cardSpacing; |
1032 | xPos += cardSpacing + maxWidth; | 1032 | xPos += cardSpacing + maxWidth; |
1033 | if (d->mDrawSeparators) | 1033 | if (d->mDrawSeparators) |
1034 | { | 1034 | { |
1035 | // Create a separator since the user asked | 1035 | // Create a separator since the user asked |
1036 | sep = new CardViewSeparator(this); | 1036 | sep = new CardViewSeparator(this); |
1037 | sep->mRect.moveTopLeft(QPoint(xPos, yPos+d->mItemMargin)); | 1037 | sep->mRect.moveTopLeft(QPoint(xPos, yPos+d->mItemMargin)); |
1038 | xPos += d->mSepWidth + cardSpacing; | 1038 | xPos += d->mSepWidth + cardSpacing; |
1039 | d->mSeparatorList.append(sep); | 1039 | d->mSeparatorList.append(sep); |
1040 | } | 1040 | } |
1041 | 1041 | ||
1042 | maxWidth = 0; | 1042 | maxWidth = 0; |
1043 | } | 1043 | } |
1044 | 1044 | ||
1045 | item->d->x = xPos; | 1045 | item->d->x = xPos; |
1046 | item->d->y = yPos; | 1046 | item->d->y = yPos; |
1047 | 1047 | ||
1048 | yPos += item->height(); | 1048 | yPos += item->height(); |
1049 | maxWidth = QMAX(maxWidth, d->mItemWidth); | 1049 | maxWidth = QMAX(maxWidth, d->mItemWidth); |
1050 | } | 1050 | } |
1051 | 1051 | ||
1052 | xPos += maxWidth; | 1052 | xPos += maxWidth; |
1053 | resizeContents( xPos + cardSpacing, maxHeight ); | 1053 | resizeContents( xPos + cardSpacing, maxHeight ); |
1054 | 1054 | ||
1055 | // Update the height of all the separators now that we know the | 1055 | // Update the height of all the separators now that we know the |
1056 | // max height of a column | 1056 | // max height of a column |
1057 | QPtrListIterator<CardViewSeparator> sepIter(d->mSeparatorList); | 1057 | QPtrListIterator<CardViewSeparator> sepIter(d->mSeparatorList); |
1058 | for (sepIter.toFirst(); sepIter.current(); ++sepIter) | 1058 | for (sepIter.toFirst(); sepIter.current(); ++sepIter) |
1059 | { | 1059 | { |
1060 | (*sepIter)->mRect.setHeight(maxHeight - 2*cardSpacing - 2*d->mItemMargin); | 1060 | (*sepIter)->mRect.setHeight(maxHeight - 2*cardSpacing - 2*d->mItemMargin); |
1061 | } | 1061 | } |
1062 | 1062 | ||
1063 | d->mLayoutDirty = false; | 1063 | d->mLayoutDirty = false; |
1064 | } | 1064 | } |
1065 | 1065 | ||
1066 | CardViewItem *CardView::itemAfter(CardViewItem *item) | 1066 | CardViewItem *CardView::itemAfter(CardViewItem *item) |
1067 | { | 1067 | { |
1068 | /*int pos = */d->mItemList.findRef(item); | 1068 | /*int pos = */d->mItemList.findRef(item); |
1069 | return d->mItemList.next();//at(pos+1); | 1069 | return d->mItemList.next();//at(pos+1); |
1070 | } | 1070 | } |
1071 | 1071 | ||
1072 | uint CardView::itemMargin() | 1072 | uint CardView::itemMargin() |
1073 | { | 1073 | { |
1074 | return d->mItemMargin; | 1074 | return d->mItemMargin; |
1075 | } | 1075 | } |
1076 | 1076 | ||
1077 | void CardView::setItemMargin( uint margin ) | 1077 | void CardView::setItemMargin( uint margin ) |
1078 | { | 1078 | { |
1079 | if ( margin == d->mItemMargin ) | 1079 | if ( margin == d->mItemMargin ) |
1080 | return; | 1080 | return; |
1081 | 1081 | ||
1082 | d->mItemMargin = margin; | 1082 | d->mItemMargin = margin; |
1083 | setLayoutDirty( true ); | 1083 | setLayoutDirty( true ); |
1084 | } | 1084 | } |
1085 | 1085 | ||
1086 | uint CardView::itemSpacing() | 1086 | uint CardView::itemSpacing() |
1087 | { | 1087 | { |
1088 | return d->mItemSpacing; | 1088 | return d->mItemSpacing; |
1089 | } | 1089 | } |
1090 | 1090 | ||
1091 | void CardView::setItemSpacing( uint spacing ) | 1091 | void CardView::setItemSpacing( uint spacing ) |
1092 | { | 1092 | { |
1093 | if ( spacing == d->mItemSpacing ) | 1093 | if ( spacing == d->mItemSpacing ) |
1094 | return; | 1094 | return; |
1095 | 1095 | ||
1096 | d->mItemSpacing = spacing; | 1096 | d->mItemSpacing = spacing; |
1097 | setLayoutDirty( true ); | 1097 | setLayoutDirty( true ); |
1098 | } | 1098 | } |
1099 | 1099 | ||
1100 | void CardView::contentsMousePressEvent(QMouseEvent *e) | 1100 | void CardView::contentsMousePressEvent(QMouseEvent *e) |
1101 | { | 1101 | { |
1102 | QScrollView::contentsMousePressEvent(e); | 1102 | QScrollView::contentsMousePressEvent(e); |
1103 | 1103 | ||
1104 | QPoint pos = e->pos(); | 1104 | QPoint pos = e->pos(); |
1105 | d->mLastClickPos = pos; | 1105 | d->mLastClickPos = pos; |
1106 | 1106 | ||
1107 | CardViewItem *item = itemAt(pos); | 1107 | CardViewItem *item = itemAt(pos); |
1108 | 1108 | ||
1109 | if (item == 0) | 1109 | if (item == 0) |
1110 | { | 1110 | { |
1111 | d->mLastClickOnItem = false; | 1111 | d->mLastClickOnItem = false; |
1112 | if ( d->mOnSeparator) | 1112 | if ( d->mOnSeparator) |
1113 | { | 1113 | { |
1114 | d->mResizeAnchor = e->x()+contentsX(); | 1114 | d->mResizeAnchor = e->x()+contentsX(); |
1115 | d->colspace = (2*d->mItemSpacing) /*+ (2*d->mItemMargin)*/; | 1115 | d->colspace = (2*d->mItemSpacing) /*+ (2*d->mItemMargin)*/; |
1116 | int ccw = d->mItemWidth + d->colspace + d->mSepWidth; | 1116 | int ccw = d->mItemWidth + d->colspace + d->mSepWidth; |
1117 | d->first = (contentsX()+d->mSepWidth)/ccw; | 1117 | d->first = (contentsX()+d->mSepWidth)/ccw; |
1118 | d->pressed = (d->mResizeAnchor+d->mSepWidth)/ccw; | 1118 | d->pressed = (d->mResizeAnchor+d->mSepWidth)/ccw; |
1119 | d->span = d->pressed - d->first; | 1119 | d->span = d->pressed - d->first; |
1120 | d->firstX = d->first * ccw; | 1120 | d->firstX = d->first * ccw; |
1121 | if ( d->firstX ) d->firstX -= d->mSepWidth; // (no sep in col 0) | 1121 | if ( d->firstX ) d->firstX -= d->mSepWidth; // (no sep in col 0) |
1122 | } | 1122 | } |
1123 | else | 1123 | else |
1124 | { | 1124 | { |
1125 | selectAll(false); | 1125 | selectAll(false); |
1126 | } | 1126 | } |
1127 | return; | 1127 | return; |
1128 | } | 1128 | } |
1129 | 1129 | ||
1130 | d->mLastClickOnItem = true; | 1130 | d->mLastClickOnItem = true; |
1131 | 1131 | ||
1132 | CardViewItem *other = d->mCurrentItem; | 1132 | CardViewItem *other = d->mCurrentItem; |
1133 | setCurrentItem( item ); | 1133 | setCurrentItem( item ); |
1134 | 1134 | ||
1135 | // Always emit the selection | 1135 | // Always emit the selection |
1136 | emit clicked(item); | 1136 | emit clicked(item); |
1137 | 1137 | ||
1138 | // Check the selection type and update accordingly | 1138 | // Check the selection type and update accordingly |
1139 | if (d->mSelectionMode == CardView::Single) | 1139 | if (d->mSelectionMode == CardView::Single) |
1140 | { | 1140 | { |
1141 | // make sure it isn't already selected | 1141 | // make sure it isn't already selected |
1142 | if (item->isSelected()) | 1142 | if (item->isSelected()) |
1143 | return; | 1143 | return; |
1144 | 1144 | ||
1145 | bool b = signalsBlocked(); | 1145 | bool b = signalsBlocked(); |
1146 | blockSignals(true); | 1146 | blockSignals(true); |
1147 | selectAll(false); | 1147 | selectAll(false); |
1148 | blockSignals(b); | 1148 | blockSignals(b); |
1149 | 1149 | ||
1150 | item->setSelected(true); | 1150 | item->setSelected(true); |
1151 | item->repaintCard(); | 1151 | item->repaintCard(); |
1152 | emit selectionChanged(item); | 1152 | emit selectionChanged(item); |
1153 | } | 1153 | } |
1154 | 1154 | ||
1155 | else if (d->mSelectionMode == CardView::Multi) | 1155 | else if (d->mSelectionMode == CardView::Multi) |
1156 | { | 1156 | { |
1157 | // toggle the selection | 1157 | // toggle the selection |
1158 | item->setSelected(!item->isSelected()); | 1158 | item->setSelected(!item->isSelected()); |
1159 | item->repaintCard(); | 1159 | item->repaintCard(); |
1160 | emit selectionChanged(); | 1160 | emit selectionChanged(); |
1161 | } | 1161 | } |
1162 | 1162 | ||
1163 | else if (d->mSelectionMode == CardView::Extended) | 1163 | else if (d->mSelectionMode == CardView::Extended) |
1164 | { | 1164 | { |
1165 | if ((e->button() & Qt::LeftButton) && | 1165 | if ((e->button() & Qt::LeftButton) && |
1166 | (e->state() & Qt::ShiftButton)) | 1166 | (e->state() & Qt::ShiftButton)) |
1167 | { | 1167 | { |
1168 | if ( item == other ) return; | 1168 | if ( item == other ) return; |
1169 | 1169 | ||
1170 | bool s = ! item->isSelected(); | 1170 | bool s = ! item->isSelected(); |
1171 | 1171 | ||
1172 | if ( s && ! (e->state() & ControlButton) ) | 1172 | if ( s && ! (e->state() & ControlButton) ) |
1173 | { | 1173 | { |
1174 | bool b = signalsBlocked(); | 1174 | bool b = signalsBlocked(); |
1175 | blockSignals(true); | 1175 | blockSignals(true); |
1176 | selectAll(false); | 1176 | selectAll(false); |
1177 | blockSignals(b); | 1177 | blockSignals(b); |
1178 | } | 1178 | } |
1179 | 1179 | ||
1180 | int from, to, a, b; | 1180 | int from, to, a, b; |
1181 | a = d->mItemList.findRef( item ); | 1181 | a = d->mItemList.findRef( item ); |
1182 | b = d->mItemList.findRef( other ); | 1182 | b = d->mItemList.findRef( other ); |
1183 | from = a < b ? a : b; | 1183 | from = a < b ? a : b; |
1184 | to = a > b ? a : b; | 1184 | to = a > b ? a : b; |
1185 | //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl; | 1185 | //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl; |
1186 | CardViewItem *aItem; | 1186 | CardViewItem *aItem; |
1187 | for ( ; from <= to; from++ ) | 1187 | for ( ; from <= to; from++ ) |
1188 | { | 1188 | { |
1189 | aItem = d->mItemList.at( from ); | 1189 | aItem = d->mItemList.at( from ); |
1190 | aItem->setSelected( s ); | 1190 | aItem->setSelected( s ); |
1191 | repaintItem( aItem ); | 1191 | repaintItem( aItem ); |
1192 | } | 1192 | } |
1193 | emit selectionChanged(); | 1193 | emit selectionChanged(); |
1194 | } | 1194 | } |
1195 | else if ((e->button() & Qt::LeftButton) && | 1195 | else if ((e->button() & Qt::LeftButton) && |
1196 | (e->state() & Qt::ControlButton)) | 1196 | (e->state() & Qt::ControlButton)) |
1197 | { | 1197 | { |
1198 | item->setSelected(!item->isSelected()); | 1198 | item->setSelected(!item->isSelected()); |
1199 | item->repaintCard(); | 1199 | item->repaintCard(); |
1200 | emit selectionChanged(); | 1200 | emit selectionChanged(); |
1201 | } | 1201 | } |
1202 | 1202 | ||
1203 | else if (e->button() & Qt::LeftButton) | 1203 | else if (e->button() & Qt::LeftButton) |
1204 | { | 1204 | { |
1205 | bool b = signalsBlocked(); | 1205 | bool b = signalsBlocked(); |
1206 | blockSignals(true); | 1206 | blockSignals(true); |
1207 | selectAll(false); | 1207 | selectAll(false); |
1208 | blockSignals(b); | 1208 | blockSignals(b); |
1209 | 1209 | ||
1210 | item->setSelected(true); | 1210 | item->setSelected(true); |
1211 | item->repaintCard(); | 1211 | item->repaintCard(); |
1212 | emit selectionChanged(); | 1212 | emit selectionChanged(); |
1213 | } | 1213 | } |
1214 | } | 1214 | } |
1215 | 1215 | ||
1216 | } | 1216 | } |
1217 | 1217 | ||
1218 | void CardView::contentsMouseReleaseEvent(QMouseEvent *e) | 1218 | void CardView::contentsMouseReleaseEvent(QMouseEvent *e) |
1219 | { | 1219 | { |
1220 | QScrollView::contentsMouseReleaseEvent(e); | 1220 | QScrollView::contentsMouseReleaseEvent(e); |
1221 | 1221 | ||
1222 | if ( d->mResizeAnchor ) | 1222 | if ( d->mResizeAnchor ) |
1223 | { | 1223 | { |
1224 | // finish the resizing: | 1224 | // finish the resizing: |
1225 | unsetCursor(); | 1225 | unsetCursor(); |
1226 | // hide rubber bands | 1226 | // hide rubber bands |
1227 | int newiw = d->mItemWidth - ((d->mResizeAnchor - d->mRubberBandAnchor)/d->span); | 1227 | int newiw = d->mItemWidth - ((d->mResizeAnchor - d->mRubberBandAnchor)/d->span); |
1228 | drawRubberBands( 0 ); | 1228 | drawRubberBands( 0 ); |
1229 | // we should move to reflect the new position if we are scrolled. | 1229 | // we should move to reflect the new position if we are scrolled. |
1230 | if ( contentsX() ) | 1230 | if ( contentsX() ) |
1231 | { | 1231 | { |
1232 | int newX = QMAX( 0, ( d->pressed * ( newiw + d->colspace + d->mSepWidth ) ) - e->x() ); | 1232 | int newX = QMAX( 0, ( d->pressed * ( newiw + d->colspace + d->mSepWidth ) ) - e->x() ); |
1233 | setContentsPos( newX, contentsY() ); | 1233 | setContentsPos( newX, contentsY() ); |
1234 | } | 1234 | } |
1235 | // set new item width | 1235 | // set new item width |
1236 | setItemWidth( newiw ); | 1236 | setItemWidth( newiw ); |
1237 | // reset anchors | 1237 | // reset anchors |
1238 | d->mResizeAnchor = 0; | 1238 | d->mResizeAnchor = 0; |
1239 | d->mRubberBandAnchor = 0; | 1239 | d->mRubberBandAnchor = 0; |
1240 | return; | 1240 | return; |
1241 | } | 1241 | } |
1242 | 1242 | ||
1243 | // If there are accel keys, we will not emit signals | 1243 | // If there are accel keys, we will not emit signals |
1244 | if ((e->state() & Qt::ShiftButton) || (e->state() & Qt::ControlButton)) | 1244 | if ((e->state() & Qt::ShiftButton) || (e->state() & Qt::ControlButton)) |
1245 | return; | 1245 | return; |
1246 | 1246 | ||
1247 | // Get the item at this position | 1247 | // Get the item at this position |
1248 | CardViewItem *item = itemAt(e->pos()); | 1248 | CardViewItem *item = itemAt(e->pos()); |
1249 | 1249 | ||
1250 | if (item && KABPrefs::instance()->mHonorSingleClick) | 1250 | if (item && KABPrefs::instance()->mHonorSingleClick) |
1251 | { | 1251 | { |
1252 | emit executed(item); | 1252 | emit executed(item); |
1253 | } | 1253 | } |
1254 | } | 1254 | } |
1255 | 1255 | ||
1256 | void CardView::contentsMouseDoubleClickEvent(QMouseEvent *e) | 1256 | void CardView::contentsMouseDoubleClickEvent(QMouseEvent *e) |
1257 | { | 1257 | { |
1258 | QScrollView::contentsMouseDoubleClickEvent(e); | 1258 | QScrollView::contentsMouseDoubleClickEvent(e); |
1259 | 1259 | ||
1260 | CardViewItem *item = itemAt(e->pos()); | 1260 | CardViewItem *item = itemAt(e->pos()); |
1261 | 1261 | ||
1262 | if (item) | 1262 | if (item) |
1263 | { | 1263 | { |
1264 | d->mCurrentItem = item; | 1264 | d->mCurrentItem = item; |
1265 | } | 1265 | } |
1266 | 1266 | ||
1267 | if (item && !KABPrefs::instance()->mHonorSingleClick) | 1267 | if (item && !KABPrefs::instance()->mHonorSingleClick) |
1268 | { | 1268 | { |
1269 | emit executed(item); | 1269 | emit executed(item); |
1270 | } else | 1270 | } else |
1271 | emit doubleClicked(item); | 1271 | emit doubleClicked(item); |
1272 | } | 1272 | } |
1273 | 1273 | ||
1274 | void CardView::contentsMouseMoveEvent( QMouseEvent *e ) | 1274 | void CardView::contentsMouseMoveEvent( QMouseEvent *e ) |
1275 | { | 1275 | { |
1276 | // resizing | 1276 | // resizing |
1277 | if ( d->mResizeAnchor ) | 1277 | if ( d->mResizeAnchor ) |
1278 | { | 1278 | { |
1279 | int x = e->x(); | 1279 | int x = e->x(); |
1280 | if ( x != d->mRubberBandAnchor ) | 1280 | if ( x != d->mRubberBandAnchor ) |
1281 | drawRubberBands( x ); | 1281 | drawRubberBands( x ); |
1282 | return; | 1282 | return; |
1283 | } | 1283 | } |
1284 | 1284 | ||
1285 | if (d->mLastClickOnItem && (e->state() & Qt::LeftButton) && | 1285 | if (d->mLastClickOnItem && (e->state() & Qt::LeftButton) && |
1286 | ((e->pos() - d->mLastClickPos).manhattanLength() > 4)) { | 1286 | ((e->pos() - d->mLastClickPos).manhattanLength() > 4)) { |
1287 | 1287 | ||
1288 | startDrag(); | 1288 | startDrag(); |
1289 | return; | 1289 | return; |
1290 | } | 1290 | } |
1291 | 1291 | ||
1292 | d->mTimer->start( 500 ); | 1292 | d->mTimer->start( 500 ); |
1293 | 1293 | ||
1294 | // see if we are over a separator | 1294 | // see if we are over a separator |
1295 | // only if we actually have them painted? | 1295 | // only if we actually have them painted? |
1296 | if ( d->mDrawSeparators ) | 1296 | if ( d->mDrawSeparators ) |
1297 | { | 1297 | { |
1298 | int colcontentw = d->mItemWidth + (2*d->mItemSpacing); | 1298 | int colcontentw = d->mItemWidth + (2*d->mItemSpacing); |
1299 | int colw = colcontentw + d->mSepWidth; | 1299 | int colw = colcontentw + d->mSepWidth; |
1300 | int m = e->x()%colw; | 1300 | int m = e->x()%colw; |
1301 | if ( m >= colcontentw && m > 0 ) | 1301 | if ( m >= colcontentw && m > 0 ) |
1302 | { | 1302 | { |
1303 | setCursor( SplitVCursor ); // Why does this fail sometimes? | 1303 | setCursor( SplitVCursor ); // Why does this fail sometimes? |
1304 | d->mOnSeparator = true; | 1304 | d->mOnSeparator = true; |
1305 | } | 1305 | } |
1306 | else | 1306 | else |
1307 | { | 1307 | { |
1308 | setCursor( ArrowCursor ); | 1308 | setCursor( ArrowCursor ); |
1309 | d->mOnSeparator = false; | 1309 | d->mOnSeparator = false; |
1310 | } | 1310 | } |
1311 | } | 1311 | } |
1312 | } | 1312 | } |
1313 | 1313 | ||
1314 | void CardView::enterEvent( QEvent * ) | 1314 | void CardView::enterEvent( QEvent * ) |
1315 | { | 1315 | { |
1316 | d->mTimer->start( 500 ); | 1316 | d->mTimer->start( 500 ); |
1317 | } | 1317 | } |
1318 | 1318 | ||
1319 | void CardView::leaveEvent( QEvent * ) | 1319 | void CardView::leaveEvent( QEvent * ) |
1320 | { | 1320 | { |
1321 | d->mTimer->stop(); | 1321 | d->mTimer->stop(); |
1322 | if (d->mOnSeparator) | 1322 | if (d->mOnSeparator) |
1323 | { | 1323 | { |
1324 | d->mOnSeparator = false; | 1324 | d->mOnSeparator = false; |
1325 | setCursor( ArrowCursor ); | 1325 | setCursor( ArrowCursor ); |
1326 | } | 1326 | } |
1327 | } | 1327 | } |
1328 | 1328 | ||
1329 | void CardView::focusInEvent( QFocusEvent * ) | 1329 | void CardView::focusInEvent( QFocusEvent * ) |
1330 | { | 1330 | { |
1331 | if (!d->mCurrentItem && d->mItemList.count() ) | 1331 | if (!d->mCurrentItem && d->mItemList.count() ) |
1332 | { | 1332 | { |
1333 | setCurrentItem( d->mItemList.first() ); | 1333 | setCurrentItem( d->mItemList.first() ); |
1334 | } | 1334 | } |
1335 | else if ( d->mCurrentItem ) | 1335 | else if ( d->mCurrentItem ) |
1336 | { | 1336 | { |
1337 | d->mCurrentItem->repaintCard(); | 1337 | d->mCurrentItem->repaintCard(); |
1338 | } | 1338 | } |
1339 | } | 1339 | } |
1340 | 1340 | ||
1341 | void CardView::focusOutEvent( QFocusEvent * ) | 1341 | void CardView::focusOutEvent( QFocusEvent * ) |
1342 | { | 1342 | { |
1343 | if (d->mCurrentItem) | 1343 | if (d->mCurrentItem) |
1344 | d->mCurrentItem->repaintCard(); | 1344 | d->mCurrentItem->repaintCard(); |
1345 | } | 1345 | } |
1346 | 1346 | ||
1347 | void CardView::keyPressEvent( QKeyEvent *e ) | 1347 | void CardView::keyPressEvent( QKeyEvent *e ) |
1348 | { | 1348 | { |
1349 | if ( ! ( childCount() && d->mCurrentItem ) ) | 1349 | if ( ! ( childCount() && d->mCurrentItem ) ) |
1350 | { | 1350 | { |
1351 | e->ignore(); | 1351 | e->ignore(); |
1352 | return; | 1352 | return; |
1353 | } | 1353 | } |
1354 | 1354 | ||
1355 | uint pos = d->mItemList.findRef( d->mCurrentItem ); | 1355 | uint pos = d->mItemList.findRef( d->mCurrentItem ); |
1356 | CardViewItem *aItem = 0L; // item that gets the focus | 1356 | CardViewItem *aItem = 0L; // item that gets the focus |
1357 | CardViewItem *old = d->mCurrentItem; | 1357 | CardViewItem *old = d->mCurrentItem; |
1358 | 1358 | ||
1359 | switch ( e->key() ) | 1359 | switch ( e->key() ) |
1360 | { | 1360 | { |
1361 | case Key_Up: | 1361 | case Key_Up: |
1362 | if ( pos > 0 ) | 1362 | if ( pos > 0 ) |
1363 | { | 1363 | { |
1364 | aItem = d->mItemList.at( pos - 1 ); | 1364 | aItem = d->mItemList.at( pos - 1 ); |
1365 | setCurrentItem( aItem ); | 1365 | setCurrentItem( aItem ); |
1366 | } | 1366 | } |
1367 | break; | 1367 | break; |
1368 | case Key_Down: | 1368 | case Key_Down: |
1369 | if ( pos < d->mItemList.count() - 1 ) | 1369 | if ( pos < d->mItemList.count() - 1 ) |
1370 | { | 1370 | { |
1371 | aItem = d->mItemList.at( pos + 1 ); | 1371 | aItem = d->mItemList.at( pos + 1 ); |
1372 | setCurrentItem( aItem ); | 1372 | setCurrentItem( aItem ); |
1373 | } | 1373 | } |
1374 | break; | 1374 | break; |
1375 | case Key_Left: | 1375 | case Key_Left: |
1376 | { | 1376 | { |
1377 | // look for an item in the previous/next column, starting from | 1377 | // look for an item in the previous/next column, starting from |
1378 | // the vertical middle of the current item. | 1378 | // the vertical middle of the current item. |
1379 | // FIXME use nice calculatd measures!!! | 1379 | // FIXME use nice calculatd measures!!! |
1380 | QPoint aPoint( d->mCurrentItem->d->x, d->mCurrentItem->d->y ); | 1380 | QPoint aPoint( d->mCurrentItem->d->x, d->mCurrentItem->d->y ); |
1381 | aPoint -= QPoint( 30,-(d->mCurrentItem->height()/2) ); | 1381 | aPoint -= QPoint( 30,-(d->mCurrentItem->height()/2) ); |
1382 | aItem = itemAt( aPoint ); | 1382 | aItem = itemAt( aPoint ); |
1383 | // maybe we hit some space below an item | 1383 | // maybe we hit some space below an item |
1384 | while ( !aItem && aPoint.y() > 27 ) | 1384 | while ( !aItem && aPoint.y() > 27 ) |
1385 | { | 1385 | { |
1386 | aPoint -= QPoint( 0, 16 ); | 1386 | aPoint -= QPoint( 0, 16 ); |
1387 | aItem = itemAt( aPoint ); | 1387 | aItem = itemAt( aPoint ); |
1388 | } | 1388 | } |
1389 | if ( aItem ) | 1389 | if ( aItem ) |
1390 | setCurrentItem( aItem ); | 1390 | setCurrentItem( aItem ); |
1391 | } | 1391 | } |
1392 | break; | 1392 | break; |
1393 | case Key_Right: | 1393 | case Key_Right: |
1394 | { | 1394 | { |
1395 | // FIXME use nice calculated measures!!! | 1395 | // FIXME use nice calculated measures!!! |
1396 | QPoint aPoint( d->mCurrentItem->d->x + d->mItemWidth, d->mCurrentItem->d->y ); | 1396 | QPoint aPoint( d->mCurrentItem->d->x + d->mItemWidth, d->mCurrentItem->d->y ); |
1397 | aPoint += QPoint( 30,(d->mCurrentItem->height()/2) ); | 1397 | aPoint += QPoint( 30,(d->mCurrentItem->height()/2) ); |
1398 | aItem = itemAt( aPoint ); | 1398 | aItem = itemAt( aPoint ); |
1399 | while ( !aItem && aPoint.y() > 27 ) | 1399 | while ( !aItem && aPoint.y() > 27 ) |
1400 | { | 1400 | { |
1401 | aPoint -= QPoint( 0, 16 ); | 1401 | aPoint -= QPoint( 0, 16 ); |
1402 | aItem = itemAt( aPoint ); | 1402 | aItem = itemAt( aPoint ); |
1403 | } | 1403 | } |
1404 | if ( aItem ) | 1404 | if ( aItem ) |
1405 | setCurrentItem( aItem ); | 1405 | setCurrentItem( aItem ); |
1406 | } | 1406 | } |
1407 | break; | 1407 | break; |
1408 | case Key_Home: | 1408 | case Key_Home: |
1409 | aItem = d->mItemList.first(); | 1409 | aItem = d->mItemList.first(); |
1410 | setCurrentItem( aItem ); | 1410 | setCurrentItem( aItem ); |
1411 | break; | 1411 | break; |
1412 | case Key_End: | 1412 | case Key_End: |
1413 | aItem = d->mItemList.last(); | 1413 | aItem = d->mItemList.last(); |
1414 | setCurrentItem( aItem ); | 1414 | setCurrentItem( aItem ); |
1415 | break; | 1415 | break; |
1416 | case Key_Prior: // PageUp | 1416 | case Key_Prior: // PageUp |
1417 | { | 1417 | { |
1418 | // QListView: "Make the item above the top visible and current" | 1418 | // QListView: "Make the item above the top visible and current" |
1419 | // TODO if contentsY(), pick the top item of the leftmost visible column | 1419 | // TODO if contentsY(), pick the top item of the leftmost visible column |
1420 | if ( contentsX() <= 0 ) | 1420 | if ( contentsX() <= 0 ) |
1421 | return; | 1421 | return; |
1422 | int cw = columnWidth(); | 1422 | int cw = columnWidth(); |
1423 | int theCol = ( QMAX( 0, ( contentsX()/cw) * cw ) ) + d->mItemSpacing; | 1423 | int theCol = ( QMAX( 0, ( contentsX()/cw) * cw ) ) + d->mItemSpacing; |
1424 | aItem = itemAt( QPoint( theCol + 1, d->mItemSpacing + 1 ) ); | 1424 | aItem = itemAt( QPoint( theCol + 1, d->mItemSpacing + 1 ) ); |
1425 | if ( aItem ) | 1425 | if ( aItem ) |
1426 | setCurrentItem( aItem ); | 1426 | setCurrentItem( aItem ); |
1427 | } | 1427 | } |
1428 | break; | 1428 | break; |
1429 | case Key_Next: // PageDown | 1429 | case Key_Next: // PageDown |
1430 | { | 1430 | { |
1431 | // QListView: "Make the item below the bottom visible and current" | 1431 | // QListView: "Make the item below the bottom visible and current" |
1432 | // find the first not fully visible column. | 1432 | // find the first not fully visible column. |
1433 | // TODO: consider if a partly visible (or even hidden) item at the | 1433 | // TODO: consider if a partly visible (or even hidden) item at the |
1434 | // bottom of the rightmost column exists | 1434 | // bottom of the rightmost column exists |
1435 | int cw = columnWidth(); | 1435 | int cw = columnWidth(); |
1436 | int theCol = ( (( contentsX() + visibleWidth() )/cw) * cw ) + d->mItemSpacing + 1; | 1436 | int theCol = ( (( contentsX() + visibleWidth() )/cw) * cw ) + d->mItemSpacing + 1; |
1437 | // if separators are on, we may need to we may be one column further right if only the spacing/sep is hidden | 1437 | // if separators are on, we may need to we may be one column further right if only the spacing/sep is hidden |
1438 | if ( d->mDrawSeparators && cw - (( contentsX() + visibleWidth() )%cw) <= int( d->mItemSpacing + d->mSepWidth ) ) | 1438 | if ( d->mDrawSeparators && cw - (( contentsX() + visibleWidth() )%cw) <= int( d->mItemSpacing + d->mSepWidth ) ) |
1439 | theCol += cw; | 1439 | theCol += cw; |
1440 | 1440 | ||
1441 | // make sure this is not too far right | 1441 | // make sure this is not too far right |
1442 | while ( theCol > contentsWidth() ) | 1442 | while ( theCol > contentsWidth() ) |
1443 | theCol -= columnWidth(); | 1443 | theCol -= columnWidth(); |
1444 | 1444 | ||
1445 | aItem = itemAt( QPoint( theCol, d->mItemSpacing + 1 ) ); | 1445 | aItem = itemAt( QPoint( theCol, d->mItemSpacing + 1 ) ); |
1446 | 1446 | ||
1447 | if ( aItem ) | 1447 | if ( aItem ) |
1448 | setCurrentItem( aItem ); | 1448 | setCurrentItem( aItem ); |
1449 | } | 1449 | } |
1450 | break; | 1450 | break; |
1451 | case Key_Space: | 1451 | case Key_Space: |
1452 | setSelected( d->mCurrentItem, !d->mCurrentItem->isSelected() ); | 1452 | setSelected( d->mCurrentItem, !d->mCurrentItem->isSelected() ); |
1453 | emit selectionChanged(); | 1453 | emit selectionChanged(); |
1454 | break; | 1454 | break; |
1455 | case Key_Return: | 1455 | case Key_Return: |
1456 | case Key_Enter: | 1456 | case Key_Enter: |
1457 | { | 1457 | { |
1458 | emit returnPressed( d->mCurrentItem ); | 1458 | emit returnPressed( d->mCurrentItem ); |
1459 | emit executed( d->mCurrentItem ); | 1459 | emit executed( d->mCurrentItem ); |
1460 | } | 1460 | } |
1461 | break; | 1461 | break; |
1462 | default: | 1462 | default: |
1463 | if ( (e->state() & ControlButton) && e->key() == Key_A ) | 1463 | if ( (e->state() & ControlButton) && e->key() == Key_A ) |
1464 | { | 1464 | { |
1465 | // select all | 1465 | // select all |
1466 | selectAll( true ); | 1466 | selectAll( true ); |
1467 | break; | 1467 | break; |
1468 | } | 1468 | } |
1469 | // if we have a string, do autosearch | 1469 | // if we have a string, do autosearch |
1470 | else if ( ! e->text().isEmpty() && e->text()[0].isPrint() ) | 1470 | else if ( ! e->text().isEmpty() && e->text()[0].isPrint() ) |
1471 | { | 1471 | { |
1472 | 1472 | ||
1473 | } | 1473 | } |
1474 | break; | 1474 | break; |
1475 | } | 1475 | } |
1476 | // handle selection | 1476 | // handle selection |
1477 | if ( aItem ) | 1477 | if ( aItem ) |
1478 | { | 1478 | { |
1479 | if ( d->mSelectionMode == CardView::Extended ) | 1479 | if ( d->mSelectionMode == CardView::Extended ) |
1480 | { | 1480 | { |
1481 | if ( (e->state() & ShiftButton) ) | 1481 | if ( (e->state() & ShiftButton) ) |
1482 | { | 1482 | { |
1483 | // shift button: toggle range | 1483 | // shift button: toggle range |
1484 | // if control button is pressed, leave all items | 1484 | // if control button is pressed, leave all items |
1485 | // and toggle selection current->old current | 1485 | // and toggle selection current->old current |
1486 | // otherwise, ?????? | 1486 | // otherwise, ?????? |
1487 | bool s = ! aItem->isSelected(); | 1487 | bool s = ! aItem->isSelected(); |
1488 | int from, to, a, b; | 1488 | int from, to, a, b; |
1489 | a = d->mItemList.findRef( aItem ); | 1489 | a = d->mItemList.findRef( aItem ); |
1490 | b = d->mItemList.findRef( old ); | 1490 | b = d->mItemList.findRef( old ); |
1491 | from = a < b ? a : b; | 1491 | from = a < b ? a : b; |
1492 | to = a > b ? a : b; | 1492 | to = a > b ? a : b; |
1493 | 1493 | ||
1494 | if ( to - from > 1 ) | 1494 | if ( to - from > 1 ) |
1495 | { | 1495 | { |
1496 | bool b = signalsBlocked(); | 1496 | bool b = signalsBlocked(); |
1497 | blockSignals(true); | 1497 | blockSignals(true); |
1498 | selectAll(false); | 1498 | selectAll(false); |
1499 | blockSignals(b); | 1499 | blockSignals(b); |
1500 | } | 1500 | } |
1501 | 1501 | ||
1502 | //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl; | 1502 | //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl; |
1503 | CardViewItem *item; | 1503 | CardViewItem *item; |
1504 | for ( ; from <= to; from++ ) | 1504 | for ( ; from <= to; from++ ) |
1505 | { | 1505 | { |
1506 | item = d->mItemList.at( from ); | 1506 | item = d->mItemList.at( from ); |
1507 | item->setSelected( s ); | 1507 | item->setSelected( s ); |
1508 | repaintItem( item ); | 1508 | repaintItem( item ); |
1509 | } | 1509 | } |
1510 | emit selectionChanged(); | 1510 | emit selectionChanged(); |
1511 | } | 1511 | } |
1512 | else if ( (e->state() & ControlButton) ) | 1512 | else if ( (e->state() & ControlButton) ) |
1513 | { | 1513 | { |
1514 | // control button: do nothing | 1514 | // control button: do nothing |
1515 | } | 1515 | } |
1516 | else | 1516 | else |
1517 | { | 1517 | { |
1518 | // no button: move selection to this item | 1518 | // no button: move selection to this item |
1519 | bool b = signalsBlocked(); | 1519 | bool b = signalsBlocked(); |
1520 | blockSignals(true); | 1520 | blockSignals(true); |
1521 | selectAll(false); | 1521 | selectAll(false); |
1522 | blockSignals(b); | 1522 | blockSignals(b); |
1523 | 1523 | ||
1524 | setSelected( aItem, true ); | 1524 | setSelected( aItem, true ); |
1525 | emit selectionChanged(); | 1525 | emit selectionChanged(); |
1526 | } | 1526 | } |
1527 | } | 1527 | } |
1528 | } | 1528 | } |
1529 | } | 1529 | } |
1530 | 1530 | ||
1531 | void CardView::contentsWheelEvent( QWheelEvent * e ) | 1531 | void CardView::contentsWheelEvent( QWheelEvent * e ) |
1532 | { | 1532 | { |
1533 | scrollBy(2*e->delta()/-3, 0); | 1533 | scrollBy(2*e->delta()/-3, 0); |
1534 | } | 1534 | } |
1535 | 1535 | ||
1536 | void CardView::setLayoutDirty(bool dirty) | 1536 | void CardView::setLayoutDirty(bool dirty) |
1537 | { | 1537 | { |
1538 | if (d->mLayoutDirty != dirty) | 1538 | if (d->mLayoutDirty != dirty) |
1539 | { | 1539 | { |
1540 | d->mLayoutDirty = dirty; | 1540 | d->mLayoutDirty = dirty; |
1541 | repaint(); | 1541 | repaint(); |
1542 | } | 1542 | } |
1543 | } | 1543 | } |
1544 | 1544 | ||
1545 | void CardView::setDrawCardBorder(bool enabled) | 1545 | void CardView::setDrawCardBorder(bool enabled) |
1546 | { | 1546 | { |
1547 | if (enabled != d->mDrawCardBorder) | 1547 | if (enabled != d->mDrawCardBorder) |
1548 | { | 1548 | { |
1549 | d->mDrawCardBorder = enabled; | 1549 | d->mDrawCardBorder = enabled; |
1550 | repaint(); | 1550 | repaint(); |
1551 | } | 1551 | } |
1552 | } | 1552 | } |
1553 | 1553 | ||
1554 | bool CardView::drawCardBorder() const | 1554 | bool CardView::drawCardBorder() const |
1555 | { | 1555 | { |
1556 | return d->mDrawCardBorder; | 1556 | return d->mDrawCardBorder; |
1557 | } | 1557 | } |
1558 | 1558 | ||
1559 | void CardView::setDrawColSeparators(bool enabled) | 1559 | void CardView::setDrawColSeparators(bool enabled) |
1560 | { | 1560 | { |
1561 | if (enabled != d->mDrawSeparators) | 1561 | if (enabled != d->mDrawSeparators) |
1562 | { | 1562 | { |
1563 | d->mDrawSeparators = enabled; | 1563 | d->mDrawSeparators = enabled; |
1564 | setLayoutDirty(true); | 1564 | setLayoutDirty(true); |
1565 | } | 1565 | } |
1566 | } | 1566 | } |
1567 | 1567 | ||
1568 | bool CardView::drawColSeparators() const | 1568 | bool CardView::drawColSeparators() const |
1569 | { | 1569 | { |
1570 | return d->mDrawSeparators; | 1570 | return d->mDrawSeparators; |
1571 | } | 1571 | } |
1572 | 1572 | ||
1573 | void CardView::setDrawFieldLabels(bool enabled) | 1573 | void CardView::setDrawFieldLabels(bool enabled) |
1574 | { | 1574 | { |
1575 | if (enabled != d->mDrawFieldLabels) | 1575 | if (enabled != d->mDrawFieldLabels) |
1576 | { | 1576 | { |
1577 | d->mDrawFieldLabels = enabled; | 1577 | d->mDrawFieldLabels = enabled; |
1578 | repaint(); | 1578 | repaint(); |
1579 | } | 1579 | } |
1580 | } | 1580 | } |
1581 | 1581 | ||
1582 | bool CardView::drawFieldLabels() const | 1582 | bool CardView::drawFieldLabels() const |
1583 | { | 1583 | { |
1584 | return d->mDrawFieldLabels; | 1584 | return d->mDrawFieldLabels; |
1585 | } | 1585 | } |
1586 | 1586 | ||
1587 | void CardView::setShowEmptyFields(bool show) | 1587 | void CardView::setShowEmptyFields(bool show) |
1588 | { | 1588 | { |
1589 | if (show != d->mShowEmptyFields) | 1589 | if (show != d->mShowEmptyFields) |
1590 | { | 1590 | { |
1591 | d->mShowEmptyFields = show; | 1591 | d->mShowEmptyFields = show; |
1592 | setLayoutDirty(true); | 1592 | setLayoutDirty(true); |
1593 | } | 1593 | } |
1594 | } | 1594 | } |
1595 | 1595 | ||
1596 | bool CardView::showEmptyFields() const | 1596 | bool CardView::showEmptyFields() const |
1597 | { | 1597 | { |
1598 | return d->mShowEmptyFields; | 1598 | return d->mShowEmptyFields; |
1599 | } | 1599 | } |
1600 | 1600 | ||
1601 | void CardView::startDrag() | 1601 | void CardView::startDrag() |
1602 | { | 1602 | { |
1603 | // The default implementation is a no-op. It must be | 1603 | // The default implementation is a no-op. It must be |
1604 | // reimplemented in a subclass to be useful | 1604 | // reimplemented in a subclass to be useful |
1605 | } | 1605 | } |
1606 | void CardView::tryShowFullText() | 1606 | void CardView::tryShowFullText() |
1607 | { | 1607 | { |
1608 | d->mTimer->stop(); | 1608 | d->mTimer->stop(); |
1609 | // if we have an item | 1609 | // if we have an item |
1610 | QPoint cpos = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) ); | 1610 | QPoint cpos = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) ); |
1611 | CardViewItem *item = itemAt( cpos ); | 1611 | CardViewItem *item = itemAt( cpos ); |
1612 | if ( item ) | 1612 | if ( item ) |
1613 | { | 1613 | { |
1614 | // query it for a value to display | 1614 | // query it for a value to display |
1615 | //QString s = item ? item->caption() : "(no item)"; | 1615 | //QString s = item ? item->caption() : "(no item)"; |
1616 | //kdDebug()<<"MOUSE REST: "<<s<<endl; | 1616 | //kdDebug()<<"MOUSE REST: "<<s<<endl; |
1617 | QPoint ipos = cpos - itemRect( item ).topLeft(); | 1617 | QPoint ipos = cpos - itemRect( item ).topLeft(); |
1618 | item->showFullString( ipos, d->mTip ); | 1618 | item->showFullString( ipos, d->mTip ); |
1619 | } | 1619 | } |
1620 | } | 1620 | } |
1621 | 1621 | ||
1622 | void CardView::drawRubberBands( int pos ) | 1622 | void CardView::drawRubberBands( int pos ) |
1623 | { | 1623 | { |
1624 | if ( pos && ((pos-d->firstX)/d->span) - d->colspace - d->mSepWidth < MIN_ITEM_WIDTH ) return; | 1624 | if ( pos && ((pos-d->firstX)/d->span) - d->colspace - d->mSepWidth < MIN_ITEM_WIDTH ) return; |
1625 | 1625 | ||
1626 | int tmpcw = (d->mRubberBandAnchor-d->firstX)/d->span; | 1626 | int tmpcw = (d->mRubberBandAnchor-d->firstX)/d->span; |
1627 | int x = d->firstX + tmpcw - d->mSepWidth - contentsX(); | 1627 | int x = d->firstX + tmpcw - d->mSepWidth - contentsX(); |
1628 | int h = visibleHeight(); | 1628 | int h = visibleHeight(); |
1629 | 1629 | ||
1630 | QPainter p( viewport() ); | 1630 | QPainter p( viewport() ); |
1631 | p.setRasterOp( XorROP ); | 1631 | p.setRasterOp( XorROP ); |
1632 | p.setPen( gray ); | 1632 | p.setPen( gray ); |
1633 | p.setBrush( gray ); | 1633 | p.setBrush( gray ); |
1634 | uint n = d->first; | 1634 | uint n = d->first; |
1635 | // erase | 1635 | // erase |
1636 | if ( d->mRubberBandAnchor ) | 1636 | if ( d->mRubberBandAnchor ) |
1637 | do { | 1637 | do { |
1638 | p.drawRect( x, 0, 2, h ); | 1638 | p.drawRect( x, 0, 2, h ); |
1639 | x += tmpcw; | 1639 | x += tmpcw; |
1640 | n++; | 1640 | n++; |
1641 | } while ( x < visibleWidth() && n < d->mSeparatorList.count() ); | 1641 | } while ( x < visibleWidth() && n < d->mSeparatorList.count() ); |
1642 | // paint new | 1642 | // paint new |
1643 | if ( ! pos ) return; | 1643 | if ( ! pos ) return; |
1644 | tmpcw = (pos - d->firstX)/d->span; | 1644 | tmpcw = (pos - d->firstX)/d->span; |
1645 | n = d->first; | 1645 | n = d->first; |
1646 | x = d->firstX + tmpcw - d->mSepWidth - contentsX(); | 1646 | x = d->firstX + tmpcw - d->mSepWidth - contentsX(); |
1647 | do { | 1647 | do { |
1648 | p.drawRect( x, 0, 2, h ); | 1648 | p.drawRect( x, 0, 2, h ); |
1649 | x += tmpcw; | 1649 | x += tmpcw; |
1650 | n++; | 1650 | n++; |
1651 | } while ( x < visibleWidth() && n < d->mSeparatorList.count() ); | 1651 | } while ( x < visibleWidth() && n < d->mSeparatorList.count() ); |
1652 | d->mRubberBandAnchor = pos; | 1652 | d->mRubberBandAnchor = pos; |
1653 | } | 1653 | } |
1654 | 1654 | ||
1655 | 1655 | ||
1656 | int CardView::itemWidth() const | 1656 | int CardView::itemWidth() const |
1657 | { | 1657 | { |
1658 | return d->mItemWidth; | 1658 | return d->mItemWidth; |
1659 | } | 1659 | } |
1660 | 1660 | ||
1661 | void CardView::setItemWidth( int w ) | 1661 | void CardView::setItemWidth( int w ) |
1662 | { | 1662 | { |
1663 | if ( w == d->mItemWidth ) | 1663 | if ( w == d->mItemWidth ) |
1664 | return; | 1664 | return; |
1665 | if ( w < MIN_ITEM_WIDTH ) | 1665 | if ( w < MIN_ITEM_WIDTH ) |
1666 | w = MIN_ITEM_WIDTH; | 1666 | w = MIN_ITEM_WIDTH; |
1667 | d->mItemWidth = w; | 1667 | d->mItemWidth = w; |
1668 | setLayoutDirty( true ); | 1668 | setLayoutDirty( true ); |
1669 | #ifndef KAB_EMBEDDED | 1669 | #ifndef KAB_EMBEDDED |
1670 | updateContents(); | 1670 | updateContents(); |
1671 | #else //KAB_EMBEDDED | 1671 | #else //KAB_EMBEDDED |
1672 | //US updateContents( d->contentsX(), d->contentsY(), visibleWidth(), visibleHeight() ); | 1672 | //US updateContents( d->contentsX(), d->contentsY(), visibleWidth(), visibleHeight() ); |
1673 | qDebug("CardView::setItemWidth has to be verified"); | 1673 | qDebug("CardView::setItemWidth has to be verified"); |
1674 | updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() ); | 1674 | updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() ); |
1675 | #endif //KAB_EMBEDDED | 1675 | #endif //KAB_EMBEDDED |
1676 | } | 1676 | } |
1677 | 1677 | ||
1678 | void CardView::setHeaderFont( const QFont &fnt ) | 1678 | void CardView::setHeaderFont( const QFont &fnt ) |
1679 | { | 1679 | { |
1680 | d->mHeaderFont = fnt; | 1680 | d->mHeaderFont = fnt; |
1681 | delete d->mBFm; | 1681 | delete d->mBFm; |
1682 | d->mBFm = new QFontMetrics( fnt ); | 1682 | d->mBFm = new QFontMetrics( fnt ); |
1683 | } | 1683 | } |
1684 | 1684 | ||
1685 | QFont CardView::headerFont() const | 1685 | QFont CardView::headerFont() const |
1686 | { | 1686 | { |
1687 | return d->mHeaderFont; | 1687 | return d->mHeaderFont; |
1688 | } | 1688 | } |
1689 | 1689 | ||
1690 | void CardView::setFont( const QFont &fnt ) | 1690 | void CardView::setFont( const QFont &fnt ) |
1691 | { | 1691 | { |
1692 | QScrollView::setFont( fnt ); | 1692 | QScrollView::setFont( fnt ); |
1693 | delete d->mFm; | 1693 | delete d->mFm; |
1694 | d->mFm = new QFontMetrics( fnt ); | 1694 | d->mFm = new QFontMetrics( fnt ); |
1695 | } | 1695 | } |
1696 | 1696 | ||
1697 | int CardView::separatorWidth() | 1697 | int CardView::separatorWidth() |
1698 | { | 1698 | { |
1699 | return d->mSepWidth; | 1699 | return d->mSepWidth; |
1700 | } | 1700 | } |
1701 | 1701 | ||
1702 | void CardView::setSeparatorWidth( int width ) | 1702 | void CardView::setSeparatorWidth( int width ) |
1703 | { | 1703 | { |
1704 | d->mSepWidth = width; | 1704 | d->mSepWidth = width; |
1705 | setLayoutDirty( true ); // hmm, actually I could just adjust the x'es... | 1705 | setLayoutDirty( true ); // hmm, actually I could just adjust the x'es... |
1706 | } | 1706 | } |
1707 | 1707 | ||
1708 | int CardView::maxFieldLines() const | 1708 | int CardView::maxFieldLines() const |
1709 | { | 1709 | { |
1710 | return d->mMaxFieldLines; | 1710 | return d->mMaxFieldLines; |
1711 | } | 1711 | } |
1712 | 1712 | ||
1713 | void CardView::setMaxFieldLines( int howmany ) | 1713 | void CardView::setMaxFieldLines( int howmany ) |
1714 | { | 1714 | { |
1715 | d->mMaxFieldLines = howmany ? howmany : INT_MAX; | 1715 | d->mMaxFieldLines = howmany ? howmany : INT_MAX; |
1716 | // FIXME update, forcing the items to recalc height!! | 1716 | // FIXME update, forcing the items to recalc height!! |
1717 | } | 1717 | } |
1718 | //END Cardview | 1718 | //END Cardview |
1719 | 1719 | ||
1720 | #ifndef KAB_EMBEDDED | 1720 | #ifndef KAB_EMBEDDED |
1721 | #include "cardview.moc" | 1721 | #include "cardview.moc" |
1722 | #endif //KAB_EMBEDDED | 1722 | #endif //KAB_EMBEDDED |