Skip to content

Commit

Permalink
Bug fix for crash when Android device not connected.
Browse files Browse the repository at this point in the history
Added playcount update when updating database.
  • Loading branch information
Harpo3 committed Aug 31, 2020
1 parent b2f8509 commit 3ec5ea3
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 29 deletions.
2 changes: 1 addition & 1 deletion ArchSimian.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = archsimian
TEMPLATE = app
VERSION = 1.07
VERSION = 1.08
DEFINES += APP_VERSION=$$VERSION

# The following define makes your compiler emit warnings if you use
Expand Down
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.13.0, 2020-08-29T17:39:53. -->
<!-- Written by QtCreator 4.13.0, 2020-08-30T14:54:04. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
55 changes: 33 additions & 22 deletions src/archsimian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QTimeLine>
#include <QProgressDialog>
#include <QFile>
#include <QDir>
#include <fstream>
#include <unistd.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -298,6 +299,7 @@ ArchSimian::ArchSimian(QWidget *parent) :
ui->updateASDBprogressBar->setVisible(false);
ui->addsongsprogressBar->setVisible(false);
ui->androiddevicebuttonlabel->setText(tr("Select Android device (for syncing play history using AIMP - requires KDEconnect and AIMP with logging enabled.)"));
ui->updateASDBlabel->setText(tr("Read lastplayed dates from AIMP/Audacious and update the play history in the Archsiman database."));
if (s_androidpathname != ""){ui->androiddevicebuttonlabel->setText(s_androidpathname);}
ui->syncthinglabel->setText(tr("Select the shared folder Syncthing will use to sync playlist and music files to Android device.)"));
if (s_syncthingpathname != ""){ui->syncthinglabel->setText(s_syncthingpathname);}
Expand Down Expand Up @@ -1652,7 +1654,7 @@ void ArchSimian::on_actionSave_Settings_triggered()

