-rw-r--r-- | core/pim/addressbook/abtable.cpp | 11 | ||||
-rw-r--r-- | core/pim/addressbook/abtable.h | 1 | ||||
-rw-r--r-- | core/pim/addressbook/addressbook.cpp | 8 |
3 files changed, 20 insertions, 0 deletions
diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp index 0911edf..17277b4 100644 --- a/core/pim/addressbook/abtable.cpp +++ b/core/pim/addressbook/abtable.cpp @@ -1,68 +1,70 @@ /********************************************************************** ** 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 <qasciidict.h> #include <qdatetime.h> #include <qfile.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 Contact &cnt, const QRegExp &r, int category ); //### qtmail/addresslist.cpp hardcodes this filename as well static QString journalFileName() { QString str = getenv("HOME"); str +="/.abjournal"; return str; } /*! \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; } @@ -404,96 +406,105 @@ QString AbTable::findContactContact( const Contact &entry ) 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(); break; case Qtopia::Anniversary: value = 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 Contact &newCnt ) { int row = numRows(); setNumRows( row + 1 ); updateJournal( newCnt, Contact::ACTION_ADD ); insertIntoTable( newCnt, row ); setCurrentCell( row, 0 ); updateVisible(); } +void AbTable::resizeRows( int size ) { + + if (numRows()) { + for (int i = 0; i < numRows(); i++) { + setRowHeight( i, size ); + } + } +} + void AbTable::updateJournal( const Contact &cnt, Contact::journal_action action, int row ) { QFile f( journalFileName() ); if ( !f.open(IO_WriteOnly|IO_Append) ) return; QString buf; QCString str; buf = "<Contact "; cnt.save( buf ); buf += " action=\"" + QString::number( (int)action ) + "\" "; if ( action == Contact::ACTION_REMOVE || action == Contact::ACTION_REPLACE) buf += " actionrow=\"" + QString::number(row) + "\" "; buf += "/>\n"; QCString cstr = buf.utf8(); f.writeBlock( cstr.data(), cstr.length() ); QCopEnvelope( "QPE/PIM", "addressbookUpdated()" ); } bool AbTable::save( const QString &fn ) { // QTime t; // t.start(); QString strNewFile = fn + ".new"; QFile f( strNewFile ); if ( !f.open( IO_WriteOnly|IO_Raw ) ) return false; int total_written; QString out; out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" " <Groups>\n" " </Groups>\n" " <Contacts>\n"; QMapIterator<AbTableItem*, Contact> it; for ( it = contactList.begin(); it != contactList.end(); ++it ) { out += "<Contact "; it.data().save( out ); out += "/>\n"; QCString cstr = out.utf8(); total_written = f.writeBlock( cstr.data(), cstr.length() ); if ( total_written != int(cstr.length()) ) { f.close(); QFile::remove( strNewFile ); return false; } out = ""; diff --git a/core/pim/addressbook/abtable.h b/core/pim/addressbook/abtable.h index 9b96997..53635ee 100644 --- a/core/pim/addressbook/abtable.h +++ b/core/pim/addressbook/abtable.h @@ -41,96 +41,97 @@ public: void setItem( const QString &txt, const QString &secondKey ); private: QString sortKey; }; class AbPickItem : public QTableItem { public: AbPickItem( QTable *t ); QWidget *createEditor() const; void setContentFromEditor( QWidget *w ); private: QGuardedPtr<QComboBox> cb; }; class AbTable : public QTable { Q_OBJECT public: AbTable( const QValueList<int> *ordered, QWidget *parent, const char *name=0 ); ~AbTable(); // NEW void addEntry( const Contact &newContact ); Contact currentEntry(); void replaceCurrentEntry( const Contact &newContact ); void init(); void deleteCurrentEntry(); void clear(); void clearFindRow() { currFindRow = -2; } void loadFields(); void refresh(); bool save( const QString &fn ); void load( const QString &fn ); // addresspicker mode void setChoiceNames( const QStringList& list); QStringList choiceNames() const; void setChoiceSelection(int index, const QStringList& list); QStringList choiceSelection(int index) const; void setShowCategory( const QString &c ); QString showCategory() const; QStringList categories(); + void resizeRows( int size ); void show(); void setPaintingEnabled( bool e ); public slots: void slotDoFind( const QString &str, bool caseSensitive, bool backwards, int category ); signals: void empty( bool ); void details(); void signalNotFound(); void signalWrapAround(); 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 loadFile( const QString &strFile, bool journalFile ); void fitColumns(); void resort(); void updateJournal( const Contact &contact, Contact::journal_action action, int row = -1 ); void insertIntoTable( const Contact &contact, int row ); void internalAddEntries( QList<Contact> &list ); QString findContactName( const Contact &entry ); QString findContactContact( const Contact &entry ); void journalFreeReplace( const Contact &cnt, int row ); void journalFreeRemove( int row ); void realignTable( int ); void updateVisible(); int lastSortCol; bool asc; QMap<AbTableItem*, Contact> contactList; const QValueList<int> *intFields; int currFindRow; QString showCat; QStringList choicenames; diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp index b7b35bc..95a8521 100644 --- a/core/pim/addressbook/addressbook.cpp +++ b/core/pim/addressbook/addressbook.cpp @@ -192,114 +192,122 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, abList->setHScrollBarMode( QScrollView::AlwaysOff ); connect( abList, SIGNAL( empty( bool ) ), this, SLOT( listIsEmpty( bool ) ) ); connect( abList, SIGNAL( details() ), this, SLOT( slotListView() ) ); connect( abList, SIGNAL(currentChanged(int,int)), this, SLOT(slotUpdateToolbar()) ); mView = 0; abList->load( addressbookXMLFilename() ); if ( QFile::exists(addressbookOldXMLFilename()) ) { abList->load( addressbookOldXMLFilename() ); QFile::remove(addressbookOldXMLFilename()); } catMenu = new QPopupMenu( this ); catMenu->setCheckable( TRUE ); connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); populateCategories(); mbList->insertItem( tr("View"), catMenu ); setCentralWidget( abList ); fontMenu = new QPopupMenu(this); fontMenu->setCheckable( true ); connect( fontMenu, SIGNAL(activated(int)), this, SLOT(slotSetFont(int))); fontMenu->insertItem("Small", 0); fontMenu->insertItem("Normal", 1); fontMenu->insertItem("Large", 2); defaultFont = new QFont( abList->font() ); slotSetFont(startFontSize); mbList->insertItem( tr("Font"), fontMenu); setCentralWidget(abList); // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); } void AddressbookWindow::slotSetFont( int size ) { if (size > 2 || size < 0) size = 1; startFontSize = size; + QFont *currentFont; + switch (size) { case 0: fontMenu->setItemChecked(0, true); fontMenu->setItemChecked(1, false); fontMenu->setItemChecked(2, false); abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); + currentFont = new QFont (abList->font()); + abList->resizeRows(currentFont->pixelSize() + 7); break; case 1: fontMenu->setItemChecked(0, false); fontMenu->setItemChecked(1, true); fontMenu->setItemChecked(2, false); abList->setFont( *defaultFont ); + currentFont = new QFont (abList->font()); + abList->resizeRows(currentFont->pixelSize() + 7); break; case 2: fontMenu->setItemChecked(0, false); fontMenu->setItemChecked(1, false); fontMenu->setItemChecked(2, true); abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) ); + currentFont = new QFont (abList->font()); + abList->resizeRows(currentFont->pixelSize() + 7); break; } } void AddressbookWindow::setDocument( const QString &filename ) { if ( filename.find(".vcf") != int(filename.length()) - 4 ) return; QValueList<Contact> cl = Contact::readVCard( filename ); for( QValueList<Contact>::Iterator it = cl.begin(); it != cl.end(); ++it ) { // QString msg = tr("You received a vCard for\n%1.\nDo You want to add it to your\naddressbook?") // .arg( (*it).fullName() ); // if ( QMessageBox::information( this, tr("received contact"), msg, QMessageBox::Ok, QMessageBox::Cancel ) == // QMessageBox::Ok ) { abList->addEntry( *it ); // } } } void AddressbookWindow::resizeEvent( QResizeEvent *e ) { QMainWindow::resizeEvent( e ); if ( centralWidget() == abList ) showList(); else if ( centralWidget() == mView ) showView(); } AddressbookWindow::~AddressbookWindow() { Config cfg("AddressBook"); cfg.setGroup("Font"); cfg.writeEntry("fontSize", startFontSize); } void AddressbookWindow::slotUpdateToolbar() { Contact ce = abList->currentEntry(); actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); } void AddressbookWindow::showList() { if ( mView ) mView->hide(); setCentralWidget( abList ); |