2 * Copyright 2016 Dario Casalinuovo. All rights reserved.
3 * Distributed under the terms of the MIT License.
8 #include "NetworkStreamWin.h"
13 #include <Clipboard.h>
14 #include <LayoutBuilder.h>
19 #undef B_TRANSLATION_CONTEXT
20 #define B_TRANSLATION_CONTEXT "MediaPlayer-NetworkStream"
29 NetworkStreamWin::NetworkStreamWin(BMessenger target
)
31 BWindow(BRect(0, 0, 300, 100), B_TRANSLATE("Open network stream"),
32 B_MODAL_WINDOW
, B_NOT_RESIZABLE
),
35 fTextControl
= new BTextControl("InputControl",
36 B_TRANSLATE("Stream URL:"), NULL
, NULL
);
38 BLayoutBuilder::Group
<>(this, B_VERTICAL
)
39 .SetInsets(B_USE_HALF_ITEM_INSETS
)
41 .AddGroup(B_HORIZONTAL
)
43 .Add(new BButton(B_TRANSLATE("OK"), new BMessage(M_OPEN_URL
)))
44 .Add(new BButton(B_TRANSLATE("Cancel"), new BMessage(M_CANCEL
)))
48 _LookIntoClipboardForUrl();
54 NetworkStreamWin::~NetworkStreamWin()
60 NetworkStreamWin::MessageReceived(BMessage
* message
)
62 switch(message
->what
) {
65 BUrl
url(fTextControl
->Text());
67 BAlert
* alert
= new BAlert(B_TRANSLATE("Bad URL"),
68 B_TRANSLATE("Invalid URL inserted!"),
75 url
.Archive(&archivedUrl
);
77 BMessage
msg(M_URL_RECEIVED
);
78 msg
.AddMessage("mediaplayer:url", &archivedUrl
);
79 fTarget
.SendMessage(&msg
);
92 if (message
->FindInt8("byte", &key
) == B_OK
94 PostMessage(M_OPEN_URL
);
100 BWindow::MessageReceived(message
);
106 NetworkStreamWin::WindowActivated(bool active
)
109 _LookIntoClipboardForUrl();
114 NetworkStreamWin::_LookIntoClipboardForUrl()
116 // Don't do anything if we already have something
117 // set to avoid annoying the user.
118 if (fTextControl
->TextView()->TextLength() > 0)
121 // Let's see if we already have an url in the clipboard
122 // in that case avoid the user to paste it.
123 if (be_clipboard
->Lock()) {
127 BMessage
* data
= be_clipboard
->Data();
128 if (data
->FindData("text/plain", B_MIME_TYPE
,
129 (const void **)&text
, &textLen
) == B_OK
) {
131 // NOTE: This is done because urls copied
132 // from WebPositive have the mime string at
134 // TODO: Looks like a problem in Web+, should
136 text
[textLen
] = '\0';
138 // Before to set the text let's see if it's really
142 fTextControl
->SetText(text
);
145 be_clipboard
->Unlock();