|
@@ -0,0 +1,95 @@
|
|
|
+#include "widget.h"
|
|
|
+#include "./ui_widget.h"
|
|
|
+
|
|
|
+#include <QNetworkReply>
|
|
|
+#include <QNetworkAccessManager>
|
|
|
+#include <QNetworkRequest>
|
|
|
+#include <QTimer>
|
|
|
+#include <QNetworkProxy>
|
|
|
+#include <regex>
|
|
|
+#include <stdlib.h>
|
|
|
+#include "QtFtp.h"
|
|
|
+
|
|
|
+#include "spdlog/spdlog.h"
|
|
|
+#include "fmtlog.h"
|
|
|
+
|
|
|
+
|
|
|
+Widget::Widget(QWidget *parent)
|
|
|
+ : QWidget(parent)
|
|
|
+ , ui(new Ui::Widget)
|
|
|
+{
|
|
|
+ ui->setupUi(this);
|
|
|
+
|
|
|
+ m_curlFtp.setFtpIPAndPort("192.168.50.100", "21");
|
|
|
+ m_curlFtp.setFtpUsernameAndPassword("microsoft", "19980714Lq");
|
|
|
+
|
|
|
+ SPDLOG_INFO("***** Qt Library *****");
|
|
|
+}
|
|
|
+
|
|
|
+Widget::~Widget()
|
|
|
+{
|
|
|
+
|
|
|
+ delete ui;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void Widget::on_pBtn_connect_clicked()
|
|
|
+{
|
|
|
+ SPDLOG_INFO("点击了“连接按钮”");
|
|
|
+ QString url = "ftp://192.168.50.100/SSD1/Picture/";
|
|
|
+ QString username = "microsoft";
|
|
|
+ QString password = "19980714Lq";
|
|
|
+
|
|
|
+ std::vector<std::string> list;
|
|
|
+ CurlFtp::listFiles(url.toStdString(), username.toStdString(), password.toStdString(), list);
|
|
|
+
|
|
|
+ for(const std::string& filename : list)
|
|
|
+ {
|
|
|
+ SPDLOG_INFO("{}", filename);
|
|
|
+ }
|
|
|
+
|
|
|
+ FMTLOG_INFO("***** Curl Library *****");
|
|
|
+ FMTLOG_INFO("{}","你好");
|
|
|
+}
|
|
|
+
|
|
|
+/* 使用Windows API进行编码转换 */
|
|
|
+char* G2U(const char* gb2312)
|
|
|
+{
|
|
|
+ int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0);
|
|
|
+ wchar_t* wstr = new wchar_t[len+1];
|
|
|
+ memset(wstr, 0, len+1);
|
|
|
+ MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len);
|
|
|
+ len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
|
|
|
+ char* str = new char[len+1];
|
|
|
+ memset(str, 0, len+1);
|
|
|
+ WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);
|
|
|
+ if(wstr) delete[] wstr;
|
|
|
+ return str;
|
|
|
+}
|
|
|
+
|
|
|
+void Widget::on_pBtn_downloadFile_clicked()
|
|
|
+{
|
|
|
+ SPDLOG_INFO("点击了“下载文件”");
|
|
|
+ std::vector<std::string> fileList;
|
|
|
+ m_curlFtp.getFileList("/SSD1/Picture/", fileList);
|
|
|
+}
|
|
|
+
|
|
|
+void Widget::on_pBtn_downloadVideo_clicked()
|
|
|
+{
|
|
|
+ SPDLOG_INFO("点击了“下载视频”");
|
|
|
+ std::shared_ptr<QtFtp> ftp = std::make_shared<QtFtp>();
|
|
|
+ ftp->setHostAndPort("192.168.50.100");
|
|
|
+ ftp->setUserPasswd("microsoft", "19980714Lq");
|
|
|
+ QString localPath = QApplication::applicationDirPath() + "/v1.mp4";
|
|
|
+ ftp->getFile(localPath, "/SSD1/Video/v1.mp4");
|
|
|
+ ftp->waitFinished(-1);
|
|
|
+ if(ftp->getResult())
|
|
|
+ {
|
|
|
+ SPDLOG_INFO("下载成功");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ SPDLOG_INFO("下载失败");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|