diff options
author | etobi <git@e-tobi.net> | 2009-11-03 19:02:47 +0100 |
---|---|---|
committer | etobi <git@e-tobi.net> | 2009-11-03 19:02:47 +0100 |
commit | 90b872ed164d8cf004b40f0128fd7a9b3ca7d27e (patch) | |
tree | b558cc69a5f750c98b90d4aac228d9d031d2316a /src | |
download | vdr-plugin-vodcatcher-90b872ed164d8cf004b40f0128fd7a9b3ca7d27e.tar.gz vdr-plugin-vodcatcher-90b872ed164d8cf004b40f0128fd7a9b3ca7d27e.tar.bz2 |
initial commit
Diffstat (limited to 'src')
144 files changed, 10275 insertions, 0 deletions
diff --git a/src/ConfigurationStub.h b/src/ConfigurationStub.h new file mode 100644 index 0000000..578c4c4 --- /dev/null +++ b/src/ConfigurationStub.h @@ -0,0 +1,68 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ConfigurationStub.h 7656 2008-08-09 21:07:45Z svntobi $ + * + */ + +#ifndef CONFIGURATIONSTUB_H_ +#define CONFIGURATIONSTUB_H_ + +#include "IConfiguration.h" + +class ConfigurationStub : public IConfiguration +{ +private: + StreamType _playBackQuality; + +public: + const std::string GetCacheDirName() const + { + return ""; + } + const std::string GetSourcesFileName() const + { + return ""; + } + int GetMaxCacheAge() const + { + return 0; + } + void SetMaxCacheAge(const int age) + { + } + void SetPlayBackQuality(const StreamType quality) + { + _playBackQuality = quality; + } + StreamType GetPlayBackQuality() const + { + return _playBackQuality; + } + + MediaPlayerType GetMediaPlayerType() const + { + return Mplayer; + } + + void SetMediaPlayerType(MediaPlayerType) + { + } +}; + +#endif diff --git a/src/CriticalSection.h b/src/CriticalSection.h new file mode 100644 index 0000000..ee60747 --- /dev/null +++ b/src/CriticalSection.h @@ -0,0 +1,36 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: CriticalSection.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___CRITICALSECTION_H +#define ___CRITICALSECTION_H + +class ICriticalSection +{ +public: + virtual ~ICriticalSection() + { + } + virtual void Enter() = 0; + virtual void Leave() = 0; +}; + +#endif diff --git a/src/CurlDownloader.cc b/src/CurlDownloader.cc new file mode 100644 index 0000000..29a0dfd --- /dev/null +++ b/src/CurlDownloader.cc @@ -0,0 +1,82 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: CurlDownloader.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <sstream> +#include <curl/curl.h> +#include "CurlDownloader.h" +#include "IDownloadCache.h" +#include "Download.h" + +using namespace std; + +CurlDownloader::CurlDownloader(IDownloadCache& downloadCache) : + downloadCache(downloadCache) +{ +} + +bool CurlDownloader::PerformDownload(Download& download) +{ + stringstream stream; + CURL *curl; + CURLcode res; + + curl = curl_easy_init(); + if (curl) + { + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &CurlDownloader::WriteDataToStream); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream); + curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &download); + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); +#ifdef DEBUG + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); +#endif + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); + curl_easy_setopt(curl, CURLOPT_USERAGENT, "vdr-vodcatcher/0.1"); + curl_easy_setopt(curl, CURLOPT_URL, download.GetUrl().c_str()); + res = curl_easy_perform(curl); + curl_easy_cleanup(curl); + if (CURLE_OK == res) + { + downloadCache.Put(stream, download.GetUrl()); + return true; + } + } + return false; +} + +size_t CurlDownloader::WriteDataToStream(const void *buffer, size_t sizeOfMemblock, size_t numberOfMemblocks, + void *streamPointer) +{ + ostream* stream = (ostream*) streamPointer; + + try + { + int bufferSize = sizeOfMemblock * numberOfMemblocks; + stream->write((const char*) buffer, bufferSize); + return bufferSize; + } + catch(...) + { + } + + return 0; +} diff --git a/src/CurlDownloader.h b/src/CurlDownloader.h new file mode 100644 index 0000000..1a4f0f3 --- /dev/null +++ b/src/CurlDownloader.h @@ -0,0 +1,44 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: CurlDownloader.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___CURLDOWNLOADER_H +#define ___CURLDOWNLOADER_H + +#include "IDownloader.h" + +class IDownloadCache; + +class CurlDownloader : public IDownloader +{ +private: + IDownloadCache& downloadCache; + +public: + CurlDownloader(IDownloadCache& downloadCache); + static size_t WriteDataToStream(const void *buffer, size_t sizeOfMemblock, size_t numberOfMemblocks, + void *streamPointer); + // <IDownloader> + bool PerformDownload(Download& download); + // </IDownloader> +}; + +#endif diff --git a/src/CurlDownloader_test.cc b/src/CurlDownloader_test.cc new file mode 100644 index 0000000..f81c37e --- /dev/null +++ b/src/CurlDownloader_test.cc @@ -0,0 +1,97 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: CurlDownloader_test.cc 7656 2008-08-09 21:07:45Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include "CurlDownloader.h" +#include <fstream> +#include <sstream> +#include "StringMessageMock.h" +#include "Download.h" +#include "DownloadCacheMock.h" +#include <stdlib.h> + +using namespace std; + +namespace +{ + +class CurlDownloaderTest : public CxxTest::TestSuite +{ +public: + void tearDown() + { + unlink("test.download"); + } + + void TestWriteData() + { + std::stringstream testStream; + const char* buffer = "MemBlock1MemBlock2MemBlock3"; + + TS_ASSERT_EQUALS(9*2, (int) CurlDownloader::WriteDataToStream( + buffer, 9, 2, &testStream)); + + TS_ASSERT_EQUALS("MemBlock1MemBlock2", testStream.str()); + } + + void TestWriteDataCausingWriteException() + { + std::filebuf streamBuf; + std::ostream testStream(&streamBuf); + testStream.exceptions(ofstream::badbit); + + const char* buffer = "X"; + + TS_ASSERT_EQUALS(0, (int) CurlDownloader::WriteDataToStream( + buffer, 1, 1, &testStream)); + } + + void TestDownload() + { + DownloadCacheMock downloadCache; + CurlDownloader downloader(downloadCache); + Download download("file://test.download"); + + system("echo -n foo >test.download"); + + downloadCache.ExpectMethod("Put", "foo", download.GetUrl()); + + TS_ASSERT(downloader.PerformDownload(download)); + + downloadCache.Verify(); + } + + void TestDownloadFailure() + { + DownloadCacheMock downloadCache; + CurlDownloader downloader(downloadCache); + Download download("file://test.download"); + + unlink("test.download"); + + TS_ASSERT(!downloader.PerformDownload(download)); + + downloadCache.Verify(); + } +}; + +}; diff --git a/src/Download.cc b/src/Download.cc new file mode 100644 index 0000000..68ca273 --- /dev/null +++ b/src/Download.cc @@ -0,0 +1,35 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: Download.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "Download.h" + +using namespace std; + +Download::Download(string url) : + url(url) +{ +} + +string Download::GetUrl() +{ + return url; +} diff --git a/src/Download.h b/src/Download.h new file mode 100644 index 0000000..77e4845 --- /dev/null +++ b/src/Download.h @@ -0,0 +1,40 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: Download.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___DOWNLOAD_H +#define ___DOWNLOAD_H + +#include <string> +#include "RefPtr.h" + +// TODO Download may be removed and replaced by std::string +class Download +{ +private: + std::string url; + +public: + Download(std::string url); + std::string GetUrl(); +}; + +#endif diff --git a/src/DownloadAction.cc b/src/DownloadAction.cc new file mode 100644 index 0000000..17c882a --- /dev/null +++ b/src/DownloadAction.cc @@ -0,0 +1,48 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: DownloadAction.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "DownloadAction.h" + +#include "IDownloadPool.h" +#include "IDownloader.h" +#include "Download.h" +#include "Thread.h" +#include "Sleeper.h" + +using namespace std; + +DownloadAction::DownloadAction(IDownloadPool& downloadPool, IDownloader& downloader) : + downloadPool(downloadPool), downloader(downloader) +{ +} + +bool DownloadAction::Action() +{ + RefPtr<Download> download = downloadPool.GetNextDownload(); + if (download.get()) + { + downloader.PerformDownload(*download); + downloadPool.RemoveDownload(download); + } + + return true; +} diff --git a/src/DownloadAction.h b/src/DownloadAction.h new file mode 100644 index 0000000..68d8f6e --- /dev/null +++ b/src/DownloadAction.h @@ -0,0 +1,44 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: DownloadAction.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___DOWNLOADACTION_H +#define ___DOWNLOADACTION_H + +#include "ThreadAction.h" + +class IDownloadPool; +class IDownloader; + +class DownloadAction : public IThreadAction +{ +private: + IDownloadPool& downloadPool; + IDownloader& downloader; + +public: + DownloadAction(IDownloadPool& downloadPool, IDownloader& downloader); + // <IThreadAction> + bool Action(); + // </IThreadAction> +}; + +#endif diff --git a/src/DownloadAction_test.cc b/src/DownloadAction_test.cc new file mode 100644 index 0000000..daab6f5 --- /dev/null +++ b/src/DownloadAction_test.cc @@ -0,0 +1,98 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: DownloadAction_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include "DownloadAction.h" +#include "StringMessageMock.h" +#include "DownloadQueue.h" +#include "IDownloader.h" +#include "Download.h" + +using namespace std; + +namespace +{ + +class MockDownloader : public StringMessageMock, public IDownloader +{ +public: + bool PerformDownload(Download& download) + { + AddMethod("PerformDownload", download.GetUrl()); + return true; + } +}; + +class DownloadActionTest : public CxxTest::TestSuite +{ +private: + MockDownloader downloader; + DownloadQueue* downloadQueue; + DownloadAction* downloadAction; + +public: + void setUp() + { + downloader.ResetMock(); + downloadQueue = new DownloadQueue(); + downloadAction = new DownloadAction(*downloadQueue, downloader); + } + + void tearDown() + { + delete downloadAction; + delete downloadQueue; + } + + void TestEmptyQueue() + { + TS_ASSERT(downloadAction->Action()); + downloader.Verify(); + } + + void TestOneItemInQueue() + { + RefPtr<Download> download = downloadQueue->AddDownload("url"); + + downloader.ExpectMethod("PerformDownload", "url"); + TS_ASSERT(downloadAction->Action()); + + downloader.Verify(); + TS_ASSERT(NULL == downloadQueue->GetNextDownload().get()); + } + + void TestTwoItemsInQueue() + { + RefPtr<Download> download1 = downloadQueue->AddDownload("url1"); + RefPtr<Download> download2 = downloadQueue->AddDownload("url2"); + + downloader.ExpectMethod("PerformDownload", "url1"); + TS_ASSERT(downloadAction->Action()); + downloader.Verify(); + + downloader.ExpectMethod("PerformDownload", "url2"); + TS_ASSERT(downloadAction->Action()); + downloader.Verify(); + } +}; + +}; diff --git a/src/DownloadCacheMock.cc b/src/DownloadCacheMock.cc new file mode 100644 index 0000000..dc092be --- /dev/null +++ b/src/DownloadCacheMock.cc @@ -0,0 +1,55 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: DownloadCacheMock.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "DownloadCacheMock.h" + +using namespace std; + +DownloadCacheMock::DownloadCacheMock() : + filesAreCached(false), fileAge(0) +{ +} + +RefPtr<istream> DownloadCacheMock::CreateStreamByUrl(const string& url) const +{ + return RefPtr<istream>(streamReturnedByCache); +} + +void DownloadCacheMock::Put(istream& document, const string& url) +{ + AddMethod("Put", MakeString(document.rdbuf()), url); +} + +long DownloadCacheMock::GetAgeInMinutes(const string& url) const +{ + return fileAge; +} + +bool DownloadCacheMock::IsCached(const string& url) const +{ + return filesAreCached; +} + +void DownloadCacheMock::CleanUp(const long maxAge) +{ + AddMethod("CleanUp", MakeString(maxAge)); +} diff --git a/src/DownloadCacheMock.h b/src/DownloadCacheMock.h new file mode 100644 index 0000000..2636ba2 --- /dev/null +++ b/src/DownloadCacheMock.h @@ -0,0 +1,47 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: DownloadCacheMock.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___DOWNLOADCACHEMOCK_H +#define ___DOWNLOADCACHEMOCK_H + +#include "StringMessageMock.h" +#include "IDownloadCache.h" + +class DownloadCacheMock : public StringMessageMock, public IDownloadCache +{ +public: + bool filesAreCached; + int fileAge; + std::istream* streamReturnedByCache; + +public: + DownloadCacheMock(); + // <IDownloadCache> + void Put(std::istream& document, const std::string& url); + RefPtr<std::istream> CreateStreamByUrl(const std::string& url) const; + long GetAgeInMinutes(const std::string& url) const; + bool IsCached(const std::string& url) const; + void CleanUp(const long maxAge); + // </IDownloadCache> +}; + +#endif // ___DOWNLOADCACHEMOCK_H diff --git a/src/DownloadObserver.h b/src/DownloadObserver.h new file mode 100644 index 0000000..9024f74 --- /dev/null +++ b/src/DownloadObserver.h @@ -0,0 +1,35 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: DownloadObserver.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___DOWNLOADOBSERVER_H +#define ___DOWNLOADOBSERVER_H + +class IDownloadObserver +{ +public: + virtual ~IDownloadObserver() + { + } + virtual void DownloadFinished() = 0; +}; + +#endif diff --git a/src/DownloadPoolMock.cc b/src/DownloadPoolMock.cc new file mode 100644 index 0000000..d8b4f06 --- /dev/null +++ b/src/DownloadPoolMock.cc @@ -0,0 +1,67 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: DownloadPoolMock.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "DownloadPoolMock.h" +#include "Download.h" + +using namespace std; + +DownloadPoolMock::DownloadPoolMock() : + StringMessageMock() +{ +} + +DownloadPoolMock::DownloadPoolMock(StringMessageMock& parent) : + StringMessageMock(parent) +{ +} + +RefPtr<Download> DownloadPoolMock::AddDownload(const std::string url) +{ + AddMethod("AddDownload", url); + lastAddedDownload = RefPtr<Download>(new Download(url)); + return lastAddedDownload; +} + +void DownloadPoolMock::RemoveDownload(RefPtr<Download> download) +{ + AddMethod("RemoveDownload", download->GetUrl()); +} + +RefPtr<Download> DownloadPoolMock::GetNextDownload() +{ + AddMethod("GetNextDownload"); + if (!returnedDownload.get()) + { + return RefPtr<Download>(); + } + else + { + return returnedDownload; + } +} + +RefPtr<Download> DownloadPoolMock::GetDownloadByUrl(string url) +{ + AddMethod("GetDownloadByUrl", url); + return returnedDownload; +} diff --git a/src/DownloadPoolMock.h b/src/DownloadPoolMock.h new file mode 100644 index 0000000..cd5db60 --- /dev/null +++ b/src/DownloadPoolMock.h @@ -0,0 +1,48 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: DownloadPoolMock.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___DOWNLOADPOOLMOCK_H +#define ___DOWNLOADPOOLMOCK_H + +#include "StringMessageMock.h" +#include "IDownloadPool.h" + +class DownloadPoolMock : public StringMessageMock, public IDownloadPool +{ +public: + RefPtr<Download> returnedDownload; + RefPtr<Download> lastAddedDownload; + +public: + DownloadPoolMock(); + DownloadPoolMock(StringMessageMock& parent); + + // <IDownloadPool> + //void AddDownload(RefPtr<Download> download); + RefPtr<Download> AddDownload(const std::string url); + void RemoveDownload(RefPtr<Download> download); + RefPtr<Download> GetNextDownload(); + RefPtr<Download> GetDownloadByUrl(std::string url); + // </IDownloadPool> +}; + +#endif // ___DOWNLOADPOOLMOCK_H diff --git a/src/DownloadQueue.cc b/src/DownloadQueue.cc new file mode 100644 index 0000000..0718806 --- /dev/null +++ b/src/DownloadQueue.cc @@ -0,0 +1,91 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: DownloadQueue.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "DownloadQueue.h" +#include "Download.h" + +using namespace std; + +RefPtr<Download> DownloadQueue::GetNextDownload() +{ + if (downloads.empty()) + { + return RefPtr<Download>(); + } + else + { + return downloads.back(); + } +} + +RefPtr<Download> DownloadQueue::GetDownloadByUrl(string url) +{ + DownloadDeque::iterator i = LocateDownload(url); + + if (i != downloads.end()) + { + return *LocateDownload(url); + } + else + { + return RefPtr<Download>(); + } +} + +void DownloadQueue::RemoveDownload(RefPtr<Download> download) +{ + DownloadDeque::iterator i = LocateDownload(download->GetUrl()); + + if (i != downloads.end()) + { + downloads.erase(i); + } +} + +DownloadQueue::DownloadDeque::iterator DownloadQueue::LocateDownload(string url) +{ + DownloadDeque::iterator i; + + for (i = downloads.begin(); i != downloads.end(); i++) + { + if ((*i)->GetUrl() == url) + { + break; + } + } + + return i; +} + +RefPtr<Download> DownloadQueue::AddDownload(const string url) +{ + DownloadDeque::iterator i = LocateDownload(url); + + if (i == downloads.end()) + { + RefPtr<Download> download(new Download(url)); + downloads.push_front(download); + return download; + } + + return *i; +} diff --git a/src/DownloadQueue.h b/src/DownloadQueue.h new file mode 100644 index 0000000..8c6b2cc --- /dev/null +++ b/src/DownloadQueue.h @@ -0,0 +1,48 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: DownloadQueue.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___DOWNLOADQUEUE_H +#define ___DOWNLOADQUEUE_H + +#include <deque> +#include "IDownloadPool.h" + +class DownloadQueue : public IDownloadPool +{ + typedef std::deque< RefPtr<Download> > DownloadDeque; + +private: + DownloadDeque downloads; + +private: + DownloadDeque::iterator LocateDownload(std:: string url); + +public: + // <IDownloadPool> + RefPtr<Download> AddDownload(const std::string url); + virtual void RemoveDownload(RefPtr<Download> download); + RefPtr<Download> GetNextDownload(); + RefPtr<Download> GetDownloadByUrl(std::string url); + // </IDownloadPool> +}; + +#endif // ___DOWNLOADQUEUE_H diff --git a/src/DownloadQueue_test.cc b/src/DownloadQueue_test.cc new file mode 100644 index 0000000..fc6b33a --- /dev/null +++ b/src/DownloadQueue_test.cc @@ -0,0 +1,105 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: DownloadQueue_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include "DownloadQueue.h" +#include "Download.h" + +namespace +{ + +class DownloadQueueTest : public CxxTest::TestSuite +{ +private: + DownloadQueue* queue; + +public: + void setUp() + { + queue = new DownloadQueue(); + } + + void tearDown() + { + delete queue; + } + + void TestEmptyQueue() + { + TS_ASSERT(NULL == queue->GetNextDownload().get()); + } + + void TestAddDownload() + { + RefPtr<Download> download = queue->AddDownload("url"); + TS_ASSERT(NULL != queue->GetNextDownload().get()); + TS_ASSERT_EQUALS("url", queue->GetNextDownload()->GetUrl()); + } + + void TestRemoveDownloadNotInQueue() + { + RefPtr<Download> download1 = queue->AddDownload("url1"); + RefPtr<Download> download2 = queue->AddDownload("url2"); + + TS_ASSERT(NULL != queue->GetNextDownload().get()); + + queue->RemoveDownload(download2); + + TS_ASSERT(NULL != queue->GetNextDownload().get()); + } + + void TestRemoveDownload() + { + RefPtr<Download> download1 = queue->AddDownload("url1"); + RefPtr<Download> download2 = queue->AddDownload("url2"); + + queue->RemoveDownload(download1); + TS_ASSERT_EQUALS("url2", queue->GetNextDownload()->GetUrl()); + + queue->RemoveDownload(download2); + TS_ASSERT(NULL == queue->GetNextDownload().get()); + } + + void TestDontAddDuplicates() + { + RefPtr<Download> download1 = queue->AddDownload("url"); + RefPtr<Download> download2 = queue->AddDownload("url"); + + queue->RemoveDownload(download1); + + TS_ASSERT(NULL == queue->GetNextDownload().get()); + } + + void TestFifo() + { + RefPtr<Download> download1 = queue->AddDownload("url1"); + RefPtr<Download> download2 = queue->AddDownload("url2"); + + TS_ASSERT_EQUALS("url1", queue->GetNextDownload()->GetUrl()); + + queue->RemoveDownload(download1); + + TS_ASSERT_EQUALS("url2", queue->GetNextDownload()->GetUrl()); + } +}; + +}; diff --git a/src/Download_test.cc b/src/Download_test.cc new file mode 100644 index 0000000..cfe087e --- /dev/null +++ b/src/Download_test.cc @@ -0,0 +1,41 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: Download_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include "Download.h" +#include "StringMessageMock.h" + +namespace +{ + +class DownloadTest : public CxxTest::TestSuite +{ +public: + void TestInitialization() + { + Download download("foo"); + TS_ASSERT_EQUALS("foo", download.GetUrl()); + } +}; + +} +; diff --git a/src/Feed.cc b/src/Feed.cc new file mode 100644 index 0000000..b284d65 --- /dev/null +++ b/src/Feed.cc @@ -0,0 +1,66 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: Feed.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "Feed.h" + +using namespace std; + +Feed::Feed(const string& url) : + url(url), _timeToLive(720) +{ + title = "unknown"; +} + +const string Feed::GetTitle() const +{ + return title; +} + +void Feed::SetTitle(const string& title) +{ + (*this).title = title; +} + +const string Feed::GetUrl() const +{ + return url; +} + +const ItemList Feed::GetItems() const +{ + return items; +} + +void Feed::SetTimeToLive(const int timeToLive) +{ + _timeToLive = timeToLive; +} + +int Feed::GetTimeToLive() const +{ + return _timeToLive; +} + +void Feed::AddItem(const Item& item) +{ + items.push_back(item); +} diff --git a/src/Feed.h b/src/Feed.h new file mode 100644 index 0000000..8da43af --- /dev/null +++ b/src/Feed.h @@ -0,0 +1,51 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: Feed.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___FEED_H +#define ___FEED_H + +#include <string> +#include <vector> +#include "Item.h" + +class Feed +{ +private: + std::string url; + std::string title; + ItemList items; + int _timeToLive; + +public: + Feed(const std::string& url); + const std::string GetTitle() const; + void SetTitle(const std::string& title); + const std::string GetUrl() const; + void AddItem(const Item& item); + const ItemList GetItems() const; + void SetTimeToLive(const int _timeToLive); + int GetTimeToLive() const; +}; + +typedef std::vector<Feed> FeedList; + +#endif // ___FEED_H diff --git a/src/FeedMenuController.cc b/src/FeedMenuController.cc new file mode 100644 index 0000000..8511686 --- /dev/null +++ b/src/FeedMenuController.cc @@ -0,0 +1,72 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: FeedMenuController.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "FeedMenuController.h" +#include "IServiceLocator.h" +#include "IListMenu.h" +#include "IMenuFactory.h" +#include "IFeedRepository.h" + +FeedMenuController::FeedMenuController(IMenuFactory& menuFactory, const IFeedRepository& feedRepository) : + _menuFactory(menuFactory), _feedRepository(feedRepository) +{ +} + +void FeedMenuController::Initialize(IListMenu* listMenu) +{ + _menu = listMenu; + + _menu->SetTitle(tr("Video Podcasts")); + + _feeds = _feedRepository.GetRootFeeds(); + + for (FeedList::iterator i = _feeds.begin(); i != _feeds.end(); i++) + { + _menu->AddItem(i->GetTitle()); + } +} + +const eOSState FeedMenuController::ProcessKey(const int selectedFeed, const eKeys key, const eOSState state) +{ + if (!state == osUnknown) + { + return state; + } + + switch (key) + { + case kOk: + { + if ((selectedFeed >= 0) && ((unsigned int) selectedFeed < _feeds.size())) + { + cOsdMenu* itemMenu = _menuFactory.CreateItemMenu(_feeds[selectedFeed]); + _menu->ShowSubMenu(itemMenu); + } + return osContinue; + } + + default: + { + return state; + } + } +} diff --git a/src/FeedMenuController.h b/src/FeedMenuController.h new file mode 100644 index 0000000..e311452 --- /dev/null +++ b/src/FeedMenuController.h @@ -0,0 +1,51 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: FeedMenuController.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___FEEDMENUPRESENTER_H +#define ___FEEDMENUPRESENTER_H + +#include <vdr/osdbase.h> +#include "Feed.h" +#include "IListMenuPresenter.h" +#include "Download.h" + +class IDownloadPool; +class IMenuFactory; +class IFeedRepository; + +class FeedMenuController : public IListMenuPresenter +{ +private: + IMenuFactory& _menuFactory; + const IFeedRepository& _feedRepository; + FeedList _feeds; + IListMenu* _menu; + +public: + FeedMenuController(IMenuFactory& menuFactory, const IFeedRepository& feedRepository); + // <IListMenuPresenter> + void Initialize(IListMenu* listMenu); + const eOSState ProcessKey(const int selectedFeed, const eKeys Key, const eOSState state); + // </IListMenuPresenter> +}; + +#endif // ___FEEDMENUPRESENTER_H diff --git a/src/FeedMenuController_test.cc b/src/FeedMenuController_test.cc new file mode 100644 index 0000000..9013a78 --- /dev/null +++ b/src/FeedMenuController_test.cc @@ -0,0 +1,145 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: FeedMenuController_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <vector> +#include <sstream> +#include <cxxtest/TestSuite.h> +#include "FeedMenuController.h" +#include "ServiceLocatorStub.h" +#include "DownloadPoolMock.h" +#include "IListMenu.h" +#include "ListMenuMock.h" +#include "IMenuFactory.h" +#include "IFeedRepository.h" + +using namespace std; + +namespace +{ + +class FeedRepositoryStub: public IFeedRepository +{ +public: + FeedList Feeds; + +public: + // <IFeedRepository> + Feed GetFeed(std::string url) + { + for (FeedList::iterator i = Feeds.begin(); i < Feeds.end(); i++) + { + if ((*i).GetUrl() == url) + { + return *i; + } + } + return Feed(url); + } + + const FeedList GetRootFeeds() const + { + return Feeds; + } + // </IFeedRepository> +}; + +class MenuFactoryStub: public IMenuFactory +{ +public: + RefPtr<cOsdMenu> Menu; + +public: + cOsdMenu* CreateItemMenu(const Feed& feed) + { + return Menu.get(); + } +}; + +class A_FeedMenuController: public CxxTest::TestSuite +{ +private: + RefPtr<FeedMenuController> _feedMenuController; + RefPtr<MenuFactoryStub> _menuFactory; + RefPtr<FeedRepositoryStub> _feedRepository; + +private: + void setUp() + { + _feedRepository = new FeedRepositoryStub(); + _menuFactory = new MenuFactoryStub(); + _feedMenuController = new FeedMenuController(*_menuFactory, *_feedRepository); + } + +public: + void Should_set_the_menu_title_on_initialization() + { + ListMenuMock menu; + menu.ExpectMethod("SetTitle", "i18n:Video Podcasts"); + _feedMenuController->Initialize(&menu); + VERIFY_EXPECTATIONS(menu); + } + + void Should_add_the_feed_titles_to_the_menu() + { + Feed feed1("feed1Url"); feed1.SetTitle("feed1"); + Feed feed2("feed2Url"); feed2.SetTitle("feed2"); + _feedRepository->Feeds.push_back(feed1); + _feedRepository->Feeds.push_back(feed2); + ListMenuMock menu; + + menu.ExpectMethod("AddItem", "feed1"); + menu.ExpectMethod("AddItem", "feed2"); + + _feedMenuController->Initialize(&menu); + + VERIFY_EXPECTATIONS(menu); + } + + void Should_do_nothing_when_pressing_ok_while_no_feeds_are_present() + { + _menuFactory->Menu = new cOsdMenu(""); + ListMenuMock menu; + _feedMenuController->Initialize(&menu); + menu.ResetMock(); + TS_ASSERT_EQUALS(osContinue, _feedMenuController->ProcessKey(0, kOk, osUnknown)); + VERIFY(menu); + } + + void Should_open_a_sub_menu_when_selecting_a_feed_with_OK() + { + Feed feed1("feed1Url"); feed1.SetTitle("feed1"); + Feed feed2("feed2Url"); feed2.SetTitle("feed2"); + _feedRepository->Feeds.push_back(feed1); + _feedRepository->Feeds.push_back(feed2); + _menuFactory->Menu = new cOsdMenu(""); + ListMenuMock menu; + + menu.ExpectMethod("ShowSubMenu", menu.MakeString(_menuFactory->Menu.get())); + + _feedMenuController->Initialize(&menu); + TS_ASSERT_EQUALS(osContinue, _feedMenuController->ProcessKey(1, kOk, osUnknown)); + + VERIFY_EXPECTATIONS(menu); + } +}; + +}; diff --git a/src/FeedRepository.cc b/src/FeedRepository.cc new file mode 100644 index 0000000..76ba0b4 --- /dev/null +++ b/src/FeedRepository.cc @@ -0,0 +1,79 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: FeedRepository.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "FeedRepository.h" + +#include "IFeedParser.h" +#include "IDownloader.h" +#include "IDownloadCache.h" +#include "Download.h" +#include "IFeedSources.h" +#include "IDownloadPool.h" + +using namespace std; + +FeedRepository::FeedRepository(IDownloadCache& downloadCache, IDownloadPool& downloadPool, IDownloader& downloader, + IFeedParser& feedParser, IFeedSources& feedSources) : + _downloadCache(downloadCache), _downloadPool(downloadPool), _downloader(downloader), _feedParser(feedParser), + _feedSources(feedSources) +{ +} + +Feed FeedRepository::GetFeed(string url) +{ + Feed feed(url); + + if (_downloadCache.IsCached(url)) + { + _feedParser.Parse(feed); + } + + if (!_downloadCache.IsCached(url) || _downloadCache.GetAgeInMinutes(url) >= feed.GetTimeToLive()) + { + RefPtr<Download> download(new Download(url)); + _downloader.PerformDownload(*download); + _feedParser.Parse(feed); + } + + return feed; +} + +const FeedList FeedRepository::GetRootFeeds() const +{ + FeedList feeds; + vector<string> urls = _feedSources.GetFeedUrls(); + + for (vector<string>::iterator i = urls.begin(); i != urls.end(); i++) + { + Feed feed(*i); + _feedParser.Parse(feed); + + if (!_downloadCache.IsCached(*i) || _downloadCache.GetAgeInMinutes(*i) >= feed.GetTimeToLive()) + { + _downloadPool.AddDownload(*i); + } + + feeds.push_back(feed); + } + + return feeds; +} diff --git a/src/FeedRepository.h b/src/FeedRepository.h new file mode 100644 index 0000000..340b700 --- /dev/null +++ b/src/FeedRepository.h @@ -0,0 +1,54 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: FeedRepository.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___FEEDREPOSITORY_H_ +#define ___FEEDREPOSITORY_H_ + +#include "IFeedRepository.h" +#include "RefPtr.h" + +class IDownloadCache; +class IDownloader; +class IFeedParser; +class IFeedSources; +class IDownloadPool; + +class FeedRepository : public IFeedRepository +{ +private: + IDownloadCache& _downloadCache; + IDownloadPool& _downloadPool; + IDownloader& _downloader; + IFeedParser& _feedParser; + IFeedSources& _feedSources; + +public: + FeedRepository(IDownloadCache& downloadCache, IDownloadPool& downloadPool, IDownloader& downloader, + IFeedParser& feedParser, IFeedSources& feedSources); + //<IFeedRepository> + Feed GetFeed(std::string url); + const FeedList GetRootFeeds() const; + //</IFeedRepository> + +}; + +#endif diff --git a/src/FeedRepository_test.cc b/src/FeedRepository_test.cc new file mode 100644 index 0000000..f7086e0 --- /dev/null +++ b/src/FeedRepository_test.cc @@ -0,0 +1,213 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: FeedRepository_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> + +#include "RefPtr.h" +#include "FeedRepository.h" +#include "DownloadCacheMock.h" +#include "DownloadPoolMock.h" +#include "IFeedSources.h" +#include "IDownloader.h" +#include "IFeedParser.h" +#include "Download.h" + +using namespace std; + +namespace +{ + +class FeedSourcesStub : public IFeedSources +{ + void GetFeeds(FeedList& feeds) const + { + } + + const vector<string> GetFeedUrls() const + { + vector<string> urls; + urls.push_back("feedUrl1"); + urls.push_back("feedUrl2"); + return urls; + } +}; + +class FeedParserStub : public IFeedParser +{ + bool Parse(Feed& feed) const + { + feed.SetTitle("Parsed"); + feed.SetTimeToLive(60); + return true; + } +}; + +class DownloaderMock : public IDownloader, public StringMessageMock +{ +public: + bool PerformDownload(Download& download) + { + AddMethod("PerformDownload", download.GetUrl()); + return true; + } +}; + +class A_FeedRepository_with_an_empty_cache : public CxxTest::TestSuite +{ +private: + RefPtr<FeedRepository> _feedRepository; + RefPtr<DownloadCacheMock> _downloadCache; + RefPtr<DownloaderMock> _downloader; + RefPtr<DownloadPoolMock> _downloadPool; + RefPtr<FeedParserStub> _feedParser; + RefPtr<IFeedSources> _feedSources; + +public: + void setUp() + { + _downloadCache = new DownloadCacheMock(); + _downloadCache->filesAreCached = false; + _downloadPool = new DownloadPoolMock(); + _feedSources = new FeedSourcesStub(); + _feedParser = new FeedParserStub(); + _downloader = new DownloaderMock(); + + _feedRepository = new FeedRepository(*_downloadCache, *_downloadPool, *_downloader, *_feedParser, *_feedSources); + } + + void Should_add_the_root_feeds_to_the_download_queue() + { + _downloadPool->ExpectMethod("AddDownload", "feedUrl1"); + _downloadPool->ExpectMethod("AddDownload", "feedUrl2"); + + _feedRepository->GetRootFeeds(); + + VERIFY_EXPECTATIONS(*_downloadPool); + } + + void Should_return_the_root_feeds() + { + FeedList feeds = _feedRepository->GetRootFeeds(); + TS_ASSERT_EQUALS((unsigned int) 2, feeds.size()); + TS_ASSERT_EQUALS("feedUrl1", feeds[0].GetUrl()); + TS_ASSERT_EQUALS("feedUrl2", feeds[1].GetUrl()); + } + + void Should_immediately_download_and_parse_a_feed_requested_by_url() + { + _downloader->ExpectMethod("PerformDownload", "url"); + + Feed feed = _feedRepository->GetFeed("url"); + + VERIFY_EXPECTATIONS(*_downloader); + TS_ASSERT_EQUALS("Parsed", feed.GetTitle()); + } +}; + +class A_FeedRepository_with_uptodate_feeds_in_the_cache : public CxxTest::TestSuite +{ +private: + RefPtr<FeedRepository> _feedRepository; + RefPtr<DownloadCacheMock> _downloadCache; + RefPtr<DownloaderMock> _downloader; + RefPtr<DownloadPoolMock> _downloadPool; + RefPtr<FeedParserStub> _feedParser; + RefPtr<IFeedSources> _feedSources; + +public: + void setUp() + { + _downloadCache = new DownloadCacheMock(); + _downloadCache->filesAreCached = true; + _downloadCache->fileAge = 10; + _downloadPool = new DownloadPoolMock(); + _feedSources = new FeedSourcesStub(); + _feedParser = new FeedParserStub(); + _downloader = new DownloaderMock(); + + _feedRepository = new FeedRepository(*_downloadCache, *_downloadPool, *_downloader, *_feedParser, *_feedSources); + } + + void Should_not_download_but_only_parse_the_root_feeds() + { + FeedList feeds = _feedRepository->GetRootFeeds(); + + VERIFY(*_downloadPool); + VERIFY(*_downloader); + TS_ASSERT_EQUALS("Parsed", feeds[0].GetTitle()); + TS_ASSERT_EQUALS("Parsed", feeds[1].GetTitle()); + } + + void Should_not_download_but_only_parse_the_feed_requested_by_url() + { + Feed feed = _feedRepository->GetFeed("feedUrl"); + + VERIFY(*_downloadPool); + VERIFY(*_downloader); + TS_ASSERT_EQUALS("Parsed", feed.GetTitle()); + } +}; + +class A_FeedRepository_with_expired_feeds_in_the_cache : public CxxTest::TestSuite +{ +private: + RefPtr<FeedRepository> _feedRepository; + RefPtr<DownloadCacheMock> _downloadCache; + RefPtr<DownloaderMock> _downloader; + RefPtr<DownloadPoolMock> _downloadPool; + RefPtr<FeedParserStub> _feedParser; + RefPtr<IFeedSources> _feedSources; + +public: + void setUp() + { + _downloadCache = new DownloadCacheMock(); + _downloadCache->filesAreCached = true; + _downloadCache->fileAge = 100; + _downloadPool = new DownloadPoolMock(); + _feedSources = new FeedSourcesStub(); + _feedParser = new FeedParserStub(); + _downloader = new DownloaderMock(); + + _feedRepository = new FeedRepository(*_downloadCache, *_downloadPool, *_downloader, *_feedParser, *_feedSources); + } + + void Should_add_the_root_feeds_to_the_download_queue() + { + _downloadPool->ExpectMethod("AddDownload", "feedUrl1"); + _downloadPool->ExpectMethod("AddDownload", "feedUrl2"); + + _feedRepository->GetRootFeeds(); + + VERIFY_EXPECTATIONS(*_downloadPool); + } + + void Should_return_the_parsed_root_feeds() + { + FeedList feeds = _feedRepository->GetRootFeeds(); + TS_ASSERT_EQUALS((unsigned int) 2, feeds.size()); + TS_ASSERT_EQUALS("Parsed", feeds[0].GetTitle()); + TS_ASSERT_EQUALS("Parsed", feeds[1].GetTitle()); + } +}; + +}; diff --git a/src/FeedUpdaterImpl.cc b/src/FeedUpdaterImpl.cc new file mode 100644 index 0000000..bd1c142 --- /dev/null +++ b/src/FeedUpdaterImpl.cc @@ -0,0 +1,50 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: FeedUpdaterImpl.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "FeedUpdaterImpl.h" +#include "IFeedSources.h" +#include "IDownloadPool.h" +#include "IDownloadCache.h" +#include "Download.h" + +using namespace std; + +FeedUpdaterImpl::FeedUpdaterImpl(IFeedSources& feedSources, IDownloadPool& downloadPool, IDownloadCache& downloadCache) : + feedSources(feedSources), downloadPool(downloadPool), downloadCache(downloadCache) +{ +} + +void FeedUpdaterImpl::Update() +{ + FeedList feeds; + feedSources.GetFeeds(feeds); + + for (FeedList::iterator i = feeds.begin(); i != feeds.end(); i++) + { + string url = (*i).GetUrl(); + + if (!downloadCache.IsCached(url) || downloadCache.GetAgeInMinutes(url) >= maxAge) + { + RefPtr<Download> download = downloadPool.AddDownload(i->GetUrl()); + } + } +} diff --git a/src/FeedUpdaterImpl.h b/src/FeedUpdaterImpl.h new file mode 100644 index 0000000..b00ea2a --- /dev/null +++ b/src/FeedUpdaterImpl.h @@ -0,0 +1,48 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: FeedUpdaterImpl.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___FEEDUPDATERIMPL_H +#define ___FEEDUPDATERIMPL_H + +#include "RefPtr.h" +#include "IFeedUpdater.h" + +class IFeedSources; +class IDownloadPool; +class IDownloadCache; + +class FeedUpdaterImpl : public IFeedUpdater +{ +private: + static const int maxAge = 2; + IFeedSources& feedSources; + IDownloadPool& downloadPool; + IDownloadCache& downloadCache; + +public: + FeedUpdaterImpl(IFeedSources& feedSources, IDownloadPool& downloadPool, IDownloadCache& downloadCache); + // <IFeedUpdater> + void Update(); + // </IFeedUpdater> +}; + +#endif // ___FEEDUPDATERIMPL_H diff --git a/src/FeedUpdaterImpl_test.cc b/src/FeedUpdaterImpl_test.cc new file mode 100644 index 0000000..c3f8ff3 --- /dev/null +++ b/src/FeedUpdaterImpl_test.cc @@ -0,0 +1,110 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: FeedUpdaterImpl_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include "FeedUpdaterImpl.h" +#include "DownloadPoolMock.h" +#include "IFeedSources.h" +#include "Download.h" +#include "DownloadCacheMock.h" + +using namespace std; + +namespace +{ + +class FeedSourcesStub : public IFeedSources +{ +public: + // <IFeedSources> + void GetFeeds(FeedList& feeds) const + { + Feed feed1("foo"); + Feed feed2("bar"); + feeds.push_back(feed1); + feeds.push_back(feed2); + } + + const vector<string> GetFeedUrls() const + { + return vector<string>(); + } + // </IFeedSources> +}; + +class FeedUpdaterImplTest : public CxxTest::TestSuite +{ +private: + FeedSourcesStub feedSources; + DownloadPoolMock downloadPool; + DownloadCacheMock downloadCache; + FeedUpdaterImpl* feedUpdater; + +public: + void setUp() + { + downloadPool.ResetMock(); + feedUpdater = new FeedUpdaterImpl(feedSources, downloadPool, + downloadCache); + } + + void tearDown() + { + delete feedUpdater; + } + + void TestDownloadNewFeeds() + { + downloadCache.filesAreCached = false; + downloadCache.fileAge = 99; + downloadPool.ExpectMethod("AddDownload", "foo"); + downloadPool.ExpectMethod("AddDownload", "bar"); + + feedUpdater->Update(); + + downloadPool.Verify(); + } + + void TestDontDownloadUptodateFeeds() + { + downloadCache.filesAreCached = true; + downloadCache.fileAge = 1; + + feedUpdater->Update(); + + downloadPool.Verify(); + } + + void TestRefreshOldFeeds() + { + downloadCache.filesAreCached = true; + downloadCache.fileAge = 3; + downloadPool.ExpectMethod("AddDownload", "foo"); + downloadPool.ExpectMethod("AddDownload", "bar"); + + feedUpdater->Update(); + + downloadPool.Verify(); + } +}; + +}; diff --git a/src/FeedUpdaterMock.cc b/src/FeedUpdaterMock.cc new file mode 100644 index 0000000..09094f9 --- /dev/null +++ b/src/FeedUpdaterMock.cc @@ -0,0 +1,28 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: FeedUpdaterMock.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "FeedUpdaterMock.h" + +void FeedUpdaterMock::Update() +{ + AddMethod("Update"); +} diff --git a/src/FeedUpdaterMock.h b/src/FeedUpdaterMock.h new file mode 100644 index 0000000..d503603 --- /dev/null +++ b/src/FeedUpdaterMock.h @@ -0,0 +1,37 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: FeedUpdaterMock.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___FEEDUPDATERMOCK +#define ___FEEDUPDATERMOCK + +#include "IFeedUpdater.h" +#include "StringMessageMock.h" + +class FeedUpdaterMock : public StringMessageMock, public IFeedUpdater +{ +public: + // <IFeedUpdater> + void Update(); + // </IFeedUpdater> +}; + +#endif diff --git a/src/Feed_test.cc b/src/Feed_test.cc new file mode 100644 index 0000000..1bb34be --- /dev/null +++ b/src/Feed_test.cc @@ -0,0 +1,65 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: Feed_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include "Feed.h" + +class A_Feed : public CxxTest::TestSuite +{ +public: + void Should_have_an_url() + { + Feed feed("url"); + TS_ASSERT_EQUALS("url", feed.GetUrl()); + } + + void Should_have_unknown_as_default_title() + { + Feed feed("foo"); + TS_ASSERT_EQUALS("unknown", feed.GetTitle()); + } + + void Should_have_an_assignable_title() + { + Feed feed(""); + feed.SetTitle("bar"); + TS_ASSERT_EQUALS("bar", feed.GetTitle()); + } + + void Should_allow_to_add_items() + { + Feed feed(""); + Item item1 = Item("item1", Rfc822DateTime(""), ""); + Item item2 = Item("item2", Rfc822DateTime(""), ""); + feed.AddItem(item1); + feed.AddItem(item2); + TS_ASSERT_EQUALS(2, (int) feed.GetItems().size()); + TS_ASSERT_EQUALS("item1", feed.GetItems()[0].GetTitle()); + TS_ASSERT_EQUALS("item2", feed.GetItems()[1].GetTitle()); + } + + void Should_have_a_default_time_to_live_of_720_minutes() + { + Feed feed(""); + TS_ASSERT_EQUALS(720, feed.GetTimeToLive()); + } +}; diff --git a/src/FeedsConfigFile.cc b/src/FeedsConfigFile.cc new file mode 100644 index 0000000..df7d3a3 --- /dev/null +++ b/src/FeedsConfigFile.cc @@ -0,0 +1,60 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: FeedsConfigFile.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <fstream> +#include "FeedsConfigFile.h" + +using namespace std; + +FeedsConfigFile::FeedsConfigFile(string sourcesFileName) : + sourcesFileName(sourcesFileName) +{ +} + +void FeedsConfigFile::GetFeeds(FeedList& feeds) const +{ + vector<string> urls = GetFeedUrls(); + for (vector<string>::iterator i = urls.begin(); i != urls.end(); i++) + { + Feed feed(*i); + feeds.push_back(feed); + } +} + +const vector<string> FeedsConfigFile::GetFeedUrls() const +{ + vector<string> urls; + ifstream sourcesFile(sourcesFileName.c_str()); + + string line; + while (getline(sourcesFile, line)) + { + if (line.find("FEED_URL=") == 0) + { + string url = line.substr(9); + + urls.push_back(url); + } + } + + return urls; +} diff --git a/src/FeedsConfigFile.h b/src/FeedsConfigFile.h new file mode 100644 index 0000000..e4cab74 --- /dev/null +++ b/src/FeedsConfigFile.h @@ -0,0 +1,41 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: FeedsConfigFile.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___FEEDSCONFIGFILE_H +#define ___FEEDSCONFIGFILE_H + +#include "IFeedSources.h" + +class FeedsConfigFile : public IFeedSources +{ +private: + std::string sourcesFileName; + +public: + FeedsConfigFile(std::string sourcesFileName); + // <IFeedSources> + void GetFeeds(FeedList& feeds) const; + const std::vector<std::string> GetFeedUrls() const; + // </IFeedSources> +}; + +#endif // ___FEEDSCONFIGFILE_H diff --git a/src/FeedsConfigFile_test.cc b/src/FeedsConfigFile_test.cc new file mode 100644 index 0000000..27b8d0c --- /dev/null +++ b/src/FeedsConfigFile_test.cc @@ -0,0 +1,88 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: FeedsConfigFile_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <fstream> +#include <cxxtest/TestSuite.h> +#include "FeedsConfigFile.h" + +using namespace std; + +namespace +{ + +class FeedsConfigFileTest : public CxxTest::TestSuite +{ +private: + void WriteConfigData(const char* data) + { + ofstream configFile("test.config", ios_base::app); + configFile << data << endl; + configFile.close(); + } + +public: + void setUp() + { + unlink("test.config"); + } + + void tearDown() + { + unlink("test.config"); + } + + void TestEmptyConfigFile() + { + FeedsConfigFile feedSources("test.config"); + FeedList feeds; + feedSources.GetFeeds(feeds); + TS_ASSERT_EQUALS(0, (int) feeds.size()); + } + + void TestSingelFeed() + { + WriteConfigData("FEED_URL=foo\n"); + + FeedsConfigFile feedSources("test.config"); + FeedList feeds; + feedSources.GetFeeds(feeds); + TS_ASSERT_EQUALS(1, (int) feeds.size()); + TS_ASSERT_EQUALS("foo", feeds[0].GetUrl()); + } + + void TestMultipleFeedsWithComments() + { + WriteConfigData("FEED_URL=foo\n"); + WriteConfigData("# Comment\n"); + WriteConfigData("# FEED_URL=abc\n"); + WriteConfigData("FEED_URL=bar\n"); + + FeedsConfigFile feedSources("test.config"); + FeedList feeds; + feedSources.GetFeeds(feeds); + TS_ASSERT_EQUALS(2, (int) feeds.size()); + TS_ASSERT_EQUALS("foo", feeds[0].GetUrl()); + TS_ASSERT_EQUALS("bar", feeds[1].GetUrl()); + } +}; + +}; diff --git a/src/HtmlToText.cc b/src/HtmlToText.cc new file mode 100644 index 0000000..6d24235 --- /dev/null +++ b/src/HtmlToText.cc @@ -0,0 +1,63 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: HtmlToText.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "HtmlToText.h" + +using namespace std; + +string HtmlToText::Convert(std::string html) +{ + string result = ""; + bool isTag = false; + + string::const_iterator htmlIterator = html.begin(); + + while (htmlIterator != html.end()) + { + switch (*htmlIterator) + { + case '<': + { + isTag = true; + break; + } + + case '>': + { + isTag = false; + break; + } + + default: + { + if (!isTag) + { + result = result + *htmlIterator; + } + } + + } + htmlIterator++; + } + + return result; +} diff --git a/src/HtmlToText.h b/src/HtmlToText.h new file mode 100644 index 0000000..2328cf2 --- /dev/null +++ b/src/HtmlToText.h @@ -0,0 +1,34 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: HtmlToText.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___HTMLTOTEXT_H +#define ___HTMLTOTEXT_H + +#include <string> + +class HtmlToText +{ +public: + static std::string Convert(std::string html); +}; + +#endif diff --git a/src/HtmlToText_test.cc b/src/HtmlToText_test.cc new file mode 100644 index 0000000..80affe8 --- /dev/null +++ b/src/HtmlToText_test.cc @@ -0,0 +1,50 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: HtmlToText_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include "HtmlToText.h" + +namespace +{ + +class HtmlToTextTest : public CxxTest::TestSuite +{ +public: + void TestEmpty() + { + TS_ASSERT_EQUALS("", HtmlToText::Convert("")); + } + + void TestNoHtml() + { + TS_ASSERT_EQUALS("test", HtmlToText::Convert("test")); + } + + void TestStripHtmlTags() + { + TS_ASSERT_EQUALS("text text text", + HtmlToText::Convert("<foo>text</foo> text <bar>text")); + } + ; +}; + +}; diff --git a/src/IConfiguration.h b/src/IConfiguration.h new file mode 100644 index 0000000..437e437 --- /dev/null +++ b/src/IConfiguration.h @@ -0,0 +1,51 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: IConfiguration.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___ICONFIGURATION_H +#define ___ICONFIGURATION_H + +#include <string> +#include "Item.h" + +enum MediaPlayerType +{ + Mplayer, + Xineliboutput +}; + +class IConfiguration +{ +public: + virtual ~IConfiguration() + { + } + virtual const std::string GetCacheDirName() const = 0; + virtual const std::string GetSourcesFileName() const = 0; + virtual int GetMaxCacheAge() const = 0; + virtual void SetMaxCacheAge(const int age) = 0; + virtual void SetPlayBackQuality(const StreamType quality) = 0; + virtual StreamType GetPlayBackQuality() const = 0; + virtual void SetMediaPlayerType(MediaPlayerType mediaplayerType) = 0; + virtual MediaPlayerType GetMediaPlayerType() const = 0; +}; + +#endif diff --git a/src/IDownloadCache.h b/src/IDownloadCache.h new file mode 100644 index 0000000..7ff150d --- /dev/null +++ b/src/IDownloadCache.h @@ -0,0 +1,43 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: IDownloadCache.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___IDOWNLOADCACHE_H +#define ___IDOWNLOADCACHE_H + +#include <string> +#include <iostream> +#include "RefPtr.h" + +class IDownloadCache +{ +public: + virtual ~IDownloadCache() + { + } + virtual RefPtr<std::istream> CreateStreamByUrl(const std::string& url) const = 0; + virtual void Put(std::istream& document, const std::string& url) = 0; + virtual long GetAgeInMinutes(const std::string& url) const = 0; + virtual bool IsCached(const std::string& url) const = 0; + virtual void CleanUp(const long maxAge) = 0; +}; + +#endif diff --git a/src/IDownloadPool.h b/src/IDownloadPool.h new file mode 100644 index 0000000..2f0e626 --- /dev/null +++ b/src/IDownloadPool.h @@ -0,0 +1,44 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: IDownloadPool.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___IDOWNLOADPOOL_H +#define ___IDOWNLOADPOOL_H + +#include "RefPtr.h" +#include <string> + +class Download; + +class IDownloadPool +{ +public: + virtual ~IDownloadPool() + { + } + //virtual void AddDownload(RefPtr<Download> download) = 0; + virtual RefPtr<Download> AddDownload(const std::string url) = 0; + virtual void RemoveDownload(RefPtr<Download> download) = 0; + virtual RefPtr<Download> GetNextDownload() = 0; + virtual RefPtr<Download> GetDownloadByUrl(std::string url) = 0; +}; + +#endif diff --git a/src/IDownloader.h b/src/IDownloader.h new file mode 100644 index 0000000..cc1161b --- /dev/null +++ b/src/IDownloader.h @@ -0,0 +1,37 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: IDownloader.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___IDOWNLOADER_H +#define ___IDOWNLOADER_H + +class Download; + +class IDownloader +{ +public: + virtual ~IDownloader() + { + } + virtual bool PerformDownload(Download& download) = 0; +}; + +#endif diff --git a/src/IErrorLogger.h b/src/IErrorLogger.h new file mode 100644 index 0000000..cb7c94a --- /dev/null +++ b/src/IErrorLogger.h @@ -0,0 +1,38 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: IErrorLogger.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___IERRORLOGGER_H +#define ___IERRORLOGGER_H + +#include <string> + +class IErrorLogger +{ +public: + virtual ~IErrorLogger() + { + } + virtual void LogError(const std::string& Message) = 0; + virtual void LogDebug(const std::string& Message) = 0; +}; + +#endif diff --git a/src/IFeedParser.h b/src/IFeedParser.h new file mode 100644 index 0000000..6b7f832 --- /dev/null +++ b/src/IFeedParser.h @@ -0,0 +1,37 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: IFeedParser.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___IFEEDPARSER_H +#define ___IFEEDPARSER_H + +class Feed; + +class IFeedParser +{ +public: + virtual ~IFeedParser() + { + } + virtual bool Parse(Feed& feed) const = 0; +}; + +#endif diff --git a/src/IFeedRepository.h b/src/IFeedRepository.h new file mode 100644 index 0000000..d0bd5e6 --- /dev/null +++ b/src/IFeedRepository.h @@ -0,0 +1,38 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: IFeedRepository.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef IFEEDREPOSITORY_H_ +#define IFEEDREPOSITORY_H_ + +#include "Feed.h" + +class IFeedRepository +{ +public: + virtual ~IFeedRepository() + { + } + virtual Feed GetFeed(std::string url) = 0; + virtual const FeedList GetRootFeeds() const = 0; +}; + +#endif diff --git a/src/IFeedSources.h b/src/IFeedSources.h new file mode 100644 index 0000000..7af8b03 --- /dev/null +++ b/src/IFeedSources.h @@ -0,0 +1,41 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: IFeedSources.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___FEEDSOURCES_H +#define ___FEEDSOURCES_H + +#include <vector> +#include <string> + +#include "Feed.h" + +class IFeedSources +{ +public: + virtual ~IFeedSources() + { + } + virtual void GetFeeds(FeedList& feeds) const = 0; + virtual const std::vector<std::string> GetFeedUrls() const = 0; +}; + +#endif diff --git a/src/IFeedUpdater.h b/src/IFeedUpdater.h new file mode 100644 index 0000000..5e7e565 --- /dev/null +++ b/src/IFeedUpdater.h @@ -0,0 +1,35 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: IFeedUpdater.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___IFEEDUPDATER_H +#define ___IFEEDUPDATER_H + +class IFeedUpdater +{ +public: + virtual ~IFeedUpdater() + { + } + virtual void Update() = 0; +}; + +#endif diff --git a/src/IItemHelpButtonsController.h b/src/IItemHelpButtonsController.h new file mode 100644 index 0000000..82af38e --- /dev/null +++ b/src/IItemHelpButtonsController.h @@ -0,0 +1,34 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: IItemHelpButtonsController.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef IITEMHELPBUTTONSCONTROLLER_H_ +#define IITEMHELPBUTTONSCONTROLLER_H_ + +class IItemHelpButtonsController +{ +public: + virtual void Initialize() = 0; + virtual void ProcessYellowKey() = 0; + virtual void ProcessGreenKey() = 0; +}; + +#endif diff --git a/src/IListMenu.h b/src/IListMenu.h new file mode 100644 index 0000000..8d3e119 --- /dev/null +++ b/src/IListMenu.h @@ -0,0 +1,44 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: IListMenu.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___ILISTMENU_H +#define ___ILISTMENU_H + +#include <string> +#include <vdr/osdbase.h> +#include "IMenu.h" + +class IListMenu : public IMenu +{ +public: + virtual ~IListMenu() + { + } + virtual void SetTitle(const std::string title) = 0; + virtual void AddItem(const std::string item) = 0; + virtual eOSState ShowSubMenu(cOsdMenu* menu) = 0; + virtual void Clear() = 0; + virtual void Refresh() = 0; + virtual bool IsActiveMenu() = 0; +}; + +#endif diff --git a/src/IListMenuPresenter.h b/src/IListMenuPresenter.h new file mode 100644 index 0000000..c0ef578 --- /dev/null +++ b/src/IListMenuPresenter.h @@ -0,0 +1,40 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: IListMenuPresenter.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___ILISTMENUPRESENTER_H +#define ___ILISTMENUPRESENTER_H + +#include <vdr/osdbase.h> + +class IListMenu; + +class IListMenuPresenter +{ +public: + virtual ~IListMenuPresenter() + { + } + virtual void Initialize(IListMenu* listMenu) = 0; + virtual const eOSState ProcessKey(const int selectedItem, const eKeys Key, const eOSState state) = 0; +}; + +#endif diff --git a/src/IMediaPlayer.h b/src/IMediaPlayer.h new file mode 100644 index 0000000..70522ad --- /dev/null +++ b/src/IMediaPlayer.h @@ -0,0 +1,35 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: IMediaPlayer.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef IMEDIAPLAYER_H_ +#define IMEDIAPLAYER_H_ + +#include <string> + +class IMediaPlayer +{ +public: + virtual ~IMediaPlayer() {}; + virtual bool Play(std::string url) = 0; +}; + +#endif /*IMEDIAPLAYER_H_*/ diff --git a/src/IMenu.h b/src/IMenu.h new file mode 100644 index 0000000..83d9ed5 --- /dev/null +++ b/src/IMenu.h @@ -0,0 +1,40 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: IMenu.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___IMENU_H +#define ___IMENU_H + +#include <string> + +class IMenu +{ +public: + virtual ~IMenu() + { + } + virtual void SetRedHelp(std::string text) = 0; + virtual void SetGreenHelp(std::string text) = 0; + virtual void SetYellowHelp(std::string text) = 0; + virtual void SetBlueHelp(std::string text) = 0; +}; + +#endif diff --git a/src/IMenuFactory.h b/src/IMenuFactory.h new file mode 100644 index 0000000..da67e3e --- /dev/null +++ b/src/IMenuFactory.h @@ -0,0 +1,38 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: IMenuFactory.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef IMENUFACTORY_H_ +#define IMENUFACTORY_H_ + +class cOsdMenu; +class Feed; + +class IMenuFactory +{ +public: + virtual ~IMenuFactory() + { + } + virtual cOsdMenu* CreateItemMenu(const Feed& feed)= 0; +}; + +#endif /*IMENUFACTORY_H_*/ diff --git a/src/IServiceLocator.h b/src/IServiceLocator.h new file mode 100644 index 0000000..67e9603 --- /dev/null +++ b/src/IServiceLocator.h @@ -0,0 +1,65 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: IServiceLocator.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___ISERVICELOCATOR_H +#define ___ISERVICELOCATOR_H + +#include "Feed.h" +#include "Item.h" +#include "RefPtr.h" + +class IFeedSources; +class IFeedParser; +class IDownloadPool; +class IDownloadCache; +class IFeedUpdater; +class IThreadAction; +class IPesPlayer; +class IMp3Decoder; +class IThread; +class IErrorLogger; +class cControl; +class cOsdMenu; +class cMenuSetupPage; +class IMenuFactory; + +class IServiceLocator +{ +public: + virtual ~IServiceLocator() + { + } + virtual IFeedSources* GetFeedSources() = 0; + virtual IFeedParser* GetFeedParser() = 0; + virtual IDownloadPool* GetDownloadPool() = 0; + virtual IDownloadCache* GetDownloadCache() = 0; + virtual IThread* GetDownloadThread() = 0; + virtual IFeedUpdater* GetFeedUpdater() = 0; + virtual RefPtr<IThreadAction> CreateDownloadAction() = 0; + virtual cOsdMenu* CreateFeedMenu() = 0; + virtual cOsdMenu* CreateItemView(Feed feed, Item item) = 0; + virtual IErrorLogger* GetErrorLogger() = 0; + virtual cMenuSetupPage* CreateSetupMenu() = 0; + virtual IMenuFactory* GetMenuFactory() = 0; +}; + +#endif // ___ISERVICELOCATOR_H diff --git a/src/IVdrInterface.h b/src/IVdrInterface.h new file mode 100644 index 0000000..7997d67 --- /dev/null +++ b/src/IVdrInterface.h @@ -0,0 +1,38 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: IVdrInterface.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___IVDRINTERFACE_H_ +#define ___IVDRINTERFACE_H_ + +#include <string> + +class IVdrInterface +{ +public: + virtual ~IVdrInterface() + { + } + virtual void ShowMessage(const std::string& message) = 0; + virtual void ShowErrorMessage(const std::string& message) = 0; +}; + +#endif diff --git a/src/Item.cc b/src/Item.cc new file mode 100644 index 0000000..aaa705d --- /dev/null +++ b/src/Item.cc @@ -0,0 +1,92 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: Item.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "Item.h" + +using namespace std; + +Item::Item(const string& title, const Rfc822DateTime& date, const string& description) +:_title(title), _date(date), _description(description) +{ +} + +const string Item::GetTitle() const +{ + return _title; +} + +const Rfc822DateTime Item::GetDate() const +{ + return _date; +} + +const string Item::GetDescription() const +{ + return _description; +} + +void Item::SetSubFeedUrl(const string& url) +{ + _subFeedUrl = url; +} + +const string Item::GetSubFeedUrl() const +{ + return _subFeedUrl; +} + +void Item::SetVideoCastStream(const StreamType quality, const std::string& url) +{ + _streams[quality] = url; +} + +const string Item::GetVideoCastStream(const StreamType quality) const +{ + if ((_streams[quality] == "") && (quality > Low)) + { + return GetVideoCastStream(StreamType(quality - 1)); + } + else + { + return _streams[quality]; + } +} + +void Item::SetStreamLength(const string& streamLength) +{ + _streamLength = streamLength; +} + +const string Item::GetStreamLength() const +{ + return _streamLength; +} + +bool Item::IsVideocast() const +{ + return (Item::GetVideoCastStream(High) != ""); +} + +bool Item::IsCategory() const +{ + return (_subFeedUrl != ""); +} diff --git a/src/Item.h b/src/Item.h new file mode 100644 index 0000000..5da0336 --- /dev/null +++ b/src/Item.h @@ -0,0 +1,62 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: Item.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___ITEM_H +#define ___ITEM_H + +#include <string> +#include <vector> +#include "Rfc822DateTime.h" +#include "StreamType.h" + +class Item +{ +private: + std::string _title; + Rfc822DateTime _date; + std::string _description; + std::string _subFeedUrl; + std::string _streams[3]; + std::string _streamLength; + +public: + Item(const std::string& title, const Rfc822DateTime& date, const std::string& description); + const std::string GetTitle() const; + const Rfc822DateTime GetDate() const; + const std::string GetDescription() const; + + void SetSubFeedUrl(const std::string& url); + const std::string GetSubFeedUrl() const; + + void SetVideoCastStream(const StreamType quality, const std::string& url); + const std::string GetVideoCastStream(const StreamType quality) const; + + void SetStreamLength(const std::string& streamLength); + const std::string GetStreamLength() const; + + bool IsVideocast() const; + bool IsCategory() const; +}; + +typedef std::vector<Item> ItemList; + +#endif // ___ITEM_H diff --git a/src/ItemMenuPresenter.cc b/src/ItemMenuPresenter.cc new file mode 100644 index 0000000..866c504 --- /dev/null +++ b/src/ItemMenuPresenter.cc @@ -0,0 +1,218 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ItemMenuPresenter.cc 7654 2008-08-06 18:40:41Z svntobi $ + * + */ + +#include <vdr/player.h> +#include "ItemMenuPresenter.h" +#include "IServiceLocator.h" +#include "IDownloadPool.h" +#include "IDownloadCache.h" +#include "Download.h" +#include <sstream> +#include "MplayerPlugin.h" +#include "RssFeedParser.h" +#include "IFeedRepository.h" +#include "IMenuFactory.h" +#include "IConfiguration.h" +#include "IVdrInterface.h" + +using namespace std; + +ItemMenuPresenter::ItemMenuPresenter(IServiceLocator& serviceLocator, Feed feed, + RefPtr<IFeedRepository> feedRepository, IConfiguration& configuration, RefPtr<IMediaPlayer> mplayerPlugin, + RefPtr<IVdrInterface> vdrInterface) : + serviceLocator(serviceLocator), feed(feed), _feedRepository(feedRepository), _configuration(configuration), + _mplayerPlugin(mplayerPlugin), _vdrInterface(vdrInterface) +{ +} + +void ItemMenuPresenter::Initialize(IListMenu* listMenu) +{ + menu = listMenu; + menu->SetTitle(feed.GetTitle()); + UpdateMenu(); +} + +const eOSState ItemMenuPresenter::ProcessKey(const int selectedItem, const eKeys key, const eOSState state) +{ + if (state == osUnknown) + { + if (IsValidItemSelection(selectedItem)) + { + return ProcessItemAction(key, displayedItems[selectedItem]); + } + } + + if (menu->IsActiveMenu()) + { + if ((key == kDown) || (key == kUp) || (key == kRight) || (key == kLeft) || (key == kNone)) + { + UpdateDownloadAndPlayButton(selectedItem); + } + } + + return state; +} + +bool ItemMenuPresenter::IsValidItemSelection(int selectedItem) +{ + int maxItems = displayedItems.size(); + return ((selectedItem < maxItems) && (selectedItem >= 0)); +} + +eOSState ItemMenuPresenter::ProcessItemAction(eKeys key, Item item) +{ + switch (key) + { + case kOk: + if (item.IsCategory()) + { + ShowSubCategory(item); + } + else + { + ShowItemView(item); + } + break; + + case kGreen: + if (PlayItem(item)) + { + return osEnd; + } + else + { + return osContinue; + } + + case kYellow: + switch (_configuration.GetPlayBackQuality()) + { + case Low: + _configuration.SetPlayBackQuality(High); + break; + case Medium: + _configuration.SetPlayBackQuality(Low); + break; + case High: + _configuration.SetPlayBackQuality(Medium); + break; + } + UpdateYellowButton(); + break; + default: + break; + } + return osContinue; +} + +void ItemMenuPresenter::UpdateYellowButton() const +{ + menu->SetYellowHelp(StreamTypeToString(_configuration.GetPlayBackQuality())); +} + +void ItemMenuPresenter::ShowItemView(Item item) +{ + cOsdMenu* itemView = serviceLocator.CreateItemView(feed, item); + menu->ShowSubMenu(itemView); +} + +void ItemMenuPresenter::ShowSubCategory(Item item) +{ + Feed feed = _feedRepository->GetFeed(item.GetSubFeedUrl()); + cOsdMenu* itemMenu = serviceLocator.GetMenuFactory()->CreateItemMenu(feed); + menu->ShowSubMenu(itemMenu); +} + +bool ItemMenuPresenter::PlayItem(Item item) +{ + if (item.IsVideocast()) + { + if (_mplayerPlugin->Play(item.GetVideoCastStream(_configuration.GetPlayBackQuality()))) + { + _vdrInterface->ShowMessage(tr("Starting playback, please wait...")); + return true; + } + else + { + _vdrInterface->ShowErrorMessage(tr("Playback failed!")); + } + } + return false; +} + +void ItemMenuPresenter::UpdateMenu() +{ + UpdateItemList(); + UpdateDownloadAndPlayButton(0); + + menu->Refresh(); +} + +void ItemMenuPresenter::UpdateItemList() +{ + displayedItems.clear(); + menu->Clear(); + + RefPtr<Download> download=serviceLocator.GetDownloadPool()->GetDownloadByUrl(feed.GetUrl()); + if (download.get()) + { + menu->AddItem(tr("Downloading...Please wait!")); + } + else + { + ItemList items = feed.GetItems(); + + if (items.empty()) + { + menu->AddItem(tr("No entries!")); + + } + else + { + for (ItemList::iterator i = items.begin(); i != items.end(); i++) + { + string menuEntry = (*i).GetDate().ToShortString(); + menuEntry += "\t" + (*i).GetTitle(); + if ((*i).GetStreamLength() != "") + { + menuEntry += " (" + (*i).GetStreamLength() + ")"; + } + menu->AddItem(menuEntry); + displayedItems.push_back(*i); + } + } + } +} + +void ItemMenuPresenter::UpdateDownloadAndPlayButton(int selectedItem) +{ + if (IsValidItemSelection(selectedItem)) + { + Item item = displayedItems[selectedItem]; + if (item.IsVideocast()) + { + menu->SetGreenHelp(tr("Play")); + menu->SetRedHelp(tr("Record")); + UpdateYellowButton(); + } + } +} diff --git a/src/ItemMenuPresenter.h b/src/ItemMenuPresenter.h new file mode 100644 index 0000000..b08a8b1 --- /dev/null +++ b/src/ItemMenuPresenter.h @@ -0,0 +1,72 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ItemMenuPresenter.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___ITEMMENUPRESENTER_H +#define ___ITEMMENUPRESENTER_H + +#include <vdr/osdbase.h> +#include "IListMenuPresenter.h" +#include "IListMenu.h" +#include "Feed.h" +#include "RefPtr.h" + +class IServiceLocator; +class IItemMenu; +class IMediaPlayer; +class IFeedRepository; +class IConfiguration; +class IVdrInterface; + +class ItemMenuPresenter : public IListMenuPresenter +{ +private: + IServiceLocator& serviceLocator; + Feed feed; + ItemList displayedItems; + IListMenu* menu; + bool _downloading; + RefPtr<IFeedRepository> _feedRepository; + IConfiguration& _configuration; + RefPtr<IMediaPlayer> _mplayerPlugin; + RefPtr<IVdrInterface> _vdrInterface; + +private: + void UpdateMenu(); + void UpdateDownloadAndPlayButton(int selectedItem); + void UpdateItemList(); + void ShowItemView(Item item); + void ShowSubCategory(Item item); + bool PlayItem(Item item); + bool IsValidItemSelection(int selectedItem); + eOSState ProcessItemAction(eKeys key, Item item); + void UpdateYellowButton() const; + +public: + ItemMenuPresenter(IServiceLocator& serviceLocator, Feed feed, RefPtr<IFeedRepository> feedRepository, + IConfiguration& configuration, RefPtr<IMediaPlayer> mplayerPlugin, RefPtr<IVdrInterface> vdrInterface); + // <IListMenuPresenter> + void Initialize(IListMenu* listMenu); + const eOSState ProcessKey(const int selectedItem, const eKeys Key, const eOSState state); + // </IListMenuPresenter> +}; + +#endif // ___ILISTMENUPRESENTER_H diff --git a/src/ItemMenuPresenter_test.cc b/src/ItemMenuPresenter_test.cc new file mode 100644 index 0000000..48386f4 --- /dev/null +++ b/src/ItemMenuPresenter_test.cc @@ -0,0 +1,312 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ItemMenuPresenter_test.cc 7656 2008-08-09 21:07:45Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include "ItemMenuPresenter.h" +#include "ServiceLocatorStub.h" +#include "ListMenuMock.h" +#include "DownloadPoolMock.h" +#include "DownloadCacheMock.h" +#include "vdr-stub/ccontrolstub.h" +#include "IMediaPlayer.h" +#include "IFeedRepository.h" +#include "ConfigurationStub.h" +#include "IVdrInterface.h" + +using namespace std; + +namespace +{ + +class An_ItemMenuPresenter_for_an_empty_feed: public CxxTest::TestSuite +{ +private: + ServiceLocatorStub _serviceLocator; + DownloadCacheMock _downloadCache; + DownloadPoolMock _downloadPool; + RefPtr<IMediaPlayer> _mplayerPlugin; + RefPtr<ListMenuMock> _menu; + RefPtr<Feed> _feed; + RefPtr<ItemMenuPresenter> _presenter; + RefPtr<IFeedRepository> _feedRepository; + RefPtr<IConfiguration> _configuration; + RefPtr<IVdrInterface> _vdrInterface; + +public: + void setUp() + { + _menu = new ListMenuMock(); + _feed = new Feed(""); + _feed->SetTitle("dummy title"); + _presenter = new ItemMenuPresenter(_serviceLocator, *_feed, _feedRepository, *_configuration, _mplayerPlugin, _vdrInterface); + _serviceLocator.downloadPool = &_downloadPool; + } + + void Should_do_nothing() + { + _presenter->Initialize(_menu.get()); + _menu->isActiveMenu = true; + + TS_ASSERT_EQUALS(osUnknown, _presenter->ProcessKey(-1, kOk, osUnknown)); + } + + void Should_display_the_feed_title_as_the_menu_title() + { + _menu->ExpectMethod("SetTitle", "dummy title"); + + _presenter->Initialize(_menu.get()); + + VERIFY_EXPECTATIONS(*_menu); + } + + void Should_display_a_no_entries_message_as_the_first_menu_entry() + { + _menu->ExpectMethod("AddItem", "i18n:No entries!"); + + _presenter->Initialize(_menu.get()); + + VERIFY_EXPECTATIONS(*_menu); + } +}; + +class FeedRepositoryMock: public IFeedRepository +{ +public: + Feed GetFeed(std::string url) { return Feed(""); } + const FeedList GetRootFeeds() const { return FeedList(); } +}; + +class MplayerPluginMock: public IMediaPlayer, public StringMessageMock +{ +public: + bool PlayResult; + + MplayerPluginMock() : + PlayResult(true) + { + } + + bool Play(string url) + { + AddMethod("Play", url); + return PlayResult; + } +}; + +class VdrInterfaceMock: public IVdrInterface, public StringMessageMock +{ +public: + void ShowMessage(const string& message) + { + AddMethod("ShowMessage", message); + } + + void ShowErrorMessage(const string& message) + { + AddMethod("ShowErrorMessage", message); + } +}; + +class An_ItemMenuPresenter_for_a_nonempty_feed : public CxxTest::TestSuite +{ +private: + ServiceLocatorStub _serviceLocator; + DownloadCacheMock _downloadCache; + DownloadPoolMock _downloadPool; + RefPtr<MplayerPluginMock> _mplayerPlugin; + RefPtr<ListMenuMock> _menu; + RefPtr<Feed> _feed; + RefPtr<ItemMenuPresenter> _presenter; + RefPtr<IFeedRepository> _feedRepository; + RefPtr<ConfigurationStub> _configuration; + RefPtr<VdrInterfaceMock> _vdrInterface; + +public: + void setUp() + { + _menu = new ListMenuMock(); + _menu->isActiveMenu = true; + _feed = new Feed(""); + Item item1("item1", Rfc822DateTime("Tue, 10 Jun 2003 04:00:00 GMT"), ""); + Item item2("item2", Rfc822DateTime("Tue, 11 Jun 2003 04:00:00 GMT"), ""); + Item item3("item2", Rfc822DateTime("Tue, 11 Jun 2003 04:00:00 GMT"), ""); + item2.SetVideoCastStream(High, "streamUrlHigh"); + item2.SetVideoCastStream(Medium, "streamUrlMedium"); + item2.SetVideoCastStream(Low, "streamUrlLow"); + item2.SetStreamLength("12 min"); + item3.SetSubFeedUrl("linkUrl"); + _feed->AddItem(item1); + _feed->AddItem(item2); + _feed->AddItem(item3); + _mplayerPlugin = new MplayerPluginMock(); + _configuration = new ConfigurationStub(); + _configuration->SetPlayBackQuality(High); + _vdrInterface = new VdrInterfaceMock(); + _presenter = new ItemMenuPresenter(_serviceLocator, *_feed, _feedRepository, *_configuration, _mplayerPlugin, _vdrInterface); + _feedRepository = new FeedRepositoryMock(); + _serviceLocator.downloadPool = &_downloadPool; + } + + void Should_display_the_item_dates_titels_and_lengths_as_menu_entries() + { + _menu->ExpectMethod("AddItem", "10.06.03\titem1"); + _menu->ExpectMethod("AddItem", "11.06.03\titem2 (12 min)"); + + _presenter->Initialize(_menu.get()); + + VERIFY_EXPECTATIONS(*_menu); + } + + void Should_set_the_green_help_button_to_play_when_moving_the_selection_to_a_videocast_item() + { + _menu->ExpectMethod("SetGreenHelp", "i18n:Play"); + + _presenter->Initialize(_menu.get()); + _presenter->ProcessKey(1, kDown, osContinue); + + VERIFY_EXPECTATIONS(*_menu); + } + + void Should_set_the_red_help_button_to_record_when_moving_the_selection_to_a_videocast_item() + { + _menu->ExpectMethod("SetRedHelp", "i18n:Record"); + + _presenter->Initialize(_menu.get()); + _presenter->ProcessKey(1, kDown, osContinue); + + VERIFY_EXPECTATIONS(*_menu); + } + + void Should_set_the_yellow_help_button_to_the_last_selected_quality_when_moving_the_selection_to_a_videocast_item() + { + _configuration->SetPlayBackQuality(Medium); + + _menu->ExpectMethod("SetYellowHelp", "i18n:Medium"); + + _presenter->Initialize(_menu.get()); + _presenter->ProcessKey(1, kDown, osContinue); + + VERIFY_EXPECTATIONS(*_menu); + } + + void Should_open_a_submenu_when_selecting_a_category_item() + { + cOsdMenu itemMenu(""); + _serviceLocator.itemMenu = &itemMenu; + + _menu->ExpectMethod("ShowSubMenu", _menu->MakeString(&itemMenu)); + + _presenter->Initialize(_menu.get()); + TS_ASSERT_EQUALS(osContinue, _presenter->ProcessKey(2, kOk, osUnknown)); + + VERIFY_EXPECTATIONS(*_menu); + } + + void Should_play_a_stream_in_the_selected_quality_when_pressing_green() + { + cOsdMenu itemMenu(""); + _serviceLocator.itemMenu = &itemMenu; + _configuration->SetPlayBackQuality(Medium); + + _mplayerPlugin->ExpectMethod("Play", "streamUrlMedium"); + + _presenter->Initialize(_menu.get()); + _presenter->ProcessKey(1, kGreen, osUnknown); + + VERIFY_EXPECTATIONS(*_mplayerPlugin); + } + + void Should_leave_the_osd_menu_when_playing_a_stream() + { + cOsdMenu itemMenu(""); + _serviceLocator.itemMenu = &itemMenu; + _configuration->SetPlayBackQuality(Medium); + + _presenter->Initialize(_menu.get()); + TS_ASSERT_EQUALS(osEnd, _presenter->ProcessKey(1, kGreen, osUnknown)); + } + + void Should_display_a_message_when_playing_a_stream() + { + cOsdMenu itemMenu(""); + _serviceLocator.itemMenu = &itemMenu; + _configuration->SetPlayBackQuality(Medium); + _presenter->Initialize(_menu.get()); + + _vdrInterface->ExpectMethod("ShowMessage", "i18n:Starting playback, please wait..."); + + _presenter->ProcessKey(1, kGreen, osUnknown); + + VERIFY(*_vdrInterface); + } + + void Should_display_a_message_when_playing_a_stream_failed() + { + cOsdMenu itemMenu(""); + _serviceLocator.itemMenu = &itemMenu; + _configuration->SetPlayBackQuality(Medium); + _presenter->Initialize(_menu.get()); + _mplayerPlugin->PlayResult = false; + + _vdrInterface->ExpectMethod("ShowErrorMessage", "i18n:Playback failed!"); + + _presenter->ProcessKey(1, kGreen, osUnknown); + + VERIFY(*_vdrInterface); + } + + void Should_not_leave_the_menu_when_playing_a_stream_failed() + { + cOsdMenu itemMenu(""); + _serviceLocator.itemMenu = &itemMenu; + _configuration->SetPlayBackQuality(Medium); + _presenter->Initialize(_menu.get()); + _mplayerPlugin->PlayResult = false; + + TS_ASSERT_EQUALS(osContinue, _presenter->ProcessKey(1, kGreen, osUnknown)); + } + + void Should_toggle_the_quality_when_pressing_the_yellow_key() + { + cOsdMenu itemMenu(""); + _serviceLocator.itemMenu = &itemMenu; + _configuration->SetPlayBackQuality(Low); + _presenter->Initialize(_menu.get()); + + _menu->ResetMock(); + _menu->ExpectMethod("SetYellowHelp", "i18n:High"); + _menu->ExpectMethod("SetYellowHelp", "i18n:Medium"); + _menu->ExpectMethod("SetYellowHelp", "i18n:Low"); + + TS_ASSERT_EQUALS(osContinue, _presenter->ProcessKey(1, kYellow, osUnknown)); + TS_ASSERT_EQUALS(High, _configuration->GetPlayBackQuality()); + + TS_ASSERT_EQUALS(osContinue, _presenter->ProcessKey(1, kYellow, osUnknown)); + TS_ASSERT_EQUALS(Medium, _configuration->GetPlayBackQuality()); + + TS_ASSERT_EQUALS(osContinue, _presenter->ProcessKey(1, kYellow, osUnknown)); + TS_ASSERT_EQUALS(Low, _configuration->GetPlayBackQuality()); + + VERIFY_EXPECTATIONS(*_menu); + } +}; +}; diff --git a/src/ItemView.h b/src/ItemView.h new file mode 100644 index 0000000..1e20908 --- /dev/null +++ b/src/ItemView.h @@ -0,0 +1,39 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ItemView.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___ITEMVIEW_H +#define ___ITEMVIEW_H + +#include <string> +#include "IMenu.h" + +class IItemView : public IMenu +{ +public: + virtual ~IItemView() + { + } + virtual void SetDescription(std::string description) = 0; + virtual void SetTitle(std::string title) = 0; +}; + +#endif diff --git a/src/ItemViewPresenter.cc b/src/ItemViewPresenter.cc new file mode 100644 index 0000000..1bde958 --- /dev/null +++ b/src/ItemViewPresenter.cc @@ -0,0 +1,87 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ItemViewPresenter.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "ItemViewPresenter.h" +#include <vdr/i18n.h> +#include "ItemView.h" +#include "IConfiguration.h" + +using namespace std; + +ItemViewPresenter::ItemViewPresenter(const string feedTitle, const Item item, IConfiguration& configuration) : + feedTitle(feedTitle), item(item), _configuration(configuration) +{ +} + +void ItemViewPresenter::Initialize(IItemView* view) +{ + this->view = view; + view->SetTitle(feedTitle); + + view->SetDescription(item.GetDate().ToLongString() + "\n\n" + item.GetTitle() + "\n\n" + item.GetDescription()); + + if (item.IsVideocast()) + { + view->SetRedHelp(tr("Record")); + view->SetGreenHelp(tr("Play")); + UpdateYellowHelp(); + } + else + { + view->SetRedHelp(""); + view->SetGreenHelp(""); + view->SetYellowHelp(""); + } +} + +eOSState ItemViewPresenter::ProcessKey(eOSState state, eKeys key) +{ + switch (key) + { + case kYellow: + switch (_configuration.GetPlayBackQuality()) + { + case High: + _configuration.SetPlayBackQuality(Medium); + break; + case Medium: + _configuration.SetPlayBackQuality(Low); + break; + case Low: + _configuration.SetPlayBackQuality(High); + break; + } + UpdateYellowHelp(); + return osContinue; + case kRed: + case kGreen: + // indicates the parent, that it can process these keys + return osUnknown; + default: + return state; + } +} + +void ItemViewPresenter::UpdateYellowHelp() +{ + view->SetYellowHelp(StreamTypeToString(_configuration.GetPlayBackQuality())); +} diff --git a/src/ItemViewPresenter.h b/src/ItemViewPresenter.h new file mode 100644 index 0000000..6dd8e4c --- /dev/null +++ b/src/ItemViewPresenter.h @@ -0,0 +1,49 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ItemViewPresenter.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___ITEMVIEWPRESENTER_H +#define ___ITEMVIEWPRESENTER_H + +#include <vdr/osdbase.h> +#include "Item.h" + +class IItemView; +class IConfiguration; + +class ItemViewPresenter +{ +private: + const std::string feedTitle; + const Item item; + IConfiguration& _configuration; + IItemView* view; + +public: + ItemViewPresenter(const std::string feedTitle, const Item item, IConfiguration& configuration); + void Initialize(IItemView* view); + eOSState ProcessKey(eOSState state, eKeys Key); + +private: + void UpdateYellowHelp(); +}; + +#endif diff --git a/src/ItemViewPresenter_test.cc b/src/ItemViewPresenter_test.cc new file mode 100644 index 0000000..5d18723 --- /dev/null +++ b/src/ItemViewPresenter_test.cc @@ -0,0 +1,202 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ItemViewPresenter_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include <string> +#include "Item.h" +#include "ItemView.h" +#include "ItemViewPresenter.h" +#include "ConfigurationStub.h" +#include "RefPtr.h" + +using namespace std; + +namespace +{ + +class ItemViewStub : public IItemView +{ +public: + string description; + string title; + string redHelp; + string greenHelp; + string yellowHelp; + +public: + // <IItemView> + void SetDescription(string description) + { + this->description = description; + } + + void SetTitle(string title) + { + this->title = title; + } + + void SetRedHelp(string text) + { + redHelp = text; + } + + void SetGreenHelp(string text) + { + greenHelp = text; + } + + void SetYellowHelp(string text) + { + yellowHelp = text; + } + void SetBlueHelp(string text) + { + } + // </IItemView> +}; + +class An_ItemViewPresenter_for_any_item : public CxxTest::TestSuite +{ +private: + ItemViewStub view; + RefPtr<ItemViewPresenter> _presenter; + RefPtr<ConfigurationStub> _configuration; + +public: + void setUp() + { + view.title = ""; + view.description = ""; + Item item("title", Rfc822DateTime("long_date"), "description"); + _configuration = new ConfigurationStub(); + _presenter = new ItemViewPresenter("FeedTitle", item, *_configuration); + } + + void Should_show_the_item_description() + { + _presenter->Initialize(&view); + + TS_ASSERT_EQUALS("long_date\n\ntitle\n\ndescription", view.description); + } + + void Should_display_the_feed_title_as_menu_title() + { + _presenter->Initialize(&view); + + TS_ASSERT_EQUALS("FeedTitle", view.title); + } + + void Should_ignore_already_processed_keys() + { + _presenter->Initialize(&view); + + TS_ASSERT_EQUALS(osBack, _presenter->ProcessKey(osBack, kOk)); + } +}; + +class An_ItemViewPresenter_for_a_non_videocast_item : public CxxTest::TestSuite +{ +private: + ItemViewStub view; + RefPtr<ItemViewPresenter> _presenter; + RefPtr<ConfigurationStub> _configuration; + +public: + void setUp() + { + view.title = ""; + view.description = ""; + Item item("title", Rfc822DateTime("long_date"), "description"); + _configuration = new ConfigurationStub(); + _configuration->SetPlayBackQuality(High); + _presenter = new ItemViewPresenter("", item, *_configuration); + } + + void Should_not_display_the_Play_and_Record_help_for_a_non_videocast_item() + { + view.redHelp = view.greenHelp = view.yellowHelp = "dummy"; + + _presenter->Initialize(&view); + + TS_ASSERT_EQUALS("", view.greenHelp); + TS_ASSERT_EQUALS("", view.redHelp); + TS_ASSERT_EQUALS("", view.yellowHelp); + } +}; + +class An_ItemViewPresenter_for_a_videocast_item : public CxxTest::TestSuite +{ +private: + ItemViewStub view; + RefPtr<ItemViewPresenter> _presenter; + RefPtr<ConfigurationStub> _configuration; + +public: + void setUp() + { + view.title = ""; + view.description = ""; + Item item("title", Rfc822DateTime("long_date"), "description"); + item.SetVideoCastStream(High, "streamUrl"); + _configuration = new ConfigurationStub(); + _configuration->SetPlayBackQuality(High); + _presenter = new ItemViewPresenter("", item, *_configuration); + } + + void Should_display_the_Play_Record_and_quality_help_for_a_videocast_item() + { + view.redHelp = view.greenHelp = view.yellowHelp = "dummy"; + _configuration->SetPlayBackQuality(High); + + _presenter->Initialize(&view); + + TS_ASSERT_EQUALS("i18n:Play", view.greenHelp); + TS_ASSERT_EQUALS("i18n:Record", view.redHelp); + TS_ASSERT_EQUALS("i18n:High", view.yellowHelp); + } + + void Should_let_the_parent_menu_handle_play_and_record() + { + _presenter->Initialize(&view); + + TS_ASSERT_EQUALS(osUnknown, _presenter->ProcessKey(osContinue, kRed)); + TS_ASSERT_EQUALS(osUnknown, _presenter->ProcessKey(osContinue, kGreen)); + } + + void Should_toggle_the_quality_when_pressing_the_yellow_key() + { + _presenter->Initialize(&view); + + TS_ASSERT_EQUALS("i18n:High", view.yellowHelp); + + _presenter->ProcessKey(osContinue, kYellow); + TS_ASSERT_EQUALS("i18n:Medium", view.yellowHelp); + + _presenter->ProcessKey(osContinue, kYellow); + TS_ASSERT_EQUALS("i18n:Low", view.yellowHelp); + + _presenter->ProcessKey(osContinue, kYellow); + TS_ASSERT_EQUALS("i18n:High", view.yellowHelp); + } +}; + +}; diff --git a/src/Item_test.cc b/src/Item_test.cc new file mode 100644 index 0000000..08b8a55 --- /dev/null +++ b/src/Item_test.cc @@ -0,0 +1,169 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: Item_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include "Item.h" +#include "RefPtr.h" + +namespace +{ + +class Any_item : public CxxTest::TestSuite +{ +private: + RefPtr<Item> _item; + +public: + void setUp() + { + _item = new Item("title", Rfc822DateTime("01 Jan 2002 00:00::00 GMT"), "description"); + } + + void Should_have_a_title() + { + TS_ASSERT_EQUALS("title", _item->GetTitle()); + } + + void Should_have_a_date() + { + TS_ASSERT_EQUALS("01.01.02", _item->GetDate().ToShortString()); + } + + void Should_have_a_description() + { + TS_ASSERT_EQUALS("description", _item->GetDescription()); + } + + void Should_not_have_videocast_streams() + { + TS_ASSERT_EQUALS("", _item->GetVideoCastStream(High)); + } + + void Should_not_be_a_videocast_item() + { + TS_ASSERT(!_item->IsVideocast()); + } + + void Should_not_be_a_category_item() + { + TS_ASSERT(!_item->IsCategory()); + } + + void Should_have_an_empty_default_stream_length() + { + TS_ASSERT_EQUALS("", _item->GetStreamLength()); + } +}; + +class An_item_with_a_sub_feed_url : public CxxTest::TestSuite +{ +private: + RefPtr<Item> _item; + +public: + void setUp() + { + _item = new Item("title", Rfc822DateTime("01 Jan 2002 00:00::00 GMT"), "description"); + _item->SetSubFeedUrl("linkUrl"); + } + + void Should_have_a_SubFeedUrl() + { + TS_ASSERT_EQUALS("linkUrl", _item->GetSubFeedUrl()); + } + + void Should_be_a_category_item() + { + TS_ASSERT(_item->IsCategory()); + } +}; + +class An_item_with_videocast_streams_in_different_qualities : public CxxTest::TestSuite +{ +private: + RefPtr<Item> _item; + +public: + void setUp() + { + _item = new Item("title", Rfc822DateTime("01 Jan 2002 00:00::00 GMT"), "description"); + _item->SetVideoCastStream(High, "hqStreamUrl"); + _item->SetVideoCastStream(Medium, "mqStreamUrl"); + _item->SetVideoCastStream(Low, "lqStreamUrl"); + _item->SetStreamLength("12 min"); + } + + void Should_have_a_high_quality_stream() + { + TS_ASSERT_EQUALS("hqStreamUrl", _item->GetVideoCastStream(High)); + } + + void Should_have_a_medium_quality_stream() + { + TS_ASSERT_EQUALS("mqStreamUrl", _item->GetVideoCastStream(Medium)); + } + + void Should_have_a_low_quality_stream() + { + TS_ASSERT_EQUALS("lqStreamUrl", _item->GetVideoCastStream(Low)); + } + + void Should_be_a_videocast_item() + { + TS_ASSERT(_item->IsVideocast()); + } + + void Should_have_a_stream_length() + { + TS_ASSERT_EQUALS("12 min", _item->GetStreamLength()); + } +}; + +class An_item_with_only_a_low_quality_videocast_stream : public CxxTest::TestSuite +{ +private: + RefPtr<Item> _item; + +public: + void setUp() + { + _item = new Item("title", Rfc822DateTime("01 Jan 2002 00:00::00 GMT"), "description"); + _item->SetVideoCastStream(Low, "lqStreamUrl"); + } + + void Should_return_the_low_quality_stream_when_requesting_a_high_quality_stream() + { + TS_ASSERT_EQUALS("lqStreamUrl", _item->GetVideoCastStream(High)); + } + + void Should_return_the_low_quality_stream_when_requesting_a_medium_quality_stream() + { + TS_ASSERT_EQUALS("lqStreamUrl", _item->GetVideoCastStream(Medium)); + } + + void Should_be_a_videocast_item() + { + TS_ASSERT(_item->IsVideocast()); + } +}; + +}; diff --git a/src/ListMenuMock.cc b/src/ListMenuMock.cc new file mode 100644 index 0000000..9af2060 --- /dev/null +++ b/src/ListMenuMock.cc @@ -0,0 +1,90 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ListMenuMock.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "ListMenuMock.h" + +using namespace std; + +ListMenuMock::ListMenuMock() +{ + red = ""; + green = ""; + yellow = ""; + blue = ""; + isActiveMenu = true; +} + + +void ListMenuMock::SetTitle(const string title) +{ + AddMethod("SetTitle", title); +} + +void ListMenuMock::AddItem(const string item) +{ + AddMethod("AddItem", item); +} + +eOSState ListMenuMock::ShowSubMenu(cOsdMenu* menu) +{ + AddMethod("ShowSubMenu", MakeString(menu)); + return osContinue; +} + +void ListMenuMock::Clear() +{ + AddMethod("Clear"); +} + +void ListMenuMock::Refresh() +{ + AddMethod("Refresh"); +} + +void ListMenuMock::SetRedHelp(const string text) +{ + AddMethod("SetRedHelp", text); + red = text; +} + +void ListMenuMock::SetGreenHelp(const string text) +{ + AddMethod("SetGreenHelp", text); + green = text; +} + +void ListMenuMock::SetYellowHelp(const string text) +{ + AddMethod("SetYellowHelp", text); + yellow = text; +} + +void ListMenuMock::SetBlueHelp(const string text) +{ + AddMethod("SetBlueHelp", text); + blue = text; +} + +bool ListMenuMock::IsActiveMenu() +{ + return isActiveMenu; +} diff --git a/src/ListMenuMock.h b/src/ListMenuMock.h new file mode 100644 index 0000000..92eb7c5 --- /dev/null +++ b/src/ListMenuMock.h @@ -0,0 +1,58 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ListMenuMock.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___LISTMENUMOCK_H +#define ___LISTMENUMOCK_H + +#include <string> +#include "StringMessageMock.h" +#include "IListMenu.h" + +class ListMenuMock : public StringMessageMock, public IListMenu +{ +public: + std::string red; + std::string green; + std::string yellow; + std::string blue; + bool isActiveMenu; + +private: + void SetHelpString(std::string& str, const char* text); + +public: + ListMenuMock(); + // <IListMenu> + void SetTitle(const std::string title); + void AddItem(const std::string item); + void SetRedHelp(const std::string text); + void SetGreenHelp(const std::string text); + void SetYellowHelp(const std::string text); + void SetBlueHelp(const std::string text); + eOSState ShowSubMenu(cOsdMenu* menu); + void Clear(); + void Refresh(); + bool IsActiveMenu(); + // </IListMenu> +}; + +#endif diff --git a/src/LocalFileCache.cc b/src/LocalFileCache.cc new file mode 100644 index 0000000..b46ec66 --- /dev/null +++ b/src/LocalFileCache.cc @@ -0,0 +1,121 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: LocalFileCache.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <sys/stat.h> +#include <fstream> +#include <dirent.h> +#include "LocalFileCache.h" +#include "SdbmHashCalculator.h" +#include <values.h> + +using namespace std; + +LocalFileCache::LocalFileCache(const string& cacheDirName) : + _cacheDirName(cacheDirName) +{ +} + +RefPtr<istream> LocalFileCache::CreateStreamByUrl(const string& url) const +{ + ifstream* localFile = new ifstream(); + localFile->open(UrlToLocalFileName(url).c_str()); + if (!localFile->fail()) + { + return RefPtr<istream>(localFile); + } + else + { + delete localFile; + return RefPtr<istream>(NULL); + } +} + +void LocalFileCache::Put(istream& document, const string& url) +{ + ofstream localFile(UrlToLocalFileName(url).c_str()); + localFile << document.rdbuf(); + localFile.close(); + if (!localFile.good()) + { + unlink(UrlToLocalFileName(url).c_str()); + } +} + +string LocalFileCache::UrlToLocalFileName(const string& url) const +{ + return _cacheDirName + "/" + SdbmHashCalculator::Calculate(url); +} + +long LocalFileCache::GetAgeInMinutes(const string& url) const +{ + return GetLocalFileAge(UrlToLocalFileName(url)); +} + +bool LocalFileCache::IsCached(const string& url) const +{ + struct stat buf; + if (0 == stat(UrlToLocalFileName(url).c_str(), &buf)) + { + return true; + } + else + { + return false; + } +} + +void LocalFileCache::CleanUp(const long maxAgeInDays) +{ + DIR* directory = opendir(_cacheDirName.c_str()); + + if (directory) + { + struct dirent* entry; + while ((entry = readdir(directory))) + { + string fileName = entry->d_name; + if ((fileName != ".") & (fileName != "..")) + { + fileName = string(_cacheDirName) + "/" + fileName; + if (GetLocalFileAge(fileName) >= maxAgeInDays * 60 * 24) + { + remove(fileName.c_str()); + } + } + } + } + + closedir(directory); +} + +long LocalFileCache::GetLocalFileAge(const string& localFileName) const +{ + struct stat buf; + time_t tm = time(NULL); + + if (0 == stat(localFileName.c_str(), &buf)) + { + return (tm - buf.st_mtime) / 60 ; + } + + return MAXLONG; +} diff --git a/src/LocalFileCache.h b/src/LocalFileCache.h new file mode 100644 index 0000000..6c31128 --- /dev/null +++ b/src/LocalFileCache.h @@ -0,0 +1,50 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: LocalFileCache.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___LOCALFILECACHE_H +#define ___LOCALFILECACHE_H + +#include <string> +#include <iostream> +#include "IDownloadCache.h" + +class LocalFileCache : public IDownloadCache +{ +private: + std::string _cacheDirName; + +private: + std::string UrlToLocalFileName(const std::string& url) const; + long GetLocalFileAge(const std::string& localFileName) const; + +public: + LocalFileCache(const std::string& cacheDirName); + // <IDownloadCache> + RefPtr<std::istream> CreateStreamByUrl(const std::string& url) const; + void Put(std::istream& document, const std::string& url); + long GetAgeInMinutes(const std::string& url) const; + bool IsCached(const std::string& url) const; + void CleanUp(const long maxAgeInDays); + // </IDownloadCache> +}; + +#endif // ___LOCALFILECACHE_H diff --git a/src/LocalFileCache_test.cc b/src/LocalFileCache_test.cc new file mode 100644 index 0000000..6bd8379 --- /dev/null +++ b/src/LocalFileCache_test.cc @@ -0,0 +1,160 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: LocalFileCache_test.cc 7656 2008-08-09 21:07:45Z svntobi $ + * + */ + +#include <time.h> +#include <sstream> +#include <cxxtest/TestSuite.h> +#include "LocalFileCache.h" +#include "SdbmHashCalculator.h" +#include "values.h" +#include <stdlib.h> + +using namespace std; + +namespace +{ + +const string CacheDir("test.cache"); + +class An_empty_LocalFileCache: public CxxTest::TestSuite +{ +private: + RefPtr<LocalFileCache> _localFileCache; + +private: + void CreateCachedFile(string fileName, long age) + { + string cachedFileName = SdbmHashCalculator::Calculate(fileName); + + time_t fileTime = time(NULL) - age * 60; + struct tm *timeComponents = localtime(&fileTime); + + char formattedTime[11]; + strftime(formattedTime, 11, "%y%m%d%H%M", timeComponents); + + string touchCommand = string("touch -t ") + formattedTime + " " + + CacheDir + "/" + cachedFileName; + + system(touchCommand.c_str()); + } + +public: + void setUp() + { + system(("rm -rf " + CacheDir).c_str()); + system(("mkdir " + CacheDir).c_str()); + _localFileCache = new LocalFileCache(CacheDir); + } + + void tearDown() + { + system(("rm -rf " + CacheDir).c_str()); + } + + void Should_not_return_any_data() + { + TS_ASSERT(NULL == _localFileCache->CreateStreamByUrl("foo://bar").get()); + } + + void Should_return_the_data_put_into_the_cache() + { + stringstream input("foo"); + _localFileCache->Put(input, "http://foo"); + + RefPtr<istream> output = _localFileCache->CreateStreamByUrl("http://foo"); + TS_ASSERT(NULL != output.get()); + + stringstream outputStr; + outputStr << output->rdbuf(); + TS_ASSERT_EQUALS(input.str(), outputStr.str()); + } + + void Should_return_different_data_by_different_urls() + { + stringstream input1("foo"); + stringstream input2("bar"); + + _localFileCache->Put(input1, "http://foo/baz"); + _localFileCache->Put(input2, "http://bar/baz"); + + stringstream output1; + stringstream output2; + + output1 << _localFileCache->CreateStreamByUrl("http://foo/baz")->rdbuf(); + output2 << _localFileCache->CreateStreamByUrl("http://bar/baz")->rdbuf(); + + TS_ASSERT_EQUALS(input1.str(), output1.str()); + TS_ASSERT_EQUALS(input2.str(), output2.str()); + } + + void Should_return_the_age_of_an_existing_entry_in_minutes() + { + CreateCachedFile("testFile", 5); + TS_ASSERT_EQUALS(5, _localFileCache->GetAgeInMinutes("testFile")); + } + + void Should_return_the_maximum_age_for_a_non_existing_entry_in_minutes() + { + TS_ASSERT_EQUALS(MAXLONG, _localFileCache->GetAgeInMinutes("testFile")); + } + + void Should_tell_if_a_file_is_cached() + { + TS_ASSERT(!_localFileCache->IsCached("testFile")); + + CreateCachedFile("testFile", 0); + TS_ASSERT(_localFileCache->IsCached("testFile")); + } + + void Should_not_clean_up_younger_files() + { + CreateCachedFile("testFile1", 5); // 5 minutes + CreateCachedFile("testFile2", 5 * 60 * 24); // 5 days + TS_ASSERT(_localFileCache->IsCached("testFile1")); + TS_ASSERT(_localFileCache->IsCached("testFile2")); + + _localFileCache->CleanUp(10); + + TS_ASSERT(_localFileCache->IsCached("testFile1")); + TS_ASSERT(_localFileCache->IsCached("testFile2")); + } + + void Should_clean_up_older_files() + { + CreateCachedFile("testFile1", 5 * 60 * 24); // 5 days + CreateCachedFile("testFile2", 10 * 60 * 24); // 10 days + TS_ASSERT(_localFileCache->IsCached("testFile1")); + TS_ASSERT(_localFileCache->IsCached("testFile2")); + + _localFileCache->CleanUp(10); + + TS_ASSERT(_localFileCache->IsCached("testFile1")); + TS_ASSERT(!_localFileCache->IsCached("testFile2")); + } + + void Should_delete_a_file_if_it_can_not_be_written_successfully() + { + // TODO: Any ideas how to test this? + } +}; + +}; diff --git a/src/Menu.h b/src/Menu.h new file mode 100644 index 0000000..34a24ae --- /dev/null +++ b/src/Menu.h @@ -0,0 +1,38 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: Menu.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___MENU_H +#define ___MENU_H + +class IMenu +{ +public: + virtual ~IMenu() + { + } + virtual void SetRedHelp(std::string text) = 0; + virtual void SetGreenHelp(std::string text) = 0; + virtual void SetYellowHelp(std::string text) = 0; + virtual void SetBlueHelp(std::string text) = 0; +}; + +#endif diff --git a/src/MplayerPlugin.cc b/src/MplayerPlugin.cc new file mode 100644 index 0000000..1ce94b0 --- /dev/null +++ b/src/MplayerPlugin.cc @@ -0,0 +1,65 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: MplayerPlugin.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "MplayerPlugin.h" +#include <vdr/plugin.h> +#include <iostream> +#include <fstream> +#include "IErrorLogger.h" + +using namespace std; + +const char* MplayerPlugin::ServiceId = "MPlayer-Play-v1"; + +MplayerPlugin::MplayerPlugin(IErrorLogger& errorLogger) : + _errorLogger(errorLogger) +{ + +} + +bool MplayerPlugin::Play(string url) +{ + _errorLogger.LogDebug("Starting to play " + url); + + MPlayerServiceData data; + const char* const tmpPlayListFileName = "/tmp/vodcatcher.pls"; + + ofstream tmpPlayList(tmpPlayListFileName); + tmpPlayList << url; + tmpPlayList.close(); + + data.data.filename = tmpPlayListFileName; + + if (!cPluginManager::CallFirstService(ServiceId, &data)) + { + _errorLogger.LogDebug((string)"Failed to locate Mplayer service '" + ServiceId + "'"); + return false; + } + + if (!data.result) + { + _errorLogger.LogDebug("Mplayer service failed"); + return false; + } + + return true; +} diff --git a/src/MplayerPlugin.h b/src/MplayerPlugin.h new file mode 100644 index 0000000..e10ef4c --- /dev/null +++ b/src/MplayerPlugin.h @@ -0,0 +1,50 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: MplayerPlugin.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___MPLAYERPLUGIN_H +#define ___MPLAYERPLUGIN_H + +#include "IMediaPlayer.h" + +class IErrorLogger; + +class MplayerPlugin : public IMediaPlayer +{ +private: + static const char* ServiceId; + IErrorLogger& _errorLogger; + +public: + MplayerPlugin(IErrorLogger& errorLogger); + virtual bool Play(std::string url); +}; + +struct MPlayerServiceData +{ + int result; + union + { + const char *filename; + } data; +}; + +#endif diff --git a/src/OsdItemView.cc b/src/OsdItemView.cc new file mode 100644 index 0000000..c41a39f --- /dev/null +++ b/src/OsdItemView.cc @@ -0,0 +1,92 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: OsdItemView.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "OsdItemView.h" +#include "ItemViewPresenter.h" + +using namespace std; + +OsdItemView::OsdItemView(RefPtr<ItemViewPresenter> presenter) +:cMenuText("", ""), presenter(presenter) +{ + this->presenter->Initialize(this); +} + +void OsdItemView::SetTitle(string title) +{ + cMenuText::SetTitle(title.c_str()); +} + +void OsdItemView::SetDescription(string description) +{ + SetText(description.c_str()); +} + +eOSState OsdItemView::ProcessKey(eKeys Key) +{ + eOSState state = cMenuText::ProcessKey(Key); + + return presenter->ProcessKey(state, Key); +} + +void OsdItemView::SetRedHelp(string text) +{ + redHelp = text; + UpdateHelpButtons(); +} + +void OsdItemView::SetGreenHelp(string text) +{ + greenHelp = text; + UpdateHelpButtons(); +} + +void OsdItemView::SetYellowHelp(string text) +{ + yellowHelp = text; + UpdateHelpButtons(); +} + +void OsdItemView::SetBlueHelp(string text) +{ + blueHelp = text; + UpdateHelpButtons(); +} + +void OsdItemView::UpdateHelpButtons() +{ + cMenuText::SetHelp(EmptyToNull(redHelp.c_str()), + EmptyToNull(greenHelp.c_str()), EmptyToNull(yellowHelp.c_str()), + EmptyToNull(blueHelp.c_str())); +} + +const char* OsdItemView::EmptyToNull(const char* str) +{ + if (*str) + { + return str; + } + else + { + return NULL; + } +} diff --git a/src/OsdItemView.h b/src/OsdItemView.h new file mode 100644 index 0000000..d106b57 --- /dev/null +++ b/src/OsdItemView.h @@ -0,0 +1,58 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: OsdItemView.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___OSDITEMVIEW_H +#define ___OSDITEMVIEW_H + +#include <vdr/menu.h> +#include "ItemView.h" +#include "RefPtr.h" + +class ItemViewPresenter; + +class OsdItemView : public cMenuText, public IItemView +{ +private: + RefPtr<ItemViewPresenter> presenter; + std::string redHelp; + std::string greenHelp; + std::string yellowHelp; + std::string blueHelp; + +private: + void UpdateHelpButtons(); + const char* EmptyToNull(const char* str); + +public: + OsdItemView(RefPtr<ItemViewPresenter> presenter); + eOSState ProcessKey(eKeys Key); + // <IItemView> + void SetDescription(std::string description); + void SetTitle(std::string title); + void SetRedHelp(std::string text); + void SetGreenHelp(std::string text); + void SetYellowHelp(std::string text); + void SetBlueHelp(std::string text); + // </IItemView> +}; + +#endif diff --git a/src/OsdListMenu.cc b/src/OsdListMenu.cc new file mode 100644 index 0000000..1a995b7 --- /dev/null +++ b/src/OsdListMenu.cc @@ -0,0 +1,112 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: OsdListMenu.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "OsdListMenu.h" +#include "IListMenuPresenter.h" + +using namespace std; + +OsdListMenu::OsdListMenu(RefPtr<IListMenuPresenter> presenter, int tabStop1) +:cOsdMenu("", tabStop1), presenter(presenter) +{ + this->presenter->Initialize(this); +} + +void OsdListMenu::SetTitle(const string title) +{ + cOsdMenu::SetTitle(title.c_str()); +} + +eOSState OsdListMenu::ProcessKey(eKeys Key) +{ + eOSState state = cOsdMenu::ProcessKey(Key); + + return presenter->ProcessKey(Current(), Key, state); +} + +void OsdListMenu::AddItem(const std::string item) +{ + Add(new cOsdItem(item.c_str())); +} + +eOSState OsdListMenu::ShowSubMenu(cOsdMenu* menu) +{ + return AddSubMenu(menu); +} + +void OsdListMenu::Clear() +{ + cOsdMenu::Clear(); +} + +void OsdListMenu::Refresh() +{ + cOsdMenu::Display(); +} + +void OsdListMenu::SetRedHelp(const string text) +{ + redHelp = text; + UpdateHelpButtons(); +} + +void OsdListMenu::SetGreenHelp(const string text) +{ + greenHelp = text; + UpdateHelpButtons(); +} + +void OsdListMenu::SetYellowHelp(string text) +{ + yellowHelp = text; + UpdateHelpButtons(); +} + +void OsdListMenu::SetBlueHelp(const string text) +{ + blueHelp = text; + UpdateHelpButtons(); +} + +void OsdListMenu::UpdateHelpButtons() +{ + cOsdMenu::SetHelp(EmptyToNull(redHelp.c_str()), + EmptyToNull(greenHelp.c_str()), EmptyToNull(yellowHelp.c_str()), + EmptyToNull(blueHelp.c_str())); +} + +const char* OsdListMenu::EmptyToNull(const char* str) const +{ + if (*str) + { + return str; + } + else + { + return NULL; + } +} + +bool OsdListMenu::IsActiveMenu() +{ + return !HasSubMenu(); +} diff --git a/src/OsdListMenu.h b/src/OsdListMenu.h new file mode 100644 index 0000000..a3a20c9 --- /dev/null +++ b/src/OsdListMenu.h @@ -0,0 +1,66 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: OsdListMenu.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___OSDLISTMENU_H +#define ___OSDLISTMENU_H + +#include <string> +#include <vdr/osdbase.h> +#include "IListMenu.h" +#include "RefPtr.h" + +class IListMenuPresenter; + +class OsdListMenu : public cOsdMenu, public IListMenu +{ +private: + RefPtr<IListMenuPresenter> presenter; + std::string redHelp; + std::string greenHelp; + std::string yellowHelp; + std::string blueHelp; + +private: + void UpdateHelpButtons(); + const char* EmptyToNull(const char* str) const; + +public: + OsdListMenu(RefPtr<IListMenuPresenter> presenter, int tabStop1 = 0); + // <cOsdMenu> + eOSState ProcessKey(eKeys Key); + // <cOsdMenu> + + // <IListMenu> + void SetTitle(const std::string title); + void SetRedHelp(const std::string text); + void SetGreenHelp(const std::string text); + void SetYellowHelp(const std::string text); + void SetBlueHelp(const std::string text); + void AddItem(const std::string item); + eOSState ShowSubMenu(cOsdMenu* menu); + void Clear(); + void Refresh(); + bool IsActiveMenu(); + // </IListMenu> +}; + +#endif // ___OSDLISTMENU_H diff --git a/src/OsdSetupMenu.cc b/src/OsdSetupMenu.cc new file mode 100644 index 0000000..1858560 --- /dev/null +++ b/src/OsdSetupMenu.cc @@ -0,0 +1,43 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: OsdSetupMenu.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "OsdSetupMenu.h" +#include "IConfiguration.h" + +const char* OsdSetupMenu::AvailableMediaPlayers[2] = {"MPlayer", "Xineliboutput"}; + +OsdSetupMenu::OsdSetupMenu(IConfiguration& configuration) +:configuration(configuration) +{ + maxCacheAge = configuration.GetMaxCacheAge(); + mediaPlayer = configuration.GetMediaPlayerType(); + Add(new cMenuEditIntItem(tr("Max. download cache age (days)"), &maxCacheAge)); + Add(new cMenuEditStraItem(tr("Media Player"), &mediaPlayer, 2, AvailableMediaPlayers)); +} + +void OsdSetupMenu::Store() +{ + configuration.SetMaxCacheAge(maxCacheAge); + configuration.SetMediaPlayerType((MediaPlayerType) mediaPlayer); + SetupStore("MaxCacheAge", maxCacheAge); + SetupStore("MediaPlayerType", mediaPlayer); +} diff --git a/src/OsdSetupMenu.h b/src/OsdSetupMenu.h new file mode 100644 index 0000000..ab92a3a --- /dev/null +++ b/src/OsdSetupMenu.h @@ -0,0 +1,45 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: OsdSetupMenu.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___OSDSETUPMENU_H +#define ___OSDSETUPMENU_H + +#include <vdr/menuitems.h> + +class IConfiguration; + +class OsdSetupMenu : public cMenuSetupPage +{ + static const char* AvailableMediaPlayers[2]; +public: + IConfiguration& configuration; + int maxCacheAge; + int mediaPlayer; + +protected: + void Store(); + +public: + OsdSetupMenu(IConfiguration& configuration); +}; + +#endif diff --git a/src/PluginCreator.cc b/src/PluginCreator.cc new file mode 100644 index 0000000..77a039b --- /dev/null +++ b/src/PluginCreator.cc @@ -0,0 +1,34 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: PluginCreator.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "VodcatcherPlugin.h" +#include "ServiceLocatorImpl.h" + +using namespace std; + +extern "C" void *VDRPluginCreator() +{ + VodcatcherPlugin* plugin = new VodcatcherPlugin; + RefPtr<IServiceLocator> serviceLocator(new ServiceLocatorImpl(*plugin)); + plugin->SetServiceLocator(serviceLocator); + return plugin; +} diff --git a/src/Queue_test.cc b/src/Queue_test.cc new file mode 100644 index 0000000..2700cce --- /dev/null +++ b/src/Queue_test.cc @@ -0,0 +1,51 @@ +#include <cxxtest/TestSuite.h> + +#include <deque> +#include <string> +#include "RefPtr.h" + +using namespace std; + +template<class T> class Queue +{ +private: + std::deque< RefPtr<T> > _queue; + +public: + void Add(RefPtr<T> item) + { + _queue.push_front(item); + } + + //void Remove(T item); + RefPtr<T> GetNext() + { + if (_queue.empty()) + { + return RefPtr<T>(); + } + else + { + return _queue.back(); + } + } + //T GetByString(std::string url); +}; + +class A_queue : public CxxTest::TestSuite +{ +public: + void Should_by_empty_by_default() + { + Queue<string> queue; + TS_ASSERT(!queue.GetNext().IsAssigned()); + } + + void Should_allow_to_add_items() + { + Queue<string> queue; + queue.Add(RefPtr<string>(new string("item"))); + TS_ASSERT(queue.GetNext().IsAssigned()); + TS_ASSERT_EQUALS("item", *queue.GetNext()); + } +}; diff --git a/src/RefPtr.h b/src/RefPtr.h new file mode 100644 index 0000000..c52af5b --- /dev/null +++ b/src/RefPtr.h @@ -0,0 +1,144 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: RefPtr.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___REFPTR__H +#define ___REFPTR__H + +#include <stddef.h> + +// +// A small note: RefPtr can cope with incomplete types as described in +// http://www.octopull.demon.co.uk/arglib/TheGrin.html by Alan Griffiths +// + +template<class X> class RefPtr +{ + typedef void (*DeleteFunction)(X* pointer); + +private: + X* managedPointer; + int* refCounter; + DeleteFunction deleteFunction; + +public: + explicit RefPtr(X* ptr = 0) : + deleteFunction(DeleteManagedPointer) + { + ManagePointer(ptr); + } + + RefPtr(const RefPtr& refPtr) : + deleteFunction(DeleteManagedPointer) + { + AttachToForeignRefPtr(refPtr.get(), refPtr.refCounter); + } + + ~RefPtr() + { + ReleasePointer(); + } + + X* get() const + { + return managedPointer; + } + + X* operator->() const + { + return managedPointer; + } + + X& operator*() const + { + return *managedPointer; + } + + RefPtr& operator=(const RefPtr& refPtr) + { + if (this != &refPtr) + { + ReleasePointer(); + + AttachToForeignRefPtr(refPtr.get(), refPtr.refCounter); + } + + return *this; + } + + RefPtr operator=(X* ptr) + { + if (this->managedPointer != ptr) + { + ReleasePointer(); + ManagePointer(ptr); + } + + return *this; + } + + template<class Y> RefPtr(const RefPtr<Y> &refPtr) : + deleteFunction(DeleteManagedPointer) + { + AttachToForeignRefPtr(refPtr.get(), refPtr.refCounter); + } + + bool IsAssigned() const + { + return (managedPointer != NULL); + } + +private: + template<class Y> friend class RefPtr; + + void ReleasePointer() + { + if (*refCounter > 0) + { + (*refCounter)--; + } + else + { + deleteFunction(managedPointer); + delete refCounter; + } + } + + void AttachToForeignRefPtr(X* foreignPtr, int* foreignRefCounter) + { + refCounter = foreignRefCounter; + (*refCounter)++; + managedPointer = foreignPtr; + } + + void ManagePointer(X* ptr) + { + this->managedPointer = ptr; + refCounter = new int(0); + } + + static void DeleteManagedPointer(X* pointer) + { + delete pointer; + } +}; + +#endif diff --git a/src/RefPtr_test.cc b/src/RefPtr_test.cc new file mode 100644 index 0000000..9966c38 --- /dev/null +++ b/src/RefPtr_test.cc @@ -0,0 +1,227 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: RefPtr_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include "RefPtr.h" +#include "StringMessageMock.h" + +using namespace std; + +class Foo : public StringMessageMock +{ +public: + Foo() + { + } + + Foo(StringMessageMock& parent, string messagePrefix = "") : + StringMessageMock(parent, messagePrefix) + { + } + + ~Foo() + { + AddMethod("dtor"); + } + + int Bar(int arg) + { + return arg; + } +}; + +class RefPtrTest : public CxxTest::TestSuite +{ +public: + void TestEmptyPtr() + { + RefPtr<Foo> ptr; + } + + void TestSingleReference() + { + StringMessageMock mock; + Foo* foo = new Foo(mock); + + mock.ExpectMethod("dtor"); + + RefPtr<Foo>* ref = new RefPtr<Foo>(foo); + delete ref; + + mock.Verify(); + } + + void TestGet() + { + Foo* foo = new Foo(); + RefPtr<Foo> ref(foo); + TS_ASSERT_EQUALS(foo, ref.get()); + } + + void TestPointerOperator() + { + Foo* foo = new Foo(); + RefPtr<Foo> ref(foo); + TS_ASSERT_EQUALS(10, ref->Bar(10)); + } + + void TestAstersikOperator() + { + Foo* foo = new Foo(); + RefPtr<Foo> ref(foo); + TS_ASSERT_EQUALS(10, (*ref).Bar(10)); + } + + void TestMultipleReferences() + { + StringMessageMock mock; + Foo* foo = new Foo(mock); + + RefPtr<Foo>* ref1 = new RefPtr<Foo>(foo); + RefPtr<Foo>* ref2 = new RefPtr<Foo>(*ref1); + RefPtr<Foo>* ref3 = new RefPtr<Foo>(*ref2); + + delete ref1; + mock.Verify(); + + delete ref3; + mock.Verify(); + + mock.ExpectMethod("dtor"); + delete ref2; + mock.Verify(); + } + + void TestAssignmentOperator() + { + StringMessageMock mock; + Foo* foo1 = new Foo(mock, "foo1"); + Foo* foo2 = new Foo(mock, "foo2"); + + RefPtr<Foo>* ref1 = new RefPtr<Foo>(foo1); + RefPtr<Foo>* ref2 = new RefPtr<Foo>(foo2); + + mock.ExpectMethod("foo2:dtor"); + + *ref2 = *ref1; + + mock.Verify(); + TS_ASSERT_EQUALS(foo1, ref2->get()); + + mock.ResetMock(); + mock.ExpectMethod("foo1:dtor"); + + delete ref1; + delete ref2; + + mock.Verify(); + } + + void TestConstAssignment() + { + StringMessageMock mock; + Foo* foo1 = new Foo(mock, "foo1"); + Foo* foo2 = new Foo(mock, "foo2"); + + const RefPtr<Foo>* ref1 = new RefPtr<Foo>(foo1); + RefPtr<Foo>* ref2 = new RefPtr<Foo>(foo2); + + mock.ExpectMethod("foo2:dtor"); + + *ref2 = *ref1; + + mock.Verify(); + TS_ASSERT_EQUALS(foo1, ref2->get()); + + mock.ResetMock(); + mock.ExpectMethod("foo1:dtor"); + + delete ref1; + delete ref2; + + mock.Verify(); + } + + void TestSelfAssignment() + { + StringMessageMock mock; + + RefPtr<Foo> ref1(new Foo(mock)); + + ref1 = ref1; + + mock.Verify(); + } + + void TestPointerAssignment() + { + StringMessageMock mock; + + Foo* foo1 = new Foo(mock, "foo1"); + RefPtr<Foo> ref(foo1); + + mock.ExpectMethod("foo1:dtor"); + + Foo* foo2 = new Foo(mock, "foo2"); + ref = foo2; + + mock.Verify(); + TS_ASSERT_EQUALS(foo2, ref.get()); + } + + void TestPointerselfAssignment() + { + StringMessageMock mock; + Foo* foo = new Foo(mock); + + RefPtr<Foo> ref(foo); + + ref = foo; + + mock.Verify(); + } + + void TestIncompletType() + { + // To some extend, imcomplete types can be handled as Alan Griffiths + // dscribes in: http://www.octopull.demon.co.uk/arglib/TheGrin.html + // + // Unfortunately, I have absolutely no idea, how to write a test + // case for this. So just watch the compiler warnings about + // not beeing able to delete an incomplete type! + } + + void TestConversionToConst() + { + RefPtr<int> nonConstContent(new int(99)); + RefPtr<const int> constContent(nonConstContent); + TS_ASSERT_EQUALS(*nonConstContent, *constContent); + } + + void TestIsAssigned() + { + RefPtr<int> ptr; + TS_ASSERT(!ptr.IsAssigned()); + ptr = new int(3); + TS_ASSERT(ptr.IsAssigned()); + } +}; diff --git a/src/Rfc822DateTime.cc b/src/Rfc822DateTime.cc new file mode 100644 index 0000000..8b7e2a0 --- /dev/null +++ b/src/Rfc822DateTime.cc @@ -0,0 +1,121 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: Rfc822DateTime.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "Rfc822DateTime.h" +#include <stdlib.h> + +using namespace std; + +Rfc822DateTime::Rfc822DateTime(string rfc822DateTimeString) +{ + this->rfc822DateTimeString = rfc822DateTimeString; + ParseRfc822DateTimeString(rfc822DateTimeString); +} + +const string Rfc822DateTime::ToShortString() const +{ + if ((year.size() != 4) || (month.size() != 2) || (day.size() != 2)) + { + return "??.??.??"; + } + else + { + return day + '.' + month + '.' + year.substr(2, 2); + } +} + +const string Rfc822DateTime::ToLongString() const +{ + return rfc822DateTimeString; +} + +void Rfc822DateTime::ParseRfc822DateTimeString(string rfc822DateTimeString) +{ + string zone = ExtractLastWord(rfc822DateTimeString); + string time = ExtractLastWord(rfc822DateTimeString); + + year = ExtractLastWord(rfc822DateTimeString); + month = ExtractLastWord(rfc822DateTimeString); + day = ExtractLastWord(rfc822DateTimeString); + + month = MonthNameToNumber(month); + + if (year.length() == 2) + { + year = "20" + year; + } + + if (day.length() == 1) + { + day = "0" + day; + } +} + +string Rfc822DateTime::ExtractLastWord(string& line) +{ + string lastWord; + + if (line != "") + { + unsigned int delimiterPos = line.rfind(" "); + unsigned int wordPos; + + if (delimiterPos == string::npos) + { + delimiterPos = 0; + wordPos = 0; + } + else + { + wordPos = delimiterPos + 1; + } + + lastWord = line.substr(wordPos); + line = line.substr(0, delimiterPos); + line.erase(line.find_last_not_of(" ") + 1); + } + + return lastWord; +} + +string Rfc822DateTime::MonthNameToNumber(string monthName) +{ + static const string months("JanFebMarAprMayJunJulAugSepOctNovDec"); + + monthName = monthName.substr(0, 3); + + unsigned int monthIndex = months.find(monthName); + + if (monthIndex == string::npos) + { + return ""; + } + else + { + char* formattedMonth; + asprintf(&formattedMonth, "%.2d", 1 + monthIndex / 3); + string monthNumber = formattedMonth; + free(formattedMonth); + + return monthNumber; + } +} diff --git a/src/Rfc822DateTime.h b/src/Rfc822DateTime.h new file mode 100644 index 0000000..d774830 --- /dev/null +++ b/src/Rfc822DateTime.h @@ -0,0 +1,47 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: Rfc822DateTime.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___RFC822DATETIME_H +#define ___RFC822DATETIME_H + +#include <string> + +class Rfc822DateTime +{ +private: + std::string rfc822DateTimeString; + std::string year; + std::string month; + std::string day; + +private: + void ParseRfc822DateTimeString(std::string rfc822DateTimeString); + static std::string ExtractLastWord(std::string& line); + static std::string MonthNameToNumber(std::string monthName); + +public: + Rfc822DateTime(std::string rfc822DateTimeString); + const std::string ToShortString() const; + const std::string ToLongString() const; +}; + +#endif diff --git a/src/Rfc822DateTime_test.cc b/src/Rfc822DateTime_test.cc new file mode 100644 index 0000000..7af517e --- /dev/null +++ b/src/Rfc822DateTime_test.cc @@ -0,0 +1,149 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: Rfc822DateTime_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include "Rfc822DateTime.h" + +namespace +{ + +class Rfc822DateTimeTest : public CxxTest::TestSuite +{ +public: + void TestInvalidRfc822DateTime() + { + Rfc822DateTime dateTime("invalid"); + TS_ASSERT_EQUALS("??.??.??", dateTime.ToShortString()); + TS_ASSERT_EQUALS("invalid", dateTime.ToLongString()); + } + + void TestFullDate() + { + Rfc822DateTime dateTime("Tue, 10 Jun 2003 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.06.03", dateTime.ToShortString()); + TS_ASSERT_EQUALS("Tue, 10 Jun 2003 04:00:00 GMT", dateTime.ToLongString()); + } + + void TestNoWeekday() + { + Rfc822DateTime dateTime("10 Jun 2003 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.06.03", dateTime.ToShortString()); + } + + void TestSingleDigitDay() + { + Rfc822DateTime dateTime("1 Jun 2003 04:00:00 GMT"); + TS_ASSERT_EQUALS("01.06.03", dateTime.ToShortString()); + } + + void TestTwoDigitYear() + { + Rfc822DateTime dateTime("1 Jun 03 04:00:00 GMT"); + TS_ASSERT_EQUALS("01.06.03", dateTime.ToShortString()); + } + + void TestAllMonths() + { + Rfc822DateTime dateTime1("10 Jan 03 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.01.03", dateTime1.ToShortString()); + + Rfc822DateTime dateTime2("10 Feb 03 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.02.03", dateTime2.ToShortString()); + + Rfc822DateTime dateTime3("10 Mar 03 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.03.03", dateTime3.ToShortString()); + + Rfc822DateTime dateTime4("10 Apr 03 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.04.03", dateTime4.ToShortString()); + + Rfc822DateTime dateTime5("10 May 03 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.05.03", dateTime5.ToShortString()); + + Rfc822DateTime dateTime6("10 Jun 03 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.06.03", dateTime6.ToShortString()); + + Rfc822DateTime dateTime7("10 Jul 03 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.07.03", dateTime7.ToShortString()); + + Rfc822DateTime dateTime8("10 Aug 03 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.08.03", dateTime8.ToShortString()); + + Rfc822DateTime dateTime9("10 Sep 03 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.09.03", dateTime9.ToShortString()); + + Rfc822DateTime dateTime10("10 Oct 03 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.10.03", dateTime10.ToShortString()); + + Rfc822DateTime dateTime11("10 Nov 03 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.11.03", dateTime11.ToShortString()); + + Rfc822DateTime dateTime12("10 Dec 03 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.12.03", dateTime12.ToShortString()); + } + + void TestExtraSpacesInDate() + { + Rfc822DateTime dateTime("Wed, 21 Dec 2005 11:28 CET"); + TS_ASSERT_EQUALS("21.12.05", dateTime.ToShortString()); + } + + void TestLongMonthNames() + { + Rfc822DateTime dateTime1("Tue, 10 January 2003 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.01.03", dateTime1.ToShortString()); + + Rfc822DateTime dateTime2("Tue, 10 February 2003 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.02.03", dateTime2.ToShortString()); + + Rfc822DateTime dateTime3("Tue, 10 March 2003 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.03.03", dateTime3.ToShortString()); + + Rfc822DateTime dateTime4("Tue, 10 April 2003 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.04.03", dateTime4.ToShortString()); + + Rfc822DateTime dateTime5("Tue, 10 May 2003 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.05.03", dateTime5.ToShortString()); + + Rfc822DateTime dateTime6("Tue, 10 June 2003 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.06.03", dateTime6.ToShortString()); + + Rfc822DateTime dateTime7("Tue, 10 July 2003 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.07.03", dateTime7.ToShortString()); + + Rfc822DateTime dateTime8("Tue, 10 August 2003 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.08.03", dateTime8.ToShortString()); + + Rfc822DateTime dateTime9("Tue, 10 September 2003 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.09.03", dateTime9.ToShortString()); + + Rfc822DateTime dateTime10("Tue, 10 October 2003 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.10.03", dateTime10.ToShortString()); + + Rfc822DateTime dateTime11("Tue, 10 November 2003 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.11.03", dateTime11.ToShortString()); + + Rfc822DateTime dateTime12("Tue, 10 December 2003 04:00:00 GMT"); + TS_ASSERT_EQUALS("10.12.03", dateTime12.ToShortString()); + } +}; + +}; diff --git a/src/RssFeedParser.cc b/src/RssFeedParser.cc new file mode 100644 index 0000000..db5558e --- /dev/null +++ b/src/RssFeedParser.cc @@ -0,0 +1,180 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: RssFeedParser.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "RssFeedParser.h" +#include "HtmlToText.h" +#include "Feed.h" +#include "IDownloadCache.h" +#include "tinyxml.h" +#include "Item.h" + +using namespace std; + +RssFeedParser::RssFeedParser(const IDownloadCache& downloadCache) : + _downloadCache(downloadCache) +{ +} + +bool RssFeedParser::Parse(Feed& feed) const +{ + RefPtr<istream> source(_downloadCache.CreateStreamByUrl(feed.GetUrl())); + + if (source.IsAssigned()) + { + RefPtr<TiXmlDocument> rssDoc = CreateRssDocument(*source); + + TiXmlHandle docHandle(rssDoc.get()); + const TiXmlNode* channelNode = docHandle.FirstChild("rss").FirstChild("channel").Node(); + if (channelNode) + { + feed.SetTitle(GetChildValue(*channelNode, "title")); + + feed.SetTimeToLive(StringToIntDefault(GetChildValue(*channelNode, "ttl"), feed.GetTimeToLive())); + + for (const TiXmlNode* itemNode = channelNode->FirstChild("item"); itemNode; itemNode + = itemNode->NextSibling("item")) + { + Item item = ParseItem(*itemNode); + feed.AddItem(item); + } + + return true; + } + } + return false; +} + +RefPtr<TiXmlDocument> RssFeedParser::CreateRssDocument(istream& rssStream) const +{ + RefPtr<TiXmlDocument> rssDoc(new TiXmlDocument()); + rssStream >> *rssDoc; + if (!rssDoc->Error()) + { + return rssDoc; + } + + return RefPtr<TiXmlDocument>(); +} + +string RssFeedParser::GetValue(const TiXmlNode& node) const +{ + const TiXmlNode* textNode = node.FirstChild(); + if (textNode) + { + return textNode->Value(); + } + return ""; +} + +const string RssFeedParser::GetAttribute(const TiXmlElement& element, string name) const +{ + const string* value = element.Attribute(name); + if (value != NULL) + { + return *value; + } + else + { + return ""; + } +} + +string RssFeedParser::GetChildValue(const TiXmlNode& root, const string& childName) const +{ + const TiXmlNode* childNode = root.FirstChild(childName); + if (childNode) + { + return GetValue(*childNode); + } + + return ""; +} + +Item RssFeedParser::ParseItem(const TiXmlNode& itemNode) const +{ + string title = GetChildValue(itemNode, "title"); + string description = GetChildValue(itemNode, "description"); + string date = GetChildValue(itemNode, "pubDate"); + + Item item(title, Rfc822DateTime(date), HtmlToText::Convert(description)); + + const TiXmlElement* subFeedElement = itemNode.FirstChildElement("videocast:subfeed"); + if (subFeedElement) + { + item.SetSubFeedUrl(GetAttribute(*subFeedElement, "url")); + } + + const TiXmlElement* enclosureElement = itemNode.FirstChildElement("enclosure"); + if (enclosureElement) + { + string type = GetAttribute(*enclosureElement, "type"); + if (type.find("video/") == 0) + { + item.SetVideoCastStream(Low, GetAttribute(*enclosureElement, "url")); + } + } + + const TiXmlElement* streamElement = itemNode.FirstChildElement("videocast:stream"); + while (streamElement) + { + ParseStreamElement(*streamElement, item); + streamElement = streamElement->NextSiblingElement("videocast:stream"); + } + + const TiXmlElement* streamInfoElement = itemNode.FirstChildElement("videocast:streaminfo"); + if (streamInfoElement) + { + item.SetStreamLength(GetAttribute(*streamInfoElement, "length")); + } + + return item; +} + +void RssFeedParser::ParseStreamElement(const TiXmlElement& streamElement, Item& item) const +{ + string quality = GetAttribute(streamElement, "quality"); + string url = GetAttribute(streamElement, "url"); + + if (quality == "high") + { + item.SetVideoCastStream(High, url); + } + else if (quality == "medium") + { + item.SetVideoCastStream(Medium, url); + } + else if (quality == "low") + { + item.SetVideoCastStream(Low, url); + } +} + +int RssFeedParser::StringToIntDefault(const string& str, const int defaultValue) const +{ + istringstream tempStream(str); + int value; + if (!(tempStream >> value)) + { + value = defaultValue; + } + return value; +} diff --git a/src/RssFeedParser.h b/src/RssFeedParser.h new file mode 100644 index 0000000..c5dc38e --- /dev/null +++ b/src/RssFeedParser.h @@ -0,0 +1,58 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: RssFeedParser.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___RSSFEEDPARSER_H +#define ___RSSFEEDPARSER_H + +#include <string> +#include "IFeedParser.h" +#include "Item.h" +#include "RefPtr.h" + +class IDownloadCache; +class TiXmlDocument; +class TiXmlNode; +class TiXmlElement; + +class RssFeedParser : public IFeedParser +{ +private: + const IDownloadCache& _downloadCache; + +private: + RefPtr<TiXmlDocument> CreateRssDocument() const; + RefPtr<TiXmlDocument> CreateRssDocument(std::istream& rssStream) const; + std::string GetChildValue(const TiXmlNode& root, const std::string& childName) const; + std::string GetValue(const TiXmlNode& node) const; + const std::string GetAttribute(const TiXmlElement& element, const std::string name) const; + Item ParseItem(const TiXmlNode& itemNode) const; + void ParseStreamElement(const TiXmlElement& streamElement, Item& item) const; + int StringToIntDefault(const std::string& str, const int defaultValue) const; + +public: + RssFeedParser(const IDownloadCache& downloadCache); + // <IFeedParser> + bool Parse(Feed& feed) const; + // </IFeedParser> +}; + +#endif //___RSSFEEDPARSER_H diff --git a/src/RssFeedParser_test.cc b/src/RssFeedParser_test.cc new file mode 100644 index 0000000..ec491f9 --- /dev/null +++ b/src/RssFeedParser_test.cc @@ -0,0 +1,338 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: RssFeedParser_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <sstream> +#include <cxxtest/TestSuite.h> +#include "RssFeedParser.h" +#include "Feed.h" +#include "DownloadCacheMock.h" + +using namespace std; + +namespace +{ + +class FeedBuilder +{ +public: + + static string CreateRssFeed(string title, string items) + { + string result; + + result = "<?xml version='1.0'?>"; + result += "<rss version='2.0'><channel>"; + result += CreateXmlTag("title", title); + result += items; + result += "</channel></rss>"; + + return result; + } + + static string CreateRssItem(string title, string pubDate, string description, string link="", string videoCasts="") + { + string result; + + result = "<item>"; + result += CreateXmlTag("title", title); + result += CreateXmlTag("pubDate", pubDate); + result += CreateXmlTag("description", description); + result += link; + result += videoCasts; + result += "</item>"; + + return result; + } + + static string CreateSubFeed(string url) + { + return CreateXmlTag("videocast:subfeed", "", CreateAttribute("url", url)); + } + + static string CreateVideoCast(string url, string quality) + { + return CreateXmlTag("videocast:stream", "", CreateAttribute("quality", quality) + CreateAttribute("url", url)); + } + + static string CreateEnclosure(string url, string type) + { + return CreateXmlTag("enclosure", "", CreateAttribute("url", url) + CreateAttribute("type", type)); + } + + static string CreateTimeToLive(string timeToLive) + { + return CreateXmlTag("ttl", timeToLive); + } + + static string CreateVideoCastStreamInfo(string streamLength) + { + return CreateXmlTag("videocast:streaminfo", "", CreateAttribute("length", streamLength)); + } + +private: + static string CreateXmlTag(string name, string value, string attributes="") + { + return "<" + name + " " + attributes + ">" + value + "</" + name + ">"; + } + + static string CreateAttribute(string name, string value) + { + if (value != "") + { + return name + "='" + value + "' "; + } + else + { + return ""; + } + } +}; + +class A_RssFeedParser : public CxxTest::TestSuite +{ +private: + RefPtr<Feed> _feed; + RefPtr<RssFeedParser> _parser; + RefPtr<DownloadCacheMock> _downloadCache; + +public: + void setUp() + { + _feed = new Feed(""); + _downloadCache = new DownloadCacheMock(); + _parser = new RssFeedParser(*_downloadCache); + } + + void Should_fail_to_parse_a_feed_that_does_not_exist_in_the_download_cache() + { + _downloadCache->streamReturnedByCache = NULL; + + TS_ASSERT(!_parser->Parse(*_feed)); + } + + void Should_fail_to_parse_an_invalid_feed() + { + _downloadCache->streamReturnedByCache = new stringstream("<invalidXml>"); + TS_ASSERT(!_parser->Parse(*_feed)); + } + + void Should_parse_the_feed_title() + { + _downloadCache->streamReturnedByCache = new stringstream(FeedBuilder::CreateRssFeed("FooTitle", "")); + TS_ASSERT(_parser->Parse(*_feed)); + TS_ASSERT_EQUALS(0, (int)_feed->GetItems().size()); + TS_ASSERT_EQUALS("FooTitle", _feed->GetTitle()); + } + + void Should_parse_a_single_item() + { + string item = FeedBuilder::CreateRssItem("ItemTitle", "3 Jun 2005 04:00:00 GMT", "ItemDescription", "", ""); + _downloadCache->streamReturnedByCache = new stringstream(FeedBuilder::CreateRssFeed("FooTitle", item)); + + TS_ASSERT(_parser->Parse(*_feed)); + TS_ASSERT_EQUALS(1, (int)_feed->GetItems().size()); + + TS_ASSERT_EQUALS("ItemTitle", _feed->GetItems()[0].GetTitle()); + TS_ASSERT_EQUALS("ItemDescription", _feed->GetItems()[0].GetDescription()); + TS_ASSERT_EQUALS("03.06.05", _feed->GetItems()[0].GetDate().ToShortString()); + } + + void Should_parse_two_items() + { + string item1 = FeedBuilder::CreateRssItem("ItemTitle1", "", "", "", ""); + string item2 = FeedBuilder::CreateRssItem("ItemTitle2", "", "", "", ""); + + _downloadCache->streamReturnedByCache = new stringstream(FeedBuilder::CreateRssFeed("FooTitle", item1 + item2)); + + TS_ASSERT(_parser->Parse(*_feed)); + TS_ASSERT_EQUALS(2, (int)_feed->GetItems().size()); + + TS_ASSERT_EQUALS("ItemTitle1", _feed->GetItems()[0].GetTitle()); + TS_ASSERT_EQUALS("ItemTitle2", _feed->GetItems()[1].GetTitle()); + } + + void Should_ignore_tags_after_the_last_item() + { + string item = FeedBuilder::CreateRssItem("ItemTitle1", "", "", "", ""); + + _downloadCache->streamReturnedByCache = new stringstream(FeedBuilder::CreateRssFeed("FooTitle", item + "<tag/>")); + + TS_ASSERT(_parser->Parse(*_feed)); + TS_ASSERT_EQUALS(1, (int)_feed->GetItems().size()); + } + + void Should_parse_an_item_with_a_sub_feed() + { + string feedXml = FeedBuilder::CreateRssFeed("", FeedBuilder::CreateRssItem("", "", "", + FeedBuilder::CreateSubFeed("linkUrl"))); + + _downloadCache->streamReturnedByCache = new stringstream(feedXml); + + TS_ASSERT(_parser->Parse(*_feed)); + TS_ASSERT_EQUALS(1, (int)_feed->GetItems().size()); + + TS_ASSERT_EQUALS("linkUrl", _feed->GetItems()[0].GetSubFeedUrl()); + } + + void Should_parse_the_different_streams_of_different_quality() + { + string feedXml = FeedBuilder::CreateRssFeed("", FeedBuilder::CreateRssItem("", "", "", "", + FeedBuilder::CreateVideoCast("urlHigh", "high") + FeedBuilder::CreateVideoCast("urlMedium", "medium") + + FeedBuilder::CreateVideoCast("urlLow", "low"))); + + _downloadCache->streamReturnedByCache = new stringstream(feedXml); + + TS_ASSERT(_parser->Parse(*_feed)); + TS_ASSERT_EQUALS(1, (int)_feed->GetItems().size()); + + TS_ASSERT_EQUALS("urlHigh", _feed->GetItems()[0].GetVideoCastStream(High)); + TS_ASSERT_EQUALS("urlMedium", _feed->GetItems()[0].GetVideoCastStream(Medium)); + TS_ASSERT_EQUALS("urlLow", _feed->GetItems()[0].GetVideoCastStream(Low)); + } + + void Should_strip_all_html_from_the_description() + { + string feedXml = FeedBuilder::CreateRssFeed("", FeedBuilder::CreateRssItem("", "", "<![CDATA[<br>test<br>]]>")); + + _downloadCache->streamReturnedByCache = new stringstream(feedXml); + + TS_ASSERT(_parser->Parse(*_feed)); + TS_ASSERT_EQUALS(1, (int)_feed->GetItems().size()); + + TS_ASSERT_EQUALS("test", _feed->GetItems()[0].GetDescription()); + } + + void Should_ignore_a_videocast_stream_without_an_url() + { + string feedXml = FeedBuilder::CreateRssFeed("", FeedBuilder::CreateRssItem("", "", "", "", + FeedBuilder::CreateVideoCast("", "high"))); + + _downloadCache->streamReturnedByCache = new stringstream(feedXml); + + TS_ASSERT(_parser->Parse(*_feed)); + TS_ASSERT_EQUALS(1, (int)_feed->GetItems().size()); + + TS_ASSERT_EQUALS("", _feed->GetItems()[0].GetVideoCastStream(High)); + } + + void Should_ignore_a_videocast_stream_without_a_quality() + { + string feedXml = FeedBuilder::CreateRssFeed("", FeedBuilder::CreateRssItem("", "", "", "", + FeedBuilder::CreateVideoCast("url", ""))); + + _downloadCache->streamReturnedByCache = new stringstream(feedXml); + + TS_ASSERT(_parser->Parse(*_feed)); + TS_ASSERT_EQUALS(1, (int)_feed->GetItems().size()); + + TS_ASSERT_EQUALS("", _feed->GetItems()[0].GetVideoCastStream(High)); + TS_ASSERT_EQUALS("", _feed->GetItems()[0].GetVideoCastStream(Low)); + TS_ASSERT_EQUALS("", _feed->GetItems()[0].GetVideoCastStream(Medium)); + } + + void Should_parse_the_streaminfo() + { + string feedXml = FeedBuilder::CreateRssFeed("", FeedBuilder::CreateRssItem("", "", "", "", + FeedBuilder::CreateVideoCast("urlHigh", "high") + FeedBuilder::CreateVideoCastStreamInfo("12 min"))); + + _downloadCache->streamReturnedByCache = new stringstream(feedXml); + + TS_ASSERT(_parser->Parse(*_feed)); + TS_ASSERT_EQUALS(1, (int)_feed->GetItems().size()); + + TS_ASSERT_EQUALS("12 min", _feed->GetItems()[0].GetStreamLength()); + } + + void Should_parse_the_feeds_time_to_live() + { + string feedXml = FeedBuilder::CreateRssFeed("", FeedBuilder::CreateTimeToLive("333")); + + _downloadCache->streamReturnedByCache = new stringstream(feedXml); + + TS_ASSERT(_parser->Parse(*_feed)); + TS_ASSERT_EQUALS(333, _feed->GetTimeToLive()); + } + + void Should_ignore_an_invalid_time_to_live() + { + string feedXml = FeedBuilder::CreateRssFeed("", FeedBuilder::CreateTimeToLive("invalid")); + + _downloadCache->streamReturnedByCache = new stringstream(feedXml); + + TS_ASSERT(_parser->Parse(*_feed)); + TS_ASSERT_EQUALS(720, _feed->GetTimeToLive()); + } + + void Should_add_a_video_encloser_as_low_type_stream() + { + string feedXml = FeedBuilder::CreateRssFeed("", FeedBuilder::CreateRssItem("", "", "", "", + FeedBuilder::CreateEnclosure("enclosureUrl", "video/dont-care"))); + + _downloadCache->streamReturnedByCache = new stringstream(feedXml); + + TS_ASSERT(_parser->Parse(*_feed)); + TS_ASSERT_EQUALS(1, (int)_feed->GetItems().size()); + + TS_ASSERT_EQUALS("enclosureUrl", _feed->GetItems()[0].GetVideoCastStream(Low)); + } + + void Should_ignore_non_video_enclosures() + { + string feedXml = FeedBuilder::CreateRssFeed("", FeedBuilder::CreateRssItem("", "", "", "", + FeedBuilder::CreateEnclosure("enclosureUrl", "audio/mp3"))); + + _downloadCache->streamReturnedByCache = new stringstream(feedXml); + + TS_ASSERT(_parser->Parse(*_feed)); + TS_ASSERT_EQUALS(1, (int)_feed->GetItems().size()); + + TS_ASSERT_EQUALS("", _feed->GetItems()[0].GetVideoCastStream(Low)); + } + + void Should_prefer_a_low_quality_videocast_stream_over_a_video_enclosure() + { + string feedXml = FeedBuilder::CreateRssFeed("", FeedBuilder::CreateRssItem("", "", "", "", + FeedBuilder::CreateVideoCast("streamUrl", "low") + FeedBuilder::CreateEnclosure("enclosureUrl", + "video/dont-care"))); + + _downloadCache->streamReturnedByCache = new stringstream(feedXml); + + TS_ASSERT(_parser->Parse(*_feed)); + TS_ASSERT_EQUALS(1, (int)_feed->GetItems().size()); + + TS_ASSERT_EQUALS("streamUrl", _feed->GetItems()[0].GetVideoCastStream(Low)); + } + + void Should_convert_text_to_current_locale() + { + string feedXml = "<?xml version='1.0' encoding='UTF-8'?><rss><channel><title>äää</title></channel></rss>"; + + _downloadCache->streamReturnedByCache = new stringstream(feedXml); + + TS_ASSERT(_parser->Parse(*_feed)); + + // TODO + // TS_ASSERT_EQUALS("äää", _feed->GetTitle()); + } +}; + +}; diff --git a/src/SdbmHashCalculator.cc b/src/SdbmHashCalculator.cc new file mode 100644 index 0000000..2785f6a --- /dev/null +++ b/src/SdbmHashCalculator.cc @@ -0,0 +1,43 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: SdbmHashCalculator.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "SdbmHashCalculator.h" +#include <sstream> +#include <iostream> + +using namespace std; + +string SdbmHashCalculator::Calculate(string str) +{ + unsigned long hash = 0; + + for (unsigned int i=0; i < str.length(); i++) + { + int character = str[i]; + hash = character + (hash << 6) + (hash << 16) - hash; + } + + ostringstream hashString; + hashString << hash; + + return hashString.str(); +} diff --git a/src/SdbmHashCalculator.h b/src/SdbmHashCalculator.h new file mode 100644 index 0000000..7f61498 --- /dev/null +++ b/src/SdbmHashCalculator.h @@ -0,0 +1,34 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: SdbmHashCalculator.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___SDBMHASHCALCULATOR_H +#define ___SDBMHASHCALCULATOR_H + +#include <string> + +class SdbmHashCalculator +{ +public: + static std::string Calculate(std::string str); +}; + +#endif diff --git a/src/SdbmHashCalculator_test.cc b/src/SdbmHashCalculator_test.cc new file mode 100644 index 0000000..dc28816 --- /dev/null +++ b/src/SdbmHashCalculator_test.cc @@ -0,0 +1,43 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: SdbmHashCalculator_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include "SdbmHashCalculator.h" + +namespace +{ + +class SdbmHashCalculatorTest : public CxxTest::TestSuite +{ +public: + void TestHashing() + { + TS_ASSERT_EQUALS("0", SdbmHashCalculator::Calculate("")); + TS_ASSERT_EQUALS("0", SdbmHashCalculator::Calculate("\0x00")); + TS_ASSERT_EQUALS("32", SdbmHashCalculator::Calculate(" ")); + TS_ASSERT_EQUALS("65", SdbmHashCalculator::Calculate("A")); + TS_ASSERT_EQUALS("4264001", SdbmHashCalculator::Calculate("AB")); + } +}; + +} +; diff --git a/src/ServiceLocatorImpl.cc b/src/ServiceLocatorImpl.cc new file mode 100644 index 0000000..820c075 --- /dev/null +++ b/src/ServiceLocatorImpl.cc @@ -0,0 +1,199 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ServiceLocatorImpl.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "ServiceLocatorImpl.h" +#include "FeedsConfigFile.h" +#include "IConfiguration.h" +#include "RssFeedParser.h" +#include "VdrThread.h" +#include "VdrSleeper.h" +#include "VdrCriticalSection.h" +#include "DownloadQueue.h" +#include "ThreadsafeDownloadPool.h" +#include "SynchedDownloadPool.h" +#include "LocalFileCache.h" +#include "CurlDownloader.h" +#include "FeedUpdaterImpl.h" +#include "DownloadAction.h" +#include "OsdListMenu.h" +#include "FeedMenuController.h" +#include "ItemMenuPresenter.h" +#include "OsdItemView.h" +#include "ItemViewPresenter.h" +#include "SyslogErrorLogger.h" +#include "OsdSetupMenu.h" +#include "MplayerPlugin.h" +#include "XineliboutputPlayer.h" +#include "FeedRepository.h" +#include "IMenuFactory.h" +#include "VdrInterface.h" + +using namespace std; + +ServiceLocatorImpl::ServiceLocatorImpl(IConfiguration& configuration) : + configuration(configuration) +{ +} + +IFeedSources* ServiceLocatorImpl::GetFeedSources() +{ + if (!feedSources.get()) + { + feedSources = RefPtr<IFeedSources>(new FeedsConfigFile(configuration.GetSourcesFileName())); + } + + return feedSources.get(); +} + +IFeedParser* ServiceLocatorImpl::GetFeedParser() +{ + if (!feedParser.get()) + { + feedParser = RefPtr<IFeedParser>(new RssFeedParser(*GetDownloadCache())); + } + + return feedParser.get(); +} + +IDownloadPool* ServiceLocatorImpl::GetDownloadPool() +{ + if (!downloadPool.get()) + { + RefPtr<ISleeper> downloadSleeper(new VdrSleeper()); + RefPtr<ICriticalSection> criticalSection(new VdrCriticalSection()); + + // Download pool decorated with thread safety and thread synchronization + RefPtr<IDownloadPool> pool(new DownloadQueue()); + RefPtr<IDownloadPool> threadSafePool(new ThreadSafeDownloadPool(pool, + criticalSection)); + RefPtr<IDownloadPool> synchedPool(new SynchedDownloadPool( + threadSafePool, downloadSleeper)); + + downloadPool = RefPtr<IDownloadPool>(synchedPool); + } + + return downloadPool.get(); +} + +IDownloadCache* ServiceLocatorImpl::GetDownloadCache() +{ + if (!downloadCache.get()) + { + downloadCache = RefPtr<IDownloadCache>(new LocalFileCache(configuration.GetCacheDirName())); + } + + return downloadCache.get(); +} + +IDownloader* ServiceLocatorImpl::GetDownloader() +{ + if (!downloader.get()) + { + downloader = RefPtr<IDownloader>(new CurlDownloader(*GetDownloadCache())); + } + + return downloader.get(); +} + +IThread* ServiceLocatorImpl::GetDownloadThread() +{ + if (!downloadThread.get()) + { + downloadThread = RefPtr<IThread>(new VdrThread(CreateDownloadAction())); + } + + return downloadThread.get(); +} + +IFeedUpdater* ServiceLocatorImpl::GetFeedUpdater() +{ + if (!feedUpdater.get()) + { + feedUpdater = RefPtr<IFeedUpdater>(new FeedUpdaterImpl(*GetFeedSources(), *GetDownloadPool(), + *GetDownloadCache())); + } + + return feedUpdater.get(); +} + +RefPtr<IThreadAction> ServiceLocatorImpl::CreateDownloadAction() +{ + return RefPtr<IThreadAction>(new DownloadAction(*GetDownloadPool(), + *GetDownloader())); +} + +IMenuFactory* ServiceLocatorImpl::GetMenuFactory() +{ + return this; +} + +cOsdMenu* ServiceLocatorImpl::CreateFeedMenu() +{ + return new OsdListMenu( + RefPtr<IListMenuPresenter>(new FeedMenuController(*GetMenuFactory(), *CreateFeedRepository()))); +} + +RefPtr<IFeedRepository> ServiceLocatorImpl::CreateFeedRepository() +{ + RefPtr<IFeedRepository> feedRepository(new FeedRepository(*GetDownloadCache(), *GetDownloadPool(), *GetDownloader(), *GetFeedParser(), *GetFeedSources())); + return feedRepository; +} + +cOsdMenu* ServiceLocatorImpl::CreateItemMenu(const Feed& feed) +{ + RefPtr<IMediaPlayer> mplayerPlugin; + + switch(configuration.GetMediaPlayerType()) + { + case Mplayer: + mplayerPlugin = new MplayerPlugin(*GetErrorLogger()); + break; + default: + mplayerPlugin = new XineliboutputPlayer(*GetErrorLogger()); + break; + } + RefPtr<IVdrInterface> vdrInterface(new VdrInterface()); + return new OsdListMenu( + RefPtr<IListMenuPresenter>(new ItemMenuPresenter(*this, feed, CreateFeedRepository(), configuration, mplayerPlugin, vdrInterface)), 9); +} + +cOsdMenu* ServiceLocatorImpl::CreateItemView(Feed feed, Item item) +{ + RefPtr<ItemViewPresenter> itemViewPresenter(new ItemViewPresenter(feed.GetTitle(), item, configuration)); + + return new OsdItemView(itemViewPresenter); +} + +IErrorLogger* ServiceLocatorImpl::GetErrorLogger() +{ + if (!errorLogger.get()) + { + errorLogger = RefPtr<IErrorLogger>(new SyslogErrorLogger()); + } + + return errorLogger.get(); +} + +cMenuSetupPage* ServiceLocatorImpl::CreateSetupMenu() +{ + return new OsdSetupMenu(configuration); +} diff --git a/src/ServiceLocatorImpl.h b/src/ServiceLocatorImpl.h new file mode 100644 index 0000000..160f98a --- /dev/null +++ b/src/ServiceLocatorImpl.h @@ -0,0 +1,75 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ServiceLocatorImpl.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___SERVICELOCATORIMPL_H +#define ___SERVICELOCATORIMPL_H + +#include "IServiceLocator.h" +#include "RefPtr.h" +#include "IMenuFactory.h" + +class IDownloader; +class IPesPacketBuffer; +class IConfiguration; +class IFeedRepository; + +class ServiceLocatorImpl : public IServiceLocator, IMenuFactory +{ +private: + IConfiguration& configuration; + RefPtr<IFeedSources> feedSources; + RefPtr<IFeedParser> feedParser; + RefPtr<IDownloadPool> downloadPool; + RefPtr<IDownloadCache> downloadCache; + RefPtr<IThread> downloadThread; + RefPtr<IDownloader> downloader; + RefPtr<IFeedUpdater> feedUpdater; + RefPtr<IErrorLogger> errorLogger; + RefPtr<IMenuFactory> menuFactory; + +private: + IDownloader* GetDownloader(); + RefPtr<IPesPacketBuffer> CreateSynchedPcmBuffer(); + +public: + ServiceLocatorImpl(IConfiguration& configuration); + // <IServiceLocator> + IFeedSources* GetFeedSources(); + IFeedParser* GetFeedParser(); + IDownloadPool* GetDownloadPool(); + IDownloadCache* GetDownloadCache(); + IThread* GetDownloadThread(); + IFeedUpdater* GetFeedUpdater(); + RefPtr<IThreadAction> CreateDownloadAction(); + cOsdMenu* CreateFeedMenu(); + cOsdMenu* CreateItemView(Feed feed, Item item); + IErrorLogger* GetErrorLogger(); + cMenuSetupPage* CreateSetupMenu(); + // </IServiceLocator> + IMenuFactory* GetMenuFactory(); + RefPtr<IFeedRepository> CreateFeedRepository(); + // <IMenuFactory> + cOsdMenu* CreateItemMenu(const Feed& feed); + // </IMenuFactory> +}; + +#endif // ___SERVICELOCATORIMPL_H diff --git a/src/ServiceLocatorStub.cc b/src/ServiceLocatorStub.cc new file mode 100644 index 0000000..c4daa16 --- /dev/null +++ b/src/ServiceLocatorStub.cc @@ -0,0 +1,103 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ServiceLocatorStub.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "ServiceLocatorStub.h" +#include "ThreadAction.h" + +using namespace std; + +ServiceLocatorStub::ServiceLocatorStub() +{ + feedSources = NULL; + feedParser = NULL; + downloadPool = NULL; + downloadCache = NULL; + feedMenu = NULL; + downloadThread = NULL; + setupMenu = NULL; +} + +IFeedSources* ServiceLocatorStub::GetFeedSources() +{ + return feedSources; +} + +IFeedParser* ServiceLocatorStub::GetFeedParser() +{ + return feedParser; +} + +IDownloadPool* ServiceLocatorStub::GetDownloadPool() +{ + return downloadPool; +} + +IDownloadCache* ServiceLocatorStub::GetDownloadCache() +{ + return downloadCache; +} + +IThread* ServiceLocatorStub::GetDownloadThread() +{ + return downloadThread; +} + +IFeedUpdater* ServiceLocatorStub::GetFeedUpdater() +{ + return feedUpdater; +} + +RefPtr<IThreadAction> ServiceLocatorStub::CreateDownloadAction() +{ + return RefPtr<IThreadAction>(NULL); +} + +cOsdMenu* ServiceLocatorStub::CreateFeedMenu() +{ + return feedMenu; +} + +cOsdMenu* ServiceLocatorStub::CreateItemMenu(const Feed& feed) +{ + return itemMenu; +} + +cOsdMenu* ServiceLocatorStub::CreateItemView(Feed feed, Item item) +{ + itemViewWasCreatedFor = item.GetTitle(); + return itemView; +} + +IErrorLogger* ServiceLocatorStub::GetErrorLogger() +{ + return errorLogger; +} + +cMenuSetupPage* ServiceLocatorStub::CreateSetupMenu() +{ + return setupMenu; +} + +IMenuFactory* ServiceLocatorStub::GetMenuFactory() +{ + return this; +} diff --git a/src/ServiceLocatorStub.h b/src/ServiceLocatorStub.h new file mode 100644 index 0000000..6e2713c --- /dev/null +++ b/src/ServiceLocatorStub.h @@ -0,0 +1,69 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ServiceLocatorStub.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___SERVICELOCATORSTUB_H +#define ___SERVICELOCATORSTUB_H + +#include "IServiceLocator.h" +#include "IMenuFactory.h" + +class ServiceLocatorStub : public IServiceLocator, IMenuFactory +{ +public: + IFeedSources* feedSources; + IFeedParser* feedParser; + IDownloadPool* downloadPool; + IDownloadCache* downloadCache; + IThread* downloadThread; + IFeedUpdater* feedUpdater; + cOsdMenu* feedMenu; + cOsdMenu* itemMenu; + cOsdMenu* itemView; + std::string itemAssignedToPlayerControl; + std::string itemViewWasCreatedFor; + cControl* playerControl; + IErrorLogger* errorLogger; + cMenuSetupPage* setupMenu; + +public: + ServiceLocatorStub(); + // <IServiceLocator> + IFeedSources* GetFeedSources(); + IFeedParser* GetFeedParser(); + IDownloadPool* GetDownloadPool(); + IDownloadCache* GetDownloadCache(); + IThread* GetDownloadThread(); + IFeedUpdater* GetFeedUpdater(); + RefPtr<IThreadAction> CreateDownloadAction(); + cOsdMenu* CreateFeedMenu(); + cOsdMenu* CreateItemView(Feed feed, Item item); + cControl* CreatePlayerControl(Item item); + IErrorLogger* GetErrorLogger(); + cMenuSetupPage* CreateSetupMenu(); + IMenuFactory* GetMenuFactory(); + // </IServiceLocator> + // <IMenuFactory> + cOsdMenu* CreateItemMenu(const Feed& feed); + // </IMenuFactory> +}; + +#endif diff --git a/src/Sleeper.h b/src/Sleeper.h new file mode 100644 index 0000000..b047891 --- /dev/null +++ b/src/Sleeper.h @@ -0,0 +1,36 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: Sleeper.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___SLEEPER_H +#define ___SLEEPER_H + +class ISleeper +{ +public: + virtual ~ISleeper() + { + } + virtual void Sleep() = 0; + virtual void WakeUp() = 0; +}; + +#endif diff --git a/src/SleeperMock.cc b/src/SleeperMock.cc new file mode 100644 index 0000000..e1e0ae0 --- /dev/null +++ b/src/SleeperMock.cc @@ -0,0 +1,44 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: SleeperMock.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "SleeperMock.h" + +using namespace std; + +SleeperMock::SleeperMock() +{ +} + +SleeperMock::SleeperMock(StringMessageMock& parent, string messagePrefix) : + StringMessageMock(parent, messagePrefix) +{ +} + +void SleeperMock::Sleep() +{ + AddMethod("Sleep"); +} + +void SleeperMock::WakeUp() +{ + AddMethod("WakeUp"); +} diff --git a/src/SleeperMock.h b/src/SleeperMock.h new file mode 100644 index 0000000..63aabe7 --- /dev/null +++ b/src/SleeperMock.h @@ -0,0 +1,40 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: SleeperMock.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___SLEEPERMOCK_H +#define ___SLEEPERMOCK_H + +#include "Sleeper.h" +#include "StringMessageMock.h" + +class SleeperMock : public StringMessageMock, public ISleeper +{ +public: + SleeperMock(); + SleeperMock(StringMessageMock& parent, std::string messagePrefix = ""); + // <ISleeper> + void Sleep(); + void WakeUp(); + // </ISleeper> +}; + +#endif diff --git a/src/StderrMock.cc b/src/StderrMock.cc new file mode 100644 index 0000000..a216acc --- /dev/null +++ b/src/StderrMock.cc @@ -0,0 +1,49 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: StderrMock.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include "StderrMock.h" + +using namespace std; + +StdErrMock::StdErrMock() +{ + backupCerrStreamBuffer = cerr.rdbuf(); + cerr.rdbuf(stdErrStringStream.rdbuf()); + stdErrStringStream.str(""); +} + +StdErrMock::~StdErrMock() +{ + cerr.rdbuf(backupCerrStreamBuffer); + backupCerrStreamBuffer = NULL; +} + +void StdErrMock::Expect(string expectation) +{ + expected = expectation; +} + +void StdErrMock::Verify() +{ + TS_ASSERT_EQUALS(expected, stdErrStringStream.str()); +} diff --git a/src/StderrMock.h b/src/StderrMock.h new file mode 100644 index 0000000..34215ae --- /dev/null +++ b/src/StderrMock.h @@ -0,0 +1,44 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: StderrMock.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___STDERRMOCK_H +#define ___STDERRMOCK_H + +#include <string> +#include <iostream> +#include <sstream> + +class StdErrMock +{ +private: + std::string expected; + std::streambuf* backupCerrStreamBuffer; + std::stringstream stdErrStringStream; + +public: + StdErrMock(); + ~StdErrMock(); + void Expect(std::string expectation); + void Verify(); +}; + +#endif diff --git a/src/StreamType.cc b/src/StreamType.cc new file mode 100644 index 0000000..44f772e --- /dev/null +++ b/src/StreamType.cc @@ -0,0 +1,17 @@ +#include "StreamType.h" + +using namespace std; + +string StreamTypeToString(StreamType type) +{ + switch (type) + { + case Low: + return tr("Low"); + case Medium: + return tr("Medium"); + case High: + return tr("High"); + } + return ""; +} diff --git a/src/StreamType.h b/src/StreamType.h new file mode 100644 index 0000000..bcd29dd --- /dev/null +++ b/src/StreamType.h @@ -0,0 +1,38 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: StreamType.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___STREAMTYPE_H_ +#define ___STREAMTYPE_H_ + +#include <string> +#include <vdr/i18n.h> + +enum StreamType +{ + Low=0, + Medium=1, + High=2, +}; + +std::string StreamTypeToString(StreamType type); + +#endif diff --git a/src/StreamType_test.cc b/src/StreamType_test.cc new file mode 100644 index 0000000..291d77f --- /dev/null +++ b/src/StreamType_test.cc @@ -0,0 +1,15 @@ +#include <cxxtest/TestSuite.h> + +#include "StreamType.h" + +class A_StreamType : public CxxTest::TestSuite +{ +public: + void Should_have_a_string_representation() + { + TS_ASSERT_EQUALS(std::string("i18n:Low"), StreamTypeToString(Low)); + TS_ASSERT_EQUALS(std::string("i18n:Medium"), StreamTypeToString(Medium)); + TS_ASSERT_EQUALS(std::string("i18n:High"), StreamTypeToString(High)); + } +}; + diff --git a/src/StringMessageMock.cc b/src/StringMessageMock.cc new file mode 100644 index 0000000..b2d76bd --- /dev/null +++ b/src/StringMessageMock.cc @@ -0,0 +1,154 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: StringMessageMock.cc 7656 2008-08-09 21:07:45Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include "StringMessageMock.h" +#include <algorithm> + +using namespace std; + +StringMessageMock::StringMessageMock() : + parent(NULL) +{ +} + +StringMessageMock::StringMessageMock(StringMessageMock& parent, string messagePrefix) : + parent(&parent), messagePrefix(messagePrefix) +{ +} + +void StringMessageMock::AddMessage(string message) +{ + if (parent) + { + if (messagePrefix != "") + { + message = messagePrefix + ":" + message; + } + parent->AddMessage(message); + } + current.push_back(message); +} + +void StringMessageMock::AddMethod(string methodName, string argument1, string argument2) +{ + AddMessage(MakeMethodMessage(methodName, argument1, argument2)); +} + +void StringMessageMock::Expect(string expectation) +{ + if (parent) + { + parent->Expect(expectation); + } + expectations.push_back(expectation); +} + +void StringMessageMock::ExpectMethod(string methodName, string argument1, string argument2) +{ + Expect(MakeMethodMessage(methodName, argument1, argument2)); +} + +void StringMessageMock::VerifyExpectations(const char* file, unsigned int line, bool ordered) +{ + vector<string>::iterator expectation = expectations.begin(); + vector<string>::iterator found = current.begin(); + + while (expectation != expectations.end()) + { + found = find(ordered ? found : current.begin(), current.end(), *expectation); + if (found == current.end()) + { + _TS_FAIL(file, line, *expectation + " expected"); + } + expectation++; + } +} + +void StringMessageMock::Verify(const char* file, unsigned int line) +{ + vector<string>::iterator i = expectations.begin(); + vector<string>::iterator j = current.begin(); + + while (i != expectations.end() && j != current.end()) + { + _TS_ASSERT_EQUALS(file, line, *i++, *j++) + } + + if (i != expectations.end()) + { + _TS_FAIL(file, line, (*i + " expected").c_str()); + } + + if (j != current.end()) + { + _TS_FAIL(file, line, (*j + " was not expected").c_str()); + } +} + +void StringMessageMock::Verify() +{ + vector<string>::iterator i = expectations.begin(); + vector<string>::iterator j = current.begin(); + + while (i != expectations.end() && j != current.end()) + { + TS_ASSERT_EQUALS(*i++, *j++) + } + + if (i != expectations.end()) + { + TS_FAIL((*i + " expected").c_str()); + } + + if (j != current.end()) + { + TS_FAIL((*j + " was not expected").c_str()); + } +} + +void StringMessageMock::ResetMock() +{ + expectations.clear(); + current.clear(); +} + +string StringMessageMock::MakeMethodMessage(string methodName, string argument1, string argument2) +{ + string message; + + message = methodName + "("; + + if (argument1 != "") + { + message = message + argument1; + } + + if (argument2 != "") + { + message = message + ", " + argument2; + } + + message = message + ")"; + + return message; +} diff --git a/src/StringMessageMock.h b/src/StringMessageMock.h new file mode 100644 index 0000000..10369ab --- /dev/null +++ b/src/StringMessageMock.h @@ -0,0 +1,68 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: StringMessageMock.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___STRINGMESSAGEMOCK_H +#define ___STRINGMESSAGEMOCK_H + +#include <string> +#include <vector> +#include <sstream> + +class StringMessageMock +{ +private: + std::vector<std::string> expectations; + std::vector<std::string> current; + StringMessageMock* parent; + std::string messagePrefix; + +private: + std::string MakeMethodMessage(std::string methodName, std::string argument1, std::string argument2); + +protected: + void AddMessage(std::string message); + void AddMethod(std::string methodName, std::string argument1 = "", std::string argument2 = ""); + +public: + StringMessageMock(); + StringMessageMock(StringMessageMock& parent, std::string messagePrefix = ""); + + template<class T> std::string MakeString(const T& subject) + { + std::stringstream sstream; + sstream << subject; + return sstream.str(); + } + + void Expect(std::string expectation); + void ExpectMethod(std::string methodName, std::string argument1 = "", std::string argument2 = ""); + void Verify(); + void Verify(const char* file, unsigned int line); + void VerifyExpectations(const char* file, unsigned int line, bool ordered=true); + void ResetMock(); +}; + +#define VERIFY_EXPECTATIONS(mock) (mock).VerifyExpectations(__FILE__, __LINE__) +#define VERIFY_EXPECTATIONS_UNORDERED(mock) (mock).VerifyExpectations(__FILE__, __LINE__, false) +#define VERIFY(mock) (mock).Verify(__FILE__, __LINE__) + +#endif // ___STRINGMESSAGEMOCK_H diff --git a/src/SynchedDownloadPool.cc b/src/SynchedDownloadPool.cc new file mode 100644 index 0000000..04d5564 --- /dev/null +++ b/src/SynchedDownloadPool.cc @@ -0,0 +1,61 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: SynchedDownloadPool.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "SynchedDownloadPool.h" +#include "Sleeper.h" +#include "Download.h" + +using namespace std; + +SynchedDownloadPool::SynchedDownloadPool(RefPtr<IDownloadPool> downloadPool, RefPtr<ISleeper> sleeper) : + downloadPool(downloadPool), sleeper(sleeper) +{ +} + +void SynchedDownloadPool::RemoveDownload(RefPtr<Download> download) +{ + downloadPool->RemoveDownload(download); +} + +RefPtr <Download> SynchedDownloadPool::GetNextDownload() +{ + RefPtr<Download> download = downloadPool->GetNextDownload(); + + if (!download.get()) + { + sleeper->Sleep(); + } + + return download; +} + +RefPtr <Download> SynchedDownloadPool::GetDownloadByUrl(string url) +{ + return downloadPool->GetDownloadByUrl(url); +} + +RefPtr<Download> SynchedDownloadPool::AddDownload(const string url) +{ + RefPtr<Download> download = downloadPool->AddDownload(url); + sleeper->WakeUp(); + return download; +} diff --git a/src/SynchedDownloadPool.h b/src/SynchedDownloadPool.h new file mode 100644 index 0000000..d17c864 --- /dev/null +++ b/src/SynchedDownloadPool.h @@ -0,0 +1,47 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: SynchedDownloadPool.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___SYNCHEDDOWNLOADPOOL_H +#define ___SYNCHEDDOWNLOADPOOL_H + +#include "IDownloadPool.h" + +class ISleeper; + +class SynchedDownloadPool : public IDownloadPool +{ +private: + RefPtr<IDownloadPool> downloadPool; + RefPtr<ISleeper> sleeper; + +public: + SynchedDownloadPool(RefPtr<IDownloadPool> downloadPool, RefPtr<ISleeper> sleeper); + // <IDownloadPool> + //void AddDownload(RefPtr<Download> download); + RefPtr<Download> AddDownload(const std::string url); + void RemoveDownload(RefPtr<Download> download); + RefPtr<Download> GetNextDownload(); + RefPtr<Download> GetDownloadByUrl(std::string url); + // </IDownloadPool> +}; + +#endif // ___SYNCHEDDOWNLOADPOOL_H diff --git a/src/SynchedDownloadPool_test.cc b/src/SynchedDownloadPool_test.cc new file mode 100644 index 0000000..8ea9042 --- /dev/null +++ b/src/SynchedDownloadPool_test.cc @@ -0,0 +1,101 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: SynchedDownloadPool_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include "SynchedDownloadPool.h" +#include "DownloadPoolMock.h" +#include "SleeperMock.h" +#include "Download.h" + +using namespace std; + +namespace +{ + +class SynchedDownloadPoolTest : public CxxTest::TestSuite +{ +public: + void TestWrappedDownloadPool() + { + DownloadPoolMock* wrappedDownloadPool = new DownloadPoolMock(); + RefPtr<IDownloadPool> wrappedDownloadPoolPtr(wrappedDownloadPool); + SynchedDownloadPool downloadPool(wrappedDownloadPoolPtr, RefPtr<ISleeper>(new SleeperMock())); + + wrappedDownloadPool->ExpectMethod("AddDownload", "foo"); + wrappedDownloadPool->ExpectMethod("GetNextDownload"); + wrappedDownloadPool->ExpectMethod("RemoveDownload", "foo"); + + RefPtr<Download> download = downloadPool.AddDownload("foo"); + wrappedDownloadPool->returnedDownload = download; + TS_ASSERT(NULL != downloadPool.GetNextDownload().get()); + downloadPool.RemoveDownload(download); + wrappedDownloadPool->Verify(); + } + + void TestSleepIfPoolIsEmpty() + { + StringMessageMock mock; + DownloadPoolMock* wrappedDownloadPool = new DownloadPoolMock(mock); + RefPtr<IDownloadPool> wrappedDownloadPoolPtr(wrappedDownloadPool); + SynchedDownloadPool downloadPool(wrappedDownloadPoolPtr, RefPtr<ISleeper>(new SleeperMock(mock))); + + mock.ExpectMethod("GetNextDownload"); + mock.ExpectMethod("Sleep"); + + TS_ASSERT(NULL == downloadPool.GetNextDownload().get()); + + mock.Verify(); + } + + void TestDoNotSleepIfPoolContainsDownloads() + { + StringMessageMock mock; + DownloadPoolMock* wrappedDownloadPool = new DownloadPoolMock(mock); + RefPtr<IDownloadPool> wrappedDownloadPoolPtr(wrappedDownloadPool); + SynchedDownloadPool downloadPool(wrappedDownloadPoolPtr, RefPtr<ISleeper>(new SleeperMock(mock))); + RefPtr<Download> download(new Download("foo")); + wrappedDownloadPool->returnedDownload = download; + + mock.ExpectMethod("GetNextDownload"); + + TS_ASSERT(NULL != downloadPool.GetNextDownload().get()); + + mock.Verify(); + } + + void TestWakeUpWhenAddingNewDownload() + { + StringMessageMock mock; + DownloadPoolMock* wrappedDownloadPool = new DownloadPoolMock(mock); + RefPtr<IDownloadPool> wrappedDownloadPoolPtr(wrappedDownloadPool); + SynchedDownloadPool downloadPool(wrappedDownloadPoolPtr, RefPtr<ISleeper>(new SleeperMock(mock))); + + mock.ExpectMethod("AddDownload", "foo"); + mock.ExpectMethod("WakeUp"); + + RefPtr<Download> download = downloadPool.AddDownload("foo"); + + mock.Verify(); + } +}; + +}; diff --git a/src/SyslogErrorLogger.cc b/src/SyslogErrorLogger.cc new file mode 100644 index 0000000..faeca21 --- /dev/null +++ b/src/SyslogErrorLogger.cc @@ -0,0 +1,36 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: SyslogErrorLogger.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "SyslogErrorLogger.h" +#include <vdr/tools.h> + +using namespace std; + +void SyslogErrorLogger::LogError(const string& Message) +{ + esyslog(("ERROR (vdr-vodcatcher): " + Message).c_str()); +} + +void SyslogErrorLogger::LogDebug(const string& Message) +{ + dsyslog(("DEBUG (vdr-vodcatcher): " + Message).c_str()); +} diff --git a/src/SyslogErrorLogger.h b/src/SyslogErrorLogger.h new file mode 100644 index 0000000..f568915 --- /dev/null +++ b/src/SyslogErrorLogger.h @@ -0,0 +1,37 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: SyslogErrorLogger.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___SYSLOGERRORLOGGER_H +#define ___SYSLOGERRORLOGGER_H + +#include "IErrorLogger.h" + +class SyslogErrorLogger : public IErrorLogger +{ +public: + // <IErrorLogger> + void LogError(const std::string& Message); + void LogDebug(const std::string& Message); + // </IErrorLogger> +}; + +#endif diff --git a/src/Thread.h b/src/Thread.h new file mode 100644 index 0000000..51b50e1 --- /dev/null +++ b/src/Thread.h @@ -0,0 +1,37 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: Thread.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___THREAD_H +#define ___THREAD_H + +class IThread +{ +public: + virtual ~IThread() + { + } + virtual void Start() = 0; + virtual void Stop() = 0; + virtual bool IsRunning() = 0; +}; + +#endif diff --git a/src/ThreadAction.h b/src/ThreadAction.h new file mode 100644 index 0000000..02816a3 --- /dev/null +++ b/src/ThreadAction.h @@ -0,0 +1,35 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ThreadAction.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___THREADACTION_H +#define ___THREADACTION_H + +class IThreadAction +{ +public: + virtual ~IThreadAction() + { + } + virtual bool Action() = 0; +}; + +#endif diff --git a/src/ThreadMock.cc b/src/ThreadMock.cc new file mode 100644 index 0000000..a7cdfd7 --- /dev/null +++ b/src/ThreadMock.cc @@ -0,0 +1,52 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ThreadMock.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "ThreadMock.h" + +using namespace std; + +ThreadMock::ThreadMock() +:StringMessageMock(), isRunning(false) +{ +} + +ThreadMock::ThreadMock(StringMessageMock& parent, string messagePrefix) +:StringMessageMock(parent, messagePrefix) +{ +} + +void ThreadMock::Start() +{ + AddMethod("Start"); + isRunning = true; +} + +void ThreadMock::Stop() +{ + AddMethod("Stop"); + isRunning = false; +} + +bool ThreadMock::IsRunning() +{ + return isRunning; +} diff --git a/src/ThreadMock.h b/src/ThreadMock.h new file mode 100644 index 0000000..47f656f --- /dev/null +++ b/src/ThreadMock.h @@ -0,0 +1,44 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ThreadMock.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___THREADMOCK_H +#define ___THREADMOCK_H + +#include "StringMessageMock.h" +#include "Thread.h" + +class ThreadMock : public StringMessageMock, public IThread +{ +private: + bool isRunning; + +public: + ThreadMock(); + ThreadMock(StringMessageMock& parent, std::string messagePrefix = ""); + // <IThread> + void Start(); + void Stop(); + bool IsRunning(); + // </IThread> +}; + +#endif diff --git a/src/ThreadsafeDownloadPool.cc b/src/ThreadsafeDownloadPool.cc new file mode 100644 index 0000000..7338a27 --- /dev/null +++ b/src/ThreadsafeDownloadPool.cc @@ -0,0 +1,66 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ThreadsafeDownloadPool.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "ThreadsafeDownloadPool.h" +#include "Thread.h" +#include "Sleeper.h" +#include "CriticalSection.h" +#include "Download.h" + +using namespace std; + +ThreadSafeDownloadPool::ThreadSafeDownloadPool(RefPtr<IDownloadPool> downloadPool, + RefPtr<ICriticalSection> criticalSection) : + downloadPool(downloadPool), criticalSection(criticalSection) +{ +} + +void ThreadSafeDownloadPool::RemoveDownload(RefPtr<Download> download) +{ + criticalSection->Enter(); + downloadPool->RemoveDownload(download); + criticalSection->Leave(); +} + +RefPtr<Download> ThreadSafeDownloadPool::GetNextDownload() +{ + criticalSection->Enter(); + RefPtr<Download> nextDownload = downloadPool->GetNextDownload(); + criticalSection->Leave(); + return nextDownload; +} + +RefPtr<Download> ThreadSafeDownloadPool::GetDownloadByUrl(string url) +{ + criticalSection->Enter(); + RefPtr<Download> download = downloadPool->GetDownloadByUrl(url); + criticalSection->Leave(); + return download; +} + +RefPtr<Download> ThreadSafeDownloadPool::AddDownload(const string url) +{ + criticalSection->Enter(); + RefPtr<Download> download = downloadPool->AddDownload(url); + criticalSection->Leave(); + return download; +} diff --git a/src/ThreadsafeDownloadPool.h b/src/ThreadsafeDownloadPool.h new file mode 100644 index 0000000..efc905b --- /dev/null +++ b/src/ThreadsafeDownloadPool.h @@ -0,0 +1,47 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ThreadsafeDownloadPool.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___THREADSAFEDOWNLOADPOOL_H +#define ___THREADSAFEDOWNLOADPOOL_H + +#include "IDownloadPool.h" + +class ICriticalSection; + +class ThreadSafeDownloadPool : public IDownloadPool +{ +private: + RefPtr<IDownloadPool> downloadPool; + RefPtr<ICriticalSection> criticalSection; + +public: + ThreadSafeDownloadPool(RefPtr<IDownloadPool> downloadPool, RefPtr<ICriticalSection> criticalSection); + // <IDownloadPool> + //void AddDownload(RefPtr<Download> download); + RefPtr<Download> AddDownload(const std::string url); + void RemoveDownload(RefPtr<Download> download); + RefPtr<Download> GetNextDownload(); + RefPtr<Download> GetDownloadByUrl(std::string url); + // </IDownloadPool> +}; + +#endif // ___THREADSAFEDOWNLOADPOOL_H diff --git a/src/ThreadsafeDownloadPool_test.cc b/src/ThreadsafeDownloadPool_test.cc new file mode 100644 index 0000000..ed5e420 --- /dev/null +++ b/src/ThreadsafeDownloadPool_test.cc @@ -0,0 +1,133 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ThreadsafeDownloadPool_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include "StringMessageMock.h" +#include "ThreadsafeDownloadPool.h" +#include "DownloadPoolMock.h" +#include "Download.h" +#include "CriticalSection.h" + +using namespace std; + +namespace +{ + +class CriticalSectionMock : public StringMessageMock, public ICriticalSection +{ +public: + CriticalSectionMock(StringMessageMock& parent) : + StringMessageMock(parent) + { + } + + // <ICriticalSection> + void Enter() + { + AddMethod("Enter"); + } + + void Leave() + { + AddMethod("Leave"); + } + // </ICriticalSection> +}; + +class ThreadSafeDownloadPoolTest : public CxxTest::TestSuite +{ +private: + StringMessageMock combinedMock; + DownloadPoolMock* downloadPool; + ICriticalSection* criticalSection; + ThreadSafeDownloadPool* queue; + +public: + void setUp() + { + combinedMock.ResetMock(); + downloadPool = new DownloadPoolMock(combinedMock); + criticalSection = new CriticalSectionMock(combinedMock); + queue = new ThreadSafeDownloadPool(RefPtr<IDownloadPool>(downloadPool), + RefPtr<ICriticalSection>(criticalSection)); + } + + void tearDown() + { + delete queue; + } + + void TestAddDownload() + { + combinedMock.ExpectMethod("Enter"); + combinedMock.ExpectMethod("AddDownload", "url"); + combinedMock.ExpectMethod("Leave"); + + RefPtr<Download> download = queue->AddDownload("url"); + + combinedMock.Verify(); + } + + void TestGetNextDownload() + { + RefPtr<Download> download(new Download("url")); + downloadPool->returnedDownload = download; + + combinedMock.ExpectMethod("Enter"); + combinedMock.ExpectMethod("GetNextDownload"); + combinedMock.ExpectMethod("Leave"); + + TS_ASSERT_EQUALS("url", queue->GetNextDownload()->GetUrl()); + + combinedMock.Verify(); + } + + void TestRemoveDownload() + { + RefPtr<Download> download(new Download("foo")); + + combinedMock.ExpectMethod("Enter"); + combinedMock.ExpectMethod("RemoveDownload", "foo"); + combinedMock.ExpectMethod("Leave"); + + queue->RemoveDownload(download); + + combinedMock.Verify(); + } + + void TestGetDownloadByUrl() + { + RefPtr<Download> download(new Download("url")); + downloadPool->returnedDownload = download; + + combinedMock.ExpectMethod("Enter"); + combinedMock.ExpectMethod("GetDownloadByUrl", "url"); + combinedMock.ExpectMethod("Leave"); + + TS_ASSERT_EQUALS("url", + queue->GetDownloadByUrl("url")->GetUrl()); + + combinedMock.Verify(); + } +}; + +}; diff --git a/src/VdrCriticalSection.cc b/src/VdrCriticalSection.cc new file mode 100644 index 0000000..25d154f --- /dev/null +++ b/src/VdrCriticalSection.cc @@ -0,0 +1,33 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: VdrCriticalSection.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "VdrCriticalSection.h" + +void VdrCriticalSection::Enter() +{ + mutex.Lock(); +} + +void VdrCriticalSection::Leave() +{ + mutex.Unlock(); +} diff --git a/src/VdrCriticalSection.h b/src/VdrCriticalSection.h new file mode 100644 index 0000000..63db989 --- /dev/null +++ b/src/VdrCriticalSection.h @@ -0,0 +1,39 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: VdrCriticalSection.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___VDRCRITICALSECTION_H +#define ___VDRCRITICALSECTION_H + +#include <vdr/thread.h> +#include "CriticalSection.h" + +class VdrCriticalSection : public ICriticalSection +{ +private: + cMutex mutex; + +public: + void Enter(); + void Leave(); +}; + +#endif diff --git a/src/VdrInterface.cc b/src/VdrInterface.cc new file mode 100644 index 0000000..8b50d11 --- /dev/null +++ b/src/VdrInterface.cc @@ -0,0 +1,36 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: VdrInterface.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "VdrInterface.h" +#include <vdr/skins.h> + +using namespace std; + +void VdrInterface::ShowMessage(const string& message) +{ + Skins.QueueMessage(mtInfo, message.c_str()); +} + +void VdrInterface::ShowErrorMessage(const string& message) +{ + Skins.Message(mtError, message.c_str()); +} diff --git a/src/VdrInterface.h b/src/VdrInterface.h new file mode 100644 index 0000000..ede6ad9 --- /dev/null +++ b/src/VdrInterface.h @@ -0,0 +1,35 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: VdrInterface.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___VDRINTERFACE_H_ +#define ___VDRINTERFACE_H_ + +#include "IVdrInterface.h" + +class VdrInterface: public IVdrInterface +{ +public: + void ShowMessage(const std::string& message); + void ShowErrorMessage(const std::string& message); +}; + +#endif /*VDRINTERFACE_H_*/ diff --git a/src/VdrSleeper.cc b/src/VdrSleeper.cc new file mode 100644 index 0000000..9f0c8cc --- /dev/null +++ b/src/VdrSleeper.cc @@ -0,0 +1,33 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: VdrSleeper.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "VdrSleeper.h" + +void VdrSleeper::Sleep() +{ + waitMutex.Wait(1000); +} + +void VdrSleeper::WakeUp() +{ + waitMutex.Signal(); +} diff --git a/src/VdrSleeper.h b/src/VdrSleeper.h new file mode 100644 index 0000000..251d8fc --- /dev/null +++ b/src/VdrSleeper.h @@ -0,0 +1,41 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: VdrSleeper.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___VDRSLEEPER_H +#define ___VDRSLEEPER_H + +#include <vdr/thread.h> +#include "Sleeper.h" + +class VdrSleeper : public ISleeper +{ +private: + cCondWait waitMutex; + +public: + // <ISleeper> + void Sleep(); + void WakeUp(); + // </ISleeper> +}; + +#endif diff --git a/src/VdrThread.cc b/src/VdrThread.cc new file mode 100644 index 0000000..f6145e7 --- /dev/null +++ b/src/VdrThread.cc @@ -0,0 +1,60 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: VdrThread.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "VdrThread.h" +#include "ThreadAction.h" + +VdrThread::VdrThread(RefPtr<IThreadAction> threadAction) : + threadAction(threadAction) +{ +} + +VdrThread::~VdrThread() +{ + Stop(); +} + +void VdrThread::Action() +{ + while (Running()) + { + if (!threadAction->Action()) + { + return; + } + } +} + +void VdrThread::Start() +{ + cThread::Start(); +} + +void VdrThread::Stop() +{ + cThread::Cancel(2000); +} + +bool VdrThread::IsRunning() +{ + return Running(); +} diff --git a/src/VdrThread.h b/src/VdrThread.h new file mode 100644 index 0000000..0ac3f20 --- /dev/null +++ b/src/VdrThread.h @@ -0,0 +1,52 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: VdrThread.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___VDRTHREAD_H +#define ___VDRTHREAD_H + +#include "RefPtr.h" +#include <vdr/thread.h> +#include "Thread.h" + +class IThreadAction; + +class VdrThread : public cThread, public IThread +{ +private: + RefPtr<IThreadAction> threadAction; + +protected: + // <cThread> + void Action(); + // </cThread> + +public: + VdrThread(RefPtr<IThreadAction> threadAction); + ~VdrThread(); + // <IThread> + void Start(); + void Stop(); + bool IsRunning(); + // <IThread> +}; + +#endif diff --git a/src/Version.h b/src/Version.h new file mode 100644 index 0000000..cb9d3b7 --- /dev/null +++ b/src/Version.h @@ -0,0 +1,28 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: Version.h 7664 2008-08-10 09:53:34Z svntobi $ + * + */ + +#ifndef ___VERSION_H +#define ___VERSION_H + +static const char VERSION[] = "0.2.1"; + +#endif diff --git a/src/VodcatcherPlugin.cc b/src/VodcatcherPlugin.cc new file mode 100644 index 0000000..3fa0fa4 --- /dev/null +++ b/src/VodcatcherPlugin.cc @@ -0,0 +1,212 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: VodcatcherPlugin.cc 7654 2008-08-06 18:40:41Z svntobi $ + * + */ + +#include "VodcatcherPlugin.h" +#include <iostream> +#include <getopt.h> +#include "Version.h" +#include "IFeedUpdater.h" +#include "IErrorLogger.h" +#include "IDownloadCache.h" +#include "IServiceLocator.h" +#include "Thread.h" + +using namespace std; + +VodcatcherPlugin::VodcatcherPlugin() : + cacheDirName(DEFAULT_CACHE_DIR), _maxCacheAge(30), _playBackQuality(High) +{ +} + +void VodcatcherPlugin::SetServiceLocator(RefPtr<IServiceLocator> serviceLocator) +{ + this->serviceLocator = serviceLocator; +} + +const char* VodcatcherPlugin::Version(void) +{ + return VERSION; +} + +const char* VodcatcherPlugin::Description(void) +{ + return tr("Browse and play video podcasts"); +} + +const char* VodcatcherPlugin::MainMenuEntry(void) +{ + return tr("Vodcatcher"); +} + +bool VodcatcherPlugin::Initialize(void) +{ + const char* configDir = ConfigDirectory(); + + if (configDir) + { + sourcesFileName = string(configDir) + "/vodcatchersources.conf"; + } + + if (CacheDirIsAccessible()) + { + return true; + } + else + { + serviceLocator->GetErrorLogger()->LogError("Unable to access cache directory `" + GetCacheDirName() + "`"); + return false; + } +} + +const char* VodcatcherPlugin::CommandLineHelp(void) +{ + return " -c, --cache=CACHE_DIR specify cache dir, defaults to " + "/var/cache/vdr-plugin-vodcatcher"; +} + +bool VodcatcherPlugin::ProcessArgs(int argc, char* argv[]) +{ + static struct option longOptions[] = + { + { "cache", required_argument, NULL, 'c' }, + { NULL } }; + + optind = 0; + opterr = 0; + + int optionChar; + int optionIndex = 0; + while ((optionChar = getopt_long(argc, argv, "c:", longOptions, &optionIndex)) != -1) + { + switch (optionChar) + { + case 'c': + { + cacheDirName = optarg; + break; + } + default: + { + cerr << argv[0] << ": " << "invalid option " << argv[optind-1] << endl; + return false; + } + } + } + return true; +} + +const string VodcatcherPlugin::GetCacheDirName() const +{ + return cacheDirName; +} + +const string VodcatcherPlugin::GetSourcesFileName() const +{ + return sourcesFileName; +} + +int VodcatcherPlugin::GetMaxCacheAge() const +{ + return _maxCacheAge; +} + +void VodcatcherPlugin::SetMaxCacheAge(const int age) +{ + _maxCacheAge = age; +} + +void VodcatcherPlugin::SetPlayBackQuality(const StreamType quality) +{ + _playBackQuality = quality; +} + +StreamType VodcatcherPlugin::GetPlayBackQuality() const +{ + return _playBackQuality; +} + +void VodcatcherPlugin::SetMediaPlayerType(const MediaPlayerType mediaPlayerType) +{ + _mediaPlayerType = mediaPlayerType; +} + +MediaPlayerType VodcatcherPlugin::GetMediaPlayerType() const +{ + return _mediaPlayerType; +} + +cOsdObject* VodcatcherPlugin::MainMenuAction() +{ + return serviceLocator->CreateFeedMenu(); +} + +bool VodcatcherPlugin::Start() +{ + serviceLocator->GetDownloadThread()->Start(); + serviceLocator->GetFeedUpdater()->Update(); + return true; +} + +void VodcatcherPlugin::Stop() +{ + serviceLocator->GetDownloadThread()->Stop(); +} + +void VodcatcherPlugin::Housekeeping() +{ + serviceLocator->GetFeedUpdater()->Update(); + serviceLocator->GetDownloadCache()->CleanUp(24 * GetMaxCacheAge()); +} + +bool VodcatcherPlugin::CacheDirIsAccessible() +{ + if (0 == access((GetCacheDirName()+"/.").c_str(), W_OK)) + { + return true; + } + else + { + return false; + } +} + +bool VodcatcherPlugin::SetupParse(const char* Name, const char* Value) +{ + if (string(Name) == "MaxCacheAge") + { + _maxCacheAge = atoi(Value); + return true; + } + + if (string(Name) == "MediaPlayerType") + { + _mediaPlayerType = (MediaPlayerType) atoi(Value); + return true; + } + + return false; +} + +cMenuSetupPage* VodcatcherPlugin::SetupMenu() +{ + return serviceLocator->CreateSetupMenu(); +} diff --git a/src/VodcatcherPlugin.h b/src/VodcatcherPlugin.h new file mode 100644 index 0000000..2aff88c --- /dev/null +++ b/src/VodcatcherPlugin.h @@ -0,0 +1,76 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: VodcatcherPlugin.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___VODCATCHERPLUGIN_H +#define ___VODCATCHERPLUGIN_H + +#include <vdr/plugin.h> +#include "RefPtr.h" +#include "IConfiguration.h" + +class IServiceLocator; + +class VodcatcherPlugin : public cPlugin, public IConfiguration +{ +private: + std::string cacheDirName; + std::string sourcesFileName; + RefPtr<IServiceLocator> serviceLocator; + unsigned int _maxCacheAge; + StreamType _playBackQuality; + MediaPlayerType _mediaPlayerType; + +private: + bool CacheDirIsAccessible(); + +public: + VodcatcherPlugin(); + void SetServiceLocator(RefPtr<IServiceLocator> serviceLocator); + // <cPlugin> + const char* Version(); + const char* Description(); + const char* MainMenuEntry(); + bool Initialize(); + bool Start(); + void Stop(); + void Housekeeping(); + const char* CommandLineHelp(); + bool ProcessArgs(int argc, char* argv[]); + cOsdObject* MainMenuAction(); + cMenuSetupPage* SetupMenu(); + bool SetupParse(const char* Name, const char* Value); + // </cPlugin> + // <IConfiguration> + const std::string GetCacheDirName() const; + const std::string GetSourcesFileName() const; + int GetMaxCacheAge() const; + void SetMaxCacheAge(const int age); + void SetPlayBackQuality(const StreamType quality); + StreamType GetPlayBackQuality() const; + void SetMediaPlayerType(MediaPlayerType mediaplayerType); + MediaPlayerType GetMediaPlayerType() const; + // </IConfiguration> +}; + +extern "C" void* VDRPluginCreator(); + +#endif // ___VODCATCHERPLUGIN_H diff --git a/src/VodcatcherPluginCommandline_test.cc b/src/VodcatcherPluginCommandline_test.cc new file mode 100644 index 0000000..442c33e --- /dev/null +++ b/src/VodcatcherPluginCommandline_test.cc @@ -0,0 +1,112 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: VodcatcherPluginCommandline_test.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <string> +#include <iostream> +#include <cxxtest/TestSuite.h> +#include "VodcatcherPlugin.h" +#include "StderrMock.h" + +using namespace std; + +namespace +{ + +class VodcatcherPluginCommandLineTest : public CxxTest::TestSuite +{ +private: + VodcatcherPlugin* plugin; + StdErrMock* stdErrMock; + +private: + void RedirectStdErr() + { + stdErrMock = new StdErrMock(); + } + + void RestoreStdErr() + { + delete stdErrMock; + } + +public: + void TestCommandLineHelp() + { + VodcatcherPlugin plugin; + TS_ASSERT_EQUALS(string(" -c, --cache=CACHE_DIR specify cache " + "dir, defaults to /var/cache/vdr-plugin-vodcatcher"), + plugin.CommandLineHelp()); + } + + void TestDefaultCommandLineParameters() + { + VodcatcherPlugin plugin; + char first[] = "dummy"; + char* argv[1] = + { first }; + + TS_ASSERT(plugin.ProcessArgs(0, argv)); + TS_ASSERT_EQUALS("/var/cache/vdr-plugin-vodcatcher", plugin.GetCacheDirName()); + } + + void TestWrongCommandLineParameters() + { + VodcatcherPlugin plugin; + StdErrMock stdErrMock; + char first[] = "dummy"; + char second[] = "--foo"; + char* argv[2] = + { first, second }; + + stdErrMock.Expect("dummy: invalid option --foo\n"); + TS_ASSERT(!plugin.ProcessArgs(2, argv)); + stdErrMock.Verify(); + } + + void TestShortCacheDirParameter() + { + VodcatcherPlugin plugin; + char first[] = "dummy"; + char second[] = "-c"; + char third[] = "/foo"; + char* argv[3] = + { first, second, third }; + + TS_ASSERT(plugin.ProcessArgs(3, argv)); + TS_ASSERT_EQUALS("/foo", plugin.GetCacheDirName()); + } + + void TestLongCacheDirParameter() + { + VodcatcherPlugin plugin; + char first[] = "dummy"; + char second[] = "--cache=/foo"; + char* argv[2] = + { first, second }; + + TS_ASSERT(plugin.ProcessArgs(2, argv)); + TS_ASSERT_EQUALS("/foo", plugin.GetCacheDirName()); + } +}; + +} +; diff --git a/src/VodcatcherPlugin_test.cc b/src/VodcatcherPlugin_test.cc new file mode 100644 index 0000000..94a0cd4 --- /dev/null +++ b/src/VodcatcherPlugin_test.cc @@ -0,0 +1,235 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: VodcatcherPlugin_test.cc 7664 2008-08-10 09:53:34Z svntobi $ + * + */ + +#include <cxxtest/TestSuite.h> +#include "vdr-stub/pluginhooks.h" +#include "VodcatcherPlugin.h" +#include "ThreadMock.h" +#include "ServiceLocatorStub.h" +#include "FeedUpdaterMock.h" +#include "IErrorLogger.h" +#include "DownloadCacheMock.h" +#include "vdr-stub/menusetuppagestub.h" + +using namespace std; + +namespace +{ + +class ErrorLoggerStub : public IErrorLogger +{ +public: + string lastLogMessage; + string lastDebugLogMessage; + +public: + // <IErrorLogger> + void LogError(const string& Message) + { + lastLogMessage = Message; + } + + void LogDebug(const string& Message) + { + lastDebugLogMessage = Message; + } + // </IErrorLogger> +}; + +class VodcatcherPluginTest : public CxxTest::TestSuite +{ +private: + VodcatcherPlugin* plugin; + ServiceLocatorStub* serviceLocator; + ErrorLoggerStub errorLoggerStub; + +public: + void setUp() + { + serviceLocator = new ServiceLocatorStub(); + plugin = new VodcatcherPlugin; + plugin->SetServiceLocator(RefPtr<IServiceLocator>(serviceLocator)); + serviceLocator->errorLogger = &errorLoggerStub; + } + + void tearDown() + { + system("rmdir ./notWritable 2>/dev/null"); + delete plugin; + } + + void TestMainMenuEntry() + { + TS_ASSERT_EQUALS(string("i18n:Vodcatcher"), plugin->MainMenuEntry()); + } + + void TestVersion() + { + TS_ASSERT_EQUALS(string("0.2.1"), plugin->Version()); + } + + void TestDescription() + { + TS_ASSERT_EQUALS(string("i18n:Browse and play video podcasts"), + plugin->Description()); + } + + void TestSourcesFileName() + { + char first[] = "dummy"; + char second[] = "--cache=."; + char* argv[2] = + { first, second }; + TS_ASSERT(plugin->ProcessArgs(2, argv)); + TS_ASSERT(plugin->Initialize()); + TS_ASSERT_EQUALS("/vdrstub/vodcatchersources.conf", + plugin->GetSourcesFileName()); + } + + void TestMainMenuAction() + { + cOsdMenu menu(""); + serviceLocator->feedMenu = &menu; + TS_ASSERT_EQUALS(&menu, plugin->MainMenuAction()); + } + + void TestSetupMenuAction() + { + MenuSetupPageStub setupMenu; + serviceLocator->setupMenu = &setupMenu; + TS_ASSERT_EQUALS(&setupMenu, plugin->SetupMenu()); + } + + void TestStartRunsDownloadThreadAndUpdatesFeeds() + { + ThreadMock downloadThread; + FeedUpdaterMock feedUpdater; + + serviceLocator->downloadThread = &downloadThread; + serviceLocator->feedUpdater = &feedUpdater; + + downloadThread.ExpectMethod("Start"); + feedUpdater.ExpectMethod("Update"); + + TS_ASSERT(plugin->Start()); + + downloadThread.Verify(); + feedUpdater.Verify(); + } + + void TestStopStopsDownloadThread() + { + ThreadMock downloadThread; + serviceLocator->downloadThread = &downloadThread; + + downloadThread.ExpectMethod("Stop"); + + plugin->Stop(); + + downloadThread.Verify(); + } + + void TestHousekeepingUpdatesFeeds() + { + FeedUpdaterMock feedUpdater; + serviceLocator->feedUpdater = &feedUpdater; + DownloadCacheMock downloadCache; + serviceLocator->downloadCache = &downloadCache; + + feedUpdater.ExpectMethod("Update"); + plugin->Housekeeping(); + feedUpdater.Verify(); + } + + void TestHousekeepingCleansCache() + { + FeedUpdaterMock feedUpdater; + serviceLocator->feedUpdater = &feedUpdater; + DownloadCacheMock downloadCache; + serviceLocator->downloadCache = &downloadCache; + plugin->SetupParse("MaxCacheAge", "10"); + + downloadCache.ExpectMethod("CleanUp", downloadCache.MakeString(10 * 24)); + plugin->Housekeeping(); + downloadCache.Verify(); + } + + void TestInitializeFailsWithErrorMessageIfCacheDirNotExisting() + { + char first[] = "dummy"; + char second[] = "--cache=/foo/notExisting"; + char* argv[2] = + { first, second }; + errorLoggerStub.lastLogMessage = ""; + + TS_ASSERT(plugin->ProcessArgs(2, argv)); + TS_ASSERT(!plugin->Initialize()); + TS_ASSERT_EQUALS("Unable to access cache directory " + "`/foo/notExisting`", errorLoggerStub.lastLogMessage); + } + + void TestInitializeFailsWithErrorMessageIfCacheDirNotWritable() + { + char first[] = "dummy"; + char second[] = "--cache=./notWritable"; + char* argv[2] = + { first, second }; + system("mkdir ./notWritable"); + system("chmod a-w ./notWritable"); + errorLoggerStub.lastLogMessage = ""; + + TS_ASSERT(plugin->ProcessArgs(2, argv)); + TS_ASSERT(!plugin->Initialize()); + TS_ASSERT_EQUALS("Unable to access cache directory " + "`./notWritable`", errorLoggerStub.lastLogMessage); + } + + void TestSetupParseFailsForUnknownSetting() + { + TS_ASSERT(!plugin->SetupParse("unknown setting", "value")); + } + + void TestDefaultMaxCacheAge() + { + TS_ASSERT_EQUALS(30, plugin->GetMaxCacheAge()); + } + + void TestSetupParseMaxCacheAge() + { + TS_ASSERT(plugin->SetupParse("MaxCacheAge", "10")); + TS_ASSERT_EQUALS(10, plugin->GetMaxCacheAge()); + } + + void TestSetMaxCacheAge() + { + plugin->SetMaxCacheAge(22); + TS_ASSERT_EQUALS(22, plugin->GetMaxCacheAge()); + } + + void TestDefaultPlayBackQuality() + { + TS_ASSERT_EQUALS(High, plugin->GetPlayBackQuality()); + } +}; + +} +; diff --git a/src/XineliboutputPlayer.cc b/src/XineliboutputPlayer.cc new file mode 100644 index 0000000..1c44e13 --- /dev/null +++ b/src/XineliboutputPlayer.cc @@ -0,0 +1,46 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: XineliboutputPlayer.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +using namespace std; + +#include "XineliboutputPlayer.h" + +const char* XineliboutputPlayer::ServiceId = "MediaPlayer-1.0"; + +XineliboutputPlayer::XineliboutputPlayer(IErrorLogger& errorLogger) : + _errorLogger(errorLogger) +{ + +} + +bool XineliboutputPlayer::Play(string url) +{ + _errorLogger.LogDebug("Starting to play " + url); + + if (!cPluginManager::CallFirstService(ServiceId, (void*) url.c_str())) + { + _errorLogger.LogDebug((string)"Failed to locate Xineliboutput MediaPlayer service '" + ServiceId + "'"); + return false; + } + + return true; +} diff --git a/src/XineliboutputPlayer.h b/src/XineliboutputPlayer.h new file mode 100644 index 0000000..2086fbe --- /dev/null +++ b/src/XineliboutputPlayer.h @@ -0,0 +1,43 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: XineliboutputPlayer.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef XINELIBOUTPUTPLAYER_H_ +#define XINELIBOUTPUTPLAYER_H_ + +#include "IMediaPlayer.h" +#include "IErrorLogger.h" +#include <vdr/plugin.h> + +class IErrorLogger; + +class XineliboutputPlayer : public IMediaPlayer +{ +private: + static const char* ServiceId; + IErrorLogger& _errorLogger; + +public: + XineliboutputPlayer(IErrorLogger& errorLogger); + virtual bool Play(std::string url); +}; + +#endif /*XINELIBOUTPUTPLAYER_H_*/ diff --git a/src/vdr-stub/ccontrolstub.cc b/src/vdr-stub/ccontrolstub.cc new file mode 100644 index 0000000..1e53f87 --- /dev/null +++ b/src/vdr-stub/ccontrolstub.cc @@ -0,0 +1,55 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ccontrolstub.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <vdr/player.h> +#include "ccontrolstub.h" +#include <vdr/osdbase.h> + +cControl::cControl(cPlayer *Player, bool Hidden) +{ +} + +cControl::~cControl() +{ +} + +cControlStub::cControlStub() +:cControl(NULL, false) +{ +} + +cControlStub::~cControlStub() +{ +} + +void cControl::Launch(cControl *control) +{ + cControlStub::LaunchedPlayerControl = control; +} + +cOsdObject* cControl::GetInfo(void) +{ + return NULL; +} + +cControl* cControlStub::LaunchedPlayerControl; + diff --git a/src/vdr-stub/ccontrolstub.h b/src/vdr-stub/ccontrolstub.h new file mode 100644 index 0000000..9218cf6 --- /dev/null +++ b/src/vdr-stub/ccontrolstub.h @@ -0,0 +1,39 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: ccontrolstub.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___CCONTROLSTUB_H +#define ___CCONTROLSTUB_H + +#include <vdr/player.h> + +class cControlStub: public cControl +{ + public: + static cControl* LaunchedPlayerControl; + + public: + cControlStub(); + ~cControlStub(); + void Hide() {}; +}; + +#endif diff --git a/src/vdr-stub/i18n.cc b/src/vdr-stub/i18n.cc new file mode 100644 index 0000000..6bab61a --- /dev/null +++ b/src/vdr-stub/i18n.cc @@ -0,0 +1,35 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: i18n.cc 7656 2008-08-09 21:07:45Z svntobi $ + * + */ + +#include <string> +#include <vector> +#include <iostream> + +using namespace std; + +const char *I18nTranslate(const char* s, const char* Plugin) +{ + static vector<string> translations; + translations.push_back(string("i18n:") + s); + + return translations[translations.size()-1].c_str(); +} diff --git a/src/vdr-stub/menuitems.cc b/src/vdr-stub/menuitems.cc new file mode 100644 index 0000000..2550ea5 --- /dev/null +++ b/src/vdr-stub/menuitems.cc @@ -0,0 +1,34 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: menuitems.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <vdr/menuitems.h> + +cMenuSetupPage::cMenuSetupPage() +:cOsdMenu("") +{ +} + +eOSState cMenuSetupPage::ProcessKey(eKeys Key) +{ + return osUnknown; +} + diff --git a/src/vdr-stub/menusetuppagestub.h b/src/vdr-stub/menusetuppagestub.h new file mode 100644 index 0000000..711c470 --- /dev/null +++ b/src/vdr-stub/menusetuppagestub.h @@ -0,0 +1,34 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: menusetuppagestub.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___MENUSETUPPAGESTUB_H +#define ___MENUSETUPPAGESTUB_H + +#include <vdr/menuitems.h> + +class MenuSetupPageStub: public cMenuSetupPage +{ + protected: + void Store() {}; +}; + +#endif diff --git a/src/vdr-stub/osdbase.cc b/src/vdr-stub/osdbase.cc new file mode 100644 index 0000000..31b991d --- /dev/null +++ b/src/vdr-stub/osdbase.cc @@ -0,0 +1,68 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: osdbase.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <vdr/osdbase.h> + +cListBase::cListBase() +{ +} + +cListBase::~cListBase() +{ +} + +void cListBase::Clear() +{ +} + +void cListBase::Move(int a, int b) +{ +} + +cOsdMenu::~cOsdMenu() +{ +} + +cOsdMenu::cOsdMenu(const char* a, int b, int c, int d, int e, int f) +{ +} + +void cOsdMenu::Clear() +{ +} + +void cOsdMenu::Del(int Index) +{ +} + +void cOsdMenu::Display(void) +{ +} + +eOSState cOsdMenu::ProcessKey(eKeys Key) +{ + return osUnknown; +} + +void cOsdObject::Show() +{ +} diff --git a/src/vdr-stub/plugin.cc b/src/vdr-stub/plugin.cc new file mode 100644 index 0000000..f1c481b --- /dev/null +++ b/src/vdr-stub/plugin.cc @@ -0,0 +1,130 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: plugin.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <string> +#include <vdr/plugin.h> +#include "pluginhooks.h" + +using namespace std; + +cPlugin::cPlugin(void) +{ +} + +cPlugin::~cPlugin() +{ +} + +const char* cPlugin::CommandLineHelp(void) +{ + return ""; +} + +bool cPlugin::ProcessArgs(int argCount, char* argValues[]) +{ + return false; +} + +bool cPlugin::Start(void) +{ + return false; +} + +void cPlugin::Stop(void) +{ +} + +void cPlugin::Housekeeping(void) +{ +} + +const char* cPlugin::MainMenuEntry(void) +{ + return ""; +} + +bool cPlugin::Initialize(void) +{ + return false; +} + +cOsdObject* cPlugin::MainMenuAction(void) +{ + return NULL; +} + +cMenuSetupPage* cPlugin::SetupMenu(void) +{ + return NULL; +} + +bool cPlugin::SetupParse(const char* Name, const char* Value) +{ + return false; +} + +bool cPlugin::Service(const char* Id, void* Data) +{ + return false; +} + +const char** cPlugin::SVDRPHelpPages(void) +{ + return NULL; +} + +cString cPlugin::SVDRPCommand(const char* Command, const char* Option, int &ReplyCode) +{ + return ""; +} + +#if APIVERSNUM >= 10507 +void cPlugin::RegisterI18n(const void *) +{ +} +#else +void cPlugin::RegisterI18n(const tI18nPhrase * const Phrases) +{ + PluginHooks::Phrases = Phrases; +} +#endif + +const char* cPlugin::ConfigDirectory(const char* PluginName) +{ + return "/vdrstub"; +} + +void cPlugin::MainThreadHook(void) +{ +} + +cString cPlugin::Active(void) +{ + return NULL; +} + +#if APIVERSNUM >= 10501 +time_t cPlugin::WakeupTime(void) +{ + return 0; +} +#endif diff --git a/src/vdr-stub/pluginhooks.cc b/src/vdr-stub/pluginhooks.cc new file mode 100644 index 0000000..719de81 --- /dev/null +++ b/src/vdr-stub/pluginhooks.cc @@ -0,0 +1,25 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: pluginhooks.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include "pluginhooks.h" + +const tI18nPhrase* PluginHooks::Phrases = NULL; diff --git a/src/vdr-stub/pluginhooks.h b/src/vdr-stub/pluginhooks.h new file mode 100644 index 0000000..4ac8cdd --- /dev/null +++ b/src/vdr-stub/pluginhooks.h @@ -0,0 +1,34 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: pluginhooks.h 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#ifndef ___PLUGINHOOKS_H +#define ___PLUGINHOOKS_H + +#include <vdr/i18n.h> + +class PluginHooks +{ + public: + static const tI18nPhrase* Phrases; +}; + +#endif diff --git a/src/vdr-stub/tools.cc b/src/vdr-stub/tools.cc new file mode 100644 index 0000000..4975303 --- /dev/null +++ b/src/vdr-stub/tools.cc @@ -0,0 +1,42 @@ +/* + * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2007 - 2008 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * $Id: tools.cc 7652 2008-08-05 21:37:57Z svntobi $ + * + */ + +#include <vdr/tools.h> +#include <vdr/config.h> + +cString::cString(const char* S, bool TakePointer) +{ +} + +cString::~cString() +{ +} + +#if APIVERSNUM < 10500 +cTimeMs::cTimeMs() +{ +} +#else +cTimeMs::cTimeMs(int Ms) +{ +} +#endif |