From b6a912e507052193a7e9cdbf4665a92866476703 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 14 Aug 2008 17:43:46 +0200 Subject: [PATCH] lighter deletion + playlist status added --- src/helpers.cpp | 53 +++++++++++++++++++++++++++-- src/helpers.h | 1 + src/menu.cpp | 64 ++++++++++++++++++++++++----------- src/misc.cpp | 9 +++-- src/misc.h | 3 +- src/ncmpcpp.cpp | 77 ++++++++++++++++++++++++++---------------- src/status_checker.cpp | 10 ++++-- 7 files changed, 158 insertions(+), 59 deletions(-) diff --git a/src/helpers.cpp b/src/helpers.cpp index 070bd0a6..875b503a 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -82,6 +82,54 @@ void WindowTitle(const string &status) printf("\033]0;%s\7",status.c_str()); } +string TotalPlaylistLength() +{ + const int MINUTE = 60; + const int HOUR = 60*MINUTE; + const int DAY = 24*HOUR; + const int YEAR = 365*DAY; + string result; + int length = 0; + for (vector::const_iterator it = vPlaylist.begin(); it != vPlaylist.end(); it++) + length += (*it)->GetTotalLength(); + + int years = length/YEAR; + if (years) + { + result += IntoStr(years) + (years == 1 ? " year" : " years"); + length -= years*YEAR; + if (length) + result += ", "; + } + int days = length/DAY; + if (days) + { + result += IntoStr(days) + (days == 1 ? " day" : " days"); + length -= days*DAY; + if (length) + result += ", "; + } + int hours = length/HOUR; + if (hours) + { + result += IntoStr(hours) + (hours == 1 ? " hour" : " hours"); + length -= hours*HOUR; + if (length) + result += ", "; + } + int minutes = length/MINUTE; + if (minutes) + { + result += IntoStr(minutes) + (minutes == 1 ? " minute" : " minutes"); + length -= minutes*MINUTE; + if (length) + result += ", "; + } + if (length) + result += IntoStr(length) + (length == 1 ? " second" : " seconds"); + return result; +} + string DisplaySong(const Song &s, const string &song_template) { string result; @@ -506,6 +554,7 @@ bool GetSongInfo(Song &s) void GetDirectory(string dir) { + int highlightme = -1; browsed_dir_scroll_begin = 0; if (browsed_dir != dir) mBrowser->Reset(); @@ -545,8 +594,7 @@ void GetDirectory(string dir) vBrowser.push_back(directory); mBrowser->AddOption("[" + directory.name + "]"); if (directory.name == browsed_subdir) - mBrowser->Highlight(mBrowser->MaxChoice()); - redraw_me = 1; + highlightme = mBrowser->MaxChoice(); break; } case MPD_DATA_TYPE_SONG: @@ -571,6 +619,7 @@ void GetDirectory(string dir) } } } + mBrowser->Highlight(highlightme); mpd_data_free(browser); browsed_subdir.clear(); diff --git a/src/helpers.h b/src/helpers.h index f89b414e..ed7d81a2 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -40,6 +40,7 @@ extern ncmpcpp_config Config; bool SortSongsByTrack(const Song &, const Song &); bool CaseInsensitiveComparison(string, string); void WindowTitle(const string &); +string TotalPlaylistLength(); string DisplaySong(const Song &, const string & = Config.song_list_format); void ShowMessage(const string &, int = Config.message_delay_time); void GetDirectory(string); diff --git a/src/menu.cpp b/src/menu.cpp index 05ec8af9..3df8bb8f 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -214,29 +214,26 @@ void Menu::DeleteOption(int no) if (itsHighlight > itsOptions.size()-1) itsHighlight = itsOptions.size()-1; + idlok(itsWindow, 1); + scrollok(itsWindow, 1); int MaxBeginning = itsOptions.size() < itsHeight ? 0 : itsOptions.size()-itsHeight; if (itsBeginning > MaxBeginning) { itsBeginning = MaxBeginning; - NeedsRedraw.push_back(itsHighlight); - Refresh(); - redraw_screen(); + wmove(itsWindow, no-1-itsBeginning, 0); + wdeleteln(itsWindow); + wscrl(itsWindow, -1); + NeedsRedraw.push_back(itsBeginning); } else { - vector