0
|
1 |
/*
|
|
2 |
============================================================================
|
|
3 |
Name : NPRHtmlCreator.cpp
|
|
4 |
Author : Symsource
|
|
5 |
|
|
6 |
Copyright (c) 2009 Symbian Foundation Ltd
|
|
7 |
This component and the accompanying materials are made available
|
|
8 |
under the terms of the License "Eclipse Public License v1.0"
|
|
9 |
which accompanies this distribution, and is available
|
|
10 |
at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
11 |
|
|
12 |
Initial Contributors:
|
|
13 |
- Symbian Foundation Ltd - initial contribution.
|
|
14 |
|
|
15 |
Contributors:
|
|
16 |
- Symsource
|
|
17 |
|
|
18 |
Description : HTML composer
|
|
19 |
============================================================================
|
|
20 |
*/
|
|
21 |
|
|
22 |
#include "NPRHtmlCreator.h"
|
|
23 |
#include "NPRStory.h"
|
|
24 |
|
|
25 |
//Constants
|
|
26 |
_LIT(KPath, "c:\\data\\npr\\story.html");
|
|
27 |
_LIT8(KHtml, "<html><body><h2>%S</h2><img vspace=\"2\" hspace=\"10\" src=\"file:///c:/data/npr/pic%d.jpg\" width=\"125\" height=\"125\" align=\"left\"/>%S</body></html>");
|
|
28 |
|
|
29 |
TInt CNPRHtmlCreator::iCurrentImage=6;
|
|
30 |
|
|
31 |
CNPRHtmlCreator* CNPRHtmlCreator::NewLC()
|
|
32 |
{
|
|
33 |
CNPRHtmlCreator* self = new (ELeave) CNPRHtmlCreator();
|
|
34 |
CleanupStack::PushL(self);
|
|
35 |
self->ConstructL();
|
|
36 |
return self;
|
|
37 |
}
|
|
38 |
|
|
39 |
CNPRHtmlCreator* CNPRHtmlCreator::NewL()
|
|
40 |
{
|
|
41 |
CNPRHtmlCreator* self = CNPRHtmlCreator::NewLC();
|
|
42 |
CleanupStack::Pop(); // self;
|
|
43 |
return self;
|
|
44 |
}
|
|
45 |
|
|
46 |
CNPRHtmlCreator::~CNPRHtmlCreator()
|
|
47 |
{
|
|
48 |
iFs.Close();
|
|
49 |
}
|
|
50 |
|
|
51 |
|
|
52 |
void CNPRHtmlCreator::ConstructL()
|
|
53 |
{
|
|
54 |
User::LeaveIfError(iFs.Connect());
|
|
55 |
}
|
|
56 |
|
|
57 |
void CNPRHtmlCreator::CreateHtmlFileL(CNPRStory* aStory)
|
|
58 |
{
|
|
59 |
TInt err = iFs.MkDirAll(KPath);
|
|
60 |
if ((KErrNone != err) && (KErrAlreadyExists != err))
|
|
61 |
{
|
|
62 |
User::Leave(err);
|
|
63 |
}
|
|
64 |
|
|
65 |
//Open the file, replacing if necessary
|
|
66 |
RFile file;
|
|
67 |
User::LeaveIfError(file.Replace(iFs,KPath,EFileWrite));
|
|
68 |
CleanupClosePushL(file);
|
|
69 |
|
|
70 |
HBufC8* title=HBufC8::NewLC(aStory->Title().Length());
|
|
71 |
title->Des().Copy(aStory->Title());
|
|
72 |
|
|
73 |
TInt textLength=aStory->Text().Length();
|
|
74 |
HBufC8* text;
|
|
75 |
if (textLength!=0)
|
|
76 |
{
|
|
77 |
text=HBufC8::NewLC(textLength);
|
|
78 |
text->Des().Copy(aStory->Text());
|
|
79 |
}
|
|
80 |
else
|
|
81 |
{
|
|
82 |
//There was no story, so just display the teaser
|
|
83 |
textLength=aStory->Teaser().Length();
|
|
84 |
text=HBufC8::NewLC(textLength);
|
|
85 |
text->Des().Copy(aStory->Teaser());
|
|
86 |
}
|
|
87 |
|
|
88 |
HBufC8 *buf = HBufC8::NewLC(KHtml().Length()
|
|
89 |
+ title->Length()
|
|
90 |
+ textLength +1
|
|
91 |
);
|
|
92 |
|
|
93 |
--iCurrentImage;
|
|
94 |
if (iCurrentImage<=0)
|
|
95 |
{
|
|
96 |
iCurrentImage=6;
|
|
97 |
}
|
|
98 |
|
|
99 |
TPtr8 ptr = buf->Des();
|
|
100 |
ptr.Format(KHtml,title, iCurrentImage,text);
|
|
101 |
|
|
102 |
//Write into the file
|
|
103 |
User::LeaveIfError(file.Write(ptr));
|
|
104 |
CleanupStack::PopAndDestroy(3); //buf,teaser,title
|
|
105 |
CleanupStack::PopAndDestroy(&file);
|
|
106 |
}
|