drumstick  2.9.0
C++ MIDI libraries using Qt objects, idioms, and style.
settingsfactory.cpp
Go to the documentation of this file.
1 /*
2  Drumstick Widgets
3  Copyright (C) 2018-2023 Pedro Lopez-Cabanillas <plcl@users.sf.net>
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include <QFileInfo>
21 
27 namespace drumstick { namespace widgets {
28 
33 QString SettingsFactory::s_fileName;
34 
40 void SettingsFactory::setFileName(const QString name)
41 {
42  SettingsFactory::s_fileName = name;
43  if (name.isEmpty()) {
44  QSettings::setDefaultFormat(QSettings::NativeFormat);
45  } else {
46  QSettings::setDefaultFormat(QSettings::IniFormat);
47  }
48 }
49 
55 {
56  return s_fileName;
57 }
58 
63 QSettings::Format SettingsFactory::format()
64 {
65  return QSettings::defaultFormat();
66 }
67 
72 QSettings*
74 {
75  if (m_settings.isNull()) {
76  if (s_fileName.isEmpty() || QSettings::defaultFormat() == QSettings::NativeFormat) {
77  m_settings.reset(new QSettings());
78  } else {
79  m_settings.reset(new QSettings(s_fileName, QSettings::IniFormat));
80  }
81  m_settings->setAtomicSyncRequired(true);
82  }
83  return m_settings.data();
84 }
85 
90 QSettings*
92 {
93  return getQSettings();
94 }
95 
96 } // namespace widgets
97 } // namespace drumstick
The QSettings class provides persistent platform-independent application settings.
static void setFileName(const QString name)
SettingsFactory::setFileName sets the global file name for the persistent settings and sets the INI f...
static QString fileName()
SettingsFactory::fileName returns the file name of the persistent settings.
QSettings * getQSettings()
SettingsFactory::getQSettings creates and/or returns a QSettings object pointer.
QSettings * operator->()
SettingsFactory::operator -> is equivalent to calling getQSettings()
static QSettings::Format format()
SettingsFactory::format returns the storage format of the persistent settings.
Drumstick common.
Definition: alsaclient.cpp:68
SettingsFactory class declaration.