Music Hub  ..
A session-wide music playback service
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 
27 namespace lomiri
28 {
29 namespace MediaHubService
30 {
31 
32 class UriCheck
33 {
34 public:
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 
79 protected:
80  UriCheck(const UriCheck&) = delete;
81  UriCheck& operator=(const UriCheck&) = delete;
82 
83 private:
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 
97 private:
98  QUrl uri_;
99  bool is_local_file_;
100  bool local_file_exists_;
101 };
102 
103 }
104 }
105 
106 #endif // URI_CHECK_H
lomiri::MediaHubService::UriCheck
Definition: uri_check.h:32
lomiri::MediaHubService::UriCheck::is_local_file
bool is_local_file() const
Definition: uri_check.h:69
lomiri::MediaHubService::UriCheck::~UriCheck
virtual ~UriCheck()
Definition: uri_check.h:50
lomiri::MediaHubService::UriCheck::UriCheck
UriCheck(const QUrl &uri)
Definition: uri_check.h:43
lomiri::MediaHubService::UriCheck::UriCheck
UriCheck()
Definition: uri_check.h:37
lomiri::MediaHubService::UriCheck::clear
void clear()
Definition: uri_check.h:64
lomiri::MediaHubService::UriCheck::operator=
UriCheck & operator=(const UriCheck &)=delete
lomiri::MediaHubService::UriCheck::set
void set(const QUrl &uri)
Definition: uri_check.h:54
lomiri::MediaHubService::UriCheck::file_exists
bool file_exists() const
Definition: uri_check.h:74
lomiri
Definition: dbus_utils.h:24
lomiri::MediaHubService::UriCheck::Ptr
std::shared_ptr< UriCheck > Ptr
Definition: uri_check.h:35