Skip to content

Commit

Permalink
Review comments. Part I.
Browse files Browse the repository at this point in the history
Signed-off-by: alex-z <[email protected]>
  • Loading branch information
allexzander committed Dec 6, 2023
1 parent ac03970 commit 07e0504
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/gui/tray/NCBusyIndicator.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ BusyIndicator {

RotationAnimator {
target: contentImage
running: false
running: root.running
onRunningChanged: contentImage.rotation = 0
from: 0
to: 360
Expand Down
1 change: 0 additions & 1 deletion src/libsync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ set(libsync_SRCS
clientstatusreporting.h
clientstatusreporting.cpp
clientstatusreportingrecord.h
clientstatusreportingrecord.cpp
cookiejar.h
cookiejar.cpp
discovery.h
Expand Down
10 changes: 4 additions & 6 deletions src/libsync/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,19 +286,17 @@ void Account::setPushNotificationsReconnectInterval(int interval)

void Account::trySetupClientStatusReporting()
{
if (_capabilities.isClientStatusReportingEnabled()) {
if (!_clientStatusReporting) {
_clientStatusReporting.reset(new ClientStatusReporting(this));
}
if (!_capabilities.isClientStatusReportingEnabled()) {
_clientStatusReporting.reset();
return;
}

if (!_clientStatusReporting) {
_clientStatusReporting.reset();
_clientStatusReporting = std::make_unique<ClientStatusReporting>(this);
}
}

void Account::reportClientStatus(const ClientStatusReporting::Status status)
void Account::reportClientStatus(const ClientStatusReporting::Status status) const
{
if (_clientStatusReporting) {
_clientStatusReporting->reportClientStatus(status);
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject

void trySetupClientStatusReporting();

void reportClientStatus(const ClientStatusReporting::Status status);
void reportClientStatus(const ClientStatusReporting::Status status) const;

[[nodiscard]] std::shared_ptr<UserStatusConnector> userStatusConnector() const;

Expand Down Expand Up @@ -444,7 +444,7 @@ private slots:

PushNotifications *_pushNotifications = nullptr;

QScopedPointer<ClientStatusReporting> _clientStatusReporting;
std::unique_ptr<ClientStatusReporting> _clientStatusReporting;

std::shared_ptr<UserStatusConnector> _userStatusConnector;

Expand Down
38 changes: 17 additions & 21 deletions src/libsync/clientstatusreporting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ void ClientStatusReporting::init()
{
Q_ASSERT(!_isInitialized);
if (_isInitialized) {
qCDebug(lcClientStatusReporting) << "Double call to init";
return;
}

Expand Down Expand Up @@ -82,30 +81,12 @@ void ClientStatusReporting::init()
return;
}

if (!query.prepare(QStringLiteral("CREATE INDEX IF NOT EXISTS name ON clientstatusreporting(name);")) || !query.exec()) {
qCDebug(lcClientStatusReporting) << "Could not create index on clientstatusreporting table:" << query.lastError().text();
return;
}

if (!query.prepare(QStringLiteral("CREATE TABLE IF NOT EXISTS keyvalue(key VARCHAR(4096), value VARCHAR(4096), PRIMARY KEY(key))")) || !query.exec()) {
qCDebug(lcClientStatusReporting) << "Could not setup client keyvalue table:" << query.lastError().text();
return;
}

// prevent issues in case enum gets changed in future, hash its value and clean the db in case there was a change
QByteArray statusNamesContatenated;
for (int i = 0; i < ClientStatusReporting::Status::Count; ++i) {
statusNamesContatenated += statusStringFromNumber(static_cast<Status>(i));
}
statusNamesContatenated += QByteArray::number(ClientStatusReporting::Status::Count);
const auto statusNamesHashCurrent = QCryptographicHash::hash(statusNamesContatenated, QCryptographicHash::Md5).toHex();
const auto statusNamesHashFromDb = getStatusNamesHash();

if (statusNamesHashCurrent != statusNamesHashFromDb) {
deleteClientStatusReportingRecords();
setStatusNamesHash(statusNamesHashCurrent);
}
//
updateStatusNamesHash();

_clientStatusReportingSendTimer.setInterval(clientStatusReportingTrySendTimerInterval);
connect(&_clientStatusReportingSendTimer, &QTimer::timeout, this, &ClientStatusReporting::sendReportToServer);
Expand Down Expand Up @@ -212,7 +193,6 @@ void ClientStatusReporting::sendReportToServer()

const auto report = prepareReport();
if (report.isEmpty()) {
qCDebug(lcClientStatusReporting) << "Failed to generate report. Report is empty.";
return;
}

Expand Down Expand Up @@ -250,6 +230,22 @@ QString ClientStatusReporting::makeDbPath() const
return ConfigFile().configPath() + QStringLiteral(".userdata_%1.db").arg(QString::fromLatin1(databaseIdHash.left(6).toHex()));
}

void ClientStatusReporting::updateStatusNamesHash()
{
QByteArray statusNamesContatenated;
for (int i = 0; i < ClientStatusReporting::Status::Count; ++i) {
statusNamesContatenated += statusStringFromNumber(static_cast<Status>(i));
}
statusNamesContatenated += QByteArray::number(ClientStatusReporting::Status::Count);
const auto statusNamesHashCurrent = QCryptographicHash::hash(statusNamesContatenated, QCryptographicHash::Md5).toHex();
const auto statusNamesHashFromDb = getStatusNamesHash();

if (statusNamesHashCurrent != statusNamesHashFromDb) {
deleteClientStatusReportingRecords();
setStatusNamesHash(statusNamesHashCurrent);
}
}

quint64 ClientStatusReporting::getLastSentReportTimestamp() const
{
QMutexLocker locker(&_mutex);
Expand Down
24 changes: 15 additions & 9 deletions src/libsync/clientstatusreporting.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
#include "owncloudlib.h"

Check failure on line 16 in src/libsync/clientstatusreporting.h

View workflow job for this annotation

GitHub Actions / build

/src/libsync/clientstatusreporting.h:16:10 [clang-diagnostic-error]

'owncloudlib.h' file not found

Check failure on line 16 in src/libsync/clientstatusreporting.h

View workflow job for this annotation

GitHub Actions / build

/src/libsync/clientstatusreporting.h:16:10 [clang-diagnostic-error]

'owncloudlib.h' file not found
#include <common/result.h>

#include <QtGlobal>
#include <QByteArray>
#include <QHash>
#include <QObject>
#include <QPair>
#include <QRecursiveMutex>
#include <QString>
#include <QTimer>
#include <QtSql>
#include <QtCore/qglobal.h>
#include <QtCore/qbytearray.h>
#include <QtCore/qhash.h>
#include <QtCore/qobject.h>
#include <QtCore/qmutex.h>
#include <QtCore/qpair.h>
#include <QtCore/qstring.h>
#include <QtCore/qtimer.h>
#include <QtSql/qsqldatabase.h>
#include <QtSql/qsqlerror.h>
#include <QtSql/qsqlrecord.h>
#include <QtSql/qsqlquery.h>

namespace OCC {

Check warning on line 32 in src/libsync/clientstatusreporting.h

View workflow job for this annotation

GitHub Actions / build

/src/libsync/clientstatusreporting.h:32:11 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'OCC' is non-const and globally accessible, consider making it const

Expand Down Expand Up @@ -52,6 +55,7 @@ class OWNCLOUDSYNC_EXPORT ClientStatusReporting : public QObject
UploadError_Virus_Detected,
Count,
};
Q_ENUM(Status);

explicit ClientStatusReporting(Account *account, QObject *parent = nullptr);
~ClientStatusReporting() override;
Expand All @@ -78,6 +82,8 @@ class OWNCLOUDSYNC_EXPORT ClientStatusReporting : public QObject

[[nodiscard]] QString makeDbPath() const;

void updateStatusNamesHash();

private slots:
void sendReportToServer();

Expand Down
24 changes: 0 additions & 24 deletions src/libsync/clientstatusreportingrecord.cpp

This file was deleted.

5 changes: 4 additions & 1 deletion src/libsync/clientstatusreportingrecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ struct OWNCLOUDSYNC_EXPORT ClientStatusReportingRecord {
quint64 _numOccurences = 1;
quint64 _lastOccurence = 0;

[[nodiscard]] bool isValid() const;
[[nodiscard]] inline bool isValid() const
{
return _status >= 0 && !_name.isEmpty() && _lastOccurence > 0;
}
};
}
2 changes: 1 addition & 1 deletion src/libsync/owncloudpropagator_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ inline QByteArray getEtagFromReply(QNetworkReply *reply)
return ret;
}

inline QPair<QByteArray, QByteArray> getExceptionFromReply(QNetworkReply *reply)
inline QPair<QByteArray, QByteArray> getExceptionFromReply(QNetworkReply * const reply)
{
Q_ASSERT(reply);
if (!reply) {
Expand Down

0 comments on commit 07e0504

Please sign in to comment.