summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuilherme Lepsch <lepsch@expertisesolutions.com.br>2015-01-02 16:18:35 -0200
committerGuilherme Lepsch <lepsch@expertisesolutions.com.br>2015-01-02 16:18:35 -0200
commit313adaa79300f87174008641b643d3e99e7bd2da (patch)
treeef4273b63cb651a4e6bc887ad9f3275807e2fde0
parentfd406f16266aab07a48107af2a87eaf1b57d4b64 (diff)
* Implemented function to reset all media files;
-rw-r--r--src/database.cc65
-rw-r--r--src/database.hh16
-rw-r--r--src/database_checker.cc57
-rw-r--r--src/database_checker.hh4
-rw-r--r--src/emodel_helpers.cc43
-rw-r--r--src/emodel_helpers.hh7
-rw-r--r--src/settingsctrl.cc6
-rw-r--r--src/settingsmodel.cc39
-rw-r--r--src/settingsmodel.hh23
9 files changed, 193 insertions, 67 deletions
diff --git a/src/database.cc b/src/database.cc
index 8901f2b..7dd4101 100644
--- a/src/database.cc
+++ b/src/database.cc
@@ -149,6 +149,71 @@ database::on_child_added(const Emodel_Children_Event &event)
149 tables.insert(std::make_pair(tablename, table)); 149 tables.insert(std::make_pair(tablename, table));
150} 150}
151 151
152void
153database::async_reset_media_tables(std::function<void(bool)> handler)
154{
155 DBG << "Reseting media tables";
156 emodel_helpers::async_child_del(db, {artists_get(), albums_get(), tracks_get()},
157 [this, handler](bool error)
158 {
159 if (error)
160 {
161 ERR << "Error deleting media tables";
162 handler(true);
163 return;
164 }
165
166 async_create_tables({&schema::artists_table, &schema::albums_table, &schema::tracks_table}, handler);
167 });
168}
169
170void
171database::async_create_tables(const std::vector<const schema::table*> &table_definitions, std::function<void(bool)> handler)
172{
173 auto count = std::make_shared<size_t>(table_definitions.size());
174
175 emc::emodel_helpers::callback_children_count_changed_add(db,
176 [count, handler](bool error, unsigned int actual_count) -> bool
177 {
178 if (error)
179 {
180 ERR << "Error creating table";
181 handler(true);
182 return false;
183 }
184
185 --(*count);
186 if (*count)
187 return true;
188
189 handler(false);
190 return false;
191 });
192
193 for (auto &table : table_definitions)
194 create_table(*table);
195}
196
197void
198database::create_table(const schema::table &table_definition)
199{
200 DBG << "Creating table: " << table_definition.name;
201 efl::eo::base obj = db.child_add();
202 esql::model_table table(::eo_ref(obj._eo_ptr()));
203 table.name_set(table_definition.name);
204
205 for (auto &field : table_definition.fields)
206 create_table_field(table, table_definition, field);
207}
208
209void
210database::create_table_field(esql::model_table table, const schema::table &table_definition, const schema::field &field_definition)
211{
212 DBG << "Creating field: " << table_definition.name << "." << field_definition.name;
213 ::efl::eina::value field_type(field_definition.type + " " + field_definition.constraint);
214 table.property_set(field_definition.name, *field_type.native_handle());
215}
216
152esql::model_database& 217esql::model_database&
153database::database_get() const 218database::database_get() const
154{ 219{
diff --git a/src/database.hh b/src/database.hh
index 055aa1f..0e09a27 100644
--- a/src/database.hh
+++ b/src/database.hh
@@ -41,6 +41,19 @@ public:
41 esql::model_table table_get(const std::string &table) const; 41 esql::model_table table_get(const std::string &table) const;
42 bool is_empty() const; 42 bool is_empty() const;
43 43
44 /**
45 * Creates tables by definitions
46 * @param handler The callback function to call once on success or error
47 */
48 void async_create_tables(const std::vector<const schema::table*> &table_definitions,
49 std::function<void(bool)> handler);
50
51 /**
52 * Reset artist, album and track tables
53 * @param handler The callback function to call once on success or error
54 */
55 void async_reset_media_tables(std::function<void(bool)> handler);
56
44private: 57private:
45 void success(); 58 void success();
46 void failure(); 59 void failure();
@@ -53,6 +66,9 @@ private:
53 void check_tables(); 66 void check_tables();
54 void on_child_added(const Emodel_Children_Event &event); 67 void on_child_added(const Emodel_Children_Event &event);
55 68
69 void create_table(const schema::table &table_definition);
70 void create_table_field(esql::model_table table, const schema::table &table_definition, const schema::field &field_definition);
71
56private: 72private:
57 std::vector<std::function<void(bool)>> handlers; 73 std::vector<std::function<void(bool)>> handlers;
58 mutable esql::model_database db; 74 mutable esql::model_database db;
diff --git a/src/database_checker.cc b/src/database_checker.cc
index eaebaa7..c4e10fe 100644
--- a/src/database_checker.cc
+++ b/src/database_checker.cc
@@ -97,25 +97,18 @@ database_checker::migrate_from_version_0()
97{ 97{
98 DBG << "Migrating from version 0"; 98 DBG << "Migrating from version 0";
99 99
100 std::function<void()> migration_done = std::bind(&database_checker::set_version, this, schema::CURRENT_VERSION); 100 database.async_create_tables(schema::tables,
101 101 [this](bool error)
102 emc::emodel_helpers::callback_children_count_changed_add(db, 102 {
103 std::bind(&database_checker::on_table_created, this, std::placeholders::_1, std::placeholders::_2, schema::tables.size(), migration_done)); 103 if (error)
104 104 {
105 for (auto &table : schema::tables) 105 ERR << "Error creating table";
106 create_table(*table); 106 failure();
107} 107 return;
108 108 }
109void
110database_checker::create_table(const schema::table &table_definition)
111{
112 DBG << "Creating table: " << table_definition.name;
113 efl::eo::base obj = db.child_add();
114 esql::model_table table(::eo_ref(obj._eo_ptr()));
115 table.name_set(table_definition.name);
116 109
117 for (auto &field : table_definition.fields) 110 set_version(schema::CURRENT_VERSION);
118 create_table_field(table, table_definition, field); 111 });
119} 112}
120 113
121void 114void
@@ -126,23 +119,6 @@ database_checker::create_table_field(esql::model_table table, const schema::tabl
126 table.property_set(field_definition.name, *field_type.native_handle()); 119 table.property_set(field_definition.name, *field_type.native_handle());
127} 120}
128 121
129bool
130database_checker::on_table_created(bool error, unsigned int actual_count, size_t expected_count, std::function<void()> migration_done)
131{
132 if (error)
133 {
134 ERR << "Error creating table";
135 failure();
136 return false;
137 }
138
139 if (actual_count != expected_count)
140 return true;
141
142 migration_done();
143 return false;
144}
145
146void 122void
147database_checker::set_version(int version) 123database_checker::set_version(int version)
148{ 124{
@@ -275,25 +251,22 @@ void
275database_checker::create_v2_tables() 251database_checker::create_v2_tables()
276{ 252{
277 DBG << "Creating version/settings table"; 253 DBG << "Creating version/settings table";
278 254 database.async_create_tables({&schema::v2::version_table, &schema::v2::settings_table},
279 emc::emodel_helpers::callback_children_count_changed_add(db,
280 std::bind(&database_checker::on_v2_tables_created, this, std::placeholders::_1)); 255 std::bind(&database_checker::on_v2_tables_created, this, std::placeholders::_1));
281 create_table(schema::v2::version_table);
282 create_table(schema::v2::settings_table);
283} 256}
284 257
285bool 258void
286database_checker::on_v2_tables_created(bool error) 259database_checker::on_v2_tables_created(bool error)
287{ 260{
288 if (error) 261 if (error)
289 { 262 {
290 ERR << "Error creating version table"; 263 ERR << "Error creating version table";
291 failure(); 264 failure();
292 return false; 265 return;
293 } 266 }
294 267
295 set_version(schema::v2::VERSION); 268 set_version(schema::v2::VERSION);
296 return false; 269 return;
297} 270}
298 271
299void 272void
diff --git a/src/database_checker.hh b/src/database_checker.hh
index 55d56ae..8ba9d64 100644
--- a/src/database_checker.hh
+++ b/src/database_checker.hh
@@ -39,9 +39,7 @@ private:
39 void on_version_row_loaded(bool error, esql::model_row row); 39 void on_version_row_loaded(bool error, esql::model_row row);
40 40
41 void migrate_from_version_0(); 41 void migrate_from_version_0();
42 void create_table(const schema::table &table_definition);
43 void create_table_field(esql::model_table table, const schema::table &table_definition, const schema::field &field_definition); 42 void create_table_field(esql::model_table table, const schema::table &table_definition, const schema::field &field_definition);
44 bool on_table_created(bool error, unsigned int actual_count, size_t expected_count, std::function<void()> migration_done);
45 void set_version(int version); 43 void set_version(int version);
46 void on_version_table_loaded(bool error, esql::model_table version_table, int version); 44 void on_version_table_loaded(bool error, esql::model_table version_table, int version);
47 void load_version_row(bool error, esql::model_row row, int version); 45 void load_version_row(bool error, esql::model_row row, int version);
@@ -50,7 +48,7 @@ private:
50 48
51 void migrate_from_version_1(); 49 void migrate_from_version_1();
52 void create_v2_tables(); 50 void create_v2_tables();
53 bool on_v2_tables_created(bool error); 51 void on_v2_tables_created(bool error);
54 52
55 void migrate_from_version_2(); 53 void migrate_from_version_2();
56 void on_migration_completed(bool error, int version); 54 void on_migration_completed(bool error, int version);
diff --git a/src/emodel_helpers.cc b/src/emodel_helpers.cc
index e2a3758..4a23dd8 100644
--- a/src/emodel_helpers.cc
+++ b/src/emodel_helpers.cc
@@ -49,7 +49,7 @@ namespace
49 return false; 49 return false;
50 } 50 }
51 51
52 bool on_properties_changed_error(void *info, std::function<void()> disconnect, std::function<void(bool)> handler) 52 bool on_load_status_error(void *info, std::function<void()> disconnect, std::function<void(bool)> handler)
53 { 53 {
54 const Emodel_Load &st = *static_cast<Emodel_Load*>(info); 54 const Emodel_Load &st = *static_cast<Emodel_Load*>(info);
55 if (!(st.status & EMODEL_LOAD_STATUS_ERROR)) 55 if (!(st.status & EMODEL_LOAD_STATUS_ERROR))
@@ -111,6 +111,19 @@ namespace
111 const Emodel_Children_Event &event = *static_cast<Emodel_Children_Event*>(info); 111 const Emodel_Children_Event &event = *static_cast<Emodel_Children_Event*>(info);
112 handler(event); 112 handler(event);
113 } 113 }
114
115 void
116 on_child_removed(void *info, std::function<void()> disconnect, std::shared_ptr<int> count, std::function<void(bool)> handler)
117 {
118 DBG << "Child removed: " << *count;
119 --(*count);
120
121 if (!(*count))
122 {
123 disconnect();
124 handler(false);
125 }
126 }
114} 127}
115 128
116namespace emc { namespace emodel_helpers { 129namespace emc { namespace emodel_helpers {
@@ -156,6 +169,30 @@ void async_children_load(::emodel model, std::function<void(bool)> handler)
156 emc::emodel_helpers::async_load(child, std::bind(&on_child_loaded, std::placeholders::_1, count, handler)); 169 emc::emodel_helpers::async_load(child, std::bind(&on_child_loaded, std::placeholders::_1, count, handler));
157} 170}
158 171
172void async_child_del(::emodel model, const std::vector<::emodel> &children, std::function<void(bool)> handler)
173{
174 assert(!children.empty());
175
176 auto count = std::make_shared<int>(children.size());
177
178 auto child_removed_connection = std::make_shared<::efl::eo::signal_connection>(nullptr);
179 auto load_status_connection = std::make_shared<::efl::eo::signal_connection>(nullptr);
180 auto disconnect = [child_removed_connection, load_status_connection]
181 {
182 child_removed_connection->disconnect();
183 load_status_connection->disconnect();
184 };
185
186 *child_removed_connection = model.callback_child_removed_add(
187 std::bind(on_child_removed, std::placeholders::_3, disconnect, count, handler));
188
189 *load_status_connection = model.callback_load_status_add(
190 std::bind(on_load_status_error, std::placeholders::_3, disconnect, handler));
191
192 for (auto &child : children)
193 model.child_del(child);
194}
195
159void async_properties_load(::emodel model, std::function<void(bool)> handler) 196void async_properties_load(::emodel model, std::function<void(bool)> handler)
160{ 197{
161 if ((model.load_status_get() & EMODEL_LOAD_STATUS_LOADED_PROPERTIES) == EMODEL_LOAD_STATUS_LOADED_PROPERTIES) 198 if ((model.load_status_get() & EMODEL_LOAD_STATUS_LOADED_PROPERTIES) == EMODEL_LOAD_STATUS_LOADED_PROPERTIES)
@@ -185,7 +222,7 @@ void callback_properties_changed_once(::emodel model, std::function<void(bool)>
185 std::bind(on_properties_changed, std::placeholders::_3, disconnect, handler)); 222 std::bind(on_properties_changed, std::placeholders::_3, disconnect, handler));
186 223
187 *load_status_connection = model.callback_load_status_add( 224 *load_status_connection = model.callback_load_status_add(
188 std::bind(on_properties_changed_error, std::placeholders::_3, disconnect, handler)); 225 std::bind(on_load_status_error, std::placeholders::_3, disconnect, handler));
189} 226}
190 227
191void callback_children_count_changed_add(::emodel model, std::function<bool(bool, unsigned int)> handler) 228void callback_children_count_changed_add(::emodel model, std::function<bool(bool, unsigned int)> handler)
@@ -224,7 +261,7 @@ void async_property_set<::efl::eina::value>(::emodel model, const std::string &p
224 std::bind(on_properties_changed_event, std::placeholders::_3, disconnect, handler)); 261 std::bind(on_properties_changed_event, std::placeholders::_3, disconnect, handler));
225 262
226 *load_status_connection = model.callback_load_status_add( 263 *load_status_connection = model.callback_load_status_add(
227 std::bind(on_properties_changed_error, std::placeholders::_3, disconnect, 264 std::bind(on_load_status_error, std::placeholders::_3, disconnect,
228 [handler](bool error) 265 [handler](bool error)
229 { 266 {
230 handler(error, std::vector<Emodel_Property_Pair*>()); 267 handler(error, std::vector<Emodel_Property_Pair*>());
diff --git a/src/emodel_helpers.hh b/src/emodel_helpers.hh
index 4529dba..a9bf213 100644
--- a/src/emodel_helpers.hh
+++ b/src/emodel_helpers.hh
@@ -129,6 +129,13 @@ void async_properties_load(::emodel model, std::function<void(bool)> handler);
129void async_children_load(::emodel model, std::function<void(bool)> handler); 129void async_children_load(::emodel model, std::function<void(bool)> handler);
130 130
131/** 131/**
132 * Deletes all children and calls handler assynchronously once on success or error
133 * @param model [description]
134 * @param handler [description]
135 */
136void async_child_del(::emodel model, const std::vector<::emodel> &children, std::function<void(bool)> handler);
137
138/**
132 * Asynchronously set a property givin the property name and its value 139 * Asynchronously set a property givin the property name and its value
133 * @param model The model 140 * @param model The model
134 * @param property The property name 141 * @param property The property name
diff --git a/src/settingsctrl.cc b/src/settingsctrl.cc
index 9eec2ff..e9b928b 100644
--- a/src/settingsctrl.cc
+++ b/src/settingsctrl.cc
@@ -51,6 +51,12 @@ settingsctrl::settingsctrl(settingsmodel &_settings, const std::function<void()>
51 bool f = fullscreen_check.state_get(); 51 bool f = fullscreen_check.state_get();
52 settings.fullscreen_set(f); 52 settings.fullscreen_set(f);
53 })); 53 }));
54
55 mupdate_bt.callback_clicked_add(
56 std::bind([this]
57 {
58 settings.update_media();
59 }));
54} 60}
55 61
56void 62void
diff --git a/src/settingsmodel.cc b/src/settingsmodel.cc
index a60a177..96f9e4b 100644
--- a/src/settingsmodel.cc
+++ b/src/settingsmodel.cc
@@ -2,20 +2,21 @@
2 * EMC - Enlightenment Media Center 2 * EMC - Enlightenment Media Center
3 * Audio/Video Player 3 * Audio/Video Player
4 */ 4 */
5#include "settingsmodel.hh"
6
7#include "database_schema.hh"
8#include "emodel_helpers.hh"
9#include "logger.hh"
5 10
11#include <Efreet.h>
6#include <Elementary.h> 12#include <Elementary.h>
7#include <elm_widget.h> 13#include <elm_widget.h>
8#include "elm_interface_atspi_accessible.h" 14#include <elm_interface_atspi_accessible.h>
9#include "elm_interface_atspi_accessible.eo.h" 15#include <elm_interface_atspi_accessible.eo.h>
10#include "elm_interface_atspi_widget_action.h" 16#include <elm_interface_atspi_widget_action.h>
11#include "elm_interface_atspi_widget_action.eo.h" 17#include <elm_interface_atspi_widget_action.eo.h>
12#include <elm_layout.eo.hh> 18#include <elm_layout.eo.hh>
13 19#include <elm_win.eo.hh>
14#include "Efreet.h"
15
16#include "settingsmodel.hh"
17#include "database_schema.hh"
18#include "emodel_helpers.hh"
19 20
20#define THEME_PATH "../themes/default" 21#define THEME_PATH "../themes/default"
21#define WIDTH 1280 22#define WIDTH 1280
@@ -137,4 +138,20 @@ settingsmodel::group_set(const std::string groupname)
137 layout.file_set(theme_dir + "/default.edj", groupname); 138 layout.file_set(theme_dir + "/default.edj", groupname);
138} 139}
139 140
140} //emc 141void
142settingsmodel::update_media()
143{
144 database.async_reset_media_tables(
145 [](bool error)
146 {
147 if (error)
148 {
149 ERR << "Error updating media files";
150 return;
151 }
152
153 // TODO: Restart tagging service
154 });
155}
156
157}
diff --git a/src/settingsmodel.hh b/src/settingsmodel.hh
index f02f6b4..a76f0e9 100644
--- a/src/settingsmodel.hh
+++ b/src/settingsmodel.hh
@@ -1,14 +1,16 @@
1#ifndef _SETTINGS_MODEL_HH 1#ifndef _SETTINGS_MODEL_HH
2#define _SETTINGS_MODEL_HH 2#define _SETTINGS_MODEL_HH
3 3
4#include <iostream> 4#include "database.hh"
5#include "Emodel.h" 5
6#include "Emodel.hh" 6#include <Emodel.h>
7#include <elm_layout.eo.hh> 7#include <Emodel.hh>
8#include <elm_win.eo.hh> 8#include <Elementary.h>
9#include <elm_widget.h>
9#include <elm_video.eo.hh> 10#include <elm_video.eo.hh>
10 11
11#include "database.hh" 12struct elm_layout;
13struct elm_win;
12 14
13namespace emc { 15namespace emc {
14 16
@@ -26,7 +28,11 @@ class settingsmodel
26 void audio_rootpath_set(std::string path); 28 void audio_rootpath_set(std::string path);
27 void fullscreen_set(bool fullscreen); 29 void fullscreen_set(bool fullscreen);
28 30
29// ::elm_video player_get(); 31 /**
32 * @brief Updates all media files
33 */
34 void update_media();
35
30 void group_set(const std::string groupname); 36 void group_set(const std::string groupname);
31 ::elm_win &win; 37 ::elm_win &win;
32 ::elm_layout &layout; 38 ::elm_layout &layout;
@@ -40,5 +46,6 @@ class settingsmodel
40 std::unordered_map<std::string, esql::model_row> rows; 46 std::unordered_map<std::string, esql::model_row> rows;
41}; 47};
42 48
43} //emc 49}
50
44#endif 51#endif