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 516 by douglas, 2005-06-20T20:34:13-07:00 vs.
Revision 554 by douglas, 2005-07-10T04:22:54-07:00

# Line 4 | Line 4
4   //
5   // $Id$
6  
7 < #include <menes/standard.hh>
7 > #include <menes/c++/standard.hh>
8  
9 < #include <menes-dbi/resultset.hpp>
9 > #include <menes/dbi/resultset.hpp>
10  
11   #include "MediaFolder.hpp"
12 + #include "Share.hpp"
13  
14 < MediaFolder::MediaFolder(_H<dbi::Connection>& connection, const api::Path& path) : connection(connection), path(path)
14 > MediaFolder::MediaFolder(const _R<dbi::Connection>& connection, const api::Path& path) : connection(connection), path(path)
15   {
16 <        _H<dbi::ResultSet> root_(connection->Parse(_B("SELECT root FROM folders WHERE path = ?"))->Execute(path.GetPath()));
16 >        _R<dbi::ResultSet> root_(connection->Parse(_B("SELECT root FROM folders WHERE path = ?"))->Execute(path.GetPath()));
17  
18          if (root_->MoveNext())
19                  root = root_->GetString(_B("root"));
19        else
20                throw;
20   }
21  
22 < MediaFolder::MediaFolder(_H<dbi::Connection>& connection, const api::Path& path, const api::Path& root) : connection(connection), path(path), root(root)
22 > MediaFolder::MediaFolder(const _R<dbi::Connection>& connection, const api::Path& path, const api::Path& root) : connection(connection), path(path), root(root)
23   {
24 <        _H<dbi::ResultSet> path_(connection->Parse(_B("SELECT path FROM folders WHERE path = ?"))->Execute(path.GetPath()));
24 >        _R<dbi::ResultSet> path_(connection->Parse(_B("SELECT path FROM folders WHERE path = ?"))->Execute(path.GetPath()));
25  
26          if (path_->MoveNext())
27                  if (path.GetPath() != root.GetPath())
# Line 36 | Line 35 | MediaFolder::MediaFolder(_H<dbi::Connect
35                          connection->Parse(_B("INSERT INTO folders (path, folder, root) VALUES (?, NULL, ?)"))->Execute(path.GetPath(), root.GetPath());
36   }
37  
38 < _L<MediaFile> MediaFolder::GetFiles() const
38 > cse::String MediaFolder::GetName() const
39 > {
40 >        if (path == root && path.GetPath().StartsWithAll(Share::shares.GetPath()))
41 >        {
42 >                api::Address address(api::Address::Resolve(path.GetParent().GetName(), _B("6996")).First());
43 >                cse::String host, port;
44 >
45 >                address.ToString(host, port, true);
46 >
47 >                return _S<ios::String>() << _B("Share from ") << host;
48 >        }
49 >        else
50 >                return path.GetName();
51 > }
52 >
53 > _L<MediaFile> MediaFolder::GetFiles(unsigned page) const
54   {
55 <        _H<dbi::ResultSet> paths(connection->Parse(_B("SELECT path FROM files WHERE live = TRUE AND folder = ?"))->Execute(path.GetPath()));
55 >        _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));
56          _L<MediaFile> files;
57  
58          while (paths->MoveNext())
# Line 47 | Line 61 | _L<MediaFile> MediaFolder::GetFiles() co
61          return files;
62   }
63  
64 < _L<MediaFolder> MediaFolder::GetFolders() const
64 > _L<MediaFolder> MediaFolder::GetFolders(unsigned page) const
65   {
66 <        _H<dbi::ResultSet> paths(connection->Parse(_B("SELECT path FROM folders WHERE live = TRUE AND folder = ?"))->Execute(path.GetPath()));
66 >        _R<dbi::ResultSet> paths(connection->Parse(_B("SELECT path FROM folders WHERE folder = ? ORDER BY path LIMIT 50 OFFSET ?"))->Execute(path.GetPath(), page * 50));
67          _L<MediaFolder> folders;
68  
69          while (paths->MoveNext())

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines