summaryrefslogtreecommitdiff
authoreilers <eilers>2002-10-27 16:18:51 (UTC)
committer eilers <eilers>2002-10-27 16:18:51 (UTC)
commitcc01384d8c2b421d5f455f32631d8c2ec4b7e844 (patch) (side-by-side diff)
tree0917ecf78c54b17620a583e584198881db24fee2
parent5f09fc992af19fc208315217eb46635a762f1e55 (diff)
downloadopie-cc01384d8c2b421d5f455f32631d8c2ec4b7e844.zip
opie-cc01384d8c2b421d5f455f32631d8c2ec4b7e844.tar.gz
opie-cc01384d8c2b421d5f455f32631d8c2ec4b7e844.tar.bz2
OContact now uses QDate to avoid wrong interpreted strings
A lot of inline functions moved into the library..
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/addressbook/abtable.cpp5
-rw-r--r--core/pim/addressbook/contacteditor.cpp34
2 files changed, 20 insertions, 19 deletions
diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp
index 4feadeb..5222f16 100644
--- a/core/pim/addressbook/abtable.cpp
+++ b/core/pim/addressbook/abtable.cpp
@@ -1,840 +1,841 @@
/**********************************************************************
** 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.
**
**********************************************************************/
#define QTOPIA_INTERNAL_CONTACT_MRE
#include <qpe/categoryselect.h>
#include <qpe/config.h>
#include <qpe/stringutil.h>
#include <qpe/qcopenvelope_qws.h>
+#include <qpe/timestring.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
static bool contactCompare( const OContact &cnt, const QRegExp &r, int category );
/*!
\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 );
}
/*!
\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 )
// #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR
// : QTable( 0, 0, parent, name, TRUE ),
// #else
: QTable( parent, name ),
// #endif
lastSortCol( -1 ),
asc( TRUE ),
intFields( order ),
currFindRow( -1 ),
mCat( 0 ),
m_inSearch (false),
m_contactdb ("addressbook", 0l, 0l, false) // Handle syncing myself.. !
{
mCat.load( categoryFileName() );
setSelectionMode( NoSelection );
init();
setSorting( TRUE );
connect( this, SIGNAL(clicked(int,int,int,const QPoint &)),
this, SLOT(itemClicked(int,int)) );
}
AbTable::~AbTable()
{
}
void AbTable::init()
{
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::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()
{
if ( sorting() ) {
if ( lastSortCol == -1 )
lastSortCol = 0;
sortColumn( lastSortCol, asc, TRUE );
//QMessageBox::information( this, "resort", "resort" );
updateVisible();
}
}
OContact AbTable::currentEntry()
{
OContact cnt;
AbTableItem *abItem;
abItem = static_cast<AbTableItem*>(item( currentRow(), 0 ));
if ( abItem ) {
cnt = contactList[abItem];
//cnt = contactList[currentRow()];
}
return cnt;
}
void AbTable::replaceCurrentEntry( const OContact &newContact )
{
int row = currentRow();
updateVisible();
journalFreeReplace( newContact, row );
}
void AbTable::deleteCurrentEntry()
{
int row = currentRow();
// a little wasteful, but it ensure's there is only one place
// where we delete.
journalFreeRemove( row );
updateVisible();
if ( numRows() == 0 )
emit empty( TRUE );
}
void AbTable::clear()
{
contactList.clear();
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 );
}
void AbTable::refresh()
{
int rows = numRows();
QString value;
AbTableItem *abi;
// hide columns so no flashing ?
if ( showBk == "Cards" ) {
hideColumn(0);
hideColumn(1);
}
for ( int r = 0; r < rows; ++r ) {
abi = static_cast<AbTableItem*>( item(r, 0) );
value = findContactContact( contactList[abi], r );
static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() );
}
resort();
}
void AbTable::keyPressEvent( QKeyEvent *e )
{
char key = toupper( e->ascii() );
if ( key >= 'A' && key <= 'Z' )
moveTo( key );
if ( m_inSearch ) {
// Running in seach-mode, therefore we will interprete
// some key differently
qWarning("Received key in search mode");
switch( e->key() ) {
case Qt::Key_Space:
case Qt::Key_Return:
case Qt::Key_Enter:
emit details();
break;
case Qt::Key_Up:
qWarning("a");
emit signalSearchBackward();
break;
case Qt::Key_Down:
qWarning("b");
emit signalSearchNext();
break;
default:
QTable::keyPressEvent( e );
}
} else {
qWarning("Received key in NON search mode");
switch( e->key() ) {
case Qt::Key_Space:
case Qt::Key_Return:
case Qt::Key_Enter:
emit details();
break;
default:
QTable::keyPressEvent( e );
}
}
}
void AbTable::moveTo( char c )
{
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() );
}
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;
}
QString AbTable::findContactContact( const OContact &entry, int /* row */ )
{
QString value;
value = "";
for ( QValueList<int>::ConstIterator it = intFields->begin();
it != intFields->end(); ++it ) {
switch ( *it ) {
default:
break;
case Qtopia::Title:
value = entry.title();
break;
case Qtopia::Suffix:
value = entry.suffix();
break;
case Qtopia::FileAs:
value = entry.fileAs();
break;
case Qtopia::DefaultEmail:
value = entry.defaultEmail();
case Qtopia::Emails:
value = entry.emails();
break;
case Qtopia::HomeStreet:
value = entry.homeStreet();
break;
case Qtopia::HomeCity:
value = entry.homeCity();
break;
case Qtopia::HomeState:
value = entry.homeState();
break;
case Qtopia::HomeZip:
value = entry.homeZip();
break;
case Qtopia::HomeCountry:
value = entry.homeCountry();
break;
case Qtopia::HomePhone:
value = entry.homePhone();
break;
case Qtopia::HomeFax:
value = entry.homeFax();
break;
case Qtopia::HomeMobile:
value = entry.homeMobile();
break;
case Qtopia::HomeWebPage:
value = entry.homeWebpage();
break;
case Qtopia::Company:
value = entry.company();
break;
case Qtopia::BusinessCity:
value = entry.businessCity();
break;
case Qtopia::BusinessStreet:
value = entry.businessStreet();
break;
case Qtopia::BusinessZip:
value = entry.businessZip();
break;
case Qtopia::BusinessCountry:
value = entry.businessCountry();
break;
case Qtopia::BusinessWebPage:
value = entry.businessWebpage();
break;
case Qtopia::JobTitle:
value = entry.jobTitle();
break;
case Qtopia::Department:
value = entry.department();
break;
case Qtopia::Office:
value = entry.office();
break;
case Qtopia::BusinessPhone:
value = entry.businessPhone();
break;
case Qtopia::BusinessFax:
value = entry.businessFax();
break;
case Qtopia::BusinessMobile:
value = entry.businessMobile();
break;
case Qtopia::BusinessPager:
value = entry.businessPager();
break;
case Qtopia::Profession:
value = entry.profession();
break;
case Qtopia::Assistant:
value = entry.assistant();
break;
case Qtopia::Manager:
value = entry.manager();
break;
case Qtopia::Spouse:
value = entry.spouse();
break;
case Qtopia::Gender:
value = entry.gender();
break;
case Qtopia::Birthday:
- value = entry.birthday();
+ value = TimeString::numberDateString( entry.birthday() );
break;
case Qtopia::Anniversary:
- value = entry.anniversary();
+ value = TimeString::numberDateString( entry.anniversary() );
break;
case Qtopia::Nickname:
value = entry.nickname();
break;
case Qtopia::Children:
value = entry.children();
break;
case Qtopia::Notes:
value = entry.notes();
break;
}
if ( !value.isEmpty() )
break;
}
return value;
}
void AbTable::addEntry( const OContact &newCnt )
{
int row = numRows();
setNumRows( row + 1 );
insertIntoTable( newCnt, row );
qWarning("abtable:AddContact");
m_contactdb.add ( newCnt );
setCurrentCell( row, 0 );
// updateVisible();
}
void AbTable::resizeRows() {
/*
if (numRows()) {
for (int i = 0; i < numRows(); i++) {
setRowHeight( i, size );
}
}
updateVisible();
*/
}
bool AbTable::save()
{
// QTime t;
// t.start();
qWarning("abtable:Save data");
return m_contactdb.save();
}
void AbTable::load()
{
setSorting( false );
setUpdatesEnabled( FALSE );
qWarning("abtable:Load data");
OContactAccess::List list = m_contactdb.allRecords();
OContactAccess::List::Iterator it;
setNumRows( list.count() );
int row = 0;
for ( it = list.begin(); it != list.end(); ++it )
insertIntoTable( *it, row++ );
setUpdatesEnabled( TRUE );
setSorting( true );
resort();
}
void AbTable::reload()
{
m_contactdb.reload();
load();
}
void AbTable::realignTable( int row )
{
QTableItem *ti1,
*ti2;
int totalRows = numRows();
for ( int curr = row; curr < totalRows - 1; curr++ ) {
// the same info from the todo list still applies, but I
// don't think it is _too_ bad.
ti1 = item( curr + 1, 0 );
ti2 = item( curr + 1, 1 );
takeItem( ti1 );
takeItem( ti2 );
setItem( curr, 0, ti1 );
setItem( curr, 1, ti2 );
}
setNumRows( totalRows - 1 );
resort();
}
// Add contact into table.
void AbTable::insertIntoTable( const OContact &cnt, int row )
{
QString strName,
strContact;
strName = findContactName( cnt );
strContact = findContactContact( cnt, row );
AbTableItem *ati;
ati = new AbTableItem( this, QTableItem::Never, strName, strContact);
contactList.insert( ati, cnt );
setItem( row, 0, ati );
ati = new AbTableItem( this, QTableItem::Never, strContact, strName);
setItem( row, 1, ati );
//### cannot do this; table only has two columns at this point
// setItem( row, 2, new AbPickItem( this ) );
// resort at some point?
}
// Replace or add an entry
void AbTable::journalFreeReplace( const OContact &cnt, int row )
{
QString strName,
strContact;
AbTableItem *ati = 0l;
strName = findContactName( cnt );
strContact = findContactContact( cnt, row );
ati = static_cast<AbTableItem*>(item(row, 0));
// Replace element if found in row "row"
// or add this element if not.
if ( ati != 0 ) { // replace
// :SX db access -> replace
qWarning ("Replace Contact in DB ! UID: %d", contactList[ati].uid() );
m_contactdb.replace ( cnt );
contactList.remove( ati );
ati->setItem( strName, strContact );
contactList.insert( ati, cnt );
ati = static_cast<AbTableItem*>(item(row, 1));
ati->setItem( strContact, strName );
}else{ // add
int myrows = numRows();
setNumRows( myrows + 1 );
insertIntoTable( cnt, myrows );
// gets deleted when returning -- Why ? (se)
// :SX db access -> add
qWarning ("Are you sure to add to database ? -> Currently disabled !!");
// m_contactdb.add( cnt );
}
}
// Remove entry
void AbTable::journalFreeRemove( int row )
{
AbTableItem *ati;
ati = static_cast<AbTableItem*>(item(row, 0));
if ( !ati )
return;
// :SX db access -> remove
qWarning ("Remove Contact from DB ! UID: %d",contactList[ati].uid() );
m_contactdb.remove( contactList[ati].uid() );
contactList.remove( ati );
realignTable( row );
}
#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::slotDoFind( const QString &findString, bool caseSensitive, bool useRegExp,
bool backwards, QString cat /* int category */ )
{
int category = 0;
// Use the current Category if nothing else selected
if ( cat.isEmpty() )
category = mCat.id( "Contacts", showCat );
else{
category = mCat.id("Contacts", cat );
}
qWarning ("Found in Category %d", category);
if ( currFindRow < -1 )
currFindRow = - 1;
clearSelection( TRUE );
int rows, row;
AbTableItem *ati;
QRegExp r( findString );
r.setCaseSensitive( caseSensitive );
r.setWildcard( !useRegExp );
rows = numRows();
static bool wrapAround = true;
bool try_again = false;
// We will loop until we found an entry or found nothing.
do {
if ( !backwards ) {
for ( row = currFindRow + 1; row < rows; row++ ) {
ati = static_cast<AbTableItem*>( item(row, 0) );
if ( contactCompare( contactList[ati], r, category ) ){
try_again = false;
break;
}
}
} else {
for ( row = currFindRow - 1; row > -1; row-- ) {
ati = static_cast<AbTableItem*>( item(row, 0) );
if ( contactCompare( contactList[ati], r, category ) ){
try_again = false;
break;
}
}
}
if ( row >= rows || row < 0 ) {
if ( row < 0 )
currFindRow = rows;
else
currFindRow = -1;
if ( wrapAround ){
emit signalWrapAround();
try_again = true;
}else{
emit signalNotFound();
try_again = false;
}
wrapAround = !wrapAround;
} else {
currFindRow = row;
QTableSelection foundSelection;
foundSelection.init( currFindRow, 0 );
foundSelection.expandTo( currFindRow, numCols() - 1 );
addSelection( foundSelection );
setCurrentCell( currFindRow, 0 /* numCols() - 1 */ );
wrapAround = true;
try_again = false;
}
} while ( try_again );
}
static bool contactCompare( const OContact &cnt, const QRegExp &r, int category )
{
bool returnMe;
QArray<int> cats;
cats = cnt.categories();
returnMe = false;
if ( (cats.count() == 0) || (category == 0) )
returnMe = cnt.match( r );
else {
int i;
for ( i = 0; i < int(cats.count()); i++ ) {
if ( cats[i] == category ) {
returnMe = cnt.match( r );
break;
}
}
}
return returnMe;
}
void AbTable::fitColumns()
{
int contentsWidth = visibleWidth() / 2;
if ( showBk == "Cards" ) {
showColumn(1);
//adjustColumn(1);
setColumnWidth( 1, visibleWidth() );
columnVisible = false;
} else {
if ( columnVisible == false ){
showColumn(0);
columnVisible = true;
}
setColumnWidth( 0, contentsWidth );
adjustColumn(1);
if ( columnWidth(1) < contentsWidth )
setColumnWidth( 1, contentsWidth );
}
}
void AbTable::show()
{
fitColumns();
QTable::show();
}
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();
}
void AbTable::itemClicked(int,int col)
{
if ( col == 2 ) {
return;
} else {
emit details();
}
}
QStringList AbTable::choiceNames() const
{
return choicenames;
}
void AbTable::setChoiceSelection(int /*index*/, const QStringList& /*list*/)
{
/* ######
QString selname = choicenames.at(index);
for (each row) {
OContact *c = contactForRow(row);
if ( list.contains(c->email) ) {
list.remove(c->email);
setText(row, 2, selname);
}
}
for (remaining list items) {
OContact *c = new contact(item);
setText(newrow, 2, selname);
}
*/
}
QStringList AbTable::choiceSelection(int /*index*/) const
{
QStringList r;
/* ######
diff --git a/core/pim/addressbook/contacteditor.cpp b/core/pim/addressbook/contacteditor.cpp
index 52ab0f2..e034b35 100644
--- a/core/pim/addressbook/contacteditor.cpp
+++ b/core/pim/addressbook/contacteditor.cpp
@@ -1,386 +1,387 @@
/*
* Copyright (c) 2002 Michael R. Crawford <mike@tuxnami.org>
+ * Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de)
*
* This file is an add-on for the OPIE 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 pacakaging
* 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.
*
*
* This is a rewrite of the abeditor.h file, modified to provide a more
* intuitive interface to TrollTech's original Address Book editor. This
* is made to operate exactly in interface with the exception of name.
*
*/
#include "contacteditor.h"
#include "addresspicker.h"
#include <qpe/categoryselect.h>
#include <qpe/qpeapplication.h>
#include <qpe/qpedialog.h>
#include <qpe/timeconversion.h>
#include <qcombobox.h>
#include <qlabel.h>
#include <qtabwidget.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qmultilineedit.h>
#include <qscrollview.h>
#include <qtoolbutton.h>
#include <qpushbutton.h>
#include <qmainwindow.h>
#include <qvaluelist.h>
#include <qpopupmenu.h>
#include <qlistbox.h>
static inline bool containsAlphaNum( const QString &str );
static inline bool constainsWhiteSpace( const QString &str );
// helper functions, convert our comma delimited list to proper
// file format...
void parseEmailFrom( const QString &txt, QString &strDefaultEmail,
QString &strAll );
// helper convert from file format to comma delimited...
void parseEmailTo( const QString &strDefaultEmail,
const QString &strOtherEmail, QString &strBack );
ContactEditor::ContactEditor( const OContact &entry,
const QValueList<int> *newOrderedValues,
QStringList *slNewOrdered,
QWidget *parent,
const char *name,
WFlags fl )
: QDialog( parent, name, TRUE, fl ),
orderedValues( newOrderedValues ),
slOrdered( *slNewOrdered ),
m_personalView ( false )
{
init();
initMap();
setEntry( entry );
qDebug("finish");
}
ContactEditor::~ContactEditor() {
}
void ContactEditor::init() {
useFullName = TRUE;
int i = 0;
/** SHut up and stop leaking
slHomeAddress = new QStringList;
slBusinessAddress = new QStringList;
slChooserNames = new QStringList;
slChooserValues = new QStringList;
slDynamicEntries = new QStringList;
*/
//*slDynamicEntries = *slOrdered;
QStringList trlChooserNames;
for (i = 0; i <= 6; i++) {
slHomeAddress.append( "" );
slBusinessAddress.append( "" );
}
{
hasGender = FALSE;
hasTitle = FALSE;
hasCompany = FALSE;
hasNotes = FALSE;
hasStreet = FALSE;
hasStreet2 = FALSE;
hasPOBox = FALSE;
hasCity = FALSE;
hasState = FALSE;
hasZip = FALSE;
hasCountry = FALSE;
QStringList::ConstIterator it = slOrdered.begin();
for ( i = 0; it != slOrdered.end(); i++, ++it ) {
if ( (*it) == "Business Fax" ) {
trlChooserNames.append( tr( "Business Fax" ) );
slChooserNames.append( *it );
slChooserValues.append("" );
//slDynamicEntries->remove( it );
continue;
}
if ( (*it) == "Home Fax" ) {
trlChooserNames.append( tr( "Home Fax" ) );
slChooserNames.append( *it );
slChooserValues.append("" );
//slDynamicEntries->remove( it );
continue;
}
if ( (*it) == "Business Phone" ) {
trlChooserNames.append( tr( "Business Phone" ) );
slChooserNames.append( *it );
slChooserValues.append( "" );
//slDynamicEntries->remove( it );
continue;
}
if ( (*it) == "Home Phone" ) {
trlChooserNames.append( tr( "Home Phone" ) );
slChooserNames.append( *it );
slChooserValues.append( "" );
//slDynamicEntries->remove( it );
continue;
}
/*
if ( (*it).right( 2 ) == tr( "IM" ) ) {
slChooserNames.append( *it );
slChooserValues.append( "" );
//slDynamicEntries->remove( it );
continue;
} */
if ( (*it) == "Business Mobile" ) {
trlChooserNames.append( tr( "Business Mobile" ) );
slChooserNames.append( *it );
slChooserValues.append( "" );
//slDynamicEntries->remove( it );
continue;
}
if ( (*it) == "Home Mobile" ) {
trlChooserNames.append( tr( "Home Mobile" ) );
slChooserNames.append( *it );
slChooserValues.append( "" );
//slDynamicEntries->remove( it );
continue;
}
if ( (*it) == "Business WebPage" ) {
trlChooserNames.append( tr( "Business WebPage" ) );
slChooserNames.append( *it );
slChooserValues.append( "" );
//slDynamicEntries->remove( it );
continue;
}
if ( (*it) == "Home Web Page" ) {
trlChooserNames.append( tr( "Home Web Page" ) );
slChooserNames.append( *it );
slChooserValues.append( "" );
//slDynamicEntries->remove( it );
continue;
}
if ( (*it) == "Business Pager" ) {
trlChooserNames.append( tr( "Business Pager" ) );
slChooserNames.append( *it );
slChooserValues.append( "" );
//slDynamicEntries->remove( it );
continue;
}
if ( *it == "Default Email" ) {
trlChooserNames.append( tr( "Default Email" ) );
slChooserNames.append( *it );
slChooserValues.append( "" );
//slDynamicEntries->remove( it );
continue;
}
if ( *it == "Emails" ) {
trlChooserNames.append( tr( "Emails" ) );
slChooserNames.append( *it );
slChooserValues.append( "" );
//slDynamicEntries->remove( it );
continue;
}
if ( *it == "Name Title" ||
*it == "First Name" ||
*it == "Middle Name" ||
*it == "Last Name" ||
*it == "File As" ||
*it == "Default Email" ||
*it == "Emails" ||
*it == "Groups" ||
*it == "Anniversary" ||
*it == "Birthday" )
continue;
if ( *it == "Name Title" ) {
//slDynamicEntries->remove( it );
continue;
}
if ( *it == "First Name" ) {
// slDynamicEntries->remove( it );
continue;
}
if ( *it == "Middle Name" ) {
// slDynamicEntries->remove( it );
continue;
}
if ( *it == "Last Name" ) {
// slDynamicEntries->remove( it );
continue;
}
if ( *it == "Suffix" ) {
// slDynamicEntries->remove( it );
continue;
}
if ( *it == "File As" ) {
// slDynamicEntries->remove( it );
continue;
}
if ( *it == "Gender" ) {
hasGender = TRUE;
// slDynamicEntries->remove( it );
continue;
}
if ( *it == "Job Title" ) {
hasTitle = TRUE;
// slDynamicEntries->remove( it );
continue;
}
if ( ( *it == "Company") || (*it == "Organization" ) ) {
hasCompany = TRUE;
// slDynamicEntries->remove( it );
continue;
}
if ( *it == "Notes" ) {
hasNotes = TRUE;
// slDynamicEntries->remove( it );
continue;
}
if ( *it == "Groups" ) {
// slDynamicEntries->remove( it );
continue;
}
if ( (*it) == "Business Street" ) {
hasStreet = TRUE;
// slDynamicEntries->remove( it );
continue;
}
if ( (*it) == "Home Street" ) {
hasStreet = TRUE;
// slDynamicEntries->remove( it );
continue;
}
/*
if ( (*it).right( 8 ) == tr( "Street 2" ) ) {
hasStreet2 = TRUE;
// slDynamicEntries->remove( it );
continue;
}
if ( (*it).right( 8 ) == tr( "P.O. Box" ) ) {
hasPOBox = TRUE;
// slDynamicEntries->remove( it );
continue;
} */
if ( (*it) == "Business City" ) {
hasCity = TRUE;
// slDynamicEntries->remove( it );
continue;
}
if ( (*it) == "Business State" ) {
hasState = TRUE;
// slDynamicEntries->remove( it );
continue;
}
if ( (*it) == "Business Zip" ) {
hasZip = TRUE;
// slDynamicEntries->remove( it );
continue;
}
if ( (*it) == "Business Country" ) {
hasCountry = TRUE;
// slDynamicEntries->remove( it );
continue;
}
if ( (*it) == "Home City" ) {
hasCity = TRUE;
// slDynamicEntries->remove( it );
continue;
}
if ( (*it) == "Home State" ) {
hasState = TRUE;
// slDynamicEntries->remove( it );
continue;
}
if ( (*it) == "Home Zip" ) {
hasZip = TRUE;
// slDynamicEntries->remove( it );
continue;
}
if ( (*it) == "Home Country" ) {
hasCountry = TRUE;
// slDynamicEntries->remove( it );
continue;
}
slDynamicEntries.append( *it );
}
}
QVBoxLayout *vb = new QVBoxLayout( this );
tabMain = new QTabWidget( this );
vb->addWidget( tabMain );
QWidget *tabViewport = new QWidget ( tabMain );
vb = new QVBoxLayout( tabViewport );
svGeneral = new QScrollView( tabViewport );
vb->addWidget( svGeneral, 0, 0 );
svGeneral->setResizePolicy( QScrollView::AutoOneFit );
svGeneral->setFrameStyle( QFrame::NoFrame );
QWidget *container = new QWidget( svGeneral->viewport() );
svGeneral->addChild( container );
QGridLayout *gl = new QGridLayout( container, 1, 1, 2, 4 );
gl->setResizeMode( QLayout::FreeResize );
btnFullName = new QPushButton( tr( "Full Name..." ), container );
gl->addWidget( btnFullName, 0, 0 );
txtFullName = new QLineEdit( container );
gl->addWidget( txtFullName, 0, 1 );
QLabel *l = new QLabel( tr( "Job Title" ), container );
gl->addWidget( l, 1, 0 );
@@ -727,1178 +728,1177 @@ void ContactEditor::init() {
svDetails->setResizePolicy( QScrollView::AutoOneFit );
svDetails->setFrameStyle( QFrame::NoFrame );
container = new QWidget( svDetails->viewport() );
svDetails->addChild( container );
gl = new QGridLayout( container, 1, 2, 2, 4 );
int counter = 0;
// Birthday
l = new QLabel( tr("Birthday"), container );
gl->addWidget( l, counter, 0 );
QPopupMenu* m1 = new QPopupMenu( container );
birthdayPicker = new DateBookMonth( m1, 0, TRUE );
m1->insertItem( birthdayPicker );
birthdayButton= new QToolButton( container, "buttonStart" );
birthdayButton->setPopup( m1 );
birthdayButton->setPopupDelay(0);
gl->addWidget( birthdayButton, counter , 1 );
connect( birthdayPicker, SIGNAL( dateClicked( int, int, int ) ),
this, SLOT( slotBirthdayDateChanged( int, int, int ) ) );
++counter;
// Anniversary
l = new QLabel( tr("Anniversary"), container );
gl->addWidget( l, counter, 0 );
m1 = new QPopupMenu( container );
anniversaryPicker = new DateBookMonth( m1, 0, TRUE );
m1->insertItem( anniversaryPicker );
anniversaryButton= new QToolButton( container, "buttonStart" );
anniversaryButton->setPopup( m1 );
anniversaryButton->setPopupDelay(0);
gl->addWidget( anniversaryButton, counter , 1 );
connect( anniversaryPicker, SIGNAL( dateClicked( int, int, int ) ),
this, SLOT( slotAnniversaryDateChanged( int, int, int ) ) );
++counter;
// Gender
l = new QLabel( tr("Gender"), container );
gl->addWidget( l, counter, 0 );
cmbGender = new QComboBox( container );
cmbGender->insertItem( "", 0 );
cmbGender->insertItem( tr("Male"), 1);
cmbGender->insertItem( tr("Female"), 2);
gl->addWidget( cmbGender, counter, 1 );
++counter;
// Create Labels and lineedit fields for every dynamic entry
QStringList::ConstIterator it = slDynamicEntries.begin();
for (i = counter; it != slDynamicEntries.end(); i++, ++it) {
l = new QLabel( QString::null , container );
listName.append( l );
gl->addWidget( l, i, 0 );
QLineEdit *e = new QLineEdit( container );
listValue.append( e );
gl->addWidget( e, i, 1);
}
// Fill labels with names..
loadFields();
tabMain->insertTab( tabViewport, tr( "Details" ) );
dlgNote = new QDialog( this, "Note Dialog", TRUE );
dlgNote->setCaption( tr("Enter Note") );
QVBoxLayout *vbNote = new QVBoxLayout( dlgNote );
txtNote = new QMultiLineEdit( dlgNote );
vbNote->addWidget( txtNote );
connect( btnNote, SIGNAL(clicked()), this, SLOT(slotNote()) );
dlgName = new QDialog( this, "Name Dialog", TRUE );
dlgName->setCaption( tr("Edit Name") );
gl = new QGridLayout( dlgName, 5, 2, 2, 3 );
l = new QLabel( tr("First Name"), dlgName );
gl->addWidget( l, 0, 0 );
txtFirstName = new QLineEdit( dlgName );
gl->addWidget( txtFirstName, 0, 1 );
l = new QLabel( tr("Middle Name"), dlgName );
gl->addWidget( l, 1, 0 );
txtMiddleName = new QLineEdit( dlgName );
gl->addWidget( txtMiddleName, 1, 1 );
l = new QLabel( tr("Last Name"), dlgName );
gl->addWidget( l, 2, 0 );
txtLastName = new QLineEdit( dlgName );
gl->addWidget( txtLastName, 2, 1 );
l = new QLabel( tr("Suffix"), dlgName );
gl->addWidget( l, 3, 0 );
txtSuffix = new QLineEdit( dlgName );
gl->addWidget( txtSuffix, 3, 1 );
space = new QSpacerItem(1,1,
QSizePolicy::Maximum,
QSizePolicy::MinimumExpanding );
gl->addItem( space, 4, 0 );
cmbChooserField1->insertStringList( trlChooserNames );
cmbChooserField2->insertStringList( trlChooserNames );
cmbChooserField3->insertStringList( trlChooserNames );
cmbChooserField4->insertStringList( trlChooserNames );
cmbChooserField1->setCurrentItem( 0 );
cmbChooserField2->setCurrentItem( 1 );
cmbChooserField3->setCurrentItem( 2 );
connect( btnFullName, SIGNAL(clicked()), this, SLOT(slotName()) );
connect( txtFullName, SIGNAL(textChanged(const QString &)), this, SLOT(slotFullNameChange(const QString &)) );
connect( txtChooserField1, SIGNAL(textChanged(const QString &)),
this, SLOT(slotChooser1Change(const QString &)) );
connect( txtChooserField2, SIGNAL(textChanged(const QString &)),
this, SLOT(slotChooser2Change(const QString &)) );
connect( txtChooserField3, SIGNAL(textChanged(const QString &)),
this, SLOT(slotChooser3Change(const QString &)) );
connect( txtChooserField4, SIGNAL(textChanged(const QString &)),
this, SLOT(slotChooser4Change(const QString &)) );
connect( txtAddress, SIGNAL(textChanged(const QString &)),
this, SLOT(slotAddressChange(const QString &)) );
//connect( txtAddress2, SIGNAL(textChanged(const QString &)), this, SLOT(slotAddress2Change(const QString &)) );
//connect( txtPOBox, SIGNAL(textChanged(const QString &)), this, SLOT(slotPOBoxChange(const QString &)) );
connect( txtCity, SIGNAL(textChanged(const QString &)),
this, SLOT(slotCityChange(const QString &)) );
connect( txtState, SIGNAL(textChanged(const QString &)),
this, SLOT(slotStateChange(const QString &)) );
connect( txtZip, SIGNAL(textChanged(const QString &)),
this, SLOT(slotZipChange(const QString &)) );
connect( cmbCountry, SIGNAL(textChanged(const QString &)),
this, SLOT(slotCountryChange(const QString &)) );
connect( cmbCountry, SIGNAL(activated(const QString &)),
this, SLOT(slotCountryChange(const QString &)) );
connect( cmbChooserField1, SIGNAL(activated(int)),
this, SLOT(slotCmbChooser1Change(int)) );
connect( cmbChooserField2, SIGNAL(activated(int)),
this, SLOT(slotCmbChooser2Change(int)) );
connect( cmbChooserField3, SIGNAL(activated(int)),
this, SLOT(slotCmbChooser3Change(int)) );
connect( cmbChooserField4, SIGNAL(activated(int)),
this, SLOT(slotCmbChooser4Change(int)) );
connect( cmbAddress, SIGNAL(activated(int)),
this, SLOT(slotAddressTypeChange(int)) );
new QPEDialogListener(this);
}
void ContactEditor::initMap()
{
/*
// since the fields and the XML fields exist, create a map
// between them...
Config cfg1( "AddressBook" );
Config cfg2( "AddressBook" );
QString strCfg1,
strCfg2;
int i;
// This stuff better exist...
cfg1.setGroup( "AddressFields" );
o cfg2.setGroup( "XMLFields" );
i = 0;
strCfg1 = cfg1.readEntry( "Field" + QString::number(i), QString::null );
strCfg2 = cfg2.readEntry( "XMLField" + QString::number(i++),
QString::null );
while ( !strCfg1.isNull() && !strCfg2.isNull() ) {
mapField.insert( strCfg1, strCfg2 );
strCfg1 = cfg1.readEntry( "Field" + QString::number(i),
QString::null );
strCfg2 = cfg2.readEntry( "XMLField" + QString::number(i++),
QString::null );
}
*/
}
void ContactEditor::slotChooser1Change( const QString &textChanged ) {
int index = cmbChooserField1->currentItem();
slChooserValues[index] = textChanged;
}
void ContactEditor::slotChooser2Change( const QString &textChanged ) {
int index = cmbChooserField2->currentItem();
slChooserValues[index] = textChanged;
}
void ContactEditor::slotChooser3Change( const QString &textChanged ) {
int index = cmbChooserField3->currentItem();
slChooserValues[index] = textChanged;
}
void ContactEditor::slotChooser4Change( const QString &textChanged ) {
int index = cmbChooserField4->currentItem();
slChooserValues[index] = textChanged;
}
void ContactEditor::slotAddressChange( const QString &textChanged ) {
if ( cmbAddress->currentItem() == 0 ) {
slBusinessAddress[0] = textChanged;
} else {
slHomeAddress[0] = textChanged;
}
}
void ContactEditor::slotAddress2Change( const QString &textChanged ) {
if ( cmbAddress->currentItem() == 0 ) {
slBusinessAddress[1] = textChanged;
} else {
slHomeAddress[1] = textChanged;
}
}
void ContactEditor::slotPOBoxChange( const QString &textChanged ) {
if ( cmbAddress->currentItem() == 0 ) {
slBusinessAddress[2] = textChanged;
} else {
slHomeAddress[2] = textChanged;
}
}
void ContactEditor::slotCityChange( const QString &textChanged ) {
if ( cmbAddress->currentItem() == 0 ) {
slBusinessAddress[3] = textChanged;
} else {
slHomeAddress[3] = textChanged;
}
}
void ContactEditor::slotStateChange( const QString &textChanged ) {
if ( cmbAddress->currentItem() == 0 ) {
slBusinessAddress[4] = textChanged;
} else {
slHomeAddress[4] = textChanged;
}
}
void ContactEditor::slotZipChange( const QString &textChanged ) {
if ( cmbAddress->currentItem() == 0 ) {
slBusinessAddress[5] = textChanged;
} else {
slHomeAddress[5] = textChanged;
}
}
void ContactEditor::slotCountryChange( const QString &textChanged ) {
if ( cmbAddress->currentItem() == 0 ) {
slBusinessAddress[6] = textChanged;
} else {
slHomeAddress[6] = textChanged;
}
}
void ContactEditor::slotCmbChooser1Change( int index ) {
txtChooserField1->setText( slChooserValues[index] );
txtChooserField1->setFocus();
}
void ContactEditor::slotCmbChooser2Change( int index ) {
txtChooserField2->setText( slChooserValues[index] );
txtChooserField2->setFocus();
}
void ContactEditor::slotCmbChooser3Change( int index ) {
txtChooserField3->setText( slChooserValues[index] );
txtChooserField3->setFocus();
}
void ContactEditor::slotCmbChooser4Change( int index ) {
txtChooserField4->setText( slChooserValues[index] );
txtChooserField4->setFocus();
}
void ContactEditor::slotAddressTypeChange( int index ) {
if ( index == 0 ) {
txtAddress->setText( slBusinessAddress[0] );
//txtAddress2->setText( (*slBusinessAddress)[1] );
//txtPOBox->setText( (*slBusinessAddress)[2] );
txtCity->setText( slBusinessAddress[3] );
txtState->setText( slBusinessAddress[4] );
txtZip->setText( slBusinessAddress[5] );
QLineEdit *txtTmp = cmbCountry->lineEdit();
txtTmp->setText( slBusinessAddress[6] );
} else {
txtAddress->setText( slHomeAddress[0] );
//txtAddress2->setText( (*slHomeAddress)[1] );
//txtPOBox->setText( (*slHomeAddress)[2] );
txtCity->setText( slHomeAddress[3] );
txtState->setText( slHomeAddress[4] );
txtZip->setText( slHomeAddress[5] );
QLineEdit *txtTmp = cmbCountry->lineEdit();
txtTmp->setText( slHomeAddress[6] );
}
}
void ContactEditor::slotFullNameChange( const QString &textChanged ) {
int index = cmbFileAs->currentItem();
cmbFileAs->clear();
cmbFileAs->insertItem( parseName( textChanged, 0 ) );
cmbFileAs->insertItem( parseName( textChanged, 1 ) );
cmbFileAs->insertItem( parseName( textChanged, 2 ) );
cmbFileAs->insertItem( parseName( textChanged, 3 ) );
cmbFileAs->setCurrentItem( index );
useFullName = TRUE;
}
// Loads the detail fields
void ContactEditor::loadFields() {
QStringList::ConstIterator it;
QListIterator<QLabel> lit( listName );
for ( it = slDynamicEntries.begin(); *lit; ++lit, ++it) {
if ( *it == "Department" )
(*lit)->setText( tr( "Department" ) );
if ( *it == "Company" )
(*lit)->setText( tr( "Company" ) );
if ( *it == "Office" )
(*lit)->setText( tr( "Office" ) );
if ( *it == "Profession" )
(*lit)->setText( tr( "Profession" ) );
if ( *it == "Assistant" )
(*lit)->setText( tr( "Assistant" ) );
if ( *it == "Manager" )
(*lit)->setText( tr( "Manager" ) );
if ( *it == "Spouse" )
(*lit)->setText( tr( "Spouse" ) );
if ( *it == "Nickname" )
(*lit)->setText( tr( "Nickname" ) );
if ( *it == "Children" )
(*lit)->setText( tr( "Children" ) );
}
- // Set DatePicker
- qWarning ("**Info: %s", ent.birthday().latin1() );
- if ( !ent.birthday().isEmpty() ){
- birthdayButton->setText( ent.birthday() );
- birthdayPicker->setDate( TimeConversion::fromString ( ent.birthday() ) );
- } else
- birthdayButton->setText( tr ("Unknown") );
-
- qWarning ("**Info: %s", ent.anniversary().latin1() );
- if ( !ent.anniversary().isEmpty() ){
- anniversaryButton->setText( ent.anniversary() );
- anniversaryPicker->setDate( TimeConversion::fromString ( ent.birthday() ) );
- } else
- anniversaryButton->setText( tr ("Unknown") );
}
void ContactEditor::accept() {
if ( isEmpty() ) {
cleanupFields();
reject();
} else {
saveEntry();
cleanupFields();
QDialog::accept();
}
}
void ContactEditor::slotNote() {
dlgNote->showMaximized();
if ( !dlgNote->exec() ) {
txtNote->setText( ent.notes() );
}
}
void ContactEditor::slotName() {
QString tmpName;
if (useFullName == TRUE) {
txtFirstName->setText( parseName(txtFullName->text(), NAME_F) );
txtMiddleName->setText( parseName(txtFullName->text(), NAME_M) );
txtLastName->setText( parseName(txtFullName->text(), NAME_L) );
txtSuffix->setText( parseName(txtFullName->text(), NAME_S) );
}
dlgName->showMaximized();
if ( dlgName->exec() ) {
tmpName = txtFirstName->text() + " " + txtMiddleName->text() + " " + txtLastName->text() + " " + txtSuffix->text();
txtFullName->setText( tmpName.simplifyWhiteSpace() );
slotFullNameChange( txtFullName->text() );
useFullName = FALSE;
}
}
void ContactEditor::setNameFocus() {
txtFullName->setFocus();
}
bool ContactEditor::isEmpty() {
// Test and see if the record should be saved.
// More strict than the original qtopia, needs name or fileas to save
QString t = txtFullName->text();
if ( !t.isEmpty() && containsAlphaNum( t ) )
return false;
t = cmbFileAs->currentText();
if ( !t.isEmpty() && containsAlphaNum( t ) )
return false;
return true;
}
QString ContactEditor::parseName( const QString fullName, int type ) {
QString simplifiedName( fullName.simplifyWhiteSpace() );
QString strFirstName;
QString strMiddleName;
QString strLastName;
QString strSuffix;
QString strTitle;
int commapos;
int spCount;
int spPos;
int spPos2;
commapos = simplifiedName.find( ',', 0, TRUE);
spCount = simplifiedName.contains( ' ', TRUE );
if ( commapos == -1 ) {
switch (spCount) {
case 0:
//return simplifiedName;
if (txtLastName->text() != "") {
strLastName = simplifiedName;
break;
}
if (txtMiddleName->text() != "") {
strMiddleName = simplifiedName;
break;
}
if (txtSuffix->text() != "") {
strSuffix = simplifiedName;
break;
}
strFirstName = simplifiedName;
break;
case 1:
spPos = simplifiedName.find( ' ', 0, TRUE );
strFirstName = simplifiedName.left( spPos );
strLastName = simplifiedName.mid( spPos + 1 );
break;
case 2:
spPos = simplifiedName.find( ' ', 0, TRUE );
strFirstName = simplifiedName.left( spPos );
spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
strMiddleName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
strLastName = simplifiedName.mid( spPos2 + 1 );
break;
case 3:
spPos = simplifiedName.find( ' ', 0, TRUE );
strFirstName = simplifiedName.left( spPos );
spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
strMiddleName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE );
strLastName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos2 );
strSuffix = simplifiedName.mid( spPos + 1 );
break;
case 4:
spPos = simplifiedName.find( ' ', 0, TRUE );
strTitle = simplifiedName.left( spPos );
spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
strFirstName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE );
strMiddleName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos2 );
spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
strLastName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
strSuffix = simplifiedName.mid( spPos2 + 1 );
break;
default:
spPos = simplifiedName.find( ' ', 0, TRUE );
strTitle = simplifiedName.left( spPos );
spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
strFirstName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE );
strMiddleName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos2 );
spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
strLastName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
strSuffix = simplifiedName.mid( spPos2 + 1 );
break;
}
} else {
simplifiedName.replace( commapos, 1, " " );
simplifiedName = simplifiedName.simplifyWhiteSpace();
switch (spCount) {
case 0:
//return simplifiedName;
if (txtLastName->text() != "") {
strLastName = simplifiedName;
break;
}
if (txtMiddleName->text() != "") {
strMiddleName = simplifiedName;
break;
}
if (txtSuffix->text() != "") {
strSuffix = simplifiedName;
break;
}
strFirstName = simplifiedName;
break;
case 1:
spPos = simplifiedName.find( ' ', 0, TRUE );
strLastName = simplifiedName.left( spPos );
strFirstName = simplifiedName.mid( spPos + 1 );
break;
case 2:
spPos = simplifiedName.find( ' ', 0, TRUE );
strLastName = simplifiedName.left( spPos );
spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
strFirstName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
strMiddleName = simplifiedName.mid( spPos2 + 1 );
break;
case 3:
spPos = simplifiedName.find( ' ', 0, TRUE );
strLastName = simplifiedName.left( spPos );
spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
strFirstName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE );
strMiddleName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos2 );
strSuffix = simplifiedName.mid( spPos + 1 );
break;
case 4:
spPos = simplifiedName.find( ' ', 0, TRUE );
strLastName = simplifiedName.left( spPos );
spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
strTitle = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE );
strFirstName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos2 );
spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
strMiddleName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
strSuffix = simplifiedName.mid( spPos2 + 1 );
break;
default:
spPos = simplifiedName.find( ' ', 0, TRUE );
strLastName = simplifiedName.left( spPos );
spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
strTitle = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE );
strFirstName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos );
spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
strMiddleName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
strSuffix = simplifiedName.mid( spPos2 + 1 );
break;
}
}
switch (type) {
case NAME_FL:
return strFirstName + " " + strLastName;
case NAME_LF:
return strLastName + ", " + strFirstName;
case NAME_LFM:
return strLastName + ", " + strFirstName + " " + strMiddleName;
case NAME_FMLS:
return strFirstName + " " + strMiddleName + " " + strLastName + " " + strSuffix;
case NAME_F:
return strFirstName;
case NAME_M:
return strMiddleName;
case NAME_L:
return strLastName;
case NAME_S:
return strSuffix;
}
return QString::null;
}
void ContactEditor::cleanupFields() {
QStringList::Iterator it = slChooserValues.begin();
for ( int i = 0; it != slChooserValues.end(); i++, ++it ) {
(*it) = "";
}
for ( int i = 0; i < 7; i++ ) {
slHomeAddress[i] = "";
slBusinessAddress[i] = "";
}
QStringList::ConstIterator cit;
QListIterator<QLineEdit> itLE( listValue );
for ( cit = slDynamicEntries.begin(); cit != slDynamicEntries.end(); ++cit, ++itLE) {
(*itLE)->setText( "" );
}
txtFirstName->setText("");
txtMiddleName->setText("");
txtLastName->setText("");
txtSuffix->setText("");
txtNote->setText("");
txtFullName->setText("");
txtJobTitle->setText("");
txtOrganization->setText("");
txtChooserField1->setText("");
txtChooserField2->setText("");
txtChooserField3->setText("");
txtAddress->setText("");
//txtAddress2->setText("");
txtCity->setText("");
//txtPOBox->setText("");
txtState->setText("");
txtZip->setText("");
QLineEdit *txtTmp = cmbCountry->lineEdit();
txtTmp->setText("");
txtTmp = cmbFileAs->lineEdit();
txtTmp->setText("");
}
void ContactEditor::setEntry( const OContact &entry ) {
cleanupFields();
ent = entry;
useFullName = FALSE;
txtFirstName->setText( ent.firstName() );
txtMiddleName->setText( ent.middleName() );
txtLastName->setText( ent.lastName() );
txtSuffix->setText( ent.suffix() );
QString *tmpString = new QString;
*tmpString = ent.firstName() + " " + ent.middleName() +
+ " " + ent.lastName() + " " + ent.suffix();
txtFullName->setText( tmpString->simplifyWhiteSpace() );
cmbFileAs->setEditText( ent.fileAs() );
if (hasTitle)
txtJobTitle->setText( ent.jobTitle() );
if (hasCompany)
txtOrganization->setText( ent.company() );
if (hasNotes)
txtNote->setText( ent.notes() );
if (hasStreet) {
slHomeAddress[0] = ent.homeStreet();
slBusinessAddress[0] = ent.businessStreet();
}
/*
if (hasStreet2) {
(*slHomeAddress)[1] = ent.homeStreet2();
(*slBusinessAddress)[1] = ent.businessStreet2();
}
if (hasPOBox) {
(*slHomeAddress)[2] = ent.homePOBox();
(*slBusinessAddress)[2] = ent.businessPOBox();
}
*/
if (hasCity) {
slHomeAddress[3] = ent.homeCity();
slBusinessAddress[3] = ent.businessCity();
}
if (hasState) {
slHomeAddress[4] = ent.homeState();
slBusinessAddress[4] = ent.businessState();
}
if (hasZip) {
slHomeAddress[5] = ent.homeZip();
slBusinessAddress[5] = ent.businessZip();
}
if (hasCountry) {
slHomeAddress[6] = ent.homeCountry();
slBusinessAddress[6] = ent.businessCountry();
}
QStringList::ConstIterator it;
QListIterator<QLineEdit> itLE( listValue );
for ( it = slDynamicEntries.begin(); it != slDynamicEntries.end(); ++it, ++itLE) {
if ( *it == "Department" )
(*itLE)->setText( ent.department() );
if ( *it == "Company" )
(*itLE)->setText( ent.company() );
if ( *it == "Office" )
(*itLE)->setText( ent.office() );
if ( *it == "Profession" )
(*itLE)->setText( ent.profession() );
if ( *it == "Assistant" )
(*itLE)->setText( ent.assistant() );
if ( *it == "Manager" )
(*itLE)->setText( ent.manager() );
if ( *it == "Spouse" )
(*itLE)->setText( ent.spouse() );
if ( *it == "Nickname" )
(*itLE)->setText( ent.nickname() );
if ( *it == "Children" )
(*itLE)->setText( ent.children() );
}
QStringList::Iterator itV;
for ( it = slChooserNames.begin(), itV = slChooserValues.begin(); it != slChooserNames.end(); ++it, ++itV ) {
if ( ( *it == "Business Phone") || ( *it == "Work Phone" ) )
*itV = ent.businessPhone();
/*
if ( *it == "Business 2 Phone" )
*itV = ent.business2Phone();
*/
if ( ( *it == "Business Fax") || ( *it == "Work Fax" ) )
*itV = ent.businessFax();
if ( ( *it == "Business Mobile" ) || ( *it == "work Mobile" ) )
*itV = ent.businessMobile();
/*
if ( *it == "Company Phone" )
*itV = ent.companyPhone();
*/
if ( *it == "Default Email" )
*itV = ent.defaultEmail();
if ( *it == "Emails" )
*itV = ent.emailList().join(", "); // :SX
if ( *it == "Home Phone" )
*itV = ent.homePhone();
/*
if ( *it == "Home 2 Phone" )
*itV = ent.home2Phone();
*/
if ( *it == "Home Fax" )
*itV = ent.homeFax();
if ( *it == "Home Mobile" )
*itV = ent.homeMobile();
/*
if ( *it == "Car Phone" )
*itV = ent.carPhone();
if ( *it == "ISDN Phone" )
*itV = ent.ISDNPhone();
if ( *it == "Other Phone" )
*itV = ent.otherPhone();
*/
if ( ( *it == "Business Pager" ) || ( *it == "Work Pager" ) )
*itV = ent.businessPager();
/*
if ( *it == "Home Pager")
*itV = ent.homePager();
if ( *it == "AIM IM" )
*itV = ent.AIMIM();
if ( *it == "ICQ IM" )
*itV = ent.ICQIM();
if ( *it == "Jabber IM" )
*itV = ent.jabberIM();
if ( *it == "MSN IM" )
*itV = ent.MSNIM();
if ( *it == "Yahoo IM" )
*itV = ent.yahooIM();
*/
if ( *it == "Home Web Page" )
*itV = ent.homeWebpage();
if ( ( *it == "Business WebPage" ) || ( *it == "Work Web Page" ) )
*itV = ent.businessWebpage();
}
cmbCat->setCategories( ent.categories(), "Contacts", tr("Contacts") );
QString gender = ent.gender();
cmbGender->setCurrentItem( gender.toInt() );
txtNote->setText( ent.notes() );
slotCmbChooser1Change( cmbChooserField1->currentItem() );
slotCmbChooser2Change( cmbChooserField2->currentItem() );
slotCmbChooser3Change( cmbChooserField3->currentItem() );
slotAddressTypeChange( cmbAddress->currentItem() );
- loadFields();
+ // loadFields(); :SX
+
+ // Set DatePicker
+ if ( !ent.birthday().isNull() ){
+ birthdayButton->setText( TimeString::numberDateString( ent.birthday() ) );
+ birthdayPicker->setDate( ent.birthday() );
+ } else
+ birthdayButton->setText( tr ("Unknown") );
+
+ if ( !ent.anniversary().isNull() ){
+ anniversaryButton->setText( TimeString::numberDateString( ent.anniversary() ) );
+ anniversaryPicker->setDate( ent.anniversary() );
+ } else
+ anniversaryButton->setText( tr ("Unknown") );
}
void ContactEditor::saveEntry() {
if ( useFullName == TRUE ) {
txtFirstName->setText( parseName( txtFullName->text(), NAME_F ) );
txtMiddleName->setText( parseName( txtFullName->text(), NAME_M ) );
txtLastName->setText( parseName( txtFullName->text(), NAME_L ) );
txtSuffix->setText( parseName( txtFullName->text(), NAME_S ) );
useFullName = FALSE;
}
/*if ( ent.firstName() != txtFirstName->text() ||
ent.lastName != txtLastName->text() ||
ent.middleName != txtMiddleName->text() ) {
*/
ent.setFirstName( txtFirstName->text() );
ent.setLastName( txtLastName->text() );
ent.setMiddleName( txtMiddleName->text() );
ent.setSuffix( txtSuffix->text() );
//}
ent.setFileAs( cmbFileAs->currentText() );
ent.setCategories( cmbCat->currentCategories() );
if (hasTitle)
ent.setJobTitle( txtJobTitle->text() );
if (hasCompany)
ent.setCompany( txtOrganization->text() );
if (hasNotes)
ent.setNotes( txtNote->text() );
if (hasStreet) {
ent.setHomeStreet( slHomeAddress[0] );
ent.setBusinessStreet( slBusinessAddress[0] );
}
/*
if (hasStreet2) {
ent.setHomeStreet2( (*slHomeAddress)[1] );
ent.setBusinessStreet2( (*slBusinessAddress)[1] );
}
if (hasPOBox) {
ent.setHomePOBox( (*slHomeAddress)[2] );
ent.setBusinessPOBox( (*slBusinessAddress)[2] );
}
*/
if (hasCity) {
ent.setHomeCity( slHomeAddress[3] );
ent.setBusinessCity( slBusinessAddress[3] );
}
if (hasState) {
ent.setHomeState( slHomeAddress[4] );
ent.setBusinessState( slBusinessAddress[4] );
}
if (hasZip) {
ent.setHomeZip( slHomeAddress[5] );
ent.setBusinessZip( slBusinessAddress[5] );
}
if (hasCountry) {
ent.setHomeCountry( slHomeAddress[6] );
ent.setBusinessCountry( slBusinessAddress[6] );
}
QStringList::ConstIterator it;
QListIterator<QLineEdit> itLE( listValue );
for ( it = slDynamicEntries.begin(); it != slDynamicEntries.end(); ++it, ++itLE) {
if ( *it == "Department" )
ent.setDepartment( (*itLE)->text() );
if ( *it == "Company" )
ent.setCompany( (*itLE)->text() );
if ( *it == "Office" )
ent.setOffice( (*itLE)->text() );
if ( *it == "Profession" )
ent.setProfession( (*itLE)->text() );
if ( *it == "Assistant" )
ent.setAssistant( (*itLE)->text() );
if ( *it == "Manager" )
ent.setManager( (*itLE)->text() );
if ( *it == "Spouse" )
ent.setSpouse( (*itLE)->text() );
if ( *it == "Nickname" )
ent.setNickname( (*itLE)->text() );
if ( *it == "Children" )
ent.setChildren( (*itLE)->text() );
}
QStringList::ConstIterator itV;
for ( it = slChooserNames.begin(), itV = slChooserValues.begin(); it != slChooserNames.end(); ++it, ++itV ) {
if ( ( *it == "Business Phone" ) || ( *it == "Work Phone" ) )
ent.setBusinessPhone( *itV );
/*
if ( *it == tr("Business 2 Phone" )
ent.setBusiness2Phone( *itV );
*/
if ( ( *it == "Business Fax" ) || ( *it == "Work Fax" ) )
ent.setBusinessFax( *itV );
if ( ( *it == "Business Mobile" ) || ( *it == "Work Mobile" ) )
ent.setBusinessMobile( *itV );
/*
if ( *it == "Company Phone" )
ent.setCompanyPhone( *itV );
*/
//if ( *it == "Default Email" )
//ent.setDefaultEmail( *itV );
if ( *it == "Emails" ){
QString allemail;
QString defaultmail;
parseEmailFrom( *itV, defaultmail, allemail );
// ent.clearEmails();
ent.setDefaultEmail( defaultmail );
ent.setEmails( allemail );
}
if ( *it == "Home Phone" )
ent.setHomePhone( *itV );
/*
if ( *it == "Home 2 Phone" )
ent.setHome2Phone( *itV );
*/
if ( *it == "Home Fax" )
ent.setHomeFax( *itV );
if ( *it == "Home Mobile" )
ent.setHomeMobile( *itV );
/*
if ( *it == "Car Phone" )
ent.setCarPhone( *itV );
if ( *it == "ISDN Phone" )
ent.setISDNPhone( *itV );
if ( *it == "Other Phone" )
ent.setOtherPhone( *itV );
*/
if ( ( *it == "Business Pager" ) || ( *it == "Work Pager" ) )
ent.setBusinessPager( *itV );
/*
if ( *it == "Home Pager" )
ent.setHomePager( *itV );
if ( *it == "AIM IM" )
ent.setAIMIM( *itV );
if ( *it == "ICQ IM" )
ent.setICQIM( *itV );
if ( *it == "Jabber IM" )
ent.setJabberIM( *itV );
if ( *it == "MSN IM" )
ent.setMSNIM( *itV );
if ( *it == "Yahoo IM" )
ent.setYahooIM( *itV );
*/
if ( *it == "Home Web Page" )
ent.setHomeWebpage( *itV );
if ( ( *it == "Business WebPage" ) || ( *it == "Work Web Page" ) )
ent.setBusinessWebpage( *itV );
}
int gender = cmbGender->currentItem();
ent.setGender( QString::number( gender ) );
QString str = txtNote->text();
if ( !str.isNull() )
ent.setNotes( str );
}
void parseEmailFrom( const QString &txt, QString &strDefaultEmail,
QString &strAll )
{
int where,
start;
if ( txt.isEmpty() )
return;
// find the first
where = txt.find( ',' );
if ( where < 0 ) {
strDefaultEmail = txt;
strAll = txt;
} else {
strDefaultEmail = txt.left( where ).stripWhiteSpace();
strAll = strDefaultEmail;
while ( where > -1 ) {
strAll.append(" ");
start = where;
where = txt.find( ',', where + 1 );
if ( where > - 1 )
strAll.append( txt.mid(start + 1, where - start - 1).stripWhiteSpace() );
else // grab until the end...
strAll.append( txt.right(txt.length() - start - 1).stripWhiteSpace() );
}
}
}
void parseEmailTo( const QString &strDefaultEmail,
const QString &strOtherEmail, QString &strBack )
{
// create a comma dilimeted set of emails...
// use the power of short circuiting...
bool foundDefault = false;
QString strTmp;
int start = 0;
int where;
// start at the beginng.
strBack = strDefaultEmail;
where = 0;
while ( where > -1 ) {
start = where;
where = strOtherEmail.find( ' ', where + 1 );
if ( where > 0 ) {
strTmp = strOtherEmail.mid( start, where - start ).stripWhiteSpace();
} else
strTmp = strOtherEmail.right( strOtherEmail.length() - start ).stripWhiteSpace();
if ( foundDefault || strTmp != strDefaultEmail ) {
strBack.append( ", " );
strBack.append( strTmp );
} else
foundDefault = true;
}
}
static inline bool containsAlphaNum( const QString &str )
{
int i,
count = str.length();
for ( i = 0; i < count; i++ )
if ( !str[i].isSpace() )
return TRUE;
return FALSE;
}
static inline bool constainsWhiteSpace( const QString &str )
{
int i,
count = str.length();
for (i = 0; i < count; i++ )
if ( str[i].isSpace() )
return TRUE;
return FALSE;
}
void ContactEditor::setPersonalView( bool personal )
{
m_personalView = personal;
if ( personal ){
cmbCat->hide();
labCat->hide();
} else{
cmbCat->show();
labCat->show();
}
}
void ContactEditor::slotAnniversaryDateChanged( int year, int month, int day)
{
QDate date;
date.setYMD( year, month, day );
QString dateString = TimeString::numberDateString( date );
anniversaryButton->setText( dateString );
- ent.setAnniversary ( dateString );
+ ent.setAnniversary ( date );
}
void ContactEditor::slotBirthdayDateChanged( int year, int month, int day)
{
QDate date;
date.setYMD( year, month, day );
QString dateString = TimeString::numberDateString( date );
birthdayButton->setText( dateString );
- ent.setBirthday ( dateString );
+ ent.setBirthday ( date );
}