basic framework for new user settings system

openmw-38
Marc Zinnschlag 9 years ago
parent 49b37ce8bf
commit 36ce8f97d7

@ -123,6 +123,10 @@ opencs_units_noqt (view/settings
frame
)
opencs_units (view/prefs
dialogue
)
opencs_units (model/settings
usersettings
setting
@ -133,6 +137,10 @@ opencs_hdrs_noqt (model/settings
support
)
opencs_units (model/prefs
state
)
opencs_units_noqt (model/filter
node unarynode narynode leafnode booleannode parser andnode ornode notnode textnode valuenode
)

@ -18,7 +18,7 @@
#endif
CS::Editor::Editor ()
: mUserSettings (mCfgMgr), mDocumentManager (mCfgMgr),
: mSettingsState (mCfgMgr), mUserSettings (mCfgMgr), mDocumentManager (mCfgMgr),
mViewManager (mDocumentManager), mPid(""),
mLock(), mMerge (mDocumentManager),
mIpcServerName ("org.openmw.OpenCS"), mServer(NULL), mClientSocket(NULL)
@ -28,7 +28,7 @@ CS::Editor::Editor ()
setupDataFiles (config.first);
CSMSettings::UserSettings::instance().loadSettings ("opencs.ini");
mSettings.setModel (CSMSettings::UserSettings::instance());
// mSettings.setModel (CSMSettings::UserSettings::instance());
NifOsg::Loader::setShowMarkers(true);

@ -20,6 +20,8 @@
#include "model/settings/usersettings.hpp"
#include "model/doc/documentmanager.hpp"
#include "model/prefs/state.hpp"
#include "view/doc/viewmanager.hpp"
#include "view/doc/startup.hpp"
#include "view/doc/filedialog.hpp"
@ -27,6 +29,8 @@
#include "view/settings/dialog.hpp"
#include "view/prefs/dialogue.hpp"
#include "view/tools/merge.hpp"
namespace VFS
@ -49,12 +53,13 @@ namespace CS
std::auto_ptr<VFS::Manager> mVFS;
Files::ConfigurationManager mCfgMgr;
CSMPrefs::State mSettingsState;
CSMSettings::UserSettings mUserSettings;
CSMDoc::DocumentManager mDocumentManager;
CSVDoc::ViewManager mViewManager;
CSVDoc::StartupDialogue mStartup;
CSVDoc::NewGameDialogue mNewGame;
CSVSettings::Dialog mSettings;
CSVPrefs::Dialogue mSettings;
CSVDoc::FileDialog mFileDialog;
boost::filesystem::path mLocal;
boost::filesystem::path mResources;

@ -0,0 +1,68 @@
#include "state.hpp"
#include <stdexcept>
CSMPrefs::State *CSMPrefs::State::sThis = 0;
void CSMPrefs::State::load()
{
// default settings file
boost::filesystem::path local = mConfigurationManager.getLocalPath() / mConfigFile;
boost::filesystem::path global = mConfigurationManager.getGlobalPath() / mConfigFile;
if (boost::filesystem::exists (local))
mSettings.loadDefault (local.string());
else if (boost::filesystem::exists (global))
mSettings.loadDefault (global.string());
else
throw std::runtime_error ("No default settings file found! Make sure the file \"opencs.ini\" was properly installed.");
// user settings file
boost::filesystem::path user = mConfigurationManager.getUserConfigPath() / mConfigFile;
if (boost::filesystem::exists (user))
mSettings.loadUser (user.string());
}
void CSMPrefs::State::declare()
{
}
CSMPrefs::State::State (const Files::ConfigurationManager& configurationManager)
: mConfigFile ("opencs.ini"), mConfigurationManager (configurationManager)
{
if (sThis)
throw std::logic_error ("An instance of CSMPRefs::State already exists");
load();
declare();
sThis = this;
}
CSMPrefs::State::~State()
{
sThis = 0;
}
void CSMPrefs::State::save()
{
boost::filesystem::path user = mConfigurationManager.getUserConfigPath() / mConfigFile;
mSettings.saveUser (user.string());
}
CSMPrefs::State& CSMPrefs::State::get()
{
if (!sThis)
throw std::logic_error ("No instance of CSMPrefs::State");
return *sThis;
}
CSMPrefs::State& CSMPrefs::get()
{
return State::get();
}

@ -0,0 +1,49 @@
#ifndef CSV_PREFS_STATE_H
#define CSM_PREFS_STATE_H
#include <QObject>
#ifndef Q_MOC_RUN
#include <components/files/configurationmanager.hpp>
#endif
#include <components/settings/settings.hpp>
namespace CSMPrefs
{
class State : public QObject
{
Q_OBJECT
static State *sThis;
const std::string mConfigFile;
const Files::ConfigurationManager& mConfigurationManager;
Settings::Manager mSettings;
// not implemented
State (const State&);
State& operator= (const State&);
private:
void load();
void declare();
public:
State (const Files::ConfigurationManager& configurationManager);
~State();
void save();
static State& get();
};
// convenience function
State& get();
}
#endif

@ -0,0 +1,72 @@
#include "dialogue.hpp"
#include <QApplication>
#include <QDesktopWidget>
#include <QSplitter>
#include <QListWidget>
#include <QStackedWidget>
#include "../../model/prefs/state.hpp"
void CSVPrefs::Dialogue::buildCategorySelector (QSplitter *main)
{
mList = new QListWidget (main);
mList->setMinimumWidth (50);
mList->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
mList->setSelectionBehavior (QAbstractItemView::SelectItems);
main->addWidget (mList);
/// \todo connect to selection signal
}
void CSVPrefs::Dialogue::buildContentArea (QSplitter *main)
{
mContent = new QStackedWidget (main);
mContent->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Expanding);
main->addWidget (mContent);
}
CSVPrefs::Dialogue::Dialogue()
{
setWindowTitle ("User Settings");
setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
setMinimumSize (600, 400);
QSplitter *main = new QSplitter (this);
setCentralWidget (main);
buildCategorySelector (main);
buildContentArea (main);
}
void CSVPrefs::Dialogue::closeEvent (QCloseEvent *event)
{
QMainWindow::closeEvent (event);
CSMPrefs::State::get().save();
}
void CSVPrefs::Dialogue::show()
{
if (QWidget *active = QApplication::activeWindow())
{
// place at the centre of the window with focus
QSize size = active->size();
move (active->geometry().x()+(size.width() - frameGeometry().width())/2,
active->geometry().y()+(size.height() - frameGeometry().height())/2);
}
else
{
// otherwise place at the centre of the screen
QPoint screenCenter = QApplication::desktop()->screenGeometry().center();
move (screenCenter - QPoint(frameGeometry().width()/2, frameGeometry().height()/2));
}
QWidget::show();
}

@ -0,0 +1,39 @@
#ifndef CSV_PREFS_DIALOGUE_H
#define CSV_PREFS_DIALOGUE_H
#include <QMainWindow>
class QSplitter;
class QListWidget;
class QStackedWidget;
namespace CSVPrefs
{
class Dialogue : public QMainWindow
{
Q_OBJECT
QListWidget *mList;
QStackedWidget *mContent;
private:
void buildCategorySelector (QSplitter *main);
void buildContentArea (QSplitter *main);
public:
Dialogue();
protected:
void closeEvent (QCloseEvent *event);
public slots:
void show();
};
}
#endif
Loading…
Cancel
Save