Refactor simple dialogs to use Lazy

This commit is contained in:
John Maguire 2016-02-12 16:01:35 +00:00
parent 74e6a1744f
commit b99b090adc
3 changed files with 6 additions and 17 deletions

View File

@ -29,6 +29,9 @@ class Lazy {
public:
explicit Lazy(std::function<T*()> init) : init_(init) {}
// Convenience constructor that will lazily default construct the object.
Lazy() : init_([]() { return new T; }) {}
T* get() const {
CheckInitialised();
return ptr_.get();

View File

@ -2196,10 +2196,6 @@ void MainWindow::PlaylistUndoRedoChanged(QAction* undo, QAction* redo) {
}
void MainWindow::AddFilesToTranscoder() {
if (!transcode_dialog_) {
transcode_dialog_.reset(new TranscodeDialog);
}
QStringList filenames;
for (const QModelIndex& index :
@ -2475,24 +2471,14 @@ EditTagDialog* MainWindow::CreateEditTagDialog() {
}
void MainWindow::ShowAboutDialog() {
if (!about_dialog_) {
about_dialog_.reset(new About);
}
about_dialog_->show();
}
void MainWindow::ShowTranscodeDialog() {
if (!transcode_dialog_) {
transcode_dialog_.reset(new TranscodeDialog);
}
transcode_dialog_->show();
}
void MainWindow::ShowErrorDialog(const QString& message) {
if (!error_dialog_) {
error_dialog_.reset(new ErrorDialog);
}
error_dialog_->ShowMessage(message);
}

View File

@ -297,7 +297,7 @@ signals:
SystemTrayIcon* tray_icon_;
OSD* osd_;
Lazy<EditTagDialog> edit_tag_dialog_;
std::unique_ptr<About> about_dialog_;
Lazy<About> about_dialog_;
GlobalShortcuts* global_shortcuts_;
@ -318,8 +318,8 @@ signals:
std::unique_ptr<AddStreamDialog> add_stream_dialog_;
std::unique_ptr<AlbumCoverManager> cover_manager_;
std::unique_ptr<Equalizer> equalizer_;
std::unique_ptr<TranscodeDialog> transcode_dialog_;
std::unique_ptr<ErrorDialog> error_dialog_;
Lazy<TranscodeDialog> transcode_dialog_;
Lazy<ErrorDialog> error_dialog_;
Lazy<OrganiseDialog> organise_dialog_;
std::unique_ptr<QueueManager> queue_manager_;