Browse Source

* Переименованы приватные и защищенные поля классов. Теперь они

начинаются с символа `_`;
* Добавлен класс реализующий систему геттеров и сеттеров
master
Тим 11 months ago
parent
commit
5ed17bf428
11 changed files with 243 additions and 30 deletions
  1. 5
    5
      Environments.cpp
  2. 1
    1
      Environments.h
  3. 180
    0
      GetterSetter.hpp
  4. 2
    2
      WBMain.cpp
  5. 1
    1
      WBMain.h
  6. 7
    7
      WBTmp.cpp
  7. 1
    1
      WBTmp.h
  8. 2
    1
      WineBottle.pro
  9. 18
    1
      wine/Execute.cpp
  10. 25
    10
      wine/Execute.h
  11. 1
    1
      wine/RegEdit.h

+ 5
- 5
Environments.cpp View File

@@ -12,7 +12,7 @@ stEnvironment::stEnvironment(const QString &unparsed)
Environments::Environments(QObject *parent) : QObject(parent)
{
for (auto &unparsed : QProcess::systemEnvironment())
envs.push_back(stEnvironment(unparsed));
_envs.push_back(stEnvironment(unparsed));
}

void Environments::addEnvironment(const QString &key, const QString &value)
@@ -22,12 +22,12 @@ void Environments::addEnvironment(const QString &key, const QString &value)

void Environments::addEnvironment(const stEnvironment &env)
{
envs.push_back(env);
_envs.push_back(env);
}

void Environments::modEnvironment(const QString &key, const QString &value)
{
for (auto &env : envs)
for (auto &env : _envs)
if (env.key == key)
env.value = value;
}
@@ -39,7 +39,7 @@ void Environments::modEnvironment(const stEnvironment &env)

QString &Environments::environmentValue(const QString &key)
{
for (auto &env : envs)
for (auto &env : _envs)
if (env.key == key)
return env.value;
throw "key " + key + " not defined";
@@ -53,7 +53,7 @@ QString &Environments::operator[](const QString &key)
QStringList Environments::environments()
{
QStringList ret;
for (auto &env : envs)
for (auto &env : _envs)
ret.push_back(env.key + "=" + env.value);
return ret;
}

+ 1
- 1
Environments.h View File

@@ -29,7 +29,7 @@ public:
virtual QStringList environments();

protected:
QList<stEnvironment> envs;
QList<stEnvironment> _envs;
};

#endif // ENVIRONMENTS_H

+ 180
- 0
GetterSetter.hpp View File

@@ -0,0 +1,180 @@
#ifndef GETTERSETTER_H
#define GETTERSETTER_H

#include <functional>

template<typename T>
class GetterSetter
{
public:
explicit GetterSetter(std::function<T(const T&)> getter, std::function<T(const T&)> setter, T value = T())
: getter(getter), setter(setter) {
operator=(value);
}
explicit GetterSetter(T value = T()){
std::function<T(const T&)> dummy = [](const T& value) -> T{
return value;
};
getter = dummy;
setter = dummy;
operator=(value);
}
virtual ~GetterSetter(){}

operator T(){
return getter(_value);
}

void operator =(const T &value){
_value = setter(value);
}

bool operator ==(const T &value){
return getter(_value) == value;
}

void operator +=(const T &value){
_value = setter(getter(_value) + value);
}

void operator -=(const T &value){
_value = setter(getter(_value) - value);
}

void operator *=(const T &value){
_value = setter(getter(_value) * value);
}

void operator /=(const T &value){
_value = setter(getter(_value) / value);
}

void operator &=(const T &value){
_value = setter(getter(_value) & value);
}

void operator |=(const T &value){
_value = setter(getter(_value) | value);
}

void operator ^=(const T &value){
_value = setter(getter(_value) ^ value);
}

T operator ~(){
return ~getter(_value);
}

private:
T _value;

std::function<T(const T&)> getter;
std::function<T(const T&)> setter;
};

template<typename T, typename V>
T operator+(GetterSetter<T> lhs, const V &rhs)
{
lhs += rhs;
T result = lhs;
return result;
}

template<typename T, typename V>
T operator+(const V &lhs, GetterSetter<T> &rhs)
{
T value = rhs;
return operator+(lhs, value);
}

template<typename T, typename V>
T operator-(GetterSetter<T> lhs, const V &rhs)
{
lhs -= rhs;
T result = lhs;
return result;
}

template<typename T, typename V>
T operator-(const V &lhs, GetterSetter<T> &rhs)
{
T value = rhs;
return operator-(lhs, value);
}

template<typename T, typename V>
T operator*(GetterSetter<T> lhs, const V &rhs)
{
lhs *= rhs;
T result = lhs;
return result;
}

template<typename T, typename V>
T operator*(const V &lhs, GetterSetter<T> &rhs)
{
T value = rhs;
return operator*(lhs, value);
}

template<typename T, typename V>
T operator/(GetterSetter<T> lhs, const V &rhs)
{
lhs /= rhs;
T result = lhs;
return result;
}

template<typename T, typename V>
T operator/(const V &lhs, GetterSetter<T> &rhs)
{
T value = rhs;
return operator/(lhs, value);
}

template<typename T, typename V>
T operator&(GetterSetter<T> lhs, const V &rhs)
{
lhs &= rhs;
T result = lhs;
return result;
}

