From bfb0f0964ecf5c470a2a27f8012b64c793807367 Mon Sep 17 00:00:00 2001 From: Louis Cornell Date: Sun, 12 Apr 2020 14:51:41 -0500 Subject: [PATCH] Error handling added for when playlist max length is reached. Added dialog message before exiting program on error --- ArchSimian.pro.user | 2 +- src/archsimian.cpp | 13 +++++++++++++ src/playlistfunctions.cpp | 7 ++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ArchSimian.pro.user b/ArchSimian.pro.user index a4dc2da..3072b86 100644 --- a/ArchSimian.pro.user +++ b/ArchSimian.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/src/archsimian.cpp b/src/archsimian.cpp index ba0c96a..b782409 100644 --- a/src/archsimian.cpp +++ b/src/archsimian.cpp @@ -863,7 +863,20 @@ void ArchSimian::on_addsongsButton_released(){ getAlbumIDs(); } if (Constants::kVerbose) std::cout << "Now selecting track for non-code-1 track selection (function selectTrack)." << std::endl; + try { selectTrack(s_ratingNextTrack,&s_selectedTrackPath,s_includeAlbumVariety); // Select track if not a code 1 selection + } + catch (const std::bad_alloc& exception) { + std::cerr << "bad_alloc detected: Maximum playlist length has been reached. Exiting program." << exception.what(); + //QMessageBox msgBox; + //msgBox.setText("Artist excludes error: Attempted to add tracks, but no available tracks found. Maximum" + //" playlist length has been reached."); + QMessageBox msgBox; + QString msgboxtxt = "Sorry, attempted to add tracks at this quantity, but not enough available tracks found. Try again with fewer tracks. Exiting program "; + msgBox.setText(msgboxtxt); + msgBox.exec(); + qApp->quit(); //Exit program + } } // Collect and collate 'track selected' info for (GUI display of) final song selections std::string shortselectedTrackPath; diff --git a/src/playlistfunctions.cpp b/src/playlistfunctions.cpp index 541de53..addaaee 100644 --- a/src/playlistfunctions.cpp +++ b/src/playlistfunctions.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include "basiclibfunctions.h" @@ -375,11 +376,11 @@ std::string selectTrack(int &s_ratingNextTrack, std::string *s_selectedTrackPath continue;} // if an excluded artist is found continue to next str1 artexcludes.close(); /* - If not yet skipped, and if the user has enabled the album variety feature, open another inner loop and iterate through + If not yet skipped (!s_excludeMatch), and if the user has enabled the album variety feature, open another inner loop and iterate through finalids.txt (which contains the album IDs which are to be excluded) and compare each ID to the str1 albumID token. Continue to next str1 if a match found (meaning it identifies an excluded album ID). */ - if (s_includeAlbumVariety){ + if ((s_includeAlbumVariety) && (!s_excludeMatch)){ // added condition on 11 Apr 2020 ---> && (!s_excludeMatch) QString appDataPathstr = QDir::homePath() + "/.local/share/" + QApplication::applicationName(); std::ifstream artistalbexcludes; // Next ensure artistalbexcludes.txt is ready to open artistalbexcludes.open (appDataPathstr.toStdString()+"/finalids.txt"); @@ -403,7 +404,7 @@ std::string selectTrack(int &s_ratingNextTrack, std::string *s_selectedTrackPath artalbexcludes.close(); continue;}// if an excluded artist is found continue to next str1 artalbexcludes.close(); - } + } finaltracksvect.push_back(tokenLTP+","+songPath); // If not skipped by now, add the track to the final list // end of the str1 while block, continue to next str1 }