start option numeration from 0 instead of 1 (1 was really stupid idea)

This commit is contained in:
unK
2008-09-05 08:33:18 +02:00
parent 9c3bd9dfb7
commit 5e7e0931a6
5 changed files with 84 additions and 113 deletions

View File

@@ -74,7 +74,7 @@ void UpdateItemList(Menu<Item> *menu)
break; break;
} }
} }
menu->BoldOption(i+1, bold); menu->BoldOption(i, bold);
bold = 0; bold = 0;
} }
} }
@@ -94,7 +94,7 @@ void UpdateSongList(Menu<Song> *menu)
break; break;
} }
} }
menu->BoldOption(i+1, bold); menu->BoldOption(i, bold);
bold = 0; bold = 0;
} }
menu->Refresh(); menu->Refresh();
@@ -102,7 +102,7 @@ void UpdateSongList(Menu<Song> *menu)
void UpdateFoundList(const SongList &v, Menu<string> *menu) void UpdateFoundList(const SongList &v, Menu<string> *menu)
{ {
int i = search_engine_static_option+1; int i = search_engine_static_option;
bool bold = 0; bool bold = 0;
for (SongList::const_iterator it = v.begin(); it != v.end(); it++, i++) for (SongList::const_iterator it = v.begin(); it != v.end(); it++, i++)
{ {
@@ -120,18 +120,6 @@ void UpdateFoundList(const SongList &v, Menu<string> *menu)
menu->Refresh(); menu->Refresh();
} }
void DeleteSong(int id)
{
Mpd->QueueDeleteSong(id);
mPlaylist->DeleteOption(id+1);
}
void PlaylistDeleteSong(const string &path, int id)
{
Mpd->QueueDeleteFromPlaylist(path, id);
mPlaylistEditor->DeleteOption(id+1);
}
string DisplayKeys(int *key, int size) string DisplayKeys(int *key, int size)
{ {
bool backspace = 1; bool backspace = 1;
@@ -973,7 +961,7 @@ void GetDirectory(string dir, string subdir)
case itDirectory: case itDirectory:
{ {
if (it->name == subdir) if (it->name == subdir)
highlightme = mBrowser->Size()+1; highlightme = mBrowser->Size();
mBrowser->AddOption(*it); mBrowser->AddOption(*it);
break; break;
} }

View File

@@ -34,9 +34,6 @@ void UpdateItemList(Menu<Item> *);
void UpdateSongList(Menu<Song> *); void UpdateSongList(Menu<Song> *);
void UpdateFoundList(const SongList &, Menu<string> *); void UpdateFoundList(const SongList &, Menu<string> *);
void DeleteSong(int);
void PlaylistDeleteSong(const string &, int);
string DisplayKeys(int *, int = 2); string DisplayKeys(int *, int = 2);
bool Keypressed(int, const int *); bool Keypressed(int, const int *);
bool SortSongsByTrack(Song *, Song *); bool SortSongsByTrack(Song *, Song *);

View File

@@ -86,10 +86,9 @@ class Menu : public Window
virtual void Highlighting(bool hl) { itsHighlightEnabled = hl; NeedsRedraw.push_back(itsHighlight); Refresh(); } virtual void Highlighting(bool hl) { itsHighlightEnabled = hl; NeedsRedraw.push_back(itsHighlight); Refresh(); }
int GetRealChoice() const; int GetRealChoice() const;
virtual int GetChoice() const { return itsHighlight+1; }
virtual int GetChoice() const { return itsHighlight; }
virtual int Size() const { return itsOptions.size(); } virtual int Size() const { return itsOptions.size(); }
int MaxRealChoice() const { return itsOptions.size()-itsStaticsNumber; }
bool Empty() { return itsOptions.empty(); } bool Empty() { return itsOptions.empty(); }
virtual bool IsStatic(int); virtual bool IsStatic(int);
@@ -250,7 +249,6 @@ void Menu<T>::AddSeparator()
template <class T> template <class T>
void Menu<T>::UpdateOption(int index, const T &item, Location location, bool separator) void Menu<T>::UpdateOption(int index, const T &item, Location location, bool separator)
{ {
index--;
try try
{ {
itsOptions.at(index)->location = location; itsOptions.at(index)->location = location;
@@ -266,7 +264,6 @@ void Menu<T>::UpdateOption(int index, const T &item, Location location, bool sep
template <class T> template <class T>
void Menu<T>::BoldOption(int index, bool bold) void Menu<T>::BoldOption(int index, bool bold)
{ {
index--;
try try
{ {
itsOptions.at(index)->is_bold = bold; itsOptions.at(index)->is_bold = bold;
@@ -280,7 +277,6 @@ void Menu<T>::BoldOption(int index, bool bold)
template <class T> template <class T>
void Menu<T>::MakeStatic(int index, bool stat) void Menu<T>::MakeStatic(int index, bool stat)
{ {
index--;
try try
{ {
if (stat && !itsOptions.at(index)->is_static) if (stat && !itsOptions.at(index)->is_static)
@@ -312,7 +308,7 @@ string Menu<T>::GetOption(int i) const
{ {
try try
{ {
return DisplayOption(itsOptions.at(i-1)->item); return DisplayOption(itsOptions.at(i)->item);
} }
catch (std::out_of_range) catch (std::out_of_range)
{ {
@@ -323,7 +319,6 @@ string Menu<T>::GetOption(int i) const
template <class T> template <class T>
void Menu<T>::DeleteOption(int no) void Menu<T>::DeleteOption(int no)
{ {
no--;
try try
{ {
if (itsOptions.at(no)->is_static) if (itsOptions.at(no)->is_static)
@@ -403,7 +398,7 @@ void Menu<T>::Refresh(bool redraw_whole_window)
itsBeginning = MaxBeginning; itsBeginning = MaxBeginning;
if (itsHighlight >= itsOptions.size()-1) if (itsHighlight >= itsOptions.size()-1)
Highlight(itsOptions.size()); Highlight(itsOptions.size()-1);
while (itsHighlight-itsBeginning > itsHeight-1) while (itsHighlight-itsBeginning > itsHeight-1)
itsBeginning++; itsBeginning++;
@@ -639,8 +634,6 @@ void Menu<T>::Go(Where where)
template <class T> template <class T>
void Menu<T>::Highlight(int which) void Menu<T>::Highlight(int which)
{ {
which--;
int old_highlight = itsHighlight; int old_highlight = itsHighlight;
int old_beginning = itsBeginning; int old_beginning = itsBeginning;
@@ -704,7 +697,6 @@ void Menu<T>::Clear(bool clear_screen)
template <class T> template <class T>
void Menu<T>::Select(int option, bool selected) void Menu<T>::Select(int option, bool selected)
{ {
option--;
try try
{ {
if (itsOptions.at(option)->selected != selected) if (itsOptions.at(option)->selected != selected)
@@ -719,7 +711,6 @@ void Menu<T>::Select(int option, bool selected)
template <class T> template <class T>
bool Menu<T>::Selected(int option) bool Menu<T>::Selected(int option)
{ {
option--;
try try
{ {
return itsOptions.at(option)->selected; return itsOptions.at(option)->selected;
@@ -748,7 +739,7 @@ bool Menu<T>::IsAnySelected()
template <class T> template <class T>
void Menu<T>::GetSelectedList(vector<int> &v) void Menu<T>::GetSelectedList(vector<int> &v)
{ {
int i = 1; int i = 0;
for (T_const_iterator it = itsOptions.begin(); it != itsOptions.end(); it++, i++) for (T_const_iterator it = itsOptions.begin(); it != itsOptions.end(); it++, i++)
if ((*it)->selected) if ((*it)->selected)
v.push_back(i); v.push_back(i);
@@ -762,7 +753,7 @@ int Menu<T>::GetRealChoice() const
for (int i = 0; i < itsHighlight; it++, i++) for (int i = 0; i < itsHighlight; it++, i++)
if (!(*it)->is_static) real_choice++; if (!(*it)->is_static) real_choice++;
return real_choice+1; return real_choice;
} }
template <class T> template <class T>
@@ -770,7 +761,7 @@ bool Menu<T>::IsStatic(int option)
{ {
try try
{ {
return itsOptions.at(option-1)->is_static; return itsOptions.at(option)->is_static;
} }
catch (std::out_of_range) catch (std::out_of_range)
{ {

View File

@@ -202,6 +202,8 @@ int main(int argc, char *argv[])
mTagEditor = new Menu<string>(0, main_start_y, COLS, main_height, "", Config.main_color, brNone); mTagEditor = new Menu<string>(0, main_start_y, COLS, main_height, "", Config.main_color, brNone);
mSearcher = static_cast<Menu<string> *>(mTagEditor->Clone()); mSearcher = static_cast<Menu<string> *>(mTagEditor->Clone());
mSearcher->SetSelectPrefix(Config.selected_item_prefix);
mSearcher->SetSelectSuffix(Config.selected_item_suffix);
int lib_artist_width = COLS/3-1; int lib_artist_width = COLS/3-1;
int lib_albums_width = COLS/3; int lib_albums_width = COLS/3;
@@ -789,14 +791,14 @@ int main(int argc, char *argv[])
case csPlaylist: case csPlaylist:
{ {
if (!mPlaylist->Empty()) if (!mPlaylist->Empty())
Mpd->PlayID(mPlaylist->at(mPlaylist->GetChoice()-1).GetID()); Mpd->PlayID(mPlaylist->at(mPlaylist->GetChoice()).GetID());
break; break;
} }
case csBrowser: case csBrowser:
{ {
GO_TO_PARENT_DIR: GO_TO_PARENT_DIR:
const Item &item = mBrowser->at(mBrowser->GetChoice()-1); const Item &item = mBrowser->at(mBrowser->GetChoice());
switch (item.type) switch (item.type)
{ {
case itDirectory: case itDirectory:
@@ -842,7 +844,7 @@ int main(int argc, char *argv[])
case csTagEditor: case csTagEditor:
{ {
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
int id = mTagEditor->GetRealChoice(); int id = mTagEditor->GetRealChoice()+1;
int option = mTagEditor->GetChoice(); int option = mTagEditor->GetChoice();
LOCK_STATUSBAR; LOCK_STATUSBAR;
Song &s = edited_song; Song &s = edited_song;
@@ -940,7 +942,7 @@ int main(int argc, char *argv[])
Mpd->UpdateDirectory(s.GetDirectory()); Mpd->UpdateDirectory(s.GetDirectory());
if (prev_screen == csSearcher) if (prev_screen == csSearcher)
{ {
*vSearched[mSearcher->GetRealChoice()-2] = s; *vSearched[mSearcher->GetRealChoice()-1] = s;
mSearcher->UpdateOption(mSearcher->GetChoice(), DisplaySong(s)); mSearcher->UpdateOption(mSearcher->GetChoice(), DisplaySong(s));
} }
} }
@@ -974,12 +976,11 @@ int main(int argc, char *argv[])
{ {
ENTER_SEARCH_ENGINE_SCREEN: ENTER_SEARCH_ENGINE_SCREEN:
int id = mSearcher->GetChoice();
int option = mSearcher->GetChoice(); int option = mSearcher->GetChoice();
LOCK_STATUSBAR; LOCK_STATUSBAR;
Song &s = searched_song; Song &s = searched_song;
switch (id) switch (option+1)
{ {
case 1: case 1:
{ {
@@ -1077,16 +1078,14 @@ int main(int argc, char *argv[])
{ {
ShowMessage("Searching..."); ShowMessage("Searching...");
Search(vSearched, s); Search(vSearched, s);
ShowMessage("Searching finished!");
if (!vSearched.empty()) if (!vSearched.empty())
{ {
bool bold = 0; bool bold = 0;
mSearcher->AddSeparator(); mSearcher->AddSeparator();
mSearcher->AddStaticBoldOption("[.white]Search results:[/white] [.green]Found " + IntoStr(vSearched.size()) + (vSearched.size() > 1 ? " songs" : " song") + "[/green]"); mSearcher->AddStaticBoldOption("[.white]Search results:[/white] [.green]Found " + IntoStr(vSearched.size()) + (vSearched.size() > 1 ? " songs" : " song") + "[/green]");
mSearcher->AddSeparator(); mSearcher->AddSeparator();
for (SongList::const_iterator it = vSearched.begin(); it != vSearched.end(); it++) for (SongList::const_iterator it = vSearched.begin(); it != vSearched.end(); it++)
{ {
for (int j = 0; j < mPlaylist->Size(); j++) for (int j = 0; j < mPlaylist->Size(); j++)
{ {
if (mPlaylist->at(j).GetHash() == (*it)->GetHash()) if (mPlaylist->at(j).GetHash() == (*it)->GetHash())
@@ -1098,8 +1097,8 @@ int main(int argc, char *argv[])
bold ? mSearcher->AddBoldOption(DisplaySong(**it)) : mSearcher->AddOption(DisplaySong(**it)); bold ? mSearcher->AddBoldOption(DisplaySong(**it)) : mSearcher->AddOption(DisplaySong(**it));
bold = 0; bold = 0;
} }
ShowMessage("Searching finished!");
for (int i = 1; i <=13; i++) for (int i = 0; i < 13; i++)
mSearcher->MakeStatic(i, 1); mSearcher->MakeStatic(i, 1);
mSearcher->Go(wDown); mSearcher->Go(wDown);
mSearcher->Go(wDown); mSearcher->Go(wDown);
@@ -1119,7 +1118,7 @@ int main(int argc, char *argv[])
} }
default: default:
{ {
Song &s = *vSearched[mSearcher->GetRealChoice()-2]; Song &s = *vSearched[mSearcher->GetRealChoice()-1];
int id = Mpd->AddSong(s); int id = Mpd->AddSong(s);
if (id >= 0) if (id >= 0)
{ {
@@ -1180,7 +1179,7 @@ int main(int argc, char *argv[])
{ {
if (!mLibSongs->Empty()) if (!mLibSongs->Empty())
{ {
Song &s = mLibSongs->at(mLibSongs->GetChoice()-1); Song &s = mLibSongs->at(mLibSongs->GetChoice());
int id = Mpd->AddSong(s); int id = Mpd->AddSong(s);
if (id >= 0) if (id >= 0)
{ {
@@ -1230,7 +1229,7 @@ int main(int argc, char *argv[])
{ {
if (!mPlaylistEditor->Empty()) if (!mPlaylistEditor->Empty())
{ {
Song &s = mPlaylistEditor->at(mPlaylistEditor->GetChoice()-1); Song &s = mPlaylistEditor->at(mPlaylistEditor->GetChoice());
int id = Mpd->AddSong(s); int id = Mpd->AddSong(s);
if (id >= 0) if (id >= 0)
{ {
@@ -1264,12 +1263,12 @@ int main(int argc, char *argv[])
{ {
if (current_screen == csBrowser) if (current_screen == csBrowser)
{ {
const Item &item = mBrowser->at(mBrowser->GetChoice()-1); const Item &item = mBrowser->at(mBrowser->GetChoice());
switch (item.type) switch (item.type)
{ {
case itDirectory: case itDirectory:
{ {
if (browsed_dir != "/" && mBrowser->GetChoice() == 1) if (browsed_dir != "/" && !mBrowser->GetChoice())
continue; // do not let add parent dir. continue; // do not let add parent dir.
SongList list; SongList list;
@@ -1315,7 +1314,7 @@ int main(int argc, char *argv[])
} }
else if (current_screen == csSearcher && !vSearched.empty()) else if (current_screen == csSearcher && !vSearched.empty())
{ {
int id = mSearcher->GetChoice()-search_engine_static_option-1; int id = mSearcher->GetChoice()-search_engine_static_option;
if (id < 0) if (id < 0)
continue; continue;
@@ -1409,7 +1408,10 @@ int main(int argc, char *argv[])
vector<int> list; vector<int> list;
mPlaylist->GetSelectedList(list); mPlaylist->GetSelectedList(list);
for (vector<int>::const_reverse_iterator it = list.rbegin(); it != list.rend(); it++) for (vector<int>::const_reverse_iterator it = list.rbegin(); it != list.rend(); it++)
DeleteSong(*it-1); {
Mpd->QueueDeleteSong(*it);
mPlaylist->DeleteOption(*it);
}
ShowMessage("Selected items deleted!"); ShowMessage("Selected items deleted!");
redraw_me = 1; redraw_me = 1;
} }
@@ -1422,7 +1424,8 @@ int main(int argc, char *argv[])
{ {
TraceMpdStatus(); TraceMpdStatus();
timer = time(NULL); timer = time(NULL);
DeleteSong(mPlaylist->GetChoice()-1); Mpd->QueueDeleteSong(mPlaylist->GetChoice());
mPlaylist->DeleteOption(mPlaylist->GetChoice());
mPlaylist->Refresh(); mPlaylist->Refresh();
mPlaylist->ReadKey(input); mPlaylist->ReadKey(input);
} }
@@ -1434,7 +1437,7 @@ int main(int argc, char *argv[])
else if (current_screen == csBrowser || wCurrent == mPlaylistList) else if (current_screen == csBrowser || wCurrent == mPlaylistList)
{ {
LOCK_STATUSBAR; LOCK_STATUSBAR;
int id = wCurrent->GetChoice()-1; int id = wCurrent->GetChoice();
const string &name = wCurrent == mBrowser ? mBrowser->at(id).name : mPlaylistList->at(id); const string &name = wCurrent == mBrowser ? mBrowser->at(id).name : mPlaylistList->at(id);
if (current_screen != csBrowser || mBrowser->at(id).type == itPlaylist) if (current_screen != csBrowser || mBrowser->at(id).type == itPlaylist)
{ {
@@ -1467,7 +1470,10 @@ int main(int argc, char *argv[])
vector<int> list; vector<int> list;
mPlaylistEditor->GetSelectedList(list); mPlaylistEditor->GetSelectedList(list);
for (vector<int>::const_reverse_iterator it = list.rbegin(); it != list.rend(); it++) for (vector<int>::const_reverse_iterator it = list.rbegin(); it != list.rend(); it++)
PlaylistDeleteSong(mPlaylistList->GetCurrentOption(), *it-1); {
Mpd->QueueDeleteFromPlaylist(mPlaylistList->GetCurrentOption(), *it);
mPlaylistEditor->DeleteOption(*it);
}
ShowMessage("Selected items deleted from playlist '" + mPlaylistList->GetCurrentOption() + "'!"); ShowMessage("Selected items deleted from playlist '" + mPlaylistList->GetCurrentOption() + "'!");
redraw_me = 1; redraw_me = 1;
} }
@@ -1478,7 +1484,8 @@ int main(int argc, char *argv[])
{ {
TraceMpdStatus(); TraceMpdStatus();
timer = time(NULL); timer = time(NULL);
PlaylistDeleteSong(mPlaylistList->GetCurrentOption(), mPlaylistEditor->GetChoice()-1); Mpd->QueueDeleteFromPlaylist(mPlaylistList->GetCurrentOption(), mPlaylistEditor->GetChoice());
mPlaylistEditor->DeleteOption(mPlaylistEditor->GetChoice());
mPlaylistEditor->Refresh(); mPlaylistEditor->Refresh();
mPlaylistEditor->ReadKey(input); mPlaylistEditor->ReadKey(input);
} }
@@ -1563,11 +1570,8 @@ int main(int argc, char *argv[])
mPlaylist->GetSelectedList(list); mPlaylist->GetSelectedList(list);
for (vector<int>::iterator it = list.begin(); it != list.end(); it++) for (vector<int>::iterator it = list.begin(); it != list.end(); it++)
{
--*it;
if (*it == now_playing) if (*it == now_playing)
mPlaylist->BoldOption(now_playing+1, 0); mPlaylist->BoldOption(now_playing, 0);
}
vector<int>origs(list); vector<int>origs(list);
@@ -1575,9 +1579,9 @@ int main(int argc, char *argv[])
{ {
TraceMpdStatus(); TraceMpdStatus();
timer = time(NULL); timer = time(NULL);
mPlaylist->Highlight(list[(list.size()-1)/2]);
for (vector<int>::iterator it = list.begin(); it != list.end(); it++) for (vector<int>::iterator it = list.begin(); it != list.end(); it++)
mPlaylist->Swap(--*it, *it); mPlaylist->Swap(--*it, *it);
mPlaylist->Highlight(list[(list.size()-1)/2]);
mPlaylist->Refresh(); mPlaylist->Refresh();
mPlaylist->ReadKey(input); mPlaylist->ReadKey(input);
} }
@@ -1588,7 +1592,7 @@ int main(int argc, char *argv[])
else else
{ {
int from, to; int from, to;
from = to = mPlaylist->GetChoice()-1; from = to = mPlaylist->GetChoice();
while (Keypressed(input, Key.MvSongUp) && to > 0) while (Keypressed(input, Key.MvSongUp) && to > 0)
{ {
TraceMpdStatus(); TraceMpdStatus();
@@ -1610,18 +1614,15 @@ int main(int argc, char *argv[])
vector<int> list; vector<int> list;
mPlaylistEditor->GetSelectedList(list); mPlaylistEditor->GetSelectedList(list);
for (vector<int>::iterator it = list.begin(); it != list.end(); it++)
--*it;
vector<int>origs(list); vector<int>origs(list);
while (Keypressed(input, Key.MvSongUp) && list.front() > 0) while (Keypressed(input, Key.MvSongUp) && list.front() > 0)
{ {
TraceMpdStatus(); TraceMpdStatus();
timer = time(NULL); timer = time(NULL);
mPlaylistEditor->Highlight(list[(list.size()-1)/2]);
for (vector<int>::iterator it = list.begin(); it != list.end(); it++) for (vector<int>::iterator it = list.begin(); it != list.end(); it++)
mPlaylistEditor->Swap(--*it, *it); mPlaylistEditor->Swap(--*it, *it);
mPlaylistEditor->Highlight(list[(list.size()-1)/2]);
mPlaylistEditor->Refresh(); mPlaylistEditor->Refresh();
mPlaylistEditor->ReadKey(input); mPlaylistEditor->ReadKey(input);
} }
@@ -1633,7 +1634,7 @@ int main(int argc, char *argv[])
else else
{ {
int from, to; int from, to;
from = to = mPlaylistEditor->GetChoice()-1; from = to = mPlaylistEditor->GetChoice();
while (Keypressed(input, Key.MvSongUp) && to > 0) while (Keypressed(input, Key.MvSongUp) && to > 0)
{ {
TraceMpdStatus(); TraceMpdStatus();
@@ -1661,11 +1662,8 @@ int main(int argc, char *argv[])
mPlaylist->GetSelectedList(list); mPlaylist->GetSelectedList(list);
for (vector<int>::iterator it = list.begin(); it != list.end(); it++) for (vector<int>::iterator it = list.begin(); it != list.end(); it++)
{
--*it;
if (*it == now_playing) if (*it == now_playing)
mPlaylist->BoldOption(now_playing+1, 0); mPlaylist->BoldOption(now_playing, 0);
}
vector<int>origs(list); vector<int>origs(list);
@@ -1673,9 +1671,9 @@ int main(int argc, char *argv[])
{ {
TraceMpdStatus(); TraceMpdStatus();
timer = time(NULL); timer = time(NULL);
mPlaylist->Highlight(list[(list.size()-1)/2]+2);
for (vector<int>::reverse_iterator it = list.rbegin(); it != list.rend(); it++) for (vector<int>::reverse_iterator it = list.rbegin(); it != list.rend(); it++)
mPlaylist->Swap(++*it, *it); mPlaylist->Swap(++*it, *it);
mPlaylist->Highlight(list[(list.size()-1)/2]);
mPlaylist->Refresh(); mPlaylist->Refresh();
mPlaylist->ReadKey(input); mPlaylist->ReadKey(input);
} }
@@ -1686,7 +1684,7 @@ int main(int argc, char *argv[])
else else
{ {
int from, to; int from, to;
from = to = mPlaylist->GetChoice()-1; from = to = mPlaylist->GetChoice();
while (Keypressed(input, Key.MvSongDown) && to < mPlaylist->Size()-1) while (Keypressed(input, Key.MvSongDown) && to < mPlaylist->Size()-1)
{ {
TraceMpdStatus(); TraceMpdStatus();
@@ -1709,18 +1707,15 @@ int main(int argc, char *argv[])
vector<int> list; vector<int> list;
mPlaylistEditor->GetSelectedList(list); mPlaylistEditor->GetSelectedList(list);
for (vector<int>::iterator it = list.begin(); it != list.end(); it++)
--*it;
vector<int>origs(list); vector<int>origs(list);
while (Keypressed(input, Key.MvSongDown) && list.back() < mPlaylistEditor->Size()-1) while (Keypressed(input, Key.MvSongDown) && list.back() < mPlaylistEditor->Size()-1)
{ {
TraceMpdStatus(); TraceMpdStatus();
timer = time(NULL); timer = time(NULL);
mPlaylistEditor->Highlight(list[(list.size()-1)/2]+2);
for (vector<int>::reverse_iterator it = list.rbegin(); it != list.rend(); it++) for (vector<int>::reverse_iterator it = list.rbegin(); it != list.rend(); it++)
mPlaylistEditor->Swap(++*it, *it); mPlaylistEditor->Swap(++*it, *it);
mPlaylistEditor->Highlight(list[(list.size()-1)/2]);
mPlaylistEditor->Refresh(); mPlaylistEditor->Refresh();
mPlaylistEditor->ReadKey(input); mPlaylistEditor->ReadKey(input);
} }
@@ -1732,7 +1727,7 @@ int main(int argc, char *argv[])
else else
{ {
int from, to; int from, to;
from = to = mPlaylistEditor->GetChoice()-1; from = to = mPlaylistEditor->GetChoice();
while (Keypressed(input, Key.MvSongDown) && to < mPlaylistEditor->Size()-1) while (Keypressed(input, Key.MvSongDown) && to < mPlaylistEditor->Size()-1)
{ {
TraceMpdStatus(); TraceMpdStatus();
@@ -1849,7 +1844,7 @@ int main(int argc, char *argv[])
else if (Keypressed(input, Key.GoToNowPlaying)) else if (Keypressed(input, Key.GoToNowPlaying))
{ {
if (current_screen == csPlaylist && now_playing >= 0) if (current_screen == csPlaylist && now_playing >= 0)
mPlaylist->Highlight(now_playing+1); mPlaylist->Highlight(now_playing);
} }
else if (Keypressed(input, Key.ToggleRepeat)) else if (Keypressed(input, Key.ToggleRepeat))
{ {
@@ -1888,12 +1883,12 @@ int main(int argc, char *argv[])
else if (Keypressed(input, Key.EditTags)) else if (Keypressed(input, Key.EditTags))
{ {
if ((wCurrent == mPlaylist && !mPlaylist->Empty()) if ((wCurrent == mPlaylist && !mPlaylist->Empty())
|| (wCurrent == mBrowser && mBrowser->at(mBrowser->GetChoice()-1).type == itSong) || (wCurrent == mBrowser && mBrowser->at(mBrowser->GetChoice()).type == itSong)
|| (wCurrent == mSearcher && !vSearched.empty() && mSearcher->GetChoice() > search_engine_static_option) || (wCurrent == mSearcher && !vSearched.empty() && mSearcher->GetChoice() > search_engine_static_option)
|| (wCurrent == mLibSongs && !mLibSongs->Empty()) || (wCurrent == mLibSongs && !mLibSongs->Empty())
|| (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())) || (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty()))
{ {
int id = wCurrent->GetChoice()-1; int id = wCurrent->GetChoice();
Song *s; Song *s;
switch (current_screen) switch (current_screen)
{ {
@@ -1933,7 +1928,7 @@ int main(int argc, char *argv[])
|| (wCurrent == mLibSongs && !mLibSongs->Empty()) || (wCurrent == mLibSongs && !mLibSongs->Empty())
|| (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())) || (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty()))
{ {
int id = wCurrent->GetChoice()-1; int id = wCurrent->GetChoice();
Song *s; Song *s;
switch (current_screen) switch (current_screen)
{ {
@@ -1941,7 +1936,7 @@ int main(int argc, char *argv[])
s = &mPlaylist->at(id); s = &mPlaylist->at(id);
break; break;
case csSearcher: case csSearcher:
s = vSearched[mSearcher->GetRealChoice()-2]; s = vSearched[id-search_engine_static_option];
break; break;
case csLibrary: case csLibrary:
s = &mLibSongs->at(id); s = &mLibSongs->at(id);
@@ -1958,7 +1953,7 @@ int main(int argc, char *argv[])
string option = DisplaySong(*s); string option = DisplaySong(*s);
GetDirectory(s->GetDirectory()); GetDirectory(s->GetDirectory());
for (int i = 1; i <= mBrowser->Size(); i++) for (int i = 0; i < mBrowser->Size(); i++)
{ {
if (option == mBrowser->GetOption(i)) if (option == mBrowser->GetOption(i))
{ {
@@ -1973,7 +1968,7 @@ int main(int argc, char *argv[])
{ {
if (wCurrent == mSearcher) if (wCurrent == mSearcher)
{ {
mSearcher->Highlight(13); // highlight 'search' button mSearcher->Highlight(12); // highlight 'search' button
goto ENTER_SEARCH_ENGINE_SCREEN; goto ENTER_SEARCH_ENGINE_SCREEN;
} }
} }
@@ -1998,13 +1993,13 @@ int main(int argc, char *argv[])
{ {
if (wCurrent == mPlaylist || wCurrent == mBrowser || (wCurrent == mSearcher && !vSearched.empty()) || wCurrent == mLibSongs || wCurrent == mPlaylistEditor) if (wCurrent == mPlaylist || wCurrent == mBrowser || (wCurrent == mSearcher && !vSearched.empty()) || wCurrent == mLibSongs || wCurrent == mPlaylistEditor)
{ {
for (int i = 1; i <= wCurrent->Size(); i++) for (int i = 0; i < wCurrent->Size(); i++)
wCurrent->Select(i, !wCurrent->Selected(i) && !wCurrent->IsStatic(i)); wCurrent->Select(i, !wCurrent->Selected(i) && !wCurrent->IsStatic(i));
// hackish shit begins // hackish shit begins
if (wCurrent == mBrowser && browsed_dir != "/") if (wCurrent == mBrowser && browsed_dir != "/")
wCurrent->Select(1, 0); // [..] cannot be selected, uhm. wCurrent->Select(0, 0); // [..] cannot be selected, uhm.
if (wCurrent == mSearcher) if (wCurrent == mSearcher)
wCurrent->Select(14, 0); // 'Reset' cannot be selected, omgplz. wCurrent->Select(13, 0); // 'Reset' cannot be selected, omgplz.
// hacking shit ends. need better solution :/ // hacking shit ends. need better solution :/
ShowMessage("Selection reversed!"); ShowMessage("Selection reversed!");
} }
@@ -2015,7 +2010,7 @@ int main(int argc, char *argv[])
{ {
if (wCurrent->IsAnySelected()) if (wCurrent->IsAnySelected())
{ {
for (int i = 1; i <= wCurrent->Size(); i++) for (int i = 0; i < wCurrent->Size(); i++)
wCurrent->Select(i, 0); wCurrent->Select(i, 0);
ShowMessage("Items deselected!"); ShowMessage("Items deselected!");
} }
@@ -2036,13 +2031,13 @@ int main(int argc, char *argv[])
{ {
case csPlaylist: case csPlaylist:
{ {
Song *s = new Song(mPlaylist->at(*it-1)); Song *s = new Song(mPlaylist->at(*it));
result.push_back(s); result.push_back(s);
break; break;
} }
case csBrowser: case csBrowser:
{ {
const Item &item = mBrowser->at(*it-1); const Item &item = mBrowser->at(*it);
switch (item.type) switch (item.type)
{ {
case itDirectory: case itDirectory:
@@ -2069,19 +2064,19 @@ int main(int argc, char *argv[])
} }
case csSearcher: case csSearcher:
{ {
Song *s = new Song(*vSearched[*it-search_engine_static_option-1]); Song *s = new Song(*vSearched[*it-search_engine_static_option]);
result.push_back(s); result.push_back(s);
break; break;
} }
case csLibrary: case csLibrary:
{ {
Song *s = new Song(mLibSongs->at(*it-1)); Song *s = new Song(mLibSongs->at(*it));
result.push_back(s); result.push_back(s);
break; break;
} }
case csPlaylistEditor: case csPlaylistEditor:
{ {
Song *s = new Song(mPlaylistEditor->at(*it-1)); Song *s = new Song(mPlaylistEditor->at(*it));
result.push_back(s); result.push_back(s);
break; break;
} }
@@ -2140,7 +2135,7 @@ int main(int argc, char *argv[])
else else
wCurrent->Refresh(1); wCurrent->Refresh(1);
if (id == 1) if (id == 0)
{ {
for (SongList::const_iterator it = result.begin(); it != result.end(); it++) for (SongList::const_iterator it = result.begin(); it != result.end(); it++)
Mpd->QueueAddSong(**it); Mpd->QueueAddSong(**it);
@@ -2152,7 +2147,7 @@ int main(int argc, char *argv[])
ShowMessage(message_part_of_songs_added); ShowMessage(message_part_of_songs_added);
} }
} }
else if (id == 2) else if (id == 1)
{ {
LOCK_STATUSBAR; LOCK_STATUSBAR;
wFooter->WriteXY(0, Config.statusbar_visibility, "Save playlist as: ", 1); wFooter->WriteXY(0, Config.statusbar_visibility, "Save playlist as: ", 1);
@@ -2167,15 +2162,15 @@ int main(int argc, char *argv[])
} }
} }
else if (id > 2 && id < mDialog->Size()) else if (id > 1 && id < mDialog->Size()-1)
{ {
for (SongList::const_iterator it = result.begin(); it != result.end(); it++) for (SongList::const_iterator it = result.begin(); it != result.end(); it++)
Mpd->QueueAddToPlaylist(playlists[id-4], **it); Mpd->QueueAddToPlaylist(playlists[id-3], **it);
Mpd->CommitQueue(); Mpd->CommitQueue();
ShowMessage("Selected items added to playlist '" + playlists[id-4] + "'!"); ShowMessage("Selected items added to playlist '" + playlists[id-3] + "'!");
} }
if (id != mDialog->Size()) if (id != mDialog->Size()-1)
{ {
// refresh playlist's lists // refresh playlist's lists
if (browsed_dir == "/") if (browsed_dir == "/")
@@ -2195,12 +2190,12 @@ int main(int argc, char *argv[])
{ {
for (int i = 0; i < mPlaylist->Size(); i++) for (int i = 0; i < mPlaylist->Size(); i++)
{ {
if (!mPlaylist->Selected(i+1) && i != now_playing) if (!mPlaylist->Selected(i) && i != now_playing)
Mpd->QueueDeleteSongId(mPlaylist->at(i).GetID()); Mpd->QueueDeleteSongId(mPlaylist->at(i).GetID());
} }
// if mpd deletes now playing song deletion will be sluggishly slow // if mpd deletes now playing song deletion will be sluggishly slow
// then so we have to assure it will be deleted at the very end. // then so we have to assure it will be deleted at the very end.
if (!mPlaylist->Selected(now_playing+1)) if (!mPlaylist->Selected(now_playing))
Mpd->QueueDeleteSongId(mPlaylist->at(now_playing).GetID()); Mpd->QueueDeleteSongId(mPlaylist->at(now_playing).GetID());
ShowMessage("Deleting all items but selected..."); ShowMessage("Deleting all items but selected...");
@@ -2247,7 +2242,7 @@ int main(int argc, char *argv[])
transform(findme.begin(), findme.end(), findme.begin(), tolower); transform(findme.begin(), findme.end(), findme.begin(), tolower);
ShowMessage("Searching..."); ShowMessage("Searching...");
for (int i = (wCurrent == mBrowser ? search_engine_static_option : 1); i <= wCurrent->Size(); i++) for (int i = (wCurrent == mBrowser ? search_engine_static_option-1 : 0); i < wCurrent->Size(); i++)
{ {
string name = OmitBBCodes(wCurrent->GetOption(i)); string name = OmitBBCodes(wCurrent->GetOption(i));
transform(name.begin(), name.end(), name.begin(), tolower); transform(name.begin(), name.end(), name.begin(), tolower);
@@ -2338,13 +2333,13 @@ int main(int argc, char *argv[])
} }
else if ( else if (
(wCurrent == mPlaylist && !mPlaylist->Empty()) (wCurrent == mPlaylist && !mPlaylist->Empty())
|| (wCurrent == mBrowser && mBrowser->at(mBrowser->GetChoice()-1).type == itSong) || (wCurrent == mBrowser && mBrowser->at(mBrowser->GetChoice()).type == itSong)
|| (wCurrent == mSearcher && !vSearched.empty() && mSearcher->GetChoice() > search_engine_static_option) || (wCurrent == mSearcher && !vSearched.empty() && mSearcher->GetChoice() > search_engine_static_option)
|| (wCurrent == mLibSongs && !mLibSongs->Empty()) || (wCurrent == mLibSongs && !mLibSongs->Empty())
|| (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())) || (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty()))
{ {
Song *s; Song *s;
int id = wCurrent->GetChoice()-1; int id = wCurrent->GetChoice();
switch (current_screen) switch (current_screen)
{ {
case csPlaylist: case csPlaylist:

View File

@@ -146,8 +146,8 @@ void NcmpcppStatusChanged(MPDConnection *Mpd, MPDStatusChanges changed, void *da
{ {
old_playing = now_playing; old_playing = now_playing;
now_playing = Mpd->GetCurrentSongPos(); now_playing = Mpd->GetCurrentSongPos();
mPlaylist->BoldOption(old_playing+1, 0); mPlaylist->BoldOption(old_playing, 0);
mPlaylist->BoldOption(now_playing+1, 1); mPlaylist->BoldOption(now_playing, 1);
} }
if (changed.Playlist) if (changed.Playlist)
@@ -193,7 +193,7 @@ void NcmpcppStatusChanged(MPDConnection *Mpd, MPDStatusChanges changed, void *da
for (int i = 0; i < mPlaylist->Size(); i++) for (int i = 0; i < mPlaylist->Size(); i++)
{ {
if (*list[i] != mPlaylist->at(i)) if (*list[i] != mPlaylist->at(i))
mPlaylist->UpdateOption(i+1, *list[i]); mPlaylist->UpdateOption(i, *list[i]);
} }
} }
FreeSongList(list); FreeSongList(list);
@@ -244,7 +244,7 @@ void NcmpcppStatusChanged(MPDConnection *Mpd, MPDStatusChanges changed, void *da
case psPlay: case psPlay:
{ {
player_state = "Playing: "; player_state = "Playing: ";
mPlaylist->BoldOption(now_playing+1, 1); mPlaylist->BoldOption(now_playing, 1);
changed.ElapsedTime = 1; changed.ElapsedTime = 1;
break; break;
} }
@@ -259,7 +259,7 @@ void NcmpcppStatusChanged(MPDConnection *Mpd, MPDStatusChanges changed, void *da
wFooter->SetColor(Config.progressbar_color); wFooter->SetColor(Config.progressbar_color);
mvwhline(wFooter->RawWin(), 0, 0, 0, wFooter->GetWidth()); mvwhline(wFooter->RawWin(), 0, 0, 0, wFooter->GetWidth());
wFooter->SetColor(Config.statusbar_color); wFooter->SetColor(Config.statusbar_color);
mPlaylist->BoldOption(old_playing+1, 0); mPlaylist->BoldOption(old_playing, 0);
now_playing = -1; now_playing = -1;
player_state.clear(); player_state.clear();
break; break;
@@ -280,10 +280,10 @@ void NcmpcppStatusChanged(MPDConnection *Mpd, MPDStatusChanges changed, void *da
Mpd->Play(now_playing); Mpd->Play(now_playing);
} }
if (old_playing >= 0) if (old_playing >= 0)
mPlaylist->BoldOption(old_playing+1, 0); mPlaylist->BoldOption(old_playing, 0);
mPlaylist->BoldOption(now_playing+1, 1); mPlaylist->BoldOption(now_playing, 1);
if (Config.autocenter_mode) if (Config.autocenter_mode)
mPlaylist->Highlight(now_playing+1); mPlaylist->Highlight(now_playing);
repeat_one_allowed = 0; repeat_one_allowed = 0;
} }
if (!Mpd->GetElapsedTime()) if (!Mpd->GetElapsedTime())