该版本可以上传xml文件以及图片到ftp服务器

main
seiyu 1 year ago
parent 9e2355e2d5
commit 92d931e56d

@ -93,7 +93,7 @@
<ClCompile>
<PreprocessorDefinitions>UNICODE;_UNICODE;WIN32;WIN64;QT_CORE_LIB;QT_WIDGETS_LIB;QT_GUI_LIB;NOMINMAX;QT_NETWORK_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>.\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;G:\code_library\c\opencv\4.3\build-opencv-cpu\include;$(ProjectDir)MvIMPACT;$(ProjectDir)Pylon6.2\include;$(ProjectDir)Common;$(ProjectDir)modbus;$(ProjectDir)MVS3.2.1\Include;$(ProjectDir)PLC;$(QTDIR)\include\QtNetwork;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<Optimization>Disabled</Optimization>
<Optimization>MaxSpeed</Optimization>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
@ -104,7 +104,7 @@
<SubSystem>Console</SubSystem>
<OutputFile>$(OutDir)\$(ProjectName).exe</OutputFile>
<AdditionalLibraryDirectories>$(QTDIR)\lib;G:\code_library\c\opencv\4.3\build-opencv-cpu\x64\vc15\lib;$(ProjectDir)Pylon6.2\lib\Win64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalDependencies>qtmaind.lib;Qt5Cored.lib;Qt5Widgetsd.lib;Qt5Guid.lib;opencv_world430d.lib;modbus.lib;mvDeviceManager.lib;MvCameraControl.lib;Qt5Networkd.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
@ -127,7 +127,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PreprocessorDefinitions>UNICODE;_UNICODE;WIN32;WIN64;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_WIDGETS_LIB;QT_GUI_LIB;NOMINMAX;QT_NETWORK_LIB;WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(QTDIR)\include\QtFtp;.\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(ProjectDir)MvIMPACT;$(ProjectDir)OpenCV455Simple\include;$(ProjectDir)Common;$(ProjectDir)Pylon6.2\include;$(ProjectDir)modbus;$(ProjectDir)MVS3.2.1\Include;$(ProjectDir)PLC;$(QTDIR)\include\QtNetwork;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(ProjectDir)MvIMPACT;$(ProjectDir)OpenCV455Simple\include;$(ProjectDir)Common;$(ProjectDir)Pylon6.2\include;$(ProjectDir)modbus;$(ProjectDir)MVS3.2.1\Include;$(ProjectDir)PLC;$(QTDIR)\include\QtNetwork;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
@ -142,7 +142,7 @@
<OutputFile>$(OutDir)\$(ProjectName).exe</OutputFile>
<AdditionalLibraryDirectories>$(QTDIR)\lib;$(ProjectDir)OpenCV455Simple\win64\vc15\lib;$(ProjectDir)Pylon6.2\lib\Win64;$(ProjectDir)MvIMPACT\lib\win64;$(ProjectDir)MVS3.2.1\lib\win64;$(ProjectDir)modbus;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalDependencies>qtmain.lib;Qt5Core.lib;Qt5Widgets.lib;Qt5Gui.lib;opencv_world455.lib;modbus.lib;mvDeviceManager.lib;MvCameraControl.lib;Qt5Network.lib;Qt5Ftp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>qtmain.lib;Qt5Core.lib;Qt5Widgets.lib;Qt5Gui.lib;opencv_world455.lib;modbus.lib;mvDeviceManager.lib;MvCameraControl.lib;Qt5Network.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries>
</Link>

@ -51,25 +51,25 @@ public:
QNetworkReply* reply = manager.put(QNetworkRequest(url), data);
QEventLoop eventLoop;
QObject::connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
// 进入等待,但事件循环依然进行 */
eventLoop.exec();
//QObject::connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
//// 进入等待,但事件循环依然进行 */
//eventLoop.exec();
QObject::connect(reply, &QNetworkReply::finished, [&]() {
if (reply->error() == QNetworkReply::NoError) {
// 读取响应数据
QByteArray responseData = reply->readAll();
// 处理响应数据
qDebug() << "Received response:" << responseData;
}
else {
// 处理错误
qDebug() << "Error occurred:" << reply->errorString();
}
//QObject::connect(reply, &QNetworkReply::finished, [&]() {
// if (reply->error() == QNetworkReply::NoError) {
// // 读取响应数据
// QByteArray responseData = reply->readAll();
// // 处理响应数据
// qDebug() << "Received response:" << responseData;
// }
// else {
// // 处理错误
// qDebug() << "Error occurred:" << reply->errorString();
// }
// 清理资源
reply->deleteLater();
});
// // 清理资源
// reply->deleteLater();
// });
}
}
};

