Source Code (Use browser search to find items of interest.)

Class Index

abbrowser'ContactEntry (./kdepim/abbrowser/entry.h:62)

class ContactEntry : public QObject
{
    Q_OBJECT

public:
/**
 * Creates a new ContactEntry object.
 */
  ContactEntry();
  ContactEntry( const ContactEntry &r );
  ContactEntry& operator=( const ContactEntry &r );

/**
 * Creates a ContactEntry object from data stored in a file.
 * 
 * Arguments:
 *
 * @param the name of the file.
 */
  ContactEntry( const QString &filename );

/**
 * Creates a ContactEntry object from data stored in a textstream.
 * 
 * Arguments:
 *
 * @param the name of the textstream.
 */
  ContactEntry( QTextStream &t );

/**
 * Returns a list of all custom fields, that is those beginning with
 * the prefix "X-CUSTOM-"
 */
  QStringList custom() const;

/**
 * Saves the entry to a file with the given filename.
 */
  void save( const QString &filename );

/**
 * Saves the entry to a text stream with the given filename.
 */
  void save( QTextStream &t );

/**
 * Loads the entry from a file with the given filename
 */
  void load( const QString &filename );

/**
 * Loads the entry from a text stream with the given filename
 */
  void load( QTextStream &t );

/**
 * Inserts a new key/value pair 
 */
  void insert( const QString key, const QString *value );

/**
 * Updates the value associated with a key. The old value
 * will be deleted.
 */
  void replace( const QString key, const QString *value );  

/**
 * Remove a key and deletes its associated value.
 */ 
  bool remove ( const QString key );

/**
 * Returns a const pointer to the value associated with a key.
 */
  const QString *find ( const QString & key ) const ;

/**
 * Returns a const pointer to the value associated with a key.
 */
  const QString *operator[] ( const QString & key ) const;

/**
 * Cause the changed signal to be emitted.
 */
  void touch();

/**
 * Remove all key/value pairs stored.
 */
  void clear();

signals:
/**
 * Emitted when key/value pair is updated or inserted
 */
  void changed();

private:
  QDict<QString> dict; // This unfortunately doesn't make a good base class
  // It's not derived from QOBject and the majority of methods are not virtual
};

abbrowser'ContactEntry::ContactEntry() (./kdepim/abbrowser/entry.cpp:77)

ContactEntry::ContactEntry() 
{
  dict.setAutoDelete( true );
}


abbrowser'ContactEntry::ContactEntry() (./kdepim/abbrowser/entry.cpp:82)

ContactEntry::ContactEntry( const ContactEntry &r )
  : QObject()
{
  QDictIterator<QString> it( r.dict );
  
  while ( it.current() ) {
    dict.replace( it.currentKey(), new QString( *it.current() ));
    ++it;
  }
}


abbrowser'ContactEntry::ContactEntry() (./kdepim/abbrowser/entry.cpp:107)

ContactEntry::ContactEntry( const QString &filename )
{
  dict.setAutoDelete( true );
  load( filename );
}


abbrowser'ContactEntry::ContactEntry() (./kdepim/abbrowser/entry.cpp:113)

ContactEntry::ContactEntry( QTextStream &t )
{
  dict.setAutoDelete( true );
  load( t );
}


abbrowser'ContactEntry::custom() (./kdepim/abbrowser/entry.cpp:119)

QStringList ContactEntry::custom() const
{
  QStringList result;
  QDictIterator<QString> it( dict );

  while ( it.current() ) {
    if (it.currentKey().find( "X-CUSTOM-", 0 ) == 0)
      result << it.currentKey();
    ++it;
  }
  return result;
}


abbrowser'ContactEntry::save() (./kdepim/abbrowser/entry.cpp:132)

void ContactEntry::save( const QString &filename )
{
  QFile f( filename );
  if ( !f.open( IO_WriteOnly ) )
    return;

  QTextStream t( &f );
  QDictIterator<QString> it( dict );

  while ( it.current() ) {
    if (it.currentKey().find( ".", 0 ) != 0) {
      t << it.currentKey() << "\n";
      t << *it.current() << "\n[EOR]\n";
    }
    ++it;
  }
  t << "[EOS]\n";
  f.close();
}


abbrowser'ContactEntry::save() (./kdepim/abbrowser/entry.cpp:152)

void ContactEntry::save( QTextStream &t )
{
  QDictIterator<QString> it( dict );

  while ( it.current() ) {
    if (it.currentKey().find( ".", 0 ) != 0) {
      t << it.currentKey() << "\n";
      t << *it.current() << "\n[EOR]\n";
    }
    ++it;
  }
  t << "[EOS]\n";
}


abbrowser'ContactEntry::load() (./kdepim/abbrowser/entry.cpp:166)

void ContactEntry::load( const QString &filename )
{
  dict.clear();

  QFile f( filename );
  if ( !f.open( IO_ReadOnly ) )
    return;

  QTextStream t( &f );

  while ( !t.eof() ) {
    QString name = t.readLine();
    if (name == "[EOS]")
      break;
    QString tmp = t.readLine();
    QString value = "";
    while (tmp != QString( "\n[EOR]" )) {
      value += tmp;
      tmp = "\n" + t.readLine();
    }
    if ((name != "") && (value != ""))
      dict.replace( name, new QString( value ));
  }
  f.close();
  emit changed();
}


abbrowser'ContactEntry::load() (./kdepim/abbrowser/entry.cpp:193)

void ContactEntry::load( QTextStream &t )
{
  while (!t.eof()) {
    QString name = t.readLine();
    if (name == "[EOS]")
      break;
    QString tmp = t.readLine();
    QString value = "";
    while (tmp != QString( "\n[EOR]" )) {
      value += tmp;
      tmp = "\n" + t.readLine();
    }
    if ((name != "") && (value != ""))
      dict.replace( name, new QString( value ));
  }
  emit changed();
}


abbrowser'ContactEntry::insert() (./kdepim/abbrowser/entry.cpp:211)

void ContactEntry::insert( const QString key, const QString *item )
{
  if (item && (*item == ""))
    return;
  dict.insert( key, item );
  emit changed();
}


abbrowser'ContactEntry::replace() (./kdepim/abbrowser/entry.cpp:219)

void ContactEntry::replace( const QString key, const QString *item )
{
  QString *current = dict.find( key );
  if (item) {
    if (current) {
      if (*item != *current) {
	if (*item == "")
	  dict.remove( key ); // temporary?
	else
	  dict.replace( key, item );
	emit changed();
      }
    }
    else { // (item && !current)
      dict.replace( key, item );
      emit changed();
    }
  }
  else
    debug( QString( "Error:" ) + 
	   " ContactEntry::replace( const QString, const QString* ) " +
	   "passed null item" );
  /*
  if (item && (*item == ""))
    dict.remove( key );
  else
    dict.replace( key, item );
  emit changed();
  */
}


abbrowser'ContactEntry::remove() (./kdepim/abbrowser/entry.cpp:250)

bool ContactEntry::remove( const QString key )
{
  if (dict.remove( key ))
    emit changed();
}


abbrowser'ContactEntry::touch() (./kdepim/abbrowser/entry.cpp:256)

void ContactEntry::touch()
{
  emit changed();
}


abbrowser'ContactEntry::find() (./kdepim/abbrowser/entry.cpp:261)

const QString *ContactEntry::find ( const QString & key ) const
{
  return dict.find( key );
}


abbrowser'ContactEntry::clear() (./kdepim/abbrowser/entry.cpp:271)

void ContactEntry::clear ()
{
  dict.clear();
  emit changed();
}