mirror of
https://github.com/lostjared/Acid.Cam.v2.Qt.git
synced 2025-12-15 11:20:01 +01:00
working on adding check
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
TARGET = Acid_Cam_v2_Qt
|
TARGET = Acid_Cam_v2_Qt
|
||||||
QT += core gui widgets
|
QT += core gui widgets network
|
||||||
DEPENDPATH += .
|
DEPENDPATH += .
|
||||||
INCLUDEPATH += . /usr/include/ /usr/local/include
|
INCLUDEPATH += . /usr/include/ /usr/local/include
|
||||||
LIBS += `pkg-config acidcam opencv --libs`
|
LIBS += `pkg-config acidcam opencv --libs`
|
||||||
@@ -14,5 +14,5 @@ QMAKE_CXXFLAGS += -std=c++11 `pkg-config acidcam opencv --cflags`
|
|||||||
RESOURCES += qresource.qrc
|
RESOURCES += qresource.qrc
|
||||||
|
|
||||||
# Input
|
# Input
|
||||||
HEADERS += main_window.h new_dialog.h plugin.h qtheaders.h select_image.h display_window.h playback_thread.h search_box.h goto_window.h chroma_window.h user_define.h
|
HEADERS += main_window.h new_dialog.h plugin.h qtheaders.h select_image.h display_window.h playback_thread.h search_box.h goto_window.h chroma_window.h user_define.h dl-man.h
|
||||||
SOURCES += main.cpp main_window.cpp new_dialog.cpp plugin.cpp select_image.cpp display_window.cpp playback_thread.cpp search_box.cpp goto_window.cpp chroma_window.cpp user_define.cpp
|
SOURCES += main.cpp main_window.cpp new_dialog.cpp plugin.cpp select_image.cpp display_window.cpp playback_thread.cpp search_box.cpp goto_window.cpp chroma_window.cpp user_define.cpp dl-man.cpp
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
TARGET = Acid_Cam_v2_Qt
|
TARGET = Acid_Cam_v2_Qt
|
||||||
QT += core gui widgets
|
QT += core gui widgets network
|
||||||
DEPENDPATH += .
|
DEPENDPATH += .
|
||||||
INCLUDEPATH += . /usr/include/ /usr/local/include
|
INCLUDEPATH += . /usr/include/ /usr/local/include
|
||||||
LIBS += `pkg-config acidcam opencv4 --libs`
|
LIBS += `pkg-config acidcam opencv4 --libs`
|
||||||
@@ -14,5 +14,5 @@ QMAKE_CXXFLAGS += -std=c++11 `pkg-config acidcam opencv4 --cflags`
|
|||||||
RESOURCES += qresource.qrc
|
RESOURCES += qresource.qrc
|
||||||
|
|
||||||
# Input
|
# Input
|
||||||
HEADERS += main_window.h new_dialog.h plugin.h qtheaders.h select_image.h display_window.h playback_thread.h search_box.h goto_window.h chroma_window.h user_define.h
|
HEADERS += main_window.h new_dialog.h plugin.h qtheaders.h select_image.h display_window.h playback_thread.h search_box.h goto_window.h chroma_window.h user_define.h dl-man.h
|
||||||
SOURCES += main.cpp main_window.cpp new_dialog.cpp plugin.cpp select_image.cpp display_window.cpp playback_thread.cpp search_box.cpp goto_window.cpp chroma_window.cpp user_define.cpp
|
SOURCES += main.cpp main_window.cpp new_dialog.cpp plugin.cpp select_image.cpp display_window.cpp playback_thread.cpp search_box.cpp goto_window.cpp chroma_window.cpp user_define.cpp dl-man.cpp
|
||||||
|
|||||||
116
src/dl-man.cpp
Normal file
116
src/dl-man.cpp
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
|
||||||
|
// From Qt5 Examples/Docs
|
||||||
|
|
||||||
|
#include"dl-man.h"
|
||||||
|
|
||||||
|
DownloadManager::DownloadManager()
|
||||||
|
{
|
||||||
|
connect(&manager, SIGNAL(finished(QNetworkReply*)),
|
||||||
|
SLOT(downloadFinished(QNetworkReply*)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadManager::doDownload(const QUrl &url)
|
||||||
|
{
|
||||||
|
QNetworkRequest request(url);
|
||||||
|
QNetworkReply *reply = manager.get(request);
|
||||||
|
|
||||||
|
#if QT_CONFIG(ssl)
|
||||||
|
connect(reply, SIGNAL(sslErrors(QList<QSslError>)),
|
||||||
|
SLOT(sslErrors(QList<QSslError>)));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
currentDownloads.append(reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DownloadManager::saveFileName(const QUrl &url)
|
||||||
|
{
|
||||||
|
QString path = url.path();
|
||||||
|
QString basename = QFileInfo(path).fileName();
|
||||||
|
|
||||||
|
if (basename.isEmpty())
|
||||||
|
basename = "download";
|
||||||
|
|
||||||
|
if (QFile::exists(basename)) {
|
||||||
|
// already exists, don't overwrite
|
||||||
|
int i = 0;
|
||||||
|
basename += '.';
|
||||||
|
while (QFile::exists(basename + QString::number(i)))
|
||||||
|
++i;
|
||||||
|
|
||||||
|
basename += QString::number(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return basename;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DownloadManager::saveToDisk(const QString &filename, QIODevice *data)
|
||||||
|
{
|
||||||
|
QFile file(filename);
|
||||||
|
if (!file.open(QIODevice::WriteOnly)) {
|
||||||
|
fprintf(stderr, "Could not open %s for writing: %s\n",
|
||||||
|
qPrintable(filename),
|
||||||
|
qPrintable(file.errorString()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
file.write(data->readAll());
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DownloadManager::isHttpRedirect(QNetworkReply *reply)
|
||||||
|
{
|
||||||
|
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
|
return statusCode == 301 || statusCode == 302 || statusCode == 303
|
||||||
|
|| statusCode == 305 || statusCode == 307 || statusCode == 308;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadManager::execute()
|
||||||
|
{
|
||||||
|
QStringList args = QCoreApplication::instance()->arguments();
|
||||||
|
args.takeFirst(); // skip the first argument, which is the program's name
|
||||||
|
if (args.isEmpty()) {
|
||||||
|
QCoreApplication::instance()->quit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const QString &arg : qAsConst(args)) {
|
||||||
|
QUrl url = QUrl::fromEncoded(arg.toLocal8Bit());
|
||||||
|
doDownload(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadManager::sslErrors(const QList<QSslError> &sslErrors)
|
||||||
|
{
|
||||||
|
#if QT_CONFIG(ssl)
|
||||||
|
for (const QSslError &error : sslErrors)
|
||||||
|
fprintf(stderr, "SSL error: %s\n", qPrintable(error.errorString()));
|
||||||
|
#else
|
||||||
|
Q_UNUSED(sslErrors);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadManager::downloadFinished(QNetworkReply *reply)
|
||||||
|
{
|
||||||
|
QUrl url = reply->url();
|
||||||
|
if (reply->error()) {
|
||||||
|
fprintf(stderr, "Download of %s failed: %s\n",
|
||||||
|
url.toEncoded().constData(),
|
||||||
|
qPrintable(reply->errorString()));
|
||||||
|
} else {
|
||||||
|
if (isHttpRedirect(reply)) {
|
||||||
|
fputs("Request was redirected.\n", stderr);
|
||||||
|
} else {
|
||||||
|
QString filename = saveFileName(url);
|
||||||
|
if (saveToDisk(filename, reply)) {
|
||||||
|
printf("Download of %s succeeded (saved to %s)\n",
|
||||||
|
url.toEncoded().constData(), qPrintable(filename));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentDownloads.removeAll(reply);
|
||||||
|
reply->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
32
src/dl-man.h
Normal file
32
src/dl-man.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
//This class is from QT examples/docs
|
||||||
|
#ifndef __DL_MAIN__H___
|
||||||
|
#define __DL_MAIN__H___
|
||||||
|
|
||||||
|
#include <QtCore>
|
||||||
|
#include <QtNetwork>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
class QSslError;
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class DownloadManager: public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
QNetworkAccessManager manager;
|
||||||
|
QVector<QNetworkReply *> currentDownloads;
|
||||||
|
|
||||||
|
public:
|
||||||
|
DownloadManager();
|
||||||
|
void doDownload(const QUrl &url);
|
||||||
|
static QString saveFileName(const QUrl &url);
|
||||||
|
bool saveToDisk(const QString &filename, QIODevice *data);
|
||||||
|
static bool isHttpRedirect(QNetworkReply *reply);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void execute();
|
||||||
|
void downloadFinished(QNetworkReply *reply);
|
||||||
|
void sslErrors(const QList<QSslError> &errors);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -111,6 +111,10 @@ AC_MainWindow::AC_MainWindow(QWidget *parent) : QMainWindow(parent) {
|
|||||||
define_window = new DefineWindow(this);
|
define_window = new DefineWindow(this);
|
||||||
define_window->hide();
|
define_window->hide();
|
||||||
define_window->main_window = this;
|
define_window->main_window = this;
|
||||||
|
|
||||||
|
QString arg = "http://lostsidedead.com/ac/version.txt";
|
||||||
|
QUrl url = QUrl::fromEncoded(arg.toLocal8Bit());
|
||||||
|
dl.doDownload(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -155,9 +159,9 @@ void AC_MainWindow::createControls() {
|
|||||||
|
|
||||||
|
|
||||||
filter_single = new QRadioButton(tr("Single Filter"), this);
|
filter_single = new QRadioButton(tr("Single Filter"), this);
|
||||||
filter_single->setGeometry(30, 40, 100, 15);
|
filter_single->setGeometry(30, 40, 200, 15);
|
||||||
filter_custom = new QRadioButton(tr("Custom Filter"), this);
|
filter_custom = new QRadioButton(tr("Custom Filter"), this);
|
||||||
filter_custom->setGeometry(30, 65, 100, 15);
|
filter_custom->setGeometry(30, 65, 200, 15);
|
||||||
|
|
||||||
filter_single->setChecked(true);
|
filter_single->setChecked(true);
|
||||||
|
|
||||||
@@ -172,12 +176,12 @@ void AC_MainWindow::createControls() {
|
|||||||
btn_clr = new QPushButton(tr("Clear Sub"), this);
|
btn_clr = new QPushButton(tr("Clear Sub"), this);
|
||||||
btn_load = new QPushButton(tr("Load"), this);
|
btn_load = new QPushButton(tr("Load"), this);
|
||||||
btn_save = new QPushButton(tr("Save"), this);
|
btn_save = new QPushButton(tr("Save"), this);
|
||||||
btn_add->setGeometry(10, 215, 100, 20);
|
btn_add->setGeometry(10, 215, 100, 25);
|
||||||
btn_remove->setGeometry(400, 215, 60, 20);
|
btn_remove->setGeometry(390, 215, 80, 25);
|
||||||
btn_moveup->setGeometry(465, 215, 60, 20);
|
btn_moveup->setGeometry(460, 215, 80, 25);
|
||||||
btn_movedown->setGeometry(530, 215, 60, 20);
|
btn_movedown->setGeometry(530, 215, 80, 25);
|
||||||
btn_load->setGeometry(655+20, 215, 55, 20);
|
btn_load->setGeometry(655+20, 215, 60, 25);
|
||||||
btn_save->setGeometry(655+60+20, 215, 55, 20);
|
btn_save->setGeometry(655+60+20, 215, 60, 25);
|
||||||
btn_sub->setGeometry(10, 165, 100, 20);
|
btn_sub->setGeometry(10, 165, 100, 20);
|
||||||
btn_clr->setGeometry(115, 165, 100, 20);
|
btn_clr->setGeometry(115, 165, 100, 20);
|
||||||
connect(btn_add, SIGNAL(clicked()), this, SLOT(addClicked()));
|
connect(btn_add, SIGNAL(clicked()), this, SLOT(addClicked()));
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
#include "goto_window.h"
|
#include "goto_window.h"
|
||||||
#include "chroma_window.h"
|
#include "chroma_window.h"
|
||||||
#include "user_define.h"
|
#include "user_define.h"
|
||||||
|
#include "dl-man.h"
|
||||||
|
|
||||||
class SearchWindow;
|
class SearchWindow;
|
||||||
|
|
||||||
@@ -141,6 +141,7 @@ private:
|
|||||||
bool loading;
|
bool loading;
|
||||||
int speed_index;
|
int speed_index;
|
||||||
cv::ocl::Context context;
|
cv::ocl::Context context;
|
||||||
|
DownloadManager dl;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const char *filer_names[];
|
extern const char *filer_names[];
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#ifndef _QT_HEADERS__
|
#ifndef _QT_HEADERS__
|
||||||
#define _QT_HEADERS__
|
#define _QT_HEADERS__
|
||||||
#define ac_version "v1.39.0"
|
#define ac_version "v1.40.0"
|
||||||
#include<QApplication>
|
#include<QApplication>
|
||||||
#include<QMainWindow>
|
#include<QMainWindow>
|
||||||
#include<QDialog>
|
#include<QDialog>
|
||||||
|
|||||||
Reference in New Issue
Block a user