added version to project file, added some files to begin with

implementing a CLI, some minor improvements
This commit is contained in:
Martchus 2015-06-24 00:54:58 +02:00
parent 93dbfa151d
commit 2def67a430
12 changed files with 257 additions and 36 deletions

View File

@ -1,49 +1,52 @@
#include "gui/mainwindow.h"
#include "gui/settings.h"
#include "cli/mainfeatures.h"
#include "gui/initiate.h"
#if defined(GUI_QTWIDGETS) || defined(GUI_QTQUICK)
# include <qtutilities/resources/qtconfigarguments.h>
#else
# include <c++utilities/application/fakeqtconfigarguments.h>
#endif
#include <qtutilities/resources/resources.h>
#if defined(GUI_QTWIDGETS)
# include <QApplication>
#elif defined(GUI_QTQUICK)
# include <QGuiApplication>
#endif
#include <c++utilities/application/failure.h>
#include <QCoreApplication>
#include <iostream>
#include "main.h"
using namespace std;
using namespace std::placeholders;
using namespace ApplicationUtilities;
int main(int argc, char *argv[])
{
// setup argument parser
ArgumentParser parser;
QT_CONFIG_ARGUMENTS qtConfigArgs;
HelpArgument helpArg(parser);
parser.setMainArguments({&qtConfigArgs.qtWidgetsGuiArg(), &helpArg});
parser.parseArgs(argc, argv);
Argument noConfirmArg("no-confirm", "n", "start downloading without confirmation");
noConfirmArg.setCombinable(true);
Argument downloadArg("download", "d", "downloads the specified data");
downloadArg.setValueNames({"URL1", "URL2", "URL3"});
downloadArg.setRequiredValueCount(-1);
downloadArg.setDenotesOperation(true);
downloadArg.setSecondaryArguments({&noConfirmArg});
downloadArg.setCallback(bind(Cli::download, argc, argv, _1, cref(noConfirmArg)));
parser.setMainArguments({&qtConfigArgs.qtWidgetsGuiArg(), &downloadArg, &helpArg});
// parse arguments
try {
parser.parseArgs(argc, argv);
} catch (Failure &ex) {
cout << "Unable to parse arguments. " << ex.what() << "\nSee --help for available commands." << endl;
}
// set meta info for application
QCoreApplication::setOrganizationName(QStringLiteral("Martchus"));
QCoreApplication::setOrganizationDomain(QStringLiteral("http://martchus.netai.net/"));
QCoreApplication::setApplicationName(QStringLiteral("Video Downloader"));
QCoreApplication::setApplicationVersion(QStringLiteral("1.0.7"));
if(qtConfigArgs.areQtGuiArgsPresent()) {
#ifdef GUI_QTWIDGETS
QGuiApplication::setOrganizationName(QStringLiteral("Martchus"));
QGuiApplication::setOrganizationDomain(QStringLiteral("http://martchus.netai.net/"));
QGuiApplication::setApplicationName(QStringLiteral("Video Downloader"));
QGuiApplication::setApplicationVersion(QStringLiteral("1.0.7"));
QApplication a(argc, argv);
QtUtilitiesResources::init();
Theme::setup();
QtGui::restoreSettings();
QtGui::MainWindow w;
w.show();
int r = a.exec();
QtGui::saveSettings();
return r;
#else
cout << "Application has not been build with Qt widgets GUI support." << endl;
#endif
return QtGui::runWidgetsGui(argc, argv);
}
return 0;
}

6
application/main.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef MAIN_H
#define MAIN_H
int main(int argc, char *argv[]);
#endif // MAIN_H

View File

