move all externs to global.h

This commit is contained in:
Andrzej Rybczak
2009-02-11 09:45:23 +01:00
parent cecb11c3d8
commit 29301aefd5
13 changed files with 204 additions and 158 deletions

View File

@@ -9,6 +9,6 @@ INCLUDES= $(all_includes)
# the library search path. # the library search path.
ncmpcpp_LDFLAGS = $(all_libraries) ncmpcpp_LDFLAGS = $(all_libraries)
noinst_HEADERS = browser.h charset.h clock.h display.h help.h helpers.h \ noinst_HEADERS = browser.h charset.h clock.h display.h global.h help.h \
lyrics.h menu.h mpdpp.h scrollpad.h search_engine.h settings.h song.h \ helpers.h lyrics.h menu.h mpdpp.h scrollpad.h search_engine.h settings.h song.h \
status_checker.h tag_editor.h window.h status_checker.h tag_editor.h window.h

View File

@@ -25,28 +25,17 @@
#include "browser.h" #include "browser.h"
#include "charset.h" #include "charset.h"
#include "display.h" #include "display.h"
#include "global.h"
#include "helpers.h" #include "helpers.h"
#include "settings.h" #include "settings.h"
#ifdef HAVE_TAGLIB_H #ifdef HAVE_TAGLIB_H
# include "tag_editor.h" # include "tag_editor.h"
#endif // HAVE_TAGLIB_H #endif // HAVE_TAGLIB_H
using namespace Global;
using namespace MPD; using namespace MPD;
using std::string; using std::string;
extern Connection *Mpd;
extern ncmpcpp_config Config;
extern Menu<Song> *mPlaylist;
extern Menu<Item> *mBrowser;
extern NcmpcppScreen current_screen;
extern string browsed_dir;
extern int browsed_dir_scroll_begin;
namespace namespace
{ {
const char *supported_extensions[] = { "wma", "asf", "rm", "mp1", "mp2", "mp3", "mp4", "m4a", "flac", "ogg", "wav", "au", "aiff", "aif", "ac3", "aac", "mpc", "it", "mod", "s3m", "xm", "wv", 0 }; const char *supported_extensions[] = { "wma", "asf", "rm", "mp1", "mp2", "mp3", "mp4", "m4a", "flac", "ogg", "wav", "au", "aiff", "aif", "ac3", "aac", "mpc", "it", "mod", "s3m", "xm", "wv", 0 };

View File

@@ -22,6 +22,7 @@
#include "clock.h" #include "clock.h"
#include "display.h" #include "display.h"
#include "global.h"
#ifdef ENABLE_CLOCK #ifdef ENABLE_CLOCK
@@ -71,9 +72,9 @@ void Display::Clock(Window &w, const tm *time)
char buf[54]; char buf[54];
strftime(buf, 64, "%x", time); strftime(buf, 64, "%x", time);
attron(COLOR_PAIR(Config.main_color)); attron(COLOR_PAIR(Global::Config.main_color));
mvprintw(w.GetStartY()+w.GetHeight(), w.GetStartX()+(w.GetWidth()-strlen(buf))/2, "%s", buf); mvprintw(w.GetStartY()+w.GetHeight(), w.GetStartX()+(w.GetWidth()-strlen(buf))/2, "%s", buf);
attroff(COLOR_PAIR(Config.main_color)); attroff(COLOR_PAIR(Global::Config.main_color));
refresh(); refresh();
for (int k = 0; k < 6; k++) for (int k = 0; k < 6; k++)
@@ -97,7 +98,7 @@ void Display::Clock(Window &w, const tm *time)
{ {
w.GotoXY(2*j+2, i); w.GotoXY(2*j+2, i);
} }
if (Config.clock_display_seconds || j < 18) if (Global::Config.clock_display_seconds || j < 18)
w << " "; w << " ";
} }
} }

View File

