ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/DecentralizedMedia/MediaFolder.cpp
(Generate patch)

Comparing DecentralizedMedia/MediaFolder.cpp (file contents):
Revision 478 by douglas, 2005-06-08T17:16:59-07:00 vs.
Revision 555 by douglas, 2005-07-10T21:18:35-07:00

# Line 4 | Line 4
4   //
5   // $Id$
6  
7 + #include <menes/c++/standard.hh>
8 +
9 + #include <menes/dbi/resultset.hpp>
10 +
11   #include "MediaFolder.hpp"
12 + #include "Share.hpp"
13 +
14 + MediaFolder::MediaFolder(const _R<Connector>& connector, const api::Path& path) : connector(connector), path(path)
15 + {
16 +        _R<dbi::Connection> connection(connector->Connect());
17 +        _R<dbi::ResultSet> root_(connection->Parse(_B("SELECT root FROM folders WHERE path = ?"))->Execute(path.GetPath()));
18 +
19 +        if (root_->MoveNext())
20 +                root = root_->GetString(_B("root"));
21 +
22 +        connector->Release(connection);
23 + }
24  
25 < MediaFolder::MediaFolder(const api::Path& path) : path(path)
25 > MediaFolder::MediaFolder(const _R<Connector>& connector, const api::Path& path, const api::Path& root) : connector(connector), path(path), root(root)
26   {
27 <        // XXX: implement
27 >        _R<dbi::Connection> connection(connector->Connect());
28 >        _R<dbi::ResultSet> path_(connection->Parse(_B("SELECT path FROM folders WHERE path = ?"))->Execute(path.GetPath()));
29 >
30 >        if (path_->MoveNext())
31 >                if (path.GetPath() != root.GetPath())
32 >                        connection->Parse(_B("UPDATE folders SET folder = ?, root = ? WHERE path = ?"))->Execute(path.GetParent().GetPath(), root.GetPath(), path.GetPath());
33 >                else
34 >                        connection->Parse(_B("UPDATE folders SET folder = NULL, root = ? WHERE path = ?"))->Execute(root.GetPath(), path.GetPath());
35 >        else
36 >                if (path.GetPath() != root.GetPath())
37 >                        connection->Parse(_B("INSERT INTO folders (path, folder, root) VALUES (?, ?, ?)"))->Execute(path.GetPath(), path.GetParent().GetPath(), root.GetPath());
38 >                else
39 >                        connection->Parse(_B("INSERT INTO folders (path, folder, root) VALUES (?, NULL, ?)"))->Execute(path.GetPath(), root.GetPath());
40 >
41 >        connector->Release(connection);
42   }
43  
44 < MediaFolder::MediaFolder(const api::Path& path, const _L<MediaFile>& files) : path(path)
44 > cse::String MediaFolder::GetName() const
45   {
46 <        // XXX: implement
46 >        if (path == root && path.GetPath().StartsWithAll(Share::shares.GetPath()))
47 >        {
48 >                api::Address address(api::Address::Resolve(path.GetParent().GetName(), _B("6996")).First());
49 >                cse::String host, port;
50 >
51 >                address.ToString(host, port, true);
52 >
53 >                return _S<ios::String>() << _B("Share from ") << host;
54 >        }
55 >        else
56 >                return path.GetName();
57   }
58  
59 < _L<MediaFile> MediaFolder::GetFiles() const
59 > _L<MediaFile> MediaFolder::GetFiles(unsigned page) const
60   {
61 +        _R<dbi::Connection> connection(connector->Connect());
62 +        _R<dbi::ResultSet> paths(connection->Parse(_B("SELECT path FROM files WHERE live = TRUE AND folder = ? ORDER BY path LIMIT 50 OFFSET ?"))->Execute(path.GetPath(), page * 50));
63          _L<MediaFile> files;
64  
65 <        // XXX: implement
65 >        while (paths->MoveNext())
66 >                files.InsertLast(MediaFile(connector, paths->GetString(_B("path"))));
67 >
68 >        connector->Release(connection);
69  
70          return files;
71   }
72  
73 < _L<MediaFolder> MediaFolder::GetFolders() const
73 > _L<MediaFolder> MediaFolder::GetFolders(unsigned page) const
74   {
75 +        _R<dbi::Connection> connection(connector->Connect());
76 +        _R<dbi::ResultSet> paths(connection->Parse(_B("SELECT path FROM folders WHERE folder = ? ORDER BY path LIMIT 50 OFFSET ?"))->Execute(path.GetPath(), page * 50));
77          _L<MediaFolder> folders;
78  
79 <        // XXX: implement
79 >        while (paths->MoveNext())
80 >                folders.InsertLast(MediaFolder(connector, paths->GetString(_B("path"))));
81 >
82 >        connector->Release(connection);
83          
84          return folders;
85   }
36
37 void MediaFolder::SetFolders(const _L<MediaFolder>& folders)
38 {
39        // XXX: implement
40 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines