author | eilers <eilers> | 2003-08-30 15:32:34 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-08-30 15:32:34 (UTC) |
commit | cfb97af8f45087e58d4b82689df22191bd657c34 (patch) (side-by-side diff) | |
tree | 9e01e85787092abb0d8c6733bbe3091eaf6a892a | |
parent | 9f07321949f8baf1a64db0e4caec58041d3f775f (diff) | |
download | opie-cfb97af8f45087e58d4b82689df22191bd657c34.zip opie-cfb97af8f45087e58d4b82689df22191bd657c34.tar.gz opie-cfb97af8f45087e58d4b82689df22191bd657c34.tar.bz2 |
Speed optimization fix:
Startup and usability improved if a lot of contacts are stored. Left speed bootleneck is the xml
file..
-rw-r--r-- | core/pim/addressbook/ablabel.cpp | 7 | ||||
-rw-r--r-- | core/pim/addressbook/abtable.cpp | 101 | ||||
-rw-r--r-- | core/pim/addressbook/abtable.h | 16 | ||||
-rw-r--r-- | core/pim/addressbook/abview.cpp | 25 | ||||
-rw-r--r-- | core/pim/addressbook/addressbook.cpp | 2 | ||||
-rw-r--r-- | core/pim/addressbook/version.h | 2 |
6 files changed, 96 insertions, 57 deletions
diff --git a/core/pim/addressbook/ablabel.cpp b/core/pim/addressbook/ablabel.cpp index 6d8de91..1914f71 100644 --- a/core/pim/addressbook/ablabel.cpp +++ b/core/pim/addressbook/ablabel.cpp @@ -1,144 +1,147 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qt Palmtop Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "ablabel.h" #include <qpe/stringutil.h> #include <qregexp.h> #include <qstylesheet.h> AbLabel::AbLabel( QWidget *parent, const char *name ): QTextView( parent, name ), m_empty( false ) { } AbLabel::~AbLabel() { } void AbLabel::setContacts( const OContactAccess::List& viewList ) { m_viewList = viewList; if (m_viewList.count() != 0){ m_empty = false; m_itCurContact = m_viewList.begin(); sync(); }else{ // m_itCurContact.clear(); m_empty = true; setText( "" ); } } int AbLabel::currentEntry_UID() { OContact contact = currentEntry(); if ( contact.isEmpty() ) return 0; else return ( contact.uid() ); } OContact AbLabel::currentEntry() { if ( ! m_empty ) return ( *m_itCurContact ); else return OContact(); } bool AbLabel::selectContact( int UID ) { - for ( m_itCurContact = m_viewList.begin(); m_itCurContact != m_viewList.end(); ++m_itCurContact){ - if ( (*m_itCurContact).uid() == UID ) + for ( int r = 0; r < m_viewList.count(); ++r ) { + if ( m_viewList.uidAt( r ) == UID ){ + m_itCurContact.setCurrent( r ); break; } + } + sync(); return true; } void AbLabel::sync() { QString text = (*m_itCurContact).toRichText(); setText( text ); } void AbLabel::keyPressEvent( QKeyEvent *e ) { // Commonly handled keys if ( !m_empty ){ switch( e->key() ) { case Qt::Key_Left: qWarning( "Left.."); case Qt::Key_Right: qWarning( "Right.."); case Qt::Key_F33: qWarning( "OK.."); emit signalOkPressed(); break; case Qt::Key_Up: qWarning( "UP.."); if ( ( visibleHeight() < contentsHeight() ) && ( verticalScrollBar()->value() > verticalScrollBar()->minValue() ) ) scrollBy( 0, -(visibleHeight()-20) ); else { --m_itCurContact; if ( *m_itCurContact != OContact() ) sync(); else m_itCurContact = m_viewList.end(); } break; case Qt::Key_Down: qWarning( "DOWN.."); // qWarning( "visible: %d, content: %d",visibleHeight(),contentsHeight()); // qWarning( "value: %d; barMaxValue: %d", verticalScrollBar()->value() // , verticalScrollBar()->maxValue() ); if ( ( visibleHeight() < contentsHeight() ) && ( verticalScrollBar()->value() < verticalScrollBar()->maxValue() ) ) scrollBy( 0, visibleHeight()-20 ); else { ++m_itCurContact; if ( *m_itCurContact != OContact() ) sync(); else m_itCurContact = m_viewList.begin(); } break; case Qt::Key_Return: // fall through case Qt::Key_Space: // fall through case Qt::Key_Enter: // we want to switch back emit signalOkPressed(); break; default: break; } } } diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp index a2617fa..4705c78 100644 --- a/core/pim/addressbook/abtable.cpp +++ b/core/pim/addressbook/abtable.cpp @@ -1,821 +1,848 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) ** ** This file is part of Qt Palmtop Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include <qpe/categoryselect.h> #include <qpe/config.h> #include <qpe/stringutil.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/timestring.h> #include <qpe/resource.h> #include <opie/orecordlist.h> #include <qasciidict.h> #include <qdatetime.h> #include <qfile.h> #include <qregexp.h> #include <qmessagebox.h> #include "abtable.h" #include <errno.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <ctype.h> //toupper() for key hack +#if 0 + /*! \class AbTableItem abtable.h \brief QTableItem based class for showing a field of an entry */ AbTableItem::AbTableItem( QTable *t, EditType et, const QString &s, const QString &secondSortKey) : QTableItem( t, et, s ) { // sortKey = s.lower() + QChar( '\0' ) + secondSortKey.lower(); sortKey = Qtopia::buildSortKey( s, secondSortKey ); } int AbTableItem::alignment() const { return AlignLeft|AlignVCenter; } QString AbTableItem::key() const { return sortKey; } // A way to reset the item, without out doing a delete or a new... void AbTableItem::setItem( const QString &txt, const QString &secondKey ) { setText( txt ); sortKey = Qtopia::buildSortKey( txt, secondKey ); // sortKey = txt.lower() + QChar( '\0' ) + secondKey.lower(); } /*! \class AbPickItem abtable.h \brief QTableItem based class for showing slection of an entry */ AbPickItem::AbPickItem( QTable *t ) : QTableItem(t, WhenCurrent, "?") { } QWidget *AbPickItem::createEditor() const { QComboBox* combo = new QComboBox( table()->viewport() ); ( (AbPickItem*)this )->cb = combo; AbTable* t = static_cast<AbTable*>(table()); QStringList c = t->choiceNames(); int cur = 0; for (QStringList::ConstIterator it = c.begin(); it!=c.end(); ++it) { if ( *it == text() ) cur = combo->count(); combo->insertItem(*it); } combo->setCurrentItem(cur); return combo; } void AbPickItem::setContentFromEditor( QWidget *w ) { if ( w->inherits("QComboBox") ) setText( ( (QComboBox*)w )->currentText() ); else QTableItem::setContentFromEditor( w ); } +#endif + /*! \class AbTable abtable.h \brief QTable based class for showing a list of entries */ AbTable::AbTable( const QValueList<int> order, QWidget *parent, const char *name ) : QTable( parent, name ), lastSortCol( -1 ), asc( TRUE ), intFields( order ), enablePainting( true ), columnVisible( true ), countNested( 0 ) { // qWarning("C'tor start"); setSelectionMode( NoSelection ); init(); setSorting( TRUE ); connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), this, SLOT(itemClicked(int,int)) ); - contactList.clear(); + // contactList.clear(); // qWarning("C'tor end"); } AbTable::~AbTable() { } void AbTable::init() { // :SX showChar = '\0'; setNumRows( 0 ); setNumCols( 2 ); horizontalHeader()->setLabel( 0, tr( "Full Name" )); horizontalHeader()->setLabel( 1, tr( "Contact" )); setLeftMargin( 0 ); verticalHeader()->hide(); columnVisible = true; } void AbTable::setContacts( const OContactAccess::List& viewList ) { - // qWarning("AbTable::setContacts()"); + qWarning("AbTable::setContacts()"); clear(); m_viewList = viewList; setSorting( false ); setPaintingEnabled( FALSE ); OContactAccess::List::Iterator it; setNumRows( m_viewList.count() ); - int row = 0; - for ( it = m_viewList.begin(); it != m_viewList.end(); ++it ) - insertIntoTable( *it, row++ ); +// int row = 0; +// for ( it = m_viewList.begin(); it != m_viewList.end(); ++it ) +// insertIntoTable( *it, row++ ); - setSorting( true ); +// setSorting( true ); - resort(); +// resort(); updateVisible(); setPaintingEnabled( TRUE ); } void AbTable::setOrderedList( const QValueList<int> ordered ) { intFields = ordered; } bool AbTable::selectContact( int UID ) { - // qWarning( "AbTable::selectContact( %d )", UID ); + qWarning( "AbTable::selectContact( %d )", UID ); int rows = numRows(); - AbTableItem *abi; OContact* foundContact = 0l; bool found = false; setPaintingEnabled( FALSE ); + qWarning( "search start" ); for ( int r = 0; r < rows; ++r ) { - abi = static_cast<AbTableItem*>( item(r, 0) ); - foundContact = &contactList[abi]; - if ( foundContact -> uid() == UID ){ + if ( m_viewList.uidAt( r ) == UID ){ ensureCellVisible( r, 0 ); setCurrentCell( r, 0 ); found = true; break; } } + qWarning( "search end" ); if ( !found ){ ensureCellVisible( 0,0 ); setCurrentCell( 0, 0 ); } setPaintingEnabled( TRUE ); return true; } +#if 0 void AbTable::insertIntoTable( const OContact& cnt, int row ) { - // qWarning( "void AbTable::insertIntoTable( const OContact& cnt, %d )", row ); + qWarning( "void AbTable::insertIntoTable( const OContact& cnt, %d )", row ); QString strName; ContactItem contactItem; strName = findContactName( cnt ); contactItem = findContactContact( cnt, row ); AbTableItem *ati; ati = new AbTableItem( this, QTableItem::Never, strName, contactItem.value ); contactList.insert( ati, cnt ); setItem( row, 0, ati ); ati = new AbTableItem( this, QTableItem::Never, contactItem.value, strName); if ( !contactItem.icon.isNull() ) ati->setPixmap( contactItem.icon ); setItem( row, 1, ati ); //### cannot do this; table only has two columns at this point // setItem( row, 2, new AbPickItem( this ) ); } - +#endif void AbTable::columnClicked( int col ) { if ( !sorting() ) return; if ( lastSortCol == -1 ) lastSortCol = col; if ( col == lastSortCol ) { asc = !asc; } else { lastSortCol = col; asc = TRUE; } //QMessageBox::information( this, "resort", "columnClicked" ); resort(); } void AbTable::resort() { - // qWarning( "void AbTable::resort()" ); + qWarning( "void AbTable::resort() NOT POSSIBLE !!" ); +#if 0 setPaintingEnabled( FALSE ); if ( sorting() ) { if ( lastSortCol == -1 ) lastSortCol = 0; sortColumn( lastSortCol, asc, TRUE ); //QMessageBox::information( this, "resort", "resort" ); updateVisible(); } setPaintingEnabled( TRUE ); +#endif } OContact AbTable::currentEntry() { - // qWarning( "OContact AbTable::currentEntry()" ); - OContact cnt; - AbTableItem *abItem; - abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); - if ( abItem ) { - cnt = contactList[abItem]; - //cnt = contactList[currentRow()]; - } - return cnt; + return m_viewList[currentRow()]; } int AbTable::currentEntry_UID() { return ( currentEntry().uid() ); } void AbTable::clear() { - // qWarning( "void AbTable::clear()" ); - contactList.clear(); + qWarning( "void AbTable::clear()" ); + // contactList.clear(); setPaintingEnabled( FALSE ); for ( int r = 0; r < numRows(); ++r ) { for ( int c = 0; c < numCols(); ++c ) { if ( cellWidget( r, c ) ) clearCellWidget( r, c ); clearCell( r, c ); } } setNumRows( 0 ); setPaintingEnabled( TRUE ); } // Refresh updates column 2 if the contactsettings changed void AbTable::refresh() { - // qWarning( "void AbTable::refresh()" ); + qWarning( "void AbTable::refresh() NOT IMPLEMENTED !!" ); + +#if 0 int rows = numRows(); AbTableItem *abi; ContactItem contactItem; setPaintingEnabled( FALSE ); for ( int r = 0; r < rows; ++r ) { abi = static_cast<AbTableItem*>( item(r, 0) ); contactItem = findContactContact( contactList[abi], r ); static_cast<AbTableItem*>( item(r, 1) )->setItem( contactItem.value, abi->text() ); if ( !contactItem.icon.isNull() ){ static_cast<AbTableItem*>( item(r, 1) )-> setPixmap( contactItem.icon ); }else{ static_cast<AbTableItem*>( item(r, 1) )-> setPixmap( QPixmap() ); } } resort(); setPaintingEnabled( TRUE ); + +#endif } void AbTable::keyPressEvent( QKeyEvent *e ) { char key = toupper( e->ascii() ); if ( key >= 'A' && key <= 'Z' ) moveTo( key ); // qWarning("Received key .."); switch( e->key() ) { case Qt::Key_Space: case Qt::Key_Return: case Qt::Key_Enter: emit signalSwitch(); break; // case Qt::Key_Up: // qWarning("a"); // emit signalKeyUp(); // break; // case Qt::Key_Down: // qWarning("b"); // emit signalKeyDown(); // break; default: QTable::keyPressEvent( e ); } } void AbTable::moveTo( char c ) { - qWarning( "void AbTable::moveTo( char c )" ); + qWarning( "void AbTable::moveTo( char c ) NOT IMPLEMENTED !!" ); +#if 0 int rows = numRows(); QString value; AbTableItem *abi; int r; if ( asc ) { r = 0; while ( r < rows-1) { abi = static_cast<AbTableItem*>( item(r, 0) ); QChar first = abi->key()[0]; //### is there a bug in QChar to char comparison??? if ( first.row() || first.cell() >= c ) break; r++; } } else { //### should probably disable reverse sorting instead r = rows - 1; while ( r > 0 ) { abi = static_cast<AbTableItem*>( item(r, 0) ); QChar first = abi->key()[0]; //### is there a bug in QChar to char comparison??? if ( first.row() || first.cell() >= c ) break; r--; } } setCurrentCell( r, currentColumn() ); -} +#endif +} +#if 0 +// Useless.. Nobody uses it .. (se) QString AbTable::findContactName( const OContact &entry ) { // We use the fileAs, then company, defaultEmail QString str; str = entry.fileAs(); if ( str.isEmpty() ) { str = entry.company(); if ( str.isEmpty() ) { str = entry.defaultEmail(); } } return str; } - +#endif void AbTable::resizeRows() { /* if (numRows()) { for (int i = 0; i < numRows(); i++) { setRowHeight( i, size ); } } updateVisible(); */ } void AbTable::realignTable() { // qWarning( "void AbTable::realignTable()" ); setPaintingEnabled( FALSE ); resizeRows(); fitColumns(); setPaintingEnabled( TRUE ); } #if QT_VERSION <= 230 #ifndef SINGLE_APP void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) { // Region of the rect we should draw QRegion reg( QRect( cx, cy, cw, ch ) ); // Subtract the table from it reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) ); // And draw the rectangles (transformed as needed) QArray<QRect> r = reg.rects(); for (unsigned int i=0; i<r.count(); i++) p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) ); } #endif #endif // int AbTable::rowHeight( int ) const // { // return 18; // } // int AbTable::rowPos( int row ) const // { // return 18*row; // } // int AbTable::rowAt( int pos ) const // { // return QMIN( pos/18, numRows()-1 ); // } void AbTable::fitColumns() { // qWarning( "void AbTable::fitColumns()" ); int contentsWidth = visibleWidth() / 2; // :SX Why too low // Fix to better value // contentsWidth = 130; setPaintingEnabled( FALSE ); if ( columnVisible == false ){ showColumn(0); columnVisible = true; } // qWarning("Width: %d", contentsWidth); setColumnWidth( 0, contentsWidth ); adjustColumn(1); if ( columnWidth(1) < contentsWidth ) setColumnWidth( 1, contentsWidth ); setPaintingEnabled( TRUE ); } void AbTable::show() { // qWarning( "void AbTable::show()" ); realignTable(); QTable::show(); } +#if 0 void AbTable::setChoiceNames( const QStringList& list) { choicenames = list; if ( choicenames.isEmpty() ) { // hide pick column setNumCols( 2 ); } else { // show pick column setNumCols( 3 ); setColumnWidth( 2, fontMetrics().width(tr( "Pick" ))+8 ); horizontalHeader()->setLabel( 2, tr( "Pick" )); } fitColumns(); } +#endif void AbTable::itemClicked(int,int col) { // qWarning( "AbTable::itemClicked(int, col:%d)", col); if ( col == 2 ) { return; } else { // qWarning ("Emitting signalSwitch()"); emit signalSwitch(); } } +#if 0 QStringList AbTable::choiceNames() const { return choicenames; } +#endif void AbTable::setChoiceSelection( const QValueList<int>& list ) { intFields = list; } QStringList AbTable::choiceSelection(int /*index*/) const { QStringList r; /* ###### QString selname = choicenames.at(index); for (each row) { OContact *c = contactForRow(row); if ( text(row,2) == selname ) { r.append(c->email); } } */ return r; } - - void AbTable::updateVisible() { // qWarning("void AbTable::updateVisible()"); int visible, totalRows, row, selectedRow = 0; visible = 0; setPaintingEnabled( FALSE ); realignTable(); totalRows = numRows(); for ( row = 0; row < totalRows; row++ ) { if ( rowHeight(row) == 0 ) { showRow( row ); adjustRow( row ); if ( isSelected( row,0 ) || isSelected( row,1 ) ) selectedRow = row; } visible++; } if ( selectedRow ) setCurrentCell( selectedRow, 0 ); if ( !visible ) setCurrentCell( -1, 0 ); setPaintingEnabled( TRUE ); } void AbTable::setPaintingEnabled( bool e ) { // qWarning("IN void AbTable::setPaintingEnabled( %d )->Nested: %d", e, countNested ); if ( e ) { if ( countNested > 0 ) --countNested; if ( ! countNested ){ setUpdatesEnabled( true ); enablePainting = true; rowHeightChanged( 0 ); viewport()->update(); } } else { ++countNested; enablePainting = false; setUpdatesEnabled( false ); } // qWarning("OUT void AbTable::setPaintingEnabled( %d )->Nested: %d", e, countNested ); } void AbTable::viewportPaintEvent( QPaintEvent* e ) { // qWarning(" void AbTable::viewportPaintEvent( QPaintEvent* e ) -> %d", enablePainting); if ( enablePainting ) QTable::viewportPaintEvent( e ); } void AbTable::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) { const QColorGroup &cg = colorGroup(); p->save(); + //qWarning( "Paint row: %d", row ); + + OContact act_contact = m_viewList[row]; + // Paint alternating background bars if ( (row % 2 ) == 0 ) { p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); p->setPen( QPen( cg.text() ) ); } else { p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Background ) ); p->setPen( QPen( cg.buttonText() ) ); } QFont f = p->font(); QFontMetrics fm(f); int marg = 2; int x = 0; int y = ( cr.height() - 14 ) / 2; - QPixmap pic = pixmap( row, col ); - if ( !pic.isNull() ) + QString nameText = act_contact.fileAs(); + + switch( col ){ + case 0: + p->drawText( x + marg,2 + fm.ascent(), nameText ); + break; + case 1:{ + + ContactItem contactItem = findContactContact( act_contact, 0 ); + QPixmap contactPic = contactItem.icon; /* pixmap( row, col ); */ + QString contactText = contactItem.value; + + if ( !contactPic.isNull() ) { - p->drawPixmap( x + marg, y, pixmap( row, col ) ); - p->drawText( x + marg + pixmap( row, col ).width() + 4,2 + fm.ascent(), text( row, col ) ); + p->drawPixmap( x + marg, y, contactPic ); + p->drawText( x + marg + contactPic.width() + + 4,2 + fm.ascent(), contactText ); } else { - p->drawText( x + marg,2 + fm.ascent(), text( row, col ) ); + p->drawText( x + marg,2 + fm.ascent(), contactText ); } + } + break; + } p->restore(); } void AbTable::rowHeightChanged( int row ) { if ( enablePainting ) QTable::rowHeightChanged( row ); } ContactItem AbTable::findContactContact( const OContact &entry, int /* row */ ) { ContactItem item; item.value = ""; for ( QValueList<int>::ConstIterator it = intFields.begin(); it != intFields.end(); ++it ) { switch ( *it ) { default: break; case Qtopia::Title: item.value = entry.title(); break; case Qtopia::Suffix: item.value = entry.suffix(); break; case Qtopia::FileAs: item.value = entry.fileAs(); break; case Qtopia::DefaultEmail: item.value = entry.defaultEmail(); if ( !item.value.isEmpty() ) item.icon = Resource::loadPixmap( "addressbook/email" ); break; case Qtopia::Emails: item.value = entry.emails(); if ( !item.value.isEmpty() ) item.icon = Resource::loadPixmap( "addressbook/email" ); break; case Qtopia::HomeStreet: item.value = entry.homeStreet(); break; case Qtopia::HomeCity: item.value = entry.homeCity(); break; case Qtopia::HomeState: item.value = entry.homeState(); break; case Qtopia::HomeZip: item.value = entry.homeZip(); break; case Qtopia::HomeCountry: item.value = entry.homeCountry(); break; case Qtopia::HomePhone: item.value = entry.homePhone(); if ( !item.value.isEmpty() ) item.icon = Resource::loadPixmap( "addressbook/phonehome" ); break; case Qtopia::HomeFax: item.value = entry.homeFax(); if ( !item.value.isEmpty() ) item.icon = Resource::loadPixmap( "addressbook/faxhome" ); break; case Qtopia::HomeMobile: item.value = entry.homeMobile(); if ( !item.value.isEmpty() ) item.icon = Resource::loadPixmap( "addressbook/mobilehome" ); break; case Qtopia::HomeWebPage: item.value = entry.homeWebpage(); if ( !item.value.isEmpty() ) item.icon = Resource::loadPixmap( "addressbook/webpagehome" ); break; case Qtopia::Company: item.value = entry.company(); break; case Qtopia::BusinessCity: item.value = entry.businessCity(); break; case Qtopia::BusinessStreet: item.value = entry.businessStreet(); break; case Qtopia::BusinessZip: item.value = entry.businessZip(); break; case Qtopia::BusinessCountry: item.value = entry.businessCountry(); break; case Qtopia::BusinessWebPage: item.value = entry.businessWebpage(); if ( !item.value.isEmpty() ) item.icon = Resource::loadPixmap( "addressbook/webpagework" ); break; case Qtopia::JobTitle: item.value = entry.jobTitle(); break; case Qtopia::Department: item.value = entry.department(); break; case Qtopia::Office: item.value = entry.office(); break; case Qtopia::BusinessPhone: item.value = entry.businessPhone(); if ( !item.value.isEmpty() ) item.icon = Resource::loadPixmap( "addressbook/phonework" ); break; case Qtopia::BusinessFax: item.value = entry.businessFax(); if ( !item.value.isEmpty() ) item.icon = Resource::loadPixmap( "addressbook/faxwork" ); break; case Qtopia::BusinessMobile: item.value = entry.businessMobile(); if ( !item.value.isEmpty() ) item.icon = Resource::loadPixmap( "addressbook/mobilework" ); break; case Qtopia::BusinessPager: item.value = entry.businessPager(); break; case Qtopia::Profession: item.value = entry.profession(); break; case Qtopia::Assistant: item.value = entry.assistant(); break; case Qtopia::Manager: item.value = entry.manager(); break; case Qtopia::Spouse: item.value = entry.spouse(); break; case Qtopia::Gender: item.value = entry.gender(); break; case Qtopia::Birthday: if ( ! entry.birthday().isNull() ){ item.value = TimeString::numberDateString( entry.birthday() ); } break; case Qtopia::Anniversary: if ( ! entry.anniversary().isNull() ){ item.value = TimeString::numberDateString( entry.anniversary() ); } break; case Qtopia::Nickname: item.value = entry.nickname(); break; case Qtopia::Children: item.value = entry.children(); break; case Qtopia::Notes: item.value = entry.notes(); break; } if ( !item.value.isEmpty() ) break; } return item; } diff --git a/core/pim/addressbook/abtable.h b/core/pim/addressbook/abtable.h index 0f7bc29..b9ebe27 100644 --- a/core/pim/addressbook/abtable.h +++ b/core/pim/addressbook/abtable.h @@ -1,152 +1,158 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) ** ** This file is part of Qt Palmtop Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #ifndef ABTABLE_H #define ABTABLE_H #include <qpe/categories.h> #include <opie/ocontact.h> #include <opie/ocontactaccess.h> #include <qmap.h> #include <qtable.h> #include <qstringlist.h> #include <qcombobox.h> #include <qpixmap.h> +#if 0 class AbTableItem : public QTableItem { public: AbTableItem( QTable *t, EditType et, const QString &s, const QString &secondSortKey); QString entryKey() const; void setEntryKey( const QString & k ); virtual int alignment() const; virtual QString key() const; void setItem( const QString &txt, const QString &secondKey ); private: QString sortKey; }; +#endif + // This is a simple container, storing all contact // information class ContactItem { public: QPixmap icon; QString value; }; +#if 0 class AbPickItem : public QTableItem { public: AbPickItem( QTable *t ); QWidget *createEditor() const; void setContentFromEditor( QWidget *w ); private: QGuardedPtr<QComboBox> cb; }; +#endif + class AbTable : public QTable { Q_OBJECT public: AbTable( const QValueList<int> ordered, QWidget *parent, const char *name=0 ); ~AbTable(); // Set the contacts shown in the table void setContacts( const OContactAccess::List& viewList ); // Set the list for primary contacts void setOrderedList( const QValueList<int> ordered ); // Selects a contact of a specific UID bool selectContact( int UID ); // Get the current selected entry OContact currentEntry(); // Get the UID of the current selected Entry int currentEntry_UID(); - QString findContactName( const OContact &entry ); + // QString findContactName( const OContact &entry ); void init(); void clear(); void refresh(); void show(); void setPaintingEnabled( bool e ); void viewportPaintEvent( QPaintEvent* e); void paintCell(QPainter* p, int row, int col, const QRect&, bool ); // addresspicker mode (What's that ? se) - void setChoiceNames( const QStringList& list); - QStringList choiceNames() const; + // void setChoiceNames( const QStringList& list); + // QStringList choiceNames() const; void setChoiceSelection( const QValueList<int>& list ); QStringList choiceSelection(int index) const; signals: void signalSwitch(); void signalEditor(); void signalKeyDown(); void signalKeyUp(); protected: virtual void keyPressEvent( QKeyEvent *e ); // int rowHeight( int ) const; // int rowPos( int row ) const; // virtual int rowAt( int pos ) const; protected slots: void moveTo( char ); virtual void columnClicked( int col ); void itemClicked(int,int col); void rowHeightChanged( int row ); private: - void insertIntoTable( const OContact &cnt, int row ); + // void insertIntoTable( const OContact &cnt, int row ); ContactItem findContactContact( const OContact &entry, int row ); void fitColumns(); void resizeRows(); void realignTable(); void resort(); void updateVisible(); int lastSortCol; bool asc; - QMap<AbTableItem*, OContact> contactList; + // QMap<AbTableItem*, OContact> contactList; QValueList<int> intFields; QStringList choicenames; bool enablePainting; bool columnVisible; int countNested; OContactAccess::List m_viewList; }; #endif // ABTABLE_H diff --git a/core/pim/addressbook/abview.cpp b/core/pim/addressbook/abview.cpp index 477f85b..6cbd556 100644 --- a/core/pim/addressbook/abview.cpp +++ b/core/pim/addressbook/abview.cpp @@ -1,502 +1,505 @@ /********************************************************************** ** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) ** ** This file is part of Qt Palmtop Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** **********************************************************************/ #include "abview.h" #include <qlayout.h> #include <qpe/global.h> #include <opie/ocontactaccessbackend_vcard.h> #include <assert.h> // Is defined in LibQPE extern QString categoryFileName(); QString addressbookPersonalVCardName() { QString filename = Global::applicationFileName("addressbook", "businesscard.vcf"); return filename; } AbView::AbView ( QWidget* parent, const QValueList<int>& ordered ): QWidget(parent), mCat(0), m_inSearch( false ), m_inPersonal( false ), m_curr_category( -1 ), m_curr_View( TableView ), m_prev_View( TableView ), m_curr_Contact ( 0 ), m_contactdb ( 0l ), m_storedDB ( 0l ), m_viewStack( 0l ), m_abTable( 0l ), m_orderedFields( ordered ) { + qWarning("AbView::c'tor"); // Load default database and handle syncing myself.. ! m_contactdb = new OContactAccess ( "addressbook", 0l, 0l, false ), mCat.load( categoryFileName() ); // Create Layout and put WidgetStack into it. QVBoxLayout *vb = new QVBoxLayout( this ); m_viewStack = new QWidgetStack( this ); vb->addWidget( m_viewStack ); // Creat TableView QVBox* tableBox = new QVBox( m_viewStack ); m_abTable = new AbTable( m_orderedFields, tableBox, "table" ); m_abTable->setCurrentCell( 0, 0 ); m_abTable->setFocus(); // Add TableView to WidgetStack and raise it m_viewStack -> addWidget( tableBox , TableView ); // Create CardView and add it to WidgetStack QVBox* cardBox = new QVBox( m_viewStack ); m_ablabel = new AbLabel( cardBox, "CardView"); m_viewStack -> addWidget( cardBox , CardView ); // Connect views to me connect ( m_abTable, SIGNAL( signalSwitch( void ) ), this, SLOT( slotSwitch( void ) ) ); connect ( m_ablabel, SIGNAL( signalOkPressed( void ) ), this, SLOT( slotSwitch( void ) ) ); load(); } AbView::~AbView() { m_contactdb -> save(); delete m_contactdb; if ( m_storedDB ){ m_storedDB -> save(); delete m_storedDB; } } void AbView::setView( Views view ) { - // qWarning("AbView::setView( Views view )"); + qWarning("AbView::setView( Views view )"); m_curr_View = view; load(); } void AbView::addEntry( const OContact &newContact ) { - // qWarning("abview:AddContact"); + qWarning("abview:AddContact"); m_contactdb->add ( newContact ); load(); } void AbView::removeEntry( const int UID ) { - // qWarning("abview:RemoveContact"); + qWarning("abview:RemoveContact"); m_contactdb->remove( UID ); load(); } void AbView::replaceEntry( const OContact &contact ) { - // qWarning("abview:ReplaceContact"); + qWarning("abview:ReplaceContact"); m_contactdb->replace( contact ); load(); } OContact AbView::currentEntry() { OContact currentContact; switch ( (int) m_curr_View ) { case TableView: currentContact = m_abTable -> currentEntry(); break; case CardView: currentContact = m_ablabel -> currentEntry(); break; } m_curr_Contact = currentContact.uid(); return currentContact; } bool AbView::save() { // qWarning("abView:Save data"); return m_contactdb->save(); } void AbView::load() { - // qWarning("abView:Load data"); + qWarning("abView:Load data"); // Letter Search is stopped at this place emit signalClearLetterPicker(); if ( m_inPersonal ) // VCard Backend does not sort.. m_list = m_contactdb->allRecords(); else{ m_list = m_contactdb->sorted( true, 0, 0, 0 ); + if ( m_curr_category != -1 ) clearForCategory(); } qWarning ("Number of contacts: %d", m_list.count()); updateView( true ); } void AbView::reload() { - // qWarning( "void AbView::reload()" ); + qWarning( "void AbView::reload()" ); m_contactdb->reload(); load(); } void AbView::clear() { // :SX } void AbView::setShowByCategory( const QString& cat ) { - // qWarning("AbView::setShowCategory( const QString& cat )"); + qWarning("AbView::setShowCategory( const QString& cat )"); int intCat = 0; // All (cat == NULL) will be stored as -1 if ( cat.isNull() ) intCat = -1; else intCat = mCat.id("Contacts", cat ); // Just do anything if we really change the category if ( intCat != m_curr_category ){ // qWarning ("Categories: Selected %s.. Number: %d", cat.latin1(), m_curr_category); m_curr_category = intCat; emit signalClearLetterPicker(); load(); } } void AbView::setShowToView( Views view ) { - // qWarning("void AbView::setShowToView( View %d )", view); - - // qWarning ("Change the View (Category is: %d)", m_curr_category); + qWarning("void AbView::setShowToView( View %d )", view); if ( m_curr_View != view ){ + qWarning ("Change the View (Category is: %d)", m_curr_category); m_prev_View = m_curr_View; m_curr_View = view; updateView(); } } void AbView::setShowByLetter( char c, AbConfig::LPSearchMode mode ) { qWarning("void AbView::setShowByLetter( %c, %d )", c, mode ); assert( mode < AbConfig::LASTELEMENT ); OContact query; if ( c == 0 ){ load(); return; }else{ // If the current Backend is unable to solve the query, we will // ignore the request .. if ( ! m_contactdb->hasQuerySettings( OContactAccess::WildCards | OContactAccess::IgnoreCase ) ){ return; } switch( mode ){ case AbConfig::LastName: query.setLastName( QString("%1*").arg(c) ); break; case AbConfig::FileAs: query.setFileAs( QString("%1*").arg(c) ); break; default: qWarning( "Unknown Searchmode for AbView::setShowByLetter ! -> %d", mode ); qWarning( "I will ignore it.." ); return; } m_list = m_contactdb->queryByExample( query, OContactAccess::WildCards | OContactAccess::IgnoreCase ); + if ( m_curr_category != -1 ) clearForCategory(); m_curr_Contact = 0; } updateView( true ); } void AbView::setListOrder( const QValueList<int>& ordered ) { m_orderedFields = ordered; if ( m_abTable ){ m_abTable->setOrderedList( ordered ); m_abTable->refresh(); } updateView(); } QString AbView::showCategory() const { return mCat.label( "Contacts", m_curr_category ); } void AbView::showPersonal( bool personal ) { - // qWarning ("void AbView::showPersonal( %d )", personal); + qWarning ("void AbView::showPersonal( %d )", personal); if ( personal ){ if ( m_inPersonal ) return; // Now switch to vCard Backend and load data. // The current default backend will be stored // to avoid unneeded load/stores. m_storedDB = m_contactdb; OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, addressbookPersonalVCardName() ); m_contactdb = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); m_inPersonal = true; m_curr_View = CardView; }else{ if ( !m_inPersonal ) return; // Remove vCard Backend and restore default m_contactdb->save(); delete m_contactdb; m_contactdb = m_storedDB; m_storedDB = 0l; m_curr_View = TableView; m_inPersonal = false; } load(); } void AbView::setCurrentUid( int uid ){ m_curr_Contact = uid; updateView( true ); //true: Don't modificate the UID ! } QStringList AbView::categories() { mCat.load( categoryFileName() ); QStringList categoryList = mCat.labels( "Contacts" ); return categoryList; } // BEGIN: Slots void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, bool , QString cat ) { // qWarning( "void AbView::slotDoFind" ); // We reloading the data: Deselect Letterpicker emit signalClearLetterPicker(); // Use the current Category if nothing else selected int category = 0; if ( cat.isEmpty() ) category = m_curr_category; else{ category = mCat.id("Contacts", cat ); } // qWarning ("Find in Category %d", category); QRegExp r( str ); r.setCaseSensitive( caseSensitive ); r.setWildcard( !useRegExp ); // Get all matching entries out of the database m_list = m_contactdb->matchRegexp( r ); // qWarning( "found: %d", m_list.count() ); if ( m_list.count() == 0 ){ emit signalNotFound(); return; } // Now remove all contacts with wrong category (if any selected) // This algorithm is a litte bit ineffective, but // we will not have a lot of matching entries.. + if ( m_curr_category != -1 ) clearForCategory(); // Now show all found entries updateView( true ); } void AbView::offSearch() { m_inSearch = false; load(); } void AbView::slotSwitch(){ // qWarning("AbView::slotSwitch()"); m_prev_View = m_curr_View; switch ( (int) m_curr_View ){ case TableView: qWarning("Switching to CardView"); m_curr_View = CardView; break; case CardView: qWarning("Switching to TableView"); m_curr_View = TableView; break; } updateView(); } // END: Slots void AbView::clearForCategory() { OContactAccess::List::Iterator it; // Now remove all contacts with wrong category if any category selected OContactAccess::List allList = m_list; if ( m_curr_category != -1 ){ for ( it = allList.begin(); it != allList.end(); ++it ){ if ( !contactCompare( *it, m_curr_category ) ){ // qWarning("Removing %d", (*it).uid()); m_list.remove( (*it).uid() ); } } } } bool AbView::contactCompare( const OContact &cnt, int category ) { // qWarning ("bool AbView::contactCompare( const OContact &cnt, %d )", category); bool returnMe; QArray<int> cats; cats = cnt.categories(); // qWarning ("Number of categories: %d", cats.count() ); returnMe = false; if ( cats.count() == 0 && category == 0 ) // Contacts with no category will just shown on "All" and "Unfiled" returnMe = true; else { int i; for ( i = 0; i < int(cats.count()); i++ ) { // qWarning("Comparing %d with %d",cats[i],category ); if ( cats[i] == category ) { returnMe = true; break; } } } // qWarning ("Return: %d", returnMe); return returnMe; } // In Some rare cases we have to update all lists.. void AbView::updateListinViews() { m_abTable -> setContacts( m_list ); m_ablabel -> setContacts( m_list ); } void AbView::updateView( bool newdata ) { // qWarning("AbView::updateView()"); if ( m_viewStack -> visibleWidget() ){ m_viewStack -> visibleWidget() -> clearFocus(); } // If we switching the view, we have to store some information if ( !newdata ){ if ( m_list.count() ){ switch ( (int) m_prev_View ) { case TableView: m_curr_Contact = m_abTable -> currentEntry_UID(); break; case CardView: m_curr_Contact = m_ablabel -> currentEntry_UID(); break; } }else m_curr_Contact = 0; } // Feed all views with new lists if ( newdata ) updateListinViews(); // Tell the world that the view is changed if ( m_curr_View != m_prev_View ) emit signalViewSwitched ( (int) m_curr_View ); m_prev_View = m_curr_View; // Switch to new View switch ( (int) m_curr_View ) { case TableView: m_abTable -> setChoiceSelection( m_orderedFields ); if ( m_curr_Contact != 0 ) m_abTable -> selectContact ( m_curr_Contact ); m_abTable -> setFocus(); break; case CardView: if ( m_curr_Contact != 0 ) m_ablabel -> selectContact( m_curr_Contact ); m_ablabel -> setFocus(); break; } // Raise the current View m_viewStack -> raiseWidget( m_curr_View ); } diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp index 03c96c8..0ba024e 100644 --- a/core/pim/addressbook/addressbook.cpp +++ b/core/pim/addressbook/addressbook.cpp @@ -1,763 +1,763 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** Copyright (C) 2003 Stefan Eilers (eilers.stefan@epost.de) ** ** This file is part of the Open Palmtop Environment (see www.opie.info). ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** **********************************************************************/ #define QTOPIA_INTERNAL_FD #include "contacteditor.h" #include "ablabel.h" #include "abview.h" #include "abtable.h" // #include "addresssettings.h" #include "addressbook.h" #include <opie/ofileselector.h> #include <opie/ofiledialog.h> #include <opie/ocontact.h> #include <opie/ocontactaccessbackend_vcard.h> #include <qpe/resource.h> #include <qpe/ir.h> #include <qpe/qpemessagebox.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/qpetoolbar.h> #include <qpe/qpemenubar.h> // #include <qtoolbar.h> // #include <qmenubar.h> #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qaction.h> #include <qdialog.h> #include <qdir.h> #include <qfile.h> #include <qimage.h> #include <qlayout.h> #include <qmessagebox.h> #include <qpixmap.h> #include <qpopupmenu.h> #include <qstringlist.h> #include <qtoolbutton.h> #include <qwhatsthis.h> #include <qdatetime.h> #include <stdlib.h> #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> #include <unistd.h> #include "picker.h" #include "configdlg.h" extern QString addressbookPersonalVCardName(); AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, WFlags f ) : QMainWindow( parent, name, f ), catMenu (0l), abEditor(0l), syncing(FALSE), m_tableViewButton(0l), m_cardViewButton(0l) { isLoading = true; m_config.load(); setCaption( tr("Contacts") ); setIcon( Resource::loadPixmap( "AddressBook" ) ); // Settings for Main Menu // setToolBarsMovable( false ); setToolBarsMovable( !m_config.fixedBars() ); setRightJustification( true ); QPEToolBar *bar = new QPEToolBar( this ); bar->setHorizontalStretchable( TRUE ); QPEMenuBar *mbList = new QPEMenuBar( bar ); mbList->setMargin( 0 ); QPopupMenu *edit = new QPopupMenu( mbList ); mbList->insertItem( tr( "Contact" ), edit ); // Category Menu catMenu = new QPopupMenu( this ); catMenu->setCheckable( TRUE ); connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); mbList->insertItem( tr("View"), catMenu ); // Create Toolbar listTools = new QPEToolBar( this, "list operations" ); listTools->setHorizontalStretchable( true ); addToolBar( listTools ); moveToolBar( listTools, m_config.getToolBarPos() ); // View Icons m_tableViewButton = new QAction( tr( "List" ), Resource::loadPixmap( "addressbook/listview" ), QString::null, 0, this, 0 ); connect( m_tableViewButton, SIGNAL( activated() ), this, SLOT( slotListView() ) ); m_tableViewButton->setToggleAction( true ); m_tableViewButton->addTo( listTools ); m_cardViewButton = new QAction( tr( "Card" ), Resource::loadPixmap( "addressbook/cardview" ), QString::null, 0, this, 0 ); connect( m_cardViewButton, SIGNAL( activated() ), this, SLOT( slotCardView() ) ); m_cardViewButton->setToggleAction( true ); m_cardViewButton->addTo( listTools ); listTools->addSeparator(); // Other Buttons QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); actionNew = a; connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) ); a->addTo( edit ); a->addTo( listTools ); a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, 0, this, 0 ); actionEdit = a; connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) ); a->addTo( edit ); a->addTo( listTools ); a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); actionTrash = a; connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) ); a->addTo( edit ); a->addTo( listTools ); // make it possible to go directly to businesscard via qcop call //#if defined(Q_WS_QWS) // Why this ? (se) #if !defined(QT_NO_COP) QCopChannel *addressChannel = new QCopChannel("QPE/Addressbook" , this ); connect (addressChannel, SIGNAL( received(const QCString &, const QByteArray &)), this, SLOT ( appMessage(const QCString &, const QByteArray &) ) ); #endif // #endif a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 ); actionFind = a; connect( a, SIGNAL(activated()), this, SLOT( slotFindOpen()) ); a->addTo( edit ); a->addTo( listTools ); // Much better search widget, taken from QTReader.. (se) searchBar = new OFloatBar( "Search", this, QMainWindow::Top, TRUE ); searchBar->setHorizontalStretchable( TRUE ); searchBar->hide(); searchEdit = new QLineEdit( searchBar, "searchEdit" ); // QFont f("unifont", 16 /*, QFont::Bold*/); // searchEdit->setFont( f ); searchBar->setStretchableWidget( searchEdit ); connect( searchEdit, SIGNAL( returnPressed( ) ), this, SLOT( slotFind( ) ) ); a = new QAction( tr( "Start Search" ), Resource::loadPixmap( "enter" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); a->addTo( searchBar ); a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( slotFindClose() ) ); a->addTo( searchBar ); a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "addressbook/sendmail" ), QString::null, 0, this, 0 ); //a->setEnabled( FALSE ); we got support for it now :) zecke actionMail = a; connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) ); a->addTo( edit ); a->addTo( listTools ); if ( Ir::supported() ) { a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null, 0, this, 0 ); actionBeam = a; connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); a->addTo( edit ); a->addTo( listTools ); } edit->insertSeparator(); a = new QAction( tr("Import vCard"), Resource::loadPixmap( "addressbook/fileimport"), QString::null, 0, this, 0); actionPersonal = a; connect( a, SIGNAL( activated() ), this, SLOT( importvCard() ) ); a->addTo( edit ); a = new QAction( tr("Export vCard"), Resource::loadPixmap( "addressbook/fileexport"), QString::null, 0, this, 0); actionPersonal = a; connect( a, SIGNAL( activated() ), this, SLOT( exportvCard() ) ); a->addTo( edit ); edit->insertSeparator(); a = new QAction( tr("My Personal Details"), Resource::loadPixmap( "addressbook/identity" ), QString::null, 0, this, 0 , TRUE ); actionPersonal = a; connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) ); a->addTo( edit ); #ifdef __DEBUG_RELEASE // Remove this function for public Release ! This is only // for debug purposes .. a = new QAction( tr( "Save all Data"), QString::null, 0, 0 ); connect( a, SIGNAL( activated() ), this , SLOT( slotSave() ) ); a->addTo( edit ); #endif a = new QAction( tr( "Config" ), Resource::loadPixmap( "SettingsIcon" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( slotConfig() ) ); a->addTo( edit ); // Create Views listContainer = new QWidget( this ); QVBoxLayout *vb = new QVBoxLayout( listContainer ); m_abView = new AbView( listContainer, m_config.orderList() ); vb->addWidget( m_abView ); // abList->setHScrollBarMode( QScrollView::AlwaysOff ); connect( m_abView, SIGNAL( signalViewSwitched ( int ) ), this, SLOT( slotViewSwitched( int ) ) ); QObject::connect( m_abView, SIGNAL(signalNotFound()), this, SLOT(slotNotFound()) ); - m_abView->load(); + // m_abView->load(); // Already done by c'tor . // Letter Picker pLabel = new LetterPicker( listContainer ); connect(pLabel, SIGNAL(letterClicked(char)), this, SLOT(slotSetLetter(char))); connect(m_abView, SIGNAL( signalClearLetterPicker() ), pLabel, SLOT( clear() ) ); vb->addWidget( pLabel ); // All Categories into view-menu.. populateCategories(); // Fontsize defaultFont = new QFont( m_abView->font() ); slotSetFont(m_config.fontSize()); m_curFontSize = m_config.fontSize(); setCentralWidget(listContainer); // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); isLoading = false; } void AddressbookWindow::slotConfig() { ConfigDlg* dlg = new ConfigDlg( this, "Config" ); dlg -> setConfig( m_config ); dlg -> showMaximized(); if ( dlg -> exec() ) { qWarning ("Config Dialog accepted!"); m_config = dlg -> getConfig(); if ( m_curFontSize != m_config.fontSize() ){ qWarning("Font was changed!"); m_curFontSize = m_config.fontSize(); emit slotSetFont( m_curFontSize ); } m_abView -> setListOrder( m_config.orderList() ); } delete dlg; } void AddressbookWindow::slotSetFont( int size ) { qWarning("void AddressbookWindow::slotSetFont( %d )", size); if (size > 2 || size < 0) size = 1; m_config.setFontSize( size ); QFont *currentFont; switch (size) { case 0: m_abView->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); currentFont = new QFont (m_abView->font()); // abList->resizeRows(currentFont->pixelSize() + 7); :SX // abList->resizeRows(); break; case 1: m_abView->setFont( *defaultFont ); currentFont = new QFont (m_abView->font()); // // abList->resizeRows(currentFont->pixelSize() + 7); // abList->resizeRows(); break; case 2: m_abView->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) ); currentFont = new QFont (m_abView->font()); // //abList->resizeRows(currentFont->pixelSize() + 7); // abList->resizeRows(); break; } } void AddressbookWindow::importvCard() { QString str = OFileDialog::getOpenFileName( 1,"/");//,"", "*", this ); if(!str.isEmpty() ){ setDocument((const QString&) str ); } } void AddressbookWindow::exportvCard() { qWarning(" void AddressbookWindow::exportvCard()"); QString filename = OFileDialog::getSaveFileName( 1,"/home/"); //,"", "*", this ); if( !filename.isEmpty() && ( filename[filename.length()-1] != '/' ) ){ qWarning(" Save to file %s, (%d)", filename.latin1(), filename.length()-1 ); OContact curCont = m_abView->currentEntry(); if ( !curCont.isEmpty() ){ OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, filename ); OContactAccess* access = new OContactAccess ( "addressbook_exp", QString::null , vcard_backend, true ); if ( access ){ access->add( curCont ); access->save(); } delete access; }else QMessageBox::critical( 0, "Export VCard", QString( tr( "You have to select a contact !") ) ); }else QMessageBox::critical( 0, "Export VCard", QString( tr( "You have to set a filename !") ) ); } void AddressbookWindow::setDocument( const QString &filename ) { qWarning( "void AddressbookWindow::setDocument( %s )", filename.latin1() ); if ( filename.find(".vcf") != int(filename.length()) - 4 ){ switch( QMessageBox::information( this, tr ( "Right file type ?" ), tr( "The selected file \n does not end with \".vcf\".\n Do you really want to open it?" ), tr( "&Yes" ), tr( "&No" ), QString::null, 0, // Enter == button 0 2 ) ) { // Escape == button 2 case 0: qWarning("YES clicked"); break; case 1: qWarning("NO clicked"); return; break; } } OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, filename ); OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); OContactAccess::List allList = access->allRecords(); qWarning( "Found number of contacts in File: %d", allList.count() ); if ( !allList.count() ) { QMessageBox::information( this, "Import VCard", "It was impossible to import\nthe VCard.\n" "The VCard may be corrupted!" ); } bool doAsk = true; OContactAccess::List::Iterator it; for ( it = allList.begin(); it != allList.end(); ++it ){ qWarning("Adding Contact from: %s", (*it).fullName().latin1() ); if ( doAsk ){ switch( QMessageBox::information( this, tr ( "Add Contact?" ), tr( "Do you really want add contact for \n%1?" ) .arg( (*it).fullName().latin1() ), tr( "&Yes" ), tr( "&No" ), tr( "&All Yes"), 0, // Enter == button 0 2 ) ) { // Escape == button 2 case 0: qWarning("YES clicked"); m_abView->addEntry( *it ); break; case 1: qWarning("NO clicked"); break; case 2: qWarning("YesAll clicked"); doAsk = false; break; } }else m_abView->addEntry( *it ); } delete access; } void AddressbookWindow::resizeEvent( QResizeEvent *e ) { QMainWindow::resizeEvent( e ); } AddressbookWindow::~AddressbookWindow() { ToolBarDock dock; int dummy; bool bDummy; getLocation ( listTools, dock, dummy, bDummy, dummy ); m_config.setToolBarDock( dock ); m_config.save(); } void AddressbookWindow::slotUpdateToolbar() { OContact ce = m_abView->currentEntry(); actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); } void AddressbookWindow::slotListNew() { OContact cnt; if( !syncing ) { editEntry( NewEntry ); } else { QMessageBox::warning(this, tr("Contacts"), tr("Can not edit data, currently syncing")); } } // void AddressbookWindow::slotListView() // { // m_abView -> init( abList->currentEntry() ); // // :SX mView->sync(); // //:SX showView(); // } void AddressbookWindow::slotListDelete() { if(!syncing) { OContact tmpEntry = m_abView ->currentEntry(); // get a name, do the best we can... QString strName = tmpEntry.fullName(); if ( strName.isEmpty() ) { strName = tmpEntry.company(); if ( strName.isEmpty() ) strName = "No Name"; } if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), strName ) ) { m_abView->removeEntry( tmpEntry.uid() ); } } else { QMessageBox::warning( this, tr("Contacts"), tr("Can not edit data, currently syncing") ); } } void AddressbookWindow::slotFindOpen() { searchBar->show(); m_abView -> inSearch(); searchEdit->setFocus(); } void AddressbookWindow::slotFindClose() { searchBar->hide(); m_abView -> offSearch(); // m_abView->setFocus(); } void AddressbookWindow::slotFind() { m_abView->slotDoFind( searchEdit->text(), m_config.beCaseSensitive(), m_config.useRegExp(), false); searchEdit->clearFocus(); // m_abView->setFocus(); } void AddressbookWindow::slotViewBack() { // :SX showList(); } void AddressbookWindow::slotViewEdit() { if(!syncing) { if (actionPersonal->isOn()) { editPersonal(); } else { editEntry( EditEntry ); } } else { QMessageBox::warning( this, tr("Contacts"), tr("Can not edit data, currently syncing") ); } } void AddressbookWindow::writeMail() { OContact c = m_abView -> currentEntry(); QString name = c.fileAs(); QString email = c.defaultEmail(); // I prefer the OPIE-Environment variable before the // QPE-one.. QString basepath = QString::fromLatin1( getenv("OPIEDIR") ); if ( basepath.isEmpty() ) basepath = QString::fromLatin1( getenv("QPEDIR") ); // Try to access the preferred. If not possible, try to // switch to the other one.. if ( m_config.useQtMail() ){ qWarning ("Accessing: %s", (basepath + "/bin/qtmail").latin1()); if ( QFile::exists( basepath + "/bin/qtmail" ) ){ qWarning ("QCop"); QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); e << name << email; return; } else m_config.setUseOpieMail( true ); } if ( m_config.useOpieMail() ){ qWarning ("Accessing: %s", (basepath + "/bin/mail").latin1()); if ( QFile::exists( basepath + "/bin/mail" ) ){ qWarning ("QCop"); QCopEnvelope e("QPE/Application/mail", "writeMail(QString,QString)"); e << name << email; return; } else m_config.setUseQtMail( true ); } } static const char * beamfile = "/tmp/obex/contact.vcf"; void AddressbookWindow::slotBeam() { QString beamFilename; OContact c; if ( actionPersonal->isOn() ) { beamFilename = addressbookPersonalVCardName(); if ( !QFile::exists( beamFilename ) ) return; // can't beam a non-existent file OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, beamFilename ); OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); OContactAccess::List allList = access->allRecords(); OContactAccess::List::Iterator it = allList.begin(); // Just take first c = *it; delete access; } else { unlink( beamfile ); // delete if exists mkdir("/tmp/obex/", 0755); c = m_abView -> currentEntry(); OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, beamfile ); OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); access->add( c ); access->save(); delete access; beamFilename = beamfile; } qWarning("Beaming: %s", beamFilename.latin1() ); Ir *ir = new Ir( this ); connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); QString description = c.fullName(); ir->send( beamFilename, description, "text/x-vCard" ); } void AddressbookWindow::beamDone( Ir *ir ) { delete ir; unlink( beamfile ); } static void parseName( const QString& name, QString *first, QString *middle, QString * last ) { int comma = name.find ( "," ); QString rest; if ( comma > 0 ) { *last = name.left( comma ); comma++; while ( comma < int(name.length()) && name[comma] == ' ' ) comma++; rest = name.mid( comma ); } else { int space = name.findRev( ' ' ); *last = name.mid( space+1 ); rest = name.left( space ); } int space = rest.find( ' ' ); if ( space <= 0 ) { *first = rest; } else { *first = rest.left( space ); *middle = rest.mid( space+1 ); } } void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) { bool needShow = FALSE; qWarning("Receiving QCop-Call with message %s", QString( msg ).latin1() ); if (msg == "editPersonal()") { editPersonal(); } else if (msg == "editPersonalAndClose()") { editPersonal(); close(); } else if ( msg == "addContact(QString,QString)" ) { QDataStream stream(data,IO_ReadOnly); QString name, email; stream >> name >> email; OContact cnt; QString fn, mn, ln; parseName( name, &fn, &mn, &ln ); // qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() ); cnt.setFirstName( fn ); cnt.setMiddleName( mn ); cnt.setLastName( ln ); cnt.insertEmails( email ); cnt.setDefaultEmail( email ); cnt.setFileAs(); m_abView -> addEntry( cnt ); // :SXm_abView()->init( cnt ); editEntry( EditEntry ); } else if ( msg == "beamBusinessCard()" ) { QString beamFilename = addressbookPersonalVCardName(); if ( !QFile::exists( beamFilename ) ) return; // can't beam a non-existent file Ir *ir = new Ir( this ); connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); QString description = "mycard.vcf"; ir->send( beamFilename, description, "text/x-vCard" ); } else if ( msg == "show(int)" ) { raise(); QDataStream stream(data,IO_ReadOnly); int uid; stream >> uid; qWarning( "Showing uid: %d" , uid ); // Deactivate Personal View.. if ( actionPersonal->isOn() ){ actionPersonal->setOn( false ); slotPersonalView(); } // Reset category and show as card.. m_abView -> setShowByCategory( QString::null ); m_abView -> setCurrentUid( uid ); slotViewSwitched ( AbView::CardView ); needShow = true; } else if ( msg == "edit(int)" ) { QDataStream stream(data,IO_ReadOnly); int uid; stream >> uid; // Deactivate Personal View.. if ( actionPersonal->isOn() ){ actionPersonal->setOn( false ); slotPersonalView(); } // Reset category and edit.. m_abView -> setShowByCategory( QString::null ); m_abView -> setCurrentUid( uid ); slotViewEdit(); } if (needShow) QPEApplication::setKeepRunning(); } void AddressbookWindow::editEntry( EntryMode entryMode ) { OContact entry; if ( !abEditor ) { abEditor = new ContactEditor( entry, this, "editor" ); } if ( entryMode == EditEntry ) abEditor->setEntry( m_abView -> currentEntry() ); else if ( entryMode == NewEntry ) abEditor->setEntry( entry ); // other things may change the caption. abEditor->setCaption( tr("Edit Address") ); #if defined(Q_WS_QWS) || defined(_WS_QWS_) abEditor->showMaximized(); #endif // fix the foxus... abEditor->setNameFocus(); if ( abEditor->exec() ) { setFocus(); if ( entryMode == NewEntry ) { OContact insertEntry = abEditor->entry(); insertEntry.assignUid(); m_abView -> addEntry( insertEntry ); m_abView -> setCurrentUid( insertEntry.uid() ); } else { OContact replEntry = abEditor->entry(); diff --git a/core/pim/addressbook/version.h b/core/pim/addressbook/version.h index 9621826..790aa95 100644 --- a/core/pim/addressbook/version.h +++ b/core/pim/addressbook/version.h @@ -1,10 +1,10 @@ #ifndef _VERSION_H_ #define _VERSION_H_ #define MAINVERSION "1" -#define SUBVERSION "0" +#define SUBVERSION "1" #define PATCHVERSION "0" #define APPNAME "OPIE_ADDRESSBOOK" #endif |