void setMemoImages(Memo *memo, char *image);
bundle *prepareBundle(Memo *memo);
void setImageToBundle(bundle *bd, Memo *memo);
+ void setSoundToBundle(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);
#include "Common/Model/Colors.h"
#include "Common/Model/Image.h"
+#include "Common/Model/SoundRecord.h"
#include "Model/DataItem.h"
#include <list>
{
namespace Model
{
- class SoundRecord;
-
/**
* @brief Image list
*/
typedef std::list<Image> ImageList;
+ /**
+ * @brief SoundRecord list
+ */
+ typedef std::list<SoundRecord> SoundRecordList;
+
/**
* @brief Memo model
*/
FieldPinned,
FieldColor,
FieldImage,
+ FieldSound,
FieldThumbnail,
FieldMax
};
enum ChangeType
{
- ChangeNone = 0,
- ChangeTitle = 1 << FieldTitle,
- ChangeContent = 1 << FieldContent,
- ChangePinned = 1 << FieldPinned,
- ChangeColor = 1 << FieldColor,
- ChangeImage = 1 << FieldImage,
+ ChangeNone = 0,
+ ChangeTitle = 1 << FieldTitle,
+ ChangeContent = 1 << FieldContent,
+ ChangePinned = 1 << FieldPinned,
+ ChangeColor = 1 << FieldColor,
+ ChangeImage = 1 << FieldImage,
+ ChangeSound = 1 << FieldSound,
ChangedThumbnail = 1 << FieldThumbnail
};
*/
const SoundRecord *getSoundRecord() const;
+ /**
+ * @return Attached sound record to remove.
+ */
+ const SoundRecord *getSoundRecordToRemove() const;
+
/**
* @brief Set Memo id.
* @param[in] id Memo id.
*/
void addSoundRecord();
+ /**
+ * @brief Add sound record to Memo.
+ * @param[in] sound Sound path
+ */
+ void addSoundRecord(std::string sound);
+
/**
* @brief Remove image from Memo.
* @param[in] index Image index to remove.
virtual int onUpdate(void *data) override;
private:
+ bool compareSounds(const SoundRecordList &list) const;
bool compareImages(const ImageList &list) const;
int generateImageIndex();
const Image *getImage(int index) const;
ImageList m_ImagesToRemove;
ImageList m_Images;
std::string m_Thumbnail;
- SoundRecord *m_SoundRecord;
+ SoundRecordList m_SoundRecords;
+ SoundRecordList m_SoundRecordsToRemove;
bool m_IsPinned;
bool m_IsNew;
};
* @brief Create sound record.
*/
SoundRecord();
+ SoundRecord(std::string path);
- SoundRecord(SoundRecord &&other) = delete;
- SoundRecord &operator=(SoundRecord &&other) = delete;
- SoundRecord(const SoundRecord &other) = delete;
- SoundRecord &operator=(const SoundRecord &other) = delete;
+ SoundRecord(SoundRecord &&other) = default;
+ SoundRecord &operator=(SoundRecord &&other) = default;
+ SoundRecord(const SoundRecord &other) = default;
+ SoundRecord &operator=(const SoundRecord &other) = default;
/**
* @return Record path.
#include "Common/Model/DataConsumer.h"
#include "Common/Model/DataBasePath.h"
+#include "Common/Model/SoundRecord.h"
#include "Utils/Callback.h"
#include "Utils/Logger.h"
setMemoImages(memo, value);
} else if (strcmp(columnName, COLUMN_THUMBNAIL_PATH) == 0) {
memo->setThumbnail(value);
+ } else if (strcmp(columnName, COLUMN_SOUND_PATH) == 0) {
+ memo->addSoundRecord(value);
} else {
ERR("Column name %s is not found", columnName);
}
bundle_add_byte(bd, COLUMN_THUMBNAIL_ID, &index, sizeof(index));
setImageToBundle(bd, memo);
+ setSoundToBundle(bd, memo);
return bd;
}
bundle_add_str_array(bd, COLUMN_IMAGE_PATH, (const char **) images.data(), images.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()) {
+ bundle_add_str(bd, SOUND_TO_SAVE, soundToSave->getPath().c_str());
+ }
+}
+
void DataConsumer::onDataChanged(data_control_h provider, data_control_data_change_type_e type, bundle *data)
{
long long *id = nullptr;
#include <algorithm>
#include "Common/Model/Memo.h"
-#include "Common/Model/SoundRecord.h"
#include "Common/Model/TextTool.h"
#include "Utils/Logger.h"
: m_Id(0)
, m_Time(0)
, m_Color(Color_1)
- , m_SoundRecord(nullptr)
, m_IsPinned(false)
, m_IsNew(true)
{
Memo::~Memo()
{
- delete m_SoundRecord;
}
bool Memo::operator==(const Memo &other) const
return (m_Id == other.m_Id && m_Time == other.m_Time && m_Color == other.m_Color
&& m_IsPinned == other.m_IsPinned && m_Title == other.m_Title
&& m_Content == other.m_Content && compareImages(other.getImages())
- && m_SoundRecord == other.m_SoundRecord);
+ && compareSounds(other.m_SoundRecords));
}
bool Memo::operator!=(const Memo &other) const
const SoundRecord *Memo::getSoundRecord() const
{
- return m_SoundRecord;
+ if (m_SoundRecords.empty()) {
+ return nullptr;
+ }
+ return &m_SoundRecords.front();
+}
+
+const SoundRecord *Memo::getSoundRecordToRemove() const
+{
+ if (m_SoundRecordsToRemove.empty()) {
+ return nullptr;
+ }
+ return &m_SoundRecordsToRemove.front();
}
void Memo::setId(long long id)
void Memo::addSoundRecord()
{
- if (m_SoundRecord) {
+ if (!m_SoundRecords.empty()) {
+ removeSoundRecord();
+ }
+ m_SoundRecords.push_back(SoundRecord());
+}
+
+void Memo::addSoundRecord(std::string sound)
+{
+ if (!m_SoundRecords.empty()) {
removeSoundRecord();
}
- m_SoundRecord = new SoundRecord();
+ m_SoundRecords.push_back(SoundRecord(sound));
}
void Memo::removeImage(int index)
void Memo::removeSoundRecord()
{
- if (m_SoundRecord) {
- delete m_SoundRecord;
- m_SoundRecord = nullptr;
+ if (!m_SoundRecords.empty()) {
+ m_SoundRecordsToRemove.push_back(std::move(m_SoundRecords.front()));
+ m_SoundRecords.clear();
}
}
bool Memo::isEmpty() const
{
- return (m_Title.empty() && m_Content.empty()
- && m_Images.empty() && (!m_SoundRecord || !m_SoundRecord->isExist()));
+ return (m_Title.empty() && m_Content.empty() && m_Images.empty()
+ && (m_SoundRecords.empty() || !m_SoundRecords.front().isExist()));
}
int Memo::onUpdate(void *data)
m_Images = memo->getImages();
changes |= ChangeImage;
}
+ if (!compareSounds(memo->m_SoundRecords)) {
+ m_SoundRecords = std::move(memo->m_SoundRecords);
+ changes |= ChangeSound;
+ }
if (strcmp(getThumbnail(), memo->getThumbnail()) != 0) {
setThumbnail(memo->getThumbnail());
changes |= ChangedThumbnail;
return true;
}
+bool Memo::compareSounds(const SoundRecordList &list) const
+{
+ return ((m_SoundRecords.empty() && list.empty())
+ || (!m_SoundRecords.empty() && !list.empty() &&
+ m_SoundRecords.front().getPath() == list.front().getPath()));
+}
+
int Memo::generateImageIndex()
{
for (int i = 0; i < MAX_IMAGE_COUNT; i++) {
{
}
+SoundRecord::SoundRecord(std::string path)
+ : m_Path(std::move(path))
+{
+}
+
const std::string &SoundRecord::getPath() const
{
return m_Path;
void setMemoStmt(sqlite3_stmt *sqlStmt, bundle *data, long long memoId);
void setRemoveMemoStmt(sqlite3_stmt *sqlStmt, long long memoId);
void setRemoveMediaStmt(sqlite3_stmt *sqlStmt, int index, const char *path, long long memoId);
- void setMediaStmt(sqlite3_stmt *sqlStmt, int index, const char *path, long long memoId);
+ void setMediaStmt(sqlite3_stmt *sqlStmt, const char *dir, int index, const char *path, long long memoId);
void setStmtText(sqlite3_stmt *sqlStmt, bundle *data, const char *key, int position);
void setStmtInt(sqlite3_stmt *sqlStmt, bundle *data, const char *key, int position);
void setRemoveFiles(int memoId, const char *stmt);
void clearSyncFiles();
- std::string getFilePath(const char *imagePath, const char *prefix, int imageIndex, int memoId);
+ std::string getFilePath(const char *imagePath, const char *dir, int imageIndex, int memoId);
bool execute(Stmts commands, int requestId, long long &memoId);
namespace
{
- const std::string thumbnailPrefix = "thumbnail";
+ const std::string thumbnailDir = std::string(getDataDir()).append("thumbnails/");
+ const std::string soundDir = std::string(getDataDir()).append("sounds/");
const std::string imageDir = std::string(getDataDir()).append("images/");
const std::string imageTempDir = std::string(getDataDir()).append("images_temp/");
callback();
return;
}
- std::string destPath = getFilePath(tnPath.c_str(), thumbnailPrefix.c_str(), 0, memoId);
+ std::string destPath = getFilePath(tnPath.c_str(), thumbnailDir.c_str(), 0, memoId);
isSuccess = Common::cropImage(tnPath.c_str(), CROP_WIDTH, CROP_HEIGHT, destPath.c_str(),
[destPath, memoId, callback, this](int error) {
data_control_provider_sql_register_cb(&cbs, this);
+ createFolder(thumbnailDir.c_str());
+ createFolder(soundDir.c_str());
createFolder(imageDir.c_str());
createFolder(imageTempDir.c_str());
}
m_FilesToRemove.push_back(path);
}
-void DataProvider::setMediaStmt(sqlite3_stmt *sqlStmt, int index, const char *path, long long memoId)
+void DataProvider::setMediaStmt(sqlite3_stmt *sqlStmt, const char *dir, int index, const char *path, long long memoId)
{
int position = 0;
- std::string destPath = getFilePath(path, "", index, memoId);
+ std::string destPath = getFilePath(path, dir, index, memoId);
int err = 0;
if (index != ABSENT_INDEX) {
for (int i = 0; i < imageCount; ++i) {
if (imageStatus[i] == Image::StatusNew) {
- commands.push_back({ insertImage, std::bind(&DataProvider::setMediaStmt, this, _1, imageIndex[i], imagePath[i], _2) });
+ commands.push_back({ insertImage, std::bind(&DataProvider::setMediaStmt, this, _1, imageDir.c_str(), imageIndex[i], imagePath[i], _2) });
}
}
}
commands.push_back({ deleteSound, std::bind(&DataProvider::setRemoveMediaStmt, this, _1, ABSENT_INDEX, soundToRemove, _2) });
}
if (soundToSave) {
- commands.push_back({ insertSound, std::bind(&DataProvider::setMediaStmt, this, _1, ABSENT_INDEX, soundToSave, _2) });
+ commands.push_back({ insertSound, std::bind(&DataProvider::setMediaStmt, this, _1, soundDir.c_str(), ABSENT_INDEX, soundToSave, _2) });
}
}
m_FilesToRename.clear();
}
-std::string DataProvider::getFilePath(const char *imagePath, const char *prefix, int imageIndex, int memoId)
+std::string DataProvider::getFilePath(const char *imagePath, const char *dir, int imageIndex, int memoId)
{
const char *imageExt = strrchr(imagePath, '.');
char path[PATH_MAX] = { 0, };
- snprintf(path, sizeof(path), "%s%s%d_%d%s", imageDir.c_str(), prefix,
+ snprintf(path, sizeof(path), "%s%d_%d%s", dir,
memoId, imageIndex, imageExt ? imageExt : "");
return path;