Quickpanel & QuickpanelActivities 01/152001/9
authorPawel Kurowski <p.kurowski2@samsung.com>
Fri, 22 Sep 2017 15:23:41 +0000 (17:23 +0200)
committerPawel Kurowski <p.kurowski2@samsung.com>
Fri, 29 Sep 2017 14:33:01 +0000 (16:33 +0200)
Menu Builder now uses Window, causing tests to fail.
This patch does not resolve quickpanel scanning/capturing switches problem.

Change-Id: Ia878609d17cf0ffc237a84aa59e2f0fbed63ff26

CMakeLists.txt
packaging/org.tizen.universal-switch.spec
res/po/en_US.po
src/MenuBuilder.cpp
src/MenuBuilder.hpp
src/Quickpanel.cpp [new file with mode: 0644]
src/Quickpanel.hpp [new file with mode: 0644]
src/QuickpanelActivity.cpp [new file with mode: 0644]
src/Window.cpp
src/Window.hpp

index 9f5d480..e53683d 100644 (file)
@@ -25,6 +25,7 @@ pkg_check_modules(pkgs REQUIRED
     gobject-2.0
     sqlite3
     tts
+    tzsh-quickpanel
 )
 
 SET(COMMON_FLAGS "-fdiagnostics-color=always -fPIC")
index befad76..46c175c 100644 (file)
@@ -27,6 +27,7 @@ BuildRequires:  pkgconfig(efl-extension)
 BuildRequires:  pkgconfig(capi-ui-efl-util)
 BuildRequires:  pkgconfig(gobject-2.0)
 BuildRequires:  pkgconfig(eldbus)
+BuildRequires:  pkgconfig(tzsh-quickpanel)
 #Required for tests
 BuildRequires:  net-config
 %if %{with docs}
index 36e6e3e..5e6252c 100644 (file)
@@ -394,6 +394,9 @@ msgstr "Back"
 msgid "IDS_ACTIVITY_NAME_MORE_OPTIONS"
 msgstr "More options"
 
+msgid "IDS_ACTIVITY_NAME_OPEN_QUICKPANEL"
+msgstr "Open notifications"
+
 # PROVIDERS
 
 msgid "IDS_SWITCH_PROVIDER_NAME_AccessoriesSwitchProvider"
index 07c481d..4a06242 100644 (file)
@@ -2,20 +2,40 @@
 #include "VConf.hpp"
 #include "VConfKeys.hpp"
 #include "UniversalSwitchLog.hpp"
-
+#include "UniversalSwitch.hpp"
+#include "Singleton.hpp"
+#include "Window.hpp"
+#include "Quickpanel.hpp"
 
 MenuItem::MenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType,
                                   VconfKeyType vconfStateKeysType, std::vector<std::string> vconfStateKeys,
                                   std::string subMenuLabel, std::string showingStateVconfKey)
        : names(std::move(names)), iconPath(std::move(iconPath)), activityType(std::move(activityType)),
          vconfStateKeysType(vconfStateKeysType), vconfStateKeys(std::move(vconfStateKeys)),
-         subMenuLabel(std::move(subMenuLabel)), showingStateVconfKey(std::move(showingStateVconfKey))
+         subMenuLabel(std::move(subMenuLabel)), showingStateVconfKey(std::move(showingStateVconfKey)),
+         quickpanelItem(false)
+{}
+
+MenuItem::MenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType, bool quickpanelItem)
+       : names(std::move(names)), iconPath(std::move(iconPath)), activityType(std::move(activityType)),
+         vconfStateKeysType(VconfKeyType::NONE), quickpanelItem(quickpanelItem)
 {}
 
 std::string MenuItem::getName() const
 {
        if (names.empty())
                return {};
+
+       if (quickpanelItem) {
+               /*
+                * Using window will crash MenuBuilderTests
+                * TODO solve in next patch
+               **/
+               auto window =  Singleton<UniversalSwitch>::instance().getMainWindow();
+               ASSERT(window, "NULL Window");
+               return gettext(names[window->getQuickpanel()->isVisible() ? 1 : 0].c_str());
+       }
+
        if (vconfStateKeys.empty())
                return gettext(names[0].c_str());
 
@@ -103,7 +123,9 @@ MenuMap::MenuMap()
                                                                                VCONF_KEY_SHOW_BACK_MENU_ITEM);
        auto openCloseNotifications     =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_OPEN_NOTI_PANEL", "IDS_CLOSE_NOTI_PANEL"},
