Skip to content

Commit

Permalink
Error handling added for when playlist max length is reached. Added d…
Browse files Browse the repository at this point in the history
…ialog message before exiting program on error
  • Loading branch information
Harpo3 committed Apr 12, 2020
1 parent 4efb0cf commit bfb0f09
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ArchSimian.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.9.82, 2019-05-04T11:46:24. -->
<!-- Written by QtCreator 4.9.82, 2020-04-12T14:43:23. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
13 changes: 13 additions & 0 deletions src/archsimian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/playlistfunctions.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <QStandardPaths>
#include <QDir>
#include <QMessageBox>
#include <fstream>
#include <sstream>
#include "basiclibfunctions.h"
Expand Down Expand Up @@ -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");
Expand All @@ -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
}
Expand Down

0 comments on commit bfb0f09

Please sign in to comment.