calendarui/commonutils/src/calenattachmentinfo.cpp
changeset 0 f979ecb2b13e
child 10 38571fd2a704
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     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 : Attachment information
       
    15 *
       
    16 */
       
    17 
       
    18 #include <eikenv.h>
       
    19 #include <gulicon.h>
       
    20 #include <avkon.rsg>
       
    21 #include <StringLoader.h>           // StringLoader
       
    22 
       
    23 #include "calenattachmentinfo.h"
       
    24 #include "calenattachmentmodel.h"
       
    25 #include "calenattachmentutils.h"
       
    26 #include "calendarui_debug.h"
       
    27 
       
    28 // ----------------------------------------------------------------------------
       
    29 // CCalenAttachmentInfo::NewL
       
    30 // First phase construction
       
    31 // ----------------------------------------------------------------------------
       
    32 //
       
    33 EXPORT_C CCalenAttachmentInfo* CCalenAttachmentInfo::NewL(
       
    34                                         CCalenAttachmentModel& aAttachmentModel,
       
    35                                         const TFileName& aFileName,
       
    36                                         const TFileName& aSystemFileName,
       
    37                                         TInt aSize,
       
    38                                         TBool aFetched,
       
    39                                         const TDataType& aDataType,
       
    40                                         TCalenAttachmentStoreType aStoreType )
       
    41     {
       
    42     TRACE_ENTRY_POINT;
       
    43     
       
    44     CCalenAttachmentInfo* self = new ( ELeave ) CCalenAttachmentInfo(
       
    45                                                     aAttachmentModel,
       
    46                                                     aFileName,
       
    47                                                     aSystemFileName,
       
    48                                                     aSize,
       
    49                                                     aFetched,
       
    50                                                     aDataType,
       
    51                                                     aStoreType);
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL();
       
    54     CleanupStack::Pop();
       
    55     
       
    56     TRACE_EXIT_POINT;
       
    57     return self;
       
    58     }
       
    59 
       
    60 // ----------------------------------------------------------------------------
       
    61 // CCalenAttachmentInfo::~CCalenAttachmentInfo
       
    62 // Destructor.
       
    63 // ----------------------------------------------------------------------------
       
    64 //
       
    65 CCalenAttachmentInfo::~CCalenAttachmentInfo()
       
    66     {
       
    67     TRACE_ENTRY_POINT;
       
    68     TRACE_EXIT_POINT;
       
    69     delete iIcon;
       
    70     }
       
    71 
       
    72 // ----------------------------------------------------------------------------
       
    73 // CCalenAttachmentInfo::CCalenAttachmentInfo
       
    74 // Constructor.
       
    75 // ----------------------------------------------------------------------------
       
    76 //
       
    77 CCalenAttachmentInfo::CCalenAttachmentInfo( CCalenAttachmentModel& aAttachmentModel,
       
    78                                             const TFileName& aFileName,
       
    79                                             const TFileName& aSystemFileName,
       
    80                                             TInt aSize,
       
    81                                             TBool aFetched,
       
    82                                             const TDataType& aDataType,
       
    83                                             TCalenAttachmentStoreType aStoreType)
       
    84     : iAttachmentModel(aAttachmentModel),
       
    85     iFileName(aFileName),
       
    86     iSystemFileName(aSystemFileName),
       
    87     iSize(aSize),
       
    88     iDataType(aDataType),
       
    89     iAttachmentStoreType(aStoreType)
       
    90     {
       
    91     TRACE_ENTRY_POINT; 
       
    92     
       
    93     SetFetched( aFetched );
       
    94     
       
    95     TRACE_EXIT_POINT;
       
    96     }
       
    97 
       
    98 // ----------------------------------------------------------------------------
       
    99 // CCalenAttachmentInfo::ConstructL
       
   100 // Second phase construction
       
   101 // ----------------------------------------------------------------------------
       
   102 //
       
   103 void CCalenAttachmentInfo::ConstructL()
       
   104     {
       
   105     TRACE_ENTRY_POINT;
       
   106     
       
   107     DoUpdateIconL();
       
   108     
       
   109     TRACE_EXIT_POINT;
       
   110     }
       
   111 
       
   112 // ----------------------------------------------------------------------------
       
   113 // CCalenAttachmentInfo::FileName
       
   114 // Returns reference to the filename.
       
   115 // ----------------------------------------------------------------------------
       
   116 //
       
   117 EXPORT_C const TFileName& CCalenAttachmentInfo::FileName() const
       
   118     {
       
   119     TRACE_ENTRY_POINT;
       
   120     TRACE_EXIT_POINT;
       
   121     
       
   122     return iFileName;
       
   123     }
       
   124 
       
   125 // ----------------------------------------------------------------------------
       
   126 // CCalenAttachmentInfo::SetFileName
       
   127 // Set the filename of this attachment.
       
   128 // ----------------------------------------------------------------------------
       
   129 //
       
   130 EXPORT_C void CCalenAttachmentInfo::SetFileName( const TFileName& aFileName )
       
   131     {
       
   132     TRACE_ENTRY_POINT;
       
   133     
       
   134     iFileName = aFileName;
       
   135 
       
   136     // find file size
       
   137     RFile file;
       
   138     RFs& fs = CEikonEnv::Static()->FsSession();
       
   139 
       
   140     TInt err = file.Open( fs, iFileName, EFileShareAny );
       
   141     if ( err == KErrAccessDenied || err == KErrInUse )
       
   142         {
       
   143         err = file.Open( fs, iFileName, EFileShareReadersOnly );
       
   144         }
       
   145     if ( err == KErrNone )
       
   146         {
       
   147         file.Size( iSize );
       
   148         }
       
   149     file.Close();
       
   150 
       
   151     TRAP_IGNORE( DoUpdateIconL() );
       
   152     
       
   153     TRACE_EXIT_POINT;
       
   154     }
       
   155 
       
   156 // ----------------------------------------------------------------------------
       
   157 // CCalenAttachmentInfo::Size
       
   158 // Returns the size.
       
   159 // ----------------------------------------------------------------------------
       
   160 //
       
   161 EXPORT_C TInt CCalenAttachmentInfo::Size() const
       
   162     {
       
   163     TRACE_ENTRY_POINT;
       
   164     TRACE_EXIT_POINT;
       
   165     return iSize;
       
   166     }
       
   167 
       
   168 // ----------------------------------------------------------------------------
       
   169 // CCalenAttachmentInfo::Size
       
   170 // Returns the size in the form of descriptor to be shown on the UI.
       
   171 // Owner ship of the size string is transfered.
       
   172 // ----------------------------------------------------------------------------
       
   173 //
       
   174 EXPORT_C HBufC* CCalenAttachmentInfo::SizeString() const
       
   175     {
       
   176     TRACE_ENTRY_POINT;
       
   177     TInt resId = R_QTN_SIZE_B;
       
   178     TInt fileSize = iSize;
       
   179     if ( fileSize >= KLocalKilo )
       
   180         {
       
   181         resId = R_QTN_SIZE_KB;
       
   182         fileSize /= KLocalKilo;
       
   183         if ( iSize % KLocalKilo )
       
   184             {
       
   185             fileSize++;
       
   186             }
       
   187         }
       
   188  
       
   189     HBufC *buf = StringLoader::LoadLC( resId, fileSize );
       
   190     CleanupStack::Pop( buf );
       
   191     TRACE_EXIT_POINT;
       
   192     return buf;
       
   193     }
       
   194 
       
   195 // ----------------------------------------------------------------------------
       
   196 // CCalenAttachmentInfo::IsFetched
       
   197 // Returns ETrue if this attachment is fetched.
       
   198 // ----------------------------------------------------------------------------
       
   199 //
       
   200 EXPORT_C TBool CCalenAttachmentInfo::IsFetched() const
       
   201     {
       
   202     TRACE_ENTRY_POINT;
       
   203     TRACE_EXIT_POINT;    
       
   204     return iIsFetched;
       
   205     }
       
   206 
       
   207 // ----------------------------------------------------------------------------
       
   208 // CCalenAttachmentInfo::SetFetched
       
   209 // Sets the fetched attribute of this attachment.
       
   210 // ----------------------------------------------------------------------------
       
   211 //
       
   212 EXPORT_C void CCalenAttachmentInfo::SetFetched( TBool aFetched )
       
   213     {
       
   214     TRACE_ENTRY_POINT;
       
   215     
       
   216     iIsFetched = aFetched;
       
   217     
       
   218     if(iIcon)
       
   219         {
       
   220         TRAP_IGNORE( DoUpdateIconL() );
       
   221         }
       
   222     
       
   223     TRACE_EXIT_POINT;
       
   224     }
       
   225 
       
   226 // ----------------------------------------------------------------------------
       
   227 // CCalenAttachmentInfo::DataType
       
   228 // Returns the datatype (MIME type) of this attachment.
       
   229 // ----------------------------------------------------------------------------
       
   230 //
       
   231 EXPORT_C const TDataType& CCalenAttachmentInfo::DataType() const
       
   232     {
       
   233     TRACE_ENTRY_POINT;
       
   234     TRACE_EXIT_POINT;
       
   235     return iDataType;
       
   236     }
       
   237 
       
   238 // ----------------------------------------------------------------------------
       
   239 // CCalenAttachmentInfo::Icon
       
   240 // Returns the icon.
       
   241 // ----------------------------------------------------------------------------
       
   242 //
       
   243 EXPORT_C CGulIcon* CCalenAttachmentInfo::Icon() const
       
   244     {
       
   245     TRACE_ENTRY_POINT;
       
   246     TRACE_EXIT_POINT;
       
   247     return iIcon;
       
   248     }
       
   249 
       
   250 // ----------------------------------------------------------------------------
       
   251 // CCalenAttachmentInfo::DoUpdateIconL
       
   252 // Update the attachment icon
       
   253 // ----------------------------------------------------------------------------
       
   254 //
       
   255 void CCalenAttachmentInfo::DoUpdateIconL()
       
   256     {
       
   257     TRACE_ENTRY_POINT;
       
   258     
       
   259     CGulIcon* resultIcon = iAttachmentModel.BitmapForFileL( *this );
       
   260         
       
   261     // icons are owned by atta info object.
       
   262     delete iIcon;
       
   263     iIcon = resultIcon;
       
   264     
       
   265     TRACE_EXIT_POINT;
       
   266     }
       
   267 
       
   268 // ----------------------------------------------------------------------------
       
   269 // CCalenAttachmentInfo::StoreType
       
   270 // Returns the store type of the attachment
       
   271 // ----------------------------------------------------------------------------
       
   272 //
       
   273 EXPORT_C CCalenAttachmentInfo::TCalenAttachmentStoreType 
       
   274             CCalenAttachmentInfo::StoreType() const
       
   275     {
       
   276     TRACE_ENTRY_POINT;
       
   277     TRACE_EXIT_POINT;
       
   278     
       
   279     return iAttachmentStoreType;
       
   280     }
       
   281 
       
   282 // ----------------------------------------------------------------------------
       
   283 // CCalenAttachmentInfo::SystemFileName
       
   284 // Returns reference to the filename.
       
   285 // ----------------------------------------------------------------------------
       
   286 //
       
   287 EXPORT_C const TFileName& CCalenAttachmentInfo::SystemFileName() const
       
   288     {
       
   289     TRACE_ENTRY_POINT;
       
   290     TRACE_EXIT_POINT;
       
   291     
       
   292     return iSystemFileName;
       
   293     }
       
   294 
       
   295 //end of file
       
   296 
       
   297