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