summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp293
1 files changed, 277 insertions, 16 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index e912941..1196360 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1,2612 +1,2873 @@
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/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (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 36
37#ifndef KAB_EMBEDDED 37#ifndef KAB_EMBEDDED
38#include <qclipboard.h> 38#include <qclipboard.h>
39#include <qdir.h> 39#include <qdir.h>
40#include <qfile.h> 40#include <qfile.h>
41#include <qapplicaton.h> 41#include <qapplicaton.h>
42#include <qlayout.h> 42#include <qlayout.h>
43#include <qregexp.h> 43#include <qregexp.h>
44#include <qvbox.h> 44#include <qvbox.h>
45#include <kabc/addresseelist.h> 45#include <kabc/addresseelist.h>
46#include <kabc/errorhandler.h> 46#include <kabc/errorhandler.h>
47#include <kabc/resource.h> 47#include <kabc/resource.h>
48#include <kabc/vcardconverter.h> 48#include <kabc/vcardconverter.h>
49#include <kapplication.h> 49#include <kapplication.h>
50#include <kactionclasses.h> 50#include <kactionclasses.h>
51#include <kcmultidialog.h> 51#include <kcmultidialog.h>
52#include <kdebug.h> 52#include <kdebug.h>
53#include <kdeversion.h> 53#include <kdeversion.h>
54#include <kkeydialog.h> 54#include <kkeydialog.h>
55#include <kmessagebox.h> 55#include <kmessagebox.h>
56#include <kprinter.h> 56#include <kprinter.h>
57#include <kprotocolinfo.h> 57#include <kprotocolinfo.h>
58#include <kresources/selectdialog.h> 58#include <kresources/selectdialog.h>
59#include <kstandarddirs.h> 59#include <kstandarddirs.h>
60#include <ktempfile.h> 60#include <ktempfile.h>
61#include <kxmlguiclient.h> 61#include <kxmlguiclient.h>
62#include <kaboutdata.h> 62#include <kaboutdata.h>
63#include <libkdepim/categoryselectdialog.h> 63#include <libkdepim/categoryselectdialog.h>
64 64
65#include "addresseeutil.h" 65#include "addresseeutil.h"
66#include "addresseeeditordialog.h" 66#include "addresseeeditordialog.h"
67#include "extensionmanager.h" 67#include "extensionmanager.h"
68#include "kstdaction.h" 68#include "kstdaction.h"
69#include "kaddressbookservice.h" 69#include "kaddressbookservice.h"
70#include "ldapsearchdialog.h" 70#include "ldapsearchdialog.h"
71#include "printing/printingwizard.h" 71#include "printing/printingwizard.h"
72#else // KAB_EMBEDDED 72#else // KAB_EMBEDDED
73 73
74#include <kapplication.h> 74#include <kapplication.h>
75#include "KDGanttMinimizeSplitter.h" 75#include "KDGanttMinimizeSplitter.h"
76#include "kaddressbookmain.h" 76#include "kaddressbookmain.h"
77#include "kactioncollection.h" 77#include "kactioncollection.h"
78#include "addresseedialog.h" 78#include "addresseedialog.h"
79//US 79//US
80#include <addresseeview.h> 80#include <addresseeview.h>
81 81
82#include <qapp.h> 82#include <qapp.h>
83#include <qmenubar.h> 83#include <qmenubar.h>
84//#include <qtoolbar.h> 84//#include <qtoolbar.h>
85#include <qmessagebox.h> 85#include <qmessagebox.h>
86#include <kdebug.h> 86#include <kdebug.h>
87#include <kiconloader.h> // needed for SmallIcon 87#include <kiconloader.h> // needed for SmallIcon
88#include <kresources/kcmkresources.h> 88#include <kresources/kcmkresources.h>
89#include <ktoolbar.h> 89#include <ktoolbar.h>
90 90
91 91
92//#include <qlabel.h> 92//#include <qlabel.h>
93 93
94 94
95#ifndef DESKTOP_VERSION 95#ifndef DESKTOP_VERSION
96#include <qpe/ir.h> 96#include <qpe/ir.h>
97#include <qpe/qpemenubar.h> 97#include <qpe/qpemenubar.h>
98#include <qtopia/qcopenvelope_qws.h> 98#include <qtopia/qcopenvelope_qws.h>
99#else 99#else
100 100
101#include <qmenubar.h> 101#include <qmenubar.h>
102#endif 102#endif
103 103
104#endif // KAB_EMBEDDED 104#endif // KAB_EMBEDDED
105#include "kcmconfigs/kcmkabconfig.h" 105#include "kcmconfigs/kcmkabconfig.h"
106#include "kcmconfigs/kcmkdepimconfig.h" 106#include "kcmconfigs/kcmkdepimconfig.h"
107#include "kpimglobalprefs.h" 107#include "kpimglobalprefs.h"
108#include "externalapphandler.h" 108#include "externalapphandler.h"
109 109
110 110
111#include <kresources/selectdialog.h> 111#include <kresources/selectdialog.h>
112#include <kmessagebox.h> 112#include <kmessagebox.h>
113 113
114#include <picture.h> 114#include <picture.h>
115#include <resource.h> 115#include <resource.h>
116 116
117//US#include <qsplitter.h> 117//US#include <qsplitter.h>
118#include <qmap.h> 118#include <qmap.h>
119#include <qdir.h> 119#include <qdir.h>
120#include <qfile.h> 120#include <qfile.h>
121#include <qvbox.h> 121#include <qvbox.h>
122#include <qlayout.h> 122#include <qlayout.h>
123#include <qclipboard.h> 123#include <qclipboard.h>
124#include <qtextstream.h> 124#include <qtextstream.h>
125 125
126#include <libkdepim/categoryselectdialog.h> 126#include <libkdepim/categoryselectdialog.h>
127#include <kabc/vcardconverter.h> 127#include <kabc/vcardconverter.h>
128 128
129 129
130#include "addresseeutil.h" 130#include "addresseeutil.h"
131#include "undocmds.h" 131#include "undocmds.h"
132#include "addresseeeditordialog.h" 132#include "addresseeeditordialog.h"
133#include "viewmanager.h" 133#include "viewmanager.h"
134#include "details/detailsviewcontainer.h" 134#include "details/detailsviewcontainer.h"
135#include "kabprefs.h" 135#include "kabprefs.h"
136#include "xxportmanager.h" 136#include "xxportmanager.h"
137#include "incsearchwidget.h" 137#include "incsearchwidget.h"
138#include "jumpbuttonbar.h" 138#include "jumpbuttonbar.h"
139#include "extensionmanager.h" 139#include "extensionmanager.h"
140#include "addresseeconfig.h" 140#include "addresseeconfig.h"
141#include <kcmultidialog.h> 141#include <kcmultidialog.h>
142 142
143#ifdef _WIN32_ 143#ifdef _WIN32_
144 144
145#include "kaimportoldialog.h" 145#include "kaimportoldialog.h"
146#else 146#else
147#include <unistd.h> 147#include <unistd.h>
148#endif 148#endif
149// sync includes 149// sync includes
150#include <libkdepim/ksyncprofile.h> 150#include <libkdepim/ksyncprofile.h>
151#include <libkdepim/ksyncprefsdialog.h> 151#include <libkdepim/ksyncprefsdialog.h>
152 152
153 153
154bool pasteWithNewUid = true; 154bool pasteWithNewUid = true;
155 155
156#ifdef KAB_EMBEDDED 156#ifdef KAB_EMBEDDED
157KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) 157KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name )
158 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), 158 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ),
159 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ 159 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/
160 mReadWrite( readWrite ), mModified( false ), mMainWindow(client) 160 mReadWrite( readWrite ), mModified( false ), mMainWindow(client)
161#else //KAB_EMBEDDED 161#else //KAB_EMBEDDED
162KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) 162KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name )
163 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), 163 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ),
164 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), 164 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ),
165 mReadWrite( readWrite ), mModified( false ) 165 mReadWrite( readWrite ), mModified( false )
166#endif //KAB_EMBEDDED 166#endif //KAB_EMBEDDED
167{ 167{
168 168
169 mBlockSaveFlag = false; 169 mBlockSaveFlag = false;
170 mExtensionBarSplitter = 0; 170 mExtensionBarSplitter = 0;
171 mIsPart = !parent->inherits( "KAddressBookMain" ); 171 mIsPart = !parent->inherits( "KAddressBookMain" );
172 172
173 mAddressBook = KABC::StdAddressBook::self(); 173 mAddressBook = KABC::StdAddressBook::self();
174 KABC::StdAddressBook::setAutomaticSave( false ); 174 KABC::StdAddressBook::setAutomaticSave( false );
175 175
176#ifndef KAB_EMBEDDED 176#ifndef KAB_EMBEDDED
177 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); 177 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler );
178#endif //KAB_EMBEDDED 178#endif //KAB_EMBEDDED
179 179
180 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), 180 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
181 SLOT( addressBookChanged() ) ); 181 SLOT( addressBookChanged() ) );
182 182
183#if 0 183#if 0
184 // LP moved to addressbook init method 184 // LP moved to addressbook init method
185 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, 185 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization,
186 "X-Department", "KADDRESSBOOK" ); 186 "X-Department", "KADDRESSBOOK" );
187 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, 187 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization,
188 "X-Profession", "KADDRESSBOOK" ); 188 "X-Profession", "KADDRESSBOOK" );
189 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 189 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
190 "X-AssistantsName", "KADDRESSBOOK" ); 190 "X-AssistantsName", "KADDRESSBOOK" );
191 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 191 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
192 "X-ManagersName", "KADDRESSBOOK" ); 192 "X-ManagersName", "KADDRESSBOOK" );
193 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 193 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
194 "X-SpousesName", "KADDRESSBOOK" ); 194 "X-SpousesName", "KADDRESSBOOK" );
195 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal, 195 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal,
196 "X-Office", "KADDRESSBOOK" ); 196 "X-Office", "KADDRESSBOOK" );
197 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 197 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
198 "X-IMAddress", "KADDRESSBOOK" ); 198 "X-IMAddress", "KADDRESSBOOK" );
199 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 199 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
200 "X-Anniversary", "KADDRESSBOOK" ); 200 "X-Anniversary", "KADDRESSBOOK" );
201 201
202 //US added this field to become compatible with Opie/qtopia addressbook 202 //US added this field to become compatible with Opie/qtopia addressbook
203 // values can be "female" or "male" or "". An empty field represents undefined. 203 // values can be "female" or "male" or "". An empty field represents undefined.
204 mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal, 204 mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal,
205 "X-Gender", "KADDRESSBOOK" ); 205 "X-Gender", "KADDRESSBOOK" );
206 mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal, 206 mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal,
207 "X-Children", "KADDRESSBOOK" ); 207 "X-Children", "KADDRESSBOOK" );
208 mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 208 mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
209 "X-FreeBusyUrl", "KADDRESSBOOK" ); 209 "X-FreeBusyUrl", "KADDRESSBOOK" );
210#endif 210#endif
211 initGUI(); 211 initGUI();
212 212
213 mIncSearchWidget->setFocus(); 213 mIncSearchWidget->setFocus();
214 214
215 215
216 connect( mViewManager, SIGNAL( selected( const QString& ) ), 216 connect( mViewManager, SIGNAL( selected( const QString& ) ),
217 SLOT( setContactSelected( const QString& ) ) ); 217 SLOT( setContactSelected( const QString& ) ) );
218 connect( mViewManager, SIGNAL( executed( const QString& ) ), 218 connect( mViewManager, SIGNAL( executed( const QString& ) ),
219 SLOT( executeContact( const QString& ) ) ); 219 SLOT( executeContact( const QString& ) ) );
220 220
221 connect( mViewManager, SIGNAL( deleteRequest( ) ), 221 connect( mViewManager, SIGNAL( deleteRequest( ) ),
222 SLOT( deleteContacts( ) ) ); 222 SLOT( deleteContacts( ) ) );
223 connect( mViewManager, SIGNAL( modified() ), 223 connect( mViewManager, SIGNAL( modified() ),
224 SLOT( setModified() ) ); 224 SLOT( setModified() ) );
225 225
226 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) ); 226 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) );
227 connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) ); 227 connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) );
228 228
229 connect( mXXPortManager, SIGNAL( modified() ), 229 connect( mXXPortManager, SIGNAL( modified() ),
230 SLOT( setModified() ) ); 230 SLOT( setModified() ) );
231 231
232 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ), 232 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ),
233 SLOT( incrementalSearch( const QString& ) ) ); 233 SLOT( incrementalSearch( const QString& ) ) );
234 connect( mIncSearchWidget, SIGNAL( fieldChanged() ), 234 connect( mIncSearchWidget, SIGNAL( fieldChanged() ),
235 mJumpButtonBar, SLOT( recreateButtons() ) ); 235 mJumpButtonBar, SLOT( recreateButtons() ) );
236 236
237 connect( mDetails, SIGNAL( sendEmail( const QString& ) ), 237 connect( mDetails, SIGNAL( sendEmail( const QString& ) ),
238 SLOT( sendMail( const QString& ) ) ); 238 SLOT( sendMail( const QString& ) ) );
239 239
240 240
241 connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&))); 241 connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&)));
242 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&))); 242 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&)));
243 243
244 244
245#ifndef KAB_EMBEDDED 245#ifndef KAB_EMBEDDED
246 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ), 246 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ),
247 mXXPortManager, SLOT( importVCard( const KURL& ) ) ); 247 mXXPortManager, SLOT( importVCard( const KURL& ) ) );
248 248
249 connect( mDetails, SIGNAL( browse( const QString& ) ), 249 connect( mDetails, SIGNAL( browse( const QString& ) ),
250 SLOT( browse( const QString& ) ) ); 250 SLOT( browse( const QString& ) ) );
251 251
252 252
253 mAddressBookService = new KAddressBookService( this ); 253 mAddressBookService = new KAddressBookService( this );
254 254
255#endif //KAB_EMBEDDED 255#endif //KAB_EMBEDDED
256 mEditorDialog = 0; 256 mEditorDialog = 0;
257 createAddresseeEditorDialog( this ); 257 createAddresseeEditorDialog( this );
258 setModified( false ); 258 setModified( false );
259} 259}
260 260
261KABCore::~KABCore() 261KABCore::~KABCore()
262{ 262{
263 // save(); 263 // save();
264 //saveSettings(); 264 //saveSettings();
265 //KABPrefs::instance()->writeConfig(); 265 //KABPrefs::instance()->writeConfig();
266 delete AddresseeConfig::instance(); 266 delete AddresseeConfig::instance();
267 mAddressBook = 0; 267 mAddressBook = 0;
268 KABC::StdAddressBook::close(); 268 KABC::StdAddressBook::close();
269} 269}
270 270
271void KABCore::restoreSettings() 271void KABCore::restoreSettings()
272{ 272{
273 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce; 273 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce;
274 274
275 bool state; 275 bool state;
276 276
277 if (mMultipleViewsAtOnce) 277 if (mMultipleViewsAtOnce)
278 state = KABPrefs::instance()->mDetailsPageVisible; 278 state = KABPrefs::instance()->mDetailsPageVisible;
279 else 279 else
280 state = false; 280 state = false;
281 281
282 mActionDetails->setChecked( state ); 282 mActionDetails->setChecked( state );
283 setDetailsVisible( state ); 283 setDetailsVisible( state );
284 284
285 state = KABPrefs::instance()->mJumpButtonBarVisible; 285 state = KABPrefs::instance()->mJumpButtonBarVisible;
286 286
287 mActionJumpBar->setChecked( state ); 287 mActionJumpBar->setChecked( state );
288 setJumpButtonBarVisible( state ); 288 setJumpButtonBarVisible( state );
289/*US 289/*US
290 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter; 290 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter;
291 if ( splitterSize.count() == 0 ) { 291 if ( splitterSize.count() == 0 ) {
292 splitterSize.append( width() / 2 ); 292 splitterSize.append( width() / 2 );
293 splitterSize.append( width() / 2 ); 293 splitterSize.append( width() / 2 );
294 } 294 }
295 mMiniSplitter->setSizes( splitterSize ); 295 mMiniSplitter->setSizes( splitterSize );
296 if ( mExtensionBarSplitter ) { 296 if ( mExtensionBarSplitter ) {
297 splitterSize = KABPrefs::instance()->mExtensionsSplitter; 297 splitterSize = KABPrefs::instance()->mExtensionsSplitter;
298 if ( splitterSize.count() == 0 ) { 298 if ( splitterSize.count() == 0 ) {
299 splitterSize.append( width() / 2 ); 299 splitterSize.append( width() / 2 );
300 splitterSize.append( width() / 2 ); 300 splitterSize.append( width() / 2 );
301 } 301 }
302 mExtensionBarSplitter->setSizes( splitterSize ); 302 mExtensionBarSplitter->setSizes( splitterSize );
303 303
304 } 304 }
305*/ 305*/
306 mViewManager->restoreSettings(); 306 mViewManager->restoreSettings();
307 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField ); 307 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField );
308 mExtensionManager->restoreSettings(); 308 mExtensionManager->restoreSettings();
309#ifdef DESKTOP_VERSION 309#ifdef DESKTOP_VERSION
310 int wid = width(); 310 int wid = width();
311 if ( wid < 10 ) 311 if ( wid < 10 )
312 wid = 400; 312 wid = 400;
313#else 313#else
314 int wid = QApplication::desktop()->width(); 314 int wid = QApplication::desktop()->width();
315 if ( wid < 640 ) 315 if ( wid < 640 )
316 wid = QApplication::desktop()->height(); 316 wid = QApplication::desktop()->height();
317#endif 317#endif
318 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter; 318 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter;
319 if ( true /*splitterSize.count() == 0*/ ) { 319 if ( true /*splitterSize.count() == 0*/ ) {
320 splitterSize.append( wid / 2 ); 320 splitterSize.append( wid / 2 );
321 splitterSize.append( wid / 2 ); 321 splitterSize.append( wid / 2 );
322 } 322 }
323 mMiniSplitter->setSizes( splitterSize ); 323 mMiniSplitter->setSizes( splitterSize );
324 if ( mExtensionBarSplitter ) { 324 if ( mExtensionBarSplitter ) {
325 //splitterSize = KABPrefs::instance()->mExtensionsSplitter; 325 //splitterSize = KABPrefs::instance()->mExtensionsSplitter;
326 if ( true /*splitterSize.count() == 0*/ ) { 326 if ( true /*splitterSize.count() == 0*/ ) {
327 splitterSize.append( wid / 2 ); 327 splitterSize.append( wid / 2 );
328 splitterSize.append( wid / 2 ); 328 splitterSize.append( wid / 2 );
329 } 329 }
330 mExtensionBarSplitter->setSizes( splitterSize ); 330 mExtensionBarSplitter->setSizes( splitterSize );
331 331
332 } 332 }
333 333
334 334
335} 335}
336 336
337void KABCore::saveSettings() 337void KABCore::saveSettings()
338{ 338{
339 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked(); 339 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked();
340 if ( mExtensionBarSplitter ) 340 if ( mExtensionBarSplitter )
341 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 341 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
342 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked(); 342 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked();
343 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes(); 343 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes();
344#ifndef KAB_EMBEDDED 344#ifndef KAB_EMBEDDED
345 345
346 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 346 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
347 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes(); 347 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes();
348#endif //KAB_EMBEDDED 348#endif //KAB_EMBEDDED
349 mExtensionManager->saveSettings(); 349 mExtensionManager->saveSettings();
350 mViewManager->saveSettings(); 350 mViewManager->saveSettings();
351 351
352 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem(); 352 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem();
353} 353}
354 354
355KABC::AddressBook *KABCore::addressBook() const 355KABC::AddressBook *KABCore::addressBook() const
356{ 356{
357 return mAddressBook; 357 return mAddressBook;
358} 358}
359 359
360KConfig *KABCore::config() 360KConfig *KABCore::config()
361{ 361{
362#ifndef KAB_EMBEDDED 362#ifndef KAB_EMBEDDED
363 return KABPrefs::instance()->config(); 363 return KABPrefs::instance()->config();
364#else //KAB_EMBEDDED 364#else //KAB_EMBEDDED
365 return KABPrefs::instance()->getConfig(); 365 return KABPrefs::instance()->getConfig();
366#endif //KAB_EMBEDDED 366#endif //KAB_EMBEDDED
367} 367}
368 368
369KActionCollection *KABCore::actionCollection() const 369KActionCollection *KABCore::actionCollection() const
370{ 370{
371 return mGUIClient->actionCollection(); 371 return mGUIClient->actionCollection();
372} 372}
373 373
374KABC::Field *KABCore::currentSearchField() const 374KABC::Field *KABCore::currentSearchField() const
375{ 375{
376 if (mIncSearchWidget) 376 if (mIncSearchWidget)
377 return mIncSearchWidget->currentField(); 377 return mIncSearchWidget->currentField();
378 else 378 else
379 return 0; 379 return 0;
380} 380}
381 381
382QStringList KABCore::selectedUIDs() const 382QStringList KABCore::selectedUIDs() const
383{ 383{
384 return mViewManager->selectedUids(); 384 return mViewManager->selectedUids();
385} 385}
386 386
387KABC::Resource *KABCore::requestResource( QWidget *parent ) 387KABC::Resource *KABCore::requestResource( QWidget *parent )
388{ 388{
389 QPtrList<KABC::Resource> kabcResources = addressBook()->resources(); 389 QPtrList<KABC::Resource> kabcResources = addressBook()->resources();
390 390
391 QPtrList<KRES::Resource> kresResources; 391 QPtrList<KRES::Resource> kresResources;
392 QPtrListIterator<KABC::Resource> resIt( kabcResources ); 392 QPtrListIterator<KABC::Resource> resIt( kabcResources );
393 KABC::Resource *resource; 393 KABC::Resource *resource;
394 while ( ( resource = resIt.current() ) != 0 ) { 394 while ( ( resource = resIt.current() ) != 0 ) {
395 ++resIt; 395 ++resIt;
396 if ( !resource->readOnly() ) { 396 if ( !resource->readOnly() ) {
397 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 397 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
398 if ( res ) 398 if ( res )
399 kresResources.append( res ); 399 kresResources.append( res );
400 } 400 }
401 } 401 }
402 402
403 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent ); 403 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent );
404 return static_cast<KABC::Resource*>( res ); 404 return static_cast<KABC::Resource*>( res );
405} 405}
406 406
407#ifndef KAB_EMBEDDED 407#ifndef KAB_EMBEDDED
408KAboutData *KABCore::createAboutData() 408KAboutData *KABCore::createAboutData()
409#else //KAB_EMBEDDED 409#else //KAB_EMBEDDED
410void KABCore::createAboutData() 410void KABCore::createAboutData()
411#endif //KAB_EMBEDDED 411#endif //KAB_EMBEDDED
412{ 412{
413#ifndef KAB_EMBEDDED 413#ifndef KAB_EMBEDDED
414 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ), 414 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ),
415 "3.1", I18N_NOOP( "The KDE Address Book" ), 415 "3.1", I18N_NOOP( "The KDE Address Book" ),
416 KAboutData::License_GPL_V2, 416 KAboutData::License_GPL_V2,
417 I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) ); 417 I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) );
418 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" ); 418 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" );
419 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) ); 419 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) );
420 about->addAuthor( "Cornelius Schumacher", 420 about->addAuthor( "Cornelius Schumacher",
421 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ), 421 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ),
422 "schumacher@kde.org" ); 422 "schumacher@kde.org" );
423 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ), 423 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ),
424 "mpilone@slac.com" ); 424 "mpilone@slac.com" );
425 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) ); 425 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) );
426 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) ); 426 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) );
427 about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ), 427 about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ),
428 "michel@klaralvdalens-datakonsult.se" ); 428 "michel@klaralvdalens-datakonsult.se" );
429 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ), 429 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ),
430 "hansen@kde.org" ); 430 "hansen@kde.org" );
431 431
432 return about; 432 return about;
433#endif //KAB_EMBEDDED 433#endif //KAB_EMBEDDED
434 434
435 QString version; 435 QString version;
436#include <../version> 436#include <../version>
437 QMessageBox::about( this, "About KAddressbook/Pi", 437 QMessageBox::about( this, "About KAddressbook/Pi",
438 "KAddressbook/Platform-independent\n" 438 "KAddressbook/Platform-independent\n"
439 "(KA/Pi) " +version + " - " + 439 "(KA/Pi) " +version + " - " +
440#ifdef DESKTOP_VERSION 440#ifdef DESKTOP_VERSION
441 "Desktop Edition\n" 441 "Desktop Edition\n"
442#else 442#else
443 "PDA-Edition\n" 443 "PDA-Edition\n"
444 "for: Zaurus 5500 / 7x0 / 8x0\n" 444 "for: Zaurus 5500 / 7x0 / 8x0\n"
445#endif 445#endif
446 446
447 "(c) 2004 Ulf Schenk\n" 447 "(c) 2004 Ulf Schenk\n"
448 "(c) 2004 Lutz Rogowski\n" 448 "(c) 2004 Lutz Rogowski\n"
449 "(c) 1997-2003, The KDE PIM Team\n" 449 "(c) 1997-2003, The KDE PIM Team\n"
450 "Tobias Koenig Current maintainer\ntokoe@kde.org\n" 450 "Tobias Koenig Current maintainer\ntokoe@kde.org\n"
451 "Don Sanders Original author\n" 451 "Don Sanders Original author\n"
452 "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n" 452 "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n"
453 "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n" 453 "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n"
454 "Greg Stern DCOP interface\n" 454 "Greg Stern DCOP interface\n"
455 "Mark Westcot Contact pinning\n" 455 "Mark Westcot Contact pinning\n"
456 "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n" 456 "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n"
457 "Steffen Hansen LDAP Lookup\nhansen@kde.org\n" 457 "Steffen Hansen LDAP Lookup\nhansen@kde.org\n"
458#ifdef _WIN32_ 458#ifdef _WIN32_
459 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n" 459 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n"
460#endif 460#endif
461 ); 461 );
462} 462}
463 463
464void KABCore::setContactSelected( const QString &uid ) 464void KABCore::setContactSelected( const QString &uid )
465{ 465{
466 KABC::Addressee addr = mAddressBook->findByUid( uid ); 466 KABC::Addressee addr = mAddressBook->findByUid( uid );
467 if ( !mDetails->isHidden() ) 467 if ( !mDetails->isHidden() )
468 mDetails->setAddressee( addr ); 468 mDetails->setAddressee( addr );
469 469
470 if ( !addr.isEmpty() ) { 470 if ( !addr.isEmpty() ) {
471 emit contactSelected( addr.formattedName() ); 471 emit contactSelected( addr.formattedName() );
472 KABC::Picture pic = addr.photo(); 472 KABC::Picture pic = addr.photo();
473 if ( pic.isIntern() ) { 473 if ( pic.isIntern() ) {
474//US emit contactSelected( pic.data() ); 474//US emit contactSelected( pic.data() );
475//US instead use: 475//US instead use:
476 QPixmap px; 476 QPixmap px;
477 if (pic.data().isNull() != true) 477 if (pic.data().isNull() != true)
478 { 478 {
479 px.convertFromImage(pic.data()); 479 px.convertFromImage(pic.data());
480 } 480 }
481 481
482 emit contactSelected( px ); 482 emit contactSelected( px );
483 } 483 }
484 } 484 }
485 485
486 486
487 mExtensionManager->setSelectionChanged(); 487 mExtensionManager->setSelectionChanged();
488 488
489 // update the actions 489 // update the actions
490 bool selected = !uid.isEmpty(); 490 bool selected = !uid.isEmpty();
491 491
492 if ( mReadWrite ) { 492 if ( mReadWrite ) {
493 mActionCut->setEnabled( selected ); 493 mActionCut->setEnabled( selected );
494 mActionPaste->setEnabled( selected ); 494 mActionPaste->setEnabled( selected );
495 } 495 }
496 496
497 mActionCopy->setEnabled( selected ); 497 mActionCopy->setEnabled( selected );
498 mActionDelete->setEnabled( selected ); 498 mActionDelete->setEnabled( selected );
499 mActionEditAddressee->setEnabled( selected ); 499 mActionEditAddressee->setEnabled( selected );
500 mActionMail->setEnabled( selected ); 500 mActionMail->setEnabled( selected );
501 mActionMailVCard->setEnabled( selected ); 501 mActionMailVCard->setEnabled( selected );
502 //if (mActionBeam) 502 //if (mActionBeam)
503 //mActionBeam->setEnabled( selected ); 503 //mActionBeam->setEnabled( selected );
504 504
505 if (mActionBeamVCard) 505 if (mActionBeamVCard)
506 mActionBeamVCard->setEnabled( selected ); 506 mActionBeamVCard->setEnabled( selected );
507 507
508 mActionWhoAmI->setEnabled( selected ); 508 mActionWhoAmI->setEnabled( selected );
509 mActionCategories->setEnabled( selected ); 509 mActionCategories->setEnabled( selected );
510} 510}
511 511
512void KABCore::sendMail() 512void KABCore::sendMail()
513{ 513{
514 sendMail( mViewManager->selectedEmails().join( ", " ) ); 514 sendMail( mViewManager->selectedEmails().join( ", " ) );
515} 515}
516 516
517void KABCore::sendMail( const QString& emaillist ) 517void KABCore::sendMail( const QString& emaillist )
518{ 518{
519 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... " 519 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... "
520 if (emaillist.contains(",") > 0) 520 if (emaillist.contains(",") > 0)
521 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null ); 521 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null );
522 else 522 else
523 ExternalAppHandler::instance()->mailToOneContact( emaillist ); 523 ExternalAppHandler::instance()->mailToOneContact( emaillist );
524} 524}
525 525
526 526
527 527
528void KABCore::mailVCard() 528void KABCore::mailVCard()
529{ 529{
530 QStringList uids = mViewManager->selectedUids(); 530 QStringList uids = mViewManager->selectedUids();
531 if ( !uids.isEmpty() ) 531 if ( !uids.isEmpty() )
532 mailVCard( uids ); 532 mailVCard( uids );
533} 533}
534 534
535void KABCore::mailVCard( const QStringList& uids ) 535void KABCore::mailVCard( const QStringList& uids )
536{ 536{
537 QStringList urls; 537 QStringList urls;
538 538
539// QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); 539// QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
540 540
541 QString dirName = "/tmp/" + KApplication::randomString( 8 ); 541 QString dirName = "/tmp/" + KApplication::randomString( 8 );
542 542
543 543
544 544
545 QDir().mkdir( dirName, true ); 545 QDir().mkdir( dirName, true );
546 546
547 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 547 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
548 KABC::Addressee a = mAddressBook->findByUid( *it ); 548 KABC::Addressee a = mAddressBook->findByUid( *it );
549 549
550 if ( a.isEmpty() ) 550 if ( a.isEmpty() )
551 continue; 551 continue;
552 552
553 QString name = a.givenName() + "_" + a.familyName() + ".vcf"; 553 QString name = a.givenName() + "_" + a.familyName() + ".vcf";
554 554
555 QString fileName = dirName + "/" + name; 555 QString fileName = dirName + "/" + name;
556 556
557 QFile outFile(fileName); 557 QFile outFile(fileName);
558 558
559 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully 559 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully
560 KABC::VCardConverter converter; 560 KABC::VCardConverter converter;
561 QString vcard; 561 QString vcard;
562 562
563 converter.addresseeToVCard( a, vcard ); 563 converter.addresseeToVCard( a, vcard );
564 564
565 QTextStream t( &outFile ); // use a text stream 565 QTextStream t( &outFile ); // use a text stream
566 t.setEncoding( QTextStream::UnicodeUTF8 ); 566 t.setEncoding( QTextStream::UnicodeUTF8 );
567 t << vcard; 567 t << vcard;
568 568
569 outFile.close(); 569 outFile.close();
570 570
571 urls.append( fileName ); 571 urls.append( fileName );
572 } 572 }
573 } 573 }
574 574
575 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); 575 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") );
576 576
577 577
578/*US 578/*US
579 kapp->invokeMailer( QString::null, QString::null, QString::null, 579 kapp->invokeMailer( QString::null, QString::null, QString::null,
580 QString::null, // subject 580 QString::null, // subject
581 QString::null, // body 581 QString::null, // body
582 QString::null, 582 QString::null,
583 urls ); // attachments 583 urls ); // attachments
584*/ 584*/
585 585
586} 586}
587 587
588/** 588/**
589 Beams the "WhoAmI contact. 589 Beams the "WhoAmI contact.
590*/ 590*/
591void KABCore::beamMySelf() 591void KABCore::beamMySelf()
592{ 592{
593 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); 593 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI();
594 if (!a.isEmpty()) 594 if (!a.isEmpty())
595 { 595 {
596 QStringList uids; 596 QStringList uids;
597 uids << a.uid(); 597 uids << a.uid();
598 598
599 beamVCard(uids); 599 beamVCard(uids);
600 } else { 600 } else {
601 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); 601 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) );
602 602
603 603
604 } 604 }
605} 605}
606 606
607void KABCore::beamVCard() 607void KABCore::beamVCard()
608{ 608{
609 QStringList uids = mViewManager->selectedUids(); 609 QStringList uids = mViewManager->selectedUids();
610 if ( !uids.isEmpty() ) 610 if ( !uids.isEmpty() )
611 beamVCard( uids ); 611 beamVCard( uids );
612} 612}
613 613
614 614
615void KABCore::beamVCard(const QStringList& uids) 615void KABCore::beamVCard(const QStringList& uids)
616{ 616{
617/*US 617/*US
618 QString beamFilename; 618 QString beamFilename;
619 Opie::OPimContact c; 619 Opie::OPimContact c;
620 if ( actionPersonal->isOn() ) { 620 if ( actionPersonal->isOn() ) {
621 beamFilename = addressbookPersonalVCardName(); 621 beamFilename = addressbookPersonalVCardName();
622 if ( !QFile::exists( beamFilename ) ) 622 if ( !QFile::exists( beamFilename ) )
623 return; // can't beam a non-existent file 623 return; // can't beam a non-existent file
624 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, 624 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
625 beamFilename ); 625 beamFilename );
626 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); 626 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
627 Opie::OPimContactAccess::List allList = access->allRecords(); 627 Opie::OPimContactAccess::List allList = access->allRecords();
628 Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first 628 Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first
629 c = *it; 629 c = *it;
630 630
631 delete access; 631 delete access;
632 } else { 632 } else {
633 unlink( beamfile ); // delete if exists 633 unlink( beamfile ); // delete if exists
634 mkdir("/tmp/obex/", 0755); 634 mkdir("/tmp/obex/", 0755);
635 c = m_abView -> currentEntry(); 635 c = m_abView -> currentEntry();
636 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, 636 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
637 beamfile ); 637 beamfile );
638 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); 638 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
639 access->add( c ); 639 access->add( c );
640 access->save(); 640 access->save();
641 delete access; 641 delete access;
642 642
643 beamFilename = beamfile; 643 beamFilename = beamfile;
644 } 644 }
645 645
646 owarn << "Beaming: " << beamFilename << oendl; 646 owarn << "Beaming: " << beamFilename << oendl;
647*/ 647*/
648 648
649#if 0 649#if 0
650 QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); 650 QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
651 651
652 QString dirName = tmpdir + "/" + KApplication::randomString( 8 ); 652 QString dirName = tmpdir + "/" + KApplication::randomString( 8 );
653 653
654 QString name = "contact.vcf"; 654 QString name = "contact.vcf";
655 655
656 QString fileName = dirName + "/" + name; 656 QString fileName = dirName + "/" + name;
657#endif 657#endif
658 // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory 658 // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory
659 // 659 //
660 QString fileName = "/tmp/kapibeamfile.vcf"; 660 QString fileName = "/tmp/kapibeamfile.vcf";
661 661
662 662
663 //QDir().mkdir( dirName, true ); 663 //QDir().mkdir( dirName, true );
664 664
665 665
666 KABC::VCardConverter converter; 666 KABC::VCardConverter converter;
667 QString description; 667 QString description;
668 QString datastream; 668 QString datastream;
669 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 669 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
670 KABC::Addressee a = mAddressBook->findByUid( *it ); 670 KABC::Addressee a = mAddressBook->findByUid( *it );
671 671
672 if ( a.isEmpty() ) 672 if ( a.isEmpty() )
673 continue; 673 continue;
674 674
675 if (description.isEmpty()) 675 if (description.isEmpty())
676 description = a.formattedName(); 676 description = a.formattedName();
677 677
678 QString vcard; 678 QString vcard;
679 converter.addresseeToVCard( a, vcard ); 679 converter.addresseeToVCard( a, vcard );
680 int start = 0; 680 int start = 0;
681 int next; 681 int next;
682 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 682 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
683 int semi = vcard.find(";", next); 683 int semi = vcard.find(";", next);
684 int dopp = vcard.find(":", next); 684 int dopp = vcard.find(":", next);
685 int sep; 685 int sep;
686 if ( semi < dopp && semi >= 0 ) 686 if ( semi < dopp && semi >= 0 )
687 sep = semi ; 687 sep = semi ;
688 else 688 else
689 sep = dopp; 689 sep = dopp;
690 datastream +=vcard.mid( start, next - start); 690 datastream +=vcard.mid( start, next - start);
691 datastream +=vcard.mid( next+5,sep -next -5 ).upper(); 691 datastream +=vcard.mid( next+5,sep -next -5 ).upper();
692 start = sep; 692 start = sep;
693 } 693 }
694 datastream += vcard.mid( start,vcard.length() ); 694 datastream += vcard.mid( start,vcard.length() );
695 } 695 }
696#ifndef DESKTOP_VERSION 696#ifndef DESKTOP_VERSION
697 QFile outFile(fileName); 697 QFile outFile(fileName);
698 if ( outFile.open(IO_WriteOnly) ) { 698 if ( outFile.open(IO_WriteOnly) ) {
699 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 699 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
700 QTextStream t( &outFile ); // use a text stream 700 QTextStream t( &outFile ); // use a text stream
701 t.setEncoding( QTextStream::UnicodeUTF8 ); 701 t.setEncoding( QTextStream::UnicodeUTF8 );
702 t <<datastream; 702 t <<datastream;
703 outFile.close(); 703 outFile.close();
704 Ir *ir = new Ir( this ); 704 Ir *ir = new Ir( this );
705 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); 705 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) );
706 ir->send( fileName, description, "text/x-vCard" ); 706 ir->send( fileName, description, "text/x-vCard" );
707 } else { 707 } else {
708 qDebug("Error open temp beam file "); 708 qDebug("Error open temp beam file ");
709 return; 709 return;
710 } 710 }
711#endif 711#endif
712 712
713} 713}
714 714
715void KABCore::beamDone( Ir *ir ) 715void KABCore::beamDone( Ir *ir )
716{ 716{
717#ifndef DESKTOP_VERSION 717#ifndef DESKTOP_VERSION
718 delete ir; 718 delete ir;
719#endif 719#endif
720} 720}
721 721
722 722
723void KABCore::browse( const QString& url ) 723void KABCore::browse( const QString& url )
724{ 724{
725#ifndef KAB_EMBEDDED 725#ifndef KAB_EMBEDDED
726 kapp->invokeBrowser( url ); 726 kapp->invokeBrowser( url );
727#else //KAB_EMBEDDED 727#else //KAB_EMBEDDED
728 qDebug("KABCore::browse must be fixed"); 728 qDebug("KABCore::browse must be fixed");
729#endif //KAB_EMBEDDED 729#endif //KAB_EMBEDDED
730} 730}
731 731
732void KABCore::selectAllContacts() 732void KABCore::selectAllContacts()
733{ 733{
734 mViewManager->setSelected( QString::null, true ); 734 mViewManager->setSelected( QString::null, true );
735} 735}
736 736
737void KABCore::deleteContacts() 737void KABCore::deleteContacts()
738{ 738{
739 QStringList uidList = mViewManager->selectedUids(); 739 QStringList uidList = mViewManager->selectedUids();
740 deleteContacts( uidList ); 740 deleteContacts( uidList );
741} 741}
742 742
743void KABCore::deleteContacts( const QStringList &uids ) 743void KABCore::deleteContacts( const QStringList &uids )
744{ 744{
745 if ( uids.count() > 0 ) { 745 if ( uids.count() > 0 ) {
746 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); 746 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids );
747 UndoStack::instance()->push( command ); 747 UndoStack::instance()->push( command );
748 RedoStack::instance()->clear(); 748 RedoStack::instance()->clear();
749 749
750 // now if we deleted anything, refresh 750 // now if we deleted anything, refresh
751 setContactSelected( QString::null ); 751 setContactSelected( QString::null );
752 setModified( true ); 752 setModified( true );
753 } 753 }
754} 754}
755 755
756void KABCore::copyContacts() 756void KABCore::copyContacts()
757{ 757{
758 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 758 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
759 759
760 QString clipText = AddresseeUtil::addresseesToClipboard( addrList ); 760 QString clipText = AddresseeUtil::addresseesToClipboard( addrList );
761 761
762 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl; 762 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl;
763 763
764 QClipboard *cb = QApplication::clipboard(); 764 QClipboard *cb = QApplication::clipboard();
765 cb->setText( clipText ); 765 cb->setText( clipText );
766} 766}
767 767
768void KABCore::cutContacts() 768void KABCore::cutContacts()
769{ 769{
770 QStringList uidList = mViewManager->selectedUids(); 770 QStringList uidList = mViewManager->selectedUids();
771 771
772//US if ( uidList.size() > 0 ) { 772//US if ( uidList.size() > 0 ) {
773 if ( uidList.count() > 0 ) { 773 if ( uidList.count() > 0 ) {
774 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); 774 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList );
775 UndoStack::instance()->push( command ); 775 UndoStack::instance()->push( command );
776 RedoStack::instance()->clear(); 776 RedoStack::instance()->clear();
777 777
778 setModified( true ); 778 setModified( true );
779 } 779 }
780} 780}
781 781
782void KABCore::pasteContacts() 782void KABCore::pasteContacts()
783{ 783{
784 QClipboard *cb = QApplication::clipboard(); 784 QClipboard *cb = QApplication::clipboard();
785 785
786 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); 786 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() );
787 787
788 pasteContacts( list ); 788 pasteContacts( list );
789} 789}
790 790
791void KABCore::pasteContacts( KABC::Addressee::List &list ) 791void KABCore::pasteContacts( KABC::Addressee::List &list )
792{ 792{
793 KABC::Resource *resource = requestResource( this ); 793 KABC::Resource *resource = requestResource( this );
794 KABC::Addressee::List::Iterator it; 794 KABC::Addressee::List::Iterator it;
795 for ( it = list.begin(); it != list.end(); ++it ) 795 for ( it = list.begin(); it != list.end(); ++it )
796 (*it).setResource( resource ); 796 (*it).setResource( resource );
797 797
798 PwPasteCommand *command = new PwPasteCommand( this, list ); 798 PwPasteCommand *command = new PwPasteCommand( this, list );
799 UndoStack::instance()->push( command ); 799 UndoStack::instance()->push( command );
800 RedoStack::instance()->clear(); 800 RedoStack::instance()->clear();
801 801
802 setModified( true ); 802 setModified( true );
803} 803}
804 804
805void KABCore::setWhoAmI() 805void KABCore::setWhoAmI()
806{ 806{
807 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 807 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
808 808
809 if ( addrList.count() > 1 ) { 809 if ( addrList.count() > 1 ) {
810 KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); 810 KMessageBox::sorry( this, i18n( "Please select only one contact." ) );
811 return; 811 return;
812 } 812 }
813 813
814 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); 814 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) );
815 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) 815 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes )
816 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); 816 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] );
817} 817}
818 818
819void KABCore::setCategories() 819void KABCore::setCategories()
820{ 820{
821 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); 821 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true );
822 if ( !dlg.exec() ) 822 if ( !dlg.exec() )
823 return; 823 return;
824 824
825 bool merge = false; 825 bool merge = false;
826 QString msg = i18n( "Merge with existing categories?" ); 826 QString msg = i18n( "Merge with existing categories?" );
827 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) 827 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes )
828 merge = true; 828 merge = true;
829 829
830 QStringList categories = dlg.selectedCategories(); 830 QStringList categories = dlg.selectedCategories();
831 831
832 QStringList uids = mViewManager->selectedUids(); 832 QStringList uids = mViewManager->selectedUids();
833 QStringList::Iterator it; 833 QStringList::Iterator it;
834 for ( it = uids.begin(); it != uids.end(); ++it ) { 834 for ( it = uids.begin(); it != uids.end(); ++it ) {
835 KABC::Addressee addr = mAddressBook->findByUid( *it ); 835 KABC::Addressee addr = mAddressBook->findByUid( *it );
836 if ( !addr.isEmpty() ) { 836 if ( !addr.isEmpty() ) {
837 if ( !merge ) 837 if ( !merge )
838 addr.setCategories( categories ); 838 addr.setCategories( categories );
839 else { 839 else {
840 QStringList addrCategories = addr.categories(); 840 QStringList addrCategories = addr.categories();
841 QStringList::Iterator catIt; 841 QStringList::Iterator catIt;
842 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { 842 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
843 if ( !addrCategories.contains( *catIt ) ) 843 if ( !addrCategories.contains( *catIt ) )
844 addrCategories.append( *catIt ); 844 addrCategories.append( *catIt );
845 } 845 }
846 addr.setCategories( addrCategories ); 846 addr.setCategories( addrCategories );
847 } 847 }
848 848
849 mAddressBook->insertAddressee( addr ); 849 mAddressBook->insertAddressee( addr );
850 } 850 }
851 } 851 }
852 852
853 if ( uids.count() > 0 ) 853 if ( uids.count() > 0 )
854 setModified( true ); 854 setModified( true );
855} 855}
856 856
857void KABCore::setSearchFields( const KABC::Field::List &fields ) 857void KABCore::setSearchFields( const KABC::Field::List &fields )
858{ 858{
859 mIncSearchWidget->setFields( fields ); 859 mIncSearchWidget->setFields( fields );
860} 860}
861 861
862void KABCore::incrementalSearch( const QString& text ) 862void KABCore::incrementalSearch( const QString& text )
863{ 863{
864 mViewManager->doSearch( text, mIncSearchWidget->currentField() ); 864 mViewManager->doSearch( text, mIncSearchWidget->currentField() );
865} 865}
866 866
867void KABCore::setModified() 867void KABCore::setModified()
868{ 868{
869 setModified( true ); 869 setModified( true );
870} 870}
871 871
872void KABCore::setModifiedWOrefresh() 872void KABCore::setModifiedWOrefresh()
873{ 873{
874 // qDebug("KABCore::setModifiedWOrefresh() "); 874 // qDebug("KABCore::setModifiedWOrefresh() ");
875 mModified = true; 875 mModified = true;
876 mActionSave->setEnabled( mModified ); 876 mActionSave->setEnabled( mModified );
877#ifdef DESKTOP_VERSION 877#ifdef DESKTOP_VERSION
878 mDetails->refreshView(); 878 mDetails->refreshView();
879#endif 879#endif
880 880
881} 881}
882void KABCore::setModified( bool modified ) 882void KABCore::setModified( bool modified )
883{ 883{
884 mModified = modified; 884 mModified = modified;
885 mActionSave->setEnabled( mModified ); 885 mActionSave->setEnabled( mModified );
886 886
887 if ( modified ) 887 if ( modified )
888 mJumpButtonBar->recreateButtons(); 888 mJumpButtonBar->recreateButtons();
889 889
890 mViewManager->refreshView(); 890 mViewManager->refreshView();
891 mDetails->refreshView(); 891 mDetails->refreshView();
892 892
893} 893}
894 894
895bool KABCore::modified() const 895bool KABCore::modified() const
896{ 896{
897 return mModified; 897 return mModified;
898} 898}
899 899
900void KABCore::contactModified( const KABC::Addressee &addr ) 900void KABCore::contactModified( const KABC::Addressee &addr )
901{ 901{
902 902
903 Command *command = 0; 903 Command *command = 0;
904 QString uid; 904 QString uid;
905 905
906 // check if it exists already 906 // check if it exists already
907 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); 907 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() );
908 if ( origAddr.isEmpty() ) 908 if ( origAddr.isEmpty() )
909 command = new PwNewCommand( mAddressBook, addr ); 909 command = new PwNewCommand( mAddressBook, addr );
910 else { 910 else {
911 command = new PwEditCommand( mAddressBook, origAddr, addr ); 911 command = new PwEditCommand( mAddressBook, origAddr, addr );
912 uid = addr.uid(); 912 uid = addr.uid();
913 } 913 }
914 914
915 UndoStack::instance()->push( command ); 915 UndoStack::instance()->push( command );
916 RedoStack::instance()->clear(); 916 RedoStack::instance()->clear();
917 917
918 setModified( true ); 918 setModified( true );
919} 919}
920 920
921void KABCore::newContact() 921void KABCore::newContact()
922{ 922{
923 923
924 924
925 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); 925 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources();
926 926
927 QPtrList<KRES::Resource> kresResources; 927 QPtrList<KRES::Resource> kresResources;
928 QPtrListIterator<KABC::Resource> it( kabcResources ); 928 QPtrListIterator<KABC::Resource> it( kabcResources );
929 KABC::Resource *resource; 929 KABC::Resource *resource;
930 while ( ( resource = it.current() ) != 0 ) { 930 while ( ( resource = it.current() ) != 0 ) {
931 ++it; 931 ++it;
932 if ( !resource->readOnly() ) { 932 if ( !resource->readOnly() ) {
933 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 933 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
934 if ( res ) 934 if ( res )
935 kresResources.append( res ); 935 kresResources.append( res );
936 } 936 }
937 } 937 }
938 938
939 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); 939 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this );
940 resource = static_cast<KABC::Resource*>( res ); 940 resource = static_cast<KABC::Resource*>( res );
941 941
942 if ( resource ) { 942 if ( resource ) {
943 KABC::Addressee addr; 943 KABC::Addressee addr;
944 addr.setResource( resource ); 944 addr.setResource( resource );
945 mEditorDialog->setAddressee( addr ); 945 mEditorDialog->setAddressee( addr );
946 KApplication::execDialog ( mEditorDialog ); 946 KApplication::execDialog ( mEditorDialog );
947 947
948 } else 948 } else
949 return; 949 return;
950 950
951 // mEditorDict.insert( dialog->addressee().uid(), dialog ); 951 // mEditorDict.insert( dialog->addressee().uid(), dialog );
952 952
953 953
954} 954}
955 955
956void KABCore::addEmail( QString aStr ) 956void KABCore::addEmail( QString aStr )
957{ 957{
958#ifndef KAB_EMBEDDED 958#ifndef KAB_EMBEDDED
959 QString fullName, email; 959 QString fullName, email;
960 960
961 KABC::Addressee::parseEmailAddress( aStr, fullName, email ); 961 KABC::Addressee::parseEmailAddress( aStr, fullName, email );
962 962
963 // Try to lookup the addressee matching the email address 963 // Try to lookup the addressee matching the email address
964 bool found = false; 964 bool found = false;
965 QStringList emailList; 965 QStringList emailList;
966 KABC::AddressBook::Iterator it; 966 KABC::AddressBook::Iterator it;
967 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { 967 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) {
968 emailList = (*it).emails(); 968 emailList = (*it).emails();
969 if ( emailList.contains( email ) > 0 ) { 969 if ( emailList.contains( email ) > 0 ) {
970 found = true; 970 found = true;
971 (*it).setNameFromString( fullName ); 971 (*it).setNameFromString( fullName );
972 editContact( (*it).uid() ); 972 editContact( (*it).uid() );
973 } 973 }
974 } 974 }
975 975
976 if ( !found ) { 976 if ( !found ) {
977 KABC::Addressee addr; 977 KABC::Addressee addr;
978 addr.setNameFromString( fullName ); 978 addr.setNameFromString( fullName );
979 addr.insertEmail( email, true ); 979 addr.insertEmail( email, true );
980 980
981 mAddressBook->insertAddressee( addr ); 981 mAddressBook->insertAddressee( addr );
982 mViewManager->refreshView( addr.uid() ); 982 mViewManager->refreshView( addr.uid() );
983 editContact( addr.uid() ); 983 editContact( addr.uid() );
984 } 984 }
985#else //KAB_EMBEDDED 985#else //KAB_EMBEDDED
986 qDebug("KABCore::addEmail finsih method"); 986 qDebug("KABCore::addEmail finsih method");
987#endif //KAB_EMBEDDED 987#endif //KAB_EMBEDDED
988} 988}
989 989
990void KABCore::importVCard( const KURL &url, bool showPreview ) 990void KABCore::importVCard( const KURL &url, bool showPreview )
991{ 991{
992 mXXPortManager->importVCard( url, showPreview ); 992 mXXPortManager->importVCard( url, showPreview );
993} 993}
994void KABCore::importFromOL() 994void KABCore::importFromOL()
995{ 995{
996#ifdef _WIN32_ 996#ifdef _WIN32_
997 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); 997 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this );
998 idgl->exec(); 998 idgl->exec();
999 KABC::Addressee::List list = idgl->getAddressList(); 999 KABC::Addressee::List list = idgl->getAddressList();
1000 if ( list.count() > 0 ) { 1000 if ( list.count() > 0 ) {
1001 KABC::Addressee::List listNew; 1001 KABC::Addressee::List listNew;
1002 KABC::Addressee::List listExisting; 1002 KABC::Addressee::List listExisting;
1003 KABC::Addressee::List::Iterator it; 1003 KABC::Addressee::List::Iterator it;
1004 KABC::AddressBook::Iterator iter; 1004 KABC::AddressBook::Iterator iter;
1005 for ( it = list.begin(); it != list.end(); ++it ) { 1005 for ( it = list.begin(); it != list.end(); ++it ) {
1006 if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) 1006 if ( mAddressBook->findByUid((*it).uid() ).isEmpty())
1007 listNew.append( (*it) ); 1007 listNew.append( (*it) );
1008 else 1008 else
1009 listExisting.append( (*it) ); 1009 listExisting.append( (*it) );
1010 } 1010 }
1011 if ( listExisting.count() > 0 ) 1011 if ( listExisting.count() > 0 )
1012 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); 1012 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() ));
1013 if ( listNew.count() > 0 ) { 1013 if ( listNew.count() > 0 ) {
1014 pasteWithNewUid = false; 1014 pasteWithNewUid = false;
1015 pasteContacts( listNew ); 1015 pasteContacts( listNew );
1016 pasteWithNewUid = true; 1016 pasteWithNewUid = true;
1017 } 1017 }
1018 } 1018 }
1019 delete idgl; 1019 delete idgl;
1020#endif 1020#endif
1021} 1021}
1022 1022
1023void KABCore::importVCard( const QString &vCard, bool showPreview ) 1023void KABCore::importVCard( const QString &vCard, bool showPreview )
1024{ 1024{
1025 mXXPortManager->importVCard( vCard, showPreview ); 1025 mXXPortManager->importVCard( vCard, showPreview );
1026} 1026}
1027 1027
1028//US added a second method without defaultparameter 1028//US added a second method without defaultparameter
1029void KABCore::editContact2() { 1029void KABCore::editContact2() {
1030 editContact( QString::null ); 1030 editContact( QString::null );
1031} 1031}
1032 1032
1033void KABCore::editContact( const QString &uid ) 1033void KABCore::editContact( const QString &uid )
1034{ 1034{
1035 1035
1036 if ( mExtensionManager->isQuickEditVisible() ) 1036 if ( mExtensionManager->isQuickEditVisible() )
1037 return; 1037 return;
1038 1038
1039 // First, locate the contact entry 1039 // First, locate the contact entry
1040 QString localUID = uid; 1040 QString localUID = uid;
1041 if ( localUID.isNull() ) { 1041 if ( localUID.isNull() ) {
1042 QStringList uidList = mViewManager->selectedUids(); 1042 QStringList uidList = mViewManager->selectedUids();
1043 if ( uidList.count() > 0 ) 1043 if ( uidList.count() > 0 )
1044 localUID = *( uidList.at( 0 ) ); 1044 localUID = *( uidList.at( 0 ) );
1045 } 1045 }
1046 1046
1047 KABC::Addressee addr = mAddressBook->findByUid( localUID ); 1047 KABC::Addressee addr = mAddressBook->findByUid( localUID );
1048 if ( !addr.isEmpty() ) { 1048 if ( !addr.isEmpty() ) {
1049 mEditorDialog->setAddressee( addr ); 1049 mEditorDialog->setAddressee( addr );
1050 KApplication::execDialog ( mEditorDialog ); 1050 KApplication::execDialog ( mEditorDialog );
1051 } 1051 }
1052} 1052}
1053 1053
1054/** 1054/**
1055 Shows or edits the detail view for the given uid. If the uid is QString::null, 1055 Shows or edits the detail view for the given uid. If the uid is QString::null,
1056 the method will try to find a selected addressee in the view. 1056 the method will try to find a selected addressee in the view.
1057 */ 1057 */
1058void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) 1058void KABCore::executeContact( const QString &uid /*US = QString::null*/ )
1059{ 1059{
1060 if ( mMultipleViewsAtOnce ) 1060 if ( mMultipleViewsAtOnce )
1061 { 1061 {
1062 editContact( uid ); 1062 editContact( uid );
1063 } 1063 }
1064 else 1064 else
1065 { 1065 {
1066 setDetailsVisible( true ); 1066 setDetailsVisible( true );
1067 mActionDetails->setChecked(true); 1067 mActionDetails->setChecked(true);
1068 } 1068 }
1069 1069
1070} 1070}
1071 1071
1072void KABCore::save() 1072void KABCore::save()
1073{ 1073{
1074 if (mBlockSaveFlag) 1074 if (mBlockSaveFlag)
1075 return; 1075 return;
1076 mBlockSaveFlag = true; 1076 mBlockSaveFlag = true;
1077 if ( !mModified ) 1077 if ( !mModified )
1078 return; 1078 return;
1079 QString text = i18n( "There was an error while attempting to save\n the " 1079 QString text = i18n( "There was an error while attempting to save\n the "
1080 "address book. Please check that some \nother application is " 1080 "address book. Please check that some \nother application is "
1081 "not using it. " ); 1081 "not using it. " );
1082 statusMessage(i18n("Saving addressbook ... ")); 1082 statusMessage(i18n("Saving addressbook ... "));
1083#ifndef KAB_EMBEDDED 1083#ifndef KAB_EMBEDDED
1084 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); 1084 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
1085 if ( !b || !b->save() ) { 1085 if ( !b || !b->save() ) {
1086 KMessageBox::error( this, text, i18n( "Unable to Save" ) ); 1086 KMessageBox::error( this, text, i18n( "Unable to Save" ) );
1087 } 1087 }
1088#else //KAB_EMBEDDED 1088#else //KAB_EMBEDDED
1089 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); 1089 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook );
1090 if ( !b || !b->save() ) { 1090 if ( !b || !b->save() ) {
1091 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); 1091 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok"));
1092 } 1092 }
1093#endif //KAB_EMBEDDED 1093#endif //KAB_EMBEDDED
1094 1094
1095 statusMessage(i18n("Addressbook saved!")); 1095 statusMessage(i18n("Addressbook saved!"));
1096 setModified( false ); 1096 setModified( false );
1097 mBlockSaveFlag = false; 1097 mBlockSaveFlag = false;
1098} 1098}
1099 1099
1100void KABCore::statusMessage(QString mess , int time ) 1100void KABCore::statusMessage(QString mess , int time )
1101{ 1101{
1102 //topLevelWidget()->setCaption( mess ); 1102 //topLevelWidget()->setCaption( mess );
1103 // pending setting timer to revome message 1103 // pending setting timer to revome message
1104} 1104}
1105void KABCore::undo() 1105void KABCore::undo()
1106{ 1106{
1107 UndoStack::instance()->undo(); 1107 UndoStack::instance()->undo();
1108 1108
1109 // Refresh the view 1109 // Refresh the view
1110 mViewManager->refreshView(); 1110 mViewManager->refreshView();
1111} 1111}
1112 1112
1113void KABCore::redo() 1113void KABCore::redo()
1114{ 1114{
1115 RedoStack::instance()->redo(); 1115 RedoStack::instance()->redo();
1116 1116
1117 // Refresh the view 1117 // Refresh the view
1118 mViewManager->refreshView(); 1118 mViewManager->refreshView();
1119} 1119}
1120 1120
1121void KABCore::setJumpButtonBarVisible( bool visible ) 1121void KABCore::setJumpButtonBarVisible( bool visible )
1122{ 1122{
1123 if (mMultipleViewsAtOnce) 1123 if (mMultipleViewsAtOnce)
1124 { 1124 {
1125 if ( visible ) 1125 if ( visible )
1126 mJumpButtonBar->show(); 1126 mJumpButtonBar->show();
1127 else 1127 else
1128 mJumpButtonBar->hide(); 1128 mJumpButtonBar->hide();
1129 } 1129 }
1130 else 1130 else
1131 { 1131 {
1132 // show the jumpbar only if "the details are hidden" == "viewmanager are shown" 1132 // show the jumpbar only if "the details are hidden" == "viewmanager are shown"
1133 if (mViewManager->isVisible()) 1133 if (mViewManager->isVisible())
1134 { 1134 {
1135 if ( visible ) 1135 if ( visible )
1136 mJumpButtonBar->show(); 1136 mJumpButtonBar->show();
1137 else 1137 else
1138 mJumpButtonBar->hide(); 1138 mJumpButtonBar->hide();
1139 } 1139 }
1140 else 1140 else
1141 { 1141 {
1142 mJumpButtonBar->hide(); 1142 mJumpButtonBar->hide();
1143 } 1143 }
1144 } 1144 }
1145} 1145}
1146 1146
1147 1147
1148void KABCore::setDetailsToState() 1148void KABCore::setDetailsToState()
1149{ 1149{
1150 setDetailsVisible( mActionDetails->isChecked() ); 1150 setDetailsVisible( mActionDetails->isChecked() );
1151} 1151}
1152 1152
1153 1153
1154 1154
1155void KABCore::setDetailsVisible( bool visible ) 1155void KABCore::setDetailsVisible( bool visible )
1156{ 1156{
1157 if (visible && mDetails->isHidden()) 1157 if (visible && mDetails->isHidden())
1158 { 1158 {
1159 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 1159 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
1160 if ( addrList.count() > 0 ) 1160 if ( addrList.count() > 0 )
1161 mDetails->setAddressee( addrList[ 0 ] ); 1161 mDetails->setAddressee( addrList[ 0 ] );
1162 } 1162 }
1163 1163
1164 // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between 1164 // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between
1165 // the listview and the detailview. We do that by changing the splitbar size. 1165 // the listview and the detailview. We do that by changing the splitbar size.
1166 if (mMultipleViewsAtOnce) 1166 if (mMultipleViewsAtOnce)
1167 { 1167 {
1168 if ( visible ) 1168 if ( visible )
1169 mDetails->show(); 1169 mDetails->show();
1170 else 1170 else
1171 mDetails->hide(); 1171 mDetails->hide();
1172 } 1172 }
1173 else 1173 else
1174 { 1174 {
1175 if ( visible ) { 1175 if ( visible ) {
1176 mViewManager->hide(); 1176 mViewManager->hide();
1177 mDetails->show(); 1177 mDetails->show();
1178 } 1178 }
1179 else { 1179 else {
1180 mViewManager->show(); 1180 mViewManager->show();
1181 mDetails->hide(); 1181 mDetails->hide();
1182 } 1182 }
1183 setJumpButtonBarVisible( !visible ); 1183 setJumpButtonBarVisible( !visible );
1184 } 1184 }
1185 1185
1186} 1186}
1187 1187
1188void KABCore::extensionChanged( int id ) 1188void KABCore::extensionChanged( int id )
1189{ 1189{
1190 //change the details view only for non desktop systems 1190 //change the details view only for non desktop systems
1191#ifndef DESKTOP_VERSION 1191#ifndef DESKTOP_VERSION
1192 1192
1193 if (id == 0) 1193 if (id == 0)
1194 { 1194 {
1195 //the user disabled the extension. 1195 //the user disabled the extension.
1196 1196
1197 if (mMultipleViewsAtOnce) 1197 if (mMultipleViewsAtOnce)
1198 { // enable detailsview again 1198 { // enable detailsview again
1199 setDetailsVisible( true ); 1199 setDetailsVisible( true );
1200 mActionDetails->setChecked( true ); 1200 mActionDetails->setChecked( true );
1201 } 1201 }
1202 else 1202 else
1203 { //go back to the listview 1203 { //go back to the listview
1204 setDetailsVisible( false ); 1204 setDetailsVisible( false );
1205 mActionDetails->setChecked( false ); 1205 mActionDetails->setChecked( false );
1206 mActionDetails->setEnabled(true); 1206 mActionDetails->setEnabled(true);
1207 } 1207 }
1208 1208
1209 } 1209 }
1210 else 1210 else
1211 { 1211 {
1212 //the user enabled the extension. 1212 //the user enabled the extension.
1213 setDetailsVisible( false ); 1213 setDetailsVisible( false );
1214 mActionDetails->setChecked( false ); 1214 mActionDetails->setChecked( false );
1215 1215
1216 if (!mMultipleViewsAtOnce) 1216 if (!mMultipleViewsAtOnce)
1217 { 1217 {
1218 mActionDetails->setEnabled(false); 1218 mActionDetails->setEnabled(false);
1219 } 1219 }
1220 1220
1221 mExtensionManager->setSelectionChanged(); 1221 mExtensionManager->setSelectionChanged();
1222 1222
1223 } 1223 }
1224 1224
1225#endif// DESKTOP_VERSION 1225#endif// DESKTOP_VERSION
1226 1226
1227} 1227}
1228 1228
1229 1229
1230void KABCore::extensionModified( const KABC::Addressee::List &list ) 1230void KABCore::extensionModified( const KABC::Addressee::List &list )
1231{ 1231{
1232 1232
1233 if ( list.count() != 0 ) { 1233 if ( list.count() != 0 ) {
1234 KABC::Addressee::List::ConstIterator it; 1234 KABC::Addressee::List::ConstIterator it;
1235 for ( it = list.begin(); it != list.end(); ++it ) 1235 for ( it = list.begin(); it != list.end(); ++it )
1236 mAddressBook->insertAddressee( *it ); 1236 mAddressBook->insertAddressee( *it );
1237 if ( list.count() > 1 ) 1237 if ( list.count() > 1 )
1238 setModified(); 1238 setModified();
1239 else 1239 else
1240 setModifiedWOrefresh(); 1240 setModifiedWOrefresh();
1241 } 1241 }
1242 if ( list.count() == 0 ) 1242 if ( list.count() == 0 )
1243 mViewManager->refreshView(); 1243 mViewManager->refreshView();
1244 else 1244 else
1245 mViewManager->refreshView( list[ 0 ].uid() ); 1245 mViewManager->refreshView( list[ 0 ].uid() );
1246 1246
1247 1247
1248 1248
1249} 1249}
1250 1250
1251QString KABCore::getNameByPhone( const QString &phone ) 1251QString KABCore::getNameByPhone( const QString &phone )
1252{ 1252{
1253#ifndef KAB_EMBEDDED 1253#ifndef KAB_EMBEDDED
1254 QRegExp r( "[/*/-/ ]" ); 1254 QRegExp r( "[/*/-/ ]" );
1255 QString localPhone( phone ); 1255 QString localPhone( phone );
1256 1256
1257 bool found = false; 1257 bool found = false;
1258 QString ownerName = ""; 1258 QString ownerName = "";
1259 KABC::AddressBook::Iterator iter; 1259 KABC::AddressBook::Iterator iter;
1260 KABC::PhoneNumber::List::Iterator phoneIter; 1260 KABC::PhoneNumber::List::Iterator phoneIter;
1261 KABC::PhoneNumber::List phoneList; 1261 KABC::PhoneNumber::List phoneList;
1262 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { 1262 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) {
1263 phoneList = (*iter).phoneNumbers(); 1263 phoneList = (*iter).phoneNumbers();
1264 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); 1264 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() );
1265 ++phoneIter) { 1265 ++phoneIter) {
1266 // Get rid of separator chars so just the numbers are compared. 1266 // Get rid of separator chars so just the numbers are compared.
1267 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { 1267 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) {
1268 ownerName = (*iter).formattedName(); 1268 ownerName = (*iter).formattedName();
1269 found = true; 1269 found = true;
1270 } 1270 }
1271 } 1271 }
1272 } 1272 }
1273 1273
1274 return ownerName; 1274 return ownerName;
1275#else //KAB_EMBEDDED 1275#else //KAB_EMBEDDED
1276 qDebug("KABCore::getNameByPhone finsih method"); 1276 qDebug("KABCore::getNameByPhone finsih method");
1277 return ""; 1277 return "";
1278#endif //KAB_EMBEDDED 1278#endif //KAB_EMBEDDED
1279 1279
1280} 1280}
1281 1281
1282void KABCore::openConfigDialog() 1282void KABCore::openConfigDialog()
1283{ 1283{
1284 KABPrefs* kab_prefs = KABPrefs::instance(); 1284 KABPrefs* kab_prefs = KABPrefs::instance();
1285 KPimGlobalPrefs* kpim_prefs = KPimGlobalPrefs::instance(); 1285 KPimGlobalPrefs* kpim_prefs = KPimGlobalPrefs::instance();
1286 1286
1287 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); 1287 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true );
1288 KCMKabConfig* kabcfg = new KCMKabConfig( kab_prefs, ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); 1288 KCMKabConfig* kabcfg = new KCMKabConfig( kab_prefs, ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" );
1289 ConfigureDialog->addModule(kabcfg ); 1289 ConfigureDialog->addModule(kabcfg );
1290 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( kpim_prefs, ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); 1290 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( kpim_prefs, ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" );
1291 ConfigureDialog->addModule(kdelibcfg ); 1291 ConfigureDialog->addModule(kdelibcfg );
1292 1292
1293 1293
1294 1294
1295 connect( ConfigureDialog, SIGNAL( applyClicked() ), 1295 connect( ConfigureDialog, SIGNAL( applyClicked() ),
1296 this, SLOT( configurationChanged() ) ); 1296 this, SLOT( configurationChanged() ) );
1297 connect( ConfigureDialog, SIGNAL( okClicked() ), 1297 connect( ConfigureDialog, SIGNAL( okClicked() ),
1298 this, SLOT( configurationChanged() ) ); 1298 this, SLOT( configurationChanged() ) );
1299 saveSettings(); 1299 saveSettings();
1300#ifndef DESKTOP_VERSION 1300#ifndef DESKTOP_VERSION
1301 ConfigureDialog->showMaximized(); 1301 ConfigureDialog->showMaximized();
1302#endif 1302#endif
1303 if ( ConfigureDialog->exec() ) 1303 if ( ConfigureDialog->exec() )
1304 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); 1304 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") );
1305 delete ConfigureDialog; 1305 delete ConfigureDialog;
1306} 1306}
1307 1307
1308void KABCore::openLDAPDialog() 1308void KABCore::openLDAPDialog()
1309{ 1309{
1310#ifndef KAB_EMBEDDED 1310#ifndef KAB_EMBEDDED
1311 if ( !mLdapSearchDialog ) { 1311 if ( !mLdapSearchDialog ) {
1312 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); 1312 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this );
1313 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, 1313 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager,
1314 SLOT( refreshView() ) ); 1314 SLOT( refreshView() ) );
1315 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, 1315 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this,
1316 SLOT( setModified() ) ); 1316 SLOT( setModified() ) );
1317 } else 1317 } else
1318 mLdapSearchDialog->restoreSettings(); 1318 mLdapSearchDialog->restoreSettings();
1319 1319
1320 if ( mLdapSearchDialog->isOK() ) 1320 if ( mLdapSearchDialog->isOK() )
1321 mLdapSearchDialog->exec(); 1321 mLdapSearchDialog->exec();
1322#else //KAB_EMBEDDED 1322#else //KAB_EMBEDDED
1323 qDebug("KABCore::openLDAPDialog() finsih method"); 1323 qDebug("KABCore::openLDAPDialog() finsih method");
1324#endif //KAB_EMBEDDED 1324#endif //KAB_EMBEDDED
1325} 1325}
1326 1326
1327void KABCore::print() 1327void KABCore::print()
1328{ 1328{
1329#ifndef KAB_EMBEDDED 1329#ifndef KAB_EMBEDDED
1330 KPrinter printer; 1330 KPrinter printer;
1331 if ( !printer.setup( this ) ) 1331 if ( !printer.setup( this ) )
1332 return; 1332 return;
1333 1333
1334 KABPrinting::PrintingWizard wizard( &printer, mAddressBook, 1334 KABPrinting::PrintingWizard wizard( &printer, mAddressBook,
1335 mViewManager->selectedUids(), this ); 1335 mViewManager->selectedUids(), this );
1336 1336
1337 wizard.exec(); 1337 wizard.exec();
1338#else //KAB_EMBEDDED 1338#else //KAB_EMBEDDED
1339 qDebug("KABCore::print() finsih method"); 1339 qDebug("KABCore::print() finsih method");
1340#endif //KAB_EMBEDDED 1340#endif //KAB_EMBEDDED
1341 1341
1342} 1342}
1343 1343
1344 1344
1345void KABCore::addGUIClient( KXMLGUIClient *client ) 1345void KABCore::addGUIClient( KXMLGUIClient *client )
1346{ 1346{
1347 if ( mGUIClient ) 1347 if ( mGUIClient )
1348 mGUIClient->insertChildClient( client ); 1348 mGUIClient->insertChildClient( client );
1349 else 1349 else
1350 KMessageBox::error( this, "no KXMLGUICLient"); 1350 KMessageBox::error( this, "no KXMLGUICLient");
1351} 1351}
1352 1352
1353 1353
1354void KABCore::configurationChanged() 1354void KABCore::configurationChanged()
1355{ 1355{
1356 mExtensionManager->reconfigure(); 1356 mExtensionManager->reconfigure();
1357} 1357}
1358 1358
1359void KABCore::addressBookChanged() 1359void KABCore::addressBookChanged()
1360{ 1360{
1361/*US 1361/*US
1362 QDictIterator<AddresseeEditorDialog> it( mEditorDict ); 1362 QDictIterator<AddresseeEditorDialog> it( mEditorDict );
1363 while ( it.current() ) { 1363 while ( it.current() ) {
1364 if ( it.current()->dirty() ) { 1364 if ( it.current()->dirty() ) {
1365 QString text = i18n( "Data has been changed externally. Unsaved " 1365 QString text = i18n( "Data has been changed externally. Unsaved "
1366 "changes will be lost." ); 1366 "changes will be lost." );
1367 KMessageBox::information( this, text ); 1367 KMessageBox::information( this, text );
1368 } 1368 }
1369 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); 1369 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) );
1370 ++it; 1370 ++it;
1371 } 1371 }
1372*/ 1372*/
1373 if (mEditorDialog) 1373 if (mEditorDialog)
1374 { 1374 {
1375 if (mEditorDialog->dirty()) 1375 if (mEditorDialog->dirty())
1376 { 1376 {
1377 QString text = i18n( "Data has been changed externally. Unsaved " 1377 QString text = i18n( "Data has been changed externally. Unsaved "
1378 "changes will be lost." ); 1378 "changes will be lost." );
1379 KMessageBox::information( this, text ); 1379 KMessageBox::information( this, text );
1380 } 1380 }
1381 QString currentuid = mEditorDialog->addressee().uid(); 1381 QString currentuid = mEditorDialog->addressee().uid();
1382 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); 1382 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) );
1383 } 1383 }
1384 mViewManager->refreshView(); 1384 mViewManager->refreshView();
1385// mDetails->refreshView(); 1385// mDetails->refreshView();
1386 1386
1387 1387
1388} 1388}
1389 1389
1390AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, 1390AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent,
1391 const char *name ) 1391 const char *name )
1392{ 1392{
1393 1393
1394 if ( mEditorDialog == 0 ) { 1394 if ( mEditorDialog == 0 ) {
1395 mEditorDialog = new AddresseeEditorDialog( this, parent, 1395 mEditorDialog = new AddresseeEditorDialog( this, parent,
1396 name ? name : "editorDialog" ); 1396 name ? name : "editorDialog" );
1397 1397
1398 1398
1399 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), 1399 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ),
1400 SLOT( contactModified( const KABC::Addressee& ) ) ); 1400 SLOT( contactModified( const KABC::Addressee& ) ) );
1401 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), 1401 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ),
1402 // SLOT( slotEditorDestroyed( const QString& ) ) ; 1402 // SLOT( slotEditorDestroyed( const QString& ) ) ;
1403 } 1403 }
1404 1404
1405 return mEditorDialog; 1405 return mEditorDialog;
1406} 1406}
1407 1407
1408void KABCore::slotEditorDestroyed( const QString &uid ) 1408void KABCore::slotEditorDestroyed( const QString &uid )
1409{ 1409{
1410 //mEditorDict.remove( uid ); 1410 //mEditorDict.remove( uid );
1411} 1411}
1412 1412
1413void KABCore::initGUI() 1413void KABCore::initGUI()
1414{ 1414{
1415#ifndef KAB_EMBEDDED 1415#ifndef KAB_EMBEDDED
1416 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1416 QHBoxLayout *topLayout = new QHBoxLayout( this );
1417 topLayout->setSpacing( KDialogBase::spacingHint() ); 1417 topLayout->setSpacing( KDialogBase::spacingHint() );
1418 1418
1419 mExtensionBarSplitter = new QSplitter( this ); 1419 mExtensionBarSplitter = new QSplitter( this );
1420 mExtensionBarSplitter->setOrientation( Qt::Vertical ); 1420 mExtensionBarSplitter->setOrientation( Qt::Vertical );
1421 1421
1422 mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); 1422 mDetailsSplitter = new QSplitter( mExtensionBarSplitter );
1423 1423
1424 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1424 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1425 mIncSearchWidget = new IncSearchWidget( viewSpace ); 1425 mIncSearchWidget = new IncSearchWidget( viewSpace );
1426 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1426 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1427 SLOT( incrementalSearch( const QString& ) ) ); 1427 SLOT( incrementalSearch( const QString& ) ) );
1428 1428
1429 mViewManager = new ViewManager( this, viewSpace ); 1429 mViewManager = new ViewManager( this, viewSpace );
1430 viewSpace->setStretchFactor( mViewManager, 1 ); 1430 viewSpace->setStretchFactor( mViewManager, 1 );
1431 1431
1432 mDetails = new ViewContainer( mDetailsSplitter ); 1432 mDetails = new ViewContainer( mDetailsSplitter );
1433 1433
1434 mJumpButtonBar = new JumpButtonBar( this, this ); 1434 mJumpButtonBar = new JumpButtonBar( this, this );
1435 1435
1436 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1436 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1437 1437
1438 topLayout->addWidget( mExtensionBarSplitter ); 1438 topLayout->addWidget( mExtensionBarSplitter );
1439 topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); 1439 topLayout->setStretchFactor( mExtensionBarSplitter, 100 );
1440 topLayout->addWidget( mJumpButtonBar ); 1440 topLayout->addWidget( mJumpButtonBar );
1441 topLayout->setStretchFactor( mJumpButtonBar, 1 ); 1441 topLayout->setStretchFactor( mJumpButtonBar, 1 );
1442 1442
1443 mXXPortManager = new XXPortManager( this, this ); 1443 mXXPortManager = new XXPortManager( this, this );
1444 1444
1445#else //KAB_EMBEDDED 1445#else //KAB_EMBEDDED
1446 //US initialize viewMenu before settingup viewmanager. 1446 //US initialize viewMenu before settingup viewmanager.
1447 // Viewmanager needs this menu to plugin submenues. 1447 // Viewmanager needs this menu to plugin submenues.
1448 viewMenu = new QPopupMenu( this ); 1448 viewMenu = new QPopupMenu( this );
1449 settingsMenu = new QPopupMenu( this ); 1449 settingsMenu = new QPopupMenu( this );
1450 //filterMenu = new QPopupMenu( this ); 1450 //filterMenu = new QPopupMenu( this );
1451 ImportMenu = new QPopupMenu( this ); 1451 ImportMenu = new QPopupMenu( this );
1452 ExportMenu = new QPopupMenu( this ); 1452 ExportMenu = new QPopupMenu( this );
1453 syncMenu = new QPopupMenu( this ); 1453 syncMenu = new QPopupMenu( this );
1454 changeMenu= new QPopupMenu( this ); 1454 changeMenu= new QPopupMenu( this );
1455 1455
1456//US since we have no splitter for the embedded system, setup 1456//US since we have no splitter for the embedded system, setup
1457// a layout with two frames. One left and one right. 1457// a layout with two frames. One left and one right.
1458 1458
1459 QBoxLayout *topLayout; 1459 QBoxLayout *topLayout;
1460 1460
1461 // = new QHBoxLayout( this ); 1461 // = new QHBoxLayout( this );
1462// QBoxLayout *topLayout = (QBoxLayout*)layout(); 1462// QBoxLayout *topLayout = (QBoxLayout*)layout();
1463 1463
1464// QWidget *mainBox = new QWidget( this ); 1464// QWidget *mainBox = new QWidget( this );
1465// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); 1465// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox);
1466 1466
1467#ifdef DESKTOP_VERSION 1467#ifdef DESKTOP_VERSION
1468 topLayout = new QHBoxLayout( this ); 1468 topLayout = new QHBoxLayout( this );
1469 1469
1470 1470
1471 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1471 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1472 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1472 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1473 1473
1474 topLayout->addWidget(mMiniSplitter ); 1474 topLayout->addWidget(mMiniSplitter );
1475 1475
1476 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); 1476 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter );
1477 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1477 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1478 mViewManager = new ViewManager( this, mExtensionBarSplitter ); 1478 mViewManager = new ViewManager( this, mExtensionBarSplitter );
1479 mDetails = new ViewContainer( mMiniSplitter ); 1479 mDetails = new ViewContainer( mMiniSplitter );
1480 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1480 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1481#else 1481#else
1482 if ( QApplication::desktop()->width() > 480 ) { 1482 if ( QApplication::desktop()->width() > 480 ) {
1483 topLayout = new QHBoxLayout( this ); 1483 topLayout = new QHBoxLayout( this );
1484 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1484 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1485 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1485 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1486 } else { 1486 } else {
1487 1487
1488 topLayout = new QHBoxLayout( this ); 1488 topLayout = new QHBoxLayout( this );
1489 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); 1489 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this);
1490 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1490 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1491 } 1491 }
1492 1492
1493 topLayout->addWidget(mMiniSplitter ); 1493 topLayout->addWidget(mMiniSplitter );
1494 mViewManager = new ViewManager( this, mMiniSplitter ); 1494 mViewManager = new ViewManager( this, mMiniSplitter );
1495 mDetails = new ViewContainer( mMiniSplitter ); 1495 mDetails = new ViewContainer( mMiniSplitter );
1496 1496
1497 1497
1498 mExtensionManager = new ExtensionManager( this, mMiniSplitter ); 1498 mExtensionManager = new ExtensionManager( this, mMiniSplitter );
1499#endif 1499#endif
1500 //eh->hide(); 1500 //eh->hide();
1501 // topLayout->addWidget(mExtensionManager ); 1501 // topLayout->addWidget(mExtensionManager );
1502 1502
1503 1503
1504/*US 1504/*US
1505#ifndef KAB_NOSPLITTER 1505#ifndef KAB_NOSPLITTER
1506 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1506 QHBoxLayout *topLayout = new QHBoxLayout( this );
1507//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1507//US topLayout->setSpacing( KDialogBase::spacingHint() );
1508 topLayout->setSpacing( 10 ); 1508 topLayout->setSpacing( 10 );
1509 1509
1510 mDetailsSplitter = new QSplitter( this ); 1510 mDetailsSplitter = new QSplitter( this );
1511 1511
1512 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1512 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1513 1513
1514 mViewManager = new ViewManager( this, viewSpace ); 1514 mViewManager = new ViewManager( this, viewSpace );
1515 viewSpace->setStretchFactor( mViewManager, 1 ); 1515 viewSpace->setStretchFactor( mViewManager, 1 );
1516 1516
1517 mDetails = new ViewContainer( mDetailsSplitter ); 1517 mDetails = new ViewContainer( mDetailsSplitter );
1518 1518
1519 topLayout->addWidget( mDetailsSplitter ); 1519 topLayout->addWidget( mDetailsSplitter );
1520 topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1520 topLayout->setStretchFactor( mDetailsSplitter, 100 );
1521#else //KAB_NOSPLITTER 1521#else //KAB_NOSPLITTER
1522 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1522 QHBoxLayout *topLayout = new QHBoxLayout( this );
1523//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1523//US topLayout->setSpacing( KDialogBase::spacingHint() );
1524 topLayout->setSpacing( 10 ); 1524 topLayout->setSpacing( 10 );
1525 1525
1526// mDetailsSplitter = new QSplitter( this ); 1526// mDetailsSplitter = new QSplitter( this );
1527 1527
1528 QVBox *viewSpace = new QVBox( this ); 1528 QVBox *viewSpace = new QVBox( this );
1529 1529
1530 mViewManager = new ViewManager( this, viewSpace ); 1530 mViewManager = new ViewManager( this, viewSpace );
1531 viewSpace->setStretchFactor( mViewManager, 1 ); 1531 viewSpace->setStretchFactor( mViewManager, 1 );
1532 1532
1533 mDetails = new ViewContainer( this ); 1533 mDetails = new ViewContainer( this );
1534 1534
1535 topLayout->addWidget( viewSpace ); 1535 topLayout->addWidget( viewSpace );
1536// topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1536// topLayout->setStretchFactor( mDetailsSplitter, 100 );
1537 topLayout->addWidget( mDetails ); 1537 topLayout->addWidget( mDetails );
1538#endif //KAB_NOSPLITTER 1538#endif //KAB_NOSPLITTER
1539*/ 1539*/
1540 1540
1541 1541
1542#endif //KAB_EMBEDDED 1542#endif //KAB_EMBEDDED
1543 initActions(); 1543 initActions();
1544 1544
1545#ifdef KAB_EMBEDDED 1545#ifdef KAB_EMBEDDED
1546 addActionsManually(); 1546 addActionsManually();
1547 //US make sure the export and import menues are initialized before creating the xxPortManager. 1547 //US make sure the export and import menues are initialized before creating the xxPortManager.
1548 mXXPortManager = new XXPortManager( this, this ); 1548 mXXPortManager = new XXPortManager( this, this );
1549 1549
1550 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); 1550 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() );
1551 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); 1551 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget);
1552 // mActionQuit->plug ( mMainWindow->toolBar()); 1552 // mActionQuit->plug ( mMainWindow->toolBar());
1553 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); 1553 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() );
1554 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); 1554 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget);
1555 // mIncSearchWidget->hide(); 1555 // mIncSearchWidget->hide();
1556 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1556 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1557 SLOT( incrementalSearch( const QString& ) ) ); 1557 SLOT( incrementalSearch( const QString& ) ) );
1558 1558
1559 1559
1560 mJumpButtonBar = new JumpButtonBar( this, this ); 1560 mJumpButtonBar = new JumpButtonBar( this, this );
1561 1561
1562 topLayout->addWidget( mJumpButtonBar ); 1562 topLayout->addWidget( mJumpButtonBar );
1563//US topLayout->setStretchFactor( mJumpButtonBar, 10 ); 1563//US topLayout->setStretchFactor( mJumpButtonBar, 10 );
1564 1564
1565// mMainWindow->getIconToolBar()->raise(); 1565// mMainWindow->getIconToolBar()->raise();
1566 1566
1567#endif //KAB_EMBEDDED 1567#endif //KAB_EMBEDDED
1568 1568
1569} 1569}
1570void KABCore::initActions() 1570void KABCore::initActions()
1571{ 1571{
1572//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1572//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1573 1573
1574#ifndef KAB_EMBEDDED 1574#ifndef KAB_EMBEDDED
1575 connect( QApplication::clipboard(), SIGNAL( dataChanged() ), 1575 connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
1576 SLOT( clipboardDataChanged() ) ); 1576 SLOT( clipboardDataChanged() ) );
1577#endif //KAB_EMBEDDED 1577#endif //KAB_EMBEDDED
1578 1578
1579 // file menu 1579 // file menu
1580 if ( mIsPart ) { 1580 if ( mIsPart ) {
1581 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, 1581 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this,
1582 SLOT( sendMail() ), actionCollection(), 1582 SLOT( sendMail() ), actionCollection(),
1583 "kaddressbook_mail" ); 1583 "kaddressbook_mail" );
1584 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, 1584 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this,
1585 SLOT( print() ), actionCollection(), "kaddressbook_print" ); 1585 SLOT( print() ), actionCollection(), "kaddressbook_print" );
1586 1586
1587 } else { 1587 } else {
1588 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); 1588 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() );
1589 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); 1589 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() );
1590 } 1590 }
1591 1591
1592 1592
1593 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, 1593 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this,
1594 SLOT( save() ), actionCollection(), "file_sync" ); 1594 SLOT( save() ), actionCollection(), "file_sync" );
1595 1595
1596 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, 1596 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this,
1597 SLOT( newContact() ), actionCollection(), "file_new_contact" ); 1597 SLOT( newContact() ), actionCollection(), "file_new_contact" );
1598 1598
1599 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, 1599 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0,
1600 this, SLOT( mailVCard() ), 1600 this, SLOT( mailVCard() ),
1601 actionCollection(), "file_mail_vcard"); 1601 actionCollection(), "file_mail_vcard");
1602 1602
1603 mActionBeamVCard = 0; 1603 mActionBeamVCard = 0;
1604 mActionBeam = 0; 1604 mActionBeam = 0;
1605 1605
1606#ifndef DESKTOP_VERSION 1606#ifndef DESKTOP_VERSION
1607 if ( Ir::supported() ) { 1607 if ( Ir::supported() ) {
1608 mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, 1608 mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this,
1609 SLOT( beamVCard() ), actionCollection(), 1609 SLOT( beamVCard() ), actionCollection(),
1610 "kaddressbook_beam_vcard" ); 1610 "kaddressbook_beam_vcard" );
1611 1611
1612 mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, 1612 mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this,
1613 SLOT( beamMySelf() ), actionCollection(), 1613 SLOT( beamMySelf() ), actionCollection(),
1614 "kaddressbook_beam_myself" ); 1614 "kaddressbook_beam_myself" );
1615 } 1615 }
1616#endif 1616#endif
1617 1617
1618 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, 1618 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0,
1619 this, SLOT( editContact2() ), 1619 this, SLOT( editContact2() ),
1620 actionCollection(), "file_properties" ); 1620 actionCollection(), "file_properties" );
1621 1621
1622#ifdef KAB_EMBEDDED 1622#ifdef KAB_EMBEDDED
1623 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); 1623 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() );
1624 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, 1624 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0,
1625 mMainWindow, SLOT( exit() ), 1625 mMainWindow, SLOT( exit() ),
1626 actionCollection(), "quit" ); 1626 actionCollection(), "quit" );
1627#endif //KAB_EMBEDDED 1627#endif //KAB_EMBEDDED
1628 1628
1629 // edit menu 1629 // edit menu
1630 if ( mIsPart ) { 1630 if ( mIsPart ) {
1631 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, 1631 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this,
1632 SLOT( copyContacts() ), actionCollection(), 1632 SLOT( copyContacts() ), actionCollection(),
1633 "kaddressbook_copy" ); 1633 "kaddressbook_copy" );
1634 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, 1634 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this,
1635 SLOT( cutContacts() ), actionCollection(), 1635 SLOT( cutContacts() ), actionCollection(),
1636 "kaddressbook_cut" ); 1636 "kaddressbook_cut" );
1637 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, 1637 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this,
1638 SLOT( pasteContacts() ), actionCollection(), 1638 SLOT( pasteContacts() ), actionCollection(),
1639 "kaddressbook_paste" ); 1639 "kaddressbook_paste" );
1640 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, 1640 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this,
1641 SLOT( selectAllContacts() ), actionCollection(), 1641 SLOT( selectAllContacts() ), actionCollection(),
1642 "kaddressbook_select_all" ); 1642 "kaddressbook_select_all" );
1643 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, 1643 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this,
1644 SLOT( undo() ), actionCollection(), 1644 SLOT( undo() ), actionCollection(),
1645 "kaddressbook_undo" ); 1645 "kaddressbook_undo" );
1646 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, 1646 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z,
1647 this, SLOT( redo() ), actionCollection(), 1647 this, SLOT( redo() ), actionCollection(),
1648 "kaddressbook_redo" ); 1648 "kaddressbook_redo" );
1649 } else { 1649 } else {
1650 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); 1650 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() );
1651 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); 1651 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() );
1652 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); 1652 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() );
1653 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); 1653 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() );
1654 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); 1654 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() );
1655 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); 1655 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() );
1656 } 1656 }
1657 1657
1658 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", 1658 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete",
1659 Key_Delete, this, SLOT( deleteContacts() ), 1659 Key_Delete, this, SLOT( deleteContacts() ),
1660 actionCollection(), "edit_delete" ); 1660 actionCollection(), "edit_delete" );
1661 1661
1662 mActionUndo->setEnabled( false ); 1662 mActionUndo->setEnabled( false );
1663 mActionRedo->setEnabled( false ); 1663 mActionRedo->setEnabled( false );
1664 1664
1665 // settings menu 1665 // settings menu
1666#ifdef KAB_EMBEDDED 1666#ifdef KAB_EMBEDDED
1667//US special menuentry to configure the addressbook resources. On KDE 1667//US special menuentry to configure the addressbook resources. On KDE
1668// you do that through the control center !!! 1668// you do that through the control center !!!
1669 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, 1669 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this,
1670 SLOT( configureResources() ), actionCollection(), 1670 SLOT( configureResources() ), actionCollection(),
1671 "kaddressbook_configure_resources" ); 1671 "kaddressbook_configure_resources" );
1672#endif //KAB_EMBEDDED 1672#endif //KAB_EMBEDDED
1673 1673
1674 if ( mIsPart ) { 1674 if ( mIsPart ) {
1675 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, 1675 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this,
1676 SLOT( openConfigDialog() ), actionCollection(), 1676 SLOT( openConfigDialog() ), actionCollection(),
1677 "kaddressbook_configure" ); 1677 "kaddressbook_configure" );
1678 1678
1679 mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, 1679 mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0,
1680 this, SLOT( configureKeyBindings() ), actionCollection(), 1680 this, SLOT( configureKeyBindings() ), actionCollection(),
1681 "kaddressbook_configure_shortcuts" ); 1681 "kaddressbook_configure_shortcuts" );
1682#ifdef KAB_EMBEDDED 1682#ifdef KAB_EMBEDDED
1683 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); 1683 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() );
1684 mActionConfigureToolbars->setEnabled( false ); 1684 mActionConfigureToolbars->setEnabled( false );
1685#endif //KAB_EMBEDDED 1685#endif //KAB_EMBEDDED
1686 1686
1687 } else { 1687 } else {
1688 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); 1688 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() );
1689 1689
1690 mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); 1690 mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() );
1691 } 1691 }
1692 1692
1693 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, 1693 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0,
1694 actionCollection(), "options_show_jump_bar" ); 1694 actionCollection(), "options_show_jump_bar" );
1695 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); 1695 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) );
1696 1696
1697 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, 1697 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0,
1698 actionCollection(), "options_show_details" ); 1698 actionCollection(), "options_show_details" );
1699 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); 1699 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) );
1700 1700
1701 // misc 1701 // misc
1702 // only enable LDAP lookup if we can handle the protocol 1702 // only enable LDAP lookup if we can handle the protocol
1703#ifndef KAB_EMBEDDED 1703#ifndef KAB_EMBEDDED
1704 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { 1704 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) {
1705 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, 1705 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0,
1706 this, SLOT( openLDAPDialog() ), actionCollection(), 1706 this, SLOT( openLDAPDialog() ), actionCollection(),
1707 "ldap_lookup" ); 1707 "ldap_lookup" );
1708 } 1708 }
1709#else //KAB_EMBEDDED 1709#else //KAB_EMBEDDED
1710 //qDebug("KABCore::initActions() LDAP has to be implemented"); 1710 //qDebug("KABCore::initActions() LDAP has to be implemented");
1711#endif //KAB_EMBEDDED 1711#endif //KAB_EMBEDDED
1712 1712
1713 1713
1714 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, 1714 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this,
1715 SLOT( setWhoAmI() ), actionCollection(), 1715 SLOT( setWhoAmI() ), actionCollection(),
1716 "set_personal" ); 1716 "set_personal" );
1717 1717
1718 1718
1719 1719
1720 1720
1721 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, 1721 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this,
1722 SLOT( setCategories() ), actionCollection(), 1722 SLOT( setCategories() ), actionCollection(),
1723 "edit_set_categories" ); 1723 "edit_set_categories" );
1724 1724
1725 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, 1725 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this,
1726 SLOT( removeVoice() ), actionCollection(), 1726 SLOT( removeVoice() ), actionCollection(),
1727 "remove_voice" ); 1727 "remove_voice" );
1728 mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this, 1728 mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this,
1729 SLOT( importFromOL() ), actionCollection(), 1729 SLOT( importFromOL() ), actionCollection(),
1730 "import_OL" ); 1730 "import_OL" );
1731#ifdef KAB_EMBEDDED 1731#ifdef KAB_EMBEDDED
1732 mActionLicence = new KAction( i18n( "Licence" ), 0, 1732 mActionLicence = new KAction( i18n( "Licence" ), 0,
1733 this, SLOT( showLicence() ), actionCollection(), 1733 this, SLOT( showLicence() ), actionCollection(),
1734 "licence_about_data" ); 1734 "licence_about_data" );
1735 mActionFaq = new KAction( i18n( "Faq" ), 0, 1735 mActionFaq = new KAction( i18n( "Faq" ), 0,
1736 this, SLOT( faq() ), actionCollection(), 1736 this, SLOT( faq() ), actionCollection(),
1737 "faq_about_data" ); 1737 "faq_about_data" );
1738 1738
1739 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, 1739 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0,
1740 this, SLOT( createAboutData() ), actionCollection(), 1740 this, SLOT( createAboutData() ), actionCollection(),
1741 "kaddressbook_about_data" ); 1741 "kaddressbook_about_data" );
1742#endif //KAB_EMBEDDED 1742#endif //KAB_EMBEDDED
1743 1743
1744 clipboardDataChanged(); 1744 clipboardDataChanged();
1745 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1745 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1746 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1746 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1747} 1747}
1748 1748
1749//US we need this function, to plug all actions into the correct menues. 1749//US we need this function, to plug all actions into the correct menues.
1750// KDE uses a XML format to plug the actions, but we work her without this overhead. 1750// KDE uses a XML format to plug the actions, but we work her without this overhead.
1751void KABCore::addActionsManually() 1751void KABCore::addActionsManually()
1752{ 1752{
1753//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1753//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1754 1754
1755#ifdef KAB_EMBEDDED 1755#ifdef KAB_EMBEDDED
1756 QPopupMenu *fileMenu = new QPopupMenu( this ); 1756 QPopupMenu *fileMenu = new QPopupMenu( this );
1757 QPopupMenu *editMenu = new QPopupMenu( this ); 1757 QPopupMenu *editMenu = new QPopupMenu( this );
1758 QPopupMenu *helpMenu = new QPopupMenu( this ); 1758 QPopupMenu *helpMenu = new QPopupMenu( this );
1759 1759
1760 KToolBar* tb = mMainWindow->toolBar(); 1760 KToolBar* tb = mMainWindow->toolBar();
1761 1761
1762#ifdef DESKTOP_VERSION 1762#ifdef DESKTOP_VERSION
1763 QMenuBar* mb = mMainWindow->menuBar(); 1763 QMenuBar* mb = mMainWindow->menuBar();
1764 1764
1765 //US setup menubar. 1765 //US setup menubar.
1766 //Disable the following block if you do not want to have a menubar. 1766 //Disable the following block if you do not want to have a menubar.
1767 mb->insertItem( "&File", fileMenu ); 1767 mb->insertItem( "&File", fileMenu );
1768 mb->insertItem( "&Edit", editMenu ); 1768 mb->insertItem( "&Edit", editMenu );
1769 mb->insertItem( "&View", viewMenu ); 1769 mb->insertItem( "&View", viewMenu );
1770 mb->insertItem( "&Settings", settingsMenu ); 1770 mb->insertItem( "&Settings", settingsMenu );
1771 mb->insertItem( i18n("Synchronize"), syncMenu ); 1771 mb->insertItem( i18n("Synchronize"), syncMenu );
1772 mb->insertItem( "&Change selected", changeMenu ); 1772 mb->insertItem( "&Change selected", changeMenu );
1773 mb->insertItem( "&Help", helpMenu ); 1773 mb->insertItem( "&Help", helpMenu );
1774 mIncSearchWidget = new IncSearchWidget( tb ); 1774 mIncSearchWidget = new IncSearchWidget( tb );
1775 // tb->insertWidget(-1, 0, mIncSearchWidget); 1775 // tb->insertWidget(-1, 0, mIncSearchWidget);
1776 1776
1777#else 1777#else
1778 //US setup toolbar 1778 //US setup toolbar
1779 QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); 1779 QPEMenuBar *menuBarTB = new QPEMenuBar( tb );
1780 QPopupMenu *popupBarTB = new QPopupMenu( this ); 1780 QPopupMenu *popupBarTB = new QPopupMenu( this );
1781 menuBarTB->insertItem( "ME", popupBarTB); 1781 menuBarTB->insertItem( "ME", popupBarTB);
1782 tb->insertWidget(-1, 0, menuBarTB); 1782 tb->insertWidget(-1, 0, menuBarTB);
1783 mIncSearchWidget = new IncSearchWidget( tb ); 1783 mIncSearchWidget = new IncSearchWidget( tb );
1784 1784
1785 tb->enableMoving(false); 1785 tb->enableMoving(false);
1786 popupBarTB->insertItem( "&File", fileMenu ); 1786 popupBarTB->insertItem( "&File", fileMenu );
1787 popupBarTB->insertItem( "&Edit", editMenu ); 1787 popupBarTB->insertItem( "&Edit", editMenu );
1788 popupBarTB->insertItem( "&View", viewMenu ); 1788 popupBarTB->insertItem( "&View", viewMenu );
1789 popupBarTB->insertItem( "&Settings", settingsMenu ); 1789 popupBarTB->insertItem( "&Settings", settingsMenu );
1790 popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); 1790 popupBarTB->insertItem( i18n("Synchronize"), syncMenu );
1791 mViewManager->getFilterAction()->plug ( popupBarTB); 1791 mViewManager->getFilterAction()->plug ( popupBarTB);
1792 popupBarTB->insertItem( "&Change selected", changeMenu ); 1792 popupBarTB->insertItem( "&Change selected", changeMenu );
1793 popupBarTB->insertItem( "&Help", helpMenu ); 1793 popupBarTB->insertItem( "&Help", helpMenu );
1794 if (QApplication::desktop()->width() > 320 ) { 1794 if (QApplication::desktop()->width() > 320 ) {
1795 // mViewManager->getFilterAction()->plug ( tb); 1795 // mViewManager->getFilterAction()->plug ( tb);
1796 } 1796 }
1797#endif 1797#endif
1798 // mActionQuit->plug ( mMainWindow->toolBar()); 1798 // mActionQuit->plug ( mMainWindow->toolBar());
1799 1799
1800 1800
1801 1801
1802 //US Now connect the actions with the menue entries. 1802 //US Now connect the actions with the menue entries.
1803 mActionPrint->plug( fileMenu ); 1803 mActionPrint->plug( fileMenu );
1804 mActionMail->plug( fileMenu ); 1804 mActionMail->plug( fileMenu );
1805 fileMenu->insertSeparator(); 1805 fileMenu->insertSeparator();
1806 1806
1807 mActionNewContact->plug( fileMenu ); 1807 mActionNewContact->plug( fileMenu );
1808 mActionNewContact->plug( tb ); 1808 mActionNewContact->plug( tb );
1809 1809
1810 mActionEditAddressee->plug( fileMenu ); 1810 mActionEditAddressee->plug( fileMenu );
1811 if ((KGlobal::getDesktopSize() > KGlobal::Small ) || 1811 if ((KGlobal::getDesktopSize() > KGlobal::Small ) ||
1812 (!KABPrefs::instance()->mMultipleViewsAtOnce )) 1812 (!KABPrefs::instance()->mMultipleViewsAtOnce ))
1813 mActionEditAddressee->plug( tb ); 1813 mActionEditAddressee->plug( tb );
1814 1814
1815 fileMenu->insertSeparator(); 1815 fileMenu->insertSeparator();
1816 mActionSave->plug( fileMenu ); 1816 mActionSave->plug( fileMenu );
1817 fileMenu->insertItem( "&Import", ImportMenu ); 1817 fileMenu->insertItem( "&Import", ImportMenu );
1818 fileMenu->insertItem( "&Export", ExportMenu ); 1818 fileMenu->insertItem( "&Export", ExportMenu );
1819 fileMenu->insertSeparator(); 1819 fileMenu->insertSeparator();
1820 mActionMailVCard->plug( fileMenu ); 1820 mActionMailVCard->plug( fileMenu );
1821#ifndef DESKTOP_VERSION 1821#ifndef DESKTOP_VERSION
1822 if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); 1822 if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu );
1823 if ( Ir::supported() ) mActionBeam->plug(fileMenu ); 1823 if ( Ir::supported() ) mActionBeam->plug(fileMenu );
1824#endif 1824#endif
1825 fileMenu->insertSeparator(); 1825 fileMenu->insertSeparator();
1826 mActionQuit->plug( fileMenu ); 1826 mActionQuit->plug( fileMenu );
1827#ifdef _WIN32_ 1827#ifdef _WIN32_
1828 mActionImportOL->plug( ImportMenu ); 1828 mActionImportOL->plug( ImportMenu );
1829#endif 1829#endif
1830 // edit menu 1830 // edit menu
1831 mActionUndo->plug( editMenu ); 1831 mActionUndo->plug( editMenu );
1832 mActionRedo->plug( editMenu ); 1832 mActionRedo->plug( editMenu );
1833 editMenu->insertSeparator(); 1833 editMenu->insertSeparator();
1834 mActionCut->plug( editMenu ); 1834 mActionCut->plug( editMenu );
1835 mActionCopy->plug( editMenu ); 1835 mActionCopy->plug( editMenu );
1836 mActionPaste->plug( editMenu ); 1836 mActionPaste->plug( editMenu );
1837 mActionDelete->plug( editMenu ); 1837 mActionDelete->plug( editMenu );
1838 editMenu->insertSeparator(); 1838 editMenu->insertSeparator();
1839 mActionSelectAll->plug( editMenu ); 1839 mActionSelectAll->plug( editMenu );
1840 1840
1841 mActionRemoveVoice->plug( changeMenu ); 1841 mActionRemoveVoice->plug( changeMenu );
1842 // settings menu 1842 // settings menu
1843//US special menuentry to configure the addressbook resources. On KDE 1843//US special menuentry to configure the addressbook resources. On KDE
1844// you do that through the control center !!! 1844// you do that through the control center !!!
1845 mActionConfigResources->plug( settingsMenu ); 1845 mActionConfigResources->plug( settingsMenu );
1846 settingsMenu->insertSeparator(); 1846 settingsMenu->insertSeparator();
1847 1847
1848 mActionConfigKAddressbook->plug( settingsMenu ); 1848 mActionConfigKAddressbook->plug( settingsMenu );
1849 1849
1850 if ( mIsPart ) { 1850 if ( mIsPart ) {
1851 mActionConfigShortcuts->plug( settingsMenu ); 1851 mActionConfigShortcuts->plug( settingsMenu );
1852 mActionConfigureToolbars->plug( settingsMenu ); 1852 mActionConfigureToolbars->plug( settingsMenu );
1853 1853
1854 } else { 1854 } else {
1855 mActionKeyBindings->plug( settingsMenu ); 1855 mActionKeyBindings->plug( settingsMenu );
1856 } 1856 }
1857 1857
1858 settingsMenu->insertSeparator(); 1858 settingsMenu->insertSeparator();
1859 1859
1860 mActionJumpBar->plug( settingsMenu ); 1860 mActionJumpBar->plug( settingsMenu );
1861 mActionDetails->plug( settingsMenu ); 1861 mActionDetails->plug( settingsMenu );
1862 if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) 1862 if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop )
1863 mActionDetails->plug( tb ); 1863 mActionDetails->plug( tb );
1864 settingsMenu->insertSeparator(); 1864 settingsMenu->insertSeparator();
1865 1865
1866 mActionWhoAmI->plug( settingsMenu ); 1866 mActionWhoAmI->plug( settingsMenu );
1867 mActionCategories->plug( settingsMenu ); 1867 mActionCategories->plug( settingsMenu );
1868 1868
1869 mActionLicence->plug( helpMenu ); 1869 mActionLicence->plug( helpMenu );
1870 mActionFaq->plug( helpMenu ); 1870 mActionFaq->plug( helpMenu );
1871 mActionAboutKAddressbook->plug( helpMenu ); 1871 mActionAboutKAddressbook->plug( helpMenu );
1872 1872
1873 if (KGlobal::getDesktopSize() > KGlobal::Small ) { 1873 if (KGlobal::getDesktopSize() > KGlobal::Small ) {
1874 1874
1875 mActionSave->plug( tb ); 1875 mActionSave->plug( tb );
1876 mViewManager->getFilterAction()->plug ( tb); 1876 mViewManager->getFilterAction()->plug ( tb);
1877 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { 1877 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) {
1878 mActionUndo->plug( tb ); 1878 mActionUndo->plug( tb );
1879 mActionDelete->plug( tb ); 1879 mActionDelete->plug( tb );
1880 mActionRedo->plug( tb ); 1880 mActionRedo->plug( tb );
1881 } 1881 }
1882 } 1882 }
1883 //mActionQuit->plug ( tb ); 1883 //mActionQuit->plug ( tb );
1884 // tb->insertWidget(-1, 0, mIncSearchWidget, 6); 1884 // tb->insertWidget(-1, 0, mIncSearchWidget, 6);
1885 1885
1886 //US link the searchwidget first to this. 1886 //US link the searchwidget first to this.
1887 // The real linkage to the toolbar happens later. 1887 // The real linkage to the toolbar happens later.
1888//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); 1888//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE);
1889//US tb->insertItem( mIncSearchWidget ); 1889//US tb->insertItem( mIncSearchWidget );
1890/*US 1890/*US
1891 mIncSearchWidget = new IncSearchWidget( tb ); 1891 mIncSearchWidget = new IncSearchWidget( tb );
1892 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1892 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1893 SLOT( incrementalSearch( const QString& ) ) ); 1893 SLOT( incrementalSearch( const QString& ) ) );
1894 1894
1895 mJumpButtonBar = new JumpButtonBar( this, this ); 1895 mJumpButtonBar = new JumpButtonBar( this, this );
1896 1896
1897//US topLayout->addWidget( mJumpButtonBar ); 1897//US topLayout->addWidget( mJumpButtonBar );
1898 this->layout()->add( mJumpButtonBar ); 1898 this->layout()->add( mJumpButtonBar );
1899*/ 1899*/
1900 1900
1901#endif //KAB_EMBEDDED 1901#endif //KAB_EMBEDDED
1902 1902
1903 connect ( syncMenu, SIGNAL( activated ( int ) ), this, SLOT (slotSyncMenu( int ) ) ); 1903 connect ( syncMenu, SIGNAL( activated ( int ) ), this, SLOT (slotSyncMenu( int ) ) );
1904 fillSyncMenu(); 1904 fillSyncMenu();
1905 1905
1906} 1906}
1907void KABCore::showLicence() 1907void KABCore::showLicence()
1908{ 1908{
1909 KApplication::showLicence(); 1909 KApplication::showLicence();
1910} 1910}
1911void KABCore::removeVoice() 1911void KABCore::removeVoice()
1912{ 1912{
1913 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 ) 1913 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 )
1914 return; 1914 return;
1915 KABC::Addressee::List list = mViewManager->selectedAddressees(); 1915 KABC::Addressee::List list = mViewManager->selectedAddressees();
1916 KABC::Addressee::List::Iterator it; 1916 KABC::Addressee::List::Iterator it;
1917 for ( it = list.begin(); it != list.end(); ++it ) { 1917 for ( it = list.begin(); it != list.end(); ++it ) {
1918 PhoneNumber::List phoneNumbers = (*it).phoneNumbers(); 1918 PhoneNumber::List phoneNumbers = (*it).phoneNumbers();
1919 PhoneNumber::List::Iterator phoneIt; 1919 PhoneNumber::List::Iterator phoneIt;
1920 bool found = false; 1920 bool found = false;
1921 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) { 1921 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) {
1922 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found 1922 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
1923 if ((*phoneIt).type() - PhoneNumber::Voice ) { 1923 if ((*phoneIt).type() - PhoneNumber::Voice ) {
1924 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); 1924 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
1925 (*it).insertPhoneNumber( (*phoneIt) ); 1925 (*it).insertPhoneNumber( (*phoneIt) );
1926 found = true; 1926 found = true;
1927 } 1927 }
1928 } 1928 }
1929 1929
1930 } 1930 }
1931 if ( found ) 1931 if ( found )
1932 contactModified((*it) ); 1932 contactModified((*it) );
1933 } 1933 }
1934} 1934}
1935 1935
1936 1936
1937 1937
1938void KABCore::clipboardDataChanged() 1938void KABCore::clipboardDataChanged()
1939{ 1939{
1940 1940
1941 if ( mReadWrite ) 1941 if ( mReadWrite )
1942 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); 1942 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() );
1943 1943
1944} 1944}
1945 1945
1946void KABCore::updateActionMenu() 1946void KABCore::updateActionMenu()
1947{ 1947{
1948 UndoStack *undo = UndoStack::instance(); 1948 UndoStack *undo = UndoStack::instance();
1949 RedoStack *redo = RedoStack::instance(); 1949 RedoStack *redo = RedoStack::instance();
1950 1950
1951 if ( undo->isEmpty() ) 1951 if ( undo->isEmpty() )
1952 mActionUndo->setText( i18n( "Undo" ) ); 1952 mActionUndo->setText( i18n( "Undo" ) );
1953 else 1953 else
1954 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); 1954 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) );
1955 1955
1956 mActionUndo->setEnabled( !undo->isEmpty() ); 1956 mActionUndo->setEnabled( !undo->isEmpty() );
1957 1957
1958 if ( !redo->top() ) 1958 if ( !redo->top() )
1959 mActionRedo->setText( i18n( "Redo" ) ); 1959 mActionRedo->setText( i18n( "Redo" ) );
1960 else 1960 else
1961 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); 1961 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) );
1962 1962
1963 mActionRedo->setEnabled( !redo->isEmpty() ); 1963 mActionRedo->setEnabled( !redo->isEmpty() );
1964} 1964}
1965 1965
1966void KABCore::configureKeyBindings() 1966void KABCore::configureKeyBindings()
1967{ 1967{
1968#ifndef KAB_EMBEDDED 1968#ifndef KAB_EMBEDDED
1969 KKeyDialog::configure( actionCollection(), true ); 1969 KKeyDialog::configure( actionCollection(), true );
1970#else //KAB_EMBEDDED 1970#else //KAB_EMBEDDED
1971 qDebug("KABCore::configureKeyBindings() not implemented"); 1971 qDebug("KABCore::configureKeyBindings() not implemented");
1972#endif //KAB_EMBEDDED 1972#endif //KAB_EMBEDDED
1973} 1973}
1974 1974
1975#ifdef KAB_EMBEDDED 1975#ifdef KAB_EMBEDDED
1976void KABCore::configureResources() 1976void KABCore::configureResources()
1977{ 1977{
1978 KRES::KCMKResources dlg( this, "" , 0 ); 1978 KRES::KCMKResources dlg( this, "" , 0 );
1979 1979
1980 if ( !dlg.exec() ) 1980 if ( !dlg.exec() )
1981 return; 1981 return;
1982 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); 1982 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") );
1983} 1983}
1984#endif //KAB_EMBEDDED 1984#endif //KAB_EMBEDDED
1985 1985
1986 1986
1987/* this method will be called through the QCop interface from Ko/Pi to select addresses 1987/* this method will be called through the QCop interface from Ko/Pi to select addresses
1988 * for the attendees list of an event. 1988 * for the attendees list of an event.
1989 */ 1989 */
1990void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) 1990void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid)
1991{ 1991{
1992 QStringList nameList; 1992 QStringList nameList;
1993 QStringList emailList; 1993 QStringList emailList;
1994 QStringList uidList; 1994 QStringList uidList;
1995 1995
1996 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); 1996 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this);
1997 uint i=0; 1997 uint i=0;
1998 for (i=0; i < list.count(); i++) 1998 for (i=0; i < list.count(); i++)
1999 { 1999 {
2000 nameList.append(list[i].realName()); 2000 nameList.append(list[i].realName());
2001 emailList.append(list[i].preferredEmail()); 2001 emailList.append(list[i].preferredEmail());
2002 uidList.append(list[i].uid()); 2002 uidList.append(list[i].uid());
2003 } 2003 }
2004 2004
2005 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); 2005 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList);
2006 2006
2007} 2007}
2008 2008
2009/* this method will be called through the QCop interface from other apps to show details of a contact. 2009/* this method will be called through the QCop interface from other apps to show details of a contact.
2010 */ 2010 */
2011void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) 2011void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid)
2012{ 2012{
2013 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); 2013 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1());
2014 2014
2015 QString foundUid = QString::null; 2015 QString foundUid = QString::null;
2016 if ( ! uid.isEmpty() ) { 2016 if ( ! uid.isEmpty() ) {
2017 Addressee adrr = mAddressBook->findByUid( uid ); 2017 Addressee adrr = mAddressBook->findByUid( uid );
2018 if ( !adrr.isEmpty() ) { 2018 if ( !adrr.isEmpty() ) {
2019 foundUid = uid; 2019 foundUid = uid;
2020 } 2020 }
2021 if ( email == "sendbacklist" ) { 2021 if ( email == "sendbacklist" ) {
2022 //qDebug("ssssssssssssssssssssssend "); 2022 //qDebug("ssssssssssssssssssssssend ");
2023 QStringList nameList; 2023 QStringList nameList;
2024 QStringList emailList; 2024 QStringList emailList;
2025 QStringList uidList; 2025 QStringList uidList;
2026 nameList.append(adrr.realName()); 2026 nameList.append(adrr.realName());
2027 emailList = adrr.emails(); 2027 emailList = adrr.emails();
2028 uidList.append( adrr.preferredEmail()); 2028 uidList.append( adrr.preferredEmail());
2029 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); 2029 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList);
2030 return; 2030 return;
2031 } 2031 }
2032 2032
2033 } 2033 }
2034 2034
2035 if ( email == "sendbacklist" ) 2035 if ( email == "sendbacklist" )
2036 return; 2036 return;
2037 if (foundUid.isEmpty()) 2037 if (foundUid.isEmpty())
2038 { 2038 {
2039 //find the uid of the person first 2039 //find the uid of the person first
2040 Addressee::List namelist; 2040 Addressee::List namelist;
2041 Addressee::List emaillist; 2041 Addressee::List emaillist;
2042 2042
2043 if (!name.isEmpty()) 2043 if (!name.isEmpty())
2044 namelist = mAddressBook->findByName( name ); 2044 namelist = mAddressBook->findByName( name );
2045 2045
2046 if (!email.isEmpty()) 2046 if (!email.isEmpty())
2047 emaillist = mAddressBook->findByEmail( email ); 2047 emaillist = mAddressBook->findByEmail( email );
2048 qDebug("count %d %d ", namelist.count(),emaillist.count() ); 2048 qDebug("count %d %d ", namelist.count(),emaillist.count() );
2049 //check if we have a match in Namelist and Emaillist 2049 //check if we have a match in Namelist and Emaillist
2050 if ((namelist.count() == 0) && (emaillist.count() > 0)) { 2050 if ((namelist.count() == 0) && (emaillist.count() > 0)) {
2051 foundUid = emaillist[0].uid(); 2051 foundUid = emaillist[0].uid();
2052 } 2052 }
2053 else if ((namelist.count() > 0) && (emaillist.count() == 0)) 2053 else if ((namelist.count() > 0) && (emaillist.count() == 0))
2054 foundUid = namelist[0].uid(); 2054 foundUid = namelist[0].uid();
2055 else 2055 else
2056 { 2056 {
2057 for (int i = 0; i < namelist.count(); i++) 2057 for (int i = 0; i < namelist.count(); i++)
2058 { 2058 {
2059 for (int j = 0; j < emaillist.count(); j++) 2059 for (int j = 0; j < emaillist.count(); j++)
2060 { 2060 {
2061 if (namelist[i] == emaillist[j]) 2061 if (namelist[i] == emaillist[j])
2062 { 2062 {
2063 foundUid = namelist[i].uid(); 2063 foundUid = namelist[i].uid();
2064 } 2064 }
2065 } 2065 }
2066 } 2066 }
2067 } 2067 }
2068 } 2068 }
2069 else 2069 else
2070 { 2070 {
2071 foundUid = uid; 2071 foundUid = uid;
2072 } 2072 }
2073 2073
2074 if (!foundUid.isEmpty()) 2074 if (!foundUid.isEmpty())
2075 { 2075 {
2076 2076
2077 // raise Ka/Pi if it is in the background 2077 // raise Ka/Pi if it is in the background
2078#ifndef DESKTOP_VERSION 2078#ifndef DESKTOP_VERSION
2079#ifndef KORG_NODCOP 2079#ifndef KORG_NODCOP
2080 //QCopEnvelope e("QPE/Application/kapi", "raise()"); 2080 //QCopEnvelope e("QPE/Application/kapi", "raise()");
2081#endif 2081#endif
2082#endif 2082#endif
2083 2083
2084 mMainWindow->showMaximized(); 2084 mMainWindow->showMaximized();
2085 mMainWindow-> raise(); 2085 mMainWindow-> raise();
2086 2086
2087 mViewManager->setSelected( "", false); 2087 mViewManager->setSelected( "", false);
2088 mViewManager->refreshView( "" ); 2088 mViewManager->refreshView( "" );
2089 mViewManager->setSelected( foundUid, true ); 2089 mViewManager->setSelected( foundUid, true );
2090 mViewManager->refreshView( foundUid ); 2090 mViewManager->refreshView( foundUid );
2091 2091
2092 if ( !mMultipleViewsAtOnce ) 2092 if ( !mMultipleViewsAtOnce )
2093 { 2093 {
2094 setDetailsVisible( true ); 2094 setDetailsVisible( true );
2095 mActionDetails->setChecked(true); 2095 mActionDetails->setChecked(true);
2096 } 2096 }
2097 } 2097 }
2098} 2098}
2099 2099
2100 2100
2101void KABCore::faq() 2101void KABCore::faq()
2102{ 2102{
2103 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); 2103 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" );
2104} 2104}
2105 2105
2106 2106
2107void KABCore::fillSyncMenu() 2107void KABCore::fillSyncMenu()
2108{ 2108{
2109 if ( syncMenu->count() ) 2109 if ( syncMenu->count() )
2110 syncMenu->clear(); 2110 syncMenu->clear();
2111 syncMenu->insertItem( i18n("Configure..."), 0 ); 2111 syncMenu->insertItem( i18n("Configure..."), 0 );
2112 syncMenu->insertSeparator(); 2112 syncMenu->insertSeparator();
2113 syncMenu->insertItem( i18n("Multiple sync"), 1 ); 2113 syncMenu->insertItem( i18n("Multiple sync"), 1 );
2114 syncMenu->insertSeparator(); 2114 syncMenu->insertSeparator();
2115 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 2115 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2116 config.setGroup("General"); 2116 config.setGroup("General");
2117 QStringList prof = config.readListEntry("SyncProfileNames"); 2117 QStringList prof = config.readListEntry("SyncProfileNames");
2118 KABPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 2118 KABPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined");
2119 if ( prof.count() < 3 ) { 2119 if ( prof.count() < 3 ) {
2120 prof.clear(); 2120 prof.clear();
2121 prof << i18n("Sharp_DTM"); 2121 prof << i18n("Sharp_DTM");
2122 prof << i18n("Local_file"); 2122 prof << i18n("Local_file");
2123 prof << i18n("Last_file"); 2123 prof << i18n("Last_file");
2124 KSyncProfile* temp = new KSyncProfile (); 2124 KSyncProfile* temp = new KSyncProfile ();
2125 temp->setName( prof[0] ); 2125 temp->setName( prof[0] );
2126 temp->writeConfig(&config); 2126 temp->writeConfig(&config);
2127 temp->setName( prof[1] ); 2127 temp->setName( prof[1] );
2128 temp->writeConfig(&config); 2128 temp->writeConfig(&config);
2129 temp->setName( prof[2] ); 2129 temp->setName( prof[2] );
2130 temp->writeConfig(&config); 2130 temp->writeConfig(&config);
2131 config.setGroup("General"); 2131 config.setGroup("General");
2132 config.writeEntry("SyncProfileNames",prof); 2132 config.writeEntry("SyncProfileNames",prof);
2133 config.writeEntry("ExternSyncProfiles","Sharp_DTM"); 2133 config.writeEntry("ExternSyncProfiles","Sharp_DTM");
2134 config.sync(); 2134 config.sync();
2135 delete temp; 2135 delete temp;
2136 } 2136 }
2137 KABPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 2137 KABPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
2138 KABPrefs::instance()->mSyncProfileNames = prof; 2138 KABPrefs::instance()->mSyncProfileNames = prof;
2139 int i; 2139 int i;
2140 for ( i = 0; i < prof.count(); ++i ) { 2140 for ( i = 0; i < prof.count(); ++i ) {
2141 2141
2142 syncMenu->insertItem( prof[i], 1000+i ); 2142 syncMenu->insertItem( prof[i], 1000+i );
2143 if ( i == 2 ) 2143 if ( i == 2 )
2144 syncMenu->insertSeparator(); 2144 syncMenu->insertSeparator();
2145 } 2145 }
2146 QDir app_dir; 2146 QDir app_dir;
2147 if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 2147 if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
2148 syncMenu->setItemEnabled( false , 1000 ); 2148 syncMenu->setItemEnabled( false , 1000 );
2149 } 2149 }
2150 //probaly useless 2150 //probaly useless
2151 //mView->setupExternSyncProfiles(); 2151 //mView->setupExternSyncProfiles();
2152} 2152}
2153void KABCore::slotSyncMenu( int action ) 2153void KABCore::slotSyncMenu( int action )
2154{ 2154{
2155 //qDebug("syncaction %d ", action); 2155 //qDebug("syncaction %d ", action);
2156 if ( action == 0 ) { 2156 if ( action == 0 ) {
2157 2157
2158 // seems to be a Qt2 event handling bug 2158 // seems to be a Qt2 event handling bug
2159 // syncmenu.clear causes a segfault at first time 2159 // syncmenu.clear causes a segfault at first time
2160 // when we call it after the main event loop, it is ok 2160 // when we call it after the main event loop, it is ok
2161 // same behaviour when calling OM/Pi via QCOP for the first time 2161 // same behaviour when calling OM/Pi via QCOP for the first time
2162 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 2162 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
2163 //confSync(); 2163 //confSync();
2164 2164
2165 return; 2165 return;
2166 } 2166 }
2167 if ( action == 1 ) { 2167 if ( action == 1 ) {
2168 multiSync( true ); 2168 multiSync( true );
2169 return; 2169 return;
2170 } 2170 }
2171 2171
2172 if (mBlockSaveFlag) 2172 if (mBlockSaveFlag)
2173 return; 2173 return;
2174 mBlockSaveFlag = true; 2174 mBlockSaveFlag = true;
2175 mCurrentSyncProfile = action - 1000 ; 2175 mCurrentSyncProfile = action - 1000 ;
2176 mCurrentSyncDevice = KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ; 2176 mCurrentSyncDevice = KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ;
2177 mCurrentSyncName = KABPrefs::instance()->mLocalMachineName ; 2177 mCurrentSyncName = KABPrefs::instance()->mLocalMachineName ;
2178 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 2178 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2179 KSyncProfile* temp = new KSyncProfile (); 2179 KSyncProfile* temp = new KSyncProfile ();
2180 temp->setName(KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2180 temp->setName(KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2181 temp->readConfig(&config); 2181 temp->readConfig(&config);
2182 KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); 2182 KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
2183 KABPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); 2183 KABPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs();
2184 KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); 2184 KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
2185 KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); 2185 KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
2186 KABPrefs::instance()->mWriteBackInFuture = 0; 2186 KABPrefs::instance()->mWriteBackInFuture = 0;
2187 if ( temp->getWriteBackFuture() ) 2187 if ( temp->getWriteBackFuture() )
2188 KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 2188 KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
2189 KABPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); 2189 KABPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync();
2190 if ( action == 1000 ) { 2190 if ( action == 1000 ) {
2191 syncSharp(); 2191 syncSharp();
2192 2192
2193 } else if ( action == 1001 ) { 2193 } else if ( action == 1001 ) {
2194 syncLocalFile(); 2194 syncLocalFile();
2195 2195
2196 } else if ( action == 1002 ) { 2196 } else if ( action == 1002 ) {
2197 quickSyncLocalFile(); 2197 quickSyncLocalFile();
2198 2198
2199 } else if ( action >= 1003 ) { 2199 } else if ( action >= 1003 ) {
2200 if ( temp->getIsLocalFileSync() ) { 2200 if ( temp->getIsLocalFileSync() ) {
2201 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 2201 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
2202 KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 2202 KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
2203 } else { 2203 } else {
2204 if ( temp->getIsPhoneSync() ) { 2204 if ( temp->getIsPhoneSync() ) {
2205 KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; 2205 KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ;
2206 KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); 2206 KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( );
2207 KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); 2207 KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( );
2208 syncPhone(); 2208 syncPhone();
2209 } else 2209 } else
2210 syncRemote( temp ); 2210 syncRemote( temp );
2211 2211
2212 } 2212 }
2213 } 2213 }
2214 delete temp; 2214 delete temp;
2215 mBlockSaveFlag = false; 2215 mBlockSaveFlag = false;
2216} 2216}
2217 2217
2218void KABCore::syncLocalFile() 2218void KABCore::syncLocalFile()
2219{ 2219{
2220 2220
2221 QString fn =KABPrefs::instance()->mLastSyncedLocalFile; 2221 QString fn =KABPrefs::instance()->mLastSyncedLocalFile;
2222 2222
2223 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); 2223 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
2224 if ( fn == "" ) 2224 if ( fn == "" )
2225 return; 2225 return;
2226 if ( syncWithFile( fn, false ) ) { 2226 if ( syncWithFile( fn, false ) ) {
2227 qDebug("syncLocalFile() successful "); 2227 qDebug("syncLocalFile() successful ");
2228 } 2228 }
2229 2229
2230} 2230}
2231bool KABCore::syncWithFile( QString fn , bool quick ) 2231bool KABCore::syncWithFile( QString fn , bool quick )
2232{ 2232{
2233 bool ret = false; 2233 bool ret = false;
2234 QFileInfo info; 2234 QFileInfo info;
2235 info.setFile( fn ); 2235 info.setFile( fn );
2236 QString mess; 2236 QString mess;
2237 bool loadbup = true; 2237 bool loadbup = true;
2238 if ( !info. exists() ) { 2238 if ( !info. exists() ) {
2239 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 2239 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
2240 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2240 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2241 mess ); 2241 mess );
2242 return ret; 2242 return ret;
2243 } 2243 }
2244 int result = 0; 2244 int result = 0;
2245 if ( !quick ) { 2245 if ( !quick ) {
2246 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 2246 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
2247 result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2247 result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2248 mess, 2248 mess,
2249 i18n("Sync"), i18n("Cancel"), 0, 2249 i18n("Sync"), i18n("Cancel"), 0,
2250 0, 1 ); 2250 0, 1 );
2251 if ( result ) 2251 if ( result )
2252 return false; 2252 return false;
2253 } 2253 }
2254 if ( KABPrefs::instance()->mAskForPreferences ) 2254 if ( KABPrefs::instance()->mAskForPreferences )
2255 edit_sync_options(); 2255 edit_sync_options();
2256 if ( result == 0 ) { 2256 if ( result == 0 ) {
2257 //qDebug("Now sycing ... "); 2257 //qDebug("Now sycing ... ");
2258 if ( ret = syncAB( fn, KABPrefs::instance()->mSyncAlgoPrefs ) ) 2258 if ( ret = syncAB( fn, KABPrefs::instance()->mSyncAlgoPrefs ) )
2259 setCaption( i18n("Synchronization successful") ); 2259 setCaption( i18n("Synchronization successful") );
2260 else 2260 else
2261 setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); 2261 setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
2262 if ( ! quick ) 2262 if ( ! quick )
2263 KABPrefs::instance()->mLastSyncedLocalFile = fn; 2263 KABPrefs::instance()->mLastSyncedLocalFile = fn;
2264 setModified(); 2264 setModified();
2265 } 2265 }
2266 return ret; 2266 return ret;
2267} 2267}
2268void KABCore::quickSyncLocalFile() 2268void KABCore::quickSyncLocalFile()
2269{ 2269{
2270 2270
2271 if ( syncWithFile( KABPrefs::instance()->mLastSyncedLocalFile, false ) ) { 2271 if ( syncWithFile( KABPrefs::instance()->mLastSyncedLocalFile, false ) ) {
2272 qDebug("quick syncLocalFile() successful "); 2272 qDebug("quick syncLocalFile() successful ");
2273 2273
2274 } 2274 }
2275} 2275}
2276void KABCore::multiSync( bool askforPrefs ) 2276void KABCore::multiSync( bool askforPrefs )
2277{ 2277{
2278 if (mBlockSaveFlag) 2278 if (mBlockSaveFlag)
2279 return; 2279 return;
2280 mBlockSaveFlag = true; 2280 mBlockSaveFlag = true;
2281 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 2281 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
2282 if ( QMessageBox::information( this, i18n("KO/Pi Sync"), 2282 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
2283 question, 2283 question,
2284 i18n("Yes"), i18n("No"), 2284 i18n("Yes"), i18n("No"),
2285 0, 0 ) != 0 ) { 2285 0, 0 ) != 0 ) {
2286 mBlockSaveFlag = false; 2286 mBlockSaveFlag = false;
2287 setCaption(i18n("Aborted! Nothing synced!")); 2287 setCaption(i18n("Aborted! Nothing synced!"));
2288 return; 2288 return;
2289 } 2289 }
2290 mCurrentSyncDevice = i18n("Multiple profiles") ; 2290 mCurrentSyncDevice = i18n("Multiple profiles") ;
2291 KABPrefs::instance()->mSyncAlgoPrefs = KABPrefs::instance()->mRingSyncAlgoPrefs; 2291 KABPrefs::instance()->mSyncAlgoPrefs = KABPrefs::instance()->mRingSyncAlgoPrefs;
2292 if ( askforPrefs ) { 2292 if ( askforPrefs ) {
2293 edit_sync_options(); 2293 edit_sync_options();
2294 KABPrefs::instance()->mRingSyncAlgoPrefs = KABPrefs::instance()->mSyncAlgoPrefs; 2294 KABPrefs::instance()->mRingSyncAlgoPrefs = KABPrefs::instance()->mSyncAlgoPrefs;
2295 } 2295 }
2296 setCaption(i18n("Multiple sync started.") ); 2296 setCaption(i18n("Multiple sync started.") );
2297 qApp->processEvents(); 2297 qApp->processEvents();
2298 int num = ringSync() ; 2298 int num = ringSync() ;
2299 if ( num > 1 ) 2299 if ( num > 1 )
2300 ringSync(); 2300 ringSync();
2301 mBlockSaveFlag = false; 2301 mBlockSaveFlag = false;
2302 if ( num ) 2302 if ( num )
2303 save(); 2303 save();
2304 if ( num ) 2304 if ( num )
2305 setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); 2305 setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) );
2306 else 2306 else
2307 setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 2307 setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
2308 return; 2308 return;
2309} 2309}
2310int KABCore::ringSync() 2310int KABCore::ringSync()
2311{ 2311{
2312 int syncedProfiles = 0; 2312 int syncedProfiles = 0;
2313 int i; 2313 int i;
2314 QTime timer; 2314 QTime timer;
2315 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 2315 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2316 QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames; 2316 QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames;
2317 KSyncProfile* temp = new KSyncProfile (); 2317 KSyncProfile* temp = new KSyncProfile ();
2318 KABPrefs::instance()->mAskForPreferences = false; 2318 KABPrefs::instance()->mAskForPreferences = false;
2319 for ( i = 0; i < syncProfileNames.count(); ++i ) { 2319 for ( i = 0; i < syncProfileNames.count(); ++i ) {
2320 mCurrentSyncProfile = i; 2320 mCurrentSyncProfile = i;
2321 temp->setName(syncProfileNames[mCurrentSyncProfile]); 2321 temp->setName(syncProfileNames[mCurrentSyncProfile]);
2322 temp->readConfig(&config); 2322 temp->readConfig(&config);
2323 if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) { 2323 if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) {
2324 setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 2324 setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
2325 ++syncedProfiles; 2325 ++syncedProfiles;
2326 // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); 2326 // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
2327 KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); 2327 KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
2328 KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); 2328 KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
2329 KABPrefs::instance()->mWriteBackInFuture = 0; 2329 KABPrefs::instance()->mWriteBackInFuture = 0;
2330 if ( temp->getWriteBackFuture() ) 2330 if ( temp->getWriteBackFuture() )
2331 KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 2331 KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
2332 KABPrefs::instance()->mShowSyncSummary = false; 2332 KABPrefs::instance()->mShowSyncSummary = false;
2333 mCurrentSyncDevice = syncProfileNames[i] ; 2333 mCurrentSyncDevice = syncProfileNames[i] ;
2334 mCurrentSyncName = KABPrefs::instance()->mLocalMachineName; 2334 mCurrentSyncName = KABPrefs::instance()->mLocalMachineName;
2335 if ( i == 0 ) { 2335 if ( i == 0 ) {
2336 syncSharp(); 2336 syncSharp();
2337 } else { 2337 } else {
2338 if ( temp->getIsLocalFileSync() ) { 2338 if ( temp->getIsLocalFileSync() ) {
2339 if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) 2339 if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) )
2340 KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 2340 KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
2341 } else { 2341 } else {
2342 if ( temp->getIsPhoneSync() ) { 2342 if ( temp->getIsPhoneSync() ) {
2343 KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; 2343 KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ;
2344 KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); 2344 KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( );
2345 KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); 2345 KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( );
2346 syncPhone(); 2346 syncPhone();
2347 } else 2347 } else
2348 syncRemote( temp, false ); 2348 syncRemote( temp, false );
2349 2349
2350 } 2350 }
2351 } 2351 }
2352 timer.start(); 2352 timer.start();
2353 setCaption(i18n("Multiple sync in progress ... please wait!") ); 2353 setCaption(i18n("Multiple sync in progress ... please wait!") );
2354 while ( timer.elapsed () < 2000 ) { 2354 while ( timer.elapsed () < 2000 ) {
2355 qApp->processEvents(); 2355 qApp->processEvents();
2356#ifndef _WIN32_ 2356#ifndef _WIN32_
2357 sleep (1); 2357 sleep (1);
2358#endif 2358#endif
2359 } 2359 }
2360 2360
2361 } 2361 }
2362 2362
2363 } 2363 }
2364 delete temp; 2364 delete temp;
2365 return syncedProfiles; 2365 return syncedProfiles;
2366} 2366}
2367 2367
2368void KABCore::syncRemote( KSyncProfile* prof, bool ask) 2368void KABCore::syncRemote( KSyncProfile* prof, bool ask)
2369{ 2369{
2370 QString question; 2370 QString question;
2371 if ( ask ) { 2371 if ( ask ) {
2372 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 2372 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
2373 if ( QMessageBox::information( this, i18n("KO/Pi Sync"), 2373 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
2374 question, 2374 question,
2375 i18n("Yes"), i18n("No"), 2375 i18n("Yes"), i18n("No"),
2376 0, 0 ) != 0 ) 2376 0, 0 ) != 0 )
2377 return; 2377 return;
2378 } 2378 }
2379 QString command = prof->getPreSyncCommandAB(); 2379 QString command = prof->getPreSyncCommandAB();
2380 int fi; 2380 int fi;
2381 if ( (fi = command.find("$PWD$")) > 0 ) { 2381 if ( (fi = command.find("$PWD$")) > 0 ) {
2382 QString pwd = getPassword(); 2382 QString pwd = getPassword();
2383 command = command.left( fi )+ pwd + command.mid( fi+5 ); 2383 command = command.left( fi )+ pwd + command.mid( fi+5 );
2384 2384
2385 } 2385 }
2386 int maxlen = 30; 2386 int maxlen = 30;
2387 if ( QApplication::desktop()->width() > 320 ) 2387 if ( QApplication::desktop()->width() > 320 )
2388 maxlen += 25; 2388 maxlen += 25;
2389 setCaption ( i18n( "Copy remote file to local machine..." ) ); 2389 setCaption ( i18n( "Copy remote file to local machine..." ) );
2390 int fileSize = 0; 2390 int fileSize = 0;
2391 int result = system ( command ); 2391 int result = system ( command );
2392 // 0 : okay 2392 // 0 : okay
2393 // 256: no such file or dir 2393 // 256: no such file or dir
2394 // 2394 //
2395 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 2395 qDebug("KO: Remote copy result(0 = okay): %d ",result );
2396 if ( result != 0 ) { 2396 if ( result != 0 ) {
2397 int len = maxlen; 2397 int len = maxlen;
2398 while ( len < command.length() ) { 2398 while ( len < command.length() ) {
2399 command.insert( len , "\n" ); 2399 command.insert( len , "\n" );
2400 len += maxlen +2; 2400 len += maxlen +2;
2401 } 2401 }
2402 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; 2402 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ;
2403 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), 2403 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"),
2404 question, 2404 question,
2405 i18n("Okay!")) ; 2405 i18n("Okay!")) ;
2406 setCaption ("KO/Pi"); 2406 setCaption ("KO/Pi");
2407 return; 2407 return;
2408 } 2408 }
2409 setCaption ( i18n( "Copying succeed." ) ); 2409 setCaption ( i18n( "Copying succeed." ) );
2410 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 2410 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
2411 if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { 2411 if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) {
2412// Event* e = mView->getLastSyncEvent(); 2412// Event* e = mView->getLastSyncEvent();
2413// e->setReadOnly( false ); 2413// e->setReadOnly( false );
2414// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2414// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2415// e->setReadOnly( true ); 2415// e->setReadOnly( true );
2416 if ( KABPrefs::instance()->mWriteBackFile ) { 2416 if ( KABPrefs::instance()->mWriteBackFile ) {
2417 command = prof->getPostSyncCommandAB(); 2417 command = prof->getPostSyncCommandAB();
2418 int fi; 2418 int fi;
2419 if ( (fi = command.find("$PWD$")) > 0 ) { 2419 if ( (fi = command.find("$PWD$")) > 0 ) {
2420 QString pwd = getPassword(); 2420 QString pwd = getPassword();
2421 command = command.left( fi )+ pwd + command.mid( fi+5 ); 2421 command = command.left( fi )+ pwd + command.mid( fi+5 );
2422 2422
2423 } 2423 }
2424 setCaption ( i18n( "Writing back file ..." ) ); 2424 setCaption ( i18n( "Writing back file ..." ) );
2425 result = system ( command ); 2425 result = system ( command );
2426 qDebug("KO: Writing back file result: %d ", result); 2426 qDebug("KO: Writing back file result: %d ", result);
2427 if ( result != 0 ) { 2427 if ( result != 0 ) {
2428 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 2428 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
2429 return; 2429 return;
2430 } else { 2430 } else {
2431 setCaption ( i18n( "Syncronization sucessfully completed" ) ); 2431 setCaption ( i18n( "Syncronization sucessfully completed" ) );
2432 } 2432 }
2433 } 2433 }
2434 } 2434 }
2435 return; 2435 return;
2436} 2436}
2437#include <qpushbutton.h> 2437#include <qpushbutton.h>
2438#include <qradiobutton.h> 2438#include <qradiobutton.h>
2439#include <qbuttongroup.h> 2439#include <qbuttongroup.h>
2440void KABCore::edit_sync_options() 2440void KABCore::edit_sync_options()
2441{ 2441{
2442 //mDialogManager->showSyncOptions(); 2442 //mDialogManager->showSyncOptions();
2443 //KABPrefs::instance()->mSyncAlgoPrefs 2443 //KABPrefs::instance()->mSyncAlgoPrefs
2444 QDialog dia( this, "dia", true ); 2444 QDialog dia( this, "dia", true );
2445 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 2445 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
2446 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 2446 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
2447 QVBoxLayout lay ( &dia ); 2447 QVBoxLayout lay ( &dia );
2448 lay.setSpacing( 2 ); 2448 lay.setSpacing( 2 );
2449 lay.setMargin( 3 ); 2449 lay.setMargin( 3 );
2450 lay.addWidget(&gr); 2450 lay.addWidget(&gr);
2451 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 2451 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
2452 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 2452 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
2453 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 2453 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
2454 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 2454 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
2455 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 2455 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
2456 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 2456 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
2457 //QRadioButton both( i18n("Take both on conflict"), &gr ); 2457 //QRadioButton both( i18n("Take both on conflict"), &gr );
2458 QPushButton pb ( "OK", &dia); 2458 QPushButton pb ( "OK", &dia);
2459 lay.addWidget( &pb ); 2459 lay.addWidget( &pb );
2460 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2460 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2461 switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { 2461 switch ( KABPrefs::instance()->mSyncAlgoPrefs ) {
2462 case 0: 2462 case 0:
2463 loc.setChecked( true); 2463 loc.setChecked( true);
2464 break; 2464 break;
2465 case 1: 2465 case 1:
2466 rem.setChecked( true ); 2466 rem.setChecked( true );
2467 break; 2467 break;
2468 case 2: 2468 case 2:
2469 newest.setChecked( true); 2469 newest.setChecked( true);
2470 break; 2470 break;
2471 case 3: 2471 case 3:
2472 ask.setChecked( true); 2472 ask.setChecked( true);
2473 break; 2473 break;
2474 case 4: 2474 case 4:
2475 f_loc.setChecked( true); 2475 f_loc.setChecked( true);
2476 break; 2476 break;
2477 case 5: 2477 case 5:
2478 f_rem.setChecked( true); 2478 f_rem.setChecked( true);
2479 break; 2479 break;
2480 case 6: 2480 case 6:
2481 // both.setChecked( true); 2481 // both.setChecked( true);
2482 break; 2482 break;
2483 default: 2483 default:
2484 break; 2484 break;
2485 } 2485 }
2486 if ( dia.exec() ) { 2486 if ( dia.exec() ) {
2487 KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 2487 KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
2488 } 2488 }
2489 2489
2490 2490
2491} 2491}
2492QString KABCore::getPassword( ) 2492QString KABCore::getPassword( )
2493{ 2493{
2494 QString retfile = ""; 2494 QString retfile = "";
2495 QDialog dia ( this, "input-dialog", true ); 2495 QDialog dia ( this, "input-dialog", true );
2496 QLineEdit lab ( &dia ); 2496 QLineEdit lab ( &dia );
2497 lab.setEchoMode( QLineEdit::Password ); 2497 lab.setEchoMode( QLineEdit::Password );
2498 QVBoxLayout lay( &dia ); 2498 QVBoxLayout lay( &dia );
2499 lay.setMargin(7); 2499 lay.setMargin(7);
2500 lay.setSpacing(7); 2500 lay.setSpacing(7);
2501 lay.addWidget( &lab); 2501 lay.addWidget( &lab);
2502 dia.setFixedSize( 230,50 ); 2502 dia.setFixedSize( 230,50 );
2503 dia.setCaption( i18n("Enter password") ); 2503 dia.setCaption( i18n("Enter password") );
2504 QPushButton pb ( "OK", &dia); 2504 QPushButton pb ( "OK", &dia);
2505 lay.addWidget( &pb ); 2505 lay.addWidget( &pb );
2506 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2506 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2507 dia.show(); 2507 dia.show();
2508 int res = dia.exec(); 2508 int res = dia.exec();
2509 if ( res ) 2509 if ( res )
2510 retfile = lab.text(); 2510 retfile = lab.text();
2511 dia.hide(); 2511 dia.hide();
2512 qApp->processEvents(); 2512 qApp->processEvents();
2513 return retfile; 2513 return retfile;
2514 2514
2515} 2515}
2516bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2516bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2517{ 2517{
2518 2518#if 0
2519 bool syncOK = true;
2520 int addedAddressee = 0;
2521 int addedAddresseeR = 0;
2522 int deletedAddresseeR = 0;
2523 int deletedAddresseeL = 0;
2524 int changedLocal = 0;
2525 int changedRemote = 0;
2526 //QPtrList<Addressee> el = local->rawAddressees();
2527 Addressee* addresseeR;
2528 QString uid;
2529 int take;
2530 Addressee* addresseeL;
2531 Addressee* addresseeRSync;
2532 Addressee* addresseeLSync;
2533 QPtrList<Addressee> addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2534 QPtrList<Addressee> addresseeLSyncSharp = local->getExternLastSyncAddressees();
2535 bool fullDateRange = false;
2536 local->resetTempSyncStat();
2537 mLastCalendarSync = QDateTime::currentDateTime();
2538 QDateTime modifiedCalendar = mLastCalendarSync;;
2539 addresseeLSync = getLastSyncAddressee();
2540 addresseeR = remote->addressee("last-syncAddressee-"+mCurrentSyncName );
2541 if ( addresseeR ) {
2542 addresseeRSync = (Addressee*) addresseeR->clone();
2543 remote->deleteAddressee(addresseeR );
2544
2545 } else {
2546 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2547 addresseeRSync = (Addressee*)addresseeLSync->clone();
2548 } else {
2549 fullDateRange = true;
2550 addresseeRSync = new Addressee();
2551 addresseeRSync->setSummary(mCurrentSyncName + i18n(" - sync addressee"));
2552 addresseeRSync->setUid("last-syncAddressee-"+mCurrentSyncName );
2553 addresseeRSync->setDtStart( mLastCalendarSync );
2554 addresseeRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
2555 addresseeRSync->setCategories( i18n("SyncAddressee") );
2556 }
2557 }
2558 if ( addresseeLSync->dtStart() == mLastCalendarSync )
2559 fullDateRange = true;
2560
2561 if ( ! fullDateRange ) {
2562 if ( addresseeLSync->dtStart() != addresseeRSync->dtStart() ) {
2563
2564 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2565 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2566 fullDateRange = true;
2567 }
2568 }
2569 if ( fullDateRange )
2570 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
2571 else
2572 mLastCalendarSync = addresseeLSync->dtStart();
2573 // for resyncing if own file has changed
2574 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2575 mLastCalendarSync = loadedFileVersion;
2576 qDebug("setting mLastCalendarSync ");
2577 }
2578 //qDebug("*************************** ");
2579 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() );
2580 QPtrList<Incidence> er = remote->rawIncidences();
2581 Incidence* inR = er.first();
2582 Incidence* inL;
2583 QProgressBar bar( er.count(),0 );
2584 bar.setCaption (i18n("Syncing - close to abort!") );
2585
2586 int w = 300;
2587 if ( QApplication::desktop()->width() < 320 )
2588 w = 220;
2589 int h = bar.sizeHint().height() ;
2590 int dw = QApplication::desktop()->width();
2591 int dh = QApplication::desktop()->height();
2592 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2593 bar.show();
2594 int modulo = (er.count()/10)+1;
2595 int incCounter = 0;
2596 while ( inR ) {
2597 if ( ! bar.isVisible() )
2598 return false;
2599 if ( incCounter % modulo == 0 )
2600 bar.setProgress( incCounter );
2601 ++incCounter;
2602 uid = inR->uid();
2603 bool skipIncidence = false;
2604 if ( uid.left(15) == QString("last-syncAddressee-") )
2605 skipIncidence = true;
2606 QString idS;
2607 qApp->processAddressees();
2608 if ( !skipIncidence ) {
2609 inL = local->incidence( uid );
2610 if ( inL ) { // maybe conflict - same uid in both calendars
2611 int maxrev = inL->revision();
2612 if ( maxrev < inR->revision() )
2613 maxrev = inR->revision();
2614 if ( (take = takeAddressee( inL, inR, mode, fullDateRange )) > 0 ) {
2615 //qDebug("take %d %s ", take, inL->summary().latin1());
2616 if ( take == 3 )
2617 return false;
2618 if ( take == 1 ) {// take local
2619 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2620 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
2621 else
2622 idS = inR->IDStr();
2623 remote->deleteIncidence( inR );
2624 if ( inL->revision() < maxrev )
2625 inL->setRevision( maxrev );
2626 inR = inL->clone();
2627 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2628 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
2629 inR->setIDStr( idS );
2630 remote->addIncidence( inR );
2631 ++changedRemote;
2632 } else {
2633 if ( inR->revision() < maxrev )
2634 inR->setRevision( maxrev );
2635 idS = inL->IDStr();
2636 local->deleteIncidence( inL );
2637 inL = inR->clone();
2638 inL->setIDStr( idS );
2639 local->addIncidence( inL );
2640 ++changedLocal;
2641 }
2642 }
2643 } else { // no conflict
2644 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2645 QString des = addresseeLSync->description();
2646 QString pref = "e";
2647 if ( inR->type() == "Todo" )
2648 pref = "t";
2649 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2650 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2651 //remote->deleteIncidence( inR );
2652 ++deletedAddresseeR;
2653 } else {
2654 inR->setLastModified( modifiedCalendar );
2655 inL = inR->clone();
2656 local->addIncidence( inL );
2657 ++addedAddressee;
2658 }
2659 } else {
2660 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
2661 inR->setLastModified( modifiedCalendar );
2662 local->addIncidence( inR->clone() );
2663 ++addedAddressee;
2664 } else {
2665 checkExternSyncAddressee(addresseeRSyncSharp, inR);
2666 remote->deleteIncidence( inR );
2667 ++deletedAddresseeR;
2668 }
2669 }
2670 }
2671 }
2672 inR = er.next();
2673 }
2674 QPtrList<Incidence> el = local->rawIncidences();
2675 inL = el.first();
2676 modulo = (el.count()/10)+1;
2677 bar.setCaption (i18n("Add / remove addressees") );
2678 bar.setTotalSteps ( el.count() ) ;
2679 bar.show();
2680 incCounter = 0;
2681
2682 while ( inL ) {
2683
2684 qApp->processAddressees();
2685 if ( ! bar.isVisible() )
2686 return false;
2687 if ( incCounter % modulo == 0 )
2688 bar.setProgress( incCounter );
2689 ++incCounter;
2690 uid = inL->uid();
2691 bool skipIncidence = false;
2692 if ( uid.left(15) == QString("last-syncAddressee-") )
2693 skipIncidence = true;
2694 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
2695 skipIncidence = true;
2696 if ( !skipIncidence ) {
2697 inR = remote->incidence( uid );
2698 if ( ! inR ) {
2699 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2700 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2701 checkExternSyncAddressee(addresseeLSyncSharp, inL);
2702 local->deleteIncidence( inL );
2703 ++deletedAddresseeL;
2704 } else {
2705 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
2706 inL->removeID(mCurrentSyncDevice );
2707 ++addedAddresseeR;
2708 //qDebug("remote added Incidence %s ", inL->summary().latin1());
2709 inL->setLastModified( modifiedCalendar );
2710 inR = inL->clone();
2711 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2712 remote->addIncidence( inR );
2713 }
2714 }
2715 } else {
2716 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
2717 checkExternSyncAddressee(addresseeLSyncSharp, inL);
2718 local->deleteIncidence( inL );
2719 ++deletedAddresseeL;
2720 } else {
2721 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
2722 ++addedAddresseeR;
2723 inL->setLastModified( modifiedCalendar );
2724 remote->addIncidence( inL->clone() );
2725 }
2726 }
2727 }
2728 }
2729 }
2730 inL = el.next();
2731 }
2732 int delFut = 0;
2733 if ( KOPrefs::instance()->mWriteBackInFuture ) {
2734 er = remote->rawIncidences();
2735 inR = er.first();
2736 QDateTime dt;
2737 QDateTime cur = QDateTime::currentDateTime();
2738 QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 );
2739 while ( inR ) {
2740 if ( inR->type() == "Todo" ) {
2741 Todo * t = (Todo*)inR;
2742 if ( t->hasDueDate() )
2743 dt = t->dtDue();
2744 else
2745 dt = cur.addSecs( 62 );
2746 }
2747 else if (inR->type() == "Addressee" ) {
2748 bool ok;
2749 dt = inR->getNextOccurence( cur, &ok );
2750 if ( !ok )
2751 dt = cur.addSecs( -62 );
2752 }
2753 else
2754 dt = inR->dtStart();
2755 if ( dt < cur || dt > end ) {
2756 remote->deleteIncidence( inR );
2757 ++delFut;
2758 }
2759 inR = er.next();
2760 }
2761 }
2762 bar.hide();
2763 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
2764 addresseeLSync->setReadOnly( false );
2765 addresseeLSync->setDtStart( mLastCalendarSync );
2766 addresseeRSync->setDtStart( mLastCalendarSync );
2767 addresseeLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
2768 addresseeRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
2769 addresseeRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
2770 addresseeLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
2771 addresseeLSync->setReadOnly( true );
2772 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2773 remote->addAddressee( addresseeRSync );
2774 QString mes;
2775 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 );
2776 QString delmess;
2777 if ( delFut ) {
2778 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture );
2779 mes += delmess;
2780 }
2781 if ( KOPrefs::instance()->mShowSyncSummary ) {
2782 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
2783 }
2784 qDebug( mes );
2785 mCalendar->checkAlarmForIncidence( 0, true );
2786 return syncOK;
2787#endif
2788 return false;
2519} 2789}
2520bool KABCore::syncAB(QString filename, int mode) 2790bool KABCore::syncAB(QString filename, int mode)
2521{ 2791{
2522 2792
2523 2793 //pending prepare addresseeview for output
2524 2794 //pending detect, if remote file has REV field. if not switch to external sync
2525 mGlobalSyncMode = SYNC_MODE_NORMAL; 2795 mGlobalSyncMode = SYNC_MODE_NORMAL;
2526 AddressBook abLocal(filename,"syncContact"); 2796 AddressBook abLocal(filename,"syncContact");
2527 bool syncOK = false; 2797 bool syncOK = false;
2528 if ( abLocal.load() ) { 2798 if ( abLocal.load() ) {
2529 qDebug("AB loaded %s mode %d",filename.latin1(), mode ); 2799 qDebug("AB loaded %s mode %d",filename.latin1(), mode );
2530 AddressBook::Iterator it; 2800 AddressBook::Iterator it;
2531 QStringList vcards; 2801 QStringList vcards;
2532 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2802 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2533 qDebug("Name %s ", (*it).familyName().latin1()); 2803 qDebug("Name %s ", (*it).familyName().latin1());
2534 } 2804 }
2535 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2805 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2536 if ( syncOK ) { 2806 if ( syncOK ) {
2537 if ( KABPrefs::instance()->mWriteBackFile ) 2807 if ( KABPrefs::instance()->mWriteBackFile )
2538 { 2808 {
2809 qDebug("saving remote AB ");
2539 abLocal.saveAB(); 2810 abLocal.saveAB();
2540 } 2811 }
2541 } 2812 }
2542 setModified(); 2813 setModified();
2543 2814
2544 } 2815 }
2545 if ( syncOK ) 2816 if ( syncOK )
2546 ;//updateView(); 2817 mViewManager->refreshView();
2547 return syncOK; 2818 return syncOK;
2548#if 0 2819#if 0
2549 mGlobalSyncMode = SYNC_MODE_NORMAL; 2820
2550 CalendarLocal* calendar = new CalendarLocal();
2551 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
2552 FileStorage* storage = new FileStorage( calendar );
2553 bool syncOK = false;
2554 storage->setFileName( filename );
2555 // qDebug("loading ... ");
2556 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 2821 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
2557 getEventViewerDialog()->setSyncMode( true ); 2822 getEventViewerDialog()->setSyncMode( true );
2558 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 2823 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
2559 getEventViewerDialog()->setSyncMode( false ); 2824 getEventViewerDialog()->setSyncMode( false );
2560 if ( syncOK ) { 2825 if ( syncOK ) {
2561 if ( KOPrefs::instance()->mWriteBackFile ) 2826 if ( KOPrefs::instance()->mWriteBackFile )
2562 { 2827 {
2563 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 2828 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
2564 storage->save(); 2829 storage->save();
2565 } 2830 }
2566 } 2831 }
2567 setModified(); 2832 setModified();
2568 } 2833 }
2569 delete storage; 2834
2570 delete calendar;
2571 if ( syncOK )
2572 updateView();
2573 return syncOK;
2574#endif 2835#endif
2575} 2836}
2576 2837
2577 2838
2578void KABCore::confSync() 2839void KABCore::confSync()
2579{ 2840{
2580 static KSyncPrefsDialog* sp = 0; 2841 static KSyncPrefsDialog* sp = 0;
2581 if ( ! sp ) { 2842 if ( ! sp ) {
2582 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 2843 sp = new KSyncPrefsDialog( this, "syncprefs", true );
2583 } 2844 }
2584 sp->usrReadConfig(); 2845 sp->usrReadConfig();
2585#ifndef DESKTOP_VERSION 2846#ifndef DESKTOP_VERSION
2586 sp->showMaximized(); 2847 sp->showMaximized();
2587#else 2848#else
2588 sp->show(); 2849 sp->show();
2589#endif 2850#endif
2590 sp->exec(); 2851 sp->exec();
2591 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 2852 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
2592 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 2853 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
2593 fillSyncMenu(); 2854 fillSyncMenu();
2594} 2855}
2595void KABCore::syncSharp() 2856void KABCore::syncSharp()
2596{ 2857{
2597 if ( mModified ) 2858 if ( mModified )
2598 save(); 2859 save();
2599 qDebug("pending syncSharp() "); 2860 qDebug("pending syncSharp() ");
2600 //mView->syncSharp(); 2861 //mView->syncSharp();
2601 setModified(); 2862 setModified();
2602 2863
2603} 2864}
2604void KABCore::syncPhone() 2865void KABCore::syncPhone()
2605{ 2866{
2606 if ( mModified ) 2867 if ( mModified )
2607 save(); 2868 save();
2608 qDebug("pending syncPhone(); "); 2869 qDebug("pending syncPhone(); ");
2609 //mView->syncPhone(); 2870 //mView->syncPhone();
2610 setModified(); 2871 setModified();
2611 2872
2612} 2873}