@@ -19,8 +19,11 @@
***************************************************************************/ ***************************************************************************/
#include "display.h" #include "display.h"
#include "global.h"
#include "helpers.h" #include "helpers.h"
using Global::Config;
using Global::mPlaylist;
using MPD::Song; using MPD::Song;
using std::string; using std::string;
@@ -90,8 +93,6 @@ string Display::Columns(string st)
void Display::TotalPlaylistLength(Window &w) void Display::TotalPlaylistLength(Window &w)
{ {
extern Menu<MPD::Song> *mPlaylist;
const int MINUTE = 60; const int MINUTE = 60;
const int HOUR = 60*MINUTE; const int HOUR = 60*MINUTE;
const int DAY = 24*HOUR; const int DAY = 24*HOUR;

119
src/global.h Normal file
View File

@@ -0,0 +1,119 @@
/***************************************************************************
* Copyright (C) 2008-2009 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 _GLOBAL_H
#define _GLOBAL_H
#include "settings.h"
#include "ncmpcpp.h"
#include "mpdpp.h"
/// FIXME: this is absolutely shitty, I need to get rid of this.
namespace Global
{
extern ncmpcpp_config Config;
extern ncmpcpp_keys Key;
extern Window *wCurrent;
extern Window *wPrev;
extern Menu<MPD::Song> *mPlaylist;
extern Menu<MPD::Item> *mBrowser;
extern Menu< std::pair<Buffer *, MPD::Song *> > *mSearcher;
extern Window *wLibActiveCol;
extern Menu<std::string> *mLibArtists;
extern Menu<string_pair> *mLibAlbums;
extern Menu<MPD::Song> *mLibSongs;
# ifdef HAVE_TAGLIB_H
extern Window *wTagEditorActiveCol;
extern Menu<Buffer> *mTagEditor;
extern Menu<string_pair> *mEditorAlbums;
extern Menu<string_pair> *mEditorDirs;
# endif // HAVE_TAGLIB_H
// blah, I use below in conditionals.
extern Menu<string_pair> *mEditorLeftCol;
extern Menu<std::string> *mEditorTagTypes;
extern Menu<MPD::Song> *mEditorTags;
extern Window *wPlaylistEditorActiveCol;
extern Menu<std::string> *mPlaylistList;
extern Menu<MPD::Song> *mPlaylistEditor;
extern Scrollpad *sHelp;
extern Scrollpad *sLyrics;
extern Scrollpad *sInfo;
extern Window *wHeader;
extern Window *wFooter;
# ifdef ENABLE_CLOCK
extern Scrollpad *wClock;
# endif
extern MPD::Connection *Mpd;
extern int now_playing;
extern int lock_statusbar_delay;
extern size_t browsed_dir_scroll_begin;
extern time_t timer;
extern std::string browsed_dir;
extern std::string editor_browsed_dir;
extern std::string editor_highlighted_dir;
extern NcmpcppScreen current_screen;
extern NcmpcppScreen prev_screen;
# ifdef HAVE_CURL_CURL_H
extern pthread_t lyrics_downloader;
extern pthread_t artist_info_downloader;
extern bool lyrics_ready;
extern bool artist_info_ready;
# endif
extern bool dont_change_now_playing;
extern bool block_progressbar_update;
extern bool block_playlist_update;
extern bool block_item_list_update;
extern bool messages_allowed;
extern bool redraw_header;
extern bool reload_lyrics;
extern std::string volume_state;
extern bool header_update_status;
extern bool header_update_status;
extern bool search_case_sensitive;
extern bool search_match_to_pattern;
extern std::string volume_state;
extern const char *search_mode_normal;
extern const char *search_mode_strict;
}
#endif

View File

@@ -20,15 +20,14 @@
#include "mpdpp.h" #include "mpdpp.h"
#include "global.h"
#include "help.h" #include "help.h"
#include "settings.h" #include "settings.h"
using Global::Key;
using Global::Mpd;
using std::string; using std::string;
extern MPD::Connection *Mpd;
extern ncmpcpp_keys Key;
namespace namespace
{ {
string DisplayKeys(int *key, int size = 2) string DisplayKeys(int *key, int size = 2)

View File

@@ -22,23 +22,17 @@
#include <iostream> #include <iostream>
#include "charset.h" #include "charset.h"
#include "global.h"
#include "helpers.h" #include "helpers.h"
#include "tag_editor.h" #include "tag_editor.h"
using namespace MPD; using namespace MPD;
using Global::Config;
using Global::Mpd;
using Global::mPlaylist;
using Global::wFooter;
using std::string; using std::string;
extern Connection *Mpd;
extern Menu<Song> *mPlaylist;
extern Menu<MPD::Item> *mBrowser;
extern Window *wFooter;
extern NcmpcppScreen current_screen;
extern bool search_case_sensitive;
extern bool search_match_to_pattern;
namespace namespace
{ {
inline void remove_the_word(string &s) inline void remove_the_word(string &s)

View File

@@ -22,30 +22,25 @@
#include <fstream> #include <fstream>
#include "charset.h" #include "charset.h"
#include "global.h"
#include "helpers.h" #include "helpers.h"
#include "lyrics.h" #include "lyrics.h"
#include "settings.h" #include "settings.h"
#include "song.h" #include "song.h"
using namespace Global;
using std::vector; using std::vector;
using std::string; using std::string;
extern Window *wCurrent;
extern Scrollpad *sLyrics;
extern Scrollpad *sInfo;
const string artists_folder = home_folder + "/.ncmpcpp/artists"; const string artists_folder = home_folder + "/.ncmpcpp/artists";
const string lyrics_folder = home_folder + "/.lyrics"; const string lyrics_folder = home_folder + "/.lyrics";
#ifdef HAVE_CURL_CURL_H #ifdef HAVE_CURL_CURL_H
extern pthread_t lyrics_downloader;
extern pthread_t artist_info_downloader;
extern bool lyrics_ready;
extern bool artist_info_ready;
pthread_mutex_t curl = PTHREAD_MUTEX_INITIALIZER;
namespace namespace
{ {
pthread_mutex_t curl = PTHREAD_MUTEX_INITIALIZER;
size_t write_data(char *buffer, size_t size, size_t nmemb, string data) size_t write_data(char *buffer, size_t size, size_t nmemb, string data)
{ {
size_t result = size * nmemb; size_t result = size * nmemb;

View File

@@ -34,6 +34,7 @@
#include "charset.h" #include "charset.h"
#include "clock.h" #include "clock.h"
#include "display.h" #include "display.h"
#include "global.h"
#include "help.h" #include "help.h"
#include "helpers.h" #include "helpers.h"
#include "lyrics.h" #include "lyrics.h"
@@ -88,93 +89,84 @@
vFoundPositions.clear(); \ vFoundPositions.clear(); \
} while (0) } while (0)
using namespace Global;
using namespace MPD; using namespace MPD;
using std::make_pair; using std::make_pair;
using std::string; using std::string;
using std::vector; using std::vector;
ncmpcpp_config Config; ncmpcpp_config Global::Config;
ncmpcpp_keys Key; ncmpcpp_keys Global::Key;
Window *wCurrent; Window *Global::wCurrent;
Window *wPrev; Window *Global::wPrev;
Menu<Song> *mPlaylist; Menu<Song> *Global::mPlaylist;
Menu<Item> *mBrowser; Menu<Item> *Global::mBrowser;
Menu< std::pair<Buffer *, Song *> > *mSearcher; Menu< std::pair<Buffer *, Song *> > *Global::mSearcher;
Window *wLibActiveCol; Window *Global::wLibActiveCol;
Menu<string> *mLibArtists; Menu<string> *Global::mLibArtists;
Menu<string_pair> *mLibAlbums; Menu<string_pair> *Global::mLibAlbums;
Menu<Song> *mLibSongs; Menu<Song> *Global::mLibSongs;
#ifdef HAVE_TAGLIB_H #ifdef HAVE_TAGLIB_H
Window *wTagEditorActiveCol; Window *Global::wTagEditorActiveCol;
Menu<Buffer> *mTagEditor; Menu<Buffer> *Global::mTagEditor;
Menu<string_pair> *mEditorAlbums; Menu<string_pair> *Global::mEditorAlbums;
Menu<string_pair> *mEditorDirs; Menu<string_pair> *Global::mEditorDirs;
#endif // HAVE_TAGLIB_H #endif // HAVE_TAGLIB_H
// blah, I use below in conditionals. // blah, I use below in conditionals.
Menu<string_pair> *mEditorLeftCol; Menu<string_pair> *Global::mEditorLeftCol;
Menu<string> *mEditorTagTypes; Menu<string> *Global::mEditorTagTypes;
Menu<Song> *mEditorTags; Menu<Song> *Global::mEditorTags;
Window *wPlaylistEditorActiveCol; Window *Global::wPlaylistEditorActiveCol;
Menu<string> *mPlaylistList; Menu<string> *Global::mPlaylistList;
Menu<Song> *mPlaylistEditor; Menu<Song> *Global::mPlaylistEditor;
Scrollpad *sHelp; Scrollpad *Global::sHelp;
Scrollpad *sLyrics; Scrollpad *Global::sLyrics;
Scrollpad *sInfo; Scrollpad *Global::sInfo;
Window *wHeader; Window *Global::wHeader;
Window *wFooter; Window *Global::wFooter;
#ifdef ENABLE_CLOCK #ifdef ENABLE_CLOCK
Scrollpad *wClock; Scrollpad *Global::wClock;
#endif #endif
Connection *Mpd; Connection *Global::Mpd;
int now_playing = -1; int Global::now_playing = -1;
int lock_statusbar_delay = -1; int Global::lock_statusbar_delay = -1;
size_t browsed_dir_scroll_begin = 0; size_t Global::browsed_dir_scroll_begin = 0;
time_t timer; time_t Global::timer;
string browsed_dir = "/"; string Global::browsed_dir = "/";
string editor_browsed_dir = "/"; string Global::editor_browsed_dir = "/";
string editor_highlighted_dir; string Global::editor_highlighted_dir;
NcmpcppScreen current_screen; NcmpcppScreen Global::current_screen;
NcmpcppScreen prev_screen; NcmpcppScreen Global::prev_screen;
#ifdef HAVE_CURL_CURL_H #ifdef HAVE_CURL_CURL_H
pthread_t lyrics_downloader; pthread_t Global::lyrics_downloader;
pthread_t artist_info_downloader; pthread_t Global::artist_info_downloader;
bool lyrics_ready = 0; bool Global::lyrics_ready = 0;
bool artist_info_ready = 0; bool Global::artist_info_ready = 0;
#endif #endif
bool dont_change_now_playing = 0; bool Global::dont_change_now_playing = 0;
bool block_progressbar_update = 0; bool Global::block_progressbar_update = 0;
bool block_playlist_update = 0; bool Global::block_playlist_update = 0;
bool block_item_list_update = 0; bool Global::block_item_list_update = 0;
bool messages_allowed = 0; bool Global::messages_allowed = 0;
//bool redraw_screen = 0; bool Global::redraw_header = 1;
bool redraw_header = 1; bool Global::reload_lyrics = 0;
bool reload_lyrics = 0;
extern bool header_update_status;
extern bool search_case_sensitive;
extern bool search_match_to_pattern;
extern string volume_state;
extern const char *search_mode_normal;
extern const char *search_mode_strict;
const char *message_part_of_songs_added = "Only part of requested songs' list added to playlist!"; const char *message_part_of_songs_added = "Only part of requested songs' list added to playlist!";

View File

@@ -19,22 +19,20 @@
***************************************************************************/ ***************************************************************************/
#include "display.h" #include "display.h"
#include "global.h"
#include "helpers.h" #include "helpers.h"
#include "search_engine.h" #include "search_engine.h"
#include "settings.h" #include "settings.h"
using namespace MPD; using namespace MPD;
using namespace Global;
using std::string; using std::string;
extern Connection *Mpd; bool Global::search_match_to_pattern = 1;
extern Menu<Song> *mPlaylist; bool Global::search_case_sensitive = 0;
extern Menu< std::pair<Buffer *, Song *> > *mSearcher;
bool search_match_to_pattern = 1; const char *Global::search_mode_normal = "Match if tag contains searched phrase";
bool search_case_sensitive = 0; const char *Global::search_mode_strict = "Match only if both values are the same";
const char *search_mode_normal = "Match if tag contains searched phrase";
const char *search_mode_strict = "Match only if both values are the same";
void UpdateFoundList() void UpdateFoundList()
{ {

View File

@@ -162,8 +162,6 @@ struct ncmpcpp_config
int lyrics_db; int lyrics_db;
}; };
extern ncmpcpp_config Config;
void CreateConfigDir(); void CreateConfigDir();
void DefaultKeys(ncmpcpp_keys &); void DefaultKeys(ncmpcpp_keys &);
void DefaultConfiguration(ncmpcpp_config &); void DefaultConfiguration(ncmpcpp_config &);

View File

@@ -23,52 +23,19 @@
#include "browser.h" #include "browser.h"
#include "charset.h" #include "charset.h"
#include "global.h"
#include "helpers.h" #include "helpers.h"
#include "search_engine.h" #include "search_engine.h"
#include "settings.h" #include "settings.h"
#include "status_checker.h" #include "status_checker.h"
using namespace Global;
using namespace MPD; using namespace MPD;
using std::string; using std::string;
extern Connection *Mpd; string Global::volume_state;
extern Menu<Song> *mPlaylist; bool Global::header_update_status = 0;
extern Menu<Item> *mBrowser;
extern Menu<string> *mLibArtists;
extern Menu<Song> *mLibSongs;
extern Menu<Song> *mPlaylistEditor;
#ifdef HAVE_TAGLIB_H
extern Menu<string> *mEditorAlbums;
extern Menu<string> *mEditorDirs;
#endif // HAVE_TAGLIB_H
extern Window *wHeader;
extern Window *wFooter;
extern time_t timer;
extern int now_playing;
extern int lock_statusbar_delay;
extern string browsed_dir;
extern NcmpcppScreen current_screen;
extern NcmpcppScreen prev_screen;
extern bool dont_change_now_playing;
extern bool block_progressbar_update;
extern bool block_playlist_update;
extern bool block_item_list_update;
extern bool messages_allowed;
extern bool redraw_header;
extern bool reload_lyrics;
string volume_state;
bool header_update_status = 0;
namespace namespace
{ {

View File

@@ -31,20 +31,13 @@
#include "charset.h" #include "charset.h"
#include "display.h" #include "display.h"
#include "global.h"
#include "helpers.h" #include "helpers.h"
#include "status_checker.h" #include "status_checker.h"
using namespace Global;
using namespace MPD; using namespace MPD;
extern ncmpcpp_keys Key;
extern Connection *Mpd;
extern Menu<Song> *mPlaylist;
extern Menu<Buffer> *mTagEditor;
extern Window *wFooter;
extern Window *wPrev;
namespace namespace
{ {
const string patterns_list_file = config_dir + "patterns.list"; const string patterns_list_file = config_dir + "patterns.list";