template<typename T, typename V>
T operator&(const V &lhs, GetterSetter<T> &rhs)
{
T value = rhs;
return operator&(lhs, value);
}

template<typename T, typename V>
T operator|(GetterSetter<T> lhs, const V &rhs)
{
lhs |= rhs;
T result = lhs;
return result;
}

template<typename T, typename V>
T operator|(const V &lhs, GetterSetter<T> &rhs)
{
T value = rhs;
return operator|(lhs, value);
}

template<typename T, typename V>
T operator^(GetterSetter<T> lhs, const V &rhs)
{
lhs ^= rhs;
T result = lhs;
return result;
}

template<typename T, typename V>
T operator^(const V &lhs, GetterSetter<T> &rhs)
{
T value = rhs;
return operator^(lhs, value);
}

#endif // GETTERSETTER_H

+ 2
- 2
WBMain.cpp View File

@@ -4,12 +4,12 @@ WBMain::WBMain(QStringList args)
: WBFace(nullptr)
{
if (args.count()){
exe = args.front();
_exe = args.front();
args.pop_front();
if (args.count())
if (le_args)
le_args->setText(args.join(" "));
setWindowTitle(exe.completeBaseName());
setWindowTitle(_exe.completeBaseName());
}
}


+ 1
- 1
WBMain.h View File

@@ -13,7 +13,7 @@ public:
~WBMain();

private:
QFileInfo exe;
QFileInfo _exe;
};

#endif // WBMAIN_H

+ 7
- 7
WBTmp.cpp View File

@@ -5,15 +5,15 @@ WBTmp *WBTmp::_this = nullptr;

WBTmp::WBTmp()
{
tmpDir = "/tmp/WineBottle/" + QString::number(QApplication::applicationPid()) + "/";
if (!tmpDir.exists())
tmpDir.mkpath(tmpDir.path());
_tmpDir = "/tmp/WineBottle/" + QString::number(QApplication::applicationPid()) + "/";
if (!_tmpDir.exists())
_tmpDir.mkpath(_tmpDir.path());
}

WBTmp::~WBTmp()
{
if (!tmpDir.exists())
tmpDir.rmdir(tmpDir.path());
if (!_tmpDir.exists())
_tmpDir.rmdir(_tmpDir.path());
}

WBTmp *WBTmp::Instance()
@@ -31,10 +31,10 @@ void WBTmp::DeleteInstance()

QString WBTmp::tmpPath()
{
return tmpDir.path();
return _tmpDir.path();
}

const QDir &WBTmp::tmp()
{
return const_cast<const QDir&>(tmpDir);
return const_cast<const QDir&>(_tmpDir);
}

+ 1
- 1
WBTmp.h View File

@@ -8,7 +8,7 @@ class WBTmp
explicit WBTmp();
virtual ~WBTmp();

QDir tmpDir;
QDir _tmpDir;
static WBTmp *_this;

public:

+ 2
- 1
WineBottle.pro View File

@@ -42,7 +42,8 @@ HEADERS += \
ui/WBFace.h \
PEHeaders.h \
wine/Execute.h \
Environments.h
Environments.h \
GetterSetter.hpp

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin

+ 18
- 1
wine/Execute.cpp View File

@@ -1,7 +1,24 @@
#include "Execute.h"

Execute::Execute(QObject *parent, QString path, QString prefix)
: Environments(parent), winePath(path), winePrefix(prefix)
: Environments(parent), _path(path), _prefix(prefix)
{
_wine = new QProcess();
}

Execute::~Execute()
{
if (_wine->state() != QProcess::ProcessState::NotRunning)
_wine->kill();
delete _wine;
}

void Execute::run()
{
// TODO: execute _wine
}

void Execute::finished(int exitCode, QProcess::ExitStatus exitStatus)
{
emit done(exitStatus);
}

+ 25
- 10
wine/Execute.h View File

@@ -4,6 +4,7 @@
#include <QObject>
#include <QProcess>
#include "../Environments.h"
#include "../GetterSetter.hpp"

enum eWineDesktop{
WD_disable,
@@ -19,8 +20,8 @@ enum eWineLog{

struct stWineDesktop{
eWineDesktop mode = WD_disable;
union{
struct{
union desktop{
struct size{
int W;
int H;
};
@@ -33,19 +34,33 @@ class Execute : public Environments
Q_OBJECT
public:
explicit Execute(QObject *parent, QString path, QString prefix);
~Execute();

private:
QString winePath;
QString winePrefix;
GetterSetter<eWineLog> wineLog;

GetterSetter<stWineDesktop> wineDesktop;

GetterSetter<QStringList> wineArgs;

GetterSetter<QString> launcher;
GetterSetter<QStringList> launcherArgs;

QStringList args;
GetterSetter<QString> exe;
GetterSetter<QStringList> exeArgs;

stWineDesktop desktop;
virtual void run();

QString exe;
QStringList exeArgs;
signals:
void done(const QProcess::ExitStatus &exitStatus);

private slots:
void finished(int exitCode, QProcess::ExitStatus exitStatus);

private:
QString _path;
QString _prefix;

QProcess *wine;
QProcess *_wine;
};

#endif // EXECUTE_H

+ 1
- 1
wine/RegEdit.h View File

@@ -11,7 +11,7 @@ public:
explicit RegEdit(QObject *parent = nullptr);

protected:
QString section;
QString _section;
};

#endif // REGEDIT_H

Loading…
Cancel
Save