void ArchSimian::on_actionAbout_triggered()
{
QMessageBox::about(this,tr("ArchSimian") ,tr("\nArchSimian v.1.07"
QMessageBox::about(this,tr("ArchSimian") ,tr("\nArchSimian v.1.08"
"\n\nThis program is free software: you can redistribute it and/or modify"
" it under the terms of the GNU General Public License as published by"
" the Free Software Foundation, either version 3 of the License, or"
Expand Down Expand Up @@ -1960,27 +1962,36 @@ void ArchSimian::on_selectAndroidDeviceButton_clicked()
void ArchSimian::on_updateASDBButton_clicked()
{
if (Constants::kVerbose){std::cout << "on_updateASDBButton_clicked: Starting getLastPlayedDates."<< std::endl;}
getLastPlayedDates(s_androidpathname); // First, poll the AIMP log and get last played dates
ui->updateASDBButton->toggle();
if (s_audaciouslogenabled == true) { // If Audacious logging enabled, process its play history
if (Constants::kVerbose){std::cout << "on_updateASDBButton_clicked: Audacious logging enabled, starting syncAudaciousLog."<< std::endl;}
syncAudaciousLog();
}
ui->updateASDBprogressBar->setValue(80);
if (Constants::kVerbose){std::cout << "on_updateASDBButton_clicked: Starting updateCleanLibDates."<< std::endl;}
updateCleanLibDates(); // Update cleanlib.dsv wih new dates
// Need to reprocess functions associated with a cleanlib.dsv change.
std::string LastTableDate = getLastTableDate();
ui->updateASDBButton->setText("Update ArchSimian Database");
ui->updateASDBButton->setDisabled(false); // Reenable button after updating
ui->updatestatusLabel->setText(tr("MM.DB date: Disabled, Library date: ")+ QString::fromStdString(LastTableDate));
ui->statusBar->showMessage("Completed getting lastplayed dates and updating Archsimian.",8000);
QFile ratingupdate(appDataPathstr+"/syncdisplay.txt");
if(!ratingupdate.open(QIODevice::ReadOnly))
QMessageBox::information(nullptr,"info",ratingupdate.errorString());
QTextStream in(&ratingupdate);
ui->updateDBtextBrowser->setText(in.readAll());
ui->statusBar->showMessage("Finished updating play history to the database",8000);
// Check existence of device directory to ensure it is paired
QDir dir;
if (dir.exists(s_androidpathname)) {
ui->updateASDBlabel->setText(tr("Read lastplayed dates from AIMP/Audacious and update the play history in the Archsiman database."));
getLastPlayedDates(s_androidpathname); // First, poll the AIMP log and get last played dates
ui->updateASDBButton->toggle();
if (s_audaciouslogenabled == true) { // If Audacious logging enabled, process its play history
if (Constants::kVerbose){std::cout << "on_updateASDBButton_clicked: Audacious logging enabled, starting syncAudaciousLog."<< std::endl;}
syncAudaciousLog();
}
ui->updateASDBprogressBar->setValue(80);
if (Constants::kVerbose){std::cout << "on_updateASDBButton_clicked: Starting updateCleanLibDates."<< std::endl;}
updateCleanLibDates(); // Update cleanlib.dsv wih new dates
// Need to reprocess functions associated with a cleanlib.dsv change.
std::string LastTableDate = getLastTableDate();
ui->updateASDBButton->setText("Update ArchSimian Database");
ui->updateASDBButton->setDisabled(false); // Reenable button after updating
ui->updatestatusLabel->setText(tr("MM.DB date: Disabled, Library date: ")+ QString::fromStdString(LastTableDate));
ui->statusBar->showMessage("Completed getting lastplayed dates and updating Archsimian.",8000);
QFile ratingupdate(appDataPathstr+"/syncdisplay.txt");
if(!ratingupdate.open(QIODevice::ReadOnly))
QMessageBox::information(nullptr,"info",ratingupdate.errorString());
QTextStream in(&ratingupdate);
ui->updateDBtextBrowser->setText(in.readAll());
ui->statusBar->showMessage("Finished updating play history to the database",8000);
}
else{
// If the device is not paired, change label
ui->updateASDBlabel->setText(tr("Android device is not paired. Pair using kdeconnect, and open device primary folder in Dolphin, then try again.)"));
}
}

void ArchSimian::on_updateASDBprogressBar_valueChanged(int value)
Expand Down
10 changes: 5 additions & 5 deletions src/archsimian.ui
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<number>2</number>
</property>
<property name="currentIndex">
<number>4</number>
<number>5</number>
</property>
<widget class="QWidget" name="playlistTab">
<property name="enabled">
Expand Down Expand Up @@ -2676,9 +2676,9 @@ new tracks (rating code 1) if 'Include new tracks' has been enabled.</string>
<property name="geometry">
<rect>
<x>200</x>
<y>10</y>
<width>291</width>
<height>31</height>
<y>0</y>
<width>301</width>
<height>51</height>
</rect>
</property>
<property name="text">
Expand Down Expand Up @@ -2736,7 +2736,7 @@ new tracks (rating code 1) if 'Include new tracks' has been enabled.</string>
</rect>
</property>
<property name="text">
<string>NOTE: This program may crash if you attempt to update ArchSimian without first ensuring KDEconnect is paired to the desktop, and the Android device 'primary' folder is open in Dolphin. If the AIMP lastplayed entries do not appear in the above panel after updating the database, try manually removing earlier history from the log, found at /primary/Android/data/com.aimp.player/cache, and update again.</string>
<string>NOTE: If the AIMP lastplayed entries do not appear in the above panel after updating the database, try manually removing earlier history from the log, found at /primary/Android/data/com.aimp.player/cache, and update again.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand Down
6 changes: 6 additions & 0 deletions src/exporttoandroidaimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ void updateCleanLibDates(){
std::string selectedLibTitleToken; // Title variable from cleanlib.dsv
std::string selectedLibAlbumToken; // Title variable from cleanlib.dsv
std::string selectedLibSQLDateToken; // SQL Date variable from cleanlib.dsv
std::string selectedPlayCountToken; // SQL Date variable from cleanlib.dsv
try { // Operation replaces cleanlib.dsv; need to protect data in event of a fatal error
// Open cleanlib2.dsv as read file
std::ifstream cleanlib; // First ensure cleanlib2.dsv is ready to open
Expand Down Expand Up @@ -347,6 +348,7 @@ void updateCleanLibDates(){
selectedLibArtistToken = tokens[Constants::kColumn1];
selectedLibAlbumToken = tokens[Constants::kColumn3];
selectedLibTitleToken = tokens[Constants::kColumn7];
selectedPlayCountToken = tokens[Constants::kColumn16];
selectedLibSQLDateToken = tokens[Constants::kColumn17];
for(auto & i : lastplayedvec){ // Assign row elements from lastplayedvec to variables to compare with Lib tokens
selectedArtistToken = i[Constants::kColumn0];
Expand All @@ -356,6 +358,9 @@ void updateCleanLibDates(){
// Match Artist and title in cleanLib from lastplayedvec and change SQL date for each if log date is newer
if ((selectedArtistToken == selectedLibArtistToken) && (selectedAlbumToken == selectedLibAlbumToken)
&& (selectedTitleToken == selectedLibTitleToken) && (std::stod(selectedSQLDateToken) > std::stod(selectedLibSQLDateToken))){
// Increase the playcount for each new lastplayed date
int temp1 = stoi(selectedPlayCountToken);
selectedPlayCountToken = std::to_string(temp1 + 1);
// Convert SQL date to a readable date for lastplayedupdate
time_t x = time_t(std::stod(selectedSQLDateToken));
x = (x - 25569) * 86400;
Expand All @@ -365,6 +370,7 @@ void updateCleanLibDates(){
"%m/%d/%Y",
gmtime(&x));
std::string datestring(yourbuf);
tokens.at(Constants::kColumn16) = selectedPlayCountToken;
tokens.at(Constants::kColumn17) = selectedSQLDateToken;
str = getChgdDSVStr(tokens,str); // Recompile str with changed token
// Print a readable date to panel
Expand Down

0 comments on commit 3ec5ea3

Please sign in to comment.