123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- #include "fileconfigdecode.h"
- #include <QDebug>
- FileConfigDecode::FileConfigDecode()
- {
- initFile();
- qDebug() << "read:" << autoSetup << rename << timeRename << autoCopy;
- }
- FileConfigDecode::~FileConfigDecode()
- {
- updateFile();
- // qDebug() << "write:" << autoSetup << rename << timeRename << autoCopy;
- }
- QString FileConfigDecode::getAddress()
- {
- return this->address;
- }
- quint16 FileConfigDecode::getPort()
- {
- return port;
- }
- bool FileConfigDecode::getAutoSetup()
- {
- return autoSetup;
- }
- bool FileConfigDecode::getRename()
- {
- return rename;
- }
- bool FileConfigDecode::getTimeRename()
- {
- return timeRename;
- }
- bool FileConfigDecode::getAutoCopy()
- {
- return autoCopy;
- }
- void FileConfigDecode::setAddress(QString value)
- {
- this->address = value;
- // updateFile();
- }
- void FileConfigDecode::setPort(quint16 value)
- {
- this->port = value;
- // updateFile();
- }
- void FileConfigDecode::setAutoSetup(bool value)
- {
- this->autoSetup = value;
- // updateFile();
- }
- void FileConfigDecode::setRename(bool value)
- {
- this->rename = value;
- // updateFile();
- }
- void FileConfigDecode::setTimeRename(bool value)
- {
- this->timeRename = value;
- // updateFile();
- }
- void FileConfigDecode::setAutoCopy(bool value)
- {
- this->autoCopy = value;
- // updateFile();
- }
- void FileConfigDecode::fileWrite(QString path, QString address, quint16 port, bool autosetup, bool rename, bool timerename, bool autocopy)
- {
- QSettings* config = new QSettings(path, QSettings::IniFormat);
- config->setIniCodec(QTextCodec::codecForName("utf-8"));
- QString section = QString("config");
- config->beginGroup(section);
- config->setValue("address", address);
- config->setValue("port", port);
- config->setValue("autosetup", autosetup);
- config->setValue("rename", rename);
- config->setValue("timerename", timerename);
- config->setValue("autocopy", autocopy);
- config->endGroup();
- delete config;
- }
- void FileConfigDecode::initFile()
- {
- QString addDataPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
- QString addFilePath = addDataPath + "config.ini";
- qDebug() << addFilePath;
- QFile file(addFilePath);
- if (file.exists()) {
- QSettings* config = new QSettings(addFilePath, QSettings::IniFormat);
- config->setIniCodec(QTextCodec::codecForName("utf-8"));
- QString section = "config/";
- this->address = config->value(section + "address").toString();
- this->port = config->value(section + "port").toUInt();
- this->autoSetup = config->value(section + "autosetup").toBool();
- this->rename = config->value(section + "rename").toBool();
- this->timeRename = config->value(section + "timerename").toBool();
- this->autoCopy = config->value(section + "autocopy").toBool();
- checkConfig();
- this->firstCreate = false;
- }
- else {
- this->firstCreate = true;
- this->address = "127.0.0.1";
- this->port = 0;
- this->autoSetup = false;
- this->rename = false;
- this->timeRename = false;
- this->autoCopy = false;
- fileWrite(addFilePath, address, port, autoSetup, rename, timeRename, autoCopy);
- }
- }
- void FileConfigDecode::checkConfig()
- {
- if (address.isEmpty()) {
- address = "127.0.0.1";
- }
- }
- void FileConfigDecode::updateFile()
- {
- QString addDataPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
- QString addFilePath = addDataPath + "config.ini";
- qDebug() << "write" << autoSetup << rename << timeRename << autoCopy;
- fileWrite(addFilePath, address, port, autoSetup, rename, timeRename, autoCopy);
- }
|