some general source code tweaks
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -108,7 +108,7 @@ void Browser::SwitchTo()
|
||||
if (myScreen != this && myScreen->isTabbable())
|
||||
Global::myPrevScreen = myScreen;
|
||||
myScreen = this;
|
||||
RedrawHeader = 1;
|
||||
RedrawHeader = true;
|
||||
}
|
||||
|
||||
std::basic_string<my_char_t> 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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 <string>
|
||||
#include "gcc.h"
|
||||
|
||||
#define Error(msg) std::cerr << "ncmpcpp: " << msg;
|
||||
|
||||
void FatalError(const std::string &msg) GNUC_NORETURN;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
36
src/global.h
36
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
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ void Help::SwitchTo()
|
||||
if (myScreen != this && myScreen->isTabbable())
|
||||
Global::myPrevScreen = myScreen;
|
||||
myScreen = this;
|
||||
Global::RedrawHeader = 1;
|
||||
Global::RedrawHeader = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ void Lastfm::SwitchTo()
|
||||
myOldScreen = myScreen;
|
||||
myScreen = this;
|
||||
|
||||
Global::RedrawHeader = 1;
|
||||
Global::RedrawHeader = true;
|
||||
}
|
||||
|
||||
void Lastfm::Load()
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ void Outputs::SwitchTo()
|
||||
myScreen = this;
|
||||
w->Window::Clear();
|
||||
|
||||
Global::RedrawHeader = 1;
|
||||
Global::RedrawHeader = true;
|
||||
}
|
||||
|
||||
void Outputs::Resize()
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -89,7 +89,7 @@ void SongInfo::SwitchTo()
|
||||
myOldScreen = myScreen;
|
||||
myScreen = this;
|
||||
|
||||
Global::RedrawHeader = 1;
|
||||
Global::RedrawHeader = true;
|
||||
|
||||
w->Clear();
|
||||
w->Reset();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -208,7 +208,7 @@ void TagEditor::SwitchTo()
|
||||
if (myScreen != this && myScreen->isTabbable())
|
||||
Global::myPrevScreen = myScreen;
|
||||
myScreen = this;
|
||||
Global::RedrawHeader = 1;
|
||||
Global::RedrawHeader = true;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ void TinyTagEditor::SwitchTo()
|
||||
|
||||
myOldScreen = myScreen;
|
||||
myScreen = this;
|
||||
Global::RedrawHeader = 1;
|
||||
Global::RedrawHeader = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -88,7 +88,7 @@ void Visualizer::SwitchTo()
|
||||
|
||||
if (itsFifo >= 0)
|
||||
Global::wFooter->SetTimeout(WindowTimeout);
|
||||
Global::RedrawHeader = 1;
|
||||
Global::RedrawHeader = true;
|
||||
}
|
||||
|
||||
void Visualizer::Resize()
|
||||
|
||||
Reference in New Issue
Block a user