Merge "[3.0] Tizen Directory Migration" into tizen
[platform/core/uifw/dali-adaptor.git] / adaptors / ecore / wayland / clipboard-impl-ecore-wl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include "clipboard-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <Ecore.h>
23 #include <Ecore_Wayland.h>
24 #include <dali/public-api/object/any.h>
25 #include <dali/public-api/object/type-registry.h>
26 #include <dali/integration-api/debug.h>
27 #include <bundle.h>
28
29 // INTERNAL INCLUDES
30 #include <singleton-service-impl.h>
31
32 #define CLIPBOARD_STR  "CLIPBOARD_STR"
33
34 ///////////////////////////////////////////////////////////////////////////////////////////////////
35 // Clipboard
36 ///////////////////////////////////////////////////////////////////////////////////////////////////
37
38 namespace Dali
39 {
40
41 namespace Internal
42 {
43
44 namespace Adaptor
45 {
46
47 struct Clipboard::Impl
48 {
49   Impl()
50   {
51     mBundle = bundle_create();
52   }
53
54   void SetItem(const char *data)
55   {
56     char *temp = NULL;
57
58     if (bundle_get_str(mBundle, CLIPBOARD_STR, &temp) == BUNDLE_ERROR_NONE)
59     {
60       bundle_del(mBundle, CLIPBOARD_STR);
61     }
62     bundle_add_str(mBundle, CLIPBOARD_STR, data);
63   }
64
65   char *GetItem()
66   {
67     char *data = NULL;
68
69     if ( bundle_get_count(mBundle) )
70     {
71       bundle_get_str(mBundle, CLIPBOARD_STR, &data);
72     }
73     return data;
74   }
75
76   int GetCount()
77   {
78     return bundle_get_count(mBundle);
79   }
80
81   bundle *mBundle;
82 };
83
84 Clipboard::Clipboard(Impl* impl)
85 : mImpl(impl)
86 {
87 }
88
89 Clipboard::~Clipboard()
90 {
91 }
92
93 Dali::Clipboard Clipboard::Get()
94 {
95   Dali::Clipboard clipboard;
96
97   Dali::SingletonService service( SingletonService::Get() );
98   if ( service )
99   {
100     // Check whether the singleton is already created
101     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::Clipboard ) );
102     if(handle)
103     {
104       // If so, downcast the handle
105       clipboard = Dali::Clipboard( dynamic_cast< Clipboard* >( handle.GetObjectPtr() ) );
106     }
107     else
108     {
109       Clipboard::Impl* impl( new Clipboard::Impl() );
110       clipboard = Dali::Clipboard( new Clipboard(impl) );
111       service.Register( typeid(Dali::Clipboard), clipboard );
112     }
113   }
114
115   return clipboard;
116 }
117
118 bool Clipboard::SetItem(const std::string &itemData )
119 {
120   mImpl->SetItem( const_cast<char*>( itemData.c_str()) );
121   return true;
122 }
123
124 /*
125  * Get string at given index of clipboard
126  */
127 std::string Clipboard::GetItem( unsigned int index )  // change string to a Dali::Text object.
128 {
129   std::string clipboardString(mImpl->GetItem());
130   return clipboardString;
131 }
132
133 /*
134  * Get number of items in clipboard
135  */
136 unsigned int Clipboard::NumberOfItems()
137 {
138   return mImpl->GetCount();
139 }
140
141 /**
142  * Show clipboard window
143  * Function to send message to show the Clipboard (cbhm) as no direct API available
144  * Reference elementary/src/modules/ctxpopup_copypasteUI/cbhm_helper.c
145  */
146 void Clipboard::ShowClipboard()
147 {
148 }
149
150 void Clipboard::HideClipboard()
151 {
152 }
153
154
155 } // namespace Adaptor
156
157 } // namespace Internal
158
159 } // namespace Dali