Merge pull request #3747 from nextcloud/bugfix/deprecated-warnings

Fix most of the deprecation warnings
This commit is contained in:
Felix Weilbach 2021-09-08 14:59:12 +02:00 committed by GitHub
commit 3fd4d5cd4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 60 additions and 54 deletions

View File

@ -295,9 +295,10 @@ void selectiveSyncFixup(OCC::SyncJournalDb *journal, const QStringList &newList)
bool ok = false;
auto oldBlackListSet = journal->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &ok).toSet();
const auto selectiveSyncList = journal->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &ok);
const QSet<QString> oldBlackListSet(selectiveSyncList.begin(), selectiveSyncList.end());
if (ok) {
auto blackListSet = newList.toSet();
const QSet<QString> blackListSet(newList.begin(), newList.end());
const auto changes = (oldBlackListSet - blackListSet) + (blackListSet - oldBlackListSet);
for (const auto &it : changes) {
journal->schedulePathForRemoteDiscovery(it);
@ -317,8 +318,6 @@ int main(int argc, char **argv)
qputenv("OPENSSL_CONF", opensslConf.toLocal8Bit());
#endif
qsrand(std::random_device()());
CmdOptions options;
options.silent = false;
options.trustSSL = false;

View File

@ -93,7 +93,6 @@ static QByteArray defaultJournalMode(const QString &dbPath)
SyncJournalDb::SyncJournalDb(const QString &dbFilePath, QObject *parent)
: QObject(parent)
, _dbFile(dbFilePath)
, _mutex(QMutex::Recursive)
, _transaction(0)
, _metadataTableIsEmpty(false)
{

View File

@ -393,7 +393,7 @@ private:
SqlDatabase _db;
QString _dbFile;
QMutex _mutex; // Public functions are protected with the mutex.
QRecursiveMutex _mutex; // Public functions are protected with the mutex.
QMap<QByteArray, int> _checksymTypeCache;
int _transaction;
bool _metadataTableIsEmpty;

View File

@ -37,6 +37,7 @@
#include <QStandardPaths>
#include <QCollator>
#include <QSysInfo>
#include <qrandom.h>
#ifdef Q_OS_UNIX
@ -64,14 +65,13 @@ Q_LOGGING_CATEGORY(lcUtility, "nextcloud.sync.utility", QtInfoMsg)
bool Utility::writeRandomFile(const QString &fname, int size)
{
int maxSize = 10 * 10 * 1024;
qsrand(QDateTime::currentMSecsSinceEpoch());
if (size == -1)
size = qrand() % maxSize;
size = rand() % maxSize;
QString randString;
for (int i = 0; i < size; i++) {
int r = qrand() % 128;
int r = rand() % 128;
randString.append(QChar(r));
}
@ -259,6 +259,11 @@ QString Utility::escape(const QString &in)
return in.toHtmlEscaped();
}
int Utility::rand()
{
return QRandomGenerator::global()->bounded(0, RAND_MAX);
}
void Utility::sleep(int sec)
{
QThread::sleep(sec);

View File

@ -50,6 +50,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcUtility)
* @{
*/
namespace Utility {
OCSYNC_EXPORT int rand();
OCSYNC_EXPORT void sleep(int sec);
OCSYNC_EXPORT void usleep(int usec);
OCSYNC_EXPORT QString formatFingerprint(const QByteArray &, bool colonSeparated = true);

View File

@ -80,17 +80,17 @@ void setLaunchOnStartup_private(const QString &appName, const QString &guiName,
QTextStream ts(&iniFile);
ts.setCodec("UTF-8");
ts << QLatin1String("[Desktop Entry]") << endl
<< QLatin1String("Name=") << guiName << endl
<< QLatin1String("GenericName=") << QLatin1String("File Synchronizer") << endl
<< QLatin1String("Exec=\"") << executablePath << "\" --background" << endl
<< QLatin1String("Terminal=") << "false" << endl
<< QLatin1String("Icon=") << APPLICATION_ICON_NAME << endl
<< QLatin1String("Categories=") << QLatin1String("Network") << endl
<< QLatin1String("Type=") << QLatin1String("Application") << endl
<< QLatin1String("StartupNotify=") << "false" << endl
<< QLatin1String("X-GNOME-Autostart-enabled=") << "true" << endl
<< QLatin1String("X-GNOME-Autostart-Delay=10") << endl;
ts << QLatin1String("[Desktop Entry]\n")
<< QLatin1String("Name=") << guiName << QLatin1Char('\n')
<< QLatin1String("GenericName=") << QLatin1String("File Synchronizer\n")
<< QLatin1String("Exec=\"") << executablePath << "\" --background\n"
<< QLatin1String("Terminal=") << "false\n"
<< QLatin1String("Icon=") << APPLICATION_ICON_NAME << QLatin1Char('\n')
<< QLatin1String("Categories=") << QLatin1String("Network\n")
<< QLatin1String("Type=") << QLatin1String("Application\n")
<< QLatin1String("StartupNotify=") << "false\n"
<< QLatin1String("X-GNOME-Autostart-enabled=") << "true\n"
<< QLatin1String("X-GNOME-Autostart-Delay=10") << Qt::endl;
} else {
if (!QFile::remove(desktopFileLocation)) {
qCWarning(lcUtility) << "Could not remove autostart desktop file";

View File

@ -907,7 +907,7 @@ void FolderStatusModel::slotApplySelectiveSync()
// The folders that were undecided or blacklisted and that are now checked should go on the white list.
// The user confirmed them already just now.
QStringList toAddToWhiteList = ((oldBlackListSet + folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncUndecidedList, &ok).toSet()) - blackListSet).toList();
QStringList toAddToWhiteList = ((oldBlackListSet + folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncUndecidedList, &ok).toSet()) - blackListSet).values();
if (!toAddToWhiteList.isEmpty()) {
auto whiteList = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList, &ok);

View File

@ -103,7 +103,7 @@ void showInFileManager(const QString &localPath)
return;
#endif
QString explorer = "explorer.exe "; // FIXME: we trust it's in PATH
const QString explorer = "explorer.exe "; // FIXME: we trust it's in PATH
QFileInfo fi(localPath);
// canonicalFilePath returns empty if the file does not exist
@ -123,7 +123,7 @@ void showInFileManager(const QString &localPath)
// only around the path. Use setNativeArguments to bypass this logic.
p.setNativeArguments(nativeArgs);
#endif
p.start(explorer);
p.start(explorer, QStringList {});
p.waitForFinished(5000);
}
} else if (Utility::isMac()) {

View File

@ -44,6 +44,7 @@
#include <QJsonObject>
#include <QJsonArray>
#include <qsslconfiguration.h>
#include <qt5keychain/keychain.h>
#include "creds/abstractcredentials.h"
@ -371,7 +372,7 @@ QSslConfiguration Account::getOrCreateSslConfig()
void Account::setApprovedCerts(const QList<QSslCertificate> certs)
{
_approvedCerts = certs;
QSslSocket::addDefaultCaCertificates(certs);
QSslConfiguration::defaultConfiguration().addCaCertificates(certs);
}
void Account::addApprovedCerts(const QList<QSslCertificate> certs)
@ -463,7 +464,7 @@ void Account::slotHandleSslErrors(QNetworkReply *reply, QList<QSslError> errors)
return;
if (!approvedCerts.isEmpty()) {
QSslSocket::addDefaultCaCertificates(approvedCerts);
QSslConfiguration::defaultConfiguration().addCaCertificates(approvedCerts);
addApprovedCerts(approvedCerts);
emit wantsAccountSaved(this);

View File

@ -645,7 +645,7 @@ int ConfigFile::updateSegment() const
// Invalid? (Unset at the very first launch)
if(segment < 0 || segment > 99) {
// Save valid segment value, normally has to be done only once.
segment = qrand() % 99;
segment = Utility::rand() % 99;
settings.setValue(QLatin1String(updateSegmentC), segment);
}

View File

@ -92,7 +92,7 @@ void Logger::doLog(QtMsgType type, const QMessageLogContext &ctx, const QString
_crashLogIndex = (_crashLogIndex + 1) % CrashLogSize;
_crashLog[_crashLogIndex] = msg;
if (_logstream) {
(*_logstream) << msg << endl;
(*_logstream) << msg << Qt::endl;
if (_doFileFlush)
_logstream->flush();
}

View File

@ -63,9 +63,9 @@ QString OWNCLOUDSYNC_EXPORT createDownloadTmpFileName(const QString &previous)
int overhead = 1 + 1 + 2 + 8; // slash dot dot-tilde ffffffff"
int spaceForFileName = qMin(254, tmpFileName.length() + overhead) - overhead;
if (tmpPath.length() > 0) {
return tmpPath + '/' + '.' + tmpFileName.left(spaceForFileName) + ".~" + (QString::number(uint(qrand() % 0xFFFFFFFF), 16));
return tmpPath + '/' + '.' + tmpFileName.left(spaceForFileName) + ".~" + (QString::number(uint(Utility::rand() % 0xFFFFFFFF), 16));
} else {
return '.' + tmpFileName.left(spaceForFileName) + ".~" + (QString::number(uint(qrand() % 0xFFFFFFFF), 16));
return '.' + tmpFileName.left(spaceForFileName) + ".~" + (QString::number(uint(Utility::rand() % 0xFFFFFFFF), 16));
}
}

View File

@ -229,7 +229,7 @@ void PropagateUploadFileNG::slotDeleteJobFinished()
void PropagateUploadFileNG::startNewUpload()
{
ASSERT(propagator()->_activeJobList.count(this) == 1);
_transferId = uint(qrand() ^ uint(_item->_modtime) ^ (uint(_fileToUpload._size) << 16) ^ qHash(_fileToUpload._file));
_transferId = uint(Utility::rand() ^ uint(_item->_modtime) ^ (uint(_fileToUpload._size) << 16) ^ qHash(_fileToUpload._file));
_sent = 0;
_currentChunk = 0;

View File

@ -39,7 +39,7 @@ void PropagateUploadFileV1::doStartUpload()
{
_chunkCount = int(std::ceil(_fileToUpload._size / double(chunkSize())));
_startChunk = 0;
_transferId = uint(qrand()) ^ uint(_item->_modtime) ^ (uint(_fileToUpload._size) << 16);
_transferId = uint(Utility::rand()) ^ uint(_item->_modtime) ^ (uint(_fileToUpload._size) << 16);
const SyncJournalDb::UploadInfo progressInfo = propagator()->_journal->getUploadInfo(_item->_file);

View File

@ -690,8 +690,12 @@ void SyncEngine::slotDiscoveryFinished()
const QString script = qEnvironmentVariable("OWNCLOUD_POST_UPDATE_SCRIPT");
qCDebug(lcEngine) << "Post Update Script: " << script;
QProcess::execute(script);
#else
auto scriptArgs = script.split(QRegExp("\\s+"), Qt::SkipEmptyParts);
if (scriptArgs.size() > 0) {
const auto scriptExecutable = scriptArgs.takeFirst();
QProcess::execute(scriptExecutable, scriptArgs);
}
#else
qCWarning(lcEngine) << "**** Attention: POST_UPDATE_SCRIPT installed, but not executed because compiled with NDEBUG";
#endif
}

View File

@ -339,7 +339,7 @@ SyncFileStatus SyncFileStatusTracker::resolveSyncAndErrorStatus(const QString &r
void SyncFileStatusTracker::invalidateParentPaths(const QString &path)
{
QStringList splitPath = path.split('/', QString::SkipEmptyParts);
QStringList splitPath = path.split('/', Qt::SkipEmptyParts);
for (int i = 0; i < splitPath.size(); ++i) {
QString parentPath = QStringList(splitPath.mid(0, i)).join(QLatin1String("/"));
emit fileStatusChanged(getSystemDestination(parentPath), fileStatus(parentPath));

View File

@ -705,17 +705,17 @@ QString Theme::versionSwitchOutput() const
QTextStream stream(&helpText);
stream << appName()
<< QLatin1String(" version ")
<< version() << endl;
<< version() << Qt::endl;
#ifdef GIT_SHA1
stream << "Git revision " << GIT_SHA1 << endl;
stream << "Git revision " << GIT_SHA1 << Qt::endl;
#endif
stream << "Using Qt " << qVersion() << ", built against Qt " << QT_VERSION_STR << endl;
stream << "Using Qt " << qVersion() << ", built against Qt " << QT_VERSION_STR << Qt::endl;
if(!QGuiApplication::platformName().isEmpty())
stream << "Using Qt platform plugin '" << QGuiApplication::platformName() << "'" << endl;
stream << "Using Qt platform plugin '" << QGuiApplication::platformName() << "'" << Qt::endl;
stream << "Using '" << QSslSocket::sslLibraryVersionString() << "'" << endl;
stream << "Running on " << Utility::platformName() << ", " << QSysInfo::currentCpuArchitecture() << endl;
stream << "Using '" << QSslSocket::sslLibraryVersionString() << "'" << Qt::endl;
stream << "Running on " << Utility::platformName() << ", " << QSysInfo::currentCpuArchitecture() << Qt::endl;
return helpText;
}

View File

@ -20,7 +20,7 @@ PathComponents::PathComponents(const char *path)
}
PathComponents::PathComponents(const QString &path)
: QStringList { path.split(QLatin1Char('/'), QString::SkipEmptyParts) }
: QStringList { path.split(QLatin1Char('/'), Qt::SkipEmptyParts) }
{
}
@ -796,7 +796,7 @@ void FakeHangingReply::abort()
// Follow more or less the implementation of QNetworkReplyImpl::abort
close();
setError(OperationCanceledError, tr("Operation canceled"));
emit error(OperationCanceledError);
emit errorOccurred(OperationCanceledError);
setFinished(true);
emit finished();
}

View File

@ -52,10 +52,10 @@ inline QString getFilePathFromUrl(const QUrl &url)
inline QByteArray generateEtag() {
return QByteArray::number(QDateTime::currentDateTimeUtc().toMSecsSinceEpoch(), 16) + QByteArray::number(qrand(), 16);
return QByteArray::number(QDateTime::currentDateTimeUtc().toMSecsSinceEpoch(), 16) + QByteArray::number(OCC::Utility::rand(), 16);
}
inline QByteArray generateFileId() {
return QByteArray::number(qrand(), 16);
return QByteArray::number(OCC::Utility::rand(), 16);
}
class PathComponents : public QStringList {

View File

@ -21,7 +21,7 @@ private slots:
const QString nonexistingPath = tmp.filePath("someNonexistingDir/test.db");
QNetworkCookie cookieA = QNetworkCookie("foo", "bar");
// tomorrow rounded
cookieA.setExpirationDate(QDateTime(QDateTime::currentDateTimeUtc().addDays(1).date()));
cookieA.setExpirationDate(QDateTime::currentDateTimeUtc().addDays(1).date().startOfDay());
const QList<QNetworkCookie> cookies = {cookieA, QNetworkCookie("foo2", "bar")};
CookieJar jar;
jar.setAllCookies(cookies);

View File

@ -103,8 +103,8 @@ class TestFolderWatcher : public QObject
#endif
public:
TestFolderWatcher() {
qsrand(QTime::currentTime().msec());
TestFolderWatcher()
{
QDir rootDir(_root.path());
_rootPath = rootDir.canonicalPath();
qDebug() << "creating test directory tree in " << _rootPath;

View File

@ -19,10 +19,9 @@ private:
QString _root;
private slots:
void initTestCase() {
qsrand(QTime::currentTime().msec());
_root = QDir::tempPath() + "/" + "test_" + QString::number(qrand());
void initTestCase()
{
_root = QDir::tempPath() + "/" + "test_" + QString::number(OCC::Utility::rand());
qDebug() << "creating test directory tree in " << _root;
QDir rootDir(_root);
@ -31,7 +30,6 @@ private slots:
rootDir.mkpath(_root + "/a1/b2/c1");
rootDir.mkpath(_root + "/a1/b3/c3");
rootDir.mkpath(_root + "/a2/b3/c3");
}
// Test the recursive path listing function findFoldersBelow

View File

@ -58,8 +58,7 @@ private slots:
void testLaunchOnStartup()
{
qsrand(QDateTime::currentDateTime().toTime_t());
QString postfix = QString::number(qrand());
QString postfix = QString::number(OCC::Utility::rand());
const QString appName = QString::fromLatin1("testLaunchOnStartup.%1").arg(postfix);
const QString guiName = "LaunchOnStartup GUI Name";