dirtycold avatar dirtycold committed f1b9448

added a tool to convert between possible Config formations

Comments (0)

Files changed (6)

tools/ConfigConverter/ConfigConverter.pro

+#-------------------------------------------------
+#
+# Project created by QtCreator 2013-09-26T16:03:31
+#
+#-------------------------------------------------
+
+QT       += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = ConfigConverter
+TEMPLATE = app
+
+
+SOURCES += main.cpp\
+        configconverterwidget.cpp
+
+HEADERS  += configconverterwidget.h
+
+FORMS    += configconverterwidget.ui
+
+CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../Build -lConfig
+else:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../Build -lConfig
+
+INCLUDEPATH += $$PWD/../../base/Config
+DEPENDPATH += $$PWD/../../base/Config
+
+CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../Build -lModel
+else:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../Build -lModel
+
+INCLUDEPATH += $$PWD/../../base/Model
+DEPENDPATH += $$PWD/../../base/Model
+
+DESTDIR = $$OUT_PWD/../../Build

tools/ConfigConverter/configconverterwidget.cpp

+#include "configconverterwidget.h"
+#include "ui_configconverterwidget.h"
+
+#include <QDir>
+#include <QFileDialog>
+#include <QStringList>
+
+#include "setting.h"
+#include "digestsetting.h"
+
+
+ConfigConverterWidget::ConfigConverterWidget(QWidget *parent) :
+	QWidget(parent),
+	ui(new Ui::ConfigConverterWidget)
+{
+	ui->setupUi(this);
+	connect(ui->in_file_button,SIGNAL(clicked()),this,SLOT(in_file_selector()));
+	connect(ui->out_file_button,SIGNAL(clicked()),this,SLOT(out_file_selector()));
+	connect(ui->convert_button,SIGNAL(clicked()),this,SLOT(convert()));
+
+	connect(ui->in_plain_check,SIGNAL(clicked(bool)),ui->in_dig_combo,SLOT(setDisabled(bool)));
+	connect(ui->out_plain_check,SIGNAL(clicked(bool)),ui->out_dig_combo,SLOT(setDisabled(bool)));
+	QStringList enc_list;
+	enc_list.append("None");
+	enc_list.append("Caesor");
+	enc_list.append("Base64");
+
+	QStringList dig_list;
+	dig_list.append("None");
+	dig_list.append("MD5");
+
+	ui->in_enc_combo->addItems(enc_list);
+	ui->in_dig_combo->addItems(dig_list);
+	ui->out_enc_combo->addItems(enc_list);
+	ui->out_dig_combo->addItems(dig_list);
+
+
+}
+
+ConfigConverterWidget::~ConfigConverterWidget()
+{
+	delete ui;
+}
+
+void ConfigConverterWidget::convert()
+{
+	if (ui->in_file_edit->text().isEmpty() || ui->out_file_edit->text().isEmpty())
+		return;
+
+	RP::EncryptionInterface::Method in_enc_method;
+	RP::EncryptionInterface::Method out_enc_method;
+	RP::DigestInterface::Method in_dig_method;
+	RP::DigestInterface::Method out_dig_method;
+
+	QString in_enc_str = ui->in_enc_combo->currentText();
+	QString out_enc_str = ui->out_enc_combo->currentText();
+	QString in_dig_str = ui->in_dig_combo->currentText();
+	QString out_dig_str = ui->out_dig_combo->currentText();
+
+
+	if (in_enc_str == "Caesor")
+		in_enc_method = RP::EncryptionInterface::Caesor;
+	else if (in_enc_str == "Base64")
+		in_enc_method = RP::EncryptionInterface::Base64;
+	else /*in_enc_str == "None"*/
+		in_enc_method = RP::EncryptionInterface::None;
+
+	if (out_enc_str == "Caesor")
+		out_enc_method = RP::EncryptionInterface::Caesor;
+	else if (out_enc_str == "Base64")
+		out_enc_method = RP::EncryptionInterface::Base64;
+	else /*out_enc_str == "None"*/
+		out_enc_method = RP::EncryptionInterface::None;
+
+	if (in_dig_str == "MD5")
+		in_dig_method = RP::DigestInterface::MD5;
+	else
+		in_dig_method = RP::DigestInterface::None;
+
+	if (out_dig_str == "MD5")
+		out_dig_method = RP::DigestInterface::MD5;
+	else
+		out_dig_method = RP::DigestInterface::None;
+
+	RP::Setting *in_setting;
+	RP::Setting *out_setting;
+
+	if (ui->in_plain_check->isChecked())
+		in_setting = new RP::Setting (ui->in_file_edit->text().toStdString(),in_enc_method,ui->in_seed_edit->text().toStdString());
+	else
+		in_setting = new RP::DigestSetting(ui->in_file_edit->text().toStdString(),in_enc_method,in_dig_method,ui->in_seed_edit->text().toStdString());
+
+	if (ui->out_plain_check->isChecked())
+		out_setting = new RP::Setting (ui->out_file_edit->text().toStdString(),out_enc_method,ui->out_seed_edit->text().toStdString());
+	else
+		out_setting = new RP::DigestSetting (ui->out_file_edit->text().toStdString(),out_enc_method,out_dig_method,ui->out_seed_edit->text().toStdString());
+
+	std::stringstream ss;
+	in_setting->read();
+	in_setting->dump(ss);
+	out_setting->map(ss);
+	out_setting->write();
+
+
+}
+
+void ConfigConverterWidget::in_file_selector()
+{
+	QDir dir = QDir::currentPath();
+	QString in_file_path = QFileDialog::getOpenFileName(this,"IN_FILE",dir.path(),"Config (*.cfg)");
+	ui->in_file_edit->setText(in_file_path);
+}
+
+void ConfigConverterWidget::out_file_selector()
+{
+	QDir dir = QDir::currentPath();
+	ui->out_file_edit->setText(
+				QFileDialog::getExistingDirectory(this,
+												  "OUT_FILE",
+												  dir.path()
+												  ));
+}

