[widget-viewer-dali]
authorHeeyong Song <heeyong.song@samsung.com>
Tue, 26 Apr 2016 09:20:56 +0000 (18:20 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Tue, 26 Apr 2016 09:20:56 +0000 (18:20 +0900)
1. Add a privilege to some APIs
2. Add the preview image and loading text

Change-Id: Ie8b388c2f3a3af463cf98608c9c3df36628a9bcc

CMakeLists.txt
images/unknown.png [new file with mode: 0644]
internal/widget_view/widget_view_impl.cpp
internal/widget_view/widget_view_impl.h
public_api/widget_view/widget_view.cpp
public_api/widget_view/widget_view.h
public_api/widget_view_manager/widget_view_manager.h

index a014ff1..bd84efc 100644 (file)
@@ -38,6 +38,7 @@ SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
 SET(CMAKE_C_FLAGS_RELEASE "-O2")
 
 SET(LOCAL_PUBLIC_HEADER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/public_api)
+SET(IMAGE_DIR "${TZ_SYS_SHARE}/${PROJECT_NAME}/images")
 
 ADD_DEFINITIONS("-DPKGNAME=\"${PROJECT_NAME}\"")
 
@@ -67,4 +68,5 @@ FOREACH(flag ${LOCAL_WIDGE_VIEW_MANAGER_HEADER_LIST})
 ENDFOREACH(flag)
 
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE DESTINATION /usr/share/license RENAME "lib${PROJECT_NAME}")
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/images/unknown.png DESTINATION ${IMAGE_DIR})
 
diff --git a/images/unknown.png b/images/unknown.png
new file mode 100644 (file)
index 0000000..535db60
Binary files /dev/null and b/images/unknown.png differ
index e00e6b9..7f56828 100644 (file)
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <widget_service.h>
 #include <widget_instance.h>
