contentstorage/caclient/src/caentry.cpp
branchRCL_3
changeset 113 0efa10d348c0
equal deleted inserted replaced
111:053c6c7c14f3 113:0efa10d348c0
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: caentry.cpp
       
    15  *
       
    16  */
       
    17 
       
    18 #include <QSharedDataPointer>
       
    19 #include <QDebug>
       
    20 #include <HbIcon>
       
    21 
       
    22 #include "caentry.h"
       
    23 #include "caentry_p.h"
       
    24 #include "caobjectadapter.h"
       
    25 #include "caiconcache.h"
       
    26 #include "caclienttest_global.h"
       
    27 #include "camenuiconutility.h"
       
    28 
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 /*!
       
    33  \class CaEntry
       
    34  \brief This abstract class describes particular entry.
       
    35  To create instance of CaEntry object, you have to use service's object's
       
    36  createEntry() method.
       
    37  \example
       
    38  \code
       
    39  QSharedPointer<CaService> service = CaService::instance();
       
    40  // default you create item (ItemEntryRole)
       
    41  CaEntry entry;
       
    42  // to create CaEntry invoking setText() and setEntryTypeName() methods
       
    43  is obligatoried
       
    44  entry.setText("Text");
       
    45  entry.setEntryTypeName("TypeName");
       
    46  CaEntry * resultEntry = service->createEntry(entry);
       
    47  ...
       
    48  delete resultEntry;
       
    49  ...
       
    50  // if you want create group, you should use entry role parametr
       
    51  CaEntry entryGroup(GroupEntryRole);
       
    52  ...
       
    53  resultEntry = service->createEntry(entryGroup);
       
    54  \endcode
       
    55  */
       
    56 
       
    57 /*!
       
    58  \var CaEntryPrivate::m_q
       
    59  Points to the CaEntry instance that uses
       
    60  this private implementation.
       
    61  */
       
    62 
       
    63 /*!
       
    64  \var CaEntryPrivate::mId
       
    65  Id.
       
    66  */
       
    67 
       
    68 /*!
       
    69  Constructor.
       
    70  \param entryRole entry's role.
       
    71  */
       
    72 CaEntry::CaEntry(EntryRole entryRole) :
       
    73     m_d(new CaEntryPrivate(this))
       
    74 {
       
    75     m_d->setRole(entryRole);
       
    76 }
       
    77 
       
    78 /*!
       
    79  Copy constructor.
       
    80  \param entry const reference to CaEntry.
       
    81  \code
       
    82  ...
       
    83  CaEntry * copyEntry( *resultEntry );
       
    84  \endcode
       
    85  */
       
    86 CaEntry::CaEntry(const CaEntry &entry) :
       
    87     m_d(new CaEntryPrivate(this))
       
    88 {
       
    89     *m_d = *(entry.m_d);
       
    90 }
       
    91 
       
    92 /*!
       
    93  Copy assignment operator.
       
    94  \param entry const reference to CaEntry.
       
    95 
       
    96  \retval reference to CaEntry.
       
    97 
       
    98  \code
       
    99  ...
       
   100  CaEntry * copyEntry;
       
   101  copyEntry = resultEntry;
       
   102  \endcode
       
   103  */
       
   104 CaEntry &CaEntry::operator=(const CaEntry &entry)
       
   105 {
       
   106     if (this != &entry) {
       
   107         m_d = entry.m_d;
       
   108     }
       
   109     return *this;
       
   110 }
       
   111 
       
   112 /*!
       
   113  Destructor.
       
   114  */
       
   115 CaEntry::~CaEntry()
       
   116 {
       
   117 
       
   118 }
       
   119 
       
   120 /*!
       
   121  Returns item id.
       
   122  \retval item id.
       
   123 
       
   124  \code
       
   125  ...
       
   126  // after create entry, we can get entry's id
       
   127  resultEntry = service->createEntry(entry);
       
   128  int entryId = resultEntry->id();
       
   129  ...
       
   130  \endcode
       
   131  */
       
   132 int CaEntry::id() const
       
   133 {
       
   134     return m_d->id();
       
   135 }
       
   136 
       
   137 /*!
       
   138  Returns item name.
       
   139  \retval name of the item.
       
   140 
       
   141  \code
       
   142  ...
       
   143  QString entryText = resultEntry->text();
       
   144  ...
       
   145  \endcode
       
   146  */
       
   147 QString CaEntry::text() const
       
   148 {
       
   149     return m_d->text();
       
   150 }
       
   151 
       
   152 /*!
       
   153  Sets localized name of the item.
       
   154  \param text new name of the item.
       
   155  \param localized set to true if its localized
       
   156 
       
   157  \code
       
   158  ...
       
   159  QString entryText( QString("EntryText") );
       
   160  resultEntry->setText( entryText, true);
       
   161  ...
       
   162  \endcode
       
   163  */
       
   164 void CaEntry::setText(const QString &text, bool localized)
       
   165 {
       
   166     m_d->setText(text, localized);
       
   167 }
       
   168 
       
   169 /*!
       
   170 Returns item description.
       
   171 \retval description of the item.
       
   172 
       
   173 \code
       
   174 ...
       
   175 QString entryDescription = resultEntry->description();
       
   176 ...
       
   177 \endcode
       
   178 */
       
   179 QString CaEntry::description() const
       
   180 {
       
   181     return m_d->description();
       
   182 }
       
   183 
       
   184 
       
   185 /*!
       
   186 Sets localized description of the item.
       
   187 \param new description of the item.
       
   188 
       
   189 \code
       
   190 ...
       
   191 QString entryDescription( QString("EntryDescription") );
       
   192 resultEntry->entryDescription(entryDescription);
       
   193 ...
       
   194 \endcode
       
   195 */
       
   196 void CaEntry::setDescription(const QString &description,
       
   197         bool localized)
       
   198 {
       
   199     m_d->setDescription(description, localized);
       
   200 }
       
   201 
       
   202 /*!
       
   203  Returns copy of icon description of the entry.
       
   204  \retval icon Description (CaIconDescription).
       
   205 
       
   206  \code
       
   207  ...
       
   208  CaIconDescription iconDesc;
       
   209  iconDesc.setBitmapId(5555);
       
   210  iconDesc.setFilename(QString("fileName"));
       
   211  iconDesc.setMaskId(5556);
       
   212  iconDesc.setSkinMajorId(5557);
       
   213  iconDesc.setSkinMinorId(5558);
       
   214 
       
   215  resultEntry->setIconDescription( iconDesc );
       
   216 
       
   217  CaIconDescription entryIcon;
       
   218  entryIcon = resultEntry->iconDescription();
       
   219  ...
       
   220  \b Output:
       
   221  iconDesc == entryIcon
       
   222 
       
   223  \endcode
       
   224  */
       
   225 CaIconDescription CaEntry::iconDescription() const
       
   226 {
       
   227     return m_d->iconDescription();
       
   228 }
       
   229 
       
   230 /*!
       
   231  Sets icon description
       
   232  \param iconDescription const reference to CaIconDescription
       
   233 
       
   234  \code
       
   235  ...
       
   236  CaIconDescription iconDesc;
       
   237  iconDesc.setBitmapId(5555);
       
   238  iconDesc.setFilename(QString("fileName"));
       
   239  iconDesc.setMaskId(5556);
       
   240  iconDesc.setSkinMajorId(5557);
       
   241  iconDesc.setSkinMinorId(5558);
       
   242 
       
   243  resultEntry->setIconDescription( iconDesc );
       
   244  ...
       
   245  \b Output:
       
   246  iconDesc == resultEntry->iconDescription();
       
   247 
       
   248  \endcode
       
   249  */
       
   250 void CaEntry::setIconDescription(const CaIconDescription &iconDescription)
       
   251 {
       
   252     m_d->setIconDescription(iconDescription);
       
   253 }
       
   254 
       
   255 /*!
       
   256  Returns items flags.
       
   257  \retval flags.
       
   258 
       
   259  \code
       
   260  ...
       
   261  TUint flags = contentarsenal::RemovableEntryFlag
       
   262  |contentarsenal::VisibleEntryFlag;
       
   263  resultEntry->setFlags( flags );
       
   264 
       
   265  EntryFlags entryFlags = resultEntry->flags();
       
   266 
       
   267  \b Output:
       
   268  flags == entryFlags
       
   269 
       
   270  \endcode
       
   271  */
       
   272 EntryFlags CaEntry::flags() const
       
   273 {
       
   274     return m_d->flags();
       
   275 }
       
   276 
       
   277 /*!
       
   278  Sets flags.
       
   279  \param flags entry flags.
       
   280 
       
   281  \code
       
   282  ...
       
   283  TUint flags = contentarsenal::RemovableEntryFlag
       
   284  |contentarsenal::VisibleEntryFlag;
       
   285  resultEntry->setFlags( flags );
       
   286  ...
       
   287  \endcode
       
   288  */
       
   289 void CaEntry::setFlags(EntryFlags flags)
       
   290 {
       
   291     m_d->setFlags(flags);
       
   292 }
       
   293 
       
   294 /*!
       
   295  Returns a name of an entry type.
       
   296  \retval name of entry type.
       
   297 
       
   298  \code
       
   299  CaEntry entry;
       
   300  entry.setText( "Text" );
       
   301  entry.setEntryTypeName( "TypeName" );
       
   302  CaEntry * resultEntry = service->createEntry( entry );
       
   303 
       
   304  QString entryTypeName = resultEntry->entryTypeName();
       
   305  \b Output:
       
   306  entryTypeName == "TypeName"
       
   307 
       
   308  \endcode
       
   309  */
       
   310 QString CaEntry::entryTypeName() const
       
   311 {
       
   312     return m_d->entryTypeName();
       
   313 }
       
   314 
       
   315 /*!
       
   316  Sets name of entry type.
       
   317  \param entryTypeName name of entry type (const reference).
       
   318 
       
   319  \code
       
   320  ...
       
   321  resultEntry->setEntryTypeName("EntryTypeName");
       
   322 
       
   323  \b Output:
       
   324  resultEntry->entryTypeName == "EntryTypeName"
       
   325 
       
   326  \endcode
       
   327  */
       
   328 void CaEntry::setEntryTypeName(const QString &entryTypeName)
       
   329 {
       
   330     m_d->setEntryTypeName(entryTypeName);
       
   331 }
       
   332 
       
   333 /*!
       
   334  Returns item attributes.
       
   335  \retval map of attributes indexed by their names.
       
   336 
       
   337  \code
       
   338  ...
       
   339  QString attrName_1( "name_1" );
       
   340  QString attrValue_1( "value_1" );
       
   341  QString attrName_2( "name_2" );
       
   342  QString attrValue_2( "value_2" );
       
   343  resultEntry->setAttribute( attrName_1, attrValue_1 );
       
   344  resultEntry->setAttribute( attrName_2, attrValue_2 );
       
   345  ...
       
   346  QMap<QString, QString> attrMap = entryAttrValue = resultEntry->attributes();
       
   347 
       
   348  \b Output:
       
   349  attrMap[0] == name: name_1, value: value_1
       
   350  attrMap[1] == name: name_2, value: value_2
       
   351 
       
   352  \endcode
       
   353  */
       
   354 QMap<QString, QString> CaEntry::attributes() const
       
   355 {
       
   356     return m_d->attributes();
       
   357 }
       
   358 
       
   359 /*!
       
   360  \param name name of an attribute
       
   361  \retval value of attribute
       
   362 
       
   363  \code
       
   364  ...
       
   365  QString attrName_1( "name_1" );
       
   366  QString attrValue_1( "value_1" );
       
   367  QString attrName_2( "name_2" );
       
   368  QString attrValue_2( "value_2" );
       
   369  resultEntry->setAttribute( attrName_1, attrValue_1 );
       
   370  resultEntry->setAttribute( attrName_2, attrValue_2 );
       
   371  ...
       
   372  QString entryAttrValue = resultEntry->attribute( attrName_1 );
       
   373 
       
   374  \b Output:
       
   375  entryAttrValue == "attrValue_1"
       
   376 
       
   377  \endcode
       
   378  */
       
   379 QString CaEntry::attribute(const QString &name) const
       
   380 {
       
   381     return m_d->attribute(name);
       
   382 }
       
   383 
       
   384 /*!
       
   385  Sets attribute.
       
   386  \param name name of an attribute.
       
   387  \param value value of an attribute.
       
   388 
       
   389  \code
       
   390  ...
       
   391  QString attrName_1( "name_1" );
       
   392  QString attrValue_1( "value_1" );
       
   393  QString attrName_2( "name_2" );
       
   394  QString attrValue_2( "value_2" );
       
   395  resultEntry->setAttribute( attrName_1, attrValue_1 );
       
   396  resultEntry->setAttribute( attrName_2, attrValue_2 );
       
   397 
       
   398  \endcode
       
   399  */
       
   400 void CaEntry::setAttribute(const QString &name, const QString &value)
       
   401 {
       
   402     m_d->setAttribute(name, value);
       
   403 }
       
   404 
       
   405 /*!
       
   406  Creates an icon.
       
   407  \param  size icon size to display
       
   408  \retval created icon (HbIcon).
       
   409 
       
   410  \code
       
   411  ...
       
   412  QSize iconSize( 50, 80 );
       
   413  HbIcon icon = resultEntry->makeIcon( iconSize );
       
   414 
       
   415  \b Output:
       
   416  icon.width() == 50
       
   417  icon.height() == 80
       
   418  icon.size() == iconSize;
       
   419  \endcode
       
   420  */
       
   421 HbIcon CaEntry::makeIcon(const QSizeF &size) const
       
   422 {
       
   423     CACLIENTTEST_FUNC_ENTRY("CaEntry::makeIcon");
       
   424     HbIcon icon = CaIconCache::cache()->icon(*this, size);
       
   425     if (icon.isNull()) {
       
   426         icon = m_d->makeIcon(size);
       
   427         CaIconCache::cache()->insert(*this, size, icon);
       
   428     }
       
   429     CACLIENTTEST_FUNC_EXIT("CaEntry::makeIcon");
       
   430     return icon;
       
   431 }
       
   432 
       
   433 /*!
       
   434  Sets entry id.
       
   435  \param id item id.
       
   436  */
       
   437 void CaEntry::setId(int id)
       
   438 {
       
   439     m_d->setId(id);
       
   440 }
       
   441 /*!
       
   442  Gets entry role.
       
   443  \retval entry's role.
       
   444 
       
   445  \code
       
   446  CaEntry entry;
       
   447  entry.setText("Text");
       
   448  entry.setEntryTypeName("TypeName");
       
   449  CaEntry * resultEntry = service->createEntry(entry);
       
   450 
       
   451  EntryRole entryRole = resultEntry->role();
       
   452 
       
   453  \b Output:
       
   454  entryRole == ItemEntryRole
       
   455 
       
   456  \endcode
       
   457 
       
   458  \code
       
   459  CaEntry entryGroup( GroupEntryRole );
       
   460  entryGroup.setText("Text");
       
   461  entryGroup.setEntryTypeName("TypeName");
       
   462  CaEntry * resultGroup = service->createEntry(entryGroup);
       
   463  EntryRole groupRole = resultGroup->role();
       
   464 
       
   465  \b Output:
       
   466  groupRole == GroupEntryRole
       
   467 
       
   468  \endcode
       
   469  */
       
   470 EntryRole CaEntry::role() const
       
   471 {
       
   472     return m_d->role();
       
   473 }
       
   474 
       
   475 
       
   476 bool CaEntry::isLocalized(LocalizationType localized)  const
       
   477 {
       
   478     return m_d->isLocalized(localized);  
       
   479 }
       
   480 
       
   481 /*
       
   482  Constructor
       
   483  \param entryPublic associated public entry
       
   484  */
       
   485 CaEntryPrivate::CaEntryPrivate(CaEntry *entryPublic) :
       
   486     m_q(entryPublic), mId(0), mText(), mDescription(), mIconDescription(),
       
   487     mFlags(RemovableEntryFlag|VisibleEntryFlag),mEntryTypeName(),
       
   488     mAttributes(), mEntryRole(ItemEntryRole), 
       
   489     mTextLocalized(false), mDescriptionLocalized(false)
       
   490 {
       
   491 }
       
   492 /*!
       
   493  Copy assignment operator.
       
   494  \param entry const reference to CaEntryPrivate.
       
   495  \retval reference to CaEntryPrivate.
       
   496  */
       
   497 CaEntryPrivate &CaEntryPrivate::operator=(const CaEntryPrivate &entry)
       
   498 {
       
   499     mId = entry.mId;
       
   500     mText = entry.mText;
       
   501     mDescription = entry.mDescription;
       
   502     mIconDescription = entry.mIconDescription;
       
   503     mFlags = entry.mFlags;
       
   504     mEntryTypeName = entry.mEntryTypeName;
       
   505     mAttributes = entry.mAttributes;
       
   506     mEntryRole = entry.mEntryRole;
       
   507     mTextLocalized = entry.mTextLocalized;
       
   508     mDescriptionLocalized = entry.mDescriptionLocalized;
       
   509     return *this;
       
   510 }
       
   511 
       
   512 /*!
       
   513  Destructor
       
   514  */
       
   515 CaEntryPrivate::~CaEntryPrivate()
       
   516 {
       
   517 }
       
   518 
       
   519 /*!
       
   520  \retval item id
       
   521  */
       
   522 int CaEntryPrivate::id() const
       
   523 {
       
   524     return mId;
       
   525 }
       
   526 
       
   527 /*!
       
   528  \retval name of the item.
       
   529  */
       
   530 QString CaEntryPrivate::text() const
       
   531 {
       
   532     return mText;
       
   533 }
       
   534 
       
   535 /*!
       
   536  Sets localized name of the item.
       
   537  \param text new name of the item.
       
   538  */
       
   539 void CaEntryPrivate::setText(const QString &text, bool localized)
       
   540 {
       
   541     mText = text;
       
   542     mTextLocalized = localized;
       
   543 }
       
   544 
       
   545 /*!
       
   546 \retval description of the item.
       
   547 */
       
   548 QString CaEntryPrivate::description() const
       
   549 {
       
   550     return mDescription;
       
   551 }
       
   552 
       
   553 /*!
       
   554 Sets description of the item.
       
   555 \param text new name of the item.
       
   556 */
       
   557 void CaEntryPrivate::setDescription(const QString &description,
       
   558         bool localized)
       
   559 {
       
   560     mDescription = description;
       
   561     mDescriptionLocalized = localized;
       
   562 }
       
   563 
       
   564 /*!
       
   565  \retval icon Description (CaIconDescription).
       
   566  */
       
   567 CaIconDescription CaEntryPrivate::iconDescription() const
       
   568 {
       
   569     return mIconDescription;
       
   570 }
       
   571 
       
   572 /*!
       
   573  Sets icon description
       
   574  \param iconDescription const reference to CaIconDescription
       
   575  */
       
   576 void CaEntryPrivate::setIconDescription(
       
   577     const CaIconDescription &iconDescription)
       
   578 {
       
   579     mIconDescription = iconDescription;
       
   580 }
       
   581 
       
   582 /*!
       
   583  \retval flags
       
   584  */
       
   585 EntryFlags CaEntryPrivate::flags() const
       
   586 {
       
   587     return mFlags;
       
   588 }
       
   589 
       
   590 /*!
       
   591  Sets flags.
       
   592  \param flags entry flags.
       
   593  */
       
   594 void CaEntryPrivate::setFlags(EntryFlags flags)
       
   595 {
       
   596     mFlags = flags;
       
   597 }
       
   598 
       
   599 /*!
       
   600  \retval name of entry type.
       
   601  */
       
   602 QString CaEntryPrivate::entryTypeName() const
       
   603 {
       
   604     return mEntryTypeName;
       
   605 }
       
   606 
       
   607 /*!
       
   608  Sets name of entry type.
       
   609  \param entryTypeName name of entry type (const reference)
       
   610  */
       
   611 void CaEntryPrivate::setEntryTypeName(const QString &entryTypeName)
       
   612 {
       
   613     mEntryTypeName = entryTypeName;
       
   614 }
       
   615 
       
   616 /*!
       
   617  \retval map of attributes indexed by their names
       
   618  */
       
   619 QMap<QString, QString> CaEntryPrivate::attributes() const
       
   620 {
       
   621     return mAttributes;
       
   622 }
       
   623 
       
   624 /*!
       
   625  \param name name of an attribute
       
   626  \retval value of attribute
       
   627  */
       
   628 QString CaEntryPrivate::attribute(const QString &name) const
       
   629 {
       
   630     return mAttributes.value(name);
       
   631 }
       
   632 
       
   633 /*!
       
   634  Sets attribute.
       
   635  \param name name of an attribute.
       
   636  \param value value of an attribute.
       
   637  */
       
   638 void CaEntryPrivate::setAttribute(const QString &name, const QString &value)
       
   639 {
       
   640     mAttributes.insert(name, value);
       
   641 }
       
   642 
       
   643 /*!
       
   644  Creates an icon.
       
   645  \param  size icon size to display
       
   646  \retval created icon (HbIcon).
       
   647  */
       
   648 HbIcon CaEntryPrivate::makeIcon(const QSizeF &size) const
       
   649 {
       
   650     return CaMenuIconUtility::getEntryIcon(*m_q, size);
       
   651 }
       
   652 
       
   653 /*!
       
   654  Sets entry id.
       
   655  \param id item id.
       
   656  */
       
   657 void CaEntryPrivate::setId(int id)
       
   658 {
       
   659     mId = id;
       
   660 }
       
   661 /*!
       
   662  Sets entry role.
       
   663  \retval entry's role.
       
   664  */
       
   665 EntryRole CaEntryPrivate::role() const
       
   666 {
       
   667     return mEntryRole;
       
   668 }
       
   669 /*!
       
   670  Gets entry role.
       
   671  \param role entry's role.
       
   672  */
       
   673 void CaEntryPrivate::setRole(const EntryRole &role)
       
   674 {
       
   675     mEntryRole = role;
       
   676 }
       
   677 
       
   678 bool CaEntryPrivate::isLocalized(LocalizationType localized)  const
       
   679 {
       
   680     if(localized == NameLocalized)
       
   681     {
       
   682         return mTextLocalized;
       
   683     }
       
   684     if(localized == DescriptionLocalized)
       
   685     {
       
   686         return mDescriptionLocalized;
       
   687     }
       
   688     return false;
       
   689     
       
   690 }
       
   691 
       
   692