#ifndef OPERATION_CONTROLLER_H
#define OPERATION_CONTROLLER_H
-#include <app_control.h>
+#include <app.h>
#include <Evas.h>
+#include <string>
namespace Ui
{
app_control_h getRequest() const;
/**
+ * @brief Get URI without prefix (if present).
+ * @param[in] scheme Scheme prefix to remove (e.g. tel: or file://)
+ * @return URI without scheme.
+ */
+ std::string getUrn(const char *scheme) const;
+
+ /**
* @brief Send failure reply to the last request
*/
void replyFailure();
virtual void onCreate() override;
virtual void onRequest(Operation operation, app_control_h request) override;
- static std::string getPhoneNumber(app_control_h appControl);
static unsigned getBadgeCount(const char *package);
-
void saveLastTab();
static TabId getLastTab();
#define OPERATION_VIEW_CONTROLLER_H
#include "OperationController.h"
-#include "Ux/SelectTypes.h"
-
-namespace Contacts
-{
- namespace List
- {
- class ListView;
- }
- namespace Settings
- {
- class ImportController;
- }
-}
class OperationViewController : public OperationController
{
private:
virtual void onRequest(Operation operation, app_control_h request);
- bool onSelectResult(Ux::SelectResults results,
- Contacts::List::ListView *view, std::string uri);
- void onImportFinish(Contacts::Settings::ImportController *importer,
- Contacts::List::ListView *view);
};
-#endif /* _OPERATION_VIEW_CONTROLLER_H_ */
+#endif /* OPERATION_VIEW_CONTROLLER_H */
return m_Request;
}
+std::string OperationController::getUrn(const char *scheme) const
+{
+ char *uri = nullptr;
+ app_control_get_uri(m_Request, &uri);
+ if (!uri) {
+ return "";
+ }
+
+ std::string path;
+ if (scheme) {
+ size_t length = strlen(scheme);
+ if (strncmp(uri, scheme, length) == 0) {
+ path = uri + length;
+ }
+ }
+
+ if (path.empty()) {
+ path = uri;
+ }
+
+ free(uri);
+ return path;
+}
+
void OperationController::replyFailure()
{
app_control_h reply;
TabId selectedTab = TabContacts;
if (operation == OperationDial) {
auto dialer = static_cast<Phone::Dialer::DialerView *>(m_Tabs[TabDialer]);
- dialer->setNumber(getPhoneNumber(request));
+ dialer->setNumber(getUrn(APP_CONTROL_URI_DIAL));
selectedTab = TabDialer;
} else if (appId && strcmp(appId, APP_CONTROL_PHONE_APPID) == 0) {
if (getBadgeCount(APP_CONTROL_PHONE_APPID) > 0) {
free(appId);
}
-std::string OperationDefaultController::getPhoneNumber(app_control_h appControl)
-{
- std::string number;
-
- char *uri = nullptr;
- app_control_get_uri(appControl, &uri);
-
- size_t length = sizeof(APP_CONTROL_URI_DIAL) - 1;
- if (uri && strncmp(uri, APP_CONTROL_URI_DIAL, length) == 0) {
- number = uri + length;
- }
-
- free(uri);
- return number;
-}
-
unsigned OperationDefaultController::getBadgeCount(const char *package)
{
unsigned count = 0;
#include "OperationViewController.h"
-#include "MainApp.h"
#include "Contacts/Details/DetailsView.h"
-#include "Contacts/List/ListView.h"
-#include "Contacts/Settings/ImportController.h"
+#include "Contacts/List/VcardView.h"
#include "Contacts/Utils.h"
-#include "Utils/Logger.h"
#include "App/AppControlRequest.h"
#include "Ui/Navigator.h"
+#include "Utils/Logger.h"
-#include <notification.h>
#include <string.h>
+#include <sys/stat.h>
+
+#define APP_CONTROL_URI_PATH "file://"
using namespace Contacts;
using namespace Contacts::Details;
using namespace Contacts::List;
-#define BUFFER_SIZE 1024
-
OperationViewController::OperationViewController()
: OperationController(OperationView)
{
view = new DetailsView(getDisplayContactId(personId));
}
} else {
- char *uri = NULL;
- app_control_get_uri(request, &uri);
- if (uri) {
- view = new ListView(uri);
- ListView *listView = (ListView *)view;
- listView->setSelectMode(Ux::SelectMulti);
- listView->setSelectCallback(std::bind(&OperationViewController::onSelectResult, this,
- std::placeholders::_1, listView, std::string(uri)));
-
- free(uri);
+ std::string path = getUrn(APP_CONTROL_URI_PATH);
+ struct stat buffer;
+ if (stat(path.c_str(), &buffer) == 0) {
+ view = new VcardView(path);
+ } else {
+ ERR("Failed to open file: \"%s\". %s", path.c_str(), strerror(errno));
}
}
ui_app_exit();
}
}
-
-bool OperationViewController::onSelectResult(Ux::SelectResults results, ListView *view, std::string uri)
-{
- std::vector<contacts_record_h> records;
- for (auto &&result : results) {
- records.push_back((contacts_record_h)result.value.data);
- }
- int count = records.size();
- if (count) {
- std::vector<std::string> vcards;
- vcards.push_back(uri);
- Settings::ImportController *importer = new Settings::ImportController(view->getEvasObject(),
- "IDS_PB_HEADER_IMPORT_CONTACTS_ABB2", count, std::move(vcards), std::move(records));
- importer->setFinishCallback(std::bind(&OperationViewController::onImportFinish, this, importer, view));
- importer->run();
- }
-
- return false;
-}
-
-void OperationViewController::onImportFinish(Settings::ImportController *importer, ListView *view)
-{
- int count = importer->getTotalCount();
- RETM_IF(count <= 0, "invalid count");
- int err = NOTIFICATION_ERROR_NONE;
-
- if (count == 1) {
- err = notification_status_message_post(_("IDS_PB_TPOP_1_CONTACT_IMPORTED"));
- } else {
- char text[BUFFER_SIZE] = { 0, };
- snprintf(text, sizeof(text), _("IDS_PB_TPOP_PD_CONTACTS_IMPORTED"), count);
- err = notification_status_message_post(text);
- }
- WARN_IF_ERR(err, "notification_status_message_post() failed.");
-
- view->getPage()->close();
-}
#include <tizen.h>
#include <list>
-namespace Utils
-{
- class UniString;
-}
-
namespace Contacts
{
namespace Model
*/
void unsetDeleteCallback();
- /**
- * @return First letter from formatted person name
- */
- virtual const Utils::UniString *getIndexLetter() const;
-
protected:
/**
* @brief ContactData updated callback
*/
#include "Contacts/Model/ContactData.h"
-#include "Utils/UniString.h"
using namespace Contacts::Model;
m_OnDeleted = nullptr;
}
-const Utils::UniString *ContactData::getIndexLetter() const
-{
- return nullptr;
-}
-
void ContactData::onUpdated(int changes)
{
if (m_OnUpdated) {
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 CONTACTS_LIST_CONTACT_ITEM_H
+#define CONTACTS_LIST_CONTACT_ITEM_H
+
+#include "Ux/SelectItem.h"
+
+#define PART_CONTACT_NAME "elm.text"
+#define PART_CONTACT_THUMBNAIL "elm.swallow.icon"
+#define PART_CONTACT_CHECK "elm.swallow.end"
+
+namespace Contacts
+{
+ namespace Model
+ {
+ class ContactRecordData;
+ }
+
+ namespace List
+ {
+ /**
+ * @brief Contact genlist item
+ */
+ class ContactItem : public Ux::SelectItem
+ {
+ public:
+ /**
+ * @brief Create contact item
+ * @param[in] contact Contact object
+ */
+ explicit ContactItem(Contacts::Model::ContactRecordData &contact);
+
+ /**
+ * @return Contact object.
+ */
+ Contacts::Model::ContactRecordData &getContact();
+
+ private:
+ virtual char *getText(Evas_Object *parent, const char *part) override;
+ virtual Evas_Object *getContent(Evas_Object *parent, const char *part) override;
+ virtual Ux::SelectResult getDefaultResult() const override;
+
+ Contacts::Model::ContactRecordData &m_Contact;
+ };
+ }
+}
+
+#endif /* CONTACTS_LIST_CONTACT_ITEM_H */
#define CONTACTS_LIST_LIST_VIEW_H
#include "Contacts/Common/ContactSelectTypes.h"
+#include "Contacts/List/Model/PersonProvider.h"
+
#include "Ux/SelectView.h"
#include "Utils/UniString.h"
namespace Ui
{
class Genlist;
- class GenlistItem;
class GenlistGroupItem;
}
namespace Contacts
{
- namespace Model
- {
- class ContactData;
- class ContactDataProvider;
- }
-
namespace List
{
- class GroupItem;
- class SelectAllItem;
- class PersonGroupItem;
class PersonItem;
-
- namespace Model
- {
- class Person;
- }
+ class PersonGroupItem;
/**
* @brief Contacts list view
* @brief Create new person list view
* @param[in] filterType Defines how to filter person list
*/
- ListView(int filterType = FilterNone);
-
- /**
- * @brief Create new vcard contact list view
- * @param[in] vcardPath Path of the vcard file
- */
- explicit ListView(const char *vcardPath);
-
+ explicit ListView(int filterType = FilterNone);
virtual ~ListView() override;
private:
virtual void onCreated() override;
virtual void onMenuPressed() override;
- void onSharePressed();
+ void onDeleteSelected();
+ void onShareSelected();
virtual void onSelectAllInsert(Ui::GenlistItem *item) override;
virtual void onSelectModeChanged(Ux::SelectMode selectMode) override;
void deletePersonGroupItem(PersonGroupItem *group);
PersonGroupItem *getNextPersonGroupItem(const Utils::UniString &indexLetter);
- PersonItem *createPersonItem(Contacts::Model::ContactData &person);
+ PersonItem *createPersonItem(Model::Person &person);
void insertPersonItem(PersonItem *item);
void updatePersonItem(PersonItem *item, int changes);
void deletePersonItem(PersonItem *item);
void onPersonDeleted(PersonItem *item);
Evas_Object *m_Box;
+ Evas_Object *m_NoContent;
Ui::Genlist *m_Genlist;
Evas_Object *m_Index;
Evas_Object *m_AddButton;
- Evas_Object *m_NoContent;
Ui::GenlistGroupItem *m_Sections[SectionMax];
- std::map<Utils::UniString, PersonGroupItem *> m_PersonGroups;
- Contacts::Model::ContactDataProvider *m_Provider;
-
- bool m_HasIndex;
+ std::map<Utils::UniString, PersonGroupItem *> m_PersonGroups;
+ Model::PersonProvider m_Provider;
};
}
}
/**
* @return First letter from formatted person name
*/
- virtual const Utils::UniString *getIndexLetter() const override;
+ const Utils::UniString &getIndexLetter() const;
/**
* @return _contacts_person record
#define CONTACTS_LIST_MODEL_VCARD_PROVIDER_H
#include "Contacts/Model/ContactDataProvider.h"
+#include <string>
namespace Contacts
{
public:
/**
* @brief Create list of vcard contacts
- * @param[in] path Vcard path
+ * @param[in] vcardPath Vcard path
*/
- VcardProvider(const char *path);
+ VcardProvider(std::string vcardPath);
VcardProvider(const VcardProvider &contact) = delete;
virtual ~VcardProvider() override;
#ifndef CONTACTS_LIST_PERSON_ITEM_H
#define CONTACTS_LIST_PERSON_ITEM_H
-#include "Ux/SelectItem.h"
-
-#define PART_PERSON_NAME "elm.text"
-#define PART_PERSON_THUMBNAIL "elm.swallow.icon"
-#define PART_CHECK "elm.swallow.end"
+#include "Contacts/List/ContactItem.h"
namespace Contacts
{
- namespace Model
- {
- class ContactData;
- }
-
namespace List
{
+ namespace Model
+ {
+ class Person;
+ }
+
/**
- * @brief Person list item
+ * @brief Person genlist item
*/
- class PersonItem : public Ux::SelectItem
+ class PersonItem : public ContactItem
{
public:
/**
* @brief Create person item
* @param[in] person Person object
*/
- explicit PersonItem(Contacts::Model::ContactData &person);
+ explicit PersonItem(Model::Person &person);
/**
- * @return Person object
+ * @return Person object.
*/
- Contacts::Model::ContactData &getPerson();
+ Model::Person &getPerson();
private:
- virtual char *getText(Evas_Object *parent, const char *part) override;
- virtual Evas_Object *getContent(Evas_Object *parent, const char *part) override;
virtual Ux::SelectResult getDefaultResult() const override;
- Contacts::Model::ContactData &m_Person;
+ Model::Person &m_Person;
};
}
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 CONTACTS_LIST_VCARD_VIEW_H
+#define CONTACTS_LIST_VCARD_VIEW_H
+
+#include "Ux/SelectView.h"
+#include "Contacts/List/Model/VcardProvider.h"
+
+namespace Ui
+{
+ class Genlist;
+}
+
+namespace Contacts
+{
+ namespace Settings
+ {
+ class ImportController;
+ }
+
+ namespace List
+ {
+ class EXPORT_API VcardView : public Ux::SelectView
+ {
+ public:
+ /**
+ * @brief Create new vcard contact list view
+ * @param[in] vcardPath Path of the vcard file
+ */
+ explicit VcardView(std::string vcardPath);
+
+ private:
+ virtual Evas_Object *onCreate(Evas_Object *parent) override;
+ virtual void onSelectAllInsert(Ui::GenlistItem *item) override;
+
+ bool onSelectResult(Ux::SelectResults results);
+ void onImportFinished(Settings::ImportController *importer);
+
+ Ui::Genlist *m_Genlist;
+ std::string m_VcardPath;
+ Model::VcardProvider m_Provider;
+ };
+ }
+}
+
+#endif /* CONTACTS_LIST_VCARD_VIEW_H */
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 "Contacts/List/ContactItem.h"
+#include "Contacts/Model/ContactRecordData.h"
+
+#include "Ui/Thumbnail.h"
+#include <app_i18n.h>
+
+using namespace Contacts::List;
+using namespace Contacts::Model;
+
+ContactItem::ContactItem(ContactRecordData &contact)
+ : m_Contact(contact)
+{
+}
+
+ContactRecordData &ContactItem::getContact()
+{
+ return m_Contact;
+}
+
+char *ContactItem::getText(Evas_Object *parent, const char *part)
+{
+ if (strcmp(part, PART_CONTACT_NAME) == 0) {
+ const char *name = m_Contact.getName();
+ return strdup(name ? name : _("IDS_LOGS_MBODY_UNKNOWN"));
+ }
+
+ return nullptr;
+}
+
+Evas_Object *ContactItem::getContent(Evas_Object *parent, const char *part)
+{
+ using Ui::Thumbnail;
+
+ if (strcmp(part, PART_CONTACT_THUMBNAIL) == 0) {
+ Thumbnail *thumbnail = Thumbnail::create(parent, Thumbnail::SizeSmall,
+ m_Contact.getImagePath());
+ thumbnail->setSizeHint(true);
+ return thumbnail->getEvasObject();
+ } else if (strcmp(part, PART_CONTACT_CHECK) == 0) {
+ return SelectItem::getContent(parent, part);
+ }
+
+ return nullptr;
+}
+
+Ux::SelectResult ContactItem::getDefaultResult() const
+{
+ return { 0, (void *) m_Contact.getContactRecord() };
+}
using namespace std::placeholders;
ListView::ListView(int filterType)
- : m_Genlist(nullptr), m_Index(nullptr), m_AddButton(nullptr),
- m_Sections{ nullptr }, m_HasIndex(true)
+ : m_Box(nullptr), m_NoContent(nullptr), m_Genlist(nullptr),
+ m_Index(nullptr), m_AddButton(nullptr),
+ m_Sections{ nullptr }, m_Provider(filterType)
{
auto strings = Common::getSelectViewStrings();
strings.titleDefault = "IDS_PB_TAB_CONTACTS";
strings.titleSingle = "IDS_PB_HEADER_SELECT_CONTACT_ABB2";
setStrings(strings);
-
- m_Provider = new PersonProvider(filterType);
-}
-
-ListView::ListView(const char *vcardPath)
- : m_Genlist(nullptr), m_Index(nullptr), m_AddButton(nullptr),
- m_Sections{ nullptr }, m_HasIndex(false)
-{
- auto strings = Common::getSelectViewStrings();
- strings.buttonDone = "IDS_PB_HEADER_IMPORT";
- setStrings(strings);
-
- m_Provider = new VcardProvider(vcardPath);
}
ListView::~ListView()
{
- m_Provider->unsetInsertCallback();
- delete m_Provider;
contacts_db_remove_changed_cb(_contacts_my_profile._uri,
makeCallbackWithLastParam(&ListView::updateMyProfileItem), this);
}
elm_layout_theme_set(layout, "layout", "application", "fastscroll");
m_Box = elm_box_add(layout);
-
+ m_NoContent = createNoContentLayout(m_Box);
m_Genlist = createGenlist(m_Box);
elm_box_pack_end(m_Box, m_Genlist->getEvasObject());
- m_NoContent = createNoContentLayout(m_Box);
-
elm_object_part_content_set(layout, "elm.swallow.content", m_Box);
elm_object_part_content_set(layout, "elm.swallow.fastscroll", createIndex(layout));
- setIndexState(layout, m_HasIndex);
-
return layout;
}
{
updateSectionsMode();
- m_Provider->setInsertCallback(std::bind(&ListView::onPersonInserted, this, _1));
+ m_Provider.setInsertCallback(std::bind(&ListView::onPersonInserted, this, _1));
contacts_db_add_changed_cb(_contacts_my_profile._uri,
makeCallbackWithLastParam(&ListView::updateMyProfileItem), this);
}
Ui::Menu *menu = new Ui::Menu();
menu->create(getEvasObject());
-
- menu->addItem("IDS_LOGS_OPT_DELETE", [this] {
- auto strings = Common::getSelectViewStrings();
- strings.buttonDone = "IDS_LOGS_OPT_DELETE";
-
- ListView *view = new ListView();
- view->setStrings(strings);
- view->setSelectMode(SelectMulti);
- view->setSelectCallback([](SelectResults results) {
- std::vector<int> ids;
- for (auto &&result : results) {
- ids.push_back(result.value.id);
- }
-
- contacts_db_delete_records(_contacts_person._uri, ids.data(), ids.size());
- return true;
- });
- getNavigator()->navigateTo(view);
- });
-
- menu->addItem("IDS_PB_OPT_SHARE", std::bind(&ListView::onSharePressed, this));
-
+ menu->addItem("IDS_LOGS_OPT_DELETE", std::bind(&ListView::onDeleteSelected, this));
+ menu->addItem("IDS_PB_OPT_SHARE", std::bind(&ListView::onShareSelected, this));
menu->addItem("IDS_PB_OPT_MANAGE_FAVOURITES_ABB", [this] {
auto manageFavPopup = new ManageFavoritesPopup(getNavigator());
manageFavPopup->create(getEvasObject());
menu->show();
}
-void ListView::onSharePressed()
+void ListView::onDeleteSelected()
+{
+ auto strings = Common::getSelectViewStrings();
+ strings.buttonDone = "IDS_LOGS_OPT_DELETE";
+
+ ListView *view = new ListView();
+ view->setStrings(strings);
+ view->setSelectMode(SelectMulti);
+ view->setSelectCallback([](SelectResults results) {
+ std::vector<int> ids;
+ ids.reserve(results.count());
+
+ for (auto &&result : results) {
+ ids.push_back(result.value.id);
+ }
+
+ contacts_db_delete_records(_contacts_person._uri, ids.data(), ids.size());
+ return true;
+ });
+ getNavigator()->navigateTo(view);
+}
+
+void ListView::onShareSelected()
{
auto strings = Common::getSelectViewStrings();
strings.buttonDone = "IDS_PB_OPT_SHARE";
view->setSelectMode(SelectMulti);
view->setSelectCallback([](SelectResults results) {
size_t count = results.count();
-
std::vector<std::string> idString(count);
- idString.reserve(count);
std::vector<const char *> ids(count);
- ids.reserve(count);
for (size_t i = 0; i < count; ++i) {
idString[i] = std::to_string(results[i].value.id);
ids[i] = idString[i].c_str();
}
- App::AppControl control = App::requestMultiShareContacts(ids.data(), count);
- control.launch();
- control.detach();
+
+ App::AppControl request = App::requestMultiShareContacts(ids.data(), count);
+ request.launch();
+ request.detach();
return true;
});
void ListView::fillPersonList()
{
if (m_PersonGroups.empty()) {
- ContactDataList list = m_Provider->getContactDataList();
+ ContactDataList list = m_Provider.getContactDataList();
PersonGroupItem *group = nullptr;
for (auto &&contactData : list) {
- const UniString *nextLetter = contactData->getIndexLetter();
- if (nextLetter) {
- if (!group || group->getTitle() != *nextLetter) {
- group = insertPersonGroupItem(*nextLetter);
- }
+ Person &person = static_cast<Person &>(*contactData);
+
+ const UniString &nextLetter = person.getIndexLetter();
+ if (!group || group->getTitle() != nextLetter) {
+ group = insertPersonGroupItem(nextLetter);
}
- auto item = createPersonItem(*contactData);
+ auto item = createPersonItem(person);
m_Genlist->insert(item, group);
onItemInserted(item);
}
void ListView::hideNoContentLayout()
{
if (evas_object_visible_get(m_NoContent)) {
- setIndexState(getEvasObject(), m_HasIndex);
+ setIndexState(getEvasObject(), true);
elm_scroller_content_min_limit(m_Genlist->getEvasObject(), EINA_FALSE, EINA_FALSE);
evas_object_size_hint_weight_set(m_Genlist->getEvasObject(), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
void ListView::updateNoContentLayout()
{
- ContactDataList list = m_Provider->getContactDataList();
+ ContactDataList list = m_Provider.getContactDataList();
list.size() > 0 ? hideNoContentLayout() : showNoContentLayout();
}
break;
case SelectSingle:
- deleteAddButton();
- page->setContent("toolbar", nullptr);
- break;
-
case SelectMulti:
deleteAddButton();
page->setContent("toolbar", nullptr);
return nullptr;
}
-PersonItem *ListView::createPersonItem(ContactData &person)
+PersonItem *ListView::createPersonItem(Person &person)
{
PersonItem *item = new PersonItem(person);
person.setUpdateCallback(std::bind(&ListView::onPersonUpdated, this, item, _1));
PersonGroupItem *group = nullptr;
PersonItem *nextItem = nullptr;
- const UniString *indexLetter = item->getPerson().getIndexLetter();
- if (indexLetter) {
- auto it = m_PersonGroups.find(*indexLetter);
- if (it != m_PersonGroups.end()) {
- group = it->second;
- nextItem = getNextPersonItem(it->second, static_cast<Person &>(item->getPerson()));
- } else {
- PersonGroupItem *nextGroup = getNextPersonGroupItem(*indexLetter);
- group = insertPersonGroupItem(*indexLetter, nextGroup);
- }
+ const UniString &indexLetter = item->getPerson().getIndexLetter();
+ auto it = m_PersonGroups.find(indexLetter);
+ if (it != m_PersonGroups.end()) {
+ group = it->second;
+ nextItem = getNextPersonItem(it->second, item->getPerson());
+ } else {
+ PersonGroupItem *nextGroup = getNextPersonGroupItem(indexLetter);
+ group = insertPersonGroupItem(indexLetter, nextGroup);
}
m_Genlist->insert(item, group, nextItem);
}
} else if (changes & ContactData::ChangedImage) {
elm_genlist_item_fields_update(item->getObjectItem(),
- PART_PERSON_THUMBNAIL, ELM_GENLIST_ITEM_FIELD_CONTENT);
+ PART_CONTACT_THUMBNAIL, ELM_GENLIST_ITEM_FIELD_CONTENT);
}
}
void ListView::onItemPressed(SelectItem *item)
{
PersonItem *personItem = static_cast<PersonItem *>(item);
- int id = static_cast<Person &>(personItem->getPerson()).getDisplayContactId();
+ int id = personItem->getPerson().getDisplayContactId();
getNavigator()->navigateTo(new Details::DetailsView(id));
}
void ListView::onPersonInserted(ContactData &person)
{
- auto item = createPersonItem(person);
+ auto item = createPersonItem(static_cast<Person &>(person));
insertPersonItem(item);
onItemInserted(item);
}
return m_ContactIds;
}
-const UniString *Person::getIndexLetter() const
+const UniString &Person::getIndexLetter() const
{
- return &m_IndexLetter;
+ return m_IndexLetter;
}
const contacts_record_h Person::getRecord() const
using namespace Contacts::Model;
using namespace Contacts::List::Model;
-VcardProvider::VcardProvider(const char *path)
+VcardProvider::VcardProvider(std::string vcardPath)
{
- int err = contacts_vcard_parse_to_contact_foreach(path, [](contacts_record_h record, void *data)->bool {
+ int err = contacts_vcard_parse_to_contact_foreach(vcardPath.c_str(), [](contacts_record_h record, void *data)->bool {
RETVM_IF(!record || !data, true, "invalid data");
ContactDataList *list = (ContactDataList *)data;
*
*/
-#include "Contacts/Model/ContactRecordData.h"
#include "Contacts/List/PersonItem.h"
+#include "Contacts/List/Model/Person.h"
#include "Contacts/Common/ContactSelectTypes.h"
-#include "Ui/Thumbnail.h"
-#include <app_i18n.h>
-using namespace Contacts;
using namespace Contacts::List;
-using namespace Contacts::Model;
+using namespace Contacts::List::Model;
-PersonItem::PersonItem(ContactData &person)
- : m_Person(person)
+PersonItem::PersonItem(Person &person)
+ : ContactItem(person), m_Person(person)
{
}
-ContactData &PersonItem::getPerson()
+Person &PersonItem::getPerson()
{
return m_Person;
}
-char *PersonItem::getText(Evas_Object *parent, const char *part)
-{
- if (strcmp(part, PART_PERSON_NAME) == 0) {
- const char *name = m_Person.getName();
- return strdup(name ? name : _("IDS_LOGS_MBODY_UNKNOWN"));
- }
-
- return nullptr;
-}
-
-Evas_Object *PersonItem::getContent(Evas_Object *parent, const char *part)
-{
- using Ui::Thumbnail;
-
- if (strcmp(part, PART_PERSON_THUMBNAIL) == 0) {
- Thumbnail *thumbnail = Thumbnail::create(parent, Thumbnail::SizeSmall,
- m_Person.getImagePath());
- thumbnail->setSizeHint(true);
- return thumbnail->getEvasObject();
- } else if (strcmp(part, PART_CHECK) == 0) {
- return SelectItem::getContent(parent, part);
- }
-
- return nullptr;
-}
-
Ux::SelectResult PersonItem::getDefaultResult() const
{
- if (m_Person.getType() == ContactData::TypeContact) {
- return { ResultPerson, (void *)static_cast<ContactRecordData &>(m_Person).getContactRecord() };
- } else {
- return { ResultPerson, m_Person.getId() };
- }
+ return { ResultPerson, m_Person.getId() };
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 "Contacts/List/VcardView.h"
+#include "Contacts/List/ContactItem.h"
+#include "Contacts/Model/ContactRecordData.h"
+#include "Contacts/Settings/ImportController.h"
+#include "Common/Strings.h"
+
+#include "Ui/Genlist.h"
+#include "Utils/Logger.h"
+
+#include <app_i18n.h>
+#include <notification.h>
+
+#define NOTI_BUFFER_SIZE 1024
+
+using namespace Contacts::Model;
+using namespace Contacts::List;
+using namespace Contacts::List::Model;
+using namespace std::placeholders;
+
+VcardView::VcardView(std::string vcardPath)
+ : m_Genlist(nullptr), m_VcardPath(std::move(vcardPath)), m_Provider(m_VcardPath)
+{
+ auto strings = Common::getSelectViewStrings();
+ strings.buttonDone = "IDS_PB_HEADER_IMPORT";
+
+ setStrings(strings);
+ setSelectMode(Ux::SelectMulti);
+ setSelectCallback(std::bind(&VcardView::onSelectResult, this, _1));
+}
+
+Evas_Object *VcardView::onCreate(Evas_Object *parent)
+{
+ m_Genlist = new Ui::Genlist();
+ m_Genlist->create(parent);
+
+ for (auto &&contact : m_Provider.getContactDataList()) {
+ ContactItem *item = new ContactItem(static_cast<ContactRecordData &>(*contact));
+ m_Genlist->insert(item);
+ onItemInserted(item);
+ }
+
+ return m_Genlist->getEvasObject();
+}
+
+void VcardView::onSelectAllInsert(Ui::GenlistItem *item)
+{
+ m_Genlist->insert(item, nullptr, nullptr, Ui::Genlist::After);
+}
+
+bool VcardView::onSelectResult(Ux::SelectResults results)
+{
+ std::vector<contacts_record_h> records;
+ for (auto &&result : results) {
+ records.push_back((contacts_record_h) result.value.data);
+ }
+
+ Settings::ImportController *importer = new Settings::ImportController(getEvasObject(),
+ "IDS_PB_HEADER_IMPORT_CONTACTS_ABB2", records.size(), { m_VcardPath }, std::move(records));
+ importer->setFinishCallback(std::bind(&VcardView::onImportFinished, this, importer));
+ importer->run();
+
+ return false;
+}
+
+void VcardView::onImportFinished(Settings::ImportController *importer)
+{
+ size_t count = importer->getTotalCount();
+ int err = NOTIFICATION_ERROR_NONE;
+
+ if (count > 1) {
+ char buffer[NOTI_BUFFER_SIZE] = { 0, };
+ snprintf(buffer, sizeof(buffer), _("IDS_PB_TPOP_PD_CONTACTS_IMPORTED"), count);
+ err = notification_status_message_post(buffer);
+ } else if (count == 1){
+ err = notification_status_message_post(_("IDS_PB_TPOP_1_CONTACT_IMPORTED"));
+ }
+ WARN_IF_ERR(err, "notification_status_message_post() failed.");
+
+ getPage()->close();
+}