diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e57d26ba..12c54934c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,10 +48,11 @@ set (musikbox_LINK_LIBS include_directories ( "${musikbox_SOURCE_DIR}/src" "${musikbox_SOURCE_DIR}/src/core" + "${musikbox_SOURCE_DIR}/src/musikbox" "${musikbox_SOURCE_DIR}/src/3rdparty/include" ) add_subdirectory(src/3rdparty) add_subdirectory(src/core) #add_subdirectory(src/contrib) -#add_subdirectory(src/musikbox) +add_subdirectory(src/musikbox) diff --git a/src/3rdparty/include/curses.h b/src/3rdparty/win32_include/curses.h similarity index 100% rename from src/3rdparty/include/curses.h rename to src/3rdparty/win32_include/curses.h diff --git a/src/3rdparty/include/panel.h b/src/3rdparty/win32_include/panel.h similarity index 100% rename from src/3rdparty/include/panel.h rename to src/3rdparty/win32_include/panel.h diff --git a/src/musikbox/CMakeLists.txt b/src/musikbox/CMakeLists.txt index 79b31d28b..376c9db47 100644 --- a/src/musikbox/CMakeLists.txt +++ b/src/musikbox/CMakeLists.txt @@ -1,20 +1,84 @@ -set (SQUARE_SRCS - stdafx.cpp - player.cpp - DummyAudioEventHandler.cpp - ConsoleUI.cpp +set (BOX_SRCS + ./Main.cpp + ./stdafx.cpp + ./app/layout/LibraryLayout.cpp + ./app/layout/MainLayout.cpp + ./app/query/CategoryListViewQuery.cpp + ./app/query/SingleTrackQuery.cpp + ./app/query/TrackListViewQuery.cpp + ./app/service/PlaybackService.cpp + ./app/util/GlobalHotkeys.cpp + ./app/util/SystemInfo.cpp + ./app/util/Text.cpp + ./app/window/CategoryListView.cpp + ./app/window/CommandWindow.cpp + ./app/window/LogWindow.cpp + ./app/window/OutputWindow.cpp + ./app/window/ResourcesWindow.cpp + ./app/window/TrackListView.cpp + ./app/window/TransportWindow.cpp + ./cursespp/Colors.cpp + ./cursespp/LayoutBase.cpp + ./cursespp/LayoutStack.cpp + ./cursespp/ListWindow.cpp + ./cursespp/Message.cpp + ./cursespp/MessageQueue.cpp + ./cursespp/MultiLineEntry.cpp + ./cursespp/Screen.cpp + ./cursespp/ScrollableWindow.cpp + ./cursespp/ScrollAdapterBase.cpp + ./cursespp/SimpleScrollAdapter.cpp + ./cursespp/SingleLineEntry.cpp + ./cursespp/Window.cpp + ./cursespp/WindowLayout.cpp ) -set (SQUARE_HEADERS - config.h - ConsoleUI.h - DummyAudioEventHandler.h - memtrace.h - stdafx.h +set (BOX_HEADERS + ./stdafx.h + ./app/layout/LibraryLayout.h + ./app/layout/MainLayout.h + ./app/query/CategoryListViewQuery.h + ./app/query/SingleTrackQuery.h + ./app/query/TrackListViewQuery.h + ./app/service/PlaybackService.h + ./app/util/GlobalHotkeys.h + ./app/util/SystemInfo.h + ./app/util/Text.h + ./app/window/CategoryListView.h + ./app/window/CommandWindow.h + ./app/window/LogWindow.h + ./app/window/OutputWindow.h + ./app/window/ResourcesWindow.h + ./app/window/TrackListView.h + ./app/window/TransportWindow.h + ./cursespp/Colors.h + ./cursespp/curses_config.h + ./cursespp/IDisplayable.h + ./cursespp/IInput.h + ./cursespp/IKeyHandler.h + ./cursespp/ILayout.h + ./cursespp/ILayoutStack.h + ./cursespp/IMessage.h + ./cursespp/IMessageTarget.h + ./cursespp/IOrderable.h + ./cursespp/IScrollable.h + ./cursespp/IScrollAdapter.h + ./cursespp/IWindow.h + ./cursespp/IWindowGroup.h + ./cursespp/LayoutBase.h + ./cursespp/LayoutStack.h + ./cursespp/ListWindow.h + ./cursespp/Message.h + ./cursespp/MessageQueue.h + ./cursespp/MultiLineEntry.h + ./cursespp/Screen.h + ./cursespp/ScrollableWindow.h + ./cursespp/ScrollAdapterBase.h + ./cursespp/SimpleScrollAdapter.h + ./cursespp/SingleLineEntry.h + ./cursespp/Window.h + ./cursespp/WindowLayout.h ) -SOURCE_GROUP ("Source Files" FILES ${SQUARE_SRCS}) -SOURCE_GROUP ("Header Files" FILES ${SQUARE_HEADERS}) - -add_executable(square ${SQUARE_SRCS} ${SQUARE_HEADERS}) -target_link_libraries(square ${musikCube_LINK_LIBS} musik) \ No newline at end of file +add_executable(musikbox ${BOX_SRCS} ${BOX_HEADERS}) +target_link_libraries(musikbox ${musikbox_LINK_LIBS} curses panel musikcore) diff --git a/src/musikbox/Main.cpp b/src/musikbox/Main.cpp index 1b2396f4a..546cac8f7 100644 --- a/src/musikbox/Main.cpp +++ b/src/musikbox/Main.cpp @@ -3,31 +3,31 @@ // // All rights reserved. // -// Redistribution and use in source and binary forms, with or without +// Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // -// * Neither the name of the author nor the names of other contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. // -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. // ////////////////////////////////////////////////////////////////////////////// @@ -95,7 +95,7 @@ static void changeLayout(WindowState& current, ILayoutPtr newLayout) { if (current.layout) { current.layout->Hide(); - current.layout = { 0 }; + current.layout.reset(); } if (newLayout) { @@ -149,7 +149,7 @@ int main(int argc, char* argv[]) std::locale locale = std::locale(); std::locale utf8Locale(locale, new boost::filesystem::detail::utf8_codecvt_facet); boost::filesystem::path::imbue(utf8Locale); - + musik::debug::init(); ttytype[0] = 30; /* min height */ @@ -184,14 +184,17 @@ int main(int argc, char* argv[]) GlobalHotkeys globalHotkeys(playback, library); - ILayoutPtr libraryLayout(new LibraryLayout(playback, library)); - ILayoutPtr consoleLayout(new MainLayout(tp, library)); + ILayoutPtr libraryLayout((ILayout *) new LibraryLayout(playback, library)); + ILayoutPtr consoleLayout((ILayout *) new MainLayout(tp, library)); int64 ch; timeout(IDLE_TIMEOUT_MS); bool quit = false; - WindowState state = { 0 }; + WindowState state; + state.input = NULL; + state.keyHandler = NULL; + changeLayout(state, libraryLayout); while (!quit) { @@ -249,4 +252,3 @@ int main(int argc, char* argv[]) return 0; } - diff --git a/src/musikbox/app/layout/LibraryLayout.cpp b/src/musikbox/app/layout/LibraryLayout.cpp index 3066f0368..af706ba5c 100755 --- a/src/musikbox/app/layout/LibraryLayout.cpp +++ b/src/musikbox/app/layout/LibraryLayout.cpp @@ -136,4 +136,4 @@ bool LibraryLayout::KeyPress(int64 ch) { } return LayoutBase::KeyPress(ch); -} \ No newline at end of file +} diff --git a/src/musikbox/app/layout/LibraryLayout.h b/src/musikbox/app/layout/LibraryLayout.h index 14e271f35..0d316df02 100755 --- a/src/musikbox/app/layout/LibraryLayout.h +++ b/src/musikbox/app/layout/LibraryLayout.h @@ -17,16 +17,16 @@ namespace musik { class LibraryLayout : public cursespp::LayoutBase, public sigslot::has_slots<> { public: LibraryLayout( - PlaybackService& playback, + PlaybackService& playback, musik::core::LibraryPtr library); virtual ~LibraryLayout(); virtual void Layout(); virtual void Show(); - virtual bool LibraryLayout::KeyPress(int64 ch); - virtual cursespp::IWindowPtr GetFocus(); - + virtual cursespp::IWindowPtr GetFocus(); + virtual bool KeyPress(int64 ch); + private: void InitializeWindows(); diff --git a/src/musikbox/app/layout/MainLayout.cpp b/src/musikbox/app/layout/MainLayout.cpp index 150a99a8c..0ed8de6b0 100755 --- a/src/musikbox/app/layout/MainLayout.cpp +++ b/src/musikbox/app/layout/MainLayout.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "stdafx.h" #include "MainLayout.h" #include @@ -73,4 +71,4 @@ void MainLayout::ProcessMessage(IMessage &message) { void MainLayout::UpdateWindows() { this->logs->Update(); this->resources->Update(); -} \ No newline at end of file +} diff --git a/src/musikbox/app/query/CategoryListViewQuery.cpp b/src/musikbox/app/query/CategoryListViewQuery.cpp index 61235a0c7..3ac87336a 100755 --- a/src/musikbox/app/query/CategoryListViewQuery.cpp +++ b/src/musikbox/app/query/CategoryListViewQuery.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "stdafx.h" #include "CategoryListViewQuery.h" @@ -17,7 +15,7 @@ using namespace musik::core::db; using namespace musik::core::library::constants; using namespace musik::box; -#define reset(x) x.reset(new std::vector>); +#define reset(x) x.reset(new std::vector >); static const std::string ALBUM_QUERY = "SELECT DISTINCT albums.id, albums.name " @@ -41,9 +39,9 @@ static boost::mutex QUERY_MAP_MUTEX; static std::map FIELD_TO_QUERY_MAP; static void initFieldToQueryMap() { - FIELD_TO_QUERY_MAP.emplace(Track::ALBUM_ID, ALBUM_QUERY); - FIELD_TO_QUERY_MAP.emplace(Track::ARTIST_ID, ARTIST_QUERY); - FIELD_TO_QUERY_MAP.emplace(Track::GENRE_ID, GENRE_QUERY); + FIELD_TO_QUERY_MAP[Track::ALBUM_ID] = ALBUM_QUERY; + FIELD_TO_QUERY_MAP[Track::ARTIST_ID] = ARTIST_QUERY; + FIELD_TO_QUERY_MAP[Track::GENRE_ID] = GENRE_QUERY; } CategoryListViewQuery::CategoryListViewQuery(const std::string& trackField) { @@ -77,7 +75,7 @@ bool CategoryListViewQuery::OnRun(Connection& db) { std::string query = FIELD_TO_QUERY_MAP[this->trackField]; Statement stmt(query.c_str(), db); - + while (stmt.Step() == Row) { std::shared_ptr row(new Result()); row->id = stmt.ColumnInt64(0); @@ -86,4 +84,4 @@ bool CategoryListViewQuery::OnRun(Connection& db) { } return true; -} \ No newline at end of file +} diff --git a/src/musikbox/app/query/CategoryListViewQuery.h b/src/musikbox/app/query/CategoryListViewQuery.h index 0bac0bb1b..51dc616b9 100755 --- a/src/musikbox/app/query/CategoryListViewQuery.h +++ b/src/musikbox/app/query/CategoryListViewQuery.h @@ -14,7 +14,7 @@ namespace musik { }; typedef std::shared_ptr>> ResultList; + std::shared_ptr > > ResultList; CategoryListViewQuery(const std::string& trackField); virtual ~CategoryListViewQuery(); @@ -30,4 +30,4 @@ namespace musik { ResultList result; }; } -} \ No newline at end of file +} diff --git a/src/musikbox/app/query/SingleTrackQuery.cpp b/src/musikbox/app/query/SingleTrackQuery.cpp index 68e81b089..b146b5363 100755 --- a/src/musikbox/app/query/SingleTrackQuery.cpp +++ b/src/musikbox/app/query/SingleTrackQuery.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "stdafx.h" #include "SingleTrackQuery.h" @@ -32,4 +30,4 @@ bool SingleTrackQuery::OnRun(Connection& db) { result.reset(new LibraryTrack()); result->SetValue("filename", filename.c_str()); return LibraryTrack::Load(result.get(), db); -} \ No newline at end of file +} diff --git a/src/musikbox/app/query/TrackListViewQuery.cpp b/src/musikbox/app/query/TrackListViewQuery.cpp index c7a39e3ac..595af18fc 100755 --- a/src/musikbox/app/query/TrackListViewQuery.cpp +++ b/src/musikbox/app/query/TrackListViewQuery.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "stdafx.h" #include "TrackListViewQuery.h" @@ -66,4 +64,4 @@ bool TrackListViewQuery::OnRun(Connection& db) { } return true; -} \ No newline at end of file +} diff --git a/src/musikbox/app/query/TrackListViewQuery.h b/src/musikbox/app/query/TrackListViewQuery.h index 9d62105ef..3d683e13b 100755 --- a/src/musikbox/app/query/TrackListViewQuery.h +++ b/src/musikbox/app/query/TrackListViewQuery.h @@ -10,10 +10,10 @@ namespace musik { class TrackListViewQuery : public musik::core::query::QueryBase { public: typedef std::shared_ptr< - std::vector> Result; + std::vector > Result; TrackListViewQuery( - musik::core::LibraryPtr library, + musik::core::LibraryPtr library, const std::string& column, DBID id); virtual ~TrackListViewQuery(); diff --git a/src/musikbox/app/util/SystemInfo.cpp b/src/musikbox/app/util/SystemInfo.cpp index 32041e5e8..b70421c73 100755 --- a/src/musikbox/app/util/SystemInfo.cpp +++ b/src/musikbox/app/util/SystemInfo.cpp @@ -2,13 +2,14 @@ #include "SystemInfo.h" +using namespace musik::box; + +#ifdef WIN32 + #include "windows.h" #include "psapi.h" #include "pdh.h" -using namespace musik::box; - -#ifdef WIN32 class WindowsSystemInfo : public SystemInfo { public: WindowsSystemInfo(); @@ -125,15 +126,15 @@ double WindowsSystemInfo::GetCpuUsage() { FILETIME ftime, fsys, fuser; ULARGE_INTEGER now, sys, user; double percent; - + GetSystemTimeAsFileTime(&ftime); memcpy(&now, &ftime, sizeof(FILETIME)); - + GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser); memcpy(&sys, &fsys, sizeof(FILETIME)); memcpy(&user, &fuser, sizeof(FILETIME)); - - percent = + + percent = (double) (sys.QuadPart - lastSysCpu.QuadPart) + (double) (user.QuadPart - lastUserCpu.QuadPart); @@ -142,11 +143,11 @@ double WindowsSystemInfo::GetCpuUsage() { percent /= diff; percent /= processorCount; - + lastCpu = now; lastUserCpu = user; lastSysCpu = sys; - + return (percent * 100.0f); } -#endif \ No newline at end of file +#endif diff --git a/src/musikbox/app/util/Text.cpp b/src/musikbox/app/util/Text.cpp index 344728690..de1ae3dc0 100755 --- a/src/musikbox/app/util/Text.cpp +++ b/src/musikbox/app/util/Text.cpp @@ -16,12 +16,13 @@ namespace musik { size_t c = 0; while (c < len && it != str.end()) { try { - utf8::next(it++, end); + utf8::next(it, end); } catch (...) { - it++; /* invalid encoding, just treat as a single char */ + /* invalid encoding, just treat as a single char */ } + ++it; ++c; } @@ -52,4 +53,4 @@ namespace musik { } } } -} \ No newline at end of file +} diff --git a/src/musikbox/app/window/CategoryListView.cpp b/src/musikbox/app/window/CategoryListView.cpp index 4c868a6c0..20a4d99f9 100755 --- a/src/musikbox/app/window/CategoryListView.cpp +++ b/src/musikbox/app/window/CategoryListView.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "stdafx.h" #include @@ -84,7 +82,7 @@ IScrollAdapter& CategoryListView::GetScrollAdapter() { return *adapter; } -CategoryListView::Adapter::Adapter(CategoryListView &parent) +CategoryListView::Adapter::Adapter(CategoryListView &parent) : parent(parent) { } @@ -100,4 +98,4 @@ IScrollAdapter::EntryPtr CategoryListView::Adapter::GetEntry(size_t index) { IScrollAdapter::EntryPtr entry(new SingleLineEntry(value)); entry->SetAttrs(attrs); return entry; -} \ No newline at end of file +} diff --git a/src/musikbox/app/window/CategoryListView.h b/src/musikbox/app/window/CategoryListView.h index 76a5ef5a4..f8431586c 100755 --- a/src/musikbox/app/window/CategoryListView.h +++ b/src/musikbox/app/window/CategoryListView.h @@ -20,7 +20,11 @@ using cursespp::ScrollAdapterBase; namespace musik { namespace box { - class CategoryListView : public ListWindow, public sigslot::has_slots<> { + class CategoryListView : + public ListWindow, + public std::enable_shared_from_this, + public sigslot::has_slots<> + { public: CategoryListView(LibraryPtr library, const std::string& fieldName); virtual ~CategoryListView(); diff --git a/src/musikbox/app/window/CommandWindow.cpp b/src/musikbox/app/window/CommandWindow.cpp index 915035b9f..98ae2b992 100755 --- a/src/musikbox/app/window/CommandWindow.cpp +++ b/src/musikbox/app/window/CommandWindow.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "stdafx.h" #include @@ -41,8 +39,8 @@ bool tostr(T& t, const std::string& s) { CommandWindow::CommandWindow( IWindow *parent, Transport& transport, - LibraryPtr library, - OutputWindow& output) + LibraryPtr library, + OutputWindow& output) : Window(parent) { this->SetContentColor(BOX_COLOR_WHITE_ON_BLACK); this->transport = &transport; @@ -232,7 +230,7 @@ void CommandWindow::ListPlugins() const { using musik::core::IPlugin; using musik::core::PluginFactory; - typedef std::vector> PluginList; + typedef std::vector > PluginList; typedef PluginFactory::NullDeleter Deleter; PluginList plugins = PluginFactory::Instance() @@ -248,4 +246,4 @@ void CommandWindow::ListPlugins() const { this->output->WriteLine(format, BOX_COLOR_RED_ON_BLUE); } -} \ No newline at end of file +} diff --git a/src/musikbox/app/window/CommandWindow.h b/src/musikbox/app/window/CommandWindow.h index 5555111a4..a9a560261 100755 --- a/src/musikbox/app/window/CommandWindow.h +++ b/src/musikbox/app/window/CommandWindow.h @@ -9,10 +9,11 @@ namespace musik { namespace box { - class CommandWindow : - public cursespp::Window, - public cursespp::IInput, - public sigslot::has_slots<> + class CommandWindow : + public cursespp::Window, + public cursespp::IInput, + public std::enable_shared_from_this, + public sigslot::has_slots<> { public: CommandWindow( @@ -21,7 +22,7 @@ namespace musik { musik::core::LibraryPtr library, OutputWindow& output); - ~CommandWindow(); + virtual ~CommandWindow(); virtual void WriteChar(int64 ch); virtual void Focus(); diff --git a/src/musikbox/app/window/LogWindow.cpp b/src/musikbox/app/window/LogWindow.cpp index d99973eee..83e7df932 100755 --- a/src/musikbox/app/window/LogWindow.cpp +++ b/src/musikbox/app/window/LogWindow.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "stdafx.h" #include "LogWindow.h" @@ -13,7 +11,7 @@ using namespace cursespp; typedef IScrollAdapter::IEntry IEntry; -LogWindow::LogWindow(IWindow *parent) +LogWindow::LogWindow(IWindow *parent) : ScrollableWindow(parent) { this->SetContentColor(BOX_COLOR_WHITE_ON_BLUE); @@ -81,4 +79,4 @@ void LogWindow::OnLogged( /* from a background thread */ entry->tag = tag; entry->message = message; pending.push_back(entry); -} \ No newline at end of file +} diff --git a/src/musikbox/app/window/LogWindow.h b/src/musikbox/app/window/LogWindow.h index 97541e273..4b2179fbe 100755 --- a/src/musikbox/app/window/LogWindow.h +++ b/src/musikbox/app/window/LogWindow.h @@ -11,10 +11,14 @@ namespace musik { namespace box { - class LogWindow : public cursespp::ScrollableWindow, public sigslot::has_slots<> { + class LogWindow : + public cursespp::ScrollableWindow, + public std::enable_shared_from_this, + public sigslot::has_slots<> + { public: LogWindow(cursespp::IWindow *parent = NULL); - ~LogWindow(); + virtual ~LogWindow(); void Update(); diff --git a/src/musikbox/app/window/OutputWindow.cpp b/src/musikbox/app/window/OutputWindow.cpp index 2cf2a3b14..571d65a33 100755 --- a/src/musikbox/app/window/OutputWindow.cpp +++ b/src/musikbox/app/window/OutputWindow.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "stdafx.h" #include "OutputWindow.h" @@ -13,7 +11,7 @@ using namespace cursespp; typedef IScrollAdapter::EntryPtr EntryPtr; -OutputWindow::OutputWindow(IWindow *parent) +OutputWindow::OutputWindow(IWindow *parent) : ScrollableWindow(parent) { this->SetContentColor(BOX_COLOR_BLACK_ON_GREY); this->adapter = new SimpleScrollAdapter(); @@ -32,4 +30,4 @@ IScrollAdapter& OutputWindow::GetScrollAdapter() { void OutputWindow::WriteLine(const std::string& text, int64 attrs) { this->adapter->AddEntry(EntryPtr(new MultiLineEntry(text, attrs))); this->OnAdapterChanged(); -} \ No newline at end of file +} diff --git a/src/musikbox/app/window/OutputWindow.h b/src/musikbox/app/window/OutputWindow.h index f351fd64e..4786ea639 100755 --- a/src/musikbox/app/window/OutputWindow.h +++ b/src/musikbox/app/window/OutputWindow.h @@ -7,16 +7,19 @@ namespace musik { namespace box { - class OutputWindow : public cursespp::ScrollableWindow { - public: - OutputWindow(cursespp::IWindow *parent = NULL); - ~OutputWindow(); + class OutputWindow : + public cursespp::ScrollableWindow, + public std::enable_shared_from_this + { + public: + OutputWindow(cursespp::IWindow *parent = NULL); + virtual ~OutputWindow(); - void WriteLine(const std::string& line, int64 attrs = -1); - virtual cursespp::IScrollAdapter& GetScrollAdapter(); + void WriteLine(const std::string& line, int64 attrs = -1); + virtual cursespp::IScrollAdapter& GetScrollAdapter(); - private: - cursespp::SimpleScrollAdapter* adapter; + private: + cursespp::SimpleScrollAdapter* adapter; }; } } diff --git a/src/musikbox/app/window/ResourcesWindow.cpp b/src/musikbox/app/window/ResourcesWindow.cpp index 378f6bf4b..ad6205f73 100755 --- a/src/musikbox/app/window/ResourcesWindow.cpp +++ b/src/musikbox/app/window/ResourcesWindow.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "stdafx.h" #include "ResourcesWindow.h" @@ -16,7 +14,7 @@ using namespace cursespp; #define BYTES_PER_MEGABYTE 1048576.0f -ResourcesWindow::ResourcesWindow(IWindow *parent) +ResourcesWindow::ResourcesWindow(IWindow *parent) : Window(parent) { this->systemInfo = SystemInfo::Create(); } @@ -33,11 +31,11 @@ void ResourcesWindow::Update() { double cpuUsage = (double) systemInfo->GetCpuUsage(); wprintw( - this->GetContent(), - "cpu %.2f%% - virt %.2f (mb) - phys %.2f (mb)", + this->GetContent(), + "cpu %.2f%% - virt %.2f (mb) - phys %.2f (mb)", cpuUsage, virtualMemoryUsed, physicalMemoryUsed); this->Repaint(); -} \ No newline at end of file +} diff --git a/src/musikbox/app/window/ResourcesWindow.h b/src/musikbox/app/window/ResourcesWindow.h index 973405db5..17a89ef30 100755 --- a/src/musikbox/app/window/ResourcesWindow.h +++ b/src/musikbox/app/window/ResourcesWindow.h @@ -7,7 +7,10 @@ namespace musik { namespace box { - class ResourcesWindow : public cursespp::Window { + class ResourcesWindow : + public cursespp::Window, + public std::enable_shared_from_this + { public: ResourcesWindow(cursespp::IWindow *parent = NULL); virtual ~ResourcesWindow(); diff --git a/src/musikbox/app/window/TrackListView.cpp b/src/musikbox/app/window/TrackListView.cpp index 3db5032c7..e11ae9cff 100755 --- a/src/musikbox/app/window/TrackListView.cpp +++ b/src/musikbox/app/window/TrackListView.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "stdafx.h" #include @@ -132,7 +130,7 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) { duration = text::Duration(duration); std::string text = boost::str( - boost::format("%s %s %s %s %s") + boost::format("%s %s %s %s %s") % group(setw(column0Width), setfill(' '), trackNum) % group(setw(column1Width), setiosflags(std::ios::left), setfill(' '), title) % group(setw(column2Width), setiosflags(std::ios::right), setfill(' '), duration) @@ -144,4 +142,4 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) { entry->SetAttrs(attrs); return entry; -} \ No newline at end of file +} diff --git a/src/musikbox/app/window/TrackListView.h b/src/musikbox/app/window/TrackListView.h index 2c135ff87..b1172325b 100755 --- a/src/musikbox/app/window/TrackListView.h +++ b/src/musikbox/app/window/TrackListView.h @@ -13,13 +13,17 @@ namespace musik { namespace box { - class TrackListView : public cursespp::ListWindow, public sigslot::has_slots<> { + class TrackListView : + public cursespp::ListWindow, + public std::enable_shared_from_this, + public sigslot::has_slots<> + { public: TrackListView( - PlaybackService& playback, + PlaybackService& playback, musik::core::LibraryPtr library); - ~TrackListView(); + virtual ~TrackListView(); virtual void ProcessMessage(cursespp::IMessage &message); virtual bool KeyPress(int64 ch); @@ -44,7 +48,7 @@ namespace musik { private: std::shared_ptr query; - std::shared_ptr> metadata; + std::shared_ptr > metadata; Adapter* adapter; PlaybackService& playback; musik::core::LibraryPtr library; diff --git a/src/musikbox/app/window/TransportWindow.cpp b/src/musikbox/app/window/TransportWindow.cpp index e4e91f09c..773aeae92 100755 --- a/src/musikbox/app/window/TransportWindow.cpp +++ b/src/musikbox/app/window/TransportWindow.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "stdafx.h" #include "TransportWindow.h" @@ -18,6 +16,8 @@ #include #include +#include + using namespace musik::core; using namespace musik::core::audio; using namespace musik::core::library; @@ -56,9 +56,9 @@ void TransportWindow::Show() { } void TransportWindow::ProcessMessage(IMessage &message) { - int type = message.Type(); - - if (type == REFRESH_TRANSPORT_READOUT) { + int type = message.Type(); + + if (type == REFRESH_TRANSPORT_READOUT) { this->Update(); DEBOUNCE_REFRESH(REFRESH_INTERVAL_MS) } @@ -102,19 +102,19 @@ void TransportWindow::Update() { WINDOW *c = this->GetContent(); bool paused = (transport->GetPlaybackState() == Transport::PlaybackPaused); - - int64 gb = COLOR_PAIR(this->focused - ? BOX_COLOR_RED_ON_BLACK + + int64 gb = COLOR_PAIR(this->focused + ? BOX_COLOR_RED_ON_BLACK : BOX_COLOR_GREEN_ON_BLACK); /* playing SONG TITLE from ALBUM NAME */ std::string duration = "0"; - if (transport->GetPlaybackState() == Transport::PlaybackStopped) { + if (transport->GetPlaybackState() == Transport::PlaybackStopped) { wattron(c, gb); wprintw(c, "playback is stopped"); wattroff(c, gb); - } + } else { std::string title, album; @@ -144,9 +144,9 @@ void TransportWindow::Update() { /* volume slider */ wprintw(c, "\n"); - + int volumePercent = (size_t) round(this->transport->Volume() * 100.0f) - 1; - int thumbOffset = min(9, (volumePercent * 10) / 100); + int thumbOffset = std::min(9, (volumePercent * 10) / 100); std::string volume = "vol "; @@ -190,7 +190,7 @@ void TransportWindow::Update() { if (secondsTotal) { size_t progress = (secondsCurrent * 100) / secondsTotal; - thumbOffset = min(timerWidth - 1, (progress * timerWidth) / 100); + thumbOffset = std::min(timerWidth - 1, (progress * timerWidth) / 100); } std::string timerTrack = ""; @@ -202,9 +202,9 @@ void TransportWindow::Update() { wprintw(c, currentTime.c_str()); wattroff(c, timerAttrs); - wprintw(c, " %s %s", - timerTrack.c_str(), + wprintw(c, " %s %s", + timerTrack.c_str(), totalTime.c_str()); this->Repaint(); -} \ No newline at end of file +} diff --git a/src/musikbox/app/window/TransportWindow.h b/src/musikbox/app/window/TransportWindow.h index d5b2e557b..5d5e3cd6d 100755 --- a/src/musikbox/app/window/TransportWindow.h +++ b/src/musikbox/app/window/TransportWindow.h @@ -10,10 +10,14 @@ namespace musik { namespace box { - class TransportWindow : public cursespp::Window, public sigslot::has_slots<> { + class TransportWindow : + public cursespp::Window, + public std::enable_shared_from_this, + public sigslot::has_slots<> + { public: TransportWindow( - musik::core::LibraryPtr library, + musik::core::LibraryPtr library, musik::core::audio::Transport& transport); ~TransportWindow(); diff --git a/src/musikbox/cursespp/Colors.cpp b/src/musikbox/cursespp/Colors.cpp index 58e7b3df6..f3935fac4 100755 --- a/src/musikbox/cursespp/Colors.cpp +++ b/src/musikbox/cursespp/Colors.cpp @@ -1,5 +1,3 @@ -#pragma once - #include #include "Colors.h" @@ -20,4 +18,4 @@ void Colors::Init() { init_pair(BOX_COLOR_RED_ON_GREY, COLOR_RED, COLOR_WHITE); init_pair(BOX_COLOR_GREEN_ON_BLACK, COLOR_GREEN, COLOR_BLACK); init_pair(BOX_COLOR_BLACK_ON_BLACK, COLOR_BLACK, COLOR_BLACK); -} \ No newline at end of file +} diff --git a/src/musikbox/cursespp/IDisplayable.h b/src/musikbox/cursespp/IDisplayable.h index edcb83b08..c8c92a1b4 100755 --- a/src/musikbox/cursespp/IDisplayable.h +++ b/src/musikbox/cursespp/IDisplayable.h @@ -3,9 +3,8 @@ namespace cursespp { class IDisplayable { public: - virtual ~IDisplayable() = 0 { } + virtual ~IDisplayable() { } virtual void Show() = 0; virtual void Hide() = 0; }; } - diff --git a/src/musikbox/cursespp/IInput.h b/src/musikbox/cursespp/IInput.h index 7b1ef0f9f..5d1d98a51 100755 --- a/src/musikbox/cursespp/IInput.h +++ b/src/musikbox/cursespp/IInput.h @@ -5,7 +5,7 @@ namespace cursespp { class IInput { public: - virtual ~IInput() = 0 { } + virtual ~IInput() { } virtual void WriteChar(int64 ch) = 0; }; -} \ No newline at end of file +} diff --git a/src/musikbox/cursespp/IKeyHandler.h b/src/musikbox/cursespp/IKeyHandler.h index e60f83123..1e3a166b9 100755 --- a/src/musikbox/cursespp/IKeyHandler.h +++ b/src/musikbox/cursespp/IKeyHandler.h @@ -5,7 +5,7 @@ namespace cursespp { class IKeyHandler { public: - virtual ~IKeyHandler() = 0 { } + virtual ~IKeyHandler() { } virtual bool KeyPress(int64 ch) = 0; }; -} \ No newline at end of file +} diff --git a/src/musikbox/cursespp/ILayout.h b/src/musikbox/cursespp/ILayout.h index 9e3a592c7..0858af4a2 100755 --- a/src/musikbox/cursespp/ILayout.h +++ b/src/musikbox/cursespp/ILayout.h @@ -10,7 +10,7 @@ namespace cursespp { class ILayout : public IWindowGroup, public IKeyHandler, public IOrderable, public IDisplayable { public: - virtual ~ILayout() = 0 { } + virtual ~ILayout() { } virtual IWindowPtr FocusNext() = 0; virtual IWindowPtr FocusPrev() = 0; virtual IWindowPtr GetFocus() = 0; @@ -20,4 +20,4 @@ namespace cursespp { }; typedef std::shared_ptr ILayoutPtr; -} \ No newline at end of file +} diff --git a/src/musikbox/cursespp/ILayoutStack.h b/src/musikbox/cursespp/ILayoutStack.h index f8898d03d..d3c06f3e4 100755 --- a/src/musikbox/cursespp/ILayoutStack.h +++ b/src/musikbox/cursespp/ILayoutStack.h @@ -6,10 +6,10 @@ namespace cursespp { class ILayoutStack { public: - virtual ~ILayoutStack() = 0 { } + virtual ~ILayoutStack() { } virtual bool Push(ILayoutPtr layout) = 0; virtual bool Pop(ILayoutPtr layout) = 0; virtual bool BringToTop(ILayoutPtr layout) = 0; virtual bool SendToBottom(ILayoutPtr layout) = 0; }; -} \ No newline at end of file +} diff --git a/src/musikbox/cursespp/IMessage.h b/src/musikbox/cursespp/IMessage.h index 4c135e7a3..de080d45a 100755 --- a/src/musikbox/cursespp/IMessage.h +++ b/src/musikbox/cursespp/IMessage.h @@ -9,7 +9,7 @@ namespace cursespp { class IMessage { public: - virtual ~IMessage() = 0 { } + virtual ~IMessage() { } virtual IMessageTarget* Target() = 0; virtual int Type() = 0; virtual int64 UserData1() = 0; @@ -17,4 +17,4 @@ namespace cursespp { }; typedef std::shared_ptr IMessagePtr; -} \ No newline at end of file +} diff --git a/src/musikbox/cursespp/IMessageTarget.h b/src/musikbox/cursespp/IMessageTarget.h index 4f2a168f4..0ec11ca8b 100755 --- a/src/musikbox/cursespp/IMessageTarget.h +++ b/src/musikbox/cursespp/IMessageTarget.h @@ -5,7 +5,8 @@ namespace cursespp { class IMessageTarget { public: + virtual ~IMessageTarget() { } virtual bool IsAcceptingMessages() = 0; virtual void ProcessMessage(IMessage &message) = 0; }; -} \ No newline at end of file +} diff --git a/src/musikbox/cursespp/IOrderable.h b/src/musikbox/cursespp/IOrderable.h index 4d72f9c61..cb3543094 100755 --- a/src/musikbox/cursespp/IOrderable.h +++ b/src/musikbox/cursespp/IOrderable.h @@ -3,8 +3,8 @@ namespace cursespp { class IOrderable { public: - virtual ~IOrderable() = 0 { } + virtual ~IOrderable() { } virtual void BringToTop() = 0; virtual void SendToBottom() = 0; }; -} \ No newline at end of file +} diff --git a/src/musikbox/cursespp/IScrollAdapter.h b/src/musikbox/cursespp/IScrollAdapter.h index e63dff61d..e154a672b 100755 --- a/src/musikbox/cursespp/IScrollAdapter.h +++ b/src/musikbox/cursespp/IScrollAdapter.h @@ -5,7 +5,7 @@ namespace cursespp { class IScrollAdapter { public: - virtual ~IScrollAdapter() = 0 { } + virtual ~IScrollAdapter() { } struct ScrollPosition { ScrollPosition() { @@ -25,7 +25,7 @@ namespace cursespp { class IEntry { public: - virtual ~IEntry() = 0 { } + virtual ~IEntry() { } virtual size_t GetLineCount() = 0; virtual std::string GetLine(size_t line) = 0; virtual std::string GetValue() = 0; @@ -42,4 +42,3 @@ namespace cursespp { virtual void DrawPage(WINDOW* window, size_t index, ScrollPosition *result = NULL) = 0; }; } - diff --git a/src/musikbox/cursespp/IScrollable.h b/src/musikbox/cursespp/IScrollable.h index e7e8e0e5d..7f040b1f3 100755 --- a/src/musikbox/cursespp/IScrollable.h +++ b/src/musikbox/cursespp/IScrollable.h @@ -3,7 +3,7 @@ namespace cursespp { class IScrollable { public: - virtual ~IScrollable() = 0 { } + virtual ~IScrollable() { } virtual void ScrollToTop() = 0; virtual void ScrollToBottom() = 0; virtual void ScrollUp(int delta = 1) = 0; @@ -11,4 +11,4 @@ namespace cursespp { virtual void PageUp() = 0; virtual void PageDown() = 0; }; -} \ No newline at end of file +} diff --git a/src/musikbox/cursespp/IWindow.h b/src/musikbox/cursespp/IWindow.h index b3180aa22..22b725314 100755 --- a/src/musikbox/cursespp/IWindow.h +++ b/src/musikbox/cursespp/IWindow.h @@ -10,7 +10,7 @@ namespace cursespp { class IWindow : public IOrderable, public IDisplayable, public IMessageTarget { public: - virtual ~IWindow() = 0 { } + virtual ~IWindow() { } virtual void Repaint() = 0; virtual void SetParent(IWindow* parent) = 0; virtual void Show() = 0; @@ -35,4 +35,4 @@ namespace cursespp { }; typedef std::shared_ptr IWindowPtr; -} \ No newline at end of file +} diff --git a/src/musikbox/cursespp/IWindowGroup.h b/src/musikbox/cursespp/IWindowGroup.h index bc763a3d4..70eb56678 100755 --- a/src/musikbox/cursespp/IWindowGroup.h +++ b/src/musikbox/cursespp/IWindowGroup.h @@ -5,10 +5,10 @@ namespace cursespp { class IWindowGroup { public: - virtual ~IWindowGroup() = 0 { } + virtual ~IWindowGroup() { } virtual bool AddWindow(IWindowPtr window) = 0; virtual bool RemoveWindow(IWindowPtr window) = 0; virtual size_t GetWindowCount() = 0; virtual IWindowPtr GetWindowAt(size_t position) = 0; }; -} \ No newline at end of file +} diff --git a/src/musikbox/cursespp/LayoutBase.cpp b/src/musikbox/cursespp/LayoutBase.cpp index a02ffb73f..7060ac9d3 100755 --- a/src/musikbox/cursespp/LayoutBase.cpp +++ b/src/musikbox/cursespp/LayoutBase.cpp @@ -7,7 +7,7 @@ using namespace cursespp; template static int find(std::vector& haystack, T& needle) { int i = 0; - std::vector::iterator it = haystack.begin(); + typename std::vector::iterator it = haystack.begin(); for (; it != haystack.end(); it++, i++) { if ((*it) == needle) { return i; @@ -42,7 +42,7 @@ static inline IWindowPtr adjustFocus(IWindowPtr oldFocus, IWindowPtr newFocus) { return newFocus; } -LayoutBase::LayoutBase(IWindow* parent) +LayoutBase::LayoutBase(IWindow* parent) : Window(parent) { this->focused = -1; this->layoutStack = 0; @@ -229,4 +229,4 @@ ILayoutStack* LayoutBase::GetLayoutStack() { void LayoutBase::SetLayoutStack(ILayoutStack* stack) { this->layoutStack = stack; -} \ No newline at end of file +} diff --git a/src/musikbox/cursespp/LayoutBase.h b/src/musikbox/cursespp/LayoutBase.h index 7fbc73a12..38b007e15 100755 --- a/src/musikbox/cursespp/LayoutBase.h +++ b/src/musikbox/cursespp/LayoutBase.h @@ -50,4 +50,4 @@ namespace cursespp { std::vector focusable; int focused; }; -} \ No newline at end of file +} diff --git a/src/musikbox/cursespp/LayoutStack.cpp b/src/musikbox/cursespp/LayoutStack.cpp index e2eb9a8fa..6cd235e50 100755 --- a/src/musikbox/cursespp/LayoutStack.cpp +++ b/src/musikbox/cursespp/LayoutStack.cpp @@ -1,5 +1,3 @@ -#pragma once - #include #include "LayoutStack.h" @@ -40,19 +38,19 @@ static inline bool erase(std::deque& group, ILayoutPtr ptr) { } bool LayoutStack::AddWindow(IWindowPtr window) { - throw std::exception("AddWindow() not supported in LayoutStack. Use Push()"); + throw std::runtime_error("AddWindow() not supported in LayoutStack. Use Push()"); } bool LayoutStack::RemoveWindow(IWindowPtr window) { - throw std::exception("RemoveWindow() not supported in LayoutStack. Use Push()"); + throw std::runtime_error("RemoveWindow() not supported in LayoutStack. Use Push()"); } size_t LayoutStack::GetWindowCount() { - throw std::exception("GetWindowCount() not supported in LayoutStack."); + throw std::runtime_error("GetWindowCount() not supported in LayoutStack."); } IWindowPtr LayoutStack::GetWindowAt(size_t position) { - throw std::exception("GetWindowAt() not supported in LayoutStack."); + throw std::runtime_error("GetWindowAt() not supported in LayoutStack."); } ILayoutStack* LayoutStack::GetLayoutStack() { diff --git a/src/musikbox/cursespp/ListWindow.cpp b/src/musikbox/cursespp/ListWindow.cpp index fb39b6b84..3ea1c341c 100755 --- a/src/musikbox/cursespp/ListWindow.cpp +++ b/src/musikbox/cursespp/ListWindow.cpp @@ -1,4 +1,5 @@ #include +#include #include "ListWindow.h" using namespace cursespp; @@ -7,7 +8,7 @@ typedef IScrollAdapter::ScrollPosition ScrollPos; size_t ListWindow::NO_SELECTION = (size_t) -1; -ListWindow::ListWindow(IWindow *parent) +ListWindow::ListWindow(IWindow *parent) : ScrollableWindow(parent) { this->selectedIndex = (size_t) -1; } @@ -24,15 +25,15 @@ void ListWindow::ScrollToTop() { void ListWindow::ScrollToBottom() { IScrollAdapter& adapter = this->GetScrollAdapter(); - this->SetSelectedIndex(max(0, adapter.GetEntryCount() - 1)); + this->SetSelectedIndex(std::max(0UL, adapter.GetEntryCount() - 1)); adapter.DrawPage(this->GetContent(), selectedIndex, &scrollPosition); this->Repaint(); } void ListWindow::Focus() { GetScrollAdapter().DrawPage( - this->GetContent(), - this->scrollPosition.firstVisibleEntryIndex, + this->GetContent(), + this->scrollPosition.firstVisibleEntryIndex, &this->scrollPosition); } @@ -46,13 +47,13 @@ void ListWindow::ScrollUp(int delta) { int minIndex = 0; int newIndex = this->selectedIndex - delta; - newIndex = max(newIndex, minIndex); + newIndex = std::max(newIndex, minIndex); if (newIndex < (int) first + 1) { drawIndex = newIndex - 1; } - drawIndex = max(0, drawIndex); + drawIndex = std::max(0, drawIndex); this->SetSelectedIndex(newIndex); @@ -75,7 +76,7 @@ void ListWindow::ScrollDown(int delta) { size_t maxIndex = adapter.GetEntryCount() - 1; size_t newIndex = this->selectedIndex + delta; - newIndex = min(newIndex, maxIndex); + newIndex = std::min(newIndex, maxIndex); if (newIndex >= last - 1) { drawIndex = drawIndex + delta; @@ -92,7 +93,7 @@ void ListWindow::PageUp() { IScrollAdapter &adapter = this->GetScrollAdapter(); ScrollPos spos = this->GetScrollPosition(); int target = (int) this->GetPreviousPageEntryIndex(); - + /* if the target position is zero, let it be so the user can see the top of the list. otherwise, scroll down by one to give indication there is more to see. */ @@ -112,7 +113,7 @@ void ListWindow::PageDown() { ScrollPos spos = this->GetScrollPosition(); size_t lastVisible = spos.firstVisibleEntryIndex + spos.visibleEntryCount - 1; - this->SetSelectedIndex(min(adapter.GetEntryCount() - 1, lastVisible + 1)); + this->SetSelectedIndex(std::min(adapter.GetEntryCount() - 1, lastVisible + 1)); adapter.DrawPage(this->GetContent(), lastVisible, &this->scrollPosition); this->Repaint(); @@ -160,4 +161,4 @@ void ListWindow::OnAdapterChanged() { IScrollAdapter::ScrollPosition& ListWindow::GetScrollPosition() { return this->scrollPosition; -} \ No newline at end of file +} diff --git a/src/musikbox/cursespp/MessageQueue.cpp b/src/musikbox/cursespp/MessageQueue.cpp index 643f1e149..653e63ab2 100755 --- a/src/musikbox/cursespp/MessageQueue.cpp +++ b/src/musikbox/cursespp/MessageQueue.cpp @@ -1,4 +1,5 @@ #include +#include #include "MessageQueue.h" using namespace boost::chrono; @@ -81,7 +82,7 @@ void MessageQueue::Remove(IMessageTarget *target, int type) { void MessageQueue::Post(IMessagePtr message, int64 delayMs) { boost::recursive_mutex::scoped_lock lock(this->queueMutex); - delayMs = max(0, delayMs); + delayMs = std::max(0LL, delayMs); milliseconds now = duration_cast( system_clock::now().time_since_epoch()); diff --git a/src/musikbox/cursespp/MultiLineEntry.cpp b/src/musikbox/cursespp/MultiLineEntry.cpp index fc0dfa525..66d439a83 100755 --- a/src/musikbox/cursespp/MultiLineEntry.cpp +++ b/src/musikbox/cursespp/MultiLineEntry.cpp @@ -1,6 +1,8 @@ #include -#include "MultiLineEntry.h" +#include +#include #include +#include "MultiLineEntry.h" using namespace cursespp; @@ -12,7 +14,7 @@ MultiLineEntry::MultiLineEntry(const std::string& value, int64 attrs) { } size_t MultiLineEntry::GetLineCount() { - return max(1, this->lines.size()); + return std::max(1UL, this->lines.size()); } std::string MultiLineEntry::GetLine(size_t n) { diff --git a/src/musikbox/cursespp/Screen.cpp b/src/musikbox/cursespp/Screen.cpp index ffaaa809e..7dc42f5ae 100755 --- a/src/musikbox/cursespp/Screen.cpp +++ b/src/musikbox/cursespp/Screen.cpp @@ -1,5 +1,3 @@ -#pragma once - #include #include "Screen.h" diff --git a/src/musikbox/cursespp/ScrollableWindow.cpp b/src/musikbox/cursespp/ScrollableWindow.cpp index 1fd6a43b3..57aea1ab6 100755 --- a/src/musikbox/cursespp/ScrollableWindow.cpp +++ b/src/musikbox/cursespp/ScrollableWindow.cpp @@ -1,6 +1,6 @@ -#pragma once - #include +#include + #include "ScrollableWindow.h" #include "Screen.h" #include "Colors.h" @@ -52,8 +52,8 @@ void ScrollableWindow::OnAdapterChanged() { ScrollPos &pos = this->GetScrollPosition(); adapter->DrawPage( - this->GetContent(), - pos.firstVisibleEntryIndex, + this->GetContent(), + pos.firstVisibleEntryIndex, &pos); this->Repaint(); @@ -72,7 +72,7 @@ void ScrollableWindow::ScrollToTop() { void ScrollableWindow::ScrollToBottom() { GetScrollAdapter().DrawPage( - this->GetContent(), + this->GetContent(), GetScrollAdapter().GetEntryCount(), &this->GetScrollPosition()); @@ -122,7 +122,7 @@ size_t ScrollableWindow::GetPreviousPageEntryIndex() { remaining -= count; } - return max(0, i); + return std::max(0, i); } void ScrollableWindow::PageUp() { @@ -144,4 +144,4 @@ bool ScrollableWindow::IsLastItemVisible() { size_t firstVisible = pos.firstVisibleEntryIndex; size_t lastVisible = firstVisible + pos.visibleEntryCount; return lastIndex >= firstVisible && lastIndex <= lastVisible; -} \ No newline at end of file +} diff --git a/src/musikbox/cursespp/Window.cpp b/src/musikbox/cursespp/Window.cpp index 4b78de719..e280fcf43 100755 --- a/src/musikbox/cursespp/Window.cpp +++ b/src/musikbox/cursespp/Window.cpp @@ -1,5 +1,3 @@ -#pragma once - #include #include "Window.h" #include "IWindowGroup.h" @@ -45,7 +43,7 @@ int Window::GetId() const { } void Window::ProcessMessage(IMessage &message) { - + } bool Window::IsAcceptingMessages() { @@ -79,9 +77,9 @@ void Window::SendToBottom() { void Window::PostMessage(int messageType, int64 user1, int64 user2, int64 delay) { MessageQueue::Instance().Post( Message::Create( - this, - messageType, - user1, + this, + messageType, + user1, user2), delay); } @@ -215,14 +213,14 @@ void Window::Create() { this->frame = (this->parent == NULL) ? newwin( - this->height, - this->width, - this->y, + this->height, + this->width, + this->y, this->x) : newwin( - this->height, - this->width, - this->parent->GetY() + this->y, + this->height, + this->width, + this->parent->GetY() + this->y, this->parent->GetX() + this->x); this->framePanel = new_panel(this->frame); diff --git a/src/musikbox/cursespp/Window.h b/src/musikbox/cursespp/Window.h index 424673a61..75aecfdb6 100755 --- a/src/musikbox/cursespp/Window.h +++ b/src/musikbox/cursespp/Window.h @@ -71,4 +71,4 @@ namespace cursespp { int64 contentColor, frameColor; int width, height, x, y; }; -} \ No newline at end of file +} diff --git a/src/musikbox/cursespp/WindowLayout.cpp b/src/musikbox/cursespp/WindowLayout.cpp index c5dd6a437..c31124fbf 100755 --- a/src/musikbox/cursespp/WindowLayout.cpp +++ b/src/musikbox/cursespp/WindowLayout.cpp @@ -1,5 +1,3 @@ -#pragma once - #include #include "WindowLayout.h" #include "LayoutStack.h" @@ -15,19 +13,19 @@ WindowLayout::~WindowLayout() { } bool WindowLayout::AddWindow(IWindowPtr window) { - throw std::exception("AddWindow() not supported in LayoutStack. Use Push()"); + throw std::runtime_error("AddWindow() not supported in LayoutStack. Use Push()"); } bool WindowLayout::RemoveWindow(IWindowPtr window) { - throw std::exception("RemoveWindow() not supported in LayoutStack. Use Push()"); + throw std::runtime_error("RemoveWindow() not supported in LayoutStack. Use Push()"); } size_t WindowLayout::GetWindowCount() { - throw std::exception("GetWindowCount() not supported in LayoutStack."); + throw std::runtime_error("GetWindowCount() not supported in LayoutStack."); } IWindowPtr WindowLayout::GetWindowAt(size_t position) { - throw std::exception("GetWindowAt() not supported in LayoutStack."); + throw std::runtime_error("GetWindowAt() not supported in LayoutStack."); } void WindowLayout::Show() { @@ -71,4 +69,4 @@ ILayoutStack* WindowLayout::GetLayoutStack() { void WindowLayout::SetLayoutStack(ILayoutStack* stack) { this->stack = stack; -} \ No newline at end of file +}