From 2a1cf9a16d15506f9693338a8cd1d174e5e98805 Mon Sep 17 00:00:00 2001 From: Nikolay Tischenko Date: Sat, 18 Dec 2010 18:03:20 +0600 Subject: [PATCH] Confirmation dialogs for dangerous actions --- src/mainwindow.cpp | 1 + src/managelibraryform.cpp | 6 ++++++ src/playerform.cpp | 1 + src/someplayer.h | 6 ++++++ 4 files changed, 14 insertions(+) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 681dd02..e997150 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -215,6 +215,7 @@ void MainWindow::_save_playlist() { } void MainWindow::_clear_current_playlist() { + CONFIRM_ACTION(this, tr("Clear playlist?")) Playlist playlist = _library->getCurrentPlaylist(); playlist.clear(); _library->saveCurrentPlaylist(playlist); diff --git a/src/managelibraryform.cpp b/src/managelibraryform.cpp index c038ef1..171d39c 100644 --- a/src/managelibraryform.cpp +++ b/src/managelibraryform.cpp @@ -120,6 +120,10 @@ void ManageLibraryForm::_process_selection(QItemSelection selected, QItemSelecti void ManageLibraryForm::_delete_selected() { QList directories; QModelIndexList idx = ui->dirView->selectionModel()->selectedIndexes(); + if (idx.count() == 0) { + return; + } + CONFIRM_ACTION(this, tr("Delete selected directories?")) foreach (QModelIndex id, idx) { if (id.column() == 1) { QString path = id.data().toString(); @@ -138,6 +142,7 @@ void ManageLibraryForm::_delete_selected() { } void ManageLibraryForm::_update_selected() { + CONFIRM_ACTION(this, tr("Update selected directories? It may takes several minutes")) QList directories; QModelIndexList idx = ui->dirView->selectionModel()->selectedIndexes(); foreach (QModelIndex id, idx) { @@ -157,6 +162,7 @@ void ManageLibraryForm::_update_selected() { } void ManageLibraryForm::_update_all() { + CONFIRM_ACTION(this, tr("Update all library? It may takes a long time")) _library->updateAll(); refresh(); emit refreshLibrary(); diff --git a/src/playerform.cpp b/src/playerform.cpp index c9111a9..945e380 100644 --- a/src/playerform.cpp +++ b/src/playerform.cpp @@ -264,6 +264,7 @@ void PlayerForm::_custom_context_menu_requested(const QPoint &pos) { } void PlayerForm::_delete_track() { + CONFIRM_ACTION(this, tr("Delete track?")) QList idx = ui->playlistView->selectionModel()->selectedIndexes(); if (idx.isEmpty()) return; diff --git a/src/someplayer.h b/src/someplayer.h index 869103c..4896b27 100644 --- a/src/someplayer.h +++ b/src/someplayer.h @@ -44,6 +44,7 @@ namespace SomePlayer { #include #include #include +#include #include "config.h" #define _DYNAMIC_PLAYLIST_MAX_COUNT_ 50 @@ -54,4 +55,9 @@ namespace SomePlayer { #define _APPLICATION_PATH_ "/opt/someplayer" +#define CONFIRM_ACTION(PARENT, TEXT) \ + if (QMessageBox::question(PARENT, tr("Confirm action"), \ + TEXT, QMessageBox::Ok, QMessageBox::Cancel) != QMessageBox::Ok) \ + {return;} + #endif -- 1.7.9.5