tools/ConfigConverter/configconverterwidget.h

+#ifndef CONFIGCONVERTERWIDGET_H
+#define CONFIGCONVERTERWIDGET_H
+
+#include <QWidget>
+#include <QString>
+
+namespace Ui {
+class ConfigConverterWidget;
+}
+
+class ConfigConverterWidget : public QWidget
+{
+	Q_OBJECT
+
+public:
+	explicit ConfigConverterWidget(QWidget *parent = 0);
+	~ConfigConverterWidget();
+public slots:
+	void convert(/*all arguments are global*/);
+	void in_file_selector();
+	void out_file_selector();
+
+private:
+	Ui::ConfigConverterWidget *ui;
+
+	QString in_file_path;
+};
+
+#endif // CONFIGCONVERTERWIDGET_H

tools/ConfigConverter/configconverterwidget.ui

+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ConfigConverterWidget</class>
+ <widget class="QWidget" name="ConfigConverterWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>977</width>
+    <height>86</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>ConfigConverterWidget</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout_3">
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout_2">
+     <item>
+      <layout class="QGridLayout" name="gridLayout">
+       <item row="2" column="7">
+        <spacer name="verticalSpacer">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>40</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item row="0" column="4">
+        <widget class="QLabel" name="enc_label">
+         <property name="text">
+          <string>encryption</string>
+         </property>
+        </widget>
+       </item>
+       <item row="0" column="5">
+        <widget class="QLabel" name="dig_label">
+         <property name="text">
+          <string>digest</string>
+         </property>
+        </widget>
+       </item>
+       <item row="0" column="6">
+        <widget class="QLabel" name="seed_label">
+         <property name="text">
+          <string>seed</string>
+         </property>
+        </widget>
+       </item>
+       <item row="3" column="0">
+        <widget class="QLabel" name="out_label">
+         <property name="text">
+          <string>Out</string>
+         </property>
+        </widget>
+       </item>
+       <item row="2" column="4">
+        <widget class="QComboBox" name="in_enc_combo"/>
+       </item>
+       <item row="3" column="5">
+        <widget class="QComboBox" name="out_dig_combo"/>
+       </item>
+       <item row="2" column="5">
+        <widget class="QComboBox" name="in_dig_combo"/>
+       </item>
+       <item row="3" column="1">
+        <widget class="QPushButton" name="out_file_button">
+         <property name="text">
+          <string>...</string>
+         </property>
+        </widget>
+       </item>
+       <item row="0" column="3">
+        <widget class="QLabel" name="plain_label">
+         <property name="text">
+          <string>plain</string>
+         </property>
+        </widget>
+       </item>
+       <item row="2" column="2">
+        <widget class="QLineEdit" name="in_file_edit"/>
+       </item>
+       <item row="3" column="6">
+        <widget class="QLineEdit" name="out_seed_edit">
+         <property name="maximumSize">
+          <size>
+           <width>200</width>
+           <height>16777215</height>
+          </size>
+         </property>
+        </widget>
+       </item>
+       <item row="2" column="1">
+        <widget class="QPushButton" name="in_file_button">
+         <property name="text">
+          <string>...</string>
+         </property>
+        </widget>
+       </item>
+       <item row="2" column="3">
+        <widget class="QCheckBox" name="in_plain_check">
+         <property name="text">
+          <string/>
+         </property>
+        </widget>
+       </item>
+       <item row="3" column="2">
+        <widget class="QLineEdit" name="out_file_edit"/>
+       </item>
+       <item row="2" column="0">
+        <widget class="QLabel" name="in_label">
+         <property name="text">
+          <string>In</string>
+         </property>
+        </widget>
+       </item>
+       <item row="2" column="6">
+        <widget class="QLineEdit" name="in_seed_edit">
+         <property name="maximumSize">
+          <size>
+           <width>200</width>
+           <height>16777215</height>
+          </size>
+         </property>
+        </widget>
+       </item>
+       <item row="3" column="4">
+        <widget class="QComboBox" name="out_enc_combo"/>
+       </item>
+       <item row="3" column="3">
+        <widget class="QCheckBox" name="out_plain_check">
+         <property name="text">
+          <string/>
+         </property>
+        </widget>
+       </item>
+       <item row="3" column="7">
+        <spacer name="verticalSpacer_2">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>40</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item row="0" column="2">
+        <widget class="QLabel" name="file_label">
+         <property name="text">
+          <string>path</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+     <item>
+      <widget class="QPushButton" name="convert_button">
+       <property name="minimumSize">
+        <size>
+         <width>60</width>
+         <height>60</height>
+        </size>
+       </property>
+       <property name="text">
+        <string>Convert</string>
+       </property>
+       <property name="default">
+        <bool>false</bool>
+       </property>
+       <property name="flat">
+        <bool>false</bool>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>

tools/ConfigConverter/main.cpp

+#include "configconverterwidget.h"
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+	QApplication a(argc, argv);
+	ConfigConverterWidget w;
+	w.show();
+
+	return a.exec();
+}
 TEMPLATE = subdirs
 
 SUBDIRS += \
-    ConfigReader
+    ConfigReader \
+    ConfigConverter
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.