Skip to content

Commit

Permalink
derive Clipboard from Singleton template, fixed clang-tidy error
Browse files Browse the repository at this point in the history
  • Loading branch information
m0dB committed Jul 22, 2023
1 parent 1cd0d05 commit 6ba9b46
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/coreservices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#endif
#include "soundio/soundmanager.h"
#include "sources/soundsourceproxy.h"
#include "util/clipboard.h"
#include "util/db/dbconnectionpooled.h"
#include "util/font.h"
#include "util/logger.h"
Expand Down Expand Up @@ -332,6 +333,7 @@ void CoreServices::initialize(QApplication* pApp) {

emit initializationProgressUpdate(50, tr("library"));
CoverArtCache::createInstance();
Clipboard::createInstance();

m_pTrackCollectionManager = std::make_shared<TrackCollectionManager>(
this,
Expand Down Expand Up @@ -588,6 +590,8 @@ void CoreServices::finalize() {
// CoverArtCache is fairly independent of everything else.
CoverArtCache::destroy();

Clipboard::destroy();

// PlayerManager depends on Engine, SoundManager, VinylControlManager, and Config
// The player manager has to be deleted before the library to ensure
// that all modified track metadata of loaded tracks is saved.
Expand Down
4 changes: 2 additions & 2 deletions src/library/basetracktablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,13 @@ void BaseTrackTableModel::cutTracks(const QModelIndexList& indices) {
}

void BaseTrackTableModel::copyTracks(const QModelIndexList& indices) const {
Clipboard::begin();
Clipboard::start();
for (const QModelIndex& index : indices) {
if (index.isValid()) {
Clipboard::add(QUrl::fromLocalFile(getTrackLocation(index)));
}
}
Clipboard::end();
Clipboard::finish();
}

int BaseTrackTableModel::pasteTracks(const QModelIndex& insertionIndex) {
Expand Down
17 changes: 6 additions & 11 deletions src/util/clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@
#include <QApplication>
#include <QClipboard>

QString& Clipboard::text() {
static QString s_text;
return s_text;
}

void Clipboard::begin() {
text() = "";
void Clipboard::start() {
instance()->m_text.clear();
}

void Clipboard::add(const QUrl& url) {
text().append(url.toString() + "\n");
instance()->m_text.append(url.toString() + "\n");
}

void Clipboard::end() {
QApplication::clipboard()->setText(text());
void Clipboard::finish() {
QApplication::clipboard()->setText(instance()->m_text);
}

QList<QUrl> Clipboard::urls() {
Expand All @@ -28,7 +23,7 @@ QList<QUrl> Clipboard::urls() {
QStringList strings = text.split("\n", QString::SkipEmptyParts);
#endif
QList<QUrl> result;
for (QString string : strings) {
for (const QString& string : strings) {
result.append(QUrl(string));
}
return result;
Expand Down
10 changes: 6 additions & 4 deletions src/util/clipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
#include <QString>
#include <QUrl>

class Clipboard {
static QString& text();
#include "util/singleton.h"

class Clipboard : public Singleton<Clipboard> {
QString m_text;

public:
static QList<QUrl> urls();
static void begin();
static void end();
static void start();
static void finish();
static void add(const QUrl& url);
};

0 comments on commit 6ba9b46

Please sign in to comment.