1.0 finish
This commit is contained in:
@@ -1,15 +1,30 @@
|
||||
#include "fileconfigdecode.h"
|
||||
#include <QDebug>
|
||||
|
||||
QScopedPointer<FileConfigDecode> FileConfigDecode::m_instance;
|
||||
|
||||
FileConfigDecode::FileConfigDecode()
|
||||
{
|
||||
// if (m_instance.isNull()) {
|
||||
// m_instance.reset(new FileConfigDecode);
|
||||
|
||||
// }
|
||||
initFile();
|
||||
qDebug() << "read:" << autoSetup << rename << timeRename << autoCopy;
|
||||
}
|
||||
|
||||
FileConfigDecode *FileConfigDecode::getInstance()
|
||||
{
|
||||
if (m_instance.isNull()) {
|
||||
m_instance.reset(new FileConfigDecode);
|
||||
|
||||
}
|
||||
|
||||
return m_instance.data();
|
||||
}
|
||||
|
||||
FileConfigDecode::~FileConfigDecode()
|
||||
{
|
||||
updateFile();
|
||||
// updateFile();
|
||||
// qDebug() << "write:" << autoSetup << rename << timeRename << autoCopy;
|
||||
}
|
||||
|
||||
@@ -43,6 +58,21 @@ bool FileConfigDecode::getAutoCopy()
|
||||
return autoCopy;
|
||||
}
|
||||
|
||||
QString FileConfigDecode::getUserName()
|
||||
{
|
||||
return userName;
|
||||
}
|
||||
|
||||
QString FileConfigDecode::getPassword()
|
||||
{
|
||||
return password;
|
||||
}
|
||||
|
||||
RenameType FileConfigDecode::getRenameType()
|
||||
{
|
||||
return renameType;
|
||||
}
|
||||
|
||||
void FileConfigDecode::setAddress(QString value)
|
||||
{
|
||||
this->address = value;
|
||||
@@ -58,28 +88,64 @@ void FileConfigDecode::setPort(quint16 value)
|
||||
void FileConfigDecode::setAutoSetup(bool value)
|
||||
{
|
||||
this->autoSetup = value;
|
||||
updateFile();
|
||||
// updateFile();
|
||||
}
|
||||
|
||||
void FileConfigDecode::setRename(bool value)
|
||||
{
|
||||
this->rename = value;
|
||||
if (value == true) {
|
||||
renameType = (renameType == RENAME_TYPE_TIME) ? RENAME_TYPE_TIME : RENAME_TYPE_NORMAL;
|
||||
}
|
||||
else {
|
||||
renameType = (renameType == RENAME_TYPE_TIME) ? RENAME_TYPE_TIME : RENAME_TYPE_NORMAL;
|
||||
}
|
||||
qDebug() << renameType;
|
||||
updateFile();
|
||||
// updateFile();
|
||||
}
|
||||
|
||||
void FileConfigDecode::setTimeRename(bool value)
|
||||
void FileConfigDecode::setTimeRename(bool value, int flag)
|
||||
{
|
||||
this->timeRename = value;
|
||||
if (value) {
|
||||
renameType = RENAME_TYPE_TIME;
|
||||
}
|
||||
|
||||
if (!value && flag == 1) {
|
||||
renameType = RENAME_TYPE_NORMAL;
|
||||
}
|
||||
|
||||
if (!value && flag == 0) {
|
||||
renameType = RENAME_TYPE_NONE;
|
||||
}
|
||||
qDebug() << renameType;
|
||||
updateFile();
|
||||
// updateFile();
|
||||
}
|
||||
|
||||
void FileConfigDecode::setAutoCopy(bool value)
|
||||
{
|
||||
this->autoCopy = value;
|
||||
updateFile();
|
||||
// updateFile();
|
||||
}
|
||||
|
||||
void FileConfigDecode::fileWrite(QString path, QString address, quint16 port, bool autosetup, bool rename, bool timerename, bool autocopy)
|
||||
void FileConfigDecode::setUserName(QString username)
|
||||
{
|
||||
this->userName = username;
|
||||
updateFile();
|
||||
}
|
||||
|
||||
void FileConfigDecode::setPassword(QString password)
|
||||
{
|
||||
this->password = password;
|
||||
updateFile();
|
||||
}
|
||||
|
||||
void FileConfigDecode::fileWrite(QString path, QString address, bool autosetup,
|
||||
bool rename, bool timerename, bool autocopy, QString username, QString password)
|
||||
{
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
QSettings* config = new QSettings(path, QSettings::IniFormat);
|
||||
@@ -105,6 +171,8 @@ void FileConfigDecode::fileWrite(QString path, QString address, quint16 port, bo
|
||||
config->setValue("rename", rename);
|
||||
config->setValue("timerename", timerename);
|
||||
config->setValue("autocopy", autocopy);
|
||||
config->setValue("username", username);
|
||||
config->setValue("password", password);
|
||||
config->endGroup();
|
||||
delete config;
|
||||
#endif
|
||||
@@ -113,7 +181,7 @@ void FileConfigDecode::fileWrite(QString path, QString address, quint16 port, bo
|
||||
void FileConfigDecode::initFile()
|
||||
{
|
||||
QString addDataPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
|
||||
QString addFilePath = addDataPath + "config.ini";
|
||||
QString addFilePath = addDataPath + "/config.ini";
|
||||
qDebug() << addFilePath;
|
||||
QFile file(addFilePath);
|
||||
if (file.exists()) {
|
||||
@@ -126,6 +194,8 @@ void FileConfigDecode::initFile()
|
||||
this->rename = config->value(section + "rename").toBool();
|
||||
this->timeRename = config->value(section + "timerename").toBool();
|
||||
this->autoCopy = config->value(section + "autocopy").toBool();
|
||||
this->userName = config->value(section+"username").toString();
|
||||
this->password = config->value(section+"password").toString();
|
||||
|
||||
checkConfig();
|
||||
|
||||
@@ -134,30 +204,38 @@ void FileConfigDecode::initFile()
|
||||
else {
|
||||
this->firstCreate = true;
|
||||
|
||||
this->address = "127.0.0.1";
|
||||
this->port = 0;
|
||||
this->address = "127.0.0.1:8080";
|
||||
this->autoSetup = false;
|
||||
this->rename = false;
|
||||
this->timeRename = false;
|
||||
this->autoCopy = false;
|
||||
this->userName = "admin";
|
||||
this->password = "admin";
|
||||
|
||||
fileWrite(addFilePath, address, port, autoSetup, rename, timeRename, autoCopy);
|
||||
fileWrite(addFilePath, address, autoSetup, rename, timeRename, autoCopy, userName, password);
|
||||
}
|
||||
}
|
||||
|
||||
void FileConfigDecode::checkConfig()
|
||||
{
|
||||
if (address.isEmpty()) {
|
||||
address = "127.0.0.1";
|
||||
address = "127.0.0.1:8080";
|
||||
}
|
||||
|
||||
if (rename)
|
||||
renameType = RENAME_TYPE_NORMAL;
|
||||
|
||||
if (timeRename)
|
||||
renameType = RENAME_TYPE_TIME;
|
||||
qDebug() << renameType;
|
||||
}
|
||||
|
||||
void FileConfigDecode::updateFile()
|
||||
{
|
||||
QString addDataPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
|
||||
QString addFilePath = addDataPath + "config.ini";
|
||||
QString addFilePath = addDataPath + "/config.ini";
|
||||
|
||||
qDebug() << "write" << autoSetup << rename << timeRename << autoCopy;
|
||||
fileWrite(addFilePath, address, port, autoSetup, rename, timeRename, autoCopy);
|
||||
fileWrite(addFilePath, address, autoSetup, rename, timeRename, autoCopy, userName, password);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,14 +6,21 @@
|
||||
#include <QFile>
|
||||
#include <QSettings>
|
||||
#include <QFileInfo>
|
||||
#include <QDebug>
|
||||
#if (QT_VERSION <= QT_VERSION_CHECK(6, 0, 0))
|
||||
#include <QTextCodec>
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
RENAME_TYPE_NONE = 0,
|
||||
RENAME_TYPE_NORMAL,
|
||||
RENAME_TYPE_TIME
|
||||
} RenameType;
|
||||
|
||||
class FileConfigDecode
|
||||
{
|
||||
public:
|
||||
FileConfigDecode();
|
||||
static FileConfigDecode* getInstance();
|
||||
~FileConfigDecode();
|
||||
|
||||
QString getAddress();
|
||||
@@ -22,13 +29,21 @@ public:
|
||||
bool getRename();
|
||||
bool getTimeRename();
|
||||
bool getAutoCopy();
|
||||
QString getUserName();
|
||||
QString getPassword();
|
||||
RenameType getRenameType();
|
||||
|
||||
void setAddress(QString value);
|
||||
void setPort(quint16 value);
|
||||
void setAutoSetup(bool value);
|
||||
void setRename(bool value);
|
||||
void setTimeRename(bool value);
|
||||
void setTimeRename(bool value, int flag);
|
||||
void setAutoCopy(bool value);
|
||||
void setUserName(QString username);
|
||||
void setPassword(QString password);
|
||||
|
||||
void initFile();
|
||||
void updateFile();
|
||||
|
||||
private:
|
||||
QString address;
|
||||
@@ -37,15 +52,22 @@ private:
|
||||
bool rename;
|
||||
bool timeRename;
|
||||
bool autoCopy;
|
||||
QString userName;
|
||||
QString password;
|
||||
|
||||
bool firstCreate;
|
||||
|
||||
void fileWrite(QString path, QString address, quint16 port, bool autosetup, bool rename, bool timerename, bool autocopy);
|
||||
RenameType renameType = RENAME_TYPE_NONE;
|
||||
|
||||
void fileWrite(QString path, QString address, bool autosetup, bool rename, bool timerename, bool autocopy, QString username, QString password);
|
||||
|
||||
static QScopedPointer<FileConfigDecode> m_instance;
|
||||
|
||||
private:
|
||||
void initFile();
|
||||
FileConfigDecode();
|
||||
|
||||
void checkConfig();
|
||||
void updateFile();
|
||||
|
||||
// void initForm();
|
||||
|
||||
};
|
||||
|
||||
@@ -284,7 +284,7 @@ void TCHttpService::setConfiguration(QString userName, QString firstPwd, QString
|
||||
if (code == 0) {
|
||||
this->m_token = jsonObj["token"].toString();
|
||||
qDebug() << this->m_token;
|
||||
this->m_isOnline = true;
|
||||
|
||||
apiMyfileCount();
|
||||
|
||||
}
|
||||
@@ -300,15 +300,18 @@ void TCHttpService::setConfiguration(QString userName, QString firstPwd, QString
|
||||
int total = jsonObj["total"].toInt();
|
||||
this->m_total = total;
|
||||
int n = total / 10 + 1;
|
||||
int pendingRequests = n;
|
||||
for (int i = 0; i < n; i++) {
|
||||
//0 10 20
|
||||
int count = (total - i * 10 >= 10) ? 10 : (total - i * 10);
|
||||
apiMyfileNormal(i*10, count);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
if (api == "myfilenormal") {
|
||||
static int loginCnt = 0;
|
||||
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(rawData);
|
||||
if (jsonDoc.isEmpty())
|
||||
return;
|
||||
@@ -328,15 +331,23 @@ void TCHttpService::setConfiguration(QString userName, QString firstPwd, QString
|
||||
QString md5 = jsonObj["md5"].toString();
|
||||
|
||||
QMap<QString, file_info_t>::iterator ite;
|
||||
ite = m_fileMap.find(file_name);
|
||||
ite = m_fileMap.find(md5);
|
||||
if (ite == m_fileMap.end()) {
|
||||
qDebug() << file_name;
|
||||
file_info_t info;
|
||||
info.share_status = share_status;
|
||||
info.size = size;
|
||||
info.url = url;
|
||||
info.file_name = file_name;
|
||||
emit signal_uploadFileSec(url);
|
||||
if (m_isOnline) {
|
||||
qDebug() << "now upload";
|
||||
emit signal_uploadFileSec(url);
|
||||
|
||||
}
|
||||
m_fileMap.insert(md5, info);
|
||||
// if (m_fileMap.size() == m_total && m_isOnline == false)
|
||||
|
||||
|
||||
}
|
||||
#if !DEBUG
|
||||
// for(auto ite = m_fileMap.constBegin(); ite != m_fileMap.constEnd(); ite++) {
|
||||
@@ -345,7 +356,14 @@ void TCHttpService::setConfiguration(QString userName, QString firstPwd, QString
|
||||
qDebug() << "fileMap size:" << m_fileMap.size();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!m_isOnline) {
|
||||
loginCnt++;
|
||||
qDebug() << "loginCnt:" << loginCnt;
|
||||
if (loginCnt == m_total/10+1) {
|
||||
m_isOnline = true;
|
||||
qDebug() << "login success";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// if (api == "upload") {
|
||||
|
||||
@@ -72,8 +72,6 @@ private:
|
||||
|
||||
bool m_uploadNum = 0;
|
||||
|
||||
signals:
|
||||
|
||||
};
|
||||
|
||||
#endif // TCHTTPSERVICE_H
|
||||
|
||||
Reference in New Issue
Block a user