MediaPlayer: Fetch the clipboard for an url

* This avoid the user to paste in the BTextControl.
* Done also when the window is activated.
This commit is contained in:
Dario Casalinuovo 2016-07-08 13:49:54 +02:00
parent 7a137e0f0c
commit 778b5d524b
2 changed files with 51 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#include <Alert.h> #include <Alert.h>
#include <Button.h> #include <Button.h>
#include <Catalog.h> #include <Catalog.h>
#include <Clipboard.h>
#include <LayoutBuilder.h> #include <LayoutBuilder.h>
#include "MainApp.h" #include "MainApp.h"
@ -43,6 +44,8 @@ NetworkStreamWin::NetworkStreamWin(BMessenger target)
.End() .End()
.End(); .End();
_LookIntoClipboardForUrl();
CenterOnScreen(); CenterOnScreen();
} }
@ -86,3 +89,48 @@ NetworkStreamWin::MessageReceived(BMessage* message)
BWindow::MessageReceived(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();
}
}

View File

@ -20,7 +20,10 @@ public:
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual void WindowActivated(bool active);
private: private:
void _LookIntoClipboardForUrl();
BMessenger fTarget; BMessenger fTarget;
BTextControl* fTextControl; BTextControl* fTextControl;
}; };