http模块有问题,需要修改

This commit is contained in:
2025-03-24 00:05:08 +08:00
commit 9d8c7baa36
66 changed files with 4602 additions and 0 deletions

View File

@@ -0,0 +1,149 @@
#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);
}

View File

@@ -0,0 +1,51 @@
#ifndef FILECONFIGDECODE_H
#define FILECONFIGDECODE_H
#include <QObject>
#include <QStandardPaths>
#include <QFile>
#include <QSettings>
#include <QFileInfo>
#include <QTextCodec>
class FileConfigDecode
{
public:
FileConfigDecode();
~FileConfigDecode();
QString getAddress();
quint16 getPort();
bool getAutoSetup();
bool getRename();
bool getTimeRename();
bool getAutoCopy();
void setAddress(QString value);
void setPort(quint16 value);
void setAutoSetup(bool value);
void setRename(bool value);
void setTimeRename(bool value);
void setAutoCopy(bool value);
private:
QString address;
quint16 port;
bool autoSetup;
bool rename;
bool timeRename;
bool autoCopy;
bool firstCreate;
void fileWrite(QString path, QString address, quint16 port, bool autosetup, bool rename, bool timerename, bool autocopy);
private:
void initFile();
void checkConfig();
void updateFile();
// void initForm();
};
#endif // FILECONFIGDECODE_H

View File

@@ -0,0 +1,5 @@
HEADERS += \
$$PWD/fileconfigdecode.h
SOURCES += \
$$PWD/fileconfigdecode.cpp