-rw-r--r-- | core/pim/addressbook/addressbook.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp index 4fa9253..b4734a4 100644 --- a/core/pim/addressbook/addressbook.cpp +++ b/core/pim/addressbook/addressbook.cpp | |||
@@ -1,893 +1,893 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** Copyright (C) 2003 Stefan Eilers (eilers.stefan@epost.de) | 3 | ** Copyright (C) 2003 Stefan Eilers (eilers.stefan@epost.de) |
4 | ** | 4 | ** |
5 | ** This file is part of the Open Palmtop Environment (see www.opie.info). | 5 | ** This file is part of the Open Palmtop Environment (see www.opie.info). |
6 | ** | 6 | ** |
7 | ** This file may be distributed and/or modified under the terms of the | 7 | ** This file may be distributed and/or modified under the terms of the |
8 | ** GNU General Public License version 2 as published by the Free Software | 8 | ** GNU General Public License version 2 as published by the Free Software |
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | 9 | ** Foundation and appearing in the file LICENSE.GPL included in the |
10 | ** packaging of this file. | 10 | ** packaging of this file. |
11 | ** | 11 | ** |
12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
14 | ** | 14 | ** |
15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
16 | ** | 16 | ** |
17 | ** | 17 | ** |
18 | **********************************************************************/ | 18 | **********************************************************************/ |
19 | 19 | ||
20 | #define QTOPIA_INTERNAL_FD | 20 | #define QTOPIA_INTERNAL_FD |
21 | 21 | ||
22 | // #include "addresssettings.h" | 22 | // #include "addresssettings.h" |
23 | #include "addressbook.h" | 23 | #include "addressbook.h" |
24 | 24 | ||
25 | #include <opie2/odebug.h> | 25 | #include <opie2/odebug.h> |
26 | #include <opie2/ofileselector.h> | 26 | #include <opie2/ofileselector.h> |
27 | #include <opie2/ofiledialog.h> | 27 | #include <opie2/ofiledialog.h> |
28 | #include <opie2/opimcontact.h> | 28 | #include <opie2/opimcontact.h> |
29 | #include <opie2/ocontactaccessbackend_vcard.h> | 29 | #include <opie2/ocontactaccessbackend_vcard.h> |
30 | #include <opie2/oresource.h> | 30 | #include <opie2/oresource.h> |
31 | 31 | ||
32 | #include <qpe/ir.h> | 32 | #include <qpe/ir.h> |
33 | #include <qpe/qpemessagebox.h> | 33 | #include <qpe/qpemessagebox.h> |
34 | #include <qmenubar.h> | 34 | #include <qmenubar.h> |
35 | #include <qpe/qpeapplication.h> | 35 | #include <qpe/qpeapplication.h> |
36 | 36 | ||
37 | #include <qaction.h> | 37 | #include <qaction.h> |
38 | #include <qlayout.h> | 38 | #include <qlayout.h> |
39 | #include <qmessagebox.h> | 39 | #include <qmessagebox.h> |
40 | #include <qtoolbutton.h> | 40 | #include <qtoolbutton.h> |
41 | 41 | ||
42 | #include <stdlib.h> | 42 | #include <stdlib.h> |
43 | #include <sys/stat.h> | 43 | #include <sys/stat.h> |
44 | #include <sys/types.h> | 44 | #include <sys/types.h> |
45 | #include <fcntl.h> | 45 | #include <fcntl.h> |
46 | #include <unistd.h> | 46 | #include <unistd.h> |
47 | 47 | ||
48 | 48 | ||
49 | #include "picker.h" | 49 | #include "picker.h" |
50 | #include "configdlg.h" | 50 | #include "configdlg.h" |
51 | 51 | ||
52 | extern QString addressbookPersonalVCardName(); | 52 | extern QString addressbookPersonalVCardName(); |
53 | 53 | ||
54 | AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, | 54 | AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, |
55 | WFlags /*f*/ ) | 55 | WFlags /*f*/ ) |
56 | : Opie::OPimMainWindow( "Addressbook", "Contacts", tr( "Contact" ), "AddressBook", | 56 | : Opie::OPimMainWindow( "Addressbook", "Contacts", tr( "Contact" ), "AddressBook", |
57 | parent, name, WType_TopLevel | WStyle_ContextHelp ), | 57 | parent, name, WType_TopLevel | WStyle_ContextHelp ), |
58 | abEditor(0l), | 58 | abEditor(0l), |
59 | syncing(false) | 59 | syncing(false) |
60 | { | 60 | { |
61 | setCaption( tr( "Contacts" ) ); | 61 | setCaption( tr( "Contacts" ) ); |
62 | 62 | ||
63 | isLoading = true; | 63 | isLoading = true; |
64 | 64 | ||
65 | m_config.load(); | 65 | m_config.load(); |
66 | 66 | ||
67 | // Create Views | 67 | // Create Views |
68 | m_listContainer = new QWidget( this ); | 68 | m_listContainer = new QWidget( this ); |
69 | QVBoxLayout *vb = new QVBoxLayout( m_listContainer ); | 69 | QVBoxLayout *vb = new QVBoxLayout( m_listContainer ); |
70 | 70 | ||
71 | m_abView = new AbView( m_listContainer, m_config.orderList() ); | 71 | m_abView = new AbView( m_listContainer, m_config.orderList() ); |
72 | vb->addWidget( m_abView ); | 72 | vb->addWidget( m_abView ); |
73 | connect( m_abView, SIGNAL(signalViewSwitched(int)), | 73 | connect( m_abView, SIGNAL(signalViewSwitched(int)), |
74 | this, SLOT(slotViewSwitched(int)) ); | 74 | this, SLOT(slotViewSwitched(int)) ); |
75 | 75 | ||
76 | QObject::connect( m_abView, SIGNAL(signalNotFound()), this, SLOT(slotNotFound()) ); | 76 | QObject::connect( m_abView, SIGNAL(signalNotFound()), this, SLOT(slotNotFound()) ); |
77 | 77 | ||
78 | // Letter Picker | 78 | // Letter Picker |
79 | pLabel = new LetterPicker( m_listContainer ); | 79 | pLabel = new LetterPicker( m_listContainer ); |
80 | connect(pLabel, SIGNAL(letterClicked(char)), this, SLOT(slotSetLetter(char))); | 80 | connect(pLabel, SIGNAL(letterClicked(char)), this, SLOT(slotSetLetter(char))); |
81 | connect(m_abView, SIGNAL(signalClearLetterPicker()), pLabel, SLOT(clear()) ); | 81 | connect(m_abView, SIGNAL(signalClearLetterPicker()), pLabel, SLOT(clear()) ); |
82 | 82 | ||
83 | vb->addWidget( pLabel ); | 83 | vb->addWidget( pLabel ); |
84 | 84 | ||
85 | // Quick search bar | 85 | // Quick search bar |
86 | m_searchBar = new OFloatBar( "Search", this, QMainWindow::Top, true ); | 86 | m_searchBar = new OFloatBar( "Search", this, QMainWindow::Top, true ); |
87 | m_searchBar->setHorizontalStretchable( true ); | 87 | m_searchBar->setHorizontalStretchable( true ); |
88 | m_searchBar->hide(); | 88 | m_searchBar->hide(); |
89 | m_searchEdit = new QLineEdit( m_searchBar, "m_searchEdit" ); | 89 | m_searchEdit = new QLineEdit( m_searchBar, "m_searchEdit" ); |
90 | 90 | ||
91 | m_searchBar->setStretchableWidget( m_searchEdit ); | 91 | m_searchBar->setStretchableWidget( m_searchEdit ); |
92 | connect( m_searchEdit, SIGNAL(returnPressed()), this, SLOT(slotFind()) ); | 92 | connect( m_searchEdit, SIGNAL(returnPressed()), this, SLOT(slotFind()) ); |
93 | 93 | ||
94 | QAction *a = new QAction( tr( "Start Search" ), | 94 | QAction *a = new QAction( tr( "Start Search" ), |
95 | Opie::Core::OResource::loadPixmap( "find", Opie::Core::OResource::SmallIcon ), | 95 | Opie::Core::OResource::loadPixmap( "find", Opie::Core::OResource::SmallIcon ), |
96 | QString::null, 0, this, 0 ); | 96 | QString::null, 0, this, 0 ); |
97 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); | 97 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); |
98 | a->addTo( m_searchBar ); | 98 | a->addTo( m_searchBar ); |
99 | 99 | ||
100 | // Insert Contact menu items | 100 | // Insert Contact menu items |
101 | QActionGroup *items = new QActionGroup( this, QString::null, false ); | 101 | QActionGroup *items = new QActionGroup( this, QString::null, false ); |
102 | 102 | ||
103 | m_actionMail = new QAction( tr( "Write Mail To" ), | 103 | m_actionMail = new QAction( tr( "Write Mail To" ), |
104 | Opie::Core::OResource::loadPixmap( "addressbook/sendmail" ), | 104 | Opie::Core::OResource::loadPixmap( "addressbook/sendmail", Opie::Core::OResource::SmallIcon ), |
105 | QString::null, 0, items, 0 ); | 105 | QString::null, 0, items, 0 ); |
106 | connect( m_actionMail, SIGNAL(activated()), this, SLOT(writeMail()) ); | 106 | connect( m_actionMail, SIGNAL(activated()), this, SLOT(writeMail()) ); |
107 | 107 | ||
108 | a = new QAction( tr("Import vCard"), | 108 | a = new QAction( tr("Import vCard"), |
109 | Opie::Core::OResource::loadPixmap( "addressbook/fileimport" ), | 109 | Opie::Core::OResource::loadPixmap( "addressbook/fileimport", Opie::Core::OResource::SmallIcon ), |
110 | QString::null, 0, items, 0 ); | 110 | QString::null, 0, items, 0 ); |
111 | connect( a, SIGNAL(activated()), this, SLOT(importvCard()) ); | 111 | connect( a, SIGNAL(activated()), this, SLOT(importvCard()) ); |
112 | 112 | ||
113 | a = new QAction( tr("Export vCard"), | 113 | a = new QAction( tr("Export vCard"), |
114 | Opie::Core::OResource::loadPixmap( "addressbook/fileexport" ), | 114 | Opie::Core::OResource::loadPixmap( "addressbook/fileexport", Opie::Core::OResource::SmallIcon ), |
115 | QString::null, 0, items, 0 ); | 115 | QString::null, 0, items, 0 ); |
116 | connect( a, SIGNAL(activated()), this, SLOT(exportvCard()) ); | 116 | connect( a, SIGNAL(activated()), this, SLOT(exportvCard()) ); |
117 | 117 | ||
118 | m_actionPersonal = new QAction( tr("My Personal Details"), | 118 | m_actionPersonal = new QAction( tr("My Personal Details"), |
119 | Opie::Core::OResource::loadPixmap( "addressbook/identity" ), | 119 | Opie::Core::OResource::loadPixmap( "addressbook/identity", Opie::Core::OResource::SmallIcon ), |
120 | QString::null, 0, items, 0 , true ); | 120 | QString::null, 0, items, 0 , true ); |
121 | connect( m_actionPersonal, SIGNAL(activated()), this, SLOT(slotPersonalView()) ); | 121 | connect( m_actionPersonal, SIGNAL(activated()), this, SLOT(slotPersonalView()) ); |
122 | 122 | ||
123 | insertItemMenuItems( items ); | 123 | insertItemMenuItems( items ); |
124 | 124 | ||
125 | // Insert View menu items | 125 | // Insert View menu items |
126 | items = new QActionGroup( this, QString::null, false ); | 126 | items = new QActionGroup( this, QString::null, false ); |
127 | 127 | ||
128 | a = new QAction( tr("Show quick search bar"),QString::null, 0, items, 0, true ); | 128 | a = new QAction( tr("Show quick search bar"),QString::null, 0, items, 0, true ); |
129 | connect( a, SIGNAL(toggled(bool)), this, SLOT(slotShowFind(bool)) ); | 129 | connect( a, SIGNAL(toggled(bool)), this, SLOT(slotShowFind(bool)) ); |
130 | 130 | ||
131 | insertViewMenuItems( items ); | 131 | insertViewMenuItems( items ); |
132 | 132 | ||
133 | // Fontsize | 133 | // Fontsize |
134 | defaultFont = new QFont( m_abView->font() ); | 134 | defaultFont = new QFont( m_abView->font() ); |
135 | slotSetFont(m_config.fontSize()); | 135 | slotSetFont(m_config.fontSize()); |
136 | m_curFontSize = m_config.fontSize(); | 136 | m_curFontSize = m_config.fontSize(); |
137 | 137 | ||
138 | setCentralWidget(m_listContainer); | 138 | setCentralWidget(m_listContainer); |
139 | 139 | ||
140 | //odebug << "adressbook contrsuction: t=" << t.elapsed() << oendl; | 140 | //odebug << "adressbook contrsuction: t=" << t.elapsed() << oendl; |
141 | connect( qApp, SIGNAL(flush()), this, SLOT(flush()) ); | 141 | connect( qApp, SIGNAL(flush()), this, SLOT(flush()) ); |
142 | connect( qApp, SIGNAL(reload()), this, SLOT(reload()) ); | 142 | connect( qApp, SIGNAL(reload()), this, SLOT(reload()) ); |
143 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), | 143 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), |
144 | this, SLOT(appMessage(const QCString&,const QByteArray&)) ); | 144 | this, SLOT(appMessage(const QCString&,const QByteArray&)) ); |
145 | 145 | ||
146 | isLoading = false; | 146 | isLoading = false; |
147 | 147 | ||
148 | // Handle category selection | 148 | // Handle category selection |
149 | setViewCategory( m_config.category() ); | 149 | setViewCategory( m_config.category() ); |
150 | m_abView->setShowByCategory( m_config.category() ); | 150 | m_abView->setShowByCategory( m_config.category() ); |
151 | connect( this, SIGNAL(categorySelected(const QString&)), | 151 | connect( this, SIGNAL(categorySelected(const QString&)), |
152 | this, SLOT(slotSetCategory(const QString&)) ); | 152 | this, SLOT(slotSetCategory(const QString&)) ); |
153 | } | 153 | } |
154 | 154 | ||
155 | void AddressbookWindow::slotSetFont( int size ) | 155 | void AddressbookWindow::slotSetFont( int size ) |
156 | { | 156 | { |
157 | odebug << "void AddressbookWindow::slotSetFont( " << size << " )" << oendl; | 157 | odebug << "void AddressbookWindow::slotSetFont( " << size << " )" << oendl; |
158 | 158 | ||
159 | if (size > 2 || size < 0) | 159 | if (size > 2 || size < 0) |
160 | size = 1; | 160 | size = 1; |
161 | 161 | ||
162 | m_config.setFontSize( size ); | 162 | m_config.setFontSize( size ); |
163 | 163 | ||
164 | QFont *currentFont; | 164 | QFont *currentFont; |
165 | 165 | ||
166 | switch (size) { | 166 | switch (size) { |
167 | case 0: | 167 | case 0: |
168 | m_abView->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); | 168 | m_abView->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); |
169 | currentFont = new QFont (m_abView->font()); | 169 | currentFont = new QFont (m_abView->font()); |
170 | // abList->resizeRows(currentFont->pixelSize() + 7); :SX | 170 | // abList->resizeRows(currentFont->pixelSize() + 7); :SX |
171 | // abList->resizeRows(); | 171 | // abList->resizeRows(); |
172 | break; | 172 | break; |
173 | case 1: | 173 | case 1: |
174 | m_abView->setFont( *defaultFont ); | 174 | m_abView->setFont( *defaultFont ); |
175 | currentFont = new QFont (m_abView->font()); | 175 | currentFont = new QFont (m_abView->font()); |
176 | // // abList->resizeRows(currentFont->pixelSize() + 7); | 176 | // // abList->resizeRows(currentFont->pixelSize() + 7); |
177 | // abList->resizeRows(); | 177 | // abList->resizeRows(); |
178 | break; | 178 | break; |
179 | case 2: | 179 | case 2: |
180 | m_abView->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) ); | 180 | m_abView->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) ); |
181 | currentFont = new QFont (m_abView->font()); | 181 | currentFont = new QFont (m_abView->font()); |
182 | // //abList->resizeRows(currentFont->pixelSize() + 7); | 182 | // //abList->resizeRows(currentFont->pixelSize() + 7); |
183 | // abList->resizeRows(); | 183 | // abList->resizeRows(); |
184 | break; | 184 | break; |
185 | } | 185 | } |
186 | } | 186 | } |
187 | 187 | ||
188 | 188 | ||
189 | 189 | ||
190 | void AddressbookWindow::importvCard() { | 190 | void AddressbookWindow::importvCard() { |
191 | QString str = Opie::Ui::OFileDialog::getOpenFileName( 1,"/");//,"", "*", this ); | 191 | QString str = Opie::Ui::OFileDialog::getOpenFileName( 1,"/");//,"", "*", this ); |
192 | if(!str.isEmpty() ){ | 192 | if(!str.isEmpty() ){ |
193 | setDocument((const QString&) str ); | 193 | setDocument((const QString&) str ); |
194 | } | 194 | } |
195 | 195 | ||
196 | } | 196 | } |
197 | void AddressbookWindow::exportvCard() | 197 | void AddressbookWindow::exportvCard() |
198 | { | 198 | { |
199 | odebug << "void AddressbookWindow::exportvCard()" << oendl; | 199 | odebug << "void AddressbookWindow::exportvCard()" << oendl; |
200 | QString filename = Opie::Ui::OFileDialog::getSaveFileName( 1,"/home/"); //,"", "*", this ); | 200 | QString filename = Opie::Ui::OFileDialog::getSaveFileName( 1,"/home/"); //,"", "*", this ); |
201 | if( !filename.isEmpty() && ( filename[filename.length()-1] != '/' ) ){ | 201 | if( !filename.isEmpty() && ( filename[filename.length()-1] != '/' ) ){ |
202 | odebug << " Save to file " << filename << ", (" << filename.length()-1 << ")" << oendl; | 202 | odebug << " Save to file " << filename << ", (" << filename.length()-1 << ")" << oendl; |
203 | Opie::OPimContact curCont = m_abView->currentEntry(); | 203 | Opie::OPimContact curCont = m_abView->currentEntry(); |
204 | if ( !curCont.isEmpty() ){ | 204 | if ( !curCont.isEmpty() ){ |
205 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | 205 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, |
206 | filename ); | 206 | filename ); |
207 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook_exp", QString::null , vcard_backend, true ); | 207 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook_exp", QString::null , vcard_backend, true ); |
208 | if ( access ){ | 208 | if ( access ){ |
209 | access->add( curCont ); | 209 | access->add( curCont ); |
210 | access->save(); | 210 | access->save(); |
211 | } | 211 | } |
212 | delete access; | 212 | delete access; |
213 | }else | 213 | }else |
214 | QMessageBox::critical( 0, "Export VCard", | 214 | QMessageBox::critical( 0, "Export VCard", |
215 | QString( tr( "You have to select a contact !") ) ); | 215 | QString( tr( "You have to select a contact !") ) ); |
216 | 216 | ||
217 | }else | 217 | }else |
218 | QMessageBox::critical( 0, "Export VCard", | 218 | QMessageBox::critical( 0, "Export VCard", |
219 | QString( tr( "You have to set a filename !") ) ); | 219 | QString( tr( "You have to set a filename !") ) ); |
220 | } | 220 | } |
221 | 221 | ||
222 | void AddressbookWindow::setDocument( const QString &filename ) | 222 | void AddressbookWindow::setDocument( const QString &filename ) |
223 | { | 223 | { |
224 | odebug << "void AddressbookWindow::setDocument( " << filename << " )" << oendl; | 224 | odebug << "void AddressbookWindow::setDocument( " << filename << " )" << oendl; |
225 | 225 | ||
226 | // Switch to default backend. This should avoid to import into | 226 | // Switch to default backend. This should avoid to import into |
227 | // the personal database accidently. | 227 | // the personal database accidently. |
228 | if ( m_actionPersonal->isOn() ){ | 228 | if ( m_actionPersonal->isOn() ){ |
229 | m_actionPersonal->setOn( false ); | 229 | m_actionPersonal->setOn( false ); |
230 | slotPersonalView(); | 230 | slotPersonalView(); |
231 | } | 231 | } |
232 | 232 | ||
233 | if ( filename.find(".vcf") != int(filename.length()) - 4 ){ | 233 | if ( filename.find(".vcf") != int(filename.length()) - 4 ){ |
234 | 234 | ||
235 | 235 | ||
236 | 236 | ||
237 | switch( QMessageBox::information( this, tr ( "Right file type ?" ), | 237 | switch( QMessageBox::information( this, tr ( "Right file type ?" ), |
238 | tr( "The selected file \n does not end with \".vcf\".\n Do you really want to open it?" ), | 238 | tr( "The selected file \n does not end with \".vcf\".\n Do you really want to open it?" ), |
239 | tr( "&Yes" ), tr( "&No" ), QString::null, | 239 | tr( "&Yes" ), tr( "&No" ), QString::null, |
240 | 0, // Enter == button 0 | 240 | 0, // Enter == button 0 |
241 | 2 ) ) { // Escape == button 2 | 241 | 2 ) ) { // Escape == button 2 |
242 | case 0: | 242 | case 0: |
243 | odebug << "YES clicked" << oendl; | 243 | odebug << "YES clicked" << oendl; |
244 | break; | 244 | break; |
245 | case 1: | 245 | case 1: |
246 | odebug << "NO clicked" << oendl; | 246 | odebug << "NO clicked" << oendl; |
247 | return; | 247 | return; |
248 | break; | 248 | break; |
249 | } | 249 | } |
250 | } | 250 | } |
251 | 251 | ||
252 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | 252 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, |
253 | filename ); | 253 | filename ); |
254 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 254 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
255 | Opie::OPimContactAccess::List allList = access->allRecords(); | 255 | Opie::OPimContactAccess::List allList = access->allRecords(); |
256 | odebug << "Found number of contacts in File: " << allList.count() << oendl; | 256 | odebug << "Found number of contacts in File: " << allList.count() << oendl; |
257 | 257 | ||
258 | if ( !allList.count() ) { | 258 | if ( !allList.count() ) { |
259 | QMessageBox::information( this, "Import VCard", | 259 | QMessageBox::information( this, "Import VCard", |
260 | "It was impossible to import\nthe VCard.\n" | 260 | "It was impossible to import\nthe VCard.\n" |
261 | "The VCard may be corrupted!" ); | 261 | "The VCard may be corrupted!" ); |
262 | } | 262 | } |
263 | 263 | ||
264 | bool doAsk = true; | 264 | bool doAsk = true; |
265 | Opie::OPimContactAccess::List::Iterator it; | 265 | Opie::OPimContactAccess::List::Iterator it; |
266 | for ( it = allList.begin(); it != allList.end(); ++it ){ | 266 | for ( it = allList.begin(); it != allList.end(); ++it ){ |
267 | odebug << "Adding Contact from: " << (*it).fullName() << oendl; | 267 | odebug << "Adding Contact from: " << (*it).fullName() << oendl; |
268 | if ( doAsk ){ | 268 | if ( doAsk ){ |
269 | switch( QMessageBox::information( this, tr ( "Add Contact?" ), | 269 | switch( QMessageBox::information( this, tr ( "Add Contact?" ), |
270 | tr( "Do you really want add contact for \n%1?" ) | 270 | tr( "Do you really want add contact for \n%1?" ) |
271 | .arg( (*it).fullName().latin1() ), | 271 | .arg( (*it).fullName().latin1() ), |
272 | tr( "&Yes" ), tr( "&No" ), tr( "&All Yes"), | 272 | tr( "&Yes" ), tr( "&No" ), tr( "&All Yes"), |
273 | 0, // Enter == button 0 | 273 | 0, // Enter == button 0 |
274 | 2 ) ) { // Escape == button 2 | 274 | 2 ) ) { // Escape == button 2 |
275 | case 0: | 275 | case 0: |
276 | odebug << "YES clicked" << oendl; | 276 | odebug << "YES clicked" << oendl; |
277 | m_abView->addEntry( *it ); | 277 | m_abView->addEntry( *it ); |
278 | break; | 278 | break; |
279 | case 1: | 279 | case 1: |
280 | odebug << "NO clicked" << oendl; | 280 | odebug << "NO clicked" << oendl; |
281 | break; | 281 | break; |
282 | case 2: | 282 | case 2: |
283 | odebug << "YesAll clicked" << oendl; | 283 | odebug << "YesAll clicked" << oendl; |
284 | doAsk = false; | 284 | doAsk = false; |
285 | break; | 285 | break; |
286 | } | 286 | } |
287 | }else | 287 | }else |
288 | m_abView->addEntry( *it ); | 288 | m_abView->addEntry( *it ); |
289 | 289 | ||
290 | } | 290 | } |
291 | 291 | ||
292 | delete access; | 292 | delete access; |
293 | } | 293 | } |
294 | 294 | ||
295 | void AddressbookWindow::resizeEvent( QResizeEvent *e ) | 295 | void AddressbookWindow::resizeEvent( QResizeEvent *e ) |
296 | { | 296 | { |
297 | QMainWindow::resizeEvent( e ); | 297 | QMainWindow::resizeEvent( e ); |
298 | 298 | ||
299 | 299 | ||
300 | } | 300 | } |
301 | 301 | ||
302 | AddressbookWindow::~AddressbookWindow() | 302 | AddressbookWindow::~AddressbookWindow() |
303 | { | 303 | { |
304 | ToolBarDock dock; | 304 | ToolBarDock dock; |
305 | int dummy; | 305 | int dummy; |
306 | bool bDummy; | 306 | bool bDummy; |
307 | getLocation ( listTools, dock, dummy, bDummy, dummy ); | 307 | getLocation ( listTools, dock, dummy, bDummy, dummy ); |
308 | m_config.setToolBarDock( dock ); | 308 | m_config.setToolBarDock( dock ); |
309 | m_config.save(); | 309 | m_config.save(); |
310 | } | 310 | } |
311 | 311 | ||
312 | int AddressbookWindow::create() | 312 | int AddressbookWindow::create() |
313 | { | 313 | { |
314 | return 0; | 314 | return 0; |
315 | } | 315 | } |
316 | 316 | ||
317 | bool AddressbookWindow::remove( int /*uid*/ ) | 317 | bool AddressbookWindow::remove( int /*uid*/ ) |
318 | { | 318 | { |
319 | return false; | 319 | return false; |
320 | } | 320 | } |
321 | 321 | ||
322 | void AddressbookWindow::beam( int /*uid*/ ) | 322 | void AddressbookWindow::beam( int /*uid*/ ) |
323 | { | 323 | { |
324 | } | 324 | } |
325 | 325 | ||
326 | void AddressbookWindow::show( int /*uid*/ ) | 326 | void AddressbookWindow::show( int /*uid*/ ) |
327 | { | 327 | { |
328 | } | 328 | } |
329 | 329 | ||
330 | void AddressbookWindow::edit( int /*uid*/ ) | 330 | void AddressbookWindow::edit( int /*uid*/ ) |
331 | { | 331 | { |
332 | } | 332 | } |
333 | 333 | ||
334 | void AddressbookWindow::add( const Opie::OPimRecord& ) | 334 | void AddressbookWindow::add( const Opie::OPimRecord& ) |
335 | { | 335 | { |
336 | } | 336 | } |
337 | 337 | ||
338 | void AddressbookWindow::slotItemNew() | 338 | void AddressbookWindow::slotItemNew() |
339 | { | 339 | { |
340 | Opie::OPimContact cnt; | 340 | Opie::OPimContact cnt; |
341 | if( !syncing ) { | 341 | if( !syncing ) { |
342 | editEntry( NewEntry ); | 342 | editEntry( NewEntry ); |
343 | } else { | 343 | } else { |
344 | QMessageBox::warning(this, tr("Contacts"), | 344 | QMessageBox::warning(this, tr("Contacts"), |
345 | tr("Can not edit data, currently syncing")); | 345 | tr("Can not edit data, currently syncing")); |
346 | } | 346 | } |
347 | } | 347 | } |
348 | 348 | ||
349 | void AddressbookWindow::slotItemEdit() | 349 | void AddressbookWindow::slotItemEdit() |
350 | { | 350 | { |
351 | if(!syncing) { | 351 | if(!syncing) { |
352 | if (m_actionPersonal->isOn()) { | 352 | if (m_actionPersonal->isOn()) { |
353 | editPersonal(); | 353 | editPersonal(); |
354 | } else { | 354 | } else { |
355 | editEntry( EditEntry ); | 355 | editEntry( EditEntry ); |
356 | } | 356 | } |
357 | } else { | 357 | } else { |
358 | QMessageBox::warning( this, tr("Contacts"), | 358 | QMessageBox::warning( this, tr("Contacts"), |
359 | tr("Can not edit data, currently syncing") ); | 359 | tr("Can not edit data, currently syncing") ); |
360 | } | 360 | } |
361 | } | 361 | } |
362 | 362 | ||
363 | void AddressbookWindow::slotItemDuplicate() | 363 | void AddressbookWindow::slotItemDuplicate() |
364 | { | 364 | { |
365 | if(!syncing) | 365 | if(!syncing) |
366 | { | 366 | { |
367 | Opie::OPimContact entry = m_abView->currentEntry(); | 367 | Opie::OPimContact entry = m_abView->currentEntry(); |
368 | entry.assignUid(); | 368 | entry.assignUid(); |
369 | m_abView->addEntry( entry ); | 369 | m_abView->addEntry( entry ); |
370 | m_abView->setCurrentUid( entry.uid() ); | 370 | m_abView->setCurrentUid( entry.uid() ); |
371 | } | 371 | } |
372 | else | 372 | else |
373 | { | 373 | { |
374 | QMessageBox::warning( this, tr("Contacts"), | 374 | QMessageBox::warning( this, tr("Contacts"), |
375 | tr("Can not edit data, currently syncing") ); | 375 | tr("Can not edit data, currently syncing") ); |
376 | } | 376 | } |
377 | } | 377 | } |
378 | 378 | ||
379 | void AddressbookWindow::slotItemDelete() | 379 | void AddressbookWindow::slotItemDelete() |
380 | { | 380 | { |
381 | if(!syncing) { | 381 | if(!syncing) { |
382 | Opie::OPimContact tmpEntry = m_abView ->currentEntry(); | 382 | Opie::OPimContact tmpEntry = m_abView ->currentEntry(); |
383 | 383 | ||
384 | // get a name, do the best we can... | 384 | // get a name, do the best we can... |
385 | QString strName = tmpEntry.fullName(); | 385 | QString strName = tmpEntry.fullName(); |
386 | if ( strName.isEmpty() ) { | 386 | if ( strName.isEmpty() ) { |
387 | strName = tmpEntry.company(); | 387 | strName = tmpEntry.company(); |
388 | if ( strName.isEmpty() ) | 388 | if ( strName.isEmpty() ) |
389 | strName = "No Name"; | 389 | strName = "No Name"; |
390 | } | 390 | } |
391 | 391 | ||
392 | 392 | ||
393 | if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), | 393 | if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), |
394 | strName ) ) { | 394 | strName ) ) { |
395 | m_abView->removeEntry( tmpEntry.uid() ); | 395 | m_abView->removeEntry( tmpEntry.uid() ); |
396 | } | 396 | } |
397 | } else { | 397 | } else { |
398 | QMessageBox::warning( this, tr("Contacts"), | 398 | QMessageBox::warning( this, tr("Contacts"), |
399 | tr("Can not edit data, currently syncing") ); | 399 | tr("Can not edit data, currently syncing") ); |
400 | } | 400 | } |
401 | } | 401 | } |
402 | 402 | ||
403 | static const char * beamfile = "/tmp/obex/contact.vcf"; | 403 | static const char * beamfile = "/tmp/obex/contact.vcf"; |
404 | 404 | ||
405 | void AddressbookWindow::slotItemBeam() | 405 | void AddressbookWindow::slotItemBeam() |
406 | { | 406 | { |
407 | QString beamFilename; | 407 | QString beamFilename; |
408 | Opie::OPimContact c; | 408 | Opie::OPimContact c; |
409 | if ( m_actionPersonal->isOn() ) { | 409 | if ( m_actionPersonal->isOn() ) { |
410 | beamFilename = addressbookPersonalVCardName(); | 410 | beamFilename = addressbookPersonalVCardName(); |
411 | if ( !QFile::exists( beamFilename ) ) | 411 | if ( !QFile::exists( beamFilename ) ) |
412 | return; // can't beam a non-existent file | 412 | return; // can't beam a non-existent file |
413 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | 413 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, |
414 | beamFilename ); | 414 | beamFilename ); |
415 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 415 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
416 | Opie::OPimContactAccess::List allList = access->allRecords(); | 416 | Opie::OPimContactAccess::List allList = access->allRecords(); |
417 | Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first | 417 | Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first |
418 | c = *it; | 418 | c = *it; |
419 | 419 | ||
420 | delete access; | 420 | delete access; |
421 | } else { | 421 | } else { |
422 | unlink( beamfile ); // delete if exists | 422 | unlink( beamfile ); // delete if exists |
423 | mkdir("/tmp/obex/", 0755); | 423 | mkdir("/tmp/obex/", 0755); |
424 | c = m_abView -> currentEntry(); | 424 | c = m_abView -> currentEntry(); |
425 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | 425 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, |
426 | beamfile ); | 426 | beamfile ); |
427 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 427 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
428 | access->add( c ); | 428 | access->add( c ); |
429 | access->save(); | 429 | access->save(); |
430 | delete access; | 430 | delete access; |
431 | 431 | ||
432 | beamFilename = beamfile; | 432 | beamFilename = beamfile; |
433 | } | 433 | } |
434 | 434 | ||
435 | odebug << "Beaming: " << beamFilename << oendl; | 435 | odebug << "Beaming: " << beamFilename << oendl; |
436 | 436 | ||
437 | Ir *ir = new Ir( this ); | 437 | Ir *ir = new Ir( this ); |
438 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); | 438 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); |
439 | QString description = c.fullName(); | 439 | QString description = c.fullName(); |
440 | ir->send( beamFilename, description, "text/x-vCard" ); | 440 | ir->send( beamFilename, description, "text/x-vCard" ); |
441 | } | 441 | } |
442 | 442 | ||
443 | void AddressbookWindow::slotItemFind() | 443 | void AddressbookWindow::slotItemFind() |
444 | { | 444 | { |
445 | } | 445 | } |
446 | 446 | ||
447 | void AddressbookWindow::slotConfigure() | 447 | void AddressbookWindow::slotConfigure() |
448 | { | 448 | { |
449 | ConfigDlg* dlg = new ConfigDlg( this, "Config" ); | 449 | ConfigDlg* dlg = new ConfigDlg( this, "Config" ); |
450 | dlg -> setConfig( m_config ); | 450 | dlg -> setConfig( m_config ); |
451 | if ( QPEApplication::execDialog( dlg ) ) { | 451 | if ( QPEApplication::execDialog( dlg ) ) { |
452 | odebug << "Config Dialog accepted!" << oendl; | 452 | odebug << "Config Dialog accepted!" << oendl; |
453 | m_config = dlg -> getConfig(); | 453 | m_config = dlg -> getConfig(); |
454 | if ( m_curFontSize != m_config.fontSize() ){ | 454 | if ( m_curFontSize != m_config.fontSize() ){ |
455 | odebug << "Font was changed!" << oendl; | 455 | odebug << "Font was changed!" << oendl; |
456 | m_curFontSize = m_config.fontSize(); | 456 | m_curFontSize = m_config.fontSize(); |
457 | emit slotSetFont( m_curFontSize ); | 457 | emit slotSetFont( m_curFontSize ); |
458 | } | 458 | } |
459 | m_abView -> setListOrder( m_config.orderList() ); | 459 | m_abView -> setListOrder( m_config.orderList() ); |
460 | } | 460 | } |
461 | 461 | ||
462 | delete dlg; | 462 | delete dlg; |
463 | } | 463 | } |
464 | 464 | ||
465 | void AddressbookWindow::slotShowFind( bool show ) | 465 | void AddressbookWindow::slotShowFind( bool show ) |
466 | { | 466 | { |
467 | if ( show ) | 467 | if ( show ) |
468 | { | 468 | { |
469 | // Display search bar | 469 | // Display search bar |
470 | m_searchBar->show(); | 470 | m_searchBar->show(); |
471 | m_abView -> inSearch(); | 471 | m_abView -> inSearch(); |
472 | m_searchEdit->setFocus(); | 472 | m_searchEdit->setFocus(); |
473 | } | 473 | } |
474 | else | 474 | else |
475 | { | 475 | { |
476 | // Hide search bar | 476 | // Hide search bar |
477 | m_searchBar->hide(); | 477 | m_searchBar->hide(); |
478 | m_abView -> offSearch(); | 478 | m_abView -> offSearch(); |
479 | } | 479 | } |
480 | } | 480 | } |
481 | 481 | ||
482 | void AddressbookWindow::slotFind() | 482 | void AddressbookWindow::slotFind() |
483 | { | 483 | { |
484 | m_abView->slotDoFind( m_searchEdit->text(), m_config.beCaseSensitive(), m_config.useRegExp(), false); | 484 | m_abView->slotDoFind( m_searchEdit->text(), m_config.beCaseSensitive(), m_config.useRegExp(), false); |
485 | 485 | ||
486 | m_searchEdit->clearFocus(); | 486 | m_searchEdit->clearFocus(); |
487 | // m_abView->setFocus(); | 487 | // m_abView->setFocus(); |
488 | 488 | ||
489 | } | 489 | } |
490 | 490 | ||
491 | void AddressbookWindow::slotViewBack() | 491 | void AddressbookWindow::slotViewBack() |
492 | { | 492 | { |
493 | // :SX showList(); | 493 | // :SX showList(); |
494 | } | 494 | } |
495 | 495 | ||
496 | void AddressbookWindow::writeMail() | 496 | void AddressbookWindow::writeMail() |
497 | { | 497 | { |
498 | Opie::OPimContact c = m_abView -> currentEntry(); | 498 | Opie::OPimContact c = m_abView -> currentEntry(); |
499 | QString name = c.fileAs(); | 499 | QString name = c.fileAs(); |
500 | QString email = c.defaultEmail(); | 500 | QString email = c.defaultEmail(); |
501 | 501 | ||
502 | // I prefer the OPIE-Environment variable before the | 502 | // I prefer the OPIE-Environment variable before the |
503 | // QPE-one.. | 503 | // QPE-one.. |
504 | QString basepath = QString::fromLatin1( getenv("OPIEDIR") ); | 504 | QString basepath = QString::fromLatin1( getenv("OPIEDIR") ); |
505 | if ( basepath.isEmpty() ) | 505 | if ( basepath.isEmpty() ) |
506 | basepath = QString::fromLatin1( getenv("QPEDIR") ); | 506 | basepath = QString::fromLatin1( getenv("QPEDIR") ); |
507 | 507 | ||
508 | // Try to access the preferred. If not possible, try to | 508 | // Try to access the preferred. If not possible, try to |
509 | // switch to the other one.. | 509 | // switch to the other one.. |
510 | if ( m_config.useQtMail() ){ | 510 | if ( m_config.useQtMail() ){ |
511 | odebug << "Accessing: " << (basepath + "/bin/qtmail") << oendl; | 511 | odebug << "Accessing: " << (basepath + "/bin/qtmail") << oendl; |
512 | if ( QFile::exists( basepath + "/bin/qtmail" ) ){ | 512 | if ( QFile::exists( basepath + "/bin/qtmail" ) ){ |
513 | odebug << "QCop" << oendl; | 513 | odebug << "QCop" << oendl; |
514 | QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); | 514 | QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); |
515 | e << name << email; | 515 | e << name << email; |
516 | return; | 516 | return; |
517 | } else | 517 | } else |
518 | m_config.setUseOpieMail( true ); | 518 | m_config.setUseOpieMail( true ); |
519 | } | 519 | } |
520 | if ( m_config.useOpieMail() ){ | 520 | if ( m_config.useOpieMail() ){ |
521 | odebug << "Accessing: " << (basepath + "/bin/opiemail") << oendl; | 521 | odebug << "Accessing: " << (basepath + "/bin/opiemail") << oendl; |
522 | if ( QFile::exists( basepath + "/bin/opiemail" ) ){ | 522 | if ( QFile::exists( basepath + "/bin/opiemail" ) ){ |
523 | odebug << "QCop" << oendl; | 523 | odebug << "QCop" << oendl; |
524 | QCopEnvelope e("QPE/Application/opiemail", "writeMail(QString,QString)"); | 524 | QCopEnvelope e("QPE/Application/opiemail", "writeMail(QString,QString)"); |
525 | e << name << email; | 525 | e << name << email; |
526 | return; | 526 | return; |
527 | } else | 527 | } else |
528 | m_config.setUseQtMail( true ); | 528 | m_config.setUseQtMail( true ); |
529 | } | 529 | } |
530 | 530 | ||
531 | } | 531 | } |
532 | 532 | ||
533 | void AddressbookWindow::beamDone( Ir *ir ) | 533 | void AddressbookWindow::beamDone( Ir *ir ) |
534 | { | 534 | { |
535 | 535 | ||
536 | delete ir; | 536 | delete ir; |
537 | unlink( beamfile ); | 537 | unlink( beamfile ); |
538 | } | 538 | } |
539 | 539 | ||
540 | 540 | ||
541 | static void parseName( const QString& name, QString *first, QString *middle, | 541 | static void parseName( const QString& name, QString *first, QString *middle, |
542 | QString * last ) | 542 | QString * last ) |
543 | { | 543 | { |
544 | 544 | ||
545 | int comma = name.find ( "," ); | 545 | int comma = name.find ( "," ); |
546 | QString rest; | 546 | QString rest; |
547 | if ( comma > 0 ) { | 547 | if ( comma > 0 ) { |
548 | *last = name.left( comma ); | 548 | *last = name.left( comma ); |
549 | comma++; | 549 | comma++; |
550 | while ( comma < int(name.length()) && name[comma] == ' ' ) | 550 | while ( comma < int(name.length()) && name[comma] == ' ' ) |
551 | comma++; | 551 | comma++; |
552 | rest = name.mid( comma ); | 552 | rest = name.mid( comma ); |
553 | } else { | 553 | } else { |
554 | int space = name.findRev( ' ' ); | 554 | int space = name.findRev( ' ' ); |
555 | *last = name.mid( space+1 ); | 555 | *last = name.mid( space+1 ); |
556 | rest = name.left( space ); | 556 | rest = name.left( space ); |
557 | } | 557 | } |
558 | int space = rest.find( ' ' ); | 558 | int space = rest.find( ' ' ); |
559 | if ( space <= 0 ) { | 559 | if ( space <= 0 ) { |
560 | *first = rest; | 560 | *first = rest; |
561 | } else { | 561 | } else { |
562 | *first = rest.left( space ); | 562 | *first = rest.left( space ); |
563 | *middle = rest.mid( space+1 ); | 563 | *middle = rest.mid( space+1 ); |
564 | } | 564 | } |
565 | 565 | ||
566 | } | 566 | } |
567 | 567 | ||
568 | 568 | ||
569 | void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) | 569 | void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) |
570 | { | 570 | { |
571 | bool needShow = false; | 571 | bool needShow = false; |
572 | odebug << "Receiving QCop-Call with message " << msg << oendl; | 572 | odebug << "Receiving QCop-Call with message " << msg << oendl; |
573 | 573 | ||
574 | 574 | ||
575 | if (msg == "editPersonal()") { | 575 | if (msg == "editPersonal()") { |
576 | editPersonal(); | 576 | editPersonal(); |
577 | 577 | ||
578 | // Categories might have changed, so reload | 578 | // Categories might have changed, so reload |
579 | reloadCategories(); | 579 | reloadCategories(); |
580 | } else if (msg == "editPersonalAndClose()") { | 580 | } else if (msg == "editPersonalAndClose()") { |
581 | editPersonal(); | 581 | editPersonal(); |
582 | close(); | 582 | close(); |
583 | } else if ( msg == "addContact(QString,QString)" ) { | 583 | } else if ( msg == "addContact(QString,QString)" ) { |
584 | QDataStream stream(data,IO_ReadOnly); | 584 | QDataStream stream(data,IO_ReadOnly); |
585 | QString name, email; | 585 | QString name, email; |
586 | stream >> name >> email; | 586 | stream >> name >> email; |
587 | 587 | ||
588 | Opie::OPimContact cnt; | 588 | Opie::OPimContact cnt; |
589 | QString fn, mn, ln; | 589 | QString fn, mn, ln; |
590 | parseName( name, &fn, &mn, &ln ); | 590 | parseName( name, &fn, &mn, &ln ); |
591 | //odebug << " " << fn << " - " << mn " - " << ln << oendl; | 591 | //odebug << " " << fn << " - " << mn " - " << ln << oendl; |
592 | cnt.setFirstName( fn ); | 592 | cnt.setFirstName( fn ); |
593 | cnt.setMiddleName( mn ); | 593 | cnt.setMiddleName( mn ); |
594 | cnt.setLastName( ln ); | 594 | cnt.setLastName( ln ); |
595 | cnt.insertEmails( email ); | 595 | cnt.insertEmails( email ); |
596 | cnt.setDefaultEmail( email ); | 596 | cnt.setDefaultEmail( email ); |
597 | cnt.setFileAs(); | 597 | cnt.setFileAs(); |
598 | 598 | ||
599 | m_abView -> addEntry( cnt ); | 599 | m_abView -> addEntry( cnt ); |
600 | 600 | ||
601 | // :SXm_abView()->init( cnt ); | 601 | // :SXm_abView()->init( cnt ); |
602 | editEntry( EditEntry ); | 602 | editEntry( EditEntry ); |
603 | 603 | ||
604 | // Categories might have changed, so reload | 604 | // Categories might have changed, so reload |
605 | reloadCategories(); | 605 | reloadCategories(); |
606 | } else if ( msg == "beamBusinessCard()" ) { | 606 | } else if ( msg == "beamBusinessCard()" ) { |
607 | QString beamFilename = addressbookPersonalVCardName(); | 607 | QString beamFilename = addressbookPersonalVCardName(); |
608 | if ( !QFile::exists( beamFilename ) ) | 608 | if ( !QFile::exists( beamFilename ) ) |
609 | return; // can't beam a non-existent file | 609 | return; // can't beam a non-existent file |
610 | 610 | ||
611 | Ir *ir = new Ir( this ); | 611 | Ir *ir = new Ir( this ); |
612 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); | 612 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); |
613 | QString description = "mycard.vcf"; | 613 | QString description = "mycard.vcf"; |
614 | ir->send( beamFilename, description, "text/x-vCard" ); | 614 | ir->send( beamFilename, description, "text/x-vCard" ); |
615 | } else if ( msg == "show(int)" ) { | 615 | } else if ( msg == "show(int)" ) { |
616 | raise(); | 616 | raise(); |
617 | QDataStream stream(data,IO_ReadOnly); | 617 | QDataStream stream(data,IO_ReadOnly); |
618 | int uid; | 618 | int uid; |
619 | stream >> uid; | 619 | stream >> uid; |
620 | 620 | ||
621 | odebug << "Showing uid: " << uid << oendl; | 621 | odebug << "Showing uid: " << uid << oendl; |
622 | 622 | ||
623 | // Deactivate Personal View.. | 623 | // Deactivate Personal View.. |
624 | if ( m_actionPersonal->isOn() ){ | 624 | if ( m_actionPersonal->isOn() ){ |
625 | m_actionPersonal->setOn( false ); | 625 | m_actionPersonal->setOn( false ); |
626 | slotPersonalView(); | 626 | slotPersonalView(); |
627 | } | 627 | } |
628 | 628 | ||
629 | // Reset category and show as card.. | 629 | // Reset category and show as card.. |
630 | m_abView -> setShowByCategory( QString::null ); | 630 | m_abView -> setShowByCategory( QString::null ); |
631 | m_abView -> setCurrentUid( uid ); | 631 | m_abView -> setCurrentUid( uid ); |
632 | slotViewSwitched ( AbView::CardView ); | 632 | slotViewSwitched ( AbView::CardView ); |
633 | 633 | ||
634 | needShow = true; | 634 | needShow = true; |
635 | 635 | ||
636 | 636 | ||
637 | } else if ( msg == "edit(int)" ) { | 637 | } else if ( msg == "edit(int)" ) { |
638 | QDataStream stream(data,IO_ReadOnly); | 638 | QDataStream stream(data,IO_ReadOnly); |
639 | int uid; | 639 | int uid; |
640 | stream >> uid; | 640 | stream >> uid; |
641 | 641 | ||
642 | // Deactivate Personal View.. | 642 | // Deactivate Personal View.. |
643 | if ( m_actionPersonal->isOn() ){ | 643 | if ( m_actionPersonal->isOn() ){ |
644 | m_actionPersonal->setOn( false ); | 644 | m_actionPersonal->setOn( false ); |
645 | slotPersonalView(); | 645 | slotPersonalView(); |
646 | } | 646 | } |
647 | 647 | ||
648 | // Reset category and edit.. | 648 | // Reset category and edit.. |
649 | m_abView -> setShowByCategory( QString::null ); | 649 | m_abView -> setShowByCategory( QString::null ); |
650 | m_abView -> setCurrentUid( uid ); | 650 | m_abView -> setCurrentUid( uid ); |
651 | slotItemEdit(); | 651 | slotItemEdit(); |
652 | 652 | ||
653 | // Categories might have changed, so reload | 653 | // Categories might have changed, so reload |
654 | reloadCategories(); | 654 | reloadCategories(); |
655 | } | 655 | } |
656 | 656 | ||
657 | if (needShow) | 657 | if (needShow) |
658 | QPEApplication::setKeepRunning(); | 658 | QPEApplication::setKeepRunning(); |
659 | } | 659 | } |
660 | 660 | ||
661 | void AddressbookWindow::editEntry( EntryMode entryMode ) | 661 | void AddressbookWindow::editEntry( EntryMode entryMode ) |
662 | { | 662 | { |
663 | Opie::OPimContact entry; | 663 | Opie::OPimContact entry; |
664 | if ( !abEditor ) { | 664 | if ( !abEditor ) { |
665 | abEditor = new ContactEditor( entry, this, "editor" ); | 665 | abEditor = new ContactEditor( entry, this, "editor" ); |
666 | } | 666 | } |
667 | if ( entryMode == EditEntry ) | 667 | if ( entryMode == EditEntry ) |
668 | abEditor->setEntry( m_abView -> currentEntry() ); | 668 | abEditor->setEntry( m_abView -> currentEntry() ); |
669 | else if ( entryMode == NewEntry ) | 669 | else if ( entryMode == NewEntry ) |
670 | abEditor->setEntry( entry ); | 670 | abEditor->setEntry( entry ); |
671 | 671 | ||
672 | // Set the dialog caption | 672 | // Set the dialog caption |
673 | if ( m_actionPersonal->isOn() ) | 673 | if ( m_actionPersonal->isOn() ) |
674 | abEditor->setCaption( tr( "Edit My Personal Details" ) ); | 674 | abEditor->setCaption( tr( "Edit My Personal Details" ) ); |
675 | else | 675 | else |
676 | abEditor->setCaption( tr( "Edit Contact" ) ); | 676 | abEditor->setCaption( tr( "Edit Contact" ) ); |
677 | 677 | ||
678 | // fix the focus... | 678 | // fix the focus... |
679 | abEditor->setNameFocus(); | 679 | abEditor->setNameFocus(); |
680 | if ( QPEApplication::execDialog( abEditor ) == QDialog::Accepted ) { | 680 | if ( QPEApplication::execDialog( abEditor ) == QDialog::Accepted ) { |
681 | setFocus(); | 681 | setFocus(); |
682 | if ( entryMode == NewEntry ) { | 682 | if ( entryMode == NewEntry ) { |
683 | Opie::OPimContact insertEntry = abEditor->entry(); | 683 | Opie::OPimContact insertEntry = abEditor->entry(); |
684 | insertEntry.assignUid(); | 684 | insertEntry.assignUid(); |
685 | m_abView -> addEntry( insertEntry ); | 685 | m_abView -> addEntry( insertEntry ); |
686 | m_abView -> setCurrentUid( insertEntry.uid() ); | 686 | m_abView -> setCurrentUid( insertEntry.uid() ); |
687 | } else { | 687 | } else { |
688 | Opie::OPimContact replEntry = abEditor->entry(); | 688 | Opie::OPimContact replEntry = abEditor->entry(); |
689 | 689 | ||
690 | if ( !replEntry.isValidUid() ) | 690 | if ( !replEntry.isValidUid() ) |
691 | replEntry.assignUid(); | 691 | replEntry.assignUid(); |
692 | 692 | ||
693 | m_abView -> replaceEntry( replEntry ); | 693 | m_abView -> replaceEntry( replEntry ); |
694 | } | 694 | } |
695 | 695 | ||
696 | // Categories might have changed, so reload | 696 | // Categories might have changed, so reload |
697 | reloadCategories(); | 697 | reloadCategories(); |
698 | } | 698 | } |
699 | } | 699 | } |
700 | 700 | ||
701 | void AddressbookWindow::editPersonal() | 701 | void AddressbookWindow::editPersonal() |
702 | { | 702 | { |
703 | Opie::OPimContact entry; | 703 | Opie::OPimContact entry; |
704 | 704 | ||
705 | // Switch to personal view if not selected | 705 | // Switch to personal view if not selected |
706 | // but take care of the menu, too | 706 | // but take care of the menu, too |
707 | if ( ! m_actionPersonal->isOn() ){ | 707 | if ( ! m_actionPersonal->isOn() ){ |
708 | odebug << "*** ++++" << oendl; | 708 | odebug << "*** ++++" << oendl; |
709 | m_actionPersonal->setOn( true ); | 709 | m_actionPersonal->setOn( true ); |
710 | slotPersonalView(); | 710 | slotPersonalView(); |
711 | } | 711 | } |
712 | 712 | ||
713 | if ( !abEditor ) { | 713 | if ( !abEditor ) { |
714 | abEditor = new ContactEditor( entry, this, "editor" ); | 714 | abEditor = new ContactEditor( entry, this, "editor" ); |
715 | } | 715 | } |
716 | 716 | ||
717 | abEditor->setPersonalView( true ); | 717 | abEditor->setPersonalView( true ); |
718 | editEntry( EditEntry ); | 718 | editEntry( EditEntry ); |
719 | abEditor->setPersonalView( false ); | 719 | abEditor->setPersonalView( false ); |
720 | 720 | ||
721 | } | 721 | } |
722 | 722 | ||
723 | 723 | ||
724 | void AddressbookWindow::slotPersonalView() | 724 | void AddressbookWindow::slotPersonalView() |
725 | { | 725 | { |
726 | odebug << "slotPersonalView()" << oendl; | 726 | odebug << "slotPersonalView()" << oendl; |
727 | 727 | ||
728 | bool personal = m_actionPersonal->isOn(); | 728 | bool personal = m_actionPersonal->isOn(); |
729 | 729 | ||
730 | // Disable actions when showing personal details | 730 | // Disable actions when showing personal details |
731 | setItemNewEnabled( !personal ); | 731 | setItemNewEnabled( !personal ); |
732 | setItemDuplicateEnabled( !personal ); | 732 | setItemDuplicateEnabled( !personal ); |
733 | setItemDeleteEnabled( !personal ); | 733 | setItemDeleteEnabled( !personal ); |
734 | m_actionMail->setEnabled( !personal ); | 734 | m_actionMail->setEnabled( !personal ); |
735 | setShowCategories( !personal ); | 735 | setShowCategories( !personal ); |
736 | 736 | ||
737 | // Display appropriate view | 737 | // Display appropriate view |
738 | m_abView->showPersonal( personal ); | 738 | m_abView->showPersonal( personal ); |
739 | 739 | ||
740 | if ( personal ) | 740 | if ( personal ) |
741 | { | 741 | { |
742 | setCaption( tr( "Contacts - My Personal Details") ); | 742 | setCaption( tr( "Contacts - My Personal Details") ); |
743 | 743 | ||
744 | // Set category to 'All' to make sure personal details is visible | 744 | // Set category to 'All' to make sure personal details is visible |
745 | setViewCategory( "All" ); | 745 | setViewCategory( "All" ); |
746 | m_abView->setShowByCategory( "All" ); | 746 | m_abView->setShowByCategory( "All" ); |
747 | 747 | ||
748 | // Temporarily disable letter picker | 748 | // Temporarily disable letter picker |
749 | pLabel->hide(); | 749 | pLabel->hide(); |
750 | } | 750 | } |
751 | else | 751 | else |
752 | { | 752 | { |
753 | setCaption( tr( "Contacts") ); | 753 | setCaption( tr( "Contacts") ); |
754 | 754 | ||
755 | // Re-enable letter picker | 755 | // Re-enable letter picker |
756 | pLabel->show(); | 756 | pLabel->show(); |
757 | } | 757 | } |
758 | } | 758 | } |
759 | 759 | ||
760 | void AddressbookWindow::reload() | 760 | void AddressbookWindow::reload() |
761 | { | 761 | { |
762 | syncing = false; | 762 | syncing = false; |
763 | m_abView->clear(); | 763 | m_abView->clear(); |
764 | m_abView->reload(); | 764 | m_abView->reload(); |
765 | } | 765 | } |
766 | 766 | ||
767 | void AddressbookWindow::flush() | 767 | void AddressbookWindow::flush() |
768 | { | 768 | { |
769 | syncing = true; | 769 | syncing = true; |
770 | m_abView->save(); | 770 | m_abView->save(); |
771 | } | 771 | } |
772 | 772 | ||
773 | 773 | ||
774 | void AddressbookWindow::closeEvent( QCloseEvent *e ) | 774 | void AddressbookWindow::closeEvent( QCloseEvent *e ) |
775 | { | 775 | { |
776 | if ( active_view == AbView::CardView ) | 776 | if ( active_view == AbView::CardView ) |
777 | { | 777 | { |
778 | if ( !m_actionPersonal->isOn() ) | 778 | if ( !m_actionPersonal->isOn() ) |
779 | { | 779 | { |
780 | // Switch to table view only if not editing personal details | 780 | // Switch to table view only if not editing personal details |
781 | slotViewSwitched( AbView::TableView ); | 781 | slotViewSwitched( AbView::TableView ); |
782 | } | 782 | } |
783 | else | 783 | else |
784 | { | 784 | { |
785 | // If currently editing personal details, switch off personal view | 785 | // If currently editing personal details, switch off personal view |
786 | m_actionPersonal->setOn( false ); | 786 | m_actionPersonal->setOn( false ); |
787 | slotPersonalView(); | 787 | slotPersonalView(); |
788 | } | 788 | } |
789 | 789 | ||
790 | e->ignore(); | 790 | e->ignore(); |
791 | return; | 791 | return; |
792 | } | 792 | } |
793 | if(syncing) { | 793 | if(syncing) { |
794 | /* shouldn't we save, I hear you say? well its already been set | 794 | /* shouldn't we save, I hear you say? well its already been set |
795 | so that an edit can not occur during a sync, and we flushed | 795 | so that an edit can not occur during a sync, and we flushed |
796 | at the start of the sync, so there is no need to save | 796 | at the start of the sync, so there is no need to save |
797 | Saving however itself would cause problems. */ | 797 | Saving however itself would cause problems. */ |
798 | e->accept(); | 798 | e->accept(); |
799 | return; | 799 | return; |
800 | } | 800 | } |
801 | //################## shouldn't always save | 801 | //################## shouldn't always save |
802 | // True, but the database handles this automatically ! (se) | 802 | // True, but the database handles this automatically ! (se) |
803 | if ( save() ) | 803 | if ( save() ) |
804 | e->accept(); | 804 | e->accept(); |
805 | else | 805 | else |
806 | e->ignore(); | 806 | e->ignore(); |
807 | } | 807 | } |
808 | 808 | ||
809 | /* | 809 | /* |
810 | Returns true if it is OK to exit | 810 | Returns true if it is OK to exit |
811 | */ | 811 | */ |
812 | 812 | ||
813 | bool AddressbookWindow::save() | 813 | bool AddressbookWindow::save() |
814 | { | 814 | { |
815 | if ( !m_abView->save() ) { | 815 | if ( !m_abView->save() ) { |
816 | if ( QMessageBox::critical( 0, tr( "Out of space" ), | 816 | if ( QMessageBox::critical( 0, tr( "Out of space" ), |
817 | tr("Unable to save information.\n" | 817 | tr("Unable to save information.\n" |
818 | "Free up some space\n" | 818 | "Free up some space\n" |
819 | "and try again.\n" | 819 | "and try again.\n" |
820 | "\nQuit anyway?"), | 820 | "\nQuit anyway?"), |
821 | QMessageBox::Yes|QMessageBox::Escape, | 821 | QMessageBox::Yes|QMessageBox::Escape, |
822 | QMessageBox::No|QMessageBox::Default ) | 822 | QMessageBox::No|QMessageBox::Default ) |
823 | != QMessageBox::No ) | 823 | != QMessageBox::No ) |
824 | return true; | 824 | return true; |
825 | else | 825 | else |
826 | return false; | 826 | return false; |
827 | } | 827 | } |
828 | return true; | 828 | return true; |
829 | } | 829 | } |
830 | 830 | ||
831 | #ifdef __DEBUG_RELEASE | 831 | #ifdef __DEBUG_RELEASE |
832 | void AddressbookWindow::slotSave() | 832 | void AddressbookWindow::slotSave() |
833 | { | 833 | { |
834 | save(); | 834 | save(); |
835 | } | 835 | } |
836 | #endif | 836 | #endif |
837 | 837 | ||
838 | 838 | ||
839 | void AddressbookWindow::slotNotFound() | 839 | void AddressbookWindow::slotNotFound() |
840 | { | 840 | { |
841 | odebug << "Got not found signal!" << oendl; | 841 | odebug << "Got not found signal!" << oendl; |
842 | QMessageBox::information( this, tr( "Not Found" ), | 842 | QMessageBox::information( this, tr( "Not Found" ), |
843 | "<qt>" + tr( "Unable to find a contact for this search pattern!" ) + "</qt>" ); | 843 | "<qt>" + tr( "Unable to find a contact for this search pattern!" ) + "</qt>" ); |
844 | 844 | ||
845 | 845 | ||
846 | } | 846 | } |
847 | void AddressbookWindow::slotWrapAround() | 847 | void AddressbookWindow::slotWrapAround() |
848 | { | 848 | { |
849 | odebug << "Got wrap signal!" << oendl; | 849 | odebug << "Got wrap signal!" << oendl; |
850 | // if ( doNotifyWrapAround ) | 850 | // if ( doNotifyWrapAround ) |
851 | // QMessageBox::information( this, tr( "End of list" ), | 851 | // QMessageBox::information( this, tr( "End of list" ), |
852 | // tr( "End of list. Wrap around now...!" ) + "\n" ); | 852 | // tr( "End of list. Wrap around now...!" ) + "\n" ); |
853 | 853 | ||
854 | } | 854 | } |
855 | 855 | ||
856 | void AddressbookWindow::slotSetCategory( const QString &category ) | 856 | void AddressbookWindow::slotSetCategory( const QString &category ) |
857 | { | 857 | { |
858 | odebug << "void AddressbookWindow::slotSetCategory( " << category << " )" << oendl; | 858 | odebug << "void AddressbookWindow::slotSetCategory( " << category << " )" << oendl; |
859 | 859 | ||
860 | // Tell the view about the selected category | 860 | // Tell the view about the selected category |
861 | QString cat = category; | 861 | QString cat = category; |
862 | if ( cat == tr( "All" ) ) | 862 | if ( cat == tr( "All" ) ) |
863 | cat = QString::null; | 863 | cat = QString::null; |
864 | m_config.setCategory( cat ); | 864 | m_config.setCategory( cat ); |
865 | m_abView -> setShowByCategory( cat ); | 865 | m_abView -> setShowByCategory( cat ); |
866 | } | 866 | } |
867 | 867 | ||
868 | void AddressbookWindow::slotViewSwitched( int view ) | 868 | void AddressbookWindow::slotViewSwitched( int view ) |
869 | { | 869 | { |
870 | odebug << "void AddressbookWindow::slotViewSwitched( " << view << " )" << oendl; | 870 | odebug << "void AddressbookWindow::slotViewSwitched( " << view << " )" << oendl; |
871 | 871 | ||
872 | // Tell the view about the selected view | 872 | // Tell the view about the selected view |
873 | m_abView -> setShowToView ( (AbView::Views) view ); | 873 | m_abView -> setShowToView ( (AbView::Views) view ); |
874 | active_view = view; | 874 | active_view = view; |
875 | } | 875 | } |
876 | 876 | ||
877 | 877 | ||
878 | void AddressbookWindow::slotListView() | 878 | void AddressbookWindow::slotListView() |
879 | { | 879 | { |
880 | slotViewSwitched( AbView::TableView ); | 880 | slotViewSwitched( AbView::TableView ); |
881 | } | 881 | } |
882 | 882 | ||
883 | void AddressbookWindow::slotCardView() | 883 | void AddressbookWindow::slotCardView() |
884 | { | 884 | { |
885 | slotViewSwitched( AbView::CardView ); | 885 | slotViewSwitched( AbView::CardView ); |
886 | } | 886 | } |
887 | 887 | ||
888 | void AddressbookWindow::slotSetLetter( char c ) { | 888 | void AddressbookWindow::slotSetLetter( char c ) { |
889 | 889 | ||
890 | m_abView->setShowByLetter( c, m_config.letterPickerSearch() ); | 890 | m_abView->setShowByLetter( c, m_config.letterPickerSearch() ); |
891 | 891 | ||
892 | } | 892 | } |
893 | 893 | ||