emailuis/nmailui/src/nmattachmentlist.cpp
changeset 43 99bcbff212ad
parent 23 2dc6caa42ec3
child 44 c2d07d913565
equal deleted inserted replaced
42:139d4b7b2938 43:99bcbff212ad
    26     Constructor
    26     Constructor
    27 */
    27 */
    28 NmAttachmentList::NmAttachmentList(NmAttachmentListWidget &listWidget)
    28 NmAttachmentList::NmAttachmentList(NmAttachmentListWidget &listWidget)
    29 : mListWidget(listWidget)
    29 : mListWidget(listWidget)
    30 {
    30 {
       
    31     NM_FUNCTION;
       
    32     
    31     updateLayout();
    33     updateLayout();
    32 }
    34 }
    33 
    35 
    34 /*!
    36 /*!
    35     Destructor
    37     Destructor
    36 */
    38 */
    37 NmAttachmentList::~NmAttachmentList()
    39 NmAttachmentList::~NmAttachmentList()
    38 { 
    40 { 
       
    41     NM_FUNCTION;
       
    42     
    39     clearList();
    43     clearList();
    40 }
    44 }
    41 
    45 
    42 /*!
    46 /*!
    43     Insert new list item. Returns the count of the attachment in list
    47     Insert new list item. Returns the count of the attachment in list
    45 int NmAttachmentList::insertAttachment(
    49 int NmAttachmentList::insertAttachment(
    46     const QString &fullFileName,
    50     const QString &fullFileName,
    47     const QString &fileSize,
    51     const QString &fileSize,
    48     const NmId &attachmentPartId)
    52     const NmId &attachmentPartId)
    49 {
    53 {
       
    54     NM_FUNCTION;
       
    55     
    50     QString displayName = fullNameToDisplayName(fullFileName);
    56     QString displayName = fullNameToDisplayName(fullFileName);
    51     mFullFileName.append(fullFileName);
    57     mFullFileName.append(fullFileName);
    52     mDisplayFileName.append(displayName);
    58     mDisplayFileName.append(displayName);
    53     mAttachmentPartId.append(attachmentPartId);
    59     mAttachmentPartId.append(attachmentPartId);
    54     mFileSize.append(fileSize);
    60     mFileSize.append(fileSize);
    65     same filename, function will search the one which nmid is not set.
    71     same filename, function will search the one which nmid is not set.
    66 */
    72 */
    67 void NmAttachmentList::setAttachmentPartId(const QString fullFileName, 
    73 void NmAttachmentList::setAttachmentPartId(const QString fullFileName, 
    68                                            const NmId &attachmentPartId)
    74                                            const NmId &attachmentPartId)
    69 {
    75 {
       
    76     NM_FUNCTION;
       
    77     
    70     for (int i=0; i<count(); ++i) {
    78     for (int i=0; i<count(); ++i) {
    71         if (mFullFileName.at(i) == fullFileName && mAttachmentPartId.at(i).id() == 0) {
    79         if (mFullFileName.at(i) == fullFileName && mAttachmentPartId.at(i).id() == 0) {
    72             mAttachmentPartId.replace(i, attachmentPartId);
    80             mAttachmentPartId.replace(i, attachmentPartId);
    73         }
    81         }
    74     }
    82     }
    77 /*!
    85 /*!
    78     Set fileSize of the attachment.
    86     Set fileSize of the attachment.
    79 */
    87 */
    80 void NmAttachmentList::setAttachmentSize(const NmId &attachmentPartId, const QString &size)
    88 void NmAttachmentList::setAttachmentSize(const NmId &attachmentPartId, const QString &size)
    81 {
    89 {
       
    90     NM_FUNCTION;
       
    91     
    82     for (int i=0; i<count(); ++i) {
    92     for (int i=0; i<count(); ++i) {
    83         if (mAttachmentPartId.at(i) == attachmentPartId) {
    93         if (mAttachmentPartId.at(i) == attachmentPartId) {
    84             mFileSize.replace(i, size);
    94             mFileSize.replace(i, size);
    85             mListWidget.setAttachmentSize(i, NmUtilities::attachmentSizeString(size.toDouble()));
    95             mListWidget.setAttachmentSize(i, NmUtilities::attachmentSizeString(size.toDouble()));
    86         }
    96         }
    90 /*!
   100 /*!
    91     Remove attachment from list position
   101     Remove attachment from list position
    92 */
   102 */
    93 void NmAttachmentList::removeAttachment(int arrayIndex)
   103 void NmAttachmentList::removeAttachment(int arrayIndex)
    94 {
   104 {
       
   105     NM_FUNCTION;
       
   106     
    95     if (arrayIndex < count()) {
   107     if (arrayIndex < count()) {
    96         // Remove UI
   108         // Remove UI
    97         mListWidget.removeAttachment(arrayIndex);
   109         mListWidget.removeAttachment(arrayIndex);
    98         // Remove from data structure
   110         // Remove from data structure
    99         mFullFileName.removeAt(arrayIndex);
   111         mFullFileName.removeAt(arrayIndex);
   106 /*!
   118 /*!
   107     Return full filename of the list item
   119     Return full filename of the list item
   108 */
   120 */
   109 QString NmAttachmentList::getFullFileNameByIndex(int arrayIndex)
   121 QString NmAttachmentList::getFullFileNameByIndex(int arrayIndex)
   110 {
   122 {
       
   123     NM_FUNCTION;
       
   124     
   111 	QString result;
   125 	QString result;
   112 	
   126 	
   113     if ( arrayIndex >= 0 && arrayIndex < mFullFileName.count() ) {
   127     if ( arrayIndex >= 0 && arrayIndex < mFullFileName.count() ) {
   114         result.append(mFullFileName.at(arrayIndex));
   128         result.append(mFullFileName.at(arrayIndex));
   115     }
   129     }
   119 /*!
   133 /*!
   120     Remove attachment which have same fullFileName from list
   134     Remove attachment which have same fullFileName from list
   121 */
   135 */
   122 void NmAttachmentList::removeAttachment(const QString &fullFileName)
   136 void NmAttachmentList::removeAttachment(const QString &fullFileName)
   123 {
   137 {
       
   138     NM_FUNCTION;
       
   139     
   124     for (int i=0; i<count(); ++i) {
   140     for (int i=0; i<count(); ++i) {
   125         if (mFullFileName.at(i) == fullFileName) {
   141         if (mFullFileName.at(i) == fullFileName) {
   126             removeAttachment(i);
   142             removeAttachment(i);
   127         }
   143         }
   128     }
   144     }
   131 /*!
   147 /*!
   132     Remove attachment which have same attachmentPartId from list
   148     Remove attachment which have same attachmentPartId from list
   133 */
   149 */
   134 void NmAttachmentList::removeAttachment(const NmId &attachmentPartId)
   150 void NmAttachmentList::removeAttachment(const NmId &attachmentPartId)
   135 {
   151 {
       
   152     NM_FUNCTION;
       
   153     
   136     for (int i=0; i<count(); ++i) {
   154     for (int i=0; i<count(); ++i) {
   137         if (mAttachmentPartId.at(i) == attachmentPartId) {
   155         if (mAttachmentPartId.at(i) == attachmentPartId) {
   138             removeAttachment(i);
   156             removeAttachment(i);
   139         }
   157         }
   140     }
   158     }
   143 /*!
   161 /*!
   144     Clear attachment list from UI and from data structure
   162     Clear attachment list from UI and from data structure
   145 */
   163 */
   146 void NmAttachmentList::clearList()
   164 void NmAttachmentList::clearList()
   147 {
   165 {
       
   166     NM_FUNCTION;
       
   167     
   148     for (int i=count()-1; i>=0; --i) {
   168     for (int i=count()-1; i>=0; --i) {
   149         // Remove from UI
   169         // Remove from UI
   150         mListWidget.removeAttachment(i);
   170         mListWidget.removeAttachment(i);
   151         // Remove from data structure
   171         // Remove from data structure
   152         mFullFileName.removeAt(i);
   172         mFullFileName.removeAt(i);
   159 /*!
   179 /*!
   160     Return attachment list widget
   180     Return attachment list widget
   161 */
   181 */
   162 NmAttachmentListWidget& NmAttachmentList::listWidget()
   182 NmAttachmentListWidget& NmAttachmentList::listWidget()
   163 {
   183 {
       
   184     NM_FUNCTION;
       
   185     
   164     return mListWidget;
   186     return mListWidget;
   165 }
   187 }
   166 
   188 
   167 /*!
   189 /*!
   168     Return attachment count
   190     Return attachment count
   169 */
   191 */
   170 int NmAttachmentList::count()
   192 int NmAttachmentList::count()
   171 {
   193 {
       
   194     NM_FUNCTION;
       
   195     
   172     return mFullFileName.count();
   196     return mFullFileName.count();
   173 }
   197 }
   174 
   198 
   175 /*!
   199 /*!
   176     Return attachment part id
   200     Return attachment part id
   177 */
   201 */
   178 NmId NmAttachmentList::nmIdByIndex(int listIndex)
   202 NmId NmAttachmentList::nmIdByIndex(int listIndex)
   179 {
   203 {
       
   204     NM_FUNCTION;
       
   205     
   180     return mAttachmentPartId.at(listIndex);
   206     return mAttachmentPartId.at(listIndex);
   181 }
   207 }
   182 
   208 
   183 /*!
   209 /*!
   184     Return array index of attachment
   210     Return array index of attachment
   185 */
   211 */
   186 int NmAttachmentList::indexByNmId(const NmId &id)
   212 int NmAttachmentList::indexByNmId(const NmId &id)
   187 {
   213 {
       
   214     NM_FUNCTION;
       
   215     
   188     for (int i=0; i<count(); ++i) {
   216     for (int i=0; i<count(); ++i) {
   189         if (mAttachmentPartId.at(i) == id) {
   217         if (mAttachmentPartId.at(i) == id) {
   190             return i;
   218             return i;
   191         }
   219         }
   192     }
   220     }
   196 /*!
   224 /*!
   197     Remove file path from full filename
   225     Remove file path from full filename
   198 */
   226 */
   199 QString NmAttachmentList::fullNameToDisplayName(const QString &fullName)
   227 QString NmAttachmentList::fullNameToDisplayName(const QString &fullName)
   200 {
   228 {
       
   229     NM_FUNCTION;
       
   230     
   201     return fullName.section('\\', -1);
   231     return fullName.section('\\', -1);
   202 }
   232 }
   203 
   233 
   204 /*!
   234 /*!
   205     Update the list layout height
   235     Update the list layout height
   206 */
   236 */
   207 void NmAttachmentList::updateLayout()
   237 void NmAttachmentList::updateLayout()
   208 {
   238 {
       
   239     NM_FUNCTION;
       
   240     
   209     // Fix this when progress bar is used
   241     // Fix this when progress bar is used
   210     mListWidget.setMaximumHeight(count() * 56); 
   242     mListWidget.setMaximumHeight(count() * 56); 
   211     QTimer::singleShot(1, this, SLOT(delayedLayoutChangeInfo()));
   243     QTimer::singleShot(1, this, SLOT(delayedLayoutChangeInfo()));
   212 }
   244 }
   213 
   245 
   214 /*!
   246 /*!
   215     Send delayed signal about attachment list layout change
   247     Send delayed signal about attachment list layout change
   216 */
   248 */
   217 void NmAttachmentList::delayedLayoutChangeInfo()
   249 void NmAttachmentList::delayedLayoutChangeInfo()
   218 {
   250 {
       
   251     NM_FUNCTION;
       
   252     
   219     emit attachmentListLayoutChanged();
   253     emit attachmentListLayoutChanged();
   220 }
   254 }
   221 
   255