diff --git a/source/AdapterIO.cpp b/source/AdapterIO.cpp index ab0a5da..24838cf 100644 --- a/source/AdapterIO.cpp +++ b/source/AdapterIO.cpp @@ -18,22 +18,17 @@ class RelativePositionIO : public BPositionIO { public: - RelativePositionIO(BAdapterIO* owner, BPositionIO* buffer, - bigtime_t timeout) - : - BPositionIO(), - fOwner(owner), - fBackPosition(0), - fStartOffset(0), - fBuffer(buffer), - fTimeout(timeout) + RelativePositionIO(BAdapterIO* owner, BPositionIO* buffer, bigtime_t timeout) + : BPositionIO(), + fOwner(owner), + fBackPosition(0), + fStartOffset(0), + fBuffer(buffer), + fTimeout(timeout) { } - virtual ~RelativePositionIO() - { - delete fBuffer; - } + virtual ~RelativePositionIO() { delete fBuffer; } status_t ResetStartOffset(off_t offset) { @@ -105,26 +100,21 @@ class RelativePositionIO : public BPositionIO { return B_OK; } - virtual ssize_t ReadAt(off_t position, void* buffer, - size_t size) + virtual ssize_t ReadAt(off_t position, void* buffer, size_t size) { AutoReadLocker _(fLock); - return fBuffer->ReadAt( - _PositionToRelative(position), buffer, size); - + return fBuffer->ReadAt(_PositionToRelative(position), buffer, size); } - virtual ssize_t WriteAt(off_t position, - const void* buffer, size_t size) + virtual ssize_t WriteAt(off_t position, const void* buffer, size_t size) { AutoWriteLocker _(fLock); - return fBuffer->WriteAt( - _PositionToRelative(position), buffer, size); + return fBuffer->WriteAt(_PositionToRelative(position), buffer, size); } - virtual off_t Seek(off_t position, uint32 seekMode) + virtual off_t Seek(off_t position, uint32 seekMode) { AutoWriteLocker _(fLock); @@ -140,14 +130,14 @@ class RelativePositionIO : public BPositionIO { return _RelativeToPosition(fBuffer->Position()); } - virtual status_t SetSize(off_t size) + virtual status_t SetSize(off_t size) { AutoWriteLocker _(fLock); return fBuffer->SetSize(_PositionToRelative(size)); } - virtual status_t GetSize(off_t* size) const + virtual status_t GetSize(off_t* size) const { AutoReadLocker _(fLock); @@ -194,43 +184,27 @@ class RelativePositionIO : public BPositionIO { return ((flags & B_MEDIA_SEEKABLE) == B_MEDIA_SEEKABLE); } - const BPositionIO* Buffer() const - { - return fBuffer; - } + const BPositionIO* Buffer() const { return fBuffer; } private: + off_t _PositionToRelative(off_t position) const { return position - fStartOffset; } - off_t _PositionToRelative(off_t position) const - { - return position - fStartOffset; - } + off_t _RelativeToPosition(off_t position) const { return position + fStartOffset; } - off_t _RelativeToPosition(off_t position) const - { - return position + fStartOffset; - } + BAdapterIO* fOwner; + off_t fBackPosition; + off_t fStartOffset; - BAdapterIO* fOwner; - off_t fBackPosition; - off_t fStartOffset; + BPositionIO* fBuffer; - BPositionIO* fBuffer; + mutable RWLocker fLock; - mutable RWLocker fLock; - - bigtime_t fTimeout; + bigtime_t fTimeout; }; BAdapterIO::BAdapterIO(int32 flags, bigtime_t timeout) - : - fFlags(flags), - fBuffer(NULL), - fTotalSize(0), - fOpened(false), - fSeekSem(-1), - fInputAdapter(NULL) + : fFlags(flags), fBuffer(NULL), fTotalSize(0), fOpened(false), fSeekSem(-1), fInputAdapter(NULL) { CALLED(); @@ -238,7 +212,7 @@ BAdapterIO::BAdapterIO(int32 flags, bigtime_t timeout) } -BAdapterIO::BAdapterIO(const BAdapterIO &) +BAdapterIO::BAdapterIO(const BAdapterIO&) { // copying not allowed... } @@ -293,19 +267,17 @@ BAdapterIO::Seek(off_t position, uint32 seekMode) off_t size = 0; if (seekMode == SEEK_CUR) - absolutePosition = Position()+position; + absolutePosition = Position() + position; else if (seekMode == SEEK_END) { if (GetSize(&size) != B_OK) return B_NOT_SUPPORTED; - absolutePosition = size-position; + absolutePosition = size - position; } status_t ret = _EvaluateWait(absolutePosition, 0); - if (ret == B_RESOURCE_UNAVAILABLE && fBuffer->IsStreaming() - && fBuffer->IsSeekable()) { - + if (ret == B_RESOURCE_UNAVAILABLE && fBuffer->IsStreaming() && fBuffer->IsSeekable()) { fSeekSem = create_sem(0, "BAdapterIO seek sem"); if (SeekRequested(absolutePosition) != B_OK) @@ -445,8 +417,8 @@ BAdapterIO::_EvaluateWait(off_t pos, off_t size) if (GetSize(&totalSize) != B_OK) TRACE("BAdapterIO::ReadAt: Can't get our size!\n"); - TRACE("BAdapterIO::_EvaluateWait TS %" B_PRId64 " P %" B_PRId64 - " S %" B_PRId64 "\n", totalSize, pos, size); + TRACE("BAdapterIO::_EvaluateWait TS %" B_PRId64 " P %" B_PRId64 " S %" B_PRId64 "\n", totalSize, + pos, size); status_t err = fBuffer->EvaluatePosition(pos, totalSize); @@ -461,16 +433,10 @@ BAdapterIO::_EvaluateWait(off_t pos, off_t size) } -BInputAdapter::BInputAdapter(BAdapterIO* io) - : - fIO(io) -{ -} +BInputAdapter::BInputAdapter(BAdapterIO* io) : fIO(io) {} -BInputAdapter::~BInputAdapter() -{ -} +BInputAdapter::~BInputAdapter() {} ssize_t @@ -481,11 +447,32 @@ BInputAdapter::Write(const void* buffer, size_t size) // FBC -void BAdapterIO::_ReservedAdapterIO1() {} -void BAdapterIO::_ReservedAdapterIO2() {} -void BAdapterIO::_ReservedAdapterIO3() {} -void BAdapterIO::_ReservedAdapterIO4() {} -void BAdapterIO::_ReservedAdapterIO5() {} - -void BInputAdapter::_ReservedInputAdapter1() {} -void BInputAdapter::_ReservedInputAdapter2() {} +void +BAdapterIO::_ReservedAdapterIO1() +{ +} +void +BAdapterIO::_ReservedAdapterIO2() +{ +} +void +BAdapterIO::_ReservedAdapterIO3() +{ +} +void +BAdapterIO::_ReservedAdapterIO4() +{ +} +void +BAdapterIO::_ReservedAdapterIO5() +{ +} + +void +BInputAdapter::_ReservedInputAdapter1() +{ +} +void +BInputAdapter::_ReservedInputAdapter2() +{ +} diff --git a/source/AdapterIO.h b/source/AdapterIO.h index c0273a8..b8c4b9e 100644 --- a/source/AdapterIO.h +++ b/source/AdapterIO.h @@ -18,83 +18,79 @@ class RelativePositionIO; class BInputAdapter { public: - virtual ssize_t Write(const void* buffer, size_t size); + virtual ssize_t Write(const void* buffer, size_t size); private: friend class BAdapterIO; - BInputAdapter(BAdapterIO* io); - virtual ~BInputAdapter(); + BInputAdapter(BAdapterIO* io); + virtual ~BInputAdapter(); - BAdapterIO* fIO; + BAdapterIO* fIO; - virtual void _ReservedInputAdapter1(); - virtual void _ReservedInputAdapter2(); + virtual void _ReservedInputAdapter1(); + virtual void _ReservedInputAdapter2(); - uint32 _reserved[2]; + uint32 _reserved[2]; }; class BAdapterIO : public BMediaIO { public: - BAdapterIO( - int32 flags, - bigtime_t timeout); - virtual ~BAdapterIO(); + BAdapterIO(int32 flags, bigtime_t timeout); + virtual ~BAdapterIO(); - virtual void GetFlags(int32* flags) const; + virtual void GetFlags(int32* flags) const; - virtual ssize_t ReadAt(off_t position, void* buffer, - size_t size); - virtual ssize_t WriteAt(off_t position, - const void* buffer, size_t size); + virtual ssize_t ReadAt(off_t position, void* buffer, size_t size); + virtual ssize_t WriteAt(off_t position, const void* buffer, size_t size); - virtual off_t Seek(off_t position, uint32 seekMode); - virtual off_t Position() const; + virtual off_t Seek(off_t position, uint32 seekMode); + virtual off_t Position() const; - virtual status_t SetSize(off_t size); - virtual status_t GetSize(off_t* size) const; + virtual status_t SetSize(off_t size); + virtual status_t GetSize(off_t* size) const; - virtual status_t Open(); + virtual status_t Open(); - virtual bool IsRunning() const; + virtual bool IsRunning() const; - void SeekCompleted(); - status_t SetBuffer(BPositionIO* buffer); + void SeekCompleted(); + status_t SetBuffer(BPositionIO* buffer); - status_t FlushRead(); + status_t FlushRead(); - BInputAdapter* BuildInputAdapter(); + BInputAdapter* BuildInputAdapter(); protected: friend class BInputAdapter; - virtual status_t SeekRequested(off_t position); + virtual status_t SeekRequested(off_t position); - ssize_t BackWrite(const void* buffer, size_t size); + ssize_t BackWrite(const void* buffer, size_t size); private: - status_t _EvaluateWait(off_t pos, off_t size); + status_t _EvaluateWait(off_t pos, off_t size); - int32 fFlags; + int32 fFlags; - RelativePositionIO* fBuffer; - off_t fTotalSize; - bool fOpened; - sem_id fSeekSem; + RelativePositionIO* fBuffer; + off_t fTotalSize; + bool fOpened; + sem_id fSeekSem; - BInputAdapter* fInputAdapter; + BInputAdapter* fInputAdapter; - BAdapterIO(const BAdapterIO&); - BAdapterIO& operator=(const BAdapterIO&); + BAdapterIO(const BAdapterIO&); + BAdapterIO& operator=(const BAdapterIO&); - virtual void _ReservedAdapterIO1(); - virtual void _ReservedAdapterIO2(); - virtual void _ReservedAdapterIO3(); - virtual void _ReservedAdapterIO4(); - virtual void _ReservedAdapterIO5(); + virtual void _ReservedAdapterIO1(); + virtual void _ReservedAdapterIO2(); + virtual void _ReservedAdapterIO3(); + virtual void _ReservedAdapterIO4(); + virtual void _ReservedAdapterIO5(); - uint32 _reserved[5]; + uint32 _reserved[5]; }; #endif // _ADAPTER_IO_H diff --git a/source/Debug.h b/source/Debug.h index 9573761..dafe296 100644 --- a/source/Debug.h +++ b/source/Debug.h @@ -31,30 +31,29 @@ #undef DEBUG #undef MSG -//#define TRACING -//#define DEBUGGING -//#define PROFILING +// #define TRACING +// #define DEBUGGING +// #define PROFILING #ifdef DEBUGGING #define DEBUG(x...) fprintf(stderr, __FILE__ " - " x) #else #define DEBUG(x...) -#endif // DEBUGGING +#endif // DEBUGGING #ifdef TRACING #define TRACE(x...) fprintf(stderr, __FILE__ " - " x) #else #define TRACE(x...) -#endif // TRACING +#endif // TRACING #define MSG(x...) fprintf(stderr, __FILE__ " - " x) #ifdef PROFILING #define PROFILE_START bigtime_t timer = system_time() #define PROFILE_MEASURE(action) \ - TRACE("%s took %2.6f seconds\r\n", action, \ - (system_time() - timer) / 1000000.0f) + TRACE("%s took %2.6f seconds\r\n", action, (system_time() - timer) / 1000000.0f) #else #define PROFILE_START #define PROFILE_MEASURE(action) -#endif // PROFILING +#endif // PROFILING -#endif // _DEBUG_H +#endif // _DEBUG_H diff --git a/source/HttpUtils.cpp b/source/HttpUtils.cpp index 04b79ab..39dd1f4 100644 --- a/source/HttpUtils.cpp +++ b/source/HttpUtils.cpp @@ -28,34 +28,29 @@ class DataLimit : public BUrlProtocolListener, public BDataIO { public: - DataLimit(BDataIO* sink, size_t limit) - : - fSink(sink), - fLimit(limit) - { - } - - ssize_t Write(const void *buffer, size_t size) override - { - if (size > fLimit) - size = fLimit; - - ssize_t written = fSink->Write(buffer, size); - if (written > 0) - fLimit -= written; - - return written; - } - - void BytesWritten(BUrlRequest* caller, size_t size) override - { - if (fLimit == 0) - caller->Stop(); - } + DataLimit(BDataIO* sink, size_t limit) : fSink(sink), fLimit(limit) {} + + ssize_t Write(const void* buffer, size_t size) override + { + if (size > fLimit) + size = fLimit; + + ssize_t written = fSink->Write(buffer, size); + if (written > 0) + fLimit -= written; + + return written; + } + + void BytesWritten(BUrlRequest* caller, size_t size) override + { + if (fLimit == 0) + caller->Stop(); + } private: - BDataIO* fSink; - size_t fLimit; + BDataIO* fSink; + size_t fLimit; }; @@ -71,8 +66,8 @@ HttpUtils::CheckPort(BUrl url, BUrl* newUrl, uint32 flags) else port = 80; - BReference resolver - = BNetworkAddressResolver::Resolve(url.Host(), port, flags); + BReference resolver = + BNetworkAddressResolver::Resolve(url.Host(), port, flags); if (resolver.Get() == NULL) return B_NO_MEMORY; status_t status = resolver->InitCheck(); @@ -91,16 +86,15 @@ HttpUtils::CheckPort(BUrl url, BUrl* newUrl, uint32 flags) status = resolver->GetNextAddress(&cookie, ipAddress); if (status != B_OK) return status; - socket = new(std::nothrow) BSocket(); + socket = new (std::nothrow) BSocket(); portStatus = socket->Connect(ipAddress); delete socket; } // If port number is 80, do not add it to the final URL // Then, prepend the appropiate protocol - newUrlString = ipAddress.ToString(ipAddress.Port() != 80) - .Prepend("://") - .Prepend(url.Protocol()); + newUrlString = + ipAddress.ToString(ipAddress.Port() != 80).Prepend("://").Prepend(url.Protocol()); if (url.HasPath()) newUrlString.Append(url.Path()); newUrl->SetUrlString(newUrlString.String()); @@ -117,8 +111,8 @@ HttpUtils::CheckPort(BUrl url, BUrl* newUrl, uint32 flags) * @return BMallocIO* filled with retrieved content */ BMallocIO* -HttpUtils::GetAll(BUrl url, BHttpHeaders* responseHeaders, bigtime_t timeOut, - BString* contentType, size_t sizeLimit) +HttpUtils::GetAll(BUrl url, BHttpHeaders* responseHeaders, bigtime_t timeOut, BString* contentType, + size_t sizeLimit) { BMallocIO* data = new BMallocIO(); if (data == NULL) @@ -127,11 +121,11 @@ HttpUtils::GetAll(BUrl url, BHttpHeaders* responseHeaders, bigtime_t timeOut, DataLimit reader(data, sizeLimit); BHttpRequest* request; if (sizeLimit) - request = dynamic_cast(BUrlProtocolRoster::MakeRequest( - url.UrlString().String(), &reader, &reader, NULL)); + request = dynamic_cast( + BUrlProtocolRoster::MakeRequest(url.UrlString().String(), &reader, &reader, NULL)); else - request = dynamic_cast(BUrlProtocolRoster::MakeRequest( - url.UrlString().String(), data, NULL, NULL)); + request = dynamic_cast( + BUrlProtocolRoster::MakeRequest(url.UrlString().String(), data, NULL, NULL)); if (request == NULL) return NULL; @@ -154,8 +148,7 @@ HttpUtils::GetAll(BUrl url, BHttpHeaders* responseHeaders, bigtime_t timeOut, BHttpResult& result = (BHttpResult&)request->Result(); int32 statusCode = result.StatusCode(); size_t bufferLen = data->BufferLength(); - if (!(statusCode == 0 || request->IsSuccessStatusCode(statusCode)) - || bufferLen == 0) { + if (!(statusCode == 0 || request->IsSuccessStatusCode(statusCode)) || bufferLen == 0) { delete data; data = NULL; } else if (contentType != NULL) diff --git a/source/HttpUtils.h b/source/HttpUtils.h index 951a6a9..e1df8f3 100644 --- a/source/HttpUtils.h +++ b/source/HttpUtils.h @@ -29,15 +29,11 @@ using namespace BPrivate::Network; class HttpUtils { public: - static status_t CheckPort(BUrl url, BUrl* newUrl, - uint32 flags = 0); - - static BMallocIO* GetAll(BUrl url, - BHttpHeaders* returnHeaders = NULL, - bigtime_t timeOut = 3000, - BString* contentType = NULL, - size_t sizeLimit = 0); + static status_t CheckPort(BUrl url, BUrl* newUrl, uint32 flags = 0); + + static BMallocIO* GetAll(BUrl url, BHttpHeaders* returnHeaders = NULL, bigtime_t timeOut = 3000, + BString* contentType = NULL, size_t sizeLimit = 0); }; -#endif // _HTTP_UTILS_H +#endif // _HTTP_UTILS_H diff --git a/source/MainWindow.cpp b/source/MainWindow.cpp index a140782..20f1984 100644 --- a/source/MainWindow.cpp +++ b/source/MainWindow.cpp @@ -45,41 +45,37 @@ MainWindow::MainWindow() - : - BWindow(BRect(0, 0, 400, 200), B_TRANSLATE_SYSTEM_NAME("StreamRadio"), - B_DOCUMENT_WINDOW, 0), - fStationFinder(NULL) + : BWindow(BRect(0, 0, 400, 200), B_TRANSLATE_SYSTEM_NAME("StreamRadio"), B_DOCUMENT_WINDOW, 0), + fStationFinder(NULL) { fSettings = &((RadioApp*)be_app)->Settings; fAllowParallelPlayback = fSettings->GetAllowParallelPlayback(); - fMenuParallelPlayback = new BMenuItem(B_TRANSLATE("Allow parallel playback"), - new BMessage(MSG_PARALLEL_PLAYBACK)); + fMenuParallelPlayback = + new BMenuItem(B_TRANSLATE("Allow parallel playback"), new BMessage(MSG_PARALLEL_PLAYBACK)); fMenuParallelPlayback->SetMarked(fAllowParallelPlayback); fMainMenu = new BMenuBar(Bounds(), "MainMenu"); BLayoutBuilder::Menu<>(fMainMenu) .AddMenu(B_TRANSLATE("App")) - .AddItem(fMenuParallelPlayback) - .AddItem(B_TRANSLATE("Help" B_UTF8_ELLIPSIS), MSG_HELP) - .AddItem(B_TRANSLATE("About"), B_ABOUT_REQUESTED) - .AddSeparator() - .AddItem(B_TRANSLATE("Quit"), B_QUIT_REQUESTED, 'Q') + .AddItem(fMenuParallelPlayback) + .AddItem(B_TRANSLATE("Help" B_UTF8_ELLIPSIS), MSG_HELP) + .AddItem(B_TRANSLATE("About"), B_ABOUT_REQUESTED) + .AddSeparator() + .AddItem(B_TRANSLATE("Quit"), B_QUIT_REQUESTED, 'Q') .End() .AddMenu(B_TRANSLATE("Station")) - .AddItem(B_TRANSLATE("Paste Shoutcast URL"), MSG_PASTE_URL, 'V') - .AddItem(B_TRANSLATE("Check station"), MSG_CHECK) - .AddItem(B_TRANSLATE("Remove station"), MSG_REMOVE, 'R') + .AddItem(B_TRANSLATE("Paste Shoutcast URL"), MSG_PASTE_URL, 'V') + .AddItem(B_TRANSLATE("Check station"), MSG_CHECK) + .AddItem(B_TRANSLATE("Remove station"), MSG_REMOVE, 'R') .End() .AddMenu(B_TRANSLATE("Search")) - .AddItem(B_TRANSLATE("Find stations" B_UTF8_ELLIPSIS), MSG_SEARCH, - 'S') + .AddItem(B_TRANSLATE("Find stations" B_UTF8_ELLIPSIS), MSG_SEARCH, 'S') .End() - .End(); + .End(); fStationList = new StationListView(true); - BScrollView* stationScroll = new BScrollView( - "scrollStation", fStationList, 0, false, true); + BScrollView* stationScroll = new BScrollView("scrollStation", fStationList, 0, false, true); fStationPanel = new StationPanel(this); @@ -88,24 +84,22 @@ MainWindow::MainWindow() BLayoutBuilder::Group<>(this, B_VERTICAL) .Add(fMainMenu) .AddGroup(B_VERTICAL) - .SetInsets(B_USE_WINDOW_INSETS, 0, B_USE_WINDOW_INSETS, - B_USE_WINDOW_INSETS) - .AddSplit(B_VERTICAL, 2) - .Add(stationScroll, 1.0f) - .Add(fStationPanel) - .SetCollapsible(1, true) - .End() - .Add(fStatusBar) + .SetInsets(B_USE_WINDOW_INSETS, 0, B_USE_WINDOW_INSETS, B_USE_WINDOW_INSETS) + .AddSplit(B_VERTICAL, 2) + .Add(stationScroll, 1.0f) + .Add(fStationPanel) + .SetCollapsible(1, true) .End() - .End(); + .Add(fStatusBar) + .End() + .End(); fStationList->Sync(fSettings->Stations); fStationList->SetInvocationMessage(new BMessage(MSG_INVOKE_STATION)); fStationList->SetSelectionMessage(new BMessage(MSG_SELECT_STATION)); fStationList->SetPlayMessage(new BMessage(MSG_INVOKE_STATION)); - fStatusBar->SetExplicitAlignment( - BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_VERTICAL_UNSET)); + fStatusBar->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_VERTICAL_UNSET)); fStatusBar->SetExplicitMinSize(BSize(10, B_SIZE_UNSET)); ResizeToPreferred(); @@ -137,8 +131,7 @@ MainWindow::MessageReceived(BMessage* message) while (message->FindRef("refs", index++, &ref) == B_OK) { Station* station = Station::Load(ref.name, new BEntry(&ref)); if ((station = Station::Load(ref.name, new BEntry(&ref)))) { - Station* existingStation - = fSettings->Stations->FindItem(station->Name()); + Station* existingStation = fSettings->Stations->FindItem(station->Name()); if (existingStation) { delete station; station = existingStation; @@ -148,12 +141,10 @@ MainWindow::MessageReceived(BMessage* message) stationItem = new StationListViewItem(station); fStationList->AddItem(stationItem); result.SetToFormat( - B_TRANSLATE("Added station %s to list"), - station->Name()->String()); + B_TRANSLATE("Added station %s to list"), station->Name()->String()); } } else - result.SetToFormat(B_TRANSLATE( - "File %s could not be loaded as a station")); + result.SetToFormat(B_TRANSLATE("File %s could not be loaded as a station")); fStatusBar->SetText(result.String()); } @@ -177,9 +168,7 @@ MainWindow::MessageReceived(BMessage* message) char* url; ssize_t numBytes; - if (data->FindData( - "text/plain", B_MIME_TYPE, (const void**) &url, &numBytes) - == B_OK) + if (data->FindData("text/plain", B_MIME_TYPE, (const void**)&url, &numBytes) == B_OK) url[numBytes] = 0; BString sUrl(url); @@ -192,13 +181,10 @@ MainWindow::MessageReceived(BMessage* message) fSettings->Stations->Save(); } else { BString msg; - msg.SetToFormat( - B_TRANSLATE("Station %s did not respond correctly and " - "could not be added"), + msg.SetToFormat(B_TRANSLATE("Station %s did not respond correctly and " + "could not be added"), station->Name()->String()); - (new BAlert(B_TRANSLATE("Add station failed"), msg, - B_TRANSLATE("OK"))) - ->Go(); + (new BAlert(B_TRANSLATE("Add station failed"), msg, B_TRANSLATE("OK")))->Go(); } } @@ -207,19 +193,17 @@ MainWindow::MessageReceived(BMessage* message) case MSG_CHECK: { - StationListViewItem* stationItem - = fStationList->ItemAt(fStationList->CurrentSelection(0)); + StationListViewItem* stationItem = + fStationList->ItemAt(fStationList->CurrentSelection(0)); if (stationItem != NULL) { Station* station = stationItem->GetStation(); status_t stationStatus = station->Probe(); BString statusText; if (stationStatus == B_OK) { - statusText - = B_TRANSLATE("Probing station %station% successful"); + statusText = B_TRANSLATE("Probing station %station% successful"); } else { - statusText - = B_TRANSLATE("Probing station %station% failed"); + statusText = B_TRANSLATE("Probing station %station% failed"); } statusText.ReplaceFirst("%station%", station->Name()->String()); @@ -233,8 +217,7 @@ MainWindow::MessageReceived(BMessage* message) case MSG_REMOVE: { - Station* station - = fStationList->StationAt(fStationList->CurrentSelection(0)); + Station* station = fStationList->StationAt(fStationList->CurrentSelection(0)); if (station != NULL) { fSettings->Stations->RemoveItem(station); fStationList->Sync(fSettings->Stations); @@ -247,7 +230,7 @@ MainWindow::MessageReceived(BMessage* message) case MSG_ADD_STATION: { Station* station = NULL; - if (message->FindPointer("station", (void**) &station) == B_OK) { + if (message->FindPointer("station", (void**)&station) == B_OK) { fSettings->Stations->AddItem(station); fStationList->Sync(fSettings->Stations); fSettings->Stations->Save(); @@ -275,8 +258,7 @@ MainWindow::MessageReceived(BMessage* message) case MSG_INVOKE_STATION: { int32 stationIndex = message->GetInt32("index", -1); - StationListViewItem* stationItem - = fStationList->ItemAt(stationIndex); + StationListViewItem* stationItem = fStationList->ItemAt(stationIndex); _Invoke(stationItem); break; } @@ -288,13 +270,11 @@ MainWindow::MessageReceived(BMessage* message) if (player != NULL && status == B_OK) { StreamPlayer::PlayState state; - status = message->FindInt32("state", (int32*) &state); + status = message->FindInt32("state", (int32*)&state); - int stationIndex = fStationList->StationIndex( - player->GetStation()); + int stationIndex = fStationList->StationIndex(player->GetStation()); if (stationIndex >= 0) { - StationListViewItem* stationItem - = fStationList->ItemAt(stationIndex); + StationListViewItem* stationItem = fStationList->ItemAt(stationIndex); stationItem->StateChanged(player->State()); if (player->State() == StreamPlayer::Stopped) { @@ -315,7 +295,7 @@ MainWindow::MessageReceived(BMessage* message) case MSG_PLAYER_BUFFER_LEVEL: { StreamPlayer* player = NULL; - status_t status = message->FindPointer("player", (void**) &player); + status_t status = message->FindPointer("player", (void**)&player); float level = message->GetFloat("level", 0.0f); if (player != NULL && status == B_OK) { Station* station = player->GetStation(); @@ -330,11 +310,10 @@ MainWindow::MessageReceived(BMessage* message) case MSG_META_CHANGE: { BString meta = B_TRANSLATE("%station% now plays %title%"); - meta.ReplaceFirst("%station%", - message->GetString("station", B_TRANSLATE("Unknown station"))); - meta.ReplaceFirst("%title%", - message->GetString( - "streamtitle", B_TRANSLATE("unknown title"))); + meta.ReplaceFirst( + "%station%", message->GetString("station", B_TRANSLATE("Unknown station"))); + meta.ReplaceFirst( + "%title%", message->GetString("streamtitle", B_TRANSLATE("unknown title"))); fStatusBar->SetText(meta.String()); break; @@ -342,8 +321,9 @@ MainWindow::MessageReceived(BMessage* message) case MSG_HELP: { - BUrl userguide = BUrl("https://github.com/HaikuArchives/" - "StreamRadio/blob/master/docs/userguide.md"); + BUrl userguide = BUrl( + "https://github.com/HaikuArchives/" + "StreamRadio/blob/master/docs/userguide.md"); userguide.OpenWithPreferredApplication(true); break; @@ -434,8 +414,8 @@ MainWindow::_TogglePlay(StationListViewItem* stationItem) stationItem->StateChanged(StreamPlayer::Playing); fStationList->SelectItem(stationItem); BString success; - success.SetToFormat(B_TRANSLATE("Now playing %s"), - stationItem->GetStation()->Name()->String()); + success.SetToFormat( + B_TRANSLATE("Now playing %s"), stationItem->GetStation()->Name()->String()); fStatusBar->SetText(success); fStatusBar->Invalidate(); fActiveStations.AddItem(stationItem); @@ -445,8 +425,7 @@ MainWindow::_TogglePlay(StationListViewItem* stationItem) BString error; error.SetToFormat(B_TRANSLATE("Failed playing station %s: %s"), - stationItem->GetStation()->Name()->String(), - strerror(status)); + stationItem->GetStation()->Name()->String(), strerror(status)); fStatusBar->SetText(error); } stationItem->SetPlayer(player); diff --git a/source/MainWindow.h b/source/MainWindow.h index af5e631..9c4d3dd 100644 --- a/source/MainWindow.h +++ b/source/MainWindow.h @@ -47,29 +47,29 @@ class MainWindow : public BWindow { public: - MainWindow(); - virtual ~MainWindow(); + MainWindow(); + virtual ~MainWindow(); - virtual void MessageReceived(BMessage* message); - virtual bool QuitRequested(); + virtual void MessageReceived(BMessage* message); + virtual bool QuitRequested(); - virtual void SetVisible(bool visible); + virtual void SetVisible(bool visible); private: - void _Invoke(StationListViewItem* stationItem); - void _TogglePlay(StationListViewItem* stationItem); + void _Invoke(StationListViewItem* stationItem); + void _TogglePlay(StationListViewItem* stationItem); private: - RadioSettings* fSettings; - BMenuBar* fMainMenu; - StationListView* fStationList; - StationFinderWindow* fStationFinder; - StationPanel* fStationPanel; - BStringView* fStatusBar; - BObjectList fActiveStations; - bool fAllowParallelPlayback; - BMenuItem* fMenuParallelPlayback; + RadioSettings* fSettings; + BMenuBar* fMainMenu; + StationListView* fStationList; + StationFinderWindow* fStationFinder; + StationPanel* fStationPanel; + BStringView* fStatusBar; + BObjectList fActiveStations; + bool fAllowParallelPlayback; + BMenuItem* fMenuParallelPlayback; }; -#endif // _MAIN_WINDOW_H +#endif // _MAIN_WINDOW_H diff --git a/source/RadioApp.cpp b/source/RadioApp.cpp index ff019d8..460145e 100644 --- a/source/RadioApp.cpp +++ b/source/RadioApp.cpp @@ -29,17 +29,10 @@ #define B_TRANSLATION_CONTEXT "RadioApp" -RadioApp::RadioApp() - : - BApplication(kAppSignature), - fArgvMessage(NULL) -{ -} +RadioApp::RadioApp() : BApplication(kAppSignature), fArgvMessage(NULL) {} -RadioApp::~RadioApp() -{ -} +RadioApp::~RadioApp() {} void @@ -78,10 +71,11 @@ RadioApp::ArgvReceived(int32 argc, char** argv) for (int32 i = 1; i < argc; i++) { char* arg = argv[i]; if (strncmp(arg, "--help", 7) == 0) { - printf(B_TRANSLATE("Usage: StreamRadio \n" - " should be a Shoutcast playlist file.\n" - "If the station already exists, it is made to play " - "otherwise it is added.\n")); + printf( + B_TRANSLATE("Usage: StreamRadio \n" + " should be a Shoutcast playlist file.\n" + "If the station already exists, it is made to play " + "otherwise it is added.\n")); exit(1); } @@ -107,16 +101,9 @@ RadioApp::ArgvReceived(int32 argc, char** argv) void RadioApp::AboutRequested() { - BAboutWindow * about = new BAboutWindow( - B_TRANSLATE_SYSTEM_NAME("StreamRadio"), kAppSignature); - - const char* kAuthors[] = { - "Fishpond", - "Humdinger", - "Jacob Secunda", - "Javier Steinaker", - NULL - }; + BAboutWindow* about = new BAboutWindow(B_TRANSLATE_SYSTEM_NAME("StreamRadio"), kAppSignature); + + const char* kAuthors[] = {"Fishpond", "Humdinger", "Jacob Secunda", "Javier Steinaker", NULL}; const char* kCopyright = "The HaikuArchives team"; diff --git a/source/RadioApp.h b/source/RadioApp.h index 0738e29..4b21b55 100644 --- a/source/RadioApp.h +++ b/source/RadioApp.h @@ -30,21 +30,21 @@ class RadioApp : BApplication { public: - RadioApp(); - ~RadioApp(); + RadioApp(); + ~RadioApp(); - virtual void ReadyToRun(); - virtual void RefsReceived(BMessage* message); - virtual void ArgvReceived(int32 argc, char** argv); - virtual void AboutRequested(); + virtual void ReadyToRun(); + virtual void RefsReceived(BMessage* message); + virtual void ArgvReceived(int32 argc, char** argv); + virtual void AboutRequested(); - MainWindow* mainWindow; + MainWindow* mainWindow; - RadioSettings Settings; + RadioSettings Settings; private: - BMessage* fArgvMessage; + BMessage* fArgvMessage; }; -#endif // _RADIO_APP_H +#endif // _RADIO_APP_H diff --git a/source/RadioSettings.cpp b/source/RadioSettings.cpp index 5968db0..cd33084 100644 --- a/source/RadioSettings.cpp +++ b/source/RadioSettings.cpp @@ -28,11 +28,7 @@ const char* kSettingsFileName = "StreamRadio.settings"; -StationsList::StationsList() - : - BObjectList() -{ -} +StationsList::StationsList() : BObjectList() {} StationsList::~StationsList() @@ -117,18 +113,14 @@ StationsList::Save() } -RadioSettings::RadioSettings() - : - BMessage() +RadioSettings::RadioSettings() : BMessage() { Stations = new StationsList(); _Load(); } -RadioSettings::RadioSettings(const RadioSettings& orig) - : - BMessage(orig) +RadioSettings::RadioSettings(const RadioSettings& orig) : BMessage(orig) { Stations = new StationsList(); Stations->AddList(orig.Stations); diff --git a/source/RadioSettings.h b/source/RadioSettings.h index 216036e..058e016 100644 --- a/source/RadioSettings.h +++ b/source/RadioSettings.h @@ -27,37 +27,37 @@ class StationsList : public BObjectList { public: - StationsList(); - virtual ~StationsList(); + StationsList(); + virtual ~StationsList(); - virtual bool AddItem(Station* station); - bool RemoveItem(Station* station); - bool RemoveItem(BString* StationName); - Station* FindItem(BString* Name); + virtual bool AddItem(Station* station); + bool RemoveItem(Station* station); + bool RemoveItem(BString* StationName); + Station* FindItem(BString* Name); - status_t Load(); - void Save(); + status_t Load(); + void Save(); }; class RadioSettings : private BMessage { public: - RadioSettings(); - RadioSettings(const RadioSettings& orig); - virtual ~RadioSettings(); + RadioSettings(); + RadioSettings(const RadioSettings& orig); + virtual ~RadioSettings(); - status_t Save(); + status_t Save(); - const char* StationFinderName(); - void SetStationFinderName(const char* name); + const char* StationFinderName(); + void SetStationFinderName(const char* name); - bool GetAllowParallelPlayback(); - void SetAllowParallelPlayback(bool set); + bool GetAllowParallelPlayback(); + void SetAllowParallelPlayback(bool set); - StationsList* Stations; + StationsList* Stations; private: - status_t _Load(); + status_t _Load(); }; -#endif // _RADIO_SETTINGS_H +#endif // _RADIO_SETTINGS_H diff --git a/source/Station.cpp b/source/Station.cpp index 1179f84..64ffe4a 100644 --- a/source/Station.cpp +++ b/source/Station.cpp @@ -19,18 +19,17 @@ #include "Station.h" -#include #include #include #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -45,6 +44,7 @@ #include #include #include +#include #include "Debug.h" #include "HttpUtils.h" @@ -59,24 +59,23 @@ const char* kMimePls = "audio/x-scpls"; Station::Station(BString name, BString uri) - : - fName(name), - fStreamUrl(uri), - fStationUrl(B_EMPTY_STRING), - fGenre(B_EMPTY_STRING), - fCountry(B_EMPTY_STRING), - fLanguage(B_EMPTY_STRING), - fSource(B_EMPTY_STRING), - fMime(B_EMPTY_STRING), - fEncoding(0), - fLogo(NULL), - fRating(0), - fBitRate(0), - fSampleRate(0), - fUniqueIdentifier(B_EMPTY_STRING), - fMetaInterval(0), - fChannels(0), - fFlags(0) + : fName(name), + fStreamUrl(uri), + fStationUrl(B_EMPTY_STRING), + fGenre(B_EMPTY_STRING), + fCountry(B_EMPTY_STRING), + fLanguage(B_EMPTY_STRING), + fSource(B_EMPTY_STRING), + fMime(B_EMPTY_STRING), + fEncoding(0), + fLogo(NULL), + fRating(0), + fBitRate(0), + fSampleRate(0), + fUniqueIdentifier(B_EMPTY_STRING), + fMetaInterval(0), + fChannels(0), + fFlags(0) { CheckFlags(); if (Flags(STATION_URI_VALID) && !Flags(STATION_HAS_FORMAT)) @@ -85,21 +84,20 @@ Station::Station(BString name, BString uri) Station::Station(const Station& orig) - : - fName(orig.fName), - fStreamUrl(orig.fStreamUrl), - fStationUrl(orig.fStationUrl), - fGenre(orig.fGenre), - fCountry(orig.fCountry), - fLanguage(orig.fLanguage), - fSource(B_EMPTY_STRING), - fEncoding(orig.fEncoding), - fRating(orig.fRating), - fBitRate(orig.fBitRate), - fSampleRate(orig.fSampleRate), - fUniqueIdentifier(orig.fUniqueIdentifier), - fMetaInterval(orig.fMetaInterval), - fChannels(orig.fChannels) + : fName(orig.fName), + fStreamUrl(orig.fStreamUrl), + fStationUrl(orig.fStationUrl), + fGenre(orig.fGenre), + fCountry(orig.fCountry), + fLanguage(orig.fLanguage), + fSource(B_EMPTY_STRING), + fEncoding(orig.fEncoding), + fRating(orig.fRating), + fBitRate(orig.fBitRate), + fSampleRate(orig.fSampleRate), + fUniqueIdentifier(orig.fUniqueIdentifier), + fMetaInterval(orig.fMetaInterval), + fChannels(orig.fChannels) { fMime.SetTo(orig.fMime.Type()); fLogo = (orig.fLogo) ? new BBitmap(orig.fLogo) : NULL; @@ -116,8 +114,7 @@ Station::~Station() status_t Station::InitCheck() { - return (fFlags & STATION_HAS_NAME && fFlags & STATION_HAS_URI) ? B_OK - : B_ERROR; + return (fFlags & STATION_HAS_NAME && fFlags & STATION_HAS_URI) ? B_OK : B_ERROR; } @@ -150,39 +147,31 @@ Station::Save() BString content; content << "[playlist]\nNumberOfEntries=1\nFile1=" << fStreamUrl << "\n"; - stationFile.Write( - content.LockBuffer(-1), content.CountBytes(0, content.CountChars())); + stationFile.Write(content.LockBuffer(-1), content.CountBytes(0, content.CountChars())); content.UnlockBuffer(); status = stationFile.Lock(); status = stationFile.WriteAttrString("META:url", &fStreamUrl.UrlString()); - status = stationFile.WriteAttr( - "BEOS:TYPE", B_MIME_TYPE, 0, kMimePls, strlen(kMimePls)); - status = stationFile.WriteAttr( - "META:bitrate", B_INT32_TYPE, 0, &fBitRate, sizeof(fBitRate)); + status = stationFile.WriteAttr("BEOS:TYPE", B_MIME_TYPE, 0, kMimePls, strlen(kMimePls)); + status = stationFile.WriteAttr("META:bitrate", B_INT32_TYPE, 0, &fBitRate, sizeof(fBitRate)); status = stationFile.WriteAttr( "META:samplerate", B_INT32_TYPE, 0, &fSampleRate, sizeof(fSampleRate)); + status = stationFile.WriteAttr("META:channels", B_INT32_TYPE, 0, &fChannels, sizeof(fChannels)); + status = + stationFile.WriteAttr("META:framesize", B_INT32_TYPE, 0, &fFrameSize, sizeof(fFrameSize)); + status = stationFile.WriteAttr("META:rating", B_INT32_TYPE, 0, &fRating, sizeof(fRating)); status = stationFile.WriteAttr( - "META:channels", B_INT32_TYPE, 0, &fChannels, sizeof(fChannels)); - status = stationFile.WriteAttr( - "META:framesize", B_INT32_TYPE, 0, &fFrameSize, sizeof(fFrameSize)); - status = stationFile.WriteAttr( - "META:rating", B_INT32_TYPE, 0, &fRating, sizeof(fRating)); - status = stationFile.WriteAttr("META:interval", B_INT32_TYPE, 0, - &fMetaInterval, sizeof(fMetaInterval)); + "META:interval", B_INT32_TYPE, 0, &fMetaInterval, sizeof(fMetaInterval)); status = stationFile.WriteAttrString("META:genre", &fGenre); status = stationFile.WriteAttrString("META:country", &fCountry); status = stationFile.WriteAttrString("META:language", &fLanguage); status = stationFile.WriteAttrString("META:source", &fSource.UrlString()); - status = stationFile.WriteAttrString( - "META:stationurl", &fStationUrl.UrlString()); + status = stationFile.WriteAttrString("META:stationurl", &fStationUrl.UrlString()); BString mimeType(fMime.Type()); status = stationFile.WriteAttrString("META:mime", &mimeType); - status = stationFile.WriteAttr( - "META:encoding", B_INT32_TYPE, 0, &fEncoding, sizeof(fEncoding)); - status = stationFile.WriteAttrString("META:uniqueidentifier", - &fUniqueIdentifier); + status = stationFile.WriteAttr("META:encoding", B_INT32_TYPE, 0, &fEncoding, sizeof(fEncoding)); + status = stationFile.WriteAttrString("META:uniqueidentifier", &fUniqueIdentifier); status = stationFile.Unlock(); BNodeInfo stationInfo; @@ -196,8 +185,7 @@ Station::Save() stationFile.WriteAttr("logo", 'BBMP', 0LL, archiveBuffer, archiveSize); free(archiveBuffer); - BBitmap* icon = new BBitmap( - BRect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1), B_RGB32, true); + BBitmap* icon = new BBitmap(BRect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1), B_RGB32, true); BView* canvas = new BView(icon->Bounds(), "canvas", B_FOLLOW_NONE, 0); icon->AddChild(canvas); @@ -213,8 +201,7 @@ Station::Save() canvas->ResizeTo(16, 16); icon->AddChild(canvas); canvas->LockLooper(); - canvas->DrawBitmap( - fLogo, fLogo->Bounds(), icon->Bounds(), B_FILTER_BITMAP_BILINEAR); + canvas->DrawBitmap(fLogo, fLogo->Bounds(), icon->Bounds(), B_FILTER_BITMAP_BILINEAR); canvas->UnlockLooper(); icon->RemoveChild(canvas); stationInfo.SetIcon(icon, B_MINI_ICON); @@ -239,10 +226,9 @@ Station::RetrieveStreamUrl() status_t status = B_ERROR; BString contentType("*/*"); - BMallocIO* plsData = HttpUtils::GetAll(fSource, NULL, 100000, &contentType, - 2000); + BMallocIO* plsData = HttpUtils::GetAll(fSource, NULL, 100000, &contentType, 2000); if (plsData != NULL) { - status = ParseUrlReference((const char*) plsData->Buffer(), fSource); + status = ParseUrlReference((const char*)plsData->Buffer(), fSource); delete plsData; } @@ -287,16 +273,14 @@ Station::Probe() // IP's should be small, anyway. if (fStreamUrl.Protocol() == "https") { - buffer = HttpUtils::GetAll(fStreamUrl, &headers, 2 * 1000 * 1000, - &contentType, 4096); + buffer = HttpUtils::GetAll(fStreamUrl, &headers, 2 * 1000 * 1000, &contentType, 4096); } else { BUrl resolvedUrl; status_t resolveStatus = HttpUtils::CheckPort(fStreamUrl, &resolvedUrl); if (resolveStatus != B_OK) return B_ERROR; - buffer = HttpUtils::GetAll( - resolvedUrl, &headers, 2 * 1000 * 1000, &contentType, 4096); + buffer = HttpUtils::GetAll(resolvedUrl, &headers, 2 * 1000 * 1000, &contentType, 4096); } #ifdef DEBUGGING @@ -329,8 +313,7 @@ Station::Probe() if ((index = headers.HasHeader("Icy-Genre")) >= 0) fGenre = headers[index].Value(); - if ((index = headers.HasHeader("Icy-Url")) >= 0 - && strlen(headers[index].Value()) > 0) + if ((index = headers.HasHeader("Icy-Url")) >= 0 && strlen(headers[index].Value()) > 0) fStationUrl.SetUrlString(headers[index].Value()); if ((index = headers.HasHeader("Ice-Audio-Info")) >= 0) { @@ -408,10 +391,10 @@ Station::ProbeBuffer(BPositionIO* buffer) status_t Station::ParseUrlReference(const char* body, const BUrl& baseUrl) { - const char* patterns[4] = {"^file[0-9]+=([^\r\n]*)[\r\n$]+", // ShoutcastUrl - "^(http://[^\r\n]*)[\r\n]+$", // Mpeg Url; - "^([^#]+[^\r\n]*)[\r\n]+$", // Mpeg Url; - "^title[0-9]+=([^\r\n]*)[\r\n$]+"}; // Shoutcast alternativ; + const char* patterns[4] = {"^file[0-9]+=([^\r\n]*)[\r\n$]+", // ShoutcastUrl + "^(http://[^\r\n]*)[\r\n]+$", // Mpeg Url; + "^([^#]+[^\r\n]*)[\r\n]+$", // Mpeg Url; + "^title[0-9]+=([^\r\n]*)[\r\n$]+"}; // Shoutcast alternativ; for (int32 i = 0; i < 3; i++) { char* match = RegFind(body, patterns[i]); @@ -460,26 +443,26 @@ Station::Load(BString name, BEntry* entry) status = file.ReadAttrString("META:language", &station->fLanguage); - status = file.ReadAttr("META:bitrate", B_INT32_TYPE, 0, &station->fBitRate, - sizeof(station->fBitRate)); + status = file.ReadAttr( + "META:bitrate", B_INT32_TYPE, 0, &station->fBitRate, sizeof(station->fBitRate)); - status = file.ReadAttr("META:rating", B_INT32_TYPE, 0, &station->fRating, - sizeof(station->fRating)); + status = + file.ReadAttr("META:rating", B_INT32_TYPE, 0, &station->fRating, sizeof(station->fRating)); - status = file.ReadAttr("META:interval", B_INT32_TYPE, 0, - &station->fMetaInterval, sizeof(station->fMetaInterval)); + status = file.ReadAttr( + "META:interval", B_INT32_TYPE, 0, &station->fMetaInterval, sizeof(station->fMetaInterval)); - status = file.ReadAttr("META:samplerate", B_INT32_TYPE, 0, - &station->fSampleRate, sizeof(station->fSampleRate)); + status = file.ReadAttr( + "META:samplerate", B_INT32_TYPE, 0, &station->fSampleRate, sizeof(station->fSampleRate)); - status = file.ReadAttr("META:channels", B_INT32_TYPE, 0, - &station->fChannels, sizeof(station->fChannels)); + status = file.ReadAttr( + "META:channels", B_INT32_TYPE, 0, &station->fChannels, sizeof(station->fChannels)); - status = file.ReadAttr("META:encoding", B_INT32_TYPE, 0, - &station->fEncoding, sizeof(station->fEncoding)); + status = file.ReadAttr( + "META:encoding", B_INT32_TYPE, 0, &station->fEncoding, sizeof(station->fEncoding)); - status = file.ReadAttr("META:framesize", B_INT32_TYPE, 0, - &station->fFrameSize, sizeof(station->fFrameSize)); + status = file.ReadAttr( + "META:framesize", B_INT32_TYPE, 0, &station->fFrameSize, sizeof(station->fFrameSize)); status = file.ReadAttrString("META:mime", &readString); station->fMime.SetTo(readString); @@ -496,12 +479,12 @@ Station::Load(BString name, BEntry* entry) attr_info attrInfo; status = file.GetAttrInfo("logo", &attrInfo); if (status == B_OK) { - char* archiveBuffer = (char*) malloc(attrInfo.size); + char* archiveBuffer = (char*)malloc(attrInfo.size); file.ReadAttr("logo", attrInfo.type, 0LL, archiveBuffer, attrInfo.size); BMessage archive; archive.Unflatten(archiveBuffer); free(archiveBuffer); - station->fLogo = (BBitmap*) BBitmap::Instantiate(&archive); + station->fLogo = (BBitmap*)BBitmap::Instantiate(&archive); } else { station->fLogo = new BBitmap(BRect(0, 0, 32, 32), B_RGB32); status = stationInfo.GetIcon(station->fLogo, B_LARGE_ICON); @@ -558,12 +541,10 @@ Station::RegFind(const char* text, const char* pattern) memset(&patternBuffer, 0, sizeof(patternBuffer)); memset(matchBuffer, 0, sizeof(matchBuffer)); - result = regcomp( - &patternBuffer, pattern, REG_EXTENDED | REG_NEWLINE | REG_ICASE); + result = regcomp(&patternBuffer, pattern, REG_EXTENDED | REG_NEWLINE | REG_ICASE); result = regexec(&patternBuffer, text, 20, matchBuffer, 0); if (result == 0 && matchBuffer[1].rm_eo > -1) { - match = strndup(text + matchBuffer[1].rm_so, - matchBuffer[1].rm_eo - matchBuffer[1].rm_so); + match = strndup(text + matchBuffer[1].rm_so, matchBuffer[1].rm_eo - matchBuffer[1].rm_so); } regfree(&patternBuffer); @@ -580,8 +561,7 @@ Station::LoadIndirectUrl(BString& shoutCastUrl) status_t status; const char* patternTitle = "]*>(.*?)]*>"; - const char* patternIcon - = "fStationUrl; - if ((!finalUrl.HasPort() || finalUrl.Port() == 80) - && (!finalUrl.HasPath() || finalUrl.Path().IsEmpty() - || finalUrl.Path() == "/")) { + if ((!finalUrl.HasPort() || finalUrl.Port() == 80) && + (!finalUrl.HasPath() || finalUrl.Path().IsEmpty() || finalUrl.Path() == "/")) { if (station->fName.IsEmpty()) station->SetName("New Station"); } else @@ -639,7 +618,7 @@ Station::LoadIndirectUrl(BString& shoutCastUrl) dataIO = HttpUtils::GetAll(finalUrl); if (dataIO != NULL) { dataIO->Write(&"", 1); - body = (char*) dataIO->Buffer(); + body = (char*)dataIO->Buffer(); char* title = RegFind(body, patternTitle); if (title != NULL) { station->fName.SetTo(title); @@ -654,8 +633,7 @@ Station::LoadIndirectUrl(BString& shoutCastUrl) contentType = "image/*"; - BMallocIO* iconIO - = HttpUtils::GetAll(finalUrl, NULL, 10000, &contentType, 2000); + BMallocIO* iconIO = HttpUtils::GetAll(finalUrl, NULL, 10000, &contentType, 2000); if (iconIO != NULL) { iconIO->Seek(0, SEEK_SET); station->fLogo = BTranslationUtils::GetBitmap(iconIO); @@ -701,9 +679,8 @@ Station::SetName(BString name) void Station::CleanName() { - if (fName.Compare("(#", 2) == 0 - && fName.FindFirst(')') >= 0 - && fName.FindFirst(')') < fName.Length()) + if (fName.Compare("(#", 2) == 0 && fName.FindFirst(')') >= 0 && + fName.FindFirst(')') < fName.Length()) fName.Remove(0, fName.FindFirst(')') + 1).Trim(); fName.RemoveCharsSet("\\/#?"); @@ -763,10 +740,9 @@ Station::StationDirectory() configDir.CreateDirectory(kSubDirStations, sStationsDirectory); BAlert* alert = new BAlert(B_TRANSLATE("Stations directory created"), - B_TRANSLATE( - "A directory for saving stations has been created in your " - "settings folder. Link this directory to your deskbar menu " - "to play stations directly."), + B_TRANSLATE("A directory for saving stations has been created in your " + "settings folder. Link this directory to your deskbar menu " + "to play stations directly."), B_TRANSLATE("OK")); alert->Go(); } diff --git a/source/Station.h b/source/Station.h index 5556108..e397971 100644 --- a/source/Station.h +++ b/source/Station.h @@ -36,7 +36,7 @@ #define STATION_URI_VALID 4 #define STATION_HAS_ENCODING 8 #define STATION_HAS_BITRATE 16 -#define STATION_HAS_FORMAT 32 // frame rate and channels +#define STATION_HAS_FORMAT 32 // frame rate and channels #define STATION_HAS_META 64 #define STATION_HAS_IDENTIFIER 128 @@ -46,52 +46,51 @@ class StreamPlayer; class Station { public: - Station(BString name, - BString uri = B_EMPTY_STRING); - Station(const Station& orig); - virtual ~Station(); + Station(BString name, BString uri = B_EMPTY_STRING); + Station(const Station& orig); + virtual ~Station(); - status_t InitCheck(); - status_t Save(); - status_t RetrieveStreamUrl(); - status_t Probe(); - status_t ProbeBuffer(BPositionIO* buffer); + status_t InitCheck(); + status_t Save(); + status_t RetrieveStreamUrl(); + status_t Probe(); + status_t ProbeBuffer(BPositionIO* buffer); - static class Station* LoadFromPlsFile(BString name); - static class Station* Load(BString name, BEntry* entry); - static class Station* LoadIndirectUrl(BString& shoutCastUrl); + static class Station* LoadFromPlsFile(BString name); + static class Station* Load(BString name, BEntry* entry); + static class Station* LoadIndirectUrl(BString& shoutCastUrl); - static BDirectory* StationDirectory(); + static BDirectory* StationDirectory(); - inline BString* Name() { return &fName; } - void SetName(BString name); + inline BString* Name() { return &fName; } + void SetName(BString name); - inline BUrl StreamUrl() { return fStreamUrl; } - inline void SetStreamUrl(BUrl uri) + inline BUrl StreamUrl() { return fStreamUrl; } + inline void SetStreamUrl(BUrl uri) { fStreamUrl = uri; CheckFlags(); fUnsaved = true; } - inline BUrl StationUrl() { return fStationUrl; } - inline void SetStation(BUrl url) + inline BUrl StationUrl() { return fStationUrl; } + inline void SetStation(BUrl url) { fStationUrl = url; CheckFlags(); fUnsaved = true; } - inline BUrl Source() { return fSource; } - inline void SetSource(BUrl source) + inline BUrl Source() { return fSource; } + inline void SetSource(BUrl source) { fSource = source; CheckFlags(); fUnsaved = true; } - inline BBitmap* Logo() { return fLogo; } - inline void SetLogo(BBitmap* logo) + inline BBitmap* Logo() { return fLogo; } + inline void SetLogo(BBitmap* logo) { delete fLogo; @@ -99,82 +98,80 @@ class Station { fUnsaved = true; } - inline BString Genre() { return fGenre; } - inline void SetGenre(BString genre) + inline BString Genre() { return fGenre; } + inline void SetGenre(BString genre) { fGenre.SetTo(genre); fUnsaved = true; } - inline BString Country() { return fCountry; } - inline void SetCountry(BString country) + inline BString Country() { return fCountry; } + inline void SetCountry(BString country) { fCountry.SetTo(country); fUnsaved = true; } - inline BString Language() { return fLanguage; } - inline void SetLanguage(BString language) + inline BString Language() { return fLanguage; } + inline void SetLanguage(BString language) { fLanguage.SetTo(language); fUnsaved = true; } - inline int32 SampleRate() { return fSampleRate; } - inline int32 BitRate() { return fBitRate; } - inline void SetBitRate(int32 bitrate) + inline int32 SampleRate() { return fSampleRate; } + inline int32 BitRate() { return fBitRate; } + inline void SetBitRate(int32 bitrate) { fBitRate = bitrate; fUnsaved = true; } - inline BString UniqueIdentifier() { return fUniqueIdentifier; } - inline void SetUniqueIdentifier(BString uniqueIdentifier) + inline BString UniqueIdentifier() { return fUniqueIdentifier; } + inline void SetUniqueIdentifier(BString uniqueIdentifier) { fUniqueIdentifier.SetTo(uniqueIdentifier); fUnsaved = true; } - inline int32 Channels() { return fChannels; } - inline int32 Encoding() { return fEncoding; } - inline size_t FrameSize() { return fFrameSize; } - inline BMimeType* Mime() { return &fMime; } + inline int32 Channels() { return fChannels; } + inline int32 Encoding() { return fEncoding; } + inline size_t FrameSize() { return fFrameSize; } + inline BMimeType* Mime() { return &fMime; } - inline int32 Flags() { return fFlags; } - inline bool Flags(uint32 flags) - { return (fFlags & flags) == flags; } + inline int32 Flags() { return fFlags; } + inline bool Flags(uint32 flags) { return (fFlags & flags) == flags; } protected: - void CheckFlags(); - static char* RegFind(const char* text, const char* pattern); - status_t ParseUrlReference(const char* body, - const BUrl& baseUrl); - void CleanName(); - - BString fName; - BUrl fStreamUrl; - BUrl fStationUrl; - BString fGenre; - BString fCountry; - BString fLanguage; - BUrl fSource; - BMimeType fMime; - uint32 fEncoding; - BBitmap* fLogo; - uint32 fRating; - uint32 fBitRate; - uint32 fSampleRate; - BString fUniqueIdentifier; - uint32 fMetaInterval; - uint32 fChannels; - uint32 fFlags; - size_t fFrameSize; - - static BDirectory* sStationsDirectory; + void CheckFlags(); + static char* RegFind(const char* text, const char* pattern); + status_t ParseUrlReference(const char* body, const BUrl& baseUrl); + void CleanName(); + + BString fName; + BUrl fStreamUrl; + BUrl fStationUrl; + BString fGenre; + BString fCountry; + BString fLanguage; + BUrl fSource; + BMimeType fMime; + uint32 fEncoding; + BBitmap* fLogo; + uint32 fRating; + uint32 fBitRate; + uint32 fSampleRate; + BString fUniqueIdentifier; + uint32 fMetaInterval; + uint32 fChannels; + uint32 fFlags; + size_t fFrameSize; + + static BDirectory* sStationsDirectory; private: - bool fUnsaved; + bool fUnsaved; }; -#endif // _STATION_H +#endif // _STATION_H diff --git a/source/StationFinder.cpp b/source/StationFinder.cpp index 7f71048..b5b58b4 100644 --- a/source/StationFinder.cpp +++ b/source/StationFinder.cpp @@ -1,7 +1,4 @@ #include "StationFinder.h" -#include "HttpUtils.h" -#include "RadioApp.h" -#include "Utils.h" #include #include #include @@ -10,14 +7,16 @@ #include #include #include +#include "HttpUtils.h" +#include "RadioApp.h" +#include "Utils.h" #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "StationFinder" -std::vector > - StationFinderServices::sServices; +std::vector > StationFinderServices::sServices; StationFinderServices::~StationFinderServices() @@ -61,18 +60,11 @@ StationFinderServices::Name(int i) } -FindByCapability::FindByCapability(char* name) - : - fName(name), - fKeywords() -{ -} +FindByCapability::FindByCapability(char* name) : fName(name), fKeywords() {} FindByCapability::FindByCapability(char* name, char* keyWords, char* delimiter) - : - fName(name), - fKeywords() + : fName(name), fKeywords() { SetKeyWords(keyWords, delimiter); } @@ -114,11 +106,7 @@ FindByCapability::SetKeyWords(char* keyWords, char* delimiter) StationFinderService::StationFinderService() - : - serviceName("unknown"), - serviceHomePage(""), - serviceLogo(NULL), - findByCapabilities(5, true) + : serviceName("unknown"), serviceHomePage(""), serviceLogo(NULL), findByCapabilities(5, true) { } @@ -169,11 +157,9 @@ StationFinderService::RegisterSearchCapability(char* name) FindByCapability* -StationFinderService::RegisterSearchCapability( - char* name, char* keywords, char* delimiter) +StationFinderService::RegisterSearchCapability(char* name, char* keywords, char* delimiter) { - FindByCapability* newCapability - = new FindByCapability(name, keywords, delimiter); + FindByCapability* newCapability = new FindByCapability(name, keywords, delimiter); findByCapabilities.AddItem(newCapability); return newCapability; @@ -181,10 +167,9 @@ StationFinderService::RegisterSearchCapability( StationFinderWindow::StationFinderWindow(BWindow* parent) - : - BWindow(BRect(0, 0, 300, 150), B_TRANSLATE("Find stations"), - B_TITLED_WINDOW, B_CLOSE_ON_ESCAPE), - fCurrentService(NULL) + : BWindow( + BRect(0, 0, 300, 150), B_TRANSLATE("Find stations"), B_TITLED_WINDOW, B_CLOSE_ON_ESCAPE), + fCurrentService(NULL) { fMessenger = new BMessenger(parent); @@ -197,11 +182,9 @@ StationFinderWindow::StationFinderWindow(BWindow* parent) fBnSearch = new BButton("fBnSearch", NULL, new BMessage(MSG_BNSEARCH)); fBnSearch->SetIcon(Utils::ResourceBitmap(RES_BN_SEARCH)); - fDdServices = new BOptionPopUp( - "fDdServices", NULL, new BMessage(MSG_SELECT_SERVICE)); + fDdServices = new BOptionPopUp("fDdServices", NULL, new BMessage(MSG_SELECT_SERVICE)); int currentServiceIndex = 0; - const char* settingsServiceName - = ((RadioApp*)be_app)->Settings.StationFinderName(); + const char* settingsServiceName = ((RadioApp*)be_app)->Settings.StationFinderName(); for (int32 i = 0; i < StationFinderServices::CountItems(); i++) { const char* serviceName = StationFinderServices::Name(i); if (settingsServiceName && !strcmp(serviceName, settingsServiceName)) @@ -212,43 +195,38 @@ StationFinderWindow::StationFinderWindow(BWindow* parent) fBnVisit = new BButton("fBnVisit", "", new BMessage(MSG_VISIT_SERVICE)); fBnVisit->SetIcon(Utils::ResourceBitmap(RES_BN_WEB)); - fDdSearchBy - = new BOptionPopUp("fDdSearchBy", NULL, new BMessage(MSG_SEARCH_BY)); + fDdSearchBy = new BOptionPopUp("fDdSearchBy", NULL, new BMessage(MSG_SEARCH_BY)); fResultView = new StationListView(); - fResultView->SetExplicitAlignment( - BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT)); + fResultView->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT)); - fBnAdd = new BButton( - "fBnAdd", B_TRANSLATE("Add"), new BMessage(MSG_ADD_STATION)); + fBnAdd = new BButton("fBnAdd", B_TRANSLATE("Add"), new BMessage(MSG_ADD_STATION)); BLayoutBuilder::Group<>(this, B_VERTICAL, 0) .AddGrid(3, 3, 0.0) - .SetInsets(B_USE_WINDOW_INSETS) - .Add(new BStringView("lbServices", B_TRANSLATE("Service")), 0, 0) - .Add(fDdServices, 1, 0) - .Add(fBnVisit, 2, 0) - - .Add(new BStringView("lbSearchBy", B_TRANSLATE("Search by")), 0, 1) - .Add(fDdSearchBy, 1, 1) - - .Add(new BStringView( - "lbSearchFor", B_TRANSLATE("Search for")), 0, 2) - .Add(fTxSearch, 1, 2) - .Add(fKwSearch, 1, 2) - .Add(fBnSearch, 2, 2) - .GetLayout(&fSearchGrid) + .SetInsets(B_USE_WINDOW_INSETS) + .Add(new BStringView("lbServices", B_TRANSLATE("Service")), 0, 0) + .Add(fDdServices, 1, 0) + .Add(fBnVisit, 2, 0) + + .Add(new BStringView("lbSearchBy", B_TRANSLATE("Search by")), 0, 1) + .Add(fDdSearchBy, 1, 1) + + .Add(new BStringView("lbSearchFor", B_TRANSLATE("Search for")), 0, 2) + .Add(fTxSearch, 1, 2) + .Add(fKwSearch, 1, 2) + .Add(fBnSearch, 2, 2) + .GetLayout(&fSearchGrid) .End() .Add(new BScrollView("srollResult", fResultView, 0, false, true), 0.9) .AddGrid(3, 1, 0.0) - .SetInsets(B_USE_WINDOW_INSETS) - .Add(fBnAdd, 2, 0) - .SetExplicitAlignment( - BAlignment(B_ALIGN_RIGHT, B_ALIGN_VERTICAL_UNSET)) + .SetInsets(B_USE_WINDOW_INSETS) + .Add(fBnAdd, 2, 0) + .SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, B_ALIGN_VERTICAL_UNSET)) .End() - .End(); + .End(); fBnAdd->SetEnabled(false); @@ -289,7 +267,6 @@ StationFinderWindow::QuitRequested() void StationFinderWindow::MessageReceived(BMessage* msg) { - switch (msg->what) { case MSG_BNSEARCH: { @@ -300,7 +277,8 @@ StationFinderWindow::MessageReceived(BMessage* msg) } } else if (fKwSearch->Value() >= 0) { DoSearch(fCurrentService->Capability(fDdSearchBy->Value()) - ->KeyWords()->StringAt(fKwSearch->Value())); + ->KeyWords() + ->StringAt(fKwSearch->Value())); } break; @@ -322,20 +300,17 @@ StationFinderWindow::MessageReceived(BMessage* msg) if (fMessenger->SendMessage(dispatch) == B_OK) { StationListViewItem* item = - (StationListViewItem*) fResultView->RemoveItem(index); + (StationListViewItem*)fResultView->RemoveItem(index); item->ClearStation(); delete item; } } else { BString msg; - msg.SetToFormat( - B_TRANSLATE("Station %s did not respond correctly and " - "could not be added"), + msg.SetToFormat(B_TRANSLATE("Station %s did not respond correctly and " + "could not be added"), station->Name()->String()); - (new BAlert(B_TRANSLATE("Add station failed"), msg, - B_TRANSLATE("OK"))) - ->Go(); + (new BAlert(B_TRANSLATE("Add station failed"), msg, B_TRANSLATE("OK")))->Go(); } } @@ -346,8 +321,7 @@ StationFinderWindow::MessageReceived(BMessage* msg) { Station* st = NULL; if (msg->FindPointer("station", (void**)&st) == B_OK) { - fResultView->InvalidateItem( - fResultView->IndexOf(fResultView->Item(st))); + fResultView->InvalidateItem(fResultView->IndexOf(fResultView->Item(st))); } break; @@ -372,11 +346,9 @@ StationFinderWindow::MessageReceived(BMessage* msg) case MSG_VISIT_SERVICE: { - if (fCurrentService != NULL - && fCurrentService->serviceHomePage != NULL - && fCurrentService->serviceHomePage.IsValid()) - fCurrentService->serviceHomePage.OpenWithPreferredApplication( - true); + if (fCurrentService != NULL && fCurrentService->serviceHomePage != NULL && + fCurrentService->serviceHomePage.IsValid()) + fCurrentService->serviceHomePage.OpenWithPreferredApplication(true); break; } @@ -402,8 +374,7 @@ StationFinderWindow::SelectService(int index) if (serviceName == NULL) return; - StationFinderService* selectedService = StationFinderServices::Instantiate( - serviceName); + StationFinderService* selectedService = StationFinderServices::Instantiate(serviceName); if (selectedService == NULL) return; @@ -472,8 +443,7 @@ StationFinderWindow::DoSearch(const char* text) be_app->SetCursor(new BCursor(B_CURSOR_ID_PROGRESS)); - BObjectList* result - = fCurrentService->FindBy(fDdSearchBy->Value(), text, this); + BObjectList* result = fCurrentService->FindBy(fDdSearchBy->Value(), text, this); if (result != NULL) { for (int32 i = 0; i < result->CountItems(); i++) fResultView->AddItem(new StationListViewItem(result->ItemAt(i))); diff --git a/source/StationFinder.h b/source/StationFinder.h index a90ffd4..822f79d 100644 --- a/source/StationFinder.h +++ b/source/StationFinder.h @@ -55,36 +55,35 @@ typedef class StationFinderService* (*InstantiateFunc)(); class StationFinderServices { public: - StationFinderServices(){}; - ~StationFinderServices(); + StationFinderServices(){}; + ~StationFinderServices(); - static void Register(char* serviceName, InstantiateFunc); + static void Register(char* serviceName, InstantiateFunc); - static StationFinderService* Instantiate(char* s); + static StationFinderService* Instantiate(char* s); - static int32 CountItems(); - static char* Name(int i); + static int32 CountItems(); + static char* Name(int i); private: - static std::vector > sServices; + static std::vector > sServices; }; class FindByCapability { public: - FindByCapability(char* name); - FindByCapability(char* name, char* keyWords, - char* delimiter); - ~FindByCapability(); + FindByCapability(char* name); + FindByCapability(char* name, char* keyWords, char* delimiter); + ~FindByCapability(); - bool HasKeyWords(); - void SetKeyWords(char* keyWords, char* delimiter); - const BStringList* KeyWords(); + bool HasKeyWords(); + void SetKeyWords(char* keyWords, char* delimiter); + const BStringList* KeyWords(); - const char* Name(); + const char* Name(); private: - BString fName; - BStringList fKeywords; + BString fName; + BStringList fKeywords; }; class StationFinderService { @@ -92,68 +91,63 @@ class StationFinderService { public: // Overridden in specific StationFinder implementations - StationFinderService(); - virtual ~StationFinderService(); + StationFinderService(); + virtual ~StationFinderService(); - static void RegisterSelf(); - static StationFinderService* Instantiate(); + static void RegisterSelf(); + static StationFinderService* Instantiate(); - virtual BObjectList* FindBy(int capabilityIndex, - const char* searchFor, - BLooper* resultUpdateTarget) = 0; + virtual BObjectList* FindBy( + int capabilityIndex, const char* searchFor, BLooper* resultUpdateTarget) = 0; // Provided by ancestor class - const char* Name() const { return serviceName.String(); } + const char* Name() const { return serviceName.String(); } - int CountCapabilities() const - { return findByCapabilities.CountItems(); } - FindByCapability* Capability(int index) const - { return findByCapabilities.ItemAt(index); } + int CountCapabilities() const { return findByCapabilities.CountItems(); } + FindByCapability* Capability(int index) const { return findByCapabilities.ItemAt(index); } - static void Register(char* name, - InstantiateFunc instantiate); + static void Register(char* name, InstantiateFunc instantiate); protected: - // To be filled by specific StationFinder implementations - BString serviceName; - BUrl serviceHomePage; - BBitmap* serviceLogo; - BObjectList findByCapabilities; - - // Helper functions - BBitmap* RetrieveLogo(BUrl url); - FindByCapability* RegisterSearchCapability(char* name); - FindByCapability* RegisterSearchCapability(char* name, - char* keyWords, char* delimiter); + // To be filled by specific StationFinder implementations + BString serviceName; + BUrl serviceHomePage; + BBitmap* serviceLogo; + BObjectList findByCapabilities; + + // Helper functions + BBitmap* RetrieveLogo(BUrl url); + FindByCapability* RegisterSearchCapability(char* name); + FindByCapability* RegisterSearchCapability(char* name, char* keyWords, char* delimiter); }; class StationFinderWindow : public BWindow { public: - StationFinderWindow(BWindow* parent); - virtual ~StationFinderWindow(); + StationFinderWindow(BWindow* parent); + virtual ~StationFinderWindow(); - void MessageReceived(BMessage* msg); - virtual bool QuitRequested(); + void MessageReceived(BMessage* msg); + virtual bool QuitRequested(); - void SelectService(int index); - void SelectCapability(int index); - void DoSearch(const char* text); + void SelectService(int index); + void SelectCapability(int index); + void DoSearch(const char* text); private: - StationFinderService* fCurrentService; - - BMessenger* fMessenger; - BTextControl* fTxSearch; - BOptionPopUp* fKwSearch; - BButton* fBnSearch; - BOptionPopUp* fDdServices; - BButton* fBnVisit; - BOptionPopUp* fDdSearchBy; - StationListView* fResultView; - BButton* fBnAdd; - - BGridLayout* fSearchGrid; + StationFinderService* fCurrentService; + + BMessenger* fMessenger; + BTextControl* fTxSearch; + BOptionPopUp* fKwSearch; + BButton* fBnSearch; + BOptionPopUp* fDdServices; + BButton* fBnVisit; + BOptionPopUp* fDdSearchBy; + StationListView* fResultView; + BButton* fBnAdd; + + BGridLayout* fSearchGrid; }; -#endif // _STATION_FINDER_H +#endif // _STATION_FINDER_H diff --git a/source/StationFinderListenLive.cpp b/source/StationFinderListenLive.cpp index faf864c..a5046d8 100644 --- a/source/StationFinderListenLive.cpp +++ b/source/StationFinderListenLive.cpp @@ -30,7 +30,8 @@ #define B_TRANSLATION_CONTEXT "StationFinderListenLive" -const char* kGenreList = "Top 40|top40\r\ +const char* kGenreList = + "Top 40|top40\r\ Hot Adult Contemporary|hotac\r\ Adult Contemporary|ac\r\ Oldies/80s/90s|oldies\r\ @@ -41,7 +42,8 @@ Rock/Classic Rock|rock\r\ Alternative|alternative\r\ Chillout/Lounge|chillout"; -const char* kCountryList = "Andorra|andorra\r\ +const char* kCountryList = + "Andorra|andorra\r\ Armenia|armenia\r\ Austria|austria\r\ Azerbaijan|azerbaijan\r\ @@ -97,12 +99,11 @@ const char* StationFinderListenLive::kBaseUrl = "http://listenlive.eu/"; StationFinderListenLive::StationFinderListenLive() - : - StationFinderService(), - fCountryKeywordAndPath(), - fGenreKeywordAndPath(), - fLookupThread(-1), - fPlsLookupList() + : StationFinderService(), + fCountryKeywordAndPath(), + fGenreKeywordAndPath(), + fLookupThread(-1), + fPlsLookupList() { serviceName.SetTo(B_TRANSLATE("listenlive.eu [experimental]")); serviceHomePage.SetUrlString("http://www.listenlive.eu/"); @@ -139,8 +140,7 @@ StationFinderListenLive::Instantiate() void StationFinderListenLive::RegisterSelf() { - Register( - "listenlive.eu [experimental]", &StationFinderListenLive::Instantiate); + Register("listenlive.eu [experimental]", &StationFinderListenLive::Instantiate); } @@ -155,8 +155,8 @@ StationFinderListenLive::~StationFinderListenLive() BObjectList* -StationFinderListenLive::FindBy(int capabilityIndex, const char* searchFor, - BLooper* resultUpdateTarget) +StationFinderListenLive::FindBy( + int capabilityIndex, const char* searchFor, BLooper* resultUpdateTarget) { if (fLookupThread >= 0) suspend_thread(fLookupThread); @@ -168,10 +168,9 @@ StationFinderListenLive::FindBy(int capabilityIndex, const char* searchFor, BString urlString(kBaseUrl); strlwr((char*)searchFor); - int keywordIndex - = Capability(capabilityIndex)->KeyWords()->IndexOf(searchFor); - BStringList* keywordAndPaths - = capabilityIndex ? &fGenreKeywordAndPath : &fCountryKeywordAndPath; + int keywordIndex = Capability(capabilityIndex)->KeyWords()->IndexOf(searchFor); + BStringList* keywordAndPaths = + capabilityIndex ? &fGenreKeywordAndPath : &fCountryKeywordAndPath; BString path(keywordAndPaths->StringAt(keywordIndex)); path.Remove(0, path.FindFirst('|') + 1); urlString << path << ".html"; @@ -180,11 +179,11 @@ StationFinderListenLive::FindBy(int capabilityIndex, const char* searchFor, BMallocIO* data = HttpUtils::GetAll(url); if (data != NULL) { switch (capabilityIndex) { - case 0: // findByCountry + case 0: // findByCountry result = ParseCountryReturn(data, searchFor); break; - case 1: // findByGenre + case 1: // findByGenre result = ParseGenreReturn(data, searchFor); break; } @@ -195,8 +194,7 @@ StationFinderListenLive::FindBy(int capabilityIndex, const char* searchFor, if (!fPlsLookupList.IsEmpty()) { if (fLookupThread < 0) - fLookupThread = spawn_thread( - &_PlsLookupFunc, "plslookup", B_NORMAL_PRIORITY, this); + fLookupThread = spawn_thread(&_PlsLookupFunc, "plslookup", B_NORMAL_PRIORITY, this); resume_thread(fLookupThread); } @@ -205,8 +203,7 @@ StationFinderListenLive::FindBy(int capabilityIndex, const char* searchFor, BObjectList* -StationFinderListenLive::ParseCountryReturn( - BMallocIO* data, const char* searchFor) +StationFinderListenLive::ParseCountryReturn(BMallocIO* data, const char* searchFor) { BObjectList* result = new BObjectList(20, true); if (result == NULL) @@ -219,9 +216,9 @@ StationFinderListenLive::ParseCountryReturn( // ORF Ö-1 // Vienna // Windows
-	//Media
MP3 + // Media">
MP3 // 128 Kbps
192 Kbps + // href="http://mp3stream3.apasf.apa.at:8000/listen.pls">192 Kbps // Information/Culture // @@ -233,8 +230,8 @@ StationFinderListenLive::ParseCountryReturn( "\\s*([^<]*)([^<]|<[^/]|\\s*" "([^<]*)\\s*", - RE_ICASE | RE_DOT_NEWLINE | RE_DOT_NOT_NULL | RE_NO_BK_PARENS - | RE_NO_BK_VBAR | RE_BACKSLASH_ESCAPE_IN_LISTS); + RE_ICASE | RE_DOT_NEWLINE | RE_DOT_NOT_NULL | RE_NO_BK_PARENS | RE_NO_BK_VBAR | + RE_BACKSLASH_ESCAPE_IN_LISTS); char* doc = (char*)data->Buffer(); off_t size; @@ -249,9 +246,8 @@ StationFinderListenLive::ParseCountryReturn( doc[matches[6].rm_eo] = 0; doc[matches[8].rm_eo] = 0; printf("Station %s at %s in %s address %s, data rate=%s, genre=%s\n", - doc + matches[2].rm_so, doc + matches[1].rm_so, - doc + matches[3].rm_so, doc + matches[5].rm_so, - doc + matches[6].rm_so, doc + matches[8].rm_so); + doc + matches[2].rm_so, doc + matches[1].rm_so, doc + matches[3].rm_so, + doc + matches[5].rm_so, doc + matches[6].rm_so, doc + matches[8].rm_so); Station* station = new Station(doc + matches[2].rm_so, NULL); if (station == NULL) @@ -291,8 +287,7 @@ StationFinderListenLive::ParseCountryReturn( BObjectList* -StationFinderListenLive::ParseGenreReturn( - BMallocIO* data, const char* searchFor) +StationFinderListenLive::ParseGenreReturn(BMallocIO* data, const char* searchFor) { BObjectList* result = new BObjectList(20, true); if (result == NULL) @@ -305,19 +300,19 @@ StationFinderListenLive::ParseGenreReturn( // ORF Ö-1 // Vienna // Windows
-	//Media
MP3 + // Media">
MP3 // 128 Kbps
192 Kbps + // href="http://mp3stream3.apasf.apa.at:8000/listen.pls">192 Kbps // Information/Culture // // // Radio - //Stephansdom Vienna Austria MP3
32 Kbps, 56 Kbps
128 Kbps + // Stephansdom Vienna Austria MP3
32 Kbps, 56 Kbps
128 Kbps // int res = regcomp(®ex, @@ -329,8 +324,8 @@ StationFinderListenLive::ParseGenreReturn( "\\s*([^<]*)([^<]|<[^/]|\\s*" "", - RE_ICASE | RE_DOT_NEWLINE | RE_DOT_NOT_NULL | RE_NO_BK_PARENS - | RE_NO_BK_VBAR | RE_BACKSLASH_ESCAPE_IN_LISTS); + RE_ICASE | RE_DOT_NEWLINE | RE_DOT_NOT_NULL | RE_NO_BK_PARENS | RE_NO_BK_VBAR | + RE_BACKSLASH_ESCAPE_IN_LISTS); char* doc = (char*)data->Buffer(); off_t size; @@ -344,11 +339,9 @@ StationFinderListenLive::ParseGenreReturn( doc[matches[4].rm_eo] = 0; doc[matches[6].rm_eo] = 0; doc[matches[7].rm_eo] = 0; - printf( - "Station %s at %s in %s - %s address %s, data rate=%s, genre=%s\n", - doc + matches[2].rm_so, doc + matches[1].rm_so, - doc + matches[3].rm_so, doc + matches[4].rm_so, - doc + matches[6].rm_so, doc + matches[7].rm_so, searchFor); + printf("Station %s at %s in %s - %s address %s, data rate=%s, genre=%s\n", + doc + matches[2].rm_so, doc + matches[1].rm_so, doc + matches[3].rm_so, + doc + matches[4].rm_so, doc + matches[6].rm_so, doc + matches[7].rm_so, searchFor); Station* station = new Station(doc + matches[2].rm_so, NULL); if (station == NULL) @@ -392,11 +385,10 @@ StationFinderListenLive::_PlsLookupFunc(void* data) StationFinderListenLive* _this = (StationFinderListenLive*)data; while (!_this->fPlsLookupList.IsEmpty()) { Station* station = _this->fPlsLookupList.FirstItem(); - TRACE("Looking up stream URL for station %s in %s\n", - station->Name()->String(), station->Source().UrlString().String()); + TRACE("Looking up stream URL for station %s in %s\n", station->Name()->String(), + station->Source().UrlString().String()); - Station* plsStation = Station::LoadIndirectUrl( - (BString&)station->Source().UrlString()); + Station* plsStation = Station::LoadIndirectUrl((BString&)station->Source().UrlString()); if (plsStation != NULL) station->SetStreamUrl(plsStation->StreamUrl()); diff --git a/source/StationFinderListenLive.h b/source/StationFinderListenLive.h index 662cb3d..6a40d67 100644 --- a/source/StationFinderListenLive.h +++ b/source/StationFinderListenLive.h @@ -25,34 +25,31 @@ class StationFinderListenLive : public StationFinderService { public: - StationFinderListenLive(); - virtual ~StationFinderListenLive(); + StationFinderListenLive(); + virtual ~StationFinderListenLive(); - static void RegisterSelf(); - static StationFinderService* Instantiate(); + static void RegisterSelf(); + static StationFinderService* Instantiate(); - virtual BObjectList* FindBy(int capabilityIndex, - const char* searchFor, - BLooper* resultUpdateTarget); + virtual BObjectList* FindBy( + int capabilityIndex, const char* searchFor, BLooper* resultUpdateTarget); - BObjectList* ParseCountryReturn(BMallocIO* data, - const char* country); - BObjectList* ParseGenreReturn(BMallocIO* data, - const char* genre); + BObjectList* ParseCountryReturn(BMallocIO* data, const char* country); + BObjectList* ParseGenreReturn(BMallocIO* data, const char* genre); private: - static int32 _PlsLookupFunc(void* data); + static int32 _PlsLookupFunc(void* data); private: - static const char* kBaseUrl; + static const char* kBaseUrl; - BStringList fCountryKeywordAndPath; - BStringList fGenreKeywordAndPath; - thread_id fLookupThread; - BObjectList fPlsLookupList; + BStringList fCountryKeywordAndPath; + BStringList fGenreKeywordAndPath; + thread_id fLookupThread; + BObjectList fPlsLookupList; - BLooper* fLookupNotify; + BLooper* fLookupNotify; }; -#endif // _STATION_FINDER_LISTEN_LIVE_H +#endif // _STATION_FINDER_LISTEN_LIVE_H diff --git a/source/StationFinderRadioNetwork.cpp b/source/StationFinderRadioNetwork.cpp index b00f053..183eaca 100644 --- a/source/StationFinderRadioNetwork.cpp +++ b/source/StationFinderRadioNetwork.cpp @@ -33,25 +33,16 @@ #define B_TRANSLATION_CONTEXT "StationFinderRadioNetwork" -const char* StationFinderRadioNetwork::kBaseUrl = - "https://all.api.radio-browser.info/"; +const char* StationFinderRadioNetwork::kBaseUrl = "https://all.api.radio-browser.info/"; BString StationFinderRadioNetwork::sCachedServerUrl = B_EMPTY_STRING; -IconLookup::IconLookup(Station* station, BUrl iconUrl) - : - fStation(station), - fIconUrl(iconUrl) -{ -} +IconLookup::IconLookup(Station* station, BUrl iconUrl) : fStation(station), fIconUrl(iconUrl) {} StationFinderRadioNetwork::StationFinderRadioNetwork() - : - StationFinderService(), - fIconLookupThread(-1), - fIconLookupList(100, true) + : StationFinderService(), fIconLookupThread(-1), fIconLookupList(100, true) { serviceName.SetTo(B_TRANSLATE("Community Radio Browser")); serviceHomePage.SetUrlString("https://www.radio-browser.info"); @@ -83,14 +74,13 @@ StationFinderRadioNetwork::Instantiate() void StationFinderRadioNetwork::RegisterSelf() { - Register( - "Community Radio Browser", &StationFinderRadioNetwork::Instantiate); + Register("Community Radio Browser", &StationFinderRadioNetwork::Instantiate); } BObjectList* -StationFinderRadioNetwork::FindBy(int capabilityIndex, const char* searchFor, - BLooper* resultUpdateTarget) +StationFinderRadioNetwork::FindBy( + int capabilityIndex, const char* searchFor, BLooper* resultUpdateTarget) { _WaitForIconLookupThread(); @@ -112,35 +102,35 @@ StationFinderRadioNetwork::FindBy(int capabilityIndex, const char* searchFor, urlString.Append("json/stations/"); switch (capabilityIndex) { - case 0: // Name search + case 0: // Name search urlString.Append("byname/"); break; - case 1: // Tag search + case 1: // Tag search urlString.Append("bytag/"); break; - case 2: // Language search + case 2: // Language search urlString.Append("bylanguage/"); break; - case 3: // Country search + case 3: // Country search urlString.Append("bycountry/"); break; - case 4: // Country code search + case 4: // Country code search urlString.Append("bycountrycodeexact/"); break; - case 5: // State/Region search + case 5: // State/Region search urlString.Append("bystate/"); break; - case 6: // Unique identifier search + case 6: // Unique identifier search urlString.Append("byuuid/"); break; - default: // A very bad kind of search? Just do a name search... + default: // A very bad kind of search? Just do a name search... urlString.Append("byname/"); break; } @@ -152,61 +142,52 @@ StationFinderRadioNetwork::FindBy(int capabilityIndex, const char* searchFor, BMessage parsedData; BMallocIO* data = HttpUtils::GetAll(finalUrl); - if (data != NULL - && BJson::Parse((const char*)data->Buffer(), data->BufferLength(), - parsedData) == B_OK) { + if (data != NULL && + BJson::Parse((const char*)data->Buffer(), data->BufferLength(), parsedData) == B_OK) { delete data; char* name; uint32 type; int32 count; - for (int32 index = 0; parsedData.GetInfo(B_MESSAGE_TYPE, index, - &name, &type, &count) == B_OK; index++) { + for (int32 index = 0; + parsedData.GetInfo(B_MESSAGE_TYPE, index, &name, &type, &count) == B_OK; index++) { BMessage stationMessage; if (parsedData.FindMessage(name, &stationMessage) == B_OK) { Station* station = new Station("unknown"); if (station == NULL) continue; - station->SetUniqueIdentifier(stationMessage.GetString( - "stationuuid", B_EMPTY_STRING)); - + station->SetUniqueIdentifier( + stationMessage.GetString("stationuuid", B_EMPTY_STRING)); + station->SetName(stationMessage.GetString("name", "unknown")); - station->SetSource(stationMessage.GetString("url", - B_EMPTY_STRING)); + station->SetSource(stationMessage.GetString("url", B_EMPTY_STRING)); - station->SetStation(stationMessage.GetString("homepage", - B_EMPTY_STRING)); + station->SetStation(stationMessage.GetString("homepage", B_EMPTY_STRING)); BString iconUrl; if (stationMessage.FindString("favicon", &iconUrl) == B_OK) { if (!iconUrl.IsEmpty()) { - fIconLookupList.AddItem( - new IconLookup(station, BUrl(iconUrl))); + fIconLookupList.AddItem(new IconLookup(station, BUrl(iconUrl))); } } - station->SetGenre(stationMessage.GetString("tags", - B_EMPTY_STRING)); + station->SetGenre(stationMessage.GetString("tags", B_EMPTY_STRING)); BString countryCode; - if (stationMessage.FindString("countrycode", &countryCode) - == B_OK) { + if (stationMessage.FindString("countrycode", &countryCode) == B_OK) { BCountry* country = new BCountry(countryCode); BString countryName; - if (country != NULL - && country->GetName(countryName) == B_OK) + if (country != NULL && country->GetName(countryName) == B_OK) station->SetCountry(countryName); delete country; } - station->SetLanguage(stationMessage.GetString("language", - B_EMPTY_STRING)); + station->SetLanguage(stationMessage.GetString("language", B_EMPTY_STRING)); - station->SetBitRate(stationMessage.GetDouble("bitrate", 0) - * 1000); + station->SetBitRate(stationMessage.GetDouble("bitrate", 0) * 1000); // Set source URL as stream URL // If the source is a playlist, this setting will be @@ -217,8 +198,7 @@ StationFinderRadioNetwork::FindBy(int capabilityIndex, const char* searchFor, } if (!fIconLookupList.IsEmpty()) { - fIconLookupThread = spawn_thread( - &_IconLookupFunc, "iconlookup", B_LOW_PRIORITY, this); + fIconLookupThread = spawn_thread(&_IconLookupFunc, "iconlookup", B_LOW_PRIORITY, this); resume_thread(fIconLookupThread); } } else { @@ -235,7 +215,7 @@ int32 StationFinderRadioNetwork::_IconLookupFunc(void* data) { StationFinderRadioNetwork* _this = (StationFinderRadioNetwork*)data; - while (_this->fIconLookupThread >=0 && !_this->fIconLookupList.IsEmpty()) { + while (_this->fIconLookupThread >= 0 && !_this->fIconLookupList.IsEmpty()) { IconLookup* item = _this->fIconLookupList.FirstItem(); BBitmap* logo = _this->RetrieveLogo(item->fIconUrl); if (logo != NULL) { @@ -243,7 +223,7 @@ StationFinderRadioNetwork::_IconLookupFunc(void* data) BMessage* notification = new BMessage(MSG_UPDATE_STATION); notification->AddPointer("station", item->fStation); - if (_this->fIconLookupThread >=0 && _this->fIconLookupNotify->LockLooper()) { + if (_this->fIconLookupThread >= 0 && _this->fIconLookupNotify->LockLooper()) { _this->fIconLookupNotify->PostMessage(notification); _this->fIconLookupNotify->UnlockLooper(); } @@ -262,8 +242,8 @@ StationFinderRadioNetwork::_CheckServer() { // Just a quick check up on our cached server...if it exists. BUrl cachedServerUrl(sCachedServerUrl); - if (!sCachedServerUrl.IsEmpty() - && HttpUtils::CheckPort(cachedServerUrl, &cachedServerUrl, 0) == B_OK) { + if (!sCachedServerUrl.IsEmpty() && + HttpUtils::CheckPort(cachedServerUrl, &cachedServerUrl, 0) == B_OK) { // It's still there! return B_OK; } diff --git a/source/StationFinderRadioNetwork.h b/source/StationFinderRadioNetwork.h index 72f2f9a..cbeb1d4 100644 --- a/source/StationFinderRadioNetwork.h +++ b/source/StationFinderRadioNetwork.h @@ -24,38 +24,37 @@ class IconLookup { public: - IconLookup(Station* station, BUrl iconUrl); + IconLookup(Station* station, BUrl iconUrl); - Station* fStation; - BUrl fIconUrl; + Station* fStation; + BUrl fIconUrl; }; class StationFinderRadioNetwork : public StationFinderService { public: - StationFinderRadioNetwork(); - virtual ~StationFinderRadioNetwork(); + StationFinderRadioNetwork(); + virtual ~StationFinderRadioNetwork(); - static void RegisterSelf(); - static StationFinderService* Instantiate(); + static void RegisterSelf(); + static StationFinderService* Instantiate(); - virtual BObjectList* FindBy(int capabilityIndex, - const char* searchFor, - BLooper* resultUpdateTarget); + virtual BObjectList* FindBy( + int capabilityIndex, const char* searchFor, BLooper* resultUpdateTarget); private: - static int32 _IconLookupFunc(void* data); - status_t _CheckServer(); - void _WaitForIconLookupThread(); + static int32 _IconLookupFunc(void* data); + status_t _CheckServer(); + void _WaitForIconLookupThread(); private: - static const char* kBaseUrl; - static BString sCachedServerUrl; + static const char* kBaseUrl; + static BString sCachedServerUrl; - thread_id fIconLookupThread; - BObjectList fIconLookupList; - BLooper* fIconLookupNotify; + thread_id fIconLookupThread; + BObjectList fIconLookupList; + BLooper* fIconLookupNotify; }; -#endif // _STATION_FINDER_RADIO_NETWORK_H +#endif // _STATION_FINDER_RADIO_NETWORK_H diff --git a/source/StationListView.cpp b/source/StationListView.cpp index e590aeb..003f5ee 100644 --- a/source/StationListView.cpp +++ b/source/StationListView.cpp @@ -35,11 +35,7 @@ StationListViewItem::StationListViewItem(Station* station) - : - BListItem(0, true), - fPlayer(NULL), - fStation(station), - fList(NULL) + : BListItem(0, true), fPlayer(NULL), fStation(station), fList(NULL) { SetHeight(SLV_HEIGHT); } @@ -58,10 +54,9 @@ StationListViewItem::~StationListViewItem() StreamPlayer::PlayState StationListViewItem::State() { - return (fPlayer != NULL) - ? fPlayer->State() - : fStation->Flags(STATION_URI_VALID) ? StreamPlayer::Stopped - : StreamPlayer::InActive; + return (fPlayer != NULL) ? fPlayer->State() + : fStation->Flags(STATION_URI_VALID) ? StreamPlayer::Stopped + : StreamPlayer::InActive; } @@ -71,27 +66,23 @@ StationListViewItem::DrawItem(BView* owner, BRect frame, bool complete) int index = ((BListView*)owner)->IndexOf(this); StationListView* ownerList = (StationListView*)owner; - ownerList->SetHighColor( - ui_color(IsSelected() ? B_MENU_SELECTION_BACKGROUND_COLOR - : ((index % 2) ? B_MENU_BACKGROUND_COLOR - : B_DOCUMENT_BACKGROUND_COLOR))); + ownerList->SetHighColor(ui_color( + IsSelected() ? B_MENU_SELECTION_BACKGROUND_COLOR + : ((index % 2) ? B_MENU_BACKGROUND_COLOR : B_DOCUMENT_BACKGROUND_COLOR))); ownerList->FillRect(frame); - owner->SetHighColor(ui_color(IsSelected() ? B_MENU_SELECTED_ITEM_TEXT_COLOR - : B_MENU_ITEM_TEXT_COLOR)); - owner->SetLowColor( - ui_color(IsSelected() ? B_MENU_SELECTION_BACKGROUND_COLOR - : ((index % 2) ? B_MENU_BACKGROUND_COLOR - : B_DOCUMENT_BACKGROUND_COLOR))); + owner->SetHighColor( + ui_color(IsSelected() ? B_MENU_SELECTED_ITEM_TEXT_COLOR : B_MENU_ITEM_TEXT_COLOR)); + owner->SetLowColor(ui_color( + IsSelected() ? B_MENU_SELECTION_BACKGROUND_COLOR + : ((index % 2) ? B_MENU_BACKGROUND_COLOR : B_DOCUMENT_BACKGROUND_COLOR))); if (fStation->Logo() != NULL) { - BRect target(SLV_INSET, SLV_INSET, SLV_HEIGHT - 2 * SLV_INSET, - SLV_HEIGHT - 2 * SLV_INSET); + BRect target(SLV_INSET, SLV_INSET, SLV_HEIGHT - 2 * SLV_INSET, SLV_HEIGHT - 2 * SLV_INSET); target.OffsetBy(frame.LeftTop()); owner->DrawBitmap( - fStation->Logo(), fStation->Logo()->Bounds(), target, - B_FILTER_BITMAP_BILINEAR); + fStation->Logo(), fStation->Logo()->Bounds(), target, B_FILTER_BITMAP_BILINEAR); } owner->SetFontSize(SLV_MAIN_FONT_SIZE); @@ -100,30 +91,26 @@ StationListViewItem::DrawItem(BView* owner, BRect frame, bool complete) float baseline = SLV_INSET + fontHeight.ascent + fontHeight.leading; owner->DrawString(fStation->Name()->String(), - frame.LeftTop() - + BPoint( - SLV_HEIGHT - SLV_INSET + SLV_PADDING, SLV_INSET + baseline)); + frame.LeftTop() + BPoint(SLV_HEIGHT - SLV_INSET + SLV_PADDING, SLV_INSET + baseline)); owner->SetFontSize(SLV_SMALL_FONT_SIZE); owner->GetFontHeight(&fontHeight); baseline += fontHeight.ascent + fontHeight.descent + fontHeight.leading; owner->DrawString(fStation->Source().UrlString(), - frame.LeftTop() - + BPoint(SLV_HEIGHT - SLV_INSET + SLV_PADDING, baseline)); + frame.LeftTop() + BPoint(SLV_HEIGHT - SLV_INSET + SLV_PADDING, baseline)); baseline += fontHeight.ascent + fontHeight.descent + fontHeight.leading; - owner->DrawString(BString("") << fStation->BitRate() / 1000.0 << " kbps " - << fStation->Mime()->Type(), - frame.LeftTop() - + BPoint(SLV_HEIGHT - SLV_INSET + SLV_PADDING, baseline)); + owner->DrawString( + BString("") << fStation->BitRate() / 1000.0 << " kbps " << fStation->Mime()->Type(), + frame.LeftTop() + BPoint(SLV_HEIGHT - SLV_INSET + SLV_PADDING, baseline)); frame = ownerList->ItemFrame(ownerList->StationIndex(fStation)); if (ownerList->CanPlay() && fStation->Flags(STATION_URI_VALID)) { BBitmap* bnBitmap = _GetButtonBitmap(State()); if (bnBitmap != NULL) { owner->SetDrawingMode(B_OP_ALPHA); - owner->DrawBitmap(bnBitmap, frame.LeftTop() - + BPoint(SLV_INSET, SLV_HEIGHT - SLV_INSET - SLV_BUTTON_SIZE)); + owner->DrawBitmap(bnBitmap, + frame.LeftTop() + BPoint(SLV_INSET, SLV_HEIGHT - SLV_INSET - SLV_BUTTON_SIZE)); owner->SetDrawingMode(B_OP_COPY); } } @@ -133,15 +120,13 @@ StationListViewItem::DrawItem(BView* owner, BRect frame, bool complete) void StationListViewItem::DrawBufferFillBar(BView* owner, BRect frame) { - if (State() == StreamPlayer::Playing - || State() == StreamPlayer::Buffering) { + if (State() == StreamPlayer::Playing || State() == StreamPlayer::Buffering) { frame.bottom -= SLV_INSET; frame.left = SLV_HEIGHT - SLV_INSET + SLV_PADDING; frame.top = frame.bottom - 5; frame.right -= SLV_PADDING; - owner->SetHighColor( - tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_LIGHTEN_2_TINT)); + owner->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_LIGHTEN_2_TINT)); owner->FillRect(frame); owner->SetHighColor(200, 30, 0); @@ -196,10 +181,7 @@ StationListViewItem::SetFillRatio(float fillRatio) StationListView::StationListView(bool canPlay) - : - BListView("Stations", B_SINGLE_SELECTION_LIST), - fPlayMsg(NULL), - fCanPlay(canPlay) + : BListView("Stations", B_SINGLE_SELECTION_LIST), fPlayMsg(NULL), fCanPlay(canPlay) { SetResizingMode(B_FOLLOW_ALL_SIDES); SetExplicitMinSize(BSize(300, 2 * SLV_HEIGHT)); @@ -232,7 +214,7 @@ void StationListView::MakeEmpty() { for (int32 i = CountItems() - 1; i >= 0; i--) { - StationListViewItem* stationItem = (StationListViewItem*) ItemAt(i); + StationListViewItem* stationItem = (StationListViewItem*)ItemAt(i); RemoveItem(i); delete stationItem; } @@ -295,7 +277,7 @@ StationListView::Sync(StationsList* stations) LockLooper(); for (int32 i = CountItems() - 1; i >= 0; i--) { - StationListViewItem* stationItem = (StationListViewItem*) ItemAt(i); + StationListViewItem* stationItem = (StationListViewItem*)ItemAt(i); if (!stations->HasItem(stationItem->GetStation())) { RemoveItem(i); delete stationItem; @@ -334,8 +316,7 @@ void StationListView::MouseUp(BPoint where) { fWhereDown -= where; - if (fWhereDown.x * fWhereDown.x + fWhereDown.y * fWhereDown.y < 5 - && fPlayMsg != NULL) { + if (fWhereDown.x * fWhereDown.x + fWhereDown.y * fWhereDown.y < 5 && fPlayMsg != NULL) { int stationIndex = IndexOf(where); BRect playFrame = ItemFrame(stationIndex); diff --git a/source/StationListView.h b/source/StationListView.h index 73c6a5c..924188c 100644 --- a/source/StationListView.h +++ b/source/StationListView.h @@ -38,67 +38,65 @@ class StationListViewItem : public BListItem { friend class StationListView; public: - StationListViewItem(Station* station); - virtual ~StationListViewItem(); + StationListViewItem(Station* station); + virtual ~StationListViewItem(); - virtual void DrawItem(BView* owner, BRect frame, - bool complete); + virtual void DrawItem(BView* owner, BRect frame, bool complete); - void DrawBufferFillBar(BView* owner, BRect frame); - virtual void Update(BView* owner, const BFont* font); - Station* GetStation() { return fStation; } - void ClearStation() { fStation = NULL; } - void StateChanged(StreamPlayer::PlayState newState); - void SetFillRatio(float fillRatio); + void DrawBufferFillBar(BView* owner, BRect frame); + virtual void Update(BView* owner, const BFont* font); + Station* GetStation() { return fStation; } + void ClearStation() { fStation = NULL; } + void StateChanged(StreamPlayer::PlayState newState); + void SetFillRatio(float fillRatio); - StreamPlayer* Player() { return fPlayer; } - StreamPlayer::PlayState State(); - void SetPlayer(StreamPlayer* player) - { fPlayer = player; } + StreamPlayer* Player() { return fPlayer; } + StreamPlayer::PlayState State(); + void SetPlayer(StreamPlayer* player) { fPlayer = player; } private: - static BBitmap* _GetButtonBitmap(StreamPlayer::PlayState state); + static BBitmap* _GetButtonBitmap(StreamPlayer::PlayState state); private: - static BBitmap* sButtonBitmap[3]; + static BBitmap* sButtonBitmap[3]; - StreamPlayer* fPlayer; - class Station* fStation; - StationListView* fList; + StreamPlayer* fPlayer; + class Station* fStation; + StationListView* fList; - float fFillRatio; + float fFillRatio; }; class StationListView : public BListView { public: - StationListView(bool canPlay = false); - virtual ~StationListView(); + StationListView(bool canPlay = false); + virtual ~StationListView(); - void Sync(StationsList* stations); + void Sync(StationsList* stations); - virtual bool AddItem(Station* station); - virtual bool AddItem(StationListViewItem* item); - virtual void MakeEmpty(); + virtual bool AddItem(Station* station); + virtual bool AddItem(StationListViewItem* item); + virtual void MakeEmpty(); - int32 StationIndex(Station* station); - StationListViewItem* Item(Station* station); - StationListViewItem* ItemAt(int32 index); - Station* StationAt(int32 index); - void SelectItem(StationListViewItem* item); + int32 StationIndex(Station* station); + StationListViewItem* Item(Station* station); + StationListViewItem* ItemAt(int32 index); + Station* StationAt(int32 index); + void SelectItem(StationListViewItem* item); - void SetPlayMessage(BMessage* playMsg); - bool CanPlay() { return fCanPlay; } + void SetPlayMessage(BMessage* playMsg); + bool CanPlay() { return fCanPlay; } private: - virtual void MouseDown(BPoint where); - virtual void MouseUp(BPoint where); + virtual void MouseDown(BPoint where); + virtual void MouseUp(BPoint where); private: - BPoint fWhereDown; - BMessage* fPlayMsg; - bool fCanPlay; + BPoint fWhereDown; + BMessage* fPlayMsg; + bool fCanPlay; }; -#endif // _STATION_LIST_VIEW_H +#endif // _STATION_LIST_VIEW_H diff --git a/source/StationPanel.cpp b/source/StationPanel.cpp index 91aa069..ddaac44 100644 --- a/source/StationPanel.cpp +++ b/source/StationPanel.cpp @@ -34,38 +34,28 @@ StationPanel::StationPanel(MainWindow* mainWindow, bool expanded) - : - BView("stationpanel", B_WILL_DRAW), - fStationItem(NULL), - fMainWindow(mainWindow) + : BView("stationpanel", B_WILL_DRAW), fStationItem(NULL), fMainWindow(mainWindow) { SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM); - SetExplicitAlignment( - BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_VERTICAL_UNSET)); + SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_VERTICAL_UNSET)); fLogo = new BView("logo", B_WILL_DRAW); fLogo->SetExplicitSize(BSize(96, 96)); - fLogo->SetViewColor( - tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_2_TINT)); + fLogo->SetViewColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_2_TINT)); - fName = new BTextControl( - "name", B_TRANSLATE("Name"), "-", new BMessage(MSG_CHG_NAME)); + fName = new BTextControl("name", B_TRANSLATE("Name"), "-", new BMessage(MSG_CHG_NAME)); - fUrl = new BTextControl( - "url", B_TRANSLATE("Stream URL"), "-", new BMessage(MSG_CHG_STREAMURL)); + fUrl = new BTextControl("url", B_TRANSLATE("Stream URL"), "-", new BMessage(MSG_CHG_STREAMURL)); - fGenre = new BTextControl( - "genre", B_TRANSLATE("Genre"), "-", new BMessage(MSG_CHG_GENRE)); + fGenre = new BTextControl("genre", B_TRANSLATE("Genre"), "-", new BMessage(MSG_CHG_GENRE)); - fStationUrl = new BTextControl("surl", B_TRANSLATE("Station URL"), "-", - new BMessage(MSG_CHG_STATIONURL)); + fStationUrl = + new BTextControl("surl", B_TRANSLATE("Station URL"), "-", new BMessage(MSG_CHG_STATIONURL)); - fVisitStation - = new BButton("bnVisitStation", "", new BMessage(MSG_VISIT_STATION)); + fVisitStation = new BButton("bnVisitStation", "", new BMessage(MSG_VISIT_STATION)); fVisitStation->SetIcon(Utils::ResourceBitmap(RES_BN_WEB)); - fVolume = new BSlider( - "volume", NULL, new BMessage(MSG_CHG_VOLUME), 0, 100, B_VERTICAL); + fVolume = new BSlider("volume", NULL, new BMessage(MSG_CHG_VOLUME), 0, 100, B_VERTICAL); fVolume->SetModificationMessage(new BMessage(MSG_CHG_VOLUME)); BLayoutBuilder::Grid<>(this, B_USE_SMALL_SPACING, B_USE_SMALL_SPACING) @@ -79,13 +69,11 @@ StationPanel::StationPanel(MainWindow* mainWindow, bool expanded) .Add(fVisitStation, 5, 2) .Add(fVolume, 6, 0, 1, 3) .AddGlue(1, 3, 5, 1) - .End(); + .End(); } -StationPanel::~StationPanel() -{ -} +StationPanel::~StationPanel() {} void @@ -128,8 +116,8 @@ StationPanel::SetStation(StationListViewItem* stationItem) fStationItem = NULL; } else { - if (stationItem->Player() != NULL - && stationItem->Player()->State() == StreamPlayer::Playing) { + if (stationItem->Player() != NULL && + stationItem->Player()->State() == StreamPlayer::Playing) { fVolume->SetEnabled(true); fVolume->SetValue(stationItem->Player()->Volume() * 100); } else @@ -139,8 +127,8 @@ StationPanel::SetStation(StationListViewItem* stationItem) Station* station = stationItem->GetStation(); if (station->Logo()) { - fLogo->SetViewBitmap(station->Logo(), station->Logo()->Bounds(), - fLogo->Bounds(), 0, B_FILTER_BITMAP_BILINEAR); + fLogo->SetViewBitmap(station->Logo(), station->Logo()->Bounds(), fLogo->Bounds(), 0, + B_FILTER_BITMAP_BILINEAR); } else fLogo->ClearViewBitmap(); @@ -164,8 +152,8 @@ StationPanel::SetStation(StationListViewItem* stationItem) void StationPanel::StateChanged(StreamPlayer::PlayState newState) { - if (fStationItem != NULL && fStationItem->Player() != NULL - && fStationItem->Player()->State() == StreamPlayer::Playing) { + if (fStationItem != NULL && fStationItem->Player() != NULL && + fStationItem->Player()->State() == StreamPlayer::Playing) { fVolume->SetEnabled(true); fVolume->SetValue(fStationItem->Player()->Volume() * 100); } else { @@ -178,17 +166,15 @@ StationPanel::StateChanged(StreamPlayer::PlayState newState) void StationPanel::MessageReceived(BMessage* msg) { - Station* station - = (fStationItem != NULL) ? fStationItem->GetStation() : NULL; + Station* station = (fStationItem != NULL) ? fStationItem->GetStation() : NULL; if (station != NULL) { entry_ref ref; - if (msg->WasDropped() && msg->IsSourceRemote() - && msg->FindRef("refs", &ref) == B_OK) { + if (msg->WasDropped() && msg->IsSourceRemote() && msg->FindRef("refs", &ref) == B_OK) { BBitmap* bm = BTranslationUtils::GetBitmap(&ref); if (bm != NULL) { station->SetLogo(bm); - fLogo->SetViewBitmap(station->Logo(), station->Logo()->Bounds(), - fLogo->Bounds(), 0, B_FILTER_BITMAP_BILINEAR); + fLogo->SetViewBitmap(station->Logo(), station->Logo()->Bounds(), fLogo->Bounds(), 0, + B_FILTER_BITMAP_BILINEAR); } return; @@ -222,8 +208,7 @@ StationPanel::MessageReceived(BMessage* msg) case MSG_VISIT_STATION: { - MSG("Trying to launch url %s\n", - station->StationUrl().UrlString().String()); + MSG("Trying to launch url %s\n", station->StationUrl().UrlString().String()); if (station->StationUrl().UrlString().IsEmpty()) { BString search; diff --git a/source/StationPanel.h b/source/StationPanel.h index 7d89361..8cd063c 100644 --- a/source/StationPanel.h +++ b/source/StationPanel.h @@ -40,28 +40,27 @@ class MainWindow; class StationPanel : public BView { public: - StationPanel(MainWindow* mainWindow, - bool expanded = false); - virtual ~StationPanel(); + StationPanel(MainWindow* mainWindow, bool expanded = false); + virtual ~StationPanel(); - virtual void AttachedToWindow(); - virtual void MessageReceived(BMessage* msg); + virtual void AttachedToWindow(); + virtual void MessageReceived(BMessage* msg); - void SetStation(StationListViewItem* stationItem); - void StateChanged(StreamPlayer::PlayState newState); + void SetStation(StationListViewItem* stationItem); + void StateChanged(StreamPlayer::PlayState newState); private: - StationListViewItem* fStationItem; - MainWindow* fMainWindow; + StationListViewItem* fStationItem; + MainWindow* fMainWindow; - BView* fLogo; - BTextControl* fName; - BTextControl* fUrl; - BTextControl* fGenre; - BTextControl* fStationUrl; - BButton* fVisitStation; - BSlider* fVolume; + BView* fLogo; + BTextControl* fName; + BTextControl* fUrl; + BTextControl* fGenre; + BTextControl* fStationUrl; + BButton* fVisitStation; + BSlider* fVolume; }; -#endif // _STATION_PANEL_H +#endif // _STATION_PANEL_H diff --git a/source/StreamIO.cpp b/source/StreamIO.cpp index 04fb10c..c3111a6 100644 --- a/source/StreamIO.cpp +++ b/source/StreamIO.cpp @@ -44,20 +44,19 @@ const char kMpegHeader2 = '\xe0'; StreamIO::StreamIO(Station* station, BLooper* metaListener) - : - BAdapterIO(B_MEDIA_STREAMING | B_MEDIA_SEEKABLE, HTTP_TIMEOUT), - fStation(station), - fReq(NULL), - fReqThread(-1), - fUnsynched(0), - fMetaInt(0), - fMetaSize(0), - fUntilMetaStart(0), - fUntilMetaEnd(0), - fMetaListener(metaListener), - fFrameSync(none), - fLimit(0), - fBuffered(0) + : BAdapterIO(B_MEDIA_STREAMING | B_MEDIA_SEEKABLE, HTTP_TIMEOUT), + fStation(station), + fReq(NULL), + fReqThread(-1), + fUnsynched(0), + fMetaInt(0), + fMetaSize(0), + fUntilMetaStart(0), + fUntilMetaEnd(0), + fMetaListener(metaListener), + fFrameSync(none), + fLimit(0), + fBuffered(0) { BUrl url = station->StreamUrl(); @@ -80,8 +79,8 @@ StreamIO::StreamIO(Station* station, BLooper* metaListener) // IP's should be small, anyway. if (url.Protocol() == "https") { - fReq = dynamic_cast(BUrlProtocolRoster::MakeRequest( - url.UrlString().String(), this, this)); + fReq = dynamic_cast( + BUrlProtocolRoster::MakeRequest(url.UrlString().String(), this, this)); } else { BUrl* newUrl = new BUrl(); if (newUrl == NULL) @@ -91,8 +90,8 @@ StreamIO::StreamIO(Station* station, BLooper* metaListener) if (portStatus != B_OK) return; - fReq = dynamic_cast(BUrlProtocolRoster::MakeRequest( - newUrl->UrlString().String(), this, this)); + fReq = dynamic_cast( + BUrlProtocolRoster::MakeRequest(newUrl->UrlString().String(), this, this)); delete newUrl; } @@ -154,21 +153,18 @@ StreamIO::ReadAt(off_t position, void* buffer, size_t size) if (fLimit == 0 || position < fLimit) { ssize_t read = BAdapterIO::ReadAt(position, buffer, size); if (read > 0) { - TRACE("Read %" B_PRIdSSIZE " of %" B_PRIuSIZE - " bytes from position %" B_PRIdOFF ", %" B_PRIuSIZE - " remaining\n", + TRACE("Read %" B_PRIdSSIZE " of %" B_PRIuSIZE " bytes from position %" B_PRIdOFF + ", %" B_PRIuSIZE " remaining\n", read, size, position, fBuffered); fBuffered -= read; } else { - TRACE("Reading %" B_PRIuSIZE " bytes from position %" B_PRIdOFF - " failed - %s\n", - size, position, strerror(read)); + TRACE("Reading %" B_PRIuSIZE " bytes from position %" B_PRIdOFF " failed - %s\n", size, + position, strerror(read)); } return read; } else { - TRACE("Position %" B_PRIdOFF " has reached limit of %" B_PRIuSIZE - ", blocking...\n", + TRACE("Position %" B_PRIdOFF " has reached limit of %" B_PRIuSIZE ", blocking...\n", position, fLimit); return 0; @@ -215,14 +211,12 @@ void StreamIO::HeadersReceived(BUrlRequest* request) { BHttpRequest* httpReq = dynamic_cast(request); - const BHttpResult* httpResult - = dynamic_cast(&request->Result()); + const BHttpResult* httpResult = dynamic_cast(&request->Result()); if (httpReq->IsRedirectionStatusCode(httpResult->StatusCode())) { - if (httpResult->StatusCode() == 301) { // Permanent redirect + if (httpResult->StatusCode() == 301) { // Permanent redirect fStation->SetStreamUrl(httpResult->Headers()["location"]); - TRACE("Permanently redirected to %s\n", - httpResult->Headers()["location"]); + TRACE("Permanently redirected to %s\n", httpResult->Headers()["location"]); } else TRACE("Redirected to %s\n", httpResult->Headers()["location"]); @@ -278,7 +272,7 @@ StreamIO::_DataWithMetaReceived(const char* data, size_t size, int next) fUntilMetaEnd = 0; fUntilMetaStart = fMetaInt; } else { - memcpy(fMetaBuffer + fMetaSize, (void*) data, size); + memcpy(fMetaBuffer + fMetaSize, (void*)data, size); written += size; fMetaSize += size; @@ -306,8 +300,7 @@ StreamIO::_DataWithMetaReceived(const char* data, size_t size, int next) fUntilMetaStart = fMetaInt; TRACE("Meta: Empty\n"); } else if (fUntilMetaEnd > 512) { - TRACE("Meta: Size of %" B_PRIdOFF " too large\n", - fUntilMetaEnd); + TRACE("Meta: Size of %" B_PRIdOFF " too large\n", fUntilMetaEnd); fUntilMetaStart = fMetaInt; fUntilMetaEnd = 0; @@ -328,8 +321,7 @@ StreamIO::_DataWithMetaReceived(const char* data, size_t size, int next) ssize_t -StreamIO::_DataUnsyncedReceived(const char* data, - size_t size, int next) +StreamIO::_DataUnsyncedReceived(const char* data, size_t size, int next) { off_t frameStart; for (frameStart = 0; frameStart < size; frameStart++) { @@ -344,16 +336,14 @@ StreamIO::_DataUnsyncedReceived(const char* data, DataFunc nextFunc = fDataFuncs.Item(next); (*this.*nextFunc)(&kMpegHeader1, 1, next + 1); - return frameStart + (*this.*nextFunc)(data + frameStart, - size - frameStart, next + 1); + return frameStart + (*this.*nextFunc)(data + frameStart, size - frameStart, next + 1); } else fFrameSync = none; } fUnsynched += size; if (fUnsynched > 8192) { - MSG("No mp3 frame header encountered in first %" B_PRIiOFF - " bytes, giving up...", + MSG("No mp3 frame header encountered in first %" B_PRIiOFF " bytes, giving up...", fUnsynched); next--; @@ -382,8 +372,7 @@ StreamIO::RequestCompleted(BUrlRequest* request, bool success) void -StreamIO::DebugMessage(BUrlRequest* caller, BUrlProtocolDebugMessage type, - const char* text) +StreamIO::DebugMessage(BUrlRequest* caller, BUrlProtocolDebugMessage type, const char* text) { DEBUG("Debug Message: %s\n", text); } @@ -404,8 +393,8 @@ StreamIO::_ProcessMeta() msg->AddString("station", fStation->Name()->String()); int res = regcomp(®ex, "([^=]*)='(([^']|'[^;])*)';", - RE_ICASE | RE_DOT_NEWLINE | RE_DOT_NOT_NULL | RE_NO_BK_PARENS - | RE_NO_BK_VBAR | RE_BACKSLASH_ESCAPE_IN_LISTS); + RE_ICASE | RE_DOT_NEWLINE | RE_DOT_NOT_NULL | RE_NO_BK_PARENS | RE_NO_BK_VBAR | + RE_BACKSLASH_ESCAPE_IN_LISTS); char* text = fMetaBuffer; while ((res = regexec(®ex, text, 3, matches, 0)) == 0) { @@ -415,8 +404,7 @@ StreamIO::_ProcessMeta() if (text + matches[2].rm_so && !(text + matches[2].rm_so)[0]) msg->AddString(strlwr(text + matches[1].rm_so), fIcyName); else - msg->AddString( - strlwr(text + matches[1].rm_so), text + matches[2].rm_so); + msg->AddString(strlwr(text + matches[1].rm_so), text + matches[2].rm_so); text += matches[0].rm_eo; } diff --git a/source/StreamIO.h b/source/StreamIO.h index 5a0bab0..baed3d3 100644 --- a/source/StreamIO.h +++ b/source/StreamIO.h @@ -40,25 +40,17 @@ typedef ssize_t (StreamIO::*DataFunc)(const char* data, size_t size, int next); class DataFuncs { public: - DataFuncs() - : - fSize(10), - fLast(-1) + DataFuncs() : fSize(10), fLast(-1) { for (int i = 0; i < fSize; i++) fFuncs[i] = NULL; }; - void - Add(DataFunc f) - { - fFuncs[++fLast] = f; - } + void Add(DataFunc f) { fFuncs[++fLast] = f; } - void - Add(DataFunc f, int before) + void Add(DataFunc f, int before) { for (int i = fLast; i >= before; i--) fFuncs[i + 1] = fFuncs[i]; @@ -67,8 +59,7 @@ class DataFuncs { }; - void - Remove(int index) + void Remove(int index) { for (int i = index; i < fLast; i++) fFuncs[i] = fFuncs[i + 1]; @@ -76,83 +67,78 @@ class DataFuncs { }; - DataFunc Item(int index) { return fFuncs[index]; }; - DataFunc First() { return fFuncs[0]; }; + DataFunc Item(int index) { return fFuncs[index]; }; + DataFunc First() { return fFuncs[0]; }; private: - DataFunc fFuncs[10]; - int fSize; - int fLast; + DataFunc fFuncs[10]; + int fSize; + int fLast; }; class StreamIO : public BAdapterIO, BUrlProtocolListener { public: - StreamIO(Station* station, - BLooper* metaListener = NULL); - ~StreamIO(); + StreamIO(Station* station, BLooper* metaListener = NULL); + ~StreamIO(); - void SetLimiter(size_t limit = 0); + void SetLimiter(size_t limit = 0); -// BAdapterIO - status_t Open() override; + // BAdapterIO + status_t Open() override; private: -// BAdapterIO - void GetFlags(int32* flags) const override; - - ssize_t Write(const void* buffer, - size_t size) override; - ssize_t WriteAt(off_t position, const void* buffer, - size_t size) override; - ssize_t ReadAt(off_t position, void* buffer, - size_t size) override; - - status_t SetSize(off_t size) override; - - bool IsRunning() const override; - -// BUrlProtocolListener - void HeadersReceived(BUrlRequest* request) override; - void RequestCompleted(BUrlRequest* request, - bool success) override; - void DebugMessage(BUrlRequest* caller, - BUrlProtocolDebugMessage type, - const char* text) override; - -// - ssize_t _DataWithMetaReceived( - const char* data, size_t size, int next); - ssize_t _DataUnsyncedReceived( - const char* data, size_t size, int next); - ssize_t _DataSyncedReceived( - const char* data, size_t size, int next); - void _ProcessMeta(); + // BAdapterIO + void GetFlags(int32* flags) const override; + + ssize_t Write(const void* buffer, size_t size) override; + ssize_t WriteAt(off_t position, const void* buffer, size_t size) override; + ssize_t ReadAt(off_t position, void* buffer, size_t size) override; + + status_t SetSize(off_t size) override; + + bool IsRunning() const override; + + // BUrlProtocolListener + void HeadersReceived(BUrlRequest* request) override; + void RequestCompleted(BUrlRequest* request, bool success) override; + void DebugMessage( + BUrlRequest* caller, BUrlProtocolDebugMessage type, const char* text) override; + + // + ssize_t _DataWithMetaReceived(const char* data, size_t size, int next); + ssize_t _DataUnsyncedReceived(const char* data, size_t size, int next); + ssize_t _DataSyncedReceived(const char* data, size_t size, int next); + void _ProcessMeta(); private: - enum FrameSync {none, first, done}; - - Station* fStation; - BHttpRequest* fReq; - thread_id fReqThread; - size_t fUnsynched; - size_t fMetaInt; - size_t fMetaSize; - off_t fUntilMetaStart; - off_t fUntilMetaEnd; - BLooper* fMetaListener; - FrameSync fFrameSync; - size_t fLimit; - size_t fBuffered; - - DataFuncs fDataFuncs; - BInputAdapter* fInputAdapter; - - const char* fIcyName; - bool fIsMutable; - char fMetaBuffer[512]; + enum FrameSync + { + none, + first, + done + }; + Station* fStation; + BHttpRequest* fReq; + thread_id fReqThread; + size_t fUnsynched; + size_t fMetaInt; + size_t fMetaSize; + off_t fUntilMetaStart; + off_t fUntilMetaEnd; + BLooper* fMetaListener; + FrameSync fFrameSync; + size_t fLimit; + size_t fBuffered; + + DataFuncs fDataFuncs; + BInputAdapter* fInputAdapter; + + const char* fIcyName; + bool fIsMutable; + char fMetaBuffer[512]; }; -#endif // _STREAM_IO_H +#endif // _STREAM_IO_H diff --git a/source/StreamPlayer.cpp b/source/StreamPlayer.cpp index 6b399c1..2611213 100644 --- a/source/StreamPlayer.cpp +++ b/source/StreamPlayer.cpp @@ -31,23 +31,21 @@ StreamPlayer::StreamPlayer(Station* station, BLooper* notify) - : - BLocker("StreamPlayer"), - fStation(station), - fNotify(notify), - fMediaFile(NULL), - fPlayer(NULL), - fState(StreamPlayer::Stopped), - fFlushCount(0) + : BLocker("StreamPlayer"), + fStation(station), + fNotify(notify), + fMediaFile(NULL), + fPlayer(NULL), + fState(StreamPlayer::Stopped), + fFlushCount(0) { - TRACE("Trying to set player for stream %s\n", - station->StreamUrl().UrlString().String()); + TRACE("Trying to set player for stream %s\n", station->StreamUrl().UrlString().String()); - fStream = new(std::nothrow) StreamIO(station, notify); + fStream = new (std::nothrow) StreamIO(station, notify); fInitStatus = fStream->Open(); if (fInitStatus != B_OK) { - MSG("Error retrieving stream from %s - %s\n", - station->StreamUrl().UrlString().String(), strerror(fInitStatus)); + MSG("Error retrieving stream from %s - %s\n", station->StreamUrl().UrlString().String(), + strerror(fInitStatus)); return; } } @@ -76,9 +74,8 @@ StreamPlayer::Play() case StreamPlayer::Stopped: { - thread_id playThreadId - = spawn_thread((thread_func)StreamPlayer::_StartPlayThreadFunc, - fStation->Name()->String(), B_NORMAL_PRIORITY, this); + thread_id playThreadId = spawn_thread((thread_func)StreamPlayer::_StartPlayThreadFunc, + fStation->Name()->String(), B_NORMAL_PRIORITY, this); resume_thread(playThreadId); break; @@ -172,16 +169,15 @@ StreamPlayer::_SetState(StreamPlayer::PlayState state) void -StreamPlayer::_GetDecodedChunk(void* cookie, void* buffer, size_t size, - const media_raw_audio_format& format) +StreamPlayer::_GetDecodedChunk( + void* cookie, void* buffer, size_t size, const media_raw_audio_format& format) { StreamPlayer* player = (StreamPlayer*)cookie; BMediaFile* fMediaFile = player->fMediaFile; - int64 reqFrames = size / format.channel_count - / (format.format & media_raw_audio_format::B_AUDIO_SIZE_MASK); - fMediaFile->TrackAt(0)->ReadFrames( - buffer, &reqFrames, &player->fHeader, &player->fInfo); + int64 reqFrames = + size / format.channel_count / (format.format & media_raw_audio_format::B_AUDIO_SIZE_MASK); + fMediaFile->TrackAt(0)->ReadFrames(buffer, &reqFrames, &player->fHeader, &player->fInfo); if (player->fFlushCount++ > 1000) { player->fFlushCount = 0; @@ -198,13 +194,12 @@ StreamPlayer::_StartPlayThreadFunc(StreamPlayer* _this) _this->_SetState(StreamPlayer::Buffering); _this->fStopRequested = false; _this->fStream->SetLimiter(0x40000); - _this->fMediaFile = new(std::nothrow) BMediaFile(_this->fStream); + _this->fMediaFile = new (std::nothrow) BMediaFile(_this->fStream); _this->fInitStatus = _this->fMediaFile->InitCheck(); if (_this->fInitStatus != B_OK) { MSG("Error creating media extractor for %s - %s\n", - _this->fStation->StreamUrl().UrlString().String(), - strerror(_this->fInitStatus)); + _this->fStation->StreamUrl().UrlString().String(), strerror(_this->fInitStatus)); } if (_this->fInitStatus != B_OK || _this->fStopRequested) { @@ -223,8 +218,7 @@ StreamPlayer::_StartPlayThreadFunc(StreamPlayer* _this) if (_this->fMediaFile->CountTracks() == 0) { MSG("No track found inside stream %s - %s\n", - _this->fStation->StreamUrl().UrlString().String(), - strerror(_this->fInitStatus)); + _this->fStation->StreamUrl().UrlString().String(), strerror(_this->fInitStatus)); } if (_this->fStopRequested) { @@ -237,12 +231,10 @@ StreamPlayer::_StartPlayThreadFunc(StreamPlayer* _this) return _this->fInitStatus; } - _this->fInitStatus - = _this->fMediaFile->TrackAt(0)->GetCodecInfo(&_this->fCodecInfo); + _this->fInitStatus = _this->fMediaFile->TrackAt(0)->GetCodecInfo(&_this->fCodecInfo); if (_this->fInitStatus != B_OK) { MSG("Could not create decoder for %s - %s\n", - _this->fStation->StreamUrl().UrlString().String(), - strerror(_this->fInitStatus)); + _this->fStation->StreamUrl().UrlString().String(), strerror(_this->fInitStatus)); } if (_this->fInitStatus != B_OK || _this->fStopRequested) { @@ -255,11 +247,9 @@ StreamPlayer::_StartPlayThreadFunc(StreamPlayer* _this) return _this->fInitStatus; } - _this->fInitStatus - = _this->fMediaFile->TrackAt(0)->DecodedFormat(&_this->fDecodedFormat); + _this->fInitStatus = _this->fMediaFile->TrackAt(0)->DecodedFormat(&_this->fDecodedFormat); if (_this->fInitStatus != B_OK) { - MSG("Could not negotiate output format - %s\n", - strerror(_this->fInitStatus)); + MSG("Could not negotiate output format - %s\n", strerror(_this->fInitStatus)); } if (_this->fInitStatus != B_OK || _this->fStopRequested) { @@ -277,13 +267,11 @@ StreamPlayer::_StartPlayThreadFunc(StreamPlayer* _this) _this->fDecodedFormat.u.raw_audio.frame_rate); _this->fPlayer = new BSoundPlayer(&_this->fDecodedFormat.u.raw_audio, - _this->fStation->Name()->String(), &StreamPlayer::_GetDecodedChunk, - NULL, _this); + _this->fStation->Name()->String(), &StreamPlayer::_GetDecodedChunk, NULL, _this); _this->fInitStatus = _this->fPlayer->InitCheck(); if (_this->fInitStatus != B_OK) { - MSG("Sound Player failed to initialize (%s)\r\n", - strerror(_this->fInitStatus)); + MSG("Sound Player failed to initialize (%s)\r\n", strerror(_this->fInitStatus)); } if (_this->fInitStatus != B_OK || _this->fStopRequested) { @@ -301,8 +289,7 @@ StreamPlayer::_StartPlayThreadFunc(StreamPlayer* _this) _this->fInitStatus = _this->fPlayer->Start(); if (_this->fInitStatus != B_OK) { - MSG("Sound Player failed to start (%s)\r\n", - strerror(_this->fInitStatus)); + MSG("Sound Player failed to start (%s)\r\n", strerror(_this->fInitStatus)); } if (_this->fInitStatus != B_OK || _this->fStopRequested) { diff --git a/source/StreamPlayer.h b/source/StreamPlayer.h index 461db7a..c5437ce 100644 --- a/source/StreamPlayer.h +++ b/source/StreamPlayer.h @@ -28,10 +28,9 @@ // Notification Messages -#define MSG_PLAYER_STATE_CHANGED \ - 'mPSC' // "player" = StreamPlayer*, "state" = int32(playState) +#define MSG_PLAYER_STATE_CHANGED 'mPSC' // "player" = StreamPlayer*, "state" = int32(playState) #define MSG_PLAYER_BUFFER_LEVEL \ - 'mPBL' // "player" = StreamPlayer*, "level" = float percent buffer filled + 'mPBL' // "player" = StreamPlayer*, "level" = float percent buffer filled class Station; @@ -39,45 +38,49 @@ class Station; class StreamPlayer : private BLocker { public: - StreamPlayer(Station* station, - BLooper* notify = NULL); - virtual ~StreamPlayer(); - - inline status_t InitCheck() { return fInitStatus; } - inline Station* GetStation() { return fStation; } - status_t Play(); - status_t Stop(); - float Volume(); - void SetVolume(float volume); - - enum PlayState { InActive = -1, Stopped, Playing, Buffering }; - inline PlayState State() { return fState; } + StreamPlayer(Station* station, BLooper* notify = NULL); + virtual ~StreamPlayer(); + + inline status_t InitCheck() { return fInitStatus; } + inline Station* GetStation() { return fStation; } + status_t Play(); + status_t Stop(); + float Volume(); + void SetVolume(float volume); + + enum PlayState + { + InActive = -1, + Stopped, + Playing, + Buffering + }; + inline PlayState State() { return fState; } private: - void _SetState(PlayState state); + void _SetState(PlayState state); - static status_t _StartPlayThreadFunc(StreamPlayer* _this); - static void _GetDecodedChunk(void* cookie, void* buffer, - size_t size, - const media_raw_audio_format& format); + static status_t _StartPlayThreadFunc(StreamPlayer* _this); + static void _GetDecodedChunk( + void* cookie, void* buffer, size_t size, const media_raw_audio_format& format); private: - Station* fStation; - BLooper* fNotify; - BMediaFile* fMediaFile; - StreamIO* fStream; - BSoundPlayer* fPlayer; - PlayState fState; - - status_t fInitStatus; - bool fStopRequested; - - media_codec_info fCodecInfo; - media_format fDecodedFormat; - media_header fHeader; - media_decode_info fInfo; - int32 fFlushCount; + Station* fStation; + BLooper* fNotify; + BMediaFile* fMediaFile; + StreamIO* fStream; + BSoundPlayer* fPlayer; + PlayState fState; + + status_t fInitStatus; + bool fStopRequested; + + media_codec_info fCodecInfo; + media_format fDecodedFormat; + media_header fHeader; + media_decode_info fInfo; + int32 fFlushCount; }; -#endif // _STREAM_PLAYER_H +#endif // _STREAM_PLAYER_H diff --git a/source/Utils.cpp b/source/Utils.cpp index 11db202..c4ca259 100644 --- a/source/Utils.cpp +++ b/source/Utils.cpp @@ -35,8 +35,7 @@ BBitmap* Utils::ResourceBitmap(int32 id) { size_t size; - const char* data - = (const char*)be_app->AppResources()->FindResource('BBMP', id, &size); + const char* data = (const char*)be_app->AppResources()->FindResource('BBMP', id, &size); if (size != 0 && data != NULL) { BMessage msg; if (msg.Unflatten(data) == B_OK) @@ -61,8 +60,8 @@ Utils::UserAgent() struct version_info version; if (appFileInfo.GetVersionInfo(&version, B_APP_VERSION_KIND) == B_OK) snprintf(sUserAgent, sizeof(sUserAgent), - "StreamRadio/%" B_PRIu32 ".%" B_PRIu32 ".%" B_PRIu32, - version.major, version.middle, version.minor); + "StreamRadio/%" B_PRIu32 ".%" B_PRIu32 ".%" B_PRIu32, version.major, version.middle, + version.minor); } if (sUserAgent[0] == 0) { diff --git a/source/Utils.h b/source/Utils.h index 7872acb..6213c64 100644 --- a/source/Utils.h +++ b/source/Utils.h @@ -30,12 +30,12 @@ class Utils { public: - Utils() {}; - virtual ~Utils() {}; + Utils(){}; + virtual ~Utils(){}; - static BBitmap* ResourceBitmap(int32 id); - static const char* UserAgent(); + static BBitmap* ResourceBitmap(int32 id); + static const char* UserAgent(); }; -#endif // _UTILS_H +#endif // _UTILS_H diff --git a/source/override.h b/source/override.h index df6cfa5..fc2a796 100644 --- a/source/override.h +++ b/source/override.h @@ -25,4 +25,4 @@ #define override #endif -#endif // _OVERRIDE_H +#endif // _OVERRIDE_H