*
*/
-#ifndef UI_DATE_POPUP_H
-#define UI_DATE_POPUP_H
+#ifndef UX_DATE_POPUP_H
+#define UX_DATE_POPUP_H
#include "Ui/Popup.h"
+#include <string>
-namespace Ui
+namespace Ux
{
/**
* @brief Popup with date picker.
*/
- class EXPORT_API DatePopup : public Popup
+ class EXPORT_API DatePopup : public Ui::Popup
{
public:
/**
* @brief Date input result callback.
* @param[in] Inputed date
*/
- typedef std::function<void(const tm&)> ResultCallback;
+ typedef std::function<void(const tm &)> ResultCallback;
+
+ /**
+ * @brief Translatable strings table for popup elements.
+ */
+ struct Strings
+ {
+ const char *popupTitle; /**< Popup title */
+ const char *buttonDone; /**< "Done" button text */
+ const char *buttonCancel; /**< "Cancel" button text */
+ };
/**
* @brief Create date popup.
+ * @param[in] format Data format for elm_datetime_format_set()
* @param[in] date Initial date value
*/
- DatePopup(tm date);
+ DatePopup(const char *format, tm date);
+
+ /**
+ * @brief Set translatable strings for popup.
+ * @remark Should be called before create().
+ * @param[in] strings Translatable strings table
+ */
+ void setStrings(Strings strings);
/**
* @brief Set date input result callback.
*/
void setResultCallback(ResultCallback callback);
- private:
+ /**
+ * @return Contained date picker.
+ */
+ Evas_Object *getDatePicker() const;
+
+ protected:
+ /**
+ * @brief Creates date picker and popup buttons.
+ * @see Control::onCreate()
+ */
virtual void onCreated() override;
- void onSetPressed();
+ private:
+ bool onDonePressed();
+
+ std::string m_Format;
tm m_Date;
- ResultCallback m_OnResult;
+
Evas_Object *m_DatePicker;
+ ResultCallback m_OnResult;
+ Strings m_Strings;
};
}
-#endif /* UI_DATE_POPUP_H */
+#endif /* UX_DATE_POPUP_H */
*
*/
-#include "Ui/DatePopup.h"
+#include "Ux/DatePopup.h"
-using namespace Ui;
+using namespace Ux;
-DatePopup::DatePopup(tm date)
- : m_Date(date), m_DatePicker(nullptr)
+DatePopup::DatePopup(const char *format, tm date)
+ : m_Format(format ? format : ""), m_Date(date),
+ m_DatePicker(nullptr), m_Strings{ nullptr }
{
}
+void DatePopup::setStrings(Strings strings)
+{
+ m_Strings = strings;
+}
+
void DatePopup::setResultCallback(ResultCallback callback)
{
m_OnResult = std::move(callback);
}
+Evas_Object *DatePopup::getDatePicker() const
+{
+ return m_DatePicker;
+}
+
void DatePopup::onCreated()
{
- setTitle("IDS_TPLATFORM_HEADER_SET_DATE");
- addButton("IDS_PB_BUTTON_CANCEL");
- addButton("IDS_ST_BUTTON_SET", [this] {
- onSetPressed();
- return true;
- });
+ setTitle(m_Strings.popupTitle);
+ addButton(m_Strings.buttonCancel);
+ addButton(m_Strings.buttonDone, std::bind(&DatePopup::onDonePressed, this));
m_DatePicker = elm_datetime_add(getEvasObject());
- elm_datetime_format_set(m_DatePicker, "%%d %%b %%Y");
+ elm_datetime_format_set(m_DatePicker, m_Format.c_str());
elm_datetime_value_set(m_DatePicker, &m_Date);
setContent(m_DatePicker);
}
-void DatePopup::onSetPressed()
+bool DatePopup::onDonePressed()
{
if (m_OnResult) {
elm_datetime_value_get(m_DatePicker, &m_Date);
m_OnResult(m_Date);
}
+
+ return true;
}
#include "Contacts/Input/ContactDateFieldControl.h"
#include "Contacts/Model/ContactDateField.h"
-#include "Ui/DatePopup.h"
+#include "Ux/DatePopup.h"
#include "Utils/Callback.h"
#include "AppsCommonButtons.h"
void ContactDateFieldControl::onButtonPressed(Evas_Object *button, void *eventInfo)
{
- Ui::DatePopup *popup = new Ui::DatePopup(m_Field.getValue());
+ Ux::DatePopup *popup = new Ux::DatePopup("%%d %%b %%Y", m_Field.getValue());
+ popup->setStrings({
+ "IDS_TPLATFORM_HEADER_SET_DATE",
+ "IDS_ST_BUTTON_SET",
+ "IDS_PB_BUTTON_CANCEL" });
popup->setResultCallback([this](const tm &date) {
m_Field.setValue(date);
update();
#include "App/AppControlRequest.h"
#include "App/Path.h"
-#include "Ui/DatePopup.h"
#include "Ui/Genlist.h"
#include "Ui/Navigator.h"
#include "Ui/Popup.h"
+#include "Ux/DatePopup.h"
#include "Utils/Callback.h"
#include "Utils/Logger.h"
#include "Utils/Range.h"
void InputView::addEventField()
{
time_t now = time(nullptr);
- Ui::DatePopup *popup = new Ui::DatePopup(*localtime(&now));
+ Ux::DatePopup *popup = new Ux::DatePopup("%%d %%b %%Y", *localtime(&now));
+ popup->setStrings({
+ "IDS_TPLATFORM_HEADER_SET_DATE",
+ "IDS_ST_BUTTON_SET",
+ "IDS_PB_BUTTON_CANCEL" });
popup->setResultCallback([this](const tm &date) {
ContactObject &field = addField(FieldEvent);
field.getField<ContactDateField>(0)->setValue(date);