diff options
author | Felix Geyer <debfx@fobos.de> | 2012-01-06 01:36:06 +0400 |
---|---|---|
committer | Felix Geyer <debfx@fobos.de> | 2012-01-06 01:36:06 +0400 |
commit | bda22394f5691320b2c70c72da05f7344241621f (patch) | |
tree | 2dac046f7bbfda6163047b0d991e86cc5a63b039 | |
parent | 5db102d668cf3001cbfecd69eb07cb4ef70156b8 (diff) |
Add a dataPath() generater function instead of using static DataPath methods.
-rw-r--r-- | src/core/DataPath.cpp | 27 | ||||
-rw-r--r-- | src/core/DataPath.h | 9 | ||||
-rw-r--r-- | src/core/DatabaseIcons.cpp | 2 | ||||
-rw-r--r-- | src/gui/MainWindow.cpp | 2 |
4 files changed, 22 insertions, 18 deletions
diff --git a/src/core/DataPath.cpp b/src/core/DataPath.cpp index 1005c0723..e902d4fb6 100644 --- a/src/core/DataPath.cpp +++ b/src/core/DataPath.cpp @@ -22,23 +22,13 @@ #include "config-keepassx.h" -DataPath* DataPath::m_instance(0); - QString DataPath::getPath(const QString& name) { - if (!m_instance) { - m_instance = new DataPath(); - } - - return m_instance->m_basePath + name; + return m_basePath + name; } QIcon DataPath::applicationIcon() { - if (!m_instance) { - m_instance = new DataPath(); - } - QIcon icon = QIcon::fromTheme("keepassx"); #if defined(QT_DEBUG) || defined(Q_WS_MAC) || defined(Q_WS_WIN) @@ -46,9 +36,9 @@ QIcon DataPath::applicationIcon() QStringList pngSizes; pngSizes << "16" << "24" << "32" << "48" << "64" << "128"; Q_FOREACH (const QString& size, pngSizes) { - icon.addFile(QString("%1/icons/application/%2x%2/apps/keepassx.png").arg(m_instance->m_basePath, size)); + icon.addFile(QString("%1/icons/application/%2x%2/apps/keepassx.png").arg(m_basePath, size)); } - icon.addFile(QString("%1/icons/application/scalable/apps/keepassx.svgz").arg(m_instance->m_basePath)); + icon.addFile(QString("%1/icons/application/scalable/apps/keepassx.svgz").arg(m_basePath)); } #endif @@ -94,3 +84,14 @@ bool DataPath::testSetDir(const QString& dir) return false; } } + +DataPath* dataPath() +{ + static DataPath* instance = 0; + + if (!instance) { + instance = new DataPath(); + } + + return instance; +} diff --git a/src/core/DataPath.h b/src/core/DataPath.h index 8c5639b83..98e45832e 100644 --- a/src/core/DataPath.h +++ b/src/core/DataPath.h @@ -24,15 +24,18 @@ class DataPath { public: - static QString getPath(const QString& name); - static QIcon applicationIcon(); + QString getPath(const QString& name); + QIcon applicationIcon(); private: DataPath(); bool testSetDir(const QString& dir); - static DataPath* m_instance; QString m_basePath; + + friend DataPath* dataPath(); }; +DataPath* dataPath(); + #endif // KEEPASSX_DATAPATH_H diff --git a/src/core/DatabaseIcons.cpp b/src/core/DatabaseIcons.cpp index e43c03921..3d5ddd3d2 100644 --- a/src/core/DatabaseIcons.cpp +++ b/src/core/DatabaseIcons.cpp @@ -31,7 +31,7 @@ QImage DatabaseIcons::icon(int index) } else { QString iconPath = QString("icons/database/").append(m_indexToName.at(index)); - QImage icon(DataPath::getPath(iconPath)); + QImage icon(dataPath()->getPath(iconPath)); m_iconCache[index] = icon; return icon; diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 51796e810..90e33c9ab 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -28,7 +28,7 @@ MainWindow::MainWindow() { m_ui->setupUi(this); - setWindowIcon(DataPath::applicationIcon()); + setWindowIcon(dataPath()->applicationIcon()); connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(currentTabChanged(int))); connect(m_ui->tabWidget, SIGNAL(entrySelectionChanged(bool)), m_ui->actionEntryEdit, SLOT(setEnabled(bool))); |