Skip to content

Commit

Permalink
MediaPlayer: Add GUI to open network streams
Browse files Browse the repository at this point in the history
  • Loading branch information
Numerio committed Jun 30, 2016
1 parent 70efd0d commit 92cb0c5
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/apps/mediaplayer/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Application MediaPlayer :
InfoWin.cpp
MainApp.cpp
MainWin.cpp
NetworkStreamWin.cpp
VideoView.cpp

: be game media tracker translation textencoding [ TargetLibstdc++ ]
Expand All @@ -128,6 +129,7 @@ DoCatalogs MediaPlayer :
MainApp.cpp
MainWin.cpp
MovePLItemsCommand.cpp
NetworkStreamWin.cpp
PeakView.cpp
PlaylistItem.cpp
PlaylistWindow.cpp
Expand Down
4 changes: 3 additions & 1 deletion src/apps/mediaplayer/MainApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ enum {
M_OPEN_PANEL_RESULT = 'oprs',
M_SAVE_PANEL_RESULT = 'sprs',

M_OPEN_PREVIOUS_PLAYLIST = 'oppp'
M_OPEN_PREVIOUS_PLAYLIST = 'oppp',

M_URL_RECEIVED = 'urrc'
};


Expand Down
18 changes: 18 additions & 0 deletions src/apps/mediaplayer/MainWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <Catalog.h>
#include <Debug.h>
#include <fs_attr.h>
#include <LayoutBuilder.h>
#include <Language.h>
#include <Locale.h>
#include <MediaRoster.h>
Expand All @@ -55,6 +56,7 @@
#include "DurationToString.h"
#include "FilePlaylistItem.h"
#include "MainApp.h"
#include "NetworkStreamWin.h"
#include "PeakView.h"
#include "PlaylistItem.h"
#include "PlaylistObserver.h"
Expand All @@ -76,6 +78,7 @@ int MainWin::sNoVideoWidth = MIN_WIDTH;
enum {
M_DUMMY = 0x100,
M_FILE_OPEN = 0x1000,
M_NETWORK_STREAM_OPEN,
M_FILE_INFO,
M_FILE_PLAYLIST,
M_FILE_CLOSE,
Expand Down Expand Up @@ -617,8 +620,10 @@ MainWin::MessageReceived(BMessage* msg)
}

case B_REFS_RECEIVED:
case M_URL_RECEIVED:
_RefsReceived(msg);
break;

case B_SIMPLE_DATA:
if (msg->HasRef("refs"))
_RefsReceived(msg);
Expand Down Expand Up @@ -831,6 +836,15 @@ MainWin::MessageReceived(BMessage* msg)
be_app->PostMessage(&appMessage);
break;
}

case M_NETWORK_STREAM_OPEN:
{
BMessenger target(this);
NetworkStreamWin* win = new NetworkStreamWin(target);
win->Show();
break;
}

case M_FILE_INFO:
ShowFileInfo();
break;
Expand Down Expand Up @@ -1499,6 +1513,10 @@ MainWin::_CreateMenu()
item->SetShortcut('O', 0);
fFileMenu->AddItem(item);

item = new BMenuItem(B_TRANSLATE("Open network stream"),
new BMessage(M_NETWORK_STREAM_OPEN));
fFileMenu->AddItem(item);

fFileMenu->AddSeparatorItem();

