Confirmation dialogs for dangerous actions
authorNikolay Tischenko <niktischenko@gmail.com>
Sat, 18 Dec 2010 12:03:20 +0000 (18:03 +0600)
committerNikolay Tischenko <niktischenko@gmail.com>
Sat, 18 Dec 2010 12:03:20 +0000 (18:03 +0600)
src/mainwindow.cpp
src/managelibraryform.cpp
src/playerform.cpp
src/someplayer.h

index 681dd02..e997150 100644 (file)
@@ -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);
index c038ef1..171d39c 100644 (file)
@@ -120,6 +120,10 @@ void ManageLibraryForm::_process_selection(QItemSelection selected, QItemSelecti
 void ManageLibraryForm::_delete_selected() {
        QList<QString> 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<QString> 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();
index c9111a9..945e380 100644 (file)
@@ -264,6 +264,7 @@ void PlayerForm::_custom_context_menu_requested(const QPoint &pos) {
 }
 
 void PlayerForm::_delete_track() {
+       CONFIRM_ACTION(this, tr("Delete track?"))
        QList<QModelIndex> idx = ui->playlistView->selectionModel()->selectedIndexes();
        if (idx.isEmpty())
                return;
index 869103c..4896b27 100644 (file)
@@ -44,6 +44,7 @@ namespace SomePlayer {
 #include <QList>
 #include <QMap>
 #include <QUrl>
+#include <QMessageBox>
 #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