diff options
Diffstat (limited to 'dali/internal/clipboard/ubuntu-x11/clipboard-impl-x.cpp')
-rw-r--r-- | dali/internal/clipboard/ubuntu-x11/clipboard-impl-x.cpp | 104 |
1 files changed, 92 insertions, 12 deletions
diff --git a/dali/internal/clipboard/ubuntu-x11/clipboard-impl-x.cpp b/dali/internal/clipboard/ubuntu-x11/clipboard-impl-x.cpp index 9c15021c3..4780e04a1 100644 --- a/dali/internal/clipboard/ubuntu-x11/clipboard-impl-x.cpp +++ b/dali/internal/clipboard/ubuntu-x11/clipboard-impl-x.cpp @@ -29,6 +29,8 @@ #include <dali/devel-api/common/singleton-service.h> #include <dali/internal/adaptor/common/adaptor-impl.h> #include <dali/internal/window-system/ubuntu-x11/window-interface-ecore-x.h> +#include <map> +#include <queue> namespace Dali { @@ -45,30 +47,64 @@ struct Clipboard::Impl bool HasType(const std::string& mimeType) { - return mMimeType == mimeType ? true : false; + for(const auto& type : mMimeTypes) + { + if (type == mimeType) + { + return true; + } + } + return false; + } + + void UpdateData(std::string& mimeType, std::string& data, bool clearBuffer) + { + if(clearBuffer) + { + mMimeTypes.clear(); + mDatas.clear(); + } + mMimeTypes.push_back(mimeType); + mDatas[mimeType] = data; } bool SetData(const Dali::Clipboard::ClipData& clipData) { - mMimeType = clipData.GetMimeType(); - mData = clipData.GetData(); + std::string mimeType = clipData.GetMimeType(); + std::string data = clipData.GetData(); - if(mData.empty()) + if(mimeType.empty() || data.empty()) { return false; } - mDataSentSignal.Emit(mMimeType.c_str(), mData.c_str()); - mDataSelectedSignal.Emit(mMimeType.c_str()); + if(mLastType != mimeType && !mMultiSelectionTimeout) + { + bool clearBuffer = HasType(mimeType); + UpdateData(mimeType, data, clearBuffer); + } + else + { + UpdateData(mimeType, data, true); + } + + mLastType = mimeType; + + mDataSentSignal.Emit(mimeType.c_str(), data.c_str()); + mDataSelectedSignal.Emit(mimeType.c_str()); + + SetMultiSelectionTimeout(); return true; } uint32_t GetData(const std::string &mimeType) { - if(!mMimeType.compare(mimeType.c_str())) + if(mDatas.count(mimeType)) { mDataId++; + mDataReceiveQueue.push(std::make_pair(mDataId, mimeType)); + // For consistency of operation with tizen Wl2, a fake callback is occurs using a timer. if(mDataReceiveTimer.IsRunning()) { @@ -83,28 +119,67 @@ struct Clipboard::Impl bool OnReceiveData() { - DALI_LOG_RELEASE_INFO("receive data, success signal emit, id:%u, type:%s, data:%s\n", mDataId, mMimeType.c_str(), mData.c_str()); - mDataReceivedSignal.Emit(mDataId, mMimeType.c_str(), mData.c_str()); + while(!mDataReceiveQueue.empty()) + { + auto item = mDataReceiveQueue.front(); + mDataReceiveQueue.pop(); + + uint32_t requestId = item.first; + std::string requestType = item.second; + std::string data = ""; + + if(mDatas.count(requestType)) + { + data = mDatas[requestType]; + } + + DALI_LOG_RELEASE_INFO("receive data, success signal emit, id:%u, type:%s, data:%s\n", requestId, requestType.c_str(), data.c_str()); + mDataReceivedSignal.Emit(requestId, requestType.c_str(), data.c_str()); + } + return false; + } + + void SetMultiSelectionTimeout() + { + mMultiSelectionTimeout = false; + if(mMultiSelectionTimeoutTimer.IsRunning()) + { + mMultiSelectionTimeoutTimer.Stop(); + } + mMultiSelectionTimeoutTimer.Start(); + } + + bool OnMultiSelectionTimeout() + { + mMultiSelectionTimeout = true; return false; } Ecore_X_Window mApplicationWindow; - std::string mMimeType; - std::string mData; uint32_t mDataId{0}; + std::string mLastType; + + std::vector<std::string> mMimeTypes; + std::map<std::string, std::string> mDatas; // type, data + std::queue<std::pair<uint32_t, std::string>> mDataReceiveQueue; // id, type Dali::Clipboard::DataSentSignalType mDataSentSignal; Dali::Clipboard::DataReceivedSignalType mDataReceivedSignal; Dali::Clipboard::DataSelectedSignalType mDataSelectedSignal; Dali::Timer mDataReceiveTimer; + Dali::Timer mMultiSelectionTimeoutTimer; + bool mMultiSelectionTimeout{false}; }; Clipboard::Clipboard(Impl* impl) : mImpl(impl) { - mImpl->mDataReceiveTimer = Dali::Timer::New(10); + mImpl->mDataReceiveTimer = Dali::Timer::New(10u); mImpl->mDataReceiveTimer.TickSignal().Connect(this, &Clipboard::OnReceiveData); + + mImpl->mMultiSelectionTimeoutTimer = Dali::Timer::New(500u); + mImpl->mMultiSelectionTimeoutTimer.TickSignal().Connect(this, &Clipboard::OnMultiSelectionTimeout); } Clipboard::~Clipboard() @@ -217,6 +292,11 @@ bool Clipboard::OnReceiveData() return mImpl->OnReceiveData(); } +bool Clipboard::OnMultiSelectionTimeout() +{ + return mImpl->OnMultiSelectionTimeout(); +} + } // namespace Adaptor } // namespace Internal |