@ -3,6 +3,11 @@
#include "QtCore\qtextstream.h"
#include <string>
//#include <ftpManager.h>
#include <wininet.h>
#include <Windows.h>
#include <sys/stat.h>
#include <io.h>
#pragma comment(lib, "Wininet.lib")
Cigarette* cg;
//extern SyncQueue<_ExportDataInfo>* export_Data_Info_queue;
@ -83,7 +88,6 @@ void ExportDataThread::stop()
//export_Data_Info_queue->put(data);
_XMLExportDataInfo data;
export_XMLData_Info_queue->put(data);
ftp.disconnect();
}
bool _ExportDataInfo::getAverageData(map<string, float> &averageData, int index)
@ -286,39 +290,37 @@ void ExportDataThread::run()
QString filePath = g_conf_path.config_path + "/" + xmlPath;
sprintf(buf, filePath.toLocal8Bit().constData(), element.cameraId);
insertXMLNode(buf, element);
QString remotePath = "/tmp/" + xmlPath;
//ftpManager.uploadSingleFile(filePath, remotePath);
QString serverAddress = "192.168.1.170";
QString port = "666";
QString userName = "FTP2";
QString pwd = "123";
bool success = false;
if (ftp.state() != QFtp::LoggedIn) {
if (!ftp.connectToHost(serverAddress, port.toInt())) {
qDebug() << "Failed to Connect";
}
else {
qDebug() << "Connected!";
if (ftp.login(userName, pwd)) {
qDebug() << "Logged in successfully!";
ftp.cd(remotePath);
// ×°Ôر¾µØÎļþ
QFile file(filePath);
bool isopen = false;
isopen = file.open(QIODevice::ReadOnly);
qDebug() << "Open file " << isopen;
if (isopen) {
success = ftp.put(&file, xmlPath);
if (success)
qDebug() << "UpLoad successful!";
else
qDebug() << "UpLoad failed!";
}
}
}
QString remotePath = "/tmp1/" + xmlPath;
ConnectServer(filePath, remotePath);
QDateTime now_ts = QDateTime::currentDateTime();
for (int index = 0; index < element.shotCounts; index++) {
// 上传ALL
QString all_folder = g_conf_path.save_pics_path + "/ALL/"
+ now_ts.toString("yyyy-MM-dd") + "/"
+ QString::number(element.cameraId + 1) + "/" + QString::number(index + 1);
QString all_folder_remote = "./image/ALL/"
+ now_ts.toString("yyyy-MM-dd") + "/"
+ QString::number(element.cameraId + 1) + "/" + QString::number(index + 1) + "/";
ConnectServer(all_folder, all_folder_remote);
// 上传ng
QString ng_folder = g_conf_path.save_pics_path + "/ng/"
+ now_ts.toString("yyyy-MM-dd") + "/"
+ QString::number(element.cameraId + 1) + "/" + QString::number(index + 1);
QString ng_folder_remote = "./image/ng/"
+ now_ts.toString("yyyy-MM-dd") + "/"
+ QString::number(element.cameraId + 1) + "/" + QString::number(index + 1) + "/";
ConnectServer(ng_folder, ng_folder_remote);
// 上传ng_result
QString ng_result_folder = g_conf_path.save_pics_path + "/ng_result/"
+ now_ts.toString("yyyy-MM-dd") + "/"
+ QString::number(element.cameraId + 1) + "/" + QString::number(index + 1);
QString ng_result_folder_remote = "./image/ng_result/"
+ now_ts.toString("yyyy-MM-dd") + "/"
+ QString::number(element.cameraId + 1) + "/" + QString::number(index + 1) + "/";
ConnectServer(ng_result_folder, ng_result_folder_remote);
}
}
}
@ -326,7 +328,6 @@ void ExportDataThread::run()
for (int index = 0; index < NumberOfSupportedCameras; index++) {
pDocument[index]->~XMLDocument();
}
}
void ExportDataThread::check_save_dir(std::string dir_path)
@ -355,4 +356,123 @@ void ExportDataThread::check_save_dir(std::string dir_path)
void ExportDataThread::EDrecMsgFromCigarette(){
flag = true;
}
void ExportDataThread::ConnectServer(QString srcPath, QString destPath) {
string filePath = srcPath.toLocal8Bit().constData();
string remotePath = destPath.toLocal8Bit().constData();
// FTP地址
string ftpServer = "192.168.1.170";
/* 端口号一般为21 */
int port = 666;
/* 用户名 */
string userName = "FTP2";
/* 密码 */
string pwd = "123";
std::vector<string> files;
// 判断上传的是文件还是文件夹标识
int size = 0;
struct stat st;
stat(filePath.c_str(), &st);
if (st.st_mode & S_IFDIR) {
//qDebug() << "filePath is Directory";
// 获取文件夹下所有文件名
GetFiles(filePath, files);
size = files.size();
}
HINTERNET hint;
HINTERNET hftp;
DWORD dw = GetLastError();
do {
hint = InternetOpen(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);
if (hint == NULL) {
break;
}
// 创建ftp连接
hftp = InternetConnectA(hint, ftpServer.c_str(), port, userName.c_str(), pwd.c_str(), INTERNET_SERVICE_FTP, 0, 0);
if (hftp == NULL) {
qDebug() << "ftp connect failed";
break;
}
// 如果目的路径不存在,一级一级创建
// 目的路径格式为:"./dir/dir1/.../"
int pos = 1;
string tempPath;
while (pos > 0) {
// 从第二个“/”开始依次找到目的路径中的“/”位置
pos = remotePath.find_first_of('/', pos + 1);
if (pos == -1)
break;
tempPath = remotePath.substr(0, pos + 1);
//qDebug() << "tempPath is " << tempPath.c_str();
if (_access(tempPath.c_str(), 0) == -1) {
/*if (FtpCreateDirectoryA(hftp, tempPath.c_str()))
qDebug() << "ftp createDirectory successful!";
else {
qDebug() << "ftp createDirectory failed because" << dw;
}*/
FtpCreateDirectoryA(hftp, tempPath.c_str());
}
}
if (FtpSetCurrentDirectoryA(hftp, tempPath.c_str())) {
// 上传文件源为一个文件
if (size == 0) {
int pos = filePath.find_last_of('/');
string destFileName = filePath.substr(pos + 1);
if (!FtpPutFileA(hftp, filePath.c_str(), destFileName.c_str(), FTP_TRANSFER_TYPE_BINARY, 0))
qDebug() << "ftp put file failed because" << dw;
}
// 上传源为一个文件夹
else{
for (int i = 0; i < size; i++) {
string tempFilePath = files[i].c_str();
//qDebug() << "tempFilePath is " << tempFilePath.c_str();
// 获取上传路径中的文件名
int pos = tempFilePath.find_last_of('/');
string destFileName = tempFilePath.substr(pos + 1);
//qDebug() << "destFileName is " << destFileName.c_str();
if(!FtpPutFileA(hftp, tempFilePath.c_str(), destFileName.c_str(), FTP_TRANSFER_TYPE_BINARY, 0))
qDebug() << "ftp put files failed because " << dw;
}
}
}
} while (0);
InternetCloseHandle(hftp);
InternetCloseHandle(hint);
}
void ExportDataThread::GetFiles(string path, std::vector<string>& files) {
//文件句柄
intptr_t hFile = 0;
//文件信息的结构体
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
{
// "\\*"是指读取文件夹下的所有类型的文件
do
{
//如果是目录,迭代之
//如果不是,加入列表
if ((fileinfo.attrib & _A_SUBDIR))
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
GetFiles(p.assign(path).append("/").append(fileinfo.name), files);
}
else
{
files.push_back(p.assign(path).append("/").append(fileinfo.name));
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}

@ -10,8 +10,7 @@
#include "tinyxml2.h"
#include "common.h"
#include "cigarette.h"
#include <QtFtp\qftp.h>
#include <QtFtp\qurlinfo.h>
#include "qdebug.h"
#define EXPORTDATA_FILE "camera%1_data_info.xml"
using namespace tinyxml2;
@ -113,13 +112,14 @@ public:
quit();
wait();
}
QFtp ftp;
void init();
void start_work();
void stop();
//int insertXMLNode(const char* xmlPath, _ExportDataInfo& data);
int insertXMLNode(const char* xmlPath, _XMLExportDataInfo& data);
void ConnectServer(QString srcPath, QString destPath);
void GetFiles(string path, std::vector<string>& files);
protected:
void run();

@ -7,13 +7,14 @@
#include <PLCDevice.h>
#include "exportData.h"
#include <QMap>
#include <ftpManager.h>
//#include <ftpManager.h>
extern AlgJd alg_jd[NumberOfSupportedCameras]; //检测胶点的AI算法
extern ConfPath g_conf_path;
extern SysConf g_sys_conf; //系统配置参数
extern DisplayLabelConf g_display_label_conf[NumberOfSupportedCameras];
extern FtpManager ftpManager;
//extern FtpManager ftpManager;
extern ExportDataThread exportDataThread;
extern int rotationAngle[NumberOfSupportedCameras]; //图片旋转角度
extern bool isNeedRotate[NumberOfSupportedCameras];
@ -247,7 +248,8 @@ void WorkThread::run()
"#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] +
".jpg";
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
ftpManager.uploadSingleFile(file_name, remotePath);
//ftpManager.uploadSingleFile(file_name, remotePath);
//exportDataThread.ConnectServer(file_name, remotePath);
m = vec_out[index].clone();
file_name = g_conf_path.save_pics_path + "/ng_result/" +
@ -255,14 +257,15 @@ void WorkThread::run()
+ QString::number(local_camera_number + 1) + "/" + QString::number(index + 1) + "/" +
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
"#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] +
".bmp";
".jpg";
remotePath = "/image/ng_result/" +
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
"#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] +
".jpg";
//g_save_queue->put(std::make_pair(file_name.toStdString(), m));
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
ftpManager.uploadSingleFile(file_name, remotePath);
//ftpManager.uploadSingleFile(file_name, remotePath);
//exportDataThread.ConnectServer(file_name, remotePath);
}
}
}

