diff --git a/src/Makefile.am b/src/Makefile.am index cab6dac9..03ae9fdb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,10 +1,40 @@ bin_PROGRAMS = ncmpcpp -ncmpcpp_SOURCES = actions.cpp browser.cpp charset.cpp clock.cpp conv.cpp \ - curl_handle.cpp display.cpp error.cpp help.cpp helpers.cpp lastfm.cpp \ - lastfm_service.cpp lyrics.cpp lyrics_fetcher.cpp media_library.cpp menu.cpp mpdpp.cpp \ - ncmpcpp.cpp outputs.cpp playlist.cpp playlist_editor.cpp screen.cpp scrollpad.cpp \ - search_engine.cpp sel_items_adder.cpp server_info.cpp settings.cpp song.cpp song_info.cpp \ - status.cpp tag_editor.cpp tiny_tag_editor.cpp tolower.cpp visualizer.cpp \ +ncmpcpp_SOURCES = \ + actions.cpp \ + browser.cpp \ + charset.cpp \ + clock.cpp \ + conv.cpp \ + curl_handle.cpp \ + display.cpp \ + error.cpp \ + global.cpp \ + help.cpp \ + helpers.cpp \ + lastfm.cpp \ + lastfm_service.cpp \ + lyrics.cpp \ + lyrics_fetcher.cpp \ + media_library.cpp \ + menu.cpp \ + mpdpp.cpp \ + ncmpcpp.cpp \ + outputs.cpp \ + playlist.cpp \ + playlist_editor.cpp \ + screen.cpp \ + scrollpad.cpp \ + search_engine.cpp \ + sel_items_adder.cpp \ + server_info.cpp \ + settings.cpp \ + song.cpp \ + song_info.cpp \ + status.cpp \ + tag_editor.cpp \ + tiny_tag_editor.cpp \ + tolower.cpp \ + visualizer.cpp \ window.cpp # set the include path found by configure @@ -12,9 +42,37 @@ INCLUDES= $(all_includes) # the library search path. ncmpcpp_LDFLAGS = $(all_libraries) -noinst_HEADERS = browser.h charset.h clock.h conv.h curl_handle.h display.h \ - error.h global.h help.h helpers.h lastfm.h lastfm_service.h lyrics.h \ - lyrics_fetcher.h macro_utilities.h media_library.h menu.h mpdpp.h outputs.h \ - playlist_editor.h screen.h scrollpad.h search_engine.h sel_items_adder.h server_info.h \ - settings.h song.h song_info.h tag_editor.h tiny_tag_editor.h tolower.h \ - visualizer.h window.h +noinst_HEADERS = \ + browser.h \ + charset.h \ + clock.h \ + conv.h \ + curl_handle.h \ + display.h \ + error.h \ + global.h \ + help.h \ + helpers.h \ + lastfm.h \ + lastfm_service.h \ + lyrics.h \ + lyrics_fetcher.h \ + macro_utilities.h \ + media_library.h \ + menu.h \ + mpdpp.h \ + outputs.h \ + playlist_editor.h \ + screen.h \ + scrollpad.h \ + search_engine.h \ + sel_items_adder.h \ + server_info.h \ + settings.h \ + song.h \ + song_info.h \ + tag_editor.h \ + tiny_tag_editor.h \ + tolower.h \ + visualizer.h \ + window.h diff --git a/src/actions.cpp b/src/actions.cpp index 1f9d1e46..0adee22e 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -162,7 +162,7 @@ void Action::ResizeScreen() } # endif - RedrawHeader = 1; + RedrawHeader = true; MainHeight = LINES-(Config.new_design ? 7 : 4); ValidateScreenSize(); @@ -184,7 +184,7 @@ void Action::ResizeScreen() wFooter->Resize(COLS, Config.statusbar_visibility ? 2 : 1); ApplyToVisibleWindows(&BasicScreen::Refresh); - RedrawStatusbar = 1; + RedrawStatusbar = true; MPD::StatusChanges changes; if (!Mpd.isPlaying() || DesignChanged) { @@ -199,7 +199,7 @@ void Action::ResizeScreen() NcmpcppStatusChanged(&Mpd, changes, 0); if (DesignChanged) { - RedrawStatusbar = 1; + RedrawStatusbar = true; NcmpcppStatusChanged(&Mpd, MPD::StatusChanges(), 0); DesignChanged = 0; ShowMessage("User interface: %s", Config.new_design ? "Alternative" : "Classic"); diff --git a/src/browser.cpp b/src/browser.cpp index 9d2ba0af..fbf12350 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -108,7 +108,7 @@ void Browser::SwitchTo() if (myScreen != this && myScreen->isTabbable()) Global::myPrevScreen = myScreen; myScreen = this; - RedrawHeader = 1; + RedrawHeader = true; } std::basic_string Browser::Title() @@ -129,7 +129,7 @@ void Browser::EnterPressed() case itDirectory: { GetDirectory(item.name, itsBrowsedDir); - RedrawHeader = 1; + RedrawHeader = true; break; } case itSong: @@ -222,7 +222,7 @@ void Browser::MouseButtonPressed(MEVENT me) if (me.bstate & BUTTON1_PRESSED) { GetDirectory(w->Current().name); - RedrawHeader = 1; + RedrawHeader = true; } else { @@ -527,7 +527,7 @@ void Browser::ChangeBrowseMode() itsBrowsedDir.resize(itsBrowsedDir.length()-1); w->Reset(); GetDirectory(itsBrowsedDir); - RedrawHeader = 1; + RedrawHeader = true; } bool Browser::DeleteItem(const MPD::Item &item) diff --git a/src/clock.cpp b/src/clock.cpp index c424bda7..a7391fa9 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -102,7 +102,7 @@ void Clock::SwitchTo() if (myScreen != this && myScreen->isTabbable()) Global::myPrevScreen = myScreen; myScreen = this; - Global::RedrawHeader = 1; + Global::RedrawHeader = true; Prepare(); itsPane->Refresh(); // clearing screen apparently fixes the problem with last digits being misrendered diff --git a/src/error.h b/src/error.h index 0e85ff31..60b32514 100644 --- a/src/error.h +++ b/src/error.h @@ -21,17 +21,11 @@ #ifndef _ERROR_H #define _ERROR_H -#if defined(__GNUC__) && __GNUC__ >= 3 -# define GNUC_NORETURN __attribute__((noreturn)) -#else -# define GNUC_NORETURN -#endif - #include +#include "gcc.h" #define Error(msg) std::cerr << "ncmpcpp: " << msg; void FatalError(const std::string &msg) GNUC_NORETURN; #endif - diff --git a/src/gcc.h b/src/gcc.h index e64c9ff1..2e1cb083 100644 --- a/src/gcc.h +++ b/src/gcc.h @@ -19,9 +19,11 @@ ***************************************************************************/ #if defined(__GNUC__) && __GNUC__ >= 3 +# define GNUC_NORETURN __attribute__((noreturn)) # define GNUC_UNUSED __attribute__((unused)) # define GNUC_PRINTF(a, b) __attribute__((format(printf, a, b))) #else +# define GNUC_NORETURN # define GNUC_UNUSED # define GNUC_PRINTF(a, b) #endif diff --git a/src/global.h b/src/global.h index 4e936c32..6afa184d 100644 --- a/src/global.h +++ b/src/global.h @@ -29,27 +29,51 @@ namespace Global { + // currently active screen (displayed in main window) extern BasicScreen *myScreen; - extern BasicScreen *myOldScreen; // for info, lyrics, popups - extern BasicScreen *myPrevScreen; // "real" screen switching (browser, search, etc.) - extern BasicScreen *myLockedScreen; // points at the screen that was locked (or is null if no screen is locked) - extern BasicScreen *myInactiveScreen; // points at inactive screen, if locking was enabled and two screens are displayed + // for info, lyrics, popups to remember which screen return to + extern BasicScreen *myOldScreen; + + // "real" screen switching (browser, search, etc.) + extern BasicScreen *myPrevScreen; + + // points at the screen that was locked (or is null if no screen is locked) + extern BasicScreen *myLockedScreen; + + // points at inactive screen, if locking was enabled and two screens are displayed + extern BasicScreen *myInactiveScreen; + + // header window (above main window) extern Window *wHeader; + + // footer window (below main window) extern Window *wFooter; + // Y coordinate of top of main window extern size_t MainStartY; + + // height of main window extern size_t MainHeight; - extern bool MessagesAllowed; + // indicates whether messages from ShowMessage function should be shown + extern bool ShowMessages; + + // indicates whether seeking action in currently in progress extern bool SeekingInProgress; + + // indicates whether header should be immediately repainted extern bool RedrawHeader; + + // indicates whether statusbar should be immediately repainted extern bool RedrawStatusbar; + // string that represents volume in right top corner. being global + // to be used for calculating width offsets in various files. extern std::string VolumeState; + // global timer extern timeval Timer; } #endif - diff --git a/src/help.cpp b/src/help.cpp index a6e9e6c9..2619c10b 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -67,7 +67,7 @@ void Help::SwitchTo() if (myScreen != this && myScreen->isTabbable()) Global::myPrevScreen = myScreen; myScreen = this; - Global::RedrawHeader = 1; + Global::RedrawHeader = true; } diff --git a/src/lastfm.cpp b/src/lastfm.cpp index 6ea4c814..179a5ca5 100644 --- a/src/lastfm.cpp +++ b/src/lastfm.cpp @@ -104,7 +104,7 @@ void Lastfm::SwitchTo() myOldScreen = myScreen; myScreen = this; - Global::RedrawHeader = 1; + Global::RedrawHeader = true; } void Lastfm::Load() diff --git a/src/lyrics.cpp b/src/lyrics.cpp index fc106d0c..cfe89d4a 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -78,7 +78,7 @@ void Lyrics::Update() const MPD::Song *s = myPlaylist->NowPlayingSong(); if (s && !s->GetArtist().empty() && !s->GetTitle().empty()) { - Global::RedrawHeader = 1; + Global::RedrawHeader = true; itsScrollBegin = 0; itsSong = *s; Load(); @@ -125,7 +125,7 @@ void Lyrics::SwitchTo() itsSong = *s; Load(); - Global::RedrawHeader = 1; + Global::RedrawHeader = true; } else { diff --git a/src/media_library.cpp b/src/media_library.cpp index 362479fb..4d6a7cd7 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -185,7 +185,7 @@ void MediaLibrary::SwitchTo() if (myScreen != this && myScreen->isTabbable()) Global::myPrevScreen = myScreen; myScreen = this; - Global::RedrawHeader = 1; + Global::RedrawHeader = true; Refresh(); UpdateSongList(Songs); } diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index f2e936b1..68cf98cd 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -41,25 +41,6 @@ #include "status.h" #include "visualizer.h" -using namespace Global; -using namespace MPD; - -BasicScreen *Global::myScreen; -BasicScreen *Global::myOldScreen; -BasicScreen *Global::myPrevScreen; -BasicScreen *Global::myLockedScreen; -BasicScreen *Global::myInactiveScreen; - -Window *Global::wHeader; -Window *Global::wFooter; - -size_t Global::MainStartY; -size_t Global::MainHeight; - -bool Global::MessagesAllowed = 0; -bool Global::SeekingInProgress = 0; -bool Global::RedrawHeader = 1; - namespace { std::ofstream errorlog; @@ -94,6 +75,20 @@ namespace int main(int argc, char **argv) { + using Global::myScreen; + using Global::myOldScreen; + using Global::myPrevScreen; + using Global::myLockedScreen; + using Global::myInactiveScreen; + + using Global::wHeader; + using Global::wFooter; + + using Global::RedrawHeader; + using Global::ShowMessages; + using Global::VolumeState; + using Global::Timer; + srand(time(0)); setlocale(LC_ALL, ""); @@ -212,7 +207,7 @@ int main(int argc, char **argv) wFooter->AddFDCallback(Mpd.GetFD(), StatusbarMPDCallback); Mpd.OrderDataFetching(); // we need info about new connection } - MessagesAllowed = 0; + ShowMessages = false; # ifdef ENABLE_VISUALIZER myVisualizer->ResetFD(); if (myScreen == myVisualizer) @@ -224,7 +219,7 @@ int main(int argc, char **argv) TraceMpdStatus(); - MessagesAllowed = 1; + ShowMessages = true; if (Action::OrderResize) Action::ResizeScreen(); @@ -234,7 +229,7 @@ int main(int argc, char **argv) && (myScreen == myPlaylist || myScreen == myBrowser || myScreen == myLyrics) ) { - RedrawHeader = 1; + RedrawHeader = true; gettimeofday(&past, 0); } if (Config.header_visibility && RedrawHeader) @@ -258,7 +253,7 @@ int main(int argc, char **argv) *wHeader << clEnd; } wHeader->Refresh(); - RedrawHeader = 0; + RedrawHeader = false; } // header stuff end diff --git a/src/outputs.cpp b/src/outputs.cpp index 492fdc2e..15664c8e 100644 --- a/src/outputs.cpp +++ b/src/outputs.cpp @@ -64,7 +64,7 @@ void Outputs::SwitchTo() myScreen = this; w->Window::Clear(); - Global::RedrawHeader = 1; + Global::RedrawHeader = true; } void Outputs::Resize() diff --git a/src/playlist.cpp b/src/playlist.cpp index dc04fa7a..7d9185a5 100644 --- a/src/playlist.cpp +++ b/src/playlist.cpp @@ -34,7 +34,7 @@ using Global::MainStartY; Playlist *myPlaylist = new Playlist; bool Playlist::ReloadTotalLength = 0; -bool Playlist::ReloadRemaining = 0; +bool Playlist::ReloadRemaining = false; const size_t Playlist::SortOptions = 10; const size_t Playlist::SortDialogWidth = 30; @@ -112,7 +112,7 @@ void Playlist::SwitchTo() EnableHighlighting(); if (w != Items) // even if sorting window is active, background has to be refreshed anyway Items->Display(); - Global::RedrawHeader = 1; + Global::RedrawHeader = true; } void Playlist::Resize() @@ -460,7 +460,7 @@ std::string Playlist::TotalLength() itsRemainingTime = 0; for (size_t i = NowPlaying; i < Items->Size(); ++i) itsRemainingTime += (*Items)[i].GetTotalLength(); - ReloadRemaining = 0; + ReloadRemaining = false; } result << '(' << Items->Size() << (Items->Size() == 1 ? " item" : " items"); diff --git a/src/playlist_editor.cpp b/src/playlist_editor.cpp index 4597f798..c181277c 100644 --- a/src/playlist_editor.cpp +++ b/src/playlist_editor.cpp @@ -121,7 +121,7 @@ void PlaylistEditor::SwitchTo() if (myScreen != this && myScreen->isTabbable()) Global::myPrevScreen = myScreen; myScreen = this; - Global::RedrawHeader = 1; + Global::RedrawHeader = true; Refresh(); UpdateSongList(Content); } diff --git a/src/search_engine.cpp b/src/search_engine.cpp index 48fa33f8..5d403241 100644 --- a/src/search_engine.cpp +++ b/src/search_engine.cpp @@ -113,7 +113,7 @@ void SearchEngine::SwitchTo() if (myScreen != this && myScreen->isTabbable()) Global::myPrevScreen = myScreen; myScreen = this; - Global::RedrawHeader = 1; + Global::RedrawHeader = true; if (!w->Back().first) { diff --git a/src/song_info.cpp b/src/song_info.cpp index 28a74af2..8520a305 100644 --- a/src/song_info.cpp +++ b/src/song_info.cpp @@ -89,7 +89,7 @@ void SongInfo::SwitchTo() myOldScreen = myScreen; myScreen = this; - Global::RedrawHeader = 1; + Global::RedrawHeader = true; w->Clear(); w->Reset(); diff --git a/src/status.cpp b/src/status.cpp index a32109f9..dbed4d0d 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -43,14 +43,12 @@ using Global::myScreen; using Global::myLockedScreen; using Global::myInactiveScreen; -using Global::wFooter; -using Global::Timer; -using Global::wHeader; -using Global::VolumeState; -bool Global::RedrawStatusbar = 0; -std::string Global::VolumeState; -timeval Global::Timer; +using Global::wFooter; +using Global::wHeader; + +using Global::Timer; +using Global::VolumeState; namespace { @@ -191,7 +189,6 @@ void NcmpcppErrorCallback(MPD::Connection *, int errorid, const char *msg, void // for errorid: // - 0-7 bits define MPD_ERROR_* codes, compare them with (0xff & errorid) // - 8-15 bits define MPD_SERVER_ERROR_* codes, compare them with (errorid >> 8) - if ((errorid >> 8) == MPD_SERVER_ERROR_PERMISSION) { wFooter->SetGetStringHelper(0); @@ -262,8 +259,8 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) } FreeSongList(list); - Playlist::ReloadTotalLength = 1; - Playlist::ReloadRemaining = 1; + Playlist::ReloadTotalLength = true; + Playlist::ReloadRemaining = true; if (myPlaylist->Items->Empty()) { @@ -330,7 +327,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) if (!np.Empty()) WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); player_state = Config.new_design ? "[playing]" : "Playing: "; - Playlist::ReloadRemaining = 1; + Playlist::ReloadRemaining = true; if (Mpd.GetOldState() == MPD::psStop) // show track info in status immediately changed.ElapsedTime = 1; break; @@ -345,7 +342,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) WindowTitle("ncmpcpp ver. "VERSION); if (!block_progressbar_update) DrawProgressbar(0, 0); - Playlist::ReloadRemaining = 1; + Playlist::ReloadRemaining = true; myPlaylist->NowPlaying = -1; if (Config.new_design) { @@ -403,7 +400,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) if (Config.now_playing_lyrics && isVisible(myLyrics) && Global::myOldScreen == myPlaylist) myLyrics->ReloadNP = 1; } - Playlist::ReloadRemaining = 1; + Playlist::ReloadRemaining = true; playing_song_scroll_begin = 0; first_line_scroll_begin = 0; second_line_scroll_begin = 0; @@ -497,7 +494,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) } if (!block_progressbar_update) DrawProgressbar(Mpd.GetElapsedTime(), Mpd.GetTotalTime()); - Global::RedrawStatusbar = 0; + Global::RedrawStatusbar = false; } else { @@ -676,7 +673,7 @@ void DrawProgressbar(unsigned elapsed, unsigned time) void ShowMessage(const char *format, ...) { - if (Global::MessagesAllowed && allow_statusbar_unlock) + if (Global::ShowMessages && allow_statusbar_unlock) { time(&time_of_statusbar_lock); lock_statusbar_delay = Config.message_delay_time; diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index b6aaa831..e2ab7f9e 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -208,7 +208,7 @@ void TagEditor::SwitchTo() if (myScreen != this && myScreen->isTabbable()) Global::myPrevScreen = myScreen; myScreen = this; - Global::RedrawHeader = 1; + Global::RedrawHeader = true; Refresh(); } diff --git a/src/tiny_tag_editor.cpp b/src/tiny_tag_editor.cpp index 36ea5e7a..f2d62dfd 100644 --- a/src/tiny_tag_editor.cpp +++ b/src/tiny_tag_editor.cpp @@ -80,7 +80,7 @@ void TinyTagEditor::SwitchTo() myOldScreen = myScreen; myScreen = this; - Global::RedrawHeader = 1; + Global::RedrawHeader = true; } else { diff --git a/src/visualizer.cpp b/src/visualizer.cpp index 43cb2e1b..59b20c53 100644 --- a/src/visualizer.cpp +++ b/src/visualizer.cpp @@ -88,7 +88,7 @@ void Visualizer::SwitchTo() if (itsFifo >= 0) Global::wFooter->SetTimeout(WindowTimeout); - Global::RedrawHeader = 1; + Global::RedrawHeader = true; } void Visualizer::Resize()