178
src/dialogs/lastfmimportdialog.cpp
Normal file
178
src/dialogs/lastfmimportdialog.cpp
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2020, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QDialog>
|
||||
#include <QStackedWidget>
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QProgressBar>
|
||||
#include <QShowEvent>
|
||||
#include <QCloseEvent>
|
||||
|
||||
#include "lastfmimportdialog.h"
|
||||
#include "ui_lastfmimportdialog.h"
|
||||
|
||||
#include "core/iconloader.h"
|
||||
#include "scrobbler/lastfmimport.h"
|
||||
|
||||
LastFMImportDialog::LastFMImportDialog(LastFMImport *lastfm_import, QWidget *parent) : QDialog(parent),
|
||||
ui_(new Ui_LastFMImportDialog),
|
||||
lastfm_import_(lastfm_import),
|
||||
finished_(false),
|
||||
playcount_total_(0),
|
||||
lastplayed_total_(0)
|
||||
{
|
||||
|
||||
ui_->setupUi(this);
|
||||
|
||||
setWindowIcon(IconLoader::Load("scrobble"));
|
||||
|
||||
ui_->stackedWidget->setCurrentWidget(ui_->page_start);
|
||||
|
||||
Reset();
|
||||
|
||||
connect(ui_->button_close, SIGNAL(clicked()), SLOT(hide()));
|
||||
connect(ui_->button_go, SIGNAL(clicked()), SLOT(Start()));
|
||||
connect(ui_->button_cancel, SIGNAL(clicked()), SLOT(Cancel()));
|
||||
|
||||
connect(ui_->checkbox_last_played, SIGNAL(stateChanged(int)), SLOT(UpdateGoButtonState()));
|
||||
connect(ui_->checkbox_playcounts, SIGNAL(stateChanged(int)), SLOT(UpdateGoButtonState()));
|
||||
|
||||
}
|
||||
|
||||
LastFMImportDialog::~LastFMImportDialog() { delete ui_; }
|
||||
|
||||
void LastFMImportDialog::showEvent(QShowEvent*) {
|
||||
|
||||
if (ui_->stackedWidget->currentWidget() == ui_->page_start) {
|
||||
Reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LastFMImportDialog::closeEvent(QCloseEvent*) {
|
||||
|
||||
if (ui_->stackedWidget->currentWidget() == ui_->page_progress && finished_) {
|
||||
finished_ = false;
|
||||
Reset();
|
||||
ui_->stackedWidget->setCurrentWidget(ui_->page_start);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LastFMImportDialog::Start() {
|
||||
|
||||
if (ui_->stackedWidget->currentWidget() == ui_->page_start && (ui_->checkbox_last_played->isChecked() || ui_->checkbox_playcounts->isChecked())) {
|
||||
ui_->stackedWidget->setCurrentWidget(ui_->page_progress);
|
||||
ui_->button_go->hide();
|
||||
ui_->button_cancel->show();
|
||||
ui_->label_progress_top->setText(tr("Receiving initial data from last.fm..."));
|
||||
lastfm_import_->ImportData(ui_->checkbox_last_played->isChecked(), ui_->checkbox_playcounts->isChecked());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LastFMImportDialog::Cancel() {
|
||||
|
||||
if (ui_->stackedWidget->currentWidget() == ui_->page_progress) {
|
||||
lastfm_import_->AbortAll();
|
||||
ui_->stackedWidget->setCurrentWidget(ui_->page_start);
|
||||
Reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LastFMImportDialog::Reset() {
|
||||
|
||||
ui_->button_go->show();
|
||||
ui_->button_cancel->hide();
|
||||
|
||||
playcount_total_ = 0;
|
||||
lastplayed_total_ = 0;
|
||||
|
||||
ui_->progressbar->setValue(0);
|
||||
ui_->label_progress_top->clear();
|
||||
ui_->label_progress_bottom->clear();
|
||||
|
||||
UpdateGoButtonState();
|
||||
|
||||
}
|
||||
|
||||
void LastFMImportDialog::UpdateTotal(const int lastplayed_total, const int playcount_total) {
|
||||
|
||||
if (ui_->stackedWidget->currentWidget() != ui_->page_progress) return;
|
||||
|
||||
playcount_total_ = playcount_total;
|
||||
lastplayed_total_ = lastplayed_total;
|
||||
|
||||
if (lastplayed_total > 0 && playcount_total > 0) {
|
||||
ui_->label_progress_top->setText(tr("Receiving playcount for %1 songs and last played for %2 songs.").arg(playcount_total).arg(lastplayed_total));
|
||||
}
|
||||
else if (lastplayed_total > 0) {
|
||||
ui_->label_progress_top->setText(tr("Receiving last played for %1 songs.").arg(lastplayed_total));
|
||||
}
|
||||
else if (playcount_total > 0) {
|
||||
ui_->label_progress_top->setText(tr("Receiving playcounts for %1 songs.").arg(playcount_total));
|
||||
}
|
||||
else {
|
||||
ui_->label_progress_top->clear();
|
||||
}
|
||||
|
||||
ui_->label_progress_bottom->clear();
|
||||
|
||||
}
|
||||
|
||||
void LastFMImportDialog::UpdateProgress(const int lastplayed_received, const int playcount_received) {
|
||||
|
||||
if (ui_->stackedWidget->currentWidget() != ui_->page_progress) return;
|
||||
|
||||
ui_->progressbar->setValue(static_cast<int>(static_cast<float>(playcount_received + lastplayed_received) / static_cast<float>(playcount_total_ + lastplayed_total_) * 100.0));
|
||||
|
||||
if (lastplayed_received > 0 && playcount_received > 0) {
|
||||
ui_->label_progress_bottom->setText(tr("Playcounts for %1 songs and last played for %2 songs received.").arg(playcount_received).arg(lastplayed_received));
|
||||
}
|
||||
else if (lastplayed_received > 0) {
|
||||
ui_->label_progress_bottom->setText(tr("Last played for %1 songs received.").arg(lastplayed_received));
|
||||
}
|
||||
else if (playcount_received > 0) {
|
||||
ui_->label_progress_bottom->setText(tr("Playcounts for %1 songs received.").arg(playcount_received));
|
||||
}
|
||||
else {
|
||||
ui_->label_progress_bottom->clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LastFMImportDialog::Finished() {
|
||||
|
||||
ui_->button_cancel->hide();
|
||||
finished_ = true;
|
||||
|
||||
}
|
||||
|
||||
void LastFMImportDialog::FinishedWithError(const QString &error) {
|
||||
|
||||
Finished();
|
||||
ui_->label_progress_bottom->setText(error);
|
||||
|
||||
}
|
||||
|
||||
void LastFMImportDialog::UpdateGoButtonState() {
|
||||
ui_->button_go->setEnabled(ui_->checkbox_last_played->isChecked() || ui_->checkbox_playcounts->isChecked());
|
||||
}
|
||||
68
src/dialogs/lastfmimportdialog.h
Normal file
68
src/dialogs/lastfmimportdialog.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2020, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LASTFMIMPORTDIALOG_H
|
||||
#define LASTFMIMPORTDIALOG_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QDialog>
|
||||
#include <QString>
|
||||
|
||||
#include "ui_lastfmimportdialog.h"
|
||||
|
||||
class QShowEvent;
|
||||
class QCloseEvent;
|
||||
class LastFMImport;
|
||||
|
||||
class LastFMImportDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LastFMImportDialog(LastFMImport *lastfm_import, QWidget *parent = nullptr);
|
||||
~LastFMImportDialog() override;
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent*);
|
||||
void closeEvent(QCloseEvent*);
|
||||
|
||||
private:
|
||||
void Reset();
|
||||
|
||||
private slots:
|
||||
void Start();
|
||||
void Cancel();
|
||||
void UpdateGoButtonState();
|
||||
|
||||
void UpdateTotal(const int lastplayed_total, const int playcount_total);
|
||||
void UpdateProgress(const int lastplayed_received, const int playcount_received);
|
||||
void Finished();
|
||||
void FinishedWithError(const QString &error);
|
||||
|
||||
private:
|
||||
Ui_LastFMImportDialog *ui_;
|
||||
LastFMImport *lastfm_import_;
|
||||
|
||||
bool finished_;
|
||||
int playcount_total_;
|
||||
int lastplayed_total_;
|
||||
};
|
||||
|
||||
#endif // LASTFMIMPORTDIALOG_H
|
||||
137
src/dialogs/lastfmimportdialog.ui
Normal file
137
src/dialogs/lastfmimportdialog.ui
Normal file
@@ -0,0 +1,137 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>LastFMImportDialog</class>
|
||||
<widget class="QDialog" name="LastFMImportDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>520</width>
|
||||
<height>249</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Import data from last.fm</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="stackedWidget">
|
||||
<widget class="QWidget" name="page_start">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_start_top">
|
||||
<property name="text">
|
||||
<string>Choose data to import from last.fm</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkbox_last_played">
|
||||
<property name="text">
|
||||
<string>Last played</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkbox_playcounts">
|
||||
<property name="text">
|
||||
<string>Play counts</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_start_bottom">
|
||||
<property name="text">
|
||||
<string>Warning: Play counts and last played from last.fm will completely replace the same data for the matched songs. Play counts will replace the data based on artist and song title for the same albums! Please backup your database before you start.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_progress">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_progress_top">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QProgressBar" name="progressbar">
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_progress_bottom">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_done"/>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_buttons">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_go">
|
||||
<property name="text">
|
||||
<string>Go!</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_close">
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_cancel">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user