-                                                                               defaultImg);//TODO add settings key, when activity will be ready;
+                                                                               defaultImg,
+                                                                               "TOGGLE_QUICKPANEL",
+                                                                               true);
        auto recentApps                         =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_RECENT_APPS"},
                                                                                defaultImg,
index ec528ee..a1fb573 100644 (file)
@@ -19,6 +19,8 @@ public:
                         VconfKeyType vconfStateKeysType = VconfKeyType::NONE, std::vector<std::string> vconfStateKeys = {},
                         std::string subMenuLabel = {}, std::string showingStateVconfKey = {});
 
+       MenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType, bool quickpanelItem);
+
        std::string getName() const;
        std::string getIconPath() const;
        std::string getActivityType() const;
@@ -35,6 +37,7 @@ private:
        std::vector<std::string> vconfStateKeys;
        std::string subMenuLabel;
        std::string showingStateVconfKey;
+       bool quickpanelItem; //TODO remove in next patch
 };
 
 class MenuMap
diff --git a/src/Quickpanel.cpp b/src/Quickpanel.cpp
new file mode 100644 (file)
index 0000000..902ffec
--- /dev/null
@@ -0,0 +1,65 @@
+#include "Quickpanel.hpp"
+#include "UniversalSwitch.hpp"
+#include "UniversalSwitchLog.hpp"
+#include "Window.hpp"
+
+Quickpanel::Quickpanel(Evas_Object *window)
+       : tzsh(nullptr), handle(nullptr)
+{
+       DEBUG("Quickpanel creation");
+       tzsh = tzsh_create(TZSH_TOOLKIT_TYPE_EFL);
+       if (!tzsh) {
+               ERROR("tzsh creation fail");
+               return;
+       }
+
+       auto tzshWin = elm_win_window_id_get(window);
+       if (!tzshWin) {
+               ERROR("tzsh window fail");
+               return;
+       }
+
+       handle = tzsh_quickpanel_create(tzsh, tzshWin);
+       if (!handle) {
+               ERROR("tzsh quickpanel creation fail");
+       }
+}
+
+Quickpanel::~Quickpanel()
+{
+       DEBUG("Quickpanel destruction");
+       if (handle) {
+               tzsh_quickpanel_destroy(handle);
+       }
+
+       if (tzsh) {
+               tzsh_destroy(tzsh);
+       }
+}
+
+bool Quickpanel::isVisible() const
+{
+       DEBUG("Quickpanel get state");
+       tzsh_quickpanel_state_visible_e visible;
+       auto error = tzsh_quickpanel_visible_get(handle, &visible);
+       if (error != TZSH_ERROR_NONE)
+               ERROR("Quickpanel get state error: %d", error);
+
+       return visible == TZSH_QUICKPANEL_STATE_VISIBLE_SHOWN;
+}
+
+void Quickpanel::show() const
+{
+       DEBUG("Quickpanel show request");
+       auto error = tzsh_quickpanel_show(handle);
+       if (error != TZSH_ERROR_NONE)
+               ERROR("Quickpanel show error: %d", error);
+}
+
+void Quickpanel::hide() const
+{
+       DEBUG("Quickpanel hide request");
+       auto error = tzsh_quickpanel_hide(handle);
+       if (error != TZSH_ERROR_NONE)
+               ERROR("Quickpanel hide error: %d", error);
+}
\ No newline at end of file
diff --git a/src/Quickpanel.hpp b/src/Quickpanel.hpp
new file mode 100644 (file)
index 0000000..ab6ae29
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef QUICKPANEL_HPP
+#define QUICKPANEL_HPP
+
+#include "Singleton.hpp"
+
+#include <Elementary.h>
+#include <tzsh.h>
+#include <tzsh_quickpanel.h>
+
+#include <memory>
+
+
+
+class Quickpanel
+{
+public:
+       Quickpanel(Evas_Object *);
+       ~Quickpanel();
+
+       bool isVisible() const;
+       void show() const;
+       void hide() const;
+
+private:
+       tzsh_h tzsh;
+       tzsh_quickpanel_h handle;
+};
+
+#endif
\ No newline at end of file
diff --git a/src/QuickpanelActivity.cpp b/src/QuickpanelActivity.cpp
new file mode 100644 (file)
index 0000000..4dbce6c
--- /dev/null
@@ -0,0 +1,51 @@
+#include "UniversalSwitch.hpp"
+#include "Activity.hpp"
+#include "ActivityFactory.hpp"
+#include "UniversalSwitchLog.hpp"
+#include "Window.hpp"
+
+#include <memory>
+
+namespace
+{
+       static constexpr char openQuickpanelActivityName[] = "OPEN_QUICKPANEL";
+       static constexpr char toggleQuickpanelActivityName[] = "TOGGLE_QUICKPANEL";
+}
+
+template <typename DerivedType, const char *tempActivityType, bool bindable>
+class QuickpanelActivity : public Activity, private RegisterActivity<DerivedType, bindable>
+{
+public:
+       constexpr static const char *activityType = tempActivityType;
+       QuickpanelActivity()
+               : Activity(activityType)
+       {}
+
+       bool process() override
+       {
+               DerivedType::changeQuickpanelState();
+               return true;
+       }
+};
+
+class OpenQuickpanelActivity : public QuickpanelActivity<OpenQuickpanelActivity, openQuickpanelActivityName, true>
+{
+public:
+       static void changeQuickpanelState()
+       {
+               Singleton<UniversalSwitch>::instance().getMainWindow()->getQuickpanel()->show();
+       }
+};
+
+class ToggleQuickpanelActivity : public QuickpanelActivity<ToggleQuickpanelActivity, toggleQuickpanelActivityName, false>
+{
+public:
+       static void changeQuickpanelState()
+       {
+               auto quickpanel = Singleton<UniversalSwitch>::instance().getMainWindow()->getQuickpanel();
+               if (quickpanel->isVisible())
+                       quickpanel->hide();
+               else
+                       quickpanel->show();
+       }
+};
\ No newline at end of file
index a3a5d35..0a6c997 100644 (file)
@@ -25,6 +25,7 @@ Window::Window()
        waylandWindow = elm_win_wl_window_get(windowHandler);
        handler.reset(windowHandler);
        ecore_wl_window_input_region_set(waylandWindow, 0, 0, 0, 0);
+       quickpanel = std::make_unique<Quickpanel>(windowHandler);
 }
 
 Evas_Object *Window::getHandler()
@@ -36,3 +37,8 @@ Rectangle Window::getDimensions() const
 {
        return {{0, 0}, {screenWidth, screenHeight}};
 }
+
+Quickpanel *Window::getQuickpanel() const
+{
+       return quickpanel.get();
+}
index 3b77c37..570cb82 100644 (file)
@@ -2,6 +2,7 @@
 #define WINDOW_HPP
 
 #include "Geometry.hpp"
+#include "Quickpanel.hpp"
 
 #include <Elementary.h>
 #include <ui/efl_util.h>
@@ -16,12 +17,14 @@ public:
 
        Evas_Object *getHandler();
        Rectangle getDimensions() const;
+       Quickpanel *getQuickpanel() const;
 
 private:
        std::unique_ptr<Evas_Object, void(*)(Evas_Object *)> handler;
        Ecore_Wl_Window *waylandWindow;
        int screenWidth;
        int screenHeight;
+       std::unique_ptr<Quickpanel> quickpanel;
 };
 
 #endif