Diffstat (limited to 'core/pim/addressbook/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/addressbook/addressbook.cpp | 654 |
1 files changed, 224 insertions, 430 deletions
diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp index 3f0ac74..a4c2c6e 100644 --- a/core/pim/addressbook/addressbook.cpp +++ b/core/pim/addressbook/addressbook.cpp | |||
@@ -33,275 +33,142 @@ | |||
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 | : QMainWindow( parent, name, f ), | 58 | : Opie::OPimMainWindow( "Addressbook", "Contacts", tr( "Contact" ), "AddressBook", |
59 | catMenu (0l), | 59 | parent, name, WType_TopLevel | WStyle_ContextHelp ), |
60 | abEditor(0l), | 60 | abEditor(0l), |
61 | syncing(FALSE), | 61 | syncing(false) |
62 | m_tableViewButton(0l), | ||
63 | m_cardViewButton(0l) | ||
64 | { | 62 | { |
63 | setCaption( tr( "Contacts" ) ); | ||
64 | |||
65 | isLoading = true; | 65 | isLoading = true; |
66 | 66 | ||
67 | m_config.load(); | 67 | m_config.load(); |
68 | 68 | ||
69 | setCaption( tr("Contacts") ); | 69 | // Create Views |
70 | setIcon( Resource::loadPixmap( "addressbook/AddressBook" ) ); | 70 | m_listContainer = new QWidget( this ); |
71 | 71 | QVBoxLayout *vb = new QVBoxLayout( m_listContainer ); | |
72 | // Settings for Main Menu | ||
73 | // setToolBarsMovable( false ); | ||
74 | setToolBarsMovable( !m_config.fixedBars() ); | ||
75 | setRightJustification( true ); | ||
76 | |||
77 | QToolBar *bar = new QToolBar( this ); | ||
78 | bar->setHorizontalStretchable( TRUE ); | ||
79 | |||
80 | QMenuBar *mbList = new QMenuBar( bar ); | ||
81 | mbList->setMargin( 0 ); | ||
82 | |||
83 | QPopupMenu *edit = new QPopupMenu( mbList ); | ||
84 | mbList->insertItem( tr( "Contact" ), edit ); | ||
85 | |||
86 | // Category Menu | ||
87 | catMenu = new QPopupMenu( this ); | ||
88 | catMenu->setCheckable( TRUE ); | ||
89 | connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); | ||
90 | mbList->insertItem( tr("View"), catMenu ); | ||
91 | |||
92 | // Create Toolbar | ||
93 | listTools = new QToolBar( this, "list operations" ); | ||
94 | listTools->setHorizontalStretchable( true ); | ||
95 | addToolBar( listTools ); | ||
96 | moveToolBar( listTools, m_config.getToolBarPos() ); | ||
97 | |||
98 | // View Icons | ||
99 | m_tableViewButton = new QAction( tr( "List" ), Resource::loadPixmap( "addressbook/listview" ), | ||
100 | QString::null, 0, this, 0 ); | ||
101 | connect( m_tableViewButton, SIGNAL( activated() ), this, SLOT( slotListView() ) ); | ||
102 | m_tableViewButton->setToggleAction( true ); | ||
103 | m_tableViewButton->addTo( listTools ); | ||
104 | m_cardViewButton = new QAction( tr( "Card" ), Resource::loadPixmap( "addressbook/cardview" ), QString::null, 0, this, 0 ); | ||
105 | connect( m_cardViewButton, SIGNAL( activated() ), this, SLOT( slotCardView() ) ); | ||
106 | m_cardViewButton->setToggleAction( true ); | ||
107 | m_cardViewButton->addTo( listTools ); | ||
108 | |||
109 | listTools->addSeparator(); | ||
110 | |||
111 | // Other Buttons | ||
112 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, | ||
113 | 0, this, 0 ); | ||
114 | actionNew = a; | ||
115 | connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) ); | ||
116 | a->addTo( edit ); | ||
117 | a->addTo( listTools ); | ||
118 | |||
119 | a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, | ||
120 | 0, this, 0 ); | ||
121 | actionEdit = a; | ||
122 | connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) ); | ||
123 | a->addTo( edit ); | ||
124 | a->addTo( listTools ); | ||
125 | |||
126 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, | ||
127 | 0, this, 0 ); | ||
128 | actionTrash = a; | ||
129 | connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) ); | ||
130 | a->addTo( edit ); | ||
131 | a->addTo( listTools ); | ||
132 | |||
133 | |||
134 | // make it possible to go directly to businesscard via qcop call | ||
135 | //#if defined(Q_WS_QWS) // Why this ? (se) | ||
136 | #if !defined(QT_NO_COP) | ||
137 | QCopChannel *addressChannel = new QCopChannel("QPE/Addressbook" , this ); | ||
138 | connect (addressChannel, SIGNAL( received(const QCString&,const QByteArray&)), | ||
139 | this, SLOT ( appMessage(const QCString&,const QByteArray&) ) ); | ||
140 | #endif | ||
141 | // #endif | ||
142 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), | ||
143 | QString::null, 0, this, 0 ); | ||
144 | actionFind = a; | ||
145 | connect( a, SIGNAL(activated()), this, SLOT( slotFindOpen()) ); | ||
146 | a->addTo( edit ); | ||
147 | a->addTo( listTools ); | ||
148 | |||
149 | // Much better search widget, taken from QTReader.. (se) | ||
150 | searchBar = new OFloatBar( "Search", this, QMainWindow::Top, TRUE ); | ||
151 | searchBar->setHorizontalStretchable( TRUE ); | ||
152 | searchBar->hide(); | ||
153 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | ||
154 | |||
155 | // QFont f("unifont", 16 /*, QFont::Bold*/); | ||
156 | // searchEdit->setFont( f ); | ||
157 | |||
158 | searchBar->setStretchableWidget( searchEdit ); | ||
159 | connect( searchEdit, SIGNAL( returnPressed() ), | ||
160 | this, SLOT( slotFind() ) ); | ||
161 | |||
162 | a = new QAction( tr( "Start Search" ), Resource::loadPixmap( "enter" ), QString::null, 0, this, 0 ); | ||
163 | connect( a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); | ||
164 | a->addTo( searchBar ); | ||
165 | |||
166 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | ||
167 | connect( a, SIGNAL( activated() ), this, SLOT( slotFindClose() ) ); | ||
168 | a->addTo( searchBar ); | ||
169 | |||
170 | a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "addressbook/sendmail" ), | ||
171 | QString::null, 0, this, 0 ); | ||
172 | //a->setEnabled( FALSE ); we got support for it now :) zecke | ||
173 | actionMail = a; | ||
174 | connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) ); | ||
175 | a->addTo( edit ); | ||
176 | a->addTo( listTools ); | ||
177 | |||
178 | if ( Ir::supported() ) { | ||
179 | a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null, | ||
180 | 0, this, 0 ); | ||
181 | actionBeam = a; | ||
182 | connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); | ||
183 | a->addTo( edit ); | ||
184 | a->addTo( listTools ); | ||
185 | } | ||
186 | 72 | ||
187 | edit->insertSeparator(); | 73 | m_abView = new AbView( m_listContainer, m_config.orderList() ); |
74 | vb->addWidget( m_abView ); | ||
75 | connect( m_abView, SIGNAL(signalViewSwitched(int)), | ||
76 | this, SLOT(slotViewSwitched(int)) ); | ||
188 | 77 | ||
189 | a = new QAction( tr("Import vCard"), Resource::loadPixmap( "addressbook/fileimport"), QString::null, | 78 | QObject::connect( m_abView, SIGNAL(signalNotFound()), this, SLOT(slotNotFound()) ); |
190 | 0, this, 0); | ||
191 | actionPersonal = a; | ||
192 | connect( a, SIGNAL( activated() ), this, SLOT( importvCard() ) ); | ||
193 | a->addTo( edit ); | ||
194 | 79 | ||
195 | a = new QAction( tr("Export vCard"), Resource::loadPixmap( "addressbook/fileexport"), QString::null, | 80 | // Letter Picker |
196 | 0, this, 0); | 81 | pLabel = new LetterPicker( m_listContainer ); |
197 | actionPersonal = a; | 82 | connect(pLabel, SIGNAL(letterClicked(char)), this, SLOT(slotSetLetter(char))); |
198 | connect( a, SIGNAL( activated() ), this, SLOT( exportvCard() ) ); | 83 | connect(m_abView, SIGNAL(signalClearLetterPicker()), pLabel, SLOT(clear()) ); |
199 | a->addTo( edit ); | ||
200 | 84 | ||
201 | edit->insertSeparator(); | 85 | vb->addWidget( pLabel ); |
202 | 86 | ||
203 | a = new QAction( tr("My Personal Details"), Resource::loadPixmap( "addressbook/identity" ), | 87 | // Quick search bar |
204 | QString::null, 0, this, 0 , TRUE ); | 88 | m_searchBar = new OFloatBar( "Search", this, QMainWindow::Top, true ); |
205 | actionPersonal = a; | 89 | m_searchBar->setHorizontalStretchable( true ); |
206 | connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) ); | 90 | m_searchBar->hide(); |
207 | a->addTo( edit ); | 91 | m_searchEdit = new QLineEdit( m_searchBar, "m_searchEdit" ); |
208 | 92 | ||
93 | m_searchBar->setStretchableWidget( m_searchEdit ); | ||
94 | connect( m_searchEdit, SIGNAL(returnPressed()), this, SLOT(slotFind()) ); | ||
209 | 95 | ||
210 | #ifdef __DEBUG_RELEASE | 96 | QAction *a = new QAction( tr( "Start Search" ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); |
211 | // Remove this function for public Release ! This is only | 97 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); |
212 | // for debug purposes .. | 98 | a->addTo( m_searchBar ); |
213 | a = new QAction( tr( "Save all Data"), QString::null, 0, 0 ); | ||
214 | connect( a, SIGNAL( activated() ), this , SLOT( slotSave() ) ); | ||
215 | a->addTo( edit ); | ||
216 | #endif | ||
217 | a = new QAction( tr( "Config" ), Resource::loadPixmap( "SettingsIcon" ), QString::null, | ||
218 | 0, this, 0 ); | ||
219 | connect( a, SIGNAL( activated() ), this, SLOT( slotConfig() ) ); | ||
220 | a->addTo( edit ); | ||
221 | 99 | ||
222 | // Create Views | 100 | // Insert Contact menu items |
223 | listContainer = new QWidget( this ); | 101 | QActionGroup *items = new QActionGroup( this, QString::null, false ); |
224 | QVBoxLayout *vb = new QVBoxLayout( listContainer ); | ||
225 | 102 | ||
226 | m_abView = new AbView( listContainer, m_config.orderList() ); | 103 | m_actionMail = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "addressbook/sendmail" ), |
227 | vb->addWidget( m_abView ); | 104 | QString::null, 0, items, 0 ); |
228 | // abList->setHScrollBarMode( QScrollView::AlwaysOff ); | 105 | connect( m_actionMail, SIGNAL(activated()), this, SLOT(writeMail()) ); |
229 | connect( m_abView, SIGNAL( signalViewSwitched(int) ), | ||
230 | this, SLOT( slotViewSwitched(int) ) ); | ||
231 | 106 | ||
107 | a = new QAction( tr("Import vCard"), Resource::loadPixmap( "addressbook/fileimport"), | ||
108 | QString::null, 0, items, 0 ); | ||
109 | connect( a, SIGNAL(activated()), this, SLOT(importvCard()) ); | ||
232 | 110 | ||
233 | QObject::connect( m_abView, SIGNAL(signalNotFound()), this, SLOT(slotNotFound()) ); | 111 | a = new QAction( tr("Export vCard"), Resource::loadPixmap( "addressbook/fileexport"), |
112 | QString::null, 0, items, 0 ); | ||
113 | connect( a, SIGNAL(activated()), this, SLOT(exportvCard()) ); | ||
234 | 114 | ||
235 | // m_abView->load(); // Already done by c'tor . | 115 | m_actionPersonal = new QAction( tr("My Personal Details"), Resource::loadPixmap( "addressbook/identity" ), |
116 | QString::null, 0, items, 0 , true ); | ||
117 | connect( m_actionPersonal, SIGNAL(activated()), this, SLOT(slotPersonalView()) ); | ||
236 | 118 | ||
237 | // Letter Picker | 119 | insertItemMenuItems( items ); |
238 | pLabel = new LetterPicker( listContainer ); | ||
239 | connect(pLabel, SIGNAL(letterClicked(char)), this, SLOT(slotSetLetter(char))); | ||
240 | connect(m_abView, SIGNAL( signalClearLetterPicker() ), pLabel, SLOT( clear() ) ); | ||
241 | 120 | ||
242 | vb->addWidget( pLabel ); | 121 | // Insert View menu items |
122 | items = new QActionGroup( this, QString::null, false ); | ||
123 | |||
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)) ); | ||
243 | 126 | ||
244 | // All Categories into view-menu.. | 127 | insertViewMenuItems( items ); |
245 | populateCategories(); | ||
246 | 128 | ||
247 | // Fontsize | 129 | // Fontsize |
248 | defaultFont = new QFont( m_abView->font() ); | 130 | defaultFont = new QFont( m_abView->font() ); |
249 | slotSetFont(m_config.fontSize()); | 131 | slotSetFont(m_config.fontSize()); |
250 | m_curFontSize = m_config.fontSize(); | 132 | m_curFontSize = m_config.fontSize(); |
251 | 133 | ||
252 | setCentralWidget(listContainer); | 134 | setCentralWidget(m_listContainer); |
253 | 135 | ||
254 | //odebug << "adressbook contrsuction: t=" << t.elapsed() << oendl; | 136 | //odebug << "adressbook contrsuction: t=" << t.elapsed() << oendl; |
255 | connect( qApp, SIGNAL( flush() ), this, SLOT( flush() ) ); | 137 | connect( qApp, SIGNAL(flush()), this, SLOT(flush()) ); |
256 | connect( qApp, SIGNAL( reload() ), this, SLOT( reload() ) ); | 138 | connect( qApp, SIGNAL(reload()), this, SLOT(reload()) ); |
257 | connect( qApp, SIGNAL( appMessage(const QCString&,const QByteArray&) ), | 139 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), |
258 | this, SLOT( appMessage(const QCString&,const QByteArray&) ) ); | 140 | this, SLOT(appMessage(const QCString&,const QByteArray&)) ); |
259 | |||
260 | 141 | ||
261 | isLoading = false; | 142 | isLoading = false; |
262 | } | ||
263 | 143 | ||
264 | 144 | // Handle category selection | |
265 | void AddressbookWindow::slotConfig() | 145 | setViewCategory( m_config.category() ); |
266 | { | 146 | m_abView->setShowByCategory( m_config.category() ); |
267 | ConfigDlg* dlg = new ConfigDlg( this, "Config" ); | 147 | connect( this, SIGNAL(categorySelected(const QString&)), |
268 | dlg -> setConfig( m_config ); | 148 | this, SLOT(slotSetCategory(const QString&)) ); |
269 | if ( QPEApplication::execDialog( dlg ) ) { | ||
270 | odebug << "Config Dialog accepted!" << oendl; | ||
271 | m_config = dlg -> getConfig(); | ||
272 | if ( m_curFontSize != m_config.fontSize() ){ | ||
273 | odebug << "Font was changed!" << oendl; | ||
274 | m_curFontSize = m_config.fontSize(); | ||
275 | emit slotSetFont( m_curFontSize ); | ||
276 | } | ||
277 | m_abView -> setListOrder( m_config.orderList() ); | ||
278 | } | ||
279 | |||
280 | delete dlg; | ||
281 | } | 149 | } |
282 | 150 | ||
283 | |||
284 | void AddressbookWindow::slotSetFont( int size ) | 151 | void AddressbookWindow::slotSetFont( int size ) |
285 | { | 152 | { |
286 | odebug << "void AddressbookWindow::slotSetFont( " << size << " )" << oendl; | 153 | odebug << "void AddressbookWindow::slotSetFont( " << size << " )" << oendl; |
287 | 154 | ||
288 | if (size > 2 || size < 0) | 155 | if (size > 2 || size < 0) |
289 | size = 1; | 156 | size = 1; |
290 | 157 | ||
291 | m_config.setFontSize( size ); | 158 | m_config.setFontSize( size ); |
292 | 159 | ||
293 | QFont *currentFont; | 160 | QFont *currentFont; |
294 | 161 | ||
295 | switch (size) { | 162 | switch (size) { |
296 | case 0: | 163 | case 0: |
297 | m_abView->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); | 164 | m_abView->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); |
298 | currentFont = new QFont (m_abView->font()); | 165 | currentFont = new QFont (m_abView->font()); |
299 | // abList->resizeRows(currentFont->pixelSize() + 7); :SX | 166 | // abList->resizeRows(currentFont->pixelSize() + 7); :SX |
300 | // abList->resizeRows(); | 167 | // abList->resizeRows(); |
301 | break; | 168 | break; |
302 | case 1: | 169 | case 1: |
303 | m_abView->setFont( *defaultFont ); | 170 | m_abView->setFont( *defaultFont ); |
304 | currentFont = new QFont (m_abView->font()); | 171 | currentFont = new QFont (m_abView->font()); |
305 | // // abList->resizeRows(currentFont->pixelSize() + 7); | 172 | // // abList->resizeRows(currentFont->pixelSize() + 7); |
306 | // abList->resizeRows(); | 173 | // abList->resizeRows(); |
307 | break; | 174 | break; |
@@ -333,50 +200,50 @@ void AddressbookWindow::exportvCard() | |||
333 | if ( !curCont.isEmpty() ){ | 200 | if ( !curCont.isEmpty() ){ |
334 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | 201 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, |
335 | filename ); | 202 | filename ); |
336 | 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 ); |
337 | if ( access ){ | 204 | if ( access ){ |
338 | access->add( curCont ); | 205 | access->add( curCont ); |
339 | access->save(); | 206 | access->save(); |
340 | } | 207 | } |
341 | delete access; | 208 | delete access; |
342 | }else | 209 | }else |
343 | QMessageBox::critical( 0, "Export VCard", | 210 | QMessageBox::critical( 0, "Export VCard", |
344 | QString( tr( "You have to select a contact !") ) ); | 211 | QString( tr( "You have to select a contact !") ) ); |
345 | 212 | ||
346 | }else | 213 | }else |
347 | QMessageBox::critical( 0, "Export VCard", | 214 | QMessageBox::critical( 0, "Export VCard", |
348 | QString( tr( "You have to set a filename !") ) ); | 215 | QString( tr( "You have to set a filename !") ) ); |
349 | } | 216 | } |
350 | 217 | ||
351 | void AddressbookWindow::setDocument( const QString &filename ) | 218 | void AddressbookWindow::setDocument( const QString &filename ) |
352 | { | 219 | { |
353 | odebug << "void AddressbookWindow::setDocument( " << filename << " )" << oendl; | 220 | odebug << "void AddressbookWindow::setDocument( " << filename << " )" << oendl; |
354 | 221 | ||
355 | // Switch to default backend. This should avoid to import into | 222 | // Switch to default backend. This should avoid to import into |
356 | // the personal database accidently. | 223 | // the personal database accidently. |
357 | if ( actionPersonal->isOn() ){ | 224 | if ( m_actionPersonal->isOn() ){ |
358 | actionPersonal->setOn( false ); | 225 | m_actionPersonal->setOn( false ); |
359 | slotPersonalView(); | 226 | slotPersonalView(); |
360 | } | 227 | } |
361 | 228 | ||
362 | if ( filename.find(".vcf") != int(filename.length()) - 4 ){ | 229 | if ( filename.find(".vcf") != int(filename.length()) - 4 ){ |
363 | 230 | ||
364 | 231 | ||
365 | 232 | ||
366 | switch( QMessageBox::information( this, tr ( "Right file type ?" ), | 233 | switch( QMessageBox::information( this, tr ( "Right file type ?" ), |
367 | 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?" ), |
368 | tr( "&Yes" ), tr( "&No" ), QString::null, | 235 | tr( "&Yes" ), tr( "&No" ), QString::null, |
369 | 0, // Enter == button 0 | 236 | 0, // Enter == button 0 |
370 | 2 ) ) { // Escape == button 2 | 237 | 2 ) ) { // Escape == button 2 |
371 | case 0: | 238 | case 0: |
372 | odebug << "YES clicked" << oendl; | 239 | odebug << "YES clicked" << oendl; |
373 | break; | 240 | break; |
374 | case 1: | 241 | case 1: |
375 | odebug << "NO clicked" << oendl; | 242 | odebug << "NO clicked" << oendl; |
376 | return; | 243 | return; |
377 | break; | 244 | break; |
378 | } | 245 | } |
379 | } | 246 | } |
380 | 247 | ||
381 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | 248 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, |
382 | filename ); | 249 | filename ); |
@@ -417,633 +284,560 @@ void AddressbookWindow::setDocument( const QString &filename ) | |||
417 | m_abView->addEntry( *it ); | 284 | m_abView->addEntry( *it ); |
418 | 285 | ||
419 | } | 286 | } |
420 | 287 | ||
421 | delete access; | 288 | delete access; |
422 | } | 289 | } |
423 | 290 | ||
424 | void AddressbookWindow::resizeEvent( QResizeEvent *e ) | 291 | void AddressbookWindow::resizeEvent( QResizeEvent *e ) |
425 | { | 292 | { |
426 | QMainWindow::resizeEvent( e ); | 293 | QMainWindow::resizeEvent( e ); |
427 | 294 | ||
428 | 295 | ||
429 | } | 296 | } |
430 | 297 | ||
431 | AddressbookWindow::~AddressbookWindow() | 298 | AddressbookWindow::~AddressbookWindow() |
432 | { | 299 | { |
433 | ToolBarDock dock; | 300 | ToolBarDock dock; |
434 | int dummy; | 301 | int dummy; |
435 | bool bDummy; | 302 | bool bDummy; |
436 | getLocation ( listTools, dock, dummy, bDummy, dummy ); | 303 | getLocation ( listTools, dock, dummy, bDummy, dummy ); |
437 | m_config.setToolBarDock( dock ); | 304 | m_config.setToolBarDock( dock ); |
438 | m_config.save(); | 305 | m_config.save(); |
439 | } | 306 | } |
440 | 307 | ||
441 | void AddressbookWindow::slotUpdateToolbar() | 308 | int AddressbookWindow::create() |
309 | { | ||
310 | return 0; | ||
311 | } | ||
312 | |||
313 | bool AddressbookWindow::remove( int /*uid*/ ) | ||
314 | { | ||
315 | return false; | ||
316 | } | ||
317 | |||
318 | void AddressbookWindow::beam( int /*uid*/ ) | ||
319 | { | ||
320 | } | ||
321 | |||
322 | void AddressbookWindow::show( int /*uid*/ ) | ||
323 | { | ||
324 | } | ||
325 | |||
326 | void AddressbookWindow::edit( int /*uid*/ ) | ||
442 | { | 327 | { |
443 | Opie::OPimContact ce = m_abView->currentEntry(); | ||
444 | actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); | ||
445 | } | 328 | } |
446 | 329 | ||
447 | void AddressbookWindow::slotListNew() | 330 | void AddressbookWindow::add( const Opie::OPimRecord& ) |
331 | { | ||
332 | } | ||
333 | |||
334 | void AddressbookWindow::slotItemNew() | ||
448 | { | 335 | { |
449 | Opie::OPimContact cnt; | 336 | Opie::OPimContact cnt; |
450 | if( !syncing ) { | 337 | if( !syncing ) { |
451 | editEntry( NewEntry ); | 338 | editEntry( NewEntry ); |
452 | } else { | 339 | } else { |
453 | QMessageBox::warning(this, tr("Contacts"), | 340 | QMessageBox::warning(this, tr("Contacts"), |
454 | tr("Can not edit data, currently syncing")); | 341 | tr("Can not edit data, currently syncing")); |
455 | } | 342 | } |
456 | } | 343 | } |
457 | 344 | ||
458 | // void AddressbookWindow::slotListView() | 345 | void AddressbookWindow::slotItemEdit() |
459 | // { | 346 | { |
460 | // m_abView -> init( abList->currentEntry() ); | 347 | if(!syncing) { |
461 | // // :SX mView->sync(); | 348 | if (m_actionPersonal->isOn()) { |
462 | // //:SXshowView(); | 349 | editPersonal(); |
463 | // } | 350 | } else { |
351 | editEntry( EditEntry ); | ||
352 | } | ||
353 | } else { | ||
354 | QMessageBox::warning( this, tr("Contacts"), | ||
355 | tr("Can not edit data, currently syncing") ); | ||
356 | } | ||
357 | } | ||
358 | |||
359 | void AddressbookWindow::slotItemDuplicate() | ||
360 | { | ||
361 | } | ||
464 | 362 | ||
465 | void AddressbookWindow::slotListDelete() | 363 | void AddressbookWindow::slotItemDelete() |
466 | { | 364 | { |
467 | if(!syncing) { | 365 | if(!syncing) { |
468 | Opie::OPimContact tmpEntry = m_abView ->currentEntry(); | 366 | Opie::OPimContact tmpEntry = m_abView ->currentEntry(); |
469 | 367 | ||
470 | // get a name, do the best we can... | 368 | // get a name, do the best we can... |
471 | QString strName = tmpEntry.fullName(); | 369 | QString strName = tmpEntry.fullName(); |
472 | if ( strName.isEmpty() ) { | 370 | if ( strName.isEmpty() ) { |
473 | strName = tmpEntry.company(); | 371 | strName = tmpEntry.company(); |
474 | if ( strName.isEmpty() ) | 372 | if ( strName.isEmpty() ) |
475 | strName = "No Name"; | 373 | strName = "No Name"; |
476 | } | 374 | } |
477 | 375 | ||
478 | 376 | ||
479 | if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), | 377 | if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), |
480 | strName ) ) { | 378 | strName ) ) { |
481 | m_abView->removeEntry( tmpEntry.uid() ); | 379 | m_abView->removeEntry( tmpEntry.uid() ); |
482 | } | 380 | } |
483 | } else { | 381 | } else { |
484 | QMessageBox::warning( this, tr("Contacts"), | 382 | QMessageBox::warning( this, tr("Contacts"), |
485 | tr("Can not edit data, currently syncing") ); | 383 | tr("Can not edit data, currently syncing") ); |
486 | } | 384 | } |
487 | } | 385 | } |
488 | 386 | ||
489 | void AddressbookWindow::slotFindOpen() | 387 | static const char * beamfile = "/tmp/obex/contact.vcf"; |
388 | |||
389 | void AddressbookWindow::slotItemBeam() | ||
490 | { | 390 | { |
491 | searchBar->show(); | 391 | QString beamFilename; |
492 | m_abView -> inSearch(); | 392 | Opie::OPimContact c; |
493 | searchEdit->setFocus(); | 393 | if ( m_actionPersonal->isOn() ) { |
394 | beamFilename = addressbookPersonalVCardName(); | ||
395 | if ( !QFile::exists( beamFilename ) ) | ||
396 | return; // can't beam a non-existent file | ||
397 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | ||
398 | beamFilename ); | ||
399 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); | ||
400 | Opie::OPimContactAccess::List allList = access->allRecords(); | ||
401 | Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first | ||
402 | c = *it; | ||
403 | |||
404 | delete access; | ||
405 | } else { | ||
406 | unlink( beamfile ); // delete if exists | ||
407 | mkdir("/tmp/obex/", 0755); | ||
408 | c = m_abView -> currentEntry(); | ||
409 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | ||
410 | beamfile ); | ||
411 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); | ||
412 | access->add( c ); | ||
413 | access->save(); | ||
414 | delete access; | ||
415 | |||
416 | beamFilename = beamfile; | ||
417 | } | ||
418 | |||
419 | odebug << "Beaming: " << beamFilename << oendl; | ||
420 | |||
421 | Ir *ir = new Ir( this ); | ||
422 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); | ||
423 | QString description = c.fullName(); | ||
424 | ir->send( beamFilename, description, "text/x-vCard" ); | ||
494 | } | 425 | } |
495 | void AddressbookWindow::slotFindClose() | 426 | |
427 | void AddressbookWindow::slotItemFind() | ||
496 | { | 428 | { |
497 | searchBar->hide(); | ||
498 | m_abView -> offSearch(); | ||
499 | // m_abView->setFocus(); | ||
500 | } | 429 | } |
501 | 430 | ||
431 | void AddressbookWindow::slotConfigure() | ||
432 | { | ||
433 | ConfigDlg* dlg = new ConfigDlg( this, "Config" ); | ||
434 | dlg -> setConfig( m_config ); | ||
435 | if ( QPEApplication::execDialog( dlg ) ) { | ||
436 | odebug << "Config Dialog accepted!" << oendl; | ||
437 | m_config = dlg -> getConfig(); | ||
438 | if ( m_curFontSize != m_config.fontSize() ){ | ||
439 | odebug << "Font was changed!" << oendl; | ||
440 | m_curFontSize = m_config.fontSize(); | ||
441 | emit slotSetFont( m_curFontSize ); | ||
442 | } | ||
443 | m_abView -> setListOrder( m_config.orderList() ); | ||
444 | } | ||
445 | |||
446 | delete dlg; | ||
447 | } | ||
448 | |||
449 | void AddressbookWindow::slotShowFind( bool show ) | ||
450 | { | ||
451 | if ( show ) | ||
452 | { | ||
453 | // Display search bar | ||
454 | m_searchBar->show(); | ||
455 | m_abView -> inSearch(); | ||
456 | m_searchEdit->setFocus(); | ||
457 | } | ||
458 | else | ||
459 | { | ||
460 | // Hide search bar | ||
461 | m_searchBar->hide(); | ||
462 | m_abView -> offSearch(); | ||
463 | } | ||
464 | } | ||
502 | 465 | ||
503 | void AddressbookWindow::slotFind() | 466 | void AddressbookWindow::slotFind() |
504 | { | 467 | { |
505 | m_abView->slotDoFind( searchEdit->text(), m_config.beCaseSensitive(), m_config.useRegExp(), false); | 468 | m_abView->slotDoFind( m_searchEdit->text(), m_config.beCaseSensitive(), m_config.useRegExp(), false); |
506 | 469 | ||
507 | searchEdit->clearFocus(); | 470 | m_searchEdit->clearFocus(); |
508 | // m_abView->setFocus(); | 471 | // m_abView->setFocus(); |
509 | 472 | ||
510 | } | 473 | } |
511 | 474 | ||
512 | void AddressbookWindow::slotViewBack() | 475 | void AddressbookWindow::slotViewBack() |
513 | { | 476 | { |
514 | // :SX showList(); | 477 | // :SX showList(); |
515 | } | 478 | } |
516 | 479 | ||
517 | void AddressbookWindow::slotViewEdit() | ||
518 | { | ||
519 | if(!syncing) { | ||
520 | if (actionPersonal->isOn()) { | ||
521 | editPersonal(); | ||
522 | } else { | ||
523 | editEntry( EditEntry ); | ||
524 | } | ||
525 | } else { | ||
526 | QMessageBox::warning( this, tr("Contacts"), | ||
527 | tr("Can not edit data, currently syncing") ); | ||
528 | } | ||
529 | } | ||
530 | |||
531 | |||
532 | |||
533 | void AddressbookWindow::writeMail() | 480 | void AddressbookWindow::writeMail() |
534 | { | 481 | { |
535 | Opie::OPimContact c = m_abView -> currentEntry(); | 482 | Opie::OPimContact c = m_abView -> currentEntry(); |
536 | QString name = c.fileAs(); | 483 | QString name = c.fileAs(); |
537 | QString email = c.defaultEmail(); | 484 | QString email = c.defaultEmail(); |
538 | 485 | ||
539 | // I prefer the OPIE-Environment variable before the | 486 | // I prefer the OPIE-Environment variable before the |
540 | // QPE-one.. | 487 | // QPE-one.. |
541 | QString basepath = QString::fromLatin1( getenv("OPIEDIR") ); | 488 | QString basepath = QString::fromLatin1( getenv("OPIEDIR") ); |
542 | if ( basepath.isEmpty() ) | 489 | if ( basepath.isEmpty() ) |
543 | basepath = QString::fromLatin1( getenv("QPEDIR") ); | 490 | basepath = QString::fromLatin1( getenv("QPEDIR") ); |
544 | 491 | ||
545 | // Try to access the preferred. If not possible, try to | 492 | // Try to access the preferred. If not possible, try to |
546 | // switch to the other one.. | 493 | // switch to the other one.. |
547 | if ( m_config.useQtMail() ){ | 494 | if ( m_config.useQtMail() ){ |
548 | odebug << "Accessing: " << (basepath + "/bin/qtmail") << oendl; | 495 | odebug << "Accessing: " << (basepath + "/bin/qtmail") << oendl; |
549 | if ( QFile::exists( basepath + "/bin/qtmail" ) ){ | 496 | if ( QFile::exists( basepath + "/bin/qtmail" ) ){ |
550 | odebug << "QCop" << oendl; | 497 | odebug << "QCop" << oendl; |
551 | QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); | 498 | QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); |
552 | e << name << email; | 499 | e << name << email; |
553 | return; | 500 | return; |
554 | } else | 501 | } else |
555 | m_config.setUseOpieMail( true ); | 502 | m_config.setUseOpieMail( true ); |
556 | } | 503 | } |
557 | if ( m_config.useOpieMail() ){ | 504 | if ( m_config.useOpieMail() ){ |
558 | odebug << "Accessing: " << (basepath + "/bin/opiemail") << oendl; | 505 | odebug << "Accessing: " << (basepath + "/bin/opiemail") << oendl; |
559 | if ( QFile::exists( basepath + "/bin/opiemail" ) ){ | 506 | if ( QFile::exists( basepath + "/bin/opiemail" ) ){ |
560 | odebug << "QCop" << oendl; | 507 | odebug << "QCop" << oendl; |
561 | QCopEnvelope e("QPE/Application/opiemail", "writeMail(QString,QString)"); | 508 | QCopEnvelope e("QPE/Application/opiemail", "writeMail(QString,QString)"); |
562 | e << name << email; | 509 | e << name << email; |
563 | return; | 510 | return; |
564 | } else | 511 | } else |
565 | m_config.setUseQtMail( true ); | 512 | m_config.setUseQtMail( true ); |
566 | } | 513 | } |
567 | 514 | ||
568 | } | 515 | } |
569 | 516 | ||
570 | static const char * beamfile = "/tmp/obex/contact.vcf"; | ||
571 | |||
572 | void AddressbookWindow::slotBeam() | ||
573 | { | ||
574 | QString beamFilename; | ||
575 | Opie::OPimContact c; | ||
576 | if ( actionPersonal->isOn() ) { | ||
577 | beamFilename = addressbookPersonalVCardName(); | ||
578 | if ( !QFile::exists( beamFilename ) ) | ||
579 | return; // can't beam a non-existent file | ||
580 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | ||
581 | beamFilename ); | ||
582 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); | ||
583 | Opie::OPimContactAccess::List allList = access->allRecords(); | ||
584 | Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first | ||
585 | c = *it; | ||
586 | |||
587 | delete access; | ||
588 | } else { | ||
589 | unlink( beamfile ); // delete if exists | ||
590 | mkdir("/tmp/obex/", 0755); | ||
591 | c = m_abView -> currentEntry(); | ||
592 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | ||
593 | beamfile ); | ||
594 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); | ||
595 | access->add( c ); | ||
596 | access->save(); | ||
597 | delete access; | ||
598 | |||
599 | beamFilename = beamfile; | ||
600 | } | ||
601 | |||
602 | odebug << "Beaming: " << beamFilename << oendl; | ||
603 | |||
604 | Ir *ir = new Ir( this ); | ||
605 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); | ||
606 | QString description = c.fullName(); | ||
607 | ir->send( beamFilename, description, "text/x-vCard" ); | ||
608 | } | ||
609 | |||
610 | void AddressbookWindow::beamDone( Ir *ir ) | 517 | void AddressbookWindow::beamDone( Ir *ir ) |
611 | { | 518 | { |
612 | 519 | ||
613 | delete ir; | 520 | delete ir; |
614 | unlink( beamfile ); | 521 | unlink( beamfile ); |
615 | } | 522 | } |
616 | 523 | ||
617 | 524 | ||
618 | static void parseName( const QString& name, QString *first, QString *middle, | 525 | static void parseName( const QString& name, QString *first, QString *middle, |
619 | QString * last ) | 526 | QString * last ) |
620 | { | 527 | { |
621 | 528 | ||
622 | int comma = name.find ( "," ); | 529 | int comma = name.find ( "," ); |
623 | QString rest; | 530 | QString rest; |
624 | if ( comma > 0 ) { | 531 | if ( comma > 0 ) { |
625 | *last = name.left( comma ); | 532 | *last = name.left( comma ); |
626 | comma++; | 533 | comma++; |
627 | while ( comma < int(name.length()) && name[comma] == ' ' ) | 534 | while ( comma < int(name.length()) && name[comma] == ' ' ) |
628 | comma++; | 535 | comma++; |
629 | rest = name.mid( comma ); | 536 | rest = name.mid( comma ); |
630 | } else { | 537 | } else { |
631 | int space = name.findRev( ' ' ); | 538 | int space = name.findRev( ' ' ); |
632 | *last = name.mid( space+1 ); | 539 | *last = name.mid( space+1 ); |
633 | rest = name.left( space ); | 540 | rest = name.left( space ); |
634 | } | 541 | } |
635 | int space = rest.find( ' ' ); | 542 | int space = rest.find( ' ' ); |
636 | if ( space <= 0 ) { | 543 | if ( space <= 0 ) { |
637 | *first = rest; | 544 | *first = rest; |
638 | } else { | 545 | } else { |
639 | *first = rest.left( space ); | 546 | *first = rest.left( space ); |
640 | *middle = rest.mid( space+1 ); | 547 | *middle = rest.mid( space+1 ); |
641 | } | 548 | } |
642 | 549 | ||
643 | } | 550 | } |
644 | 551 | ||
645 | 552 | ||
646 | void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) | 553 | void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) |
647 | { | 554 | { |
648 | bool needShow = FALSE; | 555 | bool needShow = false; |
649 | odebug << "Receiving QCop-Call with message " << msg << oendl; | 556 | odebug << "Receiving QCop-Call with message " << msg << oendl; |
650 | 557 | ||
651 | 558 | ||
652 | if (msg == "editPersonal()") { | 559 | if (msg == "editPersonal()") { |
653 | editPersonal(); | 560 | editPersonal(); |
561 | |||
562 | // Categories might have changed, so reload | ||
563 | reloadCategories(); | ||
654 | } else if (msg == "editPersonalAndClose()") { | 564 | } else if (msg == "editPersonalAndClose()") { |
655 | editPersonal(); | 565 | editPersonal(); |
656 | close(); | 566 | close(); |
657 | } else if ( msg == "addContact(QString,QString)" ) { | 567 | } else if ( msg == "addContact(QString,QString)" ) { |
658 | QDataStream stream(data,IO_ReadOnly); | 568 | QDataStream stream(data,IO_ReadOnly); |
659 | QString name, email; | 569 | QString name, email; |
660 | stream >> name >> email; | 570 | stream >> name >> email; |
661 | 571 | ||
662 | Opie::OPimContact cnt; | 572 | Opie::OPimContact cnt; |
663 | QString fn, mn, ln; | 573 | QString fn, mn, ln; |
664 | parseName( name, &fn, &mn, &ln ); | 574 | parseName( name, &fn, &mn, &ln ); |
665 | //odebug << " " << fn << " - " << mn " - " << ln << oendl; | 575 | //odebug << " " << fn << " - " << mn " - " << ln << oendl; |
666 | cnt.setFirstName( fn ); | 576 | cnt.setFirstName( fn ); |
667 | cnt.setMiddleName( mn ); | 577 | cnt.setMiddleName( mn ); |
668 | cnt.setLastName( ln ); | 578 | cnt.setLastName( ln ); |
669 | cnt.insertEmails( email ); | 579 | cnt.insertEmails( email ); |
670 | cnt.setDefaultEmail( email ); | 580 | cnt.setDefaultEmail( email ); |
671 | cnt.setFileAs(); | 581 | cnt.setFileAs(); |
672 | 582 | ||
673 | m_abView -> addEntry( cnt ); | 583 | m_abView -> addEntry( cnt ); |
674 | 584 | ||
675 | // :SXm_abView()->init( cnt ); | 585 | // :SXm_abView()->init( cnt ); |
676 | editEntry( EditEntry ); | 586 | editEntry( EditEntry ); |
587 | |||
588 | // Categories might have changed, so reload | ||
589 | reloadCategories(); | ||
677 | } else if ( msg == "beamBusinessCard()" ) { | 590 | } else if ( msg == "beamBusinessCard()" ) { |
678 | QString beamFilename = addressbookPersonalVCardName(); | 591 | QString beamFilename = addressbookPersonalVCardName(); |
679 | if ( !QFile::exists( beamFilename ) ) | 592 | if ( !QFile::exists( beamFilename ) ) |
680 | return; // can't beam a non-existent file | 593 | return; // can't beam a non-existent file |
681 | 594 | ||
682 | Ir *ir = new Ir( this ); | 595 | Ir *ir = new Ir( this ); |
683 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); | 596 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); |
684 | QString description = "mycard.vcf"; | 597 | QString description = "mycard.vcf"; |
685 | ir->send( beamFilename, description, "text/x-vCard" ); | 598 | ir->send( beamFilename, description, "text/x-vCard" ); |
686 | } else if ( msg == "show(int)" ) { | 599 | } else if ( msg == "show(int)" ) { |
687 | raise(); | 600 | raise(); |
688 | QDataStream stream(data,IO_ReadOnly); | 601 | QDataStream stream(data,IO_ReadOnly); |
689 | int uid; | 602 | int uid; |
690 | stream >> uid; | 603 | stream >> uid; |
691 | 604 | ||
692 | odebug << "Showing uid: " << uid << oendl; | 605 | odebug << "Showing uid: " << uid << oendl; |
693 | 606 | ||
694 | // Deactivate Personal View.. | 607 | // Deactivate Personal View.. |
695 | if ( actionPersonal->isOn() ){ | 608 | if ( m_actionPersonal->isOn() ){ |
696 | actionPersonal->setOn( false ); | 609 | m_actionPersonal->setOn( false ); |
697 | slotPersonalView(); | 610 | slotPersonalView(); |
698 | } | 611 | } |
699 | 612 | ||
700 | // Reset category and show as card.. | 613 | // Reset category and show as card.. |
701 | m_abView -> setShowByCategory( QString::null ); | 614 | m_abView -> setShowByCategory( QString::null ); |
702 | m_abView -> setCurrentUid( uid ); | 615 | m_abView -> setCurrentUid( uid ); |
703 | slotViewSwitched ( AbView::CardView ); | 616 | slotViewSwitched ( AbView::CardView ); |
704 | 617 | ||
705 | needShow = true; | 618 | needShow = true; |
706 | 619 | ||
707 | 620 | ||
708 | } else if ( msg == "edit(int)" ) { | 621 | } else if ( msg == "edit(int)" ) { |
709 | QDataStream stream(data,IO_ReadOnly); | 622 | QDataStream stream(data,IO_ReadOnly); |
710 | int uid; | 623 | int uid; |
711 | stream >> uid; | 624 | stream >> uid; |
712 | 625 | ||
713 | // Deactivate Personal View.. | 626 | // Deactivate Personal View.. |
714 | if ( actionPersonal->isOn() ){ | 627 | if ( m_actionPersonal->isOn() ){ |
715 | actionPersonal->setOn( false ); | 628 | m_actionPersonal->setOn( false ); |
716 | slotPersonalView(); | 629 | slotPersonalView(); |
717 | } | 630 | } |
718 | 631 | ||
719 | // Reset category and edit.. | 632 | // Reset category and edit.. |
720 | m_abView -> setShowByCategory( QString::null ); | 633 | m_abView -> setShowByCategory( QString::null ); |
721 | m_abView -> setCurrentUid( uid ); | 634 | m_abView -> setCurrentUid( uid ); |
722 | slotViewEdit(); | 635 | slotItemEdit(); |
723 | } | 636 | |
637 | // Categories might have changed, so reload | ||
638 | reloadCategories(); | ||
639 | } | ||
724 | 640 | ||
725 | if (needShow) | 641 | if (needShow) |
726 | QPEApplication::setKeepRunning(); | 642 | QPEApplication::setKeepRunning(); |
727 | |||
728 | } | 643 | } |
729 | 644 | ||
730 | void AddressbookWindow::editEntry( EntryMode entryMode ) | 645 | void AddressbookWindow::editEntry( EntryMode entryMode ) |
731 | { | 646 | { |
732 | Opie::OPimContact entry; | 647 | Opie::OPimContact entry; |
733 | if ( !abEditor ) { | 648 | if ( !abEditor ) { |
734 | abEditor = new ContactEditor( entry, this, "editor" ); | 649 | abEditor = new ContactEditor( entry, this, "editor" ); |
735 | } | 650 | } |
736 | if ( entryMode == EditEntry ) | 651 | if ( entryMode == EditEntry ) |
737 | abEditor->setEntry( m_abView -> currentEntry() ); | 652 | abEditor->setEntry( m_abView -> currentEntry() ); |
738 | else if ( entryMode == NewEntry ) | 653 | else if ( entryMode == NewEntry ) |
739 | abEditor->setEntry( entry ); | 654 | abEditor->setEntry( entry ); |
740 | // other things may change the caption. | 655 | // other things may change the caption. |
741 | abEditor->setCaption( tr("Edit Address") ); | 656 | abEditor->setCaption( tr("Edit Address") ); |
742 | 657 | ||
743 | // fix the foxus... | 658 | // fix the focus... |
744 | abEditor->setNameFocus(); | 659 | abEditor->setNameFocus(); |
745 | if ( QPEApplication::execDialog( abEditor ) ) { | 660 | if ( QPEApplication::execDialog( abEditor ) == QDialog::Accepted ) { |
746 | setFocus(); | 661 | setFocus(); |
747 | if ( entryMode == NewEntry ) { | 662 | if ( entryMode == NewEntry ) { |
748 | Opie::OPimContact insertEntry = abEditor->entry(); | 663 | Opie::OPimContact insertEntry = abEditor->entry(); |
749 | insertEntry.assignUid(); | 664 | insertEntry.assignUid(); |
750 | m_abView -> addEntry( insertEntry ); | 665 | m_abView -> addEntry( insertEntry ); |
751 | m_abView -> setCurrentUid( insertEntry.uid() ); | 666 | m_abView -> setCurrentUid( insertEntry.uid() ); |
752 | } else { | 667 | } else { |
753 | Opie::OPimContact replEntry = abEditor->entry(); | 668 | Opie::OPimContact replEntry = abEditor->entry(); |
754 | 669 | ||
755 | if ( !replEntry.isValidUid() ) | 670 | if ( !replEntry.isValidUid() ) |
756 | replEntry.assignUid(); | 671 | replEntry.assignUid(); |
757 | 672 | ||
758 | m_abView -> replaceEntry( replEntry ); | 673 | m_abView -> replaceEntry( replEntry ); |
759 | } | 674 | } |
760 | } | ||
761 | // populateCategories(); | ||
762 | 675 | ||
676 | // Categories might have changed, so reload | ||
677 | reloadCategories(); | ||
678 | } | ||
763 | } | 679 | } |
764 | 680 | ||
765 | void AddressbookWindow::editPersonal() | 681 | void AddressbookWindow::editPersonal() |
766 | { | 682 | { |
767 | Opie::OPimContact entry; | 683 | Opie::OPimContact entry; |
768 | 684 | ||
769 | // Switch to personal view if not selected | 685 | // Switch to personal view if not selected |
770 | // but take care of the menu, too | 686 | // but take care of the menu, too |
771 | if ( ! actionPersonal->isOn() ){ | 687 | if ( ! m_actionPersonal->isOn() ){ |
772 | odebug << "*** ++++" << oendl; | 688 | odebug << "*** ++++" << oendl; |
773 | actionPersonal->setOn( true ); | 689 | m_actionPersonal->setOn( true ); |
774 | slotPersonalView(); | 690 | slotPersonalView(); |
775 | } | 691 | } |
776 | 692 | ||
777 | if ( !abEditor ) { | 693 | if ( !abEditor ) { |
778 | abEditor = new ContactEditor( entry, this, "editor" ); | 694 | abEditor = new ContactEditor( entry, this, "editor" ); |
779 | } | 695 | } |
780 | 696 | ||
781 | abEditor->setCaption(tr("Edit My Personal Details")); | 697 | abEditor->setCaption(tr("Edit My Personal Details")); |
782 | abEditor->setPersonalView( true ); | 698 | abEditor->setPersonalView( true ); |
783 | editEntry( EditEntry ); | 699 | editEntry( EditEntry ); |
784 | abEditor->setPersonalView( false ); | 700 | abEditor->setPersonalView( false ); |
785 | 701 | ||
786 | } | 702 | } |
787 | 703 | ||
788 | 704 | ||
789 | void AddressbookWindow::slotPersonalView() | 705 | void AddressbookWindow::slotPersonalView() |
790 | { | 706 | { |
791 | odebug << "slotPersonalView()" << oendl; | 707 | odebug << "slotPersonalView()" << oendl; |
792 | if (!actionPersonal->isOn()) { | ||
793 | // we just turned it off | ||
794 | odebug << "slotPersonalView()-> OFF" << oendl; | ||
795 | setCaption( tr("Contacts") ); | ||
796 | actionNew->setEnabled(TRUE); | ||
797 | actionTrash->setEnabled(TRUE); | ||
798 | actionFind->setEnabled(TRUE); | ||
799 | actionMail->setEnabled(TRUE); | ||
800 | // slotUpdateToolbar(); | ||
801 | |||
802 | m_abView->showPersonal( false ); | ||
803 | 708 | ||
804 | return; | 709 | bool personal = m_actionPersonal->isOn(); |
805 | } | ||
806 | |||
807 | odebug << "slotPersonalView()-> ON" << oendl; | ||
808 | // XXX need to disable some QActions. | ||
809 | actionNew->setEnabled(FALSE); | ||
810 | actionTrash->setEnabled(FALSE); | ||
811 | actionFind->setEnabled(FALSE); | ||
812 | actionMail->setEnabled(FALSE); | ||
813 | 710 | ||
814 | setCaption( tr("Contacts - My Personal Details") ); | 711 | // Disable certain menu items when showing personal details |
712 | setItemNewEnabled( !personal ); | ||
713 | setItemDuplicateEnabled( !personal ); | ||
714 | setItemDeleteEnabled( !personal ); | ||
715 | m_actionMail->setEnabled( !personal ); | ||
815 | 716 | ||
816 | m_abView->showPersonal( true ); | 717 | // Display appropriate view |
718 | m_abView->showPersonal( personal ); | ||
817 | 719 | ||
818 | } | 720 | // Set application caption |
819 | 721 | personal ? setCaption( tr( "Contacts - My Personal Details") ) | |
820 | 722 | : setCaption( tr( "Contacts") ); | |
821 | void AddressbookWindow::listIsEmpty( bool empty ) | ||
822 | { | ||
823 | if ( !empty ) { | ||
824 | deleteButton->setEnabled( TRUE ); | ||
825 | } | ||
826 | } | 723 | } |
827 | 724 | ||
828 | void AddressbookWindow::reload() | 725 | void AddressbookWindow::reload() |
829 | { | 726 | { |
830 | syncing = FALSE; | 727 | syncing = false; |
831 | m_abView->clear(); | 728 | m_abView->clear(); |
832 | m_abView->reload(); | 729 | m_abView->reload(); |
833 | } | 730 | } |
834 | 731 | ||
835 | void AddressbookWindow::flush() | 732 | void AddressbookWindow::flush() |
836 | { | 733 | { |
837 | syncing = TRUE; | 734 | syncing = true; |
838 | m_abView->save(); | 735 | m_abView->save(); |
839 | } | 736 | } |
840 | 737 | ||
841 | 738 | ||
842 | void AddressbookWindow::closeEvent( QCloseEvent *e ) | 739 | void AddressbookWindow::closeEvent( QCloseEvent *e ) |
843 | { | 740 | { |
844 | if(active_view == AbView::CardView){ | 741 | if(active_view == AbView::CardView){ |
845 | slotViewSwitched( AbView::TableView ); | 742 | slotViewSwitched( AbView::TableView ); |
846 | e->ignore(); | 743 | e->ignore(); |
847 | return; | 744 | return; |
848 | } | 745 | } |
849 | if(syncing) { | 746 | if(syncing) { |
850 | /* shouldn't we save, I hear you say? well its already been set | 747 | /* shouldn't we save, I hear you say? well its already been set |
851 | so that an edit can not occur during a sync, and we flushed | 748 | so that an edit can not occur during a sync, and we flushed |
852 | at the start of the sync, so there is no need to save | 749 | at the start of the sync, so there is no need to save |
853 | Saving however itself would cause problems. */ | 750 | Saving however itself would cause problems. */ |
854 | e->accept(); | 751 | e->accept(); |
855 | return; | 752 | return; |
856 | } | 753 | } |
857 | //################## shouldn't always save | 754 | //################## shouldn't always save |
858 | // True, but the database handles this automatically ! (se) | 755 | // True, but the database handles this automatically ! (se) |
859 | if ( save() ) | 756 | if ( save() ) |
860 | e->accept(); | 757 | e->accept(); |
861 | else | 758 | else |
862 | e->ignore(); | 759 | e->ignore(); |
863 | } | 760 | } |
864 | 761 | ||
865 | /* | 762 | /* |
866 | Returns TRUE if it is OK to exit | 763 | Returns true if it is OK to exit |
867 | */ | 764 | */ |
868 | 765 | ||
869 | bool AddressbookWindow::save() | 766 | bool AddressbookWindow::save() |
870 | { | 767 | { |
871 | if ( !m_abView->save() ) { | 768 | if ( !m_abView->save() ) { |
872 | if ( QMessageBox::critical( 0, tr( "Out of space" ), | 769 | if ( QMessageBox::critical( 0, tr( "Out of space" ), |
873 | tr("Unable to save information.\n" | 770 | tr("Unable to save information.\n" |
874 | "Free up some space\n" | 771 | "Free up some space\n" |
875 | "and try again.\n" | 772 | "and try again.\n" |
876 | "\nQuit anyway?"), | 773 | "\nQuit anyway?"), |
877 | QMessageBox::Yes|QMessageBox::Escape, | 774 | QMessageBox::Yes|QMessageBox::Escape, |
878 | QMessageBox::No|QMessageBox::Default ) | 775 | QMessageBox::No|QMessageBox::Default ) |
879 | != QMessageBox::No ) | 776 | != QMessageBox::No ) |
880 | return TRUE; | 777 | return true; |
881 | else | 778 | else |
882 | return FALSE; | 779 | return false; |
883 | } | 780 | } |
884 | return TRUE; | 781 | return true; |
885 | } | 782 | } |
886 | 783 | ||
887 | #ifdef __DEBUG_RELEASE | 784 | #ifdef __DEBUG_RELEASE |
888 | void AddressbookWindow::slotSave() | 785 | void AddressbookWindow::slotSave() |
889 | { | 786 | { |
890 | save(); | 787 | save(); |
891 | } | 788 | } |
892 | #endif | 789 | #endif |
893 | 790 | ||
894 | 791 | ||
895 | void AddressbookWindow::slotNotFound() | 792 | void AddressbookWindow::slotNotFound() |
896 | { | 793 | { |
897 | odebug << "Got not found signal!" << oendl; | 794 | odebug << "Got not found signal!" << oendl; |
898 | QMessageBox::information( this, tr( "Not Found" ), | 795 | QMessageBox::information( this, tr( "Not Found" ), |
899 | "<qt>" + tr( "Unable to find a contact for this search pattern!" ) + "</qt>" ); | 796 | "<qt>" + tr( "Unable to find a contact for this search pattern!" ) + "</qt>" ); |
900 | 797 | ||
901 | 798 | ||
902 | } | 799 | } |
903 | void AddressbookWindow::slotWrapAround() | 800 | void AddressbookWindow::slotWrapAround() |
904 | { | 801 | { |
905 | odebug << "Got wrap signal!" << oendl; | 802 | odebug << "Got wrap signal!" << oendl; |
906 | // if ( doNotifyWrapAround ) | 803 | // if ( doNotifyWrapAround ) |
907 | // QMessageBox::information( this, tr( "End of list" ), | 804 | // QMessageBox::information( this, tr( "End of list" ), |
908 | // tr( "End of list. Wrap around now...!" ) + "\n" ); | 805 | // tr( "End of list. Wrap around now...!" ) + "\n" ); |
909 | 806 | ||
910 | } | 807 | } |
911 | 808 | ||
912 | void AddressbookWindow::slotSetCategory( int c ) | 809 | void AddressbookWindow::slotSetCategory( const QString &category ) |
913 | { | 810 | { |
914 | odebug << "void AddressbookWindow::slotSetCategory( " << c << " ) from " | 811 | odebug << "void AddressbookWindow::slotSetCategory( " << category << " )" << oendl; |
915 | << catMenu->count() << oendl; | ||
916 | |||
917 | QString cat, book; | ||
918 | AbView::Views view = AbView::TableView; | ||
919 | |||
920 | if ( c <= 0 ) | ||
921 | return; | ||
922 | |||
923 | // Switch view | ||
924 | if ( c < 3 ) | ||
925 | for ( unsigned int i = 1; i < 3; i++ ){ | ||
926 | if ( catMenu ) | ||
927 | catMenu->setItemChecked( i, c == (int)i ); | ||
928 | } | ||
929 | else | ||
930 | // Checkmark Category Menu Item Selected | ||
931 | for ( unsigned int i = 3; i < catMenu->count(); i++ ) | ||
932 | catMenu->setItemChecked( i, c == (int)i ); | ||
933 | |||
934 | // Now switch to the selected category | ||
935 | for ( unsigned int i = 1; i < catMenu->count(); i++ ) { | ||
936 | if (catMenu->isItemChecked( i )) { | ||
937 | if ( i == 1 ){ // default List view | ||
938 | book = QString::null; | ||
939 | view = AbView::TableView; | ||
940 | }else if ( i == 2 ){ | ||
941 | book = tr( "Cards" ); | ||
942 | view = AbView::CardView; | ||
943 | // }else if ( i == 3 ){ | ||
944 | // book = tr( "Personal" ); | ||
945 | // view = AbView:: PersonalView; | ||
946 | }else if ( i == 3 ){ // default All Categories | ||
947 | cat = QString::null; | ||
948 | }else if ( i == (unsigned int)catMenu->count() - 1 ){ // last menu option (seperator is counted, too) will be Unfiled | ||
949 | cat = "Unfiled"; | ||
950 | odebug << "Unfiled selected!" << oendl; | ||
951 | }else{ | ||
952 | cat = m_abView->categories()[i - 4]; | ||
953 | } | ||
954 | } | ||
955 | } | ||
956 | |||
957 | // Switch to the selected View | ||
958 | slotViewSwitched( view ); | ||
959 | 812 | ||
960 | // Tell the view about the selected category | 813 | // Tell the view about the selected category |
961 | m_abView -> setShowByCategory( cat ); | 814 | m_config.setCategory( category ); |
962 | 815 | m_abView -> setShowByCategory( category ); | |
963 | if ( book.isEmpty() ) | ||
964 | book = "List"; | ||
965 | if ( cat.isEmpty() ) | ||
966 | cat = "All"; | ||
967 | |||
968 | setCaption( tr( "Contacts" ) + " - " + book + " - " + tr( cat ) ); | ||
969 | } | 816 | } |
970 | 817 | ||
971 | void AddressbookWindow::slotViewSwitched( int view ) | 818 | void AddressbookWindow::slotViewSwitched( int view ) |
972 | { | 819 | { |
973 | odebug << "void AddressbookWindow::slotViewSwitched( " << view << " )" << oendl; | 820 | odebug << "void AddressbookWindow::slotViewSwitched( " << view << " )" << oendl; |
974 | int menu = 0; | ||
975 | |||
976 | // Switch to selected view | ||
977 | switch ( view ){ | ||
978 | case AbView::TableView: | ||
979 | menu = 1; | ||
980 | m_tableViewButton->setOn(true); | ||
981 | m_cardViewButton->setOn(false); | ||
982 | break; | ||
983 | case AbView::CardView: | ||
984 | menu = 2; | ||
985 | m_tableViewButton->setOn(false); | ||
986 | m_cardViewButton->setOn(true); | ||
987 | break; | ||
988 | } | ||
989 | for ( unsigned int i = 1; i < 3; i++ ){ | ||
990 | if ( catMenu ) | ||
991 | catMenu->setItemChecked( i, menu == (int)i ); | ||
992 | } | ||
993 | 821 | ||
994 | // Tell the view about the selected view | 822 | // Tell the view about the selected view |
995 | m_abView -> setShowToView ( (AbView::Views) view ); | 823 | m_abView -> setShowToView ( (AbView::Views) view ); |
996 | active_view = view; | 824 | active_view = view; |
997 | } | 825 | } |
998 | 826 | ||
999 | 827 | ||
1000 | void AddressbookWindow::slotListView() | 828 | void AddressbookWindow::slotListView() |
1001 | { | 829 | { |
1002 | slotViewSwitched( AbView::TableView ); | 830 | slotViewSwitched( AbView::TableView ); |
1003 | } | 831 | } |
1004 | 832 | ||
1005 | void AddressbookWindow::slotCardView() | 833 | void AddressbookWindow::slotCardView() |
1006 | { | 834 | { |
1007 | slotViewSwitched( AbView::CardView ); | 835 | slotViewSwitched( AbView::CardView ); |
1008 | } | 836 | } |
1009 | 837 | ||
1010 | void AddressbookWindow::slotSetLetter( char c ) { | 838 | void AddressbookWindow::slotSetLetter( char c ) { |
1011 | 839 | ||
1012 | m_abView->setShowByLetter( c, m_config.letterPickerSearch() ); | 840 | m_abView->setShowByLetter( c, m_config.letterPickerSearch() ); |
1013 | 841 | ||
1014 | } | 842 | } |
1015 | 843 | ||
1016 | |||
1017 | void AddressbookWindow::populateCategories() | ||
1018 | { | ||
1019 | catMenu->clear(); | ||
1020 | |||
1021 | int id, rememberId; | ||
1022 | id = 1; | ||
1023 | rememberId = 0; | ||
1024 | |||
1025 | catMenu->insertItem( Resource::loadPixmap( "addressbook/listview" ), tr( "List" ), id++ ); | ||
1026 | catMenu->insertItem( Resource::loadPixmap( "addressbook/cardview" ), tr( "Cards" ), id++ ); | ||
1027 | // catMenu->insertItem( tr( "Personal" ), id++ ); | ||
1028 | catMenu->insertSeparator(); | ||
1029 | |||
1030 | catMenu->insertItem( tr( "All" ), id++ ); | ||
1031 | QStringList categories = m_abView->categories(); | ||
1032 | categories.append( tr( "Unfiled" ) ); | ||
1033 | for ( QStringList::Iterator it = categories.begin(); | ||
1034 | it != categories.end(); ++it ) { | ||
1035 | catMenu->insertItem( *it, id ); | ||
1036 | if ( *it == m_abView -> showCategory() ) | ||
1037 | rememberId = id; | ||
1038 | ++id; | ||
1039 | } | ||
1040 | |||
1041 | |||
1042 | if ( m_abView -> showCategory().isEmpty() ) { | ||
1043 | slotSetCategory( 3 ); | ||
1044 | } | ||
1045 | else { | ||
1046 | slotSetCategory( rememberId ); | ||
1047 | } | ||
1048 | } | ||
1049 | |||