ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/DecentralizedMedia/MediaFolder.cpp
Revision: 550
Committed: 2005-07-04T23:37:40-07:00 (19 years, 11 months ago) by douglas
File size: 2499 byte(s)
Log Message:
Worky, um, -ish.

File Contents

# User Rev Content
1 douglas 476 // Media Folder
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7 douglas 516 #include <menes/standard.hh>
8 douglas 478
9 douglas 549 #include <menes/dbi/resultset.hpp>
10 douglas 489
11 douglas 516 #include "MediaFolder.hpp"
12 douglas 550 #include "Share.hpp"
13 douglas 516
14 douglas 542 MediaFolder::MediaFolder(const _R<dbi::Connection>& connection, const api::Path& path) : connection(connection), path(path)
15 douglas 478 {
16 douglas 541 _R<dbi::ResultSet> root_(connection->Parse(_B("SELECT root FROM folders WHERE path = ?"))->Execute(path.GetPath()));
17 douglas 500
18     if (root_->MoveNext())
19     root = root_->GetString(_B("root"));
20 douglas 478 }
21    
22 douglas 542 MediaFolder::MediaFolder(const _R<dbi::Connection>& connection, const api::Path& path, const api::Path& root) : connection(connection), path(path), root(root)
23 douglas 496 {
24 douglas 541 _R<dbi::ResultSet> path_(connection->Parse(_B("SELECT path FROM folders WHERE path = ?"))->Execute(path.GetPath()));
25 douglas 496
26 douglas 500 if (path_->MoveNext())
27 douglas 498 if (path.GetPath() != root.GetPath())
28 douglas 500 connection->Parse(_B("UPDATE folders SET folder = ?, root = ? WHERE path = ?"))->Execute(path.GetParent().GetPath(), root.GetPath(), path.GetPath());
29     else
30     connection->Parse(_B("UPDATE folders SET folder = NULL, root = ? WHERE path = ?"))->Execute(root.GetPath(), path.GetPath());
31     else
32     if (path.GetPath() != root.GetPath())
33 douglas 498 connection->Parse(_B("INSERT INTO folders (path, folder, root) VALUES (?, ?, ?)"))->Execute(path.GetPath(), path.GetParent().GetPath(), root.GetPath());
34     else
35     connection->Parse(_B("INSERT INTO folders (path, folder, root) VALUES (?, NULL, ?)"))->Execute(path.GetPath(), root.GetPath());
36 douglas 496 }
37    
38 douglas 550 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 douglas 478 _L<MediaFile> MediaFolder::GetFiles() const
54     {
55 douglas 550 _R<dbi::ResultSet> paths(connection->Parse(_B("SELECT path FROM files WHERE live = TRUE AND folder = ? ORDER BY path"))->Execute(path.GetPath()));
56 douglas 478 _L<MediaFile> files;
57    
58 douglas 488 while (paths->MoveNext())
59     files.InsertLast(MediaFile(connection, paths->GetString(_B("path"))));
60 douglas 478
61     return files;
62     }
63    
64     _L<MediaFolder> MediaFolder::GetFolders() const
65     {
66 douglas 550 _R<dbi::ResultSet> paths(connection->Parse(_B("SELECT path FROM folders WHERE folder = ? ORDER BY path"))->Execute(path.GetPath()));
67 douglas 478 _L<MediaFolder> folders;
68    
69 douglas 488 while (paths->MoveNext())
70     folders.InsertLast(MediaFolder(connection, paths->GetString(_B("path"))));
71 douglas 478
72     return folders;
73     }

Properties

Name Value
svn:eol-style native
svn:keywords Id