From eac75fc19c4ed515f839b12a8ea090b9315bf292 Mon Sep 17 00:00:00 2001 From: Flone Date: Sat, 2 Nov 2019 14:10:49 +0500 Subject: [PATCH] Fixed addTracks(). --- src/Model/AudioService/audioservice.cpp | 50 +++++++++++++++---------- src/View/SearchWindow/searchwindow.cpp | 14 +++++++ src/View/SearchWindow/searchwindow.h | 22 +++++++++++ src/View/SearchWindow/searchwindow.ui | 24 ++++++++++++ 4 files changed, 90 insertions(+), 20 deletions(-) create mode 100644 src/View/SearchWindow/searchwindow.cpp create mode 100644 src/View/SearchWindow/searchwindow.h create mode 100644 src/View/SearchWindow/searchwindow.ui diff --git a/src/Model/AudioService/audioservice.cpp b/src/Model/AudioService/audioservice.cpp index 874e208..76a04d2 100644 --- a/src/Model/AudioService/audioservice.cpp +++ b/src/Model/AudioService/audioservice.cpp @@ -23,7 +23,7 @@ AudioService::AudioService(MainWindow* pMainWindow) this->pMainWindow = pMainWindow; pSystem = nullptr; - pRndGen = new std::mt19937_64( static_cast(time(nullptr)) ); + pRndGen = new std::mt19937_64( std::random_device{}() ); iCurrentlyDrawingTrackIndex = new size_t(0); bMonitorTracks = false; @@ -172,22 +172,8 @@ void AudioService::addTrack(const wchar_t *pFilePath) // Get track name - size_t iNameStartIndex = 0; - for (size_t i = wPathStr.size() - 1; i >= 1; i--) - { - if (wPathStr[i] == L'/' || wPathStr[i] == L'\\') - { - iNameStartIndex = i + 1; - break; - } - } - std::wstring trackName = L""; - for (size_t i = iNameStartIndex; i < wPathStr.size() - 4; i++) - { - trackName += wPathStr[i]; - } - if (trackName.back() == L'.') trackName.pop_back(); + std::wstring trackName = getTrackName(pFilePath); @@ -268,6 +254,31 @@ void AudioService::addTrack(const wchar_t *pFilePath) mtxThreadLoadAddTrack.unlock(); } +std::wstring AudioService::getTrackName(const wchar_t *pFilePath) +{ + std::wstring wPathStr(pFilePath); + + size_t iNameStartIndex = 0; + for (size_t i = wPathStr.size() - 1; i >= 1; i--) + { + if (wPathStr[i] == L'/' || wPathStr[i] == L'\\') + { + iNameStartIndex = i + 1; + break; + } + } + + std::wstring trackName = L""; + for (size_t i = iNameStartIndex; i < wPathStr.size() - 4; i++) + { + trackName += wPathStr[i]; + } + if (trackName.back() == L'.') trackName.pop_back(); + + + return trackName; +} + void AudioService::addTracks(std::vector paths) { // This function adds tracks by using private 'threadAddTracks()' and 'addTrack()' functions. @@ -353,11 +364,10 @@ void AudioService::addTracks(std::vector paths) delete allCount; pMainWindow->hideWaitWindow(); - // Wait a little for all track widgets to show - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - if (tracks.size() > 0) pMainWindow->setFocusOnTrack(tracks.size() - 1); - mtxTracksVec.unlock(); + + pMainWindow->showAllTracks(); + return; } diff --git a/src/View/SearchWindow/searchwindow.cpp b/src/View/SearchWindow/searchwindow.cpp new file mode 100644 index 0000000..0c25680 --- /dev/null +++ b/src/View/SearchWindow/searchwindow.cpp @@ -0,0 +1,14 @@ +#include "searchwindow.h" +#include "ui_searchwindow.h" + +SearchWindow::SearchWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::SearchWindow) +{ + ui->setupUi(this); +} + +SearchWindow::~SearchWindow() +{ + delete ui; +} diff --git a/src/View/SearchWindow/searchwindow.h b/src/View/SearchWindow/searchwindow.h new file mode 100644 index 0000000..ee656b0 --- /dev/null +++ b/src/View/SearchWindow/searchwindow.h @@ -0,0 +1,22 @@ +#ifndef SEARCHWINDOW_H +#define SEARCHWINDOW_H + +#include + +namespace Ui { +class SearchWindow; +} + +class SearchWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit SearchWindow(QWidget *parent = nullptr); + ~SearchWindow(); + +private: + Ui::SearchWindow *ui; +}; + +#endif // SEARCHWINDOW_H diff --git a/src/View/SearchWindow/searchwindow.ui b/src/View/SearchWindow/searchwindow.ui new file mode 100644 index 0000000..655ee4a --- /dev/null +++ b/src/View/SearchWindow/searchwindow.ui @@ -0,0 +1,24 @@ + + + + + SearchWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + + +