+++ /dev/null
-/*
- * Copyright 2016 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef COMMON_MODEL_DATA_CONSUMER_H
-#define COMMON_MODEL_DATA_CONSUMER_H
-
-#include "Model/DataProvider.h"
-
-#include <data_control.h>
-#include <data_control_noti.h>
-
-namespace Common
-{
- namespace Model
- {
- class Memo;
-
- class EXPORT_API DataConsumer
- {
- public:
-
- /**
- * @brief Get list of memo
- * @param[in] list list of memos
- */
- typedef std::function<void(::Model::DataProvider::DataList list)> MemoListReceivedCallback;
-
- /**
- * @brief Get memo
- * @param[in] memo Memo
- */
- typedef std::function<void(::Model::DataItem *memo)> MemoReceivedCallback;
-
- /**
- * @brief Called when memo data has been changed.
- * @param[in] id Memo id
- * @param[in] type Changed type
- */
- typedef std::function<void(long long id, data_control_data_change_type_e type)> ChangeCallback;
-
- /**
- * @brief Called on result.
- * @param[in] result Result is true whether the operation was successful.
- */
- typedef std::function<void(bool result)> ResultCallback;
-
- DataConsumer();
- ~DataConsumer();
-
- DataConsumer(const DataConsumer &consumer) = delete;
- DataConsumer &operator=(const DataConsumer &consumer) = delete;
-
- /**
- * @brief Add data control callback on data changed.
- * @param[in] callback Callback that is called when data is change.
- */
- void setChangeCallback(ChangeCallback callback);
-
- /**
- * @brief Unset callback on data changed.
- */
- void unsetChangeCallback();
-
- /**
- * @brief Set result callback.
- * @param[in] callback On result callback.
- */
- void setResultCallback(ResultCallback callback);
-
- /**
- * @brief Unset result callback.
- */
- void unsetResultCallback();
-
- /**
- * @brief Get list of memos asynchronously.
- * @param[in] callback Callback that is called when memo list is received.
- */
- void getMemoList(MemoListReceivedCallback callback);
-
- /**
- * @brief Get memo asynchronously.
- * @param[in] callback Callback that is called when memo is received.
- * @param[in] id Id to find memo.
- */
- void getMemo(MemoReceivedCallback callback, int id);
-
- /**
- * @brief Insert Memo content.
- * @param[in] memo Memo content
- * @return Error code.
- */
- int insertMemo(Memo *memo);
-
- /**
- * @brief Remove Memo content.
- * @param[in] memo Memo to remove
- * @return Error code.
- */
- int removeMemo(Memo *memo);
-
- /**
- * @brief Update Memo.
- * @param[in] memo Memo to update
- * @return Error code.
- */
- int updateMemo(Memo *memo);
-
- private:
- void onDeleteResponse(int requestId, data_control_h provider,
- bool providerResult, const char *error);
- void onUpdateResponse(int requestId, data_control_h provider,
- bool providerResult, const char *error);
- void onInsertResponse(int requestId, data_control_h provider,
- long long insertedRowId, bool providerResult, const char *error);
- void onSelectResponse(int requestId, data_control_h provider,
- result_set_cursor cursor, bool providerResult, const char *error);
-
- void initialize();
- Memo *createMemo(result_set_cursor cursor, int columnCount);
- void setMemoContent(Memo *memo, result_set_cursor cursor, int column);
- void setMemoImages(Memo *memo, char *image);
- bundle *prepareBundle(Memo *memo);
- void setImageToBundle(bundle *bd, Memo *memo);
- void setSoundToBundle(bundle *bd, Memo *memo);
- void setThumbnailToBundle(bundle *bd, Memo *memo);
-
- void onDataChanged(data_control_h provider, data_control_data_change_type_e type, bundle *data);
- void onResult(data_control_h provider, data_control_error_e result, int callback_id);
-
- data_control_h m_Provider;
-
- int m_Id;
- MemoListReceivedCallback m_OnListReceived;
- MemoReceivedCallback m_OnMemoReceived;
- ChangeCallback m_OnMemoChanged;
- ResultCallback m_OnResult;
-
- int m_ListRequestId;
- int m_MemoRequestId;
- };
- }
-}
-
-#endif /* COMMON_MODEL_DATA_CONSUMER_H */
#ifndef COMMON_MODEL_MEMO_BUILDER_H
#define COMMON_MODEL_MEMO_BUILDER_H
+#include "Utils/Bundle.h"
+
#include <data_control.h>
#include <string>
* @return memo.
*/
static Memo *createMemo(bundle *data);
+
+ /**
+ * @brief Create bundle from Memo.
+ * @param[in] memo Memo to create bundle from
+ * @return Bundle containing memo data.
+ */
+ static Utils::Bundle createBundle(const Memo &memo);
+
private:
static void setMemoColumn(Memo *memo, result_set_cursor cursor, int column);
static void setMemoTextColumn(Memo *memo, result_set_cursor cursor, int column, char *columnName);
static void setMemoImages(Memo *memo, bundle *data);
static void setMemoSound(Memo *memo, bundle *data);
static void setMemoThumbnail(Memo *memo, bundle *data);
+
+ static void setMemoImagesToBundle(Utils::Bundle &bundle, const Memo &memo);
+ static void setMemoSoundsToBundle(Utils::Bundle &bundle, const Memo &memo);
+ static void setMemoThumbnailToBundle(Utils::Bundle &bundle, const Memo &memo);
};
}
}
--- /dev/null
+/*
+ * Copyright 2016 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef COMMON_MODEL_MEMO_CONSUMER_H
+#define COMMON_MODEL_MEMO_CONSUMER_H
+
+#include "Model/DataControlConsumer.h"
+
+namespace Common
+{
+ namespace Model
+ {
+ class EXPORT_API MemoConsumer : public ::Model::DataControlConsumer
+ {
+ public:
+ /**
+ * @return Consumer singleton instance.
+ */
+ static MemoConsumer &getInstance();
+
+ /**
+ * @see DataControlConsumer::getDataItem()
+ */
+ virtual void getDataItem(int id, GetCallback callback) override;
+
+ protected:
+ /**
+ * @see DataControlConsumer::createDataItem()
+ */
+ virtual ::Model::DataItem *createDataItem(result_set_cursor cursor) override;
+
+ /**
+ * @see DataControlConsumer::createBundle()
+ */
+ virtual Utils::Bundle createBundle(const ::Model::DataItem &item) override;
+
+ private:
+ MemoConsumer();
+ };
+ }
+}
+
+#endif /* COMMON_MODEL_MEMO_CONSUMER_H */
+++ /dev/null
-/*
- * Copyright 2016 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef COMMON_MODEL_MEMO_PROVIDER_H
-#define COMMON_MODEL_MEMO_PROVIDER_H
-
-#include "Common/Model/DataConsumer.h"
-#include "Model/DataProvider.h"
-
-namespace Common
-{
- namespace Model
- {
- class Memo;
-
- class EXPORT_API MemoProvider : public ::Model::DataProvider
- {
- public:
- MemoProvider();
- ~MemoProvider();
-
- MemoProvider(const MemoProvider &provider) = delete;
- MemoProvider &operator=(const DataConsumer &provider) = delete;
-
- /**
- * @brief Set result callback. Is called when a response is received.
- * @param[in] callback On result callback.
- */
- void setResultCallback(DataConsumer::ResultCallback callback);
-
- /**
- * @brief Unset result callback.
- */
- void unsetResultCallback();
-
- /**
- * @brief Get memo.
- * @param[in] id id to find memo.
- * @return memo.
- */
- Memo *getMemo(long long id);
-
- /**
- * @brief Insert memo.
- * @param[in] memo Memo to insert.
- */
- void insertMemo(Memo *memo);
-
- /**
- * @brief Update memo.
- * @param[in] memo Memo to update.
- */
- void updateMemo(Memo *memo);
-
- /**
- * @brief Delete memo.
- * @param[in] memo Memo to delete.
- */
- void deleteMemo(Memo *memo);
-
- protected:
- /**
- * @see DataProvider::startInit().
- */
- virtual void startInit() override;
-
- /**
- * @see DataProvider::startUpdate().
- */
- virtual void startUpdate() override;
-
- private:
- struct UpdateInfo
- {
- long long id;
- data_control_data_change_type_e type;
- };
-
- void onMemoReceived(::Model::DataItem *newItem, long long id, data_control_data_change_type_e type);
- void onMemoDataChanged(long long id, data_control_data_change_type_e type);
-
- void getMemoFromDB(long long id, data_control_data_change_type_e type);
-
- DataConsumer m_Consumer;
- std::list<UpdateInfo> m_Updates;
- };
- }
-}
-
-#endif /* COMMON_MODEL_MEMO_PROVIDER_H */
+++ /dev/null
-/*
- * Copyright 2016 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "Common/Model/DataConsumer.h"
-#include "Common/Model/DataBasePath.h"
-#include "Common/Model/Memo.h"
-#include <Common/Model/MemoBuilder.h>
-#include "Common/Model/SoundRecord.h"
-#include "Utils/Callback.h"
-#include "Utils/Logger.h"
-#include "Utils/Range.h"
-
-#include <stdio.h>
-#include <sqlite3.h>
-#include <algorithm>
-
-#define BUFFER_SIZE 100
-#define PROVIDER_ID "http://memo_provider"
-
-using namespace Model;
-using namespace Common::Model;
-
-DataConsumer::DataConsumer()
- : m_Provider(nullptr)
-{
- initialize();
-}
-
-DataConsumer::~DataConsumer()
-{
- data_control_remove_data_change_cb(m_Provider, m_Id);
- data_control_sql_unregister_response_cb(m_Provider);
- data_control_sql_destroy(m_Provider);
-}
-
-void DataConsumer::setChangeCallback(ChangeCallback callback)
-{
- m_OnMemoChanged = std::move(callback);
-}
-
-void DataConsumer::unsetChangeCallback()
-{
- m_OnMemoChanged = nullptr;
-}
-
-void DataConsumer::setResultCallback(ResultCallback callback)
-{
- m_OnResult = std::move(callback);
-}
-
-void DataConsumer::unsetResultCallback()
-{
- m_OnResult = nullptr;
-}
-
-void DataConsumer::getMemoList(MemoListReceivedCallback callback)
-{
- m_OnListReceived = std::move(callback);
-
- const char *columnList[] = {COLUMN_MEMO_ID, COLUMN_MEMO_TITLE, COLUMN_MEMO_TEXT, COLUMN_MEMO_PINNED, COLUMN_MEMO_TIME, COLUMN_MEMO_COLOR, COLUMN_THUMBNAIL_PATH};
- data_control_sql_select(m_Provider, (char **)columnList, Utils::count(columnList), nullptr, nullptr, &m_ListRequestId);
-}
-
-void DataConsumer::getMemo(MemoReceivedCallback callback, int id)
-{
- m_OnMemoReceived = std::move(callback);
-
- const char *columnList[] = {COLUMN_MEMO_ID, COLUMN_MEMO_TITLE, COLUMN_MEMO_TEXT, COLUMN_MEMO_PINNED, COLUMN_MEMO_TIME, COLUMN_MEMO_COLOR, COLUMN_THUMBNAIL_PATH};
-
- char where[BUFFER_SIZE];
- snprintf(where, sizeof(where), "%s = %d", COLUMN_MEMO_ID, id);
-
- data_control_sql_select(m_Provider, (char **)columnList, Utils::count(columnList), where, nullptr, &m_MemoRequestId);
-}
-
-int DataConsumer::insertMemo(Memo *memo)
-{
- bundle *bd = prepareBundle(memo);
-
- int reqId = 0;
- int err = data_control_sql_insert(m_Provider, bd, &reqId);
- WARN_IF_ERR(err, "data_control_sql_insert() failed.");
- bundle_free(bd);
-
- return err;
-}
-
-int DataConsumer::removeMemo(Memo *memo)
-{
- char where[BUFFER_SIZE];
- snprintf(where, sizeof(where), "%s = %d", COLUMN_MEMO_ID, memo->getId());
-
- int reqId = 0;
- int err = data_control_sql_delete(m_Provider, where, &reqId);
- WARN_IF_ERR(err, "data_control_sql_delete() failed.");
-
- return err;
-}
-
-int DataConsumer::updateMemo(Memo *memo)
-{
- bundle *bd = prepareBundle(memo);
-
- char where[BUFFER_SIZE];
- snprintf(where, sizeof(where), "%s = %d", COLUMN_MEMO_ID, memo->getId());
-
- int reqId = 0;
- int err = data_control_sql_update(m_Provider, bd, where, &reqId);
- WARN_IF_ERR(err, "data_control_sql_update() failed.");
-
- bundle_free(bd);
- return err;
-}
-
-void DataConsumer::onDeleteResponse(int requestId, data_control_h provider, bool providerResult, const char *error)
-{
- if (m_OnResult) {
- m_OnResult(providerResult);
- }
-}
-
-void DataConsumer::onInsertResponse(int requestId, data_control_h provider, long long insertedRowId, bool providerResult, const char *error)
-{
- if (m_OnResult) {
- m_OnResult(providerResult);
- }
-}
-
-void DataConsumer::onUpdateResponse(int requestId, data_control_h provider, bool providerResult, const char *error)
-{
- if (m_OnResult) {
- m_OnResult(providerResult);
- }
-}
-
-void DataConsumer::onSelectResponse(int requestId, data_control_h provider, result_set_cursor cursor, bool providerResult, const char *error)
-{
- RETM_IF(!providerResult, "onSelectResponse() failed.");
-
- DataProvider::DataList list;
-
- int res = data_control_sql_step_first(cursor);
-
- while (res == DATA_CONTROL_ERROR_NONE) {
- list.push_back(MemoBuilder::createMemo(cursor));
- res = data_control_sql_step_next(cursor);
- }
-
- if (m_MemoRequestId == requestId && m_OnMemoReceived) {
- m_OnMemoReceived(std::move(list.back()));
- } else if (m_ListRequestId == requestId && m_OnListReceived) {
- m_OnListReceived(std::move(list));
- }
-}
-
-void DataConsumer::initialize()
-{
- int ret = data_control_sql_create(&m_Provider);
- RETM_IF_ERR(ret, "data_control_sql_create() failed.");
-
- ret = data_control_sql_set_provider_id(m_Provider, PROVIDER_ID);
- RETM_IF_ERR(ret, "data_control_sql_set_provider_id() failed.");
-
- ret = data_control_sql_set_data_id(m_Provider, TABLE_MEMOS);
- RETM_IF_ERR(ret, "data_control_sql_set_data_id() failed.");
-
- data_control_sql_response_cb cb;
- cb.delete_cb = makeCallbackWithLastParam(&DataConsumer::onDeleteResponse);
- cb.insert_cb = makeCallbackWithLastParam(&DataConsumer::onInsertResponse);
- cb.select_cb = makeCallbackWithLastParam(&DataConsumer::onSelectResponse);
- cb.update_cb = makeCallbackWithLastParam(&DataConsumer::onUpdateResponse);
-
- data_control_sql_register_response_cb(m_Provider, &cb, this);
- data_control_add_data_change_cb(m_Provider, makeCallbackWithLastParam(&DataConsumer::onDataChanged),
- this, makeCallbackWithLastParam(&DataConsumer::onResult), this, &m_Id);
-}
-
-bundle *DataConsumer::prepareBundle(Memo *memo)
-{
- bundle *bd = bundle_create();
-
- Model::ColorId color = memo->getColor();
- bool pinned = memo->isPinned();
- time_t time = memo->getTime();
-
- bundle_add_str(bd, COLUMN_MEMO_TEXT, memo->getContent().c_str());
- bundle_add_str(bd, COLUMN_MEMO_TITLE, memo->getTitle().c_str());
- bundle_add_byte(bd, COLUMN_MEMO_COLOR, &color, sizeof(color));
- bundle_add_byte(bd, COLUMN_MEMO_PINNED, &pinned, sizeof(pinned));
- bundle_add_byte(bd, COLUMN_MEMO_TIME, &time, sizeof(time));
-
- setImageToBundle(bd, memo);
- setSoundToBundle(bd, memo);
- setThumbnailToBundle(bd, memo);
-
- return bd;
-}
-
-void DataConsumer::setImageToBundle(bundle *bd, Memo *memo)
-{
- std::vector<int> id;
- std::vector<const char *> images;
- std::vector<int> index;
-
- for (auto &&image : memo->getImages()) {
- id.push_back(image.getId());
- images.push_back(image.getPath().c_str());
- index.push_back(image.getIndex());
- }
-
- bundle_add_byte(bd, COLUMN_IMAGE_ID, (void **)id.data(), sizeof(id[0]) * id.size());
- bundle_add_str_array(bd, COLUMN_IMAGE_PATH, (const char **) images.data(), images.size());
- bundle_add_byte(bd, COLUMN_IMAGE_INDEX, (void **)index.data(), sizeof(index[0]) * index.size());
-
- std::vector<int> removedId;
-
- for (auto &&image : memo->getImagesToRemove()) {
- removedId.push_back(image.getId());
- }
-
- bundle_add_byte(bd, COLUMN_REMOVED_IMAGE_ID, (void **) removedId.data(), sizeof(removedId[0]) * removedId.size());
-}
-
-void DataConsumer::setSoundToBundle(bundle *bd, Memo *memo)
-{
- if (const SoundRecord *soundToRemove = memo->getSoundRecordToRemove()) {
- bundle_add_str(bd, SOUND_TO_REMOVE, soundToRemove->getPath().c_str());
- }
- if (const SoundRecord *soundToSave = memo->getSoundRecord()) {
- int id = soundToSave->getId();
- bundle_add_byte(bd, COLUMN_SOUND_ID, &id, sizeof(id));
- bundle_add_str(bd, SOUND_TO_SAVE, soundToSave->getPath().c_str());
- }
-}
-
-void DataConsumer::setThumbnailToBundle(bundle *bd, Memo *memo)
-{
- int id = memo->getThumbnail().getId();
- bundle_add_byte(bd, COLUMN_THUMBNAIL_ID, &id, sizeof(id));
-}
-
-void DataConsumer::onDataChanged(data_control_h provider, data_control_data_change_type_e type, bundle *data)
-{
- long long *id = nullptr;
- bundle_get_byte(data, COLUMN_MEMO_ID, (void **) &id, nullptr);
-
- if (m_OnMemoChanged) {
- m_OnMemoChanged(*id, type);
- }
-}
-
-void DataConsumer::onResult(data_control_h provider, data_control_error_e result, int callback_id)
-{
- WARN_IF_ERR((tizen_error_e)result, "data_changed_cb() failed.");
-}
return memo;
}
+Utils::Bundle MemoBuilder::createBundle(const Memo &memo)
+{
+ Utils::Bundle bundle;
+
+ bundle.addStr(COLUMN_MEMO_TEXT, memo.getContent().c_str());
+ bundle.addStr(COLUMN_MEMO_TITLE, memo.getTitle().c_str());
+ bundle.addInt(COLUMN_MEMO_COLOR, memo.getColor());
+ bundle.addInt(COLUMN_MEMO_PINNED, memo.isPinned());
+
+ time_t time = memo.getTime();
+ bundle_add_byte(bundle.getBundle(), COLUMN_MEMO_TIME, &time, sizeof(time));
+
+ setMemoImagesToBundle(bundle, memo);
+ setMemoSoundsToBundle(bundle, memo);
+ setMemoThumbnailToBundle(bundle, memo);
+
+ return bundle;
+}
+
void MemoBuilder::setMemoColumn(Memo *memo, result_set_cursor cursor, int column)
{
char columnName[BUFFER_SIZE] = { 0, };
bundle_get_byte(data, COLUMN_THUMBNAIL_ID, (void **)&id, nullptr);
memo->setThumbnail(Thumbnail(*id, ""));
}
+
+void MemoBuilder::setMemoImagesToBundle(Utils::Bundle &bundle, const Memo &memo)
+{
+ std::vector<int> id;
+ std::vector<const char *> images;
+ std::vector<int> index;
+
+ for (auto &&image : memo.getImages()) {
+ id.push_back(image.getId());
+ images.push_back(image.getPath().c_str());
+ index.push_back(image.getIndex());
+ }
+
+ bundle_add_byte(bundle.getBundle(), COLUMN_IMAGE_ID, (void **)id.data(), sizeof(id[0]) * id.size());
+ bundle_add_str_array(bundle.getBundle(), COLUMN_IMAGE_PATH, (const char **) images.data(), images.size());
+ bundle_add_byte(bundle.getBundle(), COLUMN_IMAGE_INDEX, (void **)index.data(), sizeof(index[0]) * index.size());
+
+ std::vector<int> removedId;
+
+ for (auto &&image : memo.getImagesToRemove()) {
+ removedId.push_back(image.getId());
+ }
+
+ bundle_add_byte(bundle.getBundle(), COLUMN_REMOVED_IMAGE_ID, (void **) removedId.data(), sizeof(removedId[0]) * removedId.size());
+}
+
+void MemoBuilder::setMemoSoundsToBundle(Utils::Bundle &bundle, const Memo &memo)
+{
+ if (const SoundRecord *soundToRemove = memo.getSoundRecordToRemove()) {
+ bundle.addStr(SOUND_TO_REMOVE, soundToRemove->getPath().c_str());
+ }
+ if (const SoundRecord *soundToSave = memo.getSoundRecord()) {
+ int id = soundToSave->getId();
+ bundle.addInt(COLUMN_SOUND_ID, id);
+ bundle.addStr(SOUND_TO_SAVE, soundToSave->getPath().c_str());
+ }
+}
+
+void MemoBuilder::setMemoThumbnailToBundle(Utils::Bundle &bundle, const Memo &memo)
+{
+ int id = memo.getThumbnail().getId();
+ bundle.addInt(COLUMN_THUMBNAIL_ID, id);
+}
--- /dev/null
+/*
+ * Copyright 2016 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Common/Model/MemoConsumer.h"
+
+#include "Common/Model/MemoBuilder.h"
+#include "Common/Model/DataBasePath.h"
+#include "Common/Model/Memo.h"
+
+#define PROVIDER_ID "http://memo_provider"
+
+using namespace Common::Model;
+
+namespace
+{
+ const char *columnList[] = {
+ COLUMN_MEMO_ID,
+ COLUMN_MEMO_TITLE,
+ COLUMN_MEMO_TEXT,
+ COLUMN_MEMO_PINNED,
+ COLUMN_MEMO_TIME,
+ COLUMN_MEMO_COLOR,
+ COLUMN_THUMBNAIL_PATH
+ };
+}
+
+MemoConsumer::MemoConsumer()
+ : DataControlConsumer(PROVIDER_ID, TABLE_MEMOS, columnList)
+{
+}
+
+MemoConsumer &MemoConsumer::getInstance()
+{
+ static MemoConsumer instance;
+ return instance;
+}
+
+void MemoConsumer::getDataItem(int id, GetCallback callback)
+{
+ selectDataItems(std::to_string(id).c_str(), std::move(callback));
+}
+
+::Model::DataItem *MemoConsumer::createDataItem(result_set_cursor cursor)
+{
+ return MemoBuilder::createMemo(cursor);
+}
+
+Utils::Bundle MemoConsumer::createBundle(const ::Model::DataItem &item)
+{
+ return MemoBuilder::createBundle(static_cast<const Memo &>(item));
+}
+
+++ /dev/null
-/*
- * Copyright 2016 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "Common/Model/MemoProvider.h"
-#include "Common/Model/Memo.h"
-
-#include "Utils/Logger.h"
-
-
-using namespace Model;
-using namespace Common::Model;
-
-using namespace std::placeholders;
-
-MemoProvider::MemoProvider()
-{
- m_Consumer.setChangeCallback(std::bind(&MemoProvider::onMemoDataChanged, this, _1, _2));
-}
-
-MemoProvider::~MemoProvider()
-{
- m_Consumer.unsetChangeCallback();
-}
-
-void MemoProvider::setResultCallback(DataConsumer::ResultCallback callback)
-{
- m_Consumer.setResultCallback(callback);
-}
-
-void MemoProvider::unsetResultCallback()
-{
- m_Consumer.unsetResultCallback();
-}
-
-Memo *MemoProvider::getMemo(long long id)
-{
- for (auto &&dataItem : getDataList()) {
- auto memo = static_cast<Memo *>(dataItem);
- if (memo->getId() == id) {
- return memo;
- }
- }
-
- return nullptr;
-}
-
-void MemoProvider::insertMemo(Memo *memo)
-{
- m_Consumer.insertMemo(memo);
-}
-
-void MemoProvider::updateMemo(Memo *memo)
-{
- m_Consumer.updateMemo(memo);
-}
-
-void MemoProvider::deleteMemo(Memo *memo)
-{
- m_Consumer.removeMemo(memo);
-}
-
-void MemoProvider::startInit()
-{
- m_Consumer.getMemoList(std::bind(&MemoProvider::finishInit, this, _1));
-}
-
-void MemoProvider::startUpdate()
-{
- for (auto it = m_Updates.begin(); it != m_Updates.end();) {
- if (it->type == DATA_CONTROL_DATA_CHANGE_SQL_DELETE) {
- if (Memo *memo = getMemo(it->id)) {
- deleteDataItem(*memo);
- it = m_Updates.erase(it);
- continue;
- }
- } else {
- getMemoFromDB(it->id, it->type);
- }
-
- ++it;
- }
-
- if (m_Updates.empty()) {
- finishUpdate();
- }
-}
-
-void MemoProvider::onMemoDataChanged(long long id, data_control_data_change_type_e type)
-{
- m_Updates.push_back({id, type});
- update();
-}
-
-void MemoProvider::onMemoReceived(::Model::DataItem *newItem, long long id, data_control_data_change_type_e type)
-{
- if (type == DATA_CONTROL_DATA_CHANGE_SQL_INSERT) {
- insertDataItem(newItem);
-
- } else if (type == DATA_CONTROL_DATA_CHANGE_SQL_UPDATE) {
- if (Memo *memo = getMemo(id)) {
- memo->update(newItem);
- }
- }
-
- for (auto it = m_Updates.begin(); it != m_Updates.end(); ++it) {
- if (it->id == id) {
- m_Updates.erase(it);
- break;
- }
- }
-
- if (m_Updates.empty()) {
- finishUpdate();
- }
-}
-
-void MemoProvider::getMemoFromDB(long long id, data_control_data_change_type_e type)
-{
- m_Consumer.getMemo(std::bind(&MemoProvider::onMemoReceived, this, _1, id, type), id);
-}
/**
* @brief Create Details view.
* @param[in] memo Memo.
- * @param[in] provider Memo provider.
* @see InputView.
*/
- DetailsView(Common::Model::Memo memo, Common::Model::MemoProvider *provider);
+ explicit DetailsView(Common::Model::Memo memo);
virtual ~DetailsView() override;
private:
virtual bool onBackPressed() override;
virtual void onMenuPressed() override;
virtual void onFavIconChanged() override;
- virtual void onResult(bool result) override;
+ virtual void onResult(bool isSuccess, int id) override;
void onEdit();
void onDelete();
#include <vector>
-namespace Common
-{
- namespace Model
- {
- class MemoProvider;
- }
-}
-
namespace Input
{
class TitleField;
/**
* @brief Create Input view.
* @param[in] memo Memo.
- * @param[in] provider Memo provider.
*/
- InputView(Common::Model::Memo memo, Common::Model::MemoProvider *provider);
+ explicit InputView(Common::Model::Memo memo);
virtual ~InputView() override;
protected:
virtual void onNavigation(bool isCurrent) override;
virtual void onRotationChanged(int degree) override;
virtual void onFavIconChanged() {};
- virtual void onResult(bool result);
+ virtual void onResult(bool isSuccess, int id);
InputBox *getInputBox() const;
TitleField *getTitleField() const;
RecordField *getRecordField() const;
Common::Model::Memo &getMemo();
- Common::Model::MemoProvider *getProvider() const;
private:
Evas_Object *createLayout(Evas_Object *parent, const char *layoutName);
RecordField *m_RecordField;
Common::Model::Memo m_InitialMemo;
Common::Model::Memo m_Memo;
- Common::Model::MemoProvider *m_Provider;
AttachPanel m_AttachPanel;
};
}
#ifndef LIST_MEMO_LIST_VIEW_H
#define LIST_MEMO_LIST_VIEW_H
-#include "Common/Model/MemoProvider.h"
-
-#include "Ux/SelectView.h"
+#include "Model/DataControlProvider.h"
#include "Model/SearchProvider.h"
+#include "Ux/SelectView.h"
namespace Ui
{
Evas_Object *m_AddButton;
bool m_IsSearching;
- Common::Model::MemoProvider m_DataProvider;
+ Model::DataControlProvider m_DataProvider;
Model::SearchProvider m_SearchProvider;
};
}
#define OPERATION_EDIT_CONTROLLER_H
#include "App/OperationController.h"
-#include "Common/Model/MemoProvider.h"
class OperationEditController : public App::OperationController
{
private:
virtual void onRequest(const char *operation, app_control_h request) override;
-
- Common::Model::MemoProvider m_Provider;
};
#endif /* OPERATION_EDIT_CONTROLLER_H */
#include "Input/DetailsView.h"
#include "Input/TitleField.h"
-#include "Common/Model/MemoProvider.h"
+#include "Common/Model/MemoConsumer.h"
#include "Common/Model/ShareTool.h"
#include "App/AppControlRequest.h"
#define DATETIME_FORMAT_24 "%x %R"
#define DATETIME_FORMAT_12 "%x %I:%M %p"
-DetailsView::DetailsView(Memo memo, MemoProvider *provider)
- : InputView(memo, provider)
+DetailsView::DetailsView(Memo memo)
+ : InputView(std::move(memo))
, m_Mode(ModeDetails)
{
}
void DetailsView::onFavIconChanged()
{
if (m_Mode == ModeDetails) {
- getProvider()->updateMemo(&getMemo());
+ MemoConsumer::getInstance().updateDataItem(getMemo());
}
}
-void DetailsView::onResult(bool result)
+void DetailsView::onResult(bool isSuccess, int id)
{
if (m_Mode == ModeInput) {
- InputView::onResult(result);
+ InputView::onResult(isSuccess, id);
}
}
popup->addButton("IDS_MEMO_BUTTON_CANCEL_ABB2");
popup->addButton("IDS_MEMO_BUTTON_DELETE_ABB4", [this] {
- getProvider()->deleteMemo(&getMemo());
+ MemoConsumer::getInstance().deleteDataItem(getMemo().getId());
notification_status_message_post(_("IDS_MEMO_POP_DELETED"));
getPage()->close();
return true;
{
getMemo().setContent(getInputBox()->getContent());
getMemo().setTime(getCurrentTime());
- getProvider()->updateMemo(&getMemo());
+ MemoConsumer::getInstance().updateDataItem(getMemo());
}
void DetailsView::setMode(Mode mode)
#include "Input/ColorSelector.h"
#include "Input/TitleField.h"
-#include "Common/Model/MemoProvider.h"
+#include "Common/Model/MemoConsumer.h"
#include "Common/Model/SoundRecord.h"
#include "Common/SoundManager.h"
const std::string layoutFilePath = App::getResourcePath(INPUT_LAYOUT_EDJ);
}
-InputView::InputView(Memo memo, MemoProvider *provider)
+InputView::InputView(Memo memo)
: m_DoneButton(nullptr)
, m_InputBox(nullptr)
, m_Bg(nullptr)
, m_RecordField(nullptr)
, m_InitialMemo(memo)
, m_Memo(std::move(memo))
- , m_Provider(provider)
{
- m_Provider->setResultCallback(std::bind(&InputView::onResult, this, _1));
}
InputView::~InputView()
{
- m_Provider->unsetResultCallback();
}
Evas_Object *InputView::onCreate(Evas_Object *parent)
}
}
-void InputView::onResult(bool result)
+void InputView::onResult(bool isSuccess, int id)
{
- if (result) {
+ if (isSuccess) {
getPage()->close();
}
}
return m_Memo;
}
-Common::Model::MemoProvider *InputView::getProvider() const
-{
- return m_Provider;
-}
-
Evas_Object *InputView::createLayout(Evas_Object *parent, const char *layoutName)
{
Evas_Object *layout = elm_layout_add(parent);
m_Memo.setContent(m_InputBox->getContent());
getMemo().setTime(getCurrentTime());
- if (m_Memo.isNew()) {
- m_Provider->insertMemo(&m_Memo);
- } else {
- m_Provider->updateMemo(&m_Memo);
- }
+ MemoConsumer::getInstance().saveDataItem(m_Memo, std::bind(&InputView::onResult, this, _1, _2));
}
void InputView::onCancelPressed(Evas_Object *button, void *eventInfo)
#include "List/MemoComparator.h"
#include "List/MemoSearchItem.h"
#include "List/SearchBar.h"
+
+#include "Common/Model/MemoConsumer.h"
#include "Input/DetailsView.h"
#include "App/Path.h"
MemoListView::MemoListView()
: m_Bg(nullptr), m_Content(nullptr), m_Gengrid(nullptr),
m_SearchBar(nullptr), m_AddButton(nullptr),
- m_IsSearching(false),
+ m_IsSearching(false), m_DataProvider(MemoConsumer::getInstance()),
m_SearchProvider(m_DataProvider, MemoComparator())
{
setStrings({
setSelectCallback([this](SelectResults results) {
for (auto &&result : results) {
- m_DataProvider.deleteMemo((Memo *) result.value.data);
+ Memo *memo = static_cast<Memo *>(result.value.data);
+ MemoConsumer::getInstance().deleteDataItem(memo->getId());
}
onDeleteFinished();
elm_object_part_content_set(floatButton, "button1", button);
evas_object_smart_callback_add(button, "clicked", [](void *data, Evas_Object *, void *) {
auto view = (MemoListView *) data;
- view->getNavigator()->navigateTo(new Input::InputView(Memo(), &view->m_DataProvider));
+ view->getNavigator()->navigateTo(new Input::InputView(Memo()));
}, this);
Evas_Object *image = elm_image_add(button);
auto memoItem = new MemoSearchItem(searchData);
memoItem->setSelectCallback([this, &memo] {
if (getSelectMode() == SelectNone) {
- getNavigator()->navigateTo(new Input::DetailsView(memo, &m_DataProvider));
+ getNavigator()->navigateTo(new Input::DetailsView(memo));
}
});
*/
#include "OperationEditController.h"
-#include "Input/DetailsView.h"
#include "App/AppControlRequest.h"
+#include "Common/Model/MemoConsumer.h"
+#include "Input/DetailsView.h"
#include "Ui/Navigator.h"
using namespace Common::Model;
void OperationEditController::onRequest(const char *operation, app_control_h request)
{
int id = App::getIntExtraData(request, APP_CONTROL_DATA_ID);
- m_Provider.initialize([this, id] {
- Ui::View *view = nullptr;
+ MemoConsumer::getInstance().getDataItem(id, [this](MemoConsumer::DataList dataList) {
+ Memo *memo = nullptr;
+ if (!dataList.empty()) {
+ memo = static_cast<Memo *>(dataList.front());
+ }
+ Ui::View *view = nullptr;
char *operation = nullptr;
app_control_get_operation(getRequest(), &operation);
if (operation) {
- Memo *memo = id > 0 ? m_Provider.getMemo(id) : nullptr;
if (strcmp(operation, APP_CONTROL_OPERATION_VIEW) == 0) {
if (memo) {
- view = new Input::DetailsView(*memo, &m_Provider);
+ view = new Input::DetailsView(*memo);
}
} else {
- view = new Input::InputView(memo ? *memo : Memo(), &m_Provider);
+ view = new Input::InputView(memo ? *memo : Memo());
}
free(operation);
}
+ for (auto &&item : dataList) {
+ delete item;
+ }
+
if (view) {
getNavigator()->navigateTo(view);
} else {
void DataProvider::onUpdateRequest(int requestId, data_control_h provider, bundle *updateData, const char *where)
{
- int memoId = 0;
- sscanf(where, COLUMN_MEMO_ID " = %d", &memoId);
+ int memoId = std::stoi(where);
setSuccessCallback([requestId, this] (int memoId) {
notify(memoId, DATA_CONTROL_DATA_CHANGE_SQL_UPDATE);
data_control_provider_send_update_result(requestId);
void DataProvider::onDeleteRequest(int requestId, data_control_h provider, const char *where)
{
- int memoId = 0;
- sscanf(where, COLUMN_MEMO_ID " = %d", &memoId);
-
+ int memoId = std::stoi(where);
DeleteStatement statement;
if (statement.execute(m_Db, requestId, memoId)) {
notify(memoId, DATA_CONTROL_DATA_CHANGE_SQL_DELETE);
sqlite3_stmt *sqlStmt = nullptr;
int id = 0;
if (where) {
- sscanf(where, COLUMN_MEMO_ID " = %d", &id);
+ id = std::stoi(where);
}
int err = sqlite3_prepare_v2(m_Db, where ? selectStmt : selectAllStmt, -1, &sqlStmt, nullptr);
#include <Elementary.h>
#include "App/Widget.h"
-#include "Common/Model/MemoProvider.h"
+#include "Model/DataControlProvider.h"
namespace Ui
{
namespace Common
{
+ namespace Model
+ {
+ class Memo;
+ }
+
class MemoItem;
}
Ui::Gengrid *m_Gengrid;
bool m_IsEmpty;
- Common::Model::MemoProvider m_Provider;
+ Model::DataControlProvider m_Provider;
};
#endif /* MEMO_WIDGET_H */
#include "MemoWidget.h"
#include "Common/Model/Memo.h"
+#include "Common/Model/MemoConsumer.h"
#include "Common/MemoItem.h"
#include "App/AppControl.h"
using namespace std::placeholders;
MemoWidget::MemoWidget()
- : m_Layout(nullptr), m_Gengrid(nullptr), m_IsEmpty(false)
+ : m_Layout(nullptr), m_Gengrid(nullptr), m_IsEmpty(false),
+ m_Provider(MemoConsumer::getInstance())
{
}