Ability to automatically set podcast as listened after sucesfully sending it to a device

This commit is contained in:
Krzysztof Sobiecki 2014-10-30 03:41:15 +01:00
parent 797236fc60
commit 578c9ad598
9 changed files with 46 additions and 8 deletions

View File

@ -51,6 +51,7 @@ class MusicStorage {
QString destination_;
Song metadata_;
bool overwrite_;
bool mark_as_listened_;
bool remove_original_;
ProgressFunction progress_;
};

View File

@ -39,7 +39,8 @@ const int Organise::kTranscodeProgressInterval = 500;
Organise::Organise(TaskManager* task_manager,
std::shared_ptr<MusicStorage> destination,
const OrganiseFormat& format, bool copy, bool overwrite,
const NewSongInfoList& songs_info, bool eject_after)
bool mark_as_listened,
const NewSongInfoList& songs_info, bool eject_after, QObject* caller)
: thread_(nullptr),
task_manager_(task_manager),
transcoder_(new Transcoder(this)),
@ -47,6 +48,7 @@ Organise::Organise(TaskManager* task_manager,
format_(format),
copy_(copy),
overwrite_(overwrite),
mark_as_listened_(mark_as_listened),
eject_after_(eject_after),
task_count_(songs_info.count()),
transcode_suffix_(1),
@ -59,6 +61,12 @@ Organise::Organise(TaskManager* task_manager,
for (const NewSongInfo& song_info : songs_info) {
tasks_pending_ << Task(song_info);
}
connect(this, SIGNAL(FileCopied(int)), caller, SLOT(FileCopied(int)));
}
Organise::~Organise()
{
disconnect(SIGNAL(FileCopied(int)));
}
void Organise::Start() {
@ -180,6 +188,7 @@ void Organise::ProcessSomeFiles() {
job.destination_ = task.song_info_.new_filename_;
job.metadata_ = song;
job.overwrite_ = overwrite_;
job.mark_as_listened_ = mark_as_listened_;
job.remove_original_ = !copy_;
job.progress_ = std::bind(&Organise::SetSongProgress, this, _1,
!task.transcoded_filename_.isEmpty());
@ -187,6 +196,11 @@ void Organise::ProcessSomeFiles() {
if (!destination_->CopyToStorage(job)) {
files_with_errors_ << task.song_info_.song_.basefilename();
}
else {
if(job.mark_as_listened_) {
emit FileCopied(job.metadata_.id());
}
}
// Clean up the temporary transcoded file
if (!task.transcoded_filename_.isEmpty())

View File

@ -44,9 +44,10 @@ class Organise : public QObject {
typedef QList<NewSongInfo> NewSongInfoList;
Organise(TaskManager* task_manager, std::shared_ptr<MusicStorage> destination,
const OrganiseFormat& format, bool copy, bool overwrite,
const NewSongInfoList& songs, bool eject_after);
const OrganiseFormat& format, bool copy, bool overwrite, bool mark_as_listened,
const NewSongInfoList& songs, bool eject_after, QObject* caller);
~Organise();
static const int kBatchSize;
static const int kTranscodeProgressInterval;
@ -54,6 +55,7 @@ class Organise : public QObject {
signals:
void Finished(const QStringList& files_with_errors);
void FileCopied(int database_id);
protected:
void timerEvent(QTimerEvent* e);
@ -90,6 +92,7 @@ signals:
const OrganiseFormat format_;
const bool copy_;
const bool overwrite_;
const bool mark_as_listened_;
const bool eject_after_;
int task_count_;

View File

@ -179,6 +179,7 @@ Song PodcastEpisode::ToSong(const Podcast& podcast) const {
ret.set_length_nanosec(kNsecPerSec * duration_secs());
ret.set_year(publication_date().date().year());
ret.set_comment(description());
ret.set_id(database_id());
if (ret.length_nanosec() < 0) {
ret.set_length_nanosec(-1);

View File

@ -58,7 +58,7 @@ PodcastService::PodcastService(Application* app, InternetModel* parent)
proxy_(new PodcastSortProxyModel(this)),
context_menu_(nullptr),
root_(nullptr),
organise_dialog_(new OrganiseDialog(app_->task_manager())) {
organise_dialog_(new OrganiseDialog(app_->task_manager(), nullptr, this)) {
icon_loader_->SetModel(model_);
proxy_->setSourceModel(model_);
proxy_->setDynamicSortFilter(true);
@ -476,6 +476,12 @@ void PodcastService::AddPodcast() {
add_podcast_dialog_->show();
}
void PodcastService::FileCopied(int database_id)
{
SetListened(PodcastEpisodeList() << backend_->GetEpisodeById(database_id),
true);
}
void PodcastService::SubscriptionAdded(const Podcast& podcast) {
// Ensure the root item is lazy loaded already
LazyLoadRoot();

View File

@ -65,6 +65,7 @@ class PodcastService : public InternetService {
public slots:
void AddPodcast();
void FileCopied(int database_id);
private slots:
void UpdateSelectedPodcast();

View File

@ -43,13 +43,14 @@ const char* OrganiseDialog::kDefaultFormat =
"%artist/%album{ (Disc %disc)}/{%track - }%title.%extension";
const char* OrganiseDialog::kSettingsGroup = "OrganiseDialog";
OrganiseDialog::OrganiseDialog(TaskManager* task_manager, QWidget* parent)
OrganiseDialog::OrganiseDialog(TaskManager* task_manager, QWidget* parent, QObject* caller)
: QDialog(parent),
ui_(new Ui_OrganiseDialog),
task_manager_(task_manager),
total_size_(0),
resized_by_user_(false) {
ui_->setupUi(this);
caller_=caller;
connect(ui_->button_box->button(QDialogButtonBox::Reset), SIGNAL(clicked()),
SLOT(Reset()));
@ -301,6 +302,7 @@ void OrganiseDialog::Reset() {
ui_->replace_spaces->setChecked(false);
ui_->replace_the->setChecked(false);
ui_->overwrite->setChecked(false);
ui_->mark_as_listened->setChecked(false);
ui_->eject_after->setChecked(false);
}
@ -314,6 +316,7 @@ void OrganiseDialog::showEvent(QShowEvent*) {
ui_->replace_spaces->setChecked(s.value("replace_spaces", false).toBool());
ui_->replace_the->setChecked(s.value("replace_the", false).toBool());
ui_->overwrite->setChecked(s.value("overwrite", false).toBool());
ui_->mark_as_listened->setChecked(s.value("mark_as_listened", false).toBool());
ui_->eject_after->setChecked(s.value("eject_after", false).toBool());
QString destination = s.value("destination").toString();
@ -331,6 +334,7 @@ void OrganiseDialog::accept() {
s.setValue("replace_spaces", ui_->replace_spaces->isChecked());
s.setValue("replace_the", ui_->replace_the->isChecked());
s.setValue("overwrite", ui_->overwrite->isChecked());
s.setValue("mark_as_listened", ui_->overwrite->isChecked());
s.setValue("destination", ui_->destination->currentText());
s.setValue("eject_after", ui_->eject_after->isChecked());
@ -346,7 +350,8 @@ void OrganiseDialog::accept() {
const bool copy = ui_->aftercopying->currentIndex() == 0;
Organise* organise = new Organise(
task_manager_, storage, format_, copy, ui_->overwrite->isChecked(),
new_songs_info_, ui_->eject_after->isChecked());
ui_->mark_as_listened->isChecked(),
new_songs_info_, ui_->eject_after->isChecked(), caller_);
connect(organise, SIGNAL(Finished(QStringList)),
SLOT(OrganiseFinished(QStringList)));
organise->Start();

View File

@ -41,13 +41,13 @@ class OrganiseDialog : public QDialog {
Q_OBJECT
public:
OrganiseDialog(TaskManager* task_manager, QWidget* parent = nullptr);
OrganiseDialog(TaskManager* task_manager, QWidget* parent = nullptr, QObject* caller = nullptr);
~OrganiseDialog();
static const char* kDefaultFormat;
static const char* kSettingsGroup;
QSize sizeHint() const;
QObject* caller_;
void SetDestinationModel(QAbstractItemModel* model, bool devices = false);

View File

@ -126,6 +126,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mark_as_listened">
<property name="text">
<string>Mark as listened</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>