Binary file not shown.

Binary file not shown.

@ -1,7 +0,0 @@
QMAKE_PRL_BUILD_DIR = D:/qtftp-master/qtftp-master/src/qftp
QMAKE_PRO_INPUT = qftp.pro
QMAKE_PRL_TARGET = Qt5Ftp.lib
QMAKE_PRL_CONFIG = lex yacc depend_includepath testcase_targets import_qpa_plugin windows prepare_docs qt_docs_targets qt_build_extra file_copies qmake_use qt warn_on release link_prl flat debug_and_release autogen_precompile_source embed_manifest_dll embed_manifest_exe release no_plugin_manifest win32 msvc copy_dir_files sse2 aesni sse3 ssse3 sse4_1 sse4_2 avx avx2 avx512f avx512bw avx512cd avx512dq avx512er avx512ifma avx512pf avx512vbmi avx512vl compile_examples f16c force_debug_info largefile rdrnd rdseed shani x86SimdAlways prefix_build force_independent utf8_source create_prl link_prl no_private_qt_headers_warning QTDIR_build qt_example_installs exceptions_off testcase_exceptions release ReleaseBuild Release build_pass c++11 release ReleaseBuild Release build_pass staticlib static relative_qt_rpath target_qt c++11 strict_c++ c++14 c++1z qt_install_headers need_fwd_pri qt_install_module debug_and_release build_all create_cmake skip_target_version_ext release ReleaseBuild Release build_pass have_target static staticlib exclusive_builds debug_info no_autoqmake thread moc resources
QMAKE_PRL_VERSION = 5.0.0
QMAKE_PRL_LIBS = -L\$(QTDIR)\\lib -LC:\\openssl\\lib -LC:\\Utils\\my_sql\\mysql-5.7.25-winx64\\lib -LC:\\Utils\\postgresql\\pgsql\\lib D:/QT/5.15.2/MSVC2019_64/lib/Qt5Network.lib D:/QT/5.15.2/MSVC2019_64/lib/Qt5Core.lib
QMAKE_PRL_LIBS_FOR_CMAKE = -L$(QTDIR)\\lib;-LC:\\openssl\\lib;-LC:\\Utils\\my_sql\\mysql-5.7.25-winx64\\lib;-LC:\\Utils\\postgresql\\pgsql\\lib;D:/QT/5.15.2/MSVC2019_64/lib/Qt5Network.lib;D:/QT/5.15.2/MSVC2019_64/lib/Qt5Core.lib;;;

