abstract shared parts of switchTo methods away

This commit is contained in:
Andrzej Rybczak
2012-09-15 22:27:50 +02:00
parent f7dba0a578
commit 14587cb4ec
46 changed files with 301 additions and 463 deletions

View File

@@ -87,6 +87,7 @@ noinst_HEADERS = \
regex_filter.h \ regex_filter.h \
regexes.h \ regexes.h \
screen.h \ screen.h \
screen_switcher.h \
scrollpad.h \ scrollpad.h \
search_engine.h \ search_engine.h \
sel_items_adder.h \ sel_items_adder.h \

View File

@@ -2284,15 +2284,10 @@ void Quit::Run()
void NextScreen::Run() void NextScreen::Run()
{ {
using Global::myOldScreen;
using Global::myPrevScreen;
if (Config.screen_switcher_previous) if (Config.screen_switcher_previous)
{ {
if (myScreen->isTabbable()) if (auto tababble = dynamic_cast<Tabbable *>(myScreen))
myPrevScreen->switchTo(); tababble->switchToPreviousScreen();
else
myOldScreen->switchTo();
} }
else if (!Config.screens_seq.empty()) else if (!Config.screens_seq.empty())
{ {
@@ -2306,15 +2301,10 @@ void NextScreen::Run()
void PreviousScreen::Run() void PreviousScreen::Run()
{ {
using Global::myOldScreen;
using Global::myPrevScreen;
if (Config.screen_switcher_previous) if (Config.screen_switcher_previous)
{ {
if (myScreen->isTabbable()) if (auto tababble = dynamic_cast<Tabbable *>(myScreen))
myPrevScreen->switchTo(); tababble->switchToPreviousScreen();
else
myOldScreen->switchTo();
} }
else if (!Config.screens_seq.empty()) else if (!Config.screens_seq.empty())
{ {
@@ -2326,24 +2316,27 @@ void PreviousScreen::Run()
} }
} }
#ifdef HAVE_TAGLIB_H
bool ShowHelp::canBeRun() const bool ShowHelp::canBeRun() const
{ {
return myScreen != myTinyTagEditor; return myScreen != myHelp
} # ifdef HAVE_TAGLIB_H
&& myScreen != myTinyTagEditor
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H
;
}
void ShowHelp::Run() void ShowHelp::Run()
{ {
myHelp->switchTo(); myHelp->switchTo();
} }
#ifdef HAVE_TAGLIB_H
bool ShowPlaylist::canBeRun() const bool ShowPlaylist::canBeRun() const
{ {
return myScreen != myTinyTagEditor; return myScreen != myPlaylist
} # ifdef HAVE_TAGLIB_H
&& myScreen != myTinyTagEditor;
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H
}
void ShowPlaylist::Run() void ShowPlaylist::Run()
{ {
@@ -2386,12 +2379,13 @@ void ShowMediaLibrary::Run()
myLibrary->switchTo(); myLibrary->switchTo();
} }
#ifdef HAVE_TAGLIB_H
bool ShowPlaylistEditor::canBeRun() const bool ShowPlaylistEditor::canBeRun() const
{ {
return myScreen != myTinyTagEditor; return myScreen != myPlaylistEditor
} # ifdef HAVE_TAGLIB_H
&& myScreen != myTinyTagEditor;
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H
}
void ShowPlaylistEditor::Run() void ShowPlaylistEditor::Run()
{ {
@@ -2401,7 +2395,8 @@ void ShowPlaylistEditor::Run()
bool ShowTagEditor::canBeRun() const bool ShowTagEditor::canBeRun() const
{ {
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
return myScreen != myTinyTagEditor; return myScreen != myTagEditor
&& myScreen != myTinyTagEditor;
# else # else
return false; return false;
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H
@@ -2418,11 +2413,11 @@ void ShowTagEditor::Run()
bool ShowOutputs::canBeRun() const bool ShowOutputs::canBeRun() const
{ {
# ifdef ENABLE_OUTPUTS # ifdef ENABLE_OUTPUTS
return myScreen != myOutputs
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
return myScreen != myTinyTagEditor; && myScreen != myTinyTagEditor
# else
return true;
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H
;
# else # else
return false; return false;
# endif // ENABLE_OUTPUTS # endif // ENABLE_OUTPUTS
@@ -2437,15 +2432,15 @@ void ShowOutputs::Run()
bool ShowVisualizer::canBeRun() const bool ShowVisualizer::canBeRun() const
{ {
# ifdef ENABLE_OUTPUTS # ifdef ENABLE_VISUALIZER
return myScreen != myVisualizer
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
return myScreen != myTinyTagEditor; && myScreen != myTinyTagEditor
# else
return true;
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H
;
# else # else
return false; return false;
# endif // ENABLE_OUTPUTS # endif // ENABLE_VISUALIZER
} }
void ShowVisualizer::Run() void ShowVisualizer::Run()
@@ -2458,11 +2453,11 @@ void ShowVisualizer::Run()
bool ShowClock::canBeRun() const bool ShowClock::canBeRun() const
{ {
# ifdef ENABLE_CLOCK # ifdef ENABLE_CLOCK
return myScreen != myClock
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
return myScreen != myTinyTagEditor; && myScreen != myTinyTagEditor
# else
return true;
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H
;
# else # else
return false; return false;
# endif // ENABLE_CLOCK # endif // ENABLE_CLOCK

View File

@@ -979,9 +979,7 @@ struct ShowHelp : public Action
ShowHelp() : Action(aShowHelp, "show_help") { } ShowHelp() : Action(aShowHelp, "show_help") { }
protected: protected:
# ifdef HAVE_TAGLIB_H
virtual bool canBeRun() const; virtual bool canBeRun() const;
# endif // HAVE_TAGLIB_H
virtual void Run(); virtual void Run();
}; };
@@ -990,9 +988,7 @@ struct ShowPlaylist : public Action
ShowPlaylist() : Action(aShowPlaylist, "show_playlist") { } ShowPlaylist() : Action(aShowPlaylist, "show_playlist") { }
protected: protected:
# ifdef HAVE_TAGLIB_H
virtual bool canBeRun() const; virtual bool canBeRun() const;
# endif // HAVE_TAGLIB_H
virtual void Run(); virtual void Run();
}; };
@@ -1034,9 +1030,7 @@ struct ShowPlaylistEditor : public Action
ShowPlaylistEditor() : Action(aShowPlaylistEditor, "show_playlist_editor") { } ShowPlaylistEditor() : Action(aShowPlaylistEditor, "show_playlist_editor") { }
protected: protected:
# ifdef HAVE_TAGLIB_H
virtual bool canBeRun() const; virtual bool canBeRun() const;
# endif // HAVE_TAGLIB_H
virtual void Run(); virtual void Run();
}; };

View File

@@ -38,6 +38,7 @@
#include "utility/comparators.h" #include "utility/comparators.h"
#include "title.h" #include "title.h"
#include "tags.h" #include "tags.h"
#include "screen_switcher.h"
using namespace std::placeholders; using namespace std::placeholders;
@@ -87,35 +88,27 @@ void Browser::resize()
void Browser::switchTo() void Browser::switchTo()
{ {
using Global::myLockedScreen;
using Global::myInactiveScreen;
if (myScreen == this) if (myScreen == this)
{ {
# ifndef WIN32 # ifndef WIN32
myBrowser->ChangeBrowseMode(); ChangeBrowseMode();
# endif // !WIN32 # endif // !WIN32
} }
else
if (myLockedScreen) {
updateInactiveScreen(this); SwitchTo::execute(this);
if (hasToBeResized || myLockedScreen)
resize();
if (isLocal() && Config.browser_sort_mode == smMTime) // local browser doesn't support sorting by mtime if (isLocal() && Config.browser_sort_mode == smMTime) // local browser doesn't support sorting by mtime
Config.browser_sort_mode = smName; Config.browser_sort_mode = smName;
if (w.empty()) if (w.empty())
myBrowser->GetDirectory(itsBrowsedDir); GetDirectory(itsBrowsedDir);
else else
markSongsInPlaylist(getProxySongList()); markSongsInPlaylist(getProxySongList());
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
drawHeader(); drawHeader();
} }
}
std::wstring Browser::title() std::wstring Browser::title()
{ {

View File

@@ -25,7 +25,7 @@
#include "mpdpp.h" #include "mpdpp.h"
#include "screen.h" #include "screen.h"
struct Browser : public Screen<NC::Menu<MPD::Item>>, public Filterable, public HasSongs, public Searchable struct Browser: Screen<NC::Menu<MPD::Item>>, Filterable, HasSongs, Searchable, Tabbable
{ {
Browser(); Browser();
@@ -41,7 +41,6 @@ struct Browser : public Screen<NC::Menu<MPD::Item>>, public Filterable, public H
virtual void spacePressed() OVERRIDE; virtual void spacePressed() OVERRIDE;
virtual void mouseButtonPressed(MEVENT me) OVERRIDE; virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isTabbable() OVERRIDE { return true; }
virtual bool isMergable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; }
// Filterable implementation // Filterable implementation

View File

@@ -33,6 +33,7 @@
#include "status.h" #include "status.h"
#include "statusbar.h" #include "statusbar.h"
#include "title.h" #include "title.h"
#include "screen_switcher.h"
using Global::MainHeight; using Global::MainHeight;
using Global::MainStartY; using Global::MainStartY;
@@ -76,30 +77,13 @@ void Clock::resize()
void Clock::switchTo() void Clock::switchTo()
{ {
using Global::myLockedScreen;
if (myScreen == this)
return;
if (myLockedScreen)
updateInactiveScreen(this);
size_t x_offset, width; size_t x_offset, width;
getWindowResizeParams(x_offset, width, false); getWindowResizeParams(x_offset, width, false);
if (Width > width || Height > MainHeight) if (Width > width || Height > MainHeight)
{
Statusbar::msg("Screen is too small to display clock"); Statusbar::msg("Screen is too small to display clock");
if (myLockedScreen) else
updateInactiveScreen(myLockedScreen); {
return; SwitchTo::execute(this);
}
if (hasToBeResized || myLockedScreen)
resize();
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
drawHeader(); drawHeader();
Prepare(); Prepare();
m_pane.refresh(); m_pane.refresh();
@@ -107,6 +91,7 @@ void Clock::switchTo()
w.clear(); w.clear();
w.display(); w.display();
} }
}
std::wstring Clock::title() std::wstring Clock::title()
{ {

View File

@@ -25,10 +25,11 @@
#ifdef ENABLE_CLOCK #ifdef ENABLE_CLOCK
#include "window.h" #include "interfaces.h"
#include "screen.h" #include "screen.h"
#include "window.h"
struct Clock : public Screen<NC::Window> struct Clock: Screen<NC::Window>, Tabbable
{ {
Clock(); Clock();
@@ -44,7 +45,6 @@ struct Clock : public Screen<NC::Window>
virtual void spacePressed() OVERRIDE { } virtual void spacePressed() OVERRIDE { }
virtual void mouseButtonPressed(MEVENT) OVERRIDE { } virtual void mouseButtonPressed(MEVENT) OVERRIDE { }
virtual bool isTabbable() OVERRIDE { return true; }
virtual bool isMergable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; }
protected: protected:

View File

@@ -23,8 +23,6 @@
namespace Global {// namespace Global {//
BasicScreen *myScreen; BasicScreen *myScreen;
BasicScreen *myOldScreen;
BasicScreen *myPrevScreen;
BasicScreen *myLockedScreen; BasicScreen *myLockedScreen;
BasicScreen *myInactiveScreen; BasicScreen *myInactiveScreen;

View File

@@ -31,12 +31,6 @@ namespace Global {//
// currently active screen (displayed in main window) // currently active screen (displayed in main window)
extern BasicScreen *myScreen; extern BasicScreen *myScreen;
// 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) // points at the screen that was locked (or is null if no screen is locked)
extern BasicScreen *myLockedScreen; extern BasicScreen *myLockedScreen;

View File

@@ -27,6 +27,7 @@
#include "status.h" #include "status.h"
#include "utility/wide_string.h" #include "utility/wide_string.h"
#include "title.h" #include "title.h"
#include "screen_switcher.h"
using Global::MainHeight; using Global::MainHeight;
using Global::MainStartY; using Global::MainStartY;
@@ -113,21 +114,7 @@ void Help::resize()
void Help::switchTo() void Help::switchTo()
{ {
using Global::myScreen; SwitchTo::execute(this);
using Global::myLockedScreen;
if (myScreen == this)
return;
if (myLockedScreen)
updateInactiveScreen(this);
if (hasToBeResized || myLockedScreen)
resize();
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
drawHeader(); drawHeader();
} }

View File

@@ -22,9 +22,10 @@
#define _HELP_H #define _HELP_H
#include "actions.h" #include "actions.h"
#include "interfaces.h"
#include "screen.h" #include "screen.h"
struct Help : public Screen<NC::Scrollpad> struct Help: Screen<NC::Scrollpad>, Tabbable
{ {
Help(); Help();
@@ -38,7 +39,6 @@ struct Help : public Screen<NC::Scrollpad>
virtual void enterPressed() OVERRIDE { } virtual void enterPressed() OVERRIDE { }
virtual void spacePressed() OVERRIDE { } virtual void spacePressed() OVERRIDE { }
virtual bool isTabbable() OVERRIDE { return true; }
virtual bool isMergable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; }
protected: protected:

View File

@@ -23,6 +23,7 @@
#include <string> #include <string>
#include "gcc.h" #include "gcc.h"
#include "screen.h"
#include "song.h" #include "song.h"
#include "proxy_song_list.h" #include "proxy_song_list.h"
@@ -59,4 +60,23 @@ struct HasColumns
virtual void nextColumn() = 0; virtual void nextColumn() = 0;
}; };
struct Tabbable
{
Tabbable() : m_previous_screen(0) { }
void switchToPreviousScreen() const {
if (m_previous_screen)
m_previous_screen->switchTo();
}
void setPreviousScreen(BasicScreen *screen) {
m_previous_screen = screen;
}
BasicScreen *previousScreen() const {
return m_previous_screen;
}
private:
BasicScreen *m_previous_screen;
};
#endif // _INTERFACES_H #endif // _INTERFACES_H

View File

@@ -39,6 +39,7 @@
#include "global.h" #include "global.h"
#include "statusbar.h" #include "statusbar.h"
#include "title.h" #include "title.h"
#include "screen_switcher.h"
using Global::MainHeight; using Global::MainHeight;
using Global::MainStartY; using Global::MainStartY;
@@ -83,28 +84,18 @@ void Lastfm::Take()
void Lastfm::switchTo() void Lastfm::switchTo()
{ {
using Global::myScreen; using Global::myScreen;
using Global::myOldScreen; if (myScreen != this)
using Global::myLockedScreen; {
SwitchTo::execute(this);
if (myScreen == this)
return myOldScreen->switchTo();
if (myLockedScreen)
updateInactiveScreen(this);
if (hasToBeResized || myLockedScreen)
resize();
// get an old info if it waits // get an old info if it waits
if (isReadyToTake) if (isReadyToTake)
Take(); Take();
Load(); Load();
myOldScreen = myScreen;
myScreen = this;
drawHeader(); drawHeader();
} }
else
switchToPreviousScreen();
}
void Lastfm::Load() void Lastfm::Load()
{ {

View File

@@ -28,10 +28,11 @@
#include <memory> #include <memory>
#include <pthread.h> #include <pthread.h>
#include "interfaces.h"
#include "lastfm_service.h" #include "lastfm_service.h"
#include "screen.h" #include "screen.h"
struct Lastfm : public Screen<NC::Scrollpad> struct Lastfm: Screen<NC::Scrollpad>, Tabbable
{ {
Lastfm(); Lastfm();
@@ -46,7 +47,6 @@ struct Lastfm : public Screen<NC::Scrollpad>
virtual void spacePressed() OVERRIDE { } virtual void spacePressed() OVERRIDE { }
virtual bool isMergable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; }
virtual bool isTabbable() OVERRIDE { return false; }
// private members // private members
void Refetch(); void Refetch();

View File

@@ -35,11 +35,10 @@
#include "song.h" #include "song.h"
#include "statusbar.h" #include "statusbar.h"
#include "title.h" #include "title.h"
#include "screen_switcher.h"
using Global::MainHeight; using Global::MainHeight;
using Global::MainStartY; using Global::MainStartY;
using Global::myScreen;
using Global::myOldScreen;
#ifdef HAVE_CURL_CURL_H #ifdef HAVE_CURL_CURL_H
LyricsFetcher **Lyrics::itsFetcher = 0; LyricsFetcher **Lyrics::itsFetcher = 0;
@@ -96,17 +95,9 @@ void Lyrics::update()
void Lyrics::switchTo() void Lyrics::switchTo()
{ {
using Global::myLockedScreen; using Global::myScreen;
using Global::myInactiveScreen; if (myScreen != this)
{
if (myScreen == this)
return myOldScreen->switchTo();
if (hasToBeResized)
resize();
itsScrollBegin = 0;
# ifdef HAVE_CURL_CURL_H # ifdef HAVE_CURL_CURL_H
// take lyrics if they were downloaded // take lyrics if they were downloaded
if (isReadyToTake) if (isReadyToTake)
@@ -125,28 +116,17 @@ void Lyrics::switchTo()
if (!s->getArtist().empty() && !s->getTitle().empty()) if (!s->getArtist().empty() && !s->getTitle().empty())
{ {
myOldScreen = myScreen; SwitchTo::execute(this);
myScreen = this; itsScrollBegin = 0;
itsSong = *s; itsSong = *s;
Load(); Load();
drawHeader(); drawHeader();
} }
else else
{
Statusbar::msg("Song must have both artist and title tag set"); Statusbar::msg("Song must have both artist and title tag set");
return;
}
// if we resize for locked screen, we have to do that in the end since
// fetching lyrics may fail (eg. if tags are missing) and we don't want
// to adjust screen size then.
if (myLockedScreen) // BUG
{
updateInactiveScreen(this);
resize();
} }
else
switchToPreviousScreen();
} }
std::wstring Lyrics::title() std::wstring Lyrics::title()
@@ -366,8 +346,7 @@ void Lyrics::Load()
void Lyrics::Edit() void Lyrics::Edit()
{ {
if (myScreen != this) assert(Global::myScreen == this);
return;
if (Config.external_editor.empty()) if (Config.external_editor.empty())
{ {

View File

@@ -24,11 +24,12 @@
#include <pthread.h> #include <pthread.h>
#include <queue> #include <queue>
#include "mpdpp.h" #include "interfaces.h"
#include "screen.h"
#include "lyrics_fetcher.h" #include "lyrics_fetcher.h"
#include "screen.h"
#include "song.h"
struct Lyrics : public Screen<NC::Scrollpad> struct Lyrics: Screen<NC::Scrollpad>, Tabbable
{ {
Lyrics(); Lyrics();
@@ -44,7 +45,6 @@ struct Lyrics : public Screen<NC::Scrollpad>
virtual void spacePressed() OVERRIDE; virtual void spacePressed() OVERRIDE;
virtual bool isMergable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; }
virtual bool isTabbable() OVERRIDE { return false; }
// private members // private members
void Edit(); void Edit();

View File

@@ -35,6 +35,7 @@
#include "utility/comparators.h" #include "utility/comparators.h"
#include "utility/type_conversions.h" #include "utility/type_conversions.h"
#include "title.h" #include "title.h"
#include "screen_switcher.h"
using namespace std::placeholders; using namespace std::placeholders;
@@ -197,16 +198,11 @@ void MediaLibrary::refresh()
void MediaLibrary::switchTo() void MediaLibrary::switchTo()
{ {
using Global::myLockedScreen;
if (myScreen == this) if (myScreen == this)
{ {
if (Config.media_library_disable_two_column_mode) if (!Config.media_library_disable_two_column_mode)
return;
else
{ {
hasTwoColumns = !hasTwoColumns; hasTwoColumns = !hasTwoColumns;
hasToBeResized = 1;
Tags.clear(); Tags.clear();
Albums.clear(); Albums.clear();
Albums.reset(); Albums.reset();
@@ -225,22 +221,18 @@ void MediaLibrary::switchTo()
} }
else else
Albums.setTitle(Config.titles_visibility ? "Albums" : ""); Albums.setTitle(Config.titles_visibility ? "Albums" : "");
}
}
if (myLockedScreen)
updateInactiveScreen(this);
if (hasToBeResized || myLockedScreen)
resize(); resize();
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
drawHeader();
markSongsInPlaylist(songsProxyList());
refresh(); refresh();
} }
}
else
{
SwitchTo::execute(this);
markSongsInPlaylist(songsProxyList());
drawHeader();
refresh();
}
}
std::wstring MediaLibrary::title() std::wstring MediaLibrary::title()
{ {

View File

@@ -24,7 +24,7 @@
#include "interfaces.h" #include "interfaces.h"
#include "screen.h" #include "screen.h"
struct MediaLibrary : public Screen<NC::Window *>, public Filterable, public HasColumns, public HasSongs, public Searchable struct MediaLibrary: Screen<NC::Window *>, Filterable, HasColumns, HasSongs, Searchable, Tabbable
{ {
MediaLibrary(); MediaLibrary();
@@ -40,7 +40,6 @@ struct MediaLibrary : public Screen<NC::Window *>, public Filterable, public Has
virtual void spacePressed() OVERRIDE; virtual void spacePressed() OVERRIDE;
virtual void mouseButtonPressed(MEVENT me) OVERRIDE; virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isTabbable() OVERRIDE { return true; }
virtual bool isMergable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; }
// Filterable implementation // Filterable implementation

View File

@@ -79,8 +79,6 @@ namespace
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
using Global::myScreen; using Global::myScreen;
using Global::myOldScreen;
using Global::myPrevScreen;
using Global::myLockedScreen; using Global::myLockedScreen;
using Global::myInactiveScreen; using Global::myInactiveScreen;
@@ -165,11 +163,6 @@ int main(int argc, char **argv)
wFooter->addFDCallback(Mpd.GetFD(), Statusbar::Helpers::mpd); wFooter->addFDCallback(Mpd.GetFD(), Statusbar::Helpers::mpd);
wFooter->createHistory(); wFooter->createHistory();
// initialize screens to browser as default previous screen
myScreen = myBrowser;
myPrevScreen = myBrowser;
myOldScreen = myBrowser;
// initialize global timer // initialize global timer
gettimeofday(&Timer, 0); gettimeofday(&Timer, 0);

View File

@@ -28,6 +28,7 @@
#include "status.h" #include "status.h"
#include "statusbar.h" #include "statusbar.h"
#include "title.h" #include "title.h"
#include "screen_switcher.h"
using Global::MainHeight; using Global::MainHeight;
using Global::MainStartY; using Global::MainStartY;
@@ -47,21 +48,7 @@ Outputs::Outputs()
void Outputs::switchTo() void Outputs::switchTo()
{ {
using Global::myLockedScreen; SwitchTo::execute(this);
if (myScreen == this)
return;
if (myLockedScreen)
updateInactiveScreen(this);
if (hasToBeResized || myLockedScreen)
resize();
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
w.Window::clear();
drawHeader(); drawHeader();
} }

View File

@@ -25,11 +25,12 @@
#ifdef ENABLE_OUTPUTS #ifdef ENABLE_OUTPUTS
#include "interfaces.h"
#include "menu.h" #include "menu.h"
#include "mpdpp.h" #include "mpdpp.h"
#include "screen.h" #include "screen.h"
struct Outputs : public Screen<NC::Menu<MPD::Output>> struct Outputs: Screen<NC::Menu<MPD::Output>>, Tabbable
{ {
Outputs(); Outputs();
@@ -45,7 +46,6 @@ struct Outputs : public Screen<NC::Menu<MPD::Output>>
virtual void spacePressed() OVERRIDE { } virtual void spacePressed() OVERRIDE { }
virtual void mouseButtonPressed(MEVENT me) OVERRIDE; virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isTabbable() OVERRIDE { return true; }
virtual bool isMergable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; }
// private members // private members

View File

@@ -27,6 +27,7 @@
#include "menu.h" #include "menu.h"
#include "playlist.h" #include "playlist.h"
#include "regex_filter.h" #include "regex_filter.h"
#include "screen_switcher.h"
#include "song.h" #include "song.h"
#include "status.h" #include "status.h"
#include "statusbar.h" #include "statusbar.h"
@@ -66,24 +67,8 @@ Playlist::Playlist() : itsTotalLength(0), itsRemainingTime(0), itsScrollBegin(0)
void Playlist::switchTo() void Playlist::switchTo()
{ {
using Global::myScreen; SwitchTo::execute(this);
using Global::myLockedScreen;
using Global::myInactiveScreen;
if (myScreen == this)
return;
itsScrollBegin = 0; itsScrollBegin = 0;
if (myLockedScreen)
updateInactiveScreen(this);
if (hasToBeResized || myLockedScreen)
resize();
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
EnableHighlighting(); EnableHighlighting();
drawHeader(); drawHeader();
} }

View File

@@ -27,7 +27,7 @@
#include "screen.h" #include "screen.h"
#include "song.h" #include "song.h"
struct Playlist : public Screen<NC::Menu<MPD::Song>>, public Filterable, public HasSongs, public Searchable struct Playlist: Screen<NC::Menu<MPD::Song>>, Filterable, HasSongs, Searchable, Tabbable
{ {
Playlist(); Playlist();
@@ -43,7 +43,6 @@ struct Playlist : public Screen<NC::Menu<MPD::Song>>, public Filterable, public
virtual void spacePressed() OVERRIDE; virtual void spacePressed() OVERRIDE;
virtual void mouseButtonPressed(MEVENT me) OVERRIDE; virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isTabbable() OVERRIDE { return true; }
virtual bool isMergable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; }
// Filterable implementation // Filterable implementation

View File

@@ -34,6 +34,7 @@
#include "tag_editor.h" #include "tag_editor.h"
#include "utility/comparators.h" #include "utility/comparators.h"
#include "title.h" #include "title.h"
#include "screen_switcher.h"
using namespace std::placeholders; using namespace std::placeholders;
@@ -116,23 +117,9 @@ void PlaylistEditor::refresh()
void PlaylistEditor::switchTo() void PlaylistEditor::switchTo()
{ {
using Global::myScreen; SwitchTo::execute(this);
using Global::myLockedScreen;
if (myScreen == this)
return;
if (myLockedScreen)
updateInactiveScreen(this);
if (hasToBeResized || myLockedScreen)
resize();
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
drawHeader();
markSongsInPlaylist(contentProxyList()); markSongsInPlaylist(contentProxyList());
drawHeader();
refresh(); refresh();
} }

View File

@@ -24,7 +24,7 @@
#include "interfaces.h" #include "interfaces.h"
#include "screen.h" #include "screen.h"
struct PlaylistEditor : public Screen<NC::Window *>, public Filterable, public HasColumns, public HasSongs, public Searchable struct PlaylistEditor: Screen<NC::Window *>, Filterable, HasColumns, HasSongs, Searchable, Tabbable
{ {
PlaylistEditor(); PlaylistEditor();
@@ -40,7 +40,6 @@ struct PlaylistEditor : public Screen<NC::Window *>, public Filterable, public H
virtual void spacePressed() OVERRIDE; virtual void spacePressed() OVERRIDE;
virtual void mouseButtonPressed(MEVENT me) OVERRIDE; virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isTabbable() OVERRIDE { return true; }
virtual bool isMergable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; }
// Filterable implementation // Filterable implementation

View File

@@ -117,6 +117,7 @@ void BasicScreen::unlock()
{ {
if (myInactiveScreen && myInactiveScreen != myLockedScreen) if (myInactiveScreen && myInactiveScreen != myLockedScreen)
myScreen = myInactiveScreen; myScreen = myInactiveScreen;
if (myScreen != myLockedScreen)
myLockedScreen->switchTo(); myLockedScreen->switchTo();
myLockedScreen = 0; myLockedScreen = 0;
myInactiveScreen = 0; myInactiveScreen = 0;

View File

@@ -73,10 +73,6 @@ struct BasicScreen
/// @see Screen::mouseButtonPressed() /// @see Screen::mouseButtonPressed()
virtual void mouseButtonPressed(MEVENT me) = 0; virtual void mouseButtonPressed(MEVENT me) = 0;
/// When this is overwritten with a function returning true, the
/// screen will be used in tab switching.
virtual bool isTabbable() = 0;
/// @return true if screen is mergable, ie. can be "proper" subwindow /// @return true if screen is mergable, ie. can be "proper" subwindow
/// if one of the screens is locked. Screens that somehow resemble popups /// if one of the screens is locked. Screens that somehow resemble popups
/// will want to return false here. /// will want to return false here.

60
src/screen_switcher.h Normal file
View File

@@ -0,0 +1,60 @@
/***************************************************************************
* Copyright (C) 2008-2012 by Andrzej Rybczak *
* electricityispower@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef _SCREEN_SWITCHER_H
#define _SCREEN_SWITCHER_H
#include "global.h"
class SwitchTo
{
template <bool ToBeExecuted, typename ScreenT> struct TabbableAction_ {
static void execute(ScreenT *) { }
};
template <typename ScreenT> struct TabbableAction_<true, ScreenT> {
static void execute(ScreenT *screen) {
using Global::myScreen;
// it has to work only if both current and previous screens are Tabbable
if (dynamic_cast<Tabbable *>(myScreen))
screen->setPreviousScreen(myScreen);
}
};
public:
template <typename ScreenT>
static void execute(ScreenT *screen)
{
using Global::myScreen;
using Global::myLockedScreen;
const bool isScreenMergable = screen->isMergable() && myLockedScreen;
const bool isScreenTabbable = std::is_base_of<Tabbable, ScreenT>::value;
assert(myScreen != screen);
if (isScreenMergable)
updateInactiveScreen(screen);
if (screen->hasToBeResized || isScreenMergable)
screen->resize();
TabbableAction_<isScreenTabbable, ScreenT>::execute(screen);
myScreen = screen;
}
};
#endif // _SCREEN_SWITCHER_H

View File

@@ -32,6 +32,7 @@
#include "statusbar.h" #include "statusbar.h"
#include "utility/comparators.h" #include "utility/comparators.h"
#include "title.h" #include "title.h"
#include "screen_switcher.h"
using namespace std::placeholders; using namespace std::placeholders;
@@ -125,29 +126,16 @@ void SearchEngine::resize()
void SearchEngine::switchTo() void SearchEngine::switchTo()
{ {
using Global::myScreen; if (Global::myScreen != this)
using Global::myLockedScreen;
if (myScreen == this)
{ {
reset(); SwitchTo::execute(this);
return;
}
if (myLockedScreen)
updateInactiveScreen(this);
if (hasToBeResized || myLockedScreen)
resize();
if (w.empty()) if (w.empty())
Prepare(); Prepare();
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
drawHeader();
markSongsInPlaylist(getProxySongList()); markSongsInPlaylist(getProxySongList());
drawHeader();
}
else
reset();
} }
std::wstring SearchEngine::title() std::wstring SearchEngine::title()

View File

@@ -73,7 +73,7 @@ struct SEItem
MPD::Song itsSong; MPD::Song itsSong;
}; };
struct SearchEngine : public Screen<NC::Menu<SEItem>>, public Filterable, public HasSongs, public Searchable struct SearchEngine: Screen<NC::Menu<SEItem>>, Filterable, HasSongs, Searchable, Tabbable
{ {
SearchEngine(); SearchEngine();
@@ -89,7 +89,6 @@ struct SearchEngine : public Screen<NC::Menu<SEItem>>, public Filterable, public
virtual void spacePressed() OVERRIDE; virtual void spacePressed() OVERRIDE;
virtual void mouseButtonPressed(MEVENT me) OVERRIDE; virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isTabbable() OVERRIDE { return true; }
virtual bool isMergable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; }
// Filterable implementation // Filterable implementation
@@ -111,7 +110,6 @@ struct SearchEngine : public Screen<NC::Menu<SEItem>>, public Filterable, public
virtual MPD::SongList getSelectedSongs() OVERRIDE; virtual MPD::SongList getSelectedSongs() OVERRIDE;
// private members // private members
static size_t StaticOptions; static size_t StaticOptions;
static size_t SearchButton; static size_t SearchButton;
static size_t ResetButton; static size_t ResetButton;

View File

@@ -29,6 +29,7 @@
#include "settings.h" #include "settings.h"
#include "statusbar.h" #include "statusbar.h"
#include "utility/comparators.h" #include "utility/comparators.h"
#include "screen_switcher.h"
SelectedItemsAdder *mySelectedItemsAdder; SelectedItemsAdder *mySelectedItemsAdder;
@@ -103,7 +104,6 @@ void SelectedItemsAdder::switchTo()
{ {
using Global::myScreen; using Global::myScreen;
assert(myScreen != this);
auto hs = hasSongs(myScreen); auto hs = hasSongs(myScreen);
if (!hs || !hs->allowsSelection()) if (!hs || !hs->allowsSelection())
return; return;
@@ -115,15 +115,10 @@ void SelectedItemsAdder::switchTo()
Statusbar::msg("List of selected items is empty"); Statusbar::msg("List of selected items is empty");
return; return;
} }
if (hasToBeResized)
resize();
populatePlaylistSelector(myScreen); populatePlaylistSelector(myScreen);
SwitchTo::execute(this);
// default to main window // default to main window
w = &m_playlist_selector; w = &m_playlist_selector;
myScreen = this;
} }
void SelectedItemsAdder::resize() void SelectedItemsAdder::resize()
@@ -141,10 +136,10 @@ void SelectedItemsAdder::resize()
(COLS-m_position_selector_width)/2, (COLS-m_position_selector_width)/2,
MainStartY+(MainHeight-m_position_selector_height)/2 MainStartY+(MainHeight-m_position_selector_height)/2
); );
if (m_old_screen && m_old_screen->hasToBeResized) // resize background window if (previousScreen() && previousScreen()->hasToBeResized) // resize background window
{ {
m_old_screen->resize(); previousScreen()->resize();
m_old_screen->refresh(); previousScreen()->refresh();
} }
hasToBeResized = 0; hasToBeResized = 0;
} }
@@ -162,7 +157,7 @@ void SelectedItemsAdder::refresh()
std::wstring SelectedItemsAdder::title() std::wstring SelectedItemsAdder::title()
{ {
return m_old_screen->title(); return previousScreen()->title();
} }
void SelectedItemsAdder::enterPressed() void SelectedItemsAdder::enterPressed()
@@ -187,7 +182,6 @@ void SelectedItemsAdder::mouseButtonPressed(MEVENT me)
void SelectedItemsAdder::populatePlaylistSelector(BasicScreen *old_screen) void SelectedItemsAdder::populatePlaylistSelector(BasicScreen *old_screen)
{ {
typedef SelectedItemsAdder Self; typedef SelectedItemsAdder Self;
m_old_screen = old_screen;
m_playlist_selector.reset(); m_playlist_selector.reset();
m_playlist_selector.clear(); m_playlist_selector.clear();
if (old_screen != myPlaylist) if (old_screen != myPlaylist)
@@ -245,7 +239,7 @@ void SelectedItemsAdder::addToExistingPlaylist(const std::string &playlist) cons
if (Mpd.CommitCommandsList()) if (Mpd.CommitCommandsList())
{ {
Statusbar::msg("Selected item(s) added to playlist \"%s\"", playlist.c_str()); Statusbar::msg("Selected item(s) added to playlist \"%s\"", playlist.c_str());
m_old_screen->switchTo(); switchToPreviousScreen();
} }
} }
@@ -301,7 +295,7 @@ void SelectedItemsAdder::addAfterHighlightedSong() const
void SelectedItemsAdder::cancel() void SelectedItemsAdder::cancel()
{ {
if (isActiveWindow(m_playlist_selector)) if (isActiveWindow(m_playlist_selector))
m_old_screen->switchTo(); switchToPreviousScreen();
else if (isActiveWindow(m_position_selector)) else if (isActiveWindow(m_position_selector))
w = &m_playlist_selector; w = &m_playlist_selector;
} }
@@ -309,7 +303,7 @@ void SelectedItemsAdder::cancel()
void SelectedItemsAdder::exitSuccessfully() const void SelectedItemsAdder::exitSuccessfully() const
{ {
Statusbar::msg("Selected items added"); Statusbar::msg("Selected items added");
m_old_screen->switchTo(); switchToPreviousScreen();
} }
void SelectedItemsAdder::setDimensions() void SelectedItemsAdder::setDimensions()

View File

@@ -22,10 +22,11 @@
#define _SEL_ITEMS_ADDER_H #define _SEL_ITEMS_ADDER_H
#include "exec_item.h" #include "exec_item.h"
#include "interfaces.h"
#include "screen.h" #include "screen.h"
#include "song.h" #include "song.h"
struct SelectedItemsAdder : public Screen<NC::Menu<ExecItem<std::string, void()>> *> struct SelectedItemsAdder: Screen<NC::Menu<ExecItem<std::string, void()>> *>, Tabbable
{ {
typedef typename std::remove_pointer<WindowType>::type Component; typedef typename std::remove_pointer<WindowType>::type Component;
@@ -44,7 +45,6 @@ struct SelectedItemsAdder : public Screen<NC::Menu<ExecItem<std::string, void()>
virtual void mouseButtonPressed(MEVENT me) OVERRIDE; virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isMergable() OVERRIDE { return false; } virtual bool isMergable() OVERRIDE { return false; }
virtual bool isTabbable() OVERRIDE { return false; }
protected: protected:
virtual bool isLockable() OVERRIDE { return false; } virtual bool isLockable() OVERRIDE { return false; }
@@ -65,8 +65,6 @@ private:
void setDimensions(); void setDimensions();
BasicScreen *m_old_screen;
size_t m_playlist_selector_width; size_t m_playlist_selector_width;
size_t m_playlist_selector_height; size_t m_playlist_selector_height;

View File

@@ -25,10 +25,10 @@
#include "helpers.h" #include "helpers.h"
#include "server_info.h" #include "server_info.h"
#include "statusbar.h" #include "statusbar.h"
#include "screen_switcher.h"
using Global::MainHeight; using Global::MainHeight;
using Global::MainStartY; using Global::MainStartY;
using Global::myOldScreen;
ServerInfo *myServerInfo; ServerInfo *myServerInfo;
@@ -43,41 +43,28 @@ ServerInfo::ServerInfo()
void ServerInfo::switchTo() void ServerInfo::switchTo()
{ {
using Global::myScreen; using Global::myScreen;
if (myScreen != this)
if (myScreen == this) SwitchTo::execute(this);
{ else
myOldScreen->switchTo(); switchToPreviousScreen();
return;
}
// resize() can fall back to old screen, so we need it updated
myOldScreen = myScreen;
if (hasToBeResized)
resize();
myScreen = this;
//w.Window::clear();
} }
void ServerInfo::resize() void ServerInfo::resize()
{ {
SetDimensions(); SetDimensions();
if (itsHeight < 5) // screen too low to display this window
return myOldScreen->switchTo();
w.resize(itsWidth, itsHeight); w.resize(itsWidth, itsHeight);
w.moveTo((COLS-itsWidth)/2, (MainHeight-itsHeight)/2+MainStartY); w.moveTo((COLS-itsWidth)/2, (MainHeight-itsHeight)/2+MainStartY);
if (myOldScreen && myOldScreen->hasToBeResized) // resize background window if (previousScreen() && previousScreen()->hasToBeResized) // resize background window
{ {
myOldScreen->resize(); previousScreen()->resize();
myOldScreen->refresh(); previousScreen()->refresh();
} }
hasToBeResized = 0; hasToBeResized = 0;
} }
std::wstring ServerInfo::title() std::wstring ServerInfo::title()
{ {
return myOldScreen->title(); return previousScreen()->title();
} }
void ServerInfo::update() void ServerInfo::update()

View File

@@ -21,9 +21,10 @@
#ifndef _SERVER_INFO #ifndef _SERVER_INFO
#define _SERVER_INFO #define _SERVER_INFO
#include "interfaces.h"
#include "screen.h" #include "screen.h"
struct ServerInfo : public Screen<NC::Scrollpad> struct ServerInfo: Screen<NC::Scrollpad>, Tabbable
{ {
ServerInfo(); ServerInfo();
@@ -39,7 +40,6 @@ struct ServerInfo : public Screen<NC::Scrollpad>
virtual void spacePressed() OVERRIDE { } virtual void spacePressed() OVERRIDE { }
virtual bool isMergable() OVERRIDE { return false; } virtual bool isMergable() OVERRIDE { return false; }
virtual bool isTabbable() OVERRIDE { return false; }
protected: protected:
virtual bool isLockable() OVERRIDE { return false; } virtual bool isLockable() OVERRIDE { return false; }

View File

@@ -23,6 +23,7 @@
#include "song_info.h" #include "song_info.h"
#include "tag_editor.h" #include "tag_editor.h"
#include "title.h" #include "title.h"
#include "screen_switcher.h"
#ifdef HAVE_TAGLIB_H #ifdef HAVE_TAGLIB_H
# include "fileref.h" # include "fileref.h"
@@ -71,35 +72,24 @@ std::wstring SongInfo::title()
void SongInfo::switchTo() void SongInfo::switchTo()
{ {
using Global::myScreen; using Global::myScreen;
using Global::myOldScreen; if (myScreen != this)
using Global::myLockedScreen; {
if (myScreen == this)
return myOldScreen->switchTo();
if (myLockedScreen)
updateInactiveScreen(this);
auto s = currentSong(myScreen); auto s = currentSong(myScreen);
if (!s) if (!s)
return; return;
SwitchTo::execute(this);
if (hasToBeResized || myLockedScreen)
resize();
myOldScreen = myScreen;
myScreen = this;
w.clear(); w.clear();
w.reset(); w.reset();
PrepareSong(*s); PrepareSong(*s);
w.flush(); w.flush();
// redraw header after we're done with the file, since reading it from disk // redraw header after we're done with the file, since reading it from disk
// takes a bit of time and having header updated before content of a window // takes a bit of time and having header updated before content of a window
// is displayed doesn't look nice. // is displayed doesn't look nice.
drawHeader(); drawHeader();
} }
else
switchToPreviousScreen();
}
void SongInfo::PrepareSong(MPD::Song &s) void SongInfo::PrepareSong(MPD::Song &s)
{ {

View File

@@ -21,10 +21,11 @@
#ifndef _SONG_INFO_H #ifndef _SONG_INFO_H
#define _SONG_INFO_H #define _SONG_INFO_H
#include "screen.h" #include "interfaces.h"
#include "mutable_song.h" #include "mutable_song.h"
#include "screen.h"
struct SongInfo : public Screen<NC::Scrollpad> struct SongInfo: Screen<NC::Scrollpad>, Tabbable
{ {
struct Metadata struct Metadata
{ {
@@ -47,7 +48,6 @@ struct SongInfo : public Screen<NC::Scrollpad>
virtual void spacePressed() OVERRIDE { } virtual void spacePressed() OVERRIDE { }
virtual bool isMergable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; }
virtual bool isTabbable() OVERRIDE { return false; }
// private members // private members
static const Metadata Tags[]; static const Metadata Tags[];

View File

@@ -25,6 +25,7 @@
#include "sort_playlist.h" #include "sort_playlist.h"
#include "statusbar.h" #include "statusbar.h"
#include "utility/comparators.h" #include "utility/comparators.h"
#include "screen_switcher.h"
using Global::MainHeight; using Global::MainHeight;
using Global::MainStartY; using Global::MainStartY;
@@ -62,19 +63,7 @@ SortPlaylistDialog::SortPlaylistDialog()
void SortPlaylistDialog::switchTo() void SortPlaylistDialog::switchTo()
{ {
using Global::myScreen; SwitchTo::execute(this);
using Global::myOldScreen;
using Global::myLockedScreen;
using Global::myInactiveScreen;
assert(myScreen != this);
if (hasToBeResized)
resize();
myOldScreen = myScreen;
myScreen = this;
w.reset(); w.reset();
refresh(); refresh();
} }
@@ -90,7 +79,7 @@ void SortPlaylistDialog::resize()
std::wstring SortPlaylistDialog::title() std::wstring SortPlaylistDialog::title()
{ {
return Global::myOldScreen->title(); return previousScreen()->title();
} }
void SortPlaylistDialog::enterPressed() void SortPlaylistDialog::enterPressed()
@@ -154,11 +143,11 @@ void SortPlaylistDialog::enterPressed()
if (Mpd.CommitCommandsList()) if (Mpd.CommitCommandsList())
Statusbar::msg("Playlist sorted"); Statusbar::msg("Playlist sorted");
Global::myOldScreen->switchTo(); switchToPreviousScreen();
} }
else if (*option == m_cancel_entry) else if (*option == m_cancel_entry)
{ {
Global::myOldScreen->switchTo(); switchToPreviousScreen();
} }
else else
Statusbar::msg("Move tag types up and down to adjust sort order"); Statusbar::msg("Move tag types up and down to adjust sort order");

View File

@@ -21,10 +21,11 @@
#ifndef _SORT_PLAYLIST #ifndef _SORT_PLAYLIST
#define _SORT_PLAYLIST #define _SORT_PLAYLIST
#include "interfaces.h"
#include "screen.h" #include "screen.h"
#include "song.h" #include "song.h"
struct SortPlaylistDialog : public Screen<NC::Menu<std::pair<std::string, MPD::Song::GetFunction>>> struct SortPlaylistDialog: Screen<NC::Menu<std::pair<std::string, MPD::Song::GetFunction>>>, Tabbable
{ {
SortPlaylistDialog(); SortPlaylistDialog();
@@ -39,7 +40,6 @@ struct SortPlaylistDialog : public Screen<NC::Menu<std::pair<std::string, MPD::S
virtual void spacePressed() OVERRIDE { } virtual void spacePressed() OVERRIDE { }
virtual void mouseButtonPressed(MEVENT me) OVERRIDE; virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isTabbable() OVERRIDE { return false; }
virtual bool isMergable() OVERRIDE { return false; } virtual bool isMergable() OVERRIDE { return false; }
// private members // private members

View File

@@ -290,7 +290,7 @@ void Status::Changes::songID()
if (Config.autocenter_mode && !myPlaylist->main().isFiltered()) if (Config.autocenter_mode && !myPlaylist->main().isFiltered())
myPlaylist->main().highlight(Mpd.GetCurrentlyPlayingSongPos()); myPlaylist->main().highlight(Mpd.GetCurrentlyPlayingSongPos());
if (Config.now_playing_lyrics && isVisible(myLyrics) && Global::myOldScreen == myPlaylist) if (Config.now_playing_lyrics && isVisible(myLyrics) && myLyrics->previousScreen() == myPlaylist)
myLyrics->ReloadNP = 1; myLyrics->ReloadNP = 1;
elapsedTime(); elapsedTime();

View File

@@ -37,6 +37,7 @@
#include "utility/comparators.h" #include "utility/comparators.h"
#include "title.h" #include "title.h"
#include "tags.h" #include "tags.h"
#include "screen_switcher.h"
using namespace std::placeholders; using namespace std::placeholders;
@@ -194,20 +195,7 @@ std::wstring TagEditor::title()
void TagEditor::switchTo() void TagEditor::switchTo()
{ {
using Global::myLockedScreen; SwitchTo::execute(this);
if (myScreen == this)
return;
if (myLockedScreen)
updateInactiveScreen(this);
if (hasToBeResized || myLockedScreen)
resize();
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
drawHeader(); drawHeader();
refresh(); refresh();
} }

View File

@@ -28,12 +28,11 @@
#include <list> #include <list>
#include "interfaces.h" #include "interfaces.h"
#include "mpdpp.h"
#include "mutable_song.h" #include "mutable_song.h"
#include "regex_filter.h" #include "regex_filter.h"
#include "screen.h" #include "screen.h"
struct TagEditor : public Screen<NC::Window *>, public Filterable, public HasColumns, public HasSongs, public Searchable struct TagEditor: Screen<NC::Window *>, Filterable, HasColumns, HasSongs, Searchable, Tabbable
{ {
TagEditor(); TagEditor();
@@ -49,7 +48,6 @@ struct TagEditor : public Screen<NC::Window *>, public Filterable, public HasCol
virtual void spacePressed() OVERRIDE; virtual void spacePressed() OVERRIDE;
virtual void mouseButtonPressed(MEVENT) OVERRIDE; virtual void mouseButtonPressed(MEVENT) OVERRIDE;
virtual bool isTabbable() OVERRIDE { return true; }
virtual bool isMergable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; }
// Filterable implementation // Filterable implementation

View File

@@ -33,9 +33,6 @@
#include <textidentificationframe.h> #include <textidentificationframe.h>
#include <xiphcomment.h> #include <xiphcomment.h>
#include "browser.h"
#include "playlist.h"
#include "global.h" #include "global.h"
#include "settings.h" #include "settings.h"
#include "utility/numeric_conversions.h" #include "utility/numeric_conversions.h"
@@ -253,7 +250,8 @@ bool write(MPD::MutableSong &s)
new_name += s.getDirectory() + "/" + s.getNewURI(); new_name += s.getDirectory() + "/" + s.getNewURI();
if (std::rename(old_name.c_str(), new_name.c_str()) == 0 && !s.isFromDatabase()) if (std::rename(old_name.c_str(), new_name.c_str()) == 0 && !s.isFromDatabase())
{ {
if (Global::myOldScreen == myPlaylist) // FIXME
/*if (myTinyTagEditor == myPlaylist)
{ {
// if we rename local file, it won't get updated // if we rename local file, it won't get updated
// so just remove it from playlist and add again // so just remove it from playlist and add again
@@ -269,7 +267,7 @@ bool write(MPD::MutableSong &s)
Mpd.CommitCommandsList(); Mpd.CommitCommandsList();
} }
else // only myBrowser->main() else // only myBrowser->main()
myBrowser->GetDirectory(myBrowser->CurrentDir()); myBrowser->GetDirectory(myBrowser->CurrentDir());*/
} }
} }
return true; return true;

View File

@@ -38,10 +38,10 @@
#include "tag_editor.h" #include "tag_editor.h"
#include "title.h" #include "title.h"
#include "tags.h" #include "tags.h"
#include "screen_switcher.h"
using Global::MainHeight; using Global::MainHeight;
using Global::MainStartY; using Global::MainStartY;
using Global::myOldScreen;
TinyTagEditor *myTinyTagEditor; TinyTagEditor *myTinyTagEditor;
@@ -66,22 +66,14 @@ void TinyTagEditor::resize()
void TinyTagEditor::switchTo() void TinyTagEditor::switchTo()
{ {
using Global::myScreen; using Global::myScreen;
using Global::myLockedScreen;
if (itsEdited.isStream()) if (itsEdited.isStream())
{ {
Statusbar::msg("Streams can't be edited"); Statusbar::msg("Streams can't be edited");
} }
else if (getTags()) else if (getTags())
{ {
if (myLockedScreen) m_previous_screen = myScreen;
updateInactiveScreen(this); SwitchTo::execute(this);
if (hasToBeResized || myLockedScreen)
resize();
myOldScreen = myScreen;
myScreen = this;
drawHeader(); drawHeader();
} }
else else
@@ -139,9 +131,9 @@ void TinyTagEditor::enterPressed()
Mpd.UpdateDirectory(itsEdited.getDirectory()); Mpd.UpdateDirectory(itsEdited.getDirectory());
else else
{ {
if (myOldScreen == myPlaylist) if (m_previous_screen == myPlaylist)
myPlaylist->main().current().value() = itsEdited; myPlaylist->main().current().value() = itsEdited;
else if (myOldScreen == myBrowser) else if (m_previous_screen == myBrowser)
myBrowser->GetDirectory(myBrowser->CurrentDir()); myBrowser->GetDirectory(myBrowser->CurrentDir());
} }
} }
@@ -149,7 +141,7 @@ void TinyTagEditor::enterPressed()
Statusbar::msg("Error while writing tags"); Statusbar::msg("Error while writing tags");
} }
if (option > 21) if (option > 21)
myOldScreen->switchTo(); m_previous_screen->switchTo();
} }
void TinyTagEditor::mouseButtonPressed(MEVENT me) void TinyTagEditor::mouseButtonPressed(MEVENT me)

View File

@@ -25,10 +25,11 @@
#ifdef HAVE_TAGLIB_H #ifdef HAVE_TAGLIB_H
#include "interfaces.h"
#include "mutable_song.h" #include "mutable_song.h"
#include "screen.h" #include "screen.h"
struct TinyTagEditor : public Screen<NC::Menu<NC::Buffer>> struct TinyTagEditor: Screen<NC::Menu<NC::Buffer>>
{ {
TinyTagEditor(); TinyTagEditor();
@@ -45,17 +46,17 @@ struct TinyTagEditor : public Screen<NC::Menu<NC::Buffer>>
virtual void mouseButtonPressed(MEVENT me) OVERRIDE; virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isMergable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; }
virtual bool isTabbable() OVERRIDE { return false; }
// private members // private members
void SetEdited(const MPD::Song &); void SetEdited(const MPD::Song &);
protected: protected:
virtual bool isLockable() OVERRIDE { return true; } virtual bool isLockable() OVERRIDE { return false; }
private: private:
bool getTags(); bool getTags();
MPD::MutableSong itsEdited; MPD::MutableSong itsEdited;
BasicScreen *m_previous_screen;
}; };
extern TinyTagEditor *myTinyTagEditor; extern TinyTagEditor *myTinyTagEditor;

View File

@@ -36,6 +36,7 @@
#include "status.h" #include "status.h"
#include "statusbar.h" #include "statusbar.h"
#include "title.h" #include "title.h"
#include "screen_switcher.h"
using Global::MainStartY; using Global::MainStartY;
using Global::MainHeight; using Global::MainHeight;
@@ -62,31 +63,13 @@ Visualizer::Visualizer()
void Visualizer::switchTo() void Visualizer::switchTo()
{ {
using Global::myScreen; SwitchTo::execute(this);
using Global::myLockedScreen;
if (myScreen == this)
return;
if (myLockedScreen)
updateInactiveScreen(this);
if (hasToBeResized || myLockedScreen)
resize();
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
drawHeader();
w.clear(); w.clear();
SetFD(); SetFD();
m_timer = { 0, 0 };
m_timer.tv_sec = 0;
m_timer.tv_usec = 0;
if (m_fifo >= 0) if (m_fifo >= 0)
Global::wFooter->setTimeout(WindowTimeout); Global::wFooter->setTimeout(WindowTimeout);
drawHeader();
} }
void Visualizer::resize() void Visualizer::resize()

View File

@@ -25,14 +25,15 @@
#ifdef ENABLE_VISUALIZER #ifdef ENABLE_VISUALIZER
#include "window.h" #include "interfaces.h"
#include "screen.h" #include "screen.h"
#include "window.h"
#ifdef HAVE_FFTW3_H #ifdef HAVE_FFTW3_H
# include <fftw3.h> # include <fftw3.h>
#endif #endif
struct Visualizer : public Screen<NC::Window> struct Visualizer: Screen<NC::Window>, Tabbable
{ {
Visualizer(); Visualizer();
@@ -48,7 +49,6 @@ struct Visualizer : public Screen<NC::Window>
virtual void spacePressed() OVERRIDE; virtual void spacePressed() OVERRIDE;
virtual void mouseButtonPressed(MEVENT) OVERRIDE { } virtual void mouseButtonPressed(MEVENT) OVERRIDE { }
virtual bool isTabbable() OVERRIDE { return true; }
virtual bool isMergable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; }
// private members // private members