-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilelistengine.cpp
More file actions
223 lines (199 loc) · 6.95 KB
/
Filelistengine.cpp
File metadata and controls
223 lines (199 loc) · 6.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
* ============================================================================
* Name : CFileListEngine from FileListEngine.h
* Part of : FileList
* Created : 18.12.2002 by Forum Nokia
* Implementation notes:
* Engine for constructing filelist.
* Initial content was generated by Nokia Series 60 AppWizard.
* Version : 1.0
* Copyright: Nokia Corporation
* ============================================================================
*/
// INCLUDE FILES
#include "FileListEngine.h"
#include "Filelist.hrh" // enumerations
// ================= Constants =======================
// Number, name and file size
_LIT(KStringSize,"%d\t%S\t%d bytes");
// Number, name and date modified
_LIT(KStringDate,"%d\t%S\t%S");
// Directory for Sounds
_LIT(KDirSounds,"c:\\Nokia\\Sounds\\Digital\\");
// Directory for Pictures
_LIT(KDirPictures,"c:\\Nokia\\Images\\");
// Directory for Videos
_LIT(KDirVideos,"c:\\Nokia\\Videos\\");
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CFileListEngine::ConstructL(const TRect& aRect)
// Symbian two phased constructor
// ---------------------------------------------------------
//
void CFileListEngine::ConstructL()
{
}
// Destructor
CFileListEngine::~CFileListEngine()
{
// Delete directory list
delete iDirList;
}
// ---------------------------------------------------------
// CFileListEngine::StartFileList()
// This Method reads the appropriate directory list.
// ---------------------------------------------------------
//
TInt CFileListEngine::StartFileList()
{
if (iDirList)
{
delete iDirList;
iDirList = 0;
}
TInt error = KErrNone;
// Connect to fileserver
User::LeaveIfError(iFsSession.Connect());
switch (iDirectory)
{
// Get dir. KEntryAttNormal means that no hidden files or directories are included
case EFileListSounds:
error = iFsSession.GetDir(KDirSounds,KEntryAttNormal,ESortByName,iDirList);
break;
case EFileListPictures:
error = iFsSession.GetDir(KDirPictures,KEntryAttNormal,ESortByName,iDirList);
break;
case EFileListVideos:
error = iFsSession.GetDir(KDirVideos,KEntryAttNormal,ESortByName,iDirList);
break;
default:
error = iFsSession.GetDir(KDirSounds,KEntryAttNormal,ESortByName,iDirList);
break;
}
return error;
}
// ---------------------------------------------------------
// CFileListEngine::GetFileListItems(CDesCArray* aItems)
// This Method constructs the listbox items with directory
// information
// ---------------------------------------------------------
//
void CFileListEngine::GetFileListItems(CDesCArray* aItems)
{
if(!iDirList)
return;
for (TInt i=0;i<iDirList->Count();i++)
{
TFileName filename = NULL;
if(iSizeDate==EFileListSize)
{
// Show file size
filename.Format(KStringSize,i+1,&(*iDirList)[i].iName,(*iDirList)[i].iSize);
}
else
{
// Fix the date and time string of last modification
TBuf<30> dateString;
_LIT(KDateString,"%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B");
(*iDirList)[i].iModified.FormatL(dateString,KDateString);
// Show date modified
filename.Format(KStringDate,i+1,&(*iDirList)[i].iName,&dateString);
}
aItems->AppendL(filename);
}
}
// ---------------------------------------------------------
// CFileListEngine::SetDirectory(TInt aDirectory)
// This Method sets which directory to list.
// ---------------------------------------------------------
//
void CFileListEngine::SetDirectory(TInt aDirectory)
{
if (aDirectory!=EFileListDirNoChange)
iDirectory=aDirectory;
}
// ---------------------------------------------------------
// CFileListEngine::LaunchCurrent(TInt aPosition)
// This Method launches selected item with DocumentHandler.
// DocumentHandler will launch correct application depending
// on the file type.
// Note that all the extensions do not work on emulator.
// ---------------------------------------------------------
//
void CFileListEngine::LaunchCurrent(TInt aPosition)
{
if(!iDirList)
return;
//Launch current item in the list
CDocumentHandler* handler = CDocumentHandler::NewL(NULL);
CleanupStack::PushL(handler);
TFileName descr;
// Use appropriate directory path for launching file
switch (iDirectory)
{
case EFileListSounds:
descr.Append(KDirSounds);
break;
case EFileListPictures:
descr.Append(KDirPictures);
break;
case EFileListVideos:
descr.Append(KDirVideos);
break;
default:
descr.Append(KDirSounds);
break;
}
// Add filename to be launched
descr.Append((*iDirList)[aPosition].iName);
// Create nullType. This makes the DocumentHandler to figure out the posfix for us.
TDataType nullType;
// Launch the appropriate application for this file
handler->OpenFileL(descr,nullType);
CleanupStack::PopAndDestroy(); // handler
};
// ---------------------------------------------------------
// CFileListEngine::RemoveItems(CDesCArray* aItems)
// This Method removes all listbox items when a new list
// needs to be shown.
// ---------------------------------------------------------
//
TBool CFileListEngine::RemoveItems(CDesCArray* aItems)
{
if(iDirList)
{
if (iDirList->Count())
{
aItems->Delete(0,(iDirList->Count()));
return ETrue;
}
}
return EFalse;
};
// ---------------------------------------------------------
// CFileListEngine::SetSizeDate(TInt aSizeDate)
// This Method sets whether modification date or file size
// is shown. There is also option for toggling the status.
// ---------------------------------------------------------
//
void CFileListEngine::SetSizeDate(TInt aSizeDate)
{
if (aSizeDate==EFileListToggle)
if (iSizeDate==EFileListSize)
iSizeDate=EFileListDate;
else
iSizeDate=EFileListSize;
else
if (aSizeDate!=EFileListSizeDateNoChange)
iSizeDate=aSizeDate;
};
// ---------------------------------------------------------
// CFileListEngine::EndFileList()
// This Method ends the FileList session
// ---------------------------------------------------------
//
void CFileListEngine::EndFileList()
{
// Close the file server session
iFsSession.Close();
};