File diff suppressed because it is too large Load Diff

@ -1,162 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtNetwork module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QFTP_H
#define QFTP_H
#include <QtCore/qstring.h>
#include <QtCore/qobject.h>
//#include <QtFtp/qurlinfo.h>
#include <qurlinfo.h>
QT_BEGIN_NAMESPACE
class QFtpPrivate;
class QFtp : public QObject
{
Q_OBJECT
public:
explicit QFtp(QObject *parent = 0);
virtual ~QFtp();
enum State {
Unconnected,
HostLookup,
Connecting,
Connected,
LoggedIn,
Closing
};
enum Error {
NoError,
UnknownError,
HostNotFound,
ConnectionRefused,
NotConnected
};
enum Command {
None,
SetTransferMode,
SetProxy,
ConnectToHost,
Login,
Close,
List,
Cd,
Get,
Put,
Remove,
Mkdir,
Rmdir,
Rename,
RawCommand
};
enum TransferMode {
Active,
Passive
};
enum TransferType {
Binary,
Ascii
};
int setProxy(const QString &host, quint16 port);
int connectToHost(const QString &host, quint16 port=21);
int login(const QString &user = QString(), const QString &password = QString());
int close();
int setTransferMode(TransferMode mode);
int list(const QString &dir = QString());
int cd(const QString &dir);
int get(const QString &file, QIODevice *dev=0, TransferType type = Binary);
int put(const QByteArray &data, const QString &file, TransferType type = Binary);
int put(QIODevice *dev, const QString &file, TransferType type = Binary);
int remove(const QString &file);
int mkdir(const QString &dir);
int rmdir(const QString &dir);
int rename(const QString &oldname, const QString &newname);
int rawCommand(const QString &command);
qint64 bytesAvailable() const;
qint64 read(char *data, qint64 maxlen);
QByteArray readAll();
int currentId() const;
QIODevice* currentDevice() const;
Command currentCommand() const;
bool hasPendingCommands() const;
void clearPendingCommands();
State state() const;
Error error() const;
QString errorString() const;
public Q_SLOTS:
void abort();
Q_SIGNALS:
void stateChanged(int);
void listInfo(const QUrlInfo&);
void readyRead();
void dataTransferProgress(qint64, qint64);
void rawCommandReply(int, const QString&);
void commandStarted(int);
void commandFinished(int, bool);
void done(bool);
private:
Q_DISABLE_COPY(QFtp)
QScopedPointer<QFtpPrivate> d;
Q_PRIVATE_SLOT(d, void _q_startNextCommand())
Q_PRIVATE_SLOT(d, void _q_piFinished(const QString&))
Q_PRIVATE_SLOT(d, void _q_piError(int, const QString&))
Q_PRIVATE_SLOT(d, void _q_piConnectState(int))
Q_PRIVATE_SLOT(d, void _q_piFtpReply(int, const QString&))
};
QT_END_NAMESPACE
#endif // QFTP_H

