mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-10 06:44:29 +00:00
added FileWidget; fixed OpenCS configuration
This commit is contained in:
parent
ecedb60169
commit
25b7cd33ea
@ -43,7 +43,7 @@ opencs_units_noqt (model/tools
|
|||||||
|
|
||||||
|
|
||||||
opencs_units (view/doc
|
opencs_units (view/doc
|
||||||
viewmanager view operations operation subview startup filedialog newgame
|
viewmanager view operations operation subview startup filedialog newgame filewidget
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QLocalServer>
|
#include <QLocalServer>
|
||||||
#include <QLocalSocket>
|
#include <QLocalSocket>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "model/doc/document.hpp"
|
#include "model/doc/document.hpp"
|
||||||
#include "model/world/data.hpp"
|
#include "model/world/data.hpp"
|
||||||
@ -25,6 +26,9 @@ CS::Editor::Editor() : mViewManager (mDocumentManager)
|
|||||||
connect (&mFileDialog, SIGNAL(openFiles()), this, SLOT(openFiles()));
|
connect (&mFileDialog, SIGNAL(openFiles()), this, SLOT(openFiles()));
|
||||||
connect (&mFileDialog, SIGNAL(createNewFile()), this, SLOT(createNewFile()));
|
connect (&mFileDialog, SIGNAL(createNewFile()), this, SLOT(createNewFile()));
|
||||||
|
|
||||||
|
connect (&mNewGame, SIGNAL (createRequest (const QString&)),
|
||||||
|
this, SLOT (createNewGame (const QString&)));
|
||||||
|
|
||||||
setupDataFiles();
|
setupDataFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,26 +47,39 @@ void CS::Editor::setupDataFiles()
|
|||||||
|
|
||||||
mCfgMgr.readConfiguration(variables, desc);
|
mCfgMgr.readConfiguration(variables, desc);
|
||||||
|
|
||||||
Files::PathContainer mDataDirs, mDataLocal;
|
Files::PathContainer dataDirs, dataLocal;
|
||||||
if (!variables["data"].empty()) {
|
if (!variables["data"].empty()) {
|
||||||
mDataDirs = Files::PathContainer(variables["data"].as<Files::PathContainer>());
|
dataDirs = Files::PathContainer(variables["data"].as<Files::PathContainer>());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string local = variables["data-local"].as<std::string>();
|
std::string local = variables["data-local"].as<std::string>();
|
||||||
if (!local.empty()) {
|
if (!local.empty()) {
|
||||||
mDataLocal.push_back(Files::PathContainer::value_type(local));
|
dataLocal.push_back(Files::PathContainer::value_type(local));
|
||||||
}
|
}
|
||||||
|
|
||||||
mCfgMgr.processPaths(mDataDirs);
|
mCfgMgr.processPaths (dataDirs);
|
||||||
mCfgMgr.processPaths(mDataLocal);
|
mCfgMgr.processPaths (dataLocal, true);
|
||||||
|
|
||||||
|
if (!dataLocal.empty())
|
||||||
|
mLocal = dataLocal[0];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMessageBox messageBox;
|
||||||
|
messageBox.setWindowTitle (tr ("No local data path available"));
|
||||||
|
messageBox.setIcon (QMessageBox::Critical);
|
||||||
|
messageBox.setStandardButtons (QMessageBox::Ok);
|
||||||
|
messageBox.setText(tr("<br><b>OpenCS is unable to access the local data directory. This may indicate a faulty configuration or a broken install.</b>"));
|
||||||
|
messageBox.exec();
|
||||||
|
|
||||||
|
QApplication::exit (1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Set the charset for reading the esm/esp files
|
// Set the charset for reading the esm/esp files
|
||||||
QString encoding = QString::fromStdString(variables["encoding"].as<std::string>());
|
QString encoding = QString::fromStdString(variables["encoding"].as<std::string>());
|
||||||
mFileDialog.setEncoding(encoding);
|
mFileDialog.setEncoding(encoding);
|
||||||
|
|
||||||
Files::PathContainer dataDirs;
|
dataDirs.insert (dataDirs.end(), dataLocal.begin(), dataLocal.end());
|
||||||
dataDirs.insert(dataDirs.end(), mDataDirs.begin(), mDataDirs.end());
|
|
||||||
dataDirs.insert(dataDirs.end(), mDataLocal.begin(), mDataLocal.end());
|
|
||||||
|
|
||||||
for (Files::PathContainer::const_iterator iter = dataDirs.begin(); iter != dataDirs.end(); ++iter)
|
for (Files::PathContainer::const_iterator iter = dataDirs.begin(); iter != dataDirs.end(); ++iter)
|
||||||
{
|
{
|
||||||
@ -73,7 +90,6 @@ void CS::Editor::setupDataFiles()
|
|||||||
//load the settings into the userSettings instance.
|
//load the settings into the userSettings instance.
|
||||||
const QString settingFileName = "opencs.cfg";
|
const QString settingFileName = "opencs.cfg";
|
||||||
CSMSettings::UserSettings::instance().loadSettings(settingFileName);
|
CSMSettings::UserSettings::instance().loadSettings(settingFileName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CS::Editor::createGame()
|
void CS::Editor::createGame()
|
||||||
@ -133,6 +149,23 @@ void CS::Editor::createNewFile()
|
|||||||
mFileDialog.hide();
|
mFileDialog.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CS::Editor::createNewGame (const QString& file)
|
||||||
|
{
|
||||||
|
boost::filesystem::path path (mLocal);
|
||||||
|
|
||||||
|
path /= file.toUtf8().data();
|
||||||
|
|
||||||
|
std::vector<boost::filesystem::path> files;
|
||||||
|
|
||||||
|
files.push_back (path);
|
||||||
|
|
||||||
|
CSMDoc::Document *document = mDocumentManager.addDocument (files, true);
|
||||||
|
|
||||||
|
mViewManager.addView (document);
|
||||||
|
|
||||||
|
mNewGame.hide();
|
||||||
|
}
|
||||||
|
|
||||||
void CS::Editor::showStartup()
|
void CS::Editor::showStartup()
|
||||||
{
|
{
|
||||||
if(mStartup.isHidden())
|
if(mStartup.isHidden())
|
||||||
@ -173,6 +206,9 @@ void CS::Editor::connectToIPCServer()
|
|||||||
|
|
||||||
int CS::Editor::run()
|
int CS::Editor::run()
|
||||||
{
|
{
|
||||||
|
if (mLocal.empty())
|
||||||
|
return 1;
|
||||||
|
|
||||||
mStartup.show();
|
mStartup.show();
|
||||||
|
|
||||||
QApplication::setQuitOnLastWindowClosed (true);
|
QApplication::setQuitOnLastWindowClosed (true);
|
||||||
|
@ -35,6 +35,8 @@ namespace CS
|
|||||||
FileDialog mFileDialog;
|
FileDialog mFileDialog;
|
||||||
|
|
||||||
Files::ConfigurationManager mCfgMgr;
|
Files::ConfigurationManager mCfgMgr;
|
||||||
|
boost::filesystem::path mLocal;
|
||||||
|
|
||||||
void setupDataFiles();
|
void setupDataFiles();
|
||||||
|
|
||||||
// not implemented
|
// not implemented
|
||||||
@ -59,6 +61,7 @@ namespace CS
|
|||||||
void loadDocument();
|
void loadDocument();
|
||||||
void openFiles();
|
void openFiles();
|
||||||
void createNewFile();
|
void createNewFile();
|
||||||
|
void createNewGame (const QString& file);
|
||||||
|
|
||||||
void showStartup();
|
void showStartup();
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if(!editor.makeIPCServer())
|
if(!editor.makeIPCServer())
|
||||||
{
|
{
|
||||||
editor.connectToIPCServer();
|
editor.connectToIPCServer();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return editor.run();
|
return editor.run();
|
||||||
|
54
apps/opencs/view/doc/filewidget.cpp
Normal file
54
apps/opencs/view/doc/filewidget.cpp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
|
||||||
|
#include "filewidget.hpp"
|
||||||
|
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QRegExpValidator>
|
||||||
|
#include <QRegExp>
|
||||||
|
|
||||||
|
QString CSVDoc::FileWidget::getExtension() const
|
||||||
|
{
|
||||||
|
return mAddon ? ".omwaddon" : ".omwgame";
|
||||||
|
}
|
||||||
|
|
||||||
|
CSVDoc::FileWidget::FileWidget (QWidget *parent) : QWidget (parent), mAddon (false)
|
||||||
|
{
|
||||||
|
QHBoxLayout *layout = new QHBoxLayout (this);
|
||||||
|
|
||||||
|
mInput = new QLineEdit (this);
|
||||||
|
mInput->setValidator (new QRegExpValidator(QRegExp("^[a-zA-Z0-9\\s]*$")));
|
||||||
|
|
||||||
|
layout->addWidget (mInput, 1);
|
||||||
|
|
||||||
|
mType = new QLabel (this);
|
||||||
|
|
||||||
|
layout ->addWidget (mType);
|
||||||
|
|
||||||
|
connect (mInput, SIGNAL (textChanged (const QString&)), this, SLOT (textChanged (const QString&)));
|
||||||
|
|
||||||
|
setLayout (layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVDoc::FileWidget::setType (bool addon)
|
||||||
|
{
|
||||||
|
mAddon = addon;
|
||||||
|
|
||||||
|
mType->setText (getExtension());
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CSVDoc::FileWidget::getName() const
|
||||||
|
{
|
||||||
|
QString text = mInput->text();
|
||||||
|
|
||||||
|
if (text.isEmpty())
|
||||||
|
return "";
|
||||||
|
|
||||||
|
return text + getExtension();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVDoc::FileWidget::textChanged (const QString& text)
|
||||||
|
{
|
||||||
|
emit stateChanged (!text.isEmpty());
|
||||||
|
emit nameChanged (getName());
|
||||||
|
}
|
42
apps/opencs/view/doc/filewidget.hpp
Normal file
42
apps/opencs/view/doc/filewidget.hpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#ifndef CSV_DOC_FILEWIDGET_H
|
||||||
|
#define CSV_DOC_FILEWIDGET_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class QLabel;
|
||||||
|
class QString;
|
||||||
|
class QLineEdit;
|
||||||
|
|
||||||
|
namespace CSVDoc
|
||||||
|
{
|
||||||
|
class FileWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
bool mAddon;
|
||||||
|
QLineEdit *mInput;
|
||||||
|
QLabel *mType;
|
||||||
|
|
||||||
|
QString getExtension() const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
FileWidget (QWidget *parent = 0);
|
||||||
|
|
||||||
|
void setType (bool addon);
|
||||||
|
|
||||||
|
QString getName() const;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void textChanged (const QString& text);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
void stateChanged (bool valid);
|
||||||
|
|
||||||
|
void nameChanged (const QString& file);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -3,12 +3,54 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
#include "filewidget.hpp"
|
||||||
|
|
||||||
CSVDoc::NewGameDialogue::NewGameDialogue()
|
CSVDoc::NewGameDialogue::NewGameDialogue()
|
||||||
{
|
{
|
||||||
setWindowTitle ("Create New Game");
|
setWindowTitle ("Create New Game");
|
||||||
|
|
||||||
|
QVBoxLayout *layout = new QVBoxLayout (this);
|
||||||
|
|
||||||
|
mFileWidget = new FileWidget (this);
|
||||||
|
mFileWidget->setType (false);
|
||||||
|
|
||||||
|
layout->addWidget (mFileWidget, 1);
|
||||||
|
|
||||||
|
QDialogButtonBox *buttons = new QDialogButtonBox (this);
|
||||||
|
|
||||||
|
mCreate = new QPushButton ("Create", this);
|
||||||
|
mCreate->setDefault (true);
|
||||||
|
mCreate->setEnabled (false);
|
||||||
|
|
||||||
|
buttons->addButton (mCreate, QDialogButtonBox::AcceptRole);
|
||||||
|
|
||||||
|
QPushButton *cancel = new QPushButton ("Cancel", this);
|
||||||
|
|
||||||
|
buttons->addButton (cancel, QDialogButtonBox::RejectRole);
|
||||||
|
|
||||||
|
layout->addWidget (buttons);
|
||||||
|
|
||||||
|
setLayout (layout);
|
||||||
|
|
||||||
|
connect (mFileWidget, SIGNAL (stateChanged (bool)), this, SLOT (stateChanged (bool)));
|
||||||
|
connect (mCreate, SIGNAL (clicked()), this, SLOT (create()));
|
||||||
|
connect (cancel, SIGNAL (clicked()), this, SLOT (reject()));
|
||||||
|
|
||||||
QRect scr = QApplication::desktop()->screenGeometry();
|
QRect scr = QApplication::desktop()->screenGeometry();
|
||||||
QRect rect = geometry();
|
QRect rect = geometry();
|
||||||
move (scr.center().x() - rect.center().x(), scr.center().y() - rect.center().y());
|
move (scr.center().x() - rect.center().x(), scr.center().y() - rect.center().y());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVDoc::NewGameDialogue::stateChanged (bool valid)
|
||||||
|
{
|
||||||
|
mCreate->setEnabled (valid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVDoc::NewGameDialogue::create()
|
||||||
|
{
|
||||||
|
emit createRequest (mFileWidget->getName());
|
||||||
|
}
|
||||||
|
@ -1,17 +1,34 @@
|
|||||||
#ifndef CSV_DOC_NEWGAME_H
|
#ifndef CSV_DOC_NEWGAME_H
|
||||||
#define CSV_DOC_NEWGAME_H
|
#define CSV_DOC_NEWGAME_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QDialog>
|
||||||
|
|
||||||
|
class QPushButton;
|
||||||
|
|
||||||
namespace CSVDoc
|
namespace CSVDoc
|
||||||
{
|
{
|
||||||
class NewGameDialogue : public QWidget
|
class FileWidget;
|
||||||
|
|
||||||
|
class NewGameDialogue : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
QPushButton *mCreate;
|
||||||
|
FileWidget *mFileWidget;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
NewGameDialogue();
|
NewGameDialogue();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
void createRequest (const QString& file);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void stateChanged (bool valid);
|
||||||
|
|
||||||
|
void create();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ void ConfigurationManager::readConfiguration(boost::program_options::variables_m
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigurationManager::processPaths(Files::PathContainer& dataDirs)
|
void ConfigurationManager::processPaths(Files::PathContainer& dataDirs, bool create)
|
||||||
{
|
{
|
||||||
std::string path;
|
std::string path;
|
||||||
for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it)
|
for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it)
|
||||||
@ -94,6 +94,18 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs)
|
|||||||
|
|
||||||
if (!boost::filesystem::is_directory(*it))
|
if (!boost::filesystem::is_directory(*it))
|
||||||
{
|
{
|
||||||
|
if (create)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::filesystem::create_directories (*it);
|
||||||
|
}
|
||||||
|
catch (...) {}
|
||||||
|
|
||||||
|
if (boost::filesystem::is_directory(*it))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
(*it).clear();
|
(*it).clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,9 @@ struct ConfigurationManager
|
|||||||
|
|
||||||
void readConfiguration(boost::program_options::variables_map& variables,
|
void readConfiguration(boost::program_options::variables_map& variables,
|
||||||
boost::program_options::options_description& description);
|
boost::program_options::options_description& description);
|
||||||
void processPaths(Files::PathContainer& dataDirs);
|
|
||||||
|
void processPaths(Files::PathContainer& dataDirs, bool create = false);
|
||||||
|
///< \param create Try creating the directory, if it does not exist.
|
||||||
|
|
||||||
/**< Fixed paths */
|
/**< Fixed paths */
|
||||||
const boost::filesystem::path& getGlobalPath() const;
|
const boost::filesystem::path& getGlobalPath() const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user