diff --git a/src/core/Config.cpp b/src/core/Config.cpp index b27b1d4f7..2334e1d4f 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -21,6 +21,8 @@ #include #include +Config* Config::m_instance(0); + QVariant Config::get(const QString& key) { return m_settings->value(key, m_defaults.value(key)); @@ -73,13 +75,11 @@ Config::Config() m_defaults.insert("security/clearclipboardtimeout", 10); } -Config* config() +Config* Config::instance() { - static Config* instance(0); - - if (!instance) { - instance = new Config(); + if (!m_instance) { + m_instance = new Config(); } - return instance; + return m_instance; } diff --git a/src/core/Config.h b/src/core/Config.h index 625a22a85..341e030a5 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -30,17 +30,21 @@ public: QVariant get(const QString& key, const QVariant& defaultValue); void set(const QString& key, const QVariant& value); + static Config* instance(); + private: Config(); + static Config* m_instance; + QScopedPointer m_settings; QHash m_defaults; Q_DISABLE_COPY(Config) - - friend Config* config(); }; -Config* config(); +inline Config* config() { + return Config::instance(); +} #endif // KEEPASSX_CONFIG_H diff --git a/src/core/DataPath.cpp b/src/core/DataPath.cpp index a5ed61e12..44709f6de 100644 --- a/src/core/DataPath.cpp +++ b/src/core/DataPath.cpp @@ -22,6 +22,8 @@ #include "config-keepassx.h" +DataPath* DataPath::m_instance(0); + QString DataPath::path(const QString& name) { return m_basePath + name; @@ -99,13 +101,11 @@ bool DataPath::testSetDir(const QString& dir) } } -DataPath* dataPath() +DataPath* DataPath::instance() { - static DataPath* instance = 0; - - if (!instance) { - instance = new DataPath(); + if (!m_instance) { + m_instance = new DataPath(); } - return instance; + return m_instance; } diff --git a/src/core/DataPath.h b/src/core/DataPath.h index 6a479b04c..71d3bad3f 100644 --- a/src/core/DataPath.h +++ b/src/core/DataPath.h @@ -28,17 +28,21 @@ public: QIcon applicationIcon(); QIcon icon(const QString& category, const QString& name, bool fromTheme = true); + static DataPath* instance(); + private: DataPath(); bool testSetDir(const QString& dir); + static DataPath* m_instance; + QString m_basePath; Q_DISABLE_COPY(DataPath) - - friend DataPath* dataPath(); }; -DataPath* dataPath(); +inline DataPath* dataPath() { + return DataPath::instance(); +} #endif // KEEPASSX_DATAPATH_H diff --git a/src/core/DatabaseIcons.cpp b/src/core/DatabaseIcons.cpp index e89f31310..b584f4433 100644 --- a/src/core/DatabaseIcons.cpp +++ b/src/core/DatabaseIcons.cpp @@ -19,6 +19,8 @@ #include "core/DataPath.h" +DatabaseIcons* DatabaseIcons::m_instance(0); + QImage DatabaseIcons::icon(int index) { if (index < 0 || index >= iconCount()) { @@ -146,13 +148,11 @@ DatabaseIcons::DatabaseIcons() m_pixmapCacheKeys.resize(iconCount()); } -DatabaseIcons* databaseIcons() +DatabaseIcons* DatabaseIcons::instance() { - static DatabaseIcons* instance(0); - - if (!instance) { - instance = new DatabaseIcons(); + if (!m_instance) { + m_instance = new DatabaseIcons(); } - return instance; + return m_instance; } diff --git a/src/core/DatabaseIcons.h b/src/core/DatabaseIcons.h index 7e6c2979e..24c81ba95 100644 --- a/src/core/DatabaseIcons.h +++ b/src/core/DatabaseIcons.h @@ -31,18 +31,22 @@ public: int iconCount(); int expiredIconIndex(); + static DatabaseIcons* instance(); + private: DatabaseIcons(); + static DatabaseIcons* m_instance; + QVector m_indexToName; QVector m_iconCache; QVector m_pixmapCacheKeys; Q_DISABLE_COPY(DatabaseIcons) - - friend DatabaseIcons* databaseIcons(); }; -DatabaseIcons* databaseIcons(); +inline DatabaseIcons* databaseIcons() { + return DatabaseIcons::instance(); +} #endif // KEEPASSX_DATABASEICONS_H diff --git a/src/gui/Clipboard.cpp b/src/gui/Clipboard.cpp index 3d0292c0e..90eeb2d85 100644 --- a/src/gui/Clipboard.cpp +++ b/src/gui/Clipboard.cpp @@ -28,6 +28,8 @@ #include "core/Config.h" +Clipboard* Clipboard::m_instance(0); + Clipboard::Clipboard(QObject* parent) : QObject(parent) , m_timer(new QTimer(this)) @@ -75,13 +77,11 @@ void Clipboard::clearClipboard() #endif } -Clipboard* clipboard() +Clipboard* Clipboard::instance() { - static Clipboard* instance(0); - - if (!instance) { - instance = new Clipboard(qApp); + if (!m_instance) { + m_instance = new Clipboard(qApp); } - return instance; + return m_instance; } diff --git a/src/gui/Clipboard.h b/src/gui/Clipboard.h index 75bcb1c8a..f8780c7a0 100644 --- a/src/gui/Clipboard.h +++ b/src/gui/Clipboard.h @@ -30,17 +30,21 @@ public: ~Clipboard(); void setText(const QString& text); + static Clipboard* instance(); + private Q_SLOTS: void clearClipboard(); private: explicit Clipboard(QObject* parent = 0); - QTimer* m_timer; + static Clipboard* m_instance; - friend Clipboard* clipboard(); + QTimer* m_timer; }; -Clipboard* clipboard(); +inline Clipboard* clipboard() { + return Clipboard::instance(); +} #endif // KEEPASSX_CLIPBOARD_H diff --git a/src/gui/FileDialog.cpp b/src/gui/FileDialog.cpp index 75d73ef91..620a4ef4c 100644 --- a/src/gui/FileDialog.cpp +++ b/src/gui/FileDialog.cpp @@ -19,6 +19,8 @@ #include "core/Config.h" +FileDialog* FileDialog::m_instance(0); + QString FileDialog::getOpenFileName(QWidget* parent, const QString& caption, QString dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options) @@ -78,13 +80,11 @@ FileDialog::FileDialog() { } -FileDialog* fileDialog() +FileDialog* FileDialog::instance() { - static FileDialog* instance(0); - - if (!instance) { - instance = new FileDialog(); + if (!m_instance) { + m_instance = new FileDialog(); } - return instance; + return m_instance; } diff --git a/src/gui/FileDialog.h b/src/gui/FileDialog.h index 6dac4e4b7..0b6fdae40 100644 --- a/src/gui/FileDialog.h +++ b/src/gui/FileDialog.h @@ -36,15 +36,19 @@ public: */ void setNextFileName(const QString& fileName); + static FileDialog* instance(); + private: FileDialog(); QString m_nextFileName; - Q_DISABLE_COPY(FileDialog) + static FileDialog* m_instance; - friend FileDialog* fileDialog(); + Q_DISABLE_COPY(FileDialog) }; -FileDialog* fileDialog(); +inline FileDialog* fileDialog() { + return FileDialog::instance(); +} #endif // KEEPASSX_FILEDIALOG_H