@ -0,0 +1,79 @@
#include "clidownloadinteraction.h"
#include "network/download.h"
#include "network/permissionstatus.h"
#include <c++utilities/application/commandlineutils.h>
#include <iostream>
using namespace std;
using namespace Network;
using namespace ApplicationUtilities;
namespace Cli {
CliDownloadInteraction::CliDownloadInteraction(QObject *parent) :
QObject(parent)
{}
void CliDownloadInteraction::connectDownload(Download *download)
{
connect(download, &Download::outputDeviceRequired, this, static_cast<void (CliDownloadInteraction::*) (Download *, size_t)>(&CliDownloadInteraction::downloadRequiresOutputDevice), Qt::QueuedConnection);
connect(download, &Download::overwriteingPermissionRequired, this, &CliDownloadInteraction::downloadRequriesOverwritePermission, Qt::QueuedConnection);
connect(download, &Download::appendingPermissionRequired, this, &CliDownloadInteraction::downloadRequriesAppendingPermission, Qt::QueuedConnection);
connect(download, &Download::redirectionPermissonRequired, this, &CliDownloadInteraction::downloadRequiresRedirectionPermission, Qt::QueuedConnection);
connect(download, &Download::authenticationRequired, this, &CliDownloadInteraction::downloadRequiresAuthentication, Qt::QueuedConnection);
connect(download, &Download::sslErrors, this, &CliDownloadInteraction::downloadHasSslErrors, Qt::QueuedConnection);
}
void CliDownloadInteraction::disconnectDownload(Download *download)
{
download->disconnect(this);
}
void CliDownloadInteraction::downloadRequiresOutputDevice(Download *download, size_t optionIndex)
{
downloadRequiresOutputDevice(download, optionIndex, false);
}
void CliDownloadInteraction::downloadRequiresOutputDevice(Download *download, size_t optionIndex, bool forceFileDialog)
{
// TODO
}
void CliDownloadInteraction::downloadRequriesOverwritePermission(Download *download, size_t optionIndex, const QString &file)
{
// TODO
}
void CliDownloadInteraction::downloadRequriesAppendingPermission(Download *download, size_t optionIndex, const QString &file, quint64 offset, quint64 fileSize)
{
// TODO
}
void CliDownloadInteraction::downloadRequiresRedirectionPermission(Download *download, size_t optionIndex)
{
// TODO
}
void CliDownloadInteraction::downloadRequiresAuthentication(Download *download, size_t optionIndex, const QString &realm)
{
// TODO
}
void CliDownloadInteraction::downloadHasSslErrors(Download *download, size_t optionIndex, const QList<QSslError> &sslErrors)
{
// TODO
const string downloadName = (download->downloadUrl().isEmpty() ? download->id() : download->downloadUrl().toString()).toStdString();
cout << "The download \"" << downloadName << "\" has SSL errors:" << endl;
foreach(const QSslError &error, sslErrors) {
cout << "- " << error.errorString().toStdString() << ":" << endl;
cout << " " << error.certificate().toText().toStdString() << endl;
}
if(confirmPrompt("Do you want to ignore the SSL errors for this download?")) {
// TODO
}
}
}

View File

@ -0,0 +1,40 @@
#ifndef CLI_DOWNLOADINTERACTION_H
#define CLI_DOWNLOADINTERACTION_H
#include <QObject>
#include <QSslError>
QT_BEGIN_NAMESPACE
class QString;
QT_END_NAMESPACE
namespace Network {
class Download;
}
namespace Cli {
class CliDownloadInteraction : public QObject
{
Q_OBJECT
public:
explicit CliDownloadInteraction(QObject *parent = nullptr);
public slots:
void connectDownload(Network::Download *download);
void disconnectDownload(Network::Download *download);
private slots:
void downloadRequiresOutputDevice(Network::Download *download, size_t optionIndex);
void downloadRequiresOutputDevice(Network::Download *download, size_t optionIndex, bool forceFileDialog);
void downloadRequriesOverwritePermission(Network::Download *download, size_t optionIndex, const QString &file);
void downloadRequriesAppendingPermission(Network::Download *download, size_t optionIndex, const QString &file, quint64 offset, quint64 fileSize);
void downloadRequiresRedirectionPermission(Network::Download *download, size_t optionIndex);
void downloadRequiresAuthentication(Network::Download *download, size_t optionIndex, const QString &realm);
void downloadHasSslErrors(Network::Download *download, size_t optionIndex, const QList<QSslError> &sslErrors);
};
}
#endif // CLI_DOWNLOADINTERACTION_H

11
cli/mainfeatures.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "mainfeatures.h"
namespace Cli {
mainfeatures::mainfeatures()
{
}
} // namespace Cli

20
cli/mainfeatures.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef CLI_MAINFEATURES_H
#define CLI_MAINFEATURES_H
#include <vector>
#include <string>
namespace ApplicationUtilities {
typedef std::vector<std::string> StringVector;
class Argument;
}
namespace Cli {
void download(int argc, char *argv[], const ApplicationUtilities::StringVector &parameterValues, const ApplicationUtilities::Argument &noConfirmArg);
}
#endif // CLI_MAINFEATURES_H

View File

