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
AM_PROG_LIBTOOL
CPPFLAGS="$CPPFLAGS `taglib-config --cflags`"
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]))
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)

View File

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

View File

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

View File

@@ -22,7 +22,7 @@
extern ncmpcpp_config Config;
string EMPTY;
string EMPTY_TAG;
string UNKNOWN_ARTIST;
string UNKNOWN_TITLE;
string UNKNOWN_ALBUM;
@@ -30,7 +30,7 @@ string UNKNOWN_ALBUM;
void DefineEmptyTags()
{
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_TITLE = "[" + et_col + "]<no title>[/" + et_col + "]";
UNKNOWN_ALBUM = "[" + et_col + "]<no album>[/" + et_col + "]";
@@ -115,17 +115,17 @@ bool Song::Empty() 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
{
return itsGetEmptyFields ? (itsShortName.empty() ? "" : itsShortName) : (itsShortName.empty() ? EMPTY : itsShortName);
return itsGetEmptyFields ? (itsShortName.empty() ? "" : itsShortName) : (itsShortName.empty() ? EMPTY_TAG : itsShortName);
}
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
@@ -145,21 +145,21 @@ string Song::GetAlbum() 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
{
return itsGetEmptyFields ? (itsYear.empty() ? "" : itsYear) : (itsYear.empty() ? EMPTY : itsYear);
return itsGetEmptyFields ? (itsYear.empty() ? "" : itsYear) : (itsYear.empty() ? EMPTY_TAG : itsYear);
}
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
{
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
#define HAVE_SONG_H
#include <libmpd/libmpd.h>
#include "libmpd/libmpd.h"
#include <cstdlib>
#include <string>
#include <sstream>

View File

@@ -31,7 +31,7 @@ extern ncmpcpp_config Config;
extern Menu *mPlaylist;
extern Menu *mBrowser;
extern Menu *mCurrent;
extern Menu *wCurrent;
extern Menu *mSearcher;
extern Window *wHeader;
@@ -51,8 +51,6 @@ extern int playing_song_scroll_begin;
extern int block_statusbar_update_delay;
extern long long current_playlist_id;
extern string browsed_dir;
extern string player_state;
@@ -73,6 +71,8 @@ extern bool block_progressbar_update;
extern bool block_statusbar_update;
extern bool block_playlist_update;
int old_playing;
void TraceMpdStatus()
{
mpd_status_update(conn);
@@ -119,6 +119,12 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
wFooter->Bold(1);
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 (!block_playlist_update)
@@ -143,18 +149,14 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
{
vPlaylist.push_back(playlist->song);
Song &s = vPlaylist.back();
if (mpd_player_get_current_song_pos(conn) != s.GetPosition())
if (now_playing != s.GetPosition())
mPlaylist->AddOption(DisplaySong(s));
else
{
now_playing = mpd_player_get_current_song_pos(conn);
mPlaylist->AddBoldOption(DisplaySong(s));
}
}
}
mpd_data_free(playlist);
current_playlist_id = mpd_playlist_get_playlist_id(conn);
if (current_screen == csPlaylist)
{
if (!playlist_length || mPlaylist->MaxChoice() < mPlaylist->GetHeight())
@@ -166,8 +168,7 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
{
int i = 1;
mPlaylist->BoldOption(now_playing+1, 0);
now_playing = mpd_player_get_current_song_pos(conn);
mPlaylist->BoldOption(old_playing+1, 0);
mPlaylist->BoldOption(now_playing+1, 1);
playlist = mpd_playlist_get_changes(conn, -1);
@@ -185,8 +186,6 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
playlist = mpd_data_get_next(playlist);
}
mpd_data_free(playlist);
if (current_screen == csPlaylist)
mPlaylist->Refresh();
}
}
@@ -207,8 +206,6 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
bold = 0;
}
}
if (current_screen == csBrowser)
mBrowser->Refresh();
}
if (!vSearched.empty())
{
@@ -222,21 +219,47 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
mSearcher->BoldOption(i+1, bold);
bold = 0;
}
if (current_screen == csSearcher)
mSearcher->Refresh();
}
}
if(what & MPD_CST_DATABASE)
{
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))
{
mpd_Song *song = mpd_playlist_get_current_song(conn);
if (song)
Song &s = vPlaylist[now_playing];
if (!player_state.empty())
{
Song s = song;
WindowTitle(DisplaySong(s, Config.song_window_title_format));
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() + "]";
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->Bold(0);
@@ -257,17 +280,16 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
# else
playing_song += " ** ";
# endif
const int scrollsize = max_length_without_scroll+4;
const int scrollsize = max_length_without_scroll+playing_song.length();
ncmpcpp_string_t part = playing_song.substr(playing_song_scroll_begin++, scrollsize);
if (part.length() < scrollsize)
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())
playing_song_scroll_begin = 0;
}
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->WriteXY(wFooter->GetWidth()-tracklength.length(), 1, tracklength);
@@ -283,48 +305,9 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
wFooter->SetColor(Config.statusbar_color);
}
}
}
if (what & MPD_CST_STATE)
{
string state;
int mpd_state = mpd_player_get_state(conn);
switch (mpd_state)
else
{
case MPD_PLAYER_PLAY:
{
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
if (!block_statusbar_update)
wFooter->WriteXY(0, 1, "", 1);
}
}
@@ -374,25 +357,14 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
if (!vPlaylist.empty() && id >= 0)
{
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 (now_playing >= 0)
mPlaylist->BoldOption(now_playing+1, 0);
mPlaylist->BoldOption(s.GetPosition()+1, 1);
now_playing = s.GetPosition();
if (current_screen == csPlaylist)
mPlaylist->Display();
if (old_playing >= 0)
mPlaylist->BoldOption(old_playing+1, 0);
mPlaylist->BoldOption(now_playing+1, 1);
}
if (!mpd_status_get_elapsed_song_time(conn))
{
mvwhline(wFooter->RawWin(), 0, 0, 0, wFooter->GetWidth());
wFooter->Refresh();
}
}
playing_song_scroll_begin = 0;
}

View File

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