Center organise and transcoder dialog on same screen as mainwindow

This commit is contained in:
Jonas Kvinge
2020-04-07 01:26:17 +02:00
parent 3074377b55
commit 307961cc7e
12 changed files with 260 additions and 152 deletions

View File

@@ -534,7 +534,7 @@ SongList CollectionView::GetSelectedSongs() const {
void CollectionView::Organise() {
if (!organise_dialog_)
organise_dialog_.reset(new OrganiseDialog(app_->task_manager(), app_->collection_backend()));
organise_dialog_.reset(new OrganiseDialog(app_->task_manager(), app_->collection_backend(), this));
organise_dialog_->SetDestinationModel(app_->collection_model()->directory_model());
organise_dialog_->SetCopy(false);
@@ -568,15 +568,17 @@ void CollectionView::RescanSongs() {
}
void CollectionView::CopyToDevice() {
#ifndef Q_OS_WIN
if (!organise_dialog_)
organise_dialog_.reset(new OrganiseDialog(app_->task_manager()));
organise_dialog_.reset(new OrganiseDialog(app_->task_manager(), nullptr, this));
organise_dialog_->SetDestinationModel(app_->device_manager()->connected_devices_model(), true);
organise_dialog_->SetCopy(true);
organise_dialog_->SetSongs(GetSelectedSongs());
organise_dialog_->show();
#endif
}
void CollectionView::FilterReturnPressed() {

View File

@@ -372,7 +372,7 @@ SongList ContextAlbumsView::GetSelectedSongs() const {
void ContextAlbumsView::Organise() {
if (!organise_dialog_)
organise_dialog_.reset(new OrganiseDialog(app_->task_manager()));
organise_dialog_.reset(new OrganiseDialog(app_->task_manager(), app_->collection_backend(), this));
organise_dialog_->SetDestinationModel(app_->collection_model()->directory_model());
organise_dialog_->SetCopy(false);
@@ -381,6 +381,7 @@ void ContextAlbumsView::Organise() {
else {
QMessageBox::warning(this, tr("Error"), tr("None of the selected songs were suitable for copying to a device"));
}
}
void ContextAlbumsView::EditTracks() {

View File

@@ -219,10 +219,14 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
}),
equalizer_(new Equalizer),
organise_dialog_([=]() {
OrganiseDialog *dialog = new OrganiseDialog(app->task_manager(), app->collection_backend());
OrganiseDialog *dialog = new OrganiseDialog(app->task_manager(), app->collection_backend(), this);
dialog->SetDestinationModel(app->collection()->model()->directory_model());
return dialog;
}),
transcode_dialog_([=]() {
TranscodeDialog *dialog = new TranscodeDialog(this);
return dialog;
}),
#ifdef HAVE_SUBSONIC
subsonic_view_(new InternetSongsView(app_, app->internet_services()->ServiceBySource(Song::Source_Subsonic), SubsonicSettingsPage::kSettingsGroup, SettingsDialog::Page_Subsonic, this)),
#endif

View File

@@ -222,8 +222,8 @@ class MainWindow : public QMainWindow, public PlatformInterface {
void ShowCoverManager();
void ShowAboutDialog();
void ShowTranscodeDialog();
void ShowErrorDialog(const QString& message);
void ShowTranscodeDialog();
SettingsDialog *CreateSettingsDialog();
EditTagDialog *CreateEditTagDialog();
void OpenSettingsDialog();
@@ -300,14 +300,14 @@ class MainWindow : public QMainWindow, public PlatformInterface {
PlaylistListContainer *playlist_list_;
QueueView *queue_view_;
Lazy<ErrorDialog> error_dialog_;
Lazy<SettingsDialog> settings_dialog_;
Lazy<AlbumCoverManager> cover_manager_;
std::unique_ptr<Equalizer> equalizer_;
Lazy<OrganiseDialog> organise_dialog_;
#ifdef HAVE_GSTREAMER
Lazy<TranscodeDialog> transcode_dialog_;
#endif
Lazy<ErrorDialog> error_dialog_;
Lazy<OrganiseDialog> organise_dialog_;
#if defined(HAVE_GSTREAMER) && defined(HAVE_CHROMAPRINT)
std::unique_ptr<TagFetcher> tag_fetcher_;

View File

@@ -205,7 +205,7 @@ void DeviceView::SetApplication(Application *app) {
properties_dialog_->SetDeviceManager(app_->device_manager());
organise_dialog_.reset(new OrganiseDialog(app_->task_manager()));
organise_dialog_.reset(new OrganiseDialog(app_->task_manager(), nullptr, this));
organise_dialog_->SetDestinationModel(app_->collection_model()->directory_model());
}

View File

@@ -28,6 +28,8 @@
#include <QtConcurrentRun>
#include <QAbstractItemModel>
#include <QDialog>
#include <QScreen>
#include <QWindow>
#include <QHash>
#include <QMap>
#include <QDir>
@@ -49,6 +51,7 @@
#include <QToolButton>
#include <QFlags>
#include <QShowEvent>
#include <QCloseEvent>
#include <QSettings>
#include "core/closure.h"
@@ -65,21 +68,22 @@
#include "organiseerrordialog.h"
#include "ui_organisedialog.h"
using std::shared_ptr;
using std::stable_sort;
const char *OrganiseDialog::kDefaultFormat = "%albumartist/%album{ (Disc %disc)}/{%track - }{%albumartist - }%album{ (Disc %disc)} - %title.%extension";
const char *OrganiseDialog::kSettingsGroup = "OrganiseDialog";
OrganiseDialog::OrganiseDialog(TaskManager *task_manager, CollectionBackend *backend, QWidget *parent)
OrganiseDialog::OrganiseDialog(TaskManager *task_manager, CollectionBackend *backend, QWidget *parentwindow, QWidget *parent)
: QDialog(parent),
parentwindow_(parentwindow),
ui_(new Ui_OrganiseDialog),
task_manager_(task_manager),
backend_(backend),
total_size_(0) {
ui_->setupUi(this);
setWindowFlags(windowFlags()|Qt::WindowMaximizeButtonHint);
connect(ui_->button_box->button(QDialogButtonBox::Reset), SIGNAL(clicked()), SLOT(Reset()));
ui_->aftercopying->setItemIcon(1, IconLoader::Load("edit-delete"));
@@ -131,13 +135,6 @@ OrganiseDialog::OrganiseDialog(TaskManager *task_manager, CollectionBackend *bac
ui_->insert->setMenu(tag_menu);
QSettings s;
s.beginGroup(kSettingsGroup);
if (s.contains("geometry")) {
restoreGeometry(s.value("geometry").toByteArray());
}
s.endGroup();
}
OrganiseDialog::~OrganiseDialog() {
@@ -149,6 +146,134 @@ void OrganiseDialog::SetDestinationModel(QAbstractItemModel *model, bool devices
ui_->destination->setModel(model);
ui_->eject_after->setVisible(devices);
}
void OrganiseDialog::showEvent(QShowEvent*) {
LoadGeometry();
LoadSettings();
}
void OrganiseDialog::closeEvent(QCloseEvent*) {
SaveGeometry();
}
void OrganiseDialog::accept() {
SaveSettings();
const QModelIndex destination = ui_->destination->model()->index(ui_->destination->currentIndex(), 0);
std::shared_ptr<MusicStorage> storage = destination.data(MusicStorage::Role_StorageForceConnect).value<std::shared_ptr<MusicStorage>>();
if (!storage) return;
// It deletes itself when it's finished.
const bool copy = ui_->aftercopying->currentIndex() == 0;
Organise *organise = new Organise(task_manager_, storage, format_, copy, ui_->overwrite->isChecked(), ui_->mark_as_listened->isChecked(), ui_->albumcover->isChecked(), new_songs_info_, ui_->eject_after->isChecked(), playlist_);
connect(organise, SIGNAL(Finished(QStringList, QStringList)), SLOT(OrganiseFinished(QStringList, QStringList)));
connect(organise, SIGNAL(FileCopied(int)), this, SIGNAL(FileCopied(int)));
if (backend_)
connect(organise, SIGNAL(SongPathChanged(const Song&, const QFileInfo&)), backend_, SLOT(SongPathChanged(const Song&, const QFileInfo&)));
organise->Start();
SaveGeometry();
QDialog::accept();
}
void OrganiseDialog::reject() {
SaveGeometry();
QDialog::reject();
}
void OrganiseDialog::LoadGeometry() {
if (parentwindow_) {
QSettings s;
s.beginGroup(kSettingsGroup);
if (s.contains("geometry")) {
restoreGeometry(s.value("geometry").toByteArray());
}
s.endGroup();
// Center the window on the same screen as the parentwindow.
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QScreen *screen = parentwindow_->screen();
#else
QScreen *screen = (parentwindow_->window() && parentwindow_->window()->windowHandle() ? parentwindow_->window()->windowHandle()->screen() : nullptr);
#endif
if (screen) {
const QRect sr = screen->availableGeometry();
const QRect wr({}, size().boundedTo(sr.size()));
resize(wr.size());
move(sr.center() - wr.center());
}
}
}
void OrganiseDialog::SaveGeometry() {
if (parentwindow_) {
QSettings s;
s.beginGroup(kSettingsGroup);
s.setValue("geometry", saveGeometry());
s.endGroup();
}
}
void OrganiseDialog::LoadSettings() {
QSettings s;
s.beginGroup(kSettingsGroup);
ui_->naming->setPlainText(s.value("format", kDefaultFormat).toString());
ui_->remove_non_fat->setChecked(s.value("remove_non_fat", false).toBool());
ui_->remove_non_ascii->setChecked(s.value("remove_non_ascii", false).toBool());
ui_->allow_ascii_ext->setChecked(s.value("allow_ascii_ext", false).toBool());
ui_->replace_spaces->setChecked(s.value("replace_spaces", true).toBool());
ui_->overwrite->setChecked(s.value("overwrite", false).toBool());
ui_->albumcover->setChecked(s.value("albumcover", true).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();
int index = ui_->destination->findText(destination);
if (index != -1 && !destination.isEmpty()) {
ui_->destination->setCurrentIndex(index);
}
s.endGroup();
AllowExtASCII(ui_->remove_non_ascii->isChecked());
}
void OrganiseDialog::SaveSettings() {
QSettings s;
s.beginGroup(kSettingsGroup);
s.setValue("format", ui_->naming->toPlainText());
s.setValue("remove_non_fat", ui_->remove_non_fat->isChecked());
s.setValue("remove_non_ascii", ui_->remove_non_ascii->isChecked());
s.setValue("allow_ascii_ext", ui_->allow_ascii_ext->isChecked());
s.setValue("replace_spaces", ui_->replace_spaces->isChecked());
s.setValue("overwrite", ui_->overwrite->isChecked());
s.setValue("mark_as_listened", ui_->overwrite->isChecked());
s.setValue("albumcover", ui_->albumcover->isChecked());
s.setValue("destination", ui_->destination->currentText());
s.setValue("eject_after", ui_->eject_after->isChecked());
s.endGroup();
}
bool OrganiseDialog::SetSongs(const SongList &songs) {
@@ -354,86 +479,6 @@ void OrganiseDialog::Reset() {
}
void OrganiseDialog::showEvent(QShowEvent*) {
QSettings s;
s.beginGroup(kSettingsGroup);
ui_->naming->setPlainText(s.value("format", kDefaultFormat).toString());
ui_->remove_non_fat->setChecked(s.value("remove_non_fat", false).toBool());
ui_->remove_non_ascii->setChecked(s.value("remove_non_ascii", false).toBool());
ui_->allow_ascii_ext->setChecked(s.value("allow_ascii_ext", false).toBool());
ui_->replace_spaces->setChecked(s.value("replace_spaces", true).toBool());
ui_->overwrite->setChecked(s.value("overwrite", false).toBool());
ui_->albumcover->setChecked(s.value("albumcover", true).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();
int index = ui_->destination->findText(destination);
if (index != -1 && !destination.isEmpty()) {
ui_->destination->setCurrentIndex(index);
}
s.endGroup();
AllowExtASCII(ui_->remove_non_ascii->isChecked());
}
void OrganiseDialog::accept() {
QSettings s;
s.beginGroup(kSettingsGroup);
s.setValue("format", ui_->naming->toPlainText());
s.setValue("remove_non_fat", ui_->remove_non_fat->isChecked());
s.setValue("remove_non_ascii", ui_->remove_non_ascii->isChecked());
s.setValue("allow_ascii_ext", ui_->allow_ascii_ext->isChecked());
s.setValue("replace_spaces", ui_->replace_spaces->isChecked());
s.setValue("overwrite", ui_->overwrite->isChecked());
s.setValue("mark_as_listened", ui_->overwrite->isChecked());
s.setValue("albumcover", ui_->albumcover->isChecked());
s.setValue("destination", ui_->destination->currentText());
s.setValue("eject_after", ui_->eject_after->isChecked());
s.endGroup();
const QModelIndex destination = ui_->destination->model()->index(ui_->destination->currentIndex(), 0);
std::shared_ptr<MusicStorage> storage = destination.data(MusicStorage::Role_StorageForceConnect).value<std::shared_ptr<MusicStorage>>();
if (!storage) return;
// It deletes itself when it's finished.
const bool copy = ui_->aftercopying->currentIndex() == 0;
Organise *organise = new Organise(task_manager_, storage, format_, copy, ui_->overwrite->isChecked(), ui_->mark_as_listened->isChecked(), ui_->albumcover->isChecked(), new_songs_info_, ui_->eject_after->isChecked(), playlist_);
connect(organise, SIGNAL(Finished(QStringList, QStringList)), SLOT(OrganiseFinished(QStringList, QStringList)));
connect(organise, SIGNAL(FileCopied(int)), this, SIGNAL(FileCopied(int)));
if (backend_)
connect(organise, SIGNAL(SongPathChanged(const Song&, const QFileInfo&)), backend_, SLOT(SongPathChanged(const Song&, const QFileInfo&)));
organise->Start();
SaveGeometry();
QDialog::accept();
}
void OrganiseDialog::reject() {
SaveGeometry();
QDialog::reject();
}
void OrganiseDialog::SaveGeometry() {
QSettings s;
s.beginGroup(kSettingsGroup);
s.setValue("geometry", saveGeometry());
s.endGroup();
}
void OrganiseDialog::OrganiseFinished(const QStringList files_with_errors, const QStringList log) {
if (files_with_errors.isEmpty()) return;

View File

@@ -45,6 +45,7 @@ class QAbstractItemModel;
class QWidget;
class QResizeEvent;
class QShowEvent;
class QCloseEvent;
class TaskManager;
class CollectionBackend;
@@ -55,7 +56,7 @@ class OrganiseDialog : public QDialog {
Q_OBJECT
public:
OrganiseDialog(TaskManager *task_manager, CollectionBackend *backend = nullptr, QWidget *parent = nullptr);
OrganiseDialog(TaskManager *task_manager, CollectionBackend *backend = nullptr, QWidget *parentwindow = nullptr, QWidget *parent = nullptr);
~OrganiseDialog();
static const char *kDefaultFormat;
@@ -76,6 +77,19 @@ class OrganiseDialog : public QDialog {
void SetPlaylist(const QString &playlist);
protected:
void showEvent(QShowEvent*);
void closeEvent(QCloseEvent*);
private:
void LoadGeometry();
void SaveGeometry();
void LoadSettings();
void SaveSettings();
SongList LoadSongsBlocking(const QStringList &filenames);
void SetLoadingSongs(bool loading);
signals:
void FileCopied(int);
@@ -83,9 +97,6 @@ class OrganiseDialog : public QDialog {
void accept();
void reject();
protected:
void showEvent(QShowEvent *);
private slots:
void Reset();
@@ -96,15 +107,10 @@ class OrganiseDialog : public QDialog {
void AllowExtASCII(bool checked);
void SaveGeometry();
private:
SongList LoadSongsBlocking(const QStringList &filenames);
void SetLoadingSongs(bool loading);
private:
static const char *kSettingsGroup;
QWidget *parentwindow_;
Ui_OrganiseDialog *ui_;
TaskManager *task_manager_;
CollectionBackend *backend_;

View File

@@ -17,7 +17,7 @@
<iconset resource="../../data/icons.qrc">
<normaloff>:/icons/64x64/strawberry.png</normaloff>:/icons/64x64/strawberry.png</iconset>
</property>
<layout class="QVBoxLayout" name="layout_dialog">
<layout class="QVBoxLayout" name="layout_organisedialog">
<item>
<layout class="QFormLayout" name="layout_copying">
<item row="0" column="0">

View File

@@ -25,6 +25,10 @@
#include <QtGlobal>
#include <QWidget>
#include <QDialog>
#include <QScreen>
#include <QWindow>
#include <QGuiApplication>
#include <QMainWindow>
#include <QAbstractItemModel>
#include <QtAlgorithms>
#include <QDir>
@@ -49,6 +53,8 @@
#include <QDialogButtonBox>
#include <QSettings>
#include <QTimerEvent>
#include <QShowEvent>
#include <QCloseEvent>
#include "core/iconloader.h"
#include "core/mainwindow.h"
@@ -74,8 +80,9 @@ static bool ComparePresetsByName(const TranscoderPreset &left, const TranscoderP
return left.name_ < right.name_;
}
TranscodeDialog::TranscodeDialog(QWidget *parent)
TranscodeDialog::TranscodeDialog(QMainWindow *mainwindow, QWidget *parent)
: QDialog(parent),
mainwindow_(mainwindow),
ui_(new Ui_TranscodeDialog),
log_ui_(new Ui_TranscodeLogDialog),
log_dialog_(new QDialog(this)),
@@ -85,6 +92,9 @@ TranscodeDialog::TranscodeDialog(QWidget *parent)
finished_failed_(0) {
ui_->setupUi(this);
setWindowFlags(windowFlags()|Qt::WindowMaximizeButtonHint);
ui_->files->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
log_ui_->setupUi(log_dialog_);
@@ -101,12 +111,8 @@ TranscodeDialog::TranscodeDialog(QWidget *parent)
// Load settings
QSettings s;
s.beginGroup(kSettingsGroup);
if (s.contains("geometry")) {
restoreGeometry(s.value("geometry").toByteArray());
}
last_add_dir_ = s.value("last_add_dir", QDir::homePath()).toString();
last_import_dir_ = s.value("last_import_dir", QDir::homePath()).toString();
QString last_output_format = s.value("last_output_format", "audio/x-vorbis").toString();
s.endGroup();
@@ -150,6 +156,65 @@ TranscodeDialog::~TranscodeDialog() {
delete ui_;
}
void TranscodeDialog::showEvent(QShowEvent*) {
LoadGeometry();
}
void TranscodeDialog::closeEvent(QCloseEvent*) {
SaveGeometry();
}
void TranscodeDialog::accept() {
SaveGeometry();
QDialog::accept();
}
void TranscodeDialog::reject() {
SaveGeometry();
QDialog::reject();
}
void TranscodeDialog::LoadGeometry() {
QSettings s;
s.beginGroup(kSettingsGroup);
if (s.contains("geometry")) {
restoreGeometry(s.value("geometry").toByteArray());
}
s.endGroup();
// Center the window on the same screen as the mainwindow.
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QScreen *screen = mainwindow_->screen();
#else
QScreen *screen = (mainwindow_->window() && mainwindow_->window()->windowHandle() ? mainwindow_->window()->windowHandle()->screen() : nullptr);
#endif
if (screen) {
const QRect sr = screen->availableGeometry();
const QRect wr({}, size().boundedTo(sr.size()));
resize(wr.size());
move(sr.center() - wr.center());
}
}
void TranscodeDialog::SaveGeometry() {
QSettings s;
s.beginGroup(kSettingsGroup);
s.setValue("geometry", saveGeometry());
s.endGroup();
}
void TranscodeDialog::SetWorking(bool working) {
start_button_->setVisible(!working);
@@ -390,25 +455,3 @@ QString TranscodeDialog::GetOutputFileName(const QString &input, const Transcode
}
void TranscodeDialog::SaveGeometry() {
QSettings s;
s.beginGroup(kSettingsGroup);
s.setValue("geometry", saveGeometry());
s.endGroup();
}
void TranscodeDialog::accept() {
SaveGeometry();
QDialog::accept();
}
void TranscodeDialog::reject() {
SaveGeometry();
QDialog::reject();
}

View File

@@ -30,8 +30,11 @@
#include <QStringList>
class QWidget;
class QMainWindow;
class QPushButton;
class QTimerEvent;
class QShowEvent;
class QCloseEvent;
class Transcoder;
class Ui_TranscodeDialog;
class Ui_TranscodeLogDialog;
@@ -41,7 +44,7 @@ class TranscodeDialog : public QDialog {
Q_OBJECT
public:
TranscodeDialog(QWidget *parent = nullptr);
TranscodeDialog(QMainWindow *mainwindow, QWidget *parent = nullptr);
~TranscodeDialog();
static const char *kSettingsGroup;
@@ -51,8 +54,19 @@ class TranscodeDialog : public QDialog {
void SetFilenames(const QStringList &filenames);
protected:
void showEvent(QShowEvent*);
void closeEvent(QCloseEvent*);
void timerEvent(QTimerEvent *e);
private:
void LoadGeometry();
void SaveGeometry();
void SetWorking(bool working);
void UpdateStatusText();
void UpdateProgress();
QString TrimPath(const QString &path) const;
QString GetOutputFileName(const QString &input, const TranscoderPreset &preset) const;
private slots:
void Add();
void Import();
@@ -68,14 +82,7 @@ class TranscodeDialog : public QDialog {
void reject();
private:
void SetWorking(bool working);
void UpdateStatusText();
void UpdateProgress();
QString TrimPath(const QString &path) const;
QString GetOutputFileName(const QString &input, const TranscoderPreset &preset) const;
void SaveGeometry();
private:
QMainWindow *mainwindow_;
Ui_TranscodeDialog *ui_;
Ui_TranscodeLogDialog *log_ui_;
QDialog *log_dialog_;

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>499</width>
<height>448</height>
<width>500</width>
<height>450</height>
</rect>
</property>
<property name="windowTitle">
@@ -17,7 +17,7 @@
<iconset>
<normaloff>:/icons/64x64/strawberry.png</normaloff>:/icons/64x64/strawberry.png</iconset>
</property>
<layout class="QVBoxLayout" name="layout_dialog">
<layout class="QVBoxLayout" name="layout_transcodedialog">
<item>
<widget class="QGroupBox" name="input_group">
<property name="title">

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>676</width>
<height>358</height>
<width>680</width>
<height>360</height>
</rect>
</property>
<property name="windowTitle">
@@ -17,7 +17,7 @@
<iconset resource="../../data/icons.qrc">
<normaloff>:/icons/64x64/strawberry.png</normaloff>:/icons/64x64/strawberry.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="layout_transcodelogdialog">
<item>
<widget class="QPlainTextEdit" name="log">
<property name="readOnly">