diff --git a/ChangeLog b/ChangeLog index 5cb7d3722..224ac9b10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -59,6 +59,7 @@ different to those calculated. 37. Don't use italic text for grouped view headers. 38. Save scaled covers as PNG files. +39. Use Q_GLOBAL_STATIC for Qt4.8, and Qt>=5.1 Qt-only builds. 1.3.3 ----- diff --git a/context/ultimatelyrics.cpp b/context/ultimatelyrics.cpp index 72442d5d9..728f9e1f2 100644 --- a/context/ultimatelyrics.cpp +++ b/context/ultimatelyrics.cpp @@ -24,20 +24,19 @@ #include "ultimatelyrics.h" #include "ultimatelyricsprovider.h" #include "settings.h" +#include "globalstatic.h" #include #include #include #include #include #include -#ifdef ENABLE_KDE_SUPPORT -#include -K_GLOBAL_STATIC(UltimateLyrics, instance) -#endif #if defined Q_OS_WIN #include #endif +GLOBAL_STATIC(UltimateLyrics, instance) + static bool compareLyricProviders(const UltimateLyricsProvider *a, const UltimateLyricsProvider *b) { return a->getRelevance() < b->getRelevance(); @@ -110,19 +109,6 @@ static UltimateLyricsProvider * parseProvider(QXmlStreamReader *reader) return scraper; } -UltimateLyrics * UltimateLyrics::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static UltimateLyrics *instance=0; - if(!instance) { - instance=new UltimateLyrics; - } - return instance; - #endif -} - void UltimateLyrics::release() { foreach (UltimateLyricsProvider *provider, providers) { diff --git a/dbus/powermanagement.cpp b/dbus/powermanagement.cpp index b45fdcca0..0730d6171 100644 --- a/dbus/powermanagement.cpp +++ b/dbus/powermanagement.cpp @@ -22,12 +22,10 @@ */ #include "powermanagement.h" - +#include "globalstatic.h" #ifdef ENABLE_KDE_SUPPORT #include -#include #include -K_GLOBAL_STATIC(PowerManagement, instance) #else #include "inhibitinterface.h" #include "policyagentinterface.h" @@ -36,18 +34,7 @@ K_GLOBAL_STATIC(PowerManagement, instance) #include "localize.h" #include "mpdstatus.h" -PowerManagement * PowerManagement::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static PowerManagement *instance=0; - if(!instance) { - instance=new PowerManagement; - } - return instance; - #endif -} +GLOBAL_STATIC(PowerManagement, instance) PowerManagement::PowerManagement() : inhibitSuspendWhilstPlaying(false) diff --git a/devices/filejob.cpp b/devices/filejob.cpp index fd28e7ff6..12ff7aea8 100644 --- a/devices/filejob.cpp +++ b/devices/filejob.cpp @@ -27,28 +27,13 @@ #include "songview.h" #include "covers.h" #include "thread.h" +#include "globalstatic.h" #include #include #include #include -#ifdef ENABLE_KDE_SUPPORT -#include -K_GLOBAL_STATIC(FileThread, instance) -#endif - -FileThread * FileThread::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static FileThread *instance=0; - if(!instance) { - instance=new FileThread; - } - return instance; - #endif -} +GLOBAL_STATIC(FileThread, instance) FileThread::FileThread() : thread(0) diff --git a/devices/mountpoints.cpp b/devices/mountpoints.cpp index 096366428..627922f97 100644 --- a/devices/mountpoints.cpp +++ b/devices/mountpoints.cpp @@ -22,26 +22,12 @@ */ #include "mountpoints.h" +#include "globalstatic.h" #include #include #include -#ifdef ENABLE_KDE_SUPPORT -#include -K_GLOBAL_STATIC(MountPoints, instance) -#endif -MountPoints * MountPoints::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static MountPoints *instance=0; - if(!instance) { - instance=new MountPoints; - } - return instance; - #endif -} +GLOBAL_STATIC(MountPoints, instance) MountPoints::MountPoints() : token(0) diff --git a/dynamic/dynamic.cpp b/dynamic/dynamic.cpp index 8b6b45741..129249a0e 100644 --- a/dynamic/dynamic.cpp +++ b/dynamic/dynamic.cpp @@ -32,10 +32,7 @@ #include "localize.h" #include "qtplural.h" #include "actioncollection.h" -#ifdef ENABLE_KDE_SUPPORT -#include -K_GLOBAL_STATIC(Dynamic, instance) -#endif +#include "globalstatic.h" #include #include #include @@ -50,7 +47,6 @@ K_GLOBAL_STATIC(Dynamic, instance) #endif #include #include - #if defined ENABLE_MODEL_TEST #include "modeltest.h" #endif @@ -122,21 +118,7 @@ QString Dynamic::toString(Command cmd) return QString(); } -Dynamic * Dynamic::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static Dynamic *instance=0; - if(!instance) { - instance=new Dynamic; - #if defined ENABLE_MODEL_TEST - new ModelTest(instance, instance); - #endif - } - return instance; - #endif -} +GLOBAL_STATIC(Dynamic, instance) const QString Dynamic::constRuleKey=QLatin1String("Rule"); const QString Dynamic::constArtistKey=QLatin1String("Artist"); @@ -215,6 +197,9 @@ Dynamic::Dynamic() QTimer::singleShot(500, this, SLOT(checkHelper())); startAction = ActionCollection::get()->createAction("startdynamic", i18n("Start Dynamic Playlist"), "media-playback-start"); stopAction = ActionCollection::get()->createAction("stopdynamic", i18n("Stop Dynamic Mode"), "process-stop"); + #if defined ENABLE_MODEL_TEST + new ModelTest(this, this); + #endif } QVariant Dynamic::headerData(int, Qt::Orientation, int) const diff --git a/gui/covers.cpp b/gui/covers.cpp index 0b553b0fa..708c0bd70 100644 --- a/gui/covers.cpp +++ b/gui/covers.cpp @@ -38,6 +38,7 @@ #ifdef TAGLIB_FOUND #include "tags.h" #endif +#include "globalstatic.h" #include #include #include @@ -54,14 +55,13 @@ #include #include #include - #ifdef ENABLE_KDE_SUPPORT #include -#include #include -K_GLOBAL_STATIC(Covers, instance) #endif +GLOBAL_STATIC(Covers, instance) + #include static bool debugIsEnabled=false; #define DBUG_CLASS(CLASS) if (debugIsEnabled) qWarning() << CLASS << QThread::currentThread()->objectName() << __FUNCTION__ @@ -346,19 +346,6 @@ static Covers::Image otherAppCover(const CoverDownloader::Job &job) const QSize Covers::constMaxSize(600, 600); -Covers * Covers::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static Covers *instance=0; - if(!instance) { - instance=new Covers; - } - return instance; - #endif -} - //bool Covers::isCoverFile(const QString &file) //{ // return standardNames().contains(file); diff --git a/gui/currentcover.cpp b/gui/currentcover.cpp index cbe6e6f7c..37c3ad4a1 100644 --- a/gui/currentcover.cpp +++ b/gui/currentcover.cpp @@ -26,11 +26,9 @@ #include "config.h" #include "icons.h" #include "utils.h" +#include "globalstatic.h" #include #include -#ifdef ENABLE_KDE_SUPPORT -K_GLOBAL_STATIC(CurrentCover, instance) -#endif #ifndef Q_OS_WIN static void themes(const QString &theme, QStringList &iconThemes) @@ -114,18 +112,7 @@ QString CurrentCover::findIcon(const QStringList &names) } #endif -CurrentCover * CurrentCover::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static CurrentCover *instance=0; - if(!instance) { - instance=new CurrentCover; - } - return instance; - #endif -} +GLOBAL_STATIC(CurrentCover, instance) CurrentCover::CurrentCover() : QObject(0) diff --git a/gui/mediakeys.cpp b/gui/mediakeys.cpp index f93c58d40..37ecf763c 100644 --- a/gui/mediakeys.cpp +++ b/gui/mediakeys.cpp @@ -31,22 +31,9 @@ #include "multimediakeysinterface.h" #include "stdactions.h" #include "settings.h" -#ifdef ENABLE_KDE_SUPPORT -K_GLOBAL_STATIC(MediaKeys, instance) -#endif +#include "globalstatic.h" -MediaKeys * MediaKeys::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static MediaKeys *instance=0; - if(!instance) { - instance=new MediaKeys; - } - return instance; - #endif -} +GLOBAL_STATIC(MediaKeys, instance) QString MediaKeys::toString(InterfaceType i) { diff --git a/gui/settings.cpp b/gui/settings.cpp index 5d0d34553..ba76f0220 100644 --- a/gui/settings.cpp +++ b/gui/settings.cpp @@ -29,6 +29,7 @@ #include "mpdparseutils.h" #include "utils.h" #include "mediakeys.h" +#include "globalstatic.h" #ifdef ENABLE_KDE_SUPPORT #include #include @@ -38,8 +39,6 @@ #include #include #include - -K_GLOBAL_STATIC(Settings, instance) #else #include "mediakeys.h" #endif @@ -49,18 +48,7 @@ K_GLOBAL_STATIC(Settings, instance) #define RESTRICT(VAL, MIN_VAL, MAX_VAL) (VALMAX_VAL ? MAX_VAL : VAL)) -Settings * Settings::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static Settings *instance=0; - if (!instance) { - instance=new Settings; - } - return instance; - #endif -} +GLOBAL_STATIC(Settings, instance) struct MpdDefaults { diff --git a/gui/stdactions.cpp b/gui/stdactions.cpp index 14c6a1638..339d7b122 100644 --- a/gui/stdactions.cpp +++ b/gui/stdactions.cpp @@ -31,24 +31,10 @@ #endif #include "icon.h" #include "icons.h" +#include "globalstatic.h" #include -#ifdef ENABLE_KDE_SUPPORT -#include -K_GLOBAL_STATIC(StdActions, instance) -#endif -StdActions * StdActions::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static StdActions *instance=0; - if(!instance) { - instance=new StdActions; - } - return instance; - #endif -} +GLOBAL_STATIC(StdActions, instance) StdActions::StdActions() { diff --git a/http/httpserver.cpp b/http/httpserver.cpp index c4a0cf287..d3a2e37e8 100644 --- a/http/httpserver.cpp +++ b/http/httpserver.cpp @@ -28,16 +28,13 @@ #endif #include "settings.h" #include "thread.h" +#include "globalstatic.h" #include #include #include #if QT_VERSION >= 0x050000 #include #endif -#ifdef ENABLE_KDE_SUPPORT -#include -K_GLOBAL_STATIC(HttpServer, instance) -#endif #include static bool debugIsEnabled=false; @@ -60,18 +57,7 @@ bool HttpServer::debugEnabled() return debugIsEnabled; } -HttpServer * HttpServer::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static HttpServer *instance=0; - if(!instance) { - instance=new HttpServer; - } - return instance; - #endif -} +GLOBAL_STATIC(HttpServer, instance) #ifdef ENABLE_HTTP_SERVER HttpServer::HttpServer() diff --git a/models/albumsmodel.cpp b/models/albumsmodel.cpp index 026bda5a9..e78c1e2ea 100644 --- a/models/albumsmodel.cpp +++ b/models/albumsmodel.cpp @@ -29,9 +29,7 @@ #include #include "localize.h" #include "qtplural.h" -#ifdef ENABLE_KDE_SUPPORT -#include -#endif +#include "globalstatic.h" #include "albumsmodel.h" #include "settings.h" #include "musiclibraryitemsong.h" @@ -47,32 +45,13 @@ #include "icons.h" #include "utils.h" #include "config.h" - #if defined ENABLE_MODEL_TEST #include "modeltest.h" #endif static int sortAlbums=AlbumsModel::Sort_AlbumArtist; -#ifdef ENABLE_KDE_SUPPORT -K_GLOBAL_STATIC(AlbumsModel, instance) -#endif - -AlbumsModel * AlbumsModel::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static AlbumsModel *instance=0; - if(!instance) { - instance=new AlbumsModel; - #if defined ENABLE_MODEL_TEST - new ModelTest(instance, instance); - #endif - } - return instance; - #endif -} +GLOBAL_STATIC(AlbumsModel, instance) static MusicLibraryItemAlbum::CoverSize coverSize=MusicLibraryItemAlbum::CoverMedium; static QPixmap *theDefaultIcon=0; @@ -124,6 +103,9 @@ AlbumsModel::AlbumsModel(QObject *parent) , enabled(false) // , coversRequested(false) { + #if defined ENABLE_MODEL_TEST + new ModelTest(this, this); + #endif } AlbumsModel::~AlbumsModel() diff --git a/models/devicesmodel.cpp b/models/devicesmodel.cpp index 7a1fdc46e..cb6e520b7 100644 --- a/models/devicesmodel.cpp +++ b/models/devicesmodel.cpp @@ -43,6 +43,7 @@ #if defined CDDB_FOUND || defined MUSICBRAINZ5_FOUND #include "audiocddevice.h" #endif +#include "globalstatic.h" #include #include #include @@ -58,7 +59,6 @@ #include #include #include -K_GLOBAL_STATIC(DevicesModel, instance) #else #include "solid-lite/device.h" #include "solid-lite/deviceinterface.h" @@ -69,7 +69,6 @@ K_GLOBAL_STATIC(DevicesModel, instance) #include "solid-lite/storagevolume.h" #include "solid-lite/opticaldisc.h" #endif - #if defined ENABLE_MODEL_TEST #include "modeltest.h" #endif @@ -91,21 +90,7 @@ QString DevicesModel::fixDevicePath(const QString &path) return path; } -DevicesModel * DevicesModel::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static DevicesModel *instance=0; - if(!instance) { - instance=new DevicesModel; - #if defined ENABLE_MODEL_TEST - new ModelTest(instance, instance); - #endif - } - return instance; - #endif -} +GLOBAL_STATIC(DevicesModel, instance) DevicesModel::DevicesModel(QObject *parent) : MultiMusicModel(parent) @@ -122,6 +107,9 @@ DevicesModel::DevicesModel(QObject *parent) #endif updateItemMenu(); connect(this, SIGNAL(add(const QStringList &, bool, quint8)), MPDConnection::self(), SLOT(add(const QStringList &, bool, quint8))); + #if defined ENABLE_MODEL_TEST + new ModelTest(this, this); + #endif } DevicesModel::~DevicesModel() diff --git a/models/digitallyimported.cpp b/models/digitallyimported.cpp index 4890be14a..66684b22e 100644 --- a/models/digitallyimported.cpp +++ b/models/digitallyimported.cpp @@ -26,13 +26,10 @@ #include "networkaccessmanager.h" #include "qjson/parser.h" #include "localize.h" +#include "globalstatic.h" #include #include #include -#ifdef ENABLE_KDE_SUPPORT -#include -K_GLOBAL_STATIC(DigitallyImported, instance) -#endif static const char * constDiGroup="DigitallyImported"; static const QStringList constPremiumValues=QStringList() << QLatin1String("premium_high") << QLatin1String("premium_medium") << QLatin1String("premium"); @@ -41,18 +38,7 @@ const QString DigitallyImported::constApiUserName=QLatin1String("ephemeron"); const QString DigitallyImported::constApiPassword=QLatin1String("dayeiph0ne@pp"); const QString DigitallyImported::constPublicValue=QLatin1String("public3"); -DigitallyImported * DigitallyImported::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static DigitallyImported *instance=0; - if(!instance) { - instance=new DigitallyImported; - } - return instance; - #endif -} +GLOBAL_STATIC(DigitallyImported, instance) DigitallyImported::DigitallyImported() : job(0) diff --git a/models/dirviewmodel.cpp b/models/dirviewmodel.cpp index 66986d4f3..2a904d8a4 100644 --- a/models/dirviewmodel.cpp +++ b/models/dirviewmodel.cpp @@ -46,15 +46,11 @@ #include "config.h" #include "utils.h" #include "qtiocompressor/qtiocompressor.h" - +#include "globalstatic.h" #if defined ENABLE_MODEL_TEST #include "modeltest.h" #endif -#ifdef ENABLE_KDE_SUPPORT -K_GLOBAL_STATIC(DirViewModel, instance) -#endif - static const QLatin1String constCacheName("-folder-listing"); static QString cacheFileName() @@ -67,21 +63,7 @@ static QString cacheFileName() return Utils::cacheDir(MusicLibraryModel::constLibraryCache)+fileName; } -DirViewModel * DirViewModel::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static DirViewModel *instance=0; - if(!instance) { - instance=new DirViewModel; - #if defined ENABLE_MODEL_TEST - new ModelTest(instance, instance); - #endif - } - return instance; - #endif -} +GLOBAL_STATIC(DirViewModel, instance) DirViewModel::DirViewModel(QObject *parent) : ActionModel(parent) @@ -89,6 +71,9 @@ DirViewModel::DirViewModel(QObject *parent) , databaseTimeUnreliable(false) , enabled(false) { + #if defined ENABLE_MODEL_TEST + new ModelTest(this, this); + #endif } DirViewModel::~DirViewModel() diff --git a/models/musiclibrarymodel.cpp b/models/musiclibrarymodel.cpp index 2b5e27ef5..ac35eb3a0 100644 --- a/models/musiclibrarymodel.cpp +++ b/models/musiclibrarymodel.cpp @@ -42,6 +42,7 @@ #include "icons.h" #include "stdactions.h" #include "qtiocompressor/qtiocompressor.h" +#include "globalstatic.h" #include #include #include @@ -50,33 +51,11 @@ #include #include #include -#ifdef ENABLE_KDE_SUPPORT -#include -#endif - #if defined ENABLE_MODEL_TEST #include "modeltest.h" #endif -#ifdef ENABLE_KDE_SUPPORT -K_GLOBAL_STATIC(MusicLibraryModel, instance) -#endif - -MusicLibraryModel * MusicLibraryModel::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static MusicLibraryModel *instance=0; - if(!instance) { - instance=new MusicLibraryModel; - #if defined ENABLE_MODEL_TEST - new ModelTest(instance, instance); - #endif - } - return instance; - #endif -} +GLOBAL_STATIC(MusicLibraryModel, instance) const QLatin1String MusicLibraryModel::constLibraryCache("library/"); const QLatin1String MusicLibraryModel::constLibraryExt(".xml"); @@ -160,6 +139,9 @@ MusicLibraryModel::MusicLibraryModel(QObject *parent, bool isMpdModel, bool isCh this, SLOT(updateMusicLibrary(MusicLibraryItemRoot *, QDateTime))); } rootItem->setModel(this); + #if defined ENABLE_MODEL_TEST + new ModelTest(this, this); + #endif } MusicLibraryModel::~MusicLibraryModel() diff --git a/models/onlineservicesmodel.cpp b/models/onlineservicesmodel.cpp index e0469b5d7..137782f62 100644 --- a/models/onlineservicesmodel.cpp +++ b/models/onlineservicesmodel.cpp @@ -50,37 +50,19 @@ #include "actioncollection.h" #include "networkaccessmanager.h" #include "settings.h" +#include "globalstatic.h" #include #include #include #include #include -#ifdef ENABLE_KDE_SUPPORT -#include -K_GLOBAL_STATIC(OnlineServicesModel, instance) -#endif - #if defined ENABLE_MODEL_TEST #include "modeltest.h" #endif QString OnlineServicesModel::constUdiPrefix("online-service://"); -OnlineServicesModel * OnlineServicesModel::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static OnlineServicesModel *instance=0; - if(!instance) { - instance=new OnlineServicesModel; - #if defined ENABLE_MODEL_TEST - new ModelTest(instance, instance); - #endif - } - return instance; - #endif -} +GLOBAL_STATIC(OnlineServicesModel, instance) OnlineServicesModel::OnlineServicesModel(QObject *parent) : MultiMusicModel(parent) @@ -94,6 +76,9 @@ OnlineServicesModel::OnlineServicesModel(QObject *parent) unSubscribeAction = ActionCollection::get()->createAction("unsubscribeonlineservice", i18n("Remove Subscription"), "list-remove"); refreshSubscriptionAction = ActionCollection::get()->createAction("refreshsubscription", i18n("Refresh Subscription"), "view-refresh"); load(); + #if defined ENABLE_MODEL_TEST + new ModelTest(this, this); + #endif } OnlineServicesModel::~OnlineServicesModel() diff --git a/models/playlistsmodel.cpp b/models/playlistsmodel.cpp index 64d687c5a..5f2bfa4b2 100644 --- a/models/playlistsmodel.cpp +++ b/models/playlistsmodel.cpp @@ -38,10 +38,7 @@ #include "tableview.h" #include "localize.h" #include "utils.h" -#ifdef ENABLE_KDE_SUPPORT -#include -K_GLOBAL_STATIC(PlaylistsModel, instance) -#endif +#include "globalstatic.h" #include "mpdparseutils.h" #include "mpdstats.h" #include "mpdconnection.h" @@ -68,21 +65,7 @@ QString PlaylistsModel::headerText(int col) } } -PlaylistsModel * PlaylistsModel::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static PlaylistsModel *instance=0; - if(!instance) { - instance=new PlaylistsModel; - #if defined ENABLE_MODEL_TEST - new ModelTest(instance, instance); - #endif - } - return instance; - #endif -} +GLOBAL_STATIC(PlaylistsModel, instance) PlaylistsModel::PlaylistsModel(QObject *parent) : ActionModel(parent) @@ -108,6 +91,9 @@ PlaylistsModel::PlaylistsModel(QObject *parent) connect(newAction, SIGNAL(triggered(bool)), this, SIGNAL(addToNew())); Action::initIcon(newAction); updateItemMenu(); + #if defined ENABLE_MODEL_TEST + new ModelTest(this, this); + #endif } PlaylistsModel::~PlaylistsModel() diff --git a/models/streamsmodel.cpp b/models/streamsmodel.cpp index 24fa78d28..a0c8306ba 100644 --- a/models/streamsmodel.cpp +++ b/models/streamsmodel.cpp @@ -43,6 +43,7 @@ #include "qtiocompressor/qtiocompressor.h" #include "utils.h" #include "config.h" +#include "globalstatic.h" #include #include #include @@ -58,35 +59,16 @@ #if QT_VERSION >= 0x050000 #include #endif -#ifdef ENABLE_KDE_SUPPORT -#include -K_GLOBAL_STATIC(StreamsModel, instance) -#endif #if defined Q_OS_WIN #include #endif #include #include - #if defined ENABLE_MODEL_TEST #include "modeltest.h" #endif -StreamsModel * StreamsModel::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static StreamsModel *instance=0; - if(!instance) { - instance=new StreamsModel; - #if defined ENABLE_MODEL_TEST - new ModelTest(instance, instance); - #endif - } - return instance; - #endif -} +GLOBAL_STATIC(StreamsModel, instance) const QString StreamsModel::constSubDir=QLatin1String("streams"); const QString StreamsModel::constCacheExt=QLatin1String(".xml.gz"); @@ -607,6 +589,9 @@ StreamsModel::StreamsModel(QObject *parent) } } } + #if defined ENABLE_MODEL_TEST + new ModelTest(this, this); + #endif } StreamsModel::~StreamsModel() diff --git a/mpd/mpdconnection.cpp b/mpd/mpdconnection.cpp index 5f3537e52..796921dab 100644 --- a/mpd/mpdconnection.cpp +++ b/mpd/mpdconnection.cpp @@ -30,9 +30,7 @@ #include "mpduser.h" #include "localize.h" #include "utils.h" -#ifdef ENABLE_KDE_SUPPORT -#include -#endif +#include "globalstatic.h" #include #include #include @@ -70,10 +68,6 @@ static const QByteArray constIdleMixerValue("mixer"); static const QByteArray constIdleOptionsValue("options"); static const QByteArray constIdleOutputValue("output"); -#ifdef ENABLE_KDE_SUPPORT -K_GLOBAL_STATIC(MPDConnection, conn) -#endif - static inline int socketTimeout(int dataSize) { static const int constDataBlock=100000; @@ -89,18 +83,7 @@ static QByteArray log(const QByteArray &data) } } -MPDConnection * MPDConnection::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return conn; - #else - static MPDConnection *conn=0; - if (!conn) { - conn=new MPDConnection; - } - return conn; - #endif -} +GLOBAL_STATIC(MPDConnection, instance) QByteArray MPDConnection::quote(int val) { diff --git a/mpd/mpduser.cpp b/mpd/mpduser.cpp index acaad7fb7..b5b85c1e3 100644 --- a/mpd/mpduser.cpp +++ b/mpd/mpduser.cpp @@ -26,6 +26,7 @@ #include "utils.h" #include "localize.h" #include "settings.h" +#include "globalstatic.h" #include #include #include @@ -37,10 +38,6 @@ #if defined Q_OS_WIN #include #endif -#ifdef ENABLE_KDE_SUPPORT -#include -K_GLOBAL_STATIC(MPDUser, instance) -#endif const QString MPDUser::constName=QLatin1String("-"); @@ -56,18 +53,7 @@ QString MPDUser::translatedName() return i18n("Personal"); } -MPDUser * MPDUser::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static MPDUser *instance=0; - if(!instance) { - instance=new MPDUser; - } - return instance; - #endif -} +GLOBAL_STATIC(MPDUser, instance) MPDUser::MPDUser() { diff --git a/network/networkaccessmanager.cpp b/network/networkaccessmanager.cpp index e35df2115..0750ea35f 100644 --- a/network/networkaccessmanager.cpp +++ b/network/networkaccessmanager.cpp @@ -25,12 +25,9 @@ #include "networkproxyfactory.h" #include "settings.h" #include "config.h" +#include "globalstatic.h" #include #include -#ifdef ENABLE_KDE_SUPPORT -#include -K_GLOBAL_STATIC(NetworkAccessManager, instance) -#endif #include static bool debugEnabled=false; @@ -147,18 +144,7 @@ void NetworkJob::handleReadyRead() emit readyRead(); } -NetworkAccessManager * NetworkAccessManager::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static NetworkAccessManager *instance=0; - if (!instance) { - instance=new NetworkAccessManager; - } - return instance; - #endif -} +GLOBAL_STATIC(NetworkAccessManager, instance) NetworkAccessManager::NetworkAccessManager(QObject *parent) : BASE_NETWORK_ACCESS_MANAGER(parent) diff --git a/replaygain/jobcontroller.cpp b/replaygain/jobcontroller.cpp index 93bb95b15..d5399cd49 100644 --- a/replaygain/jobcontroller.cpp +++ b/replaygain/jobcontroller.cpp @@ -23,10 +23,7 @@ #include "jobcontroller.h" #include "thread.h" -#ifdef ENABLE_KDE_SUPPORT -#include -K_GLOBAL_STATIC(JobController, instance) -#endif +#include "globalstatic.h" Job::Job() : abortRequested(false) @@ -66,18 +63,7 @@ void StandardJob::stop() deleteLater(); } -JobController * JobController::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static JobController *instance=0; - if(!instance) { - instance=new JobController; - } - return instance; - #endif -} +GLOBAL_STATIC(JobController, instance) JobController::JobController() : maxActive(1) diff --git a/support/globalstatic.h b/support/globalstatic.h new file mode 100644 index 000000000..21b89940f --- /dev/null +++ b/support/globalstatic.h @@ -0,0 +1,56 @@ +/* + * Cantata + * + * Copyright (c) 2011-2014 Craig Drummond + * + * ---- + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef GLOBAL_STATIC_H +#define GLOBAL_STATIC_H + +#include + +#ifdef ENABLE_KDE_SUPPORT + +#include +#define GLOBAL_STATIC(CLASS, VAR) \ + K_GLOBAL_STATIC(CLASS, VAR) \ + CLASS * CLASS::self() { return VAR; } + +#elif QT_VERSION >= 0x050100 || (QT_VERSION < 0x050000 && QT_VERSION >= 0x040800) + +#define GLOBAL_STATIC(CLASS, VAR) \ + Q_GLOBAL_STATIC(CLASS, VAR) \ + CLASS * CLASS::self() { return VAR(); } + +#else + +#define GLOBAL_STATIC(CLASS, VAR) \ + CLASS * CLASS::self() \ + { \ + static CLASS *VAR=0; \ + if (!VAR) { \ + VAR=new CLASS; \ + } \ + return VAR; \ + } + +#endif + +#endif diff --git a/support/thread.cpp b/support/thread.cpp index 0bedf423e..742f47d34 100644 --- a/support/thread.cpp +++ b/support/thread.cpp @@ -22,10 +22,7 @@ */ #include "thread.h" -#ifdef ENABLE_KDE_SUPPORT -#include -K_GLOBAL_STATIC(ThreadCleaner, instance) -#endif +#include "globalstatic.h" #include #include #include @@ -44,18 +41,7 @@ static void segvHandler(int i) _exit(i); } -ThreadCleaner * ThreadCleaner::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static ThreadCleaner *instance=0; - if(!instance) { - instance=new ThreadCleaner; - } - return instance; - #endif -} +GLOBAL_STATIC(ThreadCleaner, instance) void ThreadCleaner::stopAll() { diff --git a/widgets/icons.cpp b/widgets/icons.cpp index 18cf546ea..b86f44679 100644 --- a/widgets/icons.cpp +++ b/widgets/icons.cpp @@ -24,6 +24,7 @@ #include "icons.h" #include "config.h" #include "settings.h" +#include "globalstatic.h" #include #include #include @@ -36,22 +37,7 @@ #include "gtkstyle.h" #endif -#ifdef ENABLE_KDE_SUPPORT -K_GLOBAL_STATIC(Icons, instance) -#endif - -Icons * Icons::self() -{ - #ifdef ENABLE_KDE_SUPPORT - return instance; - #else - static Icons *instance=0; - if(!instance) { - instance=new Icons; - } - return instance; - #endif -} +GLOBAL_STATIC(Icons, instance) static QList constStdSizes=QList() << 16 << 22 << 32 << 48;