Fixed minor issues in Phone dialer. 19/52419/2
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Tue, 17 Nov 2015 14:16:00 +0000 (16:16 +0200)
committerEugene Kurzberg <i.kurtsberg@samsung.com>
Mon, 23 Nov 2015 09:43:10 +0000 (11:43 +0200)
Change-Id: I32d9feddf8cc0d0ea620f79d4322962647569b24
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
lib-phone/inc/Phone/Dialer/MainView.h
lib-phone/inc/Phone/Dialer/SearchResultsControl.h [moved from lib-phone/inc/Phone/Dialer/SearchResultsWidget.h with 90% similarity]
lib-phone/inc/Phone/Utils.h
lib-phone/src/Phone/Dialer/MainView.cpp
lib-phone/src/Phone/Dialer/SearchResultsControl.cpp [moved from lib-phone/src/Phone/Dialer/SearchResultsWidget.cpp with 81% similarity]
lib-phone/src/Phone/Dialer/SpeedDialPopup.cpp
lib-phone/src/Phone/Utils.cpp

index 1705fad..8e9a391 100644 (file)
@@ -33,7 +33,7 @@ namespace Phone
        namespace Dialer
        {
                class KeypadEntry;
-               class SearchResultsWidget;
+               class SearchResultsControl;
 
                /**
                 * @brief Dialer main view.
@@ -77,14 +77,12 @@ namespace Phone
 
                        static void launchCall(const std::string &number);
                        void launchSpeedDial(int digit);
-                       static std::string getSpeedDialNumber(int digit);
-                       static std::string getLastNumber();
 
                        App::AppControl m_AppControl;
                        SearchEngine m_SearchEngine;
 
                        KeypadEntry *m_Entry;
-                       SearchResultsWidget *m_SearchWidget;
+                       SearchResultsControl *m_SearchWidget;
                };
        }
 }
@@ -15,8 +15,8 @@
  *
  */
 
-#ifndef PHONE_DIALER_SEARCH_RESULTS_WIDGET_H
-#define PHONE_DIALER_SEARCH_RESULTS_WIDGET_H
+#ifndef PHONE_DIALER_SEARCH_RESULTS_CONTROL_H
+#define PHONE_DIALER_SEARCH_RESULTS_CONTROL_H
 
 #include "Ui/Control.h"
 #include "Phone/Dialer/SearchTypes.h"
@@ -28,7 +28,7 @@ namespace Phone
                /**
                 * @brief Predictive search result widget.
                 */
-               class SearchResultsWidget : public Ui::Control
+               class SearchResultsControl : public Ui::Control
                {
                public:
                        /**
@@ -37,7 +37,7 @@ namespace Phone
                         */
                        typedef std::function<void(SearchResultPtr)> SelectedCallback;
 
-                       SearchResultsWidget();
+                       SearchResultsControl();
 
                        /**
                         * @brief Set search results to be displayed
@@ -88,4 +88,4 @@ namespace Phone
        }
 }
 
-#endif /* PHONE_DIALER_SEARCH_RESULTS_WIDGET_H */
+#endif /* PHONE_DIALER_SEARCH_RESULTS_CONTROL_H */
index 5b86e79..658e3d8 100644 (file)
 #ifndef PHONE_UTILS_H
 #define PHONE_UTILS_H
 
+#include <string>
+
 namespace Phone
 {
        /**
+        * @brief Get phone number assigned to specific speed dial number.
+        * @param[in]   speedNumber Number on the dialer
+        * @return Speed dial number or empty string if not assigned.
+        */
+       std::string getSpeedDialNumber(int speedNumber);
+
+       /**
         * @brief Add speed dial number.
         * @param[in]   speedNumber Number on the dialer
         * @param[in]   numberId    ID of number to assign to @a speedNumber
         * @return true on success, false if number with this @a numberId already exists.
         */
        bool addSpeedDialNumber(int speedNumber, int numberId);
+
+       /**
+        * @return Last incoming or outgoing call number.
+        */
+       std::string getLastCallNumber();
 }
 
 #endif /* PHONE_UTILS_H */
index b4ed255..e87eeaa 100644 (file)
 #include "Phone/Dialer/AddNumberPopup.h"
 #include "Phone/Dialer/KeypadButton.h"
 #include "Phone/Dialer/KeypadEntry.h"
-#include "Phone/Dialer/SearchResultsWidget.h"
+#include "Phone/Dialer/SearchResultsControl.h"
 #include "Phone/Dialer/SpeedDialPopup.h"
 #include "Phone/SpeedDial/SettingsView.h"
+#include "Phone/Utils.h"
 
 #include "App/AppControlRequest.h"
 #include "App/Path.h"
@@ -147,7 +148,7 @@ Evas_Object *MainView::createEntry(Evas_Object *parent)
 
 Evas_Object *MainView::createSearchWidget(Evas_Object *parent)
 {
-       m_SearchWidget = new SearchResultsWidget();
+       m_SearchWidget = new SearchResultsControl();
        m_SearchWidget->setSelectedCallback(std::bind(&MainView::onResultSelected, this, _1));
        return m_SearchWidget->create(parent);
 }
@@ -157,9 +158,9 @@ Evas_Object *MainView::createKeypad(Evas_Object *parent)
        Evas_Object *table = elm_table_add(parent);
        elm_table_padding_set(table, 2, 2);
 
-       int id = 0;
-       for(int i = 0; i < KEYPAD_ROWS; ++i) {
-               for(int j = 0; j < KEYPAD_COLS; ++j, ++id) {
+       int id = KeypadButton::ID_1;
+       for (int i = 0; i < KEYPAD_ROWS; ++i) {
+               for (int j = 0; j < KEYPAD_COLS; ++j, ++id) {
                        KeypadButton *key = new KeypadButton((KeypadButton::Id) id);
                        key->setPressedCallback(std::bind(&MainView::onKeyPressed, this, _1));
                        key->setLongpressedCallback(std::bind(&MainView::onKeyLongpressed, this, _1));
@@ -279,7 +280,7 @@ void MainView::onCallPressed(Evas_Object *obj, void *event_info)
                launchCall(number);
                m_Entry->clear();
        } else {
-               m_Entry->setNumber(getLastNumber());
+               m_Entry->setNumber(Phone::getLastCallNumber());
        }
 }
 
@@ -299,7 +300,7 @@ void MainView::launchCall(const std::string &number)
 
 void MainView::launchSpeedDial(int digit)
 {
-       std::string number = getSpeedDialNumber(digit);
+       std::string number = Phone::getSpeedDialNumber(digit);
        if (!number.empty()) {
                launchCall(number);
        } else {
@@ -307,78 +308,3 @@ void MainView::launchSpeedDial(int digit)
                popup->create(getEvasObject());
        }
 }
-
-std::string MainView::getSpeedDialNumber(int digit)
-{
-       std::string number;
-       contacts_filter_h filter = NULL;
-       contacts_query_h query = NULL;
-       contacts_list_h list = NULL;
-
-       contacts_filter_create(_contacts_speeddial._uri, &filter);
-       contacts_filter_add_int(filter, _contacts_speeddial.speeddial_number, CONTACTS_MATCH_EQUAL, digit);
-
-       contacts_query_create(_contacts_speeddial._uri, &query);
-       contacts_query_set_filter(query, filter);
-
-       int err = contacts_db_get_records_with_query(query, 0, 1, &list);
-       WARN_IF(err != CONTACTS_ERROR_NONE, "contacts_db_get_records_with_query() failed(0x%x)", err);
-       if (list) {
-               contacts_record_h record = NULL;
-               contacts_list_get_current_record_p(list, &record);
-               if (record) {
-                       char *str = NULL;
-                       contacts_record_get_str_p(record, _contacts_speeddial.number, &str);
-                       if (str) {
-                               number = str;
-                       }
-               }
-
-               contacts_list_destroy(list, true);
-       }
-
-       contacts_query_destroy(query);
-       contacts_filter_destroy(filter);
-
-       return number;
-}
-
-std::string MainView::getLastNumber()
-{
-       std::string number;
-       contacts_list_h list = NULL;
-       contacts_query_h query = NULL;
-       contacts_filter_h filter = NULL;
-
-       contacts_filter_create(_contacts_person_phone_log._uri, &filter);
-       contacts_filter_add_int(filter, _contacts_person_phone_log.log_type,
-                       CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING);
-       contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND);
-       contacts_filter_add_int(filter, _contacts_person_phone_log.log_type,
-                       CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
-
-       contacts_query_create(_contacts_person_phone_log._uri, &query);
-       contacts_query_set_filter(query, filter);
-       contacts_query_set_sort(query, _contacts_person_phone_log.log_time, false);
-
-       int err = contacts_db_get_records_with_query(query, 0, 1, &list);
-       WARN_IF(err != CONTACTS_ERROR_NONE, "contacts_db_get_records_with_query() failed(0x%x)", err);
-       if (list) {
-               contacts_record_h record = NULL;
-               contacts_list_get_current_record_p(list, &record);
-               if (record) {
-                       char *str = NULL;
-                       contacts_record_get_str_p(record, _contacts_person_phone_log.address, &str);
-                       if (str) {
-                               number = str;
-                       }
-               }
-
-               contacts_list_destroy(list, true);
-       }
-
-       contacts_query_destroy(query);
-       contacts_filter_destroy(filter);
-
-       return number;
-}
@@ -15,7 +15,7 @@
  *
  */
 
-#include "Phone/Dialer/SearchResultsWidget.h"
+#include "Phone/Dialer/SearchResultsControl.h"
 #include "Phone/Dialer/SearchResultsPopup.h"
 #include "Phone/Dialer/SearchUtils.h"
 
@@ -32,13 +32,13 @@ namespace
        const std::string layoutFilePath = App::getResourcePath(DIALER_PREDICTIVE_EDJ);
 }
 
-SearchResultsWidget::SearchResultsWidget()
+SearchResultsControl::SearchResultsControl()
        : m_Results(nullptr), m_State(ResultsNone),
          m_ResultsCount(nullptr)
 {
 }
 
-void SearchResultsWidget::setResults(const SearchResults *results)
+void SearchResultsControl::setResults(const SearchResults *results)
 {
        m_Results = results;
        if (!m_Results || m_Results->empty()) {
@@ -49,33 +49,33 @@ void SearchResultsWidget::setResults(const SearchResults *results)
        }
 }
 
-void SearchResultsWidget::clearResults()
+void SearchResultsControl::clearResults()
 {
        setLayout(nullptr);
        m_State = ResultsNone;
        m_Results = nullptr;
 }
 
-void SearchResultsWidget::setSelectedCallback(SelectedCallback callback)
+void SearchResultsControl::setSelectedCallback(SelectedCallback callback)
 {
        m_OnSelected = std::move(callback);
 }
 
-Evas_Object *SearchResultsWidget::onCreate(Evas_Object *parent)
+Evas_Object *SearchResultsControl::onCreate(Evas_Object *parent)
 {
        Evas_Object *layout = elm_layout_add(parent);
        evas_object_event_callback_add(layout, EVAS_CALLBACK_MOUSE_DOWN,
-                       (Evas_Object_Event_Cb) makeCallback(&SearchResultsWidget::onResultPressed), this);
+                       (Evas_Object_Event_Cb) makeCallback(&SearchResultsControl::onResultPressed), this);
        return layout;
 }
 
-void SearchResultsWidget::setLayout(const char *groupName)
+void SearchResultsControl::setLayout(const char *groupName)
 {
        clearLayout();
        elm_layout_file_set(getEvasObject(), layoutFilePath.c_str(), groupName);
 }
 
-void SearchResultsWidget::clearLayout()
+void SearchResultsControl::clearLayout()
 {
        Eina_List *list = elm_layout_content_swallow_list_get(getEvasObject());
        Eina_List *node = nullptr;
@@ -87,7 +87,7 @@ void SearchResultsWidget::clearLayout()
        eina_list_free(list);
 }
 
-void SearchResultsWidget::setResultsEmpty()
+void SearchResultsControl::setResultsEmpty()
 {
        if (m_State != ResultsEmpty) {
                m_State = ResultsEmpty;
@@ -96,7 +96,7 @@ void SearchResultsWidget::setResultsEmpty()
        }
 }
 
-void SearchResultsWidget::setResultsPresent()
+void SearchResultsControl::setResultsPresent()
 {
        if (m_State != ResultsPresent && m_State != ResultsMany) {
                m_State = ResultsPresent;
@@ -106,7 +106,7 @@ void SearchResultsWidget::setResultsPresent()
        setResultInfo(m_Results->front());
 }
 
-void SearchResultsWidget::setResultsCount(size_t count)
+void SearchResultsControl::setResultsCount(size_t count)
 {
        if (count > 1) {
                if (m_State != ResultsMany) {
@@ -116,7 +116,7 @@ void SearchResultsWidget::setResultsCount(size_t count)
                        elm_layout_file_set(m_ResultsCount, layoutFilePath.c_str(), GROUP_PREDICTIVE_RES_COUNT);
                        evas_object_propagate_events_set(m_ResultsCount, EINA_FALSE);
                        evas_object_event_callback_add(m_ResultsCount, EVAS_CALLBACK_MOUSE_DOWN,
-                                       (Evas_Object_Event_Cb) makeCallback(&SearchResultsWidget::onShowResultsPressed), this);
+                                       (Evas_Object_Event_Cb) makeCallback(&SearchResultsControl::onShowResultsPressed), this);
                }
 
                elm_object_part_text_set(m_ResultsCount, PART_TEXT_COUNT,
@@ -129,7 +129,7 @@ void SearchResultsWidget::setResultsCount(size_t count)
        elm_object_part_content_set(getEvasObject(), PART_SWALLOW_RESULTS, m_ResultsCount);
 }
 
-void SearchResultsWidget::setResultInfo(SearchResultPtr result)
+void SearchResultsControl::setResultInfo(SearchResultPtr result)
 {
        Evas_Object *layout = getEvasObject();
        elm_object_part_content_set(layout, PART_SWALLOW_THUMBNAIL,
@@ -153,7 +153,7 @@ void SearchResultsWidget::setResultInfo(SearchResultPtr result)
        }
 }
 
-void SearchResultsWidget::setResultSpeedDial(SearchResultPtr result)
+void SearchResultsControl::setResultSpeedDial(SearchResultPtr result)
 {
        Evas_Object *speeddialLayout = elm_layout_add(getEvasObject());
        elm_layout_file_set(speeddialLayout, layoutFilePath.c_str(), GROUP_SPEEDDIAL_NUMBER);
@@ -161,9 +161,8 @@ void SearchResultsWidget::setResultSpeedDial(SearchResultPtr result)
        elm_object_part_content_set(getEvasObject(), PART_SWALLOW_SPEEDDIAL, speeddialLayout);
 }
 
-void SearchResultsWidget::onResultPressed()
+void SearchResultsControl::onResultPressed()
 {
-       TRACE;
        if (m_OnSelected) {
                if (m_Results && !m_Results->empty()) {
                        m_OnSelected(m_Results->front());
@@ -173,9 +172,8 @@ void SearchResultsWidget::onResultPressed()
        }
 }
 
-void SearchResultsWidget::onShowResultsPressed()
+void SearchResultsControl::onShowResultsPressed()
 {
-       TRACE;
        SearchResultsPopup *popup = new SearchResultsPopup(m_Results);
        popup->setSelectedCallback(m_OnSelected);
        popup->create(getEvasObject());
index 1f61210..0fe7ca5 100644 (file)
@@ -57,7 +57,7 @@ void SpeedDialPopup::onPickResult(app_control_h request, app_control_h reply,
 {
        SpeedDialPopup *popup = (SpeedDialPopup*) data;
 
-       char **numberIds = 0;
+       char **numberIds = nullptr;
        int count = 0;
 
        int err = app_control_get_extra_data_array(reply, APP_CONTROL_DATA_SELECTED, &numberIds, &count);
index 6c9329f..16a2266 100644 (file)
 
 #include <contacts.h>
 
+std::string Phone::getSpeedDialNumber(int speedNumber)
+{
+       std::string number;
+       contacts_filter_h filter = NULL;
+       contacts_query_h query = NULL;
+       contacts_list_h list = NULL;
+
+       contacts_filter_create(_contacts_speeddial._uri, &filter);
+       contacts_filter_add_int(filter, _contacts_speeddial.speeddial_number, CONTACTS_MATCH_EQUAL, speedNumber);
+
+       contacts_query_create(_contacts_speeddial._uri, &query);
+       contacts_query_set_filter(query, filter);
+
+       int err = contacts_db_get_records_with_query(query, 0, 1, &list);
+       WARN_IF(err != CONTACTS_ERROR_NONE, "contacts_db_get_records_with_query() failed(0x%x)", err);
+       if (list) {
+               contacts_record_h record = NULL;
+               contacts_list_get_current_record_p(list, &record);
+               if (record) {
+                       char *str = NULL;
+                       contacts_record_get_str_p(record, _contacts_speeddial.number, &str);
+                       if (str) {
+                               number = str;
+                       }
+               }
+
+               contacts_list_destroy(list, true);
+       }
+
+       contacts_query_destroy(query);
+       contacts_filter_destroy(filter);
+
+       return number;
+}
+
 bool Phone::addSpeedDialNumber(int speedNumber, int numberId)
 {
        contacts_filter_h filter = nullptr;
@@ -53,3 +88,43 @@ bool Phone::addSpeedDialNumber(int speedNumber, int numberId)
 
        return true;
 }
+
+std::string Phone::getLastCallNumber()
+{
+       std::string number;
+       contacts_list_h list = NULL;
+       contacts_query_h query = NULL;
+       contacts_filter_h filter = NULL;
+
+       contacts_filter_create(_contacts_person_phone_log._uri, &filter);
+       contacts_filter_add_int(filter, _contacts_person_phone_log.log_type,
+                       CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING);
+       contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND);
+       contacts_filter_add_int(filter, _contacts_person_phone_log.log_type,
+                       CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
+
+       contacts_query_create(_contacts_person_phone_log._uri, &query);
+       contacts_query_set_filter(query, filter);
+       contacts_query_set_sort(query, _contacts_person_phone_log.log_time, false);
+
+       int err = contacts_db_get_records_with_query(query, 0, 1, &list);
+       WARN_IF(err != CONTACTS_ERROR_NONE, "contacts_db_get_records_with_query() failed(0x%x)", err);
+       if (list) {
+               contacts_record_h record = NULL;
+               contacts_list_get_current_record_p(list, &record);
+               if (record) {
+                       char *str = NULL;
+                       contacts_record_get_str_p(record, _contacts_person_phone_log.address, &str);
+                       if (str) {
+                               number = str;
+                       }
+               }
+
+               contacts_list_destroy(list, true);
+       }
+
+       contacts_query_destroy(query);
+       contacts_filter_destroy(filter);
+
+       return number;
+}