Music Hub ..
A session-wide music playback service
Loading...
Searching...
No Matches
uri_check.h
Go to the documentation of this file.
1/*
2 *
3 * This program is free software: you can redistribute it and/or modify it
4 * under the terms of the GNU Lesser General Public License version 3,
5 * as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *
15 * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
16 *
17 */
18
19#ifndef URI_CHECK_H
20#define URI_CHECK_H
21
22#include <QFile>
23#include <QUrl>
24
25#include <memory>
26
27namespace lomiri
28{
29namespace MediaHubService
30{
31
33{
34public:
35 typedef std::shared_ptr<UriCheck> Ptr;
36
38 : is_local_file_(false),
39 local_file_exists_(false)
40 {
41 }
42
43 UriCheck(const QUrl &uri)
44 : uri_(uri),
45 is_local_file_(determine_if_local_file()),
46 local_file_exists_(determine_if_file_exists())
47 {
48 }
49
50 virtual ~UriCheck()
51 {
52 }
53
54 void set(const QUrl &uri)
55 {
56 if (uri.isEmpty())
57 return;
58
59 uri_ = uri;
60 is_local_file_ = determine_if_local_file();
61 local_file_exists_ = determine_if_file_exists();
62 }
63
64 void clear()
65 {
66 uri_.clear();
67 }
68
69 bool is_local_file() const
70 {
71 return is_local_file_;
72 }
73
74 bool file_exists() const
75 {
76 return local_file_exists_;
77 }
78
79protected:
80 UriCheck(const UriCheck&) = delete;
81 UriCheck& operator=(const UriCheck&) = delete;
82
83private:
84 bool determine_if_local_file()
85 {
86 return uri_.isLocalFile();
87 }
88
89 bool determine_if_file_exists()
90 {
91 if (!is_local_file_)
92 return false;
93
94 return QFile::exists(uri_.toLocalFile());
95 }
96
97private:
98 QUrl uri_;
99 bool is_local_file_;
100 bool local_file_exists_;
101};
102
103}
104}
105
106#endif // URI_CHECK_H
UriCheck(const UriCheck &)=delete
UriCheck & operator=(const UriCheck &)=delete
void set(const QUrl &uri)
Definition uri_check.h:54
std::shared_ptr< UriCheck > Ptr
Definition uri_check.h:35