CLOUD: Add icons in "/files" list

This commit is contained in:
Alexander Tkachev 2016-07-15 13:46:43 +06:00
parent 626d85ea49
commit 06ccfd4b9a
11 changed files with 49 additions and 15 deletions

View file

@ -17,12 +17,14 @@ def buildArchive(archiveName):
print ("Building '" + archiveName + "' archive:") print ("Building '" + archiveName + "' archive:")
os.chdir(archiveName) os.chdir(archiveName)
filenames = os.listdir('.') directories = ['.', './icons']
for d in directories:
filenames = os.listdir(d)
filenames.sort() filenames.sort()
for filename in filenames: for filename in filenames:
if os.path.isfile(filename) and filename.endswith(ARCHIVE_FILE_EXTENSIONS): if os.path.isfile(d + '/' + filename) and filename.endswith(ARCHIVE_FILE_EXTENSIONS):
zf.write(filename, './' + filename) zf.write(d + '/' + filename, d + '/' + filename)
print (" Adding file: " + filename) print (" Adding file: " + d + '/' + filename)
os.chdir('../') os.chdir('../')

View file

@ -68,7 +68,7 @@ void FilesPageHandler::handle(Client &client) {
"<table>{content}</table>" \ "<table>{content}</table>" \
"</body>" \ "</body>" \
"</html>"; "</html>";
Common::String itemTemplate = "<tr><td><a href=\"{link}\">{name}</a></td><td>{size}</td></tr>\n"; //TODO: load this template too? Common::String itemTemplate = "<tr><td><img src=\"icons/{icon}\"/></td><td><a href=\"{link}\">{name}</a></td><td>{size}</td></tr>\n"; //TODO: load this template too?
// load stylish response page from the archive // load stylish response page from the archive
Common::SeekableReadStream *const stream = HandlerUtils::getArchiveFile(FILES_PAGE_NAME); Common::SeekableReadStream *const stream = HandlerUtils::getArchiveFile(FILES_PAGE_NAME);
@ -99,8 +99,8 @@ void FilesPageHandler::handle(Client &client) {
bool FilesPageHandler::listDirectory(Common::String path, Common::String &content, const Common::String &itemTemplate) { bool FilesPageHandler::listDirectory(Common::String path, Common::String &content, const Common::String &itemTemplate) {
if (path == "" || path == "/") { if (path == "" || path == "/") {
addItem(content, itemTemplate, true, "/root/", _("File system root")); addItem(content, itemTemplate, IT_DIRECTORY, "/root/", _("File system root"));
addItem(content, itemTemplate, true, "/saves/", _("Saved games")); addItem(content, itemTemplate, IT_DIRECTORY, "/saves/", _("Saved games"));
return true; return true;
} }
@ -127,7 +127,7 @@ bool FilesPageHandler::listDirectory(Common::String path, Common::String &conten
filePath = "/"; filePath = "/";
else else
filePath = parentPath(prefixToAdd + filePath); filePath = parentPath(prefixToAdd + filePath);
addItem(content, itemTemplate, true, filePath, _("Parent directory")); addItem(content, itemTemplate, IT_PARENT_DIRECTORY, filePath, _("Parent directory"));
} }
// fill the content // fill the content
@ -140,14 +140,32 @@ bool FilesPageHandler::listDirectory(Common::String path, Common::String &conten
filePath.erase(0, prefixToRemove.size()); filePath.erase(0, prefixToRemove.size());
filePath = prefixToAdd + filePath; filePath = prefixToAdd + filePath;
addItem(content, itemTemplate, i->isDirectory(), filePath, name); addItem(content, itemTemplate, detectType(i->isDirectory(), name), filePath, name);
} }
return true; return true;
} }
void FilesPageHandler::addItem(Common::String &content, const Common::String &itemTemplate, bool isDirectory, Common::String path, Common::String name, Common::String size) { FilesPageHandler::ItemType FilesPageHandler::detectType(bool isDirectory, const Common::String &name) const {
Common::String item = itemTemplate; if (isDirectory) return IT_DIRECTORY;
if (name.hasSuffix(".txt")) return IT_TXT;
if (name.hasSuffix(".zip")) return IT_ZIP;
if (name.hasSuffix(".7z")) return IT_7Z;
return IT_UNKNOWN;
}
void FilesPageHandler::addItem(Common::String &content, const Common::String &itemTemplate, ItemType itemType, Common::String path, Common::String name, Common::String size) {
Common::String item = itemTemplate, icon;
bool isDirectory = (itemType == IT_DIRECTORY || itemType == IT_PARENT_DIRECTORY);
switch (itemType) {
case IT_DIRECTORY: icon = "dir.png"; break;
case IT_PARENT_DIRECTORY: icon = "up.png"; break;
case IT_TXT: icon = "txt.png"; break;
case IT_ZIP: icon = "zip.png"; break;
case IT_7Z: icon = "7z.png"; break;
default: icon = "unk.png";
}
replace(item, "{icon}", icon);
replace(item, "{link}", (isDirectory ? "files?path=" : "download?path=") + LocalWebserver::urlEncodeQueryParameterValue(path)); replace(item, "{link}", (isDirectory ? "files?path=" : "download?path=") + LocalWebserver::urlEncodeQueryParameterValue(path));
replace(item, "{name}", name); replace(item, "{name}", name);
replace(item, "{size}", size); replace(item, "{size}", size);

View file

@ -28,6 +28,15 @@
namespace Networking { namespace Networking {
class FilesPageHandler: public FilesBaseHandler { class FilesPageHandler: public FilesBaseHandler {
enum ItemType {
IT_DIRECTORY,
IT_PARENT_DIRECTORY,
IT_TXT,
IT_ZIP,
IT_7Z,
IT_UNKNOWN
};
void handle(Client &client); void handle(Client &client);
/** /**
@ -37,8 +46,11 @@ class FilesPageHandler: public FilesBaseHandler {
*/ */
bool listDirectory(Common::String path, Common::String &content, const Common::String &itemTemplate); bool listDirectory(Common::String path, Common::String &content, const Common::String &itemTemplate);
/** Helper method for detecting items' type. */
ItemType detectType(bool isDirectory, const Common::String &name) const;
/** Helper method for adding items into the files list. */ /** Helper method for adding items into the files list. */
void addItem(Common::String &content, const Common::String &itemTemplate, bool isDirectory, Common::String path, Common::String name, Common::String size = ""); void addItem(Common::String &content, const Common::String &itemTemplate, ItemType itemType, Common::String path, Common::String name, Common::String size = "");
public: public:
FilesPageHandler(); FilesPageHandler();

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 B

View file

@ -86,3 +86,5 @@ html {
background: #F3F3F3; background: #F3F3F3;
cursor: pointer; cursor: pointer;
} }
td img { vertical-align: middle; height: 20px; }