|
1 /* |
|
2 * Copyright (c) 2007-2008 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 download progress bar |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "FreestyleAttachmentDownloadProgressBar.h" |
|
20 #include "FreestyleEmailUi.rsg" |
|
21 #include "FreestyleEmailUiAttachmentsListModel.h" |
|
22 |
|
23 #include <eikprogi.h> |
|
24 |
|
25 CFreestyleAttachmentDownloadProgressBar* CFreestyleAttachmentDownloadProgressBar::NewL() |
|
26 { |
|
27 CFreestyleAttachmentDownloadProgressBar* self = new (ELeave) CFreestyleAttachmentDownloadProgressBar(); |
|
28 return self; |
|
29 } |
|
30 |
|
31 CFreestyleAttachmentDownloadProgressBar::~CFreestyleAttachmentDownloadProgressBar() |
|
32 { |
|
33 TRAP_IGNORE( RemoveProgressBarL() ); |
|
34 } |
|
35 |
|
36 TBool CFreestyleAttachmentDownloadProgressBar::IsVisible() const |
|
37 { |
|
38 return iVisible; |
|
39 } |
|
40 |
|
41 void CFreestyleAttachmentDownloadProgressBar::SetVisible( TBool aVisible ) |
|
42 { |
|
43 iVisible = aVisible; |
|
44 } |
|
45 |
|
46 void CFreestyleAttachmentDownloadProgressBar::DialogDismissedL( TInt aButtonId ) |
|
47 { |
|
48 if ( aButtonId == R_AVKON_SOFTKEYS_CLOSE ) |
|
49 { |
|
50 SetVisible( EFalse ); |
|
51 } |
|
52 iProgressBar = NULL; |
|
53 } |
|
54 |
|
55 void CFreestyleAttachmentDownloadProgressBar::ShowL() |
|
56 { |
|
57 SetVisible(); |
|
58 UpdateL( *iCurrentAttachment ); |
|
59 } |
|
60 |
|
61 void CFreestyleAttachmentDownloadProgressBar::HideL() |
|
62 { |
|
63 SetVisible( EFalse ); |
|
64 RemoveProgressBarL(); |
|
65 } |
|
66 |
|
67 void CFreestyleAttachmentDownloadProgressBar::UpdateL( const TAttachmentData& aAttachment ) |
|
68 { |
|
69 TBool changed = AttachmentChanged( aAttachment ); |
|
70 if (changed) |
|
71 { |
|
72 SetVisible(); |
|
73 } |
|
74 |
|
75 SetAttachment( aAttachment ); |
|
76 |
|
77 if ( iVisible ) |
|
78 { |
|
79 if ( changed && iProgressBar ) |
|
80 { |
|
81 RemoveProgressBarL(); |
|
82 } |
|
83 |
|
84 if ( !iProgressBar ) |
|
85 { |
|
86 CreateProgressBarL(); |
|
87 } |
|
88 |
|
89 if ( iProgressBar ) |
|
90 { |
|
91 RefreshProgressBarL(); |
|
92 } |
|
93 } |
|
94 } |
|
95 |
|
96 const TAttachmentData* CFreestyleAttachmentDownloadProgressBar::CurrentAttachment() const |
|
97 { |
|
98 return iCurrentAttachment; |
|
99 } |
|
100 |
|
101 CFreestyleAttachmentDownloadProgressBar::CFreestyleAttachmentDownloadProgressBar() |
|
102 :iProgressBar( NULL ), |
|
103 iCurrentAttachment( NULL ), |
|
104 iVisible( ETrue ) |
|
105 { |
|
106 } |
|
107 |
|
108 void CFreestyleAttachmentDownloadProgressBar::CreateProgressBarL() |
|
109 { |
|
110 ASSERT( iCurrentAttachment ); |
|
111 |
|
112 iProgressBar = new (ELeave) CAknProgressDialog( reinterpret_cast<CEikDialog**>(&iProgressBar) ); |
|
113 iProgressBar->PrepareLC( R_FSE_ATTACHMENT_DOWNLOAD_PROGRESS ); |
|
114 iProgressBar->SetCallback( this ); |
|
115 |
|
116 iProgressBar->SetTextL( iCurrentAttachment->fileName ); |
|
117 |
|
118 CEikProgressInfo* progressInfo = iProgressBar->GetProgressInfoL(); |
|
119 progressInfo->SetFinalValue( KComplete ); |
|
120 |
|
121 iProgressBar->RunLD(); |
|
122 } |
|
123 |
|
124 void CFreestyleAttachmentDownloadProgressBar::RemoveProgressBarL() |
|
125 { |
|
126 if ( iProgressBar ) |
|
127 { |
|
128 iProgressBar->ProcessFinishedL(); |
|
129 } |
|
130 delete iProgressBar; |
|
131 iProgressBar = NULL; |
|
132 } |
|
133 |
|
134 void CFreestyleAttachmentDownloadProgressBar::RefreshProgressBarL() |
|
135 { |
|
136 ASSERT( iProgressBar ); |
|
137 ASSERT( iCurrentAttachment ); |
|
138 |
|
139 CEikProgressInfo* progressInfo = iProgressBar->GetProgressInfoL(); |
|
140 progressInfo->SetAndDraw( iCurrentAttachment->downloadProgress ); |
|
141 if ( iCurrentAttachment->downloadProgress == KComplete ) |
|
142 { |
|
143 RemoveProgressBarL(); |
|
144 } |
|
145 } |
|
146 |
|
147 TBool CFreestyleAttachmentDownloadProgressBar::AttachmentChanged( const TAttachmentData& aAttachment ) const |
|
148 { |
|
149 TBool changed = ETrue; |
|
150 if ( iCurrentAttachment ) |
|
151 { |
|
152 changed = !( iCurrentAttachment->partData == aAttachment.partData ); |
|
153 } |
|
154 return changed; |
|
155 } |
|
156 |
|
157 void CFreestyleAttachmentDownloadProgressBar::SetAttachment( const TAttachmentData& aAttachment ) |
|
158 { |
|
159 iCurrentAttachment = &aAttachment; |
|
160 } |
|
161 |
|
162 void CFreestyleAttachmentDownloadProgressBar::Reset() |
|
163 { |
|
164 iCurrentAttachment = NULL; |
|
165 } |
|
166 |