~vanvugt/ubuntu/oneiric/mediatomb/fix-770964-784431

« back to all changes in this revision

Viewing changes to src/web/directories.cc

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2008-02-02 01:42:48 UTC
  • Revision ID: james.westby@ubuntu.com-20080202014248-cjouolddb8gi2zkz
Tags: upstream-0.10.0.dfsg1
ImportĀ upstreamĀ versionĀ 0.10.0.dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*MT*
 
2
    
 
3
    MediaTomb - http://www.mediatomb.cc/
 
4
    
 
5
    directories.cc - this file is part of MediaTomb.
 
6
    
 
7
    Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
 
8
                       Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
 
9
    
 
10
    Copyright (C) 2006-2007 Gena Batyan <bgeradz@mediatomb.cc>,
 
11
                            Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
 
12
                            Leonhard Wimmer <leo@mediatomb.cc>
 
13
    
 
14
    MediaTomb is free software; you can redistribute it and/or modify
 
15
    it under the terms of the GNU General Public License version 2
 
16
    as published by the Free Software Foundation.
 
17
    
 
18
    MediaTomb is distributed in the hope that it will be useful,
 
19
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
    GNU General Public License for more details.
 
22
    
 
23
    You should have received a copy of the GNU General Public License
 
24
    version 2 along with MediaTomb; if not, write to the Free Software
 
25
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
26
    
 
27
    $Id: directories.cc 1294 2007-05-13 16:28:24Z lww $
 
28
*/
 
29
 
 
30
/// \file directories.cc
 
31
 
 
32
#ifdef HAVE_CONFIG_H
 
33
    #include "autoconfig.h"
 
34
#endif
 
35
 
 
36
#include "common.h"
 
37
#include "pages.h"
 
38
#include "tools.h"
 
39
#include "storage.h"
 
40
#include "filesystem.h"
 
41
#include "string_converter.h"
 
42
 
 
43
using namespace zmm;
 
44
using namespace mxml;
 
45
 
 
46
web::directories::directories() : WebRequestHandler()
 
47
{
 
48
}
 
49
 
 
50
void web::directories::process()
 
51
{
 
52
    check_request();
 
53
 
 
54
    String path;
 
55
    String parentID = param(_("parent_id"));
 
56
    if (parentID == nil || parentID == "0")
 
57
        path = _(FS_ROOT_DIRECTORY);
 
58
    else
 
59
        path = hex_decode_string(parentID);
 
60
    
 
61
    Ref<Element> containers (new Element(_("containers")));
 
62
    containers->addAttribute(_("ofId"), parentID);
 
63
    containers->addAttribute(_("select_it"), param(_("select_it")));
 
64
    containers->addAttribute(_("type"), _("f"));
 
65
    root->appendChild(containers);
 
66
    
 
67
    Ref<Filesystem> fs(new Filesystem());
 
68
    
 
69
    Ref<Array<FsObject> > arr;
 
70
    try
 
71
    {
 
72
        arr = fs->readDirectory(path, FS_MASK_DIRECTORIES,
 
73
                                                      FS_MASK_DIRECTORIES);
 
74
    }
 
75
    catch (Exception e)
 
76
    {
 
77
        containers->addAttribute(_("success"), _("0"));
 
78
        return;
 
79
    }
 
80
    containers->addAttribute(_("success"), _("1"));
 
81
    
 
82
 
 
83
    for (int i = 0; i < arr->size(); i++)
 
84
    {
 
85
        Ref<FsObject> obj = arr->get(i);
 
86
 
 
87
        Ref<Element> ce(new Element(_("container")));
 
88
        String filename = obj->filename;
 
89
        String filepath;
 
90
        if (path.c_str()[path.length() - 1] == '/')
 
91
            filepath = path + filename;
 
92
        else
 
93
            filepath = path + '/' + filename;
 
94
        
 
95
        /// \todo replace hex_encode with base64_encode?
 
96
        String id = hex_encode(filepath.c_str(), filepath.length());
 
97
        ce->addAttribute(_("id"), id);
 
98
        if (obj->hasContent)
 
99
            ce->addAttribute(_("childCount"), String::from(1));
 
100
 
 
101
        Ref<StringConverter> f2i = StringConverter::f2i();
 
102
        ce->setText(f2i->convert(filename));
 
103
        containers->appendChild(ce);
 
104
    }
 
105
}