outsourced routings to locate additional config files
This commit is contained in:
parent
d5b880a22a
commit
2a7e8f14ed
|
@ -3,6 +3,7 @@
|
|||
#include "../network/download.h"
|
||||
#include "../network/groovesharkdownload.h"
|
||||
|
||||
#include <qtutilities/resources/resources.h>
|
||||
#include <qtutilities/settingsdialog/optioncategory.h>
|
||||
#include <qtutilities/settingsdialog/optioncategorymodel.h>
|
||||
#include <qtutilities/widgets/clearlineedit.h>
|
||||
|
@ -464,32 +465,15 @@ void restoreSettings()
|
|||
GeneralUiOptionPage::multiSelection() = settings.value("multiselection").toBool();
|
||||
|
||||
// load grooveshark authentication file
|
||||
QString groovesharkAuthenticationFile = QStringLiteral("groovesharkauthenticationinfo.json");
|
||||
QString errorMsg = QApplication::translate("QtGui::Settings", "Unable to read Grooveshark authentication information file.\n\nReason: %1\n\nThe values stored in this file are required when connection to Grooveshark. Built-in will values be used instead, but these might be deprecated.");
|
||||
const auto errorMsg = QApplication::translate("QtGui::Settings", "Unable to read Grooveshark authentication information file.\n\nReason: %1\n\nThe values stored in this file are required when connection to Grooveshark. Built-in will values be used instead, but these might be deprecated.");
|
||||
const auto groovesharkAuthenticationFile = ConfigFile::locateConfigFile(QStringLiteral("videodownloader"), QStringLiteral("json/groovesharkauthenticationinfo.json"), &settings);
|
||||
QString reason;
|
||||
if(!QFile::exists(groovesharkAuthenticationFile)) {
|
||||
groovesharkAuthenticationFile = QStringLiteral("./res/groovesharkauthenticationinfo.json");
|
||||
if(!QFile::exists(groovesharkAuthenticationFile)) {
|
||||
groovesharkAuthenticationFile = QStringLiteral("/etc/videodownloader/json/groovesharkauthenticationinfo.json");
|
||||
if(!QFile::exists(groovesharkAuthenticationFile)) {
|
||||
groovesharkAuthenticationFile = QStringLiteral("/usr/share/videodownloader/json/groovesharkauthenticationinfo.json");
|
||||
}
|
||||
}
|
||||
}
|
||||
if(QFile::exists(groovesharkAuthenticationFile)) {
|
||||
if(!groovesharkAuthenticationFile.isEmpty()) {
|
||||
if(!GroovesharkDownload::loadAuthenticationInformationFromFile(groovesharkAuthenticationFile, &reason)) {
|
||||
QMessageBox::warning(nullptr, QApplication::applicationName(), errorMsg.arg(errorMsg));
|
||||
QMessageBox::warning(nullptr, QApplication::applicationName(), errorMsg.arg(reason));
|
||||
}
|
||||
} else {
|
||||
QDir settingsDir = QFileInfo(settings.fileName()).absoluteDir();
|
||||
QString groovesharkAuthenticationFilePath = settingsDir.absoluteFilePath(groovesharkAuthenticationFile);
|
||||
if(QFile::exists(groovesharkAuthenticationFilePath)) {
|
||||
if(!GroovesharkDownload::loadAuthenticationInformationFromFile(groovesharkAuthenticationFilePath, &reason)) {
|
||||
QMessageBox::warning(nullptr, QApplication::applicationName(), errorMsg.arg(reason));
|
||||
}
|
||||
} else {
|
||||
QMessageBox::warning(nullptr, QApplication::applicationName(), errorMsg.arg(QApplication::translate("QtGui::Settings", "Unable to find \"groovesharkauthenticationinfo.json\".")));
|
||||
}
|
||||
QMessageBox::warning(nullptr, QApplication::applicationName(), errorMsg.arg(QApplication::translate("QtGui::Settings", "Unable to find \"groovesharkauthenticationinfo.json\".")));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,8 +41,10 @@ public:
|
|||
static QString &targetDirectory();
|
||||
static bool &overwriteWithoutAsking();
|
||||
static bool &determineTargetFileWithoutAsking();
|
||||
|
||||
protected:
|
||||
QWidget *setupWidget();
|
||||
|
||||
private:
|
||||
void selectTargetDirectory();
|
||||
};
|
||||
|
@ -59,8 +61,10 @@ public:
|
|||
static QByteArray &mainWindowGeometry();
|
||||
static QByteArray &mainWindowState();
|
||||
static bool &multiSelection();
|
||||
|
||||
protected:
|
||||
QWidget *setupWidget();
|
||||
|
||||
private:
|
||||
QCheckBox *m_multiSelectionCheckBox;
|
||||
};
|
||||
|
@ -75,8 +79,10 @@ public:
|
|||
bool apply();
|
||||
void reset();
|
||||
static QNetworkProxy &proxy();
|
||||
|
||||
protected:
|
||||
QWidget *setupWidget();
|
||||
|
||||
private:
|
||||
void updateProxy();
|
||||
};
|
||||
|
@ -104,8 +110,10 @@ public:
|
|||
bool apply();
|
||||
void reset();
|
||||
static bool &redirectWithoutAsking();
|
||||
|
||||
protected:
|
||||
QWidget *setupWidget();
|
||||
|
||||
private:
|
||||
QCheckBox *m_redirectCheckBox;
|
||||
};
|
||||
|
@ -120,8 +128,10 @@ public:
|
|||
bool apply();
|
||||
void reset();
|
||||
static quint64 &bytesReceived();
|
||||
|
||||
protected:
|
||||
QWidget *setupWidget();
|
||||
|
||||
private:
|
||||
QLabel *m_receivedLabel;
|
||||
};
|
||||
|
|
|
@ -460,7 +460,7 @@ void GroovesharkDownload::setupFinalRequest()
|
|||
setHeader("Refer", m_referer);
|
||||
setHeader("Accept", m_accept);
|
||||
//setHeader("Connection", "keep-alive");
|
||||
addDownloadUrl(tr("Grooveshark json request"), QUrl(QStringLiteral("http://grooveshark.com/more.php?%1").arg(method)));
|
||||
addDownloadUrl(tr("Grooveshark json request"), QUrl(QStringLiteral("http://grooveshark.com/more.php?") + method));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "../application/utils.h"
|
||||
|
||||
#include <qtutilities/resources/resources.h>
|
||||
|
||||
#include <QUrlQuery>
|
||||
#include <QJsonDocument>
|
||||
|
||||
|
@ -55,7 +57,12 @@ Download *YoutubeDownload::infoRequestDownload(bool &sucess, QString &reasonForF
|
|||
void YoutubeDownload::evalVideoInformation(Download *, QBuffer *videoInfoBuffer)
|
||||
{
|
||||
if(m_itagInfo.isEmpty()) {
|
||||
m_itagInfo = loadJsonObjectFromResource(QStringLiteral(":/jsonobjects/itaginfo"));
|
||||
// allow an external config file to be used instead of built-in values
|
||||
QString path = ConfigFile::locateConfigFile(QStringLiteral("videodownloader"), QStringLiteral("itaginfo.json"));
|
||||
if(path.isEmpty()) {
|
||||
path = QStringLiteral(":/jsonobjects/itaginfo");
|
||||
}
|
||||
m_itagInfo = loadJsonObjectFromResource(path);
|
||||
}
|
||||
videoInfoBuffer->seek(0);
|
||||
QString videoInfo(videoInfoBuffer->readAll());
|
||||
|
@ -166,17 +173,21 @@ QString YoutubeDownload::videoInfo(QString field, const QString &defaultValue)
|
|||
|
||||
QString YoutubeDownload::suitableFilename() const
|
||||
{
|
||||
QString filename = Download::suitableFilename();
|
||||
auto filename = Download::suitableFilename();
|
||||
// get chosen option, the original option (not the redirection!) is required
|
||||
size_t originalOption = chosenOption();
|
||||
auto originalOption = chosenOption();
|
||||
while(originalOption != options().at(originalOption).redirectionOf()) {
|
||||
originalOption = options().at(originalOption).redirectionOf();
|
||||
}
|
||||
QString extension;
|
||||
if(originalOption < static_cast<size_t>(m_itags.size())) {
|
||||
QString itag = m_itags.at(originalOption);
|
||||
const auto itag = m_itags.at(originalOption);
|
||||
if(m_itagInfo.contains(itag)) {
|
||||
extension = m_itagInfo.value(itag).toObject().value(QStringLiteral("container")).toString().toLower();
|
||||
const auto itagObj = m_itagInfo.value(itag).toObject();
|
||||
extension = itagObj.value(QStringLiteral("ext")).toString();
|
||||
if(extension.isEmpty()) {
|
||||
extension = itagObj.value(QStringLiteral("container")).toString().toLower();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(extension.isEmpty()) {
|
||||
|
|
Loading…
Reference in New Issue