fFileMenu->AddItem(new BMenuItem(B_TRANSLATE("File info" B_UTF8_ELLIPSIS),
Expand Down
86 changes: 86 additions & 0 deletions src/apps/mediaplayer/NetworkStreamWin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright 2016 Dario Casalinuovo. All rights reserved.
* Distributed under the terms of the MIT License.
*
*/


#include "NetworkStreamWin.h"

#include <Alert.h>
#include <Button.h>
#include <Catalog.h>
#include <LayoutBuilder.h>

#include "MainApp.h"


#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "MediaPlayer-NetworkStream"


enum {
M_OPEN_URL = 0,
M_CANCEL
};


NetworkStreamWin::NetworkStreamWin(BMessenger target)
:
BWindow(BRect(0, 0, 300, 100), "Open Network Stream",
B_TITLED_WINDOW, B_NOT_RESIZABLE),
fTarget(target)
{
fTextControl = new BTextControl("InputControl",
"Insert URL", NULL, NULL);

BLayoutBuilder::Group<>(this, B_VERTICAL)
.SetInsets(0, 0, 0, 0)
.Add(fTextControl)
.AddGroup(B_HORIZONTAL)
.Add(new BButton("Ok", new BMessage(M_OPEN_URL)))
.Add(new BButton("Cancel", new BMessage(M_CANCEL)))
.End()
.End();
}


NetworkStreamWin::~NetworkStreamWin()
{
}


void
NetworkStreamWin::MessageReceived(BMessage* message)
{
switch(message->what) {
case M_OPEN_URL:
{
BUrl url(fTextControl->Text());
if (!url.IsValid()) {
BAlert* alert = new BAlert(B_TRANSLATE("Bad URL"),
B_TRANSLATE("Invalid URL inserted!"),
B_TRANSLATE("OK"));
alert->Go();
return;
}

BMessage archivedUrl;
url.Archive(&archivedUrl);

BMessage msg(M_URL_RECEIVED);
msg.AddMessage("mediaplayer:url", &archivedUrl);
fTarget.SendMessage(&msg);

Quit();
break;
}

case M_CANCEL:
Quit();
break;

default:
BWindow::MessageReceived(message);
}
}
28 changes: 28 additions & 0 deletions src/apps/mediaplayer/NetworkStreamWin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2016 Dario Casalinuovo. All rights reserved.
* Distributed under the terms of the MIT License.
*
*/
#ifndef __NETWORK_STREAM_WIN_H
#define __NETWORK_STREAM_WIN_H


#include <Messenger.h>
#include <TextControl.h>
#include <Window.h>


class NetworkStreamWin : public BWindow
{
public:
NetworkStreamWin(BMessenger target);
virtual ~NetworkStreamWin();

virtual void MessageReceived(BMessage* message);

private:
BMessenger fTarget;
BTextControl* fTextControl;
};

#endif
2 changes: 1 addition & 1 deletion src/apps/mediaplayer/playlist/ImportPLItemsCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ImportPLItemsCommand::ImportPLItemsCommand(Playlist* playlist,
return;

Playlist temp;
temp.AppendRefs(refsMessage);
temp.AppendItems(refsMessage);

fNewCount = temp.CountItems();
if (fNewCount <= 0)
Expand Down
11 changes: 10 additions & 1 deletion src/apps/mediaplayer/playlist/Playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ Playlist::RemoveListener(Listener* listener)


void
Playlist::AppendRefs(const BMessage* refsReceivedMessage, int32 appendIndex)
Playlist::AppendItems(const BMessage* refsReceivedMessage, int32 appendIndex)
{
// the playlist is replaced by the refs in the message
// or the refs are appended at the appendIndex
Expand All @@ -448,6 +448,15 @@ Playlist::AppendRefs(const BMessage* refsReceivedMessage, int32 appendIndex)
Playlist* playlist = add ? &temporaryPlaylist : this;
bool sortPlaylist = true;

// TODO: This is not very fair, we should abstract from
// entry ref representation and support more URLs.
BMessage archivedUrl;
if (refsReceivedMessage->FindMessage("mediaplayer:url", &archivedUrl)
== B_OK) {
BUrl url(&archivedUrl);
AddItem(new UrlPlaylistItem(url));
}

entry_ref ref;
int32 subAppendIndex = CountItems();
for (int i = 0; refsReceivedMessage->FindRef("refs", i, &ref) == B_OK;
Expand Down
3 changes: 2 additions & 1 deletion src/apps/mediaplayer/playlist/Playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ class Playlist : public BLocker {
void RemoveListener(Listener* listener);

// support functions
void AppendRefs(const BMessage* refsReceivedMessage,
void AppendItems(const BMessage* refsReceivedMessage,
int32 appendIndex
= APPEND_INDEX_REPLACE_PLAYLIST);

static void AppendToPlaylistRecursive(const entry_ref& ref,
Playlist* playlist);
static void AppendPlaylistToPlaylist(const entry_ref& ref,
Expand Down
2 changes: 2 additions & 0 deletions src/apps/mediaplayer/playlist/PlaylistItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ PlaylistItem::TrackNumber() const
bigtime_t
PlaylistItem::Duration()
{
printf("duration\n");
bigtime_t duration;
if (GetAttribute(ATTR_INT64_DURATION, duration) != B_OK) {
duration = this->_CalculateDuration();
Expand Down Expand Up @@ -188,6 +189,7 @@ PlaylistItem::_NotifyListeners() const

bigtime_t PlaylistItem::_CalculateDuration()
{
printf("calc duration\n");
// To be overridden in subclasses with more efficient methods
TrackSupplier* supplier = GetTrackSupplier();

Expand Down
6 changes: 3 additions & 3 deletions src/apps/mediaplayer/playlist/PlaylistListView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,12 @@ PlaylistListView::MessageReceived(BMessage* message)

case B_SIMPLE_DATA:
if (message->HasRef("refs"))
RefsReceived(message, fDropIndex);
ItemsReceived(message, fDropIndex);
else if (message->HasPointer("list"))
SimpleListView::MessageReceived(message);
break;
case B_REFS_RECEIVED:
RefsReceived(message, fDropIndex);
ItemsReceived(message, fDropIndex);
break;

default:
Expand Down Expand Up @@ -506,7 +506,7 @@ PlaylistListView::DrawListItem(BView* owner, int32 index, BRect frame) const


void
PlaylistListView::RefsReceived(BMessage* message, int32 appendIndex)
PlaylistListView::ItemsReceived(const BMessage* message, int32 appendIndex)
{
if (fCommandStack->Perform(new (nothrow) ImportPLItemsCommand(fPlaylist,
message, appendIndex)) != B_OK) {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/mediaplayer/playlist/PlaylistListView.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PlaylistListView : public SimpleListView {
BRect frame) const;

// PlaylistListView
void RefsReceived(BMessage* message,
void ItemsReceived(const BMessage* message,
int32 appendIndex);

void Randomize();
Expand Down
3 changes: 2 additions & 1 deletion src/apps/mediaplayer/playlist/PlaylistWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ PlaylistWindow::MessageReceived(BMessage* message)
break;
}

case M_URL_RECEIVED:
case B_REFS_RECEIVED:
// Used for when we open a playlist from playlist window
if (!message->HasInt32("append_index")) {
Expand All @@ -193,7 +194,7 @@ PlaylistWindow::MessageReceived(BMessage* message)
// outside of the playlist!
int32 appendIndex;
if (message->FindInt32("append_index", &appendIndex) == B_OK)
fListView->RefsReceived(message, appendIndex);
fListView->ItemsReceived(message, appendIndex);
break;
}

Expand Down

0 comments on commit 92cb0c5

Please sign in to comment.