diff --git a/src/actions.cpp b/src/actions.cpp index 49087996..847b73e8 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -1564,14 +1564,18 @@ void ToggleScreenLock::run() { using Global::wFooter; using Global::myLockedScreen; - // FIXME: check if screen can be locked before prompting for width - if (myLockedScreen != 0) + const char *msg_unlockable_screen = "Current screen can't be locked"; + if (myLockedScreen != nullptr) { BaseScreen::unlock(); Actions::setResizeFlags(); myScreen->resize(); Statusbar::print("Screen unlocked"); } + else if (!myScreen->isLockable()) + { + Statusbar::print(msg_unlockable_screen); + } else { unsigned part = Config.locked_screen_width_part*100; @@ -1586,7 +1590,7 @@ void ToggleScreenLock::run() if (myScreen->lock()) Statusbar::printf("Screen locked (with %1%%% width)", part); else - Statusbar::print("Current screen can't be locked"); + Statusbar::print(msg_unlockable_screen); } } diff --git a/src/browser.h b/src/browser.h index b310ce51..9cbf9f04 100644 --- a/src/browser.h +++ b/src/browser.h @@ -43,6 +43,7 @@ struct Browser: Screen>, HasSongs, Searchable, Tabbable virtual void spacePressed() OVERRIDE; virtual void mouseButtonPressed(MEVENT me) OVERRIDE; + virtual bool isLockable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; } // Searchable implementation @@ -73,9 +74,6 @@ struct Browser: Screen>, HasSongs, Searchable, Tabbable static void fetchSupportedExtensions(); -protected: - virtual bool isLockable() OVERRIDE { return true; } - private: bool m_update_request; bool m_local_browser; diff --git a/src/clock.h b/src/clock.h index 119abef5..5f44aa15 100644 --- a/src/clock.h +++ b/src/clock.h @@ -46,10 +46,8 @@ struct Clock: Screen, Tabbable virtual void spacePressed() OVERRIDE { } virtual void mouseButtonPressed(MEVENT) OVERRIDE { } - virtual bool isMergable() OVERRIDE { return true; } - -protected: virtual bool isLockable() OVERRIDE { return false; } + virtual bool isMergable() OVERRIDE { return true; } private: NC::Window m_pane; diff --git a/src/help.h b/src/help.h index eef1d047..0a3ed220 100644 --- a/src/help.h +++ b/src/help.h @@ -40,10 +40,8 @@ struct Help: Screen, Tabbable virtual void enterPressed() OVERRIDE { } virtual void spacePressed() OVERRIDE { } - virtual bool isMergable() OVERRIDE { return true; } - -protected: virtual bool isLockable() OVERRIDE { return true; } + virtual bool isMergable() OVERRIDE { return true; } }; extern Help *myHelp; diff --git a/src/lastfm.h b/src/lastfm.h index 051dc8aa..09638824 100644 --- a/src/lastfm.h +++ b/src/lastfm.h @@ -48,6 +48,7 @@ struct Lastfm: Screen, Tabbable virtual void enterPressed() OVERRIDE { } virtual void spacePressed() OVERRIDE { } + virtual bool isLockable() OVERRIDE { return false; } virtual bool isMergable() OVERRIDE { return true; } template @@ -69,9 +70,6 @@ struct Lastfm: Screen, Tabbable m_title = ToWString(m_service->name()); } -protected: - virtual bool isLockable() OVERRIDE { return false; } - private: void getResult(); diff --git a/src/lyrics.h b/src/lyrics.h index bc5d5c5a..b5500566 100644 --- a/src/lyrics.h +++ b/src/lyrics.h @@ -45,6 +45,7 @@ struct Lyrics: Screen, Tabbable virtual void enterPressed() OVERRIDE { } virtual void spacePressed() OVERRIDE; + virtual bool isLockable() OVERRIDE { return false; } virtual bool isMergable() OVERRIDE { return true; } // private members @@ -60,9 +61,6 @@ struct Lyrics: Screen, Tabbable bool Reload; -protected: - virtual bool isLockable() OVERRIDE { return false; } - private: void Load(); diff --git a/src/media_library.h b/src/media_library.h index 97264743..9163c16c 100644 --- a/src/media_library.h +++ b/src/media_library.h @@ -46,6 +46,7 @@ struct MediaLibrary: Screen, HasColumns, HasSongs, Searchable, Tab virtual void spacePressed() OVERRIDE; virtual void mouseButtonPressed(MEVENT me) OVERRIDE; + virtual bool isLockable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; } // Searchable implementation @@ -135,9 +136,6 @@ struct MediaLibrary: Screen, HasColumns, HasSongs, Searchable, Tab NC::Menu Albums; NC::Menu Songs; -protected: - virtual bool isLockable() OVERRIDE { return true; } - private: void AddToPlaylist(bool); diff --git a/src/outputs.h b/src/outputs.h index 9c55d196..c7817bbf 100644 --- a/src/outputs.h +++ b/src/outputs.h @@ -47,13 +47,11 @@ struct Outputs: Screen>, Tabbable virtual void spacePressed() OVERRIDE { } virtual void mouseButtonPressed(MEVENT me) OVERRIDE; + virtual bool isLockable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; } // private members void FetchList(); - -protected: - virtual bool isLockable() OVERRIDE { return true; } }; extern Outputs *myOutputs; diff --git a/src/playlist.h b/src/playlist.h index 081f24ad..ec7bf98a 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -46,6 +46,7 @@ struct Playlist: Screen>, HasSongs, Searchable, Tabbable virtual void spacePressed() OVERRIDE; virtual void mouseButtonPressed(MEVENT me) OVERRIDE; + virtual bool isLockable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; } // Searchable implementation @@ -77,9 +78,6 @@ struct Playlist: Screen>, HasSongs, Searchable, Tabbable void reloadTotalLength() { m_reload_total_length = true; } void reloadRemaining() { m_reload_remaining = true; } -protected: - virtual bool isLockable() OVERRIDE { return true; } - private: std::string getTotalLength(); diff --git a/src/playlist_editor.h b/src/playlist_editor.h index d874fbbb..817cd33b 100644 --- a/src/playlist_editor.h +++ b/src/playlist_editor.h @@ -46,6 +46,7 @@ struct PlaylistEditor: Screen, HasColumns, HasSongs, Searchable, T virtual void spacePressed() OVERRIDE; virtual void mouseButtonPressed(MEVENT me) OVERRIDE; + virtual bool isLockable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; } // Searchable implementation @@ -80,9 +81,6 @@ struct PlaylistEditor: Screen, HasColumns, HasSongs, Searchable, T NC::Menu Playlists; NC::Menu Content; -protected: - virtual bool isLockable() OVERRIDE { return true; } - private: void AddToPlaylist(bool); diff --git a/src/screen.cpp b/src/screen.cpp index 73122b7f..5c436941 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -98,8 +98,7 @@ void BaseScreen::getWindowResizeParams(size_t &x_offset, size_t &width, bool adj bool BaseScreen::lock() { - if (myLockedScreen) - return false; + assert(myLockedScreen == nullptr); if (isLockable()) { myLockedScreen = this; diff --git a/src/screen.h b/src/screen.h index a958d539..8ba52c7a 100644 --- a/src/screen.h +++ b/src/screen.h @@ -80,6 +80,12 @@ struct BaseScreen /// @see Screen::mouseButtonPressed() virtual void mouseButtonPressed(MEVENT me) = 0; + + /// @return true if screen can be locked. Note that returning + /// false here doesn't neccesarily mean that screen is also not + /// mergable (eg. lyrics screen is not lockable since that wouldn't + /// make much sense, but it's perfectly fine to merge it). + virtual bool isLockable() = 0; /// @return true if screen is mergable, ie. can be "proper" subwindow /// if one of the screens is locked. Screens that somehow resemble popups @@ -98,12 +104,6 @@ struct BaseScreen static void unlock(); protected: - /// @return true if screen can be locked. Note that returning - /// false here doesn't neccesarily mean that screen is also not - /// mergable (eg. lyrics screen is not lockable since that wouldn't - /// make much sense, but it's perfectly fine to merge it). - virtual bool isLockable() = 0; - /// Gets X offset and width of current screen to be used eg. in resize() function. /// @param adjust_locked_screen indicates whether this function should /// automatically adjust locked screen's dimensions (if there is one set) diff --git a/src/search_engine.h b/src/search_engine.h index e448ff11..0232540a 100644 --- a/src/search_engine.h +++ b/src/search_engine.h @@ -91,6 +91,7 @@ struct SearchEngine: Screen>, HasSongs, Searchable, Tabbable virtual void spacePressed() OVERRIDE; virtual void mouseButtonPressed(MEVENT me) OVERRIDE; + virtual bool isLockable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; } // Searchable implementation @@ -113,9 +114,6 @@ struct SearchEngine: Screen>, HasSongs, Searchable, Tabbable static size_t SearchButton; static size_t ResetButton; -protected: - virtual bool isLockable() OVERRIDE { return true; } - private: void Prepare(); void Search(); diff --git a/src/sel_items_adder.h b/src/sel_items_adder.h index 525705a9..5adfcd5a 100644 --- a/src/sel_items_adder.h +++ b/src/sel_items_adder.h @@ -47,10 +47,8 @@ struct SelectedItemsAdder: Screen> *> virtual void spacePressed() OVERRIDE { } virtual void mouseButtonPressed(MEVENT me) OVERRIDE; - virtual bool isMergable() OVERRIDE { return false; } - -protected: virtual bool isLockable() OVERRIDE { return false; } + virtual bool isMergable() OVERRIDE { return false; } private: void populatePlaylistSelector(BaseScreen *screen); diff --git a/src/server_info.h b/src/server_info.h index 5213fcc0..54d0b362 100644 --- a/src/server_info.h +++ b/src/server_info.h @@ -42,10 +42,8 @@ struct ServerInfo: Screen, Tabbable virtual void enterPressed() OVERRIDE { } virtual void spacePressed() OVERRIDE { } - virtual bool isMergable() OVERRIDE { return false; } - -protected: virtual bool isLockable() OVERRIDE { return false; } + virtual bool isMergable() OVERRIDE { return false; } private: void SetDimensions(); diff --git a/src/song_info.h b/src/song_info.h index 9c07261d..2933740a 100644 --- a/src/song_info.h +++ b/src/song_info.h @@ -48,14 +48,12 @@ struct SongInfo: Screen, Tabbable virtual void enterPressed() OVERRIDE { } virtual void spacePressed() OVERRIDE { } + virtual bool isLockable() OVERRIDE { return false; } virtual bool isMergable() OVERRIDE { return true; } // private members static const Metadata Tags[]; -protected: - virtual bool isLockable() OVERRIDE { return false; } - private: void PrepareSong(MPD::Song &); }; diff --git a/src/sort_playlist.h b/src/sort_playlist.h index 32277496..9459c8ad 100644 --- a/src/sort_playlist.h +++ b/src/sort_playlist.h @@ -45,15 +45,13 @@ struct SortPlaylistDialog virtual void spacePressed() OVERRIDE { } virtual void mouseButtonPressed(MEVENT me) OVERRIDE; + virtual bool isLockable() OVERRIDE { return false; } virtual bool isMergable() OVERRIDE { return false; } // private members void moveSortOrderUp(); void moveSortOrderDown(); -protected: - virtual bool isLockable() OVERRIDE { return false; } - private: void moveSortOrderHint() const; void sort() const; diff --git a/src/tag_editor.h b/src/tag_editor.h index 5e83990b..0ca0d8ee 100644 --- a/src/tag_editor.h +++ b/src/tag_editor.h @@ -49,6 +49,7 @@ struct TagEditor: Screen, HasColumns, HasSongs, Searchable, Tabbab virtual void spacePressed() OVERRIDE; virtual void mouseButtonPressed(MEVENT) OVERRIDE; + virtual bool isLockable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; } // Searchable implementation @@ -79,9 +80,6 @@ struct TagEditor: Screen, HasColumns, HasSongs, Searchable, Tabbab NC::Menu *TagTypes; NC::Menu *Tags; -protected: - virtual bool isLockable() OVERRIDE { return true; } - private: void SetDimensions(size_t, size_t); diff --git a/src/tiny_tag_editor.h b/src/tiny_tag_editor.h index 11e10c9b..53a32707 100644 --- a/src/tiny_tag_editor.h +++ b/src/tiny_tag_editor.h @@ -46,14 +46,12 @@ struct TinyTagEditor: Screen> virtual void spacePressed() OVERRIDE { } virtual void mouseButtonPressed(MEVENT me) OVERRIDE; + virtual bool isLockable() OVERRIDE { return false; } virtual bool isMergable() OVERRIDE { return true; } // private members void SetEdited(const MPD::Song &); -protected: - virtual bool isLockable() OVERRIDE { return false; } - private: bool getTags(); MPD::MutableSong itsEdited; diff --git a/src/visualizer.h b/src/visualizer.h index f6e028df..f756e955 100644 --- a/src/visualizer.h +++ b/src/visualizer.h @@ -53,6 +53,7 @@ struct Visualizer: Screen, Tabbable virtual void spacePressed() OVERRIDE; virtual void mouseButtonPressed(MEVENT) OVERRIDE { } + virtual bool isLockable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; } // private members @@ -60,9 +61,6 @@ struct Visualizer: Screen, Tabbable void ResetFD(); void FindOutputID(); -protected: - virtual bool isLockable() OVERRIDE { return true; } - private: void DrawSoundWave(int16_t *, ssize_t, size_t, size_t); void DrawSoundWaveStereo(int16_t *, int16_t *, ssize_t, size_t);