summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-26 20:55:30 (UTC)
committer zautrix <zautrix>2004-10-26 20:55:30 (UTC)
commit13e996beddabc5e88f4f2fe49b2ce6cb8408eb30 (patch) (unidiff)
tree77395039348f3af1b5d1e1673f5638a7f34c0e99
parent8b111ae30fc51a4a580b8d485bef8ad28b0dde84 (diff)
downloadkdepimpi-13e996beddabc5e88f4f2fe49b2ce6cb8408eb30.zip
kdepimpi-13e996beddabc5e88f4f2fe49b2ce6cb8408eb30.tar.gz
kdepimpi-13e996beddabc5e88f4f2fe49b2ce6cb8408eb30.tar.bz2
added removeSyncInfo to KSyncInterface class
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp5
-rw-r--r--kaddressbook/kabcore.h1
-rw-r--r--korganizer/calendarview.cpp6
-rw-r--r--korganizer/calendarview.h1
-rw-r--r--libkdepim/ksyncmanager.h1
-rw-r--r--pwmanager/pwmanager/pwm.cpp6
-rw-r--r--pwmanager/pwmanager/pwm.h3
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp5
-rw-r--r--pwmanager/pwmanager/pwmdoc.h1
9 files changed, 27 insertions, 2 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 2a3334e..efae874 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1,2911 +1,2916 @@
1/* 1/*
2 This file is part of KAddressbook. 2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24/*s 24/*s
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#include <qtimer.h> 36#include <qtimer.h>
37#include <qlabel.h> 37#include <qlabel.h>
38#include <qregexp.h> 38#include <qregexp.h>
39#include <qlineedit.h> 39#include <qlineedit.h>
40#include <qcheckbox.h> 40#include <qcheckbox.h>
41#include <qpushbutton.h> 41#include <qpushbutton.h>
42#include <qprogressbar.h> 42#include <qprogressbar.h>
43#include <libkdepim/phoneaccess.h> 43#include <libkdepim/phoneaccess.h>
44 44
45#ifndef KAB_EMBEDDED 45#ifndef KAB_EMBEDDED
46#include <qclipboard.h> 46#include <qclipboard.h>
47#include <qdir.h> 47#include <qdir.h>
48#include <qfile.h> 48#include <qfile.h>
49#include <qapplicaton.h> 49#include <qapplicaton.h>
50#include <qprogressbar.h> 50#include <qprogressbar.h>
51#include <qlayout.h> 51#include <qlayout.h>
52#include <qregexp.h> 52#include <qregexp.h>
53#include <qvbox.h> 53#include <qvbox.h>
54#include <kabc/addresseelist.h> 54#include <kabc/addresseelist.h>
55#include <kabc/errorhandler.h> 55#include <kabc/errorhandler.h>
56#include <kabc/resource.h> 56#include <kabc/resource.h>
57#include <kabc/vcardconverter.h> 57#include <kabc/vcardconverter.h>
58#include <kapplication.h> 58#include <kapplication.h>
59#include <kactionclasses.h> 59#include <kactionclasses.h>
60#include <kcmultidialog.h> 60#include <kcmultidialog.h>
61#include <kdebug.h> 61#include <kdebug.h>
62#include <kdeversion.h> 62#include <kdeversion.h>
63#include <kkeydialog.h> 63#include <kkeydialog.h>
64#include <kmessagebox.h> 64#include <kmessagebox.h>
65#include <kprinter.h> 65#include <kprinter.h>
66#include <kprotocolinfo.h> 66#include <kprotocolinfo.h>
67#include <kresources/selectdialog.h> 67#include <kresources/selectdialog.h>
68#include <kstandarddirs.h> 68#include <kstandarddirs.h>
69#include <ktempfile.h> 69#include <ktempfile.h>
70#include <kxmlguiclient.h> 70#include <kxmlguiclient.h>
71#include <kaboutdata.h> 71#include <kaboutdata.h>
72#include <libkdepim/categoryselectdialog.h> 72#include <libkdepim/categoryselectdialog.h>
73 73
74#include "addresseeutil.h" 74#include "addresseeutil.h"
75#include "addresseeeditordialog.h" 75#include "addresseeeditordialog.h"
76#include "extensionmanager.h" 76#include "extensionmanager.h"
77#include "kstdaction.h" 77#include "kstdaction.h"
78#include "kaddressbookservice.h" 78#include "kaddressbookservice.h"
79#include "ldapsearchdialog.h" 79#include "ldapsearchdialog.h"
80#include "printing/printingwizard.h" 80#include "printing/printingwizard.h"
81#else // KAB_EMBEDDED 81#else // KAB_EMBEDDED
82 82
83#include <kapplication.h> 83#include <kapplication.h>
84#include "KDGanttMinimizeSplitter.h" 84#include "KDGanttMinimizeSplitter.h"
85#include "kaddressbookmain.h" 85#include "kaddressbookmain.h"
86#include "kactioncollection.h" 86#include "kactioncollection.h"
87#include "addresseedialog.h" 87#include "addresseedialog.h"
88//US 88//US
89#include <addresseeview.h> 89#include <addresseeview.h>
90 90
91#include <qapp.h> 91#include <qapp.h>
92#include <qmenubar.h> 92#include <qmenubar.h>
93//#include <qtoolbar.h> 93//#include <qtoolbar.h>
94#include <qmessagebox.h> 94#include <qmessagebox.h>
95#include <kdebug.h> 95#include <kdebug.h>
96#include <kiconloader.h> // needed for SmallIcon 96#include <kiconloader.h> // needed for SmallIcon
97#include <kresources/kcmkresources.h> 97#include <kresources/kcmkresources.h>
98#include <ktoolbar.h> 98#include <ktoolbar.h>
99 99
100 100
101//#include <qlabel.h> 101//#include <qlabel.h>
102 102
103 103
104#ifndef DESKTOP_VERSION 104#ifndef DESKTOP_VERSION
105#include <qpe/ir.h> 105#include <qpe/ir.h>
106#include <qpe/qpemenubar.h> 106#include <qpe/qpemenubar.h>
107#include <qtopia/qcopenvelope_qws.h> 107#include <qtopia/qcopenvelope_qws.h>
108#else 108#else
109 109
110#include <qmenubar.h> 110#include <qmenubar.h>
111#endif 111#endif
112 112
113#endif // KAB_EMBEDDED 113#endif // KAB_EMBEDDED
114#include "kcmconfigs/kcmkabconfig.h" 114#include "kcmconfigs/kcmkabconfig.h"
115#include "kcmconfigs/kcmkdepimconfig.h" 115#include "kcmconfigs/kcmkdepimconfig.h"
116#include "kpimglobalprefs.h" 116#include "kpimglobalprefs.h"
117#include "externalapphandler.h" 117#include "externalapphandler.h"
118 118
119 119
120#include <kresources/selectdialog.h> 120#include <kresources/selectdialog.h>
121#include <kmessagebox.h> 121#include <kmessagebox.h>
122 122
123#include <picture.h> 123#include <picture.h>
124#include <resource.h> 124#include <resource.h>
125 125
126//US#include <qsplitter.h> 126//US#include <qsplitter.h>
127#include <qmap.h> 127#include <qmap.h>
128#include <qdir.h> 128#include <qdir.h>
129#include <qfile.h> 129#include <qfile.h>
130#include <qvbox.h> 130#include <qvbox.h>
131#include <qlayout.h> 131#include <qlayout.h>
132#include <qclipboard.h> 132#include <qclipboard.h>
133#include <qtextstream.h> 133#include <qtextstream.h>
134 134
135#include <libkdepim/categoryselectdialog.h> 135#include <libkdepim/categoryselectdialog.h>
136#include <kabc/vcardconverter.h> 136#include <kabc/vcardconverter.h>
137 137
138 138
139#include "addresseeutil.h" 139#include "addresseeutil.h"
140#include "undocmds.h" 140#include "undocmds.h"
141#include "addresseeeditordialog.h" 141#include "addresseeeditordialog.h"
142#include "viewmanager.h" 142#include "viewmanager.h"
143#include "details/detailsviewcontainer.h" 143#include "details/detailsviewcontainer.h"
144#include "kabprefs.h" 144#include "kabprefs.h"
145#include "xxportmanager.h" 145#include "xxportmanager.h"
146#include "incsearchwidget.h" 146#include "incsearchwidget.h"
147#include "jumpbuttonbar.h" 147#include "jumpbuttonbar.h"
148#include "extensionmanager.h" 148#include "extensionmanager.h"
149#include "addresseeconfig.h" 149#include "addresseeconfig.h"
150#include <kcmultidialog.h> 150#include <kcmultidialog.h>
151 151
152#ifdef _WIN32_ 152#ifdef _WIN32_
153 153
154#include "kaimportoldialog.h" 154#include "kaimportoldialog.h"
155#else 155#else
156#include <unistd.h> 156#include <unistd.h>
157#endif 157#endif
158// sync includes 158// sync includes
159#include <libkdepim/ksyncprofile.h> 159#include <libkdepim/ksyncprofile.h>
160#include <libkdepim/ksyncprefsdialog.h> 160#include <libkdepim/ksyncprefsdialog.h>
161 161
162class KAex2phonePrefs : public QDialog 162class KAex2phonePrefs : public QDialog
163{ 163{
164 public: 164 public:
165 KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) : 165 KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) :
166 QDialog( parent, name, true ) 166 QDialog( parent, name, true )
167 { 167 {
168 setCaption( i18n("Export to phone options") ); 168 setCaption( i18n("Export to phone options") );
169 QVBoxLayout* lay = new QVBoxLayout( this ); 169 QVBoxLayout* lay = new QVBoxLayout( this );
170 lay->setSpacing( 3 ); 170 lay->setSpacing( 3 );
171 lay->setMargin( 3 ); 171 lay->setMargin( 3 );
172 QLabel *lab; 172 QLabel *lab;
173 lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) ); 173 lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) );
174 lab->setAlignment (AlignHCenter ); 174 lab->setAlignment (AlignHCenter );
175 QHBox* temphb; 175 QHBox* temphb;
176 temphb = new QHBox( this ); 176 temphb = new QHBox( this );
177 new QLabel( i18n("I/O device: "), temphb ); 177 new QLabel( i18n("I/O device: "), temphb );
178 mPhoneDevice = new QLineEdit( temphb); 178 mPhoneDevice = new QLineEdit( temphb);
179 lay->addWidget( temphb ); 179 lay->addWidget( temphb );
180 temphb = new QHBox( this ); 180 temphb = new QHBox( this );
181 new QLabel( i18n("Connection: "), temphb ); 181 new QLabel( i18n("Connection: "), temphb );
182 mPhoneConnection = new QLineEdit( temphb); 182 mPhoneConnection = new QLineEdit( temphb);
183 lay->addWidget( temphb ); 183 lay->addWidget( temphb );
184 temphb = new QHBox( this ); 184 temphb = new QHBox( this );
185 new QLabel( i18n("Model(opt.): "), temphb ); 185 new QLabel( i18n("Model(opt.): "), temphb );
186 mPhoneModel = new QLineEdit( temphb); 186 mPhoneModel = new QLineEdit( temphb);
187 lay->addWidget( temphb ); 187 lay->addWidget( temphb );
188 // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this ); 188 // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this );
189 // lay->addWidget( mWriteToSim ); 189 // lay->addWidget( mWriteToSim );
190 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) ); 190 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) );
191 lab->setAlignment (AlignHCenter ); 191 lab->setAlignment (AlignHCenter );
192 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); 192 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this );
193 lay->addWidget( ok ); 193 lay->addWidget( ok );
194 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 194 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
195 lay->addWidget( cancel ); 195 lay->addWidget( cancel );
196 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 196 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
197 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 197 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
198 resize( 220, 240 ); 198 resize( 220, 240 );
199 199
200 } 200 }
201 201
202public: 202public:
203 QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel; 203 QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel;
204 QCheckBox* mWriteToSim; 204 QCheckBox* mWriteToSim;
205}; 205};
206 206
207 207
208bool pasteWithNewUid = true; 208bool pasteWithNewUid = true;
209 209
210#ifdef KAB_EMBEDDED 210#ifdef KAB_EMBEDDED
211KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) 211KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name )
212 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), 212 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ),
213 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ 213 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/
214 mReadWrite( readWrite ), mModified( false ), mMainWindow(client) 214 mReadWrite( readWrite ), mModified( false ), mMainWindow(client)
215#else //KAB_EMBEDDED 215#else //KAB_EMBEDDED
216KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) 216KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name )
217 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), 217 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ),
218 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), 218 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ),
219 mReadWrite( readWrite ), mModified( false ) 219 mReadWrite( readWrite ), mModified( false )
220#endif //KAB_EMBEDDED 220#endif //KAB_EMBEDDED
221{ 221{
222 // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); 222 // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu);
223 // syncManager->setBlockSave(false); 223 // syncManager->setBlockSave(false);
224 mExtensionBarSplitter = 0; 224 mExtensionBarSplitter = 0;
225 mIsPart = !parent->inherits( "KAddressBookMain" ); 225 mIsPart = !parent->inherits( "KAddressBookMain" );
226 mAddressBook = KABC::StdAddressBook::self(); 226 mAddressBook = KABC::StdAddressBook::self();
227 KABC::StdAddressBook::setAutomaticSave( false ); 227 KABC::StdAddressBook::setAutomaticSave( false );
228 228
229#ifndef KAB_EMBEDDED 229#ifndef KAB_EMBEDDED
230 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); 230 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler );
231#endif //KAB_EMBEDDED 231#endif //KAB_EMBEDDED
232 232
233 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), 233 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
234 SLOT( addressBookChanged() ) ); 234 SLOT( addressBookChanged() ) );
235 235
236#if 0 236#if 0
237 // LP moved to addressbook init method 237 // LP moved to addressbook init method
238 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, 238 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization,
239 "X-Department", "KADDRESSBOOK" ); 239 "X-Department", "KADDRESSBOOK" );
240 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, 240 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization,
241 "X-Profession", "KADDRESSBOOK" ); 241 "X-Profession", "KADDRESSBOOK" );
242 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 242 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
243 "X-AssistantsName", "KADDRESSBOOK" ); 243 "X-AssistantsName", "KADDRESSBOOK" );
244 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 244 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
245 "X-ManagersName", "KADDRESSBOOK" ); 245 "X-ManagersName", "KADDRESSBOOK" );
246 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 246 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
247 "X-SpousesName", "KADDRESSBOOK" ); 247 "X-SpousesName", "KADDRESSBOOK" );
248 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal, 248 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal,
249 "X-Office", "KADDRESSBOOK" ); 249 "X-Office", "KADDRESSBOOK" );
250 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 250 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
251 "X-IMAddress", "KADDRESSBOOK" ); 251 "X-IMAddress", "KADDRESSBOOK" );
252 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 252 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
253 "X-Anniversary", "KADDRESSBOOK" ); 253 "X-Anniversary", "KADDRESSBOOK" );
254 254
255 //US added this field to become compatible with Opie/qtopia addressbook 255 //US added this field to become compatible with Opie/qtopia addressbook
256 // values can be "female" or "male" or "". An empty field represents undefined. 256 // values can be "female" or "male" or "". An empty field represents undefined.
257 mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal, 257 mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal,
258 "X-Gender", "KADDRESSBOOK" ); 258 "X-Gender", "KADDRESSBOOK" );
259 mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal, 259 mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal,
260 "X-Children", "KADDRESSBOOK" ); 260 "X-Children", "KADDRESSBOOK" );
261 mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 261 mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
262 "X-FreeBusyUrl", "KADDRESSBOOK" ); 262 "X-FreeBusyUrl", "KADDRESSBOOK" );
263#endif 263#endif
264 initGUI(); 264 initGUI();
265 265
266 mIncSearchWidget->setFocus(); 266 mIncSearchWidget->setFocus();
267 267
268 268
269 connect( mViewManager, SIGNAL( selected( const QString& ) ), 269 connect( mViewManager, SIGNAL( selected( const QString& ) ),
270 SLOT( setContactSelected( const QString& ) ) ); 270 SLOT( setContactSelected( const QString& ) ) );
271 connect( mViewManager, SIGNAL( executed( const QString& ) ), 271 connect( mViewManager, SIGNAL( executed( const QString& ) ),
272 SLOT( executeContact( const QString& ) ) ); 272 SLOT( executeContact( const QString& ) ) );
273 273
274 connect( mViewManager, SIGNAL( deleteRequest( ) ), 274 connect( mViewManager, SIGNAL( deleteRequest( ) ),
275 SLOT( deleteContacts( ) ) ); 275 SLOT( deleteContacts( ) ) );
276 connect( mViewManager, SIGNAL( modified() ), 276 connect( mViewManager, SIGNAL( modified() ),
277 SLOT( setModified() ) ); 277 SLOT( setModified() ) );
278 278
279 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) ); 279 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) );
280 connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) ); 280 connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) );
281 281
282 connect( mXXPortManager, SIGNAL( modified() ), 282 connect( mXXPortManager, SIGNAL( modified() ),
283 SLOT( setModified() ) ); 283 SLOT( setModified() ) );
284 284
285 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ), 285 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ),
286 SLOT( incrementalSearch( const QString& ) ) ); 286 SLOT( incrementalSearch( const QString& ) ) );
287 connect( mIncSearchWidget, SIGNAL( fieldChanged() ), 287 connect( mIncSearchWidget, SIGNAL( fieldChanged() ),
288 mJumpButtonBar, SLOT( recreateButtons() ) ); 288 mJumpButtonBar, SLOT( recreateButtons() ) );
289 289
290 connect( mDetails, SIGNAL( sendEmail( const QString& ) ), 290 connect( mDetails, SIGNAL( sendEmail( const QString& ) ),
291 SLOT( sendMail( const QString& ) ) ); 291 SLOT( sendMail( const QString& ) ) );
292 292
293 293
294 connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&))); 294 connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&)));
295 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&))); 295 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&)));
296 connect( ExternalAppHandler::instance(), SIGNAL (requestForBirthdayList(const QString&, const QString&)),this, SLOT(requestForBirthdayList(const QString&, const QString&))); 296 connect( ExternalAppHandler::instance(), SIGNAL (requestForBirthdayList(const QString&, const QString&)),this, SLOT(requestForBirthdayList(const QString&, const QString&)));
297 297
298 298
299#ifndef KAB_EMBEDDED 299#ifndef KAB_EMBEDDED
300 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ), 300 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ),
301 mXXPortManager, SLOT( importVCard( const KURL& ) ) ); 301 mXXPortManager, SLOT( importVCard( const KURL& ) ) );
302 302
303 connect( mDetails, SIGNAL( browse( const QString& ) ), 303 connect( mDetails, SIGNAL( browse( const QString& ) ),
304 SLOT( browse( const QString& ) ) ); 304 SLOT( browse( const QString& ) ) );
305 305
306 306
307 mAddressBookService = new KAddressBookService( this ); 307 mAddressBookService = new KAddressBookService( this );
308 308
309#endif //KAB_EMBEDDED 309#endif //KAB_EMBEDDED
310 310
311 mMessageTimer = new QTimer( this ); 311 mMessageTimer = new QTimer( this );
312 connect( mMessageTimer, SIGNAL( timeout() ), this, SLOT( setCaptionBack() ) ); 312 connect( mMessageTimer, SIGNAL( timeout() ), this, SLOT( setCaptionBack() ) );
313 mEditorDialog = 0; 313 mEditorDialog = 0;
314 createAddresseeEditorDialog( this ); 314 createAddresseeEditorDialog( this );
315 setModified( false ); 315 setModified( false );
316 mBRdisabled = 0; 316 mBRdisabled = 0;
317#ifndef DESKTOP_VERSION 317#ifndef DESKTOP_VERSION
318 infrared = 0; 318 infrared = 0;
319#endif 319#endif
320 toggleBeamReceive( ); 320 toggleBeamReceive( );
321} 321}
322 322
323KABCore::~KABCore() 323KABCore::~KABCore()
324{ 324{
325 // save(); 325 // save();
326 //saveSettings(); 326 //saveSettings();
327 //KABPrefs::instance()->writeConfig(); 327 //KABPrefs::instance()->writeConfig();
328 delete AddresseeConfig::instance(); 328 delete AddresseeConfig::instance();
329 mAddressBook = 0; 329 mAddressBook = 0;
330 KABC::StdAddressBook::close(); 330 KABC::StdAddressBook::close();
331 331
332 delete syncManager; 332 delete syncManager;
333#ifndef DESKTOP_VERSION 333#ifndef DESKTOP_VERSION
334 if ( infrared ) 334 if ( infrared )
335 delete infrared; 335 delete infrared;
336#endif 336#endif
337} 337}
338void KABCore::receive( const QCString& cmsg, const QByteArray& data ) 338void KABCore::receive( const QCString& cmsg, const QByteArray& data )
339{ 339{
340 qDebug("KA: QCOP message received: %s ", cmsg.data() ); 340 qDebug("KA: QCOP message received: %s ", cmsg.data() );
341 if ( cmsg == "setDocument(QString)" ) { 341 if ( cmsg == "setDocument(QString)" ) {
342 QDataStream stream( data, IO_ReadOnly ); 342 QDataStream stream( data, IO_ReadOnly );
343 QString fileName; 343 QString fileName;
344 stream >> fileName; 344 stream >> fileName;
345 recieve( fileName ); 345 recieve( fileName );
346 return; 346 return;
347 } 347 }
348} 348}
349void KABCore::toggleBeamReceive( ) 349void KABCore::toggleBeamReceive( )
350{ 350{
351 if ( mBRdisabled ) 351 if ( mBRdisabled )
352 return; 352 return;
353#ifndef DESKTOP_VERSION 353#ifndef DESKTOP_VERSION
354 if ( infrared ) { 354 if ( infrared ) {
355 qDebug("AB disable BeamReceive "); 355 qDebug("AB disable BeamReceive ");
356 delete infrared; 356 delete infrared;
357 infrared = 0; 357 infrared = 0;
358 mActionBR->setChecked(false); 358 mActionBR->setChecked(false);
359 return; 359 return;
360 } 360 }
361 qDebug("AB enable BeamReceive "); 361 qDebug("AB enable BeamReceive ");
362 mActionBR->setChecked(true); 362 mActionBR->setChecked(true);
363 363
364 infrared = new QCopChannel("QPE/Application/addressbook",this, "channelAB" ) ; 364 infrared = new QCopChannel("QPE/Application/addressbook",this, "channelAB" ) ;
365 QObject::connect( infrared, SIGNAL (received ( const QCString &, const QByteArray & )),this, SLOT(receive( const QCString&, const QByteArray& ))); 365 QObject::connect( infrared, SIGNAL (received ( const QCString &, const QByteArray & )),this, SLOT(receive( const QCString&, const QByteArray& )));
366#endif 366#endif
367} 367}
368 368
369 369
370void KABCore::disableBR(bool b) 370void KABCore::disableBR(bool b)
371{ 371{
372#ifndef DESKTOP_VERSION 372#ifndef DESKTOP_VERSION
373 if ( b ) { 373 if ( b ) {
374 if ( infrared ) { 374 if ( infrared ) {
375 toggleBeamReceive( ); 375 toggleBeamReceive( );
376 } 376 }
377 mBRdisabled = true; 377 mBRdisabled = true;
378 } else { 378 } else {
379 if ( mBRdisabled ) { 379 if ( mBRdisabled ) {
380 mBRdisabled = false; 380 mBRdisabled = false;
381 //toggleBeamReceive( ); 381 //toggleBeamReceive( );
382 } 382 }
383 } 383 }
384#endif 384#endif
385 385
386} 386}
387void KABCore::recieve( QString fn ) 387void KABCore::recieve( QString fn )
388{ 388{
389 //qDebug("KABCore::recieve "); 389 //qDebug("KABCore::recieve ");
390 int count = mAddressBook->importFromFile( fn, true ); 390 int count = mAddressBook->importFromFile( fn, true );
391 if ( count ) 391 if ( count )
392 setModified( true ); 392 setModified( true );
393 mViewManager->refreshView(); 393 mViewManager->refreshView();
394 message(i18n("%1 contact(s) received!").arg( count )); 394 message(i18n("%1 contact(s) received!").arg( count ));
395 topLevelWidget()->showMaximized(); 395 topLevelWidget()->showMaximized();
396 topLevelWidget()->raise(); 396 topLevelWidget()->raise();
397} 397}
398void KABCore::restoreSettings() 398void KABCore::restoreSettings()
399{ 399{
400 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce; 400 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce;
401 401
402 bool state; 402 bool state;
403 403
404 if (mMultipleViewsAtOnce) 404 if (mMultipleViewsAtOnce)
405 state = KABPrefs::instance()->mDetailsPageVisible; 405 state = KABPrefs::instance()->mDetailsPageVisible;
406 else 406 else
407 state = false; 407 state = false;
408 408
409 mActionDetails->setChecked( state ); 409 mActionDetails->setChecked( state );
410 setDetailsVisible( state ); 410 setDetailsVisible( state );
411 411
412 state = KABPrefs::instance()->mJumpButtonBarVisible; 412 state = KABPrefs::instance()->mJumpButtonBarVisible;
413 413
414 mActionJumpBar->setChecked( state ); 414 mActionJumpBar->setChecked( state );
415 setJumpButtonBarVisible( state ); 415 setJumpButtonBarVisible( state );
416/*US 416/*US
417 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter; 417 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter;
418 if ( splitterSize.count() == 0 ) { 418 if ( splitterSize.count() == 0 ) {
419 splitterSize.append( width() / 2 ); 419 splitterSize.append( width() / 2 );
420 splitterSize.append( width() / 2 ); 420 splitterSize.append( width() / 2 );
421 } 421 }
422 mMiniSplitter->setSizes( splitterSize ); 422 mMiniSplitter->setSizes( splitterSize );
423 if ( mExtensionBarSplitter ) { 423 if ( mExtensionBarSplitter ) {
424 splitterSize = KABPrefs::instance()->mExtensionsSplitter; 424 splitterSize = KABPrefs::instance()->mExtensionsSplitter;
425 if ( splitterSize.count() == 0 ) { 425 if ( splitterSize.count() == 0 ) {
426 splitterSize.append( width() / 2 ); 426 splitterSize.append( width() / 2 );
427 splitterSize.append( width() / 2 ); 427 splitterSize.append( width() / 2 );
428 } 428 }
429 mExtensionBarSplitter->setSizes( splitterSize ); 429 mExtensionBarSplitter->setSizes( splitterSize );
430 430
431 } 431 }
432*/ 432*/
433 mViewManager->restoreSettings(); 433 mViewManager->restoreSettings();
434 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField ); 434 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField );
435 mExtensionManager->restoreSettings(); 435 mExtensionManager->restoreSettings();
436#ifdef DESKTOP_VERSION 436#ifdef DESKTOP_VERSION
437 int wid = width(); 437 int wid = width();
438 if ( wid < 10 ) 438 if ( wid < 10 )
439 wid = 400; 439 wid = 400;
440#else 440#else
441 int wid = QApplication::desktop()->width(); 441 int wid = QApplication::desktop()->width();
442 if ( wid < 640 ) 442 if ( wid < 640 )
443 wid = QApplication::desktop()->height(); 443 wid = QApplication::desktop()->height();
444#endif 444#endif
445 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter; 445 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter;
446 if ( true /*splitterSize.count() == 0*/ ) { 446 if ( true /*splitterSize.count() == 0*/ ) {
447 splitterSize.append( wid / 2 ); 447 splitterSize.append( wid / 2 );
448 splitterSize.append( wid / 2 ); 448 splitterSize.append( wid / 2 );
449 } 449 }
450 mMiniSplitter->setSizes( splitterSize ); 450 mMiniSplitter->setSizes( splitterSize );
451 if ( mExtensionBarSplitter ) { 451 if ( mExtensionBarSplitter ) {
452 //splitterSize = KABPrefs::instance()->mExtensionsSplitter; 452 //splitterSize = KABPrefs::instance()->mExtensionsSplitter;
453 if ( true /*splitterSize.count() == 0*/ ) { 453 if ( true /*splitterSize.count() == 0*/ ) {
454 splitterSize.append( wid / 2 ); 454 splitterSize.append( wid / 2 );
455 splitterSize.append( wid / 2 ); 455 splitterSize.append( wid / 2 );
456 } 456 }
457 mExtensionBarSplitter->setSizes( splitterSize ); 457 mExtensionBarSplitter->setSizes( splitterSize );
458 458
459 } 459 }
460 460
461 461
462} 462}
463 463
464void KABCore::saveSettings() 464void KABCore::saveSettings()
465{ 465{
466 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked(); 466 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked();
467 if ( mExtensionBarSplitter ) 467 if ( mExtensionBarSplitter )
468 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 468 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
469 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked(); 469 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked();
470 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes(); 470 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes();
471#ifndef KAB_EMBEDDED 471#ifndef KAB_EMBEDDED
472 472
473 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 473 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
474 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes(); 474 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes();
475#endif //KAB_EMBEDDED 475#endif //KAB_EMBEDDED
476 mExtensionManager->saveSettings(); 476 mExtensionManager->saveSettings();
477 mViewManager->saveSettings(); 477 mViewManager->saveSettings();
478 478
479 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem(); 479 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem();
480} 480}
481 481
482KABC::AddressBook *KABCore::addressBook() const 482KABC::AddressBook *KABCore::addressBook() const
483{ 483{
484 return mAddressBook; 484 return mAddressBook;
485} 485}
486 486
487KConfig *KABCore::config() 487KConfig *KABCore::config()
488{ 488{
489#ifndef KAB_EMBEDDED 489#ifndef KAB_EMBEDDED
490 return KABPrefs::instance()->config(); 490 return KABPrefs::instance()->config();
491#else //KAB_EMBEDDED 491#else //KAB_EMBEDDED
492 return KABPrefs::instance()->getConfig(); 492 return KABPrefs::instance()->getConfig();
493#endif //KAB_EMBEDDED 493#endif //KAB_EMBEDDED
494} 494}
495 495
496KActionCollection *KABCore::actionCollection() const 496KActionCollection *KABCore::actionCollection() const
497{ 497{
498 return mGUIClient->actionCollection(); 498 return mGUIClient->actionCollection();
499} 499}
500 500
501KABC::Field *KABCore::currentSearchField() const 501KABC::Field *KABCore::currentSearchField() const
502{ 502{
503 if (mIncSearchWidget) 503 if (mIncSearchWidget)
504 return mIncSearchWidget->currentField(); 504 return mIncSearchWidget->currentField();
505 else 505 else
506 return 0; 506 return 0;
507} 507}
508 508
509QStringList KABCore::selectedUIDs() const 509QStringList KABCore::selectedUIDs() const
510{ 510{
511 return mViewManager->selectedUids(); 511 return mViewManager->selectedUids();
512} 512}
513 513
514KABC::Resource *KABCore::requestResource( QWidget *parent ) 514KABC::Resource *KABCore::requestResource( QWidget *parent )
515{ 515{
516 QPtrList<KABC::Resource> kabcResources = addressBook()->resources(); 516 QPtrList<KABC::Resource> kabcResources = addressBook()->resources();
517 517
518 QPtrList<KRES::Resource> kresResources; 518 QPtrList<KRES::Resource> kresResources;
519 QPtrListIterator<KABC::Resource> resIt( kabcResources ); 519 QPtrListIterator<KABC::Resource> resIt( kabcResources );
520 KABC::Resource *resource; 520 KABC::Resource *resource;
521 while ( ( resource = resIt.current() ) != 0 ) { 521 while ( ( resource = resIt.current() ) != 0 ) {
522 ++resIt; 522 ++resIt;
523 if ( !resource->readOnly() ) { 523 if ( !resource->readOnly() ) {
524 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 524 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
525 if ( res ) 525 if ( res )
526 kresResources.append( res ); 526 kresResources.append( res );
527 } 527 }
528 } 528 }
529 529
530 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent ); 530 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent );
531 return static_cast<KABC::Resource*>( res ); 531 return static_cast<KABC::Resource*>( res );
532} 532}
533 533
534#ifndef KAB_EMBEDDED 534#ifndef KAB_EMBEDDED
535KAboutData *KABCore::createAboutData() 535KAboutData *KABCore::createAboutData()
536#else //KAB_EMBEDDED 536#else //KAB_EMBEDDED
537void KABCore::createAboutData() 537void KABCore::createAboutData()
538#endif //KAB_EMBEDDED 538#endif //KAB_EMBEDDED
539{ 539{
540#ifndef KAB_EMBEDDED 540#ifndef KAB_EMBEDDED
541 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ), 541 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ),
542 "3.1", I18N_NOOP( "The KDE Address Book" ), 542 "3.1", I18N_NOOP( "The KDE Address Book" ),
543 KAboutData::License_GPL_V2, 543 KAboutData::License_GPL_V2,
544 I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) ); 544 I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) );
545 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" ); 545 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" );
546 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) ); 546 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) );
547 about->addAuthor( "Cornelius Schumacher", 547 about->addAuthor( "Cornelius Schumacher",
548 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ), 548 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ),
549 "schumacher@kde.org" ); 549 "schumacher@kde.org" );
550 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ), 550 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ),
551 "mpilone@slac.com" ); 551 "mpilone@slac.com" );
552 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) ); 552 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) );
553 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) ); 553 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) );
554 about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ), 554 about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ),
555 "michel@klaralvdalens-datakonsult.se" ); 555 "michel@klaralvdalens-datakonsult.se" );
556 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ), 556 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ),
557 "hansen@kde.org" ); 557 "hansen@kde.org" );
558 558
559 return about; 559 return about;
560#endif //KAB_EMBEDDED 560#endif //KAB_EMBEDDED
561 561
562 QString version; 562 QString version;
563#include <../version> 563#include <../version>
564 QMessageBox::about( this, "About KAddressbook/Pi", 564 QMessageBox::about( this, "About KAddressbook/Pi",
565 "KAddressbook/Platform-independent\n" 565 "KAddressbook/Platform-independent\n"
566 "(KA/Pi) " +version + " - " + 566 "(KA/Pi) " +version + " - " +
567#ifdef DESKTOP_VERSION 567#ifdef DESKTOP_VERSION
568 "Desktop Edition\n" 568 "Desktop Edition\n"
569#else 569#else
570 "PDA-Edition\n" 570 "PDA-Edition\n"
571 "for: Zaurus 5500 / 7x0 / 8x0\n" 571 "for: Zaurus 5500 / 7x0 / 8x0\n"
572#endif 572#endif
573 573
574 "(c) 2004 Ulf Schenk\n" 574 "(c) 2004 Ulf Schenk\n"
575 "(c) 2004 Lutz Rogowski\n" 575 "(c) 2004 Lutz Rogowski\n"
576 "(c) 1997-2003, The KDE PIM Team\n" 576 "(c) 1997-2003, The KDE PIM Team\n"
577 "Tobias Koenig Current maintainer\ntokoe@kde.org\n" 577 "Tobias Koenig Current maintainer\ntokoe@kde.org\n"
578 "Don Sanders Original author\n" 578 "Don Sanders Original author\n"
579 "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n" 579 "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n"
580 "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n" 580 "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n"
581 "Greg Stern DCOP interface\n" 581 "Greg Stern DCOP interface\n"
582 "Mark Westcot Contact pinning\n" 582 "Mark Westcot Contact pinning\n"
583 "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n" 583 "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n"
584 "Steffen Hansen LDAP Lookup\nhansen@kde.org\n" 584 "Steffen Hansen LDAP Lookup\nhansen@kde.org\n"
585#ifdef _WIN32_ 585#ifdef _WIN32_
586 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n" 586 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n"
587#endif 587#endif
588 ); 588 );
589} 589}
590 590
591void KABCore::setContactSelected( const QString &uid ) 591void KABCore::setContactSelected( const QString &uid )
592{ 592{
593 KABC::Addressee addr = mAddressBook->findByUid( uid ); 593 KABC::Addressee addr = mAddressBook->findByUid( uid );
594 if ( !mDetails->isHidden() ) 594 if ( !mDetails->isHidden() )
595 mDetails->setAddressee( addr ); 595 mDetails->setAddressee( addr );
596 596
597 if ( !addr.isEmpty() ) { 597 if ( !addr.isEmpty() ) {
598 emit contactSelected( addr.formattedName() ); 598 emit contactSelected( addr.formattedName() );
599 KABC::Picture pic = addr.photo(); 599 KABC::Picture pic = addr.photo();
600 if ( pic.isIntern() ) { 600 if ( pic.isIntern() ) {
601//US emit contactSelected( pic.data() ); 601//US emit contactSelected( pic.data() );
602//US instead use: 602//US instead use:
603 QPixmap px; 603 QPixmap px;
604 if (pic.data().isNull() != true) 604 if (pic.data().isNull() != true)
605 { 605 {
606 px.convertFromImage(pic.data()); 606 px.convertFromImage(pic.data());
607 } 607 }
608 608
609 emit contactSelected( px ); 609 emit contactSelected( px );
610 } 610 }
611 } 611 }
612 612
613 613
614 mExtensionManager->setSelectionChanged(); 614 mExtensionManager->setSelectionChanged();
615 615
616 // update the actions 616 // update the actions
617 bool selected = !uid.isEmpty(); 617 bool selected = !uid.isEmpty();
618 618
619 if ( mReadWrite ) { 619 if ( mReadWrite ) {
620 mActionCut->setEnabled( selected ); 620 mActionCut->setEnabled( selected );
621 mActionPaste->setEnabled( selected ); 621 mActionPaste->setEnabled( selected );
622 } 622 }
623 623
624 mActionCopy->setEnabled( selected ); 624 mActionCopy->setEnabled( selected );
625 mActionDelete->setEnabled( selected ); 625 mActionDelete->setEnabled( selected );
626 mActionEditAddressee->setEnabled( selected ); 626 mActionEditAddressee->setEnabled( selected );
627 mActionMail->setEnabled( selected ); 627 mActionMail->setEnabled( selected );
628 mActionMailVCard->setEnabled( selected ); 628 mActionMailVCard->setEnabled( selected );
629 //if (mActionBeam) 629 //if (mActionBeam)
630 //mActionBeam->setEnabled( selected ); 630 //mActionBeam->setEnabled( selected );
631 631
632 if (mActionBeamVCard) 632 if (mActionBeamVCard)
633 mActionBeamVCard->setEnabled( selected ); 633 mActionBeamVCard->setEnabled( selected );
634 634
635 mActionExport2phone->setEnabled( selected ); 635 mActionExport2phone->setEnabled( selected );
636 mActionWhoAmI->setEnabled( selected ); 636 mActionWhoAmI->setEnabled( selected );
637 mActionCategories->setEnabled( selected ); 637 mActionCategories->setEnabled( selected );
638} 638}
639 639
640void KABCore::sendMail() 640void KABCore::sendMail()
641{ 641{
642 sendMail( mViewManager->selectedEmails().join( ", " ) ); 642 sendMail( mViewManager->selectedEmails().join( ", " ) );
643} 643}
644 644
645void KABCore::sendMail( const QString& emaillist ) 645void KABCore::sendMail( const QString& emaillist )
646{ 646{
647 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... " 647 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... "
648 if (emaillist.contains(",") > 0) 648 if (emaillist.contains(",") > 0)
649 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null ); 649 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null );
650 else 650 else
651 ExternalAppHandler::instance()->mailToOneContact( emaillist ); 651 ExternalAppHandler::instance()->mailToOneContact( emaillist );
652} 652}
653 653
654 654
655 655
656void KABCore::mailVCard() 656void KABCore::mailVCard()
657{ 657{
658 QStringList uids = mViewManager->selectedUids(); 658 QStringList uids = mViewManager->selectedUids();
659 if ( !uids.isEmpty() ) 659 if ( !uids.isEmpty() )
660 mailVCard( uids ); 660 mailVCard( uids );
661} 661}
662 662
663void KABCore::mailVCard( const QStringList& uids ) 663void KABCore::mailVCard( const QStringList& uids )
664{ 664{
665 QStringList urls; 665 QStringList urls;
666 666
667// QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); 667// QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
668 668
669 QString dirName = "/tmp/" + KApplication::randomString( 8 ); 669 QString dirName = "/tmp/" + KApplication::randomString( 8 );
670 670
671 671
672 672
673 QDir().mkdir( dirName, true ); 673 QDir().mkdir( dirName, true );
674 674
675 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 675 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
676 KABC::Addressee a = mAddressBook->findByUid( *it ); 676 KABC::Addressee a = mAddressBook->findByUid( *it );
677 677
678 if ( a.isEmpty() ) 678 if ( a.isEmpty() )
679 continue; 679 continue;
680 680
681 QString name = a.givenName() + "_" + a.familyName() + ".vcf"; 681 QString name = a.givenName() + "_" + a.familyName() + ".vcf";
682 682
683 QString fileName = dirName + "/" + name; 683 QString fileName = dirName + "/" + name;
684 684
685 QFile outFile(fileName); 685 QFile outFile(fileName);
686 686
687 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully 687 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully
688 KABC::VCardConverter converter; 688 KABC::VCardConverter converter;
689 QString vcard; 689 QString vcard;
690 690
691 converter.addresseeToVCard( a, vcard ); 691 converter.addresseeToVCard( a, vcard );
692 692
693 QTextStream t( &outFile ); // use a text stream 693 QTextStream t( &outFile ); // use a text stream
694 t.setEncoding( QTextStream::UnicodeUTF8 ); 694 t.setEncoding( QTextStream::UnicodeUTF8 );
695 t << vcard; 695 t << vcard;
696 696
697 outFile.close(); 697 outFile.close();
698 698
699 urls.append( fileName ); 699 urls.append( fileName );
700 } 700 }
701 } 701 }
702 702
703 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); 703 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") );
704 704
705 705
706/*US 706/*US
707 kapp->invokeMailer( QString::null, QString::null, QString::null, 707 kapp->invokeMailer( QString::null, QString::null, QString::null,
708 QString::null, // subject 708 QString::null, // subject
709 QString::null, // body 709 QString::null, // body
710 QString::null, 710 QString::null,
711 urls ); // attachments 711 urls ); // attachments
712*/ 712*/
713 713
714} 714}
715 715
716/** 716/**
717 Beams the "WhoAmI contact. 717 Beams the "WhoAmI contact.
718*/ 718*/
719void KABCore::beamMySelf() 719void KABCore::beamMySelf()
720{ 720{
721 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); 721 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI();
722 if (!a.isEmpty()) 722 if (!a.isEmpty())
723 { 723 {
724 QStringList uids; 724 QStringList uids;
725 uids << a.uid(); 725 uids << a.uid();
726 726
727 beamVCard(uids); 727 beamVCard(uids);
728 } else { 728 } else {
729 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); 729 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) );
730 730
731 731
732 } 732 }
733} 733}
734 734
735void KABCore::export2phone() 735void KABCore::export2phone()
736{ 736{
737 737
738 KAex2phonePrefs ex2phone; 738 KAex2phonePrefs ex2phone;
739 ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection ); 739 ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection );
740 ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice ); 740 ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice );
741 ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel ); 741 ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel );
742 742
743 if ( !ex2phone.exec() ) { 743 if ( !ex2phone.exec() ) {
744 return; 744 return;
745 } 745 }
746 KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text(); 746 KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text();
747 KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text(); 747 KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text();
748 KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text(); 748 KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text();
749 749
750 750
751 PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice, 751 PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice,
752 KPimGlobalPrefs::instance()->mEx2PhoneConnection, 752 KPimGlobalPrefs::instance()->mEx2PhoneConnection,
753 KPimGlobalPrefs::instance()->mEx2PhoneModel ); 753 KPimGlobalPrefs::instance()->mEx2PhoneModel );
754 754
755 QStringList uids = mViewManager->selectedUids(); 755 QStringList uids = mViewManager->selectedUids();
756 if ( uids.isEmpty() ) 756 if ( uids.isEmpty() )
757 return; 757 return;
758 758
759 QString fileName = getPhoneFile(); 759 QString fileName = getPhoneFile();
760 if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) ) 760 if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) )
761 return; 761 return;
762 762
763 message(i18n("Exporting to phone...")); 763 message(i18n("Exporting to phone..."));
764 QTimer::singleShot( 1, this , SLOT ( writeToPhone())); 764 QTimer::singleShot( 1, this , SLOT ( writeToPhone()));
765 765
766} 766}
767QString KABCore::getPhoneFile() 767QString KABCore::getPhoneFile()
768{ 768{
769#ifdef DESKTOP_VERSION 769#ifdef DESKTOP_VERSION
770 return locateLocal("tmp", "phonefile.vcf"); 770 return locateLocal("tmp", "phonefile.vcf");
771#else 771#else
772 return "/tmp/phonefile.vcf"; 772 return "/tmp/phonefile.vcf";
773#endif 773#endif
774 774
775} 775}
776void KABCore::writeToPhone( ) 776void KABCore::writeToPhone( )
777{ 777{
778 if ( PhoneAccess::writeToPhone( getPhoneFile() ) ) 778 if ( PhoneAccess::writeToPhone( getPhoneFile() ) )
779 message(i18n("Export to phone finished!")); 779 message(i18n("Export to phone finished!"));
780 else 780 else
781 qDebug(i18n("Error exporting to phone")); 781 qDebug(i18n("Error exporting to phone"));
782} 782}
783void KABCore::beamVCard() 783void KABCore::beamVCard()
784{ 784{
785 QStringList uids = mViewManager->selectedUids(); 785 QStringList uids = mViewManager->selectedUids();
786 if ( !uids.isEmpty() ) 786 if ( !uids.isEmpty() )
787 beamVCard( uids ); 787 beamVCard( uids );
788} 788}
789 789
790 790
791void KABCore::beamVCard(const QStringList& uids) 791void KABCore::beamVCard(const QStringList& uids)
792{ 792{
793 793
794 // LR: we should use the /tmp dir on the Zaurus, 794 // LR: we should use the /tmp dir on the Zaurus,
795 // because: /tmp = RAM, (HOME)/kdepim = flash memory 795 // because: /tmp = RAM, (HOME)/kdepim = flash memory
796 796
797#ifdef DESKTOP_VERSION 797#ifdef DESKTOP_VERSION
798 QString fileName = locateLocal("tmp", "kapibeamfile.vcf"); 798 QString fileName = locateLocal("tmp", "kapibeamfile.vcf");
799#else 799#else
800 QString fileName = "/tmp/kapibeamfile.vcf"; 800 QString fileName = "/tmp/kapibeamfile.vcf";
801#endif 801#endif
802 802
803 KABC::VCardConverter converter; 803 KABC::VCardConverter converter;
804 QString description; 804 QString description;
805 QString datastream; 805 QString datastream;
806 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 806 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
807 KABC::Addressee a = mAddressBook->findByUid( *it ); 807 KABC::Addressee a = mAddressBook->findByUid( *it );
808 808
809 if ( a.isEmpty() ) 809 if ( a.isEmpty() )
810 continue; 810 continue;
811 811
812 if (description.isEmpty()) 812 if (description.isEmpty())
813 description = a.formattedName(); 813 description = a.formattedName();
814 814
815 QString vcard; 815 QString vcard;
816 converter.addresseeToVCard( a, vcard ); 816 converter.addresseeToVCard( a, vcard );
817 int start = 0; 817 int start = 0;
818 int next; 818 int next;
819 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 819 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
820 int semi = vcard.find(";", next); 820 int semi = vcard.find(";", next);
821 int dopp = vcard.find(":", next); 821 int dopp = vcard.find(":", next);
822 int sep; 822 int sep;
823 if ( semi < dopp && semi >= 0 ) 823 if ( semi < dopp && semi >= 0 )
824 sep = semi ; 824 sep = semi ;
825 else 825 else
826 sep = dopp; 826 sep = dopp;
827 datastream +=vcard.mid( start, next - start); 827 datastream +=vcard.mid( start, next - start);
828 datastream +=vcard.mid( next+5,sep -next -5 ).upper(); 828 datastream +=vcard.mid( next+5,sep -next -5 ).upper();
829 start = sep; 829 start = sep;
830 } 830 }
831 datastream += vcard.mid( start,vcard.length() ); 831 datastream += vcard.mid( start,vcard.length() );
832 } 832 }
833#ifndef DESKTOP_VERSION 833#ifndef DESKTOP_VERSION
834 QFile outFile(fileName); 834 QFile outFile(fileName);
835 if ( outFile.open(IO_WriteOnly) ) { 835 if ( outFile.open(IO_WriteOnly) ) {
836 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 836 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
837 QTextStream t( &outFile ); // use a text stream 837 QTextStream t( &outFile ); // use a text stream
838 //t.setEncoding( QTextStream::UnicodeUTF8 ); 838 //t.setEncoding( QTextStream::UnicodeUTF8 );
839 t.setEncoding( QTextStream::Latin1 ); 839 t.setEncoding( QTextStream::Latin1 );
840 t <<datastream.latin1(); 840 t <<datastream.latin1();
841 outFile.close(); 841 outFile.close();
842 Ir *ir = new Ir( this ); 842 Ir *ir = new Ir( this );
843 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); 843 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) );
844 ir->send( fileName, description, "text/x-vCard" ); 844 ir->send( fileName, description, "text/x-vCard" );
845 } else { 845 } else {
846 qDebug("Error open temp beam file "); 846 qDebug("Error open temp beam file ");
847 return; 847 return;
848 } 848 }
849#endif 849#endif
850 850
851} 851}
852 852
853void KABCore::beamDone( Ir *ir ) 853void KABCore::beamDone( Ir *ir )
854{ 854{
855#ifndef DESKTOP_VERSION 855#ifndef DESKTOP_VERSION
856 delete ir; 856 delete ir;
857#endif 857#endif
858 topLevelWidget()->raise(); 858 topLevelWidget()->raise();
859 message( i18n("Beaming finished!") ); 859 message( i18n("Beaming finished!") );
860} 860}
861 861
862 862
863void KABCore::browse( const QString& url ) 863void KABCore::browse( const QString& url )
864{ 864{
865#ifndef KAB_EMBEDDED 865#ifndef KAB_EMBEDDED
866 kapp->invokeBrowser( url ); 866 kapp->invokeBrowser( url );
867#else //KAB_EMBEDDED 867#else //KAB_EMBEDDED
868 qDebug("KABCore::browse must be fixed"); 868 qDebug("KABCore::browse must be fixed");
869#endif //KAB_EMBEDDED 869#endif //KAB_EMBEDDED
870} 870}
871 871
872void KABCore::selectAllContacts() 872void KABCore::selectAllContacts()
873{ 873{
874 mViewManager->setSelected( QString::null, true ); 874 mViewManager->setSelected( QString::null, true );
875} 875}
876 876
877void KABCore::deleteContacts() 877void KABCore::deleteContacts()
878{ 878{
879 QStringList uidList = mViewManager->selectedUids(); 879 QStringList uidList = mViewManager->selectedUids();
880 deleteContacts( uidList ); 880 deleteContacts( uidList );
881} 881}
882 882
883void KABCore::deleteContacts( const QStringList &uids ) 883void KABCore::deleteContacts( const QStringList &uids )
884{ 884{
885 if ( uids.count() > 0 ) { 885 if ( uids.count() > 0 ) {
886 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); 886 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids );
887 UndoStack::instance()->push( command ); 887 UndoStack::instance()->push( command );
888 RedoStack::instance()->clear(); 888 RedoStack::instance()->clear();
889 889
890 // now if we deleted anything, refresh 890 // now if we deleted anything, refresh
891 setContactSelected( QString::null ); 891 setContactSelected( QString::null );
892 setModified( true ); 892 setModified( true );
893 } 893 }
894} 894}
895 895
896void KABCore::copyContacts() 896void KABCore::copyContacts()
897{ 897{
898 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 898 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
899 899
900 QString clipText = AddresseeUtil::addresseesToClipboard( addrList ); 900 QString clipText = AddresseeUtil::addresseesToClipboard( addrList );
901 901
902 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl; 902 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl;
903 903
904 QClipboard *cb = QApplication::clipboard(); 904 QClipboard *cb = QApplication::clipboard();
905 cb->setText( clipText ); 905 cb->setText( clipText );
906} 906}
907 907
908void KABCore::cutContacts() 908void KABCore::cutContacts()
909{ 909{
910 QStringList uidList = mViewManager->selectedUids(); 910 QStringList uidList = mViewManager->selectedUids();
911 911
912//US if ( uidList.size() > 0 ) { 912//US if ( uidList.size() > 0 ) {
913 if ( uidList.count() > 0 ) { 913 if ( uidList.count() > 0 ) {
914 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); 914 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList );
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}
921 921
922void KABCore::pasteContacts() 922void KABCore::pasteContacts()
923{ 923{
924 QClipboard *cb = QApplication::clipboard(); 924 QClipboard *cb = QApplication::clipboard();
925 925
926 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); 926 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() );
927 927
928 pasteContacts( list ); 928 pasteContacts( list );
929} 929}
930 930
931void KABCore::pasteContacts( KABC::Addressee::List &list ) 931void KABCore::pasteContacts( KABC::Addressee::List &list )
932{ 932{
933 KABC::Resource *resource = requestResource( this ); 933 KABC::Resource *resource = requestResource( this );
934 KABC::Addressee::List::Iterator it; 934 KABC::Addressee::List::Iterator it;
935 for ( it = list.begin(); it != list.end(); ++it ) 935 for ( it = list.begin(); it != list.end(); ++it )
936 (*it).setResource( resource ); 936 (*it).setResource( resource );
937 937
938 PwPasteCommand *command = new PwPasteCommand( this, list ); 938 PwPasteCommand *command = new PwPasteCommand( this, list );
939 UndoStack::instance()->push( command ); 939 UndoStack::instance()->push( command );
940 RedoStack::instance()->clear(); 940 RedoStack::instance()->clear();
941 941
942 setModified( true ); 942 setModified( true );
943} 943}
944 944
945void KABCore::setWhoAmI() 945void KABCore::setWhoAmI()
946{ 946{
947 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 947 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
948 948
949 if ( addrList.count() > 1 ) { 949 if ( addrList.count() > 1 ) {
950 KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); 950 KMessageBox::sorry( this, i18n( "Please select only one contact." ) );
951 return; 951 return;
952 } 952 }
953 953
954 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); 954 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) );
955 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) 955 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes )
956 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); 956 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] );
957} 957}
958 958
959void KABCore::setCategories() 959void KABCore::setCategories()
960{ 960{
961 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); 961 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true );
962 if ( !dlg.exec() ) 962 if ( !dlg.exec() )
963 return; 963 return;
964 964
965 bool merge = false; 965 bool merge = false;
966 QString msg = i18n( "Merge with existing categories?" ); 966 QString msg = i18n( "Merge with existing categories?" );
967 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) 967 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes )
968 merge = true; 968 merge = true;
969 969
970 QStringList categories = dlg.selectedCategories(); 970 QStringList categories = dlg.selectedCategories();
971 971
972 QStringList uids = mViewManager->selectedUids(); 972 QStringList uids = mViewManager->selectedUids();
973 QStringList::Iterator it; 973 QStringList::Iterator it;
974 for ( it = uids.begin(); it != uids.end(); ++it ) { 974 for ( it = uids.begin(); it != uids.end(); ++it ) {
975 KABC::Addressee addr = mAddressBook->findByUid( *it ); 975 KABC::Addressee addr = mAddressBook->findByUid( *it );
976 if ( !addr.isEmpty() ) { 976 if ( !addr.isEmpty() ) {
977 if ( !merge ) 977 if ( !merge )
978 addr.setCategories( categories ); 978 addr.setCategories( categories );
979 else { 979 else {
980 QStringList addrCategories = addr.categories(); 980 QStringList addrCategories = addr.categories();
981 QStringList::Iterator catIt; 981 QStringList::Iterator catIt;
982 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { 982 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
983 if ( !addrCategories.contains( *catIt ) ) 983 if ( !addrCategories.contains( *catIt ) )
984 addrCategories.append( *catIt ); 984 addrCategories.append( *catIt );
985 } 985 }
986 addr.setCategories( addrCategories ); 986 addr.setCategories( addrCategories );
987 } 987 }
988 988
989 mAddressBook->insertAddressee( addr ); 989 mAddressBook->insertAddressee( addr );
990 } 990 }
991 } 991 }
992 992
993 if ( uids.count() > 0 ) 993 if ( uids.count() > 0 )
994 setModified( true ); 994 setModified( true );
995} 995}
996 996
997void KABCore::setSearchFields( const KABC::Field::List &fields ) 997void KABCore::setSearchFields( const KABC::Field::List &fields )
998{ 998{
999 mIncSearchWidget->setFields( fields ); 999 mIncSearchWidget->setFields( fields );
1000} 1000}
1001 1001
1002void KABCore::incrementalSearch( const QString& text ) 1002void KABCore::incrementalSearch( const QString& text )
1003{ 1003{
1004 mViewManager->doSearch( text, mIncSearchWidget->currentField() ); 1004 mViewManager->doSearch( text, mIncSearchWidget->currentField() );
1005} 1005}
1006 1006
1007void KABCore::setModified() 1007void KABCore::setModified()
1008{ 1008{
1009 setModified( true ); 1009 setModified( true );
1010} 1010}
1011 1011
1012void KABCore::setModifiedWOrefresh() 1012void KABCore::setModifiedWOrefresh()
1013{ 1013{
1014 // qDebug("KABCore::setModifiedWOrefresh() "); 1014 // qDebug("KABCore::setModifiedWOrefresh() ");
1015 mModified = true; 1015 mModified = true;
1016 mActionSave->setEnabled( mModified ); 1016 mActionSave->setEnabled( mModified );
1017#ifdef DESKTOP_VERSION 1017#ifdef DESKTOP_VERSION
1018 mDetails->refreshView(); 1018 mDetails->refreshView();
1019#endif 1019#endif
1020 1020
1021} 1021}
1022void KABCore::setModified( bool modified ) 1022void KABCore::setModified( bool modified )
1023{ 1023{
1024 mModified = modified; 1024 mModified = modified;
1025 mActionSave->setEnabled( mModified ); 1025 mActionSave->setEnabled( mModified );
1026 1026
1027 if ( modified ) 1027 if ( modified )
1028 mJumpButtonBar->recreateButtons(); 1028 mJumpButtonBar->recreateButtons();
1029 1029
1030 mViewManager->refreshView(); 1030 mViewManager->refreshView();
1031 mDetails->refreshView(); 1031 mDetails->refreshView();
1032 1032
1033} 1033}
1034 1034
1035bool KABCore::modified() const 1035bool KABCore::modified() const
1036{ 1036{
1037 return mModified; 1037 return mModified;
1038} 1038}
1039 1039
1040void KABCore::contactModified( const KABC::Addressee &addr ) 1040void KABCore::contactModified( const KABC::Addressee &addr )
1041{ 1041{
1042 1042
1043 Command *command = 0; 1043 Command *command = 0;
1044 QString uid; 1044 QString uid;
1045 1045
1046 // check if it exists already 1046 // check if it exists already
1047 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); 1047 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() );
1048 if ( origAddr.isEmpty() ) 1048 if ( origAddr.isEmpty() )
1049 command = new PwNewCommand( mAddressBook, addr ); 1049 command = new PwNewCommand( mAddressBook, addr );
1050 else { 1050 else {
1051 command = new PwEditCommand( mAddressBook, origAddr, addr ); 1051 command = new PwEditCommand( mAddressBook, origAddr, addr );
1052 uid = addr.uid(); 1052 uid = addr.uid();
1053 } 1053 }
1054 1054
1055 UndoStack::instance()->push( command ); 1055 UndoStack::instance()->push( command );
1056 RedoStack::instance()->clear(); 1056 RedoStack::instance()->clear();
1057 1057
1058 setModified( true ); 1058 setModified( true );
1059} 1059}
1060 1060
1061void KABCore::newContact() 1061void KABCore::newContact()
1062{ 1062{
1063 1063
1064 1064
1065 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); 1065 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources();
1066 1066
1067 QPtrList<KRES::Resource> kresResources; 1067 QPtrList<KRES::Resource> kresResources;
1068 QPtrListIterator<KABC::Resource> it( kabcResources ); 1068 QPtrListIterator<KABC::Resource> it( kabcResources );
1069 KABC::Resource *resource; 1069 KABC::Resource *resource;
1070 while ( ( resource = it.current() ) != 0 ) { 1070 while ( ( resource = it.current() ) != 0 ) {
1071 ++it; 1071 ++it;
1072 if ( !resource->readOnly() ) { 1072 if ( !resource->readOnly() ) {
1073 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 1073 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
1074 if ( res ) 1074 if ( res )
1075 kresResources.append( res ); 1075 kresResources.append( res );
1076 } 1076 }
1077 } 1077 }
1078 1078
1079 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); 1079 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this );
1080 resource = static_cast<KABC::Resource*>( res ); 1080 resource = static_cast<KABC::Resource*>( res );
1081 1081
1082 if ( resource ) { 1082 if ( resource ) {
1083 KABC::Addressee addr; 1083 KABC::Addressee addr;
1084 addr.setResource( resource ); 1084 addr.setResource( resource );
1085 mEditorDialog->setAddressee( addr ); 1085 mEditorDialog->setAddressee( addr );
1086 KApplication::execDialog ( mEditorDialog ); 1086 KApplication::execDialog ( mEditorDialog );
1087 1087
1088 } else 1088 } else
1089 return; 1089 return;
1090 1090
1091 // mEditorDict.insert( dialog->addressee().uid(), dialog ); 1091 // mEditorDict.insert( dialog->addressee().uid(), dialog );
1092 1092
1093 1093
1094} 1094}
1095 1095
1096void KABCore::addEmail( QString aStr ) 1096void KABCore::addEmail( QString aStr )
1097{ 1097{
1098#ifndef KAB_EMBEDDED 1098#ifndef KAB_EMBEDDED
1099 QString fullName, email; 1099 QString fullName, email;
1100 1100
1101 KABC::Addressee::parseEmailAddress( aStr, fullName, email ); 1101 KABC::Addressee::parseEmailAddress( aStr, fullName, email );
1102 1102
1103 // Try to lookup the addressee matching the email address 1103 // Try to lookup the addressee matching the email address
1104 bool found = false; 1104 bool found = false;
1105 QStringList emailList; 1105 QStringList emailList;
1106 KABC::AddressBook::Iterator it; 1106 KABC::AddressBook::Iterator it;
1107 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { 1107 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) {
1108 emailList = (*it).emails(); 1108 emailList = (*it).emails();
1109 if ( emailList.contains( email ) > 0 ) { 1109 if ( emailList.contains( email ) > 0 ) {
1110 found = true; 1110 found = true;
1111 (*it).setNameFromString( fullName ); 1111 (*it).setNameFromString( fullName );
1112 editContact( (*it).uid() ); 1112 editContact( (*it).uid() );
1113 } 1113 }
1114 } 1114 }
1115 1115
1116 if ( !found ) { 1116 if ( !found ) {
1117 KABC::Addressee addr; 1117 KABC::Addressee addr;
1118 addr.setNameFromString( fullName ); 1118 addr.setNameFromString( fullName );
1119 addr.insertEmail( email, true ); 1119 addr.insertEmail( email, true );
1120 1120
1121 mAddressBook->insertAddressee( addr ); 1121 mAddressBook->insertAddressee( addr );
1122 mViewManager->refreshView( addr.uid() ); 1122 mViewManager->refreshView( addr.uid() );
1123 editContact( addr.uid() ); 1123 editContact( addr.uid() );
1124 } 1124 }
1125#else //KAB_EMBEDDED 1125#else //KAB_EMBEDDED
1126 qDebug("KABCore::addEmail finsih method"); 1126 qDebug("KABCore::addEmail finsih method");
1127#endif //KAB_EMBEDDED 1127#endif //KAB_EMBEDDED
1128} 1128}
1129 1129
1130void KABCore::importVCard( const KURL &url, bool showPreview ) 1130void KABCore::importVCard( const KURL &url, bool showPreview )
1131{ 1131{
1132 mXXPortManager->importVCard( url, showPreview ); 1132 mXXPortManager->importVCard( url, showPreview );
1133} 1133}
1134void KABCore::importFromOL() 1134void KABCore::importFromOL()
1135{ 1135{
1136#ifdef _WIN32_ 1136#ifdef _WIN32_
1137 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); 1137 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this );
1138 idgl->exec(); 1138 idgl->exec();
1139 KABC::Addressee::List list = idgl->getAddressList(); 1139 KABC::Addressee::List list = idgl->getAddressList();
1140 if ( list.count() > 0 ) { 1140 if ( list.count() > 0 ) {
1141 KABC::Addressee::List listNew; 1141 KABC::Addressee::List listNew;
1142 KABC::Addressee::List listExisting; 1142 KABC::Addressee::List listExisting;
1143 KABC::Addressee::List::Iterator it; 1143 KABC::Addressee::List::Iterator it;
1144 KABC::AddressBook::Iterator iter; 1144 KABC::AddressBook::Iterator iter;
1145 for ( it = list.begin(); it != list.end(); ++it ) { 1145 for ( it = list.begin(); it != list.end(); ++it ) {
1146 if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) 1146 if ( mAddressBook->findByUid((*it).uid() ).isEmpty())
1147 listNew.append( (*it) ); 1147 listNew.append( (*it) );
1148 else 1148 else
1149 listExisting.append( (*it) ); 1149 listExisting.append( (*it) );
1150 } 1150 }
1151 if ( listExisting.count() > 0 ) 1151 if ( listExisting.count() > 0 )
1152 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); 1152 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() ));
1153 if ( listNew.count() > 0 ) { 1153 if ( listNew.count() > 0 ) {
1154 pasteWithNewUid = false; 1154 pasteWithNewUid = false;
1155 pasteContacts( listNew ); 1155 pasteContacts( listNew );
1156 pasteWithNewUid = true; 1156 pasteWithNewUid = true;
1157 } 1157 }
1158 } 1158 }
1159 delete idgl; 1159 delete idgl;
1160#endif 1160#endif
1161} 1161}
1162 1162
1163void KABCore::importVCard( const QString &vCard, bool showPreview ) 1163void KABCore::importVCard( const QString &vCard, bool showPreview )
1164{ 1164{
1165 mXXPortManager->importVCard( vCard, showPreview ); 1165 mXXPortManager->importVCard( vCard, showPreview );
1166} 1166}
1167 1167
1168//US added a second method without defaultparameter 1168//US added a second method without defaultparameter
1169void KABCore::editContact2() { 1169void KABCore::editContact2() {
1170 editContact( QString::null ); 1170 editContact( QString::null );
1171} 1171}
1172 1172
1173void KABCore::editContact( const QString &uid ) 1173void KABCore::editContact( const QString &uid )
1174{ 1174{
1175 1175
1176 if ( mExtensionManager->isQuickEditVisible() ) 1176 if ( mExtensionManager->isQuickEditVisible() )
1177 return; 1177 return;
1178 1178
1179 // First, locate the contact entry 1179 // First, locate the contact entry
1180 QString localUID = uid; 1180 QString localUID = uid;
1181 if ( localUID.isNull() ) { 1181 if ( localUID.isNull() ) {
1182 QStringList uidList = mViewManager->selectedUids(); 1182 QStringList uidList = mViewManager->selectedUids();
1183 if ( uidList.count() > 0 ) 1183 if ( uidList.count() > 0 )
1184 localUID = *( uidList.at( 0 ) ); 1184 localUID = *( uidList.at( 0 ) );
1185 } 1185 }
1186 1186
1187 KABC::Addressee addr = mAddressBook->findByUid( localUID ); 1187 KABC::Addressee addr = mAddressBook->findByUid( localUID );
1188 if ( !addr.isEmpty() ) { 1188 if ( !addr.isEmpty() ) {
1189 mEditorDialog->setAddressee( addr ); 1189 mEditorDialog->setAddressee( addr );
1190 KApplication::execDialog ( mEditorDialog ); 1190 KApplication::execDialog ( mEditorDialog );
1191 } 1191 }
1192} 1192}
1193 1193
1194/** 1194/**
1195 Shows or edits the detail view for the given uid. If the uid is QString::null, 1195 Shows or edits the detail view for the given uid. If the uid is QString::null,
1196 the method will try to find a selected addressee in the view. 1196 the method will try to find a selected addressee in the view.
1197 */ 1197 */
1198void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) 1198void KABCore::executeContact( const QString &uid /*US = QString::null*/ )
1199{ 1199{
1200 if ( mMultipleViewsAtOnce ) 1200 if ( mMultipleViewsAtOnce )
1201 { 1201 {
1202 editContact( uid ); 1202 editContact( uid );
1203 } 1203 }
1204 else 1204 else
1205 { 1205 {
1206 setDetailsVisible( true ); 1206 setDetailsVisible( true );
1207 mActionDetails->setChecked(true); 1207 mActionDetails->setChecked(true);
1208 } 1208 }
1209 1209
1210} 1210}
1211 1211
1212void KABCore::save() 1212void KABCore::save()
1213{ 1213{
1214 if (syncManager->blockSave()) 1214 if (syncManager->blockSave())
1215 return; 1215 return;
1216 if ( !mModified ) 1216 if ( !mModified )
1217 return; 1217 return;
1218 1218
1219 syncManager->setBlockSave(true); 1219 syncManager->setBlockSave(true);
1220 QString text = i18n( "There was an error while attempting to save\n the " 1220 QString text = i18n( "There was an error while attempting to save\n the "
1221 "address book. Please check that some \nother application is " 1221 "address book. Please check that some \nother application is "
1222 "not using it. " ); 1222 "not using it. " );
1223 message(i18n("Saving addressbook ... ")); 1223 message(i18n("Saving addressbook ... "));
1224#ifndef KAB_EMBEDDED 1224#ifndef KAB_EMBEDDED
1225 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); 1225 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
1226 if ( !b || !b->save() ) { 1226 if ( !b || !b->save() ) {
1227 KMessageBox::error( this, text, i18n( "Unable to Save" ) ); 1227 KMessageBox::error( this, text, i18n( "Unable to Save" ) );
1228 } 1228 }
1229#else //KAB_EMBEDDED 1229#else //KAB_EMBEDDED
1230 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); 1230 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook );
1231 if ( !b || !b->save() ) { 1231 if ( !b || !b->save() ) {
1232 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); 1232 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok"));
1233 } 1233 }
1234#endif //KAB_EMBEDDED 1234#endif //KAB_EMBEDDED
1235 1235
1236 message(i18n("Addressbook saved!")); 1236 message(i18n("Addressbook saved!"));
1237 setModified( false ); 1237 setModified( false );
1238 syncManager->setBlockSave(false); 1238 syncManager->setBlockSave(false);
1239} 1239}
1240 1240
1241 1241
1242void KABCore::undo() 1242void KABCore::undo()
1243{ 1243{
1244 UndoStack::instance()->undo(); 1244 UndoStack::instance()->undo();
1245 1245
1246 // Refresh the view 1246 // Refresh the view
1247 mViewManager->refreshView(); 1247 mViewManager->refreshView();
1248} 1248}
1249 1249
1250void KABCore::redo() 1250void KABCore::redo()
1251{ 1251{
1252 RedoStack::instance()->redo(); 1252 RedoStack::instance()->redo();
1253 1253
1254 // Refresh the view 1254 // Refresh the view
1255 mViewManager->refreshView(); 1255 mViewManager->refreshView();
1256} 1256}
1257 1257
1258void KABCore::setJumpButtonBarVisible( bool visible ) 1258void KABCore::setJumpButtonBarVisible( bool visible )
1259{ 1259{
1260 if (mMultipleViewsAtOnce) 1260 if (mMultipleViewsAtOnce)
1261 { 1261 {
1262 if ( visible ) 1262 if ( visible )
1263 mJumpButtonBar->show(); 1263 mJumpButtonBar->show();
1264 else 1264 else
1265 mJumpButtonBar->hide(); 1265 mJumpButtonBar->hide();
1266 } 1266 }
1267 else 1267 else
1268 { 1268 {
1269 // show the jumpbar only if "the details are hidden" == "viewmanager are shown" 1269 // show the jumpbar only if "the details are hidden" == "viewmanager are shown"
1270 if (mViewManager->isVisible()) 1270 if (mViewManager->isVisible())
1271 { 1271 {
1272 if ( visible ) 1272 if ( visible )
1273 mJumpButtonBar->show(); 1273 mJumpButtonBar->show();
1274 else 1274 else
1275 mJumpButtonBar->hide(); 1275 mJumpButtonBar->hide();
1276 } 1276 }
1277 else 1277 else
1278 { 1278 {
1279 mJumpButtonBar->hide(); 1279 mJumpButtonBar->hide();
1280 } 1280 }
1281 } 1281 }
1282} 1282}
1283 1283
1284 1284
1285void KABCore::setDetailsToState() 1285void KABCore::setDetailsToState()
1286{ 1286{
1287 setDetailsVisible( mActionDetails->isChecked() ); 1287 setDetailsVisible( mActionDetails->isChecked() );
1288} 1288}
1289 1289
1290 1290
1291 1291
1292void KABCore::setDetailsVisible( bool visible ) 1292void KABCore::setDetailsVisible( bool visible )
1293{ 1293{
1294 if (visible && mDetails->isHidden()) 1294 if (visible && mDetails->isHidden())
1295 { 1295 {
1296 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 1296 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
1297 if ( addrList.count() > 0 ) 1297 if ( addrList.count() > 0 )
1298 mDetails->setAddressee( addrList[ 0 ] ); 1298 mDetails->setAddressee( addrList[ 0 ] );
1299 } 1299 }
1300 1300
1301 // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between 1301 // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between
1302 // the listview and the detailview. We do that by changing the splitbar size. 1302 // the listview and the detailview. We do that by changing the splitbar size.
1303 if (mMultipleViewsAtOnce) 1303 if (mMultipleViewsAtOnce)
1304 { 1304 {
1305 if ( visible ) 1305 if ( visible )
1306 mDetails->show(); 1306 mDetails->show();
1307 else 1307 else
1308 mDetails->hide(); 1308 mDetails->hide();
1309 } 1309 }
1310 else 1310 else
1311 { 1311 {
1312 if ( visible ) { 1312 if ( visible ) {
1313 mViewManager->hide(); 1313 mViewManager->hide();
1314 mDetails->show(); 1314 mDetails->show();
1315 } 1315 }
1316 else { 1316 else {
1317 mViewManager->show(); 1317 mViewManager->show();
1318 mDetails->hide(); 1318 mDetails->hide();
1319 } 1319 }
1320 setJumpButtonBarVisible( !visible ); 1320 setJumpButtonBarVisible( !visible );
1321 } 1321 }
1322 1322
1323} 1323}
1324 1324
1325void KABCore::extensionChanged( int id ) 1325void KABCore::extensionChanged( int id )
1326{ 1326{
1327 //change the details view only for non desktop systems 1327 //change the details view only for non desktop systems
1328#ifndef DESKTOP_VERSION 1328#ifndef DESKTOP_VERSION
1329 1329
1330 if (id == 0) 1330 if (id == 0)
1331 { 1331 {
1332 //the user disabled the extension. 1332 //the user disabled the extension.
1333 1333
1334 if (mMultipleViewsAtOnce) 1334 if (mMultipleViewsAtOnce)
1335 { // enable detailsview again 1335 { // enable detailsview again
1336 setDetailsVisible( true ); 1336 setDetailsVisible( true );
1337 mActionDetails->setChecked( true ); 1337 mActionDetails->setChecked( true );
1338 } 1338 }
1339 else 1339 else
1340 { //go back to the listview 1340 { //go back to the listview
1341 setDetailsVisible( false ); 1341 setDetailsVisible( false );
1342 mActionDetails->setChecked( false ); 1342 mActionDetails->setChecked( false );
1343 mActionDetails->setEnabled(true); 1343 mActionDetails->setEnabled(true);
1344 } 1344 }
1345 1345
1346 } 1346 }
1347 else 1347 else
1348 { 1348 {
1349 //the user enabled the extension. 1349 //the user enabled the extension.
1350 setDetailsVisible( false ); 1350 setDetailsVisible( false );
1351 mActionDetails->setChecked( false ); 1351 mActionDetails->setChecked( false );
1352 1352
1353 if (!mMultipleViewsAtOnce) 1353 if (!mMultipleViewsAtOnce)
1354 { 1354 {
1355 mActionDetails->setEnabled(false); 1355 mActionDetails->setEnabled(false);
1356 } 1356 }
1357 1357
1358 mExtensionManager->setSelectionChanged(); 1358 mExtensionManager->setSelectionChanged();
1359 1359
1360 } 1360 }
1361 1361
1362#endif// DESKTOP_VERSION 1362#endif// DESKTOP_VERSION
1363 1363
1364} 1364}
1365 1365
1366 1366
1367void KABCore::extensionModified( const KABC::Addressee::List &list ) 1367void KABCore::extensionModified( const KABC::Addressee::List &list )
1368{ 1368{
1369 1369
1370 if ( list.count() != 0 ) { 1370 if ( list.count() != 0 ) {
1371 KABC::Addressee::List::ConstIterator it; 1371 KABC::Addressee::List::ConstIterator it;
1372 for ( it = list.begin(); it != list.end(); ++it ) 1372 for ( it = list.begin(); it != list.end(); ++it )
1373 mAddressBook->insertAddressee( *it ); 1373 mAddressBook->insertAddressee( *it );
1374 if ( list.count() > 1 ) 1374 if ( list.count() > 1 )
1375 setModified(); 1375 setModified();
1376 else 1376 else
1377 setModifiedWOrefresh(); 1377 setModifiedWOrefresh();
1378 } 1378 }
1379 if ( list.count() == 0 ) 1379 if ( list.count() == 0 )
1380 mViewManager->refreshView(); 1380 mViewManager->refreshView();
1381 else 1381 else
1382 mViewManager->refreshView( list[ 0 ].uid() ); 1382 mViewManager->refreshView( list[ 0 ].uid() );
1383 1383
1384 1384
1385 1385
1386} 1386}
1387 1387
1388QString KABCore::getNameByPhone( const QString &phone ) 1388QString KABCore::getNameByPhone( const QString &phone )
1389{ 1389{
1390#ifndef KAB_EMBEDDED 1390#ifndef KAB_EMBEDDED
1391 QRegExp r( "[/*/-/ ]" ); 1391 QRegExp r( "[/*/-/ ]" );
1392 QString localPhone( phone ); 1392 QString localPhone( phone );
1393 1393
1394 bool found = false; 1394 bool found = false;
1395 QString ownerName = ""; 1395 QString ownerName = "";
1396 KABC::AddressBook::Iterator iter; 1396 KABC::AddressBook::Iterator iter;
1397 KABC::PhoneNumber::List::Iterator phoneIter; 1397 KABC::PhoneNumber::List::Iterator phoneIter;
1398 KABC::PhoneNumber::List phoneList; 1398 KABC::PhoneNumber::List phoneList;
1399 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { 1399 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) {
1400 phoneList = (*iter).phoneNumbers(); 1400 phoneList = (*iter).phoneNumbers();
1401 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); 1401 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() );
1402 ++phoneIter) { 1402 ++phoneIter) {
1403 // Get rid of separator chars so just the numbers are compared. 1403 // Get rid of separator chars so just the numbers are compared.
1404 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { 1404 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) {
1405 ownerName = (*iter).formattedName(); 1405 ownerName = (*iter).formattedName();
1406 found = true; 1406 found = true;
1407 } 1407 }
1408 } 1408 }
1409 } 1409 }
1410 1410
1411 return ownerName; 1411 return ownerName;
1412#else //KAB_EMBEDDED 1412#else //KAB_EMBEDDED
1413 qDebug("KABCore::getNameByPhone finsih method"); 1413 qDebug("KABCore::getNameByPhone finsih method");
1414 return ""; 1414 return "";
1415#endif //KAB_EMBEDDED 1415#endif //KAB_EMBEDDED
1416 1416
1417} 1417}
1418 1418
1419void KABCore::openConfigDialog() 1419void KABCore::openConfigDialog()
1420{ 1420{
1421 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); 1421 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true );
1422 KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); 1422 KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" );
1423 ConfigureDialog->addModule(kabcfg ); 1423 ConfigureDialog->addModule(kabcfg );
1424 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); 1424 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" );
1425 ConfigureDialog->addModule(kdelibcfg ); 1425 ConfigureDialog->addModule(kdelibcfg );
1426 1426
1427 connect( ConfigureDialog, SIGNAL( applyClicked() ), 1427 connect( ConfigureDialog, SIGNAL( applyClicked() ),
1428 this, SLOT( configurationChanged() ) ); 1428 this, SLOT( configurationChanged() ) );
1429 connect( ConfigureDialog, SIGNAL( okClicked() ), 1429 connect( ConfigureDialog, SIGNAL( okClicked() ),
1430 this, SLOT( configurationChanged() ) ); 1430 this, SLOT( configurationChanged() ) );
1431 saveSettings(); 1431 saveSettings();
1432#ifndef DESKTOP_VERSION 1432#ifndef DESKTOP_VERSION
1433 ConfigureDialog->showMaximized(); 1433 ConfigureDialog->showMaximized();
1434#endif 1434#endif
1435 if ( ConfigureDialog->exec() ) 1435 if ( ConfigureDialog->exec() )
1436 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); 1436 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") );
1437 delete ConfigureDialog; 1437 delete ConfigureDialog;
1438} 1438}
1439 1439
1440void KABCore::openLDAPDialog() 1440void KABCore::openLDAPDialog()
1441{ 1441{
1442#ifndef KAB_EMBEDDED 1442#ifndef KAB_EMBEDDED
1443 if ( !mLdapSearchDialog ) { 1443 if ( !mLdapSearchDialog ) {
1444 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); 1444 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this );
1445 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, 1445 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager,
1446 SLOT( refreshView() ) ); 1446 SLOT( refreshView() ) );
1447 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, 1447 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this,
1448 SLOT( setModified() ) ); 1448 SLOT( setModified() ) );
1449 } else 1449 } else
1450 mLdapSearchDialog->restoreSettings(); 1450 mLdapSearchDialog->restoreSettings();
1451 1451
1452 if ( mLdapSearchDialog->isOK() ) 1452 if ( mLdapSearchDialog->isOK() )
1453 mLdapSearchDialog->exec(); 1453 mLdapSearchDialog->exec();
1454#else //KAB_EMBEDDED 1454#else //KAB_EMBEDDED
1455 qDebug("KABCore::openLDAPDialog() finsih method"); 1455 qDebug("KABCore::openLDAPDialog() finsih method");
1456#endif //KAB_EMBEDDED 1456#endif //KAB_EMBEDDED
1457} 1457}
1458 1458
1459void KABCore::print() 1459void KABCore::print()
1460{ 1460{
1461#ifndef KAB_EMBEDDED 1461#ifndef KAB_EMBEDDED
1462 KPrinter printer; 1462 KPrinter printer;
1463 if ( !printer.setup( this ) ) 1463 if ( !printer.setup( this ) )
1464 return; 1464 return;
1465 1465
1466 KABPrinting::PrintingWizard wizard( &printer, mAddressBook, 1466 KABPrinting::PrintingWizard wizard( &printer, mAddressBook,
1467 mViewManager->selectedUids(), this ); 1467 mViewManager->selectedUids(), this );
1468 1468
1469 wizard.exec(); 1469 wizard.exec();
1470#else //KAB_EMBEDDED 1470#else //KAB_EMBEDDED
1471 qDebug("KABCore::print() finsih method"); 1471 qDebug("KABCore::print() finsih method");
1472#endif //KAB_EMBEDDED 1472#endif //KAB_EMBEDDED
1473 1473
1474} 1474}
1475 1475
1476 1476
1477void KABCore::addGUIClient( KXMLGUIClient *client ) 1477void KABCore::addGUIClient( KXMLGUIClient *client )
1478{ 1478{
1479 if ( mGUIClient ) 1479 if ( mGUIClient )
1480 mGUIClient->insertChildClient( client ); 1480 mGUIClient->insertChildClient( client );
1481 else 1481 else
1482 KMessageBox::error( this, "no KXMLGUICLient"); 1482 KMessageBox::error( this, "no KXMLGUICLient");
1483} 1483}
1484 1484
1485 1485
1486void KABCore::configurationChanged() 1486void KABCore::configurationChanged()
1487{ 1487{
1488 mExtensionManager->reconfigure(); 1488 mExtensionManager->reconfigure();
1489} 1489}
1490 1490
1491void KABCore::addressBookChanged() 1491void KABCore::addressBookChanged()
1492{ 1492{
1493/*US 1493/*US
1494 QDictIterator<AddresseeEditorDialog> it( mEditorDict ); 1494 QDictIterator<AddresseeEditorDialog> it( mEditorDict );
1495 while ( it.current() ) { 1495 while ( it.current() ) {
1496 if ( it.current()->dirty() ) { 1496 if ( it.current()->dirty() ) {
1497 QString text = i18n( "Data has been changed externally. Unsaved " 1497 QString text = i18n( "Data has been changed externally. Unsaved "
1498 "changes will be lost." ); 1498 "changes will be lost." );
1499 KMessageBox::information( this, text ); 1499 KMessageBox::information( this, text );
1500 } 1500 }
1501 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); 1501 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) );
1502 ++it; 1502 ++it;
1503 } 1503 }
1504*/ 1504*/
1505 if (mEditorDialog) 1505 if (mEditorDialog)
1506 { 1506 {
1507 if (mEditorDialog->dirty()) 1507 if (mEditorDialog->dirty())
1508 { 1508 {
1509 QString text = i18n( "Data has been changed externally. Unsaved " 1509 QString text = i18n( "Data has been changed externally. Unsaved "
1510 "changes will be lost." ); 1510 "changes will be lost." );
1511 KMessageBox::information( this, text ); 1511 KMessageBox::information( this, text );
1512 } 1512 }
1513 QString currentuid = mEditorDialog->addressee().uid(); 1513 QString currentuid = mEditorDialog->addressee().uid();
1514 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); 1514 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) );
1515 } 1515 }
1516 mViewManager->refreshView(); 1516 mViewManager->refreshView();
1517// mDetails->refreshView(); 1517// mDetails->refreshView();
1518 1518
1519 1519
1520} 1520}
1521 1521
1522AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, 1522AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent,
1523 const char *name ) 1523 const char *name )
1524{ 1524{
1525 1525
1526 if ( mEditorDialog == 0 ) { 1526 if ( mEditorDialog == 0 ) {
1527 mEditorDialog = new AddresseeEditorDialog( this, parent, 1527 mEditorDialog = new AddresseeEditorDialog( this, parent,
1528 name ? name : "editorDialog" ); 1528 name ? name : "editorDialog" );
1529 1529
1530 1530
1531 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), 1531 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ),
1532 SLOT( contactModified( const KABC::Addressee& ) ) ); 1532 SLOT( contactModified( const KABC::Addressee& ) ) );
1533 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), 1533 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ),
1534 // SLOT( slotEditorDestroyed( const QString& ) ) ; 1534 // SLOT( slotEditorDestroyed( const QString& ) ) ;
1535 } 1535 }
1536 1536
1537 return mEditorDialog; 1537 return mEditorDialog;
1538} 1538}
1539 1539
1540void KABCore::slotEditorDestroyed( const QString &uid ) 1540void KABCore::slotEditorDestroyed( const QString &uid )
1541{ 1541{
1542 //mEditorDict.remove( uid ); 1542 //mEditorDict.remove( uid );
1543} 1543}
1544 1544
1545void KABCore::initGUI() 1545void KABCore::initGUI()
1546{ 1546{
1547#ifndef KAB_EMBEDDED 1547#ifndef KAB_EMBEDDED
1548 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1548 QHBoxLayout *topLayout = new QHBoxLayout( this );
1549 topLayout->setSpacing( KDialogBase::spacingHint() ); 1549 topLayout->setSpacing( KDialogBase::spacingHint() );
1550 1550
1551 mExtensionBarSplitter = new QSplitter( this ); 1551 mExtensionBarSplitter = new QSplitter( this );
1552 mExtensionBarSplitter->setOrientation( Qt::Vertical ); 1552 mExtensionBarSplitter->setOrientation( Qt::Vertical );
1553 1553
1554 mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); 1554 mDetailsSplitter = new QSplitter( mExtensionBarSplitter );
1555 1555
1556 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1556 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1557 mIncSearchWidget = new IncSearchWidget( viewSpace ); 1557 mIncSearchWidget = new IncSearchWidget( viewSpace );
1558 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1558 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1559 SLOT( incrementalSearch( const QString& ) ) ); 1559 SLOT( incrementalSearch( const QString& ) ) );
1560 1560
1561 mViewManager = new ViewManager( this, viewSpace ); 1561 mViewManager = new ViewManager( this, viewSpace );
1562 viewSpace->setStretchFactor( mViewManager, 1 ); 1562 viewSpace->setStretchFactor( mViewManager, 1 );
1563 1563
1564 mDetails = new ViewContainer( mDetailsSplitter ); 1564 mDetails = new ViewContainer( mDetailsSplitter );
1565 1565
1566 mJumpButtonBar = new JumpButtonBar( this, this ); 1566 mJumpButtonBar = new JumpButtonBar( this, this );
1567 1567
1568 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1568 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1569 1569
1570 topLayout->addWidget( mExtensionBarSplitter ); 1570 topLayout->addWidget( mExtensionBarSplitter );
1571 topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); 1571 topLayout->setStretchFactor( mExtensionBarSplitter, 100 );
1572 topLayout->addWidget( mJumpButtonBar ); 1572 topLayout->addWidget( mJumpButtonBar );
1573 topLayout->setStretchFactor( mJumpButtonBar, 1 ); 1573 topLayout->setStretchFactor( mJumpButtonBar, 1 );
1574 1574
1575 mXXPortManager = new XXPortManager( this, this ); 1575 mXXPortManager = new XXPortManager( this, this );
1576 1576
1577#else //KAB_EMBEDDED 1577#else //KAB_EMBEDDED
1578 //US initialize viewMenu before settingup viewmanager. 1578 //US initialize viewMenu before settingup viewmanager.
1579 // Viewmanager needs this menu to plugin submenues. 1579 // Viewmanager needs this menu to plugin submenues.
1580 viewMenu = new QPopupMenu( this ); 1580 viewMenu = new QPopupMenu( this );
1581 settingsMenu = new QPopupMenu( this ); 1581 settingsMenu = new QPopupMenu( this );
1582 //filterMenu = new QPopupMenu( this ); 1582 //filterMenu = new QPopupMenu( this );
1583 ImportMenu = new QPopupMenu( this ); 1583 ImportMenu = new QPopupMenu( this );
1584 ExportMenu = new QPopupMenu( this ); 1584 ExportMenu = new QPopupMenu( this );
1585 syncMenu = new QPopupMenu( this ); 1585 syncMenu = new QPopupMenu( this );
1586 changeMenu= new QPopupMenu( this ); 1586 changeMenu= new QPopupMenu( this );
1587 1587
1588//US since we have no splitter for the embedded system, setup 1588//US since we have no splitter for the embedded system, setup
1589// a layout with two frames. One left and one right. 1589// a layout with two frames. One left and one right.
1590 1590
1591 QBoxLayout *topLayout; 1591 QBoxLayout *topLayout;
1592 1592
1593 // = new QHBoxLayout( this ); 1593 // = new QHBoxLayout( this );
1594// QBoxLayout *topLayout = (QBoxLayout*)layout(); 1594// QBoxLayout *topLayout = (QBoxLayout*)layout();
1595 1595
1596// QWidget *mainBox = new QWidget( this ); 1596// QWidget *mainBox = new QWidget( this );
1597// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); 1597// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox);
1598 1598
1599#ifdef DESKTOP_VERSION 1599#ifdef DESKTOP_VERSION
1600 topLayout = new QHBoxLayout( this ); 1600 topLayout = new QHBoxLayout( this );
1601 1601
1602 1602
1603 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1603 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1604 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1604 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1605 1605
1606 topLayout->addWidget(mMiniSplitter ); 1606 topLayout->addWidget(mMiniSplitter );
1607 1607
1608 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); 1608 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter );
1609 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1609 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1610 mViewManager = new ViewManager( this, mExtensionBarSplitter ); 1610 mViewManager = new ViewManager( this, mExtensionBarSplitter );
1611 mDetails = new ViewContainer( mMiniSplitter ); 1611 mDetails = new ViewContainer( mMiniSplitter );
1612 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1612 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1613#else 1613#else
1614 if ( QApplication::desktop()->width() > 480 ) { 1614 if ( QApplication::desktop()->width() > 480 ) {
1615 topLayout = new QHBoxLayout( this ); 1615 topLayout = new QHBoxLayout( this );
1616 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1616 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1617 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1617 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1618 } else { 1618 } else {
1619 1619
1620 topLayout = new QHBoxLayout( this ); 1620 topLayout = new QHBoxLayout( this );
1621 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); 1621 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this);
1622 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1622 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1623 } 1623 }
1624 1624
1625 topLayout->addWidget(mMiniSplitter ); 1625 topLayout->addWidget(mMiniSplitter );
1626 mViewManager = new ViewManager( this, mMiniSplitter ); 1626 mViewManager = new ViewManager( this, mMiniSplitter );
1627 mDetails = new ViewContainer( mMiniSplitter ); 1627 mDetails = new ViewContainer( mMiniSplitter );
1628 1628
1629 1629
1630 mExtensionManager = new ExtensionManager( this, mMiniSplitter ); 1630 mExtensionManager = new ExtensionManager( this, mMiniSplitter );
1631#endif 1631#endif
1632 //eh->hide(); 1632 //eh->hide();
1633 // topLayout->addWidget(mExtensionManager ); 1633 // topLayout->addWidget(mExtensionManager );
1634 1634
1635 1635
1636/*US 1636/*US
1637#ifndef KAB_NOSPLITTER 1637#ifndef KAB_NOSPLITTER
1638 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1638 QHBoxLayout *topLayout = new QHBoxLayout( this );
1639//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1639//US topLayout->setSpacing( KDialogBase::spacingHint() );
1640 topLayout->setSpacing( 10 ); 1640 topLayout->setSpacing( 10 );
1641 1641
1642 mDetailsSplitter = new QSplitter( this ); 1642 mDetailsSplitter = new QSplitter( this );
1643 1643
1644 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1644 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1645 1645
1646 mViewManager = new ViewManager( this, viewSpace ); 1646 mViewManager = new ViewManager( this, viewSpace );
1647 viewSpace->setStretchFactor( mViewManager, 1 ); 1647 viewSpace->setStretchFactor( mViewManager, 1 );
1648 1648
1649 mDetails = new ViewContainer( mDetailsSplitter ); 1649 mDetails = new ViewContainer( mDetailsSplitter );
1650 1650
1651 topLayout->addWidget( mDetailsSplitter ); 1651 topLayout->addWidget( mDetailsSplitter );
1652 topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1652 topLayout->setStretchFactor( mDetailsSplitter, 100 );
1653#else //KAB_NOSPLITTER 1653#else //KAB_NOSPLITTER
1654 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1654 QHBoxLayout *topLayout = new QHBoxLayout( this );
1655//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1655//US topLayout->setSpacing( KDialogBase::spacingHint() );
1656 topLayout->setSpacing( 10 ); 1656 topLayout->setSpacing( 10 );
1657 1657
1658// mDetailsSplitter = new QSplitter( this ); 1658// mDetailsSplitter = new QSplitter( this );
1659 1659
1660 QVBox *viewSpace = new QVBox( this ); 1660 QVBox *viewSpace = new QVBox( this );
1661 1661
1662 mViewManager = new ViewManager( this, viewSpace ); 1662 mViewManager = new ViewManager( this, viewSpace );
1663 viewSpace->setStretchFactor( mViewManager, 1 ); 1663 viewSpace->setStretchFactor( mViewManager, 1 );
1664 1664
1665 mDetails = new ViewContainer( this ); 1665 mDetails = new ViewContainer( this );
1666 1666
1667 topLayout->addWidget( viewSpace ); 1667 topLayout->addWidget( viewSpace );
1668// topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1668// topLayout->setStretchFactor( mDetailsSplitter, 100 );
1669 topLayout->addWidget( mDetails ); 1669 topLayout->addWidget( mDetails );
1670#endif //KAB_NOSPLITTER 1670#endif //KAB_NOSPLITTER
1671*/ 1671*/
1672 1672
1673 syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); 1673 syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu);
1674 syncManager->setBlockSave(false); 1674 syncManager->setBlockSave(false);
1675 1675
1676 connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); 1676 connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) );
1677 connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); 1677 connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) );
1678 syncManager->setDefaultFileName( sentSyncFile()); 1678 syncManager->setDefaultFileName( sentSyncFile());
1679 //connect(syncManager , SIGNAL( ), this, SLOT( ) ); 1679 //connect(syncManager , SIGNAL( ), this, SLOT( ) );
1680 1680
1681#endif //KAB_EMBEDDED 1681#endif //KAB_EMBEDDED
1682 initActions(); 1682 initActions();
1683 1683
1684#ifdef KAB_EMBEDDED 1684#ifdef KAB_EMBEDDED
1685 addActionsManually(); 1685 addActionsManually();
1686 //US make sure the export and import menues are initialized before creating the xxPortManager. 1686 //US make sure the export and import menues are initialized before creating the xxPortManager.
1687 mXXPortManager = new XXPortManager( this, this ); 1687 mXXPortManager = new XXPortManager( this, this );
1688 1688
1689 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); 1689 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() );
1690 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); 1690 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget);
1691 // mActionQuit->plug ( mMainWindow->toolBar()); 1691 // mActionQuit->plug ( mMainWindow->toolBar());
1692 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); 1692 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() );
1693 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); 1693 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget);
1694 // mIncSearchWidget->hide(); 1694 // mIncSearchWidget->hide();
1695 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1695 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1696 SLOT( incrementalSearch( const QString& ) ) ); 1696 SLOT( incrementalSearch( const QString& ) ) );
1697 connect( mIncSearchWidget, SIGNAL( scrollUP() ),mViewManager, SLOT( scrollUP() ) ); 1697 connect( mIncSearchWidget, SIGNAL( scrollUP() ),mViewManager, SLOT( scrollUP() ) );
1698 connect( mIncSearchWidget, SIGNAL( scrollDOWN() ),mViewManager, SLOT( scrollDOWN() ) ); 1698 connect( mIncSearchWidget, SIGNAL( scrollDOWN() ),mViewManager, SLOT( scrollDOWN() ) );
1699 1699
1700 mJumpButtonBar = new JumpButtonBar( this, this ); 1700 mJumpButtonBar = new JumpButtonBar( this, this );
1701 1701
1702 topLayout->addWidget( mJumpButtonBar ); 1702 topLayout->addWidget( mJumpButtonBar );
1703//US topLayout->setStretchFactor( mJumpButtonBar, 10 ); 1703//US topLayout->setStretchFactor( mJumpButtonBar, 10 );
1704 1704
1705// mMainWindow->getIconToolBar()->raise(); 1705// mMainWindow->getIconToolBar()->raise();
1706 1706
1707#endif //KAB_EMBEDDED 1707#endif //KAB_EMBEDDED
1708 1708
1709} 1709}
1710void KABCore::initActions() 1710void KABCore::initActions()
1711{ 1711{
1712//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1712//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1713 1713
1714#ifndef KAB_EMBEDDED 1714#ifndef KAB_EMBEDDED
1715 connect( QApplication::clipboard(), SIGNAL( dataChanged() ), 1715 connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
1716 SLOT( clipboardDataChanged() ) ); 1716 SLOT( clipboardDataChanged() ) );
1717#endif //KAB_EMBEDDED 1717#endif //KAB_EMBEDDED
1718 1718
1719 // file menu 1719 // file menu
1720 if ( mIsPart ) { 1720 if ( mIsPart ) {
1721 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, 1721 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this,
1722 SLOT( sendMail() ), actionCollection(), 1722 SLOT( sendMail() ), actionCollection(),
1723 "kaddressbook_mail" ); 1723 "kaddressbook_mail" );
1724 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, 1724 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this,
1725 SLOT( print() ), actionCollection(), "kaddressbook_print" ); 1725 SLOT( print() ), actionCollection(), "kaddressbook_print" );
1726 1726
1727 } else { 1727 } else {
1728 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); 1728 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() );
1729 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); 1729 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() );
1730 } 1730 }
1731 1731
1732 1732
1733 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, 1733 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this,
1734 SLOT( save() ), actionCollection(), "file_sync" ); 1734 SLOT( save() ), actionCollection(), "file_sync" );
1735 1735
1736 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, 1736 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this,
1737 SLOT( newContact() ), actionCollection(), "file_new_contact" ); 1737 SLOT( newContact() ), actionCollection(), "file_new_contact" );
1738 1738
1739 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, 1739 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0,
1740 this, SLOT( mailVCard() ), 1740 this, SLOT( mailVCard() ),
1741 actionCollection(), "file_mail_vcard"); 1741 actionCollection(), "file_mail_vcard");
1742 1742
1743 mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this, 1743 mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this,
1744 SLOT( export2phone() ), actionCollection(), 1744 SLOT( export2phone() ), actionCollection(),
1745 "kaddressbook_ex2phone" ); 1745 "kaddressbook_ex2phone" );
1746 1746
1747 mActionBeamVCard = 0; 1747 mActionBeamVCard = 0;
1748 mActionBeam = 0; 1748 mActionBeam = 0;
1749 1749
1750#ifndef DESKTOP_VERSION 1750#ifndef DESKTOP_VERSION
1751 if ( Ir::supported() ) { 1751 if ( Ir::supported() ) {
1752 mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, 1752 mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this,
1753 SLOT( beamVCard() ), actionCollection(), 1753 SLOT( beamVCard() ), actionCollection(),
1754 "kaddressbook_beam_vcard" ); 1754 "kaddressbook_beam_vcard" );
1755 1755
1756 mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, 1756 mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this,
1757 SLOT( beamMySelf() ), actionCollection(), 1757 SLOT( beamMySelf() ), actionCollection(),
1758 "kaddressbook_beam_myself" ); 1758 "kaddressbook_beam_myself" );
1759 } 1759 }
1760#endif 1760#endif
1761 1761
1762 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, 1762 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0,
1763 this, SLOT( editContact2() ), 1763 this, SLOT( editContact2() ),
1764 actionCollection(), "file_properties" ); 1764 actionCollection(), "file_properties" );
1765 1765
1766#ifdef KAB_EMBEDDED 1766#ifdef KAB_EMBEDDED
1767 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); 1767 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() );
1768 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, 1768 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0,
1769 mMainWindow, SLOT( exit() ), 1769 mMainWindow, SLOT( exit() ),
1770 actionCollection(), "quit" ); 1770 actionCollection(), "quit" );
1771#endif //KAB_EMBEDDED 1771#endif //KAB_EMBEDDED
1772 1772
1773 // edit menu 1773 // edit menu
1774 if ( mIsPart ) { 1774 if ( mIsPart ) {
1775 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, 1775 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this,
1776 SLOT( copyContacts() ), actionCollection(), 1776 SLOT( copyContacts() ), actionCollection(),
1777 "kaddressbook_copy" ); 1777 "kaddressbook_copy" );
1778 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, 1778 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this,
1779 SLOT( cutContacts() ), actionCollection(), 1779 SLOT( cutContacts() ), actionCollection(),
1780 "kaddressbook_cut" ); 1780 "kaddressbook_cut" );
1781 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, 1781 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this,
1782 SLOT( pasteContacts() ), actionCollection(), 1782 SLOT( pasteContacts() ), actionCollection(),
1783 "kaddressbook_paste" ); 1783 "kaddressbook_paste" );
1784 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, 1784 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this,
1785 SLOT( selectAllContacts() ), actionCollection(), 1785 SLOT( selectAllContacts() ), actionCollection(),
1786 "kaddressbook_select_all" ); 1786 "kaddressbook_select_all" );
1787 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, 1787 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this,
1788 SLOT( undo() ), actionCollection(), 1788 SLOT( undo() ), actionCollection(),
1789 "kaddressbook_undo" ); 1789 "kaddressbook_undo" );
1790 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, 1790 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z,
1791 this, SLOT( redo() ), actionCollection(), 1791 this, SLOT( redo() ), actionCollection(),
1792 "kaddressbook_redo" ); 1792 "kaddressbook_redo" );
1793 } else { 1793 } else {
1794 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); 1794 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() );
1795 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); 1795 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() );
1796 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); 1796 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() );
1797 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); 1797 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() );
1798 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); 1798 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() );
1799 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); 1799 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() );
1800 } 1800 }
1801 1801
1802 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", 1802 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete",
1803 Key_Delete, this, SLOT( deleteContacts() ), 1803 Key_Delete, this, SLOT( deleteContacts() ),
1804 actionCollection(), "edit_delete" ); 1804 actionCollection(), "edit_delete" );
1805 1805
1806 mActionUndo->setEnabled( false ); 1806 mActionUndo->setEnabled( false );
1807 mActionRedo->setEnabled( false ); 1807 mActionRedo->setEnabled( false );
1808 1808
1809 // settings menu 1809 // settings menu
1810#ifdef KAB_EMBEDDED 1810#ifdef KAB_EMBEDDED
1811//US special menuentry to configure the addressbook resources. On KDE 1811//US special menuentry to configure the addressbook resources. On KDE
1812// you do that through the control center !!! 1812// you do that through the control center !!!
1813 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, 1813 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this,
1814 SLOT( configureResources() ), actionCollection(), 1814 SLOT( configureResources() ), actionCollection(),
1815 "kaddressbook_configure_resources" ); 1815 "kaddressbook_configure_resources" );
1816#endif //KAB_EMBEDDED 1816#endif //KAB_EMBEDDED
1817 1817
1818 if ( mIsPart ) { 1818 if ( mIsPart ) {
1819 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, 1819 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this,
1820 SLOT( openConfigDialog() ), actionCollection(), 1820 SLOT( openConfigDialog() ), actionCollection(),
1821 "kaddressbook_configure" ); 1821 "kaddressbook_configure" );
1822 1822
1823 //US not implemented yet 1823 //US not implemented yet
1824 //mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, 1824 //mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0,
1825 // this, SLOT( configureKeyBindings() ), actionCollection(), 1825 // this, SLOT( configureKeyBindings() ), actionCollection(),
1826 // "kaddressbook_configure_shortcuts" ); 1826 // "kaddressbook_configure_shortcuts" );
1827#ifdef KAB_EMBEDDED 1827#ifdef KAB_EMBEDDED
1828 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); 1828 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() );
1829 mActionConfigureToolbars->setEnabled( false ); 1829 mActionConfigureToolbars->setEnabled( false );
1830#endif //KAB_EMBEDDED 1830#endif //KAB_EMBEDDED
1831 1831
1832 } else { 1832 } else {
1833 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); 1833 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() );
1834 1834
1835 //US not implemented yet 1835 //US not implemented yet
1836 //mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); 1836 //mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() );
1837 } 1837 }
1838 1838
1839 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, 1839 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0,
1840 actionCollection(), "options_show_jump_bar" ); 1840 actionCollection(), "options_show_jump_bar" );
1841 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); 1841 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) );
1842 1842
1843 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, 1843 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0,
1844 actionCollection(), "options_show_details" ); 1844 actionCollection(), "options_show_details" );
1845 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); 1845 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) );
1846 1846
1847 1847
1848 mActionBR = new KToggleAction( i18n( "Beam receive enabled" ), "beam", 0, this, 1848 mActionBR = new KToggleAction( i18n( "Beam receive enabled" ), "beam", 0, this,
1849 SLOT( toggleBeamReceive() ), actionCollection(), 1849 SLOT( toggleBeamReceive() ), actionCollection(),
1850 "kaddressbook_beam_rec" ); 1850 "kaddressbook_beam_rec" );
1851 1851
1852 1852
1853 // misc 1853 // misc
1854 // only enable LDAP lookup if we can handle the protocol 1854 // only enable LDAP lookup if we can handle the protocol
1855#ifndef KAB_EMBEDDED 1855#ifndef KAB_EMBEDDED
1856 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { 1856 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) {
1857 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, 1857 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0,
1858 this, SLOT( openLDAPDialog() ), actionCollection(), 1858 this, SLOT( openLDAPDialog() ), actionCollection(),
1859 "ldap_lookup" ); 1859 "ldap_lookup" );
1860 } 1860 }
1861#else //KAB_EMBEDDED 1861#else //KAB_EMBEDDED
1862 //qDebug("KABCore::initActions() LDAP has to be implemented"); 1862 //qDebug("KABCore::initActions() LDAP has to be implemented");
1863#endif //KAB_EMBEDDED 1863#endif //KAB_EMBEDDED
1864 1864
1865 1865
1866 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, 1866 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this,
1867 SLOT( setWhoAmI() ), actionCollection(), 1867 SLOT( setWhoAmI() ), actionCollection(),
1868 "set_personal" ); 1868 "set_personal" );
1869 1869
1870 1870
1871 1871
1872 1872
1873 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, 1873 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this,
1874 SLOT( setCategories() ), actionCollection(), 1874 SLOT( setCategories() ), actionCollection(),
1875 "edit_set_categories" ); 1875 "edit_set_categories" );
1876 1876
1877 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, 1877 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this,
1878 SLOT( removeVoice() ), actionCollection(), 1878 SLOT( removeVoice() ), actionCollection(),
1879 "remove_voice" ); 1879 "remove_voice" );
1880 mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this, 1880 mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this,
1881 SLOT( importFromOL() ), actionCollection(), 1881 SLOT( importFromOL() ), actionCollection(),
1882 "import_OL" ); 1882 "import_OL" );
1883#ifdef KAB_EMBEDDED 1883#ifdef KAB_EMBEDDED
1884 mActionLicence = new KAction( i18n( "Licence" ), 0, 1884 mActionLicence = new KAction( i18n( "Licence" ), 0,
1885 this, SLOT( showLicence() ), actionCollection(), 1885 this, SLOT( showLicence() ), actionCollection(),
1886 "licence_about_data" ); 1886 "licence_about_data" );
1887 mActionFaq = new KAction( i18n( "Faq" ), 0, 1887 mActionFaq = new KAction( i18n( "Faq" ), 0,
1888 this, SLOT( faq() ), actionCollection(), 1888 this, SLOT( faq() ), actionCollection(),
1889 "faq_about_data" ); 1889 "faq_about_data" );
1890 mActionWN = new KAction( i18n( "What's New?" ), 0, 1890 mActionWN = new KAction( i18n( "What's New?" ), 0,
1891 this, SLOT( whatsnew() ), actionCollection(), 1891 this, SLOT( whatsnew() ), actionCollection(),
1892 "wn" ); 1892 "wn" );
1893 mActionSyncHowto = new KAction( i18n( "Sync HowTo" ), 0, 1893 mActionSyncHowto = new KAction( i18n( "Sync HowTo" ), 0,
1894 this, SLOT( synchowto() ), actionCollection(), 1894 this, SLOT( synchowto() ), actionCollection(),
1895 "sync" ); 1895 "sync" );
1896 1896
1897 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, 1897 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0,
1898 this, SLOT( createAboutData() ), actionCollection(), 1898 this, SLOT( createAboutData() ), actionCollection(),
1899 "kaddressbook_about_data" ); 1899 "kaddressbook_about_data" );
1900#endif //KAB_EMBEDDED 1900#endif //KAB_EMBEDDED
1901 1901
1902 clipboardDataChanged(); 1902 clipboardDataChanged();
1903 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1903 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1904 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1904 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1905} 1905}
1906 1906
1907//US we need this function, to plug all actions into the correct menues. 1907//US we need this function, to plug all actions into the correct menues.
1908// KDE uses a XML format to plug the actions, but we work her without this overhead. 1908// KDE uses a XML format to plug the actions, but we work her without this overhead.
1909void KABCore::addActionsManually() 1909void KABCore::addActionsManually()
1910{ 1910{
1911//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1911//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1912 1912
1913#ifdef KAB_EMBEDDED 1913#ifdef KAB_EMBEDDED
1914 QPopupMenu *fileMenu = new QPopupMenu( this ); 1914 QPopupMenu *fileMenu = new QPopupMenu( this );
1915 QPopupMenu *editMenu = new QPopupMenu( this ); 1915 QPopupMenu *editMenu = new QPopupMenu( this );
1916 QPopupMenu *helpMenu = new QPopupMenu( this ); 1916 QPopupMenu *helpMenu = new QPopupMenu( this );
1917 1917
1918 KToolBar* tb = mMainWindow->toolBar(); 1918 KToolBar* tb = mMainWindow->toolBar();
1919 1919
1920#ifdef DESKTOP_VERSION 1920#ifdef DESKTOP_VERSION
1921 QMenuBar* mb = mMainWindow->menuBar(); 1921 QMenuBar* mb = mMainWindow->menuBar();
1922 1922
1923 //US setup menubar. 1923 //US setup menubar.
1924 //Disable the following block if you do not want to have a menubar. 1924 //Disable the following block if you do not want to have a menubar.
1925 mb->insertItem( "&File", fileMenu ); 1925 mb->insertItem( "&File", fileMenu );
1926 mb->insertItem( "&Edit", editMenu ); 1926 mb->insertItem( "&Edit", editMenu );
1927 mb->insertItem( "&View", viewMenu ); 1927 mb->insertItem( "&View", viewMenu );
1928 mb->insertItem( "&Settings", settingsMenu ); 1928 mb->insertItem( "&Settings", settingsMenu );
1929 mb->insertItem( i18n("Synchronize"), syncMenu ); 1929 mb->insertItem( i18n("Synchronize"), syncMenu );
1930 mb->insertItem( "&Change selected", changeMenu ); 1930 mb->insertItem( "&Change selected", changeMenu );
1931 mb->insertItem( "&Help", helpMenu ); 1931 mb->insertItem( "&Help", helpMenu );
1932 mIncSearchWidget = new IncSearchWidget( tb ); 1932 mIncSearchWidget = new IncSearchWidget( tb );
1933 // tb->insertWidget(-1, 0, mIncSearchWidget); 1933 // tb->insertWidget(-1, 0, mIncSearchWidget);
1934 1934
1935#else 1935#else
1936 //US setup toolbar 1936 //US setup toolbar
1937 QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); 1937 QPEMenuBar *menuBarTB = new QPEMenuBar( tb );
1938 QPopupMenu *popupBarTB = new QPopupMenu( this ); 1938 QPopupMenu *popupBarTB = new QPopupMenu( this );
1939 menuBarTB->insertItem( "ME", popupBarTB); 1939 menuBarTB->insertItem( "ME", popupBarTB);
1940 tb->insertWidget(-1, 0, menuBarTB); 1940 tb->insertWidget(-1, 0, menuBarTB);
1941 mIncSearchWidget = new IncSearchWidget( tb ); 1941 mIncSearchWidget = new IncSearchWidget( tb );
1942 1942
1943 tb->enableMoving(false); 1943 tb->enableMoving(false);
1944 popupBarTB->insertItem( "&File", fileMenu ); 1944 popupBarTB->insertItem( "&File", fileMenu );
1945 popupBarTB->insertItem( "&Edit", editMenu ); 1945 popupBarTB->insertItem( "&Edit", editMenu );
1946 popupBarTB->insertItem( "&View", viewMenu ); 1946 popupBarTB->insertItem( "&View", viewMenu );
1947 popupBarTB->insertItem( "&Settings", settingsMenu ); 1947 popupBarTB->insertItem( "&Settings", settingsMenu );
1948 popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); 1948 popupBarTB->insertItem( i18n("Synchronize"), syncMenu );
1949 mViewManager->getFilterAction()->plug ( popupBarTB); 1949 mViewManager->getFilterAction()->plug ( popupBarTB);
1950 popupBarTB->insertItem( "&Change selected", changeMenu ); 1950 popupBarTB->insertItem( "&Change selected", changeMenu );
1951 popupBarTB->insertItem( "&Help", helpMenu ); 1951 popupBarTB->insertItem( "&Help", helpMenu );
1952 if (QApplication::desktop()->width() > 320 ) { 1952 if (QApplication::desktop()->width() > 320 ) {
1953 // mViewManager->getFilterAction()->plug ( tb); 1953 // mViewManager->getFilterAction()->plug ( tb);
1954 } 1954 }
1955#endif 1955#endif
1956 // mActionQuit->plug ( mMainWindow->toolBar()); 1956 // mActionQuit->plug ( mMainWindow->toolBar());
1957 1957
1958 1958
1959 1959
1960 //US Now connect the actions with the menue entries. 1960 //US Now connect the actions with the menue entries.
1961 mActionPrint->plug( fileMenu ); 1961 mActionPrint->plug( fileMenu );
1962 mActionMail->plug( fileMenu ); 1962 mActionMail->plug( fileMenu );
1963 fileMenu->insertSeparator(); 1963 fileMenu->insertSeparator();
1964 1964
1965 mActionNewContact->plug( fileMenu ); 1965 mActionNewContact->plug( fileMenu );
1966 mActionNewContact->plug( tb ); 1966 mActionNewContact->plug( tb );
1967 1967
1968 mActionEditAddressee->plug( fileMenu ); 1968 mActionEditAddressee->plug( fileMenu );
1969 if ((KGlobal::getDesktopSize() > KGlobal::Small ) || 1969 if ((KGlobal::getDesktopSize() > KGlobal::Small ) ||
1970 (!KABPrefs::instance()->mMultipleViewsAtOnce )) 1970 (!KABPrefs::instance()->mMultipleViewsAtOnce ))
1971 mActionEditAddressee->plug( tb ); 1971 mActionEditAddressee->plug( tb );
1972 1972
1973 fileMenu->insertSeparator(); 1973 fileMenu->insertSeparator();
1974 mActionSave->plug( fileMenu ); 1974 mActionSave->plug( fileMenu );
1975 fileMenu->insertItem( "&Import", ImportMenu ); 1975 fileMenu->insertItem( "&Import", ImportMenu );
1976 fileMenu->insertItem( "&Export", ExportMenu ); 1976 fileMenu->insertItem( "&Export", ExportMenu );
1977 fileMenu->insertSeparator(); 1977 fileMenu->insertSeparator();
1978 mActionMailVCard->plug( fileMenu ); 1978 mActionMailVCard->plug( fileMenu );
1979#ifndef DESKTOP_VERSION 1979#ifndef DESKTOP_VERSION
1980 if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); 1980 if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu );
1981 if ( Ir::supported() ) mActionBeam->plug(fileMenu ); 1981 if ( Ir::supported() ) mActionBeam->plug(fileMenu );
1982#endif 1982#endif
1983 fileMenu->insertSeparator(); 1983 fileMenu->insertSeparator();
1984 mActionQuit->plug( fileMenu ); 1984 mActionQuit->plug( fileMenu );
1985#ifdef _WIN32_ 1985#ifdef _WIN32_
1986 mActionImportOL->plug( ImportMenu ); 1986 mActionImportOL->plug( ImportMenu );
1987#endif 1987#endif
1988 // edit menu 1988 // edit menu
1989 mActionUndo->plug( editMenu ); 1989 mActionUndo->plug( editMenu );
1990 mActionRedo->plug( editMenu ); 1990 mActionRedo->plug( editMenu );
1991 editMenu->insertSeparator(); 1991 editMenu->insertSeparator();
1992 mActionCut->plug( editMenu ); 1992 mActionCut->plug( editMenu );
1993 mActionCopy->plug( editMenu ); 1993 mActionCopy->plug( editMenu );
1994 mActionPaste->plug( editMenu ); 1994 mActionPaste->plug( editMenu );
1995 mActionDelete->plug( editMenu ); 1995 mActionDelete->plug( editMenu );
1996 editMenu->insertSeparator(); 1996 editMenu->insertSeparator();
1997 mActionSelectAll->plug( editMenu ); 1997 mActionSelectAll->plug( editMenu );
1998 1998
1999 mActionRemoveVoice->plug( changeMenu ); 1999 mActionRemoveVoice->plug( changeMenu );
2000 // settings menu 2000 // settings menu
2001//US special menuentry to configure the addressbook resources. On KDE 2001//US special menuentry to configure the addressbook resources. On KDE
2002// you do that through the control center !!! 2002// you do that through the control center !!!
2003 mActionConfigResources->plug( settingsMenu ); 2003 mActionConfigResources->plug( settingsMenu );
2004 settingsMenu->insertSeparator(); 2004 settingsMenu->insertSeparator();
2005 2005
2006 mActionConfigKAddressbook->plug( settingsMenu ); 2006 mActionConfigKAddressbook->plug( settingsMenu );
2007 2007
2008 if ( mIsPart ) { 2008 if ( mIsPart ) {
2009 //US not implemented yet 2009 //US not implemented yet
2010 //mActionConfigShortcuts->plug( settingsMenu ); 2010 //mActionConfigShortcuts->plug( settingsMenu );
2011 //mActionConfigureToolbars->plug( settingsMenu ); 2011 //mActionConfigureToolbars->plug( settingsMenu );
2012 2012
2013 } else { 2013 } else {
2014 //US not implemented yet 2014 //US not implemented yet
2015 //mActionKeyBindings->plug( settingsMenu ); 2015 //mActionKeyBindings->plug( settingsMenu );
2016 } 2016 }
2017 2017
2018 settingsMenu->insertSeparator(); 2018 settingsMenu->insertSeparator();
2019 2019
2020 mActionJumpBar->plug( settingsMenu ); 2020 mActionJumpBar->plug( settingsMenu );
2021 mActionDetails->plug( settingsMenu ); 2021 mActionDetails->plug( settingsMenu );
2022 if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) 2022 if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop )
2023 mActionDetails->plug( tb ); 2023 mActionDetails->plug( tb );
2024 settingsMenu->insertSeparator(); 2024 settingsMenu->insertSeparator();
2025 mActionBR->plug(settingsMenu ); 2025 mActionBR->plug(settingsMenu );
2026 settingsMenu->insertSeparator(); 2026 settingsMenu->insertSeparator();
2027 2027
2028 mActionWhoAmI->plug( settingsMenu ); 2028 mActionWhoAmI->plug( settingsMenu );
2029 mActionCategories->plug( settingsMenu ); 2029 mActionCategories->plug( settingsMenu );
2030 2030
2031 2031
2032 mActionWN->plug( helpMenu ); 2032 mActionWN->plug( helpMenu );
2033 mActionSyncHowto->plug( helpMenu ); 2033 mActionSyncHowto->plug( helpMenu );
2034 mActionLicence->plug( helpMenu ); 2034 mActionLicence->plug( helpMenu );
2035 mActionFaq->plug( helpMenu ); 2035 mActionFaq->plug( helpMenu );
2036 mActionAboutKAddressbook->plug( helpMenu ); 2036 mActionAboutKAddressbook->plug( helpMenu );
2037 2037
2038 if (KGlobal::getDesktopSize() > KGlobal::Small ) { 2038 if (KGlobal::getDesktopSize() > KGlobal::Small ) {
2039 2039
2040 mActionSave->plug( tb ); 2040 mActionSave->plug( tb );
2041 mViewManager->getFilterAction()->plug ( tb); 2041 mViewManager->getFilterAction()->plug ( tb);
2042 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { 2042 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) {
2043 mActionUndo->plug( tb ); 2043 mActionUndo->plug( tb );
2044 mActionDelete->plug( tb ); 2044 mActionDelete->plug( tb );
2045 mActionRedo->plug( tb ); 2045 mActionRedo->plug( tb );
2046 } 2046 }
2047 } 2047 }
2048 //mActionQuit->plug ( tb ); 2048 //mActionQuit->plug ( tb );
2049 // tb->insertWidget(-1, 0, mIncSearchWidget, 6); 2049 // tb->insertWidget(-1, 0, mIncSearchWidget, 6);
2050 2050
2051 //US link the searchwidget first to this. 2051 //US link the searchwidget first to this.
2052 // The real linkage to the toolbar happens later. 2052 // The real linkage to the toolbar happens later.
2053//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); 2053//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE);
2054//US tb->insertItem( mIncSearchWidget ); 2054//US tb->insertItem( mIncSearchWidget );
2055/*US 2055/*US
2056 mIncSearchWidget = new IncSearchWidget( tb ); 2056 mIncSearchWidget = new IncSearchWidget( tb );
2057 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 2057 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
2058 SLOT( incrementalSearch( const QString& ) ) ); 2058 SLOT( incrementalSearch( const QString& ) ) );
2059 2059
2060 mJumpButtonBar = new JumpButtonBar( this, this ); 2060 mJumpButtonBar = new JumpButtonBar( this, this );
2061 2061
2062//US topLayout->addWidget( mJumpButtonBar ); 2062//US topLayout->addWidget( mJumpButtonBar );
2063 this->layout()->add( mJumpButtonBar ); 2063 this->layout()->add( mJumpButtonBar );
2064*/ 2064*/
2065 2065
2066#endif //KAB_EMBEDDED 2066#endif //KAB_EMBEDDED
2067 2067
2068 mActionExport2phone->plug( ExportMenu ); 2068 mActionExport2phone->plug( ExportMenu );
2069 connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); 2069 connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) );
2070 syncManager->fillSyncMenu(); 2070 syncManager->fillSyncMenu();
2071 2071
2072} 2072}
2073void KABCore::showLicence() 2073void KABCore::showLicence()
2074{ 2074{
2075 KApplication::showLicence(); 2075 KApplication::showLicence();
2076} 2076}
2077void KABCore::removeVoice() 2077void KABCore::removeVoice()
2078{ 2078{
2079 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 ) 2079 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 )
2080 return; 2080 return;
2081 KABC::Addressee::List list = mViewManager->selectedAddressees(); 2081 KABC::Addressee::List list = mViewManager->selectedAddressees();
2082 KABC::Addressee::List::Iterator it; 2082 KABC::Addressee::List::Iterator it;
2083 for ( it = list.begin(); it != list.end(); ++it ) { 2083 for ( it = list.begin(); it != list.end(); ++it ) {
2084 2084
2085 if ( (*it).removeVoice() ) 2085 if ( (*it).removeVoice() )
2086 contactModified((*it) ); 2086 contactModified((*it) );
2087 } 2087 }
2088} 2088}
2089 2089
2090 2090
2091 2091
2092void KABCore::clipboardDataChanged() 2092void KABCore::clipboardDataChanged()
2093{ 2093{
2094 2094
2095 if ( mReadWrite ) 2095 if ( mReadWrite )
2096 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); 2096 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() );
2097 2097
2098} 2098}
2099 2099
2100void KABCore::updateActionMenu() 2100void KABCore::updateActionMenu()
2101{ 2101{
2102 UndoStack *undo = UndoStack::instance(); 2102 UndoStack *undo = UndoStack::instance();
2103 RedoStack *redo = RedoStack::instance(); 2103 RedoStack *redo = RedoStack::instance();
2104 2104
2105 if ( undo->isEmpty() ) 2105 if ( undo->isEmpty() )
2106 mActionUndo->setText( i18n( "Undo" ) ); 2106 mActionUndo->setText( i18n( "Undo" ) );
2107 else 2107 else
2108 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); 2108 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) );
2109 2109
2110 mActionUndo->setEnabled( !undo->isEmpty() ); 2110 mActionUndo->setEnabled( !undo->isEmpty() );
2111 2111
2112 if ( !redo->top() ) 2112 if ( !redo->top() )
2113 mActionRedo->setText( i18n( "Redo" ) ); 2113 mActionRedo->setText( i18n( "Redo" ) );
2114 else 2114 else
2115 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); 2115 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) );
2116 2116
2117 mActionRedo->setEnabled( !redo->isEmpty() ); 2117 mActionRedo->setEnabled( !redo->isEmpty() );
2118} 2118}
2119 2119
2120void KABCore::configureKeyBindings() 2120void KABCore::configureKeyBindings()
2121{ 2121{
2122#ifndef KAB_EMBEDDED 2122#ifndef KAB_EMBEDDED
2123 KKeyDialog::configure( actionCollection(), true ); 2123 KKeyDialog::configure( actionCollection(), true );
2124#else //KAB_EMBEDDED 2124#else //KAB_EMBEDDED
2125 qDebug("KABCore::configureKeyBindings() not implemented"); 2125 qDebug("KABCore::configureKeyBindings() not implemented");
2126#endif //KAB_EMBEDDED 2126#endif //KAB_EMBEDDED
2127} 2127}
2128 2128
2129#ifdef KAB_EMBEDDED 2129#ifdef KAB_EMBEDDED
2130void KABCore::configureResources() 2130void KABCore::configureResources()
2131{ 2131{
2132 KRES::KCMKResources dlg( this, "" , 0 ); 2132 KRES::KCMKResources dlg( this, "" , 0 );
2133 2133
2134 if ( !dlg.exec() ) 2134 if ( !dlg.exec() )
2135 return; 2135 return;
2136 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); 2136 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") );
2137} 2137}
2138#endif //KAB_EMBEDDED 2138#endif //KAB_EMBEDDED
2139 2139
2140 2140
2141/* this method will be called through the QCop interface from Ko/Pi to select addresses 2141/* this method will be called through the QCop interface from Ko/Pi to select addresses
2142 * for the attendees list of an event. 2142 * for the attendees list of an event.
2143 */ 2143 */
2144void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) 2144void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid)
2145{ 2145{
2146 QStringList nameList; 2146 QStringList nameList;
2147 QStringList emailList; 2147 QStringList emailList;
2148 QStringList uidList; 2148 QStringList uidList;
2149 2149
2150 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); 2150 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this);
2151 uint i=0; 2151 uint i=0;
2152 for (i=0; i < list.count(); i++) 2152 for (i=0; i < list.count(); i++)
2153 { 2153 {
2154 nameList.append(list[i].realName()); 2154 nameList.append(list[i].realName());
2155 emailList.append(list[i].preferredEmail()); 2155 emailList.append(list[i].preferredEmail());
2156 uidList.append(list[i].uid()); 2156 uidList.append(list[i].uid());
2157 } 2157 }
2158 2158
2159 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); 2159 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList);
2160 2160
2161} 2161}
2162 2162
2163/* this method will be called through the QCop interface from Ko/Pi to select birthdays 2163/* this method will be called through the QCop interface from Ko/Pi to select birthdays
2164 * to put them into the calendar. 2164 * to put them into the calendar.
2165 */ 2165 */
2166void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid) 2166void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid)
2167{ 2167{
2168 // qDebug("KABCore::requestForBirthdayList"); 2168 // qDebug("KABCore::requestForBirthdayList");
2169 QStringList birthdayList; 2169 QStringList birthdayList;
2170 QStringList anniversaryList; 2170 QStringList anniversaryList;
2171 QStringList realNameList; 2171 QStringList realNameList;
2172 QStringList preferredEmailList; 2172 QStringList preferredEmailList;
2173 QStringList assembledNameList; 2173 QStringList assembledNameList;
2174 QStringList uidList; 2174 QStringList uidList;
2175 2175
2176 KABC::AddressBook::Iterator it; 2176 KABC::AddressBook::Iterator it;
2177 2177
2178 int count = 0; 2178 int count = 0;
2179 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { 2179 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
2180 ++count; 2180 ++count;
2181 } 2181 }
2182 QProgressBar bar(count,0 ); 2182 QProgressBar bar(count,0 );
2183 int w = 300; 2183 int w = 300;
2184 if ( QApplication::desktop()->width() < 320 ) 2184 if ( QApplication::desktop()->width() < 320 )
2185 w = 220; 2185 w = 220;
2186 int h = bar.sizeHint().height() ; 2186 int h = bar.sizeHint().height() ;
2187 int dw = QApplication::desktop()->width(); 2187 int dw = QApplication::desktop()->width();
2188 int dh = QApplication::desktop()->height(); 2188 int dh = QApplication::desktop()->height();
2189 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2189 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2190 bar.show(); 2190 bar.show();
2191 bar.setCaption (i18n("Collecting birthdays - close to abort!") ); 2191 bar.setCaption (i18n("Collecting birthdays - close to abort!") );
2192 qApp->processEvents(); 2192 qApp->processEvents();
2193 2193
2194 QDate bday; 2194 QDate bday;
2195 QString anni; 2195 QString anni;
2196 QString formattedbday; 2196 QString formattedbday;
2197 2197
2198 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) 2198 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it )
2199 { 2199 {
2200 if ( ! bar.isVisible() ) 2200 if ( ! bar.isVisible() )
2201 return; 2201 return;
2202 bar.setProgress( count++ ); 2202 bar.setProgress( count++ );
2203 qApp->processEvents(); 2203 qApp->processEvents();
2204 bday = (*it).birthday().date(); 2204 bday = (*it).birthday().date();
2205 anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" ); 2205 anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" );
2206 2206
2207 if ( bday.isValid() || !anni.isEmpty()) 2207 if ( bday.isValid() || !anni.isEmpty())
2208 { 2208 {
2209 if (bday.isValid()) 2209 if (bday.isValid())
2210 formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate); 2210 formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate);
2211 else 2211 else
2212 formattedbday = "NOTVALID"; 2212 formattedbday = "NOTVALID";
2213 if (anni.isEmpty()) 2213 if (anni.isEmpty())
2214 anni = "INVALID"; 2214 anni = "INVALID";
2215 2215
2216 birthdayList.append(formattedbday); 2216 birthdayList.append(formattedbday);
2217 anniversaryList.append(anni); //should be ISODate 2217 anniversaryList.append(anni); //should be ISODate
2218 realNameList.append((*it).realName()); 2218 realNameList.append((*it).realName());
2219 preferredEmailList.append((*it).preferredEmail()); 2219 preferredEmailList.append((*it).preferredEmail());
2220 assembledNameList.append((*it).assembledName()); 2220 assembledNameList.append((*it).assembledName());
2221 uidList.append((*it).uid()); 2221 uidList.append((*it).uid());
2222 2222
2223 qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() ); 2223 qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() );
2224 } 2224 }
2225 } 2225 }
2226 2226
2227 bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList); 2227 bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList);
2228 2228
2229} 2229}
2230 2230
2231/* this method will be called through the QCop interface from other apps to show details of a contact. 2231/* this method will be called through the QCop interface from other apps to show details of a contact.
2232 */ 2232 */
2233void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) 2233void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid)
2234{ 2234{
2235 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); 2235 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1());
2236 2236
2237 QString foundUid = QString::null; 2237 QString foundUid = QString::null;
2238 if ( ! uid.isEmpty() ) { 2238 if ( ! uid.isEmpty() ) {
2239 Addressee adrr = mAddressBook->findByUid( uid ); 2239 Addressee adrr = mAddressBook->findByUid( uid );
2240 if ( !adrr.isEmpty() ) { 2240 if ( !adrr.isEmpty() ) {
2241 foundUid = uid; 2241 foundUid = uid;
2242 } 2242 }
2243 if ( email == "sendbacklist" ) { 2243 if ( email == "sendbacklist" ) {
2244 //qDebug("ssssssssssssssssssssssend "); 2244 //qDebug("ssssssssssssssssssssssend ");
2245 QStringList nameList; 2245 QStringList nameList;
2246 QStringList emailList; 2246 QStringList emailList;
2247 QStringList uidList; 2247 QStringList uidList;
2248 nameList.append(adrr.realName()); 2248 nameList.append(adrr.realName());
2249 emailList = adrr.emails(); 2249 emailList = adrr.emails();
2250 uidList.append( adrr.preferredEmail()); 2250 uidList.append( adrr.preferredEmail());
2251 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); 2251 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList);
2252 return; 2252 return;
2253 } 2253 }
2254 2254
2255 } 2255 }
2256 2256
2257 if ( email == "sendbacklist" ) 2257 if ( email == "sendbacklist" )
2258 return; 2258 return;
2259 if (foundUid.isEmpty()) 2259 if (foundUid.isEmpty())
2260 { 2260 {
2261 //find the uid of the person first 2261 //find the uid of the person first
2262 Addressee::List namelist; 2262 Addressee::List namelist;
2263 Addressee::List emaillist; 2263 Addressee::List emaillist;
2264 2264
2265 if (!name.isEmpty()) 2265 if (!name.isEmpty())
2266 namelist = mAddressBook->findByName( name ); 2266 namelist = mAddressBook->findByName( name );
2267 2267
2268 if (!email.isEmpty()) 2268 if (!email.isEmpty())
2269 emaillist = mAddressBook->findByEmail( email ); 2269 emaillist = mAddressBook->findByEmail( email );
2270 qDebug("count %d %d ", namelist.count(),emaillist.count() ); 2270 qDebug("count %d %d ", namelist.count(),emaillist.count() );
2271 //check if we have a match in Namelist and Emaillist 2271 //check if we have a match in Namelist and Emaillist
2272 if ((namelist.count() == 0) && (emaillist.count() > 0)) { 2272 if ((namelist.count() == 0) && (emaillist.count() > 0)) {
2273 foundUid = emaillist[0].uid(); 2273 foundUid = emaillist[0].uid();
2274 } 2274 }
2275 else if ((namelist.count() > 0) && (emaillist.count() == 0)) 2275 else if ((namelist.count() > 0) && (emaillist.count() == 0))
2276 foundUid = namelist[0].uid(); 2276 foundUid = namelist[0].uid();
2277 else 2277 else
2278 { 2278 {
2279 for (int i = 0; i < namelist.count(); i++) 2279 for (int i = 0; i < namelist.count(); i++)
2280 { 2280 {
2281 for (int j = 0; j < emaillist.count(); j++) 2281 for (int j = 0; j < emaillist.count(); j++)
2282 { 2282 {
2283 if (namelist[i] == emaillist[j]) 2283 if (namelist[i] == emaillist[j])
2284 { 2284 {
2285 foundUid = namelist[i].uid(); 2285 foundUid = namelist[i].uid();
2286 } 2286 }
2287 } 2287 }
2288 } 2288 }
2289 } 2289 }
2290 } 2290 }
2291 else 2291 else
2292 { 2292 {
2293 foundUid = uid; 2293 foundUid = uid;
2294 } 2294 }
2295 2295
2296 if (!foundUid.isEmpty()) 2296 if (!foundUid.isEmpty())
2297 { 2297 {
2298 2298
2299 // raise Ka/Pi if it is in the background 2299 // raise Ka/Pi if it is in the background
2300#ifndef DESKTOP_VERSION 2300#ifndef DESKTOP_VERSION
2301#ifndef KORG_NODCOP 2301#ifndef KORG_NODCOP
2302 //QCopEnvelope e("QPE/Application/kapi", "raise()"); 2302 //QCopEnvelope e("QPE/Application/kapi", "raise()");
2303#endif 2303#endif
2304#endif 2304#endif
2305 2305
2306 mMainWindow->showMaximized(); 2306 mMainWindow->showMaximized();
2307 mMainWindow-> raise(); 2307 mMainWindow-> raise();
2308 2308
2309 mViewManager->setSelected( "", false); 2309 mViewManager->setSelected( "", false);
2310 mViewManager->refreshView( "" ); 2310 mViewManager->refreshView( "" );
2311 mViewManager->setSelected( foundUid, true ); 2311 mViewManager->setSelected( foundUid, true );
2312 mViewManager->refreshView( foundUid ); 2312 mViewManager->refreshView( foundUid );
2313 2313
2314 if ( !mMultipleViewsAtOnce ) 2314 if ( !mMultipleViewsAtOnce )
2315 { 2315 {
2316 setDetailsVisible( true ); 2316 setDetailsVisible( true );
2317 mActionDetails->setChecked(true); 2317 mActionDetails->setChecked(true);
2318 } 2318 }
2319 } 2319 }
2320} 2320}
2321 2321
2322void KABCore::whatsnew() 2322void KABCore::whatsnew()
2323{ 2323{
2324 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); 2324 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" );
2325} 2325}
2326void KABCore::synchowto() 2326void KABCore::synchowto()
2327{ 2327{
2328 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); 2328 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" );
2329} 2329}
2330 2330
2331void KABCore::faq() 2331void KABCore::faq()
2332{ 2332{
2333 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); 2333 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" );
2334} 2334}
2335 2335
2336#include <libkcal/syncdefines.h> 2336#include <libkcal/syncdefines.h>
2337 2337
2338KABC::Addressee KABCore::getLastSyncAddressee() 2338KABC::Addressee KABCore::getLastSyncAddressee()
2339{ 2339{
2340 Addressee lse; 2340 Addressee lse;
2341 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2341 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2342 2342
2343 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2343 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2344 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2344 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2345 if (lse.isEmpty()) { 2345 if (lse.isEmpty()) {
2346 qDebug("Creating new last-syncAddressee "); 2346 qDebug("Creating new last-syncAddressee ");
2347 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2347 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice );
2348 QString sum = ""; 2348 QString sum = "";
2349 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2349 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2350 sum = "E: "; 2350 sum = "E: ";
2351 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); 2351 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
2352 lse.setRevision( mLastAddressbookSync ); 2352 lse.setRevision( mLastAddressbookSync );
2353 lse.setCategories( i18n("SyncEvent") ); 2353 lse.setCategories( i18n("SyncEvent") );
2354 mAddressBook->insertAddressee( lse ); 2354 mAddressBook->insertAddressee( lse );
2355 } 2355 }
2356 return lse; 2356 return lse;
2357} 2357}
2358int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) 2358int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
2359{ 2359{
2360 2360
2361 //void setZaurusId(int id); 2361 //void setZaurusId(int id);
2362 // int zaurusId() const; 2362 // int zaurusId() const;
2363 // void setZaurusUid(int id); 2363 // void setZaurusUid(int id);
2364 // int zaurusUid() const; 2364 // int zaurusUid() const;
2365 // void setZaurusStat(int id); 2365 // void setZaurusStat(int id);
2366 // int zaurusStat() const; 2366 // int zaurusStat() const;
2367 // 0 equal 2367 // 0 equal
2368 // 1 take local 2368 // 1 take local
2369 // 2 take remote 2369 // 2 take remote
2370 // 3 cancel 2370 // 3 cancel
2371 QDateTime lastSync = mLastAddressbookSync; 2371 QDateTime lastSync = mLastAddressbookSync;
2372 QDateTime localMod = local->revision(); 2372 QDateTime localMod = local->revision();
2373 QDateTime remoteMod = remote->revision(); 2373 QDateTime remoteMod = remote->revision();
2374 2374
2375 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2375 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2376 2376
2377 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2377 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2378 bool remCh, locCh; 2378 bool remCh, locCh;
2379 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 2379 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
2380 2380
2381 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 2381 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
2382 locCh = ( localMod > mLastAddressbookSync ); 2382 locCh = ( localMod > mLastAddressbookSync );
2383 if ( !remCh && ! locCh ) { 2383 if ( !remCh && ! locCh ) {
2384 //qDebug("both not changed "); 2384 //qDebug("both not changed ");
2385 lastSync = localMod.addDays(1); 2385 lastSync = localMod.addDays(1);
2386 if ( mode <= SYNC_PREF_ASK ) 2386 if ( mode <= SYNC_PREF_ASK )
2387 return 0; 2387 return 0;
2388 } else { 2388 } else {
2389 if ( locCh ) { 2389 if ( locCh ) {
2390 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); 2390 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1());
2391 lastSync = localMod.addDays( -1 ); 2391 lastSync = localMod.addDays( -1 );
2392 if ( !remCh ) 2392 if ( !remCh )
2393 remoteMod =( lastSync.addDays( -1 ) ); 2393 remoteMod =( lastSync.addDays( -1 ) );
2394 } else { 2394 } else {
2395 //qDebug(" not loc changed "); 2395 //qDebug(" not loc changed ");
2396 lastSync = localMod.addDays( 1 ); 2396 lastSync = localMod.addDays( 1 );
2397 if ( remCh ) 2397 if ( remCh )
2398 remoteMod =( lastSync.addDays( 1 ) ); 2398 remoteMod =( lastSync.addDays( 1 ) );
2399 2399
2400 } 2400 }
2401 } 2401 }
2402 full = true; 2402 full = true;
2403 if ( mode < SYNC_PREF_ASK ) 2403 if ( mode < SYNC_PREF_ASK )
2404 mode = SYNC_PREF_ASK; 2404 mode = SYNC_PREF_ASK;
2405 } else { 2405 } else {
2406 if ( localMod == remoteMod ) 2406 if ( localMod == remoteMod )
2407 return 0; 2407 return 0;
2408 2408
2409 } 2409 }
2410 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 2410 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
2411 2411
2412 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 2412 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
2413 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 2413 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
2414 //full = true; //debug only 2414 //full = true; //debug only
2415 if ( full ) { 2415 if ( full ) {
2416 bool equ = ( (*local) == (*remote) ); 2416 bool equ = ( (*local) == (*remote) );
2417 if ( equ ) { 2417 if ( equ ) {
2418 //qDebug("equal "); 2418 //qDebug("equal ");
2419 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2419 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2420 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2420 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2421 } 2421 }
2422 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2422 if ( mode < SYNC_PREF_FORCE_LOCAL )
2423 return 0; 2423 return 0;
2424 2424
2425 }//else //debug only 2425 }//else //debug only
2426 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 2426 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
2427 } 2427 }
2428 int result; 2428 int result;
2429 bool localIsNew; 2429 bool localIsNew;
2430 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 2430 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
2431 2431
2432 if ( full && mode < SYNC_PREF_NEWEST ) 2432 if ( full && mode < SYNC_PREF_NEWEST )
2433 mode = SYNC_PREF_ASK; 2433 mode = SYNC_PREF_ASK;
2434 2434
2435 switch( mode ) { 2435 switch( mode ) {
2436 case SYNC_PREF_LOCAL: 2436 case SYNC_PREF_LOCAL:
2437 if ( lastSync > remoteMod ) 2437 if ( lastSync > remoteMod )
2438 return 1; 2438 return 1;
2439 if ( lastSync > localMod ) 2439 if ( lastSync > localMod )
2440 return 2; 2440 return 2;
2441 return 1; 2441 return 1;
2442 break; 2442 break;
2443 case SYNC_PREF_REMOTE: 2443 case SYNC_PREF_REMOTE:
2444 if ( lastSync > remoteMod ) 2444 if ( lastSync > remoteMod )
2445 return 1; 2445 return 1;
2446 if ( lastSync > localMod ) 2446 if ( lastSync > localMod )
2447 return 2; 2447 return 2;
2448 return 2; 2448 return 2;
2449 break; 2449 break;
2450 case SYNC_PREF_NEWEST: 2450 case SYNC_PREF_NEWEST:
2451 if ( localMod > remoteMod ) 2451 if ( localMod > remoteMod )
2452 return 1; 2452 return 1;
2453 else 2453 else
2454 return 2; 2454 return 2;
2455 break; 2455 break;
2456 case SYNC_PREF_ASK: 2456 case SYNC_PREF_ASK:
2457 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 2457 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
2458 if ( lastSync > remoteMod ) 2458 if ( lastSync > remoteMod )
2459 return 1; 2459 return 1;
2460 if ( lastSync > localMod ) 2460 if ( lastSync > localMod )
2461 return 2; 2461 return 2;
2462 localIsNew = localMod >= remoteMod; 2462 localIsNew = localMod >= remoteMod;
2463 //qDebug("conflict! ************************************** "); 2463 //qDebug("conflict! ************************************** ");
2464 { 2464 {
2465 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2465 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2466 result = acd.executeD(localIsNew); 2466 result = acd.executeD(localIsNew);
2467 return result; 2467 return result;
2468 } 2468 }
2469 break; 2469 break;
2470 case SYNC_PREF_FORCE_LOCAL: 2470 case SYNC_PREF_FORCE_LOCAL:
2471 return 1; 2471 return 1;
2472 break; 2472 break;
2473 case SYNC_PREF_FORCE_REMOTE: 2473 case SYNC_PREF_FORCE_REMOTE:
2474 return 2; 2474 return 2;
2475 break; 2475 break;
2476 2476
2477 default: 2477 default:
2478 // SYNC_PREF_TAKE_BOTH not implemented 2478 // SYNC_PREF_TAKE_BOTH not implemented
2479 break; 2479 break;
2480 } 2480 }
2481 return 0; 2481 return 0;
2482} 2482}
2483 2483
2484 2484
2485bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2485bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2486{ 2486{
2487 bool syncOK = true; 2487 bool syncOK = true;
2488 int addedAddressee = 0; 2488 int addedAddressee = 0;
2489 int addedAddresseeR = 0; 2489 int addedAddresseeR = 0;
2490 int deletedAddresseeR = 0; 2490 int deletedAddresseeR = 0;
2491 int deletedAddresseeL = 0; 2491 int deletedAddresseeL = 0;
2492 int changedLocal = 0; 2492 int changedLocal = 0;
2493 int changedRemote = 0; 2493 int changedRemote = 0;
2494 2494
2495 QString mCurrentSyncName = syncManager->getCurrentSyncName(); 2495 QString mCurrentSyncName = syncManager->getCurrentSyncName();
2496 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2496 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2497 2497
2498 //QPtrList<Addressee> el = local->rawAddressees(); 2498 //QPtrList<Addressee> el = local->rawAddressees();
2499 Addressee addresseeR; 2499 Addressee addresseeR;
2500 QString uid; 2500 QString uid;
2501 int take; 2501 int take;
2502 Addressee addresseeL; 2502 Addressee addresseeL;
2503 Addressee addresseeRSync; 2503 Addressee addresseeRSync;
2504 Addressee addresseeLSync; 2504 Addressee addresseeLSync;
2505 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2505 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2506 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2506 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2507 bool fullDateRange = false; 2507 bool fullDateRange = false;
2508 local->resetTempSyncStat(); 2508 local->resetTempSyncStat();
2509 mLastAddressbookSync = QDateTime::currentDateTime(); 2509 mLastAddressbookSync = QDateTime::currentDateTime();
2510 QDateTime modifiedCalendar = mLastAddressbookSync;; 2510 QDateTime modifiedCalendar = mLastAddressbookSync;;
2511 addresseeLSync = getLastSyncAddressee(); 2511 addresseeLSync = getLastSyncAddressee();
2512 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2512 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2513 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2513 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2514 if ( !addresseeR.isEmpty() ) { 2514 if ( !addresseeR.isEmpty() ) {
2515 addresseeRSync = addresseeR; 2515 addresseeRSync = addresseeR;
2516 remote->removeAddressee(addresseeR ); 2516 remote->removeAddressee(addresseeR );
2517 2517
2518 } else { 2518 } else {
2519 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2519 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2520 addresseeRSync = addresseeLSync ; 2520 addresseeRSync = addresseeLSync ;
2521 } else { 2521 } else {
2522 qDebug("FULLDATE 1"); 2522 qDebug("FULLDATE 1");
2523 fullDateRange = true; 2523 fullDateRange = true;
2524 Addressee newAdd; 2524 Addressee newAdd;
2525 addresseeRSync = newAdd; 2525 addresseeRSync = newAdd;
2526 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2526 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2527 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2527 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2528 addresseeRSync.setRevision( mLastAddressbookSync ); 2528 addresseeRSync.setRevision( mLastAddressbookSync );
2529 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2529 addresseeRSync.setCategories( i18n("SyncAddressee") );
2530 } 2530 }
2531 } 2531 }
2532 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2532 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2533 qDebug("FULLDATE 2"); 2533 qDebug("FULLDATE 2");
2534 fullDateRange = true; 2534 fullDateRange = true;
2535 } 2535 }
2536 if ( ! fullDateRange ) { 2536 if ( ! fullDateRange ) {
2537 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2537 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2538 2538
2539 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2539 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2540 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2540 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2541 fullDateRange = true; 2541 fullDateRange = true;
2542 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2542 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2543 } 2543 }
2544 } 2544 }
2545 // fullDateRange = true; // debug only! 2545 // fullDateRange = true; // debug only!
2546 if ( fullDateRange ) 2546 if ( fullDateRange )
2547 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2547 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2548 else 2548 else
2549 mLastAddressbookSync = addresseeLSync.revision(); 2549 mLastAddressbookSync = addresseeLSync.revision();
2550 // for resyncing if own file has changed 2550 // for resyncing if own file has changed
2551 // PENDING fixme later when implemented 2551 // PENDING fixme later when implemented
2552#if 0 2552#if 0
2553 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2553 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2554 mLastAddressbookSync = loadedFileVersion; 2554 mLastAddressbookSync = loadedFileVersion;
2555 qDebug("setting mLastAddressbookSync "); 2555 qDebug("setting mLastAddressbookSync ");
2556 } 2556 }
2557#endif 2557#endif
2558 2558
2559 //qDebug("*************************** "); 2559 //qDebug("*************************** ");
2560 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2560 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2561 QStringList er = remote->uidList(); 2561 QStringList er = remote->uidList();
2562 Addressee inR ;//= er.first(); 2562 Addressee inR ;//= er.first();
2563 Addressee inL; 2563 Addressee inL;
2564 2564
2565 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 2565 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2566 2566
2567 int modulo = (er.count()/10)+1; 2567 int modulo = (er.count()/10)+1;
2568 int incCounter = 0; 2568 int incCounter = 0;
2569 while ( incCounter < er.count()) { 2569 while ( incCounter < er.count()) {
2570 if (syncManager->isProgressBarCanceled()) 2570 if (syncManager->isProgressBarCanceled())
2571 return false; 2571 return false;
2572 if ( incCounter % modulo == 0 ) 2572 if ( incCounter % modulo == 0 )
2573 syncManager->showProgressBar(incCounter); 2573 syncManager->showProgressBar(incCounter);
2574 2574
2575 uid = er[ incCounter ]; 2575 uid = er[ incCounter ];
2576 bool skipIncidence = false; 2576 bool skipIncidence = false;
2577 if ( uid.left(19) == QString("last-syncAddressee-") ) 2577 if ( uid.left(19) == QString("last-syncAddressee-") )
2578 skipIncidence = true; 2578 skipIncidence = true;
2579 QString idS,OidS; 2579 QString idS,OidS;
2580 qApp->processEvents(); 2580 qApp->processEvents();
2581 if ( !skipIncidence ) { 2581 if ( !skipIncidence ) {
2582 inL = local->findByUid( uid ); 2582 inL = local->findByUid( uid );
2583 inR = remote->findByUid( uid ); 2583 inR = remote->findByUid( uid );
2584 //inL.setResource( 0 ); 2584 //inL.setResource( 0 );
2585 //inR.setResource( 0 ); 2585 //inR.setResource( 0 );
2586 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2586 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2587 if ( !inL.resource() || inL.resource()->includeInSync() ) { 2587 if ( !inL.resource() || inL.resource()->includeInSync() ) {
2588 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2588 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2589 //qDebug("take %d %s ", take, inL.summary().latin1()); 2589 //qDebug("take %d %s ", take, inL.summary().latin1());
2590 if ( take == 3 ) 2590 if ( take == 3 )
2591 return false; 2591 return false;
2592 if ( take == 1 ) {// take local 2592 if ( take == 1 ) {// take local
2593 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2593 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2594 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2594 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2595 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2595 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2596 local->insertAddressee( inL, false ); 2596 local->insertAddressee( inL, false );
2597 idS = inR.externalUID(); 2597 idS = inR.externalUID();
2598 OidS = inR.originalExternalUID(); 2598 OidS = inR.originalExternalUID();
2599 } 2599 }
2600 else 2600 else
2601 idS = inR.IDStr(); 2601 idS = inR.IDStr();
2602 remote->removeAddressee( inR ); 2602 remote->removeAddressee( inR );
2603 inR = inL; 2603 inR = inL;
2604 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2604 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2605 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2605 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2606 inR.setOriginalExternalUID( OidS ); 2606 inR.setOriginalExternalUID( OidS );
2607 inR.setExternalUID( idS ); 2607 inR.setExternalUID( idS );
2608 } else { 2608 } else {
2609 inR.setIDStr( idS ); 2609 inR.setIDStr( idS );
2610 } 2610 }
2611 inR.setResource( 0 ); 2611 inR.setResource( 0 );
2612 remote->insertAddressee( inR , false); 2612 remote->insertAddressee( inR , false);
2613 ++changedRemote; 2613 ++changedRemote;
2614 } else { // take == 2 take remote 2614 } else { // take == 2 take remote
2615 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2615 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2616 if ( inR.revision().date().year() < 2004 ) 2616 if ( inR.revision().date().year() < 2004 )
2617 inR.setRevision( modifiedCalendar ); 2617 inR.setRevision( modifiedCalendar );
2618 } 2618 }
2619 idS = inL.IDStr(); 2619 idS = inL.IDStr();
2620 local->removeAddressee( inL ); 2620 local->removeAddressee( inL );
2621 inL = inR; 2621 inL = inR;
2622 inL.setIDStr( idS ); 2622 inL.setIDStr( idS );
2623 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2623 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2624 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2624 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2625 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2625 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2626 } 2626 }
2627 inL.setResource( 0 ); 2627 inL.setResource( 0 );
2628 local->insertAddressee( inL , false ); 2628 local->insertAddressee( inL , false );
2629 ++changedLocal; 2629 ++changedLocal;
2630 } 2630 }
2631 } 2631 }
2632 } 2632 }
2633 } else { // no conflict 2633 } else { // no conflict
2634 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2634 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2635 QString des = addresseeLSync.note(); 2635 QString des = addresseeLSync.note();
2636 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2636 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2637 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2637 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2638 remote->insertAddressee( inR, false ); 2638 remote->insertAddressee( inR, false );
2639 ++deletedAddresseeR; 2639 ++deletedAddresseeR;
2640 } else { 2640 } else {
2641 inR.setRevision( modifiedCalendar ); 2641 inR.setRevision( modifiedCalendar );
2642 remote->insertAddressee( inR, false ); 2642 remote->insertAddressee( inR, false );
2643 inL = inR; 2643 inL = inR;
2644 inL.setResource( 0 ); 2644 inL.setResource( 0 );
2645 local->insertAddressee( inL , false); 2645 local->insertAddressee( inL , false);
2646 ++addedAddressee; 2646 ++addedAddressee;
2647 } 2647 }
2648 } else { 2648 } else {
2649 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2649 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2650 inR.setRevision( modifiedCalendar ); 2650 inR.setRevision( modifiedCalendar );
2651 remote->insertAddressee( inR, false ); 2651 remote->insertAddressee( inR, false );
2652 inR.setResource( 0 ); 2652 inR.setResource( 0 );
2653 local->insertAddressee( inR, false ); 2653 local->insertAddressee( inR, false );
2654 ++addedAddressee; 2654 ++addedAddressee;
2655 } else { 2655 } else {
2656 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2656 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2657 remote->removeAddressee( inR ); 2657 remote->removeAddressee( inR );
2658 ++deletedAddresseeR; 2658 ++deletedAddresseeR;
2659 } 2659 }
2660 } 2660 }
2661 } 2661 }
2662 } 2662 }
2663 ++incCounter; 2663 ++incCounter;
2664 } 2664 }
2665 er.clear(); 2665 er.clear();
2666 QStringList el = local->uidList(); 2666 QStringList el = local->uidList();
2667 modulo = (el.count()/10)+1; 2667 modulo = (el.count()/10)+1;
2668 2668
2669 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 2669 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2670 incCounter = 0; 2670 incCounter = 0;
2671 while ( incCounter < el.count()) { 2671 while ( incCounter < el.count()) {
2672 qApp->processEvents(); 2672 qApp->processEvents();
2673 if (syncManager->isProgressBarCanceled()) 2673 if (syncManager->isProgressBarCanceled())
2674 return false; 2674 return false;
2675 if ( incCounter % modulo == 0 ) 2675 if ( incCounter % modulo == 0 )
2676 syncManager->showProgressBar(incCounter); 2676 syncManager->showProgressBar(incCounter);
2677 uid = el[ incCounter ]; 2677 uid = el[ incCounter ];
2678 bool skipIncidence = false; 2678 bool skipIncidence = false;
2679 if ( uid.left(19) == QString("last-syncAddressee-") ) 2679 if ( uid.left(19) == QString("last-syncAddressee-") )
2680 skipIncidence = true; 2680 skipIncidence = true;
2681 if ( !skipIncidence ) { 2681 if ( !skipIncidence ) {
2682 inL = local->findByUid( uid ); 2682 inL = local->findByUid( uid );
2683 if ( !inL.resource() || inL.resource()->includeInSync() ) { 2683 if ( !inL.resource() || inL.resource()->includeInSync() ) {
2684 inR = remote->findByUid( uid ); 2684 inR = remote->findByUid( uid );
2685 if ( inR.isEmpty() ) { 2685 if ( inR.isEmpty() ) {
2686 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2686 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2687 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2687 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2688 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2688 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2689 local->removeAddressee( inL ); 2689 local->removeAddressee( inL );
2690 ++deletedAddresseeL; 2690 ++deletedAddresseeL;
2691 } else { 2691 } else {
2692 if ( ! syncManager->mWriteBackExistingOnly ) { 2692 if ( ! syncManager->mWriteBackExistingOnly ) {
2693 inL.removeID(mCurrentSyncDevice ); 2693 inL.removeID(mCurrentSyncDevice );
2694 ++addedAddresseeR; 2694 ++addedAddresseeR;
2695 inL.setRevision( modifiedCalendar ); 2695 inL.setRevision( modifiedCalendar );
2696 local->insertAddressee( inL, false ); 2696 local->insertAddressee( inL, false );
2697 inR = inL; 2697 inR = inL;
2698 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); 2698 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
2699 inR.setResource( 0 ); 2699 inR.setResource( 0 );
2700 remote->insertAddressee( inR, false ); 2700 remote->insertAddressee( inR, false );
2701 } 2701 }
2702 } 2702 }
2703 } else { 2703 } else {
2704 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2704 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2705 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2705 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2706 local->removeAddressee( inL ); 2706 local->removeAddressee( inL );
2707 ++deletedAddresseeL; 2707 ++deletedAddresseeL;
2708 } else { 2708 } else {
2709 if ( ! syncManager->mWriteBackExistingOnly ) { 2709 if ( ! syncManager->mWriteBackExistingOnly ) {
2710 ++addedAddresseeR; 2710 ++addedAddresseeR;
2711 inL.setRevision( modifiedCalendar ); 2711 inL.setRevision( modifiedCalendar );
2712 local->insertAddressee( inL, false ); 2712 local->insertAddressee( inL, false );
2713 inR = inL; 2713 inR = inL;
2714 inR.setResource( 0 ); 2714 inR.setResource( 0 );
2715 remote->insertAddressee( inR, false ); 2715 remote->insertAddressee( inR, false );
2716 } 2716 }
2717 } 2717 }
2718 } 2718 }
2719 } 2719 }
2720 } 2720 }
2721 } 2721 }
2722 ++incCounter; 2722 ++incCounter;
2723 } 2723 }
2724 el.clear(); 2724 el.clear();
2725 syncManager->hideProgressBar(); 2725 syncManager->hideProgressBar();
2726 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2726 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2727 // get rid of micro seconds 2727 // get rid of micro seconds
2728 QTime t = mLastAddressbookSync.time(); 2728 QTime t = mLastAddressbookSync.time();
2729 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2729 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2730 addresseeLSync.setRevision( mLastAddressbookSync ); 2730 addresseeLSync.setRevision( mLastAddressbookSync );
2731 addresseeRSync.setRevision( mLastAddressbookSync ); 2731 addresseeRSync.setRevision( mLastAddressbookSync );
2732 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2732 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2733 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2733 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2734 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2734 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2735 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2735 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2736 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2736 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2737 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2737 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2738 addresseeRSync.setNote( "" ) ; 2738 addresseeRSync.setNote( "" ) ;
2739 addresseeLSync.setNote( "" ); 2739 addresseeLSync.setNote( "" );
2740 2740
2741 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2741 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2742 remote->insertAddressee( addresseeRSync, false ); 2742 remote->insertAddressee( addresseeRSync, false );
2743 local->insertAddressee( addresseeLSync, false ); 2743 local->insertAddressee( addresseeLSync, false );
2744 QString mes; 2744 QString mes;
2745 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 ); 2745 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 );
2746 if ( syncManager->mShowSyncSummary ) { 2746 if ( syncManager->mShowSyncSummary ) {
2747 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2747 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2748 } 2748 }
2749 qDebug( mes ); 2749 qDebug( mes );
2750 return syncOK; 2750 return syncOK;
2751} 2751}
2752 2752
2753 2753
2754//this is a overwritten callbackmethods from the syncinterface 2754//this is a overwritten callbackmethods from the syncinterface
2755bool KABCore::sync(KSyncManager* manager, QString filename, int mode) 2755bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
2756{ 2756{
2757 2757
2758 //pending prepare addresseeview for output 2758 //pending prepare addresseeview for output
2759 //pending detect, if remote file has REV field. if not switch to external sync 2759 //pending detect, if remote file has REV field. if not switch to external sync
2760 mGlobalSyncMode = SYNC_MODE_NORMAL; 2760 mGlobalSyncMode = SYNC_MODE_NORMAL;
2761 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2761 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2762 2762
2763 AddressBook abLocal(filename,"syncContact"); 2763 AddressBook abLocal(filename,"syncContact");
2764 bool syncOK = false; 2764 bool syncOK = false;
2765 if ( abLocal.load() ) { 2765 if ( abLocal.load() ) {
2766 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); 2766 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
2767 bool external = false; 2767 bool external = false;
2768 bool isXML = false; 2768 bool isXML = false;
2769 if ( filename.right(4) == ".xml") { 2769 if ( filename.right(4) == ".xml") {
2770 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2770 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2771 isXML = true; 2771 isXML = true;
2772 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 2772 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
2773 } else { 2773 } else {
2774 external = !manager->mIsKapiFile; 2774 external = !manager->mIsKapiFile;
2775 if ( external ) { 2775 if ( external ) {
2776 qDebug("Setting vcf mode to external "); 2776 qDebug("Setting vcf mode to external ");
2777 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2777 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2778 AddressBook::Iterator it; 2778 AddressBook::Iterator it;
2779 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2779 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2780 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2780 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2781 (*it).computeCsum( mCurrentSyncDevice ); 2781 (*it).computeCsum( mCurrentSyncDevice );
2782 } 2782 }
2783 } 2783 }
2784 } 2784 }
2785 //AddressBook::Iterator it; 2785 //AddressBook::Iterator it;
2786 //QStringList vcards; 2786 //QStringList vcards;
2787 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2787 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2788 // qDebug("Name %s ", (*it).familyName().latin1()); 2788 // qDebug("Name %s ", (*it).familyName().latin1());
2789 //} 2789 //}
2790 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2790 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2791 if ( syncOK ) { 2791 if ( syncOK ) {
2792 if ( syncManager->mWriteBackFile ) 2792 if ( syncManager->mWriteBackFile )
2793 { 2793 {
2794 if ( external ) 2794 if ( external )
2795 abLocal.removeSyncAddressees( !isXML); 2795 abLocal.removeSyncAddressees( !isXML);
2796 qDebug("Saving remote AB "); 2796 qDebug("Saving remote AB ");
2797 if ( ! abLocal.saveAB()) 2797 if ( ! abLocal.saveAB())
2798 qDebug("Error writing back AB to file "); 2798 qDebug("Error writing back AB to file ");
2799 if ( isXML ) { 2799 if ( isXML ) {
2800 // afterwrite processing 2800 // afterwrite processing
2801 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2801 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2802 } 2802 }
2803 } 2803 }
2804 } 2804 }
2805 setModified(); 2805 setModified();
2806 2806
2807 } 2807 }
2808 if ( syncOK ) 2808 if ( syncOK )
2809 mViewManager->refreshView(); 2809 mViewManager->refreshView();
2810 return syncOK; 2810 return syncOK;
2811 2811
2812} 2812}
2813void KABCore::removeSyncInfo( QString syncProfile)
2814{
2815 qDebug("removeSyncInfo for profile %s ", syncProfile.latin1());
2816
2817}
2813 2818
2814 2819
2815//this is a overwritten callbackmethods from the syncinterface 2820//this is a overwritten callbackmethods from the syncinterface
2816bool KABCore::syncExternal(KSyncManager* manager, QString resource) 2821bool KABCore::syncExternal(KSyncManager* manager, QString resource)
2817{ 2822{
2818 if ( resource == "phone" ) 2823 if ( resource == "phone" )
2819 return syncPhone(); 2824 return syncPhone();
2820 disableBR( true ); 2825 disableBR( true );
2821 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2826 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2822 2827
2823 AddressBook abLocal( resource,"syncContact"); 2828 AddressBook abLocal( resource,"syncContact");
2824 bool syncOK = false; 2829 bool syncOK = false;
2825 if ( abLocal.load() ) { 2830 if ( abLocal.load() ) {
2826 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2831 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
2827 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2832 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2828 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); 2833 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false );
2829 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2834 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2830 if ( syncOK ) { 2835 if ( syncOK ) {
2831 if ( syncManager->mWriteBackFile ) { 2836 if ( syncManager->mWriteBackFile ) {
2832 abLocal.removeSyncAddressees( false ); 2837 abLocal.removeSyncAddressees( false );
2833 abLocal.saveAB(); 2838 abLocal.saveAB();
2834 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2839 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2835 } 2840 }
2836 } 2841 }
2837 setModified(); 2842 setModified();
2838 } 2843 }
2839 if ( syncOK ) 2844 if ( syncOK )
2840 mViewManager->refreshView(); 2845 mViewManager->refreshView();
2841 disableBR( false ); 2846 disableBR( false );
2842 return syncOK; 2847 return syncOK;
2843 2848
2844} 2849}
2845void KABCore::message( QString m ) 2850void KABCore::message( QString m )
2846{ 2851{
2847 topLevelWidget()->setCaption( m ); 2852 topLevelWidget()->setCaption( m );
2848 mMessageTimer->start( 15000, true ); 2853 mMessageTimer->start( 15000, true );
2849} 2854}
2850bool KABCore::syncPhone() 2855bool KABCore::syncPhone()
2851{ 2856{
2852 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2857 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2853 QString fileName = getPhoneFile(); 2858 QString fileName = getPhoneFile();
2854 if ( !PhoneAccess::readFromPhone( fileName) ) { 2859 if ( !PhoneAccess::readFromPhone( fileName) ) {
2855 message(i18n("Phone access failed!")); 2860 message(i18n("Phone access failed!"));
2856 return false; 2861 return false;
2857 } 2862 }
2858 AddressBook abLocal( fileName,"syncContact"); 2863 AddressBook abLocal( fileName,"syncContact");
2859 bool syncOK = false; 2864 bool syncOK = false;
2860 { 2865 {
2861 abLocal.importFromFile( fileName ); 2866 abLocal.importFromFile( fileName );
2862 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2867 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
2863 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2868 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2864 abLocal.preparePhoneSync( mCurrentSyncDevice, true ); 2869 abLocal.preparePhoneSync( mCurrentSyncDevice, true );
2865 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 2870 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
2866 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2871 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2867 if ( syncOK ) { 2872 if ( syncOK ) {
2868 if ( syncManager->mWriteBackFile ) { 2873 if ( syncManager->mWriteBackFile ) {
2869 abLocal.removeSyncAddressees( true ); 2874 abLocal.removeSyncAddressees( true );
2870 abLocal.saveABphone( fileName ); 2875 abLocal.saveABphone( fileName );
2871 abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); 2876 abLocal.findNewExtIds( fileName, mCurrentSyncDevice );
2872 //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); 2877 //abLocal.preparePhoneSync( mCurrentSyncDevice, false );
2873 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2878 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2874 } 2879 }
2875 } 2880 }
2876 setModified(); 2881 setModified();
2877 } 2882 }
2878 if ( syncOK ) 2883 if ( syncOK )
2879 mViewManager->refreshView(); 2884 mViewManager->refreshView();
2880 return syncOK; 2885 return syncOK;
2881} 2886}
2882void KABCore::getFile( bool success ) 2887void KABCore::getFile( bool success )
2883{ 2888{
2884 if ( ! success ) { 2889 if ( ! success ) {
2885 message( i18n("Error receiving file. Nothing changed!") ); 2890 message( i18n("Error receiving file. Nothing changed!") );
2886 return; 2891 return;
2887 } 2892 }
2888 int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); 2893 int count = mAddressBook->importFromFile( sentSyncFile() , false, true );
2889 if ( count ) 2894 if ( count )
2890 setModified( true ); 2895 setModified( true );
2891 message( i18n("Pi-Sync successful!") ); 2896 message( i18n("Pi-Sync successful!") );
2892 mViewManager->refreshView(); 2897 mViewManager->refreshView();
2893} 2898}
2894void KABCore::syncFileRequest() 2899void KABCore::syncFileRequest()
2895{ 2900{
2896 mAddressBook->export2File( sentSyncFile() ); 2901 mAddressBook->export2File( sentSyncFile() );
2897} 2902}
2898QString KABCore::sentSyncFile() 2903QString KABCore::sentSyncFile()
2899{ 2904{
2900#ifdef DESKTOP_VERSION 2905#ifdef DESKTOP_VERSION
2901 return locateLocal( "tmp", "copysyncab.vcf" ); 2906 return locateLocal( "tmp", "copysyncab.vcf" );
2902#else 2907#else
2903 return QString( "/tmp/copysyncab.vcf" ); 2908 return QString( "/tmp/copysyncab.vcf" );
2904#endif 2909#endif
2905} 2910}
2906 2911
2907void KABCore::setCaptionBack() 2912void KABCore::setCaptionBack()
2908{ 2913{
2909 mMessageTimer->stop(); 2914 mMessageTimer->stop();
2910 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); 2915 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") );
2911} 2916}
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h
index fcbe1e8..a288505 100644
--- a/kaddressbook/kabcore.h
+++ b/kaddressbook/kabcore.h
@@ -1,502 +1,503 @@
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#ifndef KABCORE_H 24#ifndef KABCORE_H
25#define KABCORE_H 25#define KABCORE_H
26 26
27#include <kabc/field.h> 27#include <kabc/field.h>
28 28
29#ifndef KAB_EMBEDDED 29#ifndef KAB_EMBEDDED
30#endif //KAB_EMBEDDED 30#endif //KAB_EMBEDDED
31#include <qdict.h> 31#include <qdict.h>
32#include <qtimer.h> 32#include <qtimer.h>
33 33
34#include <qwidget.h> 34#include <qwidget.h>
35#include <qpopupmenu.h> 35#include <qpopupmenu.h>
36#include <ksyncmanager.h> 36#include <ksyncmanager.h>
37#ifndef DESKTOP_VERSION 37#ifndef DESKTOP_VERSION
38#include <qcopchannel_qws.h> 38#include <qcopchannel_qws.h>
39#endif 39#endif
40 40
41namespace KABC { 41namespace KABC {
42class AddressBook; 42class AddressBook;
43} 43}
44 44
45#ifndef KAB_EMBEDDED 45#ifndef KAB_EMBEDDED
46class KAboutData; 46class KAboutData;
47class KConfig; 47class KConfig;
48 48
49class KAddressBookService; 49class KAddressBookService;
50class LDAPSearchDialog; 50class LDAPSearchDialog;
51#else //KAB_EMBEDDED 51#else //KAB_EMBEDDED
52class KAddressBookMain; 52class KAddressBookMain;
53//US class QAction; 53//US class QAction;
54#endif //KAB_EMBEDDED 54#endif //KAB_EMBEDDED
55class KCMultiDialog; 55class KCMultiDialog;
56class KXMLGUIClient; 56class KXMLGUIClient;
57class ExtensionManager; 57class ExtensionManager;
58class XXPortManager; 58class XXPortManager;
59class JumpButtonBar; 59class JumpButtonBar;
60class IncSearchWidget; 60class IncSearchWidget;
61class KDGanttMinimizeSplitter; 61class KDGanttMinimizeSplitter;
62class KAction; 62class KAction;
63class KActionCollection; 63class KActionCollection;
64class KToggleAction; 64class KToggleAction;
65class KSyncProfile; 65class KSyncProfile;
66 66
67class QAction; 67class QAction;
68class QMenuBar; 68class QMenuBar;
69class QSplitter; 69class QSplitter;
70class ViewContainer; 70class ViewContainer;
71class ViewManager; 71class ViewManager;
72class AddresseeEditorDialog; 72class AddresseeEditorDialog;
73class Ir; 73class Ir;
74 74
75class KABCore : public QWidget, public KSyncInterface 75class KABCore : public QWidget, public KSyncInterface
76{ 76{
77 Q_OBJECT 77 Q_OBJECT
78 78
79 public: 79 public:
80 KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name = 0 ); 80 KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name = 0 );
81 81
82 82
83 ~KABCore(); 83 ~KABCore();
84 84
85 85
86#ifdef KAB_EMBEDDED 86#ifdef KAB_EMBEDDED
87 //US added functionality 87 //US added functionality
88 QPopupMenu* getViewMenu() {return viewMenu;} 88 QPopupMenu* getViewMenu() {return viewMenu;}
89 QPopupMenu* getFilterMenu() {return filterMenu;} 89 QPopupMenu* getFilterMenu() {return filterMenu;}
90 QPopupMenu* getSettingsMenu() {return settingsMenu;} 90 QPopupMenu* getSettingsMenu() {return settingsMenu;}
91 void addActionsManually(); 91 void addActionsManually();
92#endif //KAB_EMBEDDED 92#endif //KAB_EMBEDDED
93 /** 93 /**
94 Restores the global settings. 94 Restores the global settings.
95 */ 95 */
96 void restoreSettings(); 96 void restoreSettings();
97 97
98 /** 98 /**
99 Saves the global settings. 99 Saves the global settings.
100 */ 100 */
101 void saveSettings(); 101 void saveSettings();
102 102
103 /** 103 /**
104 Returns a pointer to the StdAddressBook of the application. 104 Returns a pointer to the StdAddressBook of the application.
105 */ 105 */
106 KABC::AddressBook *addressBook() const; 106 KABC::AddressBook *addressBook() const;
107 107
108 /** 108 /**
109 Returns a pointer to the KConfig object of the application. 109 Returns a pointer to the KConfig object of the application.
110 */ 110 */
111 static KConfig *config(); 111 static KConfig *config();
112 112
113 /** 113 /**
114 Returns a pointer to the global KActionCollection object. So 114 Returns a pointer to the global KActionCollection object. So
115 other classes can register their actions easily. 115 other classes can register their actions easily.
116 */ 116 */
117 KActionCollection *actionCollection() const; 117 KActionCollection *actionCollection() const;
118 118
119 /** 119 /**
120 Returns the current search field of the Incremental Search Widget. 120 Returns the current search field of the Incremental Search Widget.
121 */ 121 */
122 KABC::Field *currentSearchField() const; 122 KABC::Field *currentSearchField() const;
123 123
124 /** 124 /**
125 Returns the uid list of the currently selected contacts. 125 Returns the uid list of the currently selected contacts.
126 */ 126 */
127 QStringList selectedUIDs() const; 127 QStringList selectedUIDs() const;
128 128
129 /** 129 /**
130 Displays the ResourceSelectDialog and returns the selected 130 Displays the ResourceSelectDialog and returns the selected
131 resource or a null pointer if no resource was selected by 131 resource or a null pointer if no resource was selected by
132 the user. 132 the user.
133 */ 133 */
134 KABC::Resource *requestResource( QWidget *parent ); 134 KABC::Resource *requestResource( QWidget *parent );
135 135
136#ifndef KAB_EMBEDDED 136#ifndef KAB_EMBEDDED
137 static KAboutData *createAboutData(); 137 static KAboutData *createAboutData();
138#endif //KAB_EMBEDDED 138#endif //KAB_EMBEDDED
139 139
140#ifdef KAB_EMBEDDED 140#ifdef KAB_EMBEDDED
141 inline QPopupMenu* getImportMenu() { return ImportMenu;} 141 inline QPopupMenu* getImportMenu() { return ImportMenu;}
142 inline QPopupMenu* getExportMenu() { return ExportMenu;} 142 inline QPopupMenu* getExportMenu() { return ExportMenu;}
143#endif //KAB_EMBEDDED 143#endif //KAB_EMBEDDED
144 144
145 public slots: 145 public slots:
146#ifdef KAB_EMBEDDED 146#ifdef KAB_EMBEDDED
147 void createAboutData(); 147 void createAboutData();
148#endif //KAB_EMBEDDED 148#endif //KAB_EMBEDDED
149 149
150 void showLicence(); 150 void showLicence();
151 void faq(); 151 void faq();
152 void whatsnew() ; 152 void whatsnew() ;
153 void synchowto() ; 153 void synchowto() ;
154 void writeToPhone(); 154 void writeToPhone();
155 155
156 /** 156 /**
157 Is called whenever a contact is selected in the view. 157 Is called whenever a contact is selected in the view.
158 */ 158 */
159 void setContactSelected( const QString &uid ); 159 void setContactSelected( const QString &uid );
160 160
161 /** 161 /**
162 Opens the preferred mail composer with all selected contacts as 162 Opens the preferred mail composer with all selected contacts as
163 arguments. 163 arguments.
164 */ 164 */
165 void sendMail(); 165 void sendMail();
166 166
167 /** 167 /**
168 Opens the preferred mail composer with the given contacts as 168 Opens the preferred mail composer with the given contacts as
169 arguments. 169 arguments.
170 */ 170 */
171 void sendMail( const QString& email ); 171 void sendMail( const QString& email );
172 172
173 173
174 void mailVCard(); 174 void mailVCard();
175 void mailVCard(const QStringList& uids); 175 void mailVCard(const QStringList& uids);
176 176
177 /** 177 /**
178 Beams the "WhoAmI contact. 178 Beams the "WhoAmI contact.
179 */ 179 */
180 void beamMySelf(); 180 void beamMySelf();
181 181
182 void beamVCard(); 182 void beamVCard();
183 void export2phone(); 183 void export2phone();
184 void beamVCard(const QStringList& uids); 184 void beamVCard(const QStringList& uids);
185 void beamDone( Ir *ir ); 185 void beamDone( Ir *ir );
186 186
187 187
188 /** 188 /**
189 Starts the preferred web browser with the given URL as argument. 189 Starts the preferred web browser with the given URL as argument.
190 */ 190 */
191 void browse( const QString& url ); 191 void browse( const QString& url );
192 192
193 /** 193 /**
194 Select all contacts in the view. 194 Select all contacts in the view.
195 */ 195 */
196 void selectAllContacts(); 196 void selectAllContacts();
197 197
198 /** 198 /**
199 Deletes all selected contacts from the address book. 199 Deletes all selected contacts from the address book.
200 */ 200 */
201 void deleteContacts(); 201 void deleteContacts();
202 202
203 /** 203 /**
204 Deletes given contacts from the address book. 204 Deletes given contacts from the address book.
205 205
206 @param uids The uids of the contacts, which shall be deleted. 206 @param uids The uids of the contacts, which shall be deleted.
207 */ 207 */
208 void deleteContacts( const QStringList &uids ); 208 void deleteContacts( const QStringList &uids );
209 209
210 /** 210 /**
211 Copys the selected contacts into clipboard for later pasting. 211 Copys the selected contacts into clipboard for later pasting.
212 */ 212 */
213 void copyContacts(); 213 void copyContacts();
214 214
215 /** 215 /**
216 Cuts the selected contacts and stores them for later pasting. 216 Cuts the selected contacts and stores them for later pasting.
217 */ 217 */
218 void cutContacts(); 218 void cutContacts();
219 219
220 /** 220 /**
221 Paste contacts from clipboard into the address book. 221 Paste contacts from clipboard into the address book.
222 */ 222 */
223 void pasteContacts(); 223 void pasteContacts();
224 224
225 /** 225 /**
226 Paste given contacts into the address book. 226 Paste given contacts into the address book.
227 227
228 @param list The list of addressee, which shall be pasted. 228 @param list The list of addressee, which shall be pasted.
229 */ 229 */
230 void pasteContacts( KABC::Addressee::List &list ); 230 void pasteContacts( KABC::Addressee::List &list );
231 231
232 /** 232 /**
233 Sets the whoAmI contact, that is used by many other programs to 233 Sets the whoAmI contact, that is used by many other programs to
234 get personal information about the current user. 234 get personal information about the current user.
235 */ 235 */
236 void setWhoAmI(); 236 void setWhoAmI();
237 237
238 /** 238 /**
239 Displays the category dialog and applies the result to all 239 Displays the category dialog and applies the result to all
240 selected contacts. 240 selected contacts.
241 */ 241 */
242 void setCategories(); 242 void setCategories();
243 243
244 /** 244 /**
245 Sets the field list of the Incremental Search Widget. 245 Sets the field list of the Incremental Search Widget.
246 */ 246 */
247 void setSearchFields( const KABC::Field::List &fields ); 247 void setSearchFields( const KABC::Field::List &fields );
248 248
249 /** 249 /**
250 Search with the current search field for a contact, that matches 250 Search with the current search field for a contact, that matches
251 the given text, and selects it in the view. 251 the given text, and selects it in the view.
252 */ 252 */
253 void incrementalSearch( const QString& text ); 253 void incrementalSearch( const QString& text );
254 254
255 /** 255 /**
256 Marks the address book as modified. 256 Marks the address book as modified.
257 */ 257 */
258 void setModified(); 258 void setModified();
259 /** 259 /**
260 Marks the address book as modified without refreshing the view. 260 Marks the address book as modified without refreshing the view.
261 */ 261 */
262 void setModifiedWOrefresh(); 262 void setModifiedWOrefresh();
263 263
264 /** 264 /**
265 Marks the address book as modified concerning the argument. 265 Marks the address book as modified concerning the argument.
266 */ 266 */
267 void setModified( bool modified ); 267 void setModified( bool modified );
268 268
269 /** 269 /**
270 Returns whether the address book is modified. 270 Returns whether the address book is modified.
271 */ 271 */
272 bool modified() const; 272 bool modified() const;
273 273
274 /** 274 /**
275 Called whenever an contact is modified in the contact editor 275 Called whenever an contact is modified in the contact editor
276 dialog or the quick edit. 276 dialog or the quick edit.
277 */ 277 */
278 void contactModified( const KABC::Addressee &addr ); 278 void contactModified( const KABC::Addressee &addr );
279 279
280 /** 280 /**
281 DCOP METHODS. 281 DCOP METHODS.
282 */ 282 */
283 void addEmail( QString addr ); 283 void addEmail( QString addr );
284 void importVCard( const KURL& url, bool showPreview ); 284 void importVCard( const KURL& url, bool showPreview );
285 void importVCard( const QString& vCard, bool showPreview ); 285 void importVCard( const QString& vCard, bool showPreview );
286 void newContact(); 286 void newContact();
287 QString getNameByPhone( const QString& phone ); 287 QString getNameByPhone( const QString& phone );
288 /** 288 /**
289 END DCOP METHODS 289 END DCOP METHODS
290 */ 290 */
291 291
292 /** 292 /**
293 Saves the contents of the AddressBook back to disk. 293 Saves the contents of the AddressBook back to disk.
294 */ 294 */
295 void save(); 295 void save();
296 296
297 /** 297 /**
298 Undos the last command using the undo stack. 298 Undos the last command using the undo stack.
299 */ 299 */
300 void undo(); 300 void undo();
301 301
302 /** 302 /**
303 Redos the last command that was undone, using the redo stack. 303 Redos the last command that was undone, using the redo stack.
304 */ 304 */
305 void redo(); 305 void redo();
306 306
307 /** 307 /**
308 Shows the edit dialog for the given uid. If the uid is QString::null, 308 Shows the edit dialog for the given uid. If the uid is QString::null,
309 the method will try to find a selected addressee in the view. 309 the method will try to find a selected addressee in the view.
310 */ 310 */
311 void editContact( const QString &uid /*US = QString::null*/ ); 311 void editContact( const QString &uid /*US = QString::null*/ );
312//US added a second method without defaultparameter 312//US added a second method without defaultparameter
313 void editContact2(); 313 void editContact2();
314 314
315 /** 315 /**
316 Shows or edits the detail view for the given uid. If the uid is QString::null, 316 Shows or edits the detail view for the given uid. If the uid is QString::null,
317 the method will try to find a selected addressee in the view. 317 the method will try to find a selected addressee in the view.
318 */ 318 */
319 void executeContact( const QString &uid /*US = QString::null*/ ); 319 void executeContact( const QString &uid /*US = QString::null*/ );
320 320
321 /** 321 /**
322 Launches the configuration dialog. 322 Launches the configuration dialog.
323 */ 323 */
324 void openConfigDialog(); 324 void openConfigDialog();
325 325
326 /** 326 /**
327 Launches the ldap search dialog. 327 Launches the ldap search dialog.
328 */ 328 */
329 void openLDAPDialog(); 329 void openLDAPDialog();
330 330
331 /** 331 /**
332 Creates a KAddressBookPrinter, which will display the print 332 Creates a KAddressBookPrinter, which will display the print
333 dialog and do the printing. 333 dialog and do the printing.
334 */ 334 */
335 void print(); 335 void print();
336 336
337 /** 337 /**
338 Registers a new GUI client, so plugins can register its actions. 338 Registers a new GUI client, so plugins can register its actions.
339 */ 339 */
340 void addGUIClient( KXMLGUIClient *client ); 340 void addGUIClient( KXMLGUIClient *client );
341 341
342 void requestForNameEmailUidList(const QString& sourceChannel, const QString& sessionuid); 342 void requestForNameEmailUidList(const QString& sourceChannel, const QString& sessionuid);
343 void requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid); 343 void requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid);
344 void requestForBirthdayList(const QString& sourceChannel, const QString& sessionuid); 344 void requestForBirthdayList(const QString& sourceChannel, const QString& sessionuid);
345 345
346 346
347 signals: 347 signals:
348 void contactSelected( const QString &name ); 348 void contactSelected( const QString &name );
349 void contactSelected( const QPixmap &pixmap ); 349 void contactSelected( const QPixmap &pixmap );
350 public slots: 350 public slots:
351 void recieve(QString cmsg ); 351 void recieve(QString cmsg );
352 void getFile( bool success ); 352 void getFile( bool success );
353 void syncFileRequest(); 353 void syncFileRequest();
354 void setDetailsVisible( bool visible ); 354 void setDetailsVisible( bool visible );
355 void setDetailsToState(); 355 void setDetailsToState();
356 // void slotSyncMenu( int ); 356 // void slotSyncMenu( int );
357 private slots: 357 private slots:
358 void receive( const QCString& cmsg, const QByteArray& data ); 358 void receive( const QCString& cmsg, const QByteArray& data );
359 void toggleBeamReceive( ); 359 void toggleBeamReceive( );
360 void disableBR(bool); 360 void disableBR(bool);
361 void setJumpButtonBarVisible( bool visible ); 361 void setJumpButtonBarVisible( bool visible );
362 void setCaptionBack(); 362 void setCaptionBack();
363 void importFromOL(); 363 void importFromOL();
364 void extensionModified( const KABC::Addressee::List &list ); 364 void extensionModified( const KABC::Addressee::List &list );
365 void extensionChanged( int id ); 365 void extensionChanged( int id );
366 void clipboardDataChanged(); 366 void clipboardDataChanged();
367 void updateActionMenu(); 367 void updateActionMenu();
368 void configureKeyBindings(); 368 void configureKeyBindings();
369 void removeVoice(); 369 void removeVoice();
370#ifdef KAB_EMBEDDED 370#ifdef KAB_EMBEDDED
371 void configureResources(); 371 void configureResources();
372#endif //KAB_EMBEDDED 372#endif //KAB_EMBEDDED
373 373
374 void slotEditorDestroyed( const QString &uid ); 374 void slotEditorDestroyed( const QString &uid );
375 void configurationChanged(); 375 void configurationChanged();
376 void addressBookChanged(); 376 void addressBookChanged();
377 377
378 private: 378 private:
379 bool mBRdisabled; 379 bool mBRdisabled;
380#ifndef DESKTOP_VERSION 380#ifndef DESKTOP_VERSION
381 QCopChannel* infrared; 381 QCopChannel* infrared;
382#endif 382#endif
383 QTimer *mMessageTimer; 383 QTimer *mMessageTimer;
384 void initGUI(); 384 void initGUI();
385 void initActions(); 385 void initActions();
386 QString getPhoneFile(); 386 QString getPhoneFile();
387 387
388 AddresseeEditorDialog *createAddresseeEditorDialog( QWidget *parent, 388 AddresseeEditorDialog *createAddresseeEditorDialog( QWidget *parent,
389 const char *name = 0 ); 389 const char *name = 0 );
390 390
391 KXMLGUIClient *mGUIClient; 391 KXMLGUIClient *mGUIClient;
392 392
393 KABC::AddressBook *mAddressBook; 393 KABC::AddressBook *mAddressBook;
394 394
395 ViewManager *mViewManager; 395 ViewManager *mViewManager;
396 // QSplitter *mDetailsSplitter; 396 // QSplitter *mDetailsSplitter;
397 KDGanttMinimizeSplitter *mExtensionBarSplitter; 397 KDGanttMinimizeSplitter *mExtensionBarSplitter;
398 ViewContainer *mDetails; 398 ViewContainer *mDetails;
399 KDGanttMinimizeSplitter* mMiniSplitter; 399 KDGanttMinimizeSplitter* mMiniSplitter;
400 XXPortManager *mXXPortManager; 400 XXPortManager *mXXPortManager;
401 JumpButtonBar *mJumpButtonBar; 401 JumpButtonBar *mJumpButtonBar;
402 IncSearchWidget *mIncSearchWidget; 402 IncSearchWidget *mIncSearchWidget;
403 ExtensionManager *mExtensionManager; 403 ExtensionManager *mExtensionManager;
404 404
405 KCMultiDialog *mConfigureDialog; 405 KCMultiDialog *mConfigureDialog;
406 406
407#ifndef KAB_EMBEDDED 407#ifndef KAB_EMBEDDED
408 LDAPSearchDialog *mLdapSearchDialog; 408 LDAPSearchDialog *mLdapSearchDialog;
409#endif //KAB_EMBEDDED 409#endif //KAB_EMBEDDED
410 // QDict<AddresseeEditorDialog> mEditorDict; 410 // QDict<AddresseeEditorDialog> mEditorDict;
411 AddresseeEditorDialog *mEditorDialog; 411 AddresseeEditorDialog *mEditorDialog;
412 bool mReadWrite; 412 bool mReadWrite;
413 bool mModified; 413 bool mModified;
414 bool mIsPart; 414 bool mIsPart;
415 bool mMultipleViewsAtOnce; 415 bool mMultipleViewsAtOnce;
416 416
417 417
418 //US file menu 418 //US file menu
419 KAction *mActionMail; 419 KAction *mActionMail;
420 KAction *mActionBeam; 420 KAction *mActionBeam;
421 KToggleAction *mActionBR; 421 KToggleAction *mActionBR;
422 KAction *mActionExport2phone; 422 KAction *mActionExport2phone;
423 KAction* mActionPrint; 423 KAction* mActionPrint;
424 KAction* mActionNewContact; 424 KAction* mActionNewContact;
425 KAction *mActionSave; 425 KAction *mActionSave;
426 KAction *mActionEditAddressee; 426 KAction *mActionEditAddressee;
427 KAction *mActionMailVCard; 427 KAction *mActionMailVCard;
428 KAction *mActionBeamVCard; 428 KAction *mActionBeamVCard;
429 429
430 KAction *mActionQuit; 430 KAction *mActionQuit;
431 431
432 //US edit menu 432 //US edit menu
433 KAction *mActionCopy; 433 KAction *mActionCopy;
434 KAction *mActionCut; 434 KAction *mActionCut;
435 KAction *mActionPaste; 435 KAction *mActionPaste;
436 KAction *mActionSelectAll; 436 KAction *mActionSelectAll;
437 KAction *mActionUndo; 437 KAction *mActionUndo;
438 KAction *mActionRedo; 438 KAction *mActionRedo;
439 KAction *mActionDelete; 439 KAction *mActionDelete;
440 440
441 //US settings menu 441 //US settings menu
442 KAction *mActionConfigResources; 442 KAction *mActionConfigResources;
443 KAction *mActionConfigKAddressbook; 443 KAction *mActionConfigKAddressbook;
444 KAction *mActionConfigShortcuts; 444 KAction *mActionConfigShortcuts;
445 KAction *mActionConfigureToolbars; 445 KAction *mActionConfigureToolbars;
446 KAction *mActionKeyBindings; 446 KAction *mActionKeyBindings;
447 KToggleAction *mActionJumpBar; 447 KToggleAction *mActionJumpBar;
448 KToggleAction *mActionDetails; 448 KToggleAction *mActionDetails;
449 KAction *mActionWhoAmI; 449 KAction *mActionWhoAmI;
450 KAction *mActionCategories; 450 KAction *mActionCategories;
451 KAction *mActionAboutKAddressbook; 451 KAction *mActionAboutKAddressbook;
452 KAction *mActionLicence; 452 KAction *mActionLicence;
453 KAction *mActionFaq; 453 KAction *mActionFaq;
454 KAction *mActionWN; 454 KAction *mActionWN;
455 KAction *mActionSyncHowto; 455 KAction *mActionSyncHowto;
456 456
457 KAction *mActionDeleteView; 457 KAction *mActionDeleteView;
458 458
459 QPopupMenu *viewMenu; 459 QPopupMenu *viewMenu;
460 QPopupMenu *filterMenu; 460 QPopupMenu *filterMenu;
461 QPopupMenu *settingsMenu; 461 QPopupMenu *settingsMenu;
462 QPopupMenu *changeMenu; 462 QPopupMenu *changeMenu;
463//US QAction *mActionSave; 463//US QAction *mActionSave;
464 QPopupMenu *ImportMenu; 464 QPopupMenu *ImportMenu;
465 QPopupMenu *ExportMenu; 465 QPopupMenu *ExportMenu;
466 //LR additional methods 466 //LR additional methods
467 KAction *mActionRemoveVoice; 467 KAction *mActionRemoveVoice;
468 KAction * mActionImportOL; 468 KAction * mActionImportOL;
469 469
470#ifndef KAB_EMBEDDED 470#ifndef KAB_EMBEDDED
471 KAddressBookService *mAddressBookService; 471 KAddressBookService *mAddressBookService;
472#endif //KAB_EMBEDDED 472#endif //KAB_EMBEDDED
473 473
474 class KABCorePrivate; 474 class KABCorePrivate;
475 KABCorePrivate *d; 475 KABCorePrivate *d;
476 //US bool mBlockSaveFlag; 476 //US bool mBlockSaveFlag;
477 477
478#ifdef KAB_EMBEDDED 478#ifdef KAB_EMBEDDED
479 KAddressBookMain *mMainWindow; // should be the same like mGUIClient 479 KAddressBookMain *mMainWindow; // should be the same like mGUIClient
480#endif //KAB_EMBEDDED 480#endif //KAB_EMBEDDED
481 481
482 //this are the overwritten callbackmethods from the syncinterface 482 //this are the overwritten callbackmethods from the syncinterface
483 virtual bool sync(KSyncManager* manager, QString filename, int mode); 483 virtual bool sync(KSyncManager* manager, QString filename, int mode);
484 virtual bool syncExternal(KSyncManager* manager, QString resource); 484 virtual bool syncExternal(KSyncManager* manager, QString resource);
485 virtual void removeSyncInfo( QString syncProfile);
485 bool syncPhone(); 486 bool syncPhone();
486 void message( QString m ); 487 void message( QString m );
487 488
488 // LR ******************************* 489 // LR *******************************
489 // sync stuff! 490 // sync stuff!
490 QString sentSyncFile(); 491 QString sentSyncFile();
491 QPopupMenu *syncMenu; 492 QPopupMenu *syncMenu;
492 KSyncManager* syncManager; 493 KSyncManager* syncManager;
493 int mGlobalSyncMode; 494 int mGlobalSyncMode;
494 bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode); 495 bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode);
495 KABC::Addressee getLastSyncAddressee(); 496 KABC::Addressee getLastSyncAddressee();
496 QDateTime mLastAddressbookSync; 497 QDateTime mLastAddressbookSync;
497 int takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ); 498 int takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full );
498 // ********************* 499 // *********************
499 500
500}; 501};
501 502
502#endif 503#endif
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 2ccccfa..af01625 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,3766 +1,3772 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Requires the Qt and KDE widget libraries, available at no cost at 4 Requires the Qt and KDE widget libraries, available at no cost at
5 http://www.troll.no and http://www.kde.org respectively 5 http://www.troll.no and http://www.kde.org respectively
6 6
7 Copyright (c) 1997, 1998, 1999 7 Copyright (c) 1997, 1998, 1999
8 Preston Brown (preston.brown@yale.edu) 8 Preston Brown (preston.brown@yale.edu)
9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) 9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl)
10 Ian Dawes (iadawes@globalserve.net) 10 Ian Dawes (iadawes@globalserve.net)
11 Laszlo Boloni (boloni@cs.purdue.edu) 11 Laszlo Boloni (boloni@cs.purdue.edu)
12 12
13 Copyright (c) 2000, 2001, 2002 13 Copyright (c) 2000, 2001, 2002
14 Cornelius Schumacher <schumacher@kde.org> 14 Cornelius Schumacher <schumacher@kde.org>
15 15
16 This program is free software; you can redistribute it and/or modify 16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by 17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or 18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version. 19 (at your option) any later version.
20 20
21 This program is distributed in the hope that it will be useful, 21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
24 GNU General Public License for more details. 24 GNU General Public License for more details.
25 25
26 You should have received a copy of the GNU General Public License 26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software 27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qradiobutton.h> 34#include <qradiobutton.h>
35#include <qbuttongroup.h> 35#include <qbuttongroup.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qclipboard.h> 37#include <qclipboard.h>
38#include <qcursor.h> 38#include <qcursor.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qprogressbar.h> 40#include <qprogressbar.h>
41#include <qmultilineedit.h> 41#include <qmultilineedit.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#include <qwidgetstack.h> 43#include <qwidgetstack.h>
44#include <qptrlist.h> 44#include <qptrlist.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qgroupbox.h> 46#include <qgroupbox.h>
47#include <qfile.h> 47#include <qfile.h>
48#include <qdir.h> 48#include <qdir.h>
49#ifndef KORG_NOSPLITTER 49#ifndef KORG_NOSPLITTER
50#include <qsplitter.h> 50#include <qsplitter.h>
51#endif 51#endif
52 52
53#include <kglobal.h> 53#include <kglobal.h>
54#include <kdebug.h> 54#include <kdebug.h>
55#include <kstandarddirs.h> 55#include <kstandarddirs.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57#include <kmessagebox.h> 57#include <kmessagebox.h>
58#include <knotifyclient.h> 58#include <knotifyclient.h>
59#include <kconfig.h> 59#include <kconfig.h>
60 60
61#include <libkdepim/ksyncprefsdialog.h> 61#include <libkdepim/ksyncprefsdialog.h>
62#include <krun.h> 62#include <krun.h>
63#include <kdirwatch.h> 63#include <kdirwatch.h>
64#include <libkdepim/kdatepicker.h> 64#include <libkdepim/kdatepicker.h>
65#include <libkdepim/ksyncprofile.h> 65#include <libkdepim/ksyncprofile.h>
66#include <libkdepim/kpimglobalprefs.h> 66#include <libkdepim/kpimglobalprefs.h>
67 67
68#include <libkcal/vcaldrag.h> 68#include <libkcal/vcaldrag.h>
69#include <libkcal/icaldrag.h> 69#include <libkcal/icaldrag.h>
70#include <libkcal/icalformat.h> 70#include <libkcal/icalformat.h>
71#include <libkcal/vcalformat.h> 71#include <libkcal/vcalformat.h>
72#include <libkcal/scheduler.h> 72#include <libkcal/scheduler.h>
73#include <libkcal/calendarlocal.h> 73#include <libkcal/calendarlocal.h>
74#include <libkcal/journal.h> 74#include <libkcal/journal.h>
75#include <libkcal/calfilter.h> 75#include <libkcal/calfilter.h>
76#include <libkcal/attendee.h> 76#include <libkcal/attendee.h>
77#include <libkcal/dndfactory.h> 77#include <libkcal/dndfactory.h>
78#include <libkcal/freebusy.h> 78#include <libkcal/freebusy.h>
79#include <libkcal/filestorage.h> 79#include <libkcal/filestorage.h>
80#include <libkcal/calendarresources.h> 80#include <libkcal/calendarresources.h>
81#include <libkcal/qtopiaformat.h> 81#include <libkcal/qtopiaformat.h>
82#include "../kalarmd/alarmdialog.h" 82#include "../kalarmd/alarmdialog.h"
83 83
84#ifndef DESKTOP_VERSION 84#ifndef DESKTOP_VERSION
85#include <libkcal/sharpformat.h> 85#include <libkcal/sharpformat.h>
86#include <externalapphandler.h> 86#include <externalapphandler.h>
87#endif 87#endif
88#include <libkcal/phoneformat.h> 88#include <libkcal/phoneformat.h>
89#ifndef KORG_NOMAIL 89#ifndef KORG_NOMAIL
90#include "komailclient.h" 90#include "komailclient.h"
91#endif 91#endif
92#ifndef KORG_NOPRINTER 92#ifndef KORG_NOPRINTER
93#include "calprinter.h" 93#include "calprinter.h"
94#endif 94#endif
95#ifndef KORG_NOPLUGINS 95#ifndef KORG_NOPLUGINS
96#include "kocore.h" 96#include "kocore.h"
97#endif 97#endif
98#include "koeventeditor.h" 98#include "koeventeditor.h"
99#include "kotodoeditor.h" 99#include "kotodoeditor.h"
100#include "koprefs.h" 100#include "koprefs.h"
101#include "koeventviewerdialog.h" 101#include "koeventviewerdialog.h"
102#include "publishdialog.h" 102#include "publishdialog.h"
103#include "kofilterview.h" 103#include "kofilterview.h"
104#include "koglobals.h" 104#include "koglobals.h"
105#include "koviewmanager.h" 105#include "koviewmanager.h"
106#include "koagendaview.h" 106#include "koagendaview.h"
107#include "kodialogmanager.h" 107#include "kodialogmanager.h"
108#include "outgoingdialog.h" 108#include "outgoingdialog.h"
109#include "incomingdialog.h" 109#include "incomingdialog.h"
110#include "statusdialog.h" 110#include "statusdialog.h"
111#include "kdatenavigator.h" 111#include "kdatenavigator.h"
112#include "kotodoview.h" 112#include "kotodoview.h"
113#include "datenavigator.h" 113#include "datenavigator.h"
114#include "resourceview.h" 114#include "resourceview.h"
115#include "navigatorbar.h" 115#include "navigatorbar.h"
116#include "searchdialog.h" 116#include "searchdialog.h"
117#include "mainwindow.h" 117#include "mainwindow.h"
118 118
119#include "calendarview.h" 119#include "calendarview.h"
120#ifndef DESKTOP_VERSION 120#ifndef DESKTOP_VERSION
121#include <qtopia/alarmserver.h> 121#include <qtopia/alarmserver.h>
122#endif 122#endif
123#ifndef _WIN32_ 123#ifndef _WIN32_
124#include <stdlib.h> 124#include <stdlib.h>
125#include <stdio.h> 125#include <stdio.h>
126#include <unistd.h> 126#include <unistd.h>
127#else 127#else
128#include <qprocess.h> 128#include <qprocess.h>
129#endif 129#endif
130 130
131#ifdef DESKTOP_VERSION 131#ifdef DESKTOP_VERSION
132#include <kabc/stdaddressbook.h> 132#include <kabc/stdaddressbook.h>
133#endif 133#endif
134using namespace KOrg; 134using namespace KOrg;
135using namespace KCal; 135using namespace KCal;
136extern int globalFlagBlockAgenda; 136extern int globalFlagBlockAgenda;
137extern int globalFlagBlockStartup; 137extern int globalFlagBlockStartup;
138 138
139 139
140 140
141class KOBeamPrefs : public QDialog 141class KOBeamPrefs : public QDialog
142{ 142{
143 public: 143 public:
144 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 144 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
145 QDialog( parent, name, true ) 145 QDialog( parent, name, true )
146 { 146 {
147 setCaption( i18n("Beam Options") ); 147 setCaption( i18n("Beam Options") );
148 QVBoxLayout* lay = new QVBoxLayout( this ); 148 QVBoxLayout* lay = new QVBoxLayout( this );
149 lay->setSpacing( 3 ); 149 lay->setSpacing( 3 );
150 lay->setMargin( 3 ); 150 lay->setMargin( 3 );
151 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 151 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
152 lay->addWidget( format ); 152 lay->addWidget( format );
153 format->setExclusive ( true ) ; 153 format->setExclusive ( true ) ;
154 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 154 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
155 lay->addWidget( time ); time->setExclusive ( true ) ; 155 lay->addWidget( time ); time->setExclusive ( true ) ;
156 vcal = new QRadioButton(" vCalendar ", format ); 156 vcal = new QRadioButton(" vCalendar ", format );
157 ical = new QRadioButton(" iCalendar ", format ); 157 ical = new QRadioButton(" iCalendar ", format );
158 vcal->setChecked( true ); 158 vcal->setChecked( true );
159 tz = new QRadioButton(i18n(" With timezone "), time ); 159 tz = new QRadioButton(i18n(" With timezone "), time );
160 local = new QRadioButton(i18n(" Local time "), time ); 160 local = new QRadioButton(i18n(" Local time "), time );
161 tz->setChecked( true ); 161 tz->setChecked( true );
162 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 162 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
163 lay->addWidget( ok ); 163 lay->addWidget( ok );
164 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 164 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
165 lay->addWidget( cancel ); 165 lay->addWidget( cancel );
166 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 166 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
167 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 167 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
168 resize( 200, 200 ); 168 resize( 200, 200 );
169 } 169 }
170 170
171 bool beamVcal() { return vcal->isChecked(); } 171 bool beamVcal() { return vcal->isChecked(); }
172 bool beamLocal() { return local->isChecked(); } 172 bool beamLocal() { return local->isChecked(); }
173private: 173private:
174 QRadioButton* vcal, *ical, *local, *tz; 174 QRadioButton* vcal, *ical, *local, *tz;
175}; 175};
176class KOCatPrefs : public QDialog 176class KOCatPrefs : public QDialog
177{ 177{
178 public: 178 public:
179 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 179 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
180 QDialog( parent, name, true ) 180 QDialog( parent, name, true )
181 { 181 {
182 setCaption( i18n("Manage new Categories") ); 182 setCaption( i18n("Manage new Categories") );
183 QVBoxLayout* lay = new QVBoxLayout( this ); 183 QVBoxLayout* lay = new QVBoxLayout( this );
184 lay->setSpacing( 3 ); 184 lay->setSpacing( 3 );
185 lay->setMargin( 3 ); 185 lay->setMargin( 3 );
186 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); 186 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this );
187 lay->addWidget( lab ); 187 lay->addWidget( lab );
188 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 188 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
189 lay->addWidget( format ); 189 lay->addWidget( format );
190 format->setExclusive ( true ) ; 190 format->setExclusive ( true ) ;
191 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 191 addCatBut = new QRadioButton(i18n("Add to category list"), format );
192 new QRadioButton(i18n("Remove from Events/Todos"), format ); 192 new QRadioButton(i18n("Remove from Events/Todos"), format );
193 addCatBut->setChecked( true ); 193 addCatBut->setChecked( true );
194 QPushButton * ok = new QPushButton( i18n("OK"), this ); 194 QPushButton * ok = new QPushButton( i18n("OK"), this );
195 lay->addWidget( ok ); 195 lay->addWidget( ok );
196 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 196 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
197 lay->addWidget( cancel ); 197 lay->addWidget( cancel );
198 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 198 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
199 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 199 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
200 resize( 200, 200 ); 200 resize( 200, 200 );
201 } 201 }
202 202
203 bool addCat() { return addCatBut->isChecked(); } 203 bool addCat() { return addCatBut->isChecked(); }
204private: 204private:
205 QRadioButton* addCatBut; 205 QRadioButton* addCatBut;
206}; 206};
207 207
208 208
209 209
210CalendarView::CalendarView( CalendarResources *calendar, 210CalendarView::CalendarView( CalendarResources *calendar,
211 QWidget *parent, const char *name ) 211 QWidget *parent, const char *name )
212 : CalendarViewBase( parent, name ), 212 : CalendarViewBase( parent, name ),
213 mCalendar( calendar ), 213 mCalendar( calendar ),
214 mResourceManager( calendar->resourceManager() ) 214 mResourceManager( calendar->resourceManager() )
215{ 215{
216 216
217 mEventEditor = 0; 217 mEventEditor = 0;
218 mTodoEditor = 0; 218 mTodoEditor = 0;
219 219
220 init(); 220 init();
221} 221}
222 222
223CalendarView::CalendarView( Calendar *calendar, 223CalendarView::CalendarView( Calendar *calendar,
224 QWidget *parent, const char *name ) 224 QWidget *parent, const char *name )
225 : CalendarViewBase( parent, name ), 225 : CalendarViewBase( parent, name ),
226 mCalendar( calendar ), 226 mCalendar( calendar ),
227 mResourceManager( 0 ) 227 mResourceManager( 0 )
228{ 228{
229 229
230 mEventEditor = 0; 230 mEventEditor = 0;
231 mTodoEditor = 0; 231 mTodoEditor = 0;
232 init();} 232 init();}
233 233
234void CalendarView::init() 234void CalendarView::init()
235{ 235{
236 beamDialog = new KOBeamPrefs(); 236 beamDialog = new KOBeamPrefs();
237 mDatePickerMode = 0; 237 mDatePickerMode = 0;
238 mCurrentSyncDevice = ""; 238 mCurrentSyncDevice = "";
239 writeLocale(); 239 writeLocale();
240 mViewManager = new KOViewManager( this ); 240 mViewManager = new KOViewManager( this );
241 mDialogManager = new KODialogManager( this ); 241 mDialogManager = new KODialogManager( this );
242 mEventViewerDialog = 0; 242 mEventViewerDialog = 0;
243 mModified = false; 243 mModified = false;
244 mReadOnly = false; 244 mReadOnly = false;
245 mSelectedIncidence = 0; 245 mSelectedIncidence = 0;
246 mCalPrinter = 0; 246 mCalPrinter = 0;
247 mFilters.setAutoDelete(true); 247 mFilters.setAutoDelete(true);
248 248
249 mCalendar->registerObserver( this ); 249 mCalendar->registerObserver( this );
250 // TODO: Make sure that view is updated, when calendar is changed. 250 // TODO: Make sure that view is updated, when calendar is changed.
251 251
252 mStorage = new FileStorage( mCalendar ); 252 mStorage = new FileStorage( mCalendar );
253 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 253 mNavigator = new DateNavigator( this, "datevav", mViewManager );
254 254
255 QBoxLayout *topLayout = (QBoxLayout*)layout(); 255 QBoxLayout *topLayout = (QBoxLayout*)layout();
256#ifndef KORG_NOSPLITTER 256#ifndef KORG_NOSPLITTER
257 // create the main layout frames. 257 // create the main layout frames.
258 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 258 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
259 topLayout->addWidget(mPanner); 259 topLayout->addWidget(mPanner);
260 260
261 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 261 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
262 "CalendarView::LeftFrame"); 262 "CalendarView::LeftFrame");
263 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 263 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
264 264
265 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE, 265 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE,
266 "CalendarView::DateNavigator", QDate::currentDate() ); 266 "CalendarView::DateNavigator", QDate::currentDate() );
267 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 267 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
268 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 268 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
269 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 269 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
270 270
271#ifdef KORG_NORESOURCEVIEW 271#ifdef KORG_NORESOURCEVIEW
272 mResourceView = 0; 272 mResourceView = 0;
273#else 273#else
274 if ( mResourceManager ) { 274 if ( mResourceManager ) {
275 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 275 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
276 mResourceView->updateView(); 276 mResourceView->updateView();
277 connect( mResourceView, SIGNAL( resourcesChanged() ), 277 connect( mResourceView, SIGNAL( resourcesChanged() ),
278 SLOT( updateView() ) ); 278 SLOT( updateView() ) );
279 } else { 279 } else {
280 mResourceView = 0; 280 mResourceView = 0;
281 } 281 }
282#endif 282#endif
283 QWidget *rightBox = new QWidget( mPanner ); 283 QWidget *rightBox = new QWidget( mPanner );
284 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 284 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
285 285
286 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 286 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
287 rightLayout->addWidget( mNavigatorBar ); 287 rightLayout->addWidget( mNavigatorBar );
288 288
289 mRightFrame = new QWidgetStack( rightBox ); 289 mRightFrame = new QWidgetStack( rightBox );
290 rightLayout->addWidget( mRightFrame, 1 ); 290 rightLayout->addWidget( mRightFrame, 1 );
291 291
292 mLeftFrame = mLeftSplitter; 292 mLeftFrame = mLeftSplitter;
293#else 293#else
294 QWidget *mainBox = new QWidget( this ); 294 QWidget *mainBox = new QWidget( this );
295 QWidget *leftFrame = new QWidget( mainBox ); 295 QWidget *leftFrame = new QWidget( mainBox );
296 296
297 QBoxLayout * mainBoxLayout; 297 QBoxLayout * mainBoxLayout;
298 QBoxLayout * leftFrameLayout; 298 QBoxLayout * leftFrameLayout;
299 if ( KOPrefs::instance()->mVerticalScreen ) { 299 if ( KOPrefs::instance()->mVerticalScreen ) {
300 mainBoxLayout = new QVBoxLayout(mainBox); 300 mainBoxLayout = new QVBoxLayout(mainBox);
301 leftFrameLayout = new QHBoxLayout(leftFrame ); 301 leftFrameLayout = new QHBoxLayout(leftFrame );
302 } else { 302 } else {
303 mainBoxLayout = new QHBoxLayout(mainBox); 303 mainBoxLayout = new QHBoxLayout(mainBox);
304 leftFrameLayout = new QVBoxLayout(leftFrame ); 304 leftFrameLayout = new QVBoxLayout(leftFrame );
305 } 305 }
306 topLayout->addWidget( mainBox ); 306 topLayout->addWidget( mainBox );
307 mainBoxLayout->addWidget (leftFrame); 307 mainBoxLayout->addWidget (leftFrame);
308 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE, 308 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE,
309 "CalendarView::DateNavigator", QDate::currentDate()); 309 "CalendarView::DateNavigator", QDate::currentDate());
310 // mDateNavigator->blockSignals( true ); 310 // mDateNavigator->blockSignals( true );
311 leftFrameLayout->addWidget( mDateNavigator ); 311 leftFrameLayout->addWidget( mDateNavigator );
312 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView"); 312 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView");
313 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolistsmall"); 313 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolistsmall");
314 314
315 if ( QApplication::desktop()->width() < 480 ) { 315 if ( QApplication::desktop()->width() < 480 ) {
316 leftFrameLayout->addWidget(mFilterView); 316 leftFrameLayout->addWidget(mFilterView);
317 leftFrameLayout->addWidget(mTodoList, 2 ); 317 leftFrameLayout->addWidget(mTodoList, 2 );
318 318
319 } else { 319 } else {
320 leftFrameLayout->addWidget(mTodoList,2 ); 320 leftFrameLayout->addWidget(mTodoList,2 );
321 leftFrameLayout->addWidget(mFilterView ); 321 leftFrameLayout->addWidget(mFilterView );
322 } 322 }
323 mFilterView->hide(); 323 mFilterView->hide();
324 QWidget *rightBox = new QWidget( mainBox ); 324 QWidget *rightBox = new QWidget( mainBox );
325 mainBoxLayout->addWidget ( rightBox, 10 ); 325 mainBoxLayout->addWidget ( rightBox, 10 );
326 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 326 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
327 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 327 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
328 mRightFrame = new QWidgetStack( rightBox ); 328 mRightFrame = new QWidgetStack( rightBox );
329 rightLayout->addWidget( mNavigatorBar ); 329 rightLayout->addWidget( mNavigatorBar );
330 rightLayout->addWidget( mRightFrame, 10 ); 330 rightLayout->addWidget( mRightFrame, 10 );
331 331
332 mLeftFrame = leftFrame; 332 mLeftFrame = leftFrame;
333 if ( KOPrefs::instance()->mVerticalScreen ) { 333 if ( KOPrefs::instance()->mVerticalScreen ) {
334 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 334 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
335 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 335 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
336 } else { 336 } else {
337 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 337 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
338 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 338 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
339 } 339 }
340 340
341 //qDebug("Calendarview Size %d %d ", width(), height()); 341 //qDebug("Calendarview Size %d %d ", width(), height());
342#endif 342#endif
343 343
344 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 344 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
345 SLOT( showDates( const KCal::DateList & ) ) ); 345 SLOT( showDates( const KCal::DateList & ) ) );
346 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 346 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
347 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 347 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
348 348
349 connect( mNavigatorBar, SIGNAL( goPrevYear() ), 349 connect( mNavigatorBar, SIGNAL( goPrevYear() ),
350 mNavigator, SLOT( selectPreviousYear() ) ); 350 mNavigator, SLOT( selectPreviousYear() ) );
351 connect( mNavigatorBar, SIGNAL( goNextYear() ), 351 connect( mNavigatorBar, SIGNAL( goNextYear() ),
352 mNavigator, SLOT( selectNextYear() ) ); 352 mNavigator, SLOT( selectNextYear() ) );
353 connect( mNavigatorBar, SIGNAL( goPrevMonth() ), 353 connect( mNavigatorBar, SIGNAL( goPrevMonth() ),
354 mNavigator, SLOT( selectPreviousMonth() ) ); 354 mNavigator, SLOT( selectPreviousMonth() ) );
355 connect( mNavigatorBar, SIGNAL( goNextMonth() ), 355 connect( mNavigatorBar, SIGNAL( goNextMonth() ),
356 mNavigator, SLOT( selectNextMonth() ) ); 356 mNavigator, SLOT( selectNextMonth() ) );
357 357
358 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 358 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
359 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) ); 359 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) );
360 360
361 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 361 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
362 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 362 mNavigator, SLOT( selectWeek( const QDate & ) ) );
363 363
364 connect( mDateNavigator, SIGNAL( goPrevYear() ), 364 connect( mDateNavigator, SIGNAL( goPrevYear() ),
365 mNavigator, SLOT( selectPreviousYear() ) ); 365 mNavigator, SLOT( selectPreviousYear() ) );
366 connect( mDateNavigator, SIGNAL( goNextYear() ), 366 connect( mDateNavigator, SIGNAL( goNextYear() ),
367 mNavigator, SLOT( selectNextYear() ) ); 367 mNavigator, SLOT( selectNextYear() ) );
368 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 368 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
369 mNavigator, SLOT( selectPreviousMonth() ) ); 369 mNavigator, SLOT( selectPreviousMonth() ) );
370 connect( mDateNavigator, SIGNAL( goNextMonth() ), 370 connect( mDateNavigator, SIGNAL( goNextMonth() ),
371 mNavigator, SLOT( selectNextMonth() ) ); 371 mNavigator, SLOT( selectNextMonth() ) );
372 372
373 connect( mDateNavigator, SIGNAL( goPrevious() ), 373 connect( mDateNavigator, SIGNAL( goPrevious() ),
374 mNavigator, SLOT( selectPrevious() ) ); 374 mNavigator, SLOT( selectPrevious() ) );
375 connect( mDateNavigator, SIGNAL( goNext() ), 375 connect( mDateNavigator, SIGNAL( goNext() ),
376 mNavigator, SLOT( selectNext() ) ); 376 mNavigator, SLOT( selectNext() ) );
377 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 377 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
378 mNavigator, SLOT( slotMonthSelect( int ) ) ); 378 mNavigator, SLOT( slotMonthSelect( int ) ) );
379 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ), 379 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ),
380 mNavigator, SLOT( slotMonthSelect( int ) ) ); 380 mNavigator, SLOT( slotMonthSelect( int ) ) );
381 381
382 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 382 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
383 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 383 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
384 384
385 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ), 385 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ),
386 SLOT( eventAdded( Event *) ) ); 386 SLOT( eventAdded( Event *) ) );
387 387
388 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 388 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
389 389
390 connect( this, SIGNAL( configChanged() ), 390 connect( this, SIGNAL( configChanged() ),
391 mDateNavigator, SLOT( updateConfig() ) ); 391 mDateNavigator, SLOT( updateConfig() ) );
392 392
393 connect( mTodoList, SIGNAL( newTodoSignal() ), 393 connect( mTodoList, SIGNAL( newTodoSignal() ),
394 SLOT( newTodo() ) ); 394 SLOT( newTodo() ) );
395 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 395 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
396 SLOT( newSubTodo( Todo * ) ) ); 396 SLOT( newSubTodo( Todo * ) ) );
397 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 397 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
398 SLOT( editTodo( Todo * ) ) ); 398 SLOT( editTodo( Todo * ) ) );
399 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 399 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
400 SLOT( showTodo( Todo *) ) ); 400 SLOT( showTodo( Todo *) ) );
401 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 401 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
402 SLOT( deleteTodo( Todo *) ) ); 402 SLOT( deleteTodo( Todo *) ) );
403 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 403 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
404 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 404 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
405 SLOT( purgeCompleted() ) ); 405 SLOT( purgeCompleted() ) );
406 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 406 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
407 SIGNAL( todoModified( Todo *, int ) ) ); 407 SIGNAL( todoModified( Todo *, int ) ) );
408 408
409 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 409 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
410 this, SLOT ( cloneIncidence( Incidence * ) ) ); 410 this, SLOT ( cloneIncidence( Incidence * ) ) );
411 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 411 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
412 this, SLOT (cancelIncidence( Incidence * ) ) ); 412 this, SLOT (cancelIncidence( Incidence * ) ) );
413 413
414 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 414 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
415 this, SLOT ( moveIncidence( Incidence * ) ) ); 415 this, SLOT ( moveIncidence( Incidence * ) ) );
416 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 416 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
417 this, SLOT ( beamIncidence( Incidence * ) ) ); 417 this, SLOT ( beamIncidence( Incidence * ) ) );
418 418
419 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 419 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
420 this, SLOT ( todo_unsub( Todo * ) ) ); 420 this, SLOT ( todo_unsub( Todo * ) ) );
421 421
422 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 422 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
423 this, SLOT ( todo_resub( Todo *,Todo * ) ) ); 423 this, SLOT ( todo_resub( Todo *,Todo * ) ) );
424 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 424 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
425 SLOT( updateTodo( Todo *, int ) ) ); 425 SLOT( updateTodo( Todo *, int ) ) );
426 connect( this, SIGNAL( todoModified( Todo *, int )), this, 426 connect( this, SIGNAL( todoModified( Todo *, int )), this,
427 SLOT( changeTodoDisplay( Todo *, int ) ) ); 427 SLOT( changeTodoDisplay( Todo *, int ) ) );
428 428
429 429
430 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 430 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
431 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 431 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
432 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 432 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
433 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 433 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
434 434
435 435
436 436
437 437
438 438
439 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 439 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
440 SLOT(checkClipboard())); 440 SLOT(checkClipboard()));
441 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 441 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
442 SLOT( processTodoListSelection( Incidence * ) ) ); 442 SLOT( processTodoListSelection( Incidence * ) ) );
443 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 443 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
444 444
445 // kdDebug() << "CalendarView::CalendarView() done" << endl; 445 // kdDebug() << "CalendarView::CalendarView() done" << endl;
446 446
447 mDateFrame = new QVBox(0,0,WType_Popup); 447 mDateFrame = new QVBox(0,0,WType_Popup);
448 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 448 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
449 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 449 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
450 mDateFrame->setLineWidth(3); 450 mDateFrame->setLineWidth(3);
451 mDateFrame->hide(); 451 mDateFrame->hide();
452 mDateFrame->setCaption( i18n( "Pick a date to display")); 452 mDateFrame->setCaption( i18n( "Pick a date to display"));
453 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 453 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
454 454
455 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 455 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
456 456
457 mEventEditor = mDialogManager->getEventEditor(); 457 mEventEditor = mDialogManager->getEventEditor();
458 mTodoEditor = mDialogManager->getTodoEditor(); 458 mTodoEditor = mDialogManager->getTodoEditor();
459 459
460 mFlagEditDescription = false; 460 mFlagEditDescription = false;
461 461
462 mSuspendTimer = new QTimer( this ); 462 mSuspendTimer = new QTimer( this );
463 mAlarmTimer = new QTimer( this ); 463 mAlarmTimer = new QTimer( this );
464 mRecheckAlarmTimer = new QTimer( this ); 464 mRecheckAlarmTimer = new QTimer( this );
465 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 465 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
466 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 466 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
467 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 467 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
468 mAlarmDialog = new AlarmDialog( this ); 468 mAlarmDialog = new AlarmDialog( this );
469 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 469 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
470 mAlarmDialog->setServerNotification( false ); 470 mAlarmDialog->setServerNotification( false );
471 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 471 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
472 472
473 473
474#ifndef DESKTOP_VERSION 474#ifndef DESKTOP_VERSION
475//US listen for arriving address resultsets 475//US listen for arriving address resultsets
476 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 476 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
477 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 477 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
478#endif 478#endif
479 479
480} 480}
481 481
482 482
483CalendarView::~CalendarView() 483CalendarView::~CalendarView()
484{ 484{
485 // kdDebug() << "~CalendarView()" << endl; 485 // kdDebug() << "~CalendarView()" << endl;
486 //qDebug("CalendarView::~CalendarView() "); 486 //qDebug("CalendarView::~CalendarView() ");
487 delete mDialogManager; 487 delete mDialogManager;
488 delete mViewManager; 488 delete mViewManager;
489 delete mStorage; 489 delete mStorage;
490 delete mDateFrame ; 490 delete mDateFrame ;
491 delete beamDialog; 491 delete beamDialog;
492 //kdDebug() << "~CalendarView() done" << endl; 492 //kdDebug() << "~CalendarView() done" << endl;
493} 493}
494void CalendarView::timerAlarm() 494void CalendarView::timerAlarm()
495{ 495{
496 //qDebug("CalendarView::timerAlarm() "); 496 //qDebug("CalendarView::timerAlarm() ");
497 computeAlarm(mAlarmNotification ); 497 computeAlarm(mAlarmNotification );
498} 498}
499 499
500void CalendarView::suspendAlarm() 500void CalendarView::suspendAlarm()
501{ 501{
502 //qDebug(" CalendarView::suspendAlarm() "); 502 //qDebug(" CalendarView::suspendAlarm() ");
503 computeAlarm(mSuspendAlarmNotification ); 503 computeAlarm(mSuspendAlarmNotification );
504 504
505} 505}
506 506
507void CalendarView::startAlarm( QString mess , QString filename) 507void CalendarView::startAlarm( QString mess , QString filename)
508{ 508{
509 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 509 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
510 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 510 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
511 511
512} 512}
513 513
514void CalendarView::checkNextTimerAlarm() 514void CalendarView::checkNextTimerAlarm()
515{ 515{
516 mCalendar->checkAlarmForIncidence( 0, true ); 516 mCalendar->checkAlarmForIncidence( 0, true );
517} 517}
518 518
519void CalendarView::computeAlarm( QString msg ) 519void CalendarView::computeAlarm( QString msg )
520{ 520{
521 521
522 QString mess = msg; 522 QString mess = msg;
523 QString mAlarmMessage = mess.mid( 9 ); 523 QString mAlarmMessage = mess.mid( 9 );
524 QString filename = MainWindow::resourcePath(); 524 QString filename = MainWindow::resourcePath();
525 filename += "koalarm.wav"; 525 filename += "koalarm.wav";
526 QString tempfilename; 526 QString tempfilename;
527 if ( mess.left( 13 ) == "suspend_alarm") { 527 if ( mess.left( 13 ) == "suspend_alarm") {
528 bool error = false; 528 bool error = false;
529 int len = mess.mid( 13 ).find("+++"); 529 int len = mess.mid( 13 ).find("+++");
530 if ( len < 2 ) 530 if ( len < 2 )
531 error = true; 531 error = true;
532 else { 532 else {
533 tempfilename = mess.mid( 13, len ); 533 tempfilename = mess.mid( 13, len );
534 if ( !QFile::exists( tempfilename ) ) 534 if ( !QFile::exists( tempfilename ) )
535 error = true; 535 error = true;
536 } 536 }
537 if ( ! error ) { 537 if ( ! error ) {
538 filename = tempfilename; 538 filename = tempfilename;
539 } 539 }
540 mAlarmMessage = mess.mid( 13+len+3 ); 540 mAlarmMessage = mess.mid( 13+len+3 );
541 //qDebug("suspend file %s ",tempfilename.latin1() ); 541 //qDebug("suspend file %s ",tempfilename.latin1() );
542 startAlarm( mAlarmMessage, filename); 542 startAlarm( mAlarmMessage, filename);
543 return; 543 return;
544 } 544 }
545 if ( mess.left( 11 ) == "timer_alarm") { 545 if ( mess.left( 11 ) == "timer_alarm") {
546 //mTimerTime = 0; 546 //mTimerTime = 0;
547 startAlarm( mess.mid( 11 ), filename ); 547 startAlarm( mess.mid( 11 ), filename );
548 return; 548 return;
549 } 549 }
550 if ( mess.left( 10 ) == "proc_alarm") { 550 if ( mess.left( 10 ) == "proc_alarm") {
551 bool error = false; 551 bool error = false;
552 int len = mess.mid( 10 ).find("+++"); 552 int len = mess.mid( 10 ).find("+++");
553 if ( len < 2 ) 553 if ( len < 2 )
554 error = true; 554 error = true;
555 else { 555 else {
556 tempfilename = mess.mid( 10, len ); 556 tempfilename = mess.mid( 10, len );
557 if ( !QFile::exists( tempfilename ) ) 557 if ( !QFile::exists( tempfilename ) )
558 error = true; 558 error = true;
559 } 559 }
560 if ( error ) { 560 if ( error ) {
561 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 561 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
562 mAlarmMessage += mess.mid( 10+len+3+9 ); 562 mAlarmMessage += mess.mid( 10+len+3+9 );
563 } else { 563 } else {
564 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 564 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
565 //qDebug("-----system command %s ",tempfilename.latin1() ); 565 //qDebug("-----system command %s ",tempfilename.latin1() );
566#ifndef _WIN32_ 566#ifndef _WIN32_
567 if ( vfork () == 0 ) { 567 if ( vfork () == 0 ) {
568 execl ( tempfilename.latin1(), 0 ); 568 execl ( tempfilename.latin1(), 0 );
569 return; 569 return;
570 } 570 }
571#else 571#else
572 QProcess* p = new QProcess(); 572 QProcess* p = new QProcess();
573 p->addArgument( tempfilename.latin1() ); 573 p->addArgument( tempfilename.latin1() );
574 p->start(); 574 p->start();
575 return; 575 return;
576#endif 576#endif
577 577
578 return; 578 return;
579 } 579 }
580 580
581 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 581 //qDebug("+++++++system command %s ",tempfilename.latin1() );
582 } 582 }
583 if ( mess.left( 11 ) == "audio_alarm") { 583 if ( mess.left( 11 ) == "audio_alarm") {
584 bool error = false; 584 bool error = false;
585 int len = mess.mid( 11 ).find("+++"); 585 int len = mess.mid( 11 ).find("+++");
586 if ( len < 2 ) 586 if ( len < 2 )
587 error = true; 587 error = true;
588 else { 588 else {
589 tempfilename = mess.mid( 11, len ); 589 tempfilename = mess.mid( 11, len );
590 if ( !QFile::exists( tempfilename ) ) 590 if ( !QFile::exists( tempfilename ) )
591 error = true; 591 error = true;
592 } 592 }
593 if ( ! error ) { 593 if ( ! error ) {
594 filename = tempfilename; 594 filename = tempfilename;
595 } 595 }
596 mAlarmMessage = mess.mid( 11+len+3+9 ); 596 mAlarmMessage = mess.mid( 11+len+3+9 );
597 //qDebug("audio file command %s ",tempfilename.latin1() ); 597 //qDebug("audio file command %s ",tempfilename.latin1() );
598 } 598 }
599 if ( mess.left( 9 ) == "cal_alarm") { 599 if ( mess.left( 9 ) == "cal_alarm") {
600 mAlarmMessage = mess.mid( 9 ) ; 600 mAlarmMessage = mess.mid( 9 ) ;
601 } 601 }
602 602
603 startAlarm( mAlarmMessage, filename ); 603 startAlarm( mAlarmMessage, filename );
604 604
605 605
606} 606}
607 607
608void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 608void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
609{ 609{
610 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 610 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
611 611
612 mSuspendAlarmNotification = noti; 612 mSuspendAlarmNotification = noti;
613 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 613 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
614 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 614 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
615 mSuspendTimer->start( ms , true ); 615 mSuspendTimer->start( ms , true );
616 616
617} 617}
618 618
619void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 619void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
620{ 620{
621 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 621 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
622 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 622 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
623#ifndef DESKTOP_VERSION 623#ifndef DESKTOP_VERSION
624 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 624 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
625#endif 625#endif
626 return; 626 return;
627 } 627 }
628 int maxSec; 628 int maxSec;
629 //maxSec = 5; //testing only 629 //maxSec = 5; //testing only
630 maxSec = 86400+3600; // one day+1hour 630 maxSec = 86400+3600; // one day+1hour
631 mAlarmNotification = noti; 631 mAlarmNotification = noti;
632 int sec = QDateTime::currentDateTime().secsTo( qdt ); 632 int sec = QDateTime::currentDateTime().secsTo( qdt );
633 if ( sec > maxSec ) { 633 if ( sec > maxSec ) {
634 mRecheckAlarmTimer->start( maxSec * 1000 ); 634 mRecheckAlarmTimer->start( maxSec * 1000 );
635 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 635 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
636 return; 636 return;
637 } else { 637 } else {
638 mRecheckAlarmTimer->stop(); 638 mRecheckAlarmTimer->stop();
639 } 639 }
640 //qDebug("Alarm timer started with secs: %d ", sec); 640 //qDebug("Alarm timer started with secs: %d ", sec);
641 mAlarmTimer->start( sec *1000 , true ); 641 mAlarmTimer->start( sec *1000 , true );
642 642
643} 643}
644// called by mRecheckAlarmTimer to get next alarm 644// called by mRecheckAlarmTimer to get next alarm
645// we need this, because a QTimer has only a max range of 25 days 645// we need this, because a QTimer has only a max range of 25 days
646void CalendarView::recheckTimerAlarm() 646void CalendarView::recheckTimerAlarm()
647{ 647{
648 mAlarmTimer->stop(); 648 mAlarmTimer->stop();
649 mRecheckAlarmTimer->stop(); 649 mRecheckAlarmTimer->stop();
650 mCalendar->checkAlarmForIncidence( 0, true ); 650 mCalendar->checkAlarmForIncidence( 0, true );
651} 651}
652void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 652void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
653{ 653{
654 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 654 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
655 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 655 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
656#ifndef DESKTOP_VERSION 656#ifndef DESKTOP_VERSION
657 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 657 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
658#endif 658#endif
659 return; 659 return;
660 } 660 }
661 mAlarmTimer->stop(); 661 mAlarmTimer->stop();
662} 662}
663void CalendarView::selectWeekNum ( int num ) 663void CalendarView::selectWeekNum ( int num )
664{ 664{
665 dateNavigator()->selectWeek( num ); 665 dateNavigator()->selectWeek( num );
666 mViewManager->showWeekView(); 666 mViewManager->showWeekView();
667} 667}
668KOViewManager *CalendarView::viewManager() 668KOViewManager *CalendarView::viewManager()
669{ 669{
670 return mViewManager; 670 return mViewManager;
671} 671}
672 672
673KODialogManager *CalendarView::dialogManager() 673KODialogManager *CalendarView::dialogManager()
674{ 674{
675 return mDialogManager; 675 return mDialogManager;
676} 676}
677 677
678QDate CalendarView::startDate() 678QDate CalendarView::startDate()
679{ 679{
680 DateList dates = mNavigator->selectedDates(); 680 DateList dates = mNavigator->selectedDates();
681 681
682 return dates.first(); 682 return dates.first();
683} 683}
684 684
685QDate CalendarView::endDate() 685QDate CalendarView::endDate()
686{ 686{
687 DateList dates = mNavigator->selectedDates(); 687 DateList dates = mNavigator->selectedDates();
688 688
689 return dates.last(); 689 return dates.last();
690} 690}
691 691
692 692
693void CalendarView::createPrinter() 693void CalendarView::createPrinter()
694{ 694{
695#ifndef KORG_NOPRINTER 695#ifndef KORG_NOPRINTER
696 if (!mCalPrinter) { 696 if (!mCalPrinter) {
697 mCalPrinter = new CalPrinter(this, mCalendar); 697 mCalPrinter = new CalPrinter(this, mCalendar);
698 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 698 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
699 } 699 }
700#endif 700#endif
701} 701}
702 702
703 703
704//KOPrefs::instance()->mWriteBackFile 704//KOPrefs::instance()->mWriteBackFile
705//KOPrefs::instance()->mWriteBackExistingOnly 705//KOPrefs::instance()->mWriteBackExistingOnly
706 706
707// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 707// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
708// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 708// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
709// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 709// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
710// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 710// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
711// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 711// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
712// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 712// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
713 713
714int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 714int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
715{ 715{
716 716
717 // 0 equal 717 // 0 equal
718 // 1 take local 718 // 1 take local
719 // 2 take remote 719 // 2 take remote
720 // 3 cancel 720 // 3 cancel
721 QDateTime lastSync = mLastCalendarSync; 721 QDateTime lastSync = mLastCalendarSync;
722 QDateTime localMod = local->lastModified(); 722 QDateTime localMod = local->lastModified();
723 QDateTime remoteMod = remote->lastModified(); 723 QDateTime remoteMod = remote->lastModified();
724 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 724 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
725 bool remCh, locCh; 725 bool remCh, locCh;
726 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 726 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
727 //if ( remCh ) 727 //if ( remCh )
728 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 728 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
729 locCh = ( localMod > mLastCalendarSync ); 729 locCh = ( localMod > mLastCalendarSync );
730 if ( !remCh && ! locCh ) { 730 if ( !remCh && ! locCh ) {
731 //qDebug("both not changed "); 731 //qDebug("both not changed ");
732 lastSync = localMod.addDays(1); 732 lastSync = localMod.addDays(1);
733 if ( mode <= SYNC_PREF_ASK ) 733 if ( mode <= SYNC_PREF_ASK )
734 return 0; 734 return 0;
735 } else { 735 } else {
736 if ( locCh ) { 736 if ( locCh ) {
737 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 737 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
738 lastSync = localMod.addDays( -1 ); 738 lastSync = localMod.addDays( -1 );
739 if ( !remCh ) 739 if ( !remCh )
740 remoteMod = ( lastSync.addDays( -1 ) ); 740 remoteMod = ( lastSync.addDays( -1 ) );
741 } else { 741 } else {
742 //qDebug(" not loc changed "); 742 //qDebug(" not loc changed ");
743 lastSync = localMod.addDays( 1 ); 743 lastSync = localMod.addDays( 1 );
744 if ( remCh ) 744 if ( remCh )
745 remoteMod =( lastSync.addDays( 1 ) ); 745 remoteMod =( lastSync.addDays( 1 ) );
746 746
747 } 747 }
748 } 748 }
749 full = true; 749 full = true;
750 if ( mode < SYNC_PREF_ASK ) 750 if ( mode < SYNC_PREF_ASK )
751 mode = SYNC_PREF_ASK; 751 mode = SYNC_PREF_ASK;
752 } else { 752 } else {
753 if ( localMod == remoteMod ) 753 if ( localMod == remoteMod )
754 // if ( local->revision() == remote->revision() ) 754 // if ( local->revision() == remote->revision() )
755 return 0; 755 return 0;
756 756
757 } 757 }
758 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 758 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
759 759
760 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 760 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
761 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 761 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
762 //full = true; //debug only 762 //full = true; //debug only
763 if ( full ) { 763 if ( full ) {
764 bool equ = false; 764 bool equ = false;
765 if ( local->type() == "Event" ) { 765 if ( local->type() == "Event" ) {
766 equ = (*((Event*) local) == *((Event*) remote)); 766 equ = (*((Event*) local) == *((Event*) remote));
767 } 767 }
768 else if ( local->type() =="Todo" ) 768 else if ( local->type() =="Todo" )
769 equ = (*((Todo*) local) == (*(Todo*) remote)); 769 equ = (*((Todo*) local) == (*(Todo*) remote));
770 else if ( local->type() =="Journal" ) 770 else if ( local->type() =="Journal" )
771 equ = (*((Journal*) local) == *((Journal*) remote)); 771 equ = (*((Journal*) local) == *((Journal*) remote));
772 if ( equ ) { 772 if ( equ ) {
773 //qDebug("equal "); 773 //qDebug("equal ");
774 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 774 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
775 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 775 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
776 } 776 }
777 if ( mode < SYNC_PREF_FORCE_LOCAL ) 777 if ( mode < SYNC_PREF_FORCE_LOCAL )
778 return 0; 778 return 0;
779 779
780 }//else //debug only 780 }//else //debug only
781 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 781 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
782 } 782 }
783 int result; 783 int result;
784 bool localIsNew; 784 bool localIsNew;
785 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); 785 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
786 786
787 if ( full && mode < SYNC_PREF_NEWEST ) 787 if ( full && mode < SYNC_PREF_NEWEST )
788 mode = SYNC_PREF_ASK; 788 mode = SYNC_PREF_ASK;
789 789
790 switch( mode ) { 790 switch( mode ) {
791 case SYNC_PREF_LOCAL: 791 case SYNC_PREF_LOCAL:
792 if ( lastSync > remoteMod ) 792 if ( lastSync > remoteMod )
793 return 1; 793 return 1;
794 if ( lastSync > localMod ) 794 if ( lastSync > localMod )
795 return 2; 795 return 2;
796 return 1; 796 return 1;
797 break; 797 break;
798 case SYNC_PREF_REMOTE: 798 case SYNC_PREF_REMOTE:
799 if ( lastSync > remoteMod ) 799 if ( lastSync > remoteMod )
800 return 1; 800 return 1;
801 if ( lastSync > localMod ) 801 if ( lastSync > localMod )
802 return 2; 802 return 2;
803 return 2; 803 return 2;
804 break; 804 break;
805 case SYNC_PREF_NEWEST: 805 case SYNC_PREF_NEWEST:
806 if ( localMod > remoteMod ) 806 if ( localMod > remoteMod )
807 return 1; 807 return 1;
808 else 808 else
809 return 2; 809 return 2;
810 break; 810 break;
811 case SYNC_PREF_ASK: 811 case SYNC_PREF_ASK:
812 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 812 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
813 if ( lastSync > remoteMod ) 813 if ( lastSync > remoteMod )
814 return 1; 814 return 1;
815 if ( lastSync > localMod ) 815 if ( lastSync > localMod )
816 return 2; 816 return 2;
817 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 817 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
818 localIsNew = localMod >= remoteMod; 818 localIsNew = localMod >= remoteMod;
819 if ( localIsNew ) 819 if ( localIsNew )
820 getEventViewerDialog()->setColorMode( 1 ); 820 getEventViewerDialog()->setColorMode( 1 );
821 else 821 else
822 getEventViewerDialog()->setColorMode( 2 ); 822 getEventViewerDialog()->setColorMode( 2 );
823 getEventViewerDialog()->setIncidence(local); 823 getEventViewerDialog()->setIncidence(local);
824 if ( localIsNew ) 824 if ( localIsNew )
825 getEventViewerDialog()->setColorMode( 2 ); 825 getEventViewerDialog()->setColorMode( 2 );
826 else 826 else
827 getEventViewerDialog()->setColorMode( 1 ); 827 getEventViewerDialog()->setColorMode( 1 );
828 getEventViewerDialog()->addIncidence(remote); 828 getEventViewerDialog()->addIncidence(remote);
829 getEventViewerDialog()->setColorMode( 0 ); 829 getEventViewerDialog()->setColorMode( 0 );
830 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 830 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
831 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 831 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
832 getEventViewerDialog()->showMe(); 832 getEventViewerDialog()->showMe();
833 result = getEventViewerDialog()->executeS( localIsNew ); 833 result = getEventViewerDialog()->executeS( localIsNew );
834 return result; 834 return result;
835 835
836 break; 836 break;
837 case SYNC_PREF_FORCE_LOCAL: 837 case SYNC_PREF_FORCE_LOCAL:
838 return 1; 838 return 1;
839 break; 839 break;
840 case SYNC_PREF_FORCE_REMOTE: 840 case SYNC_PREF_FORCE_REMOTE:
841 return 2; 841 return 2;
842 break; 842 break;
843 843
844 default: 844 default:
845 // SYNC_PREF_TAKE_BOTH not implemented 845 // SYNC_PREF_TAKE_BOTH not implemented
846 break; 846 break;
847 } 847 }
848 return 0; 848 return 0;
849} 849}
850Event* CalendarView::getLastSyncEvent() 850Event* CalendarView::getLastSyncEvent()
851{ 851{
852 Event* lse; 852 Event* lse;
853 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 853 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
854 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 854 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
855 if (!lse) { 855 if (!lse) {
856 lse = new Event(); 856 lse = new Event();
857 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 857 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
858 QString sum = ""; 858 QString sum = "";
859 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 859 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
860 sum = "E: "; 860 sum = "E: ";
861 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 861 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
862 lse->setDtStart( mLastCalendarSync ); 862 lse->setDtStart( mLastCalendarSync );
863 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 863 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
864 lse->setCategories( i18n("SyncEvent") ); 864 lse->setCategories( i18n("SyncEvent") );
865 lse->setReadOnly( true ); 865 lse->setReadOnly( true );
866 mCalendar->addEvent( lse ); 866 mCalendar->addEvent( lse );
867 } 867 }
868 868
869 return lse; 869 return lse;
870 870
871} 871}
872 872
873// we check, if the to delete event has a id for a profile 873// we check, if the to delete event has a id for a profile
874// if yes, we set this id in the profile to delete 874// if yes, we set this id in the profile to delete
875void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 875void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
876{ 876{
877 if ( lastSync.count() == 0 ) { 877 if ( lastSync.count() == 0 ) {
878 //qDebug(" lastSync.count() == 0"); 878 //qDebug(" lastSync.count() == 0");
879 return; 879 return;
880 } 880 }
881 if ( toDelete->type() == "Journal" ) 881 if ( toDelete->type() == "Journal" )
882 return; 882 return;
883 883
884 Event* eve = lastSync.first(); 884 Event* eve = lastSync.first();
885 885
886 while ( eve ) { 886 while ( eve ) {
887 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 887 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
888 if ( !id.isEmpty() ) { 888 if ( !id.isEmpty() ) {
889 QString des = eve->description(); 889 QString des = eve->description();
890 QString pref = "e"; 890 QString pref = "e";
891 if ( toDelete->type() == "Todo" ) 891 if ( toDelete->type() == "Todo" )
892 pref = "t"; 892 pref = "t";
893 des += pref+ id + ","; 893 des += pref+ id + ",";
894 eve->setReadOnly( false ); 894 eve->setReadOnly( false );
895 eve->setDescription( des ); 895 eve->setDescription( des );
896 //qDebug("setdes %s ", des.latin1()); 896 //qDebug("setdes %s ", des.latin1());
897 eve->setReadOnly( true ); 897 eve->setReadOnly( true );
898 } 898 }
899 eve = lastSync.next(); 899 eve = lastSync.next();
900 } 900 }
901 901
902} 902}
903void CalendarView::checkExternalId( Incidence * inc ) 903void CalendarView::checkExternalId( Incidence * inc )
904{ 904{
905 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 905 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
906 checkExternSyncEvent( lastSync, inc ); 906 checkExternSyncEvent( lastSync, inc );
907 907
908} 908}
909bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 909bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
910{ 910{
911 bool syncOK = true; 911 bool syncOK = true;
912 int addedEvent = 0; 912 int addedEvent = 0;
913 int addedEventR = 0; 913 int addedEventR = 0;
914 int deletedEventR = 0; 914 int deletedEventR = 0;
915 int deletedEventL = 0; 915 int deletedEventL = 0;
916 int changedLocal = 0; 916 int changedLocal = 0;
917 int changedRemote = 0; 917 int changedRemote = 0;
918 //QPtrList<Event> el = local->rawEvents(); 918 //QPtrList<Event> el = local->rawEvents();
919 Event* eventR; 919 Event* eventR;
920 QString uid; 920 QString uid;
921 int take; 921 int take;
922 Event* eventL; 922 Event* eventL;
923 Event* eventRSync; 923 Event* eventRSync;
924 Event* eventLSync; 924 Event* eventLSync;
925 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 925 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
926 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 926 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
927 bool fullDateRange = false; 927 bool fullDateRange = false;
928 local->resetTempSyncStat(); 928 local->resetTempSyncStat();
929 if ( mSyncKDE ) 929 if ( mSyncKDE )
930 remote->resetPilotStat(1); 930 remote->resetPilotStat(1);
931 mLastCalendarSync = QDateTime::currentDateTime(); 931 mLastCalendarSync = QDateTime::currentDateTime();
932 QDateTime modifiedCalendar = mLastCalendarSync;; 932 QDateTime modifiedCalendar = mLastCalendarSync;;
933 eventLSync = getLastSyncEvent(); 933 eventLSync = getLastSyncEvent();
934 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 934 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
935 if ( eventR ) { 935 if ( eventR ) {
936 eventRSync = (Event*) eventR->clone(); 936 eventRSync = (Event*) eventR->clone();
937 remote->deleteEvent(eventR ); 937 remote->deleteEvent(eventR );
938 938
939 } else { 939 } else {
940 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncKDE) { 940 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncKDE) {
941 eventRSync = (Event*)eventLSync->clone(); 941 eventRSync = (Event*)eventLSync->clone();
942 } else { 942 } else {
943 fullDateRange = true; 943 fullDateRange = true;
944 eventRSync = new Event(); 944 eventRSync = new Event();
945 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 945 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
946 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 946 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
947 eventRSync->setDtStart( mLastCalendarSync ); 947 eventRSync->setDtStart( mLastCalendarSync );
948 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 948 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
949 eventRSync->setCategories( i18n("SyncEvent") ); 949 eventRSync->setCategories( i18n("SyncEvent") );
950 } 950 }
951 } 951 }
952 if ( eventLSync->dtStart() == mLastCalendarSync ) 952 if ( eventLSync->dtStart() == mLastCalendarSync )
953 fullDateRange = true; 953 fullDateRange = true;
954 954
955 if ( ! fullDateRange ) { 955 if ( ! fullDateRange ) {
956 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 956 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
957 957
958 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 958 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
959 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 959 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
960 fullDateRange = true; 960 fullDateRange = true;
961 } 961 }
962 } 962 }
963 if ( mSyncKDE ) { 963 if ( mSyncKDE ) {
964 fullDateRange = ( eventLSync->dtStart() == mLastCalendarSync ); 964 fullDateRange = ( eventLSync->dtStart() == mLastCalendarSync );
965 } 965 }
966 if ( fullDateRange ) 966 if ( fullDateRange )
967 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 967 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
968 else 968 else
969 mLastCalendarSync = eventLSync->dtStart(); 969 mLastCalendarSync = eventLSync->dtStart();
970 // for resyncing if own file has changed 970 // for resyncing if own file has changed
971 if ( mCurrentSyncDevice == "deleteaftersync" ) { 971 if ( mCurrentSyncDevice == "deleteaftersync" ) {
972 mLastCalendarSync = loadedFileVersion; 972 mLastCalendarSync = loadedFileVersion;
973 //qDebug("setting mLastCalendarSync "); 973 //qDebug("setting mLastCalendarSync ");
974 } 974 }
975 //qDebug("*************************** "); 975 //qDebug("*************************** ");
976 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 976 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
977 QPtrList<Incidence> er = remote->rawIncidences(); 977 QPtrList<Incidence> er = remote->rawIncidences();
978 Incidence* inR = er.first(); 978 Incidence* inR = er.first();
979 Incidence* inL; 979 Incidence* inL;
980 QProgressBar bar( er.count(),0 ); 980 QProgressBar bar( er.count(),0 );
981 bar.setCaption (i18n("Syncing - close to abort!") ); 981 bar.setCaption (i18n("Syncing - close to abort!") );
982 982
983 int w = 300; 983 int w = 300;
984 if ( QApplication::desktop()->width() < 320 ) 984 if ( QApplication::desktop()->width() < 320 )
985 w = 220; 985 w = 220;
986 int h = bar.sizeHint().height() ; 986 int h = bar.sizeHint().height() ;
987 int dw = QApplication::desktop()->width(); 987 int dw = QApplication::desktop()->width();
988 int dh = QApplication::desktop()->height(); 988 int dh = QApplication::desktop()->height();
989 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 989 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
990 bar.show(); 990 bar.show();
991 int modulo = (er.count()/10)+1; 991 int modulo = (er.count()/10)+1;
992 int incCounter = 0; 992 int incCounter = 0;
993 while ( inR ) { 993 while ( inR ) {
994 if ( ! bar.isVisible() ) 994 if ( ! bar.isVisible() )
995 return false; 995 return false;
996 if ( incCounter % modulo == 0 ) 996 if ( incCounter % modulo == 0 )
997 bar.setProgress( incCounter ); 997 bar.setProgress( incCounter );
998 ++incCounter; 998 ++incCounter;
999 uid = inR->uid(); 999 uid = inR->uid();
1000 bool skipIncidence = false; 1000 bool skipIncidence = false;
1001 if ( uid.left(15) == QString("last-syncEvent-") ) 1001 if ( uid.left(15) == QString("last-syncEvent-") )
1002 skipIncidence = true; 1002 skipIncidence = true;
1003 QString idS; 1003 QString idS;
1004 qApp->processEvents(); 1004 qApp->processEvents();
1005 if ( !skipIncidence ) { 1005 if ( !skipIncidence ) {
1006 inL = local->incidence( uid ); 1006 inL = local->incidence( uid );
1007 if ( inL ) { // maybe conflict - same uid in both calendars 1007 if ( inL ) { // maybe conflict - same uid in both calendars
1008 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1008 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1009 //qDebug("take %d %s ", take, inL->summary().latin1()); 1009 //qDebug("take %d %s ", take, inL->summary().latin1());
1010 if ( take == 3 ) 1010 if ( take == 3 )
1011 return false; 1011 return false;
1012 if ( take == 1 ) {// take local 1012 if ( take == 1 ) {// take local
1013 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1013 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1014 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1014 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1015 else 1015 else
1016 idS = inR->IDStr(); 1016 idS = inR->IDStr();
1017 remote->deleteIncidence( inR ); 1017 remote->deleteIncidence( inR );
1018 inR = inL->clone(); 1018 inR = inL->clone();
1019 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1019 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1020 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1020 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1021 inR->setIDStr( idS ); 1021 inR->setIDStr( idS );
1022 remote->addIncidence( inR ); 1022 remote->addIncidence( inR );
1023 if ( mSyncKDE ) 1023 if ( mSyncKDE )
1024 inR->setPilotId( 2 ); 1024 inR->setPilotId( 2 );
1025 ++changedRemote; 1025 ++changedRemote;
1026 } else { 1026 } else {
1027 idS = inL->IDStr(); 1027 idS = inL->IDStr();
1028 int pid = inL->pilotId(); 1028 int pid = inL->pilotId();
1029 local->deleteIncidence( inL ); 1029 local->deleteIncidence( inL );
1030 inL = inR->clone(); 1030 inL = inR->clone();
1031 if ( mSyncKDE ) 1031 if ( mSyncKDE )
1032 inL->setPilotId( pid ); 1032 inL->setPilotId( pid );
1033 inL->setIDStr( idS ); 1033 inL->setIDStr( idS );
1034 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1034 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1035 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1035 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1036 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1036 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1037 } 1037 }
1038 local->addIncidence( inL ); 1038 local->addIncidence( inL );
1039 ++changedLocal; 1039 ++changedLocal;
1040 } 1040 }
1041 } 1041 }
1042 } else { // no conflict 1042 } else { // no conflict
1043 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1043 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1044 QString des = eventLSync->description(); 1044 QString des = eventLSync->description();
1045 QString pref = "e"; 1045 QString pref = "e";
1046 if ( inR->type() == "Todo" ) 1046 if ( inR->type() == "Todo" )
1047 pref = "t"; 1047 pref = "t";
1048 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1048 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1049 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1049 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1050 //remote->deleteIncidence( inR ); 1050 //remote->deleteIncidence( inR );
1051 ++deletedEventR; 1051 ++deletedEventR;
1052 } else { 1052 } else {
1053 inR->setLastModified( modifiedCalendar ); 1053 inR->setLastModified( modifiedCalendar );
1054 inL = inR->clone(); 1054 inL = inR->clone();
1055 inL->setIDStr( ":" ); 1055 inL->setIDStr( ":" );
1056 local->addIncidence( inL ); 1056 local->addIncidence( inL );
1057 ++addedEvent; 1057 ++addedEvent;
1058 } 1058 }
1059 } else { 1059 } else {
1060 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1060 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1061 inR->setLastModified( modifiedCalendar ); 1061 inR->setLastModified( modifiedCalendar );
1062 inL = inR->clone(); 1062 inL = inR->clone();
1063 inL->setIDStr( ":" ); 1063 inL->setIDStr( ":" );
1064 local->addIncidence( inL ); 1064 local->addIncidence( inL );
1065 ++addedEvent; 1065 ++addedEvent;
1066 } else { 1066 } else {
1067 checkExternSyncEvent(eventRSyncSharp, inR); 1067 checkExternSyncEvent(eventRSyncSharp, inR);
1068 remote->deleteIncidence( inR ); 1068 remote->deleteIncidence( inR );
1069 ++deletedEventR; 1069 ++deletedEventR;
1070 } 1070 }
1071 } 1071 }
1072 } 1072 }
1073 } 1073 }
1074 inR = er.next(); 1074 inR = er.next();
1075 } 1075 }
1076 QPtrList<Incidence> el = local->rawIncidences(); 1076 QPtrList<Incidence> el = local->rawIncidences();
1077 inL = el.first(); 1077 inL = el.first();
1078 modulo = (el.count()/10)+1; 1078 modulo = (el.count()/10)+1;
1079 bar.setCaption (i18n("Add / remove events") ); 1079 bar.setCaption (i18n("Add / remove events") );
1080 bar.setTotalSteps ( el.count() ) ; 1080 bar.setTotalSteps ( el.count() ) ;
1081 bar.show(); 1081 bar.show();
1082 incCounter = 0; 1082 incCounter = 0;
1083 1083
1084 while ( inL ) { 1084 while ( inL ) {
1085 1085
1086 qApp->processEvents(); 1086 qApp->processEvents();
1087 if ( ! bar.isVisible() ) 1087 if ( ! bar.isVisible() )
1088 return false; 1088 return false;
1089 if ( incCounter % modulo == 0 ) 1089 if ( incCounter % modulo == 0 )
1090 bar.setProgress( incCounter ); 1090 bar.setProgress( incCounter );
1091 ++incCounter; 1091 ++incCounter;
1092 uid = inL->uid(); 1092 uid = inL->uid();
1093 bool skipIncidence = false; 1093 bool skipIncidence = false;
1094 if ( uid.left(15) == QString("last-syncEvent-") ) 1094 if ( uid.left(15) == QString("last-syncEvent-") )
1095 skipIncidence = true; 1095 skipIncidence = true;
1096 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1096 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1097 skipIncidence = true; 1097 skipIncidence = true;
1098 if ( !skipIncidence ) { 1098 if ( !skipIncidence ) {
1099 inR = remote->incidence( uid ); 1099 inR = remote->incidence( uid );
1100 if ( ! inR ) { 1100 if ( ! inR ) {
1101 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1101 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1102 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1102 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1103 checkExternSyncEvent(eventLSyncSharp, inL); 1103 checkExternSyncEvent(eventLSyncSharp, inL);
1104 local->deleteIncidence( inL ); 1104 local->deleteIncidence( inL );
1105 ++deletedEventL; 1105 ++deletedEventL;
1106 } else { 1106 } else {
1107 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1107 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1108 inL->removeID(mCurrentSyncDevice ); 1108 inL->removeID(mCurrentSyncDevice );
1109 ++addedEventR; 1109 ++addedEventR;
1110 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1110 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1111 inL->setLastModified( modifiedCalendar ); 1111 inL->setLastModified( modifiedCalendar );
1112 inR = inL->clone(); 1112 inR = inL->clone();
1113 inR->setIDStr( ":" ); 1113 inR->setIDStr( ":" );
1114 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1114 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1115 remote->addIncidence( inR ); 1115 remote->addIncidence( inR );
1116 } 1116 }
1117 } 1117 }
1118 } else { 1118 } else {
1119 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1119 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1120 checkExternSyncEvent(eventLSyncSharp, inL); 1120 checkExternSyncEvent(eventLSyncSharp, inL);
1121 local->deleteIncidence( inL ); 1121 local->deleteIncidence( inL );
1122 ++deletedEventL; 1122 ++deletedEventL;
1123 } else { 1123 } else {
1124 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1124 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1125 ++addedEventR; 1125 ++addedEventR;
1126 inL->setLastModified( modifiedCalendar ); 1126 inL->setLastModified( modifiedCalendar );
1127 inR = inL->clone(); 1127 inR = inL->clone();
1128 inR->setIDStr( ":" ); 1128 inR->setIDStr( ":" );
1129 remote->addIncidence( inR ); 1129 remote->addIncidence( inR );
1130 } 1130 }
1131 } 1131 }
1132 } 1132 }
1133 } 1133 }
1134 } 1134 }
1135 inL = el.next(); 1135 inL = el.next();
1136 } 1136 }
1137 int delFut = 0; 1137 int delFut = 0;
1138 int remRem = 0; 1138 int remRem = 0;
1139 if ( mSyncManager->mWriteBackInFuture ) { 1139 if ( mSyncManager->mWriteBackInFuture ) {
1140 er = remote->rawIncidences(); 1140 er = remote->rawIncidences();
1141 remRem = er.count(); 1141 remRem = er.count();
1142 inR = er.first(); 1142 inR = er.first();
1143 QDateTime dt; 1143 QDateTime dt;
1144 QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); 1144 QDateTime cur = QDateTime::currentDateTime().addDays( -7 );
1145 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 ); 1145 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 );
1146 while ( inR ) { 1146 while ( inR ) {
1147 if ( inR->type() == "Todo" ) { 1147 if ( inR->type() == "Todo" ) {
1148 Todo * t = (Todo*)inR; 1148 Todo * t = (Todo*)inR;
1149 if ( t->hasDueDate() ) 1149 if ( t->hasDueDate() )
1150 dt = t->dtDue(); 1150 dt = t->dtDue();
1151 else 1151 else
1152 dt = cur.addSecs( 62 ); 1152 dt = cur.addSecs( 62 );
1153 } 1153 }
1154 else if (inR->type() == "Event" ) { 1154 else if (inR->type() == "Event" ) {
1155 bool ok; 1155 bool ok;
1156 dt = inR->getNextOccurence( cur, &ok ); 1156 dt = inR->getNextOccurence( cur, &ok );
1157 if ( !ok ) 1157 if ( !ok )
1158 dt = cur.addSecs( -62 ); 1158 dt = cur.addSecs( -62 );
1159 } 1159 }
1160 else 1160 else
1161 dt = inR->dtStart(); 1161 dt = inR->dtStart();
1162 if ( dt < cur || dt > end ) { 1162 if ( dt < cur || dt > end ) {
1163 remote->deleteIncidence( inR ); 1163 remote->deleteIncidence( inR );
1164 ++delFut; 1164 ++delFut;
1165 } 1165 }
1166 inR = er.next(); 1166 inR = er.next();
1167 } 1167 }
1168 } 1168 }
1169 bar.hide(); 1169 bar.hide();
1170 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1170 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1171 eventLSync->setReadOnly( false ); 1171 eventLSync->setReadOnly( false );
1172 eventLSync->setDtStart( mLastCalendarSync ); 1172 eventLSync->setDtStart( mLastCalendarSync );
1173 eventRSync->setDtStart( mLastCalendarSync ); 1173 eventRSync->setDtStart( mLastCalendarSync );
1174 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1174 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1175 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1175 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1176 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1176 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1177 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1177 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1178 eventLSync->setReadOnly( true ); 1178 eventLSync->setReadOnly( true );
1179 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncKDE) // kde is abnormal... 1179 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncKDE) // kde is abnormal...
1180 remote->addEvent( eventRSync ); 1180 remote->addEvent( eventRSync );
1181 else 1181 else
1182 delete eventRSync; 1182 delete eventRSync;
1183 QString mes; 1183 QString mes;
1184 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"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); 1184 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"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR );
1185 QString delmess; 1185 QString delmess;
1186 if ( delFut ) { 1186 if ( delFut ) {
1187 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInFuture, remRem-delFut); 1187 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInFuture, remRem-delFut);
1188 mes += delmess; 1188 mes += delmess;
1189 } 1189 }
1190 if ( mSyncManager->mShowSyncSummary ) { 1190 if ( mSyncManager->mShowSyncSummary ) {
1191 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1191 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1192 } 1192 }
1193 qDebug( mes ); 1193 qDebug( mes );
1194 mCalendar->checkAlarmForIncidence( 0, true ); 1194 mCalendar->checkAlarmForIncidence( 0, true );
1195 return syncOK; 1195 return syncOK;
1196} 1196}
1197 1197
1198void CalendarView::setSyncDevice( QString s ) 1198void CalendarView::setSyncDevice( QString s )
1199{ 1199{
1200 mCurrentSyncDevice= s; 1200 mCurrentSyncDevice= s;
1201} 1201}
1202void CalendarView::setSyncName( QString s ) 1202void CalendarView::setSyncName( QString s )
1203{ 1203{
1204 mCurrentSyncName= s; 1204 mCurrentSyncName= s;
1205} 1205}
1206bool CalendarView::syncCalendar(QString filename, int mode) 1206bool CalendarView::syncCalendar(QString filename, int mode)
1207{ 1207{
1208 //qDebug("syncCalendar %s ", filename.latin1()); 1208 //qDebug("syncCalendar %s ", filename.latin1());
1209 mGlobalSyncMode = SYNC_MODE_NORMAL; 1209 mGlobalSyncMode = SYNC_MODE_NORMAL;
1210 CalendarLocal* calendar = new CalendarLocal(); 1210 CalendarLocal* calendar = new CalendarLocal();
1211 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1211 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1212 FileStorage* storage = new FileStorage( calendar ); 1212 FileStorage* storage = new FileStorage( calendar );
1213 bool syncOK = false; 1213 bool syncOK = false;
1214 storage->setFileName( filename ); 1214 storage->setFileName( filename );
1215 // qDebug("loading ... "); 1215 // qDebug("loading ... ");
1216 if ( storage->load() ) { 1216 if ( storage->load() ) {
1217 getEventViewerDialog()->setSyncMode( true ); 1217 getEventViewerDialog()->setSyncMode( true );
1218 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1218 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1219 getEventViewerDialog()->setSyncMode( false ); 1219 getEventViewerDialog()->setSyncMode( false );
1220 if ( syncOK ) { 1220 if ( syncOK ) {
1221 if ( mSyncManager->mWriteBackFile ) 1221 if ( mSyncManager->mWriteBackFile )
1222 { 1222 {
1223 storage->setSaveFormat( new ICalFormat() ); 1223 storage->setSaveFormat( new ICalFormat() );
1224 storage->save(); 1224 storage->save();
1225 } 1225 }
1226 } 1226 }
1227 setModified( true ); 1227 setModified( true );
1228 } 1228 }
1229 delete storage; 1229 delete storage;
1230 delete calendar; 1230 delete calendar;
1231 if ( syncOK ) 1231 if ( syncOK )
1232 updateView(); 1232 updateView();
1233 return syncOK; 1233 return syncOK;
1234} 1234}
1235 1235
1236void CalendarView::syncExternal( int mode ) 1236void CalendarView::syncExternal( int mode )
1237{ 1237{
1238 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1238 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1239 1239
1240 qApp->processEvents(); 1240 qApp->processEvents();
1241 CalendarLocal* calendar = new CalendarLocal(); 1241 CalendarLocal* calendar = new CalendarLocal();
1242 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1242 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1243 bool syncOK = false; 1243 bool syncOK = false;
1244 bool loadSuccess = false; 1244 bool loadSuccess = false;
1245 PhoneFormat* phoneFormat = 0; 1245 PhoneFormat* phoneFormat = 0;
1246 emit tempDisableBR(true); 1246 emit tempDisableBR(true);
1247#ifndef DESKTOP_VERSION 1247#ifndef DESKTOP_VERSION
1248 SharpFormat* sharpFormat = 0; 1248 SharpFormat* sharpFormat = 0;
1249 if ( mode == 0 ) { // sharp 1249 if ( mode == 0 ) { // sharp
1250 sharpFormat = new SharpFormat () ; 1250 sharpFormat = new SharpFormat () ;
1251 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1251 loadSuccess = sharpFormat->load( calendar, mCalendar );
1252 1252
1253 } else 1253 } else
1254#endif 1254#endif
1255 if ( mode == 1 ) { // phone 1255 if ( mode == 1 ) { // phone
1256 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1256 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1257 mSyncManager->mPhoneDevice, 1257 mSyncManager->mPhoneDevice,
1258 mSyncManager->mPhoneConnection, 1258 mSyncManager->mPhoneConnection,
1259 mSyncManager->mPhoneModel); 1259 mSyncManager->mPhoneModel);
1260 loadSuccess = phoneFormat->load( calendar,mCalendar); 1260 loadSuccess = phoneFormat->load( calendar,mCalendar);
1261 1261
1262 } else { 1262 } else {
1263 emit tempDisableBR(false); 1263 emit tempDisableBR(false);
1264 return; 1264 return;
1265 } 1265 }
1266 if ( loadSuccess ) { 1266 if ( loadSuccess ) {
1267 getEventViewerDialog()->setSyncMode( true ); 1267 getEventViewerDialog()->setSyncMode( true );
1268 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1268 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1269 getEventViewerDialog()->setSyncMode( false ); 1269 getEventViewerDialog()->setSyncMode( false );
1270 qApp->processEvents(); 1270 qApp->processEvents();
1271 if ( syncOK ) { 1271 if ( syncOK ) {
1272 if ( mSyncManager->mWriteBackFile ) 1272 if ( mSyncManager->mWriteBackFile )
1273 { 1273 {
1274 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1274 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1275 Incidence* inc = iL.first(); 1275 Incidence* inc = iL.first();
1276 if ( phoneFormat ) { 1276 if ( phoneFormat ) {
1277 while ( inc ) { 1277 while ( inc ) {
1278 inc->removeID(mCurrentSyncDevice); 1278 inc->removeID(mCurrentSyncDevice);
1279 inc = iL.next(); 1279 inc = iL.next();
1280 } 1280 }
1281 } 1281 }
1282#ifndef DESKTOP_VERSION 1282#ifndef DESKTOP_VERSION
1283 if ( sharpFormat ) 1283 if ( sharpFormat )
1284 sharpFormat->save(calendar); 1284 sharpFormat->save(calendar);
1285#endif 1285#endif
1286 if ( phoneFormat ) 1286 if ( phoneFormat )
1287 phoneFormat->save(calendar); 1287 phoneFormat->save(calendar);
1288 iL = calendar->rawIncidences(); 1288 iL = calendar->rawIncidences();
1289 inc = iL.first(); 1289 inc = iL.first();
1290 Incidence* loc; 1290 Incidence* loc;
1291 while ( inc ) { 1291 while ( inc ) {
1292 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1292 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1293 loc = mCalendar->incidence(inc->uid() ); 1293 loc = mCalendar->incidence(inc->uid() );
1294 if ( loc ) { 1294 if ( loc ) {
1295 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1295 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1296 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1296 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1297 } 1297 }
1298 } 1298 }
1299 inc = iL.next(); 1299 inc = iL.next();
1300 } 1300 }
1301 Incidence* lse = getLastSyncEvent(); 1301 Incidence* lse = getLastSyncEvent();
1302 if ( lse ) { 1302 if ( lse ) {
1303 lse->setReadOnly( false ); 1303 lse->setReadOnly( false );
1304 lse->setDescription( "" ); 1304 lse->setDescription( "" );
1305 lse->setReadOnly( true ); 1305 lse->setReadOnly( true );
1306 } 1306 }
1307 } 1307 }
1308 } 1308 }
1309 setModified( true ); 1309 setModified( true );
1310 } else { 1310 } else {
1311 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1311 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1312 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1312 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1313 question, i18n("Ok")) ; 1313 question, i18n("Ok")) ;
1314 1314
1315 } 1315 }
1316 delete calendar; 1316 delete calendar;
1317 updateView(); 1317 updateView();
1318 emit tempDisableBR(false); 1318 emit tempDisableBR(false);
1319 return ;//syncOK; 1319 return ;//syncOK;
1320 1320
1321} 1321}
1322 1322
1323bool CalendarView::importBday() 1323bool CalendarView::importBday()
1324{ 1324{
1325#ifndef KORG_NOKABC 1325#ifndef KORG_NOKABC
1326 1326
1327#ifdef DESKTOP_VERSION 1327#ifdef DESKTOP_VERSION
1328 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1328 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1329 KABC::AddressBook::Iterator it; 1329 KABC::AddressBook::Iterator it;
1330 int count = 0; 1330 int count = 0;
1331 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1331 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1332 ++count; 1332 ++count;
1333 } 1333 }
1334 QProgressBar bar(count,0 ); 1334 QProgressBar bar(count,0 );
1335 int w = 300; 1335 int w = 300;
1336 if ( QApplication::desktop()->width() < 320 ) 1336 if ( QApplication::desktop()->width() < 320 )
1337 w = 220; 1337 w = 220;
1338 int h = bar.sizeHint().height() ; 1338 int h = bar.sizeHint().height() ;
1339 int dw = QApplication::desktop()->width(); 1339 int dw = QApplication::desktop()->width();
1340 int dh = QApplication::desktop()->height(); 1340 int dh = QApplication::desktop()->height();
1341 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1341 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1342 bar.show(); 1342 bar.show();
1343 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1343 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1344 qApp->processEvents(); 1344 qApp->processEvents();
1345 count = 0; 1345 count = 0;
1346 int addCount = 0; 1346 int addCount = 0;
1347 KCal::Attendee* a = 0; 1347 KCal::Attendee* a = 0;
1348 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1348 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1349 if ( ! bar.isVisible() ) 1349 if ( ! bar.isVisible() )
1350 return false; 1350 return false;
1351 bar.setProgress( count++ ); 1351 bar.setProgress( count++ );
1352 qApp->processEvents(); 1352 qApp->processEvents();
1353 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1353 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1354 if ( (*it).birthday().date().isValid() ){ 1354 if ( (*it).birthday().date().isValid() ){
1355 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1355 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1356 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1356 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1357 ++addCount; 1357 ++addCount;
1358 } 1358 }
1359 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1359 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1360 if ( anni.isValid() ){ 1360 if ( anni.isValid() ){
1361 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1361 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1362 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1362 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1363 ++addCount; 1363 ++addCount;
1364 } 1364 }
1365 } 1365 }
1366 updateView(); 1366 updateView();
1367 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1367 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1368#else //DESKTOP_VERSION 1368#else //DESKTOP_VERSION
1369 1369
1370 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1370 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1371 // the result should now arrive through method insertBirthdays 1371 // the result should now arrive through method insertBirthdays
1372 1372
1373#endif //DESKTOP_VERSION 1373#endif //DESKTOP_VERSION
1374 1374
1375#endif //KORG_NOKABC 1375#endif //KORG_NOKABC
1376 1376
1377 1377
1378 return true; 1378 return true;
1379} 1379}
1380 1380
1381// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1381// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1382void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1382void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1383 const QStringList& anniversaryList, const QStringList& realNameList, 1383 const QStringList& anniversaryList, const QStringList& realNameList,
1384 const QStringList& emailList, const QStringList& assembledNameList, 1384 const QStringList& emailList, const QStringList& assembledNameList,
1385 const QStringList& uidList) 1385 const QStringList& uidList)
1386{ 1386{
1387 qDebug("CalendarView::insertBirthdays"); 1387 qDebug("CalendarView::insertBirthdays");
1388 if (uid == this->name()) 1388 if (uid == this->name())
1389 { 1389 {
1390 int count = birthdayList.count(); 1390 int count = birthdayList.count();
1391 int addCount = 0; 1391 int addCount = 0;
1392 KCal::Attendee* a = 0; 1392 KCal::Attendee* a = 0;
1393 1393
1394 qDebug("CalView 1 %i", count); 1394 qDebug("CalView 1 %i", count);
1395 1395
1396 QProgressBar bar(count,0 ); 1396 QProgressBar bar(count,0 );
1397 int w = 300; 1397 int w = 300;
1398 if ( QApplication::desktop()->width() < 320 ) 1398 if ( QApplication::desktop()->width() < 320 )
1399 w = 220; 1399 w = 220;
1400 int h = bar.sizeHint().height() ; 1400 int h = bar.sizeHint().height() ;
1401 int dw = QApplication::desktop()->width(); 1401 int dw = QApplication::desktop()->width();
1402 int dh = QApplication::desktop()->height(); 1402 int dh = QApplication::desktop()->height();
1403 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1403 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1404 bar.show(); 1404 bar.show();
1405 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1405 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1406 qApp->processEvents(); 1406 qApp->processEvents();
1407 1407
1408 QDate birthday; 1408 QDate birthday;
1409 QDate anniversary; 1409 QDate anniversary;
1410 QString realName; 1410 QString realName;
1411 QString email; 1411 QString email;
1412 QString assembledName; 1412 QString assembledName;
1413 QString uid; 1413 QString uid;
1414 bool ok = true; 1414 bool ok = true;
1415 for ( int i = 0; i < count; i++) 1415 for ( int i = 0; i < count; i++)
1416 { 1416 {
1417 if ( ! bar.isVisible() ) 1417 if ( ! bar.isVisible() )
1418 return; 1418 return;
1419 bar.setProgress( i ); 1419 bar.setProgress( i );
1420 qApp->processEvents(); 1420 qApp->processEvents();
1421 1421
1422 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1422 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1423 if (!ok) { 1423 if (!ok) {
1424 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1424 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1425 } 1425 }
1426 1426
1427 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1427 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1428 if (!ok) { 1428 if (!ok) {
1429 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1429 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1430 } 1430 }
1431 realName = realNameList[i]; 1431 realName = realNameList[i];
1432 email = emailList[i]; 1432 email = emailList[i];
1433 assembledName = assembledNameList[i]; 1433 assembledName = assembledNameList[i];
1434 uid = uidList[i]; 1434 uid = uidList[i];
1435 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); 1435 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() );
1436 1436
1437 if ( birthday.isValid() ){ 1437 if ( birthday.isValid() ){
1438 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1438 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1439 KCal::Attendee::ReqParticipant,uid) ; 1439 KCal::Attendee::ReqParticipant,uid) ;
1440 if ( addAnniversary( birthday, assembledName, a, true ) ) 1440 if ( addAnniversary( birthday, assembledName, a, true ) )
1441 ++addCount; 1441 ++addCount;
1442 } 1442 }
1443 1443
1444 if ( anniversary.isValid() ){ 1444 if ( anniversary.isValid() ){
1445 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1445 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1446 KCal::Attendee::ReqParticipant,uid) ; 1446 KCal::Attendee::ReqParticipant,uid) ;
1447 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1447 if ( addAnniversary( anniversary, assembledName, a, false ) )
1448 ++addCount; 1448 ++addCount;
1449 } 1449 }
1450 } 1450 }
1451 1451
1452 updateView(); 1452 updateView();
1453 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1453 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1454 1454
1455 } 1455 }
1456 1456
1457} 1457}
1458 1458
1459 1459
1460 1460
1461bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1461bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1462{ 1462{
1463 //qDebug("addAnni "); 1463 //qDebug("addAnni ");
1464 Event * ev = new Event(); 1464 Event * ev = new Event();
1465 if ( a ) { 1465 if ( a ) {
1466 ev->addAttendee( a ); 1466 ev->addAttendee( a );
1467 } 1467 }
1468 QString kind; 1468 QString kind;
1469 if ( birthday ) 1469 if ( birthday )
1470 kind = i18n( "Birthday" ); 1470 kind = i18n( "Birthday" );
1471 else 1471 else
1472 kind = i18n( "Anniversary" ); 1472 kind = i18n( "Anniversary" );
1473 ev->setSummary( name + " - " + kind ); 1473 ev->setSummary( name + " - " + kind );
1474 ev->setOrganizer(a->email()); 1474 ev->setOrganizer(a->email());
1475 ev->setCategories( kind ); 1475 ev->setCategories( kind );
1476 ev->setDtStart( QDateTime(date) ); 1476 ev->setDtStart( QDateTime(date) );
1477 ev->setDtEnd( QDateTime(date) ); 1477 ev->setDtEnd( QDateTime(date) );
1478 ev->setFloats( true ); 1478 ev->setFloats( true );
1479 Recurrence * rec = ev->recurrence(); 1479 Recurrence * rec = ev->recurrence();
1480 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1480 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1481 rec->addYearlyNum( date.month() ); 1481 rec->addYearlyNum( date.month() );
1482 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1482 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1483 delete ev; 1483 delete ev;
1484 return false; 1484 return false;
1485 } 1485 }
1486 return true; 1486 return true;
1487 1487
1488} 1488}
1489bool CalendarView::importQtopia( const QString &categories, 1489bool CalendarView::importQtopia( const QString &categories,
1490 const QString &datebook, 1490 const QString &datebook,
1491 const QString &todolist ) 1491 const QString &todolist )
1492{ 1492{
1493 1493
1494 QtopiaFormat qtopiaFormat; 1494 QtopiaFormat qtopiaFormat;
1495 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1495 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1496 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1496 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1497 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1497 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1498 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1498 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1499 1499
1500 updateView(); 1500 updateView();
1501 return true; 1501 return true;
1502 1502
1503#if 0 1503#if 0
1504 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1504 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1505 mCurrentSyncDevice = "qtopia-XML"; 1505 mCurrentSyncDevice = "qtopia-XML";
1506 if ( mSyncManager->mAskForPreferences ) 1506 if ( mSyncManager->mAskForPreferences )
1507 edit_sync_options(); 1507 edit_sync_options();
1508 qApp->processEvents(); 1508 qApp->processEvents();
1509 CalendarLocal* calendar = new CalendarLocal(); 1509 CalendarLocal* calendar = new CalendarLocal();
1510 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1510 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1511 bool syncOK = false; 1511 bool syncOK = false;
1512 QtopiaFormat qtopiaFormat; 1512 QtopiaFormat qtopiaFormat;
1513 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1513 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1514 bool loadOk = true; 1514 bool loadOk = true;
1515 if ( !categories.isEmpty() ) 1515 if ( !categories.isEmpty() )
1516 loadOk = qtopiaFormat.load( calendar, categories ); 1516 loadOk = qtopiaFormat.load( calendar, categories );
1517 if ( loadOk && !datebook.isEmpty() ) 1517 if ( loadOk && !datebook.isEmpty() )
1518 loadOk = qtopiaFormat.load( calendar, datebook ); 1518 loadOk = qtopiaFormat.load( calendar, datebook );
1519 if ( loadOk && !todolist.isEmpty() ) 1519 if ( loadOk && !todolist.isEmpty() )
1520 loadOk = qtopiaFormat.load( calendar, todolist ); 1520 loadOk = qtopiaFormat.load( calendar, todolist );
1521 1521
1522 if ( loadOk ) { 1522 if ( loadOk ) {
1523 getEventViewerDialog()->setSyncMode( true ); 1523 getEventViewerDialog()->setSyncMode( true );
1524 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1524 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1525 getEventViewerDialog()->setSyncMode( false ); 1525 getEventViewerDialog()->setSyncMode( false );
1526 qApp->processEvents(); 1526 qApp->processEvents();
1527 if ( syncOK ) { 1527 if ( syncOK ) {
1528 if ( mSyncManager->mWriteBackFile ) 1528 if ( mSyncManager->mWriteBackFile )
1529 { 1529 {
1530 // write back XML file 1530 // write back XML file
1531 1531
1532 } 1532 }
1533 setModified( true ); 1533 setModified( true );
1534 } 1534 }
1535 } else { 1535 } else {
1536 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1536 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1537 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1537 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1538 question, i18n("Ok")) ; 1538 question, i18n("Ok")) ;
1539 } 1539 }
1540 delete calendar; 1540 delete calendar;
1541 updateView(); 1541 updateView();
1542 return syncOK; 1542 return syncOK;
1543 1543
1544 1544
1545#endif 1545#endif
1546 1546
1547} 1547}
1548 1548
1549void CalendarView::setSyncEventsReadOnly() 1549void CalendarView::setSyncEventsReadOnly()
1550{ 1550{
1551 Event * ev; 1551 Event * ev;
1552 QPtrList<Event> eL = mCalendar->rawEvents(); 1552 QPtrList<Event> eL = mCalendar->rawEvents();
1553 ev = eL.first(); 1553 ev = eL.first();
1554 while ( ev ) { 1554 while ( ev ) {
1555 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1555 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1556 ev->setReadOnly( true ); 1556 ev->setReadOnly( true );
1557 ev = eL.next(); 1557 ev = eL.next();
1558 } 1558 }
1559} 1559}
1560bool CalendarView::openCalendar(QString filename, bool merge) 1560bool CalendarView::openCalendar(QString filename, bool merge)
1561{ 1561{
1562 1562
1563 if (filename.isEmpty()) { 1563 if (filename.isEmpty()) {
1564 return false; 1564 return false;
1565 } 1565 }
1566 1566
1567 if (!QFile::exists(filename)) { 1567 if (!QFile::exists(filename)) {
1568 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1568 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1569 return false; 1569 return false;
1570 } 1570 }
1571 1571
1572 globalFlagBlockAgenda = 1; 1572 globalFlagBlockAgenda = 1;
1573 if (!merge) mCalendar->close(); 1573 if (!merge) mCalendar->close();
1574 1574
1575 mStorage->setFileName( filename ); 1575 mStorage->setFileName( filename );
1576 1576
1577 if ( mStorage->load() ) { 1577 if ( mStorage->load() ) {
1578 if ( merge ) ;//setModified( true ); 1578 if ( merge ) ;//setModified( true );
1579 else { 1579 else {
1580 //setModified( true ); 1580 //setModified( true );
1581 mViewManager->setDocumentId( filename ); 1581 mViewManager->setDocumentId( filename );
1582 mDialogManager->setDocumentId( filename ); 1582 mDialogManager->setDocumentId( filename );
1583 mTodoList->setDocumentId( filename ); 1583 mTodoList->setDocumentId( filename );
1584 } 1584 }
1585 globalFlagBlockAgenda = 2; 1585 globalFlagBlockAgenda = 2;
1586 // if ( getLastSyncEvent() ) 1586 // if ( getLastSyncEvent() )
1587 // getLastSyncEvent()->setReadOnly( true ); 1587 // getLastSyncEvent()->setReadOnly( true );
1588 mCalendar->reInitAlarmSettings(); 1588 mCalendar->reInitAlarmSettings();
1589 setSyncEventsReadOnly(); 1589 setSyncEventsReadOnly();
1590 updateUnmanagedViews(); 1590 updateUnmanagedViews();
1591 updateView(); 1591 updateView();
1592 if ( filename != MainWindow::defaultFileName() ) { 1592 if ( filename != MainWindow::defaultFileName() ) {
1593 saveCalendar( MainWindow::defaultFileName() ); 1593 saveCalendar( MainWindow::defaultFileName() );
1594 } else { 1594 } else {
1595 QFileInfo finf ( MainWindow::defaultFileName()); 1595 QFileInfo finf ( MainWindow::defaultFileName());
1596 if ( finf.exists() ) { 1596 if ( finf.exists() ) {
1597 setLoadedFileVersion( finf.lastModified () ); 1597 setLoadedFileVersion( finf.lastModified () );
1598 } 1598 }
1599 } 1599 }
1600 return true; 1600 return true;
1601 } else { 1601 } else {
1602 // while failing to load, the calendar object could 1602 // while failing to load, the calendar object could
1603 // have become partially populated. Clear it out. 1603 // have become partially populated. Clear it out.
1604 if ( !merge ) { 1604 if ( !merge ) {
1605 mCalendar->close(); 1605 mCalendar->close();
1606 mViewManager->setDocumentId( filename ); 1606 mViewManager->setDocumentId( filename );
1607 mDialogManager->setDocumentId( filename ); 1607 mDialogManager->setDocumentId( filename );
1608 mTodoList->setDocumentId( filename ); 1608 mTodoList->setDocumentId( filename );
1609 } 1609 }
1610 1610
1611 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1611 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1612 1612
1613 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1613 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1614 globalFlagBlockAgenda = 2; 1614 globalFlagBlockAgenda = 2;
1615 mCalendar->reInitAlarmSettings(); 1615 mCalendar->reInitAlarmSettings();
1616 setSyncEventsReadOnly(); 1616 setSyncEventsReadOnly();
1617 updateUnmanagedViews(); 1617 updateUnmanagedViews();
1618 updateView(); 1618 updateView();
1619 } 1619 }
1620 return false; 1620 return false;
1621} 1621}
1622void CalendarView::showOpenError() 1622void CalendarView::showOpenError()
1623{ 1623{
1624 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1624 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1625} 1625}
1626void CalendarView::setLoadedFileVersion(QDateTime dt) 1626void CalendarView::setLoadedFileVersion(QDateTime dt)
1627{ 1627{
1628 loadedFileVersion = dt; 1628 loadedFileVersion = dt;
1629} 1629}
1630bool CalendarView::checkFileChanged(QString fn) 1630bool CalendarView::checkFileChanged(QString fn)
1631{ 1631{
1632 QFileInfo finf ( fn ); 1632 QFileInfo finf ( fn );
1633 if ( !finf.exists() ) 1633 if ( !finf.exists() )
1634 return true; 1634 return true;
1635 QDateTime dt = finf.lastModified (); 1635 QDateTime dt = finf.lastModified ();
1636 if ( dt <= loadedFileVersion ) 1636 if ( dt <= loadedFileVersion )
1637 return false; 1637 return false;
1638 return true; 1638 return true;
1639 1639
1640} 1640}
1641void CalendarView::watchSavedFile() 1641void CalendarView::watchSavedFile()
1642{ 1642{
1643 QFileInfo finf ( MainWindow::defaultFileName()); 1643 QFileInfo finf ( MainWindow::defaultFileName());
1644 if ( !finf.exists() ) 1644 if ( !finf.exists() )
1645 return; 1645 return;
1646 QDateTime dt = finf.lastModified (); 1646 QDateTime dt = finf.lastModified ();
1647 if ( dt < loadedFileVersion ) { 1647 if ( dt < loadedFileVersion ) {
1648 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1648 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1649 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1649 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1650 return; 1650 return;
1651 } 1651 }
1652 loadedFileVersion = dt; 1652 loadedFileVersion = dt;
1653} 1653}
1654 1654
1655bool CalendarView::checkFileVersion(QString fn) 1655bool CalendarView::checkFileVersion(QString fn)
1656{ 1656{
1657 QFileInfo finf ( fn ); 1657 QFileInfo finf ( fn );
1658 if ( !finf.exists() ) 1658 if ( !finf.exists() )
1659 return true; 1659 return true;
1660 QDateTime dt = finf.lastModified (); 1660 QDateTime dt = finf.lastModified ();
1661 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1661 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1662 //qDebug("file on disk version %s",dt.toString().latin1()); 1662 //qDebug("file on disk version %s",dt.toString().latin1());
1663 if ( dt <= loadedFileVersion ) 1663 if ( dt <= loadedFileVersion )
1664 return true; 1664 return true;
1665 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 1665 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
1666 i18n("KO/Pi Warning"),i18n("Overwrite"), 1666 i18n("KO/Pi Warning"),i18n("Overwrite"),
1667 i18n("Sync+save")); 1667 i18n("Sync+save"));
1668 1668
1669 if ( km == KMessageBox::Cancel ) 1669 if ( km == KMessageBox::Cancel )
1670 return false; 1670 return false;
1671 if ( km == KMessageBox::Yes ) 1671 if ( km == KMessageBox::Yes )
1672 return true; 1672 return true;
1673 1673
1674 setSyncDevice("deleteaftersync" ); 1674 setSyncDevice("deleteaftersync" );
1675 mSyncManager->mAskForPreferences = true; 1675 mSyncManager->mAskForPreferences = true;
1676 mSyncManager->mSyncAlgoPrefs = 3; 1676 mSyncManager->mSyncAlgoPrefs = 3;
1677 mSyncManager->mWriteBackFile = false; 1677 mSyncManager->mWriteBackFile = false;
1678 mSyncManager->mWriteBackExistingOnly = false; 1678 mSyncManager->mWriteBackExistingOnly = false;
1679 mSyncManager->mShowSyncSummary = false; 1679 mSyncManager->mShowSyncSummary = false;
1680 syncCalendar( fn, 3 ); 1680 syncCalendar( fn, 3 );
1681 Event * e = getLastSyncEvent(); 1681 Event * e = getLastSyncEvent();
1682 mCalendar->deleteEvent ( e ); 1682 mCalendar->deleteEvent ( e );
1683 updateView(); 1683 updateView();
1684 return true; 1684 return true;
1685} 1685}
1686 1686
1687bool CalendarView::saveCalendar( QString filename ) 1687bool CalendarView::saveCalendar( QString filename )
1688{ 1688{
1689 1689
1690 // Store back all unsaved data into calendar object 1690 // Store back all unsaved data into calendar object
1691 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1691 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1692 if ( mViewManager->currentView() ) 1692 if ( mViewManager->currentView() )
1693 mViewManager->currentView()->flushView(); 1693 mViewManager->currentView()->flushView();
1694 1694
1695 1695
1696 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 1696 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
1697 mStorage->setSaveFormat( new ICalFormat() ); 1697 mStorage->setSaveFormat( new ICalFormat() );
1698 mStorage->setFileName( filename ); 1698 mStorage->setFileName( filename );
1699 bool success; 1699 bool success;
1700 success = mStorage->save(); 1700 success = mStorage->save();
1701 if ( !success ) { 1701 if ( !success ) {
1702 return false; 1702 return false;
1703 } 1703 }
1704 if ( filename == MainWindow::defaultFileName() ) { 1704 if ( filename == MainWindow::defaultFileName() ) {
1705 setLoadedFileVersion( lfv ); 1705 setLoadedFileVersion( lfv );
1706 watchSavedFile(); 1706 watchSavedFile();
1707 } 1707 }
1708 return true; 1708 return true;
1709} 1709}
1710 1710
1711void CalendarView::closeCalendar() 1711void CalendarView::closeCalendar()
1712{ 1712{
1713 1713
1714 // child windows no longer valid 1714 // child windows no longer valid
1715 emit closingDown(); 1715 emit closingDown();
1716 1716
1717 mCalendar->close(); 1717 mCalendar->close();
1718 setModified(false); 1718 setModified(false);
1719 updateView(); 1719 updateView();
1720} 1720}
1721 1721
1722void CalendarView::archiveCalendar() 1722void CalendarView::archiveCalendar()
1723{ 1723{
1724 mDialogManager->showArchiveDialog(); 1724 mDialogManager->showArchiveDialog();
1725} 1725}
1726 1726
1727 1727
1728void CalendarView::readSettings() 1728void CalendarView::readSettings()
1729{ 1729{
1730 1730
1731 1731
1732 // mViewManager->showAgendaView(); 1732 // mViewManager->showAgendaView();
1733 QString str; 1733 QString str;
1734 //qDebug("CalendarView::readSettings() "); 1734 //qDebug("CalendarView::readSettings() ");
1735 // read settings from the KConfig, supplying reasonable 1735 // read settings from the KConfig, supplying reasonable
1736 // defaults where none are to be found 1736 // defaults where none are to be found
1737 KConfig *config = KOGlobals::config(); 1737 KConfig *config = KOGlobals::config();
1738#ifndef KORG_NOSPLITTER 1738#ifndef KORG_NOSPLITTER
1739 config->setGroup("KOrganizer Geometry"); 1739 config->setGroup("KOrganizer Geometry");
1740 1740
1741 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1741 QValueList<int> sizes = config->readIntListEntry("Separator1");
1742 if (sizes.count() != 2) { 1742 if (sizes.count() != 2) {
1743 sizes << mDateNavigator->minimumSizeHint().width(); 1743 sizes << mDateNavigator->minimumSizeHint().width();
1744 sizes << 300; 1744 sizes << 300;
1745 } 1745 }
1746 mPanner->setSizes(sizes); 1746 mPanner->setSizes(sizes);
1747 1747
1748 sizes = config->readIntListEntry("Separator2"); 1748 sizes = config->readIntListEntry("Separator2");
1749 if ( ( mResourceView && sizes.count() == 4 ) || 1749 if ( ( mResourceView && sizes.count() == 4 ) ||
1750 ( !mResourceView && sizes.count() == 3 ) ) { 1750 ( !mResourceView && sizes.count() == 3 ) ) {
1751 mLeftSplitter->setSizes(sizes); 1751 mLeftSplitter->setSizes(sizes);
1752 } 1752 }
1753#endif 1753#endif
1754 globalFlagBlockAgenda = 1; 1754 globalFlagBlockAgenda = 1;
1755 mViewManager->showAgendaView(); 1755 mViewManager->showAgendaView();
1756 //mViewManager->readSettings( config ); 1756 //mViewManager->readSettings( config );
1757 mTodoList->restoreLayout(config,QString("Todo Layout")); 1757 mTodoList->restoreLayout(config,QString("Todo Layout"));
1758 readFilterSettings(config); 1758 readFilterSettings(config);
1759 config->setGroup( "Views" ); 1759 config->setGroup( "Views" );
1760 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 1760 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
1761 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 1761 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
1762 else if ( dateCount == 7 ) mNavigator->selectWeek(); 1762 else if ( dateCount == 7 ) mNavigator->selectWeek();
1763 else mNavigator->selectDates( dateCount ); 1763 else mNavigator->selectDates( dateCount );
1764 // mViewManager->readSettings( config ); 1764 // mViewManager->readSettings( config );
1765 updateConfig(); 1765 updateConfig();
1766 globalFlagBlockAgenda = 2; 1766 globalFlagBlockAgenda = 2;
1767 mViewManager->readSettings( config ); 1767 mViewManager->readSettings( config );
1768#ifdef DESKTOP_VERSION 1768#ifdef DESKTOP_VERSION
1769 config->setGroup("WidgetLayout"); 1769 config->setGroup("WidgetLayout");
1770 QStringList list; 1770 QStringList list;
1771 list = config->readListEntry("MainLayout"); 1771 list = config->readListEntry("MainLayout");
1772 int x,y,w,h; 1772 int x,y,w,h;
1773 if ( ! list.isEmpty() ) { 1773 if ( ! list.isEmpty() ) {
1774 x = list[0].toInt(); 1774 x = list[0].toInt();
1775 y = list[1].toInt(); 1775 y = list[1].toInt();
1776 w = list[2].toInt(); 1776 w = list[2].toInt();
1777 h = list[3].toInt(); 1777 h = list[3].toInt();
1778 topLevelWidget()->setGeometry(x,y,w,h); 1778 topLevelWidget()->setGeometry(x,y,w,h);
1779 1779
1780 } else { 1780 } else {
1781 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 1781 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
1782 } 1782 }
1783 list = config->readListEntry("EditEventLayout"); 1783 list = config->readListEntry("EditEventLayout");
1784 if ( ! list.isEmpty() ) { 1784 if ( ! list.isEmpty() ) {
1785 x = list[0].toInt(); 1785 x = list[0].toInt();
1786 y = list[1].toInt(); 1786 y = list[1].toInt();
1787 w = list[2].toInt(); 1787 w = list[2].toInt();
1788 h = list[3].toInt(); 1788 h = list[3].toInt();
1789 mEventEditor->setGeometry(x,y,w,h); 1789 mEventEditor->setGeometry(x,y,w,h);
1790 1790
1791 } 1791 }
1792 list = config->readListEntry("EditTodoLayout"); 1792 list = config->readListEntry("EditTodoLayout");
1793 if ( ! list.isEmpty() ) { 1793 if ( ! list.isEmpty() ) {
1794 x = list[0].toInt(); 1794 x = list[0].toInt();
1795 y = list[1].toInt(); 1795 y = list[1].toInt();
1796 w = list[2].toInt(); 1796 w = list[2].toInt();
1797 h = list[3].toInt(); 1797 h = list[3].toInt();
1798 mTodoEditor->setGeometry(x,y,w,h); 1798 mTodoEditor->setGeometry(x,y,w,h);
1799 1799
1800 } 1800 }
1801 list = config->readListEntry("ViewerLayout"); 1801 list = config->readListEntry("ViewerLayout");
1802 if ( ! list.isEmpty() ) { 1802 if ( ! list.isEmpty() ) {
1803 x = list[0].toInt(); 1803 x = list[0].toInt();
1804 y = list[1].toInt(); 1804 y = list[1].toInt();
1805 w = list[2].toInt(); 1805 w = list[2].toInt();
1806 h = list[3].toInt(); 1806 h = list[3].toInt();
1807 getEventViewerDialog()->setGeometry(x,y,w,h); 1807 getEventViewerDialog()->setGeometry(x,y,w,h);
1808 } 1808 }
1809#endif 1809#endif
1810 1810
1811} 1811}
1812 1812
1813 1813
1814void CalendarView::writeSettings() 1814void CalendarView::writeSettings()
1815{ 1815{
1816 // kdDebug() << "CalendarView::writeSettings" << endl; 1816 // kdDebug() << "CalendarView::writeSettings" << endl;
1817 1817
1818 KConfig *config = KOGlobals::config(); 1818 KConfig *config = KOGlobals::config();
1819 1819
1820#ifndef KORG_NOSPLITTER 1820#ifndef KORG_NOSPLITTER
1821 config->setGroup("KOrganizer Geometry"); 1821 config->setGroup("KOrganizer Geometry");
1822 1822
1823 QValueList<int> list = mPanner->sizes(); 1823 QValueList<int> list = mPanner->sizes();
1824 config->writeEntry("Separator1",list); 1824 config->writeEntry("Separator1",list);
1825 1825
1826 list = mLeftSplitter->sizes(); 1826 list = mLeftSplitter->sizes();
1827 config->writeEntry("Separator2",list); 1827 config->writeEntry("Separator2",list);
1828#endif 1828#endif
1829 1829
1830 mViewManager->writeSettings( config ); 1830 mViewManager->writeSettings( config );
1831 mTodoList->saveLayout(config,QString("Todo Layout")); 1831 mTodoList->saveLayout(config,QString("Todo Layout"));
1832 mDialogManager->writeSettings( config ); 1832 mDialogManager->writeSettings( config );
1833 //KOPrefs::instance()->usrWriteConfig(); 1833 //KOPrefs::instance()->usrWriteConfig();
1834 KOPrefs::instance()->writeConfig(); 1834 KOPrefs::instance()->writeConfig();
1835 1835
1836 writeFilterSettings(config); 1836 writeFilterSettings(config);
1837 1837
1838 config->setGroup( "Views" ); 1838 config->setGroup( "Views" );
1839 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 1839 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
1840 1840
1841#ifdef DESKTOP_VERSION 1841#ifdef DESKTOP_VERSION
1842 config->setGroup("WidgetLayout"); 1842 config->setGroup("WidgetLayout");
1843 QStringList list ;//= config->readListEntry("MainLayout"); 1843 QStringList list ;//= config->readListEntry("MainLayout");
1844 int x,y,w,h; 1844 int x,y,w,h;
1845 QWidget* wid; 1845 QWidget* wid;
1846 wid = topLevelWidget(); 1846 wid = topLevelWidget();
1847 x = wid->geometry().x(); 1847 x = wid->geometry().x();
1848 y = wid->geometry().y(); 1848 y = wid->geometry().y();
1849 w = wid->width(); 1849 w = wid->width();
1850 h = wid->height(); 1850 h = wid->height();
1851 list.clear(); 1851 list.clear();
1852 list << QString::number( x ); 1852 list << QString::number( x );
1853 list << QString::number( y ); 1853 list << QString::number( y );
1854 list << QString::number( w ); 1854 list << QString::number( w );
1855 list << QString::number( h ); 1855 list << QString::number( h );
1856 config->writeEntry("MainLayout",list ); 1856 config->writeEntry("MainLayout",list );
1857 1857
1858 wid = mEventEditor; 1858 wid = mEventEditor;
1859 x = wid->geometry().x(); 1859 x = wid->geometry().x();
1860 y = wid->geometry().y(); 1860 y = wid->geometry().y();
1861 w = wid->width(); 1861 w = wid->width();
1862 h = wid->height(); 1862 h = wid->height();
1863 list.clear(); 1863 list.clear();
1864 list << QString::number( x ); 1864 list << QString::number( x );
1865 list << QString::number( y ); 1865 list << QString::number( y );
1866 list << QString::number( w ); 1866 list << QString::number( w );
1867 list << QString::number( h ); 1867 list << QString::number( h );
1868 config->writeEntry("EditEventLayout",list ); 1868 config->writeEntry("EditEventLayout",list );
1869 1869
1870 wid = mTodoEditor; 1870 wid = mTodoEditor;
1871 x = wid->geometry().x(); 1871 x = wid->geometry().x();
1872 y = wid->geometry().y(); 1872 y = wid->geometry().y();
1873 w = wid->width(); 1873 w = wid->width();
1874 h = wid->height(); 1874 h = wid->height();
1875 list.clear(); 1875 list.clear();
1876 list << QString::number( x ); 1876 list << QString::number( x );
1877 list << QString::number( y ); 1877 list << QString::number( y );
1878 list << QString::number( w ); 1878 list << QString::number( w );
1879 list << QString::number( h ); 1879 list << QString::number( h );
1880 config->writeEntry("EditTodoLayout",list ); 1880 config->writeEntry("EditTodoLayout",list );
1881 wid = getEventViewerDialog(); 1881 wid = getEventViewerDialog();
1882 x = wid->geometry().x(); 1882 x = wid->geometry().x();
1883 y = wid->geometry().y(); 1883 y = wid->geometry().y();
1884 w = wid->width(); 1884 w = wid->width();
1885 h = wid->height(); 1885 h = wid->height();
1886 list.clear(); 1886 list.clear();
1887 list << QString::number( x ); 1887 list << QString::number( x );
1888 list << QString::number( y ); 1888 list << QString::number( y );
1889 list << QString::number( w ); 1889 list << QString::number( w );
1890 list << QString::number( h ); 1890 list << QString::number( h );
1891 config->writeEntry("ViewerLayout",list ); 1891 config->writeEntry("ViewerLayout",list );
1892 wid = mDialogManager->getSearchDialog(); 1892 wid = mDialogManager->getSearchDialog();
1893 if ( wid ) { 1893 if ( wid ) {
1894 x = wid->geometry().x(); 1894 x = wid->geometry().x();
1895 y = wid->geometry().y(); 1895 y = wid->geometry().y();
1896 w = wid->width(); 1896 w = wid->width();
1897 h = wid->height(); 1897 h = wid->height();
1898 list.clear(); 1898 list.clear();
1899 list << QString::number( x ); 1899 list << QString::number( x );
1900 list << QString::number( y ); 1900 list << QString::number( y );
1901 list << QString::number( w ); 1901 list << QString::number( w );
1902 list << QString::number( h ); 1902 list << QString::number( h );
1903 config->writeEntry("SearchLayout",list ); 1903 config->writeEntry("SearchLayout",list );
1904 } 1904 }
1905#endif 1905#endif
1906 1906
1907 1907
1908 config->sync(); 1908 config->sync();
1909} 1909}
1910 1910
1911void CalendarView::readFilterSettings(KConfig *config) 1911void CalendarView::readFilterSettings(KConfig *config)
1912{ 1912{
1913 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 1913 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
1914 1914
1915 mFilters.clear(); 1915 mFilters.clear();
1916 1916
1917 config->setGroup("General"); 1917 config->setGroup("General");
1918 QStringList filterList = config->readListEntry("CalendarFilters"); 1918 QStringList filterList = config->readListEntry("CalendarFilters");
1919 1919
1920 QStringList::ConstIterator it = filterList.begin(); 1920 QStringList::ConstIterator it = filterList.begin();
1921 QStringList::ConstIterator end = filterList.end(); 1921 QStringList::ConstIterator end = filterList.end();
1922 while(it != end) { 1922 while(it != end) {
1923 // kdDebug() << " filter: " << (*it) << endl; 1923 // kdDebug() << " filter: " << (*it) << endl;
1924 1924
1925 CalFilter *filter; 1925 CalFilter *filter;
1926 filter = new CalFilter(*it); 1926 filter = new CalFilter(*it);
1927 config->setGroup("Filter_" + (*it)); 1927 config->setGroup("Filter_" + (*it));
1928 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 1928 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
1929 filter->setCriteria(config->readNumEntry("Criteria",0)); 1929 filter->setCriteria(config->readNumEntry("Criteria",0));
1930 filter->setCategoryList(config->readListEntry("CategoryList")); 1930 filter->setCategoryList(config->readListEntry("CategoryList"));
1931 mFilters.append(filter); 1931 mFilters.append(filter);
1932 1932
1933 ++it; 1933 ++it;
1934 } 1934 }
1935 1935
1936 if (mFilters.count() == 0) { 1936 if (mFilters.count() == 0) {
1937 CalFilter *filter = new CalFilter(i18n("Default")); 1937 CalFilter *filter = new CalFilter(i18n("Default"));
1938 mFilters.append(filter); 1938 mFilters.append(filter);
1939 } 1939 }
1940 mFilterView->updateFilters(); 1940 mFilterView->updateFilters();
1941 config->setGroup("FilterView"); 1941 config->setGroup("FilterView");
1942 1942
1943 mFilterView->blockSignals(true); 1943 mFilterView->blockSignals(true);
1944 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 1944 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
1945 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 1945 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
1946 mFilterView->blockSignals(false); 1946 mFilterView->blockSignals(false);
1947 // We do it manually to avoid it being done twice by the above calls 1947 // We do it manually to avoid it being done twice by the above calls
1948 updateFilter(); 1948 updateFilter();
1949} 1949}
1950 1950
1951void CalendarView::writeFilterSettings(KConfig *config) 1951void CalendarView::writeFilterSettings(KConfig *config)
1952{ 1952{
1953 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 1953 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
1954 1954
1955 QStringList filterList; 1955 QStringList filterList;
1956 1956
1957 CalFilter *filter = mFilters.first(); 1957 CalFilter *filter = mFilters.first();
1958 while(filter) { 1958 while(filter) {
1959 // kdDebug() << " fn: " << filter->name() << endl; 1959 // kdDebug() << " fn: " << filter->name() << endl;
1960 filterList << filter->name(); 1960 filterList << filter->name();
1961 config->setGroup("Filter_" + filter->name()); 1961 config->setGroup("Filter_" + filter->name());
1962 config->writeEntry("Criteria",filter->criteria()); 1962 config->writeEntry("Criteria",filter->criteria());
1963 config->writeEntry("CategoryList",filter->categoryList()); 1963 config->writeEntry("CategoryList",filter->categoryList());
1964 filter = mFilters.next(); 1964 filter = mFilters.next();
1965 } 1965 }
1966 config->setGroup("General"); 1966 config->setGroup("General");
1967 config->writeEntry("CalendarFilters",filterList); 1967 config->writeEntry("CalendarFilters",filterList);
1968 1968
1969 config->setGroup("FilterView"); 1969 config->setGroup("FilterView");
1970 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 1970 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
1971 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 1971 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
1972} 1972}
1973 1973
1974 1974
1975void CalendarView::goToday() 1975void CalendarView::goToday()
1976{ 1976{
1977 mNavigator->selectToday(); 1977 mNavigator->selectToday();
1978} 1978}
1979 1979
1980void CalendarView::goNext() 1980void CalendarView::goNext()
1981{ 1981{
1982 mNavigator->selectNext(); 1982 mNavigator->selectNext();
1983} 1983}
1984 1984
1985void CalendarView::goPrevious() 1985void CalendarView::goPrevious()
1986{ 1986{
1987 mNavigator->selectPrevious(); 1987 mNavigator->selectPrevious();
1988} 1988}
1989void CalendarView::goNextMonth() 1989void CalendarView::goNextMonth()
1990{ 1990{
1991 mNavigator->selectNextMonth(); 1991 mNavigator->selectNextMonth();
1992} 1992}
1993 1993
1994void CalendarView::goPreviousMonth() 1994void CalendarView::goPreviousMonth()
1995{ 1995{
1996 mNavigator->selectPreviousMonth(); 1996 mNavigator->selectPreviousMonth();
1997} 1997}
1998void CalendarView::writeLocale() 1998void CalendarView::writeLocale()
1999{ 1999{
2000 //KPimGlobalPrefs::instance()->setGlobalConfig(); 2000 //KPimGlobalPrefs::instance()->setGlobalConfig();
2001#if 0 2001#if 0
2002 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 2002 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
2003 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 2003 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
2004 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 2004 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
2005 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 2005 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
2006 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 2006 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
2007 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 2007 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
2008 dummy = KOPrefs::instance()->mUserDateFormatShort; 2008 dummy = KOPrefs::instance()->mUserDateFormatShort;
2009 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 2009 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
2010 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 2010 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
2011 KOPrefs::instance()->mDaylightsavingStart, 2011 KOPrefs::instance()->mDaylightsavingStart,
2012 KOPrefs::instance()->mDaylightsavingEnd ); 2012 KOPrefs::instance()->mDaylightsavingEnd );
2013 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId ); 2013 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId );
2014#endif 2014#endif
2015} 2015}
2016void CalendarView::updateConfig() 2016void CalendarView::updateConfig()
2017{ 2017{
2018 writeLocale(); 2018 writeLocale();
2019 if ( KOPrefs::instance()->mUseAppColors ) 2019 if ( KOPrefs::instance()->mUseAppColors )
2020 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2020 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2021 emit configChanged(); 2021 emit configChanged();
2022 mTodoList->updateConfig(); 2022 mTodoList->updateConfig();
2023 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2023 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2024 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2024 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2025 // To make the "fill window" configurations work 2025 // To make the "fill window" configurations work
2026 //mViewManager->raiseCurrentView(); 2026 //mViewManager->raiseCurrentView();
2027} 2027}
2028 2028
2029 2029
2030void CalendarView::eventChanged(Event *event) 2030void CalendarView::eventChanged(Event *event)
2031{ 2031{
2032 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2032 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2033 //updateUnmanagedViews(); 2033 //updateUnmanagedViews();
2034} 2034}
2035 2035
2036void CalendarView::eventAdded(Event *event) 2036void CalendarView::eventAdded(Event *event)
2037{ 2037{
2038 changeEventDisplay(event,KOGlobals::EVENTADDED); 2038 changeEventDisplay(event,KOGlobals::EVENTADDED);
2039} 2039}
2040 2040
2041void CalendarView::eventToBeDeleted(Event *) 2041void CalendarView::eventToBeDeleted(Event *)
2042{ 2042{
2043 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2043 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2044} 2044}
2045 2045
2046void CalendarView::eventDeleted() 2046void CalendarView::eventDeleted()
2047{ 2047{
2048 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2048 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2049} 2049}
2050void CalendarView::changeTodoDisplay(Todo *which, int action) 2050void CalendarView::changeTodoDisplay(Todo *which, int action)
2051{ 2051{
2052 changeIncidenceDisplay((Incidence *)which, action); 2052 changeIncidenceDisplay((Incidence *)which, action);
2053 mDateNavigator->updateView(); //LR 2053 mDateNavigator->updateView(); //LR
2054 //mDialogManager->updateSearchDialog(); 2054 //mDialogManager->updateSearchDialog();
2055 2055
2056 if (which) { 2056 if (which) {
2057 mViewManager->updateWNview(); 2057 mViewManager->updateWNview();
2058 //mTodoList->updateView(); 2058 //mTodoList->updateView();
2059 } 2059 }
2060 2060
2061} 2061}
2062 2062
2063void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2063void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2064{ 2064{
2065 updateUnmanagedViews(); 2065 updateUnmanagedViews();
2066 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2066 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2067 if ( action == KOGlobals::EVENTDELETED ) { //delete 2067 if ( action == KOGlobals::EVENTDELETED ) { //delete
2068 mCalendar->checkAlarmForIncidence( 0, true ); 2068 mCalendar->checkAlarmForIncidence( 0, true );
2069 if ( mEventViewerDialog ) 2069 if ( mEventViewerDialog )
2070 mEventViewerDialog->hide(); 2070 mEventViewerDialog->hide();
2071 } 2071 }
2072 else 2072 else
2073 mCalendar->checkAlarmForIncidence( which , false ); 2073 mCalendar->checkAlarmForIncidence( which , false );
2074} 2074}
2075 2075
2076// most of the changeEventDisplays() right now just call the view's 2076// most of the changeEventDisplays() right now just call the view's
2077// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2077// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2078void CalendarView::changeEventDisplay(Event *which, int action) 2078void CalendarView::changeEventDisplay(Event *which, int action)
2079{ 2079{
2080 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2080 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2081 changeIncidenceDisplay((Incidence *)which, action); 2081 changeIncidenceDisplay((Incidence *)which, action);
2082 mDateNavigator->updateView(); 2082 mDateNavigator->updateView();
2083 //mDialogManager->updateSearchDialog(); 2083 //mDialogManager->updateSearchDialog();
2084 2084
2085 if (which) { 2085 if (which) {
2086 // If there is an event view visible update the display 2086 // If there is an event view visible update the display
2087 mViewManager->currentView()->changeEventDisplay(which,action); 2087 mViewManager->currentView()->changeEventDisplay(which,action);
2088 // TODO: check, if update needed 2088 // TODO: check, if update needed
2089 // if (which->getTodoStatus()) { 2089 // if (which->getTodoStatus()) {
2090 mTodoList->updateView(); 2090 mTodoList->updateView();
2091 // } 2091 // }
2092 } else { 2092 } else {
2093 mViewManager->currentView()->updateView(); 2093 mViewManager->currentView()->updateView();
2094 } 2094 }
2095} 2095}
2096 2096
2097 2097
2098void CalendarView::updateTodoViews() 2098void CalendarView::updateTodoViews()
2099{ 2099{
2100 2100
2101 mTodoList->updateView(); 2101 mTodoList->updateView();
2102 mViewManager->currentView()->updateView(); 2102 mViewManager->currentView()->updateView();
2103 2103
2104} 2104}
2105 2105
2106 2106
2107void CalendarView::updateView(const QDate &start, const QDate &end) 2107void CalendarView::updateView(const QDate &start, const QDate &end)
2108{ 2108{
2109 mTodoList->updateView(); 2109 mTodoList->updateView();
2110 mViewManager->updateView(start, end); 2110 mViewManager->updateView(start, end);
2111 //mDateNavigator->updateView(); 2111 //mDateNavigator->updateView();
2112} 2112}
2113 2113
2114void CalendarView::updateView() 2114void CalendarView::updateView()
2115{ 2115{
2116 DateList tmpList = mNavigator->selectedDates(); 2116 DateList tmpList = mNavigator->selectedDates();
2117 2117
2118 // We assume that the navigator only selects consecutive days. 2118 // We assume that the navigator only selects consecutive days.
2119 updateView( tmpList.first(), tmpList.last() ); 2119 updateView( tmpList.first(), tmpList.last() );
2120} 2120}
2121 2121
2122void CalendarView::updateUnmanagedViews() 2122void CalendarView::updateUnmanagedViews()
2123{ 2123{
2124 mDateNavigator->updateDayMatrix(); 2124 mDateNavigator->updateDayMatrix();
2125} 2125}
2126 2126
2127int CalendarView::msgItemDelete() 2127int CalendarView::msgItemDelete()
2128{ 2128{
2129 return KMessageBox::warningContinueCancel(this, 2129 return KMessageBox::warningContinueCancel(this,
2130 i18n("This item will be\npermanently deleted."), 2130 i18n("This item will be\npermanently deleted."),
2131 i18n("KO/Pi Confirmation"),i18n("Delete")); 2131 i18n("KO/Pi Confirmation"),i18n("Delete"));
2132} 2132}
2133 2133
2134 2134
2135void CalendarView::edit_cut() 2135void CalendarView::edit_cut()
2136{ 2136{
2137 Event *anEvent=0; 2137 Event *anEvent=0;
2138 2138
2139 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2139 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2140 2140
2141 if (mViewManager->currentView()->isEventView()) { 2141 if (mViewManager->currentView()->isEventView()) {
2142 if ( incidence && incidence->type() == "Event" ) { 2142 if ( incidence && incidence->type() == "Event" ) {
2143 anEvent = static_cast<Event *>(incidence); 2143 anEvent = static_cast<Event *>(incidence);
2144 } 2144 }
2145 } 2145 }
2146 2146
2147 if (!anEvent) { 2147 if (!anEvent) {
2148 KNotifyClient::beep(); 2148 KNotifyClient::beep();
2149 return; 2149 return;
2150 } 2150 }
2151 DndFactory factory( mCalendar ); 2151 DndFactory factory( mCalendar );
2152 factory.cutEvent(anEvent); 2152 factory.cutEvent(anEvent);
2153 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2153 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2154} 2154}
2155 2155
2156void CalendarView::edit_copy() 2156void CalendarView::edit_copy()
2157{ 2157{
2158 Event *anEvent=0; 2158 Event *anEvent=0;
2159 2159
2160 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2160 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2161 2161
2162 if (mViewManager->currentView()->isEventView()) { 2162 if (mViewManager->currentView()->isEventView()) {
2163 if ( incidence && incidence->type() == "Event" ) { 2163 if ( incidence && incidence->type() == "Event" ) {
2164 anEvent = static_cast<Event *>(incidence); 2164 anEvent = static_cast<Event *>(incidence);
2165 } 2165 }
2166 } 2166 }
2167 2167
2168 if (!anEvent) { 2168 if (!anEvent) {
2169 KNotifyClient::beep(); 2169 KNotifyClient::beep();
2170 return; 2170 return;
2171 } 2171 }
2172 DndFactory factory( mCalendar ); 2172 DndFactory factory( mCalendar );
2173 factory.copyEvent(anEvent); 2173 factory.copyEvent(anEvent);
2174} 2174}
2175 2175
2176void CalendarView::edit_paste() 2176void CalendarView::edit_paste()
2177{ 2177{
2178 QDate date = mNavigator->selectedDates().first(); 2178 QDate date = mNavigator->selectedDates().first();
2179 2179
2180 DndFactory factory( mCalendar ); 2180 DndFactory factory( mCalendar );
2181 Event *pastedEvent = factory.pasteEvent( date ); 2181 Event *pastedEvent = factory.pasteEvent( date );
2182 2182
2183 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2183 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2184} 2184}
2185 2185
2186void CalendarView::edit_options() 2186void CalendarView::edit_options()
2187{ 2187{
2188 mDialogManager->showOptionsDialog(); 2188 mDialogManager->showOptionsDialog();
2189 //writeSettings(); 2189 //writeSettings();
2190} 2190}
2191 2191
2192void CalendarView::slotSelectPickerDate( QDate d) 2192void CalendarView::slotSelectPickerDate( QDate d)
2193{ 2193{
2194 mDateFrame->hide(); 2194 mDateFrame->hide();
2195 if ( mDatePickerMode == 1 ) { 2195 if ( mDatePickerMode == 1 ) {
2196 mNavigator->slotDaySelect( d ); 2196 mNavigator->slotDaySelect( d );
2197 } else if ( mDatePickerMode == 2 ) { 2197 } else if ( mDatePickerMode == 2 ) {
2198 if ( mMoveIncidence->type() == "Todo" ) { 2198 if ( mMoveIncidence->type() == "Todo" ) {
2199 Todo * to = (Todo *) mMoveIncidence; 2199 Todo * to = (Todo *) mMoveIncidence;
2200 QTime tim; 2200 QTime tim;
2201 if ( to->hasDueDate() ) 2201 if ( to->hasDueDate() )
2202 tim = to->dtDue().time(); 2202 tim = to->dtDue().time();
2203 else { 2203 else {
2204 tim = QTime ( 0,0,0 ); 2204 tim = QTime ( 0,0,0 );
2205 to->setFloats( true ); 2205 to->setFloats( true );
2206 to->setHasDueDate( true ); 2206 to->setHasDueDate( true );
2207 } 2207 }
2208 QDateTime dt ( d,tim ); 2208 QDateTime dt ( d,tim );
2209 to->setDtDue( dt ); 2209 to->setDtDue( dt );
2210 todoChanged( to ); 2210 todoChanged( to );
2211 } else { 2211 } else {
2212 QTime tim = mMoveIncidence->dtStart().time(); 2212 QTime tim = mMoveIncidence->dtStart().time();
2213 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2213 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2214 QDateTime dt ( d,tim ); 2214 QDateTime dt ( d,tim );
2215 mMoveIncidence->setDtStart( dt ); 2215 mMoveIncidence->setDtStart( dt );
2216 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2216 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2217 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2217 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2218 } 2218 }
2219 2219
2220 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2220 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2221 } 2221 }
2222} 2222}
2223 2223
2224void CalendarView::removeCategories() 2224void CalendarView::removeCategories()
2225{ 2225{
2226 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2226 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2227 QStringList catList = KOPrefs::instance()->mCustomCategories; 2227 QStringList catList = KOPrefs::instance()->mCustomCategories;
2228 QStringList catIncList; 2228 QStringList catIncList;
2229 QStringList newCatList; 2229 QStringList newCatList;
2230 Incidence* inc = incList.first(); 2230 Incidence* inc = incList.first();
2231 int i; 2231 int i;
2232 int count = 0; 2232 int count = 0;
2233 while ( inc ) { 2233 while ( inc ) {
2234 newCatList.clear(); 2234 newCatList.clear();
2235 catIncList = inc->categories() ; 2235 catIncList = inc->categories() ;
2236 for( i = 0; i< catIncList.count(); ++i ) { 2236 for( i = 0; i< catIncList.count(); ++i ) {
2237 if ( catList.contains (catIncList[i])) 2237 if ( catList.contains (catIncList[i]))
2238 newCatList.append( catIncList[i] ); 2238 newCatList.append( catIncList[i] );
2239 } 2239 }
2240 newCatList.sort(); 2240 newCatList.sort();
2241 inc->setCategories( newCatList.join(",") ); 2241 inc->setCategories( newCatList.join(",") );
2242 inc = incList.next(); 2242 inc = incList.next();
2243 } 2243 }
2244} 2244}
2245 2245
2246int CalendarView::addCategories() 2246int CalendarView::addCategories()
2247{ 2247{
2248 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2248 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2249 QStringList catList = KOPrefs::instance()->mCustomCategories; 2249 QStringList catList = KOPrefs::instance()->mCustomCategories;
2250 QStringList catIncList; 2250 QStringList catIncList;
2251 Incidence* inc = incList.first(); 2251 Incidence* inc = incList.first();
2252 int i; 2252 int i;
2253 int count = 0; 2253 int count = 0;
2254 while ( inc ) { 2254 while ( inc ) {
2255 catIncList = inc->categories() ; 2255 catIncList = inc->categories() ;
2256 for( i = 0; i< catIncList.count(); ++i ) { 2256 for( i = 0; i< catIncList.count(); ++i ) {
2257 if ( !catList.contains (catIncList[i])) { 2257 if ( !catList.contains (catIncList[i])) {
2258 catList.append( catIncList[i] ); 2258 catList.append( catIncList[i] );
2259 //qDebug("add cat %s ", catIncList[i].latin1()); 2259 //qDebug("add cat %s ", catIncList[i].latin1());
2260 ++count; 2260 ++count;
2261 } 2261 }
2262 } 2262 }
2263 inc = incList.next(); 2263 inc = incList.next();
2264 } 2264 }
2265 catList.sort(); 2265 catList.sort();
2266 KOPrefs::instance()->mCustomCategories = catList; 2266 KOPrefs::instance()->mCustomCategories = catList;
2267 return count; 2267 return count;
2268} 2268}
2269 2269
2270void CalendarView::manageCategories() 2270void CalendarView::manageCategories()
2271{ 2271{
2272 KOCatPrefs* cp = new KOCatPrefs(); 2272 KOCatPrefs* cp = new KOCatPrefs();
2273 cp->show(); 2273 cp->show();
2274 int w =cp->sizeHint().width() ; 2274 int w =cp->sizeHint().width() ;
2275 int h = cp->sizeHint().height() ; 2275 int h = cp->sizeHint().height() ;
2276 int dw = QApplication::desktop()->width(); 2276 int dw = QApplication::desktop()->width();
2277 int dh = QApplication::desktop()->height(); 2277 int dh = QApplication::desktop()->height();
2278 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2278 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2279 if ( !cp->exec() ) { 2279 if ( !cp->exec() ) {
2280 delete cp; 2280 delete cp;
2281 return; 2281 return;
2282 } 2282 }
2283 int count = 0; 2283 int count = 0;
2284 if ( cp->addCat() ) { 2284 if ( cp->addCat() ) {
2285 count = addCategories(); 2285 count = addCategories();
2286 if ( count ) { 2286 if ( count ) {
2287 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 2287 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
2288 writeSettings(); 2288 writeSettings();
2289 } 2289 }
2290 } else { 2290 } else {
2291 removeCategories(); 2291 removeCategories();
2292 updateView(); 2292 updateView();
2293 } 2293 }
2294 delete cp; 2294 delete cp;
2295} 2295}
2296 2296
2297void CalendarView::beamIncidence(Incidence * Inc) 2297void CalendarView::beamIncidence(Incidence * Inc)
2298{ 2298{
2299 QPtrList<Incidence> delSel ; 2299 QPtrList<Incidence> delSel ;
2300 delSel.append(Inc); 2300 delSel.append(Inc);
2301 beamIncidenceList( delSel ); 2301 beamIncidenceList( delSel );
2302} 2302}
2303void CalendarView::beamCalendar() 2303void CalendarView::beamCalendar()
2304{ 2304{
2305 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 2305 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
2306 //qDebug("beamCalendar() "); 2306 //qDebug("beamCalendar() ");
2307 beamIncidenceList( delSel ); 2307 beamIncidenceList( delSel );
2308} 2308}
2309void CalendarView::beamFilteredCalendar() 2309void CalendarView::beamFilteredCalendar()
2310{ 2310{
2311 QPtrList<Incidence> delSel = mCalendar->incidences(); 2311 QPtrList<Incidence> delSel = mCalendar->incidences();
2312 //qDebug("beamFilteredCalendar() "); 2312 //qDebug("beamFilteredCalendar() ");
2313 beamIncidenceList( delSel ); 2313 beamIncidenceList( delSel );
2314} 2314}
2315void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 2315void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
2316{ 2316{
2317 if ( beamDialog->exec () == QDialog::Rejected ) 2317 if ( beamDialog->exec () == QDialog::Rejected )
2318 return; 2318 return;
2319#ifdef DESKTOP_VERSION 2319#ifdef DESKTOP_VERSION
2320 QString fn = locateLocal( "tmp", "kopibeamfile" ); 2320 QString fn = locateLocal( "tmp", "kopibeamfile" );
2321#else 2321#else
2322 QString fn = "/tmp/kopibeamfile"; 2322 QString fn = "/tmp/kopibeamfile";
2323#endif 2323#endif
2324 QString mes; 2324 QString mes;
2325 bool createbup = true; 2325 bool createbup = true;
2326 if ( createbup ) { 2326 if ( createbup ) {
2327 QString description = "\n"; 2327 QString description = "\n";
2328 CalendarLocal* cal = new CalendarLocal(); 2328 CalendarLocal* cal = new CalendarLocal();
2329 if ( beamDialog->beamLocal() ) 2329 if ( beamDialog->beamLocal() )
2330 cal->setLocalTime(); 2330 cal->setLocalTime();
2331 else 2331 else
2332 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2332 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2333 Incidence *incidence = delSel.first(); 2333 Incidence *incidence = delSel.first();
2334 bool addText = false; 2334 bool addText = false;
2335 if ( delSel.count() < 10 ) 2335 if ( delSel.count() < 10 )
2336 addText = true; 2336 addText = true;
2337 else { 2337 else {
2338 description.sprintf(i18n(" %d items?"),delSel.count() ); 2338 description.sprintf(i18n(" %d items?"),delSel.count() );
2339 } 2339 }
2340 while ( incidence ) { 2340 while ( incidence ) {
2341 Incidence *in = incidence->clone(); 2341 Incidence *in = incidence->clone();
2342 if ( ! in->summary().isEmpty() ) { 2342 if ( ! in->summary().isEmpty() ) {
2343 in->setDescription(""); 2343 in->setDescription("");
2344 } else { 2344 } else {
2345 in->setSummary( in->description().left(20)); 2345 in->setSummary( in->description().left(20));
2346 in->setDescription(""); 2346 in->setDescription("");
2347 } 2347 }
2348 if ( addText ) 2348 if ( addText )
2349 description += in->summary() + "\n"; 2349 description += in->summary() + "\n";
2350 cal->addIncidence( in ); 2350 cal->addIncidence( in );
2351 incidence = delSel.next(); 2351 incidence = delSel.next();
2352 } 2352 }
2353 if ( beamDialog->beamVcal() ) { 2353 if ( beamDialog->beamVcal() ) {
2354 fn += ".vcs"; 2354 fn += ".vcs";
2355 FileStorage storage( cal, fn, new VCalFormat ); 2355 FileStorage storage( cal, fn, new VCalFormat );
2356 storage.save(); 2356 storage.save();
2357 } else { 2357 } else {
2358 fn += ".ics"; 2358 fn += ".ics";
2359 FileStorage storage( cal, fn, new ICalFormat( ) ); 2359 FileStorage storage( cal, fn, new ICalFormat( ) );
2360 storage.save(); 2360 storage.save();
2361 } 2361 }
2362 delete cal; 2362 delete cal;
2363 mes = i18n("KO/Pi: Ready for beaming"); 2363 mes = i18n("KO/Pi: Ready for beaming");
2364 topLevelWidget()->setCaption(mes); 2364 topLevelWidget()->setCaption(mes);
2365 KApplication::convert2latin1( fn ); 2365 KApplication::convert2latin1( fn );
2366#ifndef DESKTOP_VERSION 2366#ifndef DESKTOP_VERSION
2367 Ir *ir = new Ir( this ); 2367 Ir *ir = new Ir( this );
2368 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 2368 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
2369 ir->send( fn, description, "text/x-vCalendar" ); 2369 ir->send( fn, description, "text/x-vCalendar" );
2370#endif 2370#endif
2371 } 2371 }
2372} 2372}
2373void CalendarView::beamDone( Ir *ir ) 2373void CalendarView::beamDone( Ir *ir )
2374{ 2374{
2375#ifndef DESKTOP_VERSION 2375#ifndef DESKTOP_VERSION
2376 delete ir; 2376 delete ir;
2377#endif 2377#endif
2378 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 2378 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
2379 topLevelWidget()->raise(); 2379 topLevelWidget()->raise();
2380} 2380}
2381 2381
2382void CalendarView::moveIncidence(Incidence * inc ) 2382void CalendarView::moveIncidence(Incidence * inc )
2383{ 2383{
2384 if ( !inc ) return; 2384 if ( !inc ) return;
2385 // qDebug("showDatePickerForIncidence( ) "); 2385 // qDebug("showDatePickerForIncidence( ) ");
2386 if ( mDateFrame->isVisible() ) 2386 if ( mDateFrame->isVisible() )
2387 mDateFrame->hide(); 2387 mDateFrame->hide();
2388 else { 2388 else {
2389 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ; 2389 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ;
2390 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ; 2390 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ;
2391 int dw = QApplication::desktop()->width(); 2391 int dw = QApplication::desktop()->width();
2392 int dh = QApplication::desktop()->height(); 2392 int dh = QApplication::desktop()->height();
2393 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2393 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2394 mDateFrame->show(); 2394 mDateFrame->show();
2395 } 2395 }
2396 mDatePickerMode = 2; 2396 mDatePickerMode = 2;
2397 mMoveIncidence = inc ; 2397 mMoveIncidence = inc ;
2398 QDate da; 2398 QDate da;
2399 if ( mMoveIncidence->type() == "Todo" ) { 2399 if ( mMoveIncidence->type() == "Todo" ) {
2400 Todo * to = (Todo *) mMoveIncidence; 2400 Todo * to = (Todo *) mMoveIncidence;
2401 if ( to->hasDueDate() ) 2401 if ( to->hasDueDate() )
2402 da = to->dtDue().date(); 2402 da = to->dtDue().date();
2403 else 2403 else
2404 da = QDate::currentDate(); 2404 da = QDate::currentDate();
2405 } else { 2405 } else {
2406 da = mMoveIncidence->dtStart().date(); 2406 da = mMoveIncidence->dtStart().date();
2407 } 2407 }
2408 mDatePicker->setDate( da ); 2408 mDatePicker->setDate( da );
2409} 2409}
2410void CalendarView::showDatePicker( ) 2410void CalendarView::showDatePicker( )
2411{ 2411{
2412 //qDebug("CalendarView::showDatePicker( ) "); 2412 //qDebug("CalendarView::showDatePicker( ) ");
2413 if ( mDateFrame->isVisible() ) 2413 if ( mDateFrame->isVisible() )
2414 mDateFrame->hide(); 2414 mDateFrame->hide();
2415 else { 2415 else {
2416 int w =mDatePicker->sizeHint().width() ; 2416 int w =mDatePicker->sizeHint().width() ;
2417 int h = mDatePicker->sizeHint().height() ; 2417 int h = mDatePicker->sizeHint().height() ;
2418 int dw = QApplication::desktop()->width(); 2418 int dw = QApplication::desktop()->width();
2419 int dh = QApplication::desktop()->height(); 2419 int dh = QApplication::desktop()->height();
2420 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2420 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2421 mDateFrame->show(); 2421 mDateFrame->show();
2422 } 2422 }
2423 mDatePickerMode = 1; 2423 mDatePickerMode = 1;
2424 mDatePicker->setDate( mNavigator->selectedDates().first() ); 2424 mDatePicker->setDate( mNavigator->selectedDates().first() );
2425} 2425}
2426 2426
2427void CalendarView::showEventEditor() 2427void CalendarView::showEventEditor()
2428{ 2428{
2429#ifdef DESKTOP_VERSION 2429#ifdef DESKTOP_VERSION
2430 mEventEditor->show(); 2430 mEventEditor->show();
2431#else 2431#else
2432 mEventEditor->showMaximized(); 2432 mEventEditor->showMaximized();
2433#endif 2433#endif
2434} 2434}
2435void CalendarView::showTodoEditor() 2435void CalendarView::showTodoEditor()
2436{ 2436{
2437#ifdef DESKTOP_VERSION 2437#ifdef DESKTOP_VERSION
2438 mTodoEditor->show(); 2438 mTodoEditor->show();
2439#else 2439#else
2440 mTodoEditor->showMaximized(); 2440 mTodoEditor->showMaximized();
2441#endif 2441#endif
2442} 2442}
2443 2443
2444void CalendarView::cloneIncidence() 2444void CalendarView::cloneIncidence()
2445{ 2445{
2446 Incidence *incidence = currentSelection(); 2446 Incidence *incidence = currentSelection();
2447 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2447 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2448 if ( incidence ) { 2448 if ( incidence ) {
2449 cloneIncidence(incidence); 2449 cloneIncidence(incidence);
2450 } 2450 }
2451} 2451}
2452void CalendarView::moveIncidence() 2452void CalendarView::moveIncidence()
2453{ 2453{
2454 Incidence *incidence = currentSelection(); 2454 Incidence *incidence = currentSelection();
2455 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2455 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2456 if ( incidence ) { 2456 if ( incidence ) {
2457 moveIncidence(incidence); 2457 moveIncidence(incidence);
2458 } 2458 }
2459} 2459}
2460void CalendarView::beamIncidence() 2460void CalendarView::beamIncidence()
2461{ 2461{
2462 Incidence *incidence = currentSelection(); 2462 Incidence *incidence = currentSelection();
2463 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2463 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2464 if ( incidence ) { 2464 if ( incidence ) {
2465 beamIncidence(incidence); 2465 beamIncidence(incidence);
2466 } 2466 }
2467} 2467}
2468void CalendarView::toggleCancelIncidence() 2468void CalendarView::toggleCancelIncidence()
2469{ 2469{
2470 Incidence *incidence = currentSelection(); 2470 Incidence *incidence = currentSelection();
2471 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2471 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2472 if ( incidence ) { 2472 if ( incidence ) {
2473 cancelIncidence(incidence); 2473 cancelIncidence(incidence);
2474 } 2474 }
2475} 2475}
2476 2476
2477 2477
2478void CalendarView::cancelIncidence(Incidence * inc ) 2478void CalendarView::cancelIncidence(Incidence * inc )
2479{ 2479{
2480 inc->setCancelled( ! inc->cancelled() ); 2480 inc->setCancelled( ! inc->cancelled() );
2481 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 2481 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
2482 updateView(); 2482 updateView();
2483} 2483}
2484void CalendarView::cloneIncidence(Incidence * orgInc ) 2484void CalendarView::cloneIncidence(Incidence * orgInc )
2485{ 2485{
2486 Incidence * newInc = orgInc->clone(); 2486 Incidence * newInc = orgInc->clone();
2487 newInc->recreate(); 2487 newInc->recreate();
2488 2488
2489 if ( newInc->type() == "Todo" ) { 2489 if ( newInc->type() == "Todo" ) {
2490 Todo* t = (Todo*) newInc; 2490 Todo* t = (Todo*) newInc;
2491 mTodoEditor->editTodo( t ); 2491 mTodoEditor->editTodo( t );
2492 showTodoEditor(); 2492 showTodoEditor();
2493 if ( mTodoEditor->exec() ) { 2493 if ( mTodoEditor->exec() ) {
2494 mCalendar->addTodo( t ); 2494 mCalendar->addTodo( t );
2495 updateView(); 2495 updateView();
2496 } else { 2496 } else {
2497 delete t; 2497 delete t;
2498 } 2498 }
2499 } 2499 }
2500 else { 2500 else {
2501 Event* e = (Event*) newInc; 2501 Event* e = (Event*) newInc;
2502 mEventEditor->editEvent( e ); 2502 mEventEditor->editEvent( e );
2503 showEventEditor(); 2503 showEventEditor();
2504 if ( mEventEditor->exec() ) { 2504 if ( mEventEditor->exec() ) {
2505 mCalendar->addEvent( e ); 2505 mCalendar->addEvent( e );
2506 updateView(); 2506 updateView();
2507 } else { 2507 } else {
2508 delete e; 2508 delete e;
2509 } 2509 }
2510 } 2510 }
2511} 2511}
2512 2512
2513void CalendarView::newEvent() 2513void CalendarView::newEvent()
2514{ 2514{
2515 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 2515 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
2516 KOAgendaView *aView = mViewManager->agendaView(); 2516 KOAgendaView *aView = mViewManager->agendaView();
2517 if (aView) { 2517 if (aView) {
2518 if (aView->selectionStart().isValid()) { 2518 if (aView->selectionStart().isValid()) {
2519 if (aView->selectedIsAllDay()) { 2519 if (aView->selectedIsAllDay()) {
2520 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 2520 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
2521 } else { 2521 } else {
2522 newEvent(aView->selectionStart(),aView->selectionEnd()); 2522 newEvent(aView->selectionStart(),aView->selectionEnd());
2523 } 2523 }
2524 return; 2524 return;
2525 } 2525 }
2526 } 2526 }
2527 2527
2528 QDate date = mNavigator->selectedDates().first(); 2528 QDate date = mNavigator->selectedDates().first();
2529 QDateTime current = QDateTime::currentDateTime(); 2529 QDateTime current = QDateTime::currentDateTime();
2530 if ( date <= current.date() ) { 2530 if ( date <= current.date() ) {
2531 int hour = current.time().hour() +1; 2531 int hour = current.time().hour() +1;
2532 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 2532 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
2533 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2533 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2534 } else 2534 } else
2535 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 2535 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
2536 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 2536 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
2537 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2537 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2538} 2538}
2539 2539
2540void CalendarView::newEvent(QDateTime fh) 2540void CalendarView::newEvent(QDateTime fh)
2541{ 2541{
2542 newEvent(fh, 2542 newEvent(fh,
2543 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 2543 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
2544} 2544}
2545 2545
2546void CalendarView::newEvent(QDate dt) 2546void CalendarView::newEvent(QDate dt)
2547{ 2547{
2548 newEvent(QDateTime(dt, QTime(0,0,0)), 2548 newEvent(QDateTime(dt, QTime(0,0,0)),
2549 QDateTime(dt, QTime(0,0,0)), true); 2549 QDateTime(dt, QTime(0,0,0)), true);
2550} 2550}
2551 2551
2552void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 2552void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
2553{ 2553{
2554 2554
2555 mEventEditor->newEvent(fromHint,toHint,allDay); 2555 mEventEditor->newEvent(fromHint,toHint,allDay);
2556 if ( mFilterView->filtersEnabled() ) { 2556 if ( mFilterView->filtersEnabled() ) {
2557 CalFilter *filter = mFilterView->selectedFilter(); 2557 CalFilter *filter = mFilterView->selectedFilter();
2558 if (filter && filter->showCategories()) { 2558 if (filter && filter->showCategories()) {
2559 mEventEditor->setCategories(filter->categoryList().join(",") ); 2559 mEventEditor->setCategories(filter->categoryList().join(",") );
2560 } 2560 }
2561 if ( filter ) 2561 if ( filter )
2562 mEventEditor->setSecrecy( filter->getSecrecy() ); 2562 mEventEditor->setSecrecy( filter->getSecrecy() );
2563 } 2563 }
2564 showEventEditor(); 2564 showEventEditor();
2565} 2565}
2566void CalendarView::todoAdded(Todo * t) 2566void CalendarView::todoAdded(Todo * t)
2567{ 2567{
2568 2568
2569 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 2569 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
2570 updateTodoViews(); 2570 updateTodoViews();
2571} 2571}
2572void CalendarView::todoChanged(Todo * t) 2572void CalendarView::todoChanged(Todo * t)
2573{ 2573{
2574 emit todoModified( t, 4 ); 2574 emit todoModified( t, 4 );
2575 // updateTodoViews(); 2575 // updateTodoViews();
2576} 2576}
2577void CalendarView::todoToBeDeleted(Todo *) 2577void CalendarView::todoToBeDeleted(Todo *)
2578{ 2578{
2579 //qDebug("todoToBeDeleted(Todo *) "); 2579 //qDebug("todoToBeDeleted(Todo *) ");
2580 updateTodoViews(); 2580 updateTodoViews();
2581} 2581}
2582void CalendarView::todoDeleted() 2582void CalendarView::todoDeleted()
2583{ 2583{
2584 //qDebug(" todoDeleted()"); 2584 //qDebug(" todoDeleted()");
2585 updateTodoViews(); 2585 updateTodoViews();
2586} 2586}
2587 2587
2588 2588
2589 2589
2590void CalendarView::newTodo() 2590void CalendarView::newTodo()
2591{ 2591{
2592 2592
2593 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true); 2593 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true);
2594 if ( mFilterView->filtersEnabled() ) { 2594 if ( mFilterView->filtersEnabled() ) {
2595 CalFilter *filter = mFilterView->selectedFilter(); 2595 CalFilter *filter = mFilterView->selectedFilter();
2596 if (filter && filter->showCategories()) { 2596 if (filter && filter->showCategories()) {
2597 mTodoEditor->setCategories(filter->categoryList().join(",") ); 2597 mTodoEditor->setCategories(filter->categoryList().join(",") );
2598 } 2598 }
2599 if ( filter ) 2599 if ( filter )
2600 mTodoEditor->setSecrecy( filter->getSecrecy() ); 2600 mTodoEditor->setSecrecy( filter->getSecrecy() );
2601 } 2601 }
2602 showTodoEditor(); 2602 showTodoEditor();
2603} 2603}
2604 2604
2605void CalendarView::newSubTodo() 2605void CalendarView::newSubTodo()
2606{ 2606{
2607 Todo *todo = selectedTodo(); 2607 Todo *todo = selectedTodo();
2608 if ( todo ) newSubTodo( todo ); 2608 if ( todo ) newSubTodo( todo );
2609} 2609}
2610 2610
2611void CalendarView::newSubTodo(Todo *parentEvent) 2611void CalendarView::newSubTodo(Todo *parentEvent)
2612{ 2612{
2613 2613
2614 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true); 2614 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true);
2615 showTodoEditor(); 2615 showTodoEditor();
2616} 2616}
2617 2617
2618void CalendarView::newFloatingEvent() 2618void CalendarView::newFloatingEvent()
2619{ 2619{
2620 DateList tmpList = mNavigator->selectedDates(); 2620 DateList tmpList = mNavigator->selectedDates();
2621 QDate date = tmpList.first(); 2621 QDate date = tmpList.first();
2622 2622
2623 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 2623 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
2624 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 2624 QDateTime( date, QTime( 12, 0, 0 ) ), true );
2625} 2625}
2626 2626
2627 2627
2628void CalendarView::editEvent( Event *event ) 2628void CalendarView::editEvent( Event *event )
2629{ 2629{
2630 2630
2631 if ( !event ) return; 2631 if ( !event ) return;
2632 if ( event->isReadOnly() ) { 2632 if ( event->isReadOnly() ) {
2633 showEvent( event ); 2633 showEvent( event );
2634 return; 2634 return;
2635 } 2635 }
2636 mEventEditor->editEvent( event , mFlagEditDescription); 2636 mEventEditor->editEvent( event , mFlagEditDescription);
2637 showEventEditor(); 2637 showEventEditor();
2638} 2638}
2639void CalendarView::editJournal( Journal *jour ) 2639void CalendarView::editJournal( Journal *jour )
2640{ 2640{
2641 if ( !jour ) return; 2641 if ( !jour ) return;
2642 mDialogManager->hideSearchDialog(); 2642 mDialogManager->hideSearchDialog();
2643 mViewManager->showJournalView(); 2643 mViewManager->showJournalView();
2644 mNavigator->slotDaySelect( jour->dtStart().date() ); 2644 mNavigator->slotDaySelect( jour->dtStart().date() );
2645} 2645}
2646void CalendarView::editTodo( Todo *todo ) 2646void CalendarView::editTodo( Todo *todo )
2647{ 2647{
2648 if ( !todo ) return; 2648 if ( !todo ) return;
2649 2649
2650 if ( todo->isReadOnly() ) { 2650 if ( todo->isReadOnly() ) {
2651 showTodo( todo ); 2651 showTodo( todo );
2652 return; 2652 return;
2653 } 2653 }
2654 mTodoEditor->editTodo( todo ,mFlagEditDescription); 2654 mTodoEditor->editTodo( todo ,mFlagEditDescription);
2655 showTodoEditor(); 2655 showTodoEditor();
2656 2656
2657} 2657}
2658 2658
2659KOEventViewerDialog* CalendarView::getEventViewerDialog() 2659KOEventViewerDialog* CalendarView::getEventViewerDialog()
2660{ 2660{
2661 if ( !mEventViewerDialog ) { 2661 if ( !mEventViewerDialog ) {
2662 mEventViewerDialog = new KOEventViewerDialog(this); 2662 mEventViewerDialog = new KOEventViewerDialog(this);
2663 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 2663 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
2664 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 2664 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
2665 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 2665 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
2666 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 2666 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
2667 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 2667 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
2668 viewManager(), SLOT( showAgendaView( bool ) ) ); 2668 viewManager(), SLOT( showAgendaView( bool ) ) );
2669 mEventViewerDialog->resize( 640, 480 ); 2669 mEventViewerDialog->resize( 640, 480 );
2670 2670
2671 } 2671 }
2672 return mEventViewerDialog; 2672 return mEventViewerDialog;
2673} 2673}
2674void CalendarView::showEvent(Event *event) 2674void CalendarView::showEvent(Event *event)
2675{ 2675{
2676 getEventViewerDialog()->setEvent(event); 2676 getEventViewerDialog()->setEvent(event);
2677 getEventViewerDialog()->showMe(); 2677 getEventViewerDialog()->showMe();
2678} 2678}
2679 2679
2680void CalendarView::showTodo(Todo *event) 2680void CalendarView::showTodo(Todo *event)
2681{ 2681{
2682 getEventViewerDialog()->setTodo(event); 2682 getEventViewerDialog()->setTodo(event);
2683 getEventViewerDialog()->showMe(); 2683 getEventViewerDialog()->showMe();
2684} 2684}
2685void CalendarView::showJournal( Journal *jour ) 2685void CalendarView::showJournal( Journal *jour )
2686{ 2686{
2687 getEventViewerDialog()->setJournal(jour); 2687 getEventViewerDialog()->setJournal(jour);
2688 getEventViewerDialog()->showMe(); 2688 getEventViewerDialog()->showMe();
2689 2689
2690} 2690}
2691// void CalendarView::todoModified (Todo *event, int changed) 2691// void CalendarView::todoModified (Todo *event, int changed)
2692// { 2692// {
2693// // if (mDialogList.find (event) != mDialogList.end ()) { 2693// // if (mDialogList.find (event) != mDialogList.end ()) {
2694// // kdDebug() << "Todo modified and open" << endl; 2694// // kdDebug() << "Todo modified and open" << endl;
2695// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 2695// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
2696// // temp->modified (changed); 2696// // temp->modified (changed);
2697 2697
2698// // } 2698// // }
2699 2699
2700// mViewManager->updateView(); 2700// mViewManager->updateView();
2701// } 2701// }
2702 2702
2703void CalendarView::appointment_show() 2703void CalendarView::appointment_show()
2704{ 2704{
2705 Event *anEvent = 0; 2705 Event *anEvent = 0;
2706 2706
2707 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2707 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2708 2708
2709 if (mViewManager->currentView()->isEventView()) { 2709 if (mViewManager->currentView()->isEventView()) {
2710 if ( incidence && incidence->type() == "Event" ) { 2710 if ( incidence && incidence->type() == "Event" ) {
2711 anEvent = static_cast<Event *>(incidence); 2711 anEvent = static_cast<Event *>(incidence);
2712 } 2712 }
2713 } 2713 }
2714 2714
2715 if (!anEvent) { 2715 if (!anEvent) {
2716 KNotifyClient::beep(); 2716 KNotifyClient::beep();
2717 return; 2717 return;
2718 } 2718 }
2719 2719
2720 showEvent(anEvent); 2720 showEvent(anEvent);
2721} 2721}
2722 2722
2723void CalendarView::appointment_edit() 2723void CalendarView::appointment_edit()
2724{ 2724{
2725 Event *anEvent = 0; 2725 Event *anEvent = 0;
2726 2726
2727 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2727 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2728 2728
2729 if (mViewManager->currentView()->isEventView()) { 2729 if (mViewManager->currentView()->isEventView()) {
2730 if ( incidence && incidence->type() == "Event" ) { 2730 if ( incidence && incidence->type() == "Event" ) {
2731 anEvent = static_cast<Event *>(incidence); 2731 anEvent = static_cast<Event *>(incidence);
2732 } 2732 }
2733 } 2733 }
2734 2734
2735 if (!anEvent) { 2735 if (!anEvent) {
2736 KNotifyClient::beep(); 2736 KNotifyClient::beep();
2737 return; 2737 return;
2738 } 2738 }
2739 2739
2740 editEvent(anEvent); 2740 editEvent(anEvent);
2741} 2741}
2742 2742
2743void CalendarView::appointment_delete() 2743void CalendarView::appointment_delete()
2744{ 2744{
2745 Event *anEvent = 0; 2745 Event *anEvent = 0;
2746 2746
2747 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2747 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2748 2748
2749 if (mViewManager->currentView()->isEventView()) { 2749 if (mViewManager->currentView()->isEventView()) {
2750 if ( incidence && incidence->type() == "Event" ) { 2750 if ( incidence && incidence->type() == "Event" ) {
2751 anEvent = static_cast<Event *>(incidence); 2751 anEvent = static_cast<Event *>(incidence);
2752 } 2752 }
2753 } 2753 }
2754 2754
2755 if (!anEvent) { 2755 if (!anEvent) {
2756 KNotifyClient::beep(); 2756 KNotifyClient::beep();
2757 return; 2757 return;
2758 } 2758 }
2759 2759
2760 deleteEvent(anEvent); 2760 deleteEvent(anEvent);
2761} 2761}
2762 2762
2763void CalendarView::todo_resub( Todo * parent, Todo * sub ) 2763void CalendarView::todo_resub( Todo * parent, Todo * sub )
2764{ 2764{
2765 if (!sub) return; 2765 if (!sub) return;
2766 if (!parent) return; 2766 if (!parent) return;
2767 if ( sub->relatedTo() ) 2767 if ( sub->relatedTo() )
2768 sub->relatedTo()->removeRelation(sub); 2768 sub->relatedTo()->removeRelation(sub);
2769 sub->setRelatedTo(parent); 2769 sub->setRelatedTo(parent);
2770 sub->setRelatedToUid(parent->uid()); 2770 sub->setRelatedToUid(parent->uid());
2771 parent->addRelation(sub); 2771 parent->addRelation(sub);
2772 sub->updated(); 2772 sub->updated();
2773 parent->updated(); 2773 parent->updated();
2774 setModified(true); 2774 setModified(true);
2775 updateView(); 2775 updateView();
2776} 2776}
2777void CalendarView::todo_unsub(Todo *anTodo ) 2777void CalendarView::todo_unsub(Todo *anTodo )
2778{ 2778{
2779 // Todo *anTodo = selectedTodo(); 2779 // Todo *anTodo = selectedTodo();
2780 if (!anTodo) return; 2780 if (!anTodo) return;
2781 if (!anTodo->relatedTo()) return; 2781 if (!anTodo->relatedTo()) return;
2782 anTodo->relatedTo()->removeRelation(anTodo); 2782 anTodo->relatedTo()->removeRelation(anTodo);
2783 anTodo->setRelatedTo(0); 2783 anTodo->setRelatedTo(0);
2784 anTodo->updated(); 2784 anTodo->updated();
2785 anTodo->setRelatedToUid(""); 2785 anTodo->setRelatedToUid("");
2786 setModified(true); 2786 setModified(true);
2787 updateView(); 2787 updateView();
2788} 2788}
2789 2789
2790void CalendarView::deleteTodo(Todo *todo) 2790void CalendarView::deleteTodo(Todo *todo)
2791{ 2791{
2792 if (!todo) { 2792 if (!todo) {
2793 KNotifyClient::beep(); 2793 KNotifyClient::beep();
2794 return; 2794 return;
2795 } 2795 }
2796 if (KOPrefs::instance()->mConfirm) { 2796 if (KOPrefs::instance()->mConfirm) {
2797 switch (msgItemDelete()) { 2797 switch (msgItemDelete()) {
2798 case KMessageBox::Continue: // OK 2798 case KMessageBox::Continue: // OK
2799 if (!todo->relations().isEmpty()) { 2799 if (!todo->relations().isEmpty()) {
2800 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2800 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2801 i18n("Delete To-Do")); 2801 i18n("Delete To-Do"));
2802 } else { 2802 } else {
2803 checkExternalId( todo ); 2803 checkExternalId( todo );
2804 calendar()->deleteTodo(todo); 2804 calendar()->deleteTodo(todo);
2805 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2805 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2806 updateView(); 2806 updateView();
2807 } 2807 }
2808 break; 2808 break;
2809 } // switch 2809 } // switch
2810 } else { 2810 } else {
2811 if (!todo->relations().isEmpty()) { 2811 if (!todo->relations().isEmpty()) {
2812 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2812 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2813 i18n("Delete To-Do")); 2813 i18n("Delete To-Do"));
2814 } else { 2814 } else {
2815 checkExternalId( todo ); 2815 checkExternalId( todo );
2816 mCalendar->deleteTodo(todo); 2816 mCalendar->deleteTodo(todo);
2817 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2817 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2818 updateView(); 2818 updateView();
2819 } 2819 }
2820 } 2820 }
2821 emit updateSearchDialog(); 2821 emit updateSearchDialog();
2822} 2822}
2823void CalendarView::deleteJournal(Journal *jour) 2823void CalendarView::deleteJournal(Journal *jour)
2824{ 2824{
2825 if (!jour) { 2825 if (!jour) {
2826 KNotifyClient::beep(); 2826 KNotifyClient::beep();
2827 return; 2827 return;
2828 } 2828 }
2829 if (KOPrefs::instance()->mConfirm) { 2829 if (KOPrefs::instance()->mConfirm) {
2830 switch (msgItemDelete()) { 2830 switch (msgItemDelete()) {
2831 case KMessageBox::Continue: // OK 2831 case KMessageBox::Continue: // OK
2832 calendar()->deleteJournal(jour); 2832 calendar()->deleteJournal(jour);
2833 updateView(); 2833 updateView();
2834 break; 2834 break;
2835 } // switch 2835 } // switch
2836 } else { 2836 } else {
2837 calendar()->deleteJournal(jour);; 2837 calendar()->deleteJournal(jour);;
2838 updateView(); 2838 updateView();
2839 } 2839 }
2840 emit updateSearchDialog(); 2840 emit updateSearchDialog();
2841} 2841}
2842 2842
2843void CalendarView::deleteEvent(Event *anEvent) 2843void CalendarView::deleteEvent(Event *anEvent)
2844{ 2844{
2845 if (!anEvent) { 2845 if (!anEvent) {
2846 KNotifyClient::beep(); 2846 KNotifyClient::beep();
2847 return; 2847 return;
2848 } 2848 }
2849 2849
2850 if (anEvent->recurrence()->doesRecur()) { 2850 if (anEvent->recurrence()->doesRecur()) {
2851 QDate itemDate = mViewManager->currentSelectionDate(); 2851 QDate itemDate = mViewManager->currentSelectionDate();
2852 int km; 2852 int km;
2853 if (!itemDate.isValid()) { 2853 if (!itemDate.isValid()) {
2854 //kdDebug() << "Date Not Valid" << endl; 2854 //kdDebug() << "Date Not Valid" << endl;
2855 if (KOPrefs::instance()->mConfirm) { 2855 if (KOPrefs::instance()->mConfirm) {
2856 km = KMessageBox::warningContinueCancel(this,anEvent->summary() + 2856 km = KMessageBox::warningContinueCancel(this,anEvent->summary() +
2857 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 2857 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
2858 i18n("KO/Pi Confirmation"),i18n("Delete All")); 2858 i18n("KO/Pi Confirmation"),i18n("Delete All"));
2859 if ( km == KMessageBox::Continue ) 2859 if ( km == KMessageBox::Continue )
2860 km = KMessageBox::No; // No = all below 2860 km = KMessageBox::No; // No = all below
2861 } else 2861 } else
2862 km = KMessageBox::No; 2862 km = KMessageBox::No;
2863 } else { 2863 } else {
2864 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() + 2864 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() +
2865 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 2865 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
2866 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 2866 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
2867 i18n("KO/Pi Confirmation"),i18n("Current"), 2867 i18n("KO/Pi Confirmation"),i18n("Current"),
2868 i18n("All")); 2868 i18n("All"));
2869 } 2869 }
2870 switch(km) { 2870 switch(km) {
2871 2871
2872 case KMessageBox::No: // Continue // all 2872 case KMessageBox::No: // Continue // all
2873 //qDebug("KMessageBox::No "); 2873 //qDebug("KMessageBox::No ");
2874 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2874 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2875 schedule(Scheduler::Cancel,anEvent); 2875 schedule(Scheduler::Cancel,anEvent);
2876 2876
2877 checkExternalId( anEvent); 2877 checkExternalId( anEvent);
2878 mCalendar->deleteEvent(anEvent); 2878 mCalendar->deleteEvent(anEvent);
2879 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 2879 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
2880 break; 2880 break;
2881 2881
2882 // Disabled because it does not work 2882 // Disabled because it does not work
2883 //#if 0 2883 //#if 0
2884 case KMessageBox::Yes: // just this one 2884 case KMessageBox::Yes: // just this one
2885 //QDate qd = mNavigator->selectedDates().first(); 2885 //QDate qd = mNavigator->selectedDates().first();
2886 //if (!qd.isValid()) { 2886 //if (!qd.isValid()) {
2887 // kdDebug() << "no date selected, or invalid date" << endl; 2887 // kdDebug() << "no date selected, or invalid date" << endl;
2888 // KNotifyClient::beep(); 2888 // KNotifyClient::beep();
2889 // return; 2889 // return;
2890 //} 2890 //}
2891 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 2891 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
2892 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 2892 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
2893 anEvent->addExDate(itemDate); 2893 anEvent->addExDate(itemDate);
2894 int duration = anEvent->recurrence()->duration(); 2894 int duration = anEvent->recurrence()->duration();
2895 if ( duration > 0 ) { 2895 if ( duration > 0 ) {
2896 anEvent->recurrence()->setDuration( duration - 1 ); 2896 anEvent->recurrence()->setDuration( duration - 1 );
2897 } 2897 }
2898 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 2898 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
2899 } 2899 }
2900 break; 2900 break;
2901 //#endif 2901 //#endif
2902 } // switch 2902 } // switch
2903 } else { 2903 } else {
2904 if (KOPrefs::instance()->mConfirm) { 2904 if (KOPrefs::instance()->mConfirm) {
2905 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() + 2905 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() +
2906 i18n("\nAre you sure you want\nto delete this event?"), 2906 i18n("\nAre you sure you want\nto delete this event?"),
2907 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 2907 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
2908 case KMessageBox::Continue: // OK 2908 case KMessageBox::Continue: // OK
2909 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2909 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2910 schedule(Scheduler::Cancel,anEvent); 2910 schedule(Scheduler::Cancel,anEvent);
2911 checkExternalId( anEvent); 2911 checkExternalId( anEvent);
2912 mCalendar->deleteEvent(anEvent); 2912 mCalendar->deleteEvent(anEvent);
2913 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2913 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2914 break; 2914 break;
2915 } // switch 2915 } // switch
2916 } else { 2916 } else {
2917 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2917 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2918 schedule(Scheduler::Cancel,anEvent); 2918 schedule(Scheduler::Cancel,anEvent);
2919 checkExternalId( anEvent); 2919 checkExternalId( anEvent);
2920 mCalendar->deleteEvent(anEvent); 2920 mCalendar->deleteEvent(anEvent);
2921 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2921 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2922 } 2922 }
2923 } // if-else 2923 } // if-else
2924 emit updateSearchDialog(); 2924 emit updateSearchDialog();
2925} 2925}
2926 2926
2927bool CalendarView::deleteEvent(const QString &uid) 2927bool CalendarView::deleteEvent(const QString &uid)
2928{ 2928{
2929 Event *ev = mCalendar->event(uid); 2929 Event *ev = mCalendar->event(uid);
2930 if (ev) { 2930 if (ev) {
2931 deleteEvent(ev); 2931 deleteEvent(ev);
2932 return true; 2932 return true;
2933 } else { 2933 } else {
2934 return false; 2934 return false;
2935 } 2935 }
2936} 2936}
2937 2937
2938/*****************************************************************************/ 2938/*****************************************************************************/
2939 2939
2940void CalendarView::action_mail() 2940void CalendarView::action_mail()
2941{ 2941{
2942#ifndef KORG_NOMAIL 2942#ifndef KORG_NOMAIL
2943 KOMailClient mailClient; 2943 KOMailClient mailClient;
2944 2944
2945 Incidence *incidence = currentSelection(); 2945 Incidence *incidence = currentSelection();
2946 2946
2947 if (!incidence) { 2947 if (!incidence) {
2948 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 2948 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
2949 return; 2949 return;
2950 } 2950 }
2951 if(incidence->attendeeCount() == 0 ) { 2951 if(incidence->attendeeCount() == 0 ) {
2952 KMessageBox::sorry(this, 2952 KMessageBox::sorry(this,
2953 i18n("Can't generate mail:\nNo attendees defined.\n")); 2953 i18n("Can't generate mail:\nNo attendees defined.\n"));
2954 return; 2954 return;
2955 } 2955 }
2956 2956
2957 CalendarLocal cal_tmp; 2957 CalendarLocal cal_tmp;
2958 Event *event = 0; 2958 Event *event = 0;
2959 Event *ev = 0; 2959 Event *ev = 0;
2960 if ( incidence && incidence->type() == "Event" ) { 2960 if ( incidence && incidence->type() == "Event" ) {
2961 event = static_cast<Event *>(incidence); 2961 event = static_cast<Event *>(incidence);
2962 ev = new Event(*event); 2962 ev = new Event(*event);
2963 cal_tmp.addEvent(ev); 2963 cal_tmp.addEvent(ev);
2964 } 2964 }
2965 ICalFormat mForm(); 2965 ICalFormat mForm();
2966 QString attachment = mForm.toString( &cal_tmp ); 2966 QString attachment = mForm.toString( &cal_tmp );
2967 if (ev) delete(ev); 2967 if (ev) delete(ev);
2968 2968
2969 mailClient.mailAttendees(currentSelection(), attachment); 2969 mailClient.mailAttendees(currentSelection(), attachment);
2970 2970
2971#endif 2971#endif
2972 2972
2973#if 0 2973#if 0
2974 Event *anEvent = 0; 2974 Event *anEvent = 0;
2975 if (mViewManager->currentView()->isEventView()) { 2975 if (mViewManager->currentView()->isEventView()) {
2976 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 2976 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
2977 } 2977 }
2978 2978
2979 if (!anEvent) { 2979 if (!anEvent) {
2980 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 2980 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
2981 return; 2981 return;
2982 } 2982 }
2983 if(anEvent->attendeeCount() == 0 ) { 2983 if(anEvent->attendeeCount() == 0 ) {
2984 KMessageBox::sorry(this, 2984 KMessageBox::sorry(this,
2985 i18n("Can't generate mail:\nNo attendees defined.\n")); 2985 i18n("Can't generate mail:\nNo attendees defined.\n"));
2986 return; 2986 return;
2987 } 2987 }
2988 2988
2989 mailobject.emailEvent(anEvent); 2989 mailobject.emailEvent(anEvent);
2990#endif 2990#endif
2991} 2991}
2992 2992
2993 2993
2994void CalendarView::schedule_publish(Incidence *incidence) 2994void CalendarView::schedule_publish(Incidence *incidence)
2995{ 2995{
2996 Event *event = 0; 2996 Event *event = 0;
2997 Todo *todo = 0; 2997 Todo *todo = 0;
2998 2998
2999 if (incidence == 0) { 2999 if (incidence == 0) {
3000 incidence = mViewManager->currentView()->selectedIncidences().first(); 3000 incidence = mViewManager->currentView()->selectedIncidences().first();
3001 if (incidence == 0) { 3001 if (incidence == 0) {
3002 incidence = mTodoList->selectedIncidences().first(); 3002 incidence = mTodoList->selectedIncidences().first();
3003 } 3003 }
3004 } 3004 }
3005 if ( incidence && incidence->type() == "Event" ) { 3005 if ( incidence && incidence->type() == "Event" ) {
3006 event = static_cast<Event *>(incidence); 3006 event = static_cast<Event *>(incidence);
3007 } else { 3007 } else {
3008 if ( incidence && incidence->type() == "Todo" ) { 3008 if ( incidence && incidence->type() == "Todo" ) {
3009 todo = static_cast<Todo *>(incidence); 3009 todo = static_cast<Todo *>(incidence);
3010 } 3010 }
3011 } 3011 }
3012 3012
3013 if (!event && !todo) { 3013 if (!event && !todo) {
3014 KMessageBox::sorry(this,i18n("No event selected.")); 3014 KMessageBox::sorry(this,i18n("No event selected."));
3015 return; 3015 return;
3016 } 3016 }
3017 3017
3018 PublishDialog *publishdlg = new PublishDialog(); 3018 PublishDialog *publishdlg = new PublishDialog();
3019 if (incidence->attendeeCount()>0) { 3019 if (incidence->attendeeCount()>0) {
3020 QPtrList<Attendee> attendees = incidence->attendees(); 3020 QPtrList<Attendee> attendees = incidence->attendees();
3021 attendees.first(); 3021 attendees.first();
3022 while ( attendees.current()!=0 ) { 3022 while ( attendees.current()!=0 ) {
3023 publishdlg->addAttendee(attendees.current()); 3023 publishdlg->addAttendee(attendees.current());
3024 attendees.next(); 3024 attendees.next();
3025 } 3025 }
3026 } 3026 }
3027 bool send = true; 3027 bool send = true;
3028 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3028 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3029 if ( publishdlg->exec() != QDialog::Accepted ) 3029 if ( publishdlg->exec() != QDialog::Accepted )
3030 send = false; 3030 send = false;
3031 } 3031 }
3032 if ( send ) { 3032 if ( send ) {
3033 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3033 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3034 if ( event ) { 3034 if ( event ) {
3035 Event *ev = new Event(*event); 3035 Event *ev = new Event(*event);
3036 ev->registerObserver(0); 3036 ev->registerObserver(0);
3037 ev->clearAttendees(); 3037 ev->clearAttendees();
3038 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3038 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3039 delete(ev); 3039 delete(ev);
3040 } 3040 }
3041 } else { 3041 } else {
3042 if ( todo ) { 3042 if ( todo ) {
3043 Todo *ev = new Todo(*todo); 3043 Todo *ev = new Todo(*todo);
3044 ev->registerObserver(0); 3044 ev->registerObserver(0);
3045 ev->clearAttendees(); 3045 ev->clearAttendees();
3046 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3046 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3047 delete(ev); 3047 delete(ev);
3048 } 3048 }
3049 } 3049 }
3050 } 3050 }
3051 } 3051 }
3052 delete publishdlg; 3052 delete publishdlg;
3053} 3053}
3054 3054
3055void CalendarView::schedule_request(Incidence *incidence) 3055void CalendarView::schedule_request(Incidence *incidence)
3056{ 3056{
3057 schedule(Scheduler::Request,incidence); 3057 schedule(Scheduler::Request,incidence);
3058} 3058}
3059 3059
3060void CalendarView::schedule_refresh(Incidence *incidence) 3060void CalendarView::schedule_refresh(Incidence *incidence)
3061{ 3061{
3062 schedule(Scheduler::Refresh,incidence); 3062 schedule(Scheduler::Refresh,incidence);
3063} 3063}
3064 3064
3065void CalendarView::schedule_cancel(Incidence *incidence) 3065void CalendarView::schedule_cancel(Incidence *incidence)
3066{ 3066{
3067 schedule(Scheduler::Cancel,incidence); 3067 schedule(Scheduler::Cancel,incidence);
3068} 3068}
3069 3069
3070void CalendarView::schedule_add(Incidence *incidence) 3070void CalendarView::schedule_add(Incidence *incidence)
3071{ 3071{
3072 schedule(Scheduler::Add,incidence); 3072 schedule(Scheduler::Add,incidence);
3073} 3073}
3074 3074
3075void CalendarView::schedule_reply(Incidence *incidence) 3075void CalendarView::schedule_reply(Incidence *incidence)
3076{ 3076{
3077 schedule(Scheduler::Reply,incidence); 3077 schedule(Scheduler::Reply,incidence);
3078} 3078}
3079 3079
3080void CalendarView::schedule_counter(Incidence *incidence) 3080void CalendarView::schedule_counter(Incidence *incidence)
3081{ 3081{
3082 schedule(Scheduler::Counter,incidence); 3082 schedule(Scheduler::Counter,incidence);
3083} 3083}
3084 3084
3085void CalendarView::schedule_declinecounter(Incidence *incidence) 3085void CalendarView::schedule_declinecounter(Incidence *incidence)
3086{ 3086{
3087 schedule(Scheduler::Declinecounter,incidence); 3087 schedule(Scheduler::Declinecounter,incidence);
3088} 3088}
3089 3089
3090void CalendarView::schedule_publish_freebusy(int daysToPublish) 3090void CalendarView::schedule_publish_freebusy(int daysToPublish)
3091{ 3091{
3092 QDateTime start = QDateTime::currentDateTime(); 3092 QDateTime start = QDateTime::currentDateTime();
3093 QDateTime end = start.addDays(daysToPublish); 3093 QDateTime end = start.addDays(daysToPublish);
3094 3094
3095 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 3095 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
3096 freebusy->setOrganizer(KOPrefs::instance()->email()); 3096 freebusy->setOrganizer(KOPrefs::instance()->email());
3097 3097
3098 3098
3099 PublishDialog *publishdlg = new PublishDialog(); 3099 PublishDialog *publishdlg = new PublishDialog();
3100 if ( publishdlg->exec() == QDialog::Accepted ) { 3100 if ( publishdlg->exec() == QDialog::Accepted ) {
3101 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3101 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3102 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 3102 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
3103 delete(freebusy); 3103 delete(freebusy);
3104 } 3104 }
3105 } 3105 }
3106 delete publishdlg; 3106 delete publishdlg;
3107} 3107}
3108 3108
3109void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 3109void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
3110{ 3110{
3111 Event *event = 0; 3111 Event *event = 0;
3112 Todo *todo = 0; 3112 Todo *todo = 0;
3113 3113
3114 if (incidence == 0) { 3114 if (incidence == 0) {
3115 incidence = mViewManager->currentView()->selectedIncidences().first(); 3115 incidence = mViewManager->currentView()->selectedIncidences().first();
3116 if (incidence == 0) { 3116 if (incidence == 0) {
3117 incidence = mTodoList->selectedIncidences().first(); 3117 incidence = mTodoList->selectedIncidences().first();
3118 } 3118 }
3119 } 3119 }
3120 if ( incidence && incidence->type() == "Event" ) { 3120 if ( incidence && incidence->type() == "Event" ) {
3121 event = static_cast<Event *>(incidence); 3121 event = static_cast<Event *>(incidence);
3122 } 3122 }
3123 if ( incidence && incidence->type() == "Todo" ) { 3123 if ( incidence && incidence->type() == "Todo" ) {
3124 todo = static_cast<Todo *>(incidence); 3124 todo = static_cast<Todo *>(incidence);
3125 } 3125 }
3126 3126
3127 if (!event && !todo) { 3127 if (!event && !todo) {
3128 KMessageBox::sorry(this,i18n("No event selected.")); 3128 KMessageBox::sorry(this,i18n("No event selected."));
3129 return; 3129 return;
3130 } 3130 }
3131 3131
3132 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 3132 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
3133 KMessageBox::sorry(this,i18n("The event has no attendees.")); 3133 KMessageBox::sorry(this,i18n("The event has no attendees."));
3134 return; 3134 return;
3135 } 3135 }
3136 3136
3137 Event *ev = 0; 3137 Event *ev = 0;
3138 if (event) ev = new Event(*event); 3138 if (event) ev = new Event(*event);
3139 Todo *to = 0; 3139 Todo *to = 0;
3140 if (todo) to = new Todo(*todo); 3140 if (todo) to = new Todo(*todo);
3141 3141
3142 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 3142 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
3143 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 3143 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
3144 if (!me) { 3144 if (!me) {
3145 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 3145 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
3146 return; 3146 return;
3147 } 3147 }
3148 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 3148 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
3149 StatusDialog *statdlg = new StatusDialog(this); 3149 StatusDialog *statdlg = new StatusDialog(this);
3150 if (!statdlg->exec()==QDialog::Accepted) return; 3150 if (!statdlg->exec()==QDialog::Accepted) return;
3151 me->setStatus( statdlg->status() ); 3151 me->setStatus( statdlg->status() );
3152 delete(statdlg); 3152 delete(statdlg);
3153 } 3153 }
3154 Attendee *menew = new Attendee(*me); 3154 Attendee *menew = new Attendee(*me);
3155 if (ev) { 3155 if (ev) {
3156 ev->clearAttendees(); 3156 ev->clearAttendees();
3157 ev->addAttendee(menew,false); 3157 ev->addAttendee(menew,false);
3158 } else { 3158 } else {
3159 if (to) { 3159 if (to) {
3160 todo->clearAttendees(); 3160 todo->clearAttendees();
3161 todo->addAttendee(menew,false); 3161 todo->addAttendee(menew,false);
3162 } 3162 }
3163 } 3163 }
3164 } 3164 }
3165 3165
3166 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3166 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3167 if (ev) { 3167 if (ev) {
3168 if ( !dlg->addMessage(ev,method) ) delete(ev); 3168 if ( !dlg->addMessage(ev,method) ) delete(ev);
3169 } else { 3169 } else {
3170 if (to) { 3170 if (to) {
3171 if ( !dlg->addMessage(to,method) ) delete(to); 3171 if ( !dlg->addMessage(to,method) ) delete(to);
3172 } 3172 }
3173 } 3173 }
3174} 3174}
3175 3175
3176void CalendarView::openAddressbook() 3176void CalendarView::openAddressbook()
3177{ 3177{
3178 KRun::runCommand("kaddressbook"); 3178 KRun::runCommand("kaddressbook");
3179} 3179}
3180 3180
3181void CalendarView::setModified(bool modified) 3181void CalendarView::setModified(bool modified)
3182{ 3182{
3183 if ( modified ) 3183 if ( modified )
3184 emit signalmodified(); 3184 emit signalmodified();
3185 if (mModified != modified) { 3185 if (mModified != modified) {
3186 mModified = modified; 3186 mModified = modified;
3187 emit modifiedChanged(mModified); 3187 emit modifiedChanged(mModified);
3188 } 3188 }
3189} 3189}
3190 3190
3191bool CalendarView::isReadOnly() 3191bool CalendarView::isReadOnly()
3192{ 3192{
3193 return mReadOnly; 3193 return mReadOnly;
3194} 3194}
3195 3195
3196void CalendarView::setReadOnly(bool readOnly) 3196void CalendarView::setReadOnly(bool readOnly)
3197{ 3197{
3198 if (mReadOnly != readOnly) { 3198 if (mReadOnly != readOnly) {
3199 mReadOnly = readOnly; 3199 mReadOnly = readOnly;
3200 emit readOnlyChanged(mReadOnly); 3200 emit readOnlyChanged(mReadOnly);
3201 } 3201 }
3202} 3202}
3203 3203
3204bool CalendarView::isModified() 3204bool CalendarView::isModified()
3205{ 3205{
3206 return mModified; 3206 return mModified;
3207} 3207}
3208 3208
3209void CalendarView::printSetup() 3209void CalendarView::printSetup()
3210{ 3210{
3211#ifndef KORG_NOPRINTER 3211#ifndef KORG_NOPRINTER
3212 createPrinter(); 3212 createPrinter();
3213 3213
3214 mCalPrinter->setupPrinter(); 3214 mCalPrinter->setupPrinter();
3215#endif 3215#endif
3216} 3216}
3217 3217
3218void CalendarView::print() 3218void CalendarView::print()
3219{ 3219{
3220#ifndef KORG_NOPRINTER 3220#ifndef KORG_NOPRINTER
3221 createPrinter(); 3221 createPrinter();
3222 3222
3223 DateList tmpDateList = mNavigator->selectedDates(); 3223 DateList tmpDateList = mNavigator->selectedDates();
3224 mCalPrinter->print(CalPrinter::Month, 3224 mCalPrinter->print(CalPrinter::Month,
3225 tmpDateList.first(), tmpDateList.last()); 3225 tmpDateList.first(), tmpDateList.last());
3226#endif 3226#endif
3227} 3227}
3228 3228
3229void CalendarView::printPreview() 3229void CalendarView::printPreview()
3230{ 3230{
3231#ifndef KORG_NOPRINTER 3231#ifndef KORG_NOPRINTER
3232 kdDebug() << "CalendarView::printPreview()" << endl; 3232 kdDebug() << "CalendarView::printPreview()" << endl;
3233 3233
3234 createPrinter(); 3234 createPrinter();
3235 3235
3236 DateList tmpDateList = mNavigator->selectedDates(); 3236 DateList tmpDateList = mNavigator->selectedDates();
3237 3237
3238 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 3238 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
3239 tmpDateList.last()); 3239 tmpDateList.last());
3240#endif 3240#endif
3241} 3241}
3242 3242
3243void CalendarView::exportICalendar() 3243void CalendarView::exportICalendar()
3244{ 3244{
3245 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 3245 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
3246 3246
3247 // Force correct extension 3247 // Force correct extension
3248 if (filename.right(4) != ".ics") filename += ".ics"; 3248 if (filename.right(4) != ".ics") filename += ".ics";
3249 3249
3250 FileStorage storage( mCalendar, filename, new ICalFormat() ); 3250 FileStorage storage( mCalendar, filename, new ICalFormat() );
3251 storage.save(); 3251 storage.save();
3252} 3252}
3253 3253
3254bool CalendarView::exportVCalendar( QString filename ) 3254bool CalendarView::exportVCalendar( QString filename )
3255{ 3255{
3256 if (mCalendar->journals().count() > 0) { 3256 if (mCalendar->journals().count() > 0) {
3257 int result = KMessageBox::warningContinueCancel(this, 3257 int result = KMessageBox::warningContinueCancel(this,
3258 i18n("The journal entries can not be\nexported to a vCalendar file."), 3258 i18n("The journal entries can not be\nexported to a vCalendar file."),
3259 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 3259 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
3260 true); 3260 true);
3261 if (result != KMessageBox::Continue) return false; 3261 if (result != KMessageBox::Continue) return false;
3262 } 3262 }
3263 3263
3264 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 3264 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
3265 3265
3266 // Force correct extension 3266 // Force correct extension
3267 if (filename.right(4) != ".vcs") filename += ".vcs"; 3267 if (filename.right(4) != ".vcs") filename += ".vcs";
3268 3268
3269 FileStorage storage( mCalendar, filename, new VCalFormat ); 3269 FileStorage storage( mCalendar, filename, new VCalFormat );
3270 return storage.save(); 3270 return storage.save();
3271 3271
3272} 3272}
3273 3273
3274void CalendarView::eventUpdated(Incidence *) 3274void CalendarView::eventUpdated(Incidence *)
3275{ 3275{
3276 setModified(); 3276 setModified();
3277 // Don't call updateView here. The code, which has caused the update of the 3277 // Don't call updateView here. The code, which has caused the update of the
3278 // event is responsible for updating the view. 3278 // event is responsible for updating the view.
3279 // updateView(); 3279 // updateView();
3280} 3280}
3281 3281
3282void CalendarView::adaptNavigationUnits() 3282void CalendarView::adaptNavigationUnits()
3283{ 3283{
3284 if (mViewManager->currentView()->isEventView()) { 3284 if (mViewManager->currentView()->isEventView()) {
3285 int days = mViewManager->currentView()->currentDateCount(); 3285 int days = mViewManager->currentView()->currentDateCount();
3286 if (days == 1) { 3286 if (days == 1) {
3287 emit changeNavStringPrev(i18n("&Previous Day")); 3287 emit changeNavStringPrev(i18n("&Previous Day"));
3288 emit changeNavStringNext(i18n("&Next Day")); 3288 emit changeNavStringNext(i18n("&Next Day"));
3289 } else { 3289 } else {
3290 emit changeNavStringPrev(i18n("&Previous Week")); 3290 emit changeNavStringPrev(i18n("&Previous Week"));
3291 emit changeNavStringNext(i18n("&Next Week")); 3291 emit changeNavStringNext(i18n("&Next Week"));
3292 } 3292 }
3293 } 3293 }
3294} 3294}
3295 3295
3296void CalendarView::processMainViewSelection( Incidence *incidence ) 3296void CalendarView::processMainViewSelection( Incidence *incidence )
3297{ 3297{
3298 if ( incidence ) mTodoList->clearSelection(); 3298 if ( incidence ) mTodoList->clearSelection();
3299 processIncidenceSelection( incidence ); 3299 processIncidenceSelection( incidence );
3300} 3300}
3301 3301
3302void CalendarView::processTodoListSelection( Incidence *incidence ) 3302void CalendarView::processTodoListSelection( Incidence *incidence )
3303{ 3303{
3304 if ( incidence && mViewManager->currentView() ) { 3304 if ( incidence && mViewManager->currentView() ) {
3305 mViewManager->currentView()->clearSelection(); 3305 mViewManager->currentView()->clearSelection();
3306 } 3306 }
3307 processIncidenceSelection( incidence ); 3307 processIncidenceSelection( incidence );
3308} 3308}
3309 3309
3310void CalendarView::processIncidenceSelection( Incidence *incidence ) 3310void CalendarView::processIncidenceSelection( Incidence *incidence )
3311{ 3311{
3312 if ( incidence == mSelectedIncidence ) return; 3312 if ( incidence == mSelectedIncidence ) return;
3313 3313
3314 mSelectedIncidence = incidence; 3314 mSelectedIncidence = incidence;
3315 3315
3316 emit incidenceSelected( mSelectedIncidence ); 3316 emit incidenceSelected( mSelectedIncidence );
3317 3317
3318 if ( incidence && incidence->type() == "Event" ) { 3318 if ( incidence && incidence->type() == "Event" ) {
3319 Event *event = static_cast<Event *>( incidence ); 3319 Event *event = static_cast<Event *>( incidence );
3320 if ( event->organizer() == KOPrefs::instance()->email() ) { 3320 if ( event->organizer() == KOPrefs::instance()->email() ) {
3321 emit organizerEventsSelected( true ); 3321 emit organizerEventsSelected( true );
3322 } else { 3322 } else {
3323 emit organizerEventsSelected(false); 3323 emit organizerEventsSelected(false);
3324 } 3324 }
3325 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3325 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3326 KOPrefs::instance()->email() ) ) { 3326 KOPrefs::instance()->email() ) ) {
3327 emit groupEventsSelected( true ); 3327 emit groupEventsSelected( true );
3328 } else { 3328 } else {
3329 emit groupEventsSelected(false); 3329 emit groupEventsSelected(false);
3330 } 3330 }
3331 return; 3331 return;
3332 } else { 3332 } else {
3333 if ( incidence && incidence->type() == "Todo" ) { 3333 if ( incidence && incidence->type() == "Todo" ) {
3334 emit todoSelected( true ); 3334 emit todoSelected( true );
3335 Todo *event = static_cast<Todo *>( incidence ); 3335 Todo *event = static_cast<Todo *>( incidence );
3336 if ( event->organizer() == KOPrefs::instance()->email() ) { 3336 if ( event->organizer() == KOPrefs::instance()->email() ) {
3337 emit organizerEventsSelected( true ); 3337 emit organizerEventsSelected( true );
3338 } else { 3338 } else {
3339 emit organizerEventsSelected(false); 3339 emit organizerEventsSelected(false);
3340 } 3340 }
3341 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3341 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3342 KOPrefs::instance()->email() ) ) { 3342 KOPrefs::instance()->email() ) ) {
3343 emit groupEventsSelected( true ); 3343 emit groupEventsSelected( true );
3344 } else { 3344 } else {
3345 emit groupEventsSelected(false); 3345 emit groupEventsSelected(false);
3346 } 3346 }
3347 return; 3347 return;
3348 } else { 3348 } else {
3349 emit todoSelected( false ); 3349 emit todoSelected( false );
3350 emit organizerEventsSelected(false); 3350 emit organizerEventsSelected(false);
3351 emit groupEventsSelected(false); 3351 emit groupEventsSelected(false);
3352 } 3352 }
3353 return; 3353 return;
3354 } 3354 }
3355 3355
3356 /* if ( incidence && incidence->type() == "Todo" ) { 3356 /* if ( incidence && incidence->type() == "Todo" ) {
3357 emit todoSelected( true ); 3357 emit todoSelected( true );
3358 } else { 3358 } else {
3359 emit todoSelected( false ); 3359 emit todoSelected( false );
3360 }*/ 3360 }*/
3361} 3361}
3362 3362
3363 3363
3364void CalendarView::checkClipboard() 3364void CalendarView::checkClipboard()
3365{ 3365{
3366#ifndef KORG_NODND 3366#ifndef KORG_NODND
3367 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 3367 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
3368 emit pasteEnabled(true); 3368 emit pasteEnabled(true);
3369 } else { 3369 } else {
3370 emit pasteEnabled(false); 3370 emit pasteEnabled(false);
3371 } 3371 }
3372#endif 3372#endif
3373} 3373}
3374 3374
3375void CalendarView::showDates(const DateList &selectedDates) 3375void CalendarView::showDates(const DateList &selectedDates)
3376{ 3376{
3377 // kdDebug() << "CalendarView::selectDates()" << endl; 3377 // kdDebug() << "CalendarView::selectDates()" << endl;
3378 3378
3379 if ( mViewManager->currentView() ) { 3379 if ( mViewManager->currentView() ) {
3380 updateView( selectedDates.first(), selectedDates.last() ); 3380 updateView( selectedDates.first(), selectedDates.last() );
3381 } else { 3381 } else {
3382 mViewManager->showAgendaView(); 3382 mViewManager->showAgendaView();
3383 } 3383 }
3384 3384
3385 QString selDates; 3385 QString selDates;
3386 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true); 3386 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true);
3387 if (selectedDates.first() < selectedDates.last() ) 3387 if (selectedDates.first() < selectedDates.last() )
3388 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 3388 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
3389 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 3389 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
3390 3390
3391} 3391}
3392 3392
3393QPtrList<CalFilter> CalendarView::filters() 3393QPtrList<CalFilter> CalendarView::filters()
3394{ 3394{
3395 return mFilters; 3395 return mFilters;
3396 3396
3397} 3397}
3398void CalendarView::editFilters() 3398void CalendarView::editFilters()
3399{ 3399{
3400 // kdDebug() << "CalendarView::editFilters()" << endl; 3400 // kdDebug() << "CalendarView::editFilters()" << endl;
3401 3401
3402 CalFilter *filter = mFilters.first(); 3402 CalFilter *filter = mFilters.first();
3403 while(filter) { 3403 while(filter) {
3404 kdDebug() << " Filter: " << filter->name() << endl; 3404 kdDebug() << " Filter: " << filter->name() << endl;
3405 filter = mFilters.next(); 3405 filter = mFilters.next();
3406 } 3406 }
3407 3407
3408 mDialogManager->showFilterEditDialog(&mFilters); 3408 mDialogManager->showFilterEditDialog(&mFilters);
3409} 3409}
3410void CalendarView::toggleFilter() 3410void CalendarView::toggleFilter()
3411{ 3411{
3412 showFilter(! mFilterView->isVisible()); 3412 showFilter(! mFilterView->isVisible());
3413} 3413}
3414 3414
3415KOFilterView *CalendarView::filterView() 3415KOFilterView *CalendarView::filterView()
3416{ 3416{
3417 return mFilterView; 3417 return mFilterView;
3418} 3418}
3419void CalendarView::selectFilter( int fil ) 3419void CalendarView::selectFilter( int fil )
3420{ 3420{
3421 mFilterView->setSelectedFilter( fil ); 3421 mFilterView->setSelectedFilter( fil );
3422} 3422}
3423void CalendarView::showFilter(bool visible) 3423void CalendarView::showFilter(bool visible)
3424{ 3424{
3425 if (visible) mFilterView->show(); 3425 if (visible) mFilterView->show();
3426 else mFilterView->hide(); 3426 else mFilterView->hide();
3427} 3427}
3428void CalendarView::toggleFilerEnabled( ) 3428void CalendarView::toggleFilerEnabled( )
3429{ 3429{
3430 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 3430 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
3431 if ( !mFilterView->filtersEnabled() ) 3431 if ( !mFilterView->filtersEnabled() )
3432 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 3432 topLevelWidget()->setCaption( i18n("Filter disabled ") );
3433 3433
3434} 3434}
3435void CalendarView::updateFilter() 3435void CalendarView::updateFilter()
3436{ 3436{
3437 CalFilter *filter = mFilterView->selectedFilter(); 3437 CalFilter *filter = mFilterView->selectedFilter();
3438 if (filter) { 3438 if (filter) {
3439 if (mFilterView->filtersEnabled()) { 3439 if (mFilterView->filtersEnabled()) {
3440 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() ); 3440 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() );
3441 filter->setEnabled(true); 3441 filter->setEnabled(true);
3442 } 3442 }
3443 else filter->setEnabled(false); 3443 else filter->setEnabled(false);
3444 mCalendar->setFilter(filter); 3444 mCalendar->setFilter(filter);
3445 updateView(); 3445 updateView();
3446 } 3446 }
3447} 3447}
3448 3448
3449void CalendarView::filterEdited() 3449void CalendarView::filterEdited()
3450{ 3450{
3451 mFilterView->updateFilters(); 3451 mFilterView->updateFilters();
3452 updateFilter(); 3452 updateFilter();
3453 writeSettings(); 3453 writeSettings();
3454} 3454}
3455 3455
3456 3456
3457void CalendarView::takeOverEvent() 3457void CalendarView::takeOverEvent()
3458{ 3458{
3459 Incidence *incidence = currentSelection(); 3459 Incidence *incidence = currentSelection();
3460 3460
3461 if (!incidence) return; 3461 if (!incidence) return;
3462 3462
3463 incidence->setOrganizer(KOPrefs::instance()->email()); 3463 incidence->setOrganizer(KOPrefs::instance()->email());
3464 incidence->recreate(); 3464 incidence->recreate();
3465 incidence->setReadOnly(false); 3465 incidence->setReadOnly(false);
3466 3466
3467 updateView(); 3467 updateView();
3468} 3468}
3469 3469
3470void CalendarView::takeOverCalendar() 3470void CalendarView::takeOverCalendar()
3471{ 3471{
3472 // TODO: Create Calendar::allIncidences() function and use it here 3472 // TODO: Create Calendar::allIncidences() function and use it here
3473 3473
3474 QPtrList<Event> events = mCalendar->events(); 3474 QPtrList<Event> events = mCalendar->events();
3475 for(uint i=0; i<events.count(); ++i) { 3475 for(uint i=0; i<events.count(); ++i) {
3476 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 3476 events.at(i)->setOrganizer(KOPrefs::instance()->email());
3477 events.at(i)->recreate(); 3477 events.at(i)->recreate();
3478 events.at(i)->setReadOnly(false); 3478 events.at(i)->setReadOnly(false);
3479 } 3479 }
3480 3480
3481 QPtrList<Todo> todos = mCalendar->todos(); 3481 QPtrList<Todo> todos = mCalendar->todos();
3482 for(uint i=0; i<todos.count(); ++i) { 3482 for(uint i=0; i<todos.count(); ++i) {
3483 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 3483 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
3484 todos.at(i)->recreate(); 3484 todos.at(i)->recreate();
3485 todos.at(i)->setReadOnly(false); 3485 todos.at(i)->setReadOnly(false);
3486 } 3486 }
3487 3487
3488 QPtrList<Journal> journals = mCalendar->journals(); 3488 QPtrList<Journal> journals = mCalendar->journals();
3489 for(uint i=0; i<journals.count(); ++i) { 3489 for(uint i=0; i<journals.count(); ++i) {
3490 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 3490 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
3491 journals.at(i)->recreate(); 3491 journals.at(i)->recreate();
3492 journals.at(i)->setReadOnly(false); 3492 journals.at(i)->setReadOnly(false);
3493 } 3493 }
3494 3494
3495 updateView(); 3495 updateView();
3496} 3496}
3497 3497
3498void CalendarView::showIntro() 3498void CalendarView::showIntro()
3499{ 3499{
3500 kdDebug() << "To be implemented." << endl; 3500 kdDebug() << "To be implemented." << endl;
3501} 3501}
3502 3502
3503QWidgetStack *CalendarView::viewStack() 3503QWidgetStack *CalendarView::viewStack()
3504{ 3504{
3505 return mRightFrame; 3505 return mRightFrame;
3506} 3506}
3507 3507
3508QWidget *CalendarView::leftFrame() 3508QWidget *CalendarView::leftFrame()
3509{ 3509{
3510 return mLeftFrame; 3510 return mLeftFrame;
3511} 3511}
3512 3512
3513DateNavigator *CalendarView::dateNavigator() 3513DateNavigator *CalendarView::dateNavigator()
3514{ 3514{
3515 return mNavigator; 3515 return mNavigator;
3516} 3516}
3517 3517
3518KDateNavigator* CalendarView::dateNavigatorWidget() 3518KDateNavigator* CalendarView::dateNavigatorWidget()
3519{ 3519{
3520 return mDateNavigator; 3520 return mDateNavigator;
3521} 3521}
3522void CalendarView::toggleDateNavigatorWidget() 3522void CalendarView::toggleDateNavigatorWidget()
3523{ 3523{
3524 if (mDateNavigator->isVisible()) 3524 if (mDateNavigator->isVisible())
3525 mDateNavigator->hide(); 3525 mDateNavigator->hide();
3526 else 3526 else
3527 mDateNavigator->show(); 3527 mDateNavigator->show();
3528} 3528}
3529void CalendarView::addView(KOrg::BaseView *view) 3529void CalendarView::addView(KOrg::BaseView *view)
3530{ 3530{
3531 mViewManager->addView(view); 3531 mViewManager->addView(view);
3532} 3532}
3533 3533
3534void CalendarView::showView(KOrg::BaseView *view) 3534void CalendarView::showView(KOrg::BaseView *view)
3535{ 3535{
3536 mViewManager->showView(view, mLeftFrame->isVisible()); 3536 mViewManager->showView(view, mLeftFrame->isVisible());
3537} 3537}
3538 3538
3539Incidence *CalendarView::currentSelection() 3539Incidence *CalendarView::currentSelection()
3540{ 3540{
3541 return mViewManager->currentSelection(); 3541 return mViewManager->currentSelection();
3542} 3542}
3543void CalendarView::toggleAllDaySize() 3543void CalendarView::toggleAllDaySize()
3544{ 3544{
3545 /* 3545 /*
3546 if ( KOPrefs::instance()->mAllDaySize > 47 ) 3546 if ( KOPrefs::instance()->mAllDaySize > 47 )
3547 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 3547 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
3548 else 3548 else
3549 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 3549 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
3550 */ 3550 */
3551 viewManager()->agendaView()->toggleAllDay(); 3551 viewManager()->agendaView()->toggleAllDay();
3552} 3552}
3553void CalendarView::toggleExpand() 3553void CalendarView::toggleExpand()
3554{ 3554{
3555 // if ( mLeftFrame->isHidden() ) { 3555 // if ( mLeftFrame->isHidden() ) {
3556 // mLeftFrame->show(); 3556 // mLeftFrame->show();
3557 // emit calendarViewExpanded( false ); 3557 // emit calendarViewExpanded( false );
3558 // } else { 3558 // } else {
3559 // mLeftFrame->hide(); 3559 // mLeftFrame->hide();
3560 // emit calendarViewExpanded( true ); 3560 // emit calendarViewExpanded( true );
3561 // } 3561 // }
3562 3562
3563 globalFlagBlockAgenda = 1; 3563 globalFlagBlockAgenda = 1;
3564 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 3564 emit calendarViewExpanded( !mLeftFrame->isHidden() );
3565 globalFlagBlockAgenda = 5; 3565 globalFlagBlockAgenda = 5;
3566 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 3566 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
3567 //mViewManager->showView( 0, true ); 3567 //mViewManager->showView( 0, true );
3568} 3568}
3569 3569
3570void CalendarView::calendarModified( bool modified, Calendar * ) 3570void CalendarView::calendarModified( bool modified, Calendar * )
3571{ 3571{
3572 setModified( modified ); 3572 setModified( modified );
3573} 3573}
3574 3574
3575Todo *CalendarView::selectedTodo() 3575Todo *CalendarView::selectedTodo()
3576{ 3576{
3577 Incidence *incidence = currentSelection(); 3577 Incidence *incidence = currentSelection();
3578 if ( incidence && incidence->type() == "Todo" ) { 3578 if ( incidence && incidence->type() == "Todo" ) {
3579 return static_cast<Todo *>( incidence ); 3579 return static_cast<Todo *>( incidence );
3580 } 3580 }
3581 3581
3582 incidence = mTodoList->selectedIncidences().first(); 3582 incidence = mTodoList->selectedIncidences().first();
3583 if ( incidence && incidence->type() == "Todo" ) { 3583 if ( incidence && incidence->type() == "Todo" ) {
3584 return static_cast<Todo *>( incidence ); 3584 return static_cast<Todo *>( incidence );
3585 } 3585 }
3586 3586
3587 return 0; 3587 return 0;
3588} 3588}
3589 3589
3590void CalendarView::dialogClosing(Incidence *in) 3590void CalendarView::dialogClosing(Incidence *in)
3591{ 3591{
3592 // mDialogList.remove(in); 3592 // mDialogList.remove(in);
3593} 3593}
3594 3594
3595void CalendarView::showIncidence() 3595void CalendarView::showIncidence()
3596{ 3596{
3597 Incidence *incidence = currentSelection(); 3597 Incidence *incidence = currentSelection();
3598 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3598 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3599 if ( incidence ) { 3599 if ( incidence ) {
3600 ShowIncidenceVisitor v; 3600 ShowIncidenceVisitor v;
3601 v.act( incidence, this ); 3601 v.act( incidence, this );
3602 } 3602 }
3603} 3603}
3604void CalendarView::editIncidenceDescription() 3604void CalendarView::editIncidenceDescription()
3605{ 3605{
3606 mFlagEditDescription = true; 3606 mFlagEditDescription = true;
3607 editIncidence(); 3607 editIncidence();
3608 mFlagEditDescription = false; 3608 mFlagEditDescription = false;
3609} 3609}
3610void CalendarView::editIncidence() 3610void CalendarView::editIncidence()
3611{ 3611{
3612 // qDebug("editIncidence() "); 3612 // qDebug("editIncidence() ");
3613 Incidence *incidence = currentSelection(); 3613 Incidence *incidence = currentSelection();
3614 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3614 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3615 if ( incidence ) { 3615 if ( incidence ) {
3616 EditIncidenceVisitor v; 3616 EditIncidenceVisitor v;
3617 v.act( incidence, this ); 3617 v.act( incidence, this );
3618 } 3618 }
3619} 3619}
3620 3620
3621void CalendarView::deleteIncidence() 3621void CalendarView::deleteIncidence()
3622{ 3622{
3623 Incidence *incidence = currentSelection(); 3623 Incidence *incidence = currentSelection();
3624 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3624 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3625 if ( incidence ) { 3625 if ( incidence ) {
3626 deleteIncidence(incidence); 3626 deleteIncidence(incidence);
3627 } 3627 }
3628} 3628}
3629 3629
3630void CalendarView::showIncidence(Incidence *incidence) 3630void CalendarView::showIncidence(Incidence *incidence)
3631{ 3631{
3632 if ( incidence ) { 3632 if ( incidence ) {
3633 ShowIncidenceVisitor v; 3633 ShowIncidenceVisitor v;
3634 v.act( incidence, this ); 3634 v.act( incidence, this );
3635 } 3635 }
3636} 3636}
3637 3637
3638void CalendarView::editIncidence(Incidence *incidence) 3638void CalendarView::editIncidence(Incidence *incidence)
3639{ 3639{
3640 if ( incidence ) { 3640 if ( incidence ) {
3641 3641
3642 EditIncidenceVisitor v; 3642 EditIncidenceVisitor v;
3643 v.act( incidence, this ); 3643 v.act( incidence, this );
3644 3644
3645 } 3645 }
3646} 3646}
3647 3647
3648void CalendarView::deleteIncidence(Incidence *incidence) 3648void CalendarView::deleteIncidence(Incidence *incidence)
3649{ 3649{
3650 //qDebug(" CalendarView::deleteIncidence "); 3650 //qDebug(" CalendarView::deleteIncidence ");
3651 if ( incidence ) { 3651 if ( incidence ) {
3652 DeleteIncidenceVisitor v; 3652 DeleteIncidenceVisitor v;
3653 v.act( incidence, this ); 3653 v.act( incidence, this );
3654 } 3654 }
3655} 3655}
3656 3656
3657 3657
3658void CalendarView::lookForOutgoingMessages() 3658void CalendarView::lookForOutgoingMessages()
3659{ 3659{
3660 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 3660 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
3661 ogd->loadMessages(); 3661 ogd->loadMessages();
3662} 3662}
3663 3663
3664void CalendarView::lookForIncomingMessages() 3664void CalendarView::lookForIncomingMessages()
3665{ 3665{
3666 IncomingDialog *icd = mDialogManager->incomingDialog(); 3666 IncomingDialog *icd = mDialogManager->incomingDialog();
3667 icd->retrieve(); 3667 icd->retrieve();
3668} 3668}
3669 3669
3670bool CalendarView::removeCompletedSubTodos( Todo* t ) 3670bool CalendarView::removeCompletedSubTodos( Todo* t )
3671{ 3671{
3672 bool deleteTodo = true; 3672 bool deleteTodo = true;
3673 QPtrList<Incidence> subTodos; 3673 QPtrList<Incidence> subTodos;
3674 Incidence *aTodo; 3674 Incidence *aTodo;
3675 subTodos = t->relations(); 3675 subTodos = t->relations();
3676 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 3676 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
3677 if (! removeCompletedSubTodos( (Todo*) aTodo )) 3677 if (! removeCompletedSubTodos( (Todo*) aTodo ))
3678 deleteTodo = false; 3678 deleteTodo = false;
3679 } 3679 }
3680 if ( deleteTodo ) { 3680 if ( deleteTodo ) {
3681 if ( t->isCompleted() ) { 3681 if ( t->isCompleted() ) {
3682 checkExternalId( t ); 3682 checkExternalId( t );
3683 mCalendar->deleteTodo( t ); 3683 mCalendar->deleteTodo( t );
3684 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 3684 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
3685 } 3685 }
3686 else 3686 else
3687 deleteTodo = false; 3687 deleteTodo = false;
3688 } 3688 }
3689 return deleteTodo; 3689 return deleteTodo;
3690 3690
3691} 3691}
3692void CalendarView::purgeCompleted() 3692void CalendarView::purgeCompleted()
3693{ 3693{
3694 int result = KMessageBox::warningContinueCancel(this, 3694 int result = KMessageBox::warningContinueCancel(this,
3695 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge")); 3695 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge"));
3696 3696
3697 if (result == KMessageBox::Continue) { 3697 if (result == KMessageBox::Continue) {
3698 3698
3699 QPtrList<Todo> todoCal; 3699 QPtrList<Todo> todoCal;
3700 QPtrList<Todo> rootTodos; 3700 QPtrList<Todo> rootTodos;
3701 //QPtrList<Incidence> rel; 3701 //QPtrList<Incidence> rel;
3702 Todo *aTodo;//, *rTodo; 3702 Todo *aTodo;//, *rTodo;
3703 Incidence *rIncidence; 3703 Incidence *rIncidence;
3704 bool childDelete = false; 3704 bool childDelete = false;
3705 bool deletedOne = true; 3705 bool deletedOne = true;
3706 todoCal = calendar()->todos(); 3706 todoCal = calendar()->todos();
3707 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 3707 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
3708 if ( !aTodo->relatedTo() ) 3708 if ( !aTodo->relatedTo() )
3709 rootTodos.append( aTodo ); 3709 rootTodos.append( aTodo );
3710 } 3710 }
3711 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 3711 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
3712 removeCompletedSubTodos( aTodo ); 3712 removeCompletedSubTodos( aTodo );
3713 } 3713 }
3714 3714
3715 updateView(); 3715 updateView();
3716 } 3716 }
3717} 3717}
3718 3718
3719void CalendarView::slotCalendarChanged() 3719void CalendarView::slotCalendarChanged()
3720{ 3720{
3721 ; 3721 ;
3722} 3722}
3723 3723
3724NavigatorBar *CalendarView::navigatorBar() 3724NavigatorBar *CalendarView::navigatorBar()
3725{ 3725{
3726 return mNavigatorBar; 3726 return mNavigatorBar;
3727} 3727}
3728 3728
3729 3729
3730 3730
3731void CalendarView::keyPressEvent ( QKeyEvent *e) 3731void CalendarView::keyPressEvent ( QKeyEvent *e)
3732{ 3732{
3733 //qDebug(" alendarView::keyPressEvent "); 3733 //qDebug(" alendarView::keyPressEvent ");
3734 e->ignore(); 3734 e->ignore();
3735} 3735}
3736 3736
3737 3737
3738bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) 3738bool CalendarView::sync(KSyncManager* manager, QString filename, int mode)
3739{ 3739{
3740 // mSyncManager = manager; 3740 // mSyncManager = manager;
3741 mSyncKDE = false; 3741 mSyncKDE = false;
3742 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { 3742 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) {
3743 qDebug("SyncKDE request detected!"); 3743 qDebug("SyncKDE request detected!");
3744 mSyncKDE = true; 3744 mSyncKDE = true;
3745 } 3745 }
3746 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 3746 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3747 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 3747 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3748 return syncCalendar( filename, mode ); 3748 return syncCalendar( filename, mode );
3749} 3749}
3750bool CalendarView::syncExternal(KSyncManager* manager, QString resource) 3750bool CalendarView::syncExternal(KSyncManager* manager, QString resource)
3751{ 3751{
3752 mSyncKDE = false; 3752 mSyncKDE = false;
3753 //mSyncManager = manager; 3753 //mSyncManager = manager;
3754 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 3754 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3755 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 3755 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3756 if ( resource == "sharp" ) 3756 if ( resource == "sharp" )
3757 syncExternal( 0 ); 3757 syncExternal( 0 );
3758 if ( resource == "phone" ) 3758 if ( resource == "phone" )
3759 syncExternal( 1 ); 3759 syncExternal( 1 );
3760 // pending setmodified 3760 // pending setmodified
3761 return true; 3761 return true;
3762} 3762}
3763void CalendarView::setSyncManager(KSyncManager* manager) 3763void CalendarView::setSyncManager(KSyncManager* manager)
3764{ 3764{
3765 mSyncManager = manager; 3765 mSyncManager = manager;
3766} 3766}
3767
3768void CalendarView::removeSyncInfo( QString syncProfile)
3769{
3770 qDebug("removeSyncInfo for profile %s ", syncProfile.latin1());
3771
3772}
diff --git a/korganizer/calendarview.h b/korganizer/calendarview.h
index 2818ee9..acc20d6 100644
--- a/korganizer/calendarview.h
+++ b/korganizer/calendarview.h
@@ -1,605 +1,606 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000, 2001 3 Copyright (c) 2000, 2001
4 Cornelius Schumacher <schumacher@kde.org> 4 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution. 22 without including the source code for Qt in the source distribution.
23*/ 23*/
24#ifndef CALENDARVIEW_H 24#ifndef CALENDARVIEW_H
25#define CALENDARVIEW_H 25#define CALENDARVIEW_H
26 26
27#include <qframe.h> 27#include <qframe.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#include <qwidget.h> 29#include <qwidget.h>
30#include <qptrlist.h> 30#include <qptrlist.h>
31#include <qvbox.h> 31#include <qvbox.h>
32#include <qmap.h> 32#include <qmap.h>
33#ifndef DESKTOP_VERSION 33#ifndef DESKTOP_VERSION
34#include <qtopia/ir.h> 34#include <qtopia/ir.h>
35#else 35#else
36#define Ir char 36#define Ir char
37#endif 37#endif
38#include <libkcal/calendar.h> 38#include <libkcal/calendar.h>
39#include <libkcal/scheduler.h> 39#include <libkcal/scheduler.h>
40#include <libkcal/calendarresources.h> 40#include <libkcal/calendarresources.h>
41#include <libkcal/resourcecalendar.h> 41#include <libkcal/resourcecalendar.h>
42 42
43#include <korganizer/calendarviewbase.h> 43#include <korganizer/calendarviewbase.h>
44 44
45#include <ksyncmanager.h> 45#include <ksyncmanager.h>
46 46
47class QWidgetStack; 47class QWidgetStack;
48class QSplitter; 48class QSplitter;
49 49
50class CalPrinter; 50class CalPrinter;
51class KOFilterView; 51class KOFilterView;
52class KOViewManager; 52class KOViewManager;
53class KODialogManager; 53class KODialogManager;
54class KOTodoView; 54class KOTodoView;
55class KDateNavigator; 55class KDateNavigator;
56class DateNavigator; 56class DateNavigator;
57class KOIncidenceEditor; 57class KOIncidenceEditor;
58class KDatePicker; 58class KDatePicker;
59class ResourceView; 59class ResourceView;
60class NavigatorBar; 60class NavigatorBar;
61class KOEventEditor; 61class KOEventEditor;
62class KOTodoEditor ; 62class KOTodoEditor ;
63class KOEventViewerDialog; 63class KOEventViewerDialog;
64class KOBeamPrefs; 64class KOBeamPrefs;
65class KSyncProfile; 65class KSyncProfile;
66class AlarmDialog; 66class AlarmDialog;
67class KCal::Attendee; 67class KCal::Attendee;
68 68
69namespace KCal { class FileStorage; } 69namespace KCal { class FileStorage; }
70 70
71using namespace KCal; 71using namespace KCal;
72 72
73/** 73/**
74 This is the main calendar widget. It provides the different vies on t he 74 This is the main calendar widget. It provides the different vies on t he
75 calendar data as well as the date navigator. It also handles synchronisation 75 calendar data as well as the date navigator. It also handles synchronisation
76 of the different views and controls the different dialogs like preferences, 76 of the different views and controls the different dialogs like preferences,
77 event editor, search dialog etc. 77 event editor, search dialog etc.
78 78
79 @short main calendar view widget 79 @short main calendar view widget
80 @author Cornelius Schumacher 80 @author Cornelius Schumacher
81*/ 81*/
82class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Observer, public KSyncInterface 82class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Observer, public KSyncInterface
83{ 83{
84 Q_OBJECT 84 Q_OBJECT
85 public: 85 public:
86 /** 86 /**
87 Constructs a new calendar view widget. 87 Constructs a new calendar view widget.
88 88
89 @param calendar calendar document 89 @param calendar calendar document
90 @param parent parent window 90 @param parent parent window
91 @param name Qt internal widget object name 91 @param name Qt internal widget object name
92 */ 92 */
93 CalendarView( CalendarResources *calendar, QWidget *parent = 0, 93 CalendarView( CalendarResources *calendar, QWidget *parent = 0,
94 const char *name = 0 ); 94 const char *name = 0 );
95 CalendarView( Calendar *calendar, QWidget *parent = 0, 95 CalendarView( Calendar *calendar, QWidget *parent = 0,
96 const char *name = 0 ); 96 const char *name = 0 );
97 virtual ~CalendarView(); 97 virtual ~CalendarView();
98 98
99 Calendar *calendar() { return mCalendar; } 99 Calendar *calendar() { return mCalendar; }
100 100
101 KOViewManager *viewManager(); 101 KOViewManager *viewManager();
102 KODialogManager *dialogManager(); 102 KODialogManager *dialogManager();
103 103
104 QDate startDate(); 104 QDate startDate();
105 QDate endDate(); 105 QDate endDate();
106 106
107 QWidgetStack *viewStack(); 107 QWidgetStack *viewStack();
108 QWidget *leftFrame(); 108 QWidget *leftFrame();
109 NavigatorBar *navigatorBar(); 109 NavigatorBar *navigatorBar();
110 110
111 DateNavigator *dateNavigator(); 111 DateNavigator *dateNavigator();
112 KDateNavigator *dateNavigatorWidget(); 112 KDateNavigator *dateNavigatorWidget();
113 113
114 void addView(KOrg::BaseView *); 114 void addView(KOrg::BaseView *);
115 void showView(KOrg::BaseView *); 115 void showView(KOrg::BaseView *);
116 KOEventViewerDialog* getEventViewerDialog(); 116 KOEventViewerDialog* getEventViewerDialog();
117 Incidence *currentSelection(); 117 Incidence *currentSelection();
118 118
119 signals: 119 signals:
120 void tempDisableBR(bool); 120 void tempDisableBR(bool);
121 /** This todo has been modified */ 121 /** This todo has been modified */
122 void todoModified(Todo *, int); 122 void todoModified(Todo *, int);
123 123
124 /** when change is made to options dialog, the topwidget will catch this 124 /** when change is made to options dialog, the topwidget will catch this
125 * and emit this signal which notifies all widgets which have registered 125 * and emit this signal which notifies all widgets which have registered
126 * for notification to update their settings. */ 126 * for notification to update their settings. */
127 void configChanged(); 127 void configChanged();
128 /** emitted when the topwidget is closing down, so that any attached 128 /** emitted when the topwidget is closing down, so that any attached
129 child windows can also close. */ 129 child windows can also close. */
130 void closingDown(); 130 void closingDown();
131 /** emitted right before we die */ 131 /** emitted right before we die */
132 void closed(QWidget *); 132 void closed(QWidget *);
133 133
134 /** Emitted when state of modified flag changes */ 134 /** Emitted when state of modified flag changes */
135 void modifiedChanged(bool); 135 void modifiedChanged(bool);
136 void signalmodified(); 136 void signalmodified();
137 137
138 /** Emitted when state of read-only flag changes */ 138 /** Emitted when state of read-only flag changes */
139 void readOnlyChanged(bool); 139 void readOnlyChanged(bool);
140 140
141 /** Emitted when the unit of navigation changes */ 141 /** Emitted when the unit of navigation changes */
142 void changeNavStringPrev(const QString &); 142 void changeNavStringPrev(const QString &);
143 void changeNavStringNext(const QString &); 143 void changeNavStringNext(const QString &);
144 144
145 /** Emitted when state of events selection has changed and user is organizer*/ 145 /** Emitted when state of events selection has changed and user is organizer*/
146 void organizerEventsSelected(bool); 146 void organizerEventsSelected(bool);
147 /** Emitted when state of events selection has changed and user is attendee*/ 147 /** Emitted when state of events selection has changed and user is attendee*/
148 void groupEventsSelected(bool); 148 void groupEventsSelected(bool);
149 /** 149 /**
150 Emitted when an incidence gets selected. If the selection is cleared the 150 Emitted when an incidence gets selected. If the selection is cleared the
151 signal is emitted with 0 as argument. 151 signal is emitted with 0 as argument.
152 */ 152 */
153 void incidenceSelected( Incidence * ); 153 void incidenceSelected( Incidence * );
154 /** Emitted, when a todoitem is selected or deselected. */ 154 /** Emitted, when a todoitem is selected or deselected. */
155 void todoSelected( bool ); 155 void todoSelected( bool );
156 156
157 /** 157 /**
158 Emitted, when clipboard content changes. Parameter indicates if paste 158 Emitted, when clipboard content changes. Parameter indicates if paste
159 is possible or not. 159 is possible or not.
160 */ 160 */
161 void pasteEnabled(bool); 161 void pasteEnabled(bool);
162 162
163 /** Emitted, when the number of incoming messages has changed. */ 163 /** Emitted, when the number of incoming messages has changed. */
164 void numIncomingChanged(int); 164 void numIncomingChanged(int);
165 165
166 /** Emitted, when the number of outgoing messages has changed. */ 166 /** Emitted, when the number of outgoing messages has changed. */
167 void numOutgoingChanged(int); 167 void numOutgoingChanged(int);
168 168
169 /** Send status message, which can e.g. be displayed in the status bar. */ 169 /** Send status message, which can e.g. be displayed in the status bar. */
170 void statusMessage(const QString &); 170 void statusMessage(const QString &);
171 171
172 void calendarViewExpanded( bool ); 172 void calendarViewExpanded( bool );
173 void updateSearchDialog(); 173 void updateSearchDialog();
174 174
175 175
176 public slots: 176 public slots:
177 void showOpenError(); 177 void showOpenError();
178 void watchSavedFile(); 178 void watchSavedFile();
179 void recheckTimerAlarm(); 179 void recheckTimerAlarm();
180 void checkNextTimerAlarm(); 180 void checkNextTimerAlarm();
181 void addAlarm(const QDateTime &qdt, const QString &noti ); 181 void addAlarm(const QDateTime &qdt, const QString &noti );
182 void addSuspendAlarm(const QDateTime &qdt, const QString &noti ); 182 void addSuspendAlarm(const QDateTime &qdt, const QString &noti );
183 void removeAlarm(const QDateTime &qdt, const QString &noti ); 183 void removeAlarm(const QDateTime &qdt, const QString &noti );
184 184
185 /** options dialog made a changed to the configuration. we catch this 185 /** options dialog made a changed to the configuration. we catch this
186 * and notify all widgets which need to update their configuration. */ 186 * and notify all widgets which need to update their configuration. */
187 void updateConfig(); 187 void updateConfig();
188 188
189 void insertBirthdays(const QString& uid, const QStringList& birthdayList, 189 void insertBirthdays(const QString& uid, const QStringList& birthdayList,
190 const QStringList& anniversaryList, const QStringList& realNameList, 190 const QStringList& anniversaryList, const QStringList& realNameList,
191 const QStringList& emailList, const QStringList& assembledNameList, 191 const QStringList& emailList, const QStringList& assembledNameList,
192 const QStringList& uidList); 192 const QStringList& uidList);
193 193
194 /** 194 /**
195 Load calendar from file \a filename. If \a merge is true, load 195 Load calendar from file \a filename. If \a merge is true, load
196 calendar into existing one, if it is false, clear calendar, before 196 calendar into existing one, if it is false, clear calendar, before
197 loading. Return true, if calendar could be successfully loaded. 197 loading. Return true, if calendar could be successfully loaded.
198 */ 198 */
199 bool openCalendar(QString filename, bool merge=false); 199 bool openCalendar(QString filename, bool merge=false);
200 bool syncCalendar(QString filename,int mode = 0 ); 200 bool syncCalendar(QString filename,int mode = 0 );
201 201
202 /** 202 /**
203 Save calendar data to file. Return true if calendar could be 203 Save calendar data to file. Return true if calendar could be
204 successfully saved. 204 successfully saved.
205 */ 205 */
206 bool saveCalendar(QString filename); 206 bool saveCalendar(QString filename);
207 207
208 /** 208 /**
209 Close calendar. Clear calendar data and reset views to display an empty 209 Close calendar. Clear calendar data and reset views to display an empty
210 calendar. 210 calendar.
211 */ 211 */
212 void closeCalendar(); 212 void closeCalendar();
213 213
214 /** Archive old events of calendar */ 214 /** Archive old events of calendar */
215 void archiveCalendar(); 215 void archiveCalendar();
216 216
217 void showIncidence(); 217 void showIncidence();
218 void editIncidence(); 218 void editIncidence();
219 void editIncidenceDescription(); 219 void editIncidenceDescription();
220 void deleteIncidence(); 220 void deleteIncidence();
221 void cloneIncidence(); 221 void cloneIncidence();
222 void moveIncidence(); 222 void moveIncidence();
223 void beamIncidence(); 223 void beamIncidence();
224 void toggleCancelIncidence(); 224 void toggleCancelIncidence();
225 225
226 /** create an editeventwin with supplied date/time, and if bool is true, 226 /** create an editeventwin with supplied date/time, and if bool is true,
227 * make the event take all day. */ 227 * make the event take all day. */
228 void newEvent(QDateTime, QDateTime, bool allDay = false); 228 void newEvent(QDateTime, QDateTime, bool allDay = false);
229 void newEvent(QDateTime fh); 229 void newEvent(QDateTime fh);
230 void newEvent(QDate dt); 230 void newEvent(QDate dt);
231 /** create new event without having a date hint. Takes current date as 231 /** create new event without having a date hint. Takes current date as
232 default hint. */ 232 default hint. */
233 void newEvent(); 233 void newEvent();
234 void newFloatingEvent(); 234 void newFloatingEvent();
235 235
236 /** Create a read-only viewer dialog for the supplied incidence. It calls the correct showXXX method*/ 236 /** Create a read-only viewer dialog for the supplied incidence. It calls the correct showXXX method*/
237 void showIncidence(Incidence *); 237 void showIncidence(Incidence *);
238 /** Create an editor for the supplied incidence. It calls the correct editXXX method*/ 238 /** Create an editor for the supplied incidence. It calls the correct editXXX method*/
239 void editIncidence(Incidence *); 239 void editIncidence(Incidence *);
240 /** Delete the supplied incidence. It calls the correct deleteXXX method*/ 240 /** Delete the supplied incidence. It calls the correct deleteXXX method*/
241 void deleteIncidence(Incidence *); 241 void deleteIncidence(Incidence *);
242 void cloneIncidence(Incidence *); 242 void cloneIncidence(Incidence *);
243 void cancelIncidence(Incidence *); 243 void cancelIncidence(Incidence *);
244 /** Create an editor for the supplied event. */ 244 /** Create an editor for the supplied event. */
245 void editEvent(Event *); 245 void editEvent(Event *);
246 /** Delete the supplied event. */ 246 /** Delete the supplied event. */
247 void deleteEvent(Event *); 247 void deleteEvent(Event *);
248 /** Delete the event with the given unique ID. Returns false, if event wasn't 248 /** Delete the event with the given unique ID. Returns false, if event wasn't
249 found. */ 249 found. */
250 bool deleteEvent(const QString &uid); 250 bool deleteEvent(const QString &uid);
251 /** Create a read-only viewer dialog for the supplied event. */ 251 /** Create a read-only viewer dialog for the supplied event. */
252 void showEvent(Event *); 252 void showEvent(Event *);
253 253
254 void editJournal(Journal *); 254 void editJournal(Journal *);
255 void showJournal(Journal *); 255 void showJournal(Journal *);
256 void deleteJournal(Journal *); 256 void deleteJournal(Journal *);
257 /** Create an editor dialog for a todo */ 257 /** Create an editor dialog for a todo */
258 void editTodo(Todo *); 258 void editTodo(Todo *);
259 /** Create a read-only viewer dialog for the supplied todo */ 259 /** Create a read-only viewer dialog for the supplied todo */
260 void showTodo(Todo *); 260 void showTodo(Todo *);
261 /** create new todo */ 261 /** create new todo */
262 void newTodo(); 262 void newTodo();
263 /** create new todo with a parent todo */ 263 /** create new todo with a parent todo */
264 void newSubTodo(); 264 void newSubTodo();
265 /** create new todo with a parent todo */ 265 /** create new todo with a parent todo */
266 void newSubTodo(Todo *); 266 void newSubTodo(Todo *);
267 /** Delete todo */ 267 /** Delete todo */
268 void deleteTodo(Todo *); 268 void deleteTodo(Todo *);
269 269
270 270
271 /** Check if clipboard contains vCalendar event. The signal pasteEnabled() is 271 /** Check if clipboard contains vCalendar event. The signal pasteEnabled() is
272 * emitted as result. */ 272 * emitted as result. */
273 void checkClipboard(); 273 void checkClipboard();
274 274
275 /** using the KConfig associated with the kapp variable, read in the 275 /** using the KConfig associated with the kapp variable, read in the
276 * settings from the config file. 276 * settings from the config file.
277 */ 277 */
278 void readSettings(); 278 void readSettings();
279 279
280 /** write current state to config file. */ 280 /** write current state to config file. */
281 void writeSettings(); 281 void writeSettings();
282 282
283 /** read settings for calendar filters */ 283 /** read settings for calendar filters */
284 void readFilterSettings(KConfig *config); 284 void readFilterSettings(KConfig *config);
285 285
286 /** write settings for calendar filters */ 286 /** write settings for calendar filters */
287 void writeFilterSettings(KConfig *config); 287 void writeFilterSettings(KConfig *config);
288 288
289 /** passes on the message that an event has changed to the currently 289 /** passes on the message that an event has changed to the currently
290 * activated view so that it can make appropriate display changes. */ 290 * activated view so that it can make appropriate display changes. */
291 void changeEventDisplay(Event *, int); 291 void changeEventDisplay(Event *, int);
292 void changeIncidenceDisplay(Incidence *, int); 292 void changeIncidenceDisplay(Incidence *, int);
293 void changeTodoDisplay(Todo *, int); 293 void changeTodoDisplay(Todo *, int);
294 294
295 void eventAdded(Event *); 295 void eventAdded(Event *);
296 void eventChanged(Event *); 296 void eventChanged(Event *);
297 void eventToBeDeleted(Event *); 297 void eventToBeDeleted(Event *);
298 void eventDeleted(); 298 void eventDeleted();
299 299
300 void todoAdded(Todo *); 300 void todoAdded(Todo *);
301 void todoChanged(Todo *); 301 void todoChanged(Todo *);
302 void todoToBeDeleted(Todo *); 302 void todoToBeDeleted(Todo *);
303 void todoDeleted(); 303 void todoDeleted();
304 304
305 void updateView(const QDate &start, const QDate &end); 305 void updateView(const QDate &start, const QDate &end);
306 void updateView(); 306 void updateView();
307 307
308 /** Full update of visible todo views */ 308 /** Full update of visible todo views */
309 void updateTodoViews(); 309 void updateTodoViews();
310 310
311 void updateUnmanagedViews(); 311 void updateUnmanagedViews();
312 312
313 /** cut the current appointment to the clipboard */ 313 /** cut the current appointment to the clipboard */
314 void edit_cut(); 314 void edit_cut();
315 315
316 /** copy the current appointment(s) to the clipboard */ 316 /** copy the current appointment(s) to the clipboard */
317 void edit_copy(); 317 void edit_copy();
318 318
319 /** paste the current vobject(s) in the clipboard buffer into calendar */ 319 /** paste the current vobject(s) in the clipboard buffer into calendar */
320 void edit_paste(); 320 void edit_paste();
321 321
322 /** edit viewing and configuration options. */ 322 /** edit viewing and configuration options. */
323 void edit_options(); 323 void edit_options();
324 /** 324 /**
325 Functions for printing, previewing a print, and setting up printing 325 Functions for printing, previewing a print, and setting up printing
326 parameters. 326 parameters.
327 */ 327 */
328 void print(); 328 void print();
329 void printSetup(); 329 void printSetup();
330 void printPreview(); 330 void printPreview();
331 331
332 /** Export as iCalendar file */ 332 /** Export as iCalendar file */
333 void exportICalendar(); 333 void exportICalendar();
334 334
335 /** Export as vCalendar file */ 335 /** Export as vCalendar file */
336 bool exportVCalendar( QString fn); 336 bool exportVCalendar( QString fn);
337 337
338 /** pop up a dialog to show an existing appointment. */ 338 /** pop up a dialog to show an existing appointment. */
339 void appointment_show(); 339 void appointment_show();
340 /** 340 /**
341 * pop up an Appointment Dialog to edit an existing appointment.Get 341 * pop up an Appointment Dialog to edit an existing appointment.Get
342 * information on the appointment from the list of unique IDs that is 342 * information on the appointment from the list of unique IDs that is
343 * currently in the View, called currIds. 343 * currently in the View, called currIds.
344 */ 344 */
345 void appointment_edit(); 345 void appointment_edit();
346 /** 346 /**
347 * pop up dialog confirming deletion of currently selected event in the 347 * pop up dialog confirming deletion of currently selected event in the
348 * View. 348 * View.
349 */ 349 */
350 void appointment_delete(); 350 void appointment_delete();
351 351
352 /** mails the currently selected event to a particular user as a vCalendar 352 /** mails the currently selected event to a particular user as a vCalendar
353 attachment. */ 353 attachment. */
354 void action_mail(); 354 void action_mail();
355 355
356 /* frees a subtodo from it's relation */ 356 /* frees a subtodo from it's relation */
357 void todo_unsub( Todo * ); 357 void todo_unsub( Todo * );
358 void todo_resub( Todo * parent, Todo * sub ); 358 void todo_resub( Todo * parent, Todo * sub );
359 359
360 /** Take ownership of selected event. */ 360 /** Take ownership of selected event. */
361 void takeOverEvent(); 361 void takeOverEvent();
362 362
363 /** Take ownership of all events in calendar. */ 363 /** Take ownership of all events in calendar. */
364 void takeOverCalendar(); 364 void takeOverCalendar();
365 365
366 /** query whether or not the calendar is "dirty". */ 366 /** query whether or not the calendar is "dirty". */
367 bool isModified(); 367 bool isModified();
368 /** set the state of calendar. Modified means "dirty", i.e. needing a save. */ 368 /** set the state of calendar. Modified means "dirty", i.e. needing a save. */
369 void setModified(bool modified=true); 369 void setModified(bool modified=true);
370 370
371 /** query if the calendar is read-only. */ 371 /** query if the calendar is read-only. */
372 bool isReadOnly(); 372 bool isReadOnly();
373 /** set state of calendar to read-only */ 373 /** set state of calendar to read-only */
374 void setReadOnly(bool readOnly=true); 374 void setReadOnly(bool readOnly=true);
375 375
376 void eventUpdated(Incidence *); 376 void eventUpdated(Incidence *);
377 377
378 /* iTIP scheduling actions */ 378 /* iTIP scheduling actions */
379 void schedule_publish(Incidence *incidence = 0); 379 void schedule_publish(Incidence *incidence = 0);
380 void schedule_request(Incidence *incidence = 0); 380 void schedule_request(Incidence *incidence = 0);
381 void schedule_refresh(Incidence *incidence = 0); 381 void schedule_refresh(Incidence *incidence = 0);
382 void schedule_cancel(Incidence *incidence = 0); 382 void schedule_cancel(Incidence *incidence = 0);
383 void schedule_add(Incidence *incidence = 0); 383 void schedule_add(Incidence *incidence = 0);
384 void schedule_reply(Incidence *incidence = 0); 384 void schedule_reply(Incidence *incidence = 0);
385 void schedule_counter(Incidence *incidence = 0); 385 void schedule_counter(Incidence *incidence = 0);
386 void schedule_declinecounter(Incidence *incidence = 0); 386 void schedule_declinecounter(Incidence *incidence = 0);
387 void schedule_publish_freebusy(int daysToPublish = 30); 387 void schedule_publish_freebusy(int daysToPublish = 30);
388 388
389 void openAddressbook(); 389 void openAddressbook();
390 390
391 void editFilters(); 391 void editFilters();
392 void toggleFilerEnabled(); 392 void toggleFilerEnabled();
393 QPtrList<CalFilter> filters(); 393 QPtrList<CalFilter> filters();
394 void toggleFilter(); 394 void toggleFilter();
395 void showFilter(bool visible); 395 void showFilter(bool visible);
396 void updateFilter(); 396 void updateFilter();
397 void filterEdited(); 397 void filterEdited();
398 void selectFilter( int ); 398 void selectFilter( int );
399 KOFilterView *filterView(); 399 KOFilterView *filterView();
400 400
401 void showIntro(); 401 void showIntro();
402 402
403 /** Move the curdatepient view date to today */ 403 /** Move the curdatepient view date to today */
404 void goToday(); 404 void goToday();
405 405
406 /** Move to the next date(s) in the current view */ 406 /** Move to the next date(s) in the current view */
407 void goNext(); 407 void goNext();
408 408
409 /** Move to the previous date(s) in the current view */ 409 /** Move to the previous date(s) in the current view */
410 void goPrevious(); 410 void goPrevious();
411 /** Move to the next date(s) in the current view */ 411 /** Move to the next date(s) in the current view */
412 void goNextMonth(); 412 void goNextMonth();
413 413
414 /** Move to the previous date(s) in the current view */ 414 /** Move to the previous date(s) in the current view */
415 void goPreviousMonth(); 415 void goPreviousMonth();
416 416
417 void toggleExpand(); 417 void toggleExpand();
418 void toggleDateNavigatorWidget(); 418 void toggleDateNavigatorWidget();
419 void toggleAllDaySize(); 419 void toggleAllDaySize();
420 void dialogClosing(Incidence *); 420 void dialogClosing(Incidence *);
421 421
422 /** Look for new messages in the inbox */ 422 /** Look for new messages in the inbox */
423 void lookForIncomingMessages(); 423 void lookForIncomingMessages();
424 /** Look for new messages in the outbox */ 424 /** Look for new messages in the outbox */
425 void lookForOutgoingMessages(); 425 void lookForOutgoingMessages();
426 426
427 void processMainViewSelection( Incidence * ); 427 void processMainViewSelection( Incidence * );
428 void processTodoListSelection( Incidence * ); 428 void processTodoListSelection( Incidence * );
429 429
430 void processIncidenceSelection( Incidence * ); 430 void processIncidenceSelection( Incidence * );
431 431
432 void purgeCompleted(); 432 void purgeCompleted();
433 bool removeCompletedSubTodos( Todo* ); 433 bool removeCompletedSubTodos( Todo* );
434 void slotCalendarChanged(); 434 void slotCalendarChanged();
435 bool importBday(); 435 bool importBday();
436 bool addAnniversary( QDate data, QString name, KCal::Attendee* a , bool birthday ); 436 bool addAnniversary( QDate data, QString name, KCal::Attendee* a , bool birthday );
437 bool importQtopia( const QString &categoriesFile, 437 bool importQtopia( const QString &categoriesFile,
438 const QString &datebookFile, 438 const QString &datebookFile,
439 const QString &tasklistFile ); 439 const QString &tasklistFile );
440 void syncExternal( int mode ); 440 void syncExternal( int mode );
441 void slotSelectPickerDate( QDate ) ; 441 void slotSelectPickerDate( QDate ) ;
442 void showDatePicker( ) ; 442 void showDatePicker( ) ;
443 void moveIncidence(Incidence *) ; 443 void moveIncidence(Incidence *) ;
444 void beamIncidence(Incidence *) ; 444 void beamIncidence(Incidence *) ;
445 void beamCalendar() ; 445 void beamCalendar() ;
446 void beamFilteredCalendar() ; 446 void beamFilteredCalendar() ;
447 void beamIncidenceList(QPtrList<Incidence>) ; 447 void beamIncidenceList(QPtrList<Incidence>) ;
448 void manageCategories(); 448 void manageCategories();
449 int addCategories(); 449 int addCategories();
450 void removeCategories(); 450 void removeCategories();
451 void setSyncDevice( QString ); 451 void setSyncDevice( QString );
452 void setSyncName( QString ); 452 void setSyncName( QString );
453 protected slots: 453 protected slots:
454 void timerAlarm(); 454 void timerAlarm();
455 void suspendAlarm(); 455 void suspendAlarm();
456 void beamDone( Ir *ir ); 456 void beamDone( Ir *ir );
457 /** Select a view or adapt the current view to display the specified dates. */ 457 /** Select a view or adapt the current view to display the specified dates. */
458 void showDates( const KCal::DateList & ); 458 void showDates( const KCal::DateList & );
459 void selectWeekNum ( int ); 459 void selectWeekNum ( int );
460 460
461 public: 461 public:
462 // show a standard warning 462 // show a standard warning
463 // returns KMsgBox::yesNoCancel() 463 // returns KMsgBox::yesNoCancel()
464 int msgCalModified(); 464 int msgCalModified();
465 virtual bool sync(KSyncManager* manager, QString filename, int mode); 465 virtual bool sync(KSyncManager* manager, QString filename, int mode);
466 466
467 virtual bool syncExternal(KSyncManager* manager, QString resource); 467 virtual bool syncExternal(KSyncManager* manager, QString resource);
468 virtual void removeSyncInfo( QString syncProfile);
468 void setSyncManager(KSyncManager* manager); 469 void setSyncManager(KSyncManager* manager);
469 void setLoadedFileVersion(QDateTime); 470 void setLoadedFileVersion(QDateTime);
470 bool checkFileVersion(QString fn); 471 bool checkFileVersion(QString fn);
471 bool checkFileChanged(QString fn); 472 bool checkFileChanged(QString fn);
472 Event* getLastSyncEvent(); 473 Event* getLastSyncEvent();
473 /** Adapt navigation units correpsonding to step size of navigation of the 474 /** Adapt navigation units correpsonding to step size of navigation of the
474 * current view. 475 * current view.
475 */ 476 */
476 void adaptNavigationUnits(); 477 void adaptNavigationUnits();
477 bool synchronizeCalendar( Calendar* local, Calendar* remote, int mode ); 478 bool synchronizeCalendar( Calendar* local, Calendar* remote, int mode );
478 int takeEvent( Incidence* local, Incidence* remote, int mode, bool full = false ); 479 int takeEvent( Incidence* local, Incidence* remote, int mode, bool full = false );
479 //Attendee* getYourAttendee(Event *event); 480 //Attendee* getYourAttendee(Event *event);
480 protected: 481 protected:
481 void schedule(Scheduler::Method, Incidence *incidence = 0); 482 void schedule(Scheduler::Method, Incidence *incidence = 0);
482 483
483 // returns KMsgBox::OKCandel() 484 // returns KMsgBox::OKCandel()
484 int msgItemDelete(); 485 int msgItemDelete();
485 void showEventEditor(); 486 void showEventEditor();
486 void showTodoEditor(); 487 void showTodoEditor();
487 void writeLocale(); 488 void writeLocale();
488 Todo *selectedTodo(); 489 Todo *selectedTodo();
489 490
490 private: 491 private:
491 bool mSyncKDE; 492 bool mSyncKDE;
492 KSyncManager* mSyncManager; 493 KSyncManager* mSyncManager;
493 AlarmDialog * mAlarmDialog; 494 AlarmDialog * mAlarmDialog;
494 QString mAlarmNotification; 495 QString mAlarmNotification;
495 QString mSuspendAlarmNotification; 496 QString mSuspendAlarmNotification;
496 QTimer* mSuspendTimer; 497 QTimer* mSuspendTimer;
497 QTimer* mAlarmTimer; 498 QTimer* mAlarmTimer;
498 QTimer* mRecheckAlarmTimer; 499 QTimer* mRecheckAlarmTimer;
499 void computeAlarm( QString ); 500 void computeAlarm( QString );
500 void startAlarm( QString, QString ); 501 void startAlarm( QString, QString );
501 void setSyncEventsReadOnly(); 502 void setSyncEventsReadOnly();
502 503
503 QDateTime loadedFileVersion; 504 QDateTime loadedFileVersion;
504 void checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ); 505 void checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete );
505 void checkExternalId( Incidence * inc ); 506 void checkExternalId( Incidence * inc );
506 int mGlobalSyncMode; 507 int mGlobalSyncMode;
507 QString mCurrentSyncDevice; 508 QString mCurrentSyncDevice;
508 QString mCurrentSyncName; 509 QString mCurrentSyncName;
509 KOBeamPrefs* beamDialog; 510 KOBeamPrefs* beamDialog;
510 void init(); 511 void init();
511 int mDatePickerMode; 512 int mDatePickerMode;
512 bool mFlagEditDescription; 513 bool mFlagEditDescription;
513 QDateTime mLastCalendarSync; 514 QDateTime mLastCalendarSync;
514 void createPrinter(); 515 void createPrinter();
515 516
516 void calendarModified( bool, Calendar * ); 517 void calendarModified( bool, Calendar * );
517 518
518 CalPrinter *mCalPrinter; 519 CalPrinter *mCalPrinter;
519 520
520 QSplitter *mPanner; 521 QSplitter *mPanner;
521 QSplitter *mLeftSplitter; 522 QSplitter *mLeftSplitter;
522 QWidget *mLeftFrame; 523 QWidget *mLeftFrame;
523 QWidgetStack *mRightFrame; 524 QWidgetStack *mRightFrame;
524 525
525 KDatePicker* mDatePicker; 526 KDatePicker* mDatePicker;
526 QVBox* mDateFrame; 527 QVBox* mDateFrame;
527 NavigatorBar *mNavigatorBar; 528 NavigatorBar *mNavigatorBar;
528 529
529 KDateNavigator *mDateNavigator; // widget showing small month view. 530 KDateNavigator *mDateNavigator; // widget showing small month view.
530 531
531 KOFilterView *mFilterView; 532 KOFilterView *mFilterView;
532 533
533 ResourceView *mResourceView; 534 ResourceView *mResourceView;
534 535
535 // calendar object for this viewing instance 536 // calendar object for this viewing instance
536 Calendar *mCalendar; 537 Calendar *mCalendar;
537 538
538 CalendarResourceManager *mResourceManager; 539 CalendarResourceManager *mResourceManager;
539 540
540 FileStorage *mStorage; 541 FileStorage *mStorage;
541 542
542 DateNavigator *mNavigator; 543 DateNavigator *mNavigator;
543 544
544 KOViewManager *mViewManager; 545 KOViewManager *mViewManager;
545 KODialogManager *mDialogManager; 546 KODialogManager *mDialogManager;
546 547
547 // Calendar filters 548 // Calendar filters
548 QPtrList<CalFilter> mFilters; 549 QPtrList<CalFilter> mFilters;
549 550
550 // various housekeeping variables. 551 // various housekeeping variables.
551 bool mModified; // flag indicating if calendar is modified 552 bool mModified; // flag indicating if calendar is modified
552 bool mReadOnly; // flag indicating if calendar is read-only 553 bool mReadOnly; // flag indicating if calendar is read-only
553 QDate mSaveSingleDate; 554 QDate mSaveSingleDate;
554 555
555 Incidence *mSelectedIncidence; 556 Incidence *mSelectedIncidence;
556 Incidence *mMoveIncidence; 557 Incidence *mMoveIncidence;
557 KOTodoView *mTodoList; 558 KOTodoView *mTodoList;
558 KOEventEditor * mEventEditor; 559 KOEventEditor * mEventEditor;
559 KOTodoEditor * mTodoEditor; 560 KOTodoEditor * mTodoEditor;
560 KOEventViewerDialog * mEventViewerDialog; 561 KOEventViewerDialog * mEventViewerDialog;
561 void keyPressEvent ( QKeyEvent *e) ; 562 void keyPressEvent ( QKeyEvent *e) ;
562 //QMap<Incidence*,KOIncidenceEditor*> mDialogList; 563 //QMap<Incidence*,KOIncidenceEditor*> mDialogList;
563}; 564};
564 565
565 566
566class CalendarViewVisitor : public Incidence::Visitor 567class CalendarViewVisitor : public Incidence::Visitor
567{ 568{
568 public: 569 public:
569 CalendarViewVisitor() : mView( 0 ) {} 570 CalendarViewVisitor() : mView( 0 ) {}
570 571
571 bool act( Incidence *incidence, CalendarView *view ) 572 bool act( Incidence *incidence, CalendarView *view )
572 { 573 {
573 mView = view; 574 mView = view;
574 return incidence->accept( *this ); 575 return incidence->accept( *this );
575 } 576 }
576 577
577 protected: 578 protected:
578 CalendarView *mView; 579 CalendarView *mView;
579}; 580};
580 581
581class ShowIncidenceVisitor : public CalendarViewVisitor 582class ShowIncidenceVisitor : public CalendarViewVisitor
582{ 583{
583 protected: 584 protected:
584 bool visit( Event *event ) { mView->showEvent( event ); return true; } 585 bool visit( Event *event ) { mView->showEvent( event ); return true; }
585 bool visit( Todo *todo ) { mView->showTodo( todo ); return true; } 586 bool visit( Todo *todo ) { mView->showTodo( todo ); return true; }
586 bool visit( Journal * j ) { mView->showJournal( j );return true; } 587 bool visit( Journal * j ) { mView->showJournal( j );return true; }
587}; 588};
588 589
589class EditIncidenceVisitor : public CalendarViewVisitor 590class EditIncidenceVisitor : public CalendarViewVisitor
590{ 591{
591 protected: 592 protected:
592 bool visit( Event *event ) { mView->editEvent( event ); return true; } 593 bool visit( Event *event ) { mView->editEvent( event ); return true; }
593 bool visit( Todo *todo ) { mView->editTodo( todo ); return true; } 594 bool visit( Todo *todo ) { mView->editTodo( todo ); return true; }
594 bool visit( Journal *j ) { mView->editJournal( j); return true; } 595 bool visit( Journal *j ) { mView->editJournal( j); return true; }
595}; 596};
596 597
597class DeleteIncidenceVisitor : public CalendarViewVisitor 598class DeleteIncidenceVisitor : public CalendarViewVisitor
598{ 599{
599 protected: 600 protected:
600 bool visit( Event *event ) { mView->deleteEvent( event ); return true; } 601 bool visit( Event *event ) { mView->deleteEvent( event ); return true; }
601 bool visit( Todo *todo ) { mView->deleteTodo( todo ); return true; } 602 bool visit( Todo *todo ) { mView->deleteTodo( todo ); return true; }
602 bool visit( Journal * j) {mView->deleteJournal( j ); return true; } 603 bool visit( Journal * j) {mView->deleteJournal( j ); return true; }
603}; 604};
604 605
605#endif 606#endif
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h
index 4a610fa..af4f1ab 100644
--- a/libkdepim/ksyncmanager.h
+++ b/libkdepim/ksyncmanager.h
@@ -1,211 +1,212 @@
1/* 1/*
2 This file is part of KDE-Pim/Pi. 2 This file is part of KDE-Pim/Pi.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library 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 GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19 19
20 $Id$ 20 $Id$
21*/ 21*/
22#ifndef _KSYNCMANAGER_H 22#ifndef _KSYNCMANAGER_H
23#define _KSYNCMANAGER_H 23#define _KSYNCMANAGER_H
24 24
25#include <qobject.h> 25#include <qobject.h>
26#include <qstring.h> 26#include <qstring.h>
27#include <qsocket.h> 27#include <qsocket.h>
28#include <qdatetime.h> 28#include <qdatetime.h>
29#include <qserversocket.h> 29#include <qserversocket.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qregexp.h> 31#include <qregexp.h>
32 32
33class QPopupMenu; 33class QPopupMenu;
34class KSyncProfile; 34class KSyncProfile;
35class KPimPrefs; 35class KPimPrefs;
36class QWidget; 36class QWidget;
37class KSyncManager; 37class KSyncManager;
38class KSyncInterface; 38class KSyncInterface;
39class QProgressBar; 39class QProgressBar;
40 40
41 41
42class KServerSocket : public QServerSocket 42class KServerSocket : public QServerSocket
43{ 43{
44 Q_OBJECT 44 Q_OBJECT
45 45
46 public: 46 public:
47 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); 47 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 );
48 48
49 void newConnection ( int socket ) ; 49 void newConnection ( int socket ) ;
50 void setFileName( QString fn ) {mFileName = fn;}; 50 void setFileName( QString fn ) {mFileName = fn;};
51 signals: 51 signals:
52 void file_received( bool ); 52 void file_received( bool );
53 void request_file(); 53 void request_file();
54 void saveFile(); 54 void saveFile();
55 void endConnect(); 55 void endConnect();
56 private slots: 56 private slots:
57 void discardClient(); 57 void discardClient();
58 void readClient(); 58 void readClient();
59 void readBackFileFromSocket(); 59 void readBackFileFromSocket();
60 private : 60 private :
61 bool blockRC; 61 bool blockRC;
62 void send_file(); 62 void send_file();
63 void get_file(); 63 void get_file();
64 void end_connect(); 64 void end_connect();
65 QDialog* mSyncActionDialog; 65 QDialog* mSyncActionDialog;
66 QSocket* mSocket; 66 QSocket* mSocket;
67 QString mPassWord; 67 QString mPassWord;
68 QString mFileName; 68 QString mFileName;
69 QTime piTime; 69 QTime piTime;
70 QString piFileString; 70 QString piFileString;
71}; 71};
72 72
73class KCommandSocket : public QObject 73class KCommandSocket : public QObject
74{ 74{
75 Q_OBJECT 75 Q_OBJECT
76 public: 76 public:
77 enum state { successR, errorR, successW, errorW, errorTO, quiet }; 77 enum state { successR, errorR, successW, errorW, errorTO, quiet };
78 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); 78 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 );
79 void readFile( QString ); 79 void readFile( QString );
80 void writeFile( QString ); 80 void writeFile( QString );
81 void sendStop(); 81 void sendStop();
82 82
83 signals: 83 signals:
84 void commandFinished( KCommandSocket*, int ); 84 void commandFinished( KCommandSocket*, int );
85 private slots: 85 private slots:
86 void startReadFileFromSocket(); 86 void startReadFileFromSocket();
87 void readFileFromSocket(); 87 void readFileFromSocket();
88 void deleteSocket(); 88 void deleteSocket();
89 void writeFileToSocket(); 89 void writeFileToSocket();
90 private : 90 private :
91 QSocket* mSocket; 91 QSocket* mSocket;
92 QString mPassWord; 92 QString mPassWord;
93 Q_UINT16 mPort; 93 Q_UINT16 mPort;
94 QString mHost; 94 QString mHost;
95 QString mFileName; 95 QString mFileName;
96 QTimer* mTimerSocket; 96 QTimer* mTimerSocket;
97 int mRetVal; 97 int mRetVal;
98 QTime mTime; 98 QTime mTime;
99 QString mFileString; 99 QString mFileString;
100 bool mFirst; 100 bool mFirst;
101}; 101};
102 102
103 103
104class KSyncManager : public QObject 104class KSyncManager : public QObject
105{ 105{
106 Q_OBJECT 106 Q_OBJECT
107 107
108 public: 108 public:
109 enum TargetApp { 109 enum TargetApp {
110 KOPI = 0, 110 KOPI = 0,
111 KAPI = 1, 111 KAPI = 1,
112 PWMPI = 2 }; 112 PWMPI = 2 };
113 113
114 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); 114 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu);
115 ~KSyncManager() ; 115 ~KSyncManager() ;
116 116
117 void multiSync( bool askforPrefs ); 117 void multiSync( bool askforPrefs );
118 bool blockSave() { return mBlockSaveFlag; } 118 bool blockSave() { return mBlockSaveFlag; }
119 void setBlockSave(bool sa) { mBlockSaveFlag = sa; } 119 void setBlockSave(bool sa) { mBlockSaveFlag = sa; }
120 void setDefaultFileName( QString s) { mDefFileName = s ;} 120 void setDefaultFileName( QString s) { mDefFileName = s ;}
121 QString defaultFileName() { return mDefFileName ;} 121 QString defaultFileName() { return mDefFileName ;}
122 QString syncFileName(); 122 QString syncFileName();
123 void enableQuick( bool ask = true); 123 void enableQuick( bool ask = true);
124 124
125 QString getCurrentSyncDevice() { return mCurrentSyncDevice; } 125 QString getCurrentSyncDevice() { return mCurrentSyncDevice; }
126 QString getCurrentSyncName() { return mCurrentSyncName; } 126 QString getCurrentSyncName() { return mCurrentSyncName; }
127 127
128 void showProgressBar(int percentage, QString caption = QString::null, int total=100); 128 void showProgressBar(int percentage, QString caption = QString::null, int total=100);
129 void hideProgressBar(); 129 void hideProgressBar();
130 bool isProgressBarCanceled(); 130 bool isProgressBarCanceled();
131 131
132 // sync stuff 132 // sync stuff
133 QString mLocalMachineName; 133 QString mLocalMachineName;
134 QStringList mExternSyncProfiles; 134 QStringList mExternSyncProfiles;
135 QStringList mSyncProfileNames; 135 QStringList mSyncProfileNames;
136 bool mAskForPreferences; 136 bool mAskForPreferences;
137 bool mShowSyncSummary; 137 bool mShowSyncSummary;
138 bool mIsKapiFile; 138 bool mIsKapiFile;
139 bool mWriteBackExistingOnly; 139 bool mWriteBackExistingOnly;
140 int mSyncAlgoPrefs; 140 int mSyncAlgoPrefs;
141 bool mWriteBackFile; 141 bool mWriteBackFile;
142 int mWriteBackInFuture; 142 int mWriteBackInFuture;
143 QString mPhoneDevice; 143 QString mPhoneDevice;
144 QString mPhoneConnection; 144 QString mPhoneConnection;
145 QString mPhoneModel; 145 QString mPhoneModel;
146 QString mPassWordPiSync; 146 QString mPassWordPiSync;
147 QString mActiveSyncPort; 147 QString mActiveSyncPort;
148 QString mActiveSyncIP ; 148 QString mActiveSyncIP ;
149 149
150 signals: 150 signals:
151 void save(); 151 void save();
152 void request_file(); 152 void request_file();
153 void getFile( bool ); 153 void getFile( bool );
154 154
155 public slots: 155 public slots:
156 void slotSyncMenu( int ); 156 void slotSyncMenu( int );
157 void deleteCommandSocket(KCommandSocket*s, int state); 157 void deleteCommandSocket(KCommandSocket*s, int state);
158 void readFileFromSocket(); 158 void readFileFromSocket();
159 void fillSyncMenu(); 159 void fillSyncMenu();
160 160
161 private: 161 private:
162 void syncPi(); 162 void syncPi();
163 KServerSocket * mServerSocket; 163 KServerSocket * mServerSocket;
164 KPimPrefs* mPrefs; 164 KPimPrefs* mPrefs;
165 QString mDefFileName; 165 QString mDefFileName;
166 QString mCurrentSyncDevice; 166 QString mCurrentSyncDevice;
167 QString mCurrentSyncName; 167 QString mCurrentSyncName;
168 void quickSyncLocalFile(); 168 void quickSyncLocalFile();
169 bool syncWithFile( QString fn , bool quick ); 169 bool syncWithFile( QString fn , bool quick );
170 void syncLocalFile(); 170 void syncLocalFile();
171 void syncPhone(); 171 void syncPhone();
172 void syncSharp(); 172 void syncSharp();
173 void syncKDE(); 173 void syncKDE();
174 bool syncExternalApplication(QString); 174 bool syncExternalApplication(QString);
175 int mCurrentSyncProfile ; 175 int mCurrentSyncProfile ;
176 void syncRemote( KSyncProfile* prof, bool ask = true); 176 void syncRemote( KSyncProfile* prof, bool ask = true);
177 bool edit_sync_options(); 177 bool edit_sync_options();
178 bool edit_pisync_options(); 178 bool edit_pisync_options();
179 int ringSync(); 179 int ringSync();
180 QString getPassword( ); 180 QString getPassword( );
181 bool mPisyncFinished; 181 bool mPisyncFinished;
182 bool mBlockSaveFlag; 182 bool mBlockSaveFlag;
183 QWidget* mParent; 183 QWidget* mParent;
184 KSyncInterface* mImplementation; 184 KSyncInterface* mImplementation;
185 TargetApp mTargetApp; 185 TargetApp mTargetApp;
186 QPopupMenu* mSyncMenu; 186 QPopupMenu* mSyncMenu;
187 QProgressBar* bar; 187 QProgressBar* bar;
188 188
189private slots: 189private slots:
190 void confSync(); 190 void confSync();
191 191
192 192
193}; 193};
194 194
195 195
196class KSyncInterface 196class KSyncInterface
197{ 197{
198 public : 198 public :
199 virtual void removeSyncInfo( QString syncProfile) = 0;
199 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; 200 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0;
200 virtual bool syncExternal(KSyncManager* manager, QString resource) 201 virtual bool syncExternal(KSyncManager* manager, QString resource)
201 { 202 {
202 // empty implementation, because some syncable applications do not 203 // empty implementation, because some syncable applications do not
203 // have an external(sharpdtm) syncmode, like pwmanager. 204 // have an external(sharpdtm) syncmode, like pwmanager.
204 return false; 205 return false;
205 } 206 }
206 207
207 208
208}; 209};
209 210
210 211
211#endif 212#endif
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp
index 2b8f2fa..6ae6e28 100644
--- a/pwmanager/pwmanager/pwm.cpp
+++ b/pwmanager/pwmanager/pwm.cpp
@@ -1,1472 +1,1478 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch * 3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager 14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#include <klocale.h> 20#include <klocale.h>
21#include <klistview.h> 21#include <klistview.h>
22#include <ktoolbar.h> 22#include <ktoolbar.h>
23#include <kfiledialog.h> 23#include <kfiledialog.h>
24#include <kiconloader.h> 24#include <kiconloader.h>
25#include <kmessagebox.h> 25#include <kmessagebox.h>
26 26
27#include <qstatusbar.h> 27#include <qstatusbar.h>
28 28
29#ifndef PWM_EMBEDDED 29#ifndef PWM_EMBEDDED
30#include <kmenubar.h> 30#include <kmenubar.h>
31#include <kstatusbar.h> 31#include <kstatusbar.h>
32#include <dcopclient.h> 32#include <dcopclient.h>
33#include "configwndimpl.h" 33#include "configwndimpl.h"
34#include "configuration.h" 34#include "configuration.h"
35#else 35#else
36#include <qmenubar.h> 36#include <qmenubar.h>
37#include <qmessagebox.h> 37#include <qmessagebox.h>
38#include <pwmprefs.h> 38#include <pwmprefs.h>
39#include <kpimglobalprefs.h> 39#include <kpimglobalprefs.h>
40#include <kcmconfigs/kcmpwmconfig.h> 40#include <kcmconfigs/kcmpwmconfig.h>
41#include <kcmconfigs/kcmkdepimconfig.h> 41#include <kcmconfigs/kcmkdepimconfig.h>
42#include <kcmultidialog.h> 42#include <kcmultidialog.h>
43#endif 43#endif
44 44
45 45
46#ifndef DESKTOP_VERSION 46#ifndef DESKTOP_VERSION
47#include <qpe/global.h> 47#include <qpe/global.h>
48#endif 48#endif
49 49
50#include <qpixmap.h> 50#include <qpixmap.h>
51#include <qcheckbox.h> 51#include <qcheckbox.h>
52#include <qspinbox.h> 52#include <qspinbox.h>
53#include <qlineedit.h> 53#include <qlineedit.h>
54#include <qfileinfo.h> 54#include <qfileinfo.h>
55#include <qclipboard.h> 55#include <qclipboard.h>
56 56
57 57
58#include <stdio.h> 58#include <stdio.h>
59 59
60#include "pwm.h" 60#include "pwm.h"
61#include "pwminit.h" 61#include "pwminit.h"
62#include "pwmprint.h" 62#include "pwmprint.h"
63#include "addentrywndimpl.h" 63#include "addentrywndimpl.h"
64#include "globalstuff.h" 64#include "globalstuff.h"
65#include "findwndimpl.h" 65#include "findwndimpl.h"
66#include "csv.h" 66#include "csv.h"
67 67
68#ifdef CONFIG_KWALLETIF 68#ifdef CONFIG_KWALLETIF
69# include "kwalletif.h" 69# include "kwalletif.h"
70# include "kwalletemu.h" 70# include "kwalletemu.h"
71#endif 71#endif
72#ifdef CONFIG_KEYCARD 72#ifdef CONFIG_KEYCARD
73# include "pwmkeycard.h" 73# include "pwmkeycard.h"
74#endif 74#endif
75 75
76 76
77 #define DEFAULT_SIZE (QSize(700, 400)) 77 #define DEFAULT_SIZE (QSize(700, 400))
78 78
79// Button IDs for "file" popup menu 79// Button IDs for "file" popup menu
80enum { 80enum {
81 BUTTON_POPUP_FILE_NEW = 0, 81 BUTTON_POPUP_FILE_NEW = 0,
82 BUTTON_POPUP_FILE_OPEN, 82 BUTTON_POPUP_FILE_OPEN,
83 BUTTON_POPUP_FILE_CLOSE, 83 BUTTON_POPUP_FILE_CLOSE,
84 BUTTON_POPUP_FILE_SAVE, 84 BUTTON_POPUP_FILE_SAVE,
85 BUTTON_POPUP_FILE_SAVEAS, 85 BUTTON_POPUP_FILE_SAVEAS,
86 BUTTON_POPUP_FILE_EXPORT, 86 BUTTON_POPUP_FILE_EXPORT,
87 BUTTON_POPUP_FILE_IMPORT, 87 BUTTON_POPUP_FILE_IMPORT,
88 BUTTON_POPUP_FILE_PRINT, 88 BUTTON_POPUP_FILE_PRINT,
89 BUTTON_POPUP_FILE_QUIT 89 BUTTON_POPUP_FILE_QUIT
90}; 90};
91// Button IDs for "manage" popup menu 91// Button IDs for "manage" popup menu
92enum { 92enum {
93 BUTTON_POPUP_MANAGE_ADD = 0, 93 BUTTON_POPUP_MANAGE_ADD = 0,
94 BUTTON_POPUP_MANAGE_EDIT, 94 BUTTON_POPUP_MANAGE_EDIT,
95 BUTTON_POPUP_MANAGE_DEL, 95 BUTTON_POPUP_MANAGE_DEL,
96 BUTTON_POPUP_MANAGE_CHANGEMP 96 BUTTON_POPUP_MANAGE_CHANGEMP
97}; 97};
98// Button IDs for chipcard popup menu 98// Button IDs for chipcard popup menu
99enum { 99enum {
100#ifdef CONFIG_KEYCARD 100#ifdef CONFIG_KEYCARD
101 BUTTON_POPUP_CHIPCARD_GENNEW = 0, 101 BUTTON_POPUP_CHIPCARD_GENNEW = 0,
102 BUTTON_POPUP_CHIPCARD_DEL, 102 BUTTON_POPUP_CHIPCARD_DEL,
103 BUTTON_POPUP_CHIPCARD_READID, 103 BUTTON_POPUP_CHIPCARD_READID,
104 BUTTON_POPUP_CHIPCARD_SAVEBACKUP, 104 BUTTON_POPUP_CHIPCARD_SAVEBACKUP,
105 BUTTON_POPUP_CHIPCARD_REPLAYBACKUP 105 BUTTON_POPUP_CHIPCARD_REPLAYBACKUP
106#else // CONFIG_KEYCARD 106#else // CONFIG_KEYCARD
107 BUTTON_POPUP_CHIPCARD_NO = 0 107 BUTTON_POPUP_CHIPCARD_NO = 0
108#endif // CONFIG_KEYCARD 108#endif // CONFIG_KEYCARD
109}; 109};
110// Button IDs for "view" popup menu 110// Button IDs for "view" popup menu
111enum { 111enum {
112 BUTTON_POPUP_VIEW_FIND = 0, 112 BUTTON_POPUP_VIEW_FIND = 0,
113 BUTTON_POPUP_VIEW_LOCK, 113 BUTTON_POPUP_VIEW_LOCK,
114 BUTTON_POPUP_VIEW_DEEPLOCK, 114 BUTTON_POPUP_VIEW_DEEPLOCK,
115 BUTTON_POPUP_VIEW_UNLOCK 115 BUTTON_POPUP_VIEW_UNLOCK
116}; 116};
117// Button IDs for "options" popup menu 117// Button IDs for "options" popup menu
118enum { 118enum {
119 BUTTON_POPUP_OPTIONS_CONFIG = 0 119 BUTTON_POPUP_OPTIONS_CONFIG = 0
120}; 120};
121// Button IDs for "export" popup menu (in "file" popup menu) 121// Button IDs for "export" popup menu (in "file" popup menu)
122enum { 122enum {
123 BUTTON_POPUP_EXPORT_TEXT = 0, 123 BUTTON_POPUP_EXPORT_TEXT = 0,
124 BUTTON_POPUP_EXPORT_GPASMAN, 124 BUTTON_POPUP_EXPORT_GPASMAN,
125 BUTTON_POPUP_EXPORT_CSV 125 BUTTON_POPUP_EXPORT_CSV
126#ifdef CONFIG_KWALLETIF 126#ifdef CONFIG_KWALLETIF
127 ,BUTTON_POPUP_EXPORT_KWALLET 127 ,BUTTON_POPUP_EXPORT_KWALLET
128#endif 128#endif
129}; 129};
130// Button IDs for "import" popup menu (in "file" popup menu) 130// Button IDs for "import" popup menu (in "file" popup menu)
131enum { 131enum {
132 BUTTON_POPUP_IMPORT_TEXT = 0, 132 BUTTON_POPUP_IMPORT_TEXT = 0,
133 BUTTON_POPUP_IMPORT_GPASMAN, 133 BUTTON_POPUP_IMPORT_GPASMAN,
134 BUTTON_POPUP_IMPORT_CSV 134 BUTTON_POPUP_IMPORT_CSV
135#ifdef CONFIG_KWALLETIF 135#ifdef CONFIG_KWALLETIF
136 ,BUTTON_POPUP_IMPORT_KWALLET 136 ,BUTTON_POPUP_IMPORT_KWALLET
137#endif 137#endif
138}; 138};
139 139
140#ifdef PWM_EMBEDDED 140#ifdef PWM_EMBEDDED
141// Button IDs for "help" popup menu 141// Button IDs for "help" popup menu
142enum { 142enum {
143 BUTTON_POPUP_HELP_LICENSE = 0, 143 BUTTON_POPUP_HELP_LICENSE = 0,
144 BUTTON_POPUP_HELP_FAQ, 144 BUTTON_POPUP_HELP_FAQ,
145 BUTTON_POPUP_HELP_ABOUT, 145 BUTTON_POPUP_HELP_ABOUT,
146 BUTTON_POPUP_HELP_SYNC, 146 BUTTON_POPUP_HELP_SYNC,
147 BUTTON_POPUP_HELP_WHATSNEW 147 BUTTON_POPUP_HELP_WHATSNEW
148}; 148};
149#endif 149#endif
150 150
151// Button IDs for toolbar 151// Button IDs for toolbar
152enum { 152enum {
153 BUTTON_TOOL_NEW = 0, 153 BUTTON_TOOL_NEW = 0,
154 BUTTON_TOOL_OPEN, 154 BUTTON_TOOL_OPEN,
155 BUTTON_TOOL_SAVE, 155 BUTTON_TOOL_SAVE,
156 BUTTON_TOOL_SAVEAS, 156 BUTTON_TOOL_SAVEAS,
157 BUTTON_TOOL_PRINT, 157 BUTTON_TOOL_PRINT,
158 BUTTON_TOOL_ADD, 158 BUTTON_TOOL_ADD,
159 BUTTON_TOOL_EDIT, 159 BUTTON_TOOL_EDIT,
160 BUTTON_TOOL_DEL, 160 BUTTON_TOOL_DEL,
161 BUTTON_TOOL_FIND, 161 BUTTON_TOOL_FIND,
162 BUTTON_TOOL_LOCK, 162 BUTTON_TOOL_LOCK,
163 BUTTON_TOOL_DEEPLOCK, 163 BUTTON_TOOL_DEEPLOCK,
164 BUTTON_TOOL_UNLOCK 164 BUTTON_TOOL_UNLOCK
165}; 165};
166 166
167 167
168PwM::PwM(PwMInit *_init, PwMDoc *doc, 168PwM::PwM(PwMInit *_init, PwMDoc *doc,
169 bool virginity, 169 bool virginity,
170 QWidget *parent, const char *name) 170 QWidget *parent, const char *name)
171 : KMainWindow(parent, "HALLO") 171 : KMainWindow(parent, "HALLO")
172 , forceQuit (false) 172 , forceQuit (false)
173 , forceMinimizeToTray (false) 173 , forceMinimizeToTray (false)
174{ 174{
175 syncManager = 0; 175 syncManager = 0;
176 virgin = !virginity; 176 virgin = !virginity;
177 init = _init; 177 init = _init;
178 connect(doc, SIGNAL(docClosed(PwMDoc *)), 178 connect(doc, SIGNAL(docClosed(PwMDoc *)),
179 this, SLOT(docClosed(PwMDoc *))); 179 this, SLOT(docClosed(PwMDoc *)));
180 initMenubar(); 180 initMenubar();
181 initToolbar(); 181 initToolbar();
182 initMetrics(); 182 initMetrics();
183 setVirgin(virginity); 183 setVirgin(virginity);
184 setFocusPolicy(QWidget::WheelFocus); 184 setFocusPolicy(QWidget::WheelFocus);
185#ifndef PWM_EMBEDDED 185#ifndef PWM_EMBEDDED
186 statusBar()->show(); 186 statusBar()->show();
187#endif 187#endif
188 view = makeNewListView(doc); 188 view = makeNewListView(doc);
189 setCentralWidget(view); 189 setCentralWidget(view);
190 updateCaption(); 190 updateCaption();
191 showStatMsg(i18n("Ready.")); 191 showStatMsg(i18n("Ready."));
192} 192}
193 193
194PwM::~PwM() 194PwM::~PwM()
195{ 195{
196 qDebug("PwM::~PwM() %x", this); 196 qDebug("PwM::~PwM() %x", this);
197 disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)), 197 disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)),
198 this, SLOT(docClosed(PwMDoc *))); 198 this, SLOT(docClosed(PwMDoc *)));
199 conf()->confWndMainWndSize(size()); 199 conf()->confWndMainWndSize(size());
200 //LR closing of windows changed 200 //LR closing of windows changed
201 //needed for fastload option on PDA 201 //needed for fastload option on PDA
202 //emit closed(this); 202 //emit closed(this);
203 //qDebug("PwM::~PwM() emited closed(this)"); 203 //qDebug("PwM::~PwM() emited closed(this)");
204 delete view; 204 delete view;
205 delete syncManager; 205 delete syncManager;
206} 206}
207 207
208void PwM::initMenubar() 208void PwM::initMenubar()
209{ 209{
210 KIconLoader* picons; 210 KIconLoader* picons;
211#ifndef PWM_EMBEDDED 211#ifndef PWM_EMBEDDED
212 KIconLoader icons; 212 KIconLoader icons;
213 picons = &icons; 213 picons = &icons;
214#else 214#else
215 picons = KGlobal::iconLoader(); 215 picons = KGlobal::iconLoader();
216 216
217 217
218 syncPopup = new KPopupMenu(this); 218 syncPopup = new KPopupMenu(this);
219 219
220 syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::PWMPI, PWMPrefs::instance(), syncPopup); 220 syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::PWMPI, PWMPrefs::instance(), syncPopup);
221 syncManager->setBlockSave(false); 221 syncManager->setBlockSave(false);
222 222
223 connect ( syncPopup, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); 223 connect ( syncPopup, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) );
224 syncManager->fillSyncMenu(); 224 syncManager->fillSyncMenu();
225 225
226#endif 226#endif
227 filePopup = new KPopupMenu(this); 227 filePopup = new KPopupMenu(this);
228 importPopup = new KPopupMenu(filePopup); 228 importPopup = new KPopupMenu(filePopup);
229 exportPopup = new KPopupMenu(filePopup); 229 exportPopup = new KPopupMenu(filePopup);
230 managePopup = new KPopupMenu(this); 230 managePopup = new KPopupMenu(this);
231#ifdef CONFIG_KEYCARD 231#ifdef CONFIG_KEYCARD
232 chipcardPopup = new KPopupMenu(this); 232 chipcardPopup = new KPopupMenu(this);
233#endif // CONFIG_KEYCARD 233#endif // CONFIG_KEYCARD
234 viewPopup = new KPopupMenu(this); 234 viewPopup = new KPopupMenu(this);
235 optionsPopup = new KPopupMenu(this); 235 optionsPopup = new KPopupMenu(this);
236 236
237// "file" popup menu 237// "file" popup menu
238 filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), 238 filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)),
239 i18n("&New"), this, 239 i18n("&New"), this,
240 SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW); 240 SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW);
241 filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)), 241 filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)),
242 i18n("&Open"), this, 242 i18n("&Open"), this,
243 SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN); 243 SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN);
244 filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)), 244 filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)),
245 i18n("&Close"), this, 245 i18n("&Close"), this,
246 SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE); 246 SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE);
247 filePopup->insertSeparator(); 247 filePopup->insertSeparator();
248 filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)), 248 filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)),
249 i18n("&Save"), this, 249 i18n("&Save"), this,
250 SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE); 250 SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE);
251 filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)), 251 filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)),
252 i18n("Save &as..."), 252 i18n("Save &as..."),
253 this, SLOT(saveAs_slot()), 0, 253 this, SLOT(saveAs_slot()), 0,
254 BUTTON_POPUP_FILE_SAVEAS); 254 BUTTON_POPUP_FILE_SAVEAS);
255 filePopup->insertSeparator(); 255 filePopup->insertSeparator();
256 // "file/export" popup menu 256 // "file/export" popup menu
257 exportPopup->insertItem(i18n("&Text-file..."), this, 257 exportPopup->insertItem(i18n("&Text-file..."), this,
258 SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT); 258 SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT);
259 exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, 259 exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this,
260 SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN); 260 SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN);
261 exportPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this, 261 exportPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this,
262 SLOT(exportToCsv()), 0, BUTTON_POPUP_EXPORT_CSV); 262 SLOT(exportToCsv()), 0, BUTTON_POPUP_EXPORT_CSV);
263#ifdef CONFIG_KWALLETIF 263#ifdef CONFIG_KWALLETIF
264 exportPopup->insertItem(i18n("&KWallet..."), this, 264 exportPopup->insertItem(i18n("&KWallet..."), this,
265 SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET); 265 SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET);
266#endif 266#endif
267 filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)), 267 filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)),
268 i18n("E&xport"), exportPopup, 268 i18n("E&xport"), exportPopup,
269 BUTTON_POPUP_FILE_EXPORT); 269 BUTTON_POPUP_FILE_EXPORT);
270 // "file/import" popup menu 270 // "file/import" popup menu
271 importPopup->insertItem(i18n("&Text-file..."), this, 271 importPopup->insertItem(i18n("&Text-file..."), this,
272 SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT); 272 SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT);
273 importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, 273 importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this,
274 SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN); 274 SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN);
275 importPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this, 275 importPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this,
276 SLOT(importCsv()), 0, BUTTON_POPUP_IMPORT_CSV); 276 SLOT(importCsv()), 0, BUTTON_POPUP_IMPORT_CSV);
277#ifdef CONFIG_KWALLETIF 277#ifdef CONFIG_KWALLETIF
278 importPopup->insertItem(i18n("&KWallet..."), this, 278 importPopup->insertItem(i18n("&KWallet..."), this,
279 SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET); 279 SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET);
280#endif 280#endif
281 filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)), 281 filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)),
282 i18n("I&mport"), importPopup, 282 i18n("I&mport"), importPopup,
283 BUTTON_POPUP_FILE_IMPORT); 283 BUTTON_POPUP_FILE_IMPORT);
284 filePopup->insertSeparator(); 284 filePopup->insertSeparator();
285 filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)), 285 filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)),
286 i18n("&Print..."), this, 286 i18n("&Print..."), this,
287 SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT); 287 SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT);
288 filePopup->insertSeparator(); 288 filePopup->insertSeparator();
289 filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)), 289 filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)),
290 i18n("&Quit"), this, 290 i18n("&Quit"), this,
291 SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT); 291 SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT);
292 menuBar()->insertItem(i18n("&File"), filePopup); 292 menuBar()->insertItem(i18n("&File"), filePopup);
293// "manage" popup menu 293// "manage" popup menu
294 managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)), 294 managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)),
295 i18n("&Add password"), this, 295 i18n("&Add password"), this,
296 SLOT(addPwd_slot()), 0, 296 SLOT(addPwd_slot()), 0,
297 BUTTON_POPUP_MANAGE_ADD); 297 BUTTON_POPUP_MANAGE_ADD);
298 managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)), 298 managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)),
299 i18n("&Edit"), this, SLOT(editPwd_slot()), 0, 299 i18n("&Edit"), this, SLOT(editPwd_slot()), 0,
300 BUTTON_POPUP_MANAGE_EDIT); 300 BUTTON_POPUP_MANAGE_EDIT);
301 managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), 301 managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)),
302 i18n("&Delete"), this, SLOT(deletePwd_slot()), 302 i18n("&Delete"), this, SLOT(deletePwd_slot()),
303 0, BUTTON_POPUP_MANAGE_DEL); 303 0, BUTTON_POPUP_MANAGE_DEL);
304 managePopup->insertSeparator(); 304 managePopup->insertSeparator();
305 managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)), 305 managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)),
306 i18n("Change &Master Password"), this, 306 i18n("Change &Master Password"), this,
307 SLOT(changeMasterPwd_slot()), 0, 307 SLOT(changeMasterPwd_slot()), 0,
308 BUTTON_POPUP_MANAGE_CHANGEMP); 308 BUTTON_POPUP_MANAGE_CHANGEMP);
309 menuBar()->insertItem(i18n("&Manage"), managePopup); 309 menuBar()->insertItem(i18n("&Manage"), managePopup);
310// "chipcard" popup menu 310// "chipcard" popup menu
311#ifdef CONFIG_KEYCARD 311#ifdef CONFIG_KEYCARD
312 chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), 312 chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)),
313 i18n("&Generate new key-card"), this, 313 i18n("&Generate new key-card"), this,
314 SLOT(genNewCard_slot()), 0, 314 SLOT(genNewCard_slot()), 0,
315 BUTTON_POPUP_CHIPCARD_GENNEW); 315 BUTTON_POPUP_CHIPCARD_GENNEW);
316 chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), 316 chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)),
317 i18n("&Erase key-card"), this, 317 i18n("&Erase key-card"), this,
318 SLOT(eraseCard_slot()), 0, 318 SLOT(eraseCard_slot()), 0,
319 BUTTON_POPUP_CHIPCARD_DEL); 319 BUTTON_POPUP_CHIPCARD_DEL);
320 chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)), 320 chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)),
321 i18n("Read card-&ID"), this, 321 i18n("Read card-&ID"), this,
322 SLOT(readCardId_slot()), 0, 322 SLOT(readCardId_slot()), 0,
323 BUTTON_POPUP_CHIPCARD_READID); 323 BUTTON_POPUP_CHIPCARD_READID);
324 chipcardPopup->insertSeparator(); 324 chipcardPopup->insertSeparator();
325 chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)), 325 chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)),
326 i18n("&Make card backup-image"), this, 326 i18n("&Make card backup-image"), this,
327 SLOT(makeCardBackup_slot()), 0, 327 SLOT(makeCardBackup_slot()), 0,
328 BUTTON_POPUP_CHIPCARD_SAVEBACKUP); 328 BUTTON_POPUP_CHIPCARD_SAVEBACKUP);
329 chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)), 329 chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)),
330 i18n("&Replay card backup-image"), this, 330 i18n("&Replay card backup-image"), this,
331 SLOT(replayCardBackup_slot()), 0, 331 SLOT(replayCardBackup_slot()), 0,
332 BUTTON_POPUP_CHIPCARD_REPLAYBACKUP); 332 BUTTON_POPUP_CHIPCARD_REPLAYBACKUP);
333 menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup); 333 menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup);
334#endif // CONFIG_KEYCARD 334#endif // CONFIG_KEYCARD
335// "view" popup menu 335// "view" popup menu
336 viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)), 336 viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)),
337 i18n("&Find"), this, 337 i18n("&Find"), this,
338 SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND); 338 SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND);
339 viewPopup->insertSeparator(); 339 viewPopup->insertSeparator();
340 viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)), 340 viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)),
341 i18n("&Lock all entries"), this, 341 i18n("&Lock all entries"), this,
342 SLOT(lockWnd_slot()), 0, 342 SLOT(lockWnd_slot()), 0,
343 BUTTON_POPUP_VIEW_LOCK); 343 BUTTON_POPUP_VIEW_LOCK);
344 viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)), 344 viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)),
345 i18n("&Deep-lock all entries"), this, 345 i18n("&Deep-lock all entries"), this,
346 SLOT(deepLockWnd_slot()), 0, 346 SLOT(deepLockWnd_slot()), 0,
347 BUTTON_POPUP_VIEW_DEEPLOCK); 347 BUTTON_POPUP_VIEW_DEEPLOCK);
348 viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)), 348 viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)),
349 i18n("&Unlock all entries"), this, 349 i18n("&Unlock all entries"), this,
350 SLOT(unlockWnd_slot()), 0, 350 SLOT(unlockWnd_slot()), 0,
351 BUTTON_POPUP_VIEW_UNLOCK); 351 BUTTON_POPUP_VIEW_UNLOCK);
352 menuBar()->insertItem(i18n("&View"), viewPopup); 352 menuBar()->insertItem(i18n("&View"), viewPopup);
353// "options" popup menu 353// "options" popup menu
354 optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), 354 optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)),
355 i18n("&Configure..."), this, 355 i18n("&Configure..."), this,
356 SLOT(config_slot()), 356 SLOT(config_slot()),
357 BUTTON_POPUP_OPTIONS_CONFIG); 357 BUTTON_POPUP_OPTIONS_CONFIG);
358 menuBar()->insertItem(i18n("&Options"), optionsPopup); 358 menuBar()->insertItem(i18n("&Options"), optionsPopup);
359// "help" popup menu 359// "help" popup menu
360#ifndef PWM_EMBEDDED 360#ifndef PWM_EMBEDDED
361 helpPopup = helpMenu(QString::null, false); 361 helpPopup = helpMenu(QString::null, false);
362#else 362#else
363 menuBar()->insertItem(i18n("&Sync"), syncPopup); 363 menuBar()->insertItem(i18n("&Sync"), syncPopup);
364 364
365 365
366 366
367 367
368 368
369 helpPopup = new KPopupMenu(this); 369 helpPopup = new KPopupMenu(this);
370 370
371 371
372 helpPopup->insertItem(i18n("&License"), this, 372 helpPopup->insertItem(i18n("&License"), this,
373 SLOT(showLicense_slot()), 0, 373 SLOT(showLicense_slot()), 0,
374 BUTTON_POPUP_HELP_LICENSE); 374 BUTTON_POPUP_HELP_LICENSE);
375 375
376 helpPopup->insertItem(i18n("&Faq"), this, 376 helpPopup->insertItem(i18n("&Faq"), this,
377 SLOT(faq_slot()), 0, 377 SLOT(faq_slot()), 0,
378 BUTTON_POPUP_HELP_FAQ); 378 BUTTON_POPUP_HELP_FAQ);
379 379
380 helpPopup->insertItem(i18n("&About PwManager"), this, 380 helpPopup->insertItem(i18n("&About PwManager"), this,
381 SLOT(createAboutData_slot()), 0, 381 SLOT(createAboutData_slot()), 0,
382 BUTTON_POPUP_HELP_ABOUT); 382 BUTTON_POPUP_HELP_ABOUT);
383 383
384 helpPopup->insertItem(i18n("&Sync HowTo"), this, 384 helpPopup->insertItem(i18n("&Sync HowTo"), this,
385 SLOT(syncHowTo_slot()), 0, 385 SLOT(syncHowTo_slot()), 0,
386 BUTTON_POPUP_HELP_SYNC); 386 BUTTON_POPUP_HELP_SYNC);
387 387
388 helpPopup->insertItem(i18n("&What's New"), this, 388 helpPopup->insertItem(i18n("&What's New"), this,
389 SLOT(whatsnew_slot()), 0, 389 SLOT(whatsnew_slot()), 0,
390 BUTTON_POPUP_HELP_WHATSNEW); 390 BUTTON_POPUP_HELP_WHATSNEW);
391 391
392#endif 392#endif
393 menuBar()->insertItem(i18n("&Help"), helpPopup); 393 menuBar()->insertItem(i18n("&Help"), helpPopup);
394 394
395} 395}
396 396
397void PwM::initToolbar() 397void PwM::initToolbar()
398{ 398{
399 KIconLoader* picons; 399 KIconLoader* picons;
400#ifndef PWM_EMBEDDED 400#ifndef PWM_EMBEDDED
401 KIconLoader icons; 401 KIconLoader icons;
402 picons = &icons; 402 picons = &icons;
403#else 403#else
404 picons = KGlobal::iconLoader(); 404 picons = KGlobal::iconLoader();
405#endif 405#endif
406 406
407#ifdef PWM_EMBEDDED 407#ifdef PWM_EMBEDDED
408 if ( QApplication::desktop()->width() > 320 ) 408 if ( QApplication::desktop()->width() > 320 )
409#endif 409#endif
410 { 410 {
411 toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar), 411 toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar),
412 BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this, 412 BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this,
413 SLOT(new_slot()), true, i18n("New")); 413 SLOT(new_slot()), true, i18n("New"));
414 toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar), 414 toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar),
415 BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this, 415 BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this,
416 SLOT(open_slot()), true, i18n("Open")); 416 SLOT(open_slot()), true, i18n("Open"));
417 toolBar()->insertSeparator(); 417 toolBar()->insertSeparator();
418 } 418 }
419 toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar), 419 toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar),
420 BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this, 420 BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this,
421 SLOT(save_slot()), true, i18n("Save")); 421 SLOT(save_slot()), true, i18n("Save"));
422 toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar), 422 toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar),
423 BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this, 423 BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this,
424 SLOT(saveAs_slot()), true, i18n("Save as")); 424 SLOT(saveAs_slot()), true, i18n("Save as"));
425 toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar), 425 toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar),
426 BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this, 426 BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this,
427 SLOT(print_slot()), true, i18n("Print...")); 427 SLOT(print_slot()), true, i18n("Print..."));
428 toolBar()->insertSeparator(); 428 toolBar()->insertSeparator();
429 toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar), 429 toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar),
430 BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this, 430 BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this,
431 SLOT(addPwd_slot()), true, 431 SLOT(addPwd_slot()), true,
432 i18n("Add password")); 432 i18n("Add password"));
433 toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar), 433 toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar),
434 BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this, 434 BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this,
435 SLOT(editPwd_slot()), true, 435 SLOT(editPwd_slot()), true,
436 i18n("Edit password")); 436 i18n("Edit password"));
437 toolBar()->insertButton(picons->loadIcon("editdelete", KIcon::Toolbar), 437 toolBar()->insertButton(picons->loadIcon("editdelete", KIcon::Toolbar),
438 BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this, 438 BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this,
439 SLOT(deletePwd_slot()), true, 439 SLOT(deletePwd_slot()), true,
440 i18n("Delete password")); 440 i18n("Delete password"));
441 toolBar()->insertSeparator(); 441 toolBar()->insertSeparator();
442 toolBar()->insertButton(picons->loadIcon("find", KIcon::Toolbar), 442 toolBar()->insertButton(picons->loadIcon("find", KIcon::Toolbar),
443 BUTTON_TOOL_FIND, SIGNAL(clicked(int)), this, 443 BUTTON_TOOL_FIND, SIGNAL(clicked(int)), this,
444 SLOT(find_slot()), true, i18n("Find entry")); 444 SLOT(find_slot()), true, i18n("Find entry"));
445 toolBar()->insertSeparator(); 445 toolBar()->insertSeparator();
446 toolBar()->insertButton(picons->loadIcon("halfencrypted", KIcon::Toolbar), 446 toolBar()->insertButton(picons->loadIcon("halfencrypted", KIcon::Toolbar),
447 BUTTON_TOOL_LOCK, SIGNAL(clicked(int)), this, 447 BUTTON_TOOL_LOCK, SIGNAL(clicked(int)), this,
448 SLOT(lockWnd_slot()), true, 448 SLOT(lockWnd_slot()), true,
449 i18n("Lock all entries")); 449 i18n("Lock all entries"));
450 toolBar()->insertButton(picons->loadIcon("encrypted", KIcon::Toolbar), 450 toolBar()->insertButton(picons->loadIcon("encrypted", KIcon::Toolbar),
451 BUTTON_TOOL_DEEPLOCK, SIGNAL(clicked(int)), this, 451 BUTTON_TOOL_DEEPLOCK, SIGNAL(clicked(int)), this,
452 SLOT(deepLockWnd_slot()), true, 452 SLOT(deepLockWnd_slot()), true,
453 i18n("Deep-Lock all entries")); 453 i18n("Deep-Lock all entries"));
454 toolBar()->insertButton(picons->loadIcon("decrypted", KIcon::Toolbar), 454 toolBar()->insertButton(picons->loadIcon("decrypted", KIcon::Toolbar),
455 BUTTON_TOOL_UNLOCK, SIGNAL(clicked(int)), this, 455 BUTTON_TOOL_UNLOCK, SIGNAL(clicked(int)), this,
456 SLOT(unlockWnd_slot()), true, 456 SLOT(unlockWnd_slot()), true,
457 i18n("Unlock all entries")); 457 i18n("Unlock all entries"));
458} 458}
459 459
460void PwM::initMetrics() 460void PwM::initMetrics()
461{ 461{
462 QSize s = conf()->confWndMainWndSize(); 462 QSize s = conf()->confWndMainWndSize();
463 if (s.isValid()) 463 if (s.isValid())
464 resize(s); 464 resize(s);
465 else 465 else
466 resize(DEFAULT_SIZE); 466 resize(DEFAULT_SIZE);
467} 467}
468 468
469void PwM::updateCaption() 469void PwM::updateCaption()
470{ 470{
471 setPlainCaption(curDoc()->getTitle() + " - " PROG_NAME " " PACKAGE_VER); 471 setPlainCaption(curDoc()->getTitle() + " - " PROG_NAME " " PACKAGE_VER);
472} 472}
473 473
474void PwM::hideEvent(QHideEvent *) 474void PwM::hideEvent(QHideEvent *)
475{ 475{
476 if (isMinimized()) { 476 if (isMinimized()) {
477 if (init->tray()) { 477 if (init->tray()) {
478 forceMinimizeToTray = true; 478 forceMinimizeToTray = true;
479 close(); 479 close();
480 } 480 }
481 int mmlock = conf()->confGlobMinimizeLock(); 481 int mmlock = conf()->confGlobMinimizeLock();
482 switch (mmlock) { 482 switch (mmlock) {
483 case 0: // don't lock anything 483 case 0: // don't lock anything
484 break; 484 break;
485 case 1: {// normal lock 485 case 1: {// normal lock
486 curDoc()->lockAll(true); 486 curDoc()->lockAll(true);
487 break; 487 break;
488 } case 2: {// deep-lock 488 } case 2: {// deep-lock
489 curDoc()->deepLock(); 489 curDoc()->deepLock();
490 break; 490 break;
491 } default: 491 } default:
492 WARN(); 492 WARN();
493 } 493 }
494 } 494 }
495} 495}
496 496
497void PwM::setVirgin(bool v) 497void PwM::setVirgin(bool v)
498{ 498{
499 if (virgin == v) 499 if (virgin == v)
500 return; 500 return;
501 virgin = v; 501 virgin = v;
502 filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVE, !v); 502 filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVE, !v);
503 filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVEAS, !v); 503 filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVEAS, !v);
504 filePopup->setItemEnabled(BUTTON_POPUP_FILE_EXPORT, !v); 504 filePopup->setItemEnabled(BUTTON_POPUP_FILE_EXPORT, !v);
505 filePopup->setItemEnabled(BUTTON_POPUP_FILE_PRINT, !v); 505 filePopup->setItemEnabled(BUTTON_POPUP_FILE_PRINT, !v);
506 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_EDIT, !v); 506 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_EDIT, !v);
507 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_DEL, !v); 507 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_DEL, !v);
508 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, !v); 508 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, !v);
509 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_LOCK, !v); 509 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_LOCK, !v);
510 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_DEEPLOCK, !v); 510 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_DEEPLOCK, !v);
511 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_UNLOCK, !v); 511 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_UNLOCK, !v);
512 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_FIND, !v); 512 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_FIND, !v);
513 toolBar()->setItemEnabled(BUTTON_TOOL_SAVE, !v); 513 toolBar()->setItemEnabled(BUTTON_TOOL_SAVE, !v);
514 toolBar()->setItemEnabled(BUTTON_TOOL_SAVEAS, !v); 514 toolBar()->setItemEnabled(BUTTON_TOOL_SAVEAS, !v);
515 toolBar()->setItemEnabled(BUTTON_TOOL_PRINT, !v); 515 toolBar()->setItemEnabled(BUTTON_TOOL_PRINT, !v);
516 toolBar()->setItemEnabled(BUTTON_TOOL_EDIT, !v); 516 toolBar()->setItemEnabled(BUTTON_TOOL_EDIT, !v);
517 toolBar()->setItemEnabled(BUTTON_TOOL_DEL, !v); 517 toolBar()->setItemEnabled(BUTTON_TOOL_DEL, !v);
518 toolBar()->setItemEnabled(BUTTON_TOOL_LOCK, !v); 518 toolBar()->setItemEnabled(BUTTON_TOOL_LOCK, !v);
519 toolBar()->setItemEnabled(BUTTON_TOOL_DEEPLOCK, !v); 519 toolBar()->setItemEnabled(BUTTON_TOOL_DEEPLOCK, !v);
520 toolBar()->setItemEnabled(BUTTON_TOOL_UNLOCK, !v); 520 toolBar()->setItemEnabled(BUTTON_TOOL_UNLOCK, !v);
521 toolBar()->setItemEnabled(BUTTON_TOOL_FIND, !v); 521 toolBar()->setItemEnabled(BUTTON_TOOL_FIND, !v);
522} 522}
523 523
524void PwM::new_slot() 524void PwM::new_slot()
525{ 525{
526 init->createMainWnd(); 526 init->createMainWnd();
527} 527}
528 528
529//US ENH 529//US ENH
530void PwM::open_slot() 530void PwM::open_slot()
531{ 531{
532 open_slot(""); 532 open_slot("");
533} 533}
534 534
535void PwM::open_slot(QString fn) 535void PwM::open_slot(QString fn)
536{ 536{
537 openDoc(fn); 537 openDoc(fn);
538} 538}
539 539
540PwMDoc * PwM::openDoc(QString filename, bool openDeepLocked) 540PwMDoc * PwM::openDoc(QString filename, bool openDeepLocked)
541{ 541{
542 if (!isVirgin()) { 542 if (!isVirgin()) {
543 // open the document in a new window. 543 // open the document in a new window.
544 PwM *newInstance = init->createMainWnd(); 544 PwM *newInstance = init->createMainWnd();
545 PwMDoc *newDoc = newInstance->openDoc(filename, openDeepLocked); 545 PwMDoc *newDoc = newInstance->openDoc(filename, openDeepLocked);
546 if (!newDoc) { 546 if (!newDoc) {
547 newInstance->setForceQuit(true); 547 newInstance->setForceQuit(true);
548 delete_and_null(newInstance); 548 delete_and_null(newInstance);
549 } 549 }
550 return newDoc; 550 return newDoc;
551 } 551 }
552 552
553 if (!curDoc()->openDocUi(curDoc(), filename, openDeepLocked)) 553 if (!curDoc()->openDocUi(curDoc(), filename, openDeepLocked))
554 return 0; 554 return 0;
555 showStatMsg(i18n("Successfully opened file.")); 555 showStatMsg(i18n("Successfully opened file."));
556 updateCaption(); 556 updateCaption();
557 setVirgin(false); 557 setVirgin(false);
558 return curDoc(); 558 return curDoc();
559} 559}
560 560
561PwMView * PwM::makeNewListView(PwMDoc *doc) 561PwMView * PwM::makeNewListView(PwMDoc *doc)
562{ 562{
563 PwMView *ret = new PwMView(this, this, doc); 563 PwMView *ret = new PwMView(this, this, doc);
564 ret->setFont(conf()->confGlobEntryFont()); 564 ret->setFont(conf()->confGlobEntryFont());
565 ret->show(); 565 ret->show();
566 return ret; 566 return ret;
567} 567}
568 568
569void PwM::close_slot() 569void PwM::close_slot()
570{ 570{
571 close(); 571 close();
572} 572}
573 573
574void PwM::quitButton_slot() 574void PwM::quitButton_slot()
575{ 575{
576 init->shutdownApp(0); 576 init->shutdownApp(0);
577} 577}
578 578
579void PwM::save_slot() 579void PwM::save_slot()
580{ 580{
581 save(); 581 save();
582} 582}
583 583
584bool PwM::save() 584bool PwM::save()
585{ 585{
586 if (!curDoc()->saveDocUi(curDoc())) 586 if (!curDoc()->saveDocUi(curDoc()))
587 return false; 587 return false;
588 showStatMsg(i18n("Successfully saved data.")); 588 showStatMsg(i18n("Successfully saved data."));
589 updateCaption(); 589 updateCaption();
590 return true; 590 return true;
591} 591}
592 592
593void PwM::saveAs_slot() 593void PwM::saveAs_slot()
594{ 594{
595 saveAs(); 595 saveAs();
596} 596}
597 597
598bool PwM::saveAs() 598bool PwM::saveAs()
599{ 599{
600 if (!curDoc()->saveAsDocUi(curDoc())) 600 if (!curDoc()->saveAsDocUi(curDoc()))
601 return false; 601 return false;
602 showStatMsg(i18n("Successfully saved data.")); 602 showStatMsg(i18n("Successfully saved data."));
603 updateCaption(); 603 updateCaption();
604 return true; 604 return true;
605} 605}
606 606
607//US ENH : changed code to run with older MOC 607//US ENH : changed code to run with older MOC
608void PwM::addPwd_slot() 608void PwM::addPwd_slot()
609{ 609{
610 addPwd_slot1(0, 0); 610 addPwd_slot1(0, 0);
611} 611}
612 612
613void PwM::addPwd_slot1(QString *pw, PwMDoc *_doc) 613void PwM::addPwd_slot1(QString *pw, PwMDoc *_doc)
614{ 614{
615 PwMDoc *doc; 615 PwMDoc *doc;
616 if (_doc) { 616 if (_doc) {
617 doc = _doc; 617 doc = _doc;
618 } else { 618 } else {
619 doc = curDoc(); 619 doc = curDoc();
620 } 620 }
621 PWM_ASSERT(doc); 621 PWM_ASSERT(doc);
622 doc->timer()->getLock(DocTimer::id_autoLockTimer); 622 doc->timer()->getLock(DocTimer::id_autoLockTimer);
623#ifndef PWM_EMBEDDED 623#ifndef PWM_EMBEDDED
624 AddEntryWndImpl w; 624 AddEntryWndImpl w;
625#else 625#else
626 AddEntryWndImpl w(this, "addentrywndimpl"); 626 AddEntryWndImpl w(this, "addentrywndimpl");
627#endif 627#endif
628 628
629 vector<string> catList; 629 vector<string> catList;
630 doc->getCategoryList(&catList); 630 doc->getCategoryList(&catList);
631 unsigned i, size = catList.size(); 631 unsigned i, size = catList.size();
632 for (i = 0; i < size; ++i) { 632 for (i = 0; i < size; ++i) {
633 w.addCategory(catList[i].c_str()); 633 w.addCategory(catList[i].c_str());
634 } 634 }
635 w.setCurrCategory(view->getCurrentCategory()); 635 w.setCurrCategory(view->getCurrentCategory());
636 if (pw) 636 if (pw)
637 w.pwLineEdit->setText(*pw); 637 w.pwLineEdit->setText(*pw);
638 638
639 tryAgain: 639 tryAgain:
640 if (w.exec() == 1) 640 if (w.exec() == 1)
641 { 641 {
642 PwMDataItem d; 642 PwMDataItem d;
643 643
644 //US BUG: to initialize all values of curEntr with meaningfulldata, 644 //US BUG: to initialize all values of curEntr with meaningfulldata,
645 // we call clear on it. Reason: Metadata will be uninitialized otherwise. 645 // we call clear on it. Reason: Metadata will be uninitialized otherwise.
646 // another option would be to create a constructor for PwMDataItem 646 // another option would be to create a constructor for PwMDataItem
647 d.clear(true); 647 d.clear(true);
648 648
649 d.desc = w.getDescription().latin1(); 649 d.desc = w.getDescription().latin1();
650 d.name = w.getUsername().latin1(); 650 d.name = w.getUsername().latin1();
651 d.pw = w.getPassword().latin1(); 651 d.pw = w.getPassword().latin1();
652 d.comment = w.getComment().latin1(); 652 d.comment = w.getComment().latin1();
653 d.url = w.getUrl().latin1(); 653 d.url = w.getUrl().latin1();
654 d.launcher = w.getLauncher().latin1(); 654 d.launcher = w.getLauncher().latin1();
655 PwMerror ret = doc->addEntry(w.getCategory(), &d); 655 PwMerror ret = doc->addEntry(w.getCategory(), &d);
656 if (ret == e_entryExists) { 656 if (ret == e_entryExists) {
657 KMessageBox::error(this, 657 KMessageBox::error(this,
658 i18n 658 i18n
659 ("An entry with this \"Description\",\n" 659 ("An entry with this \"Description\",\n"
660 "does already exist.\n" 660 "does already exist.\n"
661 "Please select another description."), 661 "Please select another description."),
662 i18n("entry already exists.")); 662 i18n("entry already exists."));
663 goto tryAgain; 663 goto tryAgain;
664 } else if (ret == e_maxAllowedEntr) { 664 } else if (ret == e_maxAllowedEntr) {
665 KMessageBox::error(this, i18n("The maximum possible number of\nentries" 665 KMessageBox::error(this, i18n("The maximum possible number of\nentries"
666 "has been reached.\nYou can't add more entries."), 666 "has been reached.\nYou can't add more entries."),
667 i18n("maximum number of entries")); 667 i18n("maximum number of entries"));
668 doc->timer()->putLock(DocTimer::id_autoLockTimer); 668 doc->timer()->putLock(DocTimer::id_autoLockTimer);
669 return; 669 return;
670 } 670 }
671 } 671 }
672 setVirgin(false); 672 setVirgin(false);
673 doc->timer()->putLock(DocTimer::id_autoLockTimer); 673 doc->timer()->putLock(DocTimer::id_autoLockTimer);
674} 674}
675 675
676//US ENH : changed code to run with older MOC 676//US ENH : changed code to run with older MOC
677void PwM::editPwd_slot() 677void PwM::editPwd_slot()
678{ 678{
679 editPwd_slot3(0,0,0); 679 editPwd_slot3(0,0,0);
680} 680}
681 681
682void PwM::editPwd_slot1(const QString *category) 682void PwM::editPwd_slot1(const QString *category)
683{ 683{
684 editPwd_slot3(category, 0, 0); 684 editPwd_slot3(category, 0, 0);
685} 685}
686 686
687void PwM::editPwd_slot3(const QString *category, const int *index, 687void PwM::editPwd_slot3(const QString *category, const int *index,
688 PwMDoc *_doc) 688 PwMDoc *_doc)
689{ 689{
690 PwMDoc *doc; 690 PwMDoc *doc;
691 if (_doc) { 691 if (_doc) {
692 doc = _doc; 692 doc = _doc;
693 } else { 693 } else {
694 doc = curDoc(); 694 doc = curDoc();
695 } 695 }
696 PWM_ASSERT(doc); 696 PWM_ASSERT(doc);
697 if (doc->isDocEmpty()) 697 if (doc->isDocEmpty())
698 return; 698 return;
699 if (doc->isDeepLocked()) 699 if (doc->isDeepLocked())
700 return; 700 return;
701 doc->timer()->getLock(DocTimer::id_autoLockTimer); 701 doc->timer()->getLock(DocTimer::id_autoLockTimer);
702 unsigned int curEntryIndex; 702 unsigned int curEntryIndex;
703 if (index) { 703 if (index) {
704 curEntryIndex = *index; 704 curEntryIndex = *index;
705 } else { 705 } else {
706 if (!(view->getCurEntryIndex(&curEntryIndex))) { 706 if (!(view->getCurEntryIndex(&curEntryIndex))) {
707 printDebug("couldn't get index. Maybe we have a binary entry here."); 707 printDebug("couldn't get index. Maybe we have a binary entry here.");
708 doc->timer()->putLock(DocTimer::id_autoLockTimer); 708 doc->timer()->putLock(DocTimer::id_autoLockTimer);
709 return; 709 return;
710 } 710 }
711 } 711 }
712 QString curCategory; 712 QString curCategory;
713 if (category) { 713 if (category) {
714 curCategory = *category; 714 curCategory = *category;
715 } else { 715 } else {
716 curCategory = view->getCurrentCategory(); 716 curCategory = view->getCurrentCategory();
717 } 717 }
718 PwMDataItem currItem; 718 PwMDataItem currItem;
719 if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) { 719 if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) {
720 doc->timer()->putLock(DocTimer::id_autoLockTimer); 720 doc->timer()->putLock(DocTimer::id_autoLockTimer);
721 return; 721 return;
722 } 722 }
723 BUG_ON(currItem.binary); 723 BUG_ON(currItem.binary);
724 724
725 AddEntryWndImpl w; 725 AddEntryWndImpl w;
726 vector<string> catList; 726 vector<string> catList;
727 doc->getCategoryList(&catList); 727 doc->getCategoryList(&catList);
728 unsigned i, size = catList.size(); 728 unsigned i, size = catList.size();
729 for (i = 0; i < size; ++i) { 729 for (i = 0; i < size; ++i) {
730 w.addCategory(catList[i].c_str()); 730 w.addCategory(catList[i].c_str());
731 } 731 }
732 w.setCurrCategory(curCategory); 732 w.setCurrCategory(curCategory);
733 w.setDescription(currItem.desc.c_str()); 733 w.setDescription(currItem.desc.c_str());
734 w.setUsername(currItem.name.c_str()); 734 w.setUsername(currItem.name.c_str());
735 w.setPassword(currItem.pw.c_str()); 735 w.setPassword(currItem.pw.c_str());
736 w.setUrl(currItem.url.c_str()); 736 w.setUrl(currItem.url.c_str());
737 w.setLauncher(currItem.launcher.c_str()); 737 w.setLauncher(currItem.launcher.c_str());
738 w.setComment(currItem.comment.c_str()); 738 w.setComment(currItem.comment.c_str());
739 if (w.exec() == 1) { 739 if (w.exec() == 1) {
740 currItem.desc = w.getDescription().latin1(); 740 currItem.desc = w.getDescription().latin1();
741 currItem.name = w.getUsername().latin1(); 741 currItem.name = w.getUsername().latin1();
742 currItem.pw = w.getPassword().latin1(); 742 currItem.pw = w.getPassword().latin1();
743 currItem.comment = w.getComment().latin1(); 743 currItem.comment = w.getComment().latin1();
744 currItem.url = w.getUrl().latin1(); 744 currItem.url = w.getUrl().latin1();
745 currItem.launcher = w.getLauncher().latin1(); 745 currItem.launcher = w.getLauncher().latin1();
746 if (!doc->editEntry(curCategory, w.getCategory(), 746 if (!doc->editEntry(curCategory, w.getCategory(),
747 curEntryIndex, &currItem)) { 747 curEntryIndex, &currItem)) {
748 KMessageBox::error(this, 748 KMessageBox::error(this,
749 i18n("Couldn't edit the entry.\n" 749 i18n("Couldn't edit the entry.\n"
750 "Maybe you changed the category and\n" 750 "Maybe you changed the category and\n"
751 "this entry is already present\nin the new " 751 "this entry is already present\nin the new "
752 "category?"), 752 "category?"),
753 i18n("couldn't edit entry.")); 753 i18n("couldn't edit entry."));
754 doc->timer()->putLock(DocTimer::id_autoLockTimer); 754 doc->timer()->putLock(DocTimer::id_autoLockTimer);
755 return; 755 return;
756 } 756 }
757 } 757 }
758 doc->timer()->putLock(DocTimer::id_autoLockTimer); 758 doc->timer()->putLock(DocTimer::id_autoLockTimer);
759} 759}
760 760
761void PwM::deletePwd_slot() 761void PwM::deletePwd_slot()
762{ 762{
763 PWM_ASSERT(curDoc()); 763 PWM_ASSERT(curDoc());
764 if (curDoc()->isDocEmpty()) 764 if (curDoc()->isDocEmpty())
765 return; 765 return;
766 if (curDoc()->isDeepLocked()) 766 if (curDoc()->isDeepLocked())
767 return; 767 return;
768 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 768 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
769 unsigned int curEntryIndex = 0; 769 unsigned int curEntryIndex = 0;
770 if (!(view->getCurEntryIndex(&curEntryIndex))) { 770 if (!(view->getCurEntryIndex(&curEntryIndex))) {
771 printDebug("couldn't get index"); 771 printDebug("couldn't get index");
772 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 772 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
773 return; 773 return;
774 } 774 }
775 775
776 PwMDataItem currItem; 776 PwMDataItem currItem;
777 QString curCategory = view->getCurrentCategory(); 777 QString curCategory = view->getCurrentCategory();
778 if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) { 778 if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) {
779 printDebug("couldn't get entry"); 779 printDebug("couldn't get entry");
780 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 780 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
781 return; 781 return;
782 } 782 }
783 if (KMessageBox:: 783 if (KMessageBox::
784 questionYesNo(this, 784 questionYesNo(this,
785 i18n 785 i18n
786 ("Do you really want to delete\nthe selected entry") + 786 ("Do you really want to delete\nthe selected entry") +
787 " \n\"" + QString(currItem.desc.c_str()) 787 " \n\"" + QString(currItem.desc.c_str())
788 + "\" ?", i18n("delete?")) 788 + "\" ?", i18n("delete?"))
789 == KMessageBox::Yes) { 789 == KMessageBox::Yes) {
790 790
791 curDoc()->delEntry(curCategory, curEntryIndex); 791 curDoc()->delEntry(curCategory, curEntryIndex);
792 } 792 }
793 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 793 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
794} 794}
795 795
796void PwM::changeMasterPwd_slot() 796void PwM::changeMasterPwd_slot()
797{ 797{
798 PWM_ASSERT(curDoc()); 798 PWM_ASSERT(curDoc());
799 curDoc()->changeCurrentPw(); 799 curDoc()->changeCurrentPw();
800} 800}
801 801
802void PwM::lockWnd_slot() 802void PwM::lockWnd_slot()
803{ 803{
804 PWM_ASSERT(curDoc()); 804 PWM_ASSERT(curDoc());
805 curDoc()->lockAll(true); 805 curDoc()->lockAll(true);
806} 806}
807 807
808void PwM::deepLockWnd_slot() 808void PwM::deepLockWnd_slot()
809{ 809{
810 PWM_ASSERT(curDoc()); 810 PWM_ASSERT(curDoc());
811 curDoc()->deepLock(); 811 curDoc()->deepLock();
812} 812}
813 813
814void PwM::unlockWnd_slot() 814void PwM::unlockWnd_slot()
815{ 815{
816 PWM_ASSERT(curDoc()); 816 PWM_ASSERT(curDoc());
817 curDoc()->lockAll(false); 817 curDoc()->lockAll(false);
818} 818}
819 819
820void PwM::config_slot() 820void PwM::config_slot()
821{ 821{
822 int oldStyle = conf()->confWndMainViewStyle(); 822 int oldStyle = conf()->confWndMainViewStyle();
823#ifdef PWM_EMBEDDED 823#ifdef PWM_EMBEDDED
824 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"pwmconfigdialog", true ); 824 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"pwmconfigdialog", true );
825 825
826 KCMPwmConfig* pwmcfg = new KCMPwmConfig( ConfigureDialog->getNewVBoxPage(i18n( "PwManager")) , "KCMPwmConfig" ); 826 KCMPwmConfig* pwmcfg = new KCMPwmConfig( ConfigureDialog->getNewVBoxPage(i18n( "PwManager")) , "KCMPwmConfig" );
827 ConfigureDialog->addModule(pwmcfg ); 827 ConfigureDialog->addModule(pwmcfg );
828 828
829 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); 829 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" );
830 ConfigureDialog->addModule(kdelibcfg ); 830 ConfigureDialog->addModule(kdelibcfg );
831 831
832#ifndef DESKTOP_VERSION 832#ifndef DESKTOP_VERSION
833 ConfigureDialog->showMaximized(); 833 ConfigureDialog->showMaximized();
834#endif 834#endif
835 if ( ConfigureDialog->exec() ) 835 if ( ConfigureDialog->exec() )
836 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); 836 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") );
837 delete ConfigureDialog; 837 delete ConfigureDialog;
838 838
839#else //PWM_EMBEDDED 839#else //PWM_EMBEDDED
840 // display the configuration window (modal mode) 840 // display the configuration window (modal mode)
841 if (!conf()->showConfWnd(this)) 841 if (!conf()->showConfWnd(this))
842 return; 842 return;
843#endif 843#endif
844 844
845 int newStyle = conf()->confWndMainViewStyle(); 845 int newStyle = conf()->confWndMainViewStyle();
846 // reinitialize tray 846 // reinitialize tray
847 init->initTray(); 847 init->initTray();
848 // reinitialize KWallet emulation 848 // reinitialize KWallet emulation
849 init->initKWalletEmu(); 849 init->initKWalletEmu();
850 850
851 PwMDocList *_dl = PwMDoc::getOpenDocList(); 851 PwMDocList *_dl = PwMDoc::getOpenDocList();
852 const vector<PwMDocList::listItem> *dl = _dl->getList(); 852 const vector<PwMDocList::listItem> *dl = _dl->getList();
853 vector<PwMDocList::listItem>::const_iterator i = dl->begin(), 853 vector<PwMDocList::listItem>::const_iterator i = dl->begin(),
854 end = dl->end(); 854 end = dl->end();
855 PwMDoc *doc; 855 PwMDoc *doc;
856 while (i != end) { 856 while (i != end) {
857 doc = (*i).doc; 857 doc = (*i).doc;
858 // unlock-without-mpw timeout 858 // unlock-without-mpw timeout
859 doc->timer()->start(DocTimer::id_mpwTimer); 859 doc->timer()->start(DocTimer::id_mpwTimer);
860 // auto-lock timeout 860 // auto-lock timeout
861 doc->timer()->start(DocTimer::id_autoLockTimer); 861 doc->timer()->start(DocTimer::id_autoLockTimer);
862 ++i; 862 ++i;
863 } 863 }
864 864
865 const QValueList<PwM *> *ml = init->mainWndList(); 865 const QValueList<PwM *> *ml = init->mainWndList();
866#ifndef PWM_EMBEDDED 866#ifndef PWM_EMBEDDED
867 QValueList<PwM *>::const_iterator i2 = ml->begin(), 867 QValueList<PwM *>::const_iterator i2 = ml->begin(),
868 end2 = ml->end(); 868 end2 = ml->end();
869#else 869#else
870 QValueList<PwM *>::ConstIterator i2 = ml->begin(), 870 QValueList<PwM *>::ConstIterator i2 = ml->begin(),
871 end2 = ml->end(); 871 end2 = ml->end();
872#endif 872#endif
873 PwM *pwm; 873 PwM *pwm;
874 while (i2 != end2) { 874 while (i2 != end2) {
875 pwm = *i2; 875 pwm = *i2;
876 // reinitialize the window style. 876 // reinitialize the window style.
877 if (oldStyle != newStyle) 877 if (oldStyle != newStyle)
878 pwm->curView()->initStyle(newStyle); 878 pwm->curView()->initStyle(newStyle);
879 // set the new font 879 // set the new font
880 pwm->curView()->setFont(conf()->confGlobEntryFont()); 880 pwm->curView()->setFont(conf()->confGlobEntryFont());
881 ++i2; 881 ++i2;
882 } 882 }
883} 883}
884 884
885void PwM::activateMpButton(bool activate) 885void PwM::activateMpButton(bool activate)
886{ 886{
887 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate); 887 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate);
888} 888}
889 889
890void PwM::closeEvent(QCloseEvent *e) 890void PwM::closeEvent(QCloseEvent *e)
891{ 891{
892 qDebug("PwM::closeEvent "); 892 qDebug("PwM::closeEvent ");
893 emit closed( this ); 893 emit closed( this );
894 return; 894 return;
895 e->accept(); 895 e->accept();
896} 896}
897 897
898void PwM::docClosed(PwMDoc *doc) 898void PwM::docClosed(PwMDoc *doc)
899{ 899{
900 qDebug("PwM::docClosed "); 900 qDebug("PwM::docClosed ");
901 PARAM_UNUSED(doc); 901 PARAM_UNUSED(doc);
902 PWM_ASSERT(doc == curDoc()); 902 PWM_ASSERT(doc == curDoc());
903 close(); 903 close();
904} 904}
905 905
906void PwM::find_slot() 906void PwM::find_slot()
907{ 907{
908 PWM_ASSERT(curDoc()); 908 PWM_ASSERT(curDoc());
909 if (curDoc()->isDocEmpty()) 909 if (curDoc()->isDocEmpty())
910 return; 910 return;
911 if (curDoc()->isDeepLocked()) 911 if (curDoc()->isDeepLocked())
912 return; 912 return;
913 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 913 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
914 FindWndImpl findWnd(view); 914 FindWndImpl findWnd(view);
915 findWnd.exec(); 915 findWnd.exec();
916 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 916 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
917} 917}
918 918
919void PwM::exportToText() 919void PwM::exportToText()
920{ 920{
921 PWM_ASSERT(curDoc()); 921 PWM_ASSERT(curDoc());
922 if (curDoc()->isDocEmpty()) { 922 if (curDoc()->isDocEmpty()) {
923 KMessageBox::information(this, 923 KMessageBox::information(this,
924 i18n 924 i18n
925 ("Sorry, there's nothing to export.\n" 925 ("Sorry, there's nothing to export.\n"
926 "Please first add some passwords."), 926 "Please first add some passwords."),
927 i18n("nothing to do")); 927 i18n("nothing to do"));
928 return; 928 return;
929 } 929 }
930 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 930 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
931 QString fn(KFileDialog::getSaveFileName(QString::null, 931 QString fn(KFileDialog::getSaveFileName(QString::null,
932 i18n("*|plain-text file"), 932 i18n("*|plain-text file"),
933 this)); 933 this));
934 if (fn == "") { 934 if (fn == "") {
935 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 935 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
936 return; 936 return;
937 } 937 }
938 938
939 PwMerror ret = curDoc()->exportToText(&fn); 939 PwMerror ret = curDoc()->exportToText(&fn);
940 if (ret != e_success) { 940 if (ret != e_success) {
941 KMessageBox::error(this, 941 KMessageBox::error(this,
942 i18n("Error: Couldn't write to file.\n" 942 i18n("Error: Couldn't write to file.\n"
943 "Please check if you have permission to write\n" 943 "Please check if you have permission to write\n"
944 "to the file in that directory."), 944 "to the file in that directory."),
945 i18n("error while writing")); 945 i18n("error while writing"));
946 } else 946 } else
947 showStatMsg(i18n("Successfully exported data.")); 947 showStatMsg(i18n("Successfully exported data."));
948 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 948 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
949} 949}
950 950
951bool PwM::importFromText() 951bool PwM::importFromText()
952{ 952{
953 if (!isVirgin()) { 953 if (!isVirgin()) {
954 if (KMessageBox::questionYesNo(this, 954 if (KMessageBox::questionYesNo(this,
955 i18n("Do you want to import the data\n" 955 i18n("Do you want to import the data\n"
956 "into the current document? (If you\n" 956 "into the current document? (If you\n"
957 "select \"no\", a new document will be\n" 957 "select \"no\", a new document will be\n"
958 "opened.)"), 958 "opened.)"),
959 i18n("import into this document?")) 959 i18n("import into this document?"))
960 == KMessageBox::No) { 960 == KMessageBox::No) {
961 // import the data to a new window. 961 // import the data to a new window.
962 PwM *newInstance = init->createMainWnd(); 962 PwM *newInstance = init->createMainWnd();
963 bool ok = newInstance->importFromText(); 963 bool ok = newInstance->importFromText();
964 if (!ok) { 964 if (!ok) {
965 newInstance->setForceQuit(true); 965 newInstance->setForceQuit(true);
966 delete_and_null(newInstance); 966 delete_and_null(newInstance);
967 } 967 }
968 return ok; 968 return ok;
969 } 969 }
970 } 970 }
971 971
972 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 972 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
973 PwMerror ret; 973 PwMerror ret;
974 QString path(KFileDialog::getOpenFileName(QString::null, 974 QString path(KFileDialog::getOpenFileName(QString::null,
975 i18n("*|PWM-exported text file"), 975 i18n("*|PWM-exported text file"),
976 this)); 976 this));
977 if (path == "") 977 if (path == "")
978 goto cancelImport; 978 goto cancelImport;
979 979
980 ret = curDoc()->importFromText(&path, 0); 980 ret = curDoc()->importFromText(&path, 0);
981 if (ret == e_fileFormat) { 981 if (ret == e_fileFormat) {
982 KMessageBox::error(this, 982 KMessageBox::error(this,
983 i18n("Could not read file-format.\n" 983 i18n("Could not read file-format.\n"
984 "This seems to be _not_ a valid file\n" 984 "This seems to be _not_ a valid file\n"
985 "exported by PwM."), 985 "exported by PwM."),
986 i18n("invalid file-format")); 986 i18n("invalid file-format"));
987 goto cancelImport; 987 goto cancelImport;
988 } else if (ret == e_invalidArg) { 988 } else if (ret == e_invalidArg) {
989 BUG(); 989 BUG();
990 goto cancelImport; 990 goto cancelImport;
991 } else if (ret != e_success) { 991 } else if (ret != e_success) {
992 KMessageBox::error(this, 992 KMessageBox::error(this,
993 i18n("Could not import file!\n" 993 i18n("Could not import file!\n"
994 "Do you have permission to read this file?\n" 994 "Do you have permission to read this file?\n"
995 "Do you have enough free memory?"), 995 "Do you have enough free memory?"),
996 i18n("import failed")); 996 i18n("import failed"));
997 goto cancelImport; 997 goto cancelImport;
998 } 998 }
999 setVirgin(false); 999 setVirgin(false);
1000 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1000 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1001 return true; 1001 return true;
1002 1002
1003cancelImport: 1003cancelImport:
1004 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1004 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1005 return false; 1005 return false;
1006} 1006}
1007 1007
1008void PwM::exportToGpasman() 1008void PwM::exportToGpasman()
1009{ 1009{
1010 PWM_ASSERT(curDoc()); 1010 PWM_ASSERT(curDoc());
1011 if (curDoc()->isDocEmpty()) { 1011 if (curDoc()->isDocEmpty()) {
1012 KMessageBox::information(this, 1012 KMessageBox::information(this,
1013 i18n 1013 i18n
1014 ("Sorry, there's nothing to export.\n" 1014 ("Sorry, there's nothing to export.\n"
1015 "Please first add some passwords."), 1015 "Please first add some passwords."),
1016 i18n("nothing to do")); 1016 i18n("nothing to do"));
1017 return; 1017 return;
1018 } 1018 }
1019 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1019 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1020 QString fn(KFileDialog::getSaveFileName(QString::null, 1020 QString fn(KFileDialog::getSaveFileName(QString::null,
1021 i18n("*|Gpasman or Kpasman file"), 1021 i18n("*|Gpasman or Kpasman file"),
1022 this)); 1022 this));
1023 if (fn == "") { 1023 if (fn == "") {
1024 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1024 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1025 return; 1025 return;
1026 } 1026 }
1027 1027
1028 PwMerror ret = curDoc()->exportToGpasman(&fn); 1028 PwMerror ret = curDoc()->exportToGpasman(&fn);
1029 if (ret != e_success) { 1029 if (ret != e_success) {
1030 if (ret == e_noPw) { 1030 if (ret == e_noPw) {
1031 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1031 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1032 return; 1032 return;
1033 } 1033 }
1034 KMessageBox::error(this, 1034 KMessageBox::error(this,
1035 i18n("Error: Couldn't write to file.\n" 1035 i18n("Error: Couldn't write to file.\n"
1036 "Please check if you have permission to write " 1036 "Please check if you have permission to write "
1037 "to the file in that directory."), 1037 "to the file in that directory."),
1038 i18n("error while writing")); 1038 i18n("error while writing"));
1039 } else 1039 } else
1040 showStatMsg(i18n("Successfully exported data.")); 1040 showStatMsg(i18n("Successfully exported data."));
1041 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1041 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1042} 1042}
1043 1043
1044 1044
1045 1045
1046void PwM::exportToCsv() 1046void PwM::exportToCsv()
1047{ 1047{
1048 PWM_ASSERT(curDoc()); 1048 PWM_ASSERT(curDoc());
1049 if (curDoc()->isDocEmpty()) { 1049 if (curDoc()->isDocEmpty()) {
1050 KMessageBox::information(this, 1050 KMessageBox::information(this,
1051 i18n 1051 i18n
1052 ("Sorry, there is nothing to export;\n" 1052 ("Sorry, there is nothing to export;\n"
1053 "please add some passwords first."), 1053 "please add some passwords first."),
1054 i18n("Nothing to Do")); 1054 i18n("Nothing to Do"));
1055 return; 1055 return;
1056 } 1056 }
1057 1057
1058 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1058 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1059 QString fn(KFileDialog::getSaveFileName("*.csv", i18n("*|CSV Text File"), this)); 1059 QString fn(KFileDialog::getSaveFileName("*.csv", i18n("*|CSV Text File"), this));
1060 if (fn.isEmpty()) { 1060 if (fn.isEmpty()) {
1061 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1061 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1062 return; 1062 return;
1063 } 1063 }
1064 1064
1065 Csv csv(this); 1065 Csv csv(this);
1066 if (!csv.exportData(fn, curDoc())) { 1066 if (!csv.exportData(fn, curDoc())) {
1067 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1067 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1068 showStatMsg(i18n("CSV file export failed.")); 1068 showStatMsg(i18n("CSV file export failed."));
1069 return; 1069 return;
1070 } 1070 }
1071 showStatMsg(i18n("Successfully exported data.")); 1071 showStatMsg(i18n("Successfully exported data."));
1072 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1072 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1073} 1073}
1074 1074
1075bool PwM::importCsv() 1075bool PwM::importCsv()
1076{ 1076{
1077 Csv csv(this); 1077 Csv csv(this);
1078 if (!isVirgin()) { 1078 if (!isVirgin()) {
1079 if (KMessageBox::questionYesNo(this, 1079 if (KMessageBox::questionYesNo(this,
1080 i18n("Do you want to import the data\n" 1080 i18n("Do you want to import the data\n"
1081 "into the current document? (If you\n" 1081 "into the current document? (If you\n"
1082 "select \"no\", a new document will be\n" 1082 "select \"no\", a new document will be\n"
1083 "opened.)"), 1083 "opened.)"),
1084 i18n("Import into This Document?")) 1084 i18n("Import into This Document?"))
1085 == KMessageBox::No) { 1085 == KMessageBox::No) {
1086 // import the data to a new window. 1086 // import the data to a new window.
1087 PwM *newInstance = init->createMainWnd(); 1087 PwM *newInstance = init->createMainWnd();
1088 bool ok = newInstance->importCsv(); 1088 bool ok = newInstance->importCsv();
1089 if (!ok) { 1089 if (!ok) {
1090 newInstance->setForceQuit(true); 1090 newInstance->setForceQuit(true);
1091 delete_and_null(newInstance); 1091 delete_and_null(newInstance);
1092 } 1092 }
1093 return ok; 1093 return ok;
1094 } 1094 }
1095 } 1095 }
1096 1096
1097 QString filename = KFileDialog::getOpenFileName("*.csv", i18n("*|CSV Text File"), this); 1097 QString filename = KFileDialog::getOpenFileName("*.csv", i18n("*|CSV Text File"), this);
1098 if (filename.isEmpty()) 1098 if (filename.isEmpty())
1099 return false; 1099 return false;
1100 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1100 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1101 if (!csv.importData(filename, curDoc())) { 1101 if (!csv.importData(filename, curDoc())) {
1102 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1102 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1103 showStatMsg(i18n("CSV file import failed.")); 1103 showStatMsg(i18n("CSV file import failed."));
1104 return false; 1104 return false;
1105 } 1105 }
1106 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1106 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1107 KMessageBox::information(this, 1107 KMessageBox::information(this,
1108 i18n("Successfully imported the CSV data\n" 1108 i18n("Successfully imported the CSV data\n"
1109 "into the current document."), i18n("Successfully Imported")); 1109 "into the current document."), i18n("Successfully Imported"));
1110 showStatMsg(i18n("Successfully imported")); 1110 showStatMsg(i18n("Successfully imported"));
1111 setVirgin(false); 1111 setVirgin(false);
1112 return true; 1112 return true;
1113} 1113}
1114 1114
1115 1115
1116void PwM::exportToKWallet() 1116void PwM::exportToKWallet()
1117{ 1117{
1118#ifdef CONFIG_KWALLETIF 1118#ifdef CONFIG_KWALLETIF
1119 if (!checkAndAskForKWalletEmu()) 1119 if (!checkAndAskForKWalletEmu())
1120 return; 1120 return;
1121 PWM_ASSERT(curDoc()); 1121 PWM_ASSERT(curDoc());
1122 if (curDoc()->isDocEmpty()) { 1122 if (curDoc()->isDocEmpty()) {
1123 KMessageBox::information(this, 1123 KMessageBox::information(this,
1124 i18n 1124 i18n
1125 ("Sorry, there's nothing to export.\n" 1125 ("Sorry, there's nothing to export.\n"
1126 "Please first add some passwords."), 1126 "Please first add some passwords."),
1127 i18n("nothing to do")); 1127 i18n("nothing to do"));
1128 init->initKWalletEmu(); 1128 init->initKWalletEmu();
1129 return; 1129 return;
1130 } 1130 }
1131 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1131 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1132 KWalletIf walletIf(this); 1132 KWalletIf walletIf(this);
1133 if (walletIf.kwalletExport(curDoc())) { 1133 if (walletIf.kwalletExport(curDoc())) {
1134 KMessageBox::information(this, 1134 KMessageBox::information(this,
1135 i18n("Successfully exported the data of the current " 1135 i18n("Successfully exported the data of the current "
1136 "document to KWallet."), 1136 "document to KWallet."),
1137 i18n("Successfully exported data.")); 1137 i18n("Successfully exported data."));
1138 showStatMsg(i18n("Successfully exported data.")); 1138 showStatMsg(i18n("Successfully exported data."));
1139 } 1139 }
1140 init->initKWalletEmu(); 1140 init->initKWalletEmu();
1141 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1141 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1142#endif // CONFIG_KWALLETIF 1142#endif // CONFIG_KWALLETIF
1143} 1143}
1144 1144
1145bool PwM::importFromGpasman() 1145bool PwM::importFromGpasman()
1146{ 1146{
1147 if (!isVirgin()) { 1147 if (!isVirgin()) {
1148 if (KMessageBox::questionYesNo(this, 1148 if (KMessageBox::questionYesNo(this,
1149 i18n("Do you want to import the data\n" 1149 i18n("Do you want to import the data\n"
1150 "into the current document? (If you\n" 1150 "into the current document? (If you\n"
1151 "select \"no\", a new document will be\n" 1151 "select \"no\", a new document will be\n"
1152 "opened.)"), 1152 "opened.)"),
1153 i18n("import into this document?")) 1153 i18n("import into this document?"))
1154 == KMessageBox::No) { 1154 == KMessageBox::No) {
1155 // import the data to a new window. 1155 // import the data to a new window.
1156 PwM *newInstance = init->createMainWnd(); 1156 PwM *newInstance = init->createMainWnd();
1157 bool ok = newInstance->importFromGpasman(); 1157 bool ok = newInstance->importFromGpasman();
1158 if (!ok) { 1158 if (!ok) {
1159 newInstance->setForceQuit(true); 1159 newInstance->setForceQuit(true);
1160 delete_and_null(newInstance); 1160 delete_and_null(newInstance);
1161 } 1161 }
1162 return ok; 1162 return ok;
1163 } 1163 }
1164 } 1164 }
1165 1165
1166 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1166 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1167 PwMerror ret; 1167 PwMerror ret;
1168 QString path(KFileDialog::getOpenFileName(QString::null, 1168 QString path(KFileDialog::getOpenFileName(QString::null,
1169 i18n("*|Gpasman or Kpasman file"), this)); 1169 i18n("*|Gpasman or Kpasman file"), this));
1170 if (path == "") 1170 if (path == "")
1171 goto cancelImport; 1171 goto cancelImport;
1172 ret = curDoc()->importFromGpasman(&path); 1172 ret = curDoc()->importFromGpasman(&path);
1173 if (ret == e_wrongPw) { 1173 if (ret == e_wrongPw) {
1174 if (KMessageBox::questionYesNo(this, 1174 if (KMessageBox::questionYesNo(this,
1175 i18n 1175 i18n
1176 ("This is probably the wrong master-password\n" 1176 ("This is probably the wrong master-password\n"
1177 "you have typed in.\n" 1177 "you have typed in.\n"
1178 "There is no real way to determine the\n" 1178 "There is no real way to determine the\n"
1179 "correctness of the password in the Gpasman\n" 1179 "correctness of the password in the Gpasman\n"
1180 "file-format. But I think this\n" 1180 "file-format. But I think this\n"
1181 "password ist wrong.\n" 1181 "password ist wrong.\n"
1182 "Do you want to continue nevertheless?"), 1182 "Do you want to continue nevertheless?"),
1183 i18n("password error")) 1183 i18n("password error"))
1184 == KMessageBox::No) { 1184 == KMessageBox::No) {
1185 goto cancelImport; 1185 goto cancelImport;
1186 } 1186 }
1187 } else if (ret != e_success) { 1187 } else if (ret != e_success) {
1188 KMessageBox::error(this, 1188 KMessageBox::error(this,
1189 i18n("Could not import file!\n" 1189 i18n("Could not import file!\n"
1190 "Do you have permission to read this file?"), 1190 "Do you have permission to read this file?"),
1191 i18n("import failed")); 1191 i18n("import failed"));
1192 goto cancelImport; 1192 goto cancelImport;
1193 } 1193 }
1194 setVirgin(false); 1194 setVirgin(false);
1195 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1195 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1196 return true; 1196 return true;
1197 1197
1198cancelImport: 1198cancelImport:
1199 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1199 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1200 return false; 1200 return false;
1201} 1201}
1202 1202
1203#ifdef CONFIG_KWALLETIF 1203#ifdef CONFIG_KWALLETIF
1204bool PwM::checkAndAskForKWalletEmu() 1204bool PwM::checkAndAskForKWalletEmu()
1205{ 1205{
1206 if (init->kwalletEmu()) { 1206 if (init->kwalletEmu()) {
1207 /* KWallet emulation is enabled. We can't import/export 1207 /* KWallet emulation is enabled. We can't import/export
1208 * data from/to it, while emulation is active. 1208 * data from/to it, while emulation is active.
1209 */ 1209 */
1210 if (KMessageBox::questionYesNo(this, 1210 if (KMessageBox::questionYesNo(this,
1211 i18n("KWallet emulation is enabled.\n" 1211 i18n("KWallet emulation is enabled.\n"
1212 "You can't import or export data from/to " 1212 "You can't import or export data from/to "
1213 "the original KWallet, while the emulation " 1213 "the original KWallet, while the emulation "
1214 "is active.\n" 1214 "is active.\n"
1215 "Do you want to tempoarly disable the KWallet emulation?"), 1215 "Do you want to tempoarly disable the KWallet emulation?"),
1216 i18n("Tempoarly disable KWallet emulation?")) 1216 i18n("Tempoarly disable KWallet emulation?"))
1217 == KMessageBox::Yes) { 1217 == KMessageBox::Yes) {
1218 init->initKWalletEmu(true); 1218 init->initKWalletEmu(true);
1219 PWM_ASSERT(!init->kwalletEmu()); 1219 PWM_ASSERT(!init->kwalletEmu());
1220 return true; 1220 return true;
1221 } 1221 }
1222 return false; 1222 return false;
1223 } 1223 }
1224 return true; 1224 return true;
1225} 1225}
1226#endif // CONFIG_KWALLETIF 1226#endif // CONFIG_KWALLETIF
1227 1227
1228bool PwM::importKWallet() 1228bool PwM::importKWallet()
1229{ 1229{
1230#ifdef CONFIG_KWALLETIF 1230#ifdef CONFIG_KWALLETIF
1231 if (!checkAndAskForKWalletEmu()) 1231 if (!checkAndAskForKWalletEmu())
1232 return false; 1232 return false;
1233 KWalletIf walletIf(this); 1233 KWalletIf walletIf(this);
1234 if (!isVirgin()) { 1234 if (!isVirgin()) {
1235 if (KMessageBox::questionYesNo(this, 1235 if (KMessageBox::questionYesNo(this,
1236 i18n("Do you want to import the data " 1236 i18n("Do you want to import the data "
1237 "into the current document? (If you " 1237 "into the current document? (If you "
1238 "select \"no\", a new document will be " 1238 "select \"no\", a new document will be "
1239 "opened.)"), 1239 "opened.)"),
1240 i18n("import into this document?")) 1240 i18n("import into this document?"))
1241 == KMessageBox::No) { 1241 == KMessageBox::No) {
1242 // import the data to a new window. 1242 // import the data to a new window.
1243 PwM *newInstance = init->createMainWnd(); 1243 PwM *newInstance = init->createMainWnd();
1244 bool ok = newInstance->importKWallet(); 1244 bool ok = newInstance->importKWallet();
1245 if (!ok) { 1245 if (!ok) {
1246 newInstance->setForceQuit(true); 1246 newInstance->setForceQuit(true);
1247 delete_and_null(newInstance); 1247 delete_and_null(newInstance);
1248 goto exit_fail; 1248 goto exit_fail;
1249 } else { 1249 } else {
1250 goto exit_ok; 1250 goto exit_ok;
1251 } 1251 }
1252 } 1252 }
1253 } 1253 }
1254 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1254 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1255 if (!walletIf.kwalletImport(curDoc())) { 1255 if (!walletIf.kwalletImport(curDoc())) {
1256 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1256 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1257 showStatMsg(i18n("KWallet import failed")); 1257 showStatMsg(i18n("KWallet import failed"));
1258 goto exit_fail; 1258 goto exit_fail;
1259 } 1259 }
1260 KMessageBox::information(this, 1260 KMessageBox::information(this,
1261 i18n("Successfully imported the KWallet data " 1261 i18n("Successfully imported the KWallet data "
1262 "into the current document."), 1262 "into the current document."),
1263 i18n("successfully imported")); 1263 i18n("successfully imported"));
1264 showStatMsg(i18n("successfully imported")); 1264 showStatMsg(i18n("successfully imported"));
1265 setVirgin(false); 1265 setVirgin(false);
1266 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1266 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1267 1267
1268exit_ok: 1268exit_ok:
1269 init->initKWalletEmu(); 1269 init->initKWalletEmu();
1270 return true; 1270 return true;
1271 1271
1272exit_fail: 1272exit_fail:
1273 init->initKWalletEmu(); 1273 init->initKWalletEmu();
1274#endif // CONFIG_KWALLETIF 1274#endif // CONFIG_KWALLETIF
1275 return false; 1275 return false;
1276} 1276}
1277 1277
1278void PwM::print_slot() 1278void PwM::print_slot()
1279{ 1279{
1280 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1280 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1281#ifndef PWM_EMBEDDED 1281#ifndef PWM_EMBEDDED
1282 PwMPrint p(curDoc(), this); 1282 PwMPrint p(curDoc(), this);
1283 p.printNow(); 1283 p.printNow();
1284#else 1284#else
1285 qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); 1285 qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED");
1286#endif 1286#endif
1287 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1287 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1288} 1288}
1289 1289
1290void PwM::genNewCard_slot() 1290void PwM::genNewCard_slot()
1291{ 1291{
1292#ifdef CONFIG_KEYCARD 1292#ifdef CONFIG_KEYCARD
1293 init->keycard()->genNewCard(); 1293 init->keycard()->genNewCard();
1294#endif 1294#endif
1295} 1295}
1296 1296
1297void PwM::eraseCard_slot() 1297void PwM::eraseCard_slot()
1298{ 1298{
1299#ifdef CONFIG_KEYCARD 1299#ifdef CONFIG_KEYCARD
1300 init->keycard()->eraseCard(); 1300 init->keycard()->eraseCard();
1301#endif 1301#endif
1302} 1302}
1303 1303
1304void PwM::readCardId_slot() 1304void PwM::readCardId_slot()
1305{ 1305{
1306#ifdef CONFIG_KEYCARD 1306#ifdef CONFIG_KEYCARD
1307 init->keycard()->displayKey(); 1307 init->keycard()->displayKey();
1308#endif 1308#endif
1309} 1309}
1310 1310
1311void PwM::makeCardBackup_slot() 1311void PwM::makeCardBackup_slot()
1312{ 1312{
1313#ifdef CONFIG_KEYCARD 1313#ifdef CONFIG_KEYCARD
1314 init->keycard()->makeBackupImage(); 1314 init->keycard()->makeBackupImage();
1315#endif 1315#endif
1316} 1316}
1317 1317
1318void PwM::replayCardBackup_slot() 1318void PwM::replayCardBackup_slot()
1319{ 1319{
1320#ifdef CONFIG_KEYCARD 1320#ifdef CONFIG_KEYCARD
1321 init->keycard()->replayBackupImage(); 1321 init->keycard()->replayBackupImage();
1322#endif 1322#endif
1323} 1323}
1324 1324
1325void PwM::execLauncher_slot() 1325void PwM::execLauncher_slot()
1326{ 1326{
1327 PWM_ASSERT(curDoc()); 1327 PWM_ASSERT(curDoc());
1328 if (curDoc()->isDeepLocked()) 1328 if (curDoc()->isDeepLocked())
1329 return; 1329 return;
1330 unsigned int curEntryIndex; 1330 unsigned int curEntryIndex;
1331 if (!view->getCurEntryIndex(&curEntryIndex)) 1331 if (!view->getCurEntryIndex(&curEntryIndex))
1332 return; 1332 return;
1333 bool ret = curDoc()->execLauncher(view->getCurrentCategory(), 1333 bool ret = curDoc()->execLauncher(view->getCurrentCategory(),
1334 curEntryIndex); 1334 curEntryIndex);
1335 if (ret) 1335 if (ret)
1336 showStatMsg(i18n("Executed the \"Launcher\".")); 1336 showStatMsg(i18n("Executed the \"Launcher\"."));
1337 else 1337 else
1338 showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!")); 1338 showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!"));
1339} 1339}
1340 1340
1341void PwM::goToURL_slot() 1341void PwM::goToURL_slot()
1342{ 1342{
1343 PWM_ASSERT(curDoc()); 1343 PWM_ASSERT(curDoc());
1344 if (curDoc()->isDeepLocked()) 1344 if (curDoc()->isDeepLocked())
1345 return; 1345 return;
1346 unsigned int curEntryIndex; 1346 unsigned int curEntryIndex;
1347 if (!view->getCurEntryIndex(&curEntryIndex)) 1347 if (!view->getCurEntryIndex(&curEntryIndex))
1348 return; 1348 return;
1349 bool ret = curDoc()->goToURL(view->getCurrentCategory(), 1349 bool ret = curDoc()->goToURL(view->getCurrentCategory(),
1350 curEntryIndex); 1350 curEntryIndex);
1351 if (ret) 1351 if (ret)
1352 showStatMsg(i18n("started browser with current URL.")); 1352 showStatMsg(i18n("started browser with current URL."));
1353 else 1353 else
1354 showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?")); 1354 showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?"));
1355} 1355}
1356 1356
1357void PwM::copyToClipboard(const QString &s) 1357void PwM::copyToClipboard(const QString &s)
1358{ 1358{
1359 QClipboard *cb = QApplication::clipboard(); 1359 QClipboard *cb = QApplication::clipboard();
1360#ifndef PWM_EMBEDDED 1360#ifndef PWM_EMBEDDED
1361 if (cb->supportsSelection()) 1361 if (cb->supportsSelection())
1362 cb->setText(s, QClipboard::Selection); 1362 cb->setText(s, QClipboard::Selection);
1363 cb->setText(s, QClipboard::Clipboard); 1363 cb->setText(s, QClipboard::Clipboard);
1364#else 1364#else
1365 cb->setText(s); 1365 cb->setText(s);
1366 1366
1367#endif 1367#endif
1368 1368
1369} 1369}
1370 1370
1371 1371
1372void PwM::showStatMsg(const QString &msg) 1372void PwM::showStatMsg(const QString &msg)
1373{ 1373{
1374#ifdef DESKTOP_VERSION 1374#ifdef DESKTOP_VERSION
1375 statusBar()->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); 1375 statusBar()->message(msg, STATUSBAR_MSG_TIMEOUT * 1000);
1376#else 1376#else
1377 qDebug("Statusbar : %s",msg.latin1()); 1377 qDebug("Statusbar : %s",msg.latin1());
1378 Global::statusMessage(msg); 1378 Global::statusMessage(msg);
1379#endif 1379#endif
1380} 1380}
1381 1381
1382void PwM::focusInEvent(QFocusEvent *e) 1382void PwM::focusInEvent(QFocusEvent *e)
1383{ 1383{
1384 if (e->gotFocus()) { 1384 if (e->gotFocus()) {
1385 emit gotFocus(this); 1385 emit gotFocus(this);
1386 } else if (e->lostFocus()) { 1386 } else if (e->lostFocus()) {
1387 emit lostFocus(this); 1387 emit lostFocus(this);
1388 } 1388 }
1389} 1389}
1390 1390
1391 1391
1392#ifdef PWM_EMBEDDED 1392#ifdef PWM_EMBEDDED
1393 1393
1394void PwM::whatsnew_slot() 1394void PwM::whatsnew_slot()
1395{ 1395{
1396 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); 1396 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" );
1397} 1397}
1398 1398
1399void PwM::showLicense_slot() 1399void PwM::showLicense_slot()
1400{ 1400{
1401 KApplication::showLicence(); 1401 KApplication::showLicence();
1402} 1402}
1403 1403
1404void PwM::faq_slot() 1404void PwM::faq_slot()
1405{ 1405{
1406 KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); 1406 KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" );
1407} 1407}
1408 1408
1409void PwM::syncHowTo_slot() 1409void PwM::syncHowTo_slot()
1410{ 1410{
1411 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); 1411 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" );
1412} 1412}
1413 1413
1414 1414
1415void PwM::createAboutData_slot() 1415void PwM::createAboutData_slot()
1416{ 1416{
1417 QString version; 1417 QString version;
1418#include <../version> 1418#include <../version>
1419; 1419;
1420 QMessageBox::about( this, "About PwManager/Pi", 1420 QMessageBox::about( this, "About PwManager/Pi",
1421 "PwManager/Platform-independent\n" 1421 "PwManager/Platform-independent\n"
1422 "(PWM/Pi) " +version + " - " + 1422 "(PWM/Pi) " +version + " - " +
1423#ifdef DESKTOP_VERSION 1423#ifdef DESKTOP_VERSION
1424 "Desktop Edition\n" 1424 "Desktop Edition\n"
1425#else 1425#else
1426 "PDA-Edition\n" 1426 "PDA-Edition\n"
1427 "for: Zaurus 5500 / 7x0 / 8x0\n" 1427 "for: Zaurus 5500 / 7x0 / 8x0\n"
1428#endif 1428#endif
1429 1429
1430 "(c) 2004 Ulf Schenk\n" 1430 "(c) 2004 Ulf Schenk\n"
1431 "(c) 2004 Lutz Rogowski\n" 1431 "(c) 2004 Lutz Rogowski\n"
1432 "(c) 1997-2004, The KDE PIM Team\n" 1432 "(c) 1997-2004, The KDE PIM Team\n"
1433 1433
1434 "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n" 1434 "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n"
1435 "Matt Scifo - mscifo@o1.com\n" 1435 "Matt Scifo - mscifo@o1.com\n"
1436 "Elias Probst - elias.probst@gmx.de\n" 1436 "Elias Probst - elias.probst@gmx.de\n"
1437 "George Staikos - staikos@kde.org\n" 1437 "George Staikos - staikos@kde.org\n"
1438 "Matthew Palmer - mjp16@uow.edu.au\n" 1438 "Matthew Palmer - mjp16@uow.edu.au\n"
1439 "Olivier Sessink - gpasman@nl.linux.org\n" 1439 "Olivier Sessink - gpasman@nl.linux.org\n"
1440 "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" 1440 "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n"
1441 "Troy Engel - tengel@sonic.net\n" 1441 "Troy Engel - tengel@sonic.net\n"
1442 "Wickey - wickey@gmx.at\n" 1442 "Wickey - wickey@gmx.at\n"
1443 "Ian MacGregor - original documentation author.\n" 1443 "Ian MacGregor - original documentation author.\n"
1444 ); 1444 );
1445} 1445}
1446 1446
1447 1447
1448//this are the overwritten callbackmethods from the syncinterface 1448//this are the overwritten callbackmethods from the syncinterface
1449bool PwM::sync(KSyncManager* manager, QString filename, int mode) 1449bool PwM::sync(KSyncManager* manager, QString filename, int mode)
1450{ 1450{
1451 PWM_ASSERT(curDoc()); 1451 PWM_ASSERT(curDoc());
1452 1452
1453 bool ret = curDoc()->sync(manager, filename, mode); 1453 bool ret = curDoc()->sync(manager, filename, mode);
1454 1454
1455 qDebug("PwM::sync save now: ret=%i", ret); 1455 qDebug("PwM::sync save now: ret=%i", ret);
1456 1456
1457 if (ret == true) { 1457 if (ret == true) {
1458 //US BUG: what can we call here to update the view of the current doc? 1458 //US BUG: what can we call here to update the view of the current doc?
1459 //mViewManager->refreshView(); 1459 //mViewManager->refreshView();
1460 1460
1461 //US curDoc()->sync sets the dirtyFlag in case the sync was successfull. 1461 //US curDoc()->sync sets the dirtyFlag in case the sync was successfull.
1462 save(); 1462 save();
1463 } 1463 }
1464 1464
1465 return ret; 1465 return ret;
1466} 1466}
1467
1468void PwM::removeSyncInfo( QString syncProfile)
1469{
1470 qDebug("PWM::not implemented: removeSyncInfo for profile %s ", syncProfile.latin1());
1471}
1472
1467#endif 1473#endif
1468 1474
1469 1475
1470#ifndef PWM_EMBEDDED 1476#ifndef PWM_EMBEDDED
1471#include "pwm.moc" 1477#include "pwm.moc"
1472#endif 1478#endif
diff --git a/pwmanager/pwmanager/pwm.h b/pwmanager/pwmanager/pwm.h
index 5822d59..fb34bca 100644
--- a/pwmanager/pwmanager/pwm.h
+++ b/pwmanager/pwmanager/pwm.h
@@ -1,297 +1,298 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch * 3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager 14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#ifndef __PWM_H 20#ifndef __PWM_H
21#define __PWM_H 21#define __PWM_H
22 22
23 23
24#include <kpopupmenu.h> 24#include <kpopupmenu.h>
25#include <klistview.h> 25#include <klistview.h>
26#include <kmainwindow.h> 26#include <kmainwindow.h>
27 27
28#ifndef PWM_EMBEDDED 28#ifndef PWM_EMBEDDED
29#include <kwin.h> 29#include <kwin.h>
30#include <kapp.h> 30#include <kapp.h>
31#include <kdeversion.h> 31#include <kdeversion.h>
32#else 32#else
33#include <ksyncmanager.h> 33#include <ksyncmanager.h>
34#endif 34#endif
35 35
36#include <kaction.h> 36#include <kaction.h>
37 37
38#include <qglobal.h> 38#include <qglobal.h>
39 39
40#include "pwmview.h" 40#include "pwmview.h"
41#include "pwmexception.h" 41#include "pwmexception.h"
42 42
43 43
44/** timeout for displaying a message on the status-bar (in seconds) */ 44/** timeout for displaying a message on the status-bar (in seconds) */
45 #define STATUSBAR_MSG_TIMEOUT5 45 #define STATUSBAR_MSG_TIMEOUT5
46 46
47 47
48class PwMInit; 48class PwMInit;
49class KSyncManager; 49class KSyncManager;
50 50
51/** PwM is the base class of the project */ 51/** PwM is the base class of the project */
52#ifndef PWM_EMBEDDED 52#ifndef PWM_EMBEDDED
53//MOC_SKIP_BEGIN 53//MOC_SKIP_BEGIN
54class PwM : public KMainWindow 54class PwM : public KMainWindow
55//MOC_SKIP_END 55//MOC_SKIP_END
56#else 56#else
57class PwM : public KMainWindow, public KSyncInterface 57class PwM : public KMainWindow, public KSyncInterface
58#endif 58#endif
59{ 59{
60 Q_OBJECT 60 Q_OBJECT
61public: 61public:
62 friend class PwMView; 62 friend class PwMView;
63 /** construtor */ 63 /** construtor */
64 PwM(PwMInit *_init, PwMDoc *doc, 64 PwM(PwMInit *_init, PwMDoc *doc,
65 bool virginity = true, 65 bool virginity = true,
66 QWidget* parent = 0, const char *name = 0); 66 QWidget* parent = 0, const char *name = 0);
67 /** destructor */ 67 /** destructor */
68 ~PwM(); 68 ~PwM();
69 69
70 /** copy some text to the global clipboard */ 70 /** copy some text to the global clipboard */
71 static void copyToClipboard(const QString &s); 71 static void copyToClipboard(const QString &s);
72 72
73 /** returns pointer to the view */ 73 /** returns pointer to the view */
74 PwMView * curView() 74 PwMView * curView()
75 { return view; } 75 { return view; }
76 /** returns pointer to the currently using document. */ 76 /** returns pointer to the currently using document. */
77 PwMDoc * curDoc() 77 PwMDoc * curDoc()
78 { return curView()->document(); } 78 { return curView()->document(); }
79 /** open a new doc with the given filename */ 79 /** open a new doc with the given filename */
80 PwMDoc * openDoc(QString filename, bool openDeepLocked = false); 80 PwMDoc * openDoc(QString filename, bool openDeepLocked = false);
81 /** show a message on the global status bar. 81 /** show a message on the global status bar.
82 * The message times out after some seconds. 82 * The message times out after some seconds.
83 */ 83 */
84 void showStatMsg(const QString &msg); 84 void showStatMsg(const QString &msg);
85 /** ask the user where to save the doc (if it has not been saved, yet) 85 /** ask the user where to save the doc (if it has not been saved, yet)
86 * and write the data to disk. 86 * and write the data to disk.
87 */ 87 */
88 bool save(); 88 bool save();
89 /** ask the user where to save the doc 89 /** ask the user where to save the doc
90 * and write the data to disk. 90 * and write the data to disk.
91 */ 91 */
92 bool saveAs(); 92 bool saveAs();
93 /** force quit. Quit this window, always! Don't minimize it */ 93 /** force quit. Quit this window, always! Don't minimize it */
94 bool isForceQuit() 94 bool isForceQuit()
95 { return forceQuit; } 95 { return forceQuit; }
96 /** set forceQuit */ 96 /** set forceQuit */
97 void setForceQuit(bool force) 97 void setForceQuit(bool force)
98 { forceQuit = force; } 98 { forceQuit = force; }
99 /** force minimize this window */ 99 /** force minimize this window */
100 bool isForceMinimizeToTray() 100 bool isForceMinimizeToTray()
101 { return forceMinimizeToTray; } 101 { return forceMinimizeToTray; }
102 /** set forceMinimizeToTray */ 102 /** set forceMinimizeToTray */
103 void setForceMinimizeToTray(bool force) 103 void setForceMinimizeToTray(bool force)
104 { forceMinimizeToTray = force; } 104 { forceMinimizeToTray = force; }
105 105
106public slots: 106public slots:
107 /** file/new triggered */ 107 /** file/new triggered */
108 void new_slot(); 108 void new_slot();
109 /** file/open triggered */ 109 /** file/open triggered */
110//US ENH 110//US ENH
111 void open_slot(); 111 void open_slot();
112 void open_slot(QString fn); 112 void open_slot(QString fn);
113 /** file/close triggered */ 113 /** file/close triggered */
114 void close_slot(); 114 void close_slot();
115 /** file/quit triggered */ 115 /** file/quit triggered */
116 void quitButton_slot(); 116 void quitButton_slot();
117 /** file/save triggered */ 117 /** file/save triggered */
118 void save_slot(); 118 void save_slot();
119 /** file/saveAs triggered */ 119 /** file/saveAs triggered */
120 void saveAs_slot(); 120 void saveAs_slot();
121 /** file/export/text triggered */ 121 /** file/export/text triggered */
122 void exportToText(); 122 void exportToText();
123 /** file/export/gpasman triggered */ 123 /** file/export/gpasman triggered */
124 void exportToGpasman(); 124 void exportToGpasman();
125 /** file/export/kwallet triggered */ 125 /** file/export/kwallet triggered */
126 void exportToKWallet(); 126 void exportToKWallet();
127 /** file/export/csv triggered */ 127 /** file/export/csv triggered */
128 void exportToCsv(); 128 void exportToCsv();
129 /** file/import/text triggered */ 129 /** file/import/text triggered */
130 bool importFromText(); 130 bool importFromText();
131 /** file/import/gpasman triggered */ 131 /** file/import/gpasman triggered */
132 bool importFromGpasman(); 132 bool importFromGpasman();
133 /** file/import/kwallet triggered */ 133 /** file/import/kwallet triggered */
134 bool importKWallet(); 134 bool importKWallet();
135 /** file/import/csv triggered */ 135 /** file/import/csv triggered */
136 bool importCsv(); 136 bool importCsv();
137 /** file/print triggered */ 137 /** file/print triggered */
138 void print_slot(); 138 void print_slot();
139 /** manage/add triggered */ 139 /** manage/add triggered */
140 //US ENH : changed code to run with older MOC 140 //US ENH : changed code to run with older MOC
141 141
142 void addPwd_slot(); 142 void addPwd_slot();
143 void addPwd_slot1(QString *pw, PwMDoc *_doc); 143 void addPwd_slot1(QString *pw, PwMDoc *_doc);
144 /** manage/edit triggered */ 144 /** manage/edit triggered */
145 //US ENH : changed code to run with older MOC 145 //US ENH : changed code to run with older MOC
146 void editPwd_slot(); 146 void editPwd_slot();
147 void editPwd_slot1(const QString *category); 147 void editPwd_slot1(const QString *category);
148 void editPwd_slot3(const QString *category, const int *index ,PwMDoc *_doc ); 148 void editPwd_slot3(const QString *category, const int *index ,PwMDoc *_doc );
149 149
150 /** manage/delete triggered */ 150 /** manage/delete triggered */
151 void deletePwd_slot(); 151 void deletePwd_slot();
152 /** execute the "Launcher" entry */ 152 /** execute the "Launcher" entry */
153 void execLauncher_slot(); 153 void execLauncher_slot();
154 /** open browser with URL entry */ 154 /** open browser with URL entry */
155 void goToURL_slot(); 155 void goToURL_slot();
156 /** manage/changeMasterPwd triggered */ 156 /** manage/changeMasterPwd triggered */
157 void changeMasterPwd_slot(); 157 void changeMasterPwd_slot();
158 /** lock current document */ 158 /** lock current document */
159 void lockWnd_slot(); 159 void lockWnd_slot();
160 /** deeplock current document */ 160 /** deeplock current document */
161 void deepLockWnd_slot(); 161 void deepLockWnd_slot();
162 /** window/unlock triggered */ 162 /** window/unlock triggered */
163 void unlockWnd_slot(); 163 void unlockWnd_slot();
164 /** find item */ 164 /** find item */
165 void find_slot(); 165 void find_slot();
166 /** configure clicked */ 166 /** configure clicked */
167 void config_slot(); 167 void config_slot();
168 /** (de)activate the "change master pw" button in the menu-bar */ 168 /** (de)activate the "change master pw" button in the menu-bar */
169 void activateMpButton(bool activate = true); 169 void activateMpButton(bool activate = true);
170 /** generate a new chipcard */ 170 /** generate a new chipcard */
171 void genNewCard_slot(); 171 void genNewCard_slot();
172 /** completely erase the current card */ 172 /** completely erase the current card */
173 void eraseCard_slot(); 173 void eraseCard_slot();
174 /** returns the ID number of the current card */ 174 /** returns the ID number of the current card */
175 void readCardId_slot(); 175 void readCardId_slot();
176 /** make backup image of the current card */ 176 /** make backup image of the current card */
177 void makeCardBackup_slot(); 177 void makeCardBackup_slot();
178 /** write backup image to current card */ 178 /** write backup image to current card */
179 void replayCardBackup_slot(); 179 void replayCardBackup_slot();
180 180
181#ifdef PWM_EMBEDDED 181#ifdef PWM_EMBEDDED
182 void whatsnew_slot(); 182 void whatsnew_slot();
183 void showLicense_slot(); 183 void showLicense_slot();
184 void faq_slot(); 184 void faq_slot();
185 void createAboutData_slot(); 185 void createAboutData_slot();
186 void syncHowTo_slot(); 186 void syncHowTo_slot();
187#endif 187#endif
188 188
189protected: 189protected:
190 /** is this window virgin? */ 190 /** is this window virgin? */
191 bool isVirgin() 191 bool isVirgin()
192 { return virgin; } 192 { return virgin; }
193 /** add/remove virginity */ 193 /** add/remove virginity */
194 void setVirgin(bool v); 194 void setVirgin(bool v);
195 /** initialize the menubar */ 195 /** initialize the menubar */
196 void initMenubar(); 196 void initMenubar();
197 /** initialize the toolbar */ 197 /** initialize the toolbar */
198 void initToolbar(); 198 void initToolbar();
199 /** initialize the window-metrics */ 199 /** initialize the window-metrics */
200 void initMetrics(); 200 void initMetrics();
201 /** close-event */ 201 /** close-event */
202 void closeEvent(QCloseEvent *e); 202 void closeEvent(QCloseEvent *e);
203 /** creates a new PwM-ListView and returns it */ 203 /** creates a new PwM-ListView and returns it */
204 PwMView * makeNewListView(PwMDoc *doc); 204 PwMView * makeNewListView(PwMDoc *doc);
205 /** Window hide-event */ 205 /** Window hide-event */
206 void hideEvent(QHideEvent *); 206 void hideEvent(QHideEvent *);
207 /** is this window minimized? */ 207 /** is this window minimized? */
208 bool isMinimized() 208 bool isMinimized()
209 { 209 {
210#ifndef PWM_EMBEDDED 210#ifndef PWM_EMBEDDED
211 #if KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0) 211 #if KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0)
212 return KWin::windowInfo(winId()).isMinimized(); 212 return KWin::windowInfo(winId()).isMinimized();
213 #else // KDE_VERSION 213 #else // KDE_VERSION
214 return KWin::info(winId()).isIconified(); 214 return KWin::info(winId()).isIconified();
215 #endif // KDE_VERSION 215 #endif // KDE_VERSION
216#else 216#else
217 return false; 217 return false;
218#endif 218#endif
219 } 219 }
220 /** window got the focus */ 220 /** window got the focus */
221 void focusInEvent(QFocusEvent *e); 221 void focusInEvent(QFocusEvent *e);
222 /** update the caption string */ 222 /** update the caption string */
223 void updateCaption(); 223 void updateCaption();
224#ifdef CONFIG_KWALLETIF 224#ifdef CONFIG_KWALLETIF
225 /** check if kwalletemu is enabled and ask the user what to do */ 225 /** check if kwalletemu is enabled and ask the user what to do */
226 bool checkAndAskForKWalletEmu(); 226 bool checkAndAskForKWalletEmu();
227#endif // CONFIG_KWALLETIF 227#endif // CONFIG_KWALLETIF
228 228
229protected slots: 229protected slots:
230 /** doc got closed */ 230 /** doc got closed */
231 void docClosed(PwMDoc *doc); 231 void docClosed(PwMDoc *doc);
232 232
233signals: 233signals:
234 /** window got closed (by user or someone else) */ 234 /** window got closed (by user or someone else) */
235 void closed(PwM *wnd); 235 void closed(PwM *wnd);
236 /** window got the focus (was brought to foreground) */ 236 /** window got the focus (was brought to foreground) */
237 void gotFocus(PwM *wnd); 237 void gotFocus(PwM *wnd);
238 /** window lost the focus */ 238 /** window lost the focus */
239 void lostFocus(PwM *wnd); 239 void lostFocus(PwM *wnd);
240 240
241protected: 241protected:
242 /** pointer to the view active in this KMainWindow */ 242 /** pointer to the view active in this KMainWindow */
243 PwMView *view; 243 PwMView *view;
244 /** pointer to the init class */ 244 /** pointer to the init class */
245 PwMInit *init; 245 PwMInit *init;
246 /** has this window already lost its virginity? 246 /** has this window already lost its virginity?
247 * Means is there an open working document 247 * Means is there an open working document
248 */ 248 */
249 bool virgin; 249 bool virgin;
250 /** "file" popup-menu */ 250 /** "file" popup-menu */
251 KPopupMenu *filePopup; 251 KPopupMenu *filePopup;
252 252
253 /** "manage" popup-menu */ 253 /** "manage" popup-menu */
254 KPopupMenu *managePopup; 254 KPopupMenu *managePopup;
255#ifdef CONFIG_KEYCARD 255#ifdef CONFIG_KEYCARD
256 /** "chipcard" popup-menu */ 256 /** "chipcard" popup-menu */
257 KPopupMenu *chipcardPopup; 257 KPopupMenu *chipcardPopup;
258#endif // CONFIG_KEYCARD 258#endif // CONFIG_KEYCARD
259 /** "view" popup-menu */ 259 /** "view" popup-menu */
260 KPopupMenu *viewPopup; 260 KPopupMenu *viewPopup;
261 /** "options" popup-menu */ 261 /** "options" popup-menu */
262 KPopupMenu *optionsPopup; 262 KPopupMenu *optionsPopup;
263 /** "help" popup-menu */ 263 /** "help" popup-menu */
264 KPopupMenu *helpPopup; 264 KPopupMenu *helpPopup;
265 /** "export" popup-menu */ 265 /** "export" popup-menu */
266 KPopupMenu *exportPopup; 266 KPopupMenu *exportPopup;
267 /** "import" popup-menu */ 267 /** "import" popup-menu */
268 KPopupMenu *importPopup; 268 KPopupMenu *importPopup;
269 /** force quit this window? */ 269 /** force quit this window? */
270 bool forceQuit; 270 bool forceQuit;
271 /** force minimize this window to the tray */ 271 /** force minimize this window to the tray */
272 bool forceMinimizeToTray; 272 bool forceMinimizeToTray;
273 273
274 274
275 275
276 276
277 private: 277 private:
278#ifdef PWM_EMBEDDED 278#ifdef PWM_EMBEDDED
279 //this are the overwritten callbackmethods from the syncinterface 279 //this are the overwritten callbackmethods from the syncinterface
280 virtual bool sync(KSyncManager* manager, QString filename, int mode); 280 virtual bool sync(KSyncManager* manager, QString filename, int mode);
281 virtual void removeSyncInfo( QString syncProfile);
281 282
282 // LR ******************************* 283 // LR *******************************
283 // sync stuff! 284 // sync stuff!
284 QPopupMenu *syncPopup; 285 QPopupMenu *syncPopup;
285 KSyncManager* syncManager; 286 KSyncManager* syncManager;
286#endif 287#endif
287 288
288 289
289 290
290 291
291 292
292 293
293 294
294 295
295}; 296};
296 297
297#endif 298#endif
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index cf8690f..fd17ce5 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -1,3498 +1,3501 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch * 3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.1 of pwmanager 14 * This file is originaly based on version 1.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#include "pwmdoc.h" 20#include "pwmdoc.h"
21#include "pwmview.h" 21#include "pwmview.h"
22#include "blowfish.h" 22#include "blowfish.h"
23#include "sha1.h" 23#include "sha1.h"
24#include "globalstuff.h" 24#include "globalstuff.h"
25#include "gpasmanfile.h" 25#include "gpasmanfile.h"
26#include "serializer.h" 26#include "serializer.h"
27#include "compressgzip.h" 27#include "compressgzip.h"
28//US#include "compressbzip2.h" 28//US#include "compressbzip2.h"
29#include "randomizer.h" 29#include "randomizer.h"
30#include "pwminit.h" 30#include "pwminit.h"
31#include "libgcryptif.h" 31#include "libgcryptif.h"
32#ifdef PWM_EMBEDDED 32#ifdef PWM_EMBEDDED
33#include "pwmprefs.h" 33#include "pwmprefs.h"
34#include "kglobal.h" 34#include "kglobal.h"
35#endif 35#endif
36 36
37#include <kmessagebox.h> 37#include <kmessagebox.h>
38#include <libkcal/syncdefines.h> 38#include <libkcal/syncdefines.h>
39 39
40 40
41#ifdef CONFIG_KWALLETIF 41#ifdef CONFIG_KWALLETIF
42# include "kwalletemu.h" 42# include "kwalletemu.h"
43#endif // CONFIG_KWALLETIF 43#endif // CONFIG_KWALLETIF
44 44
45#include <qdatetime.h> 45#include <qdatetime.h>
46#include <qsize.h> 46#include <qsize.h>
47#include <qfileinfo.h> 47#include <qfileinfo.h>
48#include <qfile.h> 48#include <qfile.h>
49 49
50#include <stdio.h> 50#include <stdio.h>
51#include <stdlib.h> 51#include <stdlib.h>
52#include <errno.h> 52#include <errno.h>
53#include <string.h> 53#include <string.h>
54//US#include <iostream> 54//US#include <iostream>
55#include <algorithm> 55#include <algorithm>
56#include <sys/types.h> 56#include <sys/types.h>
57#include <sys/stat.h> 57#include <sys/stat.h>
58#ifndef _WIN32_ 58#ifndef _WIN32_
59#include <unistd.h> 59#include <unistd.h>
60#include <stdint.h> 60#include <stdint.h>
61#endif 61#endif
62 62
63#ifdef PWM_EMBEDDED 63#ifdef PWM_EMBEDDED
64#ifndef Q_LONG 64#ifndef Q_LONG
65#define Q_LONG long 65#define Q_LONG long
66#endif 66#endif
67 67
68#ifndef Q_ULONG 68#ifndef Q_ULONG
69#define Q_ULONG unsigned long 69#define Q_ULONG unsigned long
70#endif 70#endif
71#endif //PWM_EMBEDDED 71#endif //PWM_EMBEDDED
72 72
73 73
74//TODO: reset to its normal value. 74//TODO: reset to its normal value.
75 #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */ 75 #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */
76 76
77using namespace std; 77using namespace std;
78 78
79 79
80void PwMDocList::add(PwMDoc *doc, const string &id) 80void PwMDocList::add(PwMDoc *doc, const string &id)
81{ 81{
82#ifdef PWM_DEBUG 82#ifdef PWM_DEBUG
83 // check for existance of object in debug mode only. 83 // check for existance of object in debug mode only.
84 vector<listItem>::iterator begin = docList.begin(), 84 vector<listItem>::iterator begin = docList.begin(),
85 end = docList.end(), 85 end = docList.end(),
86 i = begin; 86 i = begin;
87 while (i != end) { 87 while (i != end) {
88 if (i->doc == doc) { 88 if (i->doc == doc) {
89 BUG(); 89 BUG();
90 return; 90 return;
91 } 91 }
92 ++i; 92 ++i;
93 } 93 }
94#endif 94#endif
95 listItem newItem; 95 listItem newItem;
96 newItem.doc = doc; 96 newItem.doc = doc;
97 newItem.docId = id; 97 newItem.docId = id;
98 docList.push_back(newItem); 98 docList.push_back(newItem);
99} 99}
100 100
101void PwMDocList::edit(PwMDoc *doc, const string &newId) 101void PwMDocList::edit(PwMDoc *doc, const string &newId)
102{ 102{
103 vector<listItem>::iterator begin = docList.begin(), 103 vector<listItem>::iterator begin = docList.begin(),
104 end = docList.end(), 104 end = docList.end(),
105 i = begin; 105 i = begin;
106 while (i != end) { 106 while (i != end) {
107 if (i->doc == doc) { 107 if (i->doc == doc) {
108 i->docId = newId; 108 i->docId = newId;
109 return; 109 return;
110 } 110 }
111 ++i; 111 ++i;
112 } 112 }
113} 113}
114 114
115void PwMDocList::del(PwMDoc *doc) 115void PwMDocList::del(PwMDoc *doc)
116{ 116{
117 vector<listItem>::iterator begin = docList.begin(), 117 vector<listItem>::iterator begin = docList.begin(),
118 end = docList.end(), 118 end = docList.end(),
119 i = begin; 119 i = begin;
120 while (i != end) { 120 while (i != end) {
121 if (i->doc == doc) { 121 if (i->doc == doc) {
122 docList.erase(i); 122 docList.erase(i);
123 return; 123 return;
124 } 124 }
125 ++i; 125 ++i;
126 } 126 }
127} 127}
128 128
129bool PwMDocList::find(const string &id, listItem *ret) 129bool PwMDocList::find(const string &id, listItem *ret)
130{ 130{
131 vector<listItem>::iterator begin = docList.begin(), 131 vector<listItem>::iterator begin = docList.begin(),
132 end = docList.end(), 132 end = docList.end(),
133 i = begin; 133 i = begin;
134 while (i != end) { 134 while (i != end) {
135 if (i->docId == id) { 135 if (i->docId == id) {
136 if (ret) 136 if (ret)
137 *ret = *i; 137 *ret = *i;
138 return true; 138 return true;
139 } 139 }
140 ++i; 140 ++i;
141 } 141 }
142 return false; 142 return false;
143} 143}
144 144
145 145
146 146
147DocTimer::DocTimer(PwMDoc *_doc) 147DocTimer::DocTimer(PwMDoc *_doc)
148 : doc (_doc) 148 : doc (_doc)
149 , mpwLock (0) 149 , mpwLock (0)
150 , autoLockLock (0) 150 , autoLockLock (0)
151 , metaCheckLock (0) 151 , metaCheckLock (0)
152{ 152{
153 mpwTimer = new QTimer; 153 mpwTimer = new QTimer;
154 autoLockTimer = new QTimer; 154 autoLockTimer = new QTimer;
155 metaCheckTimer = new QTimer; 155 metaCheckTimer = new QTimer;
156 connect(mpwTimer, SIGNAL(timeout()), 156 connect(mpwTimer, SIGNAL(timeout()),
157 this, SLOT(mpwTimeout())); 157 this, SLOT(mpwTimeout()));
158 connect(autoLockTimer, SIGNAL(timeout()), 158 connect(autoLockTimer, SIGNAL(timeout()),
159 this, SLOT(autoLockTimeout())); 159 this, SLOT(autoLockTimeout()));
160 connect(metaCheckTimer, SIGNAL(timeout()), 160 connect(metaCheckTimer, SIGNAL(timeout()),
161 this, SLOT(metaCheckTimeout())); 161 this, SLOT(metaCheckTimeout()));
162} 162}
163 163
164DocTimer::~DocTimer() 164DocTimer::~DocTimer()
165{ 165{
166 delete mpwTimer; 166 delete mpwTimer;
167 delete autoLockTimer; 167 delete autoLockTimer;
168 delete metaCheckTimer; 168 delete metaCheckTimer;
169} 169}
170 170
171void DocTimer::start(TimerIDs timer) 171void DocTimer::start(TimerIDs timer)
172{ 172{
173 switch (timer) { 173 switch (timer) {
174 case id_mpwTimer: 174 case id_mpwTimer:
175 if (mpwTimer->isActive()) 175 if (mpwTimer->isActive())
176 mpwTimer->stop(); 176 mpwTimer->stop();
177 doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); 177 doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW);
178 mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); 178 mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true);
179 break; 179 break;
180 case id_autoLockTimer: 180 case id_autoLockTimer:
181 if (autoLockTimer->isActive()) 181 if (autoLockTimer->isActive())
182 autoLockTimer->stop(); 182 autoLockTimer->stop();
183 if (conf()->confGlobLockTimeout() > 0) 183 if (conf()->confGlobLockTimeout() > 0)
184 autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); 184 autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true);
185 break; 185 break;
186 case id_metaCheckTimer: 186 case id_metaCheckTimer:
187 if (metaCheckTimer->isActive()) 187 if (metaCheckTimer->isActive())
188 metaCheckTimer->stop(); 188 metaCheckTimer->stop();
189 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 189 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
190 break; 190 break;
191 } 191 }
192} 192}
193 193
194void DocTimer::stop(TimerIDs timer) 194void DocTimer::stop(TimerIDs timer)
195{ 195{
196 switch (timer) { 196 switch (timer) {
197 case id_mpwTimer: 197 case id_mpwTimer:
198 mpwTimer->stop(); 198 mpwTimer->stop();
199 break; 199 break;
200 case id_autoLockTimer: 200 case id_autoLockTimer:
201 autoLockTimer->stop(); 201 autoLockTimer->stop();
202 break; 202 break;
203 case id_metaCheckTimer: 203 case id_metaCheckTimer:
204 metaCheckTimer->stop(); 204 metaCheckTimer->stop();
205 break; 205 break;
206 } 206 }
207} 207}
208 208
209void DocTimer::getLock(TimerIDs timer) 209void DocTimer::getLock(TimerIDs timer)
210{ 210{
211 switch (timer) { 211 switch (timer) {
212 case id_mpwTimer: 212 case id_mpwTimer:
213 ++mpwLock; 213 ++mpwLock;
214 break; 214 break;
215 case id_autoLockTimer: 215 case id_autoLockTimer:
216 ++autoLockLock; 216 ++autoLockLock;
217 break; 217 break;
218 case id_metaCheckTimer: 218 case id_metaCheckTimer:
219 ++metaCheckLock; 219 ++metaCheckLock;
220 break; 220 break;
221 } 221 }
222} 222}
223 223
224void DocTimer::putLock(TimerIDs timer) 224void DocTimer::putLock(TimerIDs timer)
225{ 225{
226 switch (timer) { 226 switch (timer) {
227 case id_mpwTimer: 227 case id_mpwTimer:
228 if (mpwLock) 228 if (mpwLock)
229 --mpwLock; 229 --mpwLock;
230 break; 230 break;
231 case id_autoLockTimer: 231 case id_autoLockTimer:
232 if (autoLockLock) 232 if (autoLockLock)
233 --autoLockLock; 233 --autoLockLock;
234 break; 234 break;
235 case id_metaCheckTimer: 235 case id_metaCheckTimer:
236 if (metaCheckLock) 236 if (metaCheckLock)
237 --metaCheckLock; 237 --metaCheckLock;
238 break; 238 break;
239 } 239 }
240} 240}
241 241
242void DocTimer::mpwTimeout() 242void DocTimer::mpwTimeout()
243{ 243{
244 if (mpwLock) { 244 if (mpwLock) {
245 mpwTimer->start(1000, true); 245 mpwTimer->start(1000, true);
246 return; 246 return;
247 } 247 }
248 doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); 248 doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW);
249} 249}
250 250
251void DocTimer::autoLockTimeout() 251void DocTimer::autoLockTimeout()
252{ 252{
253 if (autoLockLock) { 253 if (autoLockLock) {
254 autoLockTimer->start(1000, true); 254 autoLockTimer->start(1000, true);
255 return; 255 return;
256 } 256 }
257 if (conf()->confGlobAutoDeepLock() && 257 if (conf()->confGlobAutoDeepLock() &&
258 doc->filename != QString::null && 258 doc->filename != QString::null &&
259 doc->filename != "") { 259 doc->filename != "") {
260 doc->deepLock(true); 260 doc->deepLock(true);
261 } else { 261 } else {
262 doc->lockAll(true); 262 doc->lockAll(true);
263 } 263 }
264} 264}
265 265
266void DocTimer::metaCheckTimeout() 266void DocTimer::metaCheckTimeout()
267{ 267{
268 if (metaCheckLock) { 268 if (metaCheckLock) {
269 // check again in one second. 269 // check again in one second.
270 metaCheckTimer->start(1000, true); 270 metaCheckTimer->start(1000, true);
271 return; 271 return;
272 } 272 }
273 if (doc->isDeepLocked()) { 273 if (doc->isDeepLocked()) {
274 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 274 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
275 return; 275 return;
276 } 276 }
277 if (doc->isDocEmpty()) { 277 if (doc->isDocEmpty()) {
278 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 278 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
279 return; 279 return;
280 } 280 }
281#ifdef CONFIG_KWALLETIF 281#ifdef CONFIG_KWALLETIF
282 KWalletEmu *kwlEmu = doc->init->kwalletEmu(); 282 KWalletEmu *kwlEmu = doc->init->kwalletEmu();
283 if (kwlEmu) 283 if (kwlEmu)
284 kwlEmu->suspendDocSignals(); 284 kwlEmu->suspendDocSignals();
285#endif // CONFIG_KWALLETIF 285#endif // CONFIG_KWALLETIF
286 /* We simply trigger all views to update their 286 /* We simply trigger all views to update their
287 * displayed values. This way they have a chance 287 * displayed values. This way they have a chance
288 * to get notified when some meta changes over time. 288 * to get notified when some meta changes over time.
289 * (for example an entry expired). 289 * (for example an entry expired).
290 * The _view_ is responsive for not updating its 290 * The _view_ is responsive for not updating its
291 * contents if nothing really changed! 291 * contents if nothing really changed!
292 */ 292 */
293 emit doc->dataChanged(doc); 293 emit doc->dataChanged(doc);
294#ifdef CONFIG_KWALLETIF 294#ifdef CONFIG_KWALLETIF
295 if (kwlEmu) 295 if (kwlEmu)
296 kwlEmu->resumeDocSignals(); 296 kwlEmu->resumeDocSignals();
297#endif // CONFIG_KWALLETIF 297#endif // CONFIG_KWALLETIF
298 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 298 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
299} 299}
300 300
301 301
302 302
303PwMDocList PwMDoc::openDocList; 303PwMDocList PwMDoc::openDocList;
304unsigned int PwMDocList::unnamedDocCnt = 1; 304unsigned int PwMDocList::unnamedDocCnt = 1;
305 305
306PwMDoc::PwMDoc(QObject *parent, const char *name) 306PwMDoc::PwMDoc(QObject *parent, const char *name)
307 : PwMDocUi(parent, name) 307 : PwMDocUi(parent, name)
308 , dataChangedLock (0) 308 , dataChangedLock (0)
309{ 309{
310 deleted = false; 310 deleted = false;
311 unnamedNum = 0; 311 unnamedNum = 0;
312 getOpenDocList()->add(this, getTitle().latin1()); 312 getOpenDocList()->add(this, getTitle().latin1());
313 curDocStat = 0; 313 curDocStat = 0;
314 setMaxNumEntries(); 314 setMaxNumEntries();
315 _timer = new DocTimer(this); 315 _timer = new DocTimer(this);
316 timer()->start(DocTimer::id_mpwTimer); 316 timer()->start(DocTimer::id_mpwTimer);
317 timer()->start(DocTimer::id_autoLockTimer); 317 timer()->start(DocTimer::id_autoLockTimer);
318 timer()->start(DocTimer::id_metaCheckTimer); 318 timer()->start(DocTimer::id_metaCheckTimer);
319 addCategory(DEFAULT_CATEGORY, 0, false); 319 addCategory(DEFAULT_CATEGORY, 0, false);
320 listView = 0; 320 listView = 0;
321 emit docCreated(this); 321 emit docCreated(this);
322} 322}
323 323
324PwMDoc::~PwMDoc() 324PwMDoc::~PwMDoc()
325{ 325{
326 emit docClosed(this); 326 emit docClosed(this);
327 getOpenDocList()->del(this); 327 getOpenDocList()->del(this);
328 delete _timer; 328 delete _timer;
329} 329}
330 330
331PwMerror PwMDoc::saveDoc(char compress, const QString *file) 331PwMerror PwMDoc::saveDoc(char compress, const QString *file)
332{ 332{
333 PwMerror ret, e; 333 PwMerror ret, e;
334 string serialized; 334 string serialized;
335 QFile f; 335 QFile f;
336 QString tmpFileMoved(QString::null); 336 QString tmpFileMoved(QString::null);
337 bool wasDeepLocked; 337 bool wasDeepLocked;
338 QString savedFilename(filename); 338 QString savedFilename(filename);
339 339
340 if (!file) { 340 if (!file) {
341 if (filename == "") 341 if (filename == "")
342 return e_filename; 342 return e_filename;
343 if (isDeepLocked()) { 343 if (isDeepLocked()) {
344 /* We don't need to save any data. 344 /* We don't need to save any data.
345 * It's already all on disk, because 345 * It's already all on disk, because
346 * we are deeplocked. 346 * we are deeplocked.
347 */ 347 */
348 unsetDocStatFlag(DOC_STAT_DISK_DIRTY); 348 unsetDocStatFlag(DOC_STAT_DISK_DIRTY);
349 ret = e_success; 349 ret = e_success;
350 return ret; 350 return ret;
351 } 351 }
352 } else { 352 } else {
353 if (*file == "" && filename == "") 353 if (*file == "" && filename == "")
354 return e_filename; 354 return e_filename;
355 if (*file != "") 355 if (*file != "")
356 filename = *file; 356 filename = *file;
357 } 357 }
358 358
359 wasDeepLocked = isDeepLocked(); 359 wasDeepLocked = isDeepLocked();
360 if (wasDeepLocked) { 360 if (wasDeepLocked) {
361 /* We are deeplocked. That means all data is already 361 /* We are deeplocked. That means all data is already
362 * on disk. BUT we need to do saving procedure, 362 * on disk. BUT we need to do saving procedure,
363 * because *file != savedFilename. 363 * because *file != savedFilename.
364 * Additionally we need to tempoarly restore 364 * Additionally we need to tempoarly restore
365 * the old "filename", because deepLock() references it. 365 * the old "filename", because deepLock() references it.
366 */ 366 */
367 QString newFilename(filename); 367 QString newFilename(filename);
368 filename = savedFilename; 368 filename = savedFilename;
369 getDataChangedLock(); 369 getDataChangedLock();
370 e = deepLock(false); 370 e = deepLock(false);
371 putDataChangedLock(); 371 putDataChangedLock();
372 filename = newFilename; 372 filename = newFilename;
373 switch (e) { 373 switch (e) {
374 case e_success: 374 case e_success:
375 break; 375 break;
376 case e_wrongPw: 376 case e_wrongPw:
377 case e_noPw: 377 case e_noPw:
378 emitDataChanged(this); 378 emitDataChanged(this);
379 return e; 379 return e;
380 default: 380 default:
381 emitDataChanged(this); 381 emitDataChanged(this);
382 return e_openFile; 382 return e_openFile;
383 } 383 }
384 } 384 }
385 385
386 if (!isPwAvailable()) { 386 if (!isPwAvailable()) {
387 /* password is not available. This means, the 387 /* password is not available. This means, the
388 * document wasn't saved, yet. 388 * document wasn't saved, yet.
389 */ 389 */
390 bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); 390 bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD);
391 QString pw(requestNewMpw(&useChipcard)); 391 QString pw(requestNewMpw(&useChipcard));
392 if (pw != "") { 392 if (pw != "") {
393 currentPw = pw; 393 currentPw = pw;
394 } else { 394 } else {
395 return e_noPw; 395 return e_noPw;
396 } 396 }
397 if (useChipcard) { 397 if (useChipcard) {
398 setDocStatFlag(DOC_STAT_USE_CHIPCARD); 398 setDocStatFlag(DOC_STAT_USE_CHIPCARD);
399 } else { 399 } else {
400 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); 400 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD);
401 } 401 }
402 } 402 }
403 403
404 int _cryptAlgo = conf()->confGlobCryptAlgo(); 404 int _cryptAlgo = conf()->confGlobCryptAlgo();
405 int _hashAlgo = conf()->confGlobHashAlgo(); 405 int _hashAlgo = conf()->confGlobHashAlgo();
406 406
407 // sanity check for the selected algorithms 407 // sanity check for the selected algorithms
408 if (_cryptAlgo < PWM_CRYPT_BLOWFISH || 408 if (_cryptAlgo < PWM_CRYPT_BLOWFISH ||
409 _cryptAlgo > PWM_CRYPT_TWOFISH128) { 409 _cryptAlgo > PWM_CRYPT_TWOFISH128) {
410 printWarn("Invalid Crypto-Algorithm selected! " 410 printWarn("Invalid Crypto-Algorithm selected! "
411 "Config-file seems to be corrupt. " 411 "Config-file seems to be corrupt. "
412 "Falling back to Blowfish."); 412 "Falling back to Blowfish.");
413 _cryptAlgo = PWM_CRYPT_BLOWFISH; 413 _cryptAlgo = PWM_CRYPT_BLOWFISH;
414 } 414 }
415 if (_hashAlgo < PWM_HASH_SHA1 || 415 if (_hashAlgo < PWM_HASH_SHA1 ||
416 _hashAlgo > PWM_HASH_TIGER) { 416 _hashAlgo > PWM_HASH_TIGER) {
417 printWarn("Invalid Hash-Algorithm selected! " 417 printWarn("Invalid Hash-Algorithm selected! "
418 "Config-file seems to be corrupt. " 418 "Config-file seems to be corrupt. "
419 "Falling back to SHA1."); 419 "Falling back to SHA1.");
420 _hashAlgo = PWM_HASH_SHA1; 420 _hashAlgo = PWM_HASH_SHA1;
421 } 421 }
422 char cryptAlgo = static_cast<char>(_cryptAlgo); 422 char cryptAlgo = static_cast<char>(_cryptAlgo);
423 char hashAlgo = static_cast<char>(_hashAlgo); 423 char hashAlgo = static_cast<char>(_hashAlgo);
424 424
425 if (conf()->confGlobMakeFileBackup()) { 425 if (conf()->confGlobMakeFileBackup()) {
426 if (!backupFile(filename)) 426 if (!backupFile(filename))
427 return e_fileBackup; 427 return e_fileBackup;
428 } 428 }
429 if (QFile::exists(filename)) { 429 if (QFile::exists(filename)) {
430 /* Move the existing file to some tmp file. 430 /* Move the existing file to some tmp file.
431 * When saving file succeeds, delete tmp file. Otherwise 431 * When saving file succeeds, delete tmp file. Otherwise
432 * move tmp file back. See below. 432 * move tmp file back. See below.
433 */ 433 */
434 Randomizer *rnd = Randomizer::obj(); 434 Randomizer *rnd = Randomizer::obj();
435 char rnd_buf[5]; 435 char rnd_buf[5];
436 sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF, 436 sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF,
437 rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF); 437 rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF);
438 tmpFileMoved = filename + "." + rnd_buf + ".mv"; 438 tmpFileMoved = filename + "." + rnd_buf + ".mv";
439 if (!copyFile(filename, tmpFileMoved)) 439 if (!copyFile(filename, tmpFileMoved))
440 return e_openFile; 440 return e_openFile;
441 if (!QFile::remove(filename)) { 441 if (!QFile::remove(filename)) {
442 printWarn(string("removing orig file ") 442 printWarn(string("removing orig file ")
443 + filename.latin1() 443 + filename.latin1()
444 + " failed!"); 444 + " failed!");
445 } 445 }
446 } 446 }
447 f.setName(filename); 447 f.setName(filename);
448 if (!f.open(IO_ReadWrite)) { 448 if (!f.open(IO_ReadWrite)) {
449 ret = e_openFile; 449 ret = e_openFile;
450 goto out_moveback; 450 goto out_moveback;
451 } 451 }
452 e = writeFileHeader(hashAlgo, hashAlgo, 452 e = writeFileHeader(hashAlgo, hashAlgo,
453 cryptAlgo, compress, 453 cryptAlgo, compress,
454 &currentPw, &f); 454 &currentPw, &f);
455 if (e == e_hashNotImpl) { 455 if (e == e_hashNotImpl) {
456 printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl"); 456 printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl");
457 f.close(); 457 f.close();
458 ret = e_hashNotImpl; 458 ret = e_hashNotImpl;
459 goto out_moveback; 459 goto out_moveback;
460 } else if (e != e_success) { 460 } else if (e != e_success) {
461 printDebug("PwMDoc::saveDoc(): writeFileHeader() failed"); 461 printDebug("PwMDoc::saveDoc(): writeFileHeader() failed");
462 f.close(); 462 f.close();
463 ret = e_writeHeader; 463 ret = e_writeHeader;
464 goto out_moveback; 464 goto out_moveback;
465 } 465 }
466 if (!serializeDta(&serialized)) { 466 if (!serializeDta(&serialized)) {
467 printDebug("PwMDoc::saveDoc(): serializeDta() failed"); 467 printDebug("PwMDoc::saveDoc(): serializeDta() failed");
468 f.close(); 468 f.close();
469 ret = e_serializeDta; 469 ret = e_serializeDta;
470 goto out_moveback; 470 goto out_moveback;
471 } 471 }
472 e = writeDataHash(hashAlgo, &serialized, &f); 472 e = writeDataHash(hashAlgo, &serialized, &f);
473 if (e == e_hashNotImpl) { 473 if (e == e_hashNotImpl) {
474 printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl"); 474 printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl");
475 f.close(); 475 f.close();
476 ret = e_hashNotImpl; 476 ret = e_hashNotImpl;
477 goto out_moveback; 477 goto out_moveback;
478 } else if (e != e_success) { 478 } else if (e != e_success) {
479 printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); 479 printDebug("PwMDoc::saveDoc(): writeDataHash() failed");
480 f.close(); 480 f.close();
481 ret = e_writeHeader; 481 ret = e_writeHeader;
482 goto out_moveback; 482 goto out_moveback;
483 } 483 }
484 if (!compressDta(&serialized, compress)) { 484 if (!compressDta(&serialized, compress)) {
485 printDebug("PwMDoc::saveDoc(): compressDta() failed"); 485 printDebug("PwMDoc::saveDoc(): compressDta() failed");
486 f.close(); 486 f.close();
487 ret = e_enc; 487 ret = e_enc;
488 goto out_moveback; 488 goto out_moveback;
489 } 489 }
490 e = encrypt(&serialized, &currentPw, &f, cryptAlgo); 490 e = encrypt(&serialized, &currentPw, &f, cryptAlgo);
491 if (e == e_weakPw) { 491 if (e == e_weakPw) {
492 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); 492 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw");
493 f.close(); 493 f.close();
494 ret = e_weakPw; 494 ret = e_weakPw;
495 goto out_moveback; 495 goto out_moveback;
496 } else if (e == e_cryptNotImpl) { 496 } else if (e == e_cryptNotImpl) {
497 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); 497 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl");
498 f.close(); 498 f.close();
499 ret = e_cryptNotImpl; 499 ret = e_cryptNotImpl;
500 goto out_moveback; 500 goto out_moveback;
501 } else if (e != e_success) { 501 } else if (e != e_success) {
502 printDebug("PwMDoc::saveDoc(): encrypt() failed"); 502 printDebug("PwMDoc::saveDoc(): encrypt() failed");
503 f.close(); 503 f.close();
504 ret = e_enc; 504 ret = e_enc;
505 goto out_moveback; 505 goto out_moveback;
506 } 506 }
507 unsetDocStatFlag(DOC_STAT_DISK_DIRTY); 507 unsetDocStatFlag(DOC_STAT_DISK_DIRTY);
508 f.close(); 508 f.close();
509#ifndef _WIN32_ 509#ifndef _WIN32_
510 if (chmod(filename.latin1(), 510 if (chmod(filename.latin1(),
511 conf()->confGlobFilePermissions())) { 511 conf()->confGlobFilePermissions())) {
512 printWarn(string("chmod failed: ") + strerror(errno)); 512 printWarn(string("chmod failed: ") + strerror(errno));
513 } 513 }
514#endif 514#endif
515 openDocList.edit(this, getTitle().latin1()); 515 openDocList.edit(this, getTitle().latin1());
516 if (wasDeepLocked) { 516 if (wasDeepLocked) {
517 /* Do _not_ save the data with the deepLock() 517 /* Do _not_ save the data with the deepLock()
518 * call, because this will recurse 518 * call, because this will recurse
519 * into saveDoc() 519 * into saveDoc()
520 */ 520 */
521 deepLock(true, false); 521 deepLock(true, false);
522 /* We don't check return value here, because 522 /* We don't check return value here, because
523 * it won't fail. See NOTE in deepLock() 523 * it won't fail. See NOTE in deepLock()
524 */ 524 */
525 } 525 }
526 if (tmpFileMoved != QString::null) { 526 if (tmpFileMoved != QString::null) {
527 // now remove the moved file. 527 // now remove the moved file.
528 if (!QFile::remove(tmpFileMoved)) { 528 if (!QFile::remove(tmpFileMoved)) {
529 printWarn(string("removing file ") 529 printWarn(string("removing file ")
530 + tmpFileMoved.latin1() 530 + tmpFileMoved.latin1()
531 + " failed!"); 531 + " failed!");
532 } 532 }
533 } 533 }
534 ret = e_success; 534 ret = e_success;
535 printDebug(string("writing file { name: ") 535 printDebug(string("writing file { name: ")
536 + filename.latin1() + " compress: " 536 + filename.latin1() + " compress: "
537 + tostr(static_cast<int>(compress)) + " cryptAlgo: " 537 + tostr(static_cast<int>(compress)) + " cryptAlgo: "
538 + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " 538 + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: "
539 + tostr(static_cast<int>(hashAlgo)) 539 + tostr(static_cast<int>(hashAlgo))
540 + " }"); 540 + " }");
541 goto out; 541 goto out;
542out_moveback: 542out_moveback:
543 if (tmpFileMoved != QString::null) { 543 if (tmpFileMoved != QString::null) {
544 if (copyFile(tmpFileMoved, filename)) { 544 if (copyFile(tmpFileMoved, filename)) {
545 if (!QFile::remove(tmpFileMoved)) { 545 if (!QFile::remove(tmpFileMoved)) {
546 printWarn(string("removing tmp file ") 546 printWarn(string("removing tmp file ")
547 + filename.latin1() 547 + filename.latin1()
548 + " failed!"); 548 + " failed!");
549 } 549 }
550 } else { 550 } else {
551 printWarn(string("couldn't copy file ") 551 printWarn(string("couldn't copy file ")
552 + tmpFileMoved.latin1() 552 + tmpFileMoved.latin1()
553 + " back to " 553 + " back to "
554 + filename.latin1()); 554 + filename.latin1());
555 } 555 }
556 } 556 }
557out: 557out:
558 return ret; 558 return ret;
559} 559}
560 560
561PwMerror PwMDoc::openDoc(const QString *file, int openLocked) 561PwMerror PwMDoc::openDoc(const QString *file, int openLocked)
562{ 562{
563 PWM_ASSERT(file); 563 PWM_ASSERT(file);
564 PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); 564 PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2);
565 string decrypted, dataHash; 565 string decrypted, dataHash;
566 PwMerror ret; 566 PwMerror ret;
567 char cryptAlgo, dataHashType, compress; 567 char cryptAlgo, dataHashType, compress;
568 unsigned int headerLen; 568 unsigned int headerLen;
569 569
570 if (*file == "") 570 if (*file == "")
571 return e_readFile; 571 return e_readFile;
572 filename = *file; 572 filename = *file;
573 /* check if this file is already open. 573 /* check if this file is already open.
574 * This does not catch symlinks! 574 * This does not catch symlinks!
575 */ 575 */
576 if (!isDeepLocked()) { 576 if (!isDeepLocked()) {
577 if (getOpenDocList()->find(filename.latin1())) 577 if (getOpenDocList()->find(filename.latin1()))
578 return e_alreadyOpen; 578 return e_alreadyOpen;
579 } 579 }
580 QFile f(filename); 580 QFile f(filename);
581 581
582 if (openLocked == 2) { 582 if (openLocked == 2) {
583 // open deep-locked 583 // open deep-locked
584 if (!QFile::exists(filename)) 584 if (!QFile::exists(filename))
585 return e_openFile; 585 return e_openFile;
586 if (deepLock(true, false) != e_success) 586 if (deepLock(true, false) != e_success)
587 return e_openFile; 587 return e_openFile;
588 goto out_success; 588 goto out_success;
589 } 589 }
590 590
591 if (!f.open(IO_ReadOnly)) 591 if (!f.open(IO_ReadOnly))
592 return e_openFile; 592 return e_openFile;
593 593
594 ret = checkHeader(&cryptAlgo, &currentPw, &compress, &headerLen, 594 ret = checkHeader(&cryptAlgo, &currentPw, &compress, &headerLen,
595 &dataHashType, &dataHash, &f); 595 &dataHashType, &dataHash, &f);
596 if (ret != e_success) { 596 if (ret != e_success) {
597 printDebug("PwMDoc::openDoc(): checkHeader() failed"); 597 printDebug("PwMDoc::openDoc(): checkHeader() failed");
598 f.close(); 598 f.close();
599 if (ret == e_wrongPw) { 599 if (ret == e_wrongPw) {
600 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 600 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
601 return ret; 601 return ret;
602 } else if (ret == e_noPw || 602 } else if (ret == e_noPw ||
603 ret == e_fileVer || 603 ret == e_fileVer ||
604 ret == e_fileFormat || 604 ret == e_fileFormat ||
605 ret == e_hashNotImpl) { 605 ret == e_hashNotImpl) {
606 return ret; 606 return ret;
607 } else 607 } else
608 return e_readFile; 608 return e_readFile;
609 } 609 }
610 ret = decrypt(&decrypted, headerLen, &currentPw, cryptAlgo, &f); 610 ret = decrypt(&decrypted, headerLen, &currentPw, cryptAlgo, &f);
611 if (ret == e_cryptNotImpl) { 611 if (ret == e_cryptNotImpl) {
612 printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); 612 printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl");
613 f.close(); 613 f.close();
614 return e_cryptNotImpl; 614 return e_cryptNotImpl;
615 } else if (ret != e_success) { 615 } else if (ret != e_success) {
616 printDebug("PwMDoc::openDoc(): decrypt() failed"); 616 printDebug("PwMDoc::openDoc(): decrypt() failed");
617 f.close(); 617 f.close();
618 return e_readFile; 618 return e_readFile;
619 } 619 }
620 if (!decompressDta(&decrypted, compress)) { 620 if (!decompressDta(&decrypted, compress)) {
621 printDebug("PwMDoc::openDoc(): decompressDta() failed"); 621 printDebug("PwMDoc::openDoc(): decompressDta() failed");
622 f.close(); 622 f.close();
623 return e_fileCorrupt; 623 return e_fileCorrupt;
624 } 624 }
625 ret = checkDataHash(dataHashType, &dataHash, &decrypted); 625 ret = checkDataHash(dataHashType, &dataHash, &decrypted);
626 if (ret == e_hashNotImpl) { 626 if (ret == e_hashNotImpl) {
627 printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); 627 printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl");
628 f.close(); 628 f.close();
629 return e_hashNotImpl; 629 return e_hashNotImpl;
630 } else if (ret != e_success) { 630 } else if (ret != e_success) {
631 printDebug("PwMDoc::openDoc(): checkDataHash() failed"); 631 printDebug("PwMDoc::openDoc(): checkDataHash() failed");
632 f.close(); 632 f.close();
633 return e_fileCorrupt; 633 return e_fileCorrupt;
634 } 634 }
635 if (!deSerializeDta(&decrypted, openLocked == 1)) { 635 if (!deSerializeDta(&decrypted, openLocked == 1)) {
636 printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); 636 printDebug("PwMDoc::openDoc(): deSerializeDta() failed");
637 f.close(); 637 f.close();
638 return e_readFile; 638 return e_readFile;
639 } 639 }
640 f.close(); 640 f.close();
641 timer()->start(DocTimer::id_mpwTimer); 641 timer()->start(DocTimer::id_mpwTimer);
642 timer()->start(DocTimer::id_autoLockTimer); 642 timer()->start(DocTimer::id_autoLockTimer);
643out_success: 643out_success:
644 openDocList.edit(this, getTitle().latin1()); 644 openDocList.edit(this, getTitle().latin1());
645 emit docOpened(this); 645 emit docOpened(this);
646 return e_success; 646 return e_success;
647} 647}
648 648
649PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, 649PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress,
650 QString *pw, QFile *f) 650 QString *pw, QFile *f)
651{ 651{
652 PWM_ASSERT(pw); 652 PWM_ASSERT(pw);
653 PWM_ASSERT(f); 653 PWM_ASSERT(f);
654 //US ENH: or maybe a bug: checking here for listView does not make sense because we do not check anywhere else 654 //US ENH: or maybe a bug: checking here for listView does not make sense because we do not check anywhere else
655 //Wenn I sync, I open a doc without a view => listView is 0 => Assertion 655 //Wenn I sync, I open a doc without a view => listView is 0 => Assertion
656 //USPWM_ASSERT(listView); 656 //USPWM_ASSERT(listView);
657 if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != 657 if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) !=
658 static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { 658 static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) {
659 return e_writeFile; 659 return e_writeFile;
660 } 660 }
661 if (f->putch(PWM_FILE_VER) == -1 || 661 if (f->putch(PWM_FILE_VER) == -1 ||
662 f->putch(keyHash) == -1 || 662 f->putch(keyHash) == -1 ||
663 f->putch(dataHash) == -1 || 663 f->putch(dataHash) == -1 ||
664 f->putch(crypt) == -1 || 664 f->putch(crypt) == -1 ||
665 f->putch(compress) == -1 || 665 f->putch(compress) == -1 ||
666 f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? 666 f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ?
667 (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { 667 (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) {
668 return e_writeFile; 668 return e_writeFile;
669 } 669 }
670 670
671 // write bytes of NUL-data. These bytes are reserved for future-use. 671 // write bytes of NUL-data. These bytes are reserved for future-use.
672 const int bufSize = 64; 672 const int bufSize = 64;
673 char tmp_buf[bufSize]; 673 char tmp_buf[bufSize];
674 memset(tmp_buf, 0x00, bufSize); 674 memset(tmp_buf, 0x00, bufSize);
675 if (f->writeBlock(tmp_buf, bufSize) != bufSize) 675 if (f->writeBlock(tmp_buf, bufSize) != bufSize)
676 return e_writeFile; 676 return e_writeFile;
677 677
678 switch (keyHash) { 678 switch (keyHash) {
679 case PWM_HASH_SHA1: { 679 case PWM_HASH_SHA1: {
680 const int hashlen = SHA1_HASH_LEN_BYTE; 680 const int hashlen = SHA1_HASH_LEN_BYTE;
681 Sha1 hash; 681 Sha1 hash;
682 hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); 682 hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length());
683 string ret = hash.sha1_read(); 683 string ret = hash.sha1_read();
684 if (f->writeBlock(ret.c_str(), hashlen) != hashlen) 684 if (f->writeBlock(ret.c_str(), hashlen) != hashlen)
685 return e_writeFile; 685 return e_writeFile;
686 break; 686 break;
687 } 687 }
688 case PWM_HASH_SHA256: 688 case PWM_HASH_SHA256:
689 /*... fall through */ 689 /*... fall through */
690 case PWM_HASH_SHA384: 690 case PWM_HASH_SHA384:
691 case PWM_HASH_SHA512: 691 case PWM_HASH_SHA512:
692 case PWM_HASH_MD5: 692 case PWM_HASH_MD5:
693 case PWM_HASH_RMD160: 693 case PWM_HASH_RMD160:
694 case PWM_HASH_TIGER: 694 case PWM_HASH_TIGER:
695 { 695 {
696 if (!LibGCryptIf::available()) 696 if (!LibGCryptIf::available())
697 return e_hashNotImpl; 697 return e_hashNotImpl;
698 LibGCryptIf gc; 698 LibGCryptIf gc;
699 PwMerror err; 699 PwMerror err;
700 unsigned char *buf; 700 unsigned char *buf;
701 size_t hashLen; 701 size_t hashLen;
702 err = gc.hash(&buf, 702 err = gc.hash(&buf,
703 &hashLen, 703 &hashLen,
704 reinterpret_cast<const unsigned char *>(pw->latin1()), 704 reinterpret_cast<const unsigned char *>(pw->latin1()),
705 pw->length(), 705 pw->length(),
706 keyHash); 706 keyHash);
707 if (err != e_success) 707 if (err != e_success)
708 return e_hashNotImpl; 708 return e_hashNotImpl;
709 if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) 709 if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen)
710 != static_cast<Q_LONG>(hashLen)) { 710 != static_cast<Q_LONG>(hashLen)) {
711 delete [] buf; 711 delete [] buf;
712 return e_hashNotImpl; 712 return e_hashNotImpl;
713 } 713 }
714 delete [] buf; 714 delete [] buf;
715 break; 715 break;
716 } 716 }
717 default: { 717 default: {
718 return e_hashNotImpl; 718 return e_hashNotImpl;
719 } } 719 } }
720 return e_success; 720 return e_success;
721} 721}
722 722
723PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, 723PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress,
724 unsigned int *headerLength, char *dataHashType, 724 unsigned int *headerLength, char *dataHashType,
725 string *dataHash, QFile *f) 725 string *dataHash, QFile *f)
726{ 726{
727 PWM_ASSERT(cryptAlgo); 727 PWM_ASSERT(cryptAlgo);
728 PWM_ASSERT(pw); 728 PWM_ASSERT(pw);
729 PWM_ASSERT(headerLength); 729 PWM_ASSERT(headerLength);
730 PWM_ASSERT(dataHashType); 730 PWM_ASSERT(dataHashType);
731 PWM_ASSERT(dataHash); 731 PWM_ASSERT(dataHash);
732 PWM_ASSERT(f); 732 PWM_ASSERT(f);
733 int tmpRet; 733 int tmpRet;
734 // check "magic" header 734 // check "magic" header
735 const char magicHdr[] = FILE_ID_HEADER; 735 const char magicHdr[] = FILE_ID_HEADER;
736 const int hdrLen = array_size(magicHdr) - 1; 736 const int hdrLen = array_size(magicHdr) - 1;
737 char tmp[hdrLen]; 737 char tmp[hdrLen];
738 if (f->readBlock(tmp, hdrLen) != hdrLen) 738 if (f->readBlock(tmp, hdrLen) != hdrLen)
739 return e_readFile; 739 return e_readFile;
740 if (memcmp(tmp, magicHdr, hdrLen) != 0) 740 if (memcmp(tmp, magicHdr, hdrLen) != 0)
741 return e_fileFormat; 741 return e_fileFormat;
742 // read and check file ver 742 // read and check file ver
743 int fileV = f->getch(); 743 int fileV = f->getch();
744 if (fileV == -1) 744 if (fileV == -1)
745 return e_fileFormat; 745 return e_fileFormat;
746 if (fileV != PWM_FILE_VER) 746 if (fileV != PWM_FILE_VER)
747 return e_fileVer; 747 return e_fileVer;
748 // read hash hash type 748 // read hash hash type
749 int keyHash = f->getch(); 749 int keyHash = f->getch();
750 if (keyHash == -1) 750 if (keyHash == -1)
751 return e_fileFormat; 751 return e_fileFormat;
752 // read data hash type 752 // read data hash type
753 tmpRet = f->getch(); 753 tmpRet = f->getch();
754 if (tmpRet == -1) 754 if (tmpRet == -1)
755 return e_fileFormat; 755 return e_fileFormat;
756 *dataHashType = tmpRet; 756 *dataHashType = tmpRet;
757 // read crypt algo 757 // read crypt algo
758 tmpRet = f->getch(); 758 tmpRet = f->getch();
759 if (tmpRet == -1) 759 if (tmpRet == -1)
760 return e_fileFormat; 760 return e_fileFormat;
761 *cryptAlgo = tmpRet; 761 *cryptAlgo = tmpRet;
762 // get compression-algo 762 // get compression-algo
763 tmpRet = f->getch(); 763 tmpRet = f->getch();
764 if (tmpRet == -1) 764 if (tmpRet == -1)
765 return e_fileFormat; 765 return e_fileFormat;
766 *compress = tmpRet; 766 *compress = tmpRet;
767 // get the MPW-flag 767 // get the MPW-flag
768 int mpw_flag = f->getch(); 768 int mpw_flag = f->getch();
769 if (mpw_flag == -1) 769 if (mpw_flag == -1)
770 return e_fileFormat; 770 return e_fileFormat;
771 if (mpw_flag == 0x01) 771 if (mpw_flag == 0x01)
772 setDocStatFlag(DOC_STAT_USE_CHIPCARD); 772 setDocStatFlag(DOC_STAT_USE_CHIPCARD);
773 else 773 else
774 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); 774 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD);
775 // skip the "RESERVED"-bytes 775 // skip the "RESERVED"-bytes
776 if (!(f->at(f->at() + 64))) 776 if (!(f->at(f->at() + 64)))
777 return e_fileFormat; 777 return e_fileFormat;
778 778
779 *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 779 *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
780 if (*pw == "") { 780 if (*pw == "") {
781 /* the user didn't give a master-password 781 /* the user didn't give a master-password
782 * or didn't insert a chipcard 782 * or didn't insert a chipcard
783 */ 783 */
784 return e_noPw; 784 return e_noPw;
785 } 785 }
786 // verify key-hash 786 // verify key-hash
787 switch (keyHash) { 787 switch (keyHash) {
788 case PWM_HASH_SHA1: { 788 case PWM_HASH_SHA1: {
789 // read hash from header 789 // read hash from header
790 const int hashLen = SHA1_HASH_LEN_BYTE; 790 const int hashLen = SHA1_HASH_LEN_BYTE;
791 string readHash; 791 string readHash;
792 int i; 792 int i;
793 for (i = 0; i < hashLen; ++i) 793 for (i = 0; i < hashLen; ++i)
794 readHash.push_back(f->getch()); 794 readHash.push_back(f->getch());
795 Sha1 hash; 795 Sha1 hash;
796 hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); 796 hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length());
797 string ret = hash.sha1_read(); 797 string ret = hash.sha1_read();
798 if (ret != readHash) 798 if (ret != readHash)
799 return e_wrongPw;// hash doesn't match (wrong key) 799 return e_wrongPw;// hash doesn't match (wrong key)
800 break; 800 break;
801 } 801 }
802 case PWM_HASH_SHA256: 802 case PWM_HASH_SHA256:
803 /*... fall through */ 803 /*... fall through */
804 case PWM_HASH_SHA384: 804 case PWM_HASH_SHA384:
805 case PWM_HASH_SHA512: 805 case PWM_HASH_SHA512:
806 case PWM_HASH_MD5: 806 case PWM_HASH_MD5:
807 case PWM_HASH_RMD160: 807 case PWM_HASH_RMD160:
808 case PWM_HASH_TIGER: { 808 case PWM_HASH_TIGER: {
809 if (!LibGCryptIf::available()) 809 if (!LibGCryptIf::available())
810 return e_hashNotImpl; 810 return e_hashNotImpl;
811 LibGCryptIf gc; 811 LibGCryptIf gc;
812 PwMerror err; 812 PwMerror err;
813 unsigned char *buf; 813 unsigned char *buf;
814 size_t hashLen; 814 size_t hashLen;
815 err = gc.hash(&buf, 815 err = gc.hash(&buf,
816 &hashLen, 816 &hashLen,
817 reinterpret_cast<const unsigned char *>(pw->latin1()), 817 reinterpret_cast<const unsigned char *>(pw->latin1()),
818 pw->length(), 818 pw->length(),
819 keyHash); 819 keyHash);
820 if (err != e_success) 820 if (err != e_success)
821 return e_hashNotImpl; 821 return e_hashNotImpl;
822 string calcHash(reinterpret_cast<const char *>(buf), 822 string calcHash(reinterpret_cast<const char *>(buf),
823 static_cast<string::size_type>(hashLen)); 823 static_cast<string::size_type>(hashLen));
824 delete [] buf; 824 delete [] buf;
825 // read hash from header 825 // read hash from header
826 string readHash; 826 string readHash;
827 size_t i; 827 size_t i;
828 for (i = 0; i < hashLen; ++i) 828 for (i = 0; i < hashLen; ++i)
829 readHash.push_back(f->getch()); 829 readHash.push_back(f->getch());
830 if (calcHash != readHash) 830 if (calcHash != readHash)
831 return e_wrongPw;// hash doesn't match (wrong key) 831 return e_wrongPw;// hash doesn't match (wrong key)
832 break; 832 break;
833 } 833 }
834 default: { 834 default: {
835 return e_hashNotImpl; 835 return e_hashNotImpl;
836 } } 836 } }
837 // read the data-hash from the file 837 // read the data-hash from the file
838 unsigned int hashLen, i; 838 unsigned int hashLen, i;
839 switch (*dataHashType) { 839 switch (*dataHashType) {
840 case PWM_HASH_SHA1: 840 case PWM_HASH_SHA1:
841 hashLen = SHA1_HASH_LEN_BYTE; 841 hashLen = SHA1_HASH_LEN_BYTE;
842 break; 842 break;
843 case PWM_HASH_SHA256: 843 case PWM_HASH_SHA256:
844 /*... fall through */ 844 /*... fall through */
845 case PWM_HASH_SHA384: 845 case PWM_HASH_SHA384:
846 case PWM_HASH_SHA512: 846 case PWM_HASH_SHA512:
847 case PWM_HASH_MD5: 847 case PWM_HASH_MD5:
848 case PWM_HASH_RMD160: 848 case PWM_HASH_RMD160:
849 case PWM_HASH_TIGER: { 849 case PWM_HASH_TIGER: {
850 if (!LibGCryptIf::available()) 850 if (!LibGCryptIf::available())
851 return e_hashNotImpl; 851 return e_hashNotImpl;
852 LibGCryptIf gc; 852 LibGCryptIf gc;
853 hashLen = gc.hashLength(*dataHashType); 853 hashLen = gc.hashLength(*dataHashType);
854 if (hashLen == 0) 854 if (hashLen == 0)
855 return e_hashNotImpl; 855 return e_hashNotImpl;
856 break; 856 break;
857 } 857 }
858 default: 858 default:
859 return e_hashNotImpl; 859 return e_hashNotImpl;
860 } 860 }
861 *dataHash = ""; 861 *dataHash = "";
862 for (i = 0; i < hashLen; ++i) { 862 for (i = 0; i < hashLen; ++i) {
863 tmpRet = f->getch(); 863 tmpRet = f->getch();
864 if (tmpRet == -1) 864 if (tmpRet == -1)
865 return e_fileFormat; 865 return e_fileFormat;
866 dataHash->push_back(static_cast<char>(tmpRet)); 866 dataHash->push_back(static_cast<char>(tmpRet));
867 } 867 }
868 *headerLength = f->at(); 868 *headerLength = f->at();
869#ifndef PWM_EMBEDDED 869#ifndef PWM_EMBEDDED
870 printDebug(string("opening file { compress: ") 870 printDebug(string("opening file { compress: ")
871 + tostr(static_cast<int>(*compress)) + " cryptAlgo: " 871 + tostr(static_cast<int>(*compress)) + " cryptAlgo: "
872 + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " 872 + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: "
873 + tostr(static_cast<int>(keyHash)) 873 + tostr(static_cast<int>(keyHash))
874 + " }"); 874 + " }");
875#else 875#else
876 printDebug(string("opening file { compress: ") 876 printDebug(string("opening file { compress: ")
877 + tostr((int)(*compress)) + " cryptAlgo: " 877 + tostr((int)(*compress)) + " cryptAlgo: "
878 + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " 878 + tostr((int)(*cryptAlgo)) + " keyHashAlgo: "
879 + tostr((int)(keyHash)) 879 + tostr((int)(keyHash))
880 + " }"); 880 + " }");
881#endif 881#endif
882 882
883 return e_success; 883 return e_success;
884} 884}
885 885
886PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) 886PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f)
887{ 887{
888 PWM_ASSERT(d); 888 PWM_ASSERT(d);
889 PWM_ASSERT(f); 889 PWM_ASSERT(f);
890 890
891 switch (dataHash) { 891 switch (dataHash) {
892 case PWM_HASH_SHA1: { 892 case PWM_HASH_SHA1: {
893 const int hashLen = SHA1_HASH_LEN_BYTE; 893 const int hashLen = SHA1_HASH_LEN_BYTE;
894 Sha1 h; 894 Sha1 h;
895 h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size()); 895 h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size());
896 string hRet = h.sha1_read(); 896 string hRet = h.sha1_read();
897 if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) 897 if (f->writeBlock(hRet.c_str(), hashLen) != hashLen)
898 return e_writeFile; 898 return e_writeFile;
899 break; 899 break;
900 } 900 }
901 case PWM_HASH_SHA256: 901 case PWM_HASH_SHA256:
902 /*... fall through */ 902 /*... fall through */
903 case PWM_HASH_SHA384: 903 case PWM_HASH_SHA384:
904 case PWM_HASH_SHA512: 904 case PWM_HASH_SHA512:
905 case PWM_HASH_MD5: 905 case PWM_HASH_MD5:
906 case PWM_HASH_RMD160: 906 case PWM_HASH_RMD160:
907 case PWM_HASH_TIGER: { 907 case PWM_HASH_TIGER: {
908 if (!LibGCryptIf::available()) 908 if (!LibGCryptIf::available())
909 return e_hashNotImpl; 909 return e_hashNotImpl;
910 LibGCryptIf gc; 910 LibGCryptIf gc;
911 PwMerror err; 911 PwMerror err;
912 unsigned char *buf; 912 unsigned char *buf;
913 size_t hashLen; 913 size_t hashLen;
914 err = gc.hash(&buf, 914 err = gc.hash(&buf,
915 &hashLen, 915 &hashLen,
916 reinterpret_cast<const unsigned char *>(d->c_str()), 916 reinterpret_cast<const unsigned char *>(d->c_str()),
917 d->size(), 917 d->size(),
918 dataHash); 918 dataHash);
919 if (err != e_success) 919 if (err != e_success)
920 return e_hashNotImpl; 920 return e_hashNotImpl;
921 if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) 921 if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen)
922 != static_cast<Q_LONG>(hashLen)) { 922 != static_cast<Q_LONG>(hashLen)) {
923 delete [] buf; 923 delete [] buf;
924 return e_hashNotImpl; 924 return e_hashNotImpl;
925 } 925 }
926 delete [] buf; 926 delete [] buf;
927 break; 927 break;
928 } 928 }
929 default: { 929 default: {
930 return e_hashNotImpl; 930 return e_hashNotImpl;
931 } } 931 } }
932 932
933 return e_success; 933 return e_success;
934} 934}
935 935
936bool PwMDoc::backupFile(const QString &filePath) 936bool PwMDoc::backupFile(const QString &filePath)
937{ 937{
938 QFileInfo fi(filePath); 938 QFileInfo fi(filePath);
939 if (!fi.exists()) 939 if (!fi.exists())
940 return true; // Yes, true is correct. 940 return true; // Yes, true is correct.
941 QString pathOnly(fi.dirPath(true)); 941 QString pathOnly(fi.dirPath(true));
942 QString nameOnly(fi.fileName()); 942 QString nameOnly(fi.fileName());
943 QString backupPath = pathOnly 943 QString backupPath = pathOnly
944 + "/~" 944 + "/~"
945 + nameOnly 945 + nameOnly
946 + ".backup"; 946 + ".backup";
947 return copyFile(filePath, backupPath); 947 return copyFile(filePath, backupPath);
948} 948}
949 949
950bool PwMDoc::copyFile(const QString &src, const QString &dst) 950bool PwMDoc::copyFile(const QString &src, const QString &dst)
951{ 951{
952 QFileInfo fi(src); 952 QFileInfo fi(src);
953 if (!fi.exists()) 953 if (!fi.exists())
954 return false; 954 return false;
955 if (QFile::exists(dst)) { 955 if (QFile::exists(dst)) {
956 if (!QFile::remove(dst)) 956 if (!QFile::remove(dst))
957 return false; 957 return false;
958 } 958 }
959 QFile srcFd(src); 959 QFile srcFd(src);
960 if (!srcFd.open(IO_ReadOnly)) 960 if (!srcFd.open(IO_ReadOnly))
961 return false; 961 return false;
962 QFile dstFd(dst); 962 QFile dstFd(dst);
963 if (!dstFd.open(IO_ReadWrite)) { 963 if (!dstFd.open(IO_ReadWrite)) {
964 srcFd.close(); 964 srcFd.close();
965 return false; 965 return false;
966 } 966 }
967 const int tmpBuf_size = 512; 967 const int tmpBuf_size = 512;
968 char tmpBuf[tmpBuf_size]; 968 char tmpBuf[tmpBuf_size];
969 Q_LONG bytesRead, bytesWritten; 969 Q_LONG bytesRead, bytesWritten;
970 970
971 while (!srcFd.atEnd()) { 971 while (!srcFd.atEnd()) {
972 bytesRead = srcFd.readBlock(tmpBuf, 972 bytesRead = srcFd.readBlock(tmpBuf,
973 static_cast<Q_ULONG>(tmpBuf_size)); 973 static_cast<Q_ULONG>(tmpBuf_size));
974 if (bytesRead == -1) { 974 if (bytesRead == -1) {
975 srcFd.close(); 975 srcFd.close();
976 dstFd.close(); 976 dstFd.close();
977 return false; 977 return false;
978 } 978 }
979 bytesWritten = dstFd.writeBlock(tmpBuf, 979 bytesWritten = dstFd.writeBlock(tmpBuf,
980 static_cast<Q_ULONG>(bytesRead)); 980 static_cast<Q_ULONG>(bytesRead));
981 if (bytesWritten != bytesRead) { 981 if (bytesWritten != bytesRead) {
982 srcFd.close(); 982 srcFd.close();
983 dstFd.close(); 983 dstFd.close();
984 return false; 984 return false;
985 } 985 }
986 } 986 }
987 srcFd.close(); 987 srcFd.close();
988 dstFd.close(); 988 dstFd.close();
989 return true; 989 return true;
990} 990}
991 991
992PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, 992PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d,
993 bool dontFlagDirty, bool updateMeta) 993 bool dontFlagDirty, bool updateMeta)
994{ 994{
995 PWM_ASSERT(d); 995 PWM_ASSERT(d);
996 unsigned int cat = 0; 996 unsigned int cat = 0;
997 997
998 if (isDeepLocked()) { 998 if (isDeepLocked()) {
999 PwMerror ret; 999 PwMerror ret;
1000 ret = deepLock(false); 1000 ret = deepLock(false);
1001 if (ret != e_success) 1001 if (ret != e_success)
1002 return e_lock; 1002 return e_lock;
1003 } 1003 }
1004 1004
1005 addCategory(category, &cat); 1005 addCategory(category, &cat);
1006 1006
1007 if (numEntries(category) >= maxEntries) 1007 if (numEntries(category) >= maxEntries)
1008 return e_maxAllowedEntr; 1008 return e_maxAllowedEntr;
1009 1009
1010 vector<unsigned int> foundPositions; 1010 vector<unsigned int> foundPositions;
1011 /* historically this was: 1011 /* historically this was:
1012 *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | 1012 *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME |
1013 * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; 1013 * SEARCH_IN_URL | SEARCH_IN_LAUNCHER;
1014 * But for now we only search in desc. 1014 * But for now we only search in desc.
1015 * That's a tweak to be KWallet compatible. But it should not add 1015 * That's a tweak to be KWallet compatible. But it should not add
1016 * usability-drop onto PwManager, does it? 1016 * usability-drop onto PwManager, does it?
1017 * (And yes, "int" was a bug. Correct is "unsigned int") 1017 * (And yes, "int" was a bug. Correct is "unsigned int")
1018 */ 1018 */
1019 const unsigned int searchIn = SEARCH_IN_DESC; 1019 const unsigned int searchIn = SEARCH_IN_DESC;
1020 findEntry(cat, *d, searchIn, &foundPositions, true); 1020 findEntry(cat, *d, searchIn, &foundPositions, true);
1021 if (foundPositions.size()) { 1021 if (foundPositions.size()) {
1022 // DOH! We found this entry. 1022 // DOH! We found this entry.
1023 return e_entryExists; 1023 return e_entryExists;
1024 } 1024 }
1025 1025
1026 d->listViewPos = -1; 1026 d->listViewPos = -1;
1027 d->lockStat = conf()->confGlobNewEntrLockStat(); 1027 d->lockStat = conf()->confGlobNewEntrLockStat();
1028 if (updateMeta) { 1028 if (updateMeta) {
1029 d->meta.create = QDateTime::currentDateTime(); 1029 d->meta.create = QDateTime::currentDateTime();
1030 d->meta.update = d->meta.create; 1030 d->meta.update = d->meta.create;
1031 } 1031 }
1032 dti.dta[cat].d.push_back(*d); 1032 dti.dta[cat].d.push_back(*d);
1033 1033
1034 delAllEmptyCat(true); 1034 delAllEmptyCat(true);
1035 1035
1036 if (!dontFlagDirty) 1036 if (!dontFlagDirty)
1037 flagDirty(); 1037 flagDirty();
1038 return e_success; 1038 return e_success;
1039} 1039}
1040 1040
1041PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, 1041PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex,
1042 bool checkIfExist) 1042 bool checkIfExist)
1043{ 1043{
1044 if (isDeepLocked()) { 1044 if (isDeepLocked()) {
1045 PwMerror ret; 1045 PwMerror ret;
1046 ret = deepLock(false); 1046 ret = deepLock(false);
1047 if (ret != e_success) 1047 if (ret != e_success)
1048 return e_lock; 1048 return e_lock;
1049 } 1049 }
1050 if (checkIfExist) { 1050 if (checkIfExist) {
1051 if (findCategory(category, categoryIndex)) 1051 if (findCategory(category, categoryIndex))
1052 return e_categoryExists; 1052 return e_categoryExists;
1053 } 1053 }
1054 PwMCategoryItem item; 1054 PwMCategoryItem item;
1055 item.name = category.latin1(); 1055 item.name = category.latin1();
1056 dti.dta.push_back(item); 1056 dti.dta.push_back(item);
1057 if (categoryIndex) 1057 if (categoryIndex)
1058 *categoryIndex = dti.dta.size() - 1; 1058 *categoryIndex = dti.dta.size() - 1;
1059 return e_success; 1059 return e_success;
1060} 1060}
1061 1061
1062bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) 1062bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty)
1063{ 1063{
1064 unsigned int cat = 0; 1064 unsigned int cat = 0;
1065 1065
1066 if (!findCategory(category, &cat)) { 1066 if (!findCategory(category, &cat)) {
1067 BUG(); 1067 BUG();
1068 return false; 1068 return false;
1069 } 1069 }
1070 1070
1071 return delEntry(cat, index, dontFlagDirty); 1071 return delEntry(cat, index, dontFlagDirty);
1072} 1072}
1073 1073
1074bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) 1074bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty)
1075{ 1075{
1076 if (isDeepLocked()) 1076 if (isDeepLocked())
1077 return false; 1077 return false;
1078 if (index > dti.dta[category].d.size() - 1) 1078 if (index > dti.dta[category].d.size() - 1)
1079 return false; 1079 return false;
1080 getDataChangedLock(); 1080 getDataChangedLock();
1081 if (!lockAt(category, index, false)) { 1081 if (!lockAt(category, index, false)) {
1082 putDataChangedLock(); 1082 putDataChangedLock();
1083 return false; 1083 return false;
1084 } 1084 }
1085 putDataChangedLock(); 1085 putDataChangedLock();
1086 int lvPos = dti.dta[category].d[index].listViewPos; 1086 int lvPos = dti.dta[category].d[index].listViewPos;
1087 1087
1088 // delete entry 1088 // delete entry
1089 dti.dta[category].d.erase(dti.dta[category].d.begin() + index); 1089 dti.dta[category].d.erase(dti.dta[category].d.begin() + index);
1090 1090
1091 unsigned int i, entries = numEntries(category); 1091 unsigned int i, entries = numEntries(category);
1092 if (!entries) { 1092 if (!entries) {
1093 // no more entries in this category, so 1093 // no more entries in this category, so
1094 // we can delete it, too. 1094 // we can delete it, too.
1095 BUG_ON(!delCategory(category)); 1095 BUG_ON(!delCategory(category));
1096 // delCategory() flags it dirty, so we need not to do so. 1096 // delCategory() flags it dirty, so we need not to do so.
1097 return true; 1097 return true;
1098 } 1098 }
1099 for (i = 0; i < entries; ++i) { 1099 for (i = 0; i < entries; ++i) {
1100 // decrement all listViewPositions that are greater than the deleted. 1100 // decrement all listViewPositions that are greater than the deleted.
1101 if (dti.dta[category].d[i].listViewPos > lvPos) 1101 if (dti.dta[category].d[i].listViewPos > lvPos)
1102 --dti.dta[category].d[i].listViewPos; 1102 --dti.dta[category].d[i].listViewPos;
1103 } 1103 }
1104 1104
1105 if (!dontFlagDirty) 1105 if (!dontFlagDirty)
1106 flagDirty(); 1106 flagDirty();
1107 return true; 1107 return true;
1108} 1108}
1109 1109
1110bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, 1110bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory,
1111 unsigned int index, PwMDataItem *d, bool updateMeta) 1111 unsigned int index, PwMDataItem *d, bool updateMeta)
1112{ 1112{
1113 PWM_ASSERT(d); 1113 PWM_ASSERT(d);
1114 unsigned int oldCat = 0; 1114 unsigned int oldCat = 0;
1115 1115
1116 if (!findCategory(oldCategory, &oldCat)) { 1116 if (!findCategory(oldCategory, &oldCat)) {
1117 BUG(); 1117 BUG();
1118 return false; 1118 return false;
1119 } 1119 }
1120 1120
1121 return editEntry(oldCat, newCategory, index, d, updateMeta); 1121 return editEntry(oldCat, newCategory, index, d, updateMeta);
1122} 1122}
1123 1123
1124bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, 1124bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory,
1125 unsigned int index, PwMDataItem *d, bool updateMeta) 1125 unsigned int index, PwMDataItem *d, bool updateMeta)
1126{ 1126{
1127 if (isDeepLocked()) 1127 if (isDeepLocked())
1128 return false; 1128 return false;
1129 if (updateMeta) { 1129 if (updateMeta) {
1130 d->meta.update = QDateTime::currentDateTime(); 1130 d->meta.update = QDateTime::currentDateTime();
1131 if (d->meta.create.isNull()) { 1131 if (d->meta.create.isNull()) {
1132 d->meta.create = d->meta.update; 1132 d->meta.create = d->meta.update;
1133 } 1133 }
1134 } 1134 }
1135 if (dti.dta[oldCategory].name != newCategory.latin1()) { 1135 if (dti.dta[oldCategory].name != newCategory.latin1()) {
1136 // the user changed the category. 1136 // the user changed the category.
1137 PwMerror ret; 1137 PwMerror ret;
1138 d->rev = 0; 1138 d->rev = 0;
1139 ret = addEntry(newCategory, d, true, false); 1139 ret = addEntry(newCategory, d, true, false);
1140 if (ret != e_success) 1140 if (ret != e_success)
1141 return false; 1141 return false;
1142 if (!delEntry(oldCategory, index, true)) 1142 if (!delEntry(oldCategory, index, true))
1143 return false; 1143 return false;
1144 } else { 1144 } else {
1145 d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. 1145 d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter.
1146 dti.dta[oldCategory].d[index] = *d; 1146 dti.dta[oldCategory].d[index] = *d;
1147 } 1147 }
1148 flagDirty(); 1148 flagDirty();
1149 return true; 1149 return true;
1150} 1150}
1151 1151
1152unsigned int PwMDoc::numEntries(const QString &category) 1152unsigned int PwMDoc::numEntries(const QString &category)
1153{ 1153{
1154 unsigned int cat = 0; 1154 unsigned int cat = 0;
1155 1155
1156 if (!findCategory(category, &cat)) { 1156 if (!findCategory(category, &cat)) {
1157 BUG(); 1157 BUG();
1158 return 0; 1158 return 0;
1159 } 1159 }
1160 1160
1161 return numEntries(cat); 1161 return numEntries(cat);
1162} 1162}
1163 1163
1164bool PwMDoc::serializeDta(string *d) 1164bool PwMDoc::serializeDta(string *d)
1165{ 1165{
1166 PWM_ASSERT(d); 1166 PWM_ASSERT(d);
1167 Serializer ser; 1167 Serializer ser;
1168 if (!ser.serialize(dti)) 1168 if (!ser.serialize(dti))
1169 return false; 1169 return false;
1170 d->assign(ser.getXml()); 1170 d->assign(ser.getXml());
1171 if (!d->size()) 1171 if (!d->size())
1172 return false; 1172 return false;
1173 return true; 1173 return true;
1174} 1174}
1175 1175
1176bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) 1176bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked)
1177{ 1177{
1178 PWM_ASSERT(d); 1178 PWM_ASSERT(d);
1179#ifndef PWM_EMBEDDED 1179#ifndef PWM_EMBEDDED
1180 try { 1180 try {
1181 1181
1182 Serializer ser(d->c_str()); 1182 Serializer ser(d->c_str());
1183 ser.setDefaultLockStat(entriesLocked); 1183 ser.setDefaultLockStat(entriesLocked);
1184 if (!ser.deSerialize(&dti)) 1184 if (!ser.deSerialize(&dti))
1185 return false; 1185 return false;
1186 } catch (PwMException) { 1186 } catch (PwMException) {
1187 return false; 1187 return false;
1188 } 1188 }
1189#else 1189#else
1190 Serializer ser(d->c_str()); 1190 Serializer ser(d->c_str());
1191 ser.setDefaultLockStat(entriesLocked); 1191 ser.setDefaultLockStat(entriesLocked);
1192 if (!ser.deSerialize(&dti)) 1192 if (!ser.deSerialize(&dti))
1193 return false; 1193 return false;
1194#endif 1194#endif
1195 1195
1196 emitDataChanged(this); 1196 emitDataChanged(this);
1197 return true; 1197 return true;
1198} 1198}
1199 1199
1200bool PwMDoc::getEntry(const QString &category, unsigned int index, 1200bool PwMDoc::getEntry(const QString &category, unsigned int index,
1201 PwMDataItem * d, bool unlockIfLocked) 1201 PwMDataItem * d, bool unlockIfLocked)
1202{ 1202{
1203 PWM_ASSERT(d); 1203 PWM_ASSERT(d);
1204 unsigned int cat = 0; 1204 unsigned int cat = 0;
1205 1205
1206 if (!findCategory(category, &cat)) { 1206 if (!findCategory(category, &cat)) {
1207 BUG(); 1207 BUG();
1208 return false; 1208 return false;
1209 } 1209 }
1210 1210
1211 return getEntry(cat, index, d, unlockIfLocked); 1211 return getEntry(cat, index, d, unlockIfLocked);
1212} 1212}
1213 1213
1214bool PwMDoc::getEntry(unsigned int category, unsigned int index, 1214bool PwMDoc::getEntry(unsigned int category, unsigned int index,
1215 PwMDataItem *d, bool unlockIfLocked) 1215 PwMDataItem *d, bool unlockIfLocked)
1216{ 1216{
1217 if (index > dti.dta[category].d.size() - 1) 1217 if (index > dti.dta[category].d.size() - 1)
1218 return false; 1218 return false;
1219 1219
1220 bool locked = isLocked(category, index); 1220 bool locked = isLocked(category, index);
1221 if (locked) { 1221 if (locked) {
1222 /* this entry is locked. We don't return a password, 1222 /* this entry is locked. We don't return a password,
1223 * until it's unlocked by the user by inserting 1223 * until it's unlocked by the user by inserting
1224 * chipcard or entering the mpw 1224 * chipcard or entering the mpw
1225 */ 1225 */
1226 if (unlockIfLocked) { 1226 if (unlockIfLocked) {
1227 if (!lockAt(category, index, false)) { 1227 if (!lockAt(category, index, false)) {
1228 return false; 1228 return false;
1229 } 1229 }
1230 locked = false; 1230 locked = false;
1231 } 1231 }
1232 } 1232 }
1233 1233
1234 *d = dti.dta[category].d[index]; 1234 *d = dti.dta[category].d[index];
1235 if (locked) 1235 if (locked)
1236 d->pw = LOCKED_STRING.latin1(); 1236 d->pw = LOCKED_STRING.latin1();
1237 1237
1238 return true; 1238 return true;
1239} 1239}
1240 1240
1241PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, 1241PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos,
1242 string *foundComment) 1242 string *foundComment)
1243{ 1243{
1244 PWM_ASSERT(foundComment); 1244 PWM_ASSERT(foundComment);
1245 unsigned int cat = 0; 1245 unsigned int cat = 0;
1246 1246
1247 if (!findCategory(category, &cat)) 1247 if (!findCategory(category, &cat))
1248 return e_invalidArg; 1248 return e_invalidArg;
1249 1249
1250 unsigned int i, entries = numEntries(cat); 1250 unsigned int i, entries = numEntries(cat);
1251 for (i = 0; i < entries; ++i) { 1251 for (i = 0; i < entries; ++i) {
1252 if (dti.dta[cat].d[i].listViewPos == listViewPos) { 1252 if (dti.dta[cat].d[i].listViewPos == listViewPos) {
1253 *foundComment = dti.dta[cat].d[i].comment; 1253 *foundComment = dti.dta[cat].d[i].comment;
1254 if (dti.dta[cat].d[i].binary) 1254 if (dti.dta[cat].d[i].binary)
1255 return e_binEntry; 1255 return e_binEntry;
1256 return e_normalEntry; 1256 return e_normalEntry;
1257 } 1257 }
1258 } 1258 }
1259 BUG(); 1259 BUG();
1260 return e_generic; 1260 return e_generic;
1261} 1261}
1262 1262
1263bool PwMDoc::compressDta(string *d, char algo) 1263bool PwMDoc::compressDta(string *d, char algo)
1264{ 1264{
1265 PWM_ASSERT(d); 1265 PWM_ASSERT(d);
1266 switch (algo) { 1266 switch (algo) {
1267 case PWM_COMPRESS_GZIP: { 1267 case PWM_COMPRESS_GZIP: {
1268 CompressGzip comp; 1268 CompressGzip comp;
1269 return comp.compress(d); 1269 return comp.compress(d);
1270 } 1270 }
1271#ifndef PWM_EMBEDDED 1271#ifndef PWM_EMBEDDED
1272 case PWM_COMPRESS_BZIP2: { 1272 case PWM_COMPRESS_BZIP2: {
1273 CompressBzip2 comp; 1273 CompressBzip2 comp;
1274 return comp.compress(d); 1274 return comp.compress(d);
1275 } 1275 }
1276#endif 1276#endif
1277 case PWM_COMPRESS_NONE: { 1277 case PWM_COMPRESS_NONE: {
1278 return true; 1278 return true;
1279 } default: { 1279 } default: {
1280 BUG(); 1280 BUG();
1281 } 1281 }
1282 } 1282 }
1283 return false; 1283 return false;
1284} 1284}
1285 1285
1286bool PwMDoc::decompressDta(string *d, char algo) 1286bool PwMDoc::decompressDta(string *d, char algo)
1287{ 1287{
1288 PWM_ASSERT(d); 1288 PWM_ASSERT(d);
1289 switch (algo) { 1289 switch (algo) {
1290 case PWM_COMPRESS_GZIP: { 1290 case PWM_COMPRESS_GZIP: {
1291 CompressGzip comp; 1291 CompressGzip comp;
1292 return comp.decompress(d); 1292 return comp.decompress(d);
1293 } 1293 }
1294#ifndef PWM_EMBEDDED 1294#ifndef PWM_EMBEDDED
1295 case PWM_COMPRESS_BZIP2: { 1295 case PWM_COMPRESS_BZIP2: {
1296 CompressBzip2 comp; 1296 CompressBzip2 comp;
1297 return comp.decompress(d); 1297 return comp.decompress(d);
1298 } 1298 }
1299#endif 1299#endif
1300 case PWM_COMPRESS_NONE: { 1300 case PWM_COMPRESS_NONE: {
1301 return true; 1301 return true;
1302 } 1302 }
1303 } 1303 }
1304 return false; 1304 return false;
1305} 1305}
1306 1306
1307PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) 1307PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo)
1308{ 1308{
1309 PWM_ASSERT(d); 1309 PWM_ASSERT(d);
1310 PWM_ASSERT(pw); 1310 PWM_ASSERT(pw);
1311 PWM_ASSERT(f); 1311 PWM_ASSERT(f);
1312 1312
1313 size_t encSize; 1313 size_t encSize;
1314 byte *encrypted = 0; 1314 byte *encrypted = 0;
1315 1315
1316 switch (algo) { 1316 switch (algo) {
1317 case PWM_CRYPT_BLOWFISH: { 1317 case PWM_CRYPT_BLOWFISH: {
1318 Blowfish::padNull(d); 1318 Blowfish::padNull(d);
1319 encSize = d->length(); 1319 encSize = d->length();
1320 encrypted = new byte[encSize]; 1320 encrypted = new byte[encSize];
1321 Blowfish bf; 1321 Blowfish bf;
1322 if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { 1322 if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) {
1323 delete [] encrypted; 1323 delete [] encrypted;
1324 return e_weakPw; 1324 return e_weakPw;
1325 } 1325 }
1326 bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); 1326 bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize);
1327 break; 1327 break;
1328 } 1328 }
1329 case PWM_CRYPT_AES128: 1329 case PWM_CRYPT_AES128:
1330 /*... fall through */ 1330 /*... fall through */
1331 case PWM_CRYPT_AES192: 1331 case PWM_CRYPT_AES192:
1332 case PWM_CRYPT_AES256: 1332 case PWM_CRYPT_AES256:
1333 case PWM_CRYPT_3DES: 1333 case PWM_CRYPT_3DES:
1334 case PWM_CRYPT_TWOFISH: 1334 case PWM_CRYPT_TWOFISH:
1335 case PWM_CRYPT_TWOFISH128: { 1335 case PWM_CRYPT_TWOFISH128: {
1336 if (!LibGCryptIf::available()) 1336 if (!LibGCryptIf::available())
1337 return e_cryptNotImpl; 1337 return e_cryptNotImpl;
1338 LibGCryptIf gc; 1338 LibGCryptIf gc;
1339 PwMerror err; 1339 PwMerror err;
1340 unsigned char *plain = new unsigned char[d->length() + 1024]; 1340 unsigned char *plain = new unsigned char[d->length() + 1024];
1341 memcpy(plain, d->c_str(), d->length()); 1341 memcpy(plain, d->c_str(), d->length());
1342 err = gc.encrypt(&encrypted, 1342 err = gc.encrypt(&encrypted,
1343 &encSize, 1343 &encSize,
1344 plain, 1344 plain,
1345 d->length(), 1345 d->length(),
1346 reinterpret_cast<const unsigned char *>(pw->latin1()), 1346 reinterpret_cast<const unsigned char *>(pw->latin1()),
1347 pw->length(), 1347 pw->length(),
1348 algo); 1348 algo);
1349 delete [] plain; 1349 delete [] plain;
1350 if (err != e_success) 1350 if (err != e_success)
1351 return e_cryptNotImpl; 1351 return e_cryptNotImpl;
1352 break; 1352 break;
1353 } 1353 }
1354 default: { 1354 default: {
1355 delete_ifnot_null_array(encrypted); 1355 delete_ifnot_null_array(encrypted);
1356 return e_cryptNotImpl; 1356 return e_cryptNotImpl;
1357 } } 1357 } }
1358 1358
1359 // write encrypted data to file 1359 // write encrypted data to file
1360 if (f->writeBlock(reinterpret_cast<const char *>(encrypted), 1360 if (f->writeBlock(reinterpret_cast<const char *>(encrypted),
1361 static_cast<Q_ULONG>(encSize)) 1361 static_cast<Q_ULONG>(encSize))
1362 != static_cast<Q_LONG>(encSize)) { 1362 != static_cast<Q_LONG>(encSize)) {
1363 delete_ifnot_null_array(encrypted); 1363 delete_ifnot_null_array(encrypted);
1364 return e_writeFile; 1364 return e_writeFile;
1365 } 1365 }
1366 delete_ifnot_null_array(encrypted); 1366 delete_ifnot_null_array(encrypted);
1367 return e_success; 1367 return e_success;
1368} 1368}
1369 1369
1370PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, 1370PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw,
1371 char algo, QFile *f) 1371 char algo, QFile *f)
1372{ 1372{
1373 PWM_ASSERT(d); 1373 PWM_ASSERT(d);
1374 PWM_ASSERT(pw); 1374 PWM_ASSERT(pw);
1375 PWM_ASSERT(f); 1375 PWM_ASSERT(f);
1376 1376
1377 unsigned int cryptLen = f->size() - pos; 1377 unsigned int cryptLen = f->size() - pos;
1378 byte *encrypted = new byte[cryptLen]; 1378 byte *encrypted = new byte[cryptLen];
1379 byte *decrypted = new byte[cryptLen]; 1379 byte *decrypted = new byte[cryptLen];
1380 1380
1381 f->at(pos); 1381 f->at(pos);
1382#ifndef PWM_EMBEDDED 1382#ifndef PWM_EMBEDDED
1383 if (f->readBlock(reinterpret_cast<char *>(encrypted), 1383 if (f->readBlock(reinterpret_cast<char *>(encrypted),
1384 static_cast<Q_ULONG>(cryptLen)) 1384 static_cast<Q_ULONG>(cryptLen))
1385 != static_cast<Q_LONG>(cryptLen)) { 1385 != static_cast<Q_LONG>(cryptLen)) {
1386 delete [] encrypted; 1386 delete [] encrypted;
1387 delete [] decrypted; 1387 delete [] decrypted;
1388 return e_readFile; 1388 return e_readFile;
1389 } 1389 }
1390#else 1390#else
1391 if (f->readBlock((char *)(encrypted), 1391 if (f->readBlock((char *)(encrypted),
1392 (unsigned long)(cryptLen)) 1392 (unsigned long)(cryptLen))
1393 != (long)(cryptLen)) { 1393 != (long)(cryptLen)) {
1394 delete [] encrypted; 1394 delete [] encrypted;
1395 delete [] decrypted; 1395 delete [] decrypted;
1396 return e_readFile; 1396 return e_readFile;
1397 } 1397 }
1398#endif 1398#endif
1399 switch (algo) { 1399 switch (algo) {
1400 case PWM_CRYPT_BLOWFISH: { 1400 case PWM_CRYPT_BLOWFISH: {
1401 Blowfish bf; 1401 Blowfish bf;
1402 bf.bf_setkey((byte *) pw->latin1(), pw->length()); 1402 bf.bf_setkey((byte *) pw->latin1(), pw->length());
1403 bf.bf_decrypt(decrypted, encrypted, cryptLen); 1403 bf.bf_decrypt(decrypted, encrypted, cryptLen);
1404 break; 1404 break;
1405 } 1405 }
1406 case PWM_CRYPT_AES128: 1406 case PWM_CRYPT_AES128:
1407 /*... fall through */ 1407 /*... fall through */
1408 case PWM_CRYPT_AES192: 1408 case PWM_CRYPT_AES192:
1409 case PWM_CRYPT_AES256: 1409 case PWM_CRYPT_AES256:
1410 case PWM_CRYPT_3DES: 1410 case PWM_CRYPT_3DES:
1411 case PWM_CRYPT_TWOFISH: 1411 case PWM_CRYPT_TWOFISH:
1412 case PWM_CRYPT_TWOFISH128: { 1412 case PWM_CRYPT_TWOFISH128: {
1413 if (!LibGCryptIf::available()) 1413 if (!LibGCryptIf::available())
1414 return e_cryptNotImpl; 1414 return e_cryptNotImpl;
1415 LibGCryptIf gc; 1415 LibGCryptIf gc;
1416 PwMerror err; 1416 PwMerror err;
1417 err = gc.decrypt(&decrypted, 1417 err = gc.decrypt(&decrypted,
1418 &cryptLen, 1418 &cryptLen,
1419 encrypted, 1419 encrypted,
1420 cryptLen, 1420 cryptLen,
1421 reinterpret_cast<const unsigned char *>(pw->latin1()), 1421 reinterpret_cast<const unsigned char *>(pw->latin1()),
1422 pw->length(), 1422 pw->length(),
1423 algo); 1423 algo);
1424 if (err != e_success) { 1424 if (err != e_success) {
1425 delete [] encrypted; 1425 delete [] encrypted;
1426 delete [] decrypted; 1426 delete [] decrypted;
1427 return e_cryptNotImpl; 1427 return e_cryptNotImpl;
1428 } 1428 }
1429 break; 1429 break;
1430 } 1430 }
1431 default: { 1431 default: {
1432 delete [] encrypted; 1432 delete [] encrypted;
1433 delete [] decrypted; 1433 delete [] decrypted;
1434 return e_cryptNotImpl; 1434 return e_cryptNotImpl;
1435 } } 1435 } }
1436 delete [] encrypted; 1436 delete [] encrypted;
1437#ifndef PWM_EMBEDDED 1437#ifndef PWM_EMBEDDED
1438 d->assign(reinterpret_cast<const char *>(decrypted), 1438 d->assign(reinterpret_cast<const char *>(decrypted),
1439 static_cast<string::size_type>(cryptLen)); 1439 static_cast<string::size_type>(cryptLen));
1440#else 1440#else
1441 d->assign((const char *)(decrypted), 1441 d->assign((const char *)(decrypted),
1442 (string::size_type)(cryptLen)); 1442 (string::size_type)(cryptLen));
1443#endif 1443#endif
1444 delete [] decrypted; 1444 delete [] decrypted;
1445 if (algo == PWM_CRYPT_BLOWFISH) { 1445 if (algo == PWM_CRYPT_BLOWFISH) {
1446 if (!Blowfish::unpadNull(d)) { 1446 if (!Blowfish::unpadNull(d)) {
1447 BUG(); 1447 BUG();
1448 return e_readFile; 1448 return e_readFile;
1449 } 1449 }
1450 } 1450 }
1451 return e_success; 1451 return e_success;
1452} 1452}
1453 1453
1454PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, 1454PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash,
1455 const string *dataStream) 1455 const string *dataStream)
1456{ 1456{
1457 PWM_ASSERT(dataHash); 1457 PWM_ASSERT(dataHash);
1458 PWM_ASSERT(dataStream); 1458 PWM_ASSERT(dataStream);
1459 switch(dataHashType) { 1459 switch(dataHashType) {
1460 case PWM_HASH_SHA1: { 1460 case PWM_HASH_SHA1: {
1461 Sha1 hash; 1461 Sha1 hash;
1462 hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); 1462 hash.sha1_write((byte*)dataStream->c_str(), dataStream->length());
1463 string ret = hash.sha1_read(); 1463 string ret = hash.sha1_read();
1464 if (ret != *dataHash) 1464 if (ret != *dataHash)
1465 return e_fileCorrupt; 1465 return e_fileCorrupt;
1466 break; 1466 break;
1467 } 1467 }
1468 case PWM_HASH_SHA256: 1468 case PWM_HASH_SHA256:
1469 /*... fall through */ 1469 /*... fall through */
1470 case PWM_HASH_SHA384: 1470 case PWM_HASH_SHA384:
1471 case PWM_HASH_SHA512: 1471 case PWM_HASH_SHA512:
1472 case PWM_HASH_MD5: 1472 case PWM_HASH_MD5:
1473 case PWM_HASH_RMD160: 1473 case PWM_HASH_RMD160:
1474 case PWM_HASH_TIGER: { 1474 case PWM_HASH_TIGER: {
1475 if (!LibGCryptIf::available()) 1475 if (!LibGCryptIf::available())
1476 return e_hashNotImpl; 1476 return e_hashNotImpl;
1477 LibGCryptIf gc; 1477 LibGCryptIf gc;
1478 PwMerror err; 1478 PwMerror err;
1479 unsigned char *buf; 1479 unsigned char *buf;
1480 size_t hashLen; 1480 size_t hashLen;
1481 err = gc.hash(&buf, 1481 err = gc.hash(&buf,
1482 &hashLen, 1482 &hashLen,
1483 reinterpret_cast<const unsigned char *>(dataStream->c_str()), 1483 reinterpret_cast<const unsigned char *>(dataStream->c_str()),
1484 dataStream->length(), 1484 dataStream->length(),
1485 dataHashType); 1485 dataHashType);
1486 if (err != e_success) 1486 if (err != e_success)
1487 return e_hashNotImpl; 1487 return e_hashNotImpl;
1488 string calcHash(reinterpret_cast<const char *>(buf), 1488 string calcHash(reinterpret_cast<const char *>(buf),
1489 static_cast<string::size_type>(hashLen)); 1489 static_cast<string::size_type>(hashLen));
1490 delete [] buf; 1490 delete [] buf;
1491 if (calcHash != *dataHash) 1491 if (calcHash != *dataHash)
1492 return e_fileCorrupt; 1492 return e_fileCorrupt;
1493 break; 1493 break;
1494 } 1494 }
1495 default: 1495 default:
1496 return e_hashNotImpl; 1496 return e_hashNotImpl;
1497 } 1497 }
1498 return e_success; 1498 return e_success;
1499} 1499}
1500 1500
1501bool PwMDoc::lockAt(unsigned int category, unsigned int index, 1501bool PwMDoc::lockAt(unsigned int category, unsigned int index,
1502 bool lock) 1502 bool lock)
1503{ 1503{
1504 if (index >= numEntries(category)) { 1504 if (index >= numEntries(category)) {
1505 BUG(); 1505 BUG();
1506 return false; 1506 return false;
1507 } 1507 }
1508 if (lock == dti.dta[category].d[index].lockStat) 1508 if (lock == dti.dta[category].d[index].lockStat)
1509 return true; 1509 return true;
1510 1510
1511 if (!lock && currentPw != "") { 1511 if (!lock && currentPw != "") {
1512 // "unlocking" and "password is already set" 1512 // "unlocking" and "password is already set"
1513 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { 1513 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) {
1514 // unlocking without pw not allowed 1514 // unlocking without pw not allowed
1515 QString pw; 1515 QString pw;
1516 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1516 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1517 if (pw != "") { 1517 if (pw != "") {
1518 if (pw != currentPw) { 1518 if (pw != currentPw) {
1519 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1519 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1520 return false; 1520 return false;
1521 } else { 1521 } else {
1522 timer()->start(DocTimer::id_mpwTimer); 1522 timer()->start(DocTimer::id_mpwTimer);
1523 } 1523 }
1524 } else { 1524 } else {
1525 return false; 1525 return false;
1526 } 1526 }
1527 } else { 1527 } else {
1528 timer()->start(DocTimer::id_mpwTimer); 1528 timer()->start(DocTimer::id_mpwTimer);
1529 } 1529 }
1530 } 1530 }
1531 1531
1532 dti.dta[category].d[index].lockStat = lock; 1532 dti.dta[category].d[index].lockStat = lock;
1533 dti.dta[category].d[index].rev++; // increment revision counter. 1533 dti.dta[category].d[index].rev++; // increment revision counter.
1534 1534
1535 emitDataChanged(this); 1535 emitDataChanged(this);
1536 if (!lock) 1536 if (!lock)
1537 timer()->start(DocTimer::id_autoLockTimer); 1537 timer()->start(DocTimer::id_autoLockTimer);
1538 1538
1539 return true; 1539 return true;
1540 1540
1541} 1541}
1542 1542
1543bool PwMDoc::lockAt(const QString &category,unsigned int index, 1543bool PwMDoc::lockAt(const QString &category,unsigned int index,
1544 bool lock) 1544 bool lock)
1545{ 1545{
1546 unsigned int cat = 0; 1546 unsigned int cat = 0;
1547 1547
1548 if (!findCategory(category, &cat)) { 1548 if (!findCategory(category, &cat)) {
1549 BUG(); 1549 BUG();
1550 return false; 1550 return false;
1551 } 1551 }
1552 1552
1553 return lockAt(cat, index, lock); 1553 return lockAt(cat, index, lock);
1554} 1554}
1555 1555
1556bool PwMDoc::lockAll(bool lock) 1556bool PwMDoc::lockAll(bool lock)
1557{ 1557{
1558 if (!lock && isDeepLocked()) { 1558 if (!lock && isDeepLocked()) {
1559 PwMerror ret; 1559 PwMerror ret;
1560 ret = deepLock(false); 1560 ret = deepLock(false);
1561 if (ret != e_success) 1561 if (ret != e_success)
1562 return false; 1562 return false;
1563 return true; 1563 return true;
1564 } 1564 }
1565 if (isDocEmpty()) { 1565 if (isDocEmpty()) {
1566 return true; 1566 return true;
1567 } 1567 }
1568 if (!lock && currentPw != "") { 1568 if (!lock && currentPw != "") {
1569 // unlocking and password is already set 1569 // unlocking and password is already set
1570 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { 1570 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) {
1571 // unlocking without pw not allowed 1571 // unlocking without pw not allowed
1572 QString pw; 1572 QString pw;
1573 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1573 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1574 if (pw != "") { 1574 if (pw != "") {
1575 if (pw != currentPw) { 1575 if (pw != currentPw) {
1576 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1576 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1577 return false; 1577 return false;
1578 } else { 1578 } else {
1579 timer()->start(DocTimer::id_mpwTimer); 1579 timer()->start(DocTimer::id_mpwTimer);
1580 } 1580 }
1581 } else { 1581 } else {
1582 return false; 1582 return false;
1583 } 1583 }
1584 } else { 1584 } else {
1585 timer()->start(DocTimer::id_mpwTimer); 1585 timer()->start(DocTimer::id_mpwTimer);
1586 } 1586 }
1587 } 1587 }
1588 1588
1589 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 1589 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
1590 catEnd = dti.dta.end(), 1590 catEnd = dti.dta.end(),
1591 catI = catBegin; 1591 catI = catBegin;
1592 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 1592 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1593 while (catI != catEnd) { 1593 while (catI != catEnd) {
1594 entrBegin = catI->d.begin(); 1594 entrBegin = catI->d.begin();
1595 entrEnd = catI->d.end(); 1595 entrEnd = catI->d.end();
1596 entrI = entrBegin; 1596 entrI = entrBegin;
1597 while (entrI != entrEnd) { 1597 while (entrI != entrEnd) {
1598 entrI->lockStat = lock; 1598 entrI->lockStat = lock;
1599 entrI->rev++; // increment revision counter. 1599 entrI->rev++; // increment revision counter.
1600 ++entrI; 1600 ++entrI;
1601 } 1601 }
1602 ++catI; 1602 ++catI;
1603 } 1603 }
1604 1604
1605 emitDataChanged(this); 1605 emitDataChanged(this);
1606 if (lock) 1606 if (lock)
1607 timer()->stop(DocTimer::id_autoLockTimer); 1607 timer()->stop(DocTimer::id_autoLockTimer);
1608 else 1608 else
1609 timer()->start(DocTimer::id_autoLockTimer); 1609 timer()->start(DocTimer::id_autoLockTimer);
1610 1610
1611 return true; 1611 return true;
1612} 1612}
1613 1613
1614bool PwMDoc::isLocked(const QString &category, unsigned int index) 1614bool PwMDoc::isLocked(const QString &category, unsigned int index)
1615{ 1615{
1616 unsigned int cat = 0; 1616 unsigned int cat = 0;
1617 1617
1618 if (!findCategory(category, &cat)) { 1618 if (!findCategory(category, &cat)) {
1619 BUG(); 1619 BUG();
1620 return false; 1620 return false;
1621 } 1621 }
1622 1622
1623 return isLocked(cat, index); 1623 return isLocked(cat, index);
1624} 1624}
1625 1625
1626bool PwMDoc::unlockAll_tempoary(bool revert) 1626bool PwMDoc::unlockAll_tempoary(bool revert)
1627{ 1627{
1628 static vector< vector<bool> > *oldLockStates = 0; 1628 static vector< vector<bool> > *oldLockStates = 0;
1629 static bool wasDeepLocked; 1629 static bool wasDeepLocked;
1630 1630
1631 if (revert) {// revert the unlocking 1631 if (revert) {// revert the unlocking
1632 if (oldLockStates) { 1632 if (oldLockStates) {
1633 /* we actually _have_ unlocked something, because 1633 /* we actually _have_ unlocked something, because
1634 * we have allocated space for the oldLockStates. 1634 * we have allocated space for the oldLockStates.
1635 * So, go on and revert them! 1635 * So, go on and revert them!
1636 */ 1636 */
1637 if (wasDeepLocked) { 1637 if (wasDeepLocked) {
1638 PwMerror ret = deepLock(true); 1638 PwMerror ret = deepLock(true);
1639 if (ret == e_success) { 1639 if (ret == e_success) {
1640 /* deep-lock succeed. We are save. 1640 /* deep-lock succeed. We are save.
1641 * (but if it failed, just go on 1641 * (but if it failed, just go on
1642 * lock them normally) 1642 * lock them normally)
1643 */ 1643 */
1644 delete_and_null(oldLockStates); 1644 delete_and_null(oldLockStates);
1645 timer()->start(DocTimer::id_autoLockTimer); 1645 timer()->start(DocTimer::id_autoLockTimer);
1646 printDebug("tempoary unlocking of dta " 1646 printDebug("tempoary unlocking of dta "
1647 "reverted by deep-locking."); 1647 "reverted by deep-locking.");
1648 return true; 1648 return true;
1649 } 1649 }
1650 printDebug("deep-lock failed while reverting! " 1650 printDebug("deep-lock failed while reverting! "
1651 "Falling back to normal-lock."); 1651 "Falling back to normal-lock.");
1652 } 1652 }
1653 if (unlikely(!wasDeepLocked && 1653 if (unlikely(!wasDeepLocked &&
1654 numCategories() != oldLockStates->size())) { 1654 numCategories() != oldLockStates->size())) {
1655 /* DOH! We have modified "dta" while 1655 /* DOH! We have modified "dta" while
1656 * it was unlocked tempoary. DON'T DO THIS! 1656 * it was unlocked tempoary. DON'T DO THIS!
1657 */ 1657 */
1658 BUG(); 1658 BUG();
1659 delete_and_null(oldLockStates); 1659 delete_and_null(oldLockStates);
1660 timer()->start(DocTimer::id_autoLockTimer); 1660 timer()->start(DocTimer::id_autoLockTimer);
1661 return false; 1661 return false;
1662 } 1662 }
1663 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 1663 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
1664 catEnd = dti.dta.end(), 1664 catEnd = dti.dta.end(),
1665 catI = catBegin; 1665 catI = catBegin;
1666 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 1666 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1667 vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); 1667 vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin();
1668 vector<bool>::iterator oldEntrStatBegin, 1668 vector<bool>::iterator oldEntrStatBegin,
1669 oldEntrStatEnd, 1669 oldEntrStatEnd,
1670 oldEntrStatI; 1670 oldEntrStatI;
1671 while (catI != catEnd) { 1671 while (catI != catEnd) {
1672 entrBegin = catI->d.begin(); 1672 entrBegin = catI->d.begin();
1673 entrEnd = catI->d.end(); 1673 entrEnd = catI->d.end();
1674 entrI = entrBegin; 1674 entrI = entrBegin;
1675 if (likely(!wasDeepLocked)) { 1675 if (likely(!wasDeepLocked)) {
1676 oldEntrStatBegin = oldCatStatI->begin(); 1676 oldEntrStatBegin = oldCatStatI->begin();
1677 oldEntrStatEnd = oldCatStatI->end(); 1677 oldEntrStatEnd = oldCatStatI->end();
1678 oldEntrStatI = oldEntrStatBegin; 1678 oldEntrStatI = oldEntrStatBegin;
1679 if (unlikely(catI->d.size() != oldCatStatI->size())) { 1679 if (unlikely(catI->d.size() != oldCatStatI->size())) {
1680 /* DOH! We have modified "dta" while 1680 /* DOH! We have modified "dta" while
1681 * it was unlocked tempoary. DON'T DO THIS! 1681 * it was unlocked tempoary. DON'T DO THIS!
1682 */ 1682 */
1683 BUG(); 1683 BUG();
1684 delete_and_null(oldLockStates); 1684 delete_and_null(oldLockStates);
1685 timer()->start(DocTimer::id_autoLockTimer); 1685 timer()->start(DocTimer::id_autoLockTimer);
1686 return false; 1686 return false;
1687 } 1687 }
1688 } 1688 }
1689 while (entrI != entrEnd) { 1689 while (entrI != entrEnd) {
1690 if (wasDeepLocked) { 1690 if (wasDeepLocked) {
1691 /* this is an error-fallback if 1691 /* this is an error-fallback if
1692 * deeplock didn't succeed 1692 * deeplock didn't succeed
1693 */ 1693 */
1694 entrI->lockStat = true; 1694 entrI->lockStat = true;
1695 } else { 1695 } else {
1696 entrI->lockStat = *oldEntrStatI; 1696 entrI->lockStat = *oldEntrStatI;
1697 } 1697 }
1698 ++entrI; 1698 ++entrI;
1699 if (likely(!wasDeepLocked)) 1699 if (likely(!wasDeepLocked))
1700 ++oldEntrStatI; 1700 ++oldEntrStatI;
1701 } 1701 }
1702 ++catI; 1702 ++catI;
1703 if (likely(!wasDeepLocked)) 1703 if (likely(!wasDeepLocked))
1704 ++oldCatStatI; 1704 ++oldCatStatI;
1705 } 1705 }
1706 delete_and_null(oldLockStates); 1706 delete_and_null(oldLockStates);
1707 if (unlikely(wasDeepLocked)) { 1707 if (unlikely(wasDeepLocked)) {
1708 /* error fallback... */ 1708 /* error fallback... */
1709 unsetDocStatFlag(DOC_STAT_DEEPLOCKED); 1709 unsetDocStatFlag(DOC_STAT_DEEPLOCKED);
1710 emitDataChanged(this); 1710 emitDataChanged(this);
1711 printDebug("WARNING: unlockAll_tempoary(true) " 1711 printDebug("WARNING: unlockAll_tempoary(true) "
1712 "deeplock fallback!"); 1712 "deeplock fallback!");
1713 } 1713 }
1714 printDebug("tempoary unlocking of dta reverted."); 1714 printDebug("tempoary unlocking of dta reverted.");
1715 } else { 1715 } else {
1716 printDebug("unlockAll_tempoary(true): nothing to do."); 1716 printDebug("unlockAll_tempoary(true): nothing to do.");
1717 } 1717 }
1718 timer()->start(DocTimer::id_autoLockTimer); 1718 timer()->start(DocTimer::id_autoLockTimer);
1719 } else {// unlock all data tempoary 1719 } else {// unlock all data tempoary
1720 if (unlikely(oldLockStates != 0)) { 1720 if (unlikely(oldLockStates != 0)) {
1721 /* DOH! We have already unlocked the data tempoarly. 1721 /* DOH! We have already unlocked the data tempoarly.
1722 * No need to do it twice. ;) 1722 * No need to do it twice. ;)
1723 */ 1723 */
1724 BUG(); 1724 BUG();
1725 return false; 1725 return false;
1726 } 1726 }
1727 wasDeepLocked = false; 1727 wasDeepLocked = false;
1728 bool mustUnlock = false; 1728 bool mustUnlock = false;
1729 if (isDeepLocked()) { 1729 if (isDeepLocked()) {
1730 PwMerror ret; 1730 PwMerror ret;
1731 while (1) { 1731 while (1) {
1732 ret = deepLock(false); 1732 ret = deepLock(false);
1733 if (ret == e_success) { 1733 if (ret == e_success) {
1734 break; 1734 break;
1735 } else if (ret == e_wrongPw) { 1735 } else if (ret == e_wrongPw) {
1736 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1736 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1737 } else { 1737 } else {
1738 printDebug("deep-unlocking failed while " 1738 printDebug("deep-unlocking failed while "
1739 "tempoary unlocking!"); 1739 "tempoary unlocking!");
1740 return false; 1740 return false;
1741 } 1741 }
1742 } 1742 }
1743 wasDeepLocked = true; 1743 wasDeepLocked = true;
1744 mustUnlock = true; 1744 mustUnlock = true;
1745 } else { 1745 } else {
1746 // first check if it's needed to unlock some entries 1746 // first check if it's needed to unlock some entries
1747 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 1747 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
1748 catEnd = dti.dta.end(), 1748 catEnd = dti.dta.end(),
1749 catI = catBegin; 1749 catI = catBegin;
1750 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 1750 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1751 while (catI != catEnd) { 1751 while (catI != catEnd) {
1752 entrBegin = catI->d.begin(); 1752 entrBegin = catI->d.begin();
1753 entrEnd = catI->d.end(); 1753 entrEnd = catI->d.end();
1754 entrI = entrBegin; 1754 entrI = entrBegin;
1755 while (entrI != entrEnd) { 1755 while (entrI != entrEnd) {
1756 if (entrI->lockStat == true) { 1756 if (entrI->lockStat == true) {
1757 mustUnlock = true; 1757 mustUnlock = true;
1758 break; 1758 break;
1759 } 1759 }
1760 ++entrI; 1760 ++entrI;
1761 } 1761 }
1762 if (mustUnlock) 1762 if (mustUnlock)
1763 break; 1763 break;
1764 ++catI; 1764 ++catI;
1765 } 1765 }
1766 } 1766 }
1767 if (!mustUnlock) { 1767 if (!mustUnlock) {
1768 // nothing to do. 1768 // nothing to do.
1769 timer()->stop(DocTimer::id_autoLockTimer); 1769 timer()->stop(DocTimer::id_autoLockTimer);
1770 printDebug("unlockAll_tempoary(): nothing to do."); 1770 printDebug("unlockAll_tempoary(): nothing to do.");
1771 return true; 1771 return true;
1772 } else if (!wasDeepLocked) { 1772 } else if (!wasDeepLocked) {
1773 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && 1773 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) &&
1774 currentPw != "") { 1774 currentPw != "") {
1775 /* we can't unlock without mpw, so 1775 /* we can't unlock without mpw, so
1776 * we need to ask for it. 1776 * we need to ask for it.
1777 */ 1777 */
1778 QString pw; 1778 QString pw;
1779 while (1) { 1779 while (1) {
1780 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1780 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1781 if (pw == "") { 1781 if (pw == "") {
1782 return false; 1782 return false;
1783 } else if (pw == currentPw) { 1783 } else if (pw == currentPw) {
1784 break; 1784 break;
1785 } 1785 }
1786 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1786 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1787 } 1787 }
1788 } 1788 }
1789 } 1789 }
1790 timer()->stop(DocTimer::id_autoLockTimer); 1790 timer()->stop(DocTimer::id_autoLockTimer);
1791 oldLockStates = new vector< vector<bool> >; 1791 oldLockStates = new vector< vector<bool> >;
1792 vector<bool> tmp_vec; 1792 vector<bool> tmp_vec;
1793 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 1793 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
1794 catEnd = dti.dta.end(), 1794 catEnd = dti.dta.end(),
1795 catI = catBegin; 1795 catI = catBegin;
1796 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 1796 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1797 while (catI != catEnd) { 1797 while (catI != catEnd) {
1798 entrBegin = catI->d.begin(); 1798 entrBegin = catI->d.begin();
1799 entrEnd = catI->d.end(); 1799 entrEnd = catI->d.end();
1800 entrI = entrBegin; 1800 entrI = entrBegin;
1801 while (entrI != entrEnd) { 1801 while (entrI != entrEnd) {
1802 if (!wasDeepLocked) { 1802 if (!wasDeepLocked) {
1803 tmp_vec.push_back(entrI->lockStat); 1803 tmp_vec.push_back(entrI->lockStat);
1804 } 1804 }
1805 entrI->lockStat = false; 1805 entrI->lockStat = false;
1806 ++entrI; 1806 ++entrI;
1807 } 1807 }
1808 if (!wasDeepLocked) { 1808 if (!wasDeepLocked) {
1809 oldLockStates->push_back(tmp_vec); 1809 oldLockStates->push_back(tmp_vec);
1810 tmp_vec.clear(); 1810 tmp_vec.clear();
1811 } 1811 }
1812 ++catI; 1812 ++catI;
1813 } 1813 }
1814 printDebug("tempoary unlocked dta."); 1814 printDebug("tempoary unlocked dta.");
1815 } 1815 }
1816 1816
1817 return true; 1817 return true;
1818} 1818}
1819 1819
1820PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) 1820PwMerror PwMDoc::deepLock(bool lock, bool saveToFile)
1821{ 1821{
1822 PwMerror ret; 1822 PwMerror ret;
1823 /* NOTE: saveDoc() depends on this function to return 1823 /* NOTE: saveDoc() depends on this function to return
1824 * e_success if saveToFile == false 1824 * e_success if saveToFile == false
1825 */ 1825 */
1826 1826
1827 if (lock) { 1827 if (lock) {
1828 if (isDeepLocked()) 1828 if (isDeepLocked())
1829 return e_lock; 1829 return e_lock;
1830 if (saveToFile) { 1830 if (saveToFile) {
1831 if (isDocEmpty()) 1831 if (isDocEmpty())
1832 return e_docIsEmpty; 1832 return e_docIsEmpty;
1833 ret = saveDoc(conf()->confGlobCompression()); 1833 ret = saveDoc(conf()->confGlobCompression());
1834 if (ret == e_filename) { 1834 if (ret == e_filename) {
1835 /* the doc wasn't saved to a file 1835 /* the doc wasn't saved to a file
1836 * by the user, yet. 1836 * by the user, yet.
1837 */ 1837 */
1838 cantDeeplock_notSavedMsgBox(); 1838 cantDeeplock_notSavedMsgBox();
1839 return e_docNotSaved; 1839 return e_docNotSaved;
1840 } else if (ret != e_success) { 1840 } else if (ret != e_success) {
1841 return e_lock; 1841 return e_lock;
1842 } 1842 }
1843 } 1843 }
1844 timer()->stop(DocTimer::id_autoLockTimer); 1844 timer()->stop(DocTimer::id_autoLockTimer);
1845 clearDoc(); 1845 clearDoc();
1846 PwMDataItem d; 1846 PwMDataItem d;
1847 d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); 1847 d.desc = IS_DEEPLOCKED_SHORTMSG.latin1();
1848 d.comment = IS_DEEPLOCKED_MSG.latin1(); 1848 d.comment = IS_DEEPLOCKED_MSG.latin1();
1849 d.listViewPos = 0; 1849 d.listViewPos = 0;
1850 addEntry(DEFAULT_CATEGORY, &d, true); 1850 addEntry(DEFAULT_CATEGORY, &d, true);
1851 lockAt(DEFAULT_CATEGORY, 0, true); 1851 lockAt(DEFAULT_CATEGORY, 0, true);
1852 unsetDocStatFlag(DOC_STAT_DISK_DIRTY); 1852 unsetDocStatFlag(DOC_STAT_DISK_DIRTY);
1853 setDocStatFlag(DOC_STAT_DEEPLOCKED); 1853 setDocStatFlag(DOC_STAT_DEEPLOCKED);
1854 } else { 1854 } else {
1855 if (!isDeepLocked()) 1855 if (!isDeepLocked())
1856 return e_lock; 1856 return e_lock;
1857 ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) 1857 ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen())
1858 ? 0 : 1); 1858 ? 0 : 1);
1859 if (ret == e_wrongPw) { 1859 if (ret == e_wrongPw) {
1860 return e_wrongPw; 1860 return e_wrongPw;
1861 } else if (ret != e_success) { 1861 } else if (ret != e_success) {
1862 printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") 1862 printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ")
1863 + tostr(static_cast<int>(ret))); 1863 + tostr(static_cast<int>(ret)));
1864 return e_lock; 1864 return e_lock;
1865 } 1865 }
1866 unsetDocStatFlag(DOC_STAT_DEEPLOCKED); 1866 unsetDocStatFlag(DOC_STAT_DEEPLOCKED);
1867 timer()->start(DocTimer::id_autoLockTimer); 1867 timer()->start(DocTimer::id_autoLockTimer);
1868 } 1868 }
1869 1869
1870 emitDataChanged(this); 1870 emitDataChanged(this);
1871 return e_success; 1871 return e_success;
1872} 1872}
1873 1873
1874void PwMDoc::_deepUnlock() 1874void PwMDoc::_deepUnlock()
1875{ 1875{
1876 deepLock(false); 1876 deepLock(false);
1877} 1877}
1878 1878
1879void PwMDoc::clearDoc() 1879void PwMDoc::clearDoc()
1880{ 1880{
1881 dti.clear(); 1881 dti.clear();
1882 PwMCategoryItem d; 1882 PwMCategoryItem d;
1883 d.name = DEFAULT_CATEGORY.latin1(); 1883 d.name = DEFAULT_CATEGORY.latin1();
1884 dti.dta.push_back(d); 1884 dti.dta.push_back(d);
1885 currentPw = ""; 1885 currentPw = "";
1886 unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); 1886 unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW);
1887} 1887}
1888 1888
1889void PwMDoc::changeCurrentPw() 1889void PwMDoc::changeCurrentPw()
1890{ 1890{
1891 if (currentPw == "") 1891 if (currentPw == "")
1892 return; // doc hasn't been saved. No mpw available. 1892 return; // doc hasn't been saved. No mpw available.
1893 bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); 1893 bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD);
1894 QString pw = requestMpwChange(&currentPw, &useChipcard); 1894 QString pw = requestMpwChange(&currentPw, &useChipcard);
1895 if (pw == "") 1895 if (pw == "")
1896 return; 1896 return;
1897 if (useChipcard) 1897 if (useChipcard)
1898 setDocStatFlag(DOC_STAT_USE_CHIPCARD); 1898 setDocStatFlag(DOC_STAT_USE_CHIPCARD);
1899 else 1899 else
1900 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); 1900 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD);
1901 setCurrentPw(pw); 1901 setCurrentPw(pw);
1902} 1902}
1903 1903
1904void PwMDoc::setListViewPos(const QString &category, unsigned int index, 1904void PwMDoc::setListViewPos(const QString &category, unsigned int index,
1905 int pos) 1905 int pos)
1906{ 1906{
1907 unsigned int cat = 0; 1907 unsigned int cat = 0;
1908 1908
1909 if (!findCategory(category, &cat)) { 1909 if (!findCategory(category, &cat)) {
1910 BUG(); 1910 BUG();
1911 return; 1911 return;
1912 } 1912 }
1913 setListViewPos(cat, index, pos); 1913 setListViewPos(cat, index, pos);
1914} 1914}
1915 1915
1916void PwMDoc::setListViewPos(unsigned int category, unsigned int index, 1916void PwMDoc::setListViewPos(unsigned int category, unsigned int index,
1917 int pos) 1917 int pos)
1918{ 1918{
1919 dti.dta[category].d[index].listViewPos = pos; 1919 dti.dta[category].d[index].listViewPos = pos;
1920 1920
1921/* FIXME workaround: don't flag dirty, because this function sometimes 1921/* FIXME workaround: don't flag dirty, because this function sometimes
1922 * get's called when it shouldn't. It's because PwMView assumes 1922 * get's called when it shouldn't. It's because PwMView assumes
1923 * the user resorted the UI on behalf of signal layoutChanged(). 1923 * the user resorted the UI on behalf of signal layoutChanged().
1924 * This is somewhat broken and incorrect, but I've no other 1924 * This is somewhat broken and incorrect, but I've no other
1925 * solution for now. 1925 * solution for now.
1926 */ 1926 */
1927 //setDocStatFlag(DOC_STAT_DISK_DIRTY); 1927 //setDocStatFlag(DOC_STAT_DISK_DIRTY);
1928} 1928}
1929 1929
1930int PwMDoc::getListViewPos(const QString &category, unsigned int index) 1930int PwMDoc::getListViewPos(const QString &category, unsigned int index)
1931{ 1931{
1932 unsigned int cat = 0; 1932 unsigned int cat = 0;
1933 1933
1934 if (!findCategory(category, &cat)) { 1934 if (!findCategory(category, &cat)) {
1935 BUG(); 1935 BUG();
1936 return -1; 1936 return -1;
1937 } 1937 }
1938 1938
1939 return dti.dta[cat].d[index].listViewPos; 1939 return dti.dta[cat].d[index].listViewPos;
1940} 1940}
1941 1941
1942void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, 1942void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn,
1943 vector<unsigned int> *foundPositions, bool breakAfterFound, 1943 vector<unsigned int> *foundPositions, bool breakAfterFound,
1944 bool caseSensitive, bool exactWordMatch, bool sortByLvp) 1944 bool caseSensitive, bool exactWordMatch, bool sortByLvp)
1945{ 1945{
1946 PWM_ASSERT(foundPositions); 1946 PWM_ASSERT(foundPositions);
1947 PWM_ASSERT(searchIn); 1947 PWM_ASSERT(searchIn);
1948 foundPositions->clear(); 1948 foundPositions->clear();
1949 1949
1950 unsigned int i, entries = numEntries(category); 1950 unsigned int i, entries = numEntries(category);
1951 for (i = 0; i < entries; ++i) { 1951 for (i = 0; i < entries; ++i) {
1952 if (searchIn & SEARCH_IN_DESC) { 1952 if (searchIn & SEARCH_IN_DESC) {
1953 if (!compareString(find.desc, dti.dta[category].d[i].desc, 1953 if (!compareString(find.desc, dti.dta[category].d[i].desc,
1954 caseSensitive, exactWordMatch)) { 1954 caseSensitive, exactWordMatch)) {
1955 continue; 1955 continue;
1956 } 1956 }
1957 } 1957 }
1958 if (searchIn & SEARCH_IN_NAME) { 1958 if (searchIn & SEARCH_IN_NAME) {
1959 if (!compareString(find.name, dti.dta[category].d[i].name, 1959 if (!compareString(find.name, dti.dta[category].d[i].name,
1960 caseSensitive, exactWordMatch)) { 1960 caseSensitive, exactWordMatch)) {
1961 continue; 1961 continue;
1962 } 1962 }
1963 } 1963 }
1964 if (searchIn & SEARCH_IN_PW) { 1964 if (searchIn & SEARCH_IN_PW) {
1965 bool wasLocked = isLocked(category, i); 1965 bool wasLocked = isLocked(category, i);
1966 getDataChangedLock(); 1966 getDataChangedLock();
1967 lockAt(category, i, false); 1967 lockAt(category, i, false);
1968 if (!compareString(find.pw, dti.dta[category].d[i].pw, 1968 if (!compareString(find.pw, dti.dta[category].d[i].pw,
1969 caseSensitive, exactWordMatch)) { 1969 caseSensitive, exactWordMatch)) {
1970 lockAt(category, i, wasLocked); 1970 lockAt(category, i, wasLocked);
1971 putDataChangedLock(); 1971 putDataChangedLock();
1972 continue; 1972 continue;
1973 } 1973 }
1974 lockAt(category, i, wasLocked); 1974 lockAt(category, i, wasLocked);
1975 putDataChangedLock(); 1975 putDataChangedLock();
1976 } 1976 }
1977 if (searchIn & SEARCH_IN_COMMENT) { 1977 if (searchIn & SEARCH_IN_COMMENT) {
1978 if (!compareString(find.comment, dti.dta[category].d[i].comment, 1978 if (!compareString(find.comment, dti.dta[category].d[i].comment,
1979 caseSensitive, exactWordMatch)) { 1979 caseSensitive, exactWordMatch)) {
1980 continue; 1980 continue;
1981 } 1981 }
1982 } 1982 }
1983 if (searchIn & SEARCH_IN_URL) { 1983 if (searchIn & SEARCH_IN_URL) {
1984 if (!compareString(find.url, dti.dta[category].d[i].url, 1984 if (!compareString(find.url, dti.dta[category].d[i].url,
1985 caseSensitive, exactWordMatch)) { 1985 caseSensitive, exactWordMatch)) {
1986 continue; 1986 continue;
1987 } 1987 }
1988 } 1988 }
1989 if (searchIn & SEARCH_IN_LAUNCHER) { 1989 if (searchIn & SEARCH_IN_LAUNCHER) {
1990 if (!compareString(find.launcher, dti.dta[category].d[i].launcher, 1990 if (!compareString(find.launcher, dti.dta[category].d[i].launcher,
1991 caseSensitive, exactWordMatch)) { 1991 caseSensitive, exactWordMatch)) {
1992 continue; 1992 continue;
1993 } 1993 }
1994 } 1994 }
1995 1995
1996 // all selected "searchIn" matched. 1996 // all selected "searchIn" matched.
1997 foundPositions->push_back(i); 1997 foundPositions->push_back(i);
1998 if (breakAfterFound) 1998 if (breakAfterFound)
1999 break; 1999 break;
2000 } 2000 }
2001 2001
2002 if (sortByLvp && foundPositions->size() > 1) { 2002 if (sortByLvp && foundPositions->size() > 1) {
2003 vector< pair<unsigned int /* foundPosition (real doc pos) */, 2003 vector< pair<unsigned int /* foundPosition (real doc pos) */,
2004 unsigned int /* lvp-pos */> > tmp_vec; 2004 unsigned int /* lvp-pos */> > tmp_vec;
2005 2005
2006 unsigned int i, items = foundPositions->size(); 2006 unsigned int i, items = foundPositions->size();
2007 pair<unsigned int, unsigned int> tmp_pair; 2007 pair<unsigned int, unsigned int> tmp_pair;
2008 for (i = 0; i < items; ++i) { 2008 for (i = 0; i < items; ++i) {
2009 tmp_pair.first = (*foundPositions)[i]; 2009 tmp_pair.first = (*foundPositions)[i];
2010 tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos; 2010 tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos;
2011 tmp_vec.push_back(tmp_pair); 2011 tmp_vec.push_back(tmp_pair);
2012 } 2012 }
2013 sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); 2013 sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater());
2014 foundPositions->clear(); 2014 foundPositions->clear();
2015 for (i = 0; i < items; ++i) { 2015 for (i = 0; i < items; ++i) {
2016 foundPositions->push_back(tmp_vec[i].first); 2016 foundPositions->push_back(tmp_vec[i].first);
2017 } 2017 }
2018 } 2018 }
2019} 2019}
2020 2020
2021void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, 2021void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn,
2022 vector<unsigned int> *foundPositions, bool breakAfterFound, 2022 vector<unsigned int> *foundPositions, bool breakAfterFound,
2023 bool caseSensitive, bool exactWordMatch, bool sortByLvp) 2023 bool caseSensitive, bool exactWordMatch, bool sortByLvp)
2024{ 2024{
2025 PWM_ASSERT(foundPositions); 2025 PWM_ASSERT(foundPositions);
2026 unsigned int cat = 0; 2026 unsigned int cat = 0;
2027 2027
2028 if (!findCategory(category, &cat)) { 2028 if (!findCategory(category, &cat)) {
2029 foundPositions->clear(); 2029 foundPositions->clear();
2030 return; 2030 return;
2031 } 2031 }
2032 2032
2033 findEntry(cat, find, searchIn, foundPositions, breakAfterFound, 2033 findEntry(cat, find, searchIn, foundPositions, breakAfterFound,
2034 caseSensitive, exactWordMatch, sortByLvp); 2034 caseSensitive, exactWordMatch, sortByLvp);
2035} 2035}
2036 2036
2037bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, 2037bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive,
2038 bool exactWordMatch) 2038 bool exactWordMatch)
2039{ 2039{
2040 QString _s1(s1.c_str()); 2040 QString _s1(s1.c_str());
2041 QString _s2(s2.c_str()); 2041 QString _s2(s2.c_str());
2042 if (!caseSensitive) { 2042 if (!caseSensitive) {
2043 _s1 = _s1.lower(); 2043 _s1 = _s1.lower();
2044 _s2 = _s2.lower(); 2044 _s2 = _s2.lower();
2045 } 2045 }
2046 if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) 2046 if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1))
2047 return true; 2047 return true;
2048 return false; 2048 return false;
2049} 2049}
2050 2050
2051bool PwMDoc::findCategory(const QString &name, unsigned int *index) 2051bool PwMDoc::findCategory(const QString &name, unsigned int *index)
2052{ 2052{
2053 vector<PwMCategoryItem>::iterator i = dti.dta.begin(), 2053 vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
2054 end = dti.dta.end(); 2054 end = dti.dta.end();
2055 while (i != end) { 2055 while (i != end) {
2056 if ((*i).name == name.latin1()) { 2056 if ((*i).name == name.latin1()) {
2057 if (index) { 2057 if (index) {
2058 *index = i - dti.dta.begin(); 2058 *index = i - dti.dta.begin();
2059 } 2059 }
2060 return true; 2060 return true;
2061 } 2061 }
2062 ++i; 2062 ++i;
2063 } 2063 }
2064 return false; 2064 return false;
2065} 2065}
2066 2066
2067bool PwMDoc::renameCategory(const QString &category, const QString &newName) 2067bool PwMDoc::renameCategory(const QString &category, const QString &newName)
2068{ 2068{
2069 unsigned int cat = 0; 2069 unsigned int cat = 0;
2070 2070
2071 if (!findCategory(category, &cat)) 2071 if (!findCategory(category, &cat))
2072 return false; 2072 return false;
2073 2073
2074 return renameCategory(cat, newName); 2074 return renameCategory(cat, newName);
2075} 2075}
2076 2076
2077bool PwMDoc::renameCategory(unsigned int category, const QString &newName, 2077bool PwMDoc::renameCategory(unsigned int category, const QString &newName,
2078 bool dontFlagDirty) 2078 bool dontFlagDirty)
2079{ 2079{
2080 if (category > numCategories() - 1) 2080 if (category > numCategories() - 1)
2081 return false; 2081 return false;
2082 2082
2083 dti.dta[category].name = newName.latin1(); 2083 dti.dta[category].name = newName.latin1();
2084 if (!dontFlagDirty) 2084 if (!dontFlagDirty)
2085 flagDirty(); 2085 flagDirty();
2086 2086
2087 return true; 2087 return true;
2088} 2088}
2089 2089
2090bool PwMDoc::delCategory(const QString &category) 2090bool PwMDoc::delCategory(const QString &category)
2091{ 2091{
2092 unsigned int cat = 0; 2092 unsigned int cat = 0;
2093 2093
2094 if (!findCategory(category, &cat)) 2094 if (!findCategory(category, &cat))
2095 return false; 2095 return false;
2096 2096
2097 return delCategory(cat); 2097 return delCategory(cat);
2098} 2098}
2099 2099
2100bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) 2100bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty)
2101{ 2101{
2102 if (category > numCategories() - 1) 2102 if (category > numCategories() - 1)
2103 return false; 2103 return false;
2104 2104
2105 // We don't delete it, if it is the last existing 2105 // We don't delete it, if it is the last existing
2106 // category! Instead we rename it to "Default". 2106 // category! Instead we rename it to "Default".
2107 if (numCategories() > 1) { 2107 if (numCategories() > 1) {
2108 dti.dta.erase(dti.dta.begin() + category); 2108 dti.dta.erase(dti.dta.begin() + category);
2109 } else { 2109 } else {
2110 renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); 2110 renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty);
2111 return true; 2111 return true;
2112 } 2112 }
2113 if (!dontFlagDirty) 2113 if (!dontFlagDirty)
2114 flagDirty(); 2114 flagDirty();
2115 2115
2116 return true; 2116 return true;
2117} 2117}
2118 2118
2119void PwMDoc::delAllEmptyCat(bool dontFlagDirty) 2119void PwMDoc::delAllEmptyCat(bool dontFlagDirty)
2120{ 2120{
2121 vector<PwMCategoryItem>::iterator begin = dti.dta.begin(), 2121 vector<PwMCategoryItem>::iterator begin = dti.dta.begin(),
2122 end = dti.dta.end(), 2122 end = dti.dta.end(),
2123 i = begin; 2123 i = begin;
2124 while (i != end) { 2124 while (i != end) {
2125 if (i->d.empty()) { 2125 if (i->d.empty()) {
2126 delCategory(begin - i, dontFlagDirty); 2126 delCategory(begin - i, dontFlagDirty);
2127 } 2127 }
2128 ++i; 2128 ++i;
2129 } 2129 }
2130} 2130}
2131 2131
2132void PwMDoc::getCategoryList(vector<string> *list) 2132void PwMDoc::getCategoryList(vector<string> *list)
2133{ 2133{
2134 PWM_ASSERT(list); 2134 PWM_ASSERT(list);
2135 list->clear(); 2135 list->clear();
2136 vector<PwMCategoryItem>::iterator i = dti.dta.begin(), 2136 vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
2137 end = dti.dta.end(); 2137 end = dti.dta.end();
2138 while (i != end) { 2138 while (i != end) {
2139 list->push_back(i->name); 2139 list->push_back(i->name);
2140 ++i; 2140 ++i;
2141 } 2141 }
2142} 2142}
2143 2143
2144void PwMDoc::getCategoryList(QStringList *list) 2144void PwMDoc::getCategoryList(QStringList *list)
2145{ 2145{
2146 PWM_ASSERT(list); 2146 PWM_ASSERT(list);
2147 list->clear(); 2147 list->clear();
2148 vector<PwMCategoryItem>::iterator i = dti.dta.begin(), 2148 vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
2149 end = dti.dta.end(); 2149 end = dti.dta.end();
2150 while (i != end) { 2150 while (i != end) {
2151#ifndef PWM_EMBEDDED 2151#ifndef PWM_EMBEDDED
2152 list->push_back(i->name.c_str()); 2152 list->push_back(i->name.c_str());
2153#else 2153#else
2154 list->append(i->name.c_str()); 2154 list->append(i->name.c_str());
2155#endif 2155#endif
2156 ++i; 2156 ++i;
2157 } 2157 }
2158} 2158}
2159 2159
2160void PwMDoc::getEntryList(const QString &category, QStringList *list) 2160void PwMDoc::getEntryList(const QString &category, QStringList *list)
2161{ 2161{
2162 PWM_ASSERT(list); 2162 PWM_ASSERT(list);
2163 unsigned int cat = 0; 2163 unsigned int cat = 0;
2164 if (!findCategory(category, &cat)) { 2164 if (!findCategory(category, &cat)) {
2165 list->clear(); 2165 list->clear();
2166 return; 2166 return;
2167 } 2167 }
2168 getEntryList(cat, list); 2168 getEntryList(cat, list);
2169} 2169}
2170 2170
2171void PwMDoc::getEntryList(const QString &category, vector<string> *list) 2171void PwMDoc::getEntryList(const QString &category, vector<string> *list)
2172{ 2172{
2173 PWM_ASSERT(list); 2173 PWM_ASSERT(list);
2174 unsigned int cat = 0; 2174 unsigned int cat = 0;
2175 if (!findCategory(category, &cat)) { 2175 if (!findCategory(category, &cat)) {
2176 list->clear(); 2176 list->clear();
2177 return; 2177 return;
2178 } 2178 }
2179 getEntryList(cat, list); 2179 getEntryList(cat, list);
2180} 2180}
2181 2181
2182void PwMDoc::getEntryList(unsigned int category, vector<string> *list) 2182void PwMDoc::getEntryList(unsigned int category, vector<string> *list)
2183{ 2183{
2184 PWM_ASSERT(list); 2184 PWM_ASSERT(list);
2185 list->clear(); 2185 list->clear();
2186 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), 2186 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(),
2187 end = dti.dta[category].d.end(), 2187 end = dti.dta[category].d.end(),
2188 i = begin; 2188 i = begin;
2189 while (i != end) { 2189 while (i != end) {
2190 list->push_back(i->desc); 2190 list->push_back(i->desc);
2191 ++i; 2191 ++i;
2192 } 2192 }
2193} 2193}
2194 2194
2195void PwMDoc::getEntryList(unsigned int category, QStringList *list) 2195void PwMDoc::getEntryList(unsigned int category, QStringList *list)
2196{ 2196{
2197 PWM_ASSERT(list); 2197 PWM_ASSERT(list);
2198 list->clear(); 2198 list->clear();
2199 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), 2199 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(),
2200 end = dti.dta[category].d.end(), 2200 end = dti.dta[category].d.end(),
2201 i = begin; 2201 i = begin;
2202 while (i != end) { 2202 while (i != end) {
2203#ifndef PWM_EMBEDDED 2203#ifndef PWM_EMBEDDED
2204 list->push_back(i->desc.c_str()); 2204 list->push_back(i->desc.c_str());
2205#else 2205#else
2206 list->append(i->desc.c_str()); 2206 list->append(i->desc.c_str());
2207#endif 2207#endif
2208 ++i; 2208 ++i;
2209 } 2209 }
2210} 2210}
2211 2211
2212bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) 2212bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex)
2213{ 2213{
2214 unsigned int cat = 0; 2214 unsigned int cat = 0;
2215 2215
2216 if (!findCategory(category, &cat)) 2216 if (!findCategory(category, &cat))
2217 return false; 2217 return false;
2218 2218
2219 return execLauncher(cat, entryIndex); 2219 return execLauncher(cat, entryIndex);
2220} 2220}
2221 2221
2222bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) 2222bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex)
2223{ 2223{
2224#ifndef _WIN32_ 2224#ifndef _WIN32_
2225 if (geteuid() == 0) { 2225 if (geteuid() == 0) {
2226 rootAlertMsgBox(); 2226 rootAlertMsgBox();
2227 return false; 2227 return false;
2228 } 2228 }
2229#endif 2229#endif
2230 QString command(dti.dta[category].d[entryIndex].launcher.c_str()); 2230 QString command(dti.dta[category].d[entryIndex].launcher.c_str());
2231 bool wasLocked = isLocked(category, entryIndex); 2231 bool wasLocked = isLocked(category, entryIndex);
2232 2232
2233 if (command.find("$p") != -1) { 2233 if (command.find("$p") != -1) {
2234 /* the user requested the password to be included 2234 /* the user requested the password to be included
2235 * into the command. We have to ask for the password, 2235 * into the command. We have to ask for the password,
2236 * if it's locked. We do that by unlocking the entry 2236 * if it's locked. We do that by unlocking the entry
2237 */ 2237 */
2238 if (!lockAt(category, entryIndex, false)) 2238 if (!lockAt(category, entryIndex, false))
2239 return false; 2239 return false;
2240 } 2240 }
2241#ifndef PWM_EMBEDDED 2241#ifndef PWM_EMBEDDED
2242 command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); 2242 command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str());
2243 command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); 2243 command.replace("$n", dti.dta[category].d[entryIndex].name.c_str());
2244 command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); 2244 command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str());
2245 command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); 2245 command.replace("$u", dti.dta[category].d[entryIndex].url.c_str());
2246 command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); 2246 command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str());
2247#else 2247#else
2248 command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); 2248 command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str());
2249 command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); 2249 command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str());
2250 command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); 2250 command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str());
2251 command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); 2251 command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str());
2252 command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); 2252 command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str());
2253#endif 2253#endif
2254 command.append(" &"); 2254 command.append(" &");
2255 2255
2256 QString customXterm(conf()->confGlobXtermCommand()); 2256 QString customXterm(conf()->confGlobXtermCommand());
2257 if (!customXterm.isEmpty()) 2257 if (!customXterm.isEmpty())
2258 command = customXterm + " " + command; 2258 command = customXterm + " " + command;
2259 2259
2260 system(command.latin1()); 2260 system(command.latin1());
2261 2261
2262 lockAt(category, entryIndex, wasLocked); 2262 lockAt(category, entryIndex, wasLocked);
2263 return true; 2263 return true;
2264} 2264}
2265 2265
2266bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) 2266bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex)
2267{ 2267{
2268 unsigned int cat = 0; 2268 unsigned int cat = 0;
2269 2269
2270 if (!findCategory(category, &cat)) 2270 if (!findCategory(category, &cat))
2271 return false; 2271 return false;
2272 2272
2273 return goToURL(cat, entryIndex); 2273 return goToURL(cat, entryIndex);
2274} 2274}
2275 2275
2276bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) 2276bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex)
2277{ 2277{
2278#ifndef _WIN32_ 2278#ifndef _WIN32_
2279 if (geteuid() == 0) { 2279 if (geteuid() == 0) {
2280 rootAlertMsgBox(); 2280 rootAlertMsgBox();
2281 return false; 2281 return false;
2282 } 2282 }
2283#endif 2283#endif
2284 QString url(dti.dta[category].d[entryIndex].url.c_str()); 2284 QString url(dti.dta[category].d[entryIndex].url.c_str());
2285 if (url.isEmpty()) 2285 if (url.isEmpty())
2286 return false; 2286 return false;
2287 2287
2288 QString customBrowser(conf()->confGlobBrowserCommand()); 2288 QString customBrowser(conf()->confGlobBrowserCommand());
2289 if (!customBrowser.isEmpty()) { 2289 if (!customBrowser.isEmpty()) {
2290 browserProc.clearArguments(); 2290 browserProc.clearArguments();
2291 browserProc << customBrowser << url; 2291 browserProc << customBrowser << url;
2292 if (browserProc.start(KProcess::DontCare)) 2292 if (browserProc.start(KProcess::DontCare))
2293 return true; 2293 return true;
2294 } 2294 }
2295 2295
2296 browserProc.clearArguments(); 2296 browserProc.clearArguments();
2297 browserProc << "konqueror" << url; 2297 browserProc << "konqueror" << url;
2298 if (browserProc.start(KProcess::DontCare)) 2298 if (browserProc.start(KProcess::DontCare))
2299 return true; 2299 return true;
2300 2300
2301 browserProc.clearArguments(); 2301 browserProc.clearArguments();
2302 browserProc << "mozilla" << url; 2302 browserProc << "mozilla" << url;
2303 if (browserProc.start(KProcess::DontCare)) 2303 if (browserProc.start(KProcess::DontCare))
2304 return true; 2304 return true;
2305 2305
2306 browserProc.clearArguments(); 2306 browserProc.clearArguments();
2307 browserProc << "opera" << url; 2307 browserProc << "opera" << url;
2308 if (browserProc.start(KProcess::DontCare)) 2308 if (browserProc.start(KProcess::DontCare))
2309 return true; 2309 return true;
2310 return false; 2310 return false;
2311} 2311}
2312 2312
2313PwMerror PwMDoc::exportToText(const QString *file) 2313PwMerror PwMDoc::exportToText(const QString *file)
2314{ 2314{
2315 PWM_ASSERT(file); 2315 PWM_ASSERT(file);
2316 if (QFile::exists(*file)) { 2316 if (QFile::exists(*file)) {
2317 if (!QFile::remove(*file)) 2317 if (!QFile::remove(*file))
2318 return e_accessFile; 2318 return e_accessFile;
2319 } 2319 }
2320 QFile f(*file); 2320 QFile f(*file);
2321 if (!f.open(IO_ReadWrite)) 2321 if (!f.open(IO_ReadWrite))
2322 return e_openFile; 2322 return e_openFile;
2323 2323
2324 if (!unlockAll_tempoary()) { 2324 if (!unlockAll_tempoary()) {
2325 f.close(); 2325 f.close();
2326 return e_lock; 2326 return e_lock;
2327 } 2327 }
2328 2328
2329 // write header 2329 // write header
2330 string header = i18n("Password table generated by\nPwM v").latin1(); 2330 string header = i18n("Password table generated by\nPwM v").latin1();
2331 header += PACKAGE_VER; 2331 header += PACKAGE_VER;
2332 header += i18n("\non ").latin1(); 2332 header += i18n("\non ").latin1();
2333 QDate currDate = QDate::currentDate(); 2333 QDate currDate = QDate::currentDate();
2334 QTime currTime = QTime::currentTime(); 2334 QTime currTime = QTime::currentTime();
2335 2335
2336#ifndef PWM_EMBEDDED 2336#ifndef PWM_EMBEDDED
2337 header += currDate.toString("ddd MMMM d ").latin1(); 2337 header += currDate.toString("ddd MMMM d ").latin1();
2338 header += currTime.toString("hh:mm:ss ").latin1(); 2338 header += currTime.toString("hh:mm:ss ").latin1();
2339#else 2339#else
2340 QString dfs = KGlobal::locale()->dateFormatShort(); 2340 QString dfs = KGlobal::locale()->dateFormatShort();
2341 bool ampm = KGlobal::locale()->use12Clock(); 2341 bool ampm = KGlobal::locale()->use12Clock();
2342 KGlobal::locale()->setDateFormatShort("%A %B %d"); 2342 KGlobal::locale()->setDateFormatShort("%A %B %d");
2343 KGlobal::locale()->setHore24Format(true); 2343 KGlobal::locale()->setHore24Format(true);
2344 2344
2345 header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined).latin1(); 2345 header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined).latin1();
2346 header += KGlobal::locale()->formatTime(currTime, true).latin1(); 2346 header += KGlobal::locale()->formatTime(currTime, true).latin1();
2347 KGlobal::locale()->setDateFormatShort(dfs); 2347 KGlobal::locale()->setDateFormatShort(dfs);
2348 KGlobal::locale()->setHore24Format(!ampm); 2348 KGlobal::locale()->setHore24Format(!ampm);
2349 2349
2350#endif 2350#endif
2351 header += tostr(currDate.year()); 2351 header += tostr(currDate.year());
2352 header += "\n==============================\n\n"; 2352 header += "\n==============================\n\n";
2353 2353
2354 2354
2355#ifndef PWM_EMBEDDED 2355#ifndef PWM_EMBEDDED
2356 if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) { 2356 if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) {
2357 unlockAll_tempoary(true); 2357 unlockAll_tempoary(true);
2358 f.close(); 2358 f.close();
2359 return e_writeFile; 2359 return e_writeFile;
2360 } 2360 }
2361#else 2361#else
2362 if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) { 2362 if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) {
2363 unlockAll_tempoary(true); 2363 unlockAll_tempoary(true);
2364 f.close(); 2364 f.close();
2365 return e_writeFile; 2365 return e_writeFile;
2366 } 2366 }
2367#endif 2367#endif
2368 unsigned int i, numCat = numCategories(); 2368 unsigned int i, numCat = numCategories();
2369 unsigned int j, numEnt; 2369 unsigned int j, numEnt;
2370 string exp; 2370 string exp;
2371 for (i = 0; i < numCat; ++i) { 2371 for (i = 0; i < numCat; ++i) {
2372 numEnt = numEntries(i); 2372 numEnt = numEntries(i);
2373 2373
2374 exp = "\n== Category: "; 2374 exp = "\n== Category: ";
2375 exp += dti.dta[i].name; 2375 exp += dti.dta[i].name;
2376 exp += " ==\n"; 2376 exp += " ==\n";
2377#ifndef PWM_EMBEDDED 2377#ifndef PWM_EMBEDDED
2378 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { 2378 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) {
2379 unlockAll_tempoary(true); 2379 unlockAll_tempoary(true);
2380 f.close(); 2380 f.close();
2381 return e_writeFile; 2381 return e_writeFile;
2382 } 2382 }
2383#else 2383#else
2384 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { 2384 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) {
2385 unlockAll_tempoary(true); 2385 unlockAll_tempoary(true);
2386 f.close(); 2386 f.close();
2387 return e_writeFile; 2387 return e_writeFile;
2388 } 2388 }
2389#endif 2389#endif
2390 for (j = 0; j < numEnt; ++j) { 2390 for (j = 0; j < numEnt; ++j) {
2391 exp = "\n-- "; 2391 exp = "\n-- ";
2392 exp += dti.dta[i].d[j].desc; 2392 exp += dti.dta[i].d[j].desc;
2393 exp += " --\n"; 2393 exp += " --\n";
2394 2394
2395 exp += i18n("Username: ").latin1(); 2395 exp += i18n("Username: ").latin1();
2396 exp += dti.dta[i].d[j].name; 2396 exp += dti.dta[i].d[j].name;
2397 exp += "\n"; 2397 exp += "\n";
2398 2398
2399 exp += i18n("Password: ").latin1(); 2399 exp += i18n("Password: ").latin1();
2400 exp += dti.dta[i].d[j].pw; 2400 exp += dti.dta[i].d[j].pw;
2401 exp += "\n"; 2401 exp += "\n";
2402 2402
2403 exp += i18n("Comment: ").latin1(); 2403 exp += i18n("Comment: ").latin1();
2404 exp += dti.dta[i].d[j].comment; 2404 exp += dti.dta[i].d[j].comment;
2405 exp += "\n"; 2405 exp += "\n";
2406 2406
2407 exp += i18n("URL: ").latin1(); 2407 exp += i18n("URL: ").latin1();
2408 exp += dti.dta[i].d[j].url; 2408 exp += dti.dta[i].d[j].url;
2409 exp += "\n"; 2409 exp += "\n";
2410 2410
2411 exp += i18n("Launcher: ").latin1(); 2411 exp += i18n("Launcher: ").latin1();
2412 exp += dti.dta[i].d[j].launcher; 2412 exp += dti.dta[i].d[j].launcher;
2413 exp += "\n"; 2413 exp += "\n";
2414 2414
2415#ifndef PWM_EMBEDDED 2415#ifndef PWM_EMBEDDED
2416 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { 2416 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) {
2417 unlockAll_tempoary(true); 2417 unlockAll_tempoary(true);
2418 f.close(); 2418 f.close();
2419 return e_writeFile; 2419 return e_writeFile;
2420 } 2420 }
2421#else 2421#else
2422 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { 2422 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) {
2423 unlockAll_tempoary(true); 2423 unlockAll_tempoary(true);
2424 f.close(); 2424 f.close();
2425 return e_writeFile; 2425 return e_writeFile;
2426 } 2426 }
2427#endif 2427#endif
2428 } 2428 }
2429 } 2429 }
2430 unlockAll_tempoary(true); 2430 unlockAll_tempoary(true);
2431 f.close(); 2431 f.close();
2432 2432
2433 return e_success; 2433 return e_success;
2434} 2434}
2435 2435
2436PwMerror PwMDoc::importFromText(const QString *file, int format) 2436PwMerror PwMDoc::importFromText(const QString *file, int format)
2437{ 2437{
2438 PWM_ASSERT(file); 2438 PWM_ASSERT(file);
2439 if (format == 0) 2439 if (format == 0)
2440 return importText_PwM(file); 2440 return importText_PwM(file);
2441 else if (format == -1) { 2441 else if (format == -1) {
2442 // probe for all formats 2442 // probe for all formats
2443 if (importText_PwM(file) == e_success) 2443 if (importText_PwM(file) == e_success)
2444 return e_success; 2444 return e_success;
2445 dti.clear(); 2445 dti.clear();
2446 emitDataChanged(this); 2446 emitDataChanged(this);
2447 // add next format here... 2447 // add next format here...
2448 return e_fileFormat; 2448 return e_fileFormat;
2449 } 2449 }
2450 return e_invalidArg; 2450 return e_invalidArg;
2451} 2451}
2452 2452
2453PwMerror PwMDoc::importText_PwM(const QString *file) 2453PwMerror PwMDoc::importText_PwM(const QString *file)
2454{ 2454{
2455#ifndef PWM_EMBEDDED 2455#ifndef PWM_EMBEDDED
2456 PWM_ASSERT(file); 2456 PWM_ASSERT(file);
2457 FILE *f; 2457 FILE *f;
2458 int tmp; 2458 int tmp;
2459 ssize_t ret; 2459 ssize_t ret;
2460 string curCat; 2460 string curCat;
2461 unsigned int entriesRead = 0; 2461 unsigned int entriesRead = 0;
2462 PwMDataItem currItem; 2462 PwMDataItem currItem;
2463 f = fopen(file->latin1(), "r"); 2463 f = fopen(file->latin1(), "r");
2464 if (!f) 2464 if (!f)
2465 return e_openFile; 2465 return e_openFile;
2466 size_t ch_tmp_size = 1024; 2466 size_t ch_tmp_size = 1024;
2467 char *ch_tmp = (char*)malloc(ch_tmp_size); 2467 char *ch_tmp = (char*)malloc(ch_tmp_size);
2468 if (!ch_tmp) { 2468 if (!ch_tmp) {
2469 fclose(f); 2469 fclose(f);
2470 return e_outOfMem; 2470 return e_outOfMem;
2471 } 2471 }
2472 2472
2473 // - check header 2473 // - check header
2474 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. 2474 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line.
2475 goto formatError; 2475 goto formatError;
2476 // check version-string and return version in "ch_tmp". 2476 // check version-string and return version in "ch_tmp".
2477 if (fscanf(f, "PwM v%s", ch_tmp) != 1) { 2477 if (fscanf(f, "PwM v%s", ch_tmp) != 1) {
2478 // header not recognized as PwM generated header 2478 // header not recognized as PwM generated header
2479 goto formatError; 2479 goto formatError;
2480 } 2480 }
2481 // set filepointer behind version-string-line previously checked 2481 // set filepointer behind version-string-line previously checked
2482 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2482 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2483 goto formatError; 2483 goto formatError;
2484 // skip next line containing the build-date 2484 // skip next line containing the build-date
2485 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2485 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2486 goto formatError; 2486 goto formatError;
2487 // read header termination line 2487 // read header termination line
2488 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2488 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2489 goto formatError; 2489 goto formatError;
2490 if (strcmp(ch_tmp, "==============================\n")) 2490 if (strcmp(ch_tmp, "==============================\n"))
2491 goto formatError; 2491 goto formatError;
2492 2492
2493 // - read entries 2493 // - read entries
2494 do { 2494 do {
2495 // find beginning of next category 2495 // find beginning of next category
2496 do { 2496 do {
2497 tmp = fgetc(f); 2497 tmp = fgetc(f);
2498 } while (tmp == '\n' && tmp != EOF); 2498 } while (tmp == '\n' && tmp != EOF);
2499 if (tmp == EOF) 2499 if (tmp == EOF)
2500 break; 2500 break;
2501 2501
2502 // decrement filepos by one 2502 // decrement filepos by one
2503 fseek(f, -1, SEEK_CUR); 2503 fseek(f, -1, SEEK_CUR);
2504 // read cat-name 2504 // read cat-name
2505 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2505 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2506 goto formatError; 2506 goto formatError;
2507 // check cat-name format 2507 // check cat-name format
2508 if (memcmp(ch_tmp, "== Category: ", 13) != 0) 2508 if (memcmp(ch_tmp, "== Category: ", 13) != 0)
2509 goto formatError; 2509 goto formatError;
2510 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) 2510 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0)
2511 goto formatError; 2511 goto formatError;
2512 // copy cat-name 2512 // copy cat-name
2513 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); 2513 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16);
2514 2514
2515 do { 2515 do {
2516 // find beginning of next entry 2516 // find beginning of next entry
2517 do { 2517 do {
2518 tmp = fgetc(f); 2518 tmp = fgetc(f);
2519 } while (tmp == '\n' && tmp != EOF && tmp != '='); 2519 } while (tmp == '\n' && tmp != EOF && tmp != '=');
2520 if (tmp == EOF) 2520 if (tmp == EOF)
2521 break; 2521 break;
2522 if (tmp == '=') { 2522 if (tmp == '=') {
2523 fseek(f, -1, SEEK_CUR); 2523 fseek(f, -1, SEEK_CUR);
2524 break; 2524 break;
2525 } 2525 }
2526 // decrement filepos by one 2526 // decrement filepos by one
2527 fseek(f, -1, SEEK_CUR); 2527 fseek(f, -1, SEEK_CUR);
2528 // read desc-line 2528 // read desc-line
2529 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2529 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2530 goto formatError; 2530 goto formatError;
2531 // check desc-line format 2531 // check desc-line format
2532 if (memcmp(ch_tmp, "-- ", 3) != 0) 2532 if (memcmp(ch_tmp, "-- ", 3) != 0)
2533 goto formatError; 2533 goto formatError;
2534 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) 2534 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0)
2535 goto formatError; 2535 goto formatError;
2536 // add desc-line 2536 // add desc-line
2537 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); 2537 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6);
2538 2538
2539 // read username-line 2539 // read username-line
2540 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2540 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2541 goto formatError; 2541 goto formatError;
2542 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) 2542 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name))
2543 goto formatError; 2543 goto formatError;
2544 2544
2545 // read pw-line 2545 // read pw-line
2546 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2546 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2547 goto formatError; 2547 goto formatError;
2548 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) 2548 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw))
2549 goto formatError; 2549 goto formatError;
2550 2550
2551 // read comment-line 2551 // read comment-line
2552 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2552 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2553 goto formatError; 2553 goto formatError;
2554 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) 2554 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment))
2555 goto formatError; 2555 goto formatError;
2556 2556
2557 // read URL-line 2557 // read URL-line
2558 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2558 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2559 goto formatError; 2559 goto formatError;
2560 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) 2560 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url))
2561 goto formatError; 2561 goto formatError;
2562 2562
2563 // read launcher-line 2563 // read launcher-line
2564 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2564 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2565 goto formatError; 2565 goto formatError;
2566 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) 2566 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher))
2567 goto formatError; 2567 goto formatError;
2568 2568
2569 currItem.lockStat = true; 2569 currItem.lockStat = true;
2570 currItem.listViewPos = -1; 2570 currItem.listViewPos = -1;
2571 addEntry(curCat.c_str(), &currItem, true); 2571 addEntry(curCat.c_str(), &currItem, true);
2572 ++entriesRead; 2572 ++entriesRead;
2573 } while (1); 2573 } while (1);
2574 } while (1); 2574 } while (1);
2575 if (!entriesRead) 2575 if (!entriesRead)
2576 goto formatError; 2576 goto formatError;
2577 2577
2578 free(ch_tmp); 2578 free(ch_tmp);
2579 fclose(f); 2579 fclose(f);
2580 flagDirty(); 2580 flagDirty();
2581 return e_success; 2581 return e_success;
2582 2582
2583 formatError: 2583 formatError:
2584 free(ch_tmp); 2584 free(ch_tmp);
2585 fclose(f); 2585 fclose(f);
2586 return e_fileFormat; 2586 return e_fileFormat;
2587#else 2587#else
2588 PWM_ASSERT(file); 2588 PWM_ASSERT(file);
2589 QFile f(file->latin1()); 2589 QFile f(file->latin1());
2590 int tmp; 2590 int tmp;
2591 ssize_t ret; 2591 ssize_t ret;
2592 string curCat; 2592 string curCat;
2593 unsigned int entriesRead = 0; 2593 unsigned int entriesRead = 0;
2594 PwMDataItem currItem; 2594 PwMDataItem currItem;
2595 bool res = f.open(IO_ReadOnly); 2595 bool res = f.open(IO_ReadOnly);
2596 if (res == false) 2596 if (res == false)
2597 return e_openFile; 2597 return e_openFile;
2598 2598
2599 unsigned int ch_tmp_size = 1024; 2599 unsigned int ch_tmp_size = 1024;
2600 char *ch_tmp = (char*)malloc(ch_tmp_size); 2600 char *ch_tmp = (char*)malloc(ch_tmp_size);
2601 if (!ch_tmp) { 2601 if (!ch_tmp) {
2602 f.close(); 2602 f.close();
2603 return e_outOfMem; 2603 return e_outOfMem;
2604 } 2604 }
2605 2605
2606 // - check header 2606 // - check header
2607 if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line. 2607 if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line.
2608 goto formatError; 2608 goto formatError;
2609 2609
2610 //US read fileversion first, then check if ok. 2610 //US read fileversion first, then check if ok.
2611 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2611 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2612 goto formatError; 2612 goto formatError;
2613 2613
2614 // check version-string and return version in "ch_tmp". 2614 // check version-string and return version in "ch_tmp".
2615 //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) { 2615 //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) {
2616 //US // header not recognized as PwM generated header 2616 //US // header not recognized as PwM generated header
2617 //US goto formatError; 2617 //US goto formatError;
2618 //US} 2618 //US}
2619 //US set filepointer behind version-string-line previously checked 2619 //US set filepointer behind version-string-line previously checked
2620 //US if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2620 //US if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2621 //US goto formatError; 2621 //US goto formatError;
2622 // skip next line containing the build-date 2622 // skip next line containing the build-date
2623 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2623 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2624 goto formatError; 2624 goto formatError;
2625 // read header termination line 2625 // read header termination line
2626 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2626 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2627 goto formatError; 2627 goto formatError;
2628 if (strcmp(ch_tmp, "==============================\n")) 2628 if (strcmp(ch_tmp, "==============================\n"))
2629 goto formatError; 2629 goto formatError;
2630 2630
2631 // - read entries 2631 // - read entries
2632 do { 2632 do {
2633 // find beginning of next category 2633 // find beginning of next category
2634 do { 2634 do {
2635 tmp = f.getch(); 2635 tmp = f.getch();
2636 } while (tmp == '\n' && tmp != EOF); 2636 } while (tmp == '\n' && tmp != EOF);
2637 if (tmp == EOF) 2637 if (tmp == EOF)
2638 break; 2638 break;
2639 2639
2640 // decrement filepos by one 2640 // decrement filepos by one
2641 f.at(f.at()-1); 2641 f.at(f.at()-1);
2642 // read cat-name 2642 // read cat-name
2643 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2643 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2644 goto formatError; 2644 goto formatError;
2645 // check cat-name format 2645 // check cat-name format
2646 if (memcmp(ch_tmp, "== Category: ", 13) != 0) 2646 if (memcmp(ch_tmp, "== Category: ", 13) != 0)
2647 goto formatError; 2647 goto formatError;
2648 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) 2648 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0)
2649 goto formatError; 2649 goto formatError;
2650 // copy cat-name 2650 // copy cat-name
2651 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); 2651 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16);
2652 2652
2653 do { 2653 do {
2654 // find beginning of next entry 2654 // find beginning of next entry
2655 do { 2655 do {
2656 tmp = f.getch(); 2656 tmp = f.getch();
2657 } while (tmp == '\n' && tmp != EOF && tmp != '='); 2657 } while (tmp == '\n' && tmp != EOF && tmp != '=');
2658 if (tmp == EOF) 2658 if (tmp == EOF)
2659 break; 2659 break;
2660 if (tmp == '=') { 2660 if (tmp == '=') {
2661 f.at(f.at()-1); 2661 f.at(f.at()-1);
2662 break; 2662 break;
2663 } 2663 }
2664 // decrement filepos by one 2664 // decrement filepos by one
2665 f.at(f.at()-1); 2665 f.at(f.at()-1);
2666 // read desc-line 2666 // read desc-line
2667 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2667 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2668 goto formatError; 2668 goto formatError;
2669 // check desc-line format 2669 // check desc-line format
2670 if (memcmp(ch_tmp, "-- ", 3) != 0) 2670 if (memcmp(ch_tmp, "-- ", 3) != 0)
2671 goto formatError; 2671 goto formatError;
2672 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) 2672 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0)
2673 goto formatError; 2673 goto formatError;
2674 // add desc-line 2674 // add desc-line
2675 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); 2675 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6);
2676 2676
2677 // read username-line 2677 // read username-line
2678 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2678 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2679 goto formatError; 2679 goto formatError;
2680 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) 2680 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name))
2681 goto formatError; 2681 goto formatError;
2682 2682
2683 // read pw-line 2683 // read pw-line
2684 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2684 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2685 goto formatError; 2685 goto formatError;
2686 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) 2686 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw))
2687 goto formatError; 2687 goto formatError;
2688 2688
2689 // read comment-line 2689 // read comment-line
2690 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2690 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2691 goto formatError; 2691 goto formatError;
2692 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) 2692 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment))
2693 goto formatError; 2693 goto formatError;
2694 2694
2695 // read URL-line 2695 // read URL-line
2696 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2696 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2697 goto formatError; 2697 goto formatError;
2698 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) 2698 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url))
2699 goto formatError; 2699 goto formatError;
2700 2700
2701 // read launcher-line 2701 // read launcher-line
2702 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2702 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2703 goto formatError; 2703 goto formatError;
2704 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) 2704 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher))
2705 goto formatError; 2705 goto formatError;
2706 2706
2707 currItem.lockStat = true; 2707 currItem.lockStat = true;
2708 currItem.listViewPos = -1; 2708 currItem.listViewPos = -1;
2709 addEntry(curCat.c_str(), &currItem, true); 2709 addEntry(curCat.c_str(), &currItem, true);
2710 ++entriesRead; 2710 ++entriesRead;
2711 } while (1); 2711 } while (1);
2712 } while (1); 2712 } while (1);
2713 if (!entriesRead) 2713 if (!entriesRead)
2714 goto formatError; 2714 goto formatError;
2715 2715
2716 free(ch_tmp); 2716 free(ch_tmp);
2717 f.close(); 2717 f.close();
2718 flagDirty(); 2718 flagDirty();
2719 return e_success; 2719 return e_success;
2720 2720
2721 formatError: 2721 formatError:
2722 free(ch_tmp); 2722 free(ch_tmp);
2723 f.close(); 2723 f.close();
2724 return e_fileFormat; 2724 return e_fileFormat;
2725 2725
2726#endif 2726#endif
2727 2727
2728} 2728}
2729 2729
2730bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) 2730bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out)
2731{ 2731{
2732 PWM_ASSERT(in && out); 2732 PWM_ASSERT(in && out);
2733 ssize_t i = 0, len = in_size - 1; 2733 ssize_t i = 0, len = in_size - 1;
2734 while (i < len) { 2734 while (i < len) {
2735 if (in[i] == ':') 2735 if (in[i] == ':')
2736 break; 2736 break;
2737 ++i; 2737 ++i;
2738 } 2738 }
2739 i += 2; 2739 i += 2;
2740 *out = ""; 2740 *out = "";
2741 out->append(in + i, in_size - i - 1); 2741 out->append(in + i, in_size - i - 1);
2742 return true; 2742 return true;
2743} 2743}
2744 2744
2745PwMerror PwMDoc::exportToGpasman(const QString *file) 2745PwMerror PwMDoc::exportToGpasman(const QString *file)
2746{ 2746{
2747 PWM_ASSERT(file); 2747 PWM_ASSERT(file);
2748 GpasmanFile gp; 2748 GpasmanFile gp;
2749 int ret; 2749 int ret;
2750 2750
2751 if (!unlockAll_tempoary()) 2751 if (!unlockAll_tempoary())
2752 return e_lock; 2752 return e_lock;
2753 2753
2754 QString gpmPassword; 2754 QString gpmPassword;
2755 while (1) { 2755 while (1) {
2756 gpmPassword = requestNewMpw(0); 2756 gpmPassword = requestNewMpw(0);
2757 if (gpmPassword == "") { 2757 if (gpmPassword == "") {
2758 unlockAll_tempoary(true); 2758 unlockAll_tempoary(true);
2759 return e_noPw; 2759 return e_noPw;
2760 } 2760 }
2761 if (gpmPassword.length() < 4) { 2761 if (gpmPassword.length() < 4) {
2762 gpmPwLenErrMsgBox(); 2762 gpmPwLenErrMsgBox();
2763 } else { 2763 } else {
2764 break; 2764 break;
2765 } 2765 }
2766 } 2766 }
2767 2767
2768 ret = gp.save_init(file->latin1(), gpmPassword.latin1()); 2768 ret = gp.save_init(file->latin1(), gpmPassword.latin1());
2769 if (ret != 1) { 2769 if (ret != 1) {
2770 unlockAll_tempoary(true); 2770 unlockAll_tempoary(true);
2771 return e_accessFile; 2771 return e_accessFile;
2772 } 2772 }
2773 2773
2774 char *entry[4]; 2774 char *entry[4];
2775 unsigned int numCat = numCategories(), i; 2775 unsigned int numCat = numCategories(), i;
2776 unsigned int numEntr, j; 2776 unsigned int numEntr, j;
2777 int descLen, nameLen, pwLen, commentLen; 2777 int descLen, nameLen, pwLen, commentLen;
2778 for (i = 0; i < numCat; ++i) { 2778 for (i = 0; i < numCat; ++i) {
2779 numEntr = numEntries(i); 2779 numEntr = numEntries(i);
2780 for (j = 0; j < numEntr; ++j) { 2780 for (j = 0; j < numEntr; ++j) {
2781 descLen = dti.dta[i].d[j].desc.length(); 2781 descLen = dti.dta[i].d[j].desc.length();
2782 nameLen = dti.dta[i].d[j].name.length(); 2782 nameLen = dti.dta[i].d[j].name.length();
2783 pwLen = dti.dta[i].d[j].pw.length(); 2783 pwLen = dti.dta[i].d[j].pw.length();
2784 commentLen = dti.dta[i].d[j].comment.length(); 2784 commentLen = dti.dta[i].d[j].comment.length();
2785 entry[0] = new char[descLen + 1]; 2785 entry[0] = new char[descLen + 1];
2786 entry[1] = new char[nameLen + 1]; 2786 entry[1] = new char[nameLen + 1];
2787 entry[2] = new char[pwLen + 1]; 2787 entry[2] = new char[pwLen + 1];
2788 entry[3] = new char[commentLen + 1]; 2788 entry[3] = new char[commentLen + 1];
2789 strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); 2789 strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str());
2790 strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); 2790 strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str());
2791 strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); 2791 strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str());
2792 strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); 2792 strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str());
2793 entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; 2793 entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0';
2794 entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; 2794 entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0';
2795 entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; 2795 entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0';
2796 entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; 2796 entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0';
2797 2797
2798 ret = gp.save_entry(entry); 2798 ret = gp.save_entry(entry);
2799 if (ret == -1){ 2799 if (ret == -1){
2800 delete [] entry[0]; 2800 delete [] entry[0];
2801 delete [] entry[1]; 2801 delete [] entry[1];
2802 delete [] entry[2]; 2802 delete [] entry[2];
2803 delete [] entry[3]; 2803 delete [] entry[3];
2804 gp.save_finalize(); 2804 gp.save_finalize();
2805 unlockAll_tempoary(true); 2805 unlockAll_tempoary(true);
2806 return e_writeFile; 2806 return e_writeFile;
2807 } 2807 }
2808 2808
2809 delete [] entry[0]; 2809 delete [] entry[0];
2810 delete [] entry[1]; 2810 delete [] entry[1];
2811 delete [] entry[2]; 2811 delete [] entry[2];
2812 delete [] entry[3]; 2812 delete [] entry[3];
2813 } 2813 }
2814 } 2814 }
2815 unlockAll_tempoary(true); 2815 unlockAll_tempoary(true);
2816 if (gp.save_finalize() == -1) 2816 if (gp.save_finalize() == -1)
2817 return e_writeFile; 2817 return e_writeFile;
2818 2818
2819 return e_success; 2819 return e_success;
2820} 2820}
2821 2821
2822PwMerror PwMDoc::importFromGpasman(const QString *file) 2822PwMerror PwMDoc::importFromGpasman(const QString *file)
2823{ 2823{
2824 PWM_ASSERT(file); 2824 PWM_ASSERT(file);
2825 QString pw = requestMpw(false); 2825 QString pw = requestMpw(false);
2826 if (pw == "") 2826 if (pw == "")
2827 return e_noPw; 2827 return e_noPw;
2828 GpasmanFile gp; 2828 GpasmanFile gp;
2829 int ret, i; 2829 int ret, i;
2830 PwMerror ret2; 2830 PwMerror ret2;
2831 char *entry[4]; 2831 char *entry[4];
2832 PwMDataItem tmpData; 2832 PwMDataItem tmpData;
2833 ret = gp.load_init(file->latin1(), pw.latin1()); 2833 ret = gp.load_init(file->latin1(), pw.latin1());
2834 if (ret != 1) 2834 if (ret != 1)
2835 return e_accessFile; 2835 return e_accessFile;
2836 2836
2837 do { 2837 do {
2838 ret = gp.load_entry(entry); 2838 ret = gp.load_entry(entry);
2839 if(ret != 1) 2839 if(ret != 1)
2840 break; 2840 break;
2841 tmpData.desc = entry[0]; 2841 tmpData.desc = entry[0];
2842 tmpData.name = entry[1]; 2842 tmpData.name = entry[1];
2843 tmpData.pw = entry[2]; 2843 tmpData.pw = entry[2];
2844 tmpData.comment = entry[3]; 2844 tmpData.comment = entry[3];
2845 tmpData.lockStat = true; 2845 tmpData.lockStat = true;
2846 tmpData.listViewPos = -1; 2846 tmpData.listViewPos = -1;
2847 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); 2847 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true);
2848 for (i = 0; i < 4; ++i) 2848 for (i = 0; i < 4; ++i)
2849 free(entry[i]); 2849 free(entry[i]);
2850 if (ret2 == e_maxAllowedEntr) { 2850 if (ret2 == e_maxAllowedEntr) {
2851 gp.load_finalize(); 2851 gp.load_finalize();
2852 return e_maxAllowedEntr; 2852 return e_maxAllowedEntr;
2853 } 2853 }
2854 } while (1); 2854 } while (1);
2855 gp.load_finalize(); 2855 gp.load_finalize();
2856 if (isDocEmpty()) 2856 if (isDocEmpty())
2857 return e_wrongPw; // we assume this. 2857 return e_wrongPw; // we assume this.
2858 2858
2859 flagDirty(); 2859 flagDirty();
2860 return e_success; 2860 return e_success;
2861} 2861}
2862 2862
2863 2863
2864//US: we use the stl sort algorythm to sort all elements in the order 2864//US: we use the stl sort algorythm to sort all elements in the order
2865//of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1 2865//of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1
2866struct PwMDataItemListViewPosSort 2866struct PwMDataItemListViewPosSort
2867{ 2867{
2868 bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd) 2868 bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd)
2869 { 2869 {
2870 //qDebug("pwMDoc::PwMDataItemListViewPosSort()"); 2870 //qDebug("pwMDoc::PwMDataItemListViewPosSort()");
2871 if ((rpEnd)->listViewPos < 0) 2871 if ((rpEnd)->listViewPos < 0)
2872 return false; 2872 return false;
2873 else 2873 else
2874 return (rpStart)->listViewPos < (rpEnd)->listViewPos; 2874 return (rpStart)->listViewPos < (rpEnd)->listViewPos;
2875 } 2875 }
2876}; 2876};
2877 2877
2878void PwMDoc::ensureLvp() 2878void PwMDoc::ensureLvp()
2879{ 2879{
2880 if (isDocEmpty()) 2880 if (isDocEmpty())
2881 return; 2881 return;
2882 2882
2883 //US ENH BUG: when using syncronizing, this way of sorting 2883 //US ENH BUG: when using syncronizing, this way of sorting
2884 //is not sufficient, because there might be empty spaces 2884 //is not sufficient, because there might be empty spaces
2885 // at the beginning. But the old algorythm only can add elements 2885 // at the beginning. But the old algorythm only can add elements
2886 //to the end.The result are crashes because of list overflows 2886 //to the end.The result are crashes because of list overflows
2887 //we need something to fill all gaps. 2887 //we need something to fill all gaps.
2888 vector<PwMDataItem*> sorted; 2888 vector<PwMDataItem*> sorted;
2889 vector< PwMDataItem*>::iterator sortedBegin, 2889 vector< PwMDataItem*>::iterator sortedBegin,
2890 sortedEnd, 2890 sortedEnd,
2891 sortedI; 2891 sortedI;
2892 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 2892 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
2893 catEnd = dti.dta.end(), 2893 catEnd = dti.dta.end(),
2894 catI = catBegin; 2894 catI = catBegin;
2895 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 2895 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
2896 int lvpTop, tmpLvp; 2896 int lvpTop, tmpLvp;
2897 2897
2898 //qDebug("collect:"); 2898 //qDebug("collect:");
2899 2899
2900 while (catI != catEnd) { 2900 while (catI != catEnd) {
2901 lvpTop = -1; 2901 lvpTop = -1;
2902 sorted.clear(); 2902 sorted.clear();
2903 2903
2904 entrBegin = catI->d.begin(); 2904 entrBegin = catI->d.begin();
2905 entrEnd = catI->d.end(); 2905 entrEnd = catI->d.end();
2906 entrI = entrBegin; 2906 entrI = entrBegin;
2907 2907
2908 //US: we use the stl sort algorythm to sort all elements in the order 2908 //US: we use the stl sort algorythm to sort all elements in the order
2909 //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1 2909 //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1
2910 while (entrI != entrEnd) { 2910 while (entrI != entrEnd) {
2911 //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); 2911 //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
2912 sorted.push_back((PwMDataItem*)&(*entrI)); 2912 sorted.push_back((PwMDataItem*)&(*entrI));
2913 ++entrI; 2913 ++entrI;
2914 } 2914 }
2915 2915
2916 sortedBegin = sorted.begin(); 2916 sortedBegin = sorted.begin();
2917 sortedEnd = sorted.end(); 2917 sortedEnd = sorted.end();
2918 2918
2919 sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort()); 2919 sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort());
2920 2920
2921 // qDebug("resort:"); 2921 // qDebug("resort:");
2922 //now we have all sorted in a collection 2922 //now we have all sorted in a collection
2923 //Now start with the sorted and reset listviewpos. 2923 //Now start with the sorted and reset listviewpos.
2924 sortedBegin = sorted.begin(); 2924 sortedBegin = sorted.begin();
2925 sortedEnd = sorted.end(); 2925 sortedEnd = sorted.end();
2926 sortedI = sortedBegin; 2926 sortedI = sortedBegin;
2927 2927
2928 while (sortedI != sortedEnd) { 2928 while (sortedI != sortedEnd) {
2929 // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1); 2929 // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1);
2930 (*sortedI)->listViewPos = ++lvpTop; 2930 (*sortedI)->listViewPos = ++lvpTop;
2931 ++sortedI; 2931 ++sortedI;
2932 } 2932 }
2933 2933
2934 /*/debug 2934 /*/debug
2935 entrBegin = catI->d.begin(); 2935 entrBegin = catI->d.begin();
2936 entrEnd = catI->d.end(); 2936 entrEnd = catI->d.end();
2937 entrI = entrBegin; 2937 entrI = entrBegin;
2938 2938
2939 while (entrI != entrEnd) { 2939 while (entrI != entrEnd) {
2940 qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); 2940 qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
2941 ++entrI; 2941 ++entrI;
2942 } 2942 }
2943 */ 2943 */
2944 2944
2945 ++catI; 2945 ++catI;
2946 } 2946 }
2947} 2947}
2948 2948
2949QString PwMDoc::getTitle() 2949QString PwMDoc::getTitle()
2950{ 2950{
2951 /* NOTE: We have to ensure, that the returned title 2951 /* NOTE: We have to ensure, that the returned title
2952 * is unique and not reused somewhere else while 2952 * is unique and not reused somewhere else while
2953 * this document is valid (open). 2953 * this document is valid (open).
2954 */ 2954 */
2955 QString title(getFilename()); 2955 QString title(getFilename());
2956 2956
2957 //US ENH: The whole filename on PDAs is too long. So use only the last characters 2957 //US ENH: The whole filename on PDAs is too long. So use only the last characters
2958 if (QApplication::desktop()->width() < 640) 2958 if (QApplication::desktop()->width() < 640)
2959 { 2959 {
2960 if (title.length() > 30) 2960 if (title.length() > 30)
2961 title = "..." + title.right(30); 2961 title = "..." + title.right(30);
2962 2962
2963 } 2963 }
2964 2964
2965 2965
2966 if (title.isEmpty()) { 2966 if (title.isEmpty()) {
2967 if (unnamedNum == 0) { 2967 if (unnamedNum == 0) {
2968 unnamedNum = PwMDocList::getNewUnnamedNumber(); 2968 unnamedNum = PwMDocList::getNewUnnamedNumber();
2969 PWM_ASSERT(unnamedNum != 0); 2969 PWM_ASSERT(unnamedNum != 0);
2970 } 2970 }
2971 title = DEFAULT_TITLE; 2971 title = DEFAULT_TITLE;
2972 title += " "; 2972 title += " ";
2973 title += tostr(unnamedNum).c_str(); 2973 title += tostr(unnamedNum).c_str();
2974 } 2974 }
2975 return title; 2975 return title;
2976} 2976}
2977 2977
2978bool PwMDoc::tryDelete() 2978bool PwMDoc::tryDelete()
2979{ 2979{
2980 2980
2981 if (deleted) 2981 if (deleted)
2982 return true; 2982 return true;
2983 int ret; 2983 int ret;
2984 if (isDirty()) { 2984 if (isDirty()) {
2985 ret = dirtyAskSave(getTitle()); 2985 ret = dirtyAskSave(getTitle());
2986 if (ret == 0) { // save to disk 2986 if (ret == 0) { // save to disk
2987 if (!saveDocUi(this)) 2987 if (!saveDocUi(this))
2988 goto out_ignore; 2988 goto out_ignore;
2989 } else if (ret == 1) { // don't save and delete 2989 } else if (ret == 1) { // don't save and delete
2990 goto out_accept; 2990 goto out_accept;
2991 } else { // cancel operation 2991 } else { // cancel operation
2992 goto out_ignore; 2992 goto out_ignore;
2993 } 2993 }
2994 } 2994 }
2995out_accept: 2995out_accept:
2996 deleted = true; 2996 deleted = true;
2997 delete this; 2997 delete this;
2998 return true; 2998 return true;
2999out_ignore: 2999out_ignore:
3000 return false; 3000 return false;
3001} 3001}
3002 3002
3003 3003
3004 3004
3005#ifdef PWM_EMBEDDED 3005#ifdef PWM_EMBEDDED
3006//US ENH: this is the magic function that syncronizes the this doc with the remote doc 3006//US ENH: this is the magic function that syncronizes the this doc with the remote doc
3007//US it could have been defined as static, but I did not want to. 3007//US it could have been defined as static, but I did not want to.
3008PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) 3008PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode )
3009{ 3009{
3010 int addedPasswordsLocal = 0; 3010 int addedPasswordsLocal = 0;
3011 int addedPasswordsRemote = 0; 3011 int addedPasswordsRemote = 0;
3012 int deletedPasswordsRemote = 0; 3012 int deletedPasswordsRemote = 0;
3013 int deletedPasswordsLocal = 0; 3013 int deletedPasswordsLocal = 0;
3014 int changedLocal = 0; 3014 int changedLocal = 0;
3015 int changedRemote = 0; 3015 int changedRemote = 0;
3016 3016
3017 PwMSyncItem* syncItemLocal; 3017 PwMSyncItem* syncItemLocal;
3018 PwMSyncItem* syncItemRemote; 3018 PwMSyncItem* syncItemRemote;
3019 3019
3020 QString mCurrentSyncName = manager->getCurrentSyncName(); 3020 QString mCurrentSyncName = manager->getCurrentSyncName();
3021 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3021 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3022 3022
3023 bool fullDateRange = false; 3023 bool fullDateRange = false;
3024 int take; 3024 int take;
3025 // local->resetTempSyncStat(); 3025 // local->resetTempSyncStat();
3026 QDateTime mLastSync = QDateTime::currentDateTime(); 3026 QDateTime mLastSync = QDateTime::currentDateTime();
3027 QDateTime modifiedSync = mLastSync; 3027 QDateTime modifiedSync = mLastSync;
3028 3028
3029 unsigned int index; 3029 unsigned int index;
3030 //Step 1. Find syncinfo in Local file and create if not existent. 3030 //Step 1. Find syncinfo in Local file and create if not existent.
3031 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 3031 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
3032 if (found == false) 3032 if (found == false)
3033 { 3033 {
3034 PwMSyncItem newSyncItemLocal; 3034 PwMSyncItem newSyncItemLocal;
3035 newSyncItemLocal.syncName = mCurrentSyncDevice.latin1(); 3035 newSyncItemLocal.syncName = mCurrentSyncDevice.latin1();
3036 newSyncItemLocal.lastSyncDate = mLastSync; 3036 newSyncItemLocal.lastSyncDate = mLastSync;
3037 syncLocal->addSyncDataEntry(&newSyncItemLocal, true); 3037 syncLocal->addSyncDataEntry(&newSyncItemLocal, true);
3038 found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 3038 found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
3039 if (found == false) { 3039 if (found == false) {
3040 qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); 3040 qDebug("PwMDoc::syncronize : newly created local sync data could not be found");
3041 return e_syncError; 3041 return e_syncError;
3042 } 3042 }
3043 } 3043 }
3044 3044
3045 syncItemLocal = syncLocal->getSyncDataEntry(index); 3045 syncItemLocal = syncLocal->getSyncDataEntry(index);
3046 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); 3046 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1());
3047 3047
3048 //Step 2. Find syncinfo in remote file and create if not existent. 3048 //Step 2. Find syncinfo in remote file and create if not existent.
3049 found = syncRemote->findSyncData(mCurrentSyncName, &index); 3049 found = syncRemote->findSyncData(mCurrentSyncName, &index);
3050 if (found == false) 3050 if (found == false)
3051 { 3051 {
3052 qDebug("FULLDATE 1"); 3052 qDebug("FULLDATE 1");
3053 fullDateRange = true; 3053 fullDateRange = true;
3054 PwMSyncItem newSyncItemRemote; 3054 PwMSyncItem newSyncItemRemote;
3055 newSyncItemRemote.syncName = mCurrentSyncName.latin1(); 3055 newSyncItemRemote.syncName = mCurrentSyncName.latin1();
3056 newSyncItemRemote.lastSyncDate = mLastSync; 3056 newSyncItemRemote.lastSyncDate = mLastSync;
3057 syncRemote->addSyncDataEntry(&newSyncItemRemote, true); 3057 syncRemote->addSyncDataEntry(&newSyncItemRemote, true);
3058 found = syncRemote->findSyncData(mCurrentSyncName, &index); 3058 found = syncRemote->findSyncData(mCurrentSyncName, &index);
3059 if (found == false) { 3059 if (found == false) {
3060 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); 3060 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found");
3061 return e_syncError; 3061 return e_syncError;
3062 } 3062 }
3063 } 3063 }
3064 3064
3065 syncItemRemote = syncRemote->getSyncDataEntry(index); 3065 syncItemRemote = syncRemote->getSyncDataEntry(index);
3066 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); 3066 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1());
3067 //and remove the found entry here. We will reenter it later again. 3067 //and remove the found entry here. We will reenter it later again.
3068 //US syncRemote->delSyncDataEntry(index, true); 3068 //US syncRemote->delSyncDataEntry(index, true);
3069 3069
3070 3070
3071 if ( syncItemLocal->lastSyncDate == mLastSync ) { 3071 if ( syncItemLocal->lastSyncDate == mLastSync ) {
3072 qDebug("FULLDATE 2"); 3072 qDebug("FULLDATE 2");
3073 fullDateRange = true; 3073 fullDateRange = true;
3074 } 3074 }
3075 3075
3076 if ( ! fullDateRange ) { 3076 if ( ! fullDateRange ) {
3077 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { 3077 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) {
3078 3078
3079 fullDateRange = true; 3079 fullDateRange = true;
3080 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); 3080 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() );
3081 } 3081 }
3082 } 3082 }
3083 // fullDateRange = true; // debug only! 3083 // fullDateRange = true; // debug only!
3084 if ( fullDateRange ) 3084 if ( fullDateRange )
3085 mLastSync = QDateTime::currentDateTime().addDays( -100*365); 3085 mLastSync = QDateTime::currentDateTime().addDays( -100*365);
3086 else 3086 else
3087 mLastSync = syncItemLocal->lastSyncDate; 3087 mLastSync = syncItemLocal->lastSyncDate;
3088 3088
3089 3089
3090 qDebug("*************************** "); 3090 qDebug("*************************** ");
3091 qDebug("mLastSync %s ",mLastSync.toString().latin1() ); 3091 qDebug("mLastSync %s ",mLastSync.toString().latin1() );
3092 QStringList er = syncRemote->getIDEntryList(); 3092 QStringList er = syncRemote->getIDEntryList();
3093 PwMDataItem* inRemote ;//= er.first(); 3093 PwMDataItem* inRemote ;//= er.first();
3094 PwMDataItem* inLocal; 3094 PwMDataItem* inLocal;
3095 unsigned int catLocal, indexLocal; 3095 unsigned int catLocal, indexLocal;
3096 unsigned int catRemote, indexRemote; 3096 unsigned int catRemote, indexRemote;
3097 3097
3098 QString uid; 3098 QString uid;
3099 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 3099 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
3100 3100
3101 int modulo = (er.count()/10)+1; 3101 int modulo = (er.count()/10)+1;
3102 unsigned int incCounter = 0; 3102 unsigned int incCounter = 0;
3103 while ( incCounter < er.count()) { 3103 while ( incCounter < er.count()) {
3104 if (manager->isProgressBarCanceled()) 3104 if (manager->isProgressBarCanceled())
3105 return e_syncError; 3105 return e_syncError;
3106 if ( incCounter % modulo == 0 ) 3106 if ( incCounter % modulo == 0 )
3107 manager->showProgressBar(incCounter); 3107 manager->showProgressBar(incCounter);
3108 3108
3109 uid = er[ incCounter ]; 3109 uid = er[ incCounter ];
3110 qDebug("sync uid %s from remote file", uid.latin1()); 3110 qDebug("sync uid %s from remote file", uid.latin1());
3111 3111
3112 qApp->processEvents(); 3112 qApp->processEvents();
3113 3113
3114 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3114 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3115 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3115 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3116 PWM_ASSERT(inRemote); 3116 PWM_ASSERT(inRemote);
3117 if ( inLocal != 0 ) { // maybe conflict - same uid in both files 3117 if ( inLocal != 0 ) { // maybe conflict - same uid in both files
3118 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { 3118 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
3119 qDebug("take %d %s ", take, inLocal->desc.c_str()); 3119 qDebug("take %d %s ", take, inLocal->desc.c_str());
3120 if ( take == 3 ) 3120 if ( take == 3 )
3121 return e_syncError; 3121 return e_syncError;
3122 if ( take == 1 ) {// take local 3122 if ( take == 1 ) {// take local
3123 int oldlistpos = inRemote->listViewPos; 3123 int oldlistpos = inRemote->listViewPos;
3124 (*inRemote) = (*inLocal); 3124 (*inRemote) = (*inLocal);
3125 inRemote->listViewPos = oldlistpos; 3125 inRemote->listViewPos = oldlistpos;
3126 ++changedRemote; 3126 ++changedRemote;
3127 } else { // take == 2 take remote 3127 } else { // take == 2 take remote
3128 int oldlistpos = inLocal->listViewPos; 3128 int oldlistpos = inLocal->listViewPos;
3129 (*inLocal) = (*inRemote); 3129 (*inLocal) = (*inRemote);
3130 inLocal->listViewPos = oldlistpos; 3130 inLocal->listViewPos = oldlistpos;
3131 ++changedLocal; 3131 ++changedLocal;
3132 } 3132 }
3133 } 3133 }
3134 } else { // no conflict 3134 } else { // no conflict
3135 if ( inRemote->meta.update > mLastSync || mode == 5 ) { 3135 if ( inRemote->meta.update > mLastSync || mode == 5 ) {
3136 inRemote->meta.update = modifiedSync; 3136 inRemote->meta.update = modifiedSync;
3137 3137
3138 //first check if we have a matching category in the local file 3138 //first check if we have a matching category in the local file
3139 const string* remotecat = syncRemote->getCategory(catRemote); 3139 const string* remotecat = syncRemote->getCategory(catRemote);
3140 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); 3140 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false);
3141 3141
3142 ++addedPasswordsLocal; 3142 ++addedPasswordsLocal;
3143 } else { 3143 } else {
3144 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 3144 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
3145 syncRemote->delEntry(catRemote, indexRemote, true); 3145 syncRemote->delEntry(catRemote, indexRemote, true);
3146 ++deletedPasswordsRemote; 3146 ++deletedPasswordsRemote;
3147 } 3147 }
3148 } 3148 }
3149 3149
3150 ++incCounter; 3150 ++incCounter;
3151 } 3151 }
3152 3152
3153 3153
3154 er.clear(); 3154 er.clear();
3155 QStringList el = syncLocal->getIDEntryList(); 3155 QStringList el = syncLocal->getIDEntryList();
3156 modulo = (el.count()/10)+1; 3156 modulo = (el.count()/10)+1;
3157 3157
3158 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 3158 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
3159 incCounter = 0; 3159 incCounter = 0;
3160 while ( incCounter < el.count()) { 3160 while ( incCounter < el.count()) {
3161 qApp->processEvents(); 3161 qApp->processEvents();
3162 if (manager->isProgressBarCanceled()) 3162 if (manager->isProgressBarCanceled())
3163 return e_syncError; 3163 return e_syncError;
3164 if ( incCounter % modulo == 0 ) 3164 if ( incCounter % modulo == 0 )
3165 manager->showProgressBar(incCounter); 3165 manager->showProgressBar(incCounter);
3166 uid = el[ incCounter ]; 3166 uid = el[ incCounter ];
3167 qDebug("sync uid %s from local file", uid.latin1()); 3167 qDebug("sync uid %s from local file", uid.latin1());
3168 3168
3169 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3169 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3170 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3170 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3171 PWM_ASSERT(inLocal); 3171 PWM_ASSERT(inLocal);
3172 3172
3173 if ( inRemote == 0 ) { 3173 if ( inRemote == 0 ) {
3174 if ( inLocal->meta.update < mLastSync && mode != 4 ) { 3174 if ( inLocal->meta.update < mLastSync && mode != 4 ) {
3175 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 3175 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
3176 syncLocal->delEntry(catLocal, indexLocal, true); 3176 syncLocal->delEntry(catLocal, indexLocal, true);
3177 ++deletedPasswordsLocal; 3177 ++deletedPasswordsLocal;
3178 } else { 3178 } else {
3179 if ( ! manager->mWriteBackExistingOnly ) { 3179 if ( ! manager->mWriteBackExistingOnly ) {
3180 ++addedPasswordsRemote; 3180 ++addedPasswordsRemote;
3181 inLocal->meta.update = modifiedSync; 3181 inLocal->meta.update = modifiedSync;
3182 3182
3183 //first check if we have a matching category in the remote file 3183 //first check if we have a matching category in the remote file
3184 const string* localcat = syncLocal->getCategory(catLocal); 3184 const string* localcat = syncLocal->getCategory(catLocal);
3185 3185
3186 PwMDataItem newEntry; 3186 PwMDataItem newEntry;
3187 newEntry = *inLocal; 3187 newEntry = *inLocal;
3188 inRemote = &newEntry; 3188 inRemote = &newEntry;
3189 3189
3190 //USsyncRemote->insertAddressee( inRemote, false ); 3190 //USsyncRemote->insertAddressee( inRemote, false );
3191 syncRemote->addEntry(localcat->c_str(), inRemote, true, false); 3191 syncRemote->addEntry(localcat->c_str(), inRemote, true, false);
3192 3192
3193 } 3193 }
3194 } 3194 }
3195 3195
3196 } 3196 }
3197 ++incCounter; 3197 ++incCounter;
3198 } 3198 }
3199 el.clear(); 3199 el.clear();
3200 manager->hideProgressBar(); 3200 manager->hideProgressBar();
3201 3201
3202 // Now write the info back into the sync data space of the files 3202 // Now write the info back into the sync data space of the files
3203 3203
3204 mLastSync = QDateTime::currentDateTime().addSecs( 1 ); 3204 mLastSync = QDateTime::currentDateTime().addSecs( 1 );
3205 // get rid of micro seconds 3205 // get rid of micro seconds
3206 QTime t = mLastSync.time(); 3206 QTime t = mLastSync.time();
3207 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 3207 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
3208 3208
3209 3209
3210 syncItemLocal->lastSyncDate = mLastSync; 3210 syncItemLocal->lastSyncDate = mLastSync;
3211 syncItemRemote->lastSyncDate = mLastSync; 3211 syncItemRemote->lastSyncDate = mLastSync;
3212 3212
3213 QString mes; 3213 QString mes;
3214 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"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote ); 3214 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"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote );
3215 if ( manager->mShowSyncSummary ) { 3215 if ( manager->mShowSyncSummary ) {
3216 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); 3216 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") );
3217 } 3217 }
3218 qDebug( mes ); 3218 qDebug( mes );
3219 return e_success; 3219 return e_success;
3220} 3220}
3221 3221
3222 3222
3223int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) 3223int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full )
3224{ 3224{
3225 // 0 equal 3225 // 0 equal
3226 // 1 take local 3226 // 1 take local
3227 // 2 take remote 3227 // 2 take remote
3228 // 3 cancel 3228 // 3 cancel
3229 QDateTime localMod = local->meta.update; 3229 QDateTime localMod = local->meta.update;
3230 QDateTime remoteMod = remote->meta.update; 3230 QDateTime remoteMod = remote->meta.update;
3231 3231
3232 if ( localMod == remoteMod ) 3232 if ( localMod == remoteMod )
3233 return 0; 3233 return 0;
3234 3234
3235 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); 3235 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() );
3236 3236
3237 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 3237 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
3238 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 3238 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
3239 //full = true; //debug only 3239 //full = true; //debug only
3240 if ( full ) { 3240 if ( full ) {
3241 bool equ = ( (*local) == (*remote) ); 3241 bool equ = ( (*local) == (*remote) );
3242 if ( equ ) { 3242 if ( equ ) {
3243 //qDebug("equal "); 3243 //qDebug("equal ");
3244 if ( mode < SYNC_PREF_FORCE_LOCAL ) 3244 if ( mode < SYNC_PREF_FORCE_LOCAL )
3245 return 0; 3245 return 0;
3246 3246
3247 }//else //debug only 3247 }//else //debug only
3248 //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); 3248 //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str());
3249 } 3249 }
3250 3250
3251 int result; 3251 int result;
3252 bool localIsNew; 3252 bool localIsNew;
3253 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 3253 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
3254 3254
3255 if ( full && mode < SYNC_PREF_NEWEST ) 3255 if ( full && mode < SYNC_PREF_NEWEST )
3256 mode = SYNC_PREF_ASK; 3256 mode = SYNC_PREF_ASK;
3257 3257
3258 switch( mode ) { 3258 switch( mode ) {
3259 case SYNC_PREF_LOCAL: 3259 case SYNC_PREF_LOCAL:
3260 if ( lastSync > remoteMod ) 3260 if ( lastSync > remoteMod )
3261 return 1; 3261 return 1;
3262 if ( lastSync > localMod ) 3262 if ( lastSync > localMod )
3263 return 2; 3263 return 2;
3264 return 1; 3264 return 1;
3265 break; 3265 break;
3266 case SYNC_PREF_REMOTE: 3266 case SYNC_PREF_REMOTE:
3267 if ( lastSync > remoteMod ) 3267 if ( lastSync > remoteMod )
3268 return 1; 3268 return 1;
3269 if ( lastSync > localMod ) 3269 if ( lastSync > localMod )
3270 return 2; 3270 return 2;
3271 return 2; 3271 return 2;
3272 break; 3272 break;
3273 case SYNC_PREF_NEWEST: 3273 case SYNC_PREF_NEWEST:
3274 if ( localMod > remoteMod ) 3274 if ( localMod > remoteMod )
3275 return 1; 3275 return 1;
3276 else 3276 else
3277 return 2; 3277 return 2;
3278 break; 3278 break;
3279 case SYNC_PREF_ASK: 3279 case SYNC_PREF_ASK:
3280 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 3280 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
3281 if ( lastSync > remoteMod ) 3281 if ( lastSync > remoteMod )
3282 return 1; 3282 return 1;
3283 if ( lastSync > localMod ) 3283 if ( lastSync > localMod )
3284 return 2; 3284 return 2;
3285 localIsNew = localMod >= remoteMod; 3285 localIsNew = localMod >= remoteMod;
3286 //qDebug("conflict! ************************************** "); 3286 //qDebug("conflict! ************************************** ");
3287 { 3287 {
3288 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); 3288 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ );
3289 result = acd.executeD(localIsNew); 3289 result = acd.executeD(localIsNew);
3290 return result; 3290 return result;
3291 } 3291 }
3292 break; 3292 break;
3293 case SYNC_PREF_FORCE_LOCAL: 3293 case SYNC_PREF_FORCE_LOCAL:
3294 return 1; 3294 return 1;
3295 break; 3295 break;
3296 case SYNC_PREF_FORCE_REMOTE: 3296 case SYNC_PREF_FORCE_REMOTE:
3297 return 2; 3297 return 2;
3298 break; 3298 break;
3299 3299
3300 default: 3300 default:
3301 // SYNC_PREF_TAKE_BOTH not implemented 3301 // SYNC_PREF_TAKE_BOTH not implemented
3302 break; 3302 break;
3303 } 3303 }
3304 return 0; 3304 return 0;
3305} 3305}
3306 3306
3307 3307void PwMDoc::removeSyncInfo( QString syncProfile)
3308{
3309 qDebug("PwMDoc::not implemented: removeSyncInfo for profile %s ", syncProfile.latin1());
3310}
3308 3311
3309 3312
3310//this are the overwritten callbackmethods from the syncinterface 3313//this are the overwritten callbackmethods from the syncinterface
3311bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) 3314bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode)
3312{ 3315{
3313 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3316 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3314 3317
3315 //1) unlock local file first if necessary (ask for password) 3318 //1) unlock local file first if necessary (ask for password)
3316 if (this->isDeepLocked()) { 3319 if (this->isDeepLocked()) {
3317 PwMerror ret = this->deepLock(false); 3320 PwMerror ret = this->deepLock(false);
3318 if (ret != e_success) 3321 if (ret != e_success)
3319 return false; 3322 return false;
3320 } 3323 }
3321 3324
3322 //2) construct and open a new doc on the stack(automatic cleanup of remote file). 3325 //2) construct and open a new doc on the stack(automatic cleanup of remote file).
3323 PwMDoc syncTarget(this, "synctarget"); 3326 PwMDoc syncTarget(this, "synctarget");
3324 PwMDoc* pSyncTarget = &syncTarget; 3327 PwMDoc* pSyncTarget = &syncTarget;
3325 3328
3326 3329
3327 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); 3330 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/);
3328 3331
3329 if (err == e_alreadyOpen) { 3332 if (err == e_alreadyOpen) {
3330 PwMDocList::listItem li; 3333 PwMDocList::listItem li;
3331 if (getOpenDocList()->find(filename.latin1(), &li)) 3334 if (getOpenDocList()->find(filename.latin1(), &li))
3332 pSyncTarget = li.doc; 3335 pSyncTarget = li.doc;
3333 else { 3336 else {
3334 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3337 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3335 return false; 3338 return false;
3336 } 3339 }
3337 } 3340 }
3338 else if (err != e_success) { 3341 else if (err != e_success) {
3339 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3342 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3340 return false; 3343 return false;
3341 } 3344 }
3342 3345
3343 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); 3346 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode );
3344 3347
3345 3348
3346 //3) unlock remote file first if necessary (ask for password) 3349 //3) unlock remote file first if necessary (ask for password)
3347 if (pSyncTarget->isDeepLocked()) { 3350 if (pSyncTarget->isDeepLocked()) {
3348 PwMerror ret = pSyncTarget->deepLock(false); 3351 PwMerror ret = pSyncTarget->deepLock(false);
3349 if (ret != e_success) 3352 if (ret != e_success)
3350 return false; 3353 return false;
3351 } 3354 }
3352 3355
3353 3356
3354 err = syncronize(manager, this, pSyncTarget, mode ); 3357 err = syncronize(manager, this, pSyncTarget, mode );
3355 3358
3356 if (err == e_success) { 3359 if (err == e_success) {
3357 if ( manager->mWriteBackFile ){ 3360 if ( manager->mWriteBackFile ){
3358 qDebug("Saving remote PWManager file"); 3361 qDebug("Saving remote PWManager file");
3359 err = pSyncTarget->saveDoc(conf()->confGlobCompression()); 3362 err = pSyncTarget->saveDoc(conf()->confGlobCompression());
3360 if (err != e_success) { 3363 if (err != e_success) {
3361 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); 3364 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1());
3362 return false; 3365 return false;
3363 } 3366 }
3364 } 3367 }
3365 3368
3366 flagDirty(); 3369 flagDirty();
3367 return true; 3370 return true;
3368 } 3371 }
3369 else { 3372 else {
3370 return false; 3373 return false;
3371 } 3374 }
3372} 3375}
3373 3376
3374#endif 3377#endif
3375 3378
3376 3379
3377bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) 3380bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index)
3378{ 3381{
3379 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), 3382 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(),
3380 end = dti.syncDta.end(); 3383 end = dti.syncDta.end();
3381 3384
3382 while (i != end) { 3385 while (i != end) {
3383 if ((*i).syncName == syncname.latin1()) { 3386 if ((*i).syncName == syncname.latin1()) {
3384 if (index) { 3387 if (index) {
3385 *index = i - dti.syncDta.begin(); 3388 *index = i - dti.syncDta.begin();
3386 } 3389 }
3387 return true; 3390 return true;
3388 } 3391 }
3389 ++i; 3392 ++i;
3390 } 3393 }
3391 return false; 3394 return false;
3392}; 3395};
3393 3396
3394/** add new syncdataentry */ 3397/** add new syncdataentry */
3395PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) 3398PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty)
3396{ 3399{
3397 PWM_ASSERT(d); 3400 PWM_ASSERT(d);
3398 3401
3399 if (isDeepLocked()) { 3402 if (isDeepLocked()) {
3400 PwMerror ret; 3403 PwMerror ret;
3401 ret = deepLock(false); 3404 ret = deepLock(false);
3402 if (ret != e_success) 3405 if (ret != e_success)
3403 return e_lock; 3406 return e_lock;
3404 } 3407 }
3405 unsigned int index; 3408 unsigned int index;
3406 3409
3407 const QString tmp = d->syncName.c_str(); 3410 const QString tmp = d->syncName.c_str();
3408 bool exists = findSyncData(d->syncName.c_str(), &index); 3411 bool exists = findSyncData(d->syncName.c_str(), &index);
3409 3412
3410 if (exists == true) { 3413 if (exists == true) {
3411 // DOH! We found this entry. 3414 // DOH! We found this entry.
3412 return e_entryExists; 3415 return e_entryExists;
3413 } 3416 }
3414 3417
3415 dti.syncDta.push_back(*d); 3418 dti.syncDta.push_back(*d);
3416 3419
3417 if (!dontFlagDirty) 3420 if (!dontFlagDirty)
3418 flagDirty(); 3421 flagDirty();
3419 return e_success; 3422 return e_success;
3420} 3423}
3421 3424
3422 3425
3423 3426
3424/** delete syncdata entry */ 3427/** delete syncdata entry */
3425bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) 3428bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty)
3426{ 3429{
3427 if (isDeepLocked()) 3430 if (isDeepLocked())
3428 return false; 3431 return false;
3429 if (index > dti.syncDta.size() - 1) 3432 if (index > dti.syncDta.size() - 1)
3430 return false; 3433 return false;
3431 3434
3432 // delete entry 3435 // delete entry
3433 dti.syncDta.erase(dti.syncDta.begin() + index); 3436 dti.syncDta.erase(dti.syncDta.begin() + index);
3434 3437
3435 if (!dontFlagDirty) 3438 if (!dontFlagDirty)
3436 flagDirty(); 3439 flagDirty();
3437 return true; 3440 return true;
3438} 3441}
3439 3442
3440 3443
3441PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) 3444PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index)
3442{ 3445{
3443 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), 3446 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
3444 catend = dti.dta.end(); 3447 catend = dti.dta.end();
3445 3448
3446 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 3449 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
3447 3450
3448 while (catcounter != catend) { 3451 while (catcounter != catend) {
3449 entrBegin = catcounter->d.begin(); 3452 entrBegin = catcounter->d.begin();
3450 entrEnd = catcounter->d.end(); 3453 entrEnd = catcounter->d.end();
3451 entrI = entrBegin; 3454 entrI = entrBegin;
3452 while (entrI != entrEnd) { 3455 while (entrI != entrEnd) {
3453 if ((*entrI).meta.uniqueid == uid.latin1()) { 3456 if ((*entrI).meta.uniqueid == uid.latin1()) {
3454 if (category) 3457 if (category)
3455 *category = catcounter - dti.dta.begin(); 3458 *category = catcounter - dti.dta.begin();
3456 if (index) 3459 if (index)
3457 *index = entrI - entrBegin; 3460 *index = entrI - entrBegin;
3458 3461
3459 return &(*entrI); 3462 return &(*entrI);
3460 } 3463 }
3461 ++entrI; 3464 ++entrI;
3462 } 3465 }
3463 ++catcounter; 3466 ++catcounter;
3464 } 3467 }
3465 3468
3466 return 0; 3469 return 0;
3467} 3470}
3468 3471
3469QStringList PwMDoc::getIDEntryList() 3472QStringList PwMDoc::getIDEntryList()
3470{ 3473{
3471 QStringList results; 3474 QStringList results;
3472 3475
3473 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), 3476 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
3474 catend = dti.dta.end(); 3477 catend = dti.dta.end();
3475 3478
3476 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 3479 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
3477 3480
3478 while (catcounter != catend) { 3481 while (catcounter != catend) {
3479 entrBegin = catcounter->d.begin(); 3482 entrBegin = catcounter->d.begin();
3480 entrEnd = catcounter->d.end(); 3483 entrEnd = catcounter->d.end();
3481 entrI = entrBegin; 3484 entrI = entrBegin;
3482 while (entrI != entrEnd) { 3485 while (entrI != entrEnd) {
3483 results.append( (*entrI).meta.uniqueid.c_str() ); 3486 results.append( (*entrI).meta.uniqueid.c_str() );
3484 ++entrI; 3487 ++entrI;
3485 } 3488 }
3486 ++catcounter; 3489 ++catcounter;
3487 } 3490 }
3488 3491
3489 return results; 3492 return results;
3490} 3493}
3491 3494
3492 3495
3493 3496
3494 3497
3495 3498
3496#ifndef PWM_EMBEDDED 3499#ifndef PWM_EMBEDDED
3497#include "pwmdoc.moc" 3500#include "pwmdoc.moc"
3498#endif 3501#endif
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h
index 55e3231..e419c24 100644
--- a/pwmanager/pwmanager/pwmdoc.h
+++ b/pwmanager/pwmanager/pwmdoc.h
@@ -1,788 +1,789 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch * 3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.1 of pwmanager 14 * This file is originaly based on version 1.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#ifndef __PWMDOC_H 20#ifndef __PWMDOC_H
21#define __PWMDOC_H 21#define __PWMDOC_H
22#ifdef _WIN32_ 22#ifdef _WIN32_
23#define ssize_t unsigned int 23#define ssize_t unsigned int
24#endif 24#endif
25 #define PWM_FILE_VER (static_cast<char>(0x05)) 25 #define PWM_FILE_VER (static_cast<char>(0x05))
26 26
27 #define PWM_HASH_SHA1 (static_cast<char>(0x01)) 27 #define PWM_HASH_SHA1 (static_cast<char>(0x01))
28 #define PWM_HASH_SHA256 (static_cast<char>(0x02)) 28 #define PWM_HASH_SHA256 (static_cast<char>(0x02))
29 #define PWM_HASH_SHA384 (static_cast<char>(0x03)) 29 #define PWM_HASH_SHA384 (static_cast<char>(0x03))
30 #define PWM_HASH_SHA512 (static_cast<char>(0x04)) 30 #define PWM_HASH_SHA512 (static_cast<char>(0x04))
31 #define PWM_HASH_MD5 (static_cast<char>(0x05)) 31 #define PWM_HASH_MD5 (static_cast<char>(0x05))
32 #define PWM_HASH_RMD160 (static_cast<char>(0x06)) 32 #define PWM_HASH_RMD160 (static_cast<char>(0x06))
33 #define PWM_HASH_TIGER (static_cast<char>(0x07)) 33 #define PWM_HASH_TIGER (static_cast<char>(0x07))
34 34
35 #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) 35 #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01))
36 #define PWM_CRYPT_AES128(static_cast<char>(0x02)) 36 #define PWM_CRYPT_AES128(static_cast<char>(0x02))
37 #define PWM_CRYPT_AES192(static_cast<char>(0x03)) 37 #define PWM_CRYPT_AES192(static_cast<char>(0x03))
38 #define PWM_CRYPT_AES256(static_cast<char>(0x04)) 38 #define PWM_CRYPT_AES256(static_cast<char>(0x04))
39 #define PWM_CRYPT_3DES (static_cast<char>(0x05)) 39 #define PWM_CRYPT_3DES (static_cast<char>(0x05))
40 #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) 40 #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06))
41 #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) 41 #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07))
42 42
43 #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) 43 #define PWM_COMPRESS_NONE(static_cast<char>(0x00))
44 #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) 44 #define PWM_COMPRESS_GZIP(static_cast<char>(0x01))
45 #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) 45 #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02))
46 46
47 #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) 47 #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0)))
48 #define FILE_ID_HEADER "PWM_PASSWORD_FILE" 48 #define FILE_ID_HEADER "PWM_PASSWORD_FILE"
49 49
50 50
51#include "pwmexception.h" 51#include "pwmexception.h"
52#include "pwmdocui.h" 52#include "pwmdocui.h"
53 53
54#include <qobject.h> 54#include <qobject.h>
55#include <qtimer.h> 55#include <qtimer.h>
56#include <qdatetime.h> 56#include <qdatetime.h>
57 57
58#include <kprocess.h> 58#include <kprocess.h>
59 59
60#ifndef PWM_EMBEDDED 60#ifndef PWM_EMBEDDED
61#include "configuration.h" 61#include "configuration.h"
62#else 62#else
63#include <kapplication.h> 63#include <kapplication.h>
64#include <ksyncmanager.h> 64#include <ksyncmanager.h>
65#endif 65#endif
66 66
67#include <string> 67#include <string>
68#include <vector> 68#include <vector>
69#include <utility> 69#include <utility>
70 70
71using std::vector; 71using std::vector;
72using std::string; 72using std::string;
73using std::pair; 73using std::pair;
74 74
75/* used in findEntry() function */ 75/* used in findEntry() function */
76 #define SEARCH_IN_DESC (1) 76 #define SEARCH_IN_DESC (1)
77 #define SEARCH_IN_NAME (1 << 1) 77 #define SEARCH_IN_NAME (1 << 1)
78 #define SEARCH_IN_PW (1 << 2) 78 #define SEARCH_IN_PW (1 << 2)
79 #define SEARCH_IN_COMMENT(1 << 3) 79 #define SEARCH_IN_COMMENT(1 << 3)
80 #define SEARCH_IN_URL (1 << 4) 80 #define SEARCH_IN_URL (1 << 4)
81 #define SEARCH_IN_LAUNCHER(1 << 5) 81 #define SEARCH_IN_LAUNCHER(1 << 5)
82 #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ 82 #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \
83 SEARCH_IN_PW | SEARCH_IN_COMMENT| \ 83 SEARCH_IN_PW | SEARCH_IN_COMMENT| \
84 SEARCH_IN_URL| SEARCH_IN_LAUNCHER) 84 SEARCH_IN_URL| SEARCH_IN_LAUNCHER)
85 85
86/** document deeplocked. Data is out for lunch to disk */ 86/** document deeplocked. Data is out for lunch to disk */
87 #define DOC_STAT_DEEPLOCKED (1) 87 #define DOC_STAT_DEEPLOCKED (1)
88/** encrypted document on disk is dirty. data has to go to disk. */ 88/** encrypted document on disk is dirty. data has to go to disk. */
89 #define DOC_STAT_DISK_DIRTY (1 << 1) 89 #define DOC_STAT_DISK_DIRTY (1 << 1)
90/** we are using a chipcard to encrypt the data */ 90/** we are using a chipcard to encrypt the data */
91 #define DOC_STAT_USE_CHIPCARD (1 << 2) 91 #define DOC_STAT_USE_CHIPCARD (1 << 2)
92/** use "currentPw" to unlock. (This flag is set/unset by a timer) */ 92/** use "currentPw" to unlock. (This flag is set/unset by a timer) */
93 #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) 93 #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3)
94 94
95class PwMDoc; 95class PwMDoc;
96class PwMView; 96class PwMView;
97class QFile; 97class QFile;
98 98
99/* meta data for a PwMDataItem */ 99/* meta data for a PwMDataItem */
100struct PwMMetaData 100struct PwMMetaData
101{ 101{
102 PwMMetaData() 102 PwMMetaData()
103 : updateInt (0) 103 : updateInt (0)
104 { } 104 { }
105 /** creation date of the PwMDataItem to which 105 /** creation date of the PwMDataItem to which
106 * this meta data belongs. 106 * this meta data belongs.
107 */ 107 */
108 QDateTimecreate; 108 QDateTimecreate;
109 /** becomes valid on this date */ 109 /** becomes valid on this date */
110 QDateTimevalid; 110 QDateTimevalid;
111 /** expire date */ 111 /** expire date */
112 QDateTimeexpire; 112 QDateTimeexpire;
113 /** update date (last updated at this date) */ 113 /** update date (last updated at this date) */
114 QDateTimeupdate; 114 QDateTimeupdate;
115 /** update interval (in minutes). Time since the 115 /** update interval (in minutes). Time since the
116 * last update to remind the user to update the item. 116 * last update to remind the user to update the item.
117 * 0 disables. 117 * 0 disables.
118 */ 118 */
119 unsigned long updateInt; 119 unsigned long updateInt;
120 120
121 //US ENH: enhancements of the filestructure 121 //US ENH: enhancements of the filestructure
122 /* each entry gets a unique id assigned */ 122 /* each entry gets a unique id assigned */
123 string uniqueid; 123 string uniqueid;
124 124
125 125
126 void clear() 126 void clear()
127 { 127 {
128 create = QDateTime(); 128 create = QDateTime();
129 expire = QDateTime(); 129 expire = QDateTime();
130 update = QDateTime(); 130 update = QDateTime();
131 updateInt = 0; 131 updateInt = 0;
132 uniqueid = KApplication::randomString(8).latin1(); 132 uniqueid = KApplication::randomString(8).latin1();
133 } 133 }
134 134
135 inline bool isValid() const 135 inline bool isValid() const
136 { 136 {
137 if (valid.isNull()) 137 if (valid.isNull())
138 return true; 138 return true;
139 return (valid < QDateTime::currentDateTime()); 139 return (valid < QDateTime::currentDateTime());
140 } 140 }
141 inline bool isExpired() const 141 inline bool isExpired() const
142 { 142 {
143 if (expire.isNull()) 143 if (expire.isNull())
144 return false; 144 return false;
145 return (expire < QDateTime::currentDateTime()); 145 return (expire < QDateTime::currentDateTime());
146 } 146 }
147 inline bool isUpdateIntOver() const 147 inline bool isUpdateIntOver() const
148 { 148 {
149 if (updateInt == 0 || 149 if (updateInt == 0 ||
150 update.isNull()) 150 update.isNull())
151 return false; 151 return false;
152 QDateTime d(update); 152 QDateTime d(update);
153 return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); 153 return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime());
154 } 154 }
155}; 155};
156 156
157struct PwMDataItem 157struct PwMDataItem
158{ 158{
159 PwMDataItem() 159 PwMDataItem()
160 : lockStat (true) 160 : lockStat (true)
161 , listViewPos (-1) 161 , listViewPos (-1)
162 , binary (false) 162 , binary (false)
163 , rev (0) 163 , rev (0)
164 { } 164 { }
165 165
166 /** password description */ 166 /** password description */
167 stringdesc; 167 stringdesc;
168 /** user-name */ 168 /** user-name */
169 stringname; 169 stringname;
170 /** the password itself */ 170 /** the password itself */
171 stringpw; 171 stringpw;
172 /** some comment */ 172 /** some comment */
173 stringcomment; 173 stringcomment;
174 /** an URL string */ 174 /** an URL string */
175 stringurl; 175 stringurl;
176 /** launcher. Can be executed as a system() command */ 176 /** launcher. Can be executed as a system() command */
177 stringlauncher; 177 stringlauncher;
178 /** locking status. If locked (true), pw is not emitted through getEntry() */ 178 /** locking status. If locked (true), pw is not emitted through getEntry() */
179 boollockStat; 179 boollockStat;
180 /** position of this item in main "list-view" 180 /** position of this item in main "list-view"
181 * If -1, the position is not yet specified and should be appended to the list 181 * If -1, the position is not yet specified and should be appended to the list
182 */ 182 */
183 intlistViewPos; 183 intlistViewPos;
184 /** does this entry contain binary data? */ 184 /** does this entry contain binary data? */
185 bool binary; 185 bool binary;
186 /** meta data for this data item. */ 186 /** meta data for this data item. */
187 PwMMetaData meta; 187 PwMMetaData meta;
188 /** data revision counter. This counter can be used 188 /** data revision counter. This counter can be used
189 * to easily, efficiently determine if this data item 189 * to easily, efficiently determine if this data item
190 * has changed since some time. 190 * has changed since some time.
191 * This counter is incremented on every update. 191 * This counter is incremented on every update.
192 */ 192 */
193 unsigned int rev; 193 unsigned int rev;
194 194
195 void clear(bool clearMeta = true) 195 void clear(bool clearMeta = true)
196 { 196 {
197 /* NOTE: Don't use .clear() here to be 197 /* NOTE: Don't use .clear() here to be
198 * backward compatible with gcc-2 (Debian Woody) 198 * backward compatible with gcc-2 (Debian Woody)
199 */ 199 */
200 desc = ""; 200 desc = "";
201 name = ""; 201 name = "";
202 pw = ""; 202 pw = "";
203 comment = ""; 203 comment = "";
204 url = ""; 204 url = "";
205 launcher = ""; 205 launcher = "";
206 lockStat = true; 206 lockStat = true;
207 listViewPos = -1; 207 listViewPos = -1;
208 binary = false; 208 binary = false;
209 if (clearMeta) 209 if (clearMeta)
210 meta.clear(); 210 meta.clear();
211 } 211 }
212 //US ENH: we need this operator to compare two items if we have no unique ids 212 //US ENH: we need this operator to compare two items if we have no unique ids
213 //available. Generaly this happens before the first sync 213 //available. Generaly this happens before the first sync
214 214
215 bool PwMDataItem::operator==( const PwMDataItem &a ) const 215 bool PwMDataItem::operator==( const PwMDataItem &a ) const
216 { 216 {
217 //qDebug("oper==%s", a.desc.c_str()); 217 //qDebug("oper==%s", a.desc.c_str());
218 if ( desc != a.desc ) return false; 218 if ( desc != a.desc ) return false;
219 if ( name != a.name ) return false; 219 if ( name != a.name ) return false;
220 if ( pw != a.pw ) return false; 220 if ( pw != a.pw ) return false;
221 if ( comment != a.comment ) return false; 221 if ( comment != a.comment ) return false;
222 if ( url != a.url ) return false; 222 if ( url != a.url ) return false;
223 if ( launcher != a.launcher ) return false; 223 if ( launcher != a.launcher ) return false;
224 //all other field will not be checked. 224 //all other field will not be checked.
225 return true; 225 return true;
226 } 226 }
227}; 227};
228 228
229struct PwMCategoryItem 229struct PwMCategoryItem
230{ 230{
231 /** all PwMDataItems (all passwords) within this category */ 231 /** all PwMDataItems (all passwords) within this category */
232 vector<PwMDataItem>d; 232 vector<PwMDataItem>d;
233 /** category name/description */ 233 /** category name/description */
234 string name; 234 string name;
235 235
236 void clear() 236 void clear()
237 { 237 {
238 d.clear(); 238 d.clear();
239 name = ""; 239 name = "";
240 } 240 }
241}; 241};
242 242
243struct PwMSyncItem 243struct PwMSyncItem
244{ 244{
245 string syncName; 245 string syncName;
246 QDateTime lastSyncDate; 246 QDateTime lastSyncDate;
247 247
248 void clear() 248 void clear()
249 { 249 {
250 lastSyncDate = QDateTime(); 250 lastSyncDate = QDateTime();
251 syncName = ""; 251 syncName = "";
252 } 252 }
253}; 253};
254 254
255struct PwMItem 255struct PwMItem
256{ 256{
257 vector<PwMCategoryItem> dta; 257 vector<PwMCategoryItem> dta;
258 vector<PwMSyncItem> syncDta; 258 vector<PwMSyncItem> syncDta;
259 259
260 void clear() 260 void clear()
261 { 261 {
262 dta.clear(); 262 dta.clear();
263 syncDta.clear(); 263 syncDta.clear();
264 } 264 }
265}; 265};
266 266
267 267
268/** "Function Object" for sort()ing PwMDataItem::listViewPos */ 268/** "Function Object" for sort()ing PwMDataItem::listViewPos */
269class dta_lvp_greater 269class dta_lvp_greater
270{ 270{
271public: 271public:
272 bool operator() (const pair<unsigned int, unsigned int> &d1, 272 bool operator() (const pair<unsigned int, unsigned int> &d1,
273 const pair<unsigned int, unsigned int> &d2) 273 const pair<unsigned int, unsigned int> &d2)
274 { 274 {
275 return d1.second > d2.second; 275 return d1.second > d2.second;
276 } 276 }
277}; 277};
278 278
279/** list of PwMDoc documents and it's IDs */ 279/** list of PwMDoc documents and it's IDs */
280class PwMDocList 280class PwMDocList
281{ 281{
282public: 282public:
283 struct listItem 283 struct listItem
284 { 284 {
285 /** document filename (known as ID, here) */ 285 /** document filename (known as ID, here) */
286 string docId; 286 string docId;
287 /** pointer to the document class */ 287 /** pointer to the document class */
288 PwMDoc *doc; 288 PwMDoc *doc;
289 }; 289 };
290 290
291 PwMDocList() {} 291 PwMDocList() {}
292 292
293 /** add a new item to the list */ 293 /** add a new item to the list */
294 void add(PwMDoc *doc, const string &id); 294 void add(PwMDoc *doc, const string &id);
295 /** changes the contents of an existing item */ 295 /** changes the contents of an existing item */
296 void edit(PwMDoc *doc, const string &newId); 296 void edit(PwMDoc *doc, const string &newId);
297 /** remove the given item */ 297 /** remove the given item */
298 void del(PwMDoc *doc); 298 void del(PwMDoc *doc);
299 /** get the item at index */ 299 /** get the item at index */
300 listItem getAt(int index) 300 listItem getAt(int index)
301 { return docList[index]; } 301 { return docList[index]; }
302 /** find an entry with this id */ 302 /** find an entry with this id */
303 bool find(const string &id, listItem *ret = 0); 303 bool find(const string &id, listItem *ret = 0);
304 /** returns a copy of the list */ 304 /** returns a copy of the list */
305 const vector<listItem>* getList() const 305 const vector<listItem>* getList() const
306 { return &docList; } 306 { return &docList; }
307 307
308 308
309 /** returns a new unique number to extend the name of 309 /** returns a new unique number to extend the name of
310 * an unnamed document. 310 * an unnamed document.
311 */ 311 */
312 static unsigned int getNewUnnamedNumber() 312 static unsigned int getNewUnnamedNumber()
313 { return unnamedDocCnt++; } 313 { return unnamedDocCnt++; }
314 314
315protected: 315protected:
316 /* Hm, I think we shouldn't really use a "list" here, should we? 316 /* Hm, I think we shouldn't really use a "list" here, should we?
317 * So I decided to actually use a vector. 317 * So I decided to actually use a vector.
318 */ 318 */
319 vector<listItem> docList; 319 vector<listItem> docList;
320 /** This value is used to get a new number for yet unnamed 320 /** This value is used to get a new number for yet unnamed
321 * documents. It is incremented on every request. So it's 321 * documents. It is incremented on every request. So it's
322 * theoretically possible to overflow it, but... :) 322 * theoretically possible to overflow it, but... :)
323 */ 323 */
324 static unsigned int unnamedDocCnt; 324 static unsigned int unnamedDocCnt;
325}; 325};
326 326
327/** implements timers for the document */ 327/** implements timers for the document */
328class DocTimer : public QObject 328class DocTimer : public QObject
329{ 329{
330 Q_OBJECT 330 Q_OBJECT
331public: 331public:
332 enum TimerIDs 332 enum TimerIDs
333 { 333 {
334 id_mpwTimer, 334 id_mpwTimer,
335 id_autoLockTimer, 335 id_autoLockTimer,
336 id_metaCheckTimer 336 id_metaCheckTimer
337 }; 337 };
338 338
339public: 339public:
340 DocTimer(PwMDoc *_doc); 340 DocTimer(PwMDoc *_doc);
341 ~DocTimer(); 341 ~DocTimer();
342 342
343 /** start the timer */ 343 /** start the timer */
344 void start(TimerIDs timer); 344 void start(TimerIDs timer);
345 /** stop the timer */ 345 /** stop the timer */
346 void stop(TimerIDs timer); 346 void stop(TimerIDs timer);
347 /** get the lock for a timer. 347 /** get the lock for a timer.
348 * This lock is a recursive lock. When a lock is 348 * This lock is a recursive lock. When a lock is
349 * held, the timer will be stopped and timeout is 349 * held, the timer will be stopped and timeout is
350 * guaranteed to not happen 350 * guaranteed to not happen
351 */ 351 */
352 void getLock(TimerIDs timer); 352 void getLock(TimerIDs timer);
353 /** put a recursive timer lock */ 353 /** put a recursive timer lock */
354 void putLock(TimerIDs timer); 354 void putLock(TimerIDs timer);
355 355
356protected slots: 356protected slots:
357 /** timeout slot for the mpw timer */ 357 /** timeout slot for the mpw timer */
358 void mpwTimeout(); 358 void mpwTimeout();
359 /** timeout slot for the autoLock timer */ 359 /** timeout slot for the autoLock timer */
360 void autoLockTimeout(); 360 void autoLockTimeout();
361 /** timeout slot for the metaCheck timer */ 361 /** timeout slot for the metaCheck timer */
362 void metaCheckTimeout(); 362 void metaCheckTimeout();
363 363
364protected: 364protected:
365 /** pointer to the document associated with this timer. */ 365 /** pointer to the document associated with this timer. */
366 PwMDoc *doc; 366 PwMDoc *doc;
367 /** timer object for mpw timer */ 367 /** timer object for mpw timer */
368 QTimer *mpwTimer; 368 QTimer *mpwTimer;
369 /** timer object for the autoLock timer */ 369 /** timer object for the autoLock timer */
370 QTimer *autoLockTimer; 370 QTimer *autoLockTimer;
371 /** timer object for the metaCheck timer */ 371 /** timer object for the metaCheck timer */
372 QTimer *metaCheckTimer; 372 QTimer *metaCheckTimer;
373 /** lock counter for the mpw timer */ 373 /** lock counter for the mpw timer */
374 unsigned int mpwLock; 374 unsigned int mpwLock;
375 /** lock counter for the autoLock timer */ 375 /** lock counter for the autoLock timer */
376 unsigned int autoLockLock; 376 unsigned int autoLockLock;
377 /** lock counter for the metaCheck timer */ 377 /** lock counter for the metaCheck timer */
378 unsigned int metaCheckLock; 378 unsigned int metaCheckLock;
379}; 379};
380 380
381/** Document class for PwM */ 381/** Document class for PwM */
382//US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required. 382//US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required.
383// But PwMDoc is handling the sync by itself. 383// But PwMDoc is handling the sync by itself.
384class PwMDoc : public PwMDocUi, public KSyncInterface 384class PwMDoc : public PwMDocUi, public KSyncInterface
385 385
386{ 386{
387 Q_OBJECT 387 Q_OBJECT
388 friend class DocTimer; 388 friend class DocTimer;
389 389
390public: 390public:
391 /** construtor */ 391 /** construtor */
392 PwMDoc(QObject* parent = 0, const char *name = 0); 392 PwMDoc(QObject* parent = 0, const char *name = 0);
393 /** destructor */ 393 /** destructor */
394 ~PwMDoc(); 394 ~PwMDoc();
395 395
396 /** returns a pointer to a list of all open documents */ 396 /** returns a pointer to a list of all open documents */
397 static PwMDocList* getOpenDocList() 397 static PwMDocList* getOpenDocList()
398 { return &openDocList; } 398 { return &openDocList; }
399 399
400 /** flag document dirty. dta changed */ 400 /** flag document dirty. dta changed */
401 void flagDirty() 401 void flagDirty()
402 { 402 {
403 setDocStatFlag(DOC_STAT_DISK_DIRTY); 403 setDocStatFlag(DOC_STAT_DISK_DIRTY);
404 emitDataChanged(this); 404 emitDataChanged(this);
405 } 405 }
406 /** modified? */ 406 /** modified? */
407 bool isDirty() 407 bool isDirty()
408 { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } 408 { return getDocStatFlag(DOC_STAT_DISK_DIRTY); }
409 /** save document to disk */ 409 /** save document to disk */
410 PwMerror saveDoc(char compress, const QString *file = 0); 410 PwMerror saveDoc(char compress, const QString *file = 0);
411 /** read document from file. 411 /** read document from file.
412 * "openLocked is must be set to either of these values: 412 * "openLocked is must be set to either of these values:
413 * 0 == open with all entries unlocked 413 * 0 == open with all entries unlocked
414 * 1 == open with all entries locked 414 * 1 == open with all entries locked
415 * 2 == open deep-locked 415 * 2 == open deep-locked
416 */ 416 */
417 PwMerror openDoc(const QString *file, int openLocked); 417 PwMerror openDoc(const QString *file, int openLocked);
418 /** export document to ascii-textfile */ 418 /** export document to ascii-textfile */
419 PwMerror exportToText(const QString *file); 419 PwMerror exportToText(const QString *file);
420 /** export document to gpasman / kpasman file */ 420 /** export document to gpasman / kpasman file */
421 PwMerror exportToGpasman(const QString *file); 421 PwMerror exportToGpasman(const QString *file);
422 /** import document from ascii-textfile */ 422 /** import document from ascii-textfile */
423 PwMerror importFromText(const QString *file, int format = -1); 423 PwMerror importFromText(const QString *file, int format = -1);
424 /** import document from gpasman / kpasman file */ 424 /** import document from gpasman / kpasman file */
425 PwMerror importFromGpasman(const QString *file); 425 PwMerror importFromGpasman(const QString *file);
426 /** add new entry */ 426 /** add new entry */
427 PwMerror addEntry(const QString &category, PwMDataItem *d, 427 PwMerror addEntry(const QString &category, PwMDataItem *d,
428 bool dontFlagDirty = false, bool updateMeta = true); 428 bool dontFlagDirty = false, bool updateMeta = true);
429 /** add new category. This function doesn't flag the document dirty! */ 429 /** add new category. This function doesn't flag the document dirty! */
430 PwMerror addCategory(const QString &category, unsigned int *categoryIndex, 430 PwMerror addCategory(const QString &category, unsigned int *categoryIndex,
431 bool checkIfExist = true); 431 bool checkIfExist = true);
432 /** rename an existing category */ 432 /** rename an existing category */
433 bool renameCategory(const QString &category, const QString &newName); 433 bool renameCategory(const QString &category, const QString &newName);
434 /** rename an existing category */ 434 /** rename an existing category */
435 bool renameCategory(unsigned int category, const QString &newName, 435 bool renameCategory(unsigned int category, const QString &newName,
436 bool dontFlagDirty = false); 436 bool dontFlagDirty = false);
437 /** delete an existing category */ 437 /** delete an existing category */
438 bool delCategory(const QString &category); 438 bool delCategory(const QString &category);
439 /** delete an existing category */ 439 /** delete an existing category */
440 bool delCategory(unsigned int category, bool dontFlagDirty = false); 440 bool delCategory(unsigned int category, bool dontFlagDirty = false);
441 /** returns a list of all category-names */ 441 /** returns a list of all category-names */
442 void getCategoryList(vector<string> *list); 442 void getCategoryList(vector<string> *list);
443 /** returns a list of all category-names */ 443 /** returns a list of all category-names */
444 void getCategoryList(QStringList *list); 444 void getCategoryList(QStringList *list);
445 /** returns a list of all entry-descs in the given category */ 445 /** returns a list of all entry-descs in the given category */
446 void getEntryList(const QString &category, QStringList *list); 446 void getEntryList(const QString &category, QStringList *list);
447 /** returns a list of all entry-descs in the given category */ 447 /** returns a list of all entry-descs in the given category */
448 void getEntryList(const QString &category, vector<string> *list); 448 void getEntryList(const QString &category, vector<string> *list);
449 /** returns a list of all entry-descs in the given category */ 449 /** returns a list of all entry-descs in the given category */
450 void getEntryList(unsigned int category, vector<string> *list); 450 void getEntryList(unsigned int category, vector<string> *list);
451 /** returns a list of all entry-descs in the given category */ 451 /** returns a list of all entry-descs in the given category */
452 void getEntryList(unsigned int category, QStringList *list); 452 void getEntryList(unsigned int category, QStringList *list);
453 /** delete entry */ 453 /** delete entry */
454 bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); 454 bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false);
455 /** delete entry */ 455 /** delete entry */
456 bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); 456 bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false);
457 /** edit entry */ 457 /** edit entry */
458 bool editEntry(const QString &oldCategory, const QString &newCategory, 458 bool editEntry(const QString &oldCategory, const QString &newCategory,
459 unsigned int index, PwMDataItem *d, bool updateMeta = true); 459 unsigned int index, PwMDataItem *d, bool updateMeta = true);
460 /** edit entry */ 460 /** edit entry */
461 bool editEntry(unsigned int oldCategory, const QString &newCategory, 461 bool editEntry(unsigned int oldCategory, const QString &newCategory,
462 unsigned int index, PwMDataItem *d, bool updateMeta = true); 462 unsigned int index, PwMDataItem *d, bool updateMeta = true);
463 /** finds the category with the "name" and return it's index */ 463 /** finds the category with the "name" and return it's index */
464 bool findCategory(const QString &name, unsigned int *index); 464 bool findCategory(const QString &name, unsigned int *index);
465 /** search for an entry "find" and check while searching only for 465 /** search for an entry "find" and check while searching only for
466 * the data-fields specified by "searchIn". To set the "searchIn" 466 * the data-fields specified by "searchIn". To set the "searchIn"
467 * value, we may use one or more of the SEARCH_IN_* defines at 467 * value, we may use one or more of the SEARCH_IN_* defines at
468 * the top of this header-file. It returns the positions of all 468 * the top of this header-file. It returns the positions of all
469 * matched entries in "foundPositions". If "breakAfterFound" is true, 469 * matched entries in "foundPositions". If "breakAfterFound" is true,
470 * the function terminates after the first occurence of the entry 470 * the function terminates after the first occurence of the entry
471 * and doesn't go on searching. So foundPositions->size() is never 471 * and doesn't go on searching. So foundPositions->size() is never
472 * > 1 if breakAfterFound is true. 472 * > 1 if breakAfterFound is true.
473 */ 473 */
474 void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, 474 void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn,
475 vector<unsigned int> *foundPositions, bool breakAfterFound = false, 475 vector<unsigned int> *foundPositions, bool breakAfterFound = false,
476 bool caseSensitive = true, bool exactWordMatch = true, 476 bool caseSensitive = true, bool exactWordMatch = true,
477 bool sortByLvp = false); 477 bool sortByLvp = false);
478 /** see the above funtion. This function allows to set the category by name. */ 478 /** see the above funtion. This function allows to set the category by name. */
479 void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, 479 void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn,
480 vector<unsigned int> *foundPositions, bool breakAfterFound = false, 480 vector<unsigned int> *foundPositions, bool breakAfterFound = false,
481 bool caseSensitive = true, bool exactWordMatch = true, 481 bool caseSensitive = true, bool exactWordMatch = true,
482 bool sortByLvp = false); 482 bool sortByLvp = false);
483 /** returns number of entries */ 483 /** returns number of entries */
484 unsigned int numEntries(const QString &category); 484 unsigned int numEntries(const QString &category);
485 unsigned int numEntries(unsigned int category) 485 unsigned int numEntries(unsigned int category)
486 { return dti.dta[category].d.size(); } 486 { return dti.dta[category].d.size(); }
487 /** returns number of categories */ 487 /** returns number of categories */
488 unsigned int numCategories() 488 unsigned int numCategories()
489 { return dti.dta.size(); } 489 { return dti.dta.size(); }
490 /** returns the name of the category at "index" */ 490 /** returns the name of the category at "index" */
491 const string* getCategory(unsigned int index) 491 const string* getCategory(unsigned int index)
492 { return (&(dti.dta[index].name)); } 492 { return (&(dti.dta[index].name)); }
493 493
494 /** returns the data of item at "index". 494 /** returns the data of item at "index".
495 * It unlocks the entry if it's locked and unlockIfLocked is true. 495 * It unlocks the entry if it's locked and unlockIfLocked is true.
496 * If the entry is locked, but unlockIfLocked is false, it'll not return 496 * If the entry is locked, but unlockIfLocked is false, it'll not return
497 * the pw. 497 * the pw.
498 */ 498 */
499 bool getEntry(const QString &category, unsigned int index, 499 bool getEntry(const QString &category, unsigned int index,
500 PwMDataItem *d, bool unlockIfLocked = false); 500 PwMDataItem *d, bool unlockIfLocked = false);
501 bool getEntry(unsigned int category, unsigned int index, 501 bool getEntry(unsigned int category, unsigned int index,
502 PwMDataItem *d, bool unlockIfLocked = false); 502 PwMDataItem *d, bool unlockIfLocked = false);
503 /** returns the comment-string by looking at the category 503 /** returns the comment-string by looking at the category
504 * and the listViewPos 504 * and the listViewPos
505 */ 505 */
506 PwMerror getCommentByLvp(const QString &category, int listViewPos, 506 PwMerror getCommentByLvp(const QString &category, int listViewPos,
507 string *foundComment); 507 string *foundComment);
508 /** checks if a password is already available. (currentPw) */ 508 /** checks if a password is already available. (currentPw) */
509 bool isPwAvailable() 509 bool isPwAvailable()
510 { return (currentPw != ""); } 510 { return (currentPw != ""); }
511 /** un/lock entry at "index". If needed, ask for password. */ 511 /** un/lock entry at "index". If needed, ask for password. */
512 bool lockAt(const QString &category, unsigned int index, 512 bool lockAt(const QString &category, unsigned int index,
513 bool lock = true); 513 bool lock = true);
514 bool lockAt(unsigned int category, unsigned int index, 514 bool lockAt(unsigned int category, unsigned int index,
515 bool lock = true); 515 bool lock = true);
516 /** returns the lock-status at "index" */ 516 /** returns the lock-status at "index" */
517 bool isLocked(const QString &category, unsigned int index); 517 bool isLocked(const QString &category, unsigned int index);
518 bool isLocked(unsigned int category, unsigned int index) 518 bool isLocked(unsigned int category, unsigned int index)
519 { return dti.dta[category].d[index].lockStat; } 519 { return dti.dta[category].d[index].lockStat; }
520 /** returns the deeplock status */ 520 /** returns the deeplock status */
521 bool isDeepLocked() 521 bool isDeepLocked()
522 { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } 522 { return getDocStatFlag(DOC_STAT_DEEPLOCKED); }
523 /** (un)lock all entries */ 523 /** (un)lock all entries */
524 bool lockAll(bool lock); 524 bool lockAll(bool lock);
525 /** unlocks all entries tempoarly. 525 /** unlocks all entries tempoarly.
526 * 1st NOTE: Be very careful with this function! :) 526 * 1st NOTE: Be very careful with this function! :)
527 * 2nd NOTE: After you have called unlockAll_Tempoary(); , 527 * 2nd NOTE: After you have called unlockAll_Tempoary(); ,
528 * please DON'T forget to call unlockAll_Tempoary(true); 528 * please DON'T forget to call unlockAll_Tempoary(true);
529 * _before_ the user (or someone else) is able to change 529 * _before_ the user (or someone else) is able to change
530 * the document! 530 * the document!
531 * 3rd NOTE: Please DON'T change "dta" while the data is tempoary 531 * 3rd NOTE: Please DON'T change "dta" while the data is tempoary
532 * unlocked! This will cause corruption. 532 * unlocked! This will cause corruption.
533 */ 533 */
534 bool unlockAll_tempoary(bool revert = false); 534 bool unlockAll_tempoary(bool revert = false);
535 /** deep-(un)locks the document. 535 /** deep-(un)locks the document.
536 * deep-locking writes all data to the file, deletes all data 536 * deep-locking writes all data to the file, deletes all data
537 * in memory, but doesn't close the document. 537 * in memory, but doesn't close the document.
538 * deep-locking is only available, if the user previously saved 538 * deep-locking is only available, if the user previously saved
539 * the doc to a file (with a password). 539 * the doc to a file (with a password).
540 * If "saveToFile" is false, it does NOT write the data to the file! 540 * If "saveToFile" is false, it does NOT write the data to the file!
541 */ 541 */
542 PwMerror deepLock(bool lock = true, bool saveToFile = true); 542 PwMerror deepLock(bool lock = true, bool saveToFile = true);
543 /** is unlockable without pw? */ 543 /** is unlockable without pw? */
544 bool unlockWoPw() 544 bool unlockWoPw()
545 { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } 545 { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); }
546 /** get the "currentPassword" */ 546 /** get the "currentPassword" */
547 const QString& getCurrentPw() 547 const QString& getCurrentPw()
548 { return currentPw; } 548 { return currentPw; }
549 /** open a window and request the user to change the mpw */ 549 /** open a window and request the user to change the mpw */
550 void changeCurrentPw(); 550 void changeCurrentPw();
551 /** set the "listViewPos" variable of "dta" */ 551 /** set the "listViewPos" variable of "dta" */
552 void setListViewPos(const QString &category, unsigned int index, 552 void setListViewPos(const QString &category, unsigned int index,
553 int pos); 553 int pos);
554 /** set the "listViewPos" variable of "dta" */ 554 /** set the "listViewPos" variable of "dta" */
555 void setListViewPos(unsigned int category, unsigned int index, 555 void setListViewPos(unsigned int category, unsigned int index,
556 int pos); 556 int pos);
557 /** get the "listViewPos" variable of "dta" */ 557 /** get the "listViewPos" variable of "dta" */
558 int getListViewPos(const QString &category, unsigned int index); 558 int getListViewPos(const QString &category, unsigned int index);
559 /** set the maximum number of entries allowed */ 559 /** set the maximum number of entries allowed */
560 void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) 560 void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES)
561 { maxEntries = num; } 561 { maxEntries = num; }
562 /** get the maximum number of entries allowed */ 562 /** get the maximum number of entries allowed */
563 unsigned int getMaxNumEntries() 563 unsigned int getMaxNumEntries()
564 { return maxEntries; } 564 { return maxEntries; }
565 /** ensure all listViewPos of all dta items are set. (are ! -1). 565 /** ensure all listViewPos of all dta items are set. (are ! -1).
566 * If there are some undefined entries, add them to the end of 566 * If there are some undefined entries, add them to the end of
567 * the listViewPos(itions). */ 567 * the listViewPos(itions). */
568 void ensureLvp(); 568 void ensureLvp();
569 /** execute the "launcher" of this entry */ 569 /** execute the "launcher" of this entry */
570 bool execLauncher(const QString &category, unsigned int entryIndex); 570 bool execLauncher(const QString &category, unsigned int entryIndex);
571 /** see above */ 571 /** see above */
572 bool execLauncher(unsigned int category, unsigned int entryIndex); 572 bool execLauncher(unsigned int category, unsigned int entryIndex);
573 /** open a browser with the URL-section of the given entry */ 573 /** open a browser with the URL-section of the given entry */
574 bool goToURL(const QString &category, unsigned int entryIndex); 574 bool goToURL(const QString &category, unsigned int entryIndex);
575 /** see above */ 575 /** see above */
576 bool goToURL(unsigned int category, unsigned int entryIndex); 576 bool goToURL(unsigned int category, unsigned int entryIndex);
577 /** returns true if there is no entry present in the document. 577 /** returns true if there is no entry present in the document.
578 * Note: The "default" Category is present everytime, so 578 * Note: The "default" Category is present everytime, so
579 * it's checked for it's entries. 579 * it's checked for it's entries.
580 */ 580 */
581 bool isDocEmpty() 581 bool isDocEmpty()
582 { 582 {
583 if (numCategories() > 1) 583 if (numCategories() > 1)
584 return false; 584 return false;
585 if (numEntries(0)) 585 if (numEntries(0))
586 return false; 586 return false;
587 return true; 587 return true;
588 } 588 }
589 /** returns the filename of this doc */ 589 /** returns the filename of this doc */
590 const QString& getFilename() 590 const QString& getFilename()
591 { return filename; } 591 { return filename; }
592 /** returns the title of the doc */ 592 /** returns the title of the doc */
593 QString getTitle(); 593 QString getTitle();
594 /** sets the list-view-pointer hold in the doc */ 594 /** sets the list-view-pointer hold in the doc */
595 void setListViewPointer(PwMView *_listView) 595 void setListViewPointer(PwMView *_listView)
596 { listView = _listView; } 596 { listView = _listView; }
597 /** returns the list-view-pointer */ 597 /** returns the list-view-pointer */
598 PwMView * getListViewPointer() 598 PwMView * getListViewPointer()
599 { return listView; } 599 { return listView; }
600 /** try to delete the doc. The user may be asked to save 600 /** try to delete the doc. The user may be asked to save
601 * the data. The user may cancel the whole operation. 601 * the data. The user may cancel the whole operation.
602 * false is returned, then. 602 * false is returned, then.
603 */ 603 */
604 bool tryDelete(); 604 bool tryDelete();
605 /** is the doc deleted? (with tryDelete() ) */ 605 /** is the doc deleted? (with tryDelete() ) */
606 bool isDeleted() 606 bool isDeleted()
607 { return deleted; } 607 { return deleted; }
608 /** returns the document timer object */ 608 /** returns the document timer object */
609 DocTimer * timer() 609 DocTimer * timer()
610 { return _timer; } 610 { return _timer; }
611 /** get a lock on the dataChanged signal. 611 /** get a lock on the dataChanged signal.
612 * If someone is holding a lock, the signal is not emitted. 612 * If someone is holding a lock, the signal is not emitted.
613 */ 613 */
614 void getDataChangedLock() 614 void getDataChangedLock()
615 { ++dataChangedLock; } 615 { ++dataChangedLock; }
616 /** put the dataChanged lock */ 616 /** put the dataChanged lock */
617 void putDataChangedLock() 617 void putDataChangedLock()
618 { --dataChangedLock; } 618 { --dataChangedLock; }
619 /** returns the revision count of the item at cat/index */ 619 /** returns the revision count of the item at cat/index */
620 unsigned int getEntryRevCnt(unsigned int category, unsigned int index) 620 unsigned int getEntryRevCnt(unsigned int category, unsigned int index)
621 { return dti.dta[category].d[index].rev; } 621 { return dti.dta[category].d[index].rev; }
622 /** returns a const pointer to the entries meta */ 622 /** returns a const pointer to the entries meta */
623 const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) 623 const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index)
624 { return &(dti.dta[category].d[index].meta); } 624 { return &(dti.dta[category].d[index].meta); }
625 /** is the entry at "category" "index" a binary entry? */ 625 /** is the entry at "category" "index" a binary entry? */
626 bool isBinEntry(unsigned int category, unsigned int index) 626 bool isBinEntry(unsigned int category, unsigned int index)
627 { return dti.dta[category].d[index].binary; } 627 { return dti.dta[category].d[index].binary; }
628 628
629public slots: 629public slots:
630 /** wrapper for PwMTray */ 630 /** wrapper for PwMTray */
631 void _deepUnlock(); 631 void _deepUnlock();
632 632
633signals: 633signals:
634 /** the data of the document has changed and must be updated 634 /** the data of the document has changed and must be updated
635 * in all views. 635 * in all views.
636 * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! 636 * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal!
637 */ 637 */
638 void dataChanged(PwMDoc *document); 638 void dataChanged(PwMDoc *document);
639 /** the document class is going to close. This signal may be 639 /** the document class is going to close. This signal may be
640 * used to nofify all views, that the user closed the document, 640 * used to nofify all views, that the user closed the document,
641 * so the views can go down, too. 641 * so the views can go down, too.
642 */ 642 */
643 void docClosed(PwMDoc *document); 643 void docClosed(PwMDoc *document);
644 /** somebody just opened the document */ 644 /** somebody just opened the document */
645 void docOpened(PwMDoc *document); 645 void docOpened(PwMDoc *document);
646 /** this document object just got created */ 646 /** this document object just got created */
647 void docCreated(PwMDoc *document); 647 void docCreated(PwMDoc *document);
648 648
649public: 649public:
650 /** emit the dataChanged signal after checking for a lock */ 650 /** emit the dataChanged signal after checking for a lock */
651 void emitDataChanged(PwMDoc *document) 651 void emitDataChanged(PwMDoc *document)
652 { 652 {
653 if (!dataChangedLock) 653 if (!dataChangedLock)
654 emit dataChanged(document); 654 emit dataChanged(document);
655 } 655 }
656 656
657protected: 657protected:
658 /** current file for this doc */ 658 /** current file for this doc */
659 QString filename; 659 QString filename;
660//US ENH: we need a place where we keep the syncentries. So I invented 660//US ENH: we need a place where we keep the syncentries. So I invented
661// struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem 661// struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem
662 /** holds all data */ 662 /** holds all data */
663 PwMItem dti; 663 PwMItem dti;
664 /** maximum number of entries */ 664 /** maximum number of entries */
665 unsigned int maxEntries; 665 unsigned int maxEntries;
666 /** currently used password to encrypt data */ 666 /** currently used password to encrypt data */
667 QString currentPw; 667 QString currentPw;
668 /** current global document status flags */ 668 /** current global document status flags */
669 unsigned int curDocStat; 669 unsigned int curDocStat;
670 /** browser process for goToURL() */ 670 /** browser process for goToURL() */
671 KProcess browserProc; 671 KProcess browserProc;
672 /** pointer to the list-view, using this document. 672 /** pointer to the list-view, using this document.
673 * As there can only be one list-view per doc, we 673 * As there can only be one list-view per doc, we
674 * don't need a list here. 674 * don't need a list here.
675 */ 675 */
676 PwMView *listView; 676 PwMView *listView;
677 /** unnamedNum is used to store the "unnamed counter" 677 /** unnamedNum is used to store the "unnamed counter"
678 * for this document, while it's unnamed. If it's 0, 678 * for this document, while it's unnamed. If it's 0,
679 * we have to get a new unique one. 679 * we have to get a new unique one.
680 */ 680 */
681 unsigned int unnamedNum; 681 unsigned int unnamedNum;
682 /** is this doc going to be deleted (executing in destructor context) */ 682 /** is this doc going to be deleted (executing in destructor context) */
683 bool deleted; 683 bool deleted;
684 /** document timer */ 684 /** document timer */
685 DocTimer *_timer; 685 DocTimer *_timer;
686 /** lock counter for the "dataChanged" signal */ 686 /** lock counter for the "dataChanged" signal */
687 unsigned int dataChangedLock; 687 unsigned int dataChangedLock;
688 688
689 /** list of all open documents */ 689 /** list of all open documents */
690 static PwMDocList openDocList; 690 static PwMDocList openDocList;
691 691
692protected: 692protected:
693 /** serialize "dta" and return it in "d". */ 693 /** serialize "dta" and return it in "d". */
694 bool serializeDta(string *d); 694 bool serializeDta(string *d);
695 /** de-serialize "d" and overwrite "dta" */ 695 /** de-serialize "d" and overwrite "dta" */
696 bool deSerializeDta(const string *d, bool entriesLocked); 696 bool deSerializeDta(const string *d, bool entriesLocked);
697 /** write header to file */ 697 /** write header to file */
698 PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, 698 PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress,
699 QString *pw, QFile *f); 699 QString *pw, QFile *f);
700 /** write data-hash to file */ 700 /** write data-hash to file */
701 PwMerror writeDataHash(char dataHash, string *d, QFile *f); 701 PwMerror writeDataHash(char dataHash, string *d, QFile *f);
702 /** check header. Read header info and verify key-hash and filever. 702 /** check header. Read header info and verify key-hash and filever.
703 * returns length of header in "headerLength" */ 703 * returns length of header in "headerLength" */
704 PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, 704 PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress,
705 unsigned int *headerLength, char *dataHashType, 705 unsigned int *headerLength, char *dataHashType,
706 string *dataHash, QFile *f); 706 string *dataHash, QFile *f);
707 /** check the data-hash */ 707 /** check the data-hash */
708 PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); 708 PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream);
709 /** encrypt data "d" and write to "filename" */ 709 /** encrypt data "d" and write to "filename" */
710 PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); 710 PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo);
711 /** read data from file beginning at "pos", decrypt and return it */ 711 /** read data from file beginning at "pos", decrypt and return it */
712 PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f); 712 PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f);
713 /** compress the data */ 713 /** compress the data */
714 bool compressDta(string *d, char algo); 714 bool compressDta(string *d, char algo);
715 /** uncompress the data */ 715 /** uncompress the data */
716 bool decompressDta(string *d, char algo); 716 bool decompressDta(string *d, char algo);
717 /** internal import function for a text-file generated by PwM. 717 /** internal import function for a text-file generated by PwM.
718 * If this is not a valid PwM-exported file, it returns e_fileFormat */ 718 * If this is not a valid PwM-exported file, it returns e_fileFormat */
719 PwMerror importText_PwM(const QString *file); 719 PwMerror importText_PwM(const QString *file);
720 /** PwM-text-import helper function to extract the name/pw/comment out 720 /** PwM-text-import helper function to extract the name/pw/comment out
721 * of one entry-line */ 721 * of one entry-line */
722 bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); 722 bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out);
723 /** compare two strings */ 723 /** compare two strings */
724 bool compareString(const string &s1, const string &s2, bool caseSensitive, 724 bool compareString(const string &s1, const string &s2, bool caseSensitive,
725 bool exactWordMatch); 725 bool exactWordMatch);
726 /** clears all document-data */ 726 /** clears all document-data */
727 void clearDoc(); 727 void clearDoc();
728 /** delete all empty categories */ 728 /** delete all empty categories */
729 void delAllEmptyCat(bool dontFlagDirty); 729 void delAllEmptyCat(bool dontFlagDirty);
730 /** set a document status flag */ 730 /** set a document status flag */
731 void setDocStatFlag(unsigned int statFlag) 731 void setDocStatFlag(unsigned int statFlag)
732 { curDocStat |= statFlag; } 732 { curDocStat |= statFlag; }
733 /** unset a document status flag */ 733 /** unset a document status flag */
734 void unsetDocStatFlag(unsigned int statFlag) 734 void unsetDocStatFlag(unsigned int statFlag)
735 { curDocStat &= ~statFlag; } 735 { curDocStat &= ~statFlag; }
736 /** get a document status flag */ 736 /** get a document status flag */
737 bool getDocStatFlag(unsigned int statFlag) const 737 bool getDocStatFlag(unsigned int statFlag) const
738 { return (curDocStat & statFlag); } 738 { return (curDocStat & statFlag); }
739 /** set the "currentPassword" */ 739 /** set the "currentPassword" */
740 void setCurrentPw(const QString &pw) 740 void setCurrentPw(const QString &pw)
741 { 741 {
742 currentPw = pw; 742 currentPw = pw;
743 setDocStatFlag(DOC_STAT_DISK_DIRTY); 743 setDocStatFlag(DOC_STAT_DISK_DIRTY);
744 } 744 }
745 /** make a backup-copy of the given file */ 745 /** make a backup-copy of the given file */
746 bool backupFile(const QString &filePath); 746 bool backupFile(const QString &filePath);
747 /** copy a file from src to dst */ 747 /** copy a file from src to dst */
748 bool copyFile(const QString &src, const QString &dst); 748 bool copyFile(const QString &src, const QString &dst);
749 749
750 750
751 public: 751 public:
752#ifdef PWM_EMBEDDED 752#ifdef PWM_EMBEDDED
753 //US ENH: this is the magic function that syncronizes the local doc with the remote doc. 753 //US ENH: this is the magic function that syncronizes the local doc with the remote doc.
754 PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); 754 PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode );
755 755
756 //takePwMDataItem returns the following values 756 //takePwMDataItem returns the following values
757 // 0 equal 757 // 0 equal
758 // 1 take local 758 // 1 take local
759 // 2 take remote 759 // 2 take remote
760 // 3 cancel 760 // 3 cancel
761 int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); 761 int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full );
762 762
763 //the following methods are the overwritten callbackmethods from the syncinterface 763 //the following methods are the overwritten callbackmethods from the syncinterface
764 virtual bool sync(KSyncManager* manager, QString filename, int mode); 764 virtual bool sync(KSyncManager* manager, QString filename, int mode);
765 virtual void removeSyncInfo( QString syncProfile);
765 766
766#endif 767#endif
767 private: 768 private:
768 //US ENH: helpermethods to access the sync data for a certain syncname. 769 //US ENH: helpermethods to access the sync data for a certain syncname.
769 // It returns the syncdatas index 770 // It returns the syncdatas index
770 bool findSyncData(const QString &syncname, unsigned int *index); 771 bool findSyncData(const QString &syncname, unsigned int *index);
771 772
772 /** add new syncdataentry */ 773 /** add new syncdataentry */
773 PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); 774 PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false);
774 775
775 /** returns a pointer to the syncdata */ 776 /** returns a pointer to the syncdata */
776 PwMSyncItem* getSyncDataEntry(unsigned int index) 777 PwMSyncItem* getSyncDataEntry(unsigned int index)
777 { return &(dti.syncDta[index]); } 778 { return &(dti.syncDta[index]); }
778 779
779 /** delete entry */ 780 /** delete entry */
780 bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); 781 bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false);
781 782
782 PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); 783 PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index);
783 784
784 QStringList getIDEntryList(); 785 QStringList getIDEntryList();
785 786
786}; 787};
787 788
788#endif 789#endif