summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/config33
-rw-r--r--doc/ncmpcpp.110
-rw-r--r--src/actions.cpp20
-rw-r--r--src/cmdargs.cpp51
-rw-r--r--src/ncmpcpp.cpp4
-rw-r--r--src/screen_type.cpp92
-rw-r--r--src/screen_type.h18
-rw-r--r--src/settings.cpp69
-rw-r--r--src/settings.h26
9 files changed, 155 insertions, 168 deletions
diff --git a/doc/config b/doc/config
index af3d9dae..cd0dfbba 100644
--- a/doc/config
+++ b/doc/config
@@ -366,28 +366,21 @@
#display_screens_numbers_on_start = "yes"
#
##
-## How shall key_screen_switcher work?
+## How shall screen switcher work?
##
-## - "previous" - switch between current and last used screen
-## - "sequence: 2 -> 9 -> 5" - switch between given sequence of screens.
+## - "previous" - switch between the current and previous screen.
+## - "screen1,...,screenN" - switch between given sequence of screens.
##
-## Screen numbers you can use after 'sequence' keyword are:
+## Screens available for use: help, playlist, browser, search_engine,
+## media_library, playlist_editor, tag_editor, outputs, visualizer, clock.
##
-## - 1 - help
-## - 2 - playlist
-## - 3 - browser
-## - 4 - search engine
-## - 5 - media library
-## - 6 - playlist editor
-## - 7 - tag editor
-## - 8 - outputs
-## - 9 - visualizer
-## - 10 - clock
+#screen_switcher_mode = "playlist, browser"
+#
##
-## As you can see, above example will switch between
-## playlist, visualizer and media library screens.
+## Note: You can define startup screen for ncmpcpp
+## by choosing screen from the list above.
##
-#screen_switcher_mode = "sequence: 2 -> 3"
+#startup_screen = "playlist"
#
##
## Default width of locked screen (in %).
@@ -398,12 +391,6 @@
#
#ask_for_locked_screen_width_part = "yes"
#
-##
-## Note: You can define startup screen for ncmpcpp
-## by choosing screen number from the list above.
-##
-#startup_screen = "2"
-#
#jump_to_now_playing_song_at_start = "yes"
#
#ask_before_clearing_main_playlist = "no"
diff --git a/doc/ncmpcpp.1 b/doc/ncmpcpp.1
index 1f16fb90..741bdd66 100644
--- a/doc/ncmpcpp.1
+++ b/doc/ncmpcpp.1
@@ -19,7 +19,7 @@ Connect to server at port [6600]
Use alternative configuration file
.TP
.B \-s, \-\-screen <name>
-Specify the startup screen (<name> may be: help, playlist, browser, search-engine, media-library, playlist-editor, tag-editor, outputs, visualizer, clock)
+Specify the startup screen (<name> may be: help, playlist, browser, search_engine, media_library, playlist_editor, tag_editor, outputs, visualizer, clock)
.TP
.B \-?, \-\-help
Display help.
@@ -256,7 +256,10 @@ If set to "playlist", Search engine will perform searching in current MPD playli
If enabled, screens' names and their keybindings will be shown in header window until key is pressed, otherwise they won't be displayed at all.
.TP
.B screen_switcher_mode = SWITCHER_MODE
-If set to "previous", key_screen_switcher will switch between current and last used screen. If set to "sequence: user_defined_sequence", it will switch between given sequence of screens. Syntax clarification can be found in example config file.
+If set to "previous", key_screen_switcher will switch between current and last used screen. If set to "screen1,...screenN" (a list of screens) it will switch between them in a sequence. Syntax clarification can be found in example config file.
+.TP
+.B startup_screen = SCREEN_NAME
+Screen that has to be displayed at start (playlist by default).
.TP
.B locked_screen_width_part = 20-80
If you want to lock a screen, ncmpcpp asks for % of locked screen's width to be reserved before that and provides a default value, which is the one you can set here.
@@ -264,9 +267,6 @@ If you want to lock a screen, ncmpcpp asks for % of locked screen's width to be
.B ask_for_locked_screen_width_part = yes/no
If enabled, ncmpcpp will ask for % of locked screen's width each time you want to lock a screen. If you disable that, it'll silently attempt to use default value.
.TP
-.B startup_screen = SCREEN_NUMBER
-Screen that has to be displayed at start (playlist by default).
-.TP
.B jump_to_now_playing_song_at_start = yes/no
If enabled, ncmpcpp will jump at start to now playing song if mpd is playing or paused.
.TP
diff --git a/src/actions.cpp b/src/actions.cpp
index 0c1f4938..0902f430 100644
--- a/src/actions.cpp
+++ b/src/actions.cpp
@@ -2213,11 +2213,13 @@ void NextScreen::run()
}
else if (!Config.screens_seq.empty())
{
- auto screen = std::find(Config.screens_seq.begin(), Config.screens_seq.end(), myScreen);
- if (++screen == Config.screens_seq.end())
- Config.screens_seq.front()->switchTo();
+ auto screen_type = std::find(Config.screens_seq.begin(), Config.screens_seq.end(),
+ myScreen->type()
+ );
+ if (++screen_type == Config.screens_seq.end())
+ toScreen(Config.screens_seq.front())->switchTo();
else
- (*screen)->switchTo();
+ toScreen(*screen_type)->switchTo();
}
}
@@ -2230,11 +2232,13 @@ void PreviousScreen::run()
}
else if (!Config.screens_seq.empty())
{
- auto screen = std::find(Config.screens_seq.begin(), Config.screens_seq.end(), myScreen);
- if (screen == Config.screens_seq.begin())
- Config.screens_seq.back()->switchTo();
+ auto screen_type = std::find(Config.screens_seq.begin(), Config.screens_seq.end(),
+ myScreen->type()
+ );
+ if (screen_type == Config.screens_seq.begin())
+ toScreen(Config.screens_seq.back())->switchTo();
else
- (*--screen)->switchTo();
+ toScreen(*--screen_type)->switchTo();
}
}
diff --git a/src/cmdargs.cpp b/src/cmdargs.cpp
index 3548e4ee..a246fa76 100644
--- a/src/cmdargs.cpp
+++ b/src/cmdargs.cpp
@@ -18,29 +18,13 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#include <cassert>
-#include <cstring>
-#include <boost/algorithm/string/replace.hpp>
#include <iostream>
-#include "actions.h"
-#include "charset.h"
#include "cmdargs.h"
#include "config.h"
#include "mpdpp.h"
#include "settings.h"
-#include "help.h"
-#include "playlist.h"
-#include "browser.h"
-#include "search_engine.h"
-#include "media_library.h"
-#include "playlist_editor.h"
-#include "tag_editor.h"
-#include "outputs.h"
-#include "visualizer.h"
-#include "clock.h"
-
void ParseArgv(int argc, char **argv)
{
for (int i = 1; i < argc; ++i)
@@ -122,39 +106,14 @@ void ParseArgv(int argc, char **argv)
if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--screen"))
{
- if (++i == argc) {
+ if (++i == argc)
+ {
std::cerr << "No screen specified" << std::endl;
exit(1);
}
- if (!strcmp(argv[i], "help"))
- Config.startup_screen = myHelp;
- else if (!strcmp(argv[i], "playlist"))
- Config.startup_screen = myPlaylist;
- else if (!strcmp(argv[i], "browser"))
- Config.startup_screen = myBrowser;
- else if (!strcmp(argv[i], "search-engine"))
- Config.startup_screen = mySearcher;
- else if (!strcmp(argv[i], "media-library"))
- Config.startup_screen = myLibrary;
- else if (!strcmp(argv[i], "playlist-editor"))
- Config.startup_screen = myPlaylistEditor;
-# ifdef HAVE_TAGLIB_H
- else if (!strcmp(argv[i], "tag-editor"))
- Config.startup_screen = myTagEditor;
-# endif // HAVE_TAGLIB_H
-# ifdef ENABLE_OUTPUTS
- else if (!strcmp(argv[i], "outputs"))
- Config.startup_screen = myOutputs;
-# endif // ENABLE_OUTPUTS
-# ifdef ENABLE_VISUALIZER
- else if (!strcmp(argv[i], "visualizer"))
- Config.startup_screen = myVisualizer;
-# endif // ENABLE_VISUALIZER
-# ifdef ENABLE_CLOCK
- else if (!strcmp(argv[i], "clock"))
- Config.startup_screen = myClock;
-# endif // ENABLE_CLOCK
- else {
+ Config.startup_screen_type = stringtoStartupScreenType(argv[i]);
+ if (Config.startup_screen_type == ScreenType::Unknown)
+ {
std::cerr << "Invalid screen: " << argv[i] << std::endl;
exit(1);
}
diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp
index 1c379461..b31d5aed 100644
--- a/src/ncmpcpp.cpp
+++ b/src/ncmpcpp.cpp
@@ -206,8 +206,8 @@ int main(int argc, char **argv)
}
// go to startup screen
- if (Config.startup_screen != myScreen)
- Config.startup_screen->switchTo();
+ if (Config.startup_screen_type != myScreen->type())
+ toScreen(Config.startup_screen_type)->switchTo();
myBrowser->fetchSupportedExtensions();
# ifdef ENABLE_OUTPUTS
diff --git a/src/screen_type.cpp b/src/screen_type.cpp
index 4ae477ce..eb639889 100644
--- a/src/screen_type.cpp
+++ b/src/screen_type.cpp
@@ -18,43 +18,72 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
+#include "config.h"
#include "screen_type.h"
-ScreenType stringtoStarterScreenType(const std::string &s)
+#include "browser.h"
+#include "clock.h"
+#include "help.h"
+#include "lastfm.h"
+#include "lyrics.h"
+#include "media_library.h"
+#include "outputs.h"
+#include "playlist.h"
+#include "playlist_editor.h"
+#include "search_engine.h"
+#include "sel_items_adder.h"
+#include "server_info.h"
+#include "song_info.h"
+#include "sort_playlist.h"
+#include "tag_editor.h"
+#include "tiny_tag_editor.h"
+#include "visualizer.h"
+
+ScreenType stringtoStartupScreenType(const std::string &s)
{
ScreenType result = ScreenType::Unknown;
if (s == "browser")
result = ScreenType::Browser;
+# ifdef ENABLE_CLOCK
else if (s == "clock")
result = ScreenType::Clock;
+# endif // ENABLE_CLOCK
else if (s == "help")
result = ScreenType::Help;
else if (s == "media_library")
result = ScreenType::MediaLibrary;
+# ifdef ENABLE_OUTPUTS
else if (s == "outputs")
result = ScreenType::Outputs;
+# endif // ENABLE_OUTPUTS
else if (s == "playlist")
result = ScreenType::Playlist;
else if (s == "playlist_editor")
result = ScreenType::PlaylistEditor;
else if (s == "search_engine")
result = ScreenType::SearchEngine;
+# ifdef HAVE_TAGLIB_H
else if (s == "tag_editor")
result = ScreenType::TagEditor;
+# endif // HAVE_TAGLIB_H
+# ifdef ENABLE_VISUALIZER
else if (s == "visualizer")
result = ScreenType::Visualizer;
+# endif // ENABLE_VISUALIZER
return result;
}
ScreenType stringToScreenType(const std::string &s)
{
- ScreenType result = stringtoStarterScreenType(s);
+ ScreenType result = stringtoStartupScreenType(s);
if (result == ScreenType::Unknown)
{
- if (s == "last_fm")
- result = ScreenType::Lastfm;
- else if (s == "lyrics")
+ if (s == "lyrics")
result = ScreenType::Lyrics;
+# ifdef HAVE_CURL_CURL_H
+ else if (s == "last_fm")
+ result = ScreenType::Lastfm;
+# endif // HAVE_CURL_CURL_H
else if (s == "selected_items_adder")
result = ScreenType::SelectedItemsAdder;
else if (s == "server_info")
@@ -63,8 +92,61 @@ ScreenType stringToScreenType(const std::string &s)
result = ScreenType::SongInfo;
else if (s == "sort_playlist_dialog")
result = ScreenType::SortPlaylistDialog;
+# ifdef HAVE_TAGLIB_H
else if (s == "tiny_tag_editor")
result = ScreenType::TinyTagEditor;
+# endif // HAVE_TAGLIB_H
}
return result;
}
+
+BaseScreen *toScreen(ScreenType st)
+{
+ switch (st)
+ {
+ case ScreenType::Browser:
+ return myBrowser;
+# ifdef ENABLE_CLOCK
+ case ScreenType::Clock:
+ return myClock;
+# endif // ENABLE_CLOCK
+ case ScreenType::Help:
+ return myHelp;
+ case ScreenType::Lastfm:
+ return myLastfm;
+ case ScreenType::Lyrics:
+ return myLyrics;
+ case ScreenType::MediaLibrary:
+ return myLibrary;
+# ifdef ENABLE_OUTPUTS
+ case ScreenType::Outputs:
+ return myOutputs;
+# endif // ENABLE_OUTPUTS
+ case ScreenType::Playlist:
+ return myPlaylist;
+ case ScreenType::PlaylistEditor:
+ return myPlaylistEditor;
+ case ScreenType::SearchEngine:
+ return mySearcher;
+ case ScreenType::SelectedItemsAdder:
+ return mySelectedItemsAdder;
+ case ScreenType::ServerInfo:
+ return myServerInfo;
+ case ScreenType::SongInfo:
+ return mySongInfo;
+ case ScreenType::SortPlaylistDialog:
+ return mySortPlaylistDialog;
+# ifdef HAVE_TAGLIB_H
+ case ScreenType::TagEditor:
+ return myTagEditor;
+ case ScreenType::TinyTagEditor:
+ return myTinyTagEditor;
+# endif // HAVE_TAGLIB_H
+# ifdef ENABLE_VISUALIZER
+ case ScreenType::Visualizer:
+ return myVisualizer;
+# endif // ENABLE_VISUALIZER
+ default:
+ return nullptr;
+ }
+}
diff --git a/src/screen_type.h b/src/screen_type.h
index b4b2c2c0..a1568120 100644
--- a/src/screen_type.h
+++ b/src/screen_type.h
@@ -22,15 +22,25 @@
#define NCMPCPP_SCREEN_TYPE_H
#include <string>
+#include "config.h"
+
+// forward declaration
+struct BaseScreen;
enum class ScreenType {
Browser,
+# ifdef ENABLE_CLOCK
Clock,
+# endif // ENABLE_CLOCK
Help,
+# ifdef HAVE_CURL_CURL_H
Lastfm,
+# endif // HAVE_CURL_CURL_H
Lyrics,
MediaLibrary,
+# ifdef ENABLE_OUTPUTS
Outputs,
+# endif // ENABLE_OUTPUTS
Playlist,
PlaylistEditor,
SearchEngine,
@@ -38,13 +48,19 @@ enum class ScreenType {
ServerInfo,
SongInfo,
SortPlaylistDialog,
+# ifdef HAVE_TAGLIB_H
TagEditor,
TinyTagEditor,
+# endif // HAVE_TAGLIB_H
Unknown,
+# ifdef ENABLE_VISUALIZER
Visualizer,
+# endif // ENABLE_VISUALIZER
};
-ScreenType stringtoStarterScreenType(const std::string &s);
+ScreenType stringtoStartupScreenType(const std::string &s);
ScreenType stringToScreenType(const std::string &s);
+BaseScreen *toScreen(ScreenType st);
+
#endif // NCMPCPP_SCREEN_TYPE_H
diff --git a/src/settings.cpp b/src/settings.cpp
index c5eb2bc2..9a12c97f 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -60,43 +60,6 @@ Configuration Config;
namespace
{
- ScreenRef intToScreen(int n)
- {
- switch (n)
- {
- case 1:
- return myHelp;
- case 2:
- return myPlaylist;
- case 3:
- return myBrowser;
- case 4:
- return mySearcher;
- case 5:
- return myLibrary;
- case 6:
- return myPlaylistEditor;
-# ifdef HAVE_TAGLIB_H
- case 7:
- return myTagEditor;
-# endif // HAVE_TAGLIB_H
-# ifdef ENABLE_OUTPUTS
- case 8:
- return myOutputs;
-# endif // ENABLE_OUTPUTS
-# ifdef ENABLE_VISUALIZER
- case 9:
- return myVisualizer;
-# endif // ENABLE_VISUALIZER
-# ifdef ENABLE_CLOCK
- case 10:
- return myClock;
-# endif // ENABLE_CLOCK
- default:
- return ScreenRef();
- }
- }
-
std::string GetOptionName(const std::string &s)
{
size_t equal = s.find('=');
@@ -241,11 +204,11 @@ void Configuration::SetDefaults()
if (system_encoding == "UTF-8") // mpd uses utf-8 by default so no need to convert
system_encoding.clear();
# endif // HAVE_LANGINFO_H
- startup_screen = myPlaylist;
+ startup_screen_type = ScreenType::Playlist;
browser_sort_mode = smName;
// default screens sequence
- screens_seq.push_back(myPlaylist);
- screens_seq.push_back(myBrowser);
+ screens_seq.push_back(ScreenType::Playlist);
+ screens_seq.push_back(ScreenType::Browser);
}
Configuration::Configuration()
@@ -625,24 +588,20 @@ void Configuration::Read()
}
else if (name == "screen_switcher_mode")
{
- if (v.find("previous") != std::string::npos)
- {
+ if (v == "previous")
screen_switcher_previous = true;
- }
- else if (v.find("sequence") != std::string::npos)
+ else
{
screen_switcher_previous = false;
screens_seq.clear();
- for (std::string::const_iterator it = v.begin(); it != v.end(); )
+ boost::sregex_token_iterator i(v.begin(), v.end(), boost::regex("\\w+")), j;
+ for (; i != j; ++i)
{
- while (it != v.end() && !isdigit(*it))
- ++it;
- if (it == v.end())
- break;
- if (auto screen = intToScreen(atoi(&*it)))
+ auto screen = stringtoStartupScreenType(*i);
+ if (screen != ScreenType::Unknown)
screens_seq.push_back(screen);
- while (it != v.end() && isdigit(*it))
- ++it;
+ else
+ std::cerr << "screen_switcher_mode: unknown screen: " << *i << "\n";
}
// throw away duplicates
screens_seq.unique();
@@ -650,9 +609,9 @@ void Configuration::Read()
}
else if (name == "startup_screen")
{
- startup_screen = intToScreen(atoi(v.c_str()));
- if (!startup_screen)
- startup_screen = myPlaylist;
+ startup_screen_type = stringtoStartupScreenType(v);
+ if (startup_screen_type == ScreenType::Unknown)
+ startup_screen_type = ScreenType::Playlist;
}
else if (name == "autocenter_mode")
{
diff --git a/src/settings.h b/src/settings.h
index 0ea78c68..c8d77014 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -26,6 +26,7 @@
#include <vector>
#include <mpd/client.h>
#include "actions.h"
+#include "screen_type.h"
#include "strbuffer.h"
struct BaseScreen; // forward declaration for screens sequence
@@ -46,27 +47,6 @@ struct Column
bool display_empty_tag;
};
-// FIXME: temporary hack
-struct ScreenRef
-{
- ScreenRef() : m_ptr(0) { }
- template <typename ScreenT>
- ScreenRef(ScreenT *&ptr) : m_ptr(reinterpret_cast<BaseScreen **>(&ptr)) { }
-
- BaseScreen &operator*() const { return **m_ptr; }
- BaseScreen *operator->() const { return *m_ptr; }
-
- bool operator==(const ScreenRef &rhs) const { return m_ptr == rhs.m_ptr; }
- bool operator!=(const ScreenRef &rhs) const { return m_ptr != rhs.m_ptr; }
- bool operator==(const BaseScreen *rhs) const { return *m_ptr == rhs; }
- bool operator!=(const BaseScreen *rhs) const { return *m_ptr != rhs; }
-
- operator bool() { return m_ptr != 0; }
-
-private:
- BaseScreen **m_ptr;
-};
-
struct Configuration
{
Configuration();
@@ -208,8 +188,8 @@ struct Configuration
size_t now_playing_prefix_length;
size_t now_playing_suffix_length;
- ScreenRef startup_screen;
- std::list<ScreenRef> screens_seq;
+ ScreenType startup_screen_type;
+ std::list<ScreenType> screens_seq;
SortMode browser_sort_mode;