* differentiate green editon and installed edition
This commit is contained in:
parent
e37053f2dd
commit
6d8654ee3e
|
@ -14,6 +14,7 @@ SOURCES += \
|
|||
main.cpp \
|
||||
mainwindow.cpp \
|
||||
settings.cpp \
|
||||
settingsdialog.cpp \
|
||||
systemconsts.cpp \
|
||||
utils.cpp
|
||||
|
||||
|
@ -22,11 +23,13 @@ HEADERS += \
|
|||
editorlist.h \
|
||||
mainwindow.h \
|
||||
settings.h \
|
||||
settingsdialog.h \
|
||||
systemconsts.h \
|
||||
utils.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
mainwindow.ui \
|
||||
settingsdialog.ui
|
||||
|
||||
TRANSLATIONS += \
|
||||
RedPandaIDE_zh_CN.ts
|
||||
|
|
|
@ -1,22 +1,71 @@
|
|||
#include "mainwindow.h"
|
||||
#include "settings.h"
|
||||
#include "systemconsts.h"
|
||||
#include "utils.h"
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QTranslator>
|
||||
#include <QDebug>
|
||||
#include <QStandardPaths>
|
||||
#include <QMessageBox>
|
||||
|
||||
// we have to wrap the following in a function, or it will crash createAppSettings when debug, don't know why
|
||||
void showConfigCantWriteMsg(const QString& filename) {
|
||||
QMessageBox::information(nullptr, QObject::tr("Error"),
|
||||
QString(QObject::tr("Can't write to configuration file %1")).arg(filename));
|
||||
}
|
||||
|
||||
Settings* createAppSettings(const QString& filepath = QString()) {
|
||||
QString filename("");
|
||||
if (filename.isEmpty()) {
|
||||
|
||||
// // if (isGreenEdition()) {
|
||||
// // name = QApplication::applicationDirPath() + QDir::separator() +
|
||||
// // "config" + QDir::separator() + APP_SETTSINGS_FILENAME;
|
||||
// // } else {
|
||||
filename = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation)[0]
|
||||
+ QDir::separator() + APP_SETTSINGS_FILENAME;
|
||||
// // }
|
||||
} else {
|
||||
filename = filepath;
|
||||
}
|
||||
|
||||
QDir dir = QFileInfo(filename).absoluteDir();
|
||||
if (!dir.exists()) {
|
||||
if (!dir.mkpath(dir.absolutePath())) {
|
||||
QMessageBox::information(nullptr, QObject::tr("Error"),
|
||||
QString(QObject::tr("Can't create configuration folder %1")).arg(dir.absolutePath()));
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
QFileInfo fileInfo(filename);
|
||||
|
||||
if (fileInfo.exists() && !fileInfo.isWritable()) {
|
||||
showConfigCantWriteMsg(filename);
|
||||
return nullptr;
|
||||
}
|
||||
return new Settings(filename);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
//load translations
|
||||
QTranslator trans;
|
||||
qDebug()<<QDir::currentPath();
|
||||
trans.load(("RedPandaIDE_zh_CN"));
|
||||
app.installTranslator(&trans);
|
||||
|
||||
SystemConsts systemConsts;
|
||||
pSystemConsts = &systemConsts;
|
||||
Settings settings;
|
||||
pSettings = &settings;
|
||||
|
||||
pSettings = createAppSettings();
|
||||
if (pSettings == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
auto settings = std::unique_ptr<Settings>(pSettings);
|
||||
|
||||
MainWindow mainWindow;
|
||||
pMainWindow = &mainWindow;
|
||||
mainWindow.show();
|
||||
|
|
|
@ -213,6 +213,17 @@
|
|||
<addaction name="actionSave"/>
|
||||
<addaction name="actionSave_All"/>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="toolBar_2">
|
||||
<property name="windowTitle">
|
||||
<string>toolBar_2</string>
|
||||
</property>
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<action name="actionNew">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
|
|
|
@ -5,19 +5,17 @@
|
|||
|
||||
Settings* pSettings;
|
||||
|
||||
Settings::Settings():
|
||||
mSettings(QSettings::IniFormat,QSettings::UserScope,"Red Panda C++"),
|
||||
Settings::Settings(const QString &filename):
|
||||
mSettings(filename,QSettings::IniFormat),
|
||||
mDirs(this),
|
||||
mEditor(this)
|
||||
{
|
||||
|
||||
// default values for editors
|
||||
mEditor.setDefault(SETTING_EDITOR_DEFAULT_ENCODING, QTextCodec::codecForLocale()->name());
|
||||
mEditor.setDefault(SETTING_EDITOR_AUTO_INDENT,true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Settings::setDefault(const QString&group,const QString &key, const QVariant &value) {
|
||||
mSettings.beginGroup(group);
|
||||
auto act = finally([this] {
|
||||
|
@ -112,3 +110,11 @@ void Settings::Editor::setAutoIndent(bool indent)
|
|||
}
|
||||
|
||||
|
||||
|
||||
Settings::CompilerSet::CompilerSet(Settings *settings, int index, const QString& compilerFolder):
|
||||
_Base(settings, "CompilerSet_"+QString(index)),
|
||||
|
||||
mIndex(index)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -2,12 +2,26 @@
|
|||
#define SETTINGS_H
|
||||
|
||||
#include <QSettings>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#define SETTING_DIRS "dirs"
|
||||
#define SETTING_EDITOR "editor"
|
||||
#define SETTING_EDITOR_DEFAULT_ENCODING "default_encoding"
|
||||
#define SETTING_EDITOR_AUTO_INDENT "default_auto_indent"
|
||||
|
||||
class Settings;
|
||||
|
||||
typedef struct {
|
||||
int name; // language table index of "Generate debugging info"
|
||||
int section; // language table index of "C options"
|
||||
bool isC;
|
||||
bool isCpp; // True (C++ option?) - can be both C and C++ option...
|
||||
bool isLinker; // Is it a linker param
|
||||
int value; // True
|
||||
QString Setting; // "-g3"
|
||||
QStringList Choices; // replaces "Yes/No" standard choices (max 30 different choices)
|
||||
} CompilerOption, *PCompilerOption;
|
||||
|
||||
class Settings
|
||||
{
|
||||
|
@ -39,9 +53,55 @@ public:
|
|||
void setAutoIndent(bool indent);
|
||||
};
|
||||
|
||||
public:
|
||||
Settings();
|
||||
class CompilerSet: public _Base {
|
||||
public:
|
||||
explicit CompilerSet(Settings *settings, int index, const QString& compilerFolder = QString());
|
||||
|
||||
private:
|
||||
int mIndex;
|
||||
// Executables, most are hardcoded
|
||||
QString mCCompilerName;
|
||||
QString mCPPCompilerName;
|
||||
QString mMakeName;
|
||||
QString mDebuggerName;
|
||||
QString mProfilerName;
|
||||
QString mResourceCompilerName;
|
||||
|
||||
// Directories, mostly hardcoded too
|
||||
QStringList mBinDirs;
|
||||
QStringList mCIncludeDirs;
|
||||
QStringList mCPPIncludeDirs;
|
||||
QStringList mLibDirs;
|
||||
|
||||
// Misc. properties
|
||||
QString mDumpMachine; // "x86_64-w64-mingw32", "mingw32" etc
|
||||
QString mVersion; // "4.7.1"
|
||||
QString mType; // "TDM-GCC", "MinGW"
|
||||
QString mName; // "TDM-GCC 4.7.1 Release"
|
||||
QString mFolder; // MinGW64, MinGW32
|
||||
QStringList mDefIncludes; // default include dir
|
||||
QStringList fDefines; // list of predefined constants
|
||||
QString mTarget; // 'X86_64' / 'i686'
|
||||
|
||||
// User settings
|
||||
bool mAddCustomCompileParams;
|
||||
bool mAddCustomLinkParams;
|
||||
QString mCustomCompileParams;
|
||||
QString mCustomLinkParams;
|
||||
bool mStaticLink;
|
||||
bool mAddCharsetParams;
|
||||
|
||||
// Options
|
||||
std::vector<std::shared_ptr<CompilerOption>> mOptions;
|
||||
};
|
||||
|
||||
public:
|
||||
explicit Settings(const QString& filename);
|
||||
explicit Settings(Settings&& settings) = delete;
|
||||
explicit Settings(const Settings& settings) = delete;
|
||||
|
||||
Settings& operator= (const Settings& settings) = delete;
|
||||
Settings& operator= (const Settings&& settings) = delete;
|
||||
void setDefault(const QString& group, const QString &key, const QVariant &value);
|
||||
void setValue(const QString& group, const QString &key, const QVariant &value);
|
||||
QVariant value(const QString& group, const QString &key);
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#include "settingsdialog.h"
|
||||
#include "ui_settingsdialog.h"
|
||||
|
||||
SettingsDialog::SettingsDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::SettingsDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
SettingsDialog::~SettingsDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef SETTINGSDIALOG_H
|
||||
#define SETTINGSDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class SettingsDialog;
|
||||
}
|
||||
|
||||
class SettingsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SettingsDialog(QWidget *parent = nullptr);
|
||||
~SettingsDialog();
|
||||
|
||||
private:
|
||||
Ui::SettingsDialog *ui;
|
||||
};
|
||||
|
||||
#endif // SETTINGSDIALOG_H
|
|
@ -0,0 +1,150 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SettingsDialog</class>
|
||||
<widget class="QDialog" name="SettingsDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>977</width>
|
||||
<height>622</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QListView" name="listView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QFrame" name="frame_2">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_3">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_4">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>192</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>OK</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="text">
|
||||
<string>Apply</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_3">
|
||||
<property name="text">
|
||||
<string>Cancle</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <QStringList>
|
||||
|
||||
#define APP_SETTSINGS_FILENAME "redpandacpp.ini"
|
||||
|
||||
class SystemConsts
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#include "utils.h"
|
||||
#include <QApplication>
|
||||
#include <QByteArray>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QSettings>
|
||||
#include <QString>
|
||||
#include <QTextCodec>
|
||||
|
||||
|
@ -60,3 +64,18 @@ bool isTextAllAscii(const QString& text) {
|
|||
}
|
||||
|
||||
|
||||
static bool gIsGreenEdition = false;
|
||||
static bool gIsGreenEditionInited = false;
|
||||
bool isGreenEdition()
|
||||
{
|
||||
if (!gIsGreenEditionInited) {
|
||||
QSettings settings("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\RedPanda-C++",
|
||||
QSettings::NativeFormat);
|
||||
QString regPath = QFileInfo(settings.value("UninstallString").toString()).absolutePath();
|
||||
|
||||
QString appPath = QApplication::instance()->applicationDirPath();
|
||||
gIsGreenEdition = (regPath != appPath);
|
||||
gIsGreenEditionInited = true;
|
||||
}
|
||||
return gIsGreenEdition;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ class QString;
|
|||
#define ENCODING_SYSTEM_DEFAULT "SYSTEM"
|
||||
#define ENCODING_ASCII "ASCII"
|
||||
|
||||
bool isGreenEdition();
|
||||
|
||||
const QByteArray GuessTextEncoding(const QByteArray& text);
|
||||
|
||||
bool isTextAllAscii(const QString& text);
|
||||
|
|
Loading…
Reference in New Issue