some fixes, code cleanups and corrected configure.in

This commit is contained in:
unknown
2008-08-06 14:51:12 +02:00
parent e2d4e5c8d8
commit c7672f1779
8 changed files with 187 additions and 204 deletions

View File

@@ -7,25 +7,56 @@ AC_LANG_CPLUSPLUS
AC_PROG_CXX AC_PROG_CXX
AM_PROG_LIBTOOL AM_PROG_LIBTOOL
CPPFLAGS="$CPPFLAGS `taglib-config --cflags`"
AC_ARG_ENABLE(unicode,[ --enable-unicode Enable utf8 support ], [unicode=$enableval], [unicode=yes]) AC_ARG_ENABLE(unicode,[ --enable-unicode Enable utf8 support ], [unicode=$enableval], [unicode=yes])
if test "$unicode" = "yes" ; then
AC_CHECK_LIB(ncursesw, initscr, , AC_MSG_ERROR([ncursesw library is required]))
AC_CHECK_HEADERS([ncursesw/ncurses.h], , AC_MSG_ERROR([missing ncursesw.h header]))
CPPFLAGS="$CPPFLAGS -DUTF8_ENABLED"
LDFLAGS="$LDFLAGS -lncursesw"
else
AC_CHECK_LIB(ncurses, initscr, , AC_MSG_ERROR([ncurses library is required]))
AC_CHECK_HEADERS([ncurses.h], , AC_MSG_ERROR([missing ncurses.h header]))
LDFLAGS="$LDFLAGS -lncurses"
fi
PKG_CHECK_MODULES([libmpd], libmpd, LDFLAGS="$LDFLAGS -lmpd", AC_MSG_ERROR([mpd library is required])) dnl ========================
dnl = checking for ncurses =
dnl ========================
if test "$unicode" = "yes" ; then
AC_PATH_PROG(NCURSESW5_CONFIG, ncursesw5-config)
if test "$NCURSESW5_CONFIG" != "" ; then
CPPFLAGS="$CPPFLAGS -DUTF8_ENABLED `$NCURSESW5_CONFIG --cflags`"
LDFLAGS="$LDFLAGS `$NCURSESW5_CONFIG --libs`"
AC_CHECK_LIB(ncursesw, initscr, , AC_MSG_ERROR([ncursesw library is required]))
else
AC_MSG_ERROR([ncursesw5-config executable is missing])
fi
else
AC_PATH_PROG(NCURSES5_CONFIG, ncurses5-config)
if test "$NCURSES5_CONFIG" != "" ; then
CPPFLAGS="$CPPFLAGS `$NCURSES5_CONFIG --cflags`"
LDFLAGS="$LDFLAGS `$NCURSES5_CONFIG --libs`"
AC_CHECK_LIB(ncurses, initscr, , AC_MSG_ERROR([ncurses library is required]))
else
AC_MSG_ERROR([ncurses5-config executable is missing])
fi
fi
AC_CHECK_HEADERS([ncurses.h], , AC_MSG_ERROR([missing ncurses.h header]))
dnl =======================
dnl = checking for libmpd =
dnl =======================
PKG_CHECK_MODULES([libmpd], libmpd >= 0.15.3, , AC_MSG_ERROR([libmpd-0.15.3 or higher is required]))
AC_SUBST(libmpd_CFLAGS)
AC_SUBST(libmpd_LIBS)
CPPFLAGS="$CPPFLAGS $libmpd_CFLAGS"
LDFLAGS="$LDFLAGS $libmpd_LIBS"
AC_CHECK_HEADERS([libmpd/libmpd.h], , AC_MSG_ERROR([missing libmpd.h header])) AC_CHECK_HEADERS([libmpd/libmpd.h], , AC_MSG_ERROR([missing libmpd.h header]))
PKG_CHECK_MODULES([taglib], taglib, LDFLAGS="$LDFLAGS `taglib-config --libs`", AC_MSG_ERROR([taglib library is required]))
AC_CHECK_HEADERS([taglib.h], , AC_MSG_ERROR([missing taglib.h header])) dnl =======================
dnl = checking for taglib =
dnl =======================
AC_PATH_PROG(TAGLIB_CONFIG, taglib-config)
if test "$TAGLIB_CONFIG" != "" ; then
CPPFLAGS="$CPPFLAGS `$TAGLIB_CONFIG --cflags`"
PKG_CHECK_MODULES([taglib], taglib, LDFLAGS="$LDFLAGS `$TAGLIB_CONFIG --libs`", AC_MSG_ERROR([taglib library is required]))
AC_CHECK_HEADERS([taglib.h], , AC_MSG_ERROR([missing taglib.h header]))
else
AC_MSG_ERROR([taglib-config executable is missing])
fi
AC_OUTPUT(Makefile src/Makefile) AC_OUTPUT(Makefile src/Makefile)

View File