@ -1,728 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtNetwork module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qurlinfo.h"
#include "qurl.h"
#include "qdir.h"
#include <limits.h>
QT_BEGIN_NAMESPACE
class QUrlInfoPrivate
{
public:
QUrlInfoPrivate() :
permissions(0),
size(0),
isDir(false),
isFile(true),
isSymLink(false),
isWritable(true),
isReadable(true),
isExecutable(false)
{}
QString name;
int permissions;
QString owner;
QString group;
qint64 size;
QDateTime lastModified;
QDateTime lastRead;
bool isDir;
bool isFile;
bool isSymLink;
bool isWritable;
bool isReadable;
bool isExecutable;
};
/*!
\class QUrlInfo
\brief The QUrlInfo class stores information about URLs.
\ingroup io
\ingroup network
\inmodule QtNetwork
The information about a URL that can be retrieved includes name(),
permissions(), owner(), group(), size(), lastModified(),
lastRead(), isDir(), isFile(), isSymLink(), isWritable(),
isReadable() and isExecutable().
You can create your own QUrlInfo objects passing in all the
relevant information in the constructor, and you can modify a
QUrlInfo; for each getter mentioned above there is an equivalent
setter. Note that setting values does not affect the underlying
resource that the QUrlInfo provides information about; for example
if you call setWritable(true) on a read-only resource the only
thing changed is the QUrlInfo object, not the resource.
\sa QUrl, {FTP Example}
*/
/*!
\enum QUrlInfo::PermissionSpec
This enum is used by the permissions() function to report the
permissions of a file.
\value ReadOwner The file is readable by the owner of the file.
\value WriteOwner The file is writable by the owner of the file.
\value ExeOwner The file is executable by the owner of the file.
\value ReadGroup The file is readable by the group.
\value WriteGroup The file is writable by the group.
\value ExeGroup The file is executable by the group.
\value ReadOther The file is readable by anyone.
\value WriteOther The file is writable by anyone.
\value ExeOther The file is executable by anyone.
*/
/*!
Constructs an invalid QUrlInfo object with default values.
\sa isValid()
*/
QUrlInfo::QUrlInfo()
{
d = 0;
}
/*!
Copy constructor, copies \a ui to this URL info object.
*/
QUrlInfo::QUrlInfo(const QUrlInfo &ui)
{
if (ui.d) {
d = new QUrlInfoPrivate;
*d = *ui.d;
} else {
d = 0;
}
}
/*!
Constructs a QUrlInfo object by specifying all the URL's
information.
The information that is passed is the \a name, file \a
permissions, \a owner and \a group and the file's \a size. Also
passed is the \a lastModified date/time and the \a lastRead
date/time. Flags are also passed, specifically, \a isDir, \a
isFile, \a isSymLink, \a isWritable, \a isReadable and \a
isExecutable.
*/
QUrlInfo::QUrlInfo(const QString &name, int permissions, const QString &owner,
const QString &group, qint64 size, const QDateTime &lastModified,
const QDateTime &lastRead, bool isDir, bool isFile, bool isSymLink,
bool isWritable, bool isReadable, bool isExecutable)
{
d = new QUrlInfoPrivate;
d->name = name;
d->permissions = permissions;
d->owner = owner;
d->group = group;
d->size = size;
d->lastModified = lastModified;
d->lastRead = lastRead;
d->isDir = isDir;
d->isFile = isFile;
d->isSymLink = isSymLink;
d->isWritable = isWritable;
d->isReadable = isReadable;
d->isExecutable = isExecutable;
}
/*!
Constructs a QUrlInfo object by specifying all the URL's
information.
The information that is passed is the \a url, file \a
permissions, \a owner and \a group and the file's \a size. Also
passed is the \a lastModified date/time and the \a lastRead
date/time. Flags are also passed, specifically, \a isDir, \a
isFile, \a isSymLink, \a isWritable, \a isReadable and \a
isExecutable.
*/
QUrlInfo::QUrlInfo(const QUrl &url, int permissions, const QString &owner,
const QString &group, qint64 size, const QDateTime &lastModified,
const QDateTime &lastRead, bool isDir, bool isFile, bool isSymLink,
bool isWritable, bool isReadable, bool isExecutable)
{
d = new QUrlInfoPrivate;
d->name = QFileInfo(url.path()).fileName();
d->permissions = permissions;
d->owner = owner;
d->group = group;
d->size = size;
d->lastModified = lastModified;
d->lastRead = lastRead;
d->isDir = isDir;
d->isFile = isFile;
d->isSymLink = isSymLink;
d->isWritable = isWritable;
d->isReadable = isReadable;
d->isExecutable = isExecutable;
}
/*!
Sets the name of the URL to \a name. The name is the full text,
for example, "http://qt.nokia.com/doc/qurlinfo.html".
If you call this function for an invalid URL info, this function
turns it into a valid one.
\sa isValid()
*/
void QUrlInfo::setName(const QString &name)
{
if (!d)
d = new QUrlInfoPrivate;
d->name = name;
}
/*!
If \a b is true then the URL is set to be a directory; if \a b is
false then the URL is set not to be a directory (which normally
means it is a file). (Note that a URL can refer to both a file and
a directory even though most file systems do not support this.)
If you call this function for an invalid URL info, this function
turns it into a valid one.
\sa isValid()
*/
void QUrlInfo::setDir(bool b)
{
if (!d)
d = new QUrlInfoPrivate;
d->isDir = b;
}
/*!
If \a b is true then the URL is set to be a file; if \b is false
then the URL is set not to be a file (which normally means it is a
directory). (Note that a URL can refer to both a file and a
directory even though most file systems do not support this.)
If you call this function for an invalid URL info, this function
turns it into a valid one.
\sa isValid()
*/
void QUrlInfo::setFile(bool b)
{
if (!d)
d = new QUrlInfoPrivate;
d->isFile = b;
}
/*!
Specifies that the URL refers to a symbolic link if \a b is true
and that it does not if \a b is false.
If you call this function for an invalid URL info, this function
turns it into a valid one.
\sa isValid()
*/
void QUrlInfo::setSymLink(bool b)
{
if (!d)
d = new QUrlInfoPrivate;
d->isSymLink = b;
}
/*!
Specifies that the URL is writable if \a b is true and not
writable if \a b is false.
If you call this function for an invalid URL info, this function
turns it into a valid one.
\sa isValid()
*/
void QUrlInfo::setWritable(bool b)
{
if (!d)
d = new QUrlInfoPrivate;
d->isWritable = b;
}
/*!
Specifies that the URL is readable if \a b is true and not
readable if \a b is false.
If you call this function for an invalid URL info, this function
turns it into a valid one.
\sa isValid()
*/
void QUrlInfo::setReadable(bool b)
{
if (!d)
d = new QUrlInfoPrivate;
d->isReadable = b;
}
/*!
Specifies that the owner of the URL is called \a s.
If you call this function for an invalid URL info, this function
turns it into a valid one.
\sa isValid()
*/
void QUrlInfo::setOwner(const QString &s)
{
if (!d)
d = new QUrlInfoPrivate;
d->owner = s;
}
/*!
Specifies that the owning group of the URL is called \a s.
If you call this function for an invalid URL info, this function
turns it into a valid one.
\sa isValid()
*/
void QUrlInfo::setGroup(const QString &s)
{
if (!d)
d = new QUrlInfoPrivate;
d->group = s;
}
/*!
Specifies the \a size of the URL.
If you call this function for an invalid URL info, this function
turns it into a valid one.
\sa isValid()
*/
void QUrlInfo::setSize(qint64 size)
{
if (!d)
d = new QUrlInfoPrivate;
d->size = size;
}
/*!
Specifies that the URL has access permissions \a p.
If you call this function for an invalid URL info, this function
turns it into a valid one.
\sa isValid()
*/
void QUrlInfo::setPermissions(int p)
{
if (!d)
d = new QUrlInfoPrivate;
d->permissions = p;
}
/*!
Specifies that the object the URL refers to was last modified at
\a dt.
If you call this function for an invalid URL info, this function
turns it into a valid one.
\sa isValid()
*/
void QUrlInfo::setLastModified(const QDateTime &dt)
{
if (!d)
d = new QUrlInfoPrivate;
d->lastModified = dt;
}
/*!
\since 4.4
Specifies that the object the URL refers to was last read at
\a dt.
If you call this function for an invalid URL info, this function
turns it into a valid one.
\sa isValid()
*/
void QUrlInfo::setLastRead(const QDateTime &dt)
{
if (!d)
d = new QUrlInfoPrivate;
d->lastRead = dt;
}
/*!
Destroys the URL info object.
*/
QUrlInfo::~QUrlInfo()
{
delete d;
}
/*!
Assigns the values of \a ui to this QUrlInfo object.
*/
QUrlInfo &QUrlInfo::operator=(const QUrlInfo &ui)
{
if (ui.d) {
if (!d)
d= new QUrlInfoPrivate;
*d = *ui.d;
} else {
delete d;
d = 0;
}
return *this;
}
/*!
Returns the file name of the URL.
\sa isValid()
*/
QString QUrlInfo::name() const
{
if (!d)
return QString();
return d->name;
}
/*!
Returns the permissions of the URL. You can use the \c PermissionSpec flags
to test for certain permissions.
\sa isValid()
*/
int QUrlInfo::permissions() const
{
if (!d)
return 0;
return d->permissions;
}
/*!
Returns the owner of the URL.
\sa isValid()
*/
QString QUrlInfo::owner() const
{
if (!d)
return QString();
return d->owner;
}
/*!
Returns the group of the URL.
\sa isValid()
*/
QString QUrlInfo::group() const
{
if (!d)
return QString();
return d->group;
}
/*!
Returns the size of the URL.
\sa isValid()
*/
qint64 QUrlInfo::size() const
{
if (!d)
return 0;
return d->size;
}
/*!
Returns the last modification date of the URL.
\sa isValid()
*/
QDateTime QUrlInfo::lastModified() const
{
if (!d)
return QDateTime();
return d->lastModified;
}
/*!
Returns the date when the URL was last read.
\sa isValid()
*/
QDateTime QUrlInfo::lastRead() const
{
if (!d)
return QDateTime();
return d->lastRead;
}
/*!
Returns true if the URL is a directory; otherwise returns false.
\sa isValid()
*/
bool QUrlInfo::isDir() const
{
if (!d)
return false;
return d->isDir;
}
/*!
Returns true if the URL is a file; otherwise returns false.
\sa isValid()
*/
bool QUrlInfo::isFile() const
{
if (!d)
return false;
return d->isFile;
}
/*!
Returns true if the URL is a symbolic link; otherwise returns false.
\sa isValid()
*/
bool QUrlInfo::isSymLink() const
{
if (!d)
return false;
return d->isSymLink;
}
/*!
Returns true if the URL is writable; otherwise returns false.
\sa isValid()
*/
bool QUrlInfo::isWritable() const
{
if (!d)
return false;
return d->isWritable;
}
/*!
Returns true if the URL is readable; otherwise returns false.
\sa isValid()
*/
bool QUrlInfo::isReadable() const
{
if (!d)
return false;
return d->isReadable;
}
/*!
Returns true if the URL is executable; otherwise returns false.
\sa isValid()
*/
bool QUrlInfo::isExecutable() const
{
if (!d)
return false;
return d->isExecutable;
}
/*!
Returns true if \a i1 is greater than \a i2; otherwise returns
false. The objects are compared by the value, which is specified
by \a sortBy. This must be one of QDir::Name, QDir::Time or
QDir::Size.
*/
bool QUrlInfo::greaterThan(const QUrlInfo &i1, const QUrlInfo &i2,
int sortBy)
{
switch (sortBy) {
case QDir::Name:
return i1.name() > i2.name();
case QDir::Time:
return i1.lastModified() > i2.lastModified();
case QDir::Size:
return i1.size() > i2.size();
default:
return false;
}
}
/*!
Returns true if \a i1 is less than \a i2; otherwise returns false.
The objects are compared by the value, which is specified by \a
sortBy. This must be one of QDir::Name, QDir::Time or QDir::Size.
*/
bool QUrlInfo::lessThan(const QUrlInfo &i1, const QUrlInfo &i2,
int sortBy)
{
return !greaterThan(i1, i2, sortBy);
}
/*!
Returns true if \a i1 equals to \a i2; otherwise returns false.
The objects are compared by the value, which is specified by \a
sortBy. This must be one of QDir::Name, QDir::Time or QDir::Size.
*/
bool QUrlInfo::equal(const QUrlInfo &i1, const QUrlInfo &i2,
int sortBy)
{
switch (sortBy) {
case QDir::Name:
return i1.name() == i2.name();
case QDir::Time:
return i1.lastModified() == i2.lastModified();
case QDir::Size:
return i1.size() == i2.size();
default:
return false;
}
}
/*!
Returns true if this QUrlInfo is equal to \a other; otherwise
returns false.
\sa lessThan(), equal()
*/
bool QUrlInfo::operator==(const QUrlInfo &other) const
{
if (!d)
return other.d == 0;
if (!other.d)
return false;
return (d->name == other.d->name &&
d->permissions == other.d->permissions &&
d->owner == other.d->owner &&
d->group == other.d->group &&
d->size == other.d->size &&
d->lastModified == other.d->lastModified &&
d->lastRead == other.d->lastRead &&
d->isDir == other.d->isDir &&
d->isFile == other.d->isFile &&
d->isSymLink == other.d->isSymLink &&
d->isWritable == other.d->isWritable &&
d->isReadable == other.d->isReadable &&
d->isExecutable == other.d->isExecutable);
}
/*!
\fn bool QUrlInfo::operator!=(const QUrlInfo &other) const
\since 4.2
Returns true if this QUrlInfo is not equal to \a other; otherwise
returns false.
\sa lessThan(), equal()
*/
/*!
Returns true if the URL info is valid; otherwise returns false.
Valid means that the QUrlInfo contains real information.
You should always check if the URL info is valid before relying on
the values.
*/
bool QUrlInfo::isValid() const
{
return d != 0;
}
QT_END_NAMESPACE

