summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuilherme Lepsch <lepsch@expertisesolutions.com.br>2014-12-09 16:19:58 -0200
committerGuilherme Lepsch <lepsch@expertisesolutions.com.br>2014-12-09 16:19:58 -0200
commit113a080e468711e6af5695a4b2d15cec2d699cff (patch)
tree5caef440abdaa20b6a9c030764eb8f0bca6ad2cd
parent3a56797736cc7bda9b2377715d09d70f2cf6f787 (diff)
* eio_model C++ wrapper doesn't need to be unique_ptr. It's already ref-counted.
-rw-r--r--src/file_scanner.cc62
-rw-r--r--src/file_scanner.hh7
2 files changed, 25 insertions, 44 deletions
diff --git a/src/file_scanner.cc b/src/file_scanner.cc
index 928ef65..ce5a077 100644
--- a/src/file_scanner.cc
+++ b/src/file_scanner.cc
@@ -72,18 +72,25 @@ void file_scanner::scan_path(const std::string &path)
72{ 72{
73 //return; 73 //return;
74 std::cout << "Scanning path: " << path << std::endl; 74 std::cout << "Scanning path: " << path << std::endl;
75 std::unique_ptr<eio::model> file_model(new eio::model()); 75 eio::model file_model;
76 file_model->path_set(path); 76 std::cout << "Setting path: " << path << std::endl;
77 file_model->callback_children_count_changed_add( 77 file_model.path_set(path);
78 std::bind(&file_scanner::file_found, this, *file_model, std::placeholders::_3)); 78 std::cout << "Path have been set to: " << path << std::endl;
79 file_model->load(); 79 scan_path(file_model);
80 files.push_back(move(file_model)); 80}
81
82void file_scanner::scan_path(eio::model path)
83{
84 path.callback_children_count_changed_add(
85 std::bind(&file_scanner::file_found, this, path, std::placeholders::_3));
86 path.load();
87 files.push_back(path);
81} 88}
82 89
83static int count = -1; 90static int count = -1;
84const auto MAX_COUNT = 20; 91const auto MAX_COUNT = 20;
85 92
86bool file_scanner::file_found(eio::model &file_model, void *info) 93bool file_scanner::file_found(eio::model file_model, void *info)
87{ 94{
88 if (count > MAX_COUNT) return true; 95 if (count > MAX_COUNT) return true;
89 96
@@ -109,7 +116,7 @@ bool file_scanner::file_found(eio::model &file_model, void *info)
109 return true; 116 return true;
110} 117}
111 118
112bool file_scanner::file_status(eio::model &file, void *info) 119bool file_scanner::file_status(eio::model file, void *info)
113{ 120{
114 if (count > MAX_COUNT) return false; 121 if (count > MAX_COUNT) return false;
115 122
@@ -131,7 +138,7 @@ bool file_scanner::file_status(eio::model &file, void *info)
131 ) return false; 138 ) return false;
132 139
133 if (is_directory) 140 if (is_directory)
134 scan_path(path); 141 scan_path(file);
135 else 142 else
136 check_media_file(path); 143 check_media_file(path);
137 144
@@ -147,38 +154,6 @@ void file_scanner::check_media_file(const std::string &path)
147 } 154 }
148 std::cout << "Notifying: " << path << std::endl; 155 std::cout << "Notifying: " << path << std::endl;
149 pending_file.notify_one(); 156 pending_file.notify_one();
150
151 /*std::cout << "Checking if filename is a recognized media type: " << path << std::endl;
152
153 TagLib::FileRef file(path.c_str());
154 if (file.isNull() || !file.tag())
155 return;
156
157 if (count == -1)
158 count = 0;
159 else
160 ++count;
161
162 TagLib::Tag *tag = file.tag();
163
164 auto to_string = [](const TagLib::String &str) -> std::string
165 {
166 if (str == TagLib::String::null)
167 return "";
168
169 const auto UNICODE = true;
170 return str.to8Bit(UNICODE);
171 };
172
173 ::emc::tag new_tag;
174 new_tag.file = path;
175 new_tag.title = to_string(tag->title());
176 new_tag.track = tag->track();
177 new_tag.artist = to_string(tag->artist());
178 new_tag.album = to_string(tag->album());
179 new_tag.genre = to_string(tag->genre());
180 new_tag.year = tag->year();
181 media_file_add_cb(new_tag);*/
182} 157}
183 158
184void file_scanner::process() 159void file_scanner::process()
@@ -215,6 +190,11 @@ file_scanner::process_file(const std::string &path)
215 if (file.isNull() || !file.tag()) 190 if (file.isNull() || !file.tag())
216 return; 191 return;
217 192
193 if (count == -1)
194 count = 0;
195 else
196 ++count;
197
218 TagLib::Tag *tag = file.tag(); 198 TagLib::Tag *tag = file.tag();
219 199
220 auto to_string = [](const TagLib::String &str) -> std::string 200 auto to_string = [](const TagLib::String &str) -> std::string
diff --git a/src/file_scanner.hh b/src/file_scanner.hh
index f44640c..f3fcf76 100644
--- a/src/file_scanner.hh
+++ b/src/file_scanner.hh
@@ -39,8 +39,9 @@ public:
39private: 39private:
40 std::vector<std::string> get_configured_paths() const; 40 std::vector<std::string> get_configured_paths() const;
41 void scan_path(const std::string &path); 41 void scan_path(const std::string &path);
42 bool file_found(eio::model &file_model, void *info); 42 void scan_path(eio::model path);
43 bool file_status(eio::model &file_model, void *info); 43 bool file_found(eio::model file_model, void *info);
44 bool file_status(eio::model file_model, void *info);
44 void check_media_file(const std::string &path); 45 void check_media_file(const std::string &path);
45 46
46 void process(); 47 void process();
@@ -48,7 +49,7 @@ private:
48 void process_file(const std::string &path); 49 void process_file(const std::string &path);
49 50
50private: 51private:
51 std::vector<std::unique_ptr<eio::model>> files; 52 std::vector<eio::model> files;
52 std::function<void(const tag&)> media_file_add_cb; 53 std::function<void(const tag&)> media_file_add_cb;
53 ::efl::eina::condition_variable pending_file; 54 ::efl::eina::condition_variable pending_file;
54 ::efl::eina::mutex mutex; 55 ::efl::eina::mutex mutex;