@ -12,7 +12,17 @@ unix {
QMAKE_LFLAGS += "-Wl,--rpath=./"
}
# prefix
targetprefix = .
targetprefix = $$(TARGET_PREFIX)
equals(targetprefix, "") {
win32 {
targetprefix = ../../..
} else {
targetprefix = ../..
}
}
message("Using target prefix \"$${targetprefix}\".")
# print install root
message("Using install root \"$$(INSTALL_ROOT)\".")
# target
CONFIG(debug, debug|release) {
TARGET = $$targetprefix/$${projectname}d

View File

@ -7,7 +7,6 @@
QT_BEGIN_NAMESPACE
class QWidget;
class QString;
//class QSslError;
QT_END_NAMESPACE
namespace Network {

35
gui/initiate.cpp Normal file
View File

@ -0,0 +1,35 @@
#include "initiate.h"
#include "settings.h"
#include "mainwindow.h"
#include <qtutilities/resources/resources.h>
#if defined(GUI_QTWIDGETS)
# include <QApplication>
#elif defined(GUI_QTQUICK)
# include <QGuiApplication>
#endif
using namespace std;
namespace QtGui {
int runWidgetsGui(int argc, char *argv[])
{
#ifdef GUI_QTWIDGETS
QApplication a(argc, argv);
QtUtilitiesResources::init();
Theme::setup();
QtGui::restoreSettings();
QtGui::MainWindow w;
w.show();
int r = a.exec();
QtGui::saveSettings();
return r;
#else
cout << "Application has not been build with Qt widgets GUI support." << endl;
return 0;
#endif
}
}

10
gui/initiate.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef QTGUI_INIT_H
#define QTGUI_INIT_H
namespace QtGui {
int runWidgetsGui(int argc, char *argv[]);
}
#endif // QTGUI_INIT_H

View File

@ -137,7 +137,7 @@ void HttpDownload::checkStatusAndClear(size_t optionIndex)
reportDownloadInterrupted(optionIndex);
reply->deleteLater();
m_replies.removeAll(reply);
} else if((error == QNetworkReply::AuthenticationRequiredError)) {
} else if(error == QNetworkReply::AuthenticationRequiredError) {
// authentication is required
reportAuthenticationRequired(optionIndex, m_realm);
reply->deleteLater();

View File

@ -1,4 +1,5 @@
projectname = videodownloader
VERSION = 1.0.7
# include ../../common.pri when building as part of a subdirs project; otherwise include general.pri
!include(../../common.pri) {
@ -51,7 +52,10 @@ SOURCES += application/main.cpp \
itemdelegates/progressbaritemdelegate.cpp \
gui/downloadinteraction.cpp \
gui/settings.cpp \
network/optiondata.cpp
network/optiondata.cpp \
gui/initiate.cpp \
cli/mainfeatures.cpp \
cli/clidownloadinteraction.cpp
HEADERS += application/main.h \
network/bitsharedownload.h \
@ -83,7 +87,11 @@ HEADERS += application/main.h \
gui/settings.h \
network/authenticationcredentials.h \
network/permissionstatus.h \
network/optiondata.h
network/optiondata.h \
application/main.h \
gui/initiate.h \
cli/mainfeatures.h \
cli/clidownloadinteraction.h
testdownload {
SOURCES += network/testdownload.cpp
@ -127,14 +135,14 @@ INCLUDEPATH += ../
target.path = $$(INSTALL_ROOT)/bin
INSTALLS += target
icon.path = $$(INSTALL_ROOT)/share/icons/hicolor/scalable/apps/
icon.files = ./resources/icons/hicolor/scalable/apps/$${projectname}.svg
icon.files = $${PWD}/resources/icons/hicolor/scalable/apps/$${projectname}.svg
INSTALLS += icon
menu.path = $$(INSTALL_ROOT)/share/applications/
menu.files = ./resources/desktop/applications/$${projectname}.desktop
menu.files = $${PWD}/resources/desktop/applications/$${projectname}.desktop
INSTALLS += menu
translations.path = $$(INSTALL_ROOT)/share/$${projectname}/translations/
translations.files = ./translations/*.qm
translations.files = $${PWD}/translations/*.qm
INSTALLS += translations
json.path = $$(INSTALL_ROOT)/share/$${projectname}/json/
json.files = ./resources/json/groovesharkauthenticationinfo.json
json.files = $${PWD}/resources/json/groovesharkauthenticationinfo.json
INSTALLS += json