/**
* @brief Called when user confirmation button is pressed.
* @param[in] Inputed text
+ * @return Whether to destroy the popup.
*/
- typedef std::function<void(const char *)> ResultCallback;
+ typedef std::function<bool(const char *)> ResultCallback;
/**
* @brief Translatable strings table for popup elements.
addButton(m_Strings.buttonCancel);
Evas_Object *button = addButton(m_Strings.buttonDone, std::bind(&EditfieldPopup::onDoneButtonPressed, this));
+ elm_object_focus_allow_set(button, EINA_FALSE);
+
Evas_Object *entry = m_Editfield->getEntry();
elm_entry_input_panel_return_key_type_set(entry, ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
elm_entry_input_panel_return_key_disabled_set(entry, EINA_TRUE);
bool EditfieldPopup::onDoneButtonPressed()
{
+ bool shouldClose = true;
if (m_OnResult) {
char *text = elm_entry_markup_to_utf8(elm_entry_entry_get(m_Editfield->getEntry()));
- m_OnResult(text);
+ shouldClose = m_OnResult(text);
free(text);
}
- return true;
+ return shouldClose;
}
void EditfieldPopup::onDoneKeyPressed(Evas_Object *entry, void *eventInfo)
{
- onDoneButtonPressed();
- close();
+ if (onDoneButtonPressed()) {
+ close();
+ }
}
void EditfieldPopup::onEntryChanged(Evas_Object *button, Evas_Object *entry, void *eventInfo)
void onDonePressed(Evas_Object *button, void *eventInfo);
void onNameFilled(bool isFilled);
- bool isAlreadyExists();
void save();
-
void getGroupMembers();
Model::Group m_Group;
* @brief Create group object
* @param[in] id _contacts_group id
*/
- Group(int id = 0);
+ explicit Group(int id = 0);
/**
* @brief Create group object
* @param[in] record _contacts_group record
*/
- Group(contacts_record_h record);
+ explicit Group(contacts_record_h record);
virtual ~Group() override;
/**
contacts_record_h getRecord() const;
/**
+ * @return Whether the group has unique name.
+ */
+ bool isUnique() const;
+
+ /**
+ * @brief Save group to the database.
+ * @return Group ID on success, Contacts API error code otherwise.
+ */
+ int save();
+
+ /**
* @brief Compares group's values
* @return True if sort value less than in @a that, otherwise false
*/
*/
#include "Contacts/Groups/CreateGroupItem.h"
+#include "Contacts/Groups/Model/Group.h"
#include "Ui/Genlist.h"
#include "Ui/Scale.h"
#include "Ux/EditfieldPopup.h"
#include "Utils/Callback.h"
+#include <app_i18n.h>
#include <contacts.h>
+#include <notification.h>
#include "AppsCommonButtons.h"
#define BUTTON_COLOR_PRESSED 61, 76, 135, 255
using namespace Contacts::Groups;
+using namespace Contacts::Groups::Model;
void CreateGroupItem::setResultCallback(ResultCallback callback)
{
"IDS_PB_BUTTON_CANCEL"
});
popup->setResultCallback([this](const char *name) {
- int id = 0;
- contacts_record_h record = nullptr;
- contacts_record_create(_contacts_group._uri, &record);
- contacts_record_set_str(record, _contacts_group.name, name);
- contacts_db_insert_record(record, &id);
- contacts_record_destroy(record, true);
+ Group group;
+ contacts_record_set_str(group.getRecord(), _contacts_group.name, name);
+ if (!group.isUnique()) {
+ notification_status_message_post(_("IDS_PB_TPOP_GROUP_NAME_ALREADY_IN_USE"));
+ return false;
+ }
+ int id = group.save();
if (m_OnResult) {
m_OnResult(id);
}
+ return true;
});
popup->create(getParent()->getEvasObject());
popup->show();
void InputView::onDonePressed(Evas_Object *button, void *eventInfo)
{
- if (isAlreadyExists()) {
+ if (!m_Group.isUnique()) {
notification_status_message_post(_("IDS_PB_TPOP_GROUP_NAME_ALREADY_IN_USE"));
return;
}
save();
-
getPage()->close();
}
elm_object_disabled_set(m_DoneButton, !isFilled);
}
-bool InputView::isAlreadyExists()
-{
- contacts_filter_h filter = nullptr;
- contacts_filter_create(_contacts_group._uri, &filter);
- contacts_filter_add_str(filter, _contacts_group.name,
- CONTACTS_MATCH_EXACTLY, m_Group.getName());
-
- if (m_Group.getId()) {
- contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND);
- contacts_filter_add_int(filter, _contacts_group.id, CONTACTS_MATCH_NOT_EQUAL, m_Group.getId());
- }
-
- contacts_query_h query = nullptr;
- contacts_query_create(_contacts_group._uri, &query);
- contacts_query_set_filter(query, filter);
- contacts_filter_destroy(filter);
-
- int count = 0;
- contacts_db_get_count_with_query(query, &count);
- contacts_query_destroy(query);
-
- return count != 0;
-}
-
void InputView::save()
{
- int groupId = m_Group.getId();
- if (!groupId) {
- contacts_db_insert_record(m_Group.getRecord(), &groupId);
- }
+ int groupId = m_Group.save();
for (auto &&personId : m_AddMembersItem->getMembers()) {
auto it = std::find_if(m_GroupMembers.begin(), m_GroupMembers.end(), [personId](int id) {
}
contacts_list_destroy(contacts, true);
}
-
- contacts_db_update_record(m_Group.getRecord());
}
void InputView::getGroupMembers()
*/
#include "Contacts/Groups/Model/Group.h"
-
#include "Contacts/Groups/Model/Queries.h"
#include "Common/Database/RecordUtils.h"
+#include "Utils/Logger.h"
-using namespace Contacts::Groups::Model;
using namespace Common::Database;
+using namespace Contacts::Groups::Model;
Group::Group(int id)
{
return m_Record;
}
+bool Group::isUnique() const
+{
+ contacts_filter_h filter = nullptr;
+ contacts_filter_create(_contacts_group._uri, &filter);
+ contacts_filter_add_str(filter, _contacts_group.name,
+ CONTACTS_MATCH_EXACTLY, getName());
+
+ if (int id = getId()) {
+ contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND);
+ contacts_filter_add_int(filter, _contacts_group.id, CONTACTS_MATCH_NOT_EQUAL, id);
+ }
+
+ contacts_query_h query = nullptr;
+ contacts_query_create(_contacts_group._uri, &query);
+ contacts_query_set_filter(query, filter);
+ contacts_filter_destroy(filter);
+
+ int count = 0;
+ contacts_db_get_count_with_query(query, &count);
+ contacts_query_destroy(query);
+
+ return count == 0;
+}
+
+int Group::save()
+{
+ int id = 0;
+ int err = CONTACTS_ERROR_NONE;
+
+ if (getId() == 0) {
+ err = contacts_db_insert_record(m_Record, &id);
+ RETVM_IF_ERR(err, err, "contacts_db_insert_record() failed.");
+ } else {
+ err = contacts_db_update_record(m_Record);
+ RETVM_IF_ERR(err, err, "contacts_db_update_record() failed.");
+ id = getId();
+ }
+
+ return id;
+}
+
bool Group::operator<(const Group &that) const
{
return getSortValue() < that.getSortValue();
m_TypeField.setValue(value);
m_LabelField.setValue(label);
setText(label);
+ return true;
});
popup->create(getEvasObject());