Formatting

This commit is contained in:
Jonas Kvinge 2019-04-12 19:55:19 +02:00
parent 77903a5ecd
commit 368bb54870
10 changed files with 29 additions and 36 deletions

View File

@ -37,8 +37,8 @@
#define DataCommaSizeFromQString(x) x.toUtf8().constData(), x.toUtf8().length() #define DataCommaSizeFromQString(x) x.toUtf8().constData(), x.toUtf8().length()
// Reads and writes uint32 length encoded protobufs to a socket. // Reads and writes uint32 length encoded protobufs to a socket.
// This base QObject is separate from AbstractMessageHandler because moc can't // This base QObject is separate from AbstractMessageHandler because moc can't handle templated classes.
// handle templated classes. Use AbstractMessageHandler instead. // Use AbstractMessageHandler instead.
class _MessageHandlerBase : public QObject { class _MessageHandlerBase : public QObject {
Q_OBJECT Q_OBJECT
@ -76,8 +76,7 @@ protected:
}; };
// Reads and writes uint32 length encoded MessageType messages to a socket. // Reads and writes uint32 length encoded MessageType messages to a socket.
// You should subclass this and implement the MessageArrived(MessageType) // You should subclass this and implement the MessageArrived(MessageType) method.
// method.
template <typename MT> template <typename MT>
class AbstractMessageHandler : public _MessageHandlerBase { class AbstractMessageHandler : public _MessageHandlerBase {
public: public:
@ -87,21 +86,19 @@ public:
typedef MT MessageType; typedef MT MessageType;
typedef MessageReply<MT> ReplyType; typedef MessageReply<MT> ReplyType;
// Serialises the message and writes it to the socket. This version MUST be // Serialises the message and writes it to the socket.
// called from the thread in which the AbstractMessageHandler was created. // This version MUST be called from the thread in which the AbstractMessageHandler was created.
void SendMessage(const MessageType &message); void SendMessage(const MessageType &message);
// Serialises the message and writes it to the socket. This version may be // Serialises the message and writes it to the socket.
// called from any thread. // This version may be called from any thread.
void SendMessageAsync(const MessageType &message); void SendMessageAsync(const MessageType &message);
// Sends the request message inside and takes ownership of the MessageReply. // Sends the request message inside and takes ownership of the MessageReply.
// The MessageReply's Finished() signal will be emitted when a reply arrives // The MessageReply's Finished() signal will be emitted when a reply arrives with the same ID. Must be called from my thread.
// with the same ID. Must be called from my thread.
void SendRequest(ReplyType *reply); void SendRequest(ReplyType *reply);
// Sets the "id" field of reply to the same as the request, and sends the // Sets the "id" field of reply to the same as the request, and sends the reply on the socket. Used on the worker side.
// reply on the socket. Used on the worker side.
void SendReply(const MessageType &request, MessageType *reply); void SendReply(const MessageType &request, MessageType *reply);
protected: protected:
@ -131,8 +128,7 @@ void AbstractMessageHandler<MT>::SendMessage(const MessageType &message) {
template <typename MT> template <typename MT>
void AbstractMessageHandler<MT>::SendMessageAsync(const MessageType &message) { void AbstractMessageHandler<MT>::SendMessageAsync(const MessageType &message) {
std::string data = message.SerializeAsString(); std::string data = message.SerializeAsString();
metaObject()->invokeMethod(this, "WriteMessage", Qt::QueuedConnection, metaObject()->invokeMethod(this, "WriteMessage", Qt::QueuedConnection, Q_ARG(QByteArray, QByteArray(data.data(), data.size())));
Q_ARG(QByteArray, QByteArray(data.data(), data.size())));
} }
template<typename MT> template<typename MT>
@ -159,7 +155,8 @@ bool AbstractMessageHandler<MT>::RawMessageArrived(const QByteArray &data) {
if (reply) { if (reply) {
// This is a reply to a message that we created earlier. // This is a reply to a message that we created earlier.
reply->SetReply(message); reply->SetReply(message);
} else { }
else {
MessageArrived(message); MessageArrived(message);
} }

View File

@ -22,4 +22,4 @@ class QObject;
void WaitForSignal(QObject *sender, const char *signal); void WaitForSignal(QObject *sender, const char *signal);
#endif // WAITFORSIGNAL_H #endif // WAITFORSIGNAL_H

View File

@ -114,8 +114,7 @@ private:
template <typename T> template <typename T>
Worker *FindWorker(T Worker::*member, T value) { Worker *FindWorker(T Worker::*member, T value) {
for (typename QList<Worker>::iterator it = workers_.begin() ; for (typename QList<Worker>::iterator it = workers_.begin() ; it != workers_.end() ; ++it) {
it != workers_.end() ; ++it) {
if ((*it).*member == value) { if ((*it).*member == value) {
return &(*it); return &(*it);
} }
@ -158,8 +157,7 @@ template <typename HandlerType>
WorkerPool<HandlerType>::WorkerPool(QObject *parent) WorkerPool<HandlerType>::WorkerPool(QObject *parent)
: _WorkerPoolBase(parent), : _WorkerPoolBase(parent),
next_worker_(0), next_worker_(0),
next_id_(0) next_id_(0) {
{
worker_count_ = qBound(1, QThread::idealThreadCount() / 2, 2); worker_count_ = qBound(1, QThread::idealThreadCount() / 2, 2);
local_server_name_ = qApp->applicationName().toLower(); local_server_name_ = qApp->applicationName().toLower();
@ -396,4 +394,3 @@ HandlerType *WorkerPool<HandlerType>::NextHandler() const {
} }
#endif // WORKERPOOL_H #endif // WORKERPOOL_H

View File

@ -41,4 +41,4 @@ private:
TagReader tag_reader_; TagReader tag_reader_;
}; };
#endif // TAGREADERWORKER_H #endif // TAGREADERWORKER_H

View File

@ -595,7 +595,8 @@ bool Database::IntegrityCheck(QSqlDatabase db) {
if (message == "ok") { if (message == "ok") {
ok = true; ok = true;
break; break;
} else { }
else {
if (!error_reported) { app_->AddError(tr("Database corruption detected.")); } if (!error_reported) { app_->AddError(tr("Database corruption detected.")); }
app_->AddError("Database: " + message); app_->AddError("Database: " + message);
error_reported = true; error_reported = true;
@ -677,9 +678,9 @@ void Database::BackupFile(const QString &filename) {
do { do {
ret = sqlite3_backup_step(backup, 16); ret = sqlite3_backup_step(backup, 16);
const int page_count = sqlite3_backup_pagecount(backup); const int page_count = sqlite3_backup_pagecount(backup);
app_->task_manager()->SetTaskProgress( app_->task_manager()->SetTaskProgress(task_id, page_count - sqlite3_backup_remaining(backup), page_count);
task_id, page_count - sqlite3_backup_remaining(backup), page_count); }
} while (ret == SQLITE_OK); while (ret == SQLITE_OK);
if (ret != SQLITE_DONE) { if (ret != SQLITE_DONE) {
qLog(Error) << "Database backup failed"; qLog(Error) << "Database backup failed";

View File

@ -1321,7 +1321,7 @@ void MainWindow::AddToPlaylist(QAction *action) {
} }
SongList songs; SongList songs;
for (const PlaylistItemPtr &item : items) { for (const PlaylistItemPtr item : items) {
songs << item->Metadata(); songs << item->Metadata();
} }
@ -1587,7 +1587,7 @@ void MainWindow::EditTracks() {
void MainWindow::EditTagDialogAccepted() { void MainWindow::EditTagDialogAccepted() {
for (const PlaylistItemPtr &item : edit_tag_dialog_->playlist_items()) { for (const PlaylistItemPtr item : edit_tag_dialog_->playlist_items()) {
item->Reload(); item->Reload();
} }
@ -2256,7 +2256,7 @@ void MainWindow::AutoCompleteTags() {
void MainWindow::AutoCompleteTagsAccepted() { void MainWindow::AutoCompleteTagsAccepted() {
for (const PlaylistItemPtr &item : autocomplete_tag_items_) { for (const PlaylistItemPtr item : autocomplete_tag_items_) {
item->Reload(); item->Reload();
} }

View File

@ -265,8 +265,6 @@ bool RemoveRecursive(const QString &path) {
return dir.rmdir(path); return dir.rmdir(path);
return true;
} }
bool CopyRecursive(const QString &source, const QString &destination) { bool CopyRecursive(const QString &source, const QString &destination) {

View File

@ -861,7 +861,7 @@ void Playlist::InsertItems(const PlaylistItemList &itemsIn, int pos, bool play_n
// exercise vetoes // exercise vetoes
SongList songs; SongList songs;
for (const PlaylistItemPtr &item : items) { for (const PlaylistItemPtr item : items) {
songs << item->Metadata(); songs << item->Metadata();
} }
@ -1736,7 +1736,7 @@ QSortFilterProxyModel *Playlist::proxy() const { return proxy_; }
SongList Playlist::GetAllSongs() const { SongList Playlist::GetAllSongs() const {
SongList ret; SongList ret;
for (const PlaylistItemPtr &item : items_) { for (const PlaylistItemPtr item : items_) {
ret << item->Metadata(); ret << item->Metadata();
} }
return ret; return ret;
@ -1746,7 +1746,7 @@ PlaylistItemList Playlist::GetAllItems() const { return items_; }
quint64 Playlist::GetTotalLength() const { quint64 Playlist::GetTotalLength() const {
quint64 ret = 0; quint64 ret = 0;
for (const PlaylistItemPtr &item : items_) { for (const PlaylistItemPtr item : items_) {
quint64 length = item->Metadata().length_nanosec(); quint64 length = item->Metadata().length_nanosec();
if (length > 0) ret += length; if (length > 0) ret += length;
} }

View File

@ -292,7 +292,7 @@ void PlaylistBackend::SavePlaylist(int playlist, const PlaylistItemList &items,
if (db_->CheckErrors(clear)) return; if (db_->CheckErrors(clear)) return;
// Save the new ones // Save the new ones
for (const PlaylistItemPtr &item : items) { for (const PlaylistItemPtr item : items) {
insert.bindValue(":playlist", playlist); insert.bindValue(":playlist", playlist);
item->BindToQuery(&insert); item->BindToQuery(&insert);

View File

@ -451,7 +451,7 @@ void PlaylistManager::SongsDiscovered(const SongList &songs) {
for (const Song &song : songs) { for (const Song &song : songs) {
for (const Data &data : playlists_) { for (const Data &data : playlists_) {
PlaylistItemList items = data.p->collection_items_by_id(song.id()); PlaylistItemList items = data.p->collection_items_by_id(song.id());
for (PlaylistItemPtr &item : items) { for (const PlaylistItemPtr item : items) {
if (item->Metadata().directory_id() != song.directory_id()) continue; if (item->Metadata().directory_id() != song.directory_id()) continue;
static_cast<CollectionPlaylistItem*>(item.get())->SetMetadata(song); static_cast<CollectionPlaylistItem*>(item.get())->SetMetadata(song);
data.p->ItemChanged(item); data.p->ItemChanged(item);