+#include <tzplatform_config.h>
 
 namespace Dali
 {
@@ -38,6 +39,8 @@ namespace Internal
 namespace
 {
 
+#define WIDGET_VIEW_RESOURCE_DEFAULT_IMG "/widget_viewer_dali/images/unknown.png"
+
 #if defined(DEBUG_ENABLED)
 Integration::Log::Filter* gWidgetViewLogging  = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_WIDGET_VIEW" );
 #endif
@@ -70,6 +73,8 @@ WidgetView::WidgetView()
   mHeight( 0 ),
   mPid( 0 ),
   mPeriod( 0.0 ),
+  mPreviewEnabled( true ),
+  mStateTextEnabled( true ),
   mPermanentDelete( true )
 {
 }
@@ -85,6 +90,8 @@ WidgetView::WidgetView( const std::string& widgetId, const std::string& contentI
   mHeight( height ),
   mPid( 0 ),
   mPeriod( period ),
+  mPreviewEnabled( true ),
+  mStateTextEnabled( true ),
   mPermanentDelete( true )
 {
 }
@@ -117,13 +124,64 @@ const std::string& WidgetView::GetInstanceId() const
   return mInstanceId;
 }
 
-const std::string& WidgetView::GetContentInfo() const
+const std::string& WidgetView::GetContentInfo()
 {
+  widget_instance_h instance;
+  bundle* bundle = NULL;
+  bundle_raw* contentInfo = NULL;
+  int contentLength = 0;
+
+  mContentInfo.clear();
+
+  if( mWidgetId.empty() || mInstanceId.empty() )
+  {
+    DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Widget id (%s) or instance id (%s) is invalid.\n", mWidgetId.c_str(), mInstanceId.c_str() );
+    return mContentInfo;
+  }
+
+  instance = widget_instance_get_instance( mWidgetId.c_str(), mInstanceId.c_str() );
+  if( !instance )
+  {
+    DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: widget_instance_get_instance is failed. [%s]\n", mInstanceId.c_str() );
+    return mContentInfo;
+  }
+
+  if( widget_instance_get_content( instance, &bundle ) < 0 )
+  {
+    DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Failed to get content of widget. [%s]\n", mInstanceId.c_str() );
+    return mContentInfo;
+  }
+
+  if( !bundle )
+  {
+    DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Cotent of widget [%s] is invalid.\n", mInstanceId.c_str() );
+    return mContentInfo;
+  }
+
+  if( bundle_encode( bundle, &contentInfo, &contentLength ) < 0 )
+  {
+    DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: bundle_encode is failed. [%s]\n", mInstanceId.c_str() );
+    return mContentInfo;
+  }
+
+  mContentInfo = reinterpret_cast< char* >( contentInfo );
+
   return mContentInfo;
 }
 
-const std::string& WidgetView::GetTitle() const
+const std::string& WidgetView::GetTitle()
 {
+  if( mObjectView )
+  {
+    mTitle = mObjectView.GetTitle();
+    if( mTitle.empty() )
+    {
+      mTitle = widget_service_get_name( mWidgetId.c_str(), NULL );
+    }
+  }
+
+  DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetTitle: title = %s\n", mTitle.c_str() );
+
   return mTitle;
 }
 
@@ -132,10 +190,51 @@ double WidgetView::GetPeriod() const
   return mPeriod;
 }
 
+void WidgetView::SetPreviewEnabled( bool enabled )
+{
+  mPreviewEnabled = enabled;
+
+  if( mPreviewImage )
+  {
+    mPreviewImage.SetVisible( enabled );
+  }
+}
+
+bool WidgetView::GetPreviewEnabled() const
+{
+  return mPreviewEnabled;
+}
+
+void WidgetView::SetStateTextEnabled( bool enabled )
+{
+  mStateTextEnabled = enabled;
+
+  if( mStateText )
+  {
+    mStateText.SetVisible( enabled );
+  }
+}
+
+bool WidgetView::GetStateTextEnabled() const
+{
+  return mStateTextEnabled;
+}
+
 void WidgetView::ActivateFaultedWidget()
 {
   if( mPid < 0 )
   {
+    // Esable preview and text
+    if( mPreviewEnabled )
+    {
+      mPreviewImage.SetVisible( true );
+    }
+
+    if( mStateTextEnabled )
+    {
+      mStateText.SetVisible( true );
+    }
+
     // launch widget again
     mPid = widget_instance_launch( mWidgetId.c_str(), mInstanceId.c_str(), mBundle, mWidth, mHeight );
     if( mPid < 0)
@@ -166,9 +265,17 @@ void WidgetView::AddObjectView( Pepper::ObjectView objectView )
   mObjectView.SetAnchorPoint( AnchorPoint::CENTER );
 
   Self().Add( mObjectView );
-  Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
 
-  mTitle = mObjectView.GetTitle();
+  // Disable preview and text
+  if( mPreviewEnabled )
+  {
+    mPreviewImage.SetVisible( false );
+  }
+
+  if( mStateTextEnabled )
+  {
+    mStateText.SetVisible( false );
+  }
 
   // Emit signal
   Dali::WidgetView::WidgetView handle( GetOwner() );
@@ -197,6 +304,9 @@ Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetDeletedSig
 void WidgetView::OnInitialize()
 {
   char* instanceId = NULL;
+  char* previewPath = NULL;
+  std::string previewImage;
+  widget_size_type_e sizeType;
 
   if( !mContentInfo.empty() )
   {
@@ -227,6 +337,47 @@ void WidgetView::OnInitialize()
 
   mInstanceId = instanceId;
 
+  // Preview image
+  widget_service_get_size_type( mWidth, mHeight, &sizeType );
+
+  previewPath = widget_service_get_preview_image_path( mWidgetId.c_str(), sizeType );
+  if( previewPath )
+  {
+    previewImage = previewPath;
+    free( previewPath );
+  }
+  else
+  {
+    previewImage = tzplatform_getenv( TZ_SYS_SHARE );
+    previewImage.append( WIDGET_VIEW_RESOURCE_DEFAULT_IMG );
+  }
+
+  DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: preview image path = %s\n", previewImage.c_str() );
+
+  mPreviewImage = Toolkit::ImageView::New( previewImage );
+
+  mPreviewImage.SetParentOrigin( ParentOrigin::CENTER );
+  mPreviewImage.SetAnchorPoint( AnchorPoint::CENTER );
+
+  if( !previewPath )
+  {
+    mPreviewImage.SetSize( mWidth, mHeight );
+  }
+
+  Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
+  Self().Add( mPreviewImage );
+
+  // State text
+  // TODO: use po files
+  mStateText = Toolkit::TextLabel::New( "Loading..." );
+
+  mStateText.SetParentOrigin( ParentOrigin::CENTER );
+  mStateText.SetAnchorPoint( AnchorPoint::CENTER );
+  mStateText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
+  mStateText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
+
+  mPreviewImage.Add( mStateText );
+
   // launch widget
   mPid = widget_instance_launch( mWidgetId.c_str(), instanceId, mBundle, mWidth, mHeight );
   if( mPid < 0)
index 3e33b9b..d490e07 100644 (file)
@@ -23,6 +23,8 @@
 
 // EXTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/control-impl.h>
+#include <dali-toolkit/public-api/controls/image-view/image-view.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
 #include <pepper-dali/public-api/object-view/object-view.h>
 #include <bundle.h>
 
@@ -57,12 +59,12 @@ public:
   /**
    * @copydoc Dali::WidgetView::WidgetView::GetContentInfo
    */
-  const std::string& GetContentInfo() const;
+  const std::string& GetContentInfo();
 
   /**
    * @copydoc Dali::WidgetView::WidgetView::GetTitle
    */
-  const std::string& GetTitle() const;
+  const std::string& GetTitle();
 
   /**
    * @copydoc Dali::WidgetView::WidgetView::GetPeriod
@@ -70,6 +72,26 @@ public:
   double GetPeriod() const;
 
   /**
+   * @copydoc Dali::WidgetView::WidgetView::SetPreviewEnabled
+   */
+  void SetPreviewEnabled( bool enabled );
+
+  /**
+   * @copydoc Dali::WidgetView::WidgetView::GetPreviewEnabled
+   */
+  bool GetPreviewEnabled() const;
+
+  /**
+   * @copydoc Dali::WidgetView::WidgetView::SetStateTextEnabled
+   */
+  void SetStateTextEnabled( bool enabled );
+
+  /**
+   * @copydoc Dali::WidgetView::WidgetView::GetStateTextEnabled
+   */
+  bool GetStateTextEnabled() const;
+
+  /**
    * @copydoc Dali::WidgetView::WidgetView::ActivateFaultedWidget
    */
   void ActivateFaultedWidget();
@@ -126,7 +148,9 @@ private:
 
 private:
 
-  Pepper::ObjectView mObjectView;
+  Pepper::ObjectView mObjectView;     ///< Widget content
+  Toolkit::ImageView mPreviewImage;   ///< Preview image
+  Toolkit::TextLabel mStateText;      ///< State text
 
   std::string mWidgetId;
   std::string mInstanceId;
@@ -140,6 +164,8 @@ private:
   int mPid;
   double mPeriod;
 
+  bool mPreviewEnabled;
+  bool mStateTextEnabled;
   bool mPermanentDelete;
 
   // Signals
index b52ee3f..8e992b8 100644 (file)
@@ -69,12 +69,12 @@ const std::string& WidgetView::GetInstanceId() const
   return Dali::WidgetView::GetImplementation( *this ).GetInstanceId();
 }
 
-const std::string& WidgetView::GetContentInfo() const
+const std::string& WidgetView::GetContentInfo()
 {
   return Dali::WidgetView::GetImplementation( *this ).GetContentInfo();
 }
 
-const std::string& WidgetView::GetTitle() const
+const std::string& WidgetView::GetTitle()
 {
   return Dali::WidgetView::GetImplementation( *this ).GetTitle();
 }
@@ -84,6 +84,26 @@ double WidgetView::GetPeriod() const
   return Dali::WidgetView::GetImplementation( *this ).GetPeriod();
 }
 
+void WidgetView::SetPreviewEnabled( bool enabled )
+{
+  Dali::WidgetView::GetImplementation( *this ).SetPreviewEnabled( enabled );
+}
+
+bool WidgetView::GetPreviewEnabled() const
+{
+  return Dali::WidgetView::GetImplementation( *this ).GetPreviewEnabled();
+}
+
+void WidgetView::SetStateTextEnabled( bool enabled )
+{
+  Dali::WidgetView::GetImplementation( *this ).SetStateTextEnabled( enabled );
+}
+
+bool WidgetView::GetStateTextEnabled() const
+{
+  return Dali::WidgetView::GetImplementation( *this ).GetStateTextEnabled();
+}
+
 void WidgetView::ActivateFaultedWidget()
 {
   return Dali::WidgetView::GetImplementation( *this ).ActivateFaultedWidget();
index 4583173..5a201a0 100644 (file)
@@ -51,6 +51,8 @@ public:
    * @brief Create widget view.
    *
    * @since_tizen 3.0
+   * @privlevel public
+   * @privilege %http://tizen.org/privilege/widget.viewer
    * @param[in] widgetId The widget id.
    * @param[in] contentInfo Contents that will be given to the widget instance.
    * @param[in] width The widget width.
@@ -107,6 +109,8 @@ public:
    * @brief Get the id of the widget.
    *
    * @since_tizen 3.0
+   * @privlevel public
+   * @privilege %http://tizen.org/privilege/widget.viewer
    * @return The widget id on success, otherwise an empty string.
    */
   const std::string& GetWidgetId() const;
@@ -115,6 +119,8 @@ public:
    * @brief Get the instance id of the widget.
    *
    * @since_tizen 3.0
+   * @privlevel public
+   * @privilege %http://tizen.org/privilege/widget.viewer
    * @return The instance id on success, otherwise an empty string.
    */
   const std::string& GetInstanceId() const;
@@ -124,28 +130,74 @@ public:
    * This string can be used for creating contents of widget again after reboot a device or recovered from crash(abnormal status).
    *
    * @since_tizen 3.0
+   * @privlevel public
+   * @privilege %http://tizen.org/privilege/widget.viewer
    * @return The content string to be recognize content of the widget or an empty string if there is no specific content string.
    */
-  const std::string& GetContentInfo() const;
+  const std::string& GetContentInfo();
 
   /**
    * @brief Get the summarized string of the widget content for accessibility.
    * If the accessibility feature is turned on, a viewer can use this text to describe the widget.
    *
    * @since_tizen 3.0
+   * @privlevel public
+   * @privilege %http://tizen.org/privilege/widget.viewer
    * @return The title string to be used for summarizing the widget or an empty string if there is no summarized text for content of given widget.
    */
-  const std::string& GetTitle() const;
+  const std::string& GetTitle();
 
   /**
    * @brief Get the update period of the widget.
    *
    * @since_tizen 3.0
+   * @privlevel public
+   * @privilege %http://tizen.org/privilege/widget.viewer
    * @return The update period of the widget.
    */
   double GetPeriod() const;
 
   /**
+   * @brief Sets whether to enable or disable the preview of the widget
+   *
+   * @since_tizen 3.0
+   * @privlevel public
+   * @privilege %http://tizen.org/privilege/widget.viewer
+   * @param[in] enable Whether to enable the preview of the widget or not
+   */
+  void SetPreviewEnabled( bool enabled );
+
+  /**
+   * @brief Checks if the preview of the widget has been enabled or not.
+   *
+   * @since_tizen 3.0
+   * @privlevel public
+   * @privilege %http://tizen.org/privilege/widget.viewer
+   * @return Whether the preview of the widget is enabled
+   */
+  bool GetPreviewEnabled() const;
+
+  /**
+   * @brief Sets whether to enable or disable the state message of the widget
+   *
+   * @since_tizen 3.0
+   * @privlevel public
+   * @privilege %http://tizen.org/privilege/widget.viewer
+   * @param[in] enable Whether to enable the state message of the widget or not
+   */
+  void SetStateTextEnabled( bool enabled );
+
+  /**
+   * @brief Checks if the state message of the widget has been enabled or not.
+   *
+   * @since_tizen 3.0
+   * @privlevel public
+   * @privilege %http://tizen.org/privilege/widget.viewer
+   * @return Whether the state message of the widget is enabled
+   */
+  bool GetStateTextEnabled() const;
+
+  /**
    * @brief Activate a widget in faulted state.
    * A widget in faulted state MUST be activated before adding the widget.
    *
@@ -159,6 +211,8 @@ public:
    * @brief Check whether the widget is faulted.
    *
    * @since_tizen 3.0
+   * @privlevel public
+   * @privilege %http://tizen.org/privilege/widget.viewer
    * @return true for faulted state, otherwise false.
    */
   bool IsWidgetFaulted();
@@ -167,6 +221,8 @@ public:
    * @brief Set the deletion mode.
    *
    * @since_tizen 3.0
+   * @privlevel public
+   * @privilege %http://tizen.org/privilege/widget.viewer
    * @param[in] permanentDelete Pass true if you want to delete this widget instance permanently, or pass false if you want to keep it and it will be re-created soon.
    */
   void SetPermanentDelete( bool permanentDelete );
index 9157863..c2ccd51 100644 (file)
@@ -56,6 +56,8 @@ public:
    * @brief Create widget view manager.
    *
    * @since_tizen 3.0
+   * @privlevel public
+   * @privilege %http://tizen.org/privilege/widget.viewer
    * @param[in] application Application class for the widget view manager.
    * @param[in] name Widget view manager name. It is used for socket name internally.
    * @return A handle to WidgetViewManager.
@@ -111,6 +113,8 @@ public:
    * @brief Creates a new widget view object
    *
    * @since_tizen 3.0
+   * @privlevel public
+   * @privilege %http://tizen.org/privilege/widget.viewer
    * @param[in] widgetId The widget id.
    * @param[in] contentInfo Contents that will be given to the widget instance.
    * @param[in] width The widget width.