smf/smfservermodule/smfclient/common/smfcontact.cpp
changeset 7 be09cf1f39dd
equal deleted inserted replaced
6:c39a6cfd1fb9 7:be09cf1f39dd
       
     1 /*
       
     2  * smfcontact.cpp
       
     3  *
       
     4  *  Created on: Apr 15, 2010
       
     5  *      Author: manasij
       
     6  */
       
     7 #include "smfcontact.h"
       
     8 #include <QFile>
       
     9 #include <QTextStream>
       
    10 
       
    11 
       
    12 	/**
       
    13 	 * Constructor with default argument
       
    14 	 * @param aParent The parent object
       
    15 	 */
       
    16 	SmfContact::SmfContact( QObject *aParent)//:QObject(aParent)
       
    17 	{
       
    18 		d = new SmfContactPrivate;
       
    19 	}
       
    20 	
       
    21 	/**
       
    22 	 * Copy Constructor
       
    23 	 * @param aOther The reference object
       
    24 	 */
       
    25 	SmfContact::SmfContact( const SmfContact &aOther ): d (aOther.d)
       
    26 		{
       
    27 		
       
    28 		}
       
    29 	
       
    30 	/**
       
    31 	 * Destructor
       
    32 	 */
       
    33 	SmfContact::~SmfContact( )
       
    34 		{
       
    35 		
       
    36 		}
       
    37 	QStringList SmfContact::subTypes( ) const
       
    38 			{
       
    39 		
       
    40 			}
       
    41 	
       
    42 	/**
       
    43 	 * Method to convert an SmfContact to a QContact
       
    44 	 * Changes made to the returned QContact will not be reflected 
       
    45 	 * in its parent SmfContact object
       
    46 	 * @param aContact QContact corresponding to SmfContact 
       
    47 	 */
       
    48 	void SmfContact::convert( QContact &aContact ) const
       
    49 			{
       
    50 		
       
    51 			}
       
    52 	
       
    53 	/**
       
    54 	 * Method to get the value of a sub field for this contact
       
    55 	 * @param aSubType The sub field type 
       
    56 	 * @return The value of the sub field subType
       
    57 	 * @see subTypes()
       
    58 	 */
       
    59 	QVariant SmfContact::value( const QString& aSubType ) const
       
    60 			{
       
    61 			if(d->m_details.contains(aSubType))
       
    62 				return d->m_details.value(aSubType);
       
    63 			else
       
    64 				return QString("Not found");
       
    65 			}
       
    66 	
       
    67 	void SmfContact::setValue(const QString& aSubType,QVariant& value)
       
    68 		{
       
    69 		d->m_details.insert(aSubType,value);
       
    70 		}
       
    71 	void SmfContact::writeLog(QString log) const
       
    72 		{
       
    73 		QFile file("c:\\data\\SmfClientLogs.txt");
       
    74 	    if (!file.open(QIODevice::Append | QIODevice::Text))
       
    75 		         return;
       
    76 	    QTextStream out(&file);
       
    77 	    out << log << "\n";
       
    78 	    file.close();
       
    79 
       
    80 		}
       
    81 	/**
       
    82 	 * Method for Externalization. Writes the SmfContact object to 
       
    83 	 * the stream and returns a reference to the stream.
       
    84 	 * @param aDataStream Stream to be written
       
    85 	 * @param aContact The SmfContact object to be externalized
       
    86 	 * @return reference to the written stream
       
    87 	 */
       
    88 	//TODO:-Need to revisit
       
    89 
       
    90 	QDataStream &operator<<( QDataStream &aDataStream, 
       
    91 			const SmfContact& aContact )
       
    92 		{
       
    93 		aContact.writeLog("smfContact::operator<<");
       
    94 		QVariant var = aContact.value("Name");
       
    95 		QContactName cn = var.value<QContactName>();
       
    96 		aDataStream<<cn;
       
    97 		return aDataStream;
       
    98 		
       
    99 		}
       
   100 
       
   101 	/**
       
   102 	 * Method for Internalization. Reads a SmfContact object from 
       
   103 	 * the stream and returns a reference to the stream.
       
   104 	 * @param aDataStream Stream to be read
       
   105 	 * @param aContact The SmfContact object to be internalized
       
   106 	 * @return reference to the stream
       
   107 	 */
       
   108 	
       
   109 	QDataStream &operator>>( QDataStream &aDataStream, 
       
   110 			SmfContact& aContact )
       
   111 		{
       
   112 		aContact.writeLog("smfContact::operator>>");
       
   113 		//explicitely adding fields for the classes that don't provide 
       
   114 		//internalizatio/externalization :(
       
   115 		QContactName name;
       
   116 		//QString name;
       
   117 		aDataStream>>name;
       
   118 		QVariant var = QVariant::fromValue(name);
       
   119 		aContact.setValue("Name",var);
       
   120 		return aDataStream;
       
   121 		}
       
   122 	QDataStream &operator<<( QDataStream &aDataStream, 
       
   123 			const QContactName &aContact )
       
   124 		{
       
   125 		//Qt mobility introduces API compatibility break
       
   126 #ifdef OLDER_QT_MOBILITY
       
   127 		aDataStream<<aContact.first();
       
   128 		aDataStream<<aContact.last();
       
   129 #else
       
   130 		
       
   131 		aDataStream<<aContact.firstName();
       
   132 		aDataStream<<aContact.lastName();
       
   133 #endif
       
   134 		return aDataStream;
       
   135 		}
       
   136 
       
   137 	QDataStream &operator>>( QDataStream &aDataStream, 
       
   138 			QContactName &aContact )
       
   139 		{
       
   140 		QString first;
       
   141 		QString last;
       
   142 		aDataStream>>first;
       
   143 #ifdef OLDER_QT_MOBILITY
       
   144 		aContact.setFirst(first);
       
   145 #else
       
   146 		aContact.setFirstName(first);
       
   147 #endif
       
   148 
       
   149 		aDataStream>>last;
       
   150 #ifdef OLDER_QT_MOBILITY
       
   151 		aContact.setLast(last);
       
   152 #else
       
   153 		aContact.setLastName(last);
       
   154 #endif
       
   155 		return aDataStream;
       
   156 		}