From 778b5d524b1bfc02fc04b6bb48fe92fe6abb4e8e Mon Sep 17 00:00:00 2001 From: Dario Casalinuovo Date: Fri, 8 Jul 2016 13:49:54 +0200 Subject: [PATCH] MediaPlayer: Fetch the clipboard for an url * This avoid the user to paste in the BTextControl. * Done also when the window is activated. --- src/apps/mediaplayer/NetworkStreamWin.cpp | 48 +++++++++++++++++++++++ src/apps/mediaplayer/NetworkStreamWin.h | 3 ++ 2 files changed, 51 insertions(+) diff --git a/src/apps/mediaplayer/NetworkStreamWin.cpp b/src/apps/mediaplayer/NetworkStreamWin.cpp index b1351f6e17..f7a02c73ce 100644 --- a/src/apps/mediaplayer/NetworkStreamWin.cpp +++ b/src/apps/mediaplayer/NetworkStreamWin.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "MainApp.h" @@ -43,6 +44,8 @@ NetworkStreamWin::NetworkStreamWin(BMessenger target) .End() .End(); + _LookIntoClipboardForUrl(); + CenterOnScreen(); } @@ -86,3 +89,48 @@ NetworkStreamWin::MessageReceived(BMessage* message) BWindow::MessageReceived(message); } } + + +void +NetworkStreamWin::WindowActivated(bool active) +{ + if (active) + _LookIntoClipboardForUrl(); +} + + +void +NetworkStreamWin::_LookIntoClipboardForUrl() +{ + // Don't do anything if we already have something + // set to avoid annoying the user. + if (fTextControl->TextView()->TextLength() > 0) + return; + + // Let's see if we already have an url in the clipboard + // in that case avoid the user to paste it. + if (be_clipboard->Lock()) { + char* text = NULL; + int32 textLen = 0; + + BMessage* data = be_clipboard->Data(); + if (data->FindData("text/plain", B_MIME_TYPE, + (const void **)&text, &textLen) == B_OK) { + + // NOTE: This is done because urls copied + // from WebPositive have the mime string at + // the end. + // TODO: Looks like a problem in Web+, should + // be fixed. + text[textLen] = '\0'; + + // Before to set the text let's see if it's really + // a valid URL. + BUrl url(text); + if (url.IsValid()) + fTextControl->SetText(text); + } + + be_clipboard->Unlock(); + } +} diff --git a/src/apps/mediaplayer/NetworkStreamWin.h b/src/apps/mediaplayer/NetworkStreamWin.h index b88f629831..c3d03112c9 100644 --- a/src/apps/mediaplayer/NetworkStreamWin.h +++ b/src/apps/mediaplayer/NetworkStreamWin.h @@ -20,7 +20,10 @@ public: virtual void MessageReceived(BMessage* message); + virtual void WindowActivated(bool active); private: + void _LookIntoClipboardForUrl(); + BMessenger fTarget; BTextControl* fTextControl; };