#include "App/AppControl.h"
#include "Ui/GenItem.h"
+#include <dpm/device-policy-manager.h>
+
namespace Contacts
{
namespace Settings
*/
class ImportItem : public Ui::GenItem
{
+ public:
+ /**
+ * @brief Create genlist import item
+ * @param[in] handle DPM handle
+ */
+ explicit ImportItem(device_policy_manager_h handle);
+
private:
virtual char *getText(Evas_Object *parent, const char *part) override;
virtual void onSelected() override;
void onImportFinish(ImportController *importer);
void onStorageSelected(void *data);
void onSimContactImport(int totalCount, int importedCount);
+ void onSdCardStateChanged(const char* name, const char* state);
void importFromSim();
+ void showPolicyPopup();
App::AppControl m_AppControl;
+ device_policy_manager_h m_DpmHandle;
+ int m_DpmCallbackId;
};
}
}
#include "Contacts/Settings/Model/Storage.h"
#include "App/AppControlRequest.h"
+#include "Common/Dpm.h"
#include "Ui/Genlist.h"
#include "Ui/ListPopup.h"
#include "Ui/ProcessPopup.h"
using namespace Contacts::Settings;
using namespace Contacts::Settings::Model;
+using namespace Common::Dpm;
using namespace std::placeholders;
using namespace Ui;
ImportStorageSimCard
};
+ImportItem::ImportItem(device_policy_manager_h handle)
+ : m_DpmHandle(handle), m_DpmCallbackId(0)
+{
+}
+
char *ImportItem::getText(Evas_Object *parent, const char *part)
{
if (strcmp(part, "elm.text") == 0) {
void ImportItem::onSelected()
{
- if (isAccessGranted(STORAGE_TYPE_EXTERNAL, StorageAccessRead)) {
- ListPopup *popup = new ListPopup();
- popup->create(getParent()->getEvasObject());
- popup->setTitle("IDS_PB_HEADER_IMPORT");
+ ListPopup *popup = new ListPopup();
+ popup->create(getParent()->getEvasObject());
+ popup->setTitle("IDS_PB_HEADER_IMPORT");
+ if (isAllowed(m_DpmHandle, PolicySdCard) && isAccessGranted(STORAGE_TYPE_EXTERNAL, StorageAccessRead)) {
popup->addItem("IDS_PB_OPT_SD_CARD", (void *) ImportStorageSdCard);
- popup->addItem("IDS_PB_OPT_DEVICE", (void *) ImportStorageDevice);
-
- bool isSimInitialized = false;
- contacts_sim_get_initialization_status_by_sim_slot_no(0, &isSimInitialized);
- if (isSimInitialized) {
- popup->addItem("IDS_PB_OPT_SIM_CARD", (void *) ImportStorageSimCard);
- }
+ }
+ popup->addItem("IDS_PB_OPT_DEVICE", (void *) ImportStorageDevice);
- popup->setSelectCallback(std::bind(&ImportItem::onStorageSelected, this, _1));
- popup->show();
- } else {
- onStorageSelected((void *) ImportStorageDevice);
+ bool isSimInitialized = false;
+ contacts_sim_get_initialization_status_by_sim_slot_no(0, &isSimInitialized);
+ if (isSimInitialized) {
+ popup->addItem("IDS_PB_OPT_SIM_CARD", (void *) ImportStorageSimCard);
}
+
+ popup->setSelectCallback(std::bind(&ImportItem::onStorageSelected, this, _1));
+ popup->show();
}
void ImportItem::onPickResult(app_control_h request, app_control_h reply,
{
ImportStorageType storageType = (ImportStorageType) (long) data;
- if (storageType == ImportStorageSimCard) {
- importFromSim();
- } else {
- m_AppControl = App::requestPickVcard(getDirectoryPath((storage_type_e) storageType,
- STORAGE_DIRECTORY_MAX).c_str());
- m_AppControl.launch(makeCallbackWithLastParam(&ImportItem::onPickResult), this);
+ switch (storageType) {
+ case ImportStorageSimCard:
+ importFromSim();
+ break;
+ case ImportStorageSdCard:
+ if (!isAllowed(m_DpmHandle, PolicySdCard)) {
+ showPolicyPopup();
+ return;
+ }
+ m_DpmCallbackId = addPolicyChangedCallback(m_DpmHandle, PolicySdCard,
+ makeCallbackWithLastParam(&ImportItem::onSdCardStateChanged), this);
+ //break is absent because launch of app control is also needed for SD card
+ case ImportStorageDevice:
+ m_AppControl = App::requestPickVcard(getDirectoryPath((storage_type_e) storageType,
+ STORAGE_DIRECTORY_MAX).c_str());
+ m_AppControl.launch(makeCallbackWithLastParam(&ImportItem::onPickResult), this);
+ break;
}
}
//TODO Implement show of progress popup
}
+void ImportItem::onSdCardStateChanged(const char* name, const char* state)
+{
+ if (m_DpmCallbackId) {
+ m_AppControl.terminate();
+ dpm_remove_policy_changed_cb(m_DpmHandle, m_DpmCallbackId);
+ m_DpmCallbackId = 0;
+
+ showPolicyPopup();
+ }
+}
+
void ImportItem::importFromSim()
{
Ui::ProcessPopup *popup = Ui::ProcessPopup::create(getParent()->getEvasObject(),
WARN_IF_ERR(err, "notification_status_message_post() failed.");
});
}
+
+void ImportItem::showPolicyPopup()
+{
+ char buf[BUFFER_SIZE] = { 0, };
+ snprintf(buf, sizeof(buf), _("IDS_IDLE_TPOP_SECURITY_POLICY_PREVENTS_USE_OF_PS"),
+ _("IDS_PB_OPT_SD_CARD"));
+
+ int err = notification_status_message_post(buf);
+ WARN_IF_ERR(err, "notification_status_message_post() failed.");
+}