mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-22 18:52:30 +01:00
Add toLocal to remove file:///
This commit is contained in:
parent
5aa714a165
commit
bbb827ed66
@ -297,6 +297,15 @@ void Util::Util::requestDataProtection()
|
||||
});
|
||||
}
|
||||
|
||||
QJsonArray Util::fillArray(const QVector<QString>& items)
|
||||
{
|
||||
QJsonArray array;
|
||||
for (const QString& item : items) {
|
||||
array.append(item);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
SearchType::SearchType Util::getSearchTypeFromInstalledType(const InstalledType::InstalledType type)
|
||||
{
|
||||
using InstalledType::InstalledType;
|
||||
@ -387,4 +396,77 @@ void Util::logToGui(QtMsgType type, const QMessageLogContext& context, const QSt
|
||||
utilPointer->appendDebugMessages(log);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Takes ownership of \a obj and \a name. Tries to save into a text file
|
||||
with of name.
|
||||
*/
|
||||
bool Util::writeSettings(const QJsonObject& obj, const QString& name)
|
||||
{
|
||||
QFile file { name };
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug() << "Could not open" << name;
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
out.setCodec("UTF-8");
|
||||
QJsonDocument doc(obj);
|
||||
|
||||
out << doc.toJson();
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Takes ownership of \a obj and \a name. Tries to save into a text file
|
||||
with of name.
|
||||
*/
|
||||
bool Util::writeFile(const QString& text, const QString& name)
|
||||
{
|
||||
QFile file { name };
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug() << "Could not open" << name;
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
out.setCodec("UTF-8");
|
||||
|
||||
out << text;
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Takes reference to \a obj. If the copy of the thumbnail is successful,
|
||||
it adds the corresponding settings entry to the json object reference.
|
||||
*/
|
||||
bool Util::copyPreviewThumbnail(QJsonObject& obj, const QString& name, const QString& destination)
|
||||
{
|
||||
QUrl previewThumbnailUrl { name };
|
||||
QFileInfo previewImageFile(previewThumbnailUrl.toLocalFile());
|
||||
|
||||
if (!name.isEmpty()) {
|
||||
if (!QFile::copy(previewThumbnailUrl.toLocalFile(), destination)) {
|
||||
qDebug() << "Could not copy" << previewThumbnailUrl.toLocalFile() << " to " << name;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
obj.insert("previewThumbnail", previewImageFile.fileName());
|
||||
obj.insert("preview", previewImageFile.fileName());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Converts the given \a url string to a local file path.
|
||||
*/
|
||||
QString Util::toLocal(const QString& url)
|
||||
{
|
||||
return QUrl(url).toLocalFile();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -105,17 +105,21 @@ public slots:
|
||||
void requestAllLicenses();
|
||||
void requestDataProtection();
|
||||
|
||||
static QJsonArray fillArray(const QVector<QString>& items);
|
||||
static SearchType::SearchType getSearchTypeFromInstalledType(const InstalledType::InstalledType type);
|
||||
static std::optional<InstalledType::InstalledType> getInstalledTypeFromString(const QString& type);
|
||||
static std::optional<QJsonObject> parseQByteArrayToQJsonObject(const QByteArray& byteArray);
|
||||
static std::optional<QJsonObject> openJsonFileToObject(const QString& path);
|
||||
static std::optional<QString> openJsonFileToString(const QString& path);
|
||||
static std::optional<QVersionNumber> getVersionNumberFromString(const QString& str);
|
||||
static bool writeJsonObjectToFile(const QString& absoluteFilePath, const QJsonObject& object, bool truncate = true);
|
||||
static QString toString(const QStringList& list);
|
||||
static void appendToMetricsFile(const QString& key, const QVariant& value);
|
||||
|
||||
static void logToGui(QtMsgType type, const QMessageLogContext& context, const QString& msg);
|
||||
static bool writeJsonObjectToFile(const QString& absoluteFilePath, const QJsonObject& object, bool truncate = true);
|
||||
static bool writeSettings(const QJsonObject& obj, const QString& name);
|
||||
static bool writeFile(const QString& text, const QString& name);
|
||||
static bool copyPreviewThumbnail(QJsonObject& obj, const QString& name, const QString& destination);
|
||||
static QString toString(const QStringList& list);
|
||||
static QString toLocal(const QString& url);
|
||||
static QString generateRandomString(quint32 length = 32);
|
||||
|
||||
void setNavigation(QString nav)
|
||||
|
Loading…
Reference in New Issue
Block a user