@@ -56,7 +56,7 @@ extern bool block_statusbar_update;
extern bool search_case_sensitive; extern bool search_case_sensitive;
extern bool search_mode_match; extern bool search_mode_match;
extern string EMPTY; extern string EMPTY_TAG;
extern string UNKNOWN_ARTIST; extern string UNKNOWN_ARTIST;
extern string UNKNOWN_TITLE; extern string UNKNOWN_TITLE;
extern string UNKNOWN_ALBUM; extern string UNKNOWN_ALBUM;
@@ -159,7 +159,7 @@ string DisplaySong(const Song &s, const string &song_template)
{ {
if (link_tags) if (link_tags)
{ {
if (s.GetYear() != EMPTY) if (s.GetYear() != EMPTY_TAG)
result += s.GetYear(); result += s.GetYear();
else else
tags_present = 0; tags_present = 0;
@@ -172,7 +172,7 @@ string DisplaySong(const Song &s, const string &song_template)
{ {
if (link_tags) if (link_tags)
{ {
if (s.GetTrack() != EMPTY) if (s.GetTrack() != EMPTY_TAG)
result += s.GetTrack(); result += s.GetTrack();
else else
tags_present = 0; tags_present = 0;
@@ -185,7 +185,7 @@ string DisplaySong(const Song &s, const string &song_template)
{ {
if (link_tags) if (link_tags)
{ {
if (s.GetGenre() != EMPTY) if (s.GetGenre() != EMPTY_TAG)
result += s.GetGenre(); result += s.GetGenre();
else else
tags_present = 0; tags_present = 0;
@@ -198,7 +198,7 @@ string DisplaySong(const Song &s, const string &song_template)
{ {
if (link_tags) if (link_tags)
{ {
if (s.GetComment() != EMPTY) if (s.GetComment() != EMPTY_TAG)
result += s.GetComment(); result += s.GetComment();
else else
tags_present = 0; tags_present = 0;
@@ -435,7 +435,6 @@ void GetDirectory(string dir)
vFileType.push_back(MPD_DATA_TYPE_DIRECTORY); vFileType.push_back(MPD_DATA_TYPE_DIRECTORY);
vNameList.push_back(""); vNameList.push_back("");
} }
browser = mpd_database_get_directory(conn, (char *)dir.c_str()); browser = mpd_database_get_directory(conn, (char *)dir.c_str());
FOR_EACH_MPD_DATA(browser) FOR_EACH_MPD_DATA(browser)
{ {

View File

@@ -30,6 +30,15 @@
#define FOR_EACH_MPD_DATA(x) for (; (x); (x) = mpd_data_get_next(x)) #define FOR_EACH_MPD_DATA(x) for (; (x); (x) = mpd_data_get_next(x))
#define BLOCK_STATUSBAR_UPDATE \
block_statusbar_update = 1; \
allow_statusbar_unblock = 0;
#define UNBLOCK_STATUSBAR_UPDATE \
allow_statusbar_unblock = 1; \
if (block_statusbar_update_delay < 0) \
block_statusbar_update = 0;
char *MPD_HOST = getenv("MPD_HOST"); char *MPD_HOST = getenv("MPD_HOST");
int MPD_PORT = getenv("MPD_PORT") ? atoi(getenv("MPD_PORT")) : 6600; int MPD_PORT = getenv("MPD_PORT") ? atoi(getenv("MPD_PORT")) : 6600;
char *MPD_PASSWORD = getenv("MPD_PASSWORD"); char *MPD_PASSWORD = getenv("MPD_PASSWORD");
@@ -41,8 +50,8 @@ vector<Song> vSearched;
vector<MpdDataType> vFileType; vector<MpdDataType> vFileType;
vector<string> vNameList; vector<string> vNameList;
Window *mCurrent = 0; Window *wCurrent = 0;
Window *mPrev = 0; Window *wPrev = 0;
Menu *mPlaylist; Menu *mPlaylist;
Menu *mBrowser; Menu *mBrowser;
Menu *mTagEditor; Menu *mTagEditor;
@@ -66,8 +75,6 @@ int browsed_dir_scroll_begin = 0;
int block_statusbar_update_delay = -1; int block_statusbar_update_delay = -1;
long long current_playlist_id = -1;
string browsed_dir = "/"; string browsed_dir = "/";
string browsed_subdir; string browsed_subdir;
string player_state; string player_state;
@@ -99,7 +106,7 @@ bool block_playlist_update = 0;
bool search_case_sensitive = 1; bool search_case_sensitive = 1;
bool search_mode_match = 1; bool search_mode_match = 1;
extern string EMPTY; extern string EMPTY_TAG;
extern string UNKNOWN_ARTIST; extern string UNKNOWN_ARTIST;
extern string UNKNOWN_TITLE; extern string UNKNOWN_TITLE;
extern string UNKNOWN_ALBUM; extern string UNKNOWN_ALBUM;
@@ -208,10 +215,10 @@ int main(int argc, char *argv[])
wFooter->SetColor(Config.statusbar_color); wFooter->SetColor(Config.statusbar_color);
wFooter->Refresh(); wFooter->Refresh();
mCurrent = mPlaylist; wCurrent = mPlaylist;
current_screen = csPlaylist; current_screen = csPlaylist;
mCurrent->Display(); wCurrent->Display();
int input; int input;
timer = time(NULL); timer = time(NULL);
@@ -286,9 +293,9 @@ int main(int argc, char *argv[])
wHeader->Bold(0); wHeader->Bold(0);
} }
mCurrent->Refresh(); wCurrent->Refresh();
mCurrent->ReadKey(input); wCurrent->ReadKey(input);
if (input == ERR) if (input == ERR)
continue; continue;
@@ -305,19 +312,19 @@ int main(int argc, char *argv[])
switch (input) switch (input)
{ {
case KEY_UP: mCurrent->Go(UP); continue; case KEY_UP: wCurrent->Go(UP); continue;
case KEY_DOWN: mCurrent->Go(DOWN); continue; case KEY_DOWN: wCurrent->Go(DOWN); continue;
case KEY_PPAGE: mCurrent->Go(PAGE_UP); continue; case KEY_PPAGE: wCurrent->Go(PAGE_UP); continue;
case KEY_NPAGE: mCurrent->Go(PAGE_DOWN); continue; case KEY_NPAGE: wCurrent->Go(PAGE_DOWN); continue;
case KEY_HOME: mCurrent->Go(HOME); continue; case KEY_HOME: wCurrent->Go(HOME); continue;
case KEY_END: mCurrent->Go(END); continue; case KEY_END: wCurrent->Go(END); continue;
case KEY_RESIZE: case KEY_RESIZE:
{ {
int in; int in;
while (1) while (1)
{ {
mCurrent->ReadKey(in); wCurrent->ReadKey(in);
if (in == KEY_RESIZE) if (in == KEY_RESIZE)
continue; continue;
else else
@@ -342,19 +349,11 @@ int main(int argc, char *argv[])
wFooter->MoveTo(0, LINES-2); wFooter->MoveTo(0, LINES-2);
wFooter->Resize(COLS, wFooter->GetHeight()); wFooter->Resize(COLS, wFooter->GetHeight());
if (mCurrent != sHelp) if (wCurrent != sHelp)
mCurrent->Hide(); wCurrent->Hide();
mCurrent->Display(); wCurrent->Display();
wHeader->DisableBB();
wHeader->Bold(1);
mvwhline(wHeader->RawWin(), 1, 0, 0, wHeader->GetWidth());
if (!switch_state.empty())
wHeader->WriteXY(wHeader->GetWidth()-switch_state.length()-3, 1, "[" + switch_state + "]");
wHeader->Refresh();
wHeader->Bold(0);
wHeader->EnableBB();
header_update_status = 1;
int mpd_state = mpd_player_get_state(conn); int mpd_state = mpd_player_get_state(conn);
if (mpd_state == MPD_PLAYER_PLAY || mpd_state == MPD_PLAYER_PAUSE) if (mpd_state == MPD_PLAYER_PLAY || mpd_state == MPD_PLAYER_PAUSE)
NcmpcppStatusChanged(conn, MPD_CST_ELAPSED_TIME); // restore status NcmpcppStatusChanged(conn, MPD_CST_ELAPSED_TIME); // restore status
@@ -449,8 +448,7 @@ int main(int argc, char *argv[])
{ {
int id = mTagEditor->GetRealChoice(); int id = mTagEditor->GetRealChoice();
int option = mTagEditor->GetChoice(); int option = mTagEditor->GetChoice();
block_statusbar_update = 1; BLOCK_STATUSBAR_UPDATE
allow_statusbar_unblock = 0;
Song &s = edited_song; Song &s = edited_song;
switch (id) switch (id)
@@ -488,7 +486,7 @@ int main(int argc, char *argv[])
case 4: case 4:
{ {
wFooter->WriteXY(0, 1, "[b]New year:[/b] ", 1); wFooter->WriteXY(0, 1, "[b]New year:[/b] ", 1);
if (s.GetYear() == EMPTY) if (s.GetYear() == EMPTY_TAG)
s.SetDate(wFooter->GetString(4, TraceMpdStatus)); s.SetDate(wFooter->GetString(4, TraceMpdStatus));
else else
s.SetDate(wFooter->GetString(s.GetYear(), 4, TraceMpdStatus)); s.SetDate(wFooter->GetString(s.GetYear(), 4, TraceMpdStatus));
@@ -498,7 +496,7 @@ int main(int argc, char *argv[])
case 5: case 5:
{ {
wFooter->WriteXY(0, 1, "[b]New track:[/b] ", 1); wFooter->WriteXY(0, 1, "[b]New track:[/b] ", 1);
if (s.GetTrack() == EMPTY) if (s.GetTrack() == EMPTY_TAG)
s.SetTrack(wFooter->GetString(3, TraceMpdStatus)); s.SetTrack(wFooter->GetString(3, TraceMpdStatus));
else else
s.SetTrack(wFooter->GetString(s.GetTrack(), 3, TraceMpdStatus)); s.SetTrack(wFooter->GetString(s.GetTrack(), 3, TraceMpdStatus));
@@ -508,7 +506,7 @@ int main(int argc, char *argv[])
case 6: case 6:
{ {
wFooter->WriteXY(0, 1, "[b]New genre:[/b] ", 1); wFooter->WriteXY(0, 1, "[b]New genre:[/b] ", 1);
if (s.GetGenre() == EMPTY) if (s.GetGenre() == EMPTY_TAG)
s.SetGenre(wFooter->GetString("", TraceMpdStatus)); s.SetGenre(wFooter->GetString("", TraceMpdStatus));
else else
s.SetGenre(wFooter->GetString(s.GetGenre(), TraceMpdStatus)); s.SetGenre(wFooter->GetString(s.GetGenre(), TraceMpdStatus));
@@ -518,7 +516,7 @@ int main(int argc, char *argv[])
case 7: case 7:
{ {
wFooter->WriteXY(0, 1, "[b]New comment:[/b] ", 1); wFooter->WriteXY(0, 1, "[b]New comment:[/b] ", 1);
if (s.GetComment() == EMPTY) if (s.GetComment() == EMPTY_TAG)
s.SetComment(wFooter->GetString("", TraceMpdStatus)); s.SetComment(wFooter->GetString("", TraceMpdStatus));
else else
s.SetComment(wFooter->GetString(s.GetComment(), TraceMpdStatus)); s.SetComment(wFooter->GetString(s.GetComment(), TraceMpdStatus));
@@ -554,23 +552,20 @@ int main(int argc, char *argv[])
} }
case 9: case 9:
{ {
mCurrent->Clear(); wCurrent->Clear();
mCurrent = mPrev; wCurrent = wPrev;
current_screen = prev_screen; current_screen = prev_screen;
break; break;
} }
} }
allow_statusbar_unblock = 1; UNBLOCK_STATUSBAR_UPDATE
if (block_statusbar_update_delay < 0)
block_statusbar_update = 0;
break; break;
} }
case csSearcher: case csSearcher:
{ {
int id = mSearcher->GetChoice(); int id = mSearcher->GetChoice();
int option = mSearcher->GetChoice(); int option = mSearcher->GetChoice();
block_statusbar_update = 1; BLOCK_STATUSBAR_UPDATE
allow_statusbar_unblock = 0;
Song &s = searched_song; Song &s = searched_song;
switch (id) switch (id)
@@ -578,7 +573,7 @@ int main(int argc, char *argv[])
case 1: case 1:
{ {
wFooter->WriteXY(0, 1, "[b]Filename:[/b] ", 1); wFooter->WriteXY(0, 1, "[b]Filename:[/b] ", 1);
if (s.GetShortFilename() == EMPTY) if (s.GetShortFilename() == EMPTY_TAG)
s.SetShortFilename(wFooter->GetString("", TraceMpdStatus)); s.SetShortFilename(wFooter->GetString("", TraceMpdStatus));
else else
s.SetShortFilename(wFooter->GetString(s.GetShortFilename(), TraceMpdStatus)); s.SetShortFilename(wFooter->GetString(s.GetShortFilename(), TraceMpdStatus));
@@ -618,7 +613,7 @@ int main(int argc, char *argv[])
case 5: case 5:
{ {
wFooter->WriteXY(0, 1, "[b]Year:[/b] ", 1); wFooter->WriteXY(0, 1, "[b]Year:[/b] ", 1);
if (s.GetYear() == EMPTY) if (s.GetYear() == EMPTY_TAG)
s.SetDate(wFooter->GetString(4, TraceMpdStatus)); s.SetDate(wFooter->GetString(4, TraceMpdStatus));
else else
s.SetDate(wFooter->GetString(s.GetYear(), 4, TraceMpdStatus)); s.SetDate(wFooter->GetString(s.GetYear(), 4, TraceMpdStatus));
@@ -628,7 +623,7 @@ int main(int argc, char *argv[])
case 6: case 6:
{ {
wFooter->WriteXY(0, 1, "[b]Track:[/b] ", 1); wFooter->WriteXY(0, 1, "[b]Track:[/b] ", 1);
if (s.GetTrack() == EMPTY) if (s.GetTrack() == EMPTY_TAG)
s.SetTrack(wFooter->GetString(3, TraceMpdStatus)); s.SetTrack(wFooter->GetString(3, TraceMpdStatus));
else else
s.SetTrack(wFooter->GetString(s.GetTrack(), 3, TraceMpdStatus)); s.SetTrack(wFooter->GetString(s.GetTrack(), 3, TraceMpdStatus));
@@ -638,7 +633,7 @@ int main(int argc, char *argv[])
case 7: case 7:
{ {
wFooter->WriteXY(0, 1, "[b]Genre:[/b] ", 1); wFooter->WriteXY(0, 1, "[b]Genre:[/b] ", 1);
if (s.GetGenre() == EMPTY) if (s.GetGenre() == EMPTY_TAG)
s.SetGenre(wFooter->GetString("", TraceMpdStatus)); s.SetGenre(wFooter->GetString("", TraceMpdStatus));
else else
s.SetGenre(wFooter->GetString(s.GetGenre(), TraceMpdStatus)); s.SetGenre(wFooter->GetString(s.GetGenre(), TraceMpdStatus));
@@ -648,7 +643,7 @@ int main(int argc, char *argv[])
case 8: case 8:
{ {
wFooter->WriteXY(0, 1, "[b]Comment:[/b] ", 1); wFooter->WriteXY(0, 1, "[b]Comment:[/b] ", 1);
if (s.GetComment() == EMPTY) if (s.GetComment() == EMPTY_TAG)
s.SetComment(wFooter->GetString("", TraceMpdStatus)); s.SetComment(wFooter->GetString("", TraceMpdStatus));
else else
s.SetComment(wFooter->GetString(s.GetComment(), TraceMpdStatus)); s.SetComment(wFooter->GetString(s.GetComment(), TraceMpdStatus));
@@ -723,10 +718,7 @@ int main(int argc, char *argv[])
break; break;
} }
} }
allow_statusbar_unblock = 1; UNBLOCK_STATUSBAR_UPDATE
if (block_statusbar_update_delay < 0)
block_statusbar_update = 0;
break; break;
} }
} }
@@ -840,9 +832,7 @@ int main(int argc, char *argv[])
} }
if (current_screen == csBrowser) if (current_screen == csBrowser)
{ {
block_statusbar_update = 1; BLOCK_STATUSBAR_UPDATE
allow_statusbar_unblock = 0;
int id = mBrowser->GetChoice()-1; int id = mBrowser->GetChoice()-1;
if (vFileType[id] == MPD_DATA_TYPE_PLAYLIST) if (vFileType[id] == MPD_DATA_TYPE_PLAYLIST)
{ {
@@ -866,9 +856,7 @@ int main(int argc, char *argv[])
else else
ShowMessage("Aborted!"); ShowMessage("Aborted!");
curs_set(0); curs_set(0);
allow_statusbar_unblock = 1; UNBLOCK_STATUSBAR_UPDATE
if (block_statusbar_update_delay < 0)
block_statusbar_update = 0;
} }
} }
break; break;
@@ -891,13 +879,10 @@ int main(int argc, char *argv[])
case 'S': // save playlist case 'S': // save playlist
{ {
string playlist_name; string playlist_name;
block_statusbar_update = 1; BLOCK_STATUSBAR_UPDATE
allow_statusbar_unblock = 0;
wFooter->WriteXY(0, 1, "Save playlist as: ", 1); wFooter->WriteXY(0, 1, "Save playlist as: ", 1);
playlist_name = wFooter->GetString("", TraceMpdStatus); playlist_name = wFooter->GetString("", TraceMpdStatus);
allow_statusbar_unblock = 1; UNBLOCK_STATUSBAR_UPDATE
if (block_statusbar_update_delay < 0)
block_statusbar_update = 0;
if (playlist_name.find("/") != string::npos) if (playlist_name.find("/") != string::npos)
{ {
ShowMessage("Playlist name cannot contain slashes!"); ShowMessage("Playlist name cannot contain slashes!");
@@ -950,7 +935,7 @@ int main(int argc, char *argv[])
break; break;
block_progressbar_update = 1; block_progressbar_update = 1;
block_statusbar_update = 1; BLOCK_STATUSBAR_UPDATE
int songpos, in; int songpos, in;
@@ -989,7 +974,7 @@ int main(int argc, char *argv[])
mpd_player_seek(conn, songpos); mpd_player_seek(conn, songpos);
block_progressbar_update = 0; block_progressbar_update = 0;
block_statusbar_update = 0; UNBLOCK_STATUSBAR_UPDATE
break; break;
} }
@@ -1029,15 +1014,15 @@ int main(int argc, char *argv[])
} }
case 'E': case 'e': // edit song's tags case 'E': case 'e': // edit song's tags
{ {
int id = mCurrent->GetChoice()-1; int id = wCurrent->GetChoice()-1;
switch (current_screen) switch (current_screen)
{ {
case csPlaylist: case csPlaylist:
{ {
if (GetSongInfo(vPlaylist[id])) if (GetSongInfo(vPlaylist[id]))
{ {
mCurrent = mTagEditor; wCurrent = mTagEditor;
mPrev = mPlaylist; wPrev = mPlaylist;
current_screen = csTagEditor; current_screen = csTagEditor;
prev_screen = csPlaylist; prev_screen = csPlaylist;
} }
@@ -1052,8 +1037,8 @@ int main(int argc, char *argv[])
Song edited = mpd_database_get_fileinfo(conn, vNameList[id].c_str()); Song edited = mpd_database_get_fileinfo(conn, vNameList[id].c_str());
if (GetSongInfo(edited)) if (GetSongInfo(edited))
{ {
mCurrent = mTagEditor; wCurrent = mTagEditor;
mPrev = mBrowser; wPrev = mBrowser;
current_screen = csTagEditor; current_screen = csTagEditor;
prev_screen = csBrowser; prev_screen = csBrowser;
} }
@@ -1068,8 +1053,8 @@ int main(int argc, char *argv[])
{ {
if (GetSongInfo(vSearched[id-search_engine_static_option])) if (GetSongInfo(vSearched[id-search_engine_static_option]))
{ {
mCurrent = mTagEditor; wCurrent = mTagEditor;
mPrev = mSearcher; wPrev = mSearcher;
current_screen = csTagEditor; current_screen = csTagEditor;
prev_screen = csSearcher; prev_screen = csSearcher;
} }
@@ -1089,16 +1074,13 @@ int main(int argc, char *argv[])
break; break;
int newpos = 0; int newpos = 0;
string position; string position;
block_statusbar_update = 1; BLOCK_STATUSBAR_UPDATE
allow_statusbar_unblock = 0;
wFooter->WriteXY(0, 1, "Position to go (in %): ", 1); wFooter->WriteXY(0, 1, "Position to go (in %): ", 1);
position = wFooter->GetString(3, TraceMpdStatus); position = wFooter->GetString(3, TraceMpdStatus);
newpos = atoi(position.c_str()); newpos = atoi(position.c_str());
if (newpos > 0 && newpos < 100 && !position.empty()) if (newpos > 0 && newpos < 100 && !position.empty())
mpd_player_seek(conn, vPlaylist[now_playing].GetTotalLength()*newpos/100.0); mpd_player_seek(conn, vPlaylist[now_playing].GetTotalLength()*newpos/100.0);
allow_statusbar_unblock = 1; UNBLOCK_STATUSBAR_UPDATE
if (block_statusbar_update_delay < 0)
block_statusbar_update = 0;
break; break;
} }
case 'c': // clear playlist case 'c': // clear playlist
@@ -1109,20 +1091,20 @@ int main(int argc, char *argv[])
} }
case '1': // help screen case '1': // help screen
{ {
if (mCurrent != sHelp) if (wCurrent != sHelp)
{ {
mCurrent->Hide(); wCurrent->Hide();
mCurrent = sHelp; wCurrent = sHelp;
current_screen = csHelp; current_screen = csHelp;
} }
break; break;
} }
case '2': // playlist screen case '2': // playlist screen
{ {
if (mCurrent != mPlaylist && current_screen != csTagEditor) if (wCurrent != mPlaylist && current_screen != csTagEditor)
{ {
mCurrent->Hide(); wCurrent->Hide();
mCurrent = mPlaylist; wCurrent = mPlaylist;
current_screen = csPlaylist; current_screen = csPlaylist;
} }
break; break;
@@ -1132,10 +1114,10 @@ int main(int argc, char *argv[])
if (browsed_dir.empty()) if (browsed_dir.empty())
browsed_dir = "/"; browsed_dir = "/";
if (mCurrent != mBrowser && current_screen != csTagEditor) if (wCurrent != mBrowser && current_screen != csTagEditor)
{ {
mCurrent->Hide(); wCurrent->Hide();
mCurrent = mBrowser; wCurrent = mBrowser;
current_screen = csBrowser; current_screen = csBrowser;
} }
if (mBrowser->Empty()) if (mBrowser->Empty())
@@ -1146,10 +1128,10 @@ int main(int argc, char *argv[])
{ {
if (current_screen != csTagEditor && current_screen != csSearcher) if (current_screen != csTagEditor && current_screen != csSearcher)
{ {
mCurrent->Hide(); wCurrent->Hide();
if (vSearched.empty()) if (vSearched.empty())
PrepareSearchEngine(searched_song); PrepareSearchEngine(searched_song);
mCurrent = mSearcher; wCurrent = mSearcher;
current_screen = csSearcher; current_screen = csSearcher;
} }
break; break;

View File

@@ -31,12 +31,15 @@ const bool UNICODE = 0;
# define NCMPCPP_TO_WSTRING(x) (x) # define NCMPCPP_TO_WSTRING(x) (x)
#endif #endif
#define NCMPCPP_VERSION "0.1"
#define ENTER 10 #define ENTER 10
#define KEY_SPACE 32 #define KEY_SPACE 32
#include "fileref.h" #include "fileref.h"
#include "tag.h" #include "tag.h"
#include <libmpd/libmpd.h> #include "libmpd/libmpd.h"
#include <clocale> #include <clocale>
#include <ctime> #include <ctime>
#include <unistd.h> #include <unistd.h>

View File

@@ -22,7 +22,7 @@
extern ncmpcpp_config Config; extern ncmpcpp_config Config;
string EMPTY; string EMPTY_TAG;
string UNKNOWN_ARTIST; string UNKNOWN_ARTIST;
string UNKNOWN_TITLE; string UNKNOWN_TITLE;
string UNKNOWN_ALBUM; string UNKNOWN_ALBUM;
@@ -30,7 +30,7 @@ string UNKNOWN_ALBUM;
void DefineEmptyTags() void DefineEmptyTags()
{ {
const string et_col = IntoStr(Config.empty_tags_color); const string et_col = IntoStr(Config.empty_tags_color);
EMPTY = "[" + et_col + "]<empty>[/" + et_col + "]"; EMPTY_TAG = "[" + et_col + "]<empty>[/" + et_col + "]";
UNKNOWN_ARTIST = "[" + et_col + "]<no artist>[/" + et_col + "]"; UNKNOWN_ARTIST = "[" + et_col + "]<no artist>[/" + et_col + "]";
UNKNOWN_TITLE = "[" + et_col + "]<no title>[/" + et_col + "]"; UNKNOWN_TITLE = "[" + et_col + "]<no title>[/" + et_col + "]";
UNKNOWN_ALBUM = "[" + et_col + "]<no album>[/" + et_col + "]"; UNKNOWN_ALBUM = "[" + et_col + "]<no album>[/" + et_col + "]";
@@ -115,17 +115,17 @@ bool Song::Empty() const
string Song::GetFile() const string Song::GetFile() const
{ {
return itsGetEmptyFields ? (itsFile.empty() ? "" : itsFile) : (itsFile.empty() ? EMPTY : itsFile); return itsGetEmptyFields ? (itsFile.empty() ? "" : itsFile) : (itsFile.empty() ? EMPTY_TAG : itsFile);
} }
string Song::GetShortFilename() const string Song::GetShortFilename() const
{ {
return itsGetEmptyFields ? (itsShortName.empty() ? "" : itsShortName) : (itsShortName.empty() ? EMPTY : itsShortName); return itsGetEmptyFields ? (itsShortName.empty() ? "" : itsShortName) : (itsShortName.empty() ? EMPTY_TAG : itsShortName);
} }
string Song::GetDirectory() const string Song::GetDirectory() const
{ {
return itsGetEmptyFields ? (itsDirectory.empty() ? "" : itsDirectory) : (itsDirectory.empty() ? EMPTY : itsDirectory); return itsGetEmptyFields ? (itsDirectory.empty() ? "" : itsDirectory) : (itsDirectory.empty() ? EMPTY_TAG : itsDirectory);
} }
string Song::GetArtist() const string Song::GetArtist() const
@@ -145,21 +145,21 @@ string Song::GetAlbum() const
string Song::GetTrack() const string Song::GetTrack() const
{ {
return itsGetEmptyFields ? (itsTrack.empty() ? "" : itsTrack) : (itsTrack.empty() ? EMPTY : itsTrack); return itsGetEmptyFields ? (itsTrack.empty() ? "" : itsTrack) : (itsTrack.empty() ? EMPTY_TAG : itsTrack);
} }
string Song::GetYear() const string Song::GetYear() const
{ {
return itsGetEmptyFields ? (itsYear.empty() ? "" : itsYear) : (itsYear.empty() ? EMPTY : itsYear); return itsGetEmptyFields ? (itsYear.empty() ? "" : itsYear) : (itsYear.empty() ? EMPTY_TAG : itsYear);
} }
string Song::GetGenre() const string Song::GetGenre() const
{ {
return itsGetEmptyFields ? (itsGenre.empty() ? "" : itsGenre) : (itsGenre.empty() ? EMPTY : itsGenre); return itsGetEmptyFields ? (itsGenre.empty() ? "" : itsGenre) : (itsGenre.empty() ? EMPTY_TAG : itsGenre);
} }
string Song::GetComment() const string Song::GetComment() const
{ {
return itsGetEmptyFields ? (itsComment.empty() ? "" : itsComment) : (itsComment.empty() ? EMPTY : itsComment); return itsGetEmptyFields ? (itsComment.empty() ? "" : itsComment) : (itsComment.empty() ? EMPTY_TAG : itsComment);
} }

View File

@@ -21,7 +21,7 @@
#ifndef HAVE_SONG_H #ifndef HAVE_SONG_H
#define HAVE_SONG_H #define HAVE_SONG_H
#include <libmpd/libmpd.h> #include "libmpd/libmpd.h"
#include <cstdlib> #include <cstdlib>
#include <string> #include <string>
#include <sstream> #include <sstream>

View File

@@ -31,7 +31,7 @@ extern ncmpcpp_config Config;
extern Menu *mPlaylist; extern Menu *mPlaylist;
extern Menu *mBrowser; extern Menu *mBrowser;
extern Menu *mCurrent; extern Menu *wCurrent;
extern Menu *mSearcher; extern Menu *mSearcher;
extern Window *wHeader; extern Window *wHeader;
@@ -51,8 +51,6 @@ extern int playing_song_scroll_begin;
extern int block_statusbar_update_delay; extern int block_statusbar_update_delay;
extern long long current_playlist_id;
extern string browsed_dir; extern string browsed_dir;
extern string player_state; extern string player_state;
@@ -73,6 +71,8 @@ extern bool block_progressbar_update;
extern bool block_statusbar_update; extern bool block_statusbar_update;
extern bool block_playlist_update; extern bool block_playlist_update;
int old_playing;
void TraceMpdStatus() void TraceMpdStatus()
{ {
mpd_status_update(conn); mpd_status_update(conn);
@@ -119,6 +119,12 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
wFooter->Bold(1); wFooter->Bold(1);
wFooter->GetXY(sx, sy); wFooter->GetXY(sx, sy);
if (now_playing != mpd_player_get_current_song_pos(conn))
{
old_playing = now_playing;
now_playing = mpd_player_get_current_song_pos(conn);
}
if (what & MPD_CST_PLAYLIST) if (what & MPD_CST_PLAYLIST)
{ {
if (!block_playlist_update) if (!block_playlist_update)
@@ -143,18 +149,14 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
{ {
vPlaylist.push_back(playlist->song); vPlaylist.push_back(playlist->song);
Song &s = vPlaylist.back(); Song &s = vPlaylist.back();
if (mpd_player_get_current_song_pos(conn) != s.GetPosition()) if (now_playing != s.GetPosition())
mPlaylist->AddOption(DisplaySong(s)); mPlaylist->AddOption(DisplaySong(s));
else else
{
now_playing = mpd_player_get_current_song_pos(conn);
mPlaylist->AddBoldOption(DisplaySong(s)); mPlaylist->AddBoldOption(DisplaySong(s));
}
} }
} }
mpd_data_free(playlist); mpd_data_free(playlist);
current_playlist_id = mpd_playlist_get_playlist_id(conn);
if (current_screen == csPlaylist) if (current_screen == csPlaylist)
{ {
if (!playlist_length || mPlaylist->MaxChoice() < mPlaylist->GetHeight()) if (!playlist_length || mPlaylist->MaxChoice() < mPlaylist->GetHeight())
@@ -166,8 +168,7 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
{ {
int i = 1; int i = 1;
mPlaylist->BoldOption(now_playing+1, 0); mPlaylist->BoldOption(old_playing+1, 0);
now_playing = mpd_player_get_current_song_pos(conn);
mPlaylist->BoldOption(now_playing+1, 1); mPlaylist->BoldOption(now_playing+1, 1);
playlist = mpd_playlist_get_changes(conn, -1); playlist = mpd_playlist_get_changes(conn, -1);
@@ -185,8 +186,6 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
playlist = mpd_data_get_next(playlist); playlist = mpd_data_get_next(playlist);
} }
mpd_data_free(playlist); mpd_data_free(playlist);
if (current_screen == csPlaylist)
mPlaylist->Refresh();
} }
} }
@@ -207,8 +206,6 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
bold = 0; bold = 0;
} }
} }
if (current_screen == csBrowser)
mBrowser->Refresh();
} }
if (!vSearched.empty()) if (!vSearched.empty())
{ {
@@ -222,21 +219,47 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
mSearcher->BoldOption(i+1, bold); mSearcher->BoldOption(i+1, bold);
bold = 0; bold = 0;
} }
if (current_screen == csSearcher)
mSearcher->Refresh();
} }
} }
if(what & MPD_CST_DATABASE) if(what & MPD_CST_DATABASE)
{
GetDirectory(browsed_dir); GetDirectory(browsed_dir);
mCurrent->Refresh(); if (what & MPD_CST_STATE)
{
int mpd_state = mpd_player_get_state(conn);
switch (mpd_state)
{
case MPD_PLAYER_PLAY:
{
Song &s = vPlaylist[now_playing];
player_state = "Playing: ";
mPlaylist->BoldOption(now_playing+1, 1);
break;
}
case MPD_PLAYER_PAUSE:
{
player_state = "[Paused] ";
break;
}
case MPD_PLAYER_STOP:
{
WindowTitle("ncmpc++ ver. "NCMPCPP_VERSION);
wFooter->SetColor(Config.progressbar_color);
mvwhline(wFooter->RawWin(), 0, 0, 0, wFooter->GetWidth());
wFooter->SetColor(Config.statusbar_color);
mPlaylist->BoldOption(old_playing+1, 0);
now_playing = -1;
player_state.clear();
break;
}
}
if (!block_statusbar_update)
wFooter->WriteXY(0, 1, player_state, player_state.empty());
} }
if ((what & MPD_CST_ELAPSED_TIME)) if ((what & MPD_CST_ELAPSED_TIME))
{ {
mpd_Song *song = mpd_playlist_get_current_song(conn); Song &s = vPlaylist[now_playing];
if (song) if (!player_state.empty())
{ {
Song s = song;
WindowTitle(DisplaySong(s, Config.song_window_title_format)); WindowTitle(DisplaySong(s, Config.song_window_title_format));
int elapsed = mpd_status_get_elapsed_song_time(conn); int elapsed = mpd_status_get_elapsed_song_time(conn);
@@ -246,7 +269,7 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
string tracklength = " [" + ShowTime(elapsed) + "/" + s.GetLength() + "]"; string tracklength = " [" + ShowTime(elapsed) + "/" + s.GetLength() + "]";
ncmpcpp_string_t playing_song = NCMPCPP_TO_WSTRING(OmitBBCodes(DisplaySong(s, Config.song_status_format))); ncmpcpp_string_t playing_song = NCMPCPP_TO_WSTRING(OmitBBCodes(DisplaySong(s, Config.song_status_format)));
int max_length_without_scroll = wFooter->GetWidth()-9-tracklength.length(); int max_length_without_scroll = wFooter->GetWidth()-player_state.length()-tracklength.length();
wFooter->WriteXY(0, 1, player_state); wFooter->WriteXY(0, 1, player_state);
wFooter->Bold(0); wFooter->Bold(0);
@@ -257,17 +280,16 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
# else # else
playing_song += " ** "; playing_song += " ** ";
# endif # endif
const int scrollsize = max_length_without_scroll+playing_song.length();
const int scrollsize = max_length_without_scroll+4;
ncmpcpp_string_t part = playing_song.substr(playing_song_scroll_begin++, scrollsize); ncmpcpp_string_t part = playing_song.substr(playing_song_scroll_begin++, scrollsize);
if (part.length() < scrollsize) if (part.length() < scrollsize)
part += playing_song.substr(0, scrollsize-part.length()); part += playing_song.substr(0, scrollsize-part.length());
wFooter->WriteXY(9, 1, part); wFooter->WriteXY(player_state.length(), 1, part);
if (playing_song_scroll_begin >= playing_song.length()) if (playing_song_scroll_begin >= playing_song.length())
playing_song_scroll_begin = 0; playing_song_scroll_begin = 0;
} }
else else
wFooter->WriteXY(9, 1, OmitBBCodes(DisplaySong(s, Config.song_status_format)), 1); wFooter->WriteXY(player_state.length(), 1, OmitBBCodes(DisplaySong(s, Config.song_status_format)), 1);
wFooter->Bold(1); wFooter->Bold(1);
wFooter->WriteXY(wFooter->GetWidth()-tracklength.length(), 1, tracklength); wFooter->WriteXY(wFooter->GetWidth()-tracklength.length(), 1, tracklength);
@@ -283,48 +305,9 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
wFooter->SetColor(Config.statusbar_color); wFooter->SetColor(Config.statusbar_color);
} }
} }
} else
if (what & MPD_CST_STATE)
{
string state;
int mpd_state = mpd_player_get_state(conn);
switch (mpd_state)
{ {
case MPD_PLAYER_PLAY: if (!block_statusbar_update)
{
Song &s = vPlaylist[mpd_player_get_current_song_pos(conn)];
now_playing = s.GetPosition();
player_state = "Playing: ";
mPlaylist->BoldOption(now_playing+1, 1);
if (current_screen == csPlaylist)
mPlaylist->Refresh();
break;
}
case MPD_PLAYER_PAUSE:
{
player_state = "[Paused] ";
break;
}
case MPD_PLAYER_STOP:
{
WindowTitle("ncmpc++ ver. 0.1");
wFooter->SetColor(Config.progressbar_color);
mvwhline(wFooter->RawWin(), 0, 0, 0, wFooter->GetWidth());
wFooter->SetColor(Config.statusbar_color);
now_playing = -1;
player_state.clear();
for (int i = 1; i <= mPlaylist->MaxChoice(); i++)
mPlaylist->BoldOption(i, 0);
if (current_screen == csPlaylist)
mPlaylist->Refresh();
break;
}
}
if (!block_statusbar_update || mpd_state == MPD_PLAYER_STOP)
{
if (!player_state.empty())
wFooter->WriteXY(0, 1, player_state);
else
wFooter->WriteXY(0, 1, "", 1); wFooter->WriteXY(0, 1, "", 1);
} }
} }
@@ -374,25 +357,14 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
if (!vPlaylist.empty() && id >= 0) if (!vPlaylist.empty() && id >= 0)
{ {
Song &s = vPlaylist[id]; Song &s = vPlaylist[id];
/*if (s.GetArtist() != UNKNOWN_ARTIST || s.GetTitle() != UNKNOWN_TITLE)
printf("\033]0;%s - %s\7",OmitBBCodes(s.GetArtist()).c_str(), OmitBBCodes(s.GetTitle()).c_str());
else
printf("\033]0;%s\7",s.GetShortFilename().c_str());*/
//wHeader->WriteXY(0, 0, "Song: " + (string)song->artist + " - " + (string)song->title);
if (!mPlaylist->Empty()) if (!mPlaylist->Empty())
{ {
if (now_playing >= 0) if (old_playing >= 0)
mPlaylist->BoldOption(now_playing+1, 0); mPlaylist->BoldOption(old_playing+1, 0);
mPlaylist->BoldOption(s.GetPosition()+1, 1); mPlaylist->BoldOption(now_playing+1, 1);
now_playing = s.GetPosition();
if (current_screen == csPlaylist)
mPlaylist->Display();
} }
if (!mpd_status_get_elapsed_song_time(conn)) if (!mpd_status_get_elapsed_song_time(conn))
{
mvwhline(wFooter->RawWin(), 0, 0, 0, wFooter->GetWidth()); mvwhline(wFooter->RawWin(), 0, 0, 0, wFooter->GetWidth());
wFooter->Refresh();
}
} }
playing_song_scroll_begin = 0; playing_song_scroll_begin = 0;
} }

View File

@@ -21,11 +21,7 @@
#ifndef HAVE_WINDOW_H #ifndef HAVE_WINDOW_H
#define HAVE_WINDOW_H #define HAVE_WINDOW_H
#ifdef UTF8_ENABLED #include "ncurses.h"
# include <ncursesw/ncurses.h>
#else
# include <ncurses.h>
#endif
#include <vector> #include <vector>
#include <string> #include <string>