@ -1,121 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtNetwork module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QURLINFO_H
#define QURLINFO_H
#include <QtCore/qdatetime.h>
#include <QtCore/qstring.h>
#include <QtCore/qiodevice.h>
QT_BEGIN_NAMESPACE
class QUrl;
class QUrlInfoPrivate;
class QUrlInfo
{
public:
enum PermissionSpec {
ReadOwner = 00400, WriteOwner = 00200, ExeOwner = 00100,
ReadGroup = 00040, WriteGroup = 00020, ExeGroup = 00010,
ReadOther = 00004, WriteOther = 00002, ExeOther = 00001 };
QUrlInfo();
QUrlInfo(const QUrlInfo &ui);
QUrlInfo(const QString &name, int permissions, const QString &owner,
const QString &group, qint64 size, const QDateTime &lastModified,
const QDateTime &lastRead, bool isDir, bool isFile, bool isSymLink,
bool isWritable, bool isReadable, bool isExecutable);
QUrlInfo(const QUrl &url, int permissions, const QString &owner,
const QString &group, qint64 size, const QDateTime &lastModified,
const QDateTime &lastRead, bool isDir, bool isFile, bool isSymLink,
bool isWritable, bool isReadable, bool isExecutable);
QUrlInfo &operator=(const QUrlInfo &ui);
virtual ~QUrlInfo();
virtual void setName(const QString &name);
virtual void setDir(bool b);
virtual void setFile(bool b);
virtual void setSymLink(bool b);
virtual void setOwner(const QString &s);
virtual void setGroup(const QString &s);
virtual void setSize(qint64 size);
virtual void setWritable(bool b);
virtual void setReadable(bool b);
virtual void setPermissions(int p);
virtual void setLastModified(const QDateTime &dt);
void setLastRead(const QDateTime &dt);
bool isValid() const;
QString name() const;
int permissions() const;
QString owner() const;
QString group() const;
qint64 size() const;
QDateTime lastModified() const;
QDateTime lastRead() const;
bool isDir() const;
bool isFile() const;
bool isSymLink() const;
bool isWritable() const;
bool isReadable() const;
bool isExecutable() const;
static bool greaterThan(const QUrlInfo &i1, const QUrlInfo &i2,
int sortBy);
static bool lessThan(const QUrlInfo &i1, const QUrlInfo &i2,
int sortBy);
static bool equal(const QUrlInfo &i1, const QUrlInfo &i2,
int sortBy);
bool operator==(const QUrlInfo &i) const;
inline bool operator!=(const QUrlInfo &i) const
{ return !operator==(i); }
private:
QUrlInfoPrivate *d;
};
QT_END_NAMESPACE
#endif // QURLINFO_H
Loading…
Cancel
Save