[Patch] New option for files removing feature

Forum to talk about the development of SMPlayer (code, patches...).

[Patch] New option for files removing feature

Postby capt.d. » Sat May 14, 2016 1:08 pm

Aloha

I've added a potentially dangerous option :mrgreen: to the playlist's preferences tab. Now we can disable confirmation popup.
Tested on 16.1.0.

---
Live long and prosper.
capt.d.

Code: Select all
diff -up src/basegui.cpp ./basegui.cpp
--- src/basegui.cpp   2016-01-11 12:03:02.000000000 +0100
+++ ./basegui.cpp   2016-05-12 13:29:51.000000000 +0200
@@ -3026,7 +3026,7 @@ void BaseGui::showPreferencesDialog() {
    pl->setSavePlaylistOnExit(playlist->savePlaylistOnExit());
    pl->setPlayFilesFromStart(playlist->playFilesFromStart());
    pl->setIgnorePlayerErrors(playlist->ignorePlayerErrors());
-
+   pl->setAskMeAgainWhenRemovingFile(playlist->askMeAgainWhenRemovingFile());
    pref_dialog->show();
 }
 
@@ -3118,7 +3118,7 @@ void BaseGui::applyNewPreferences() {
    playlist->setSavePlaylistOnExit(pl->savePlaylistOnExit());
    playlist->setPlayFilesFromStart(pl->playFilesFromStart());
    playlist->setIgnorePlayerErrors(pl->ignorePlayerErrors());
-
+   playlist->setAskMeAgainWhenRemovingFile(pl->askMeAgainWhenRemovingFile());
 
    if (need_update_language) {
       translator->load(pref->language);
diff -up src/playlist.cpp ./playlist.cpp
--- src/playlist.cpp   2016-01-05 00:34:33.000000000 +0100
+++ ./playlist.cpp   2016-05-12 13:39:27.000000000 +0200
@@ -82,6 +82,8 @@ Playlist::Playlist( Core *c, QWidget * p
    automatically_play_next = true;
    ignore_player_errors = false;
 
+   ask_when_remove_file = true;
+
    row_spacing = -1; // Default height
 
    modified = false;
@@ -1357,12 +1359,14 @@ void Playlist::deleteSelectedFileFromDis
 
       QFileInfo fi(filename);
       if (fi.exists() && fi.isFile() && fi.isWritable()) {
-         // Ask the user for confirmation
-         int res = QMessageBox::question(this, tr("Confirm deletion"),
-                  tr("You're about to DELETE the file '%1' from your drive.").arg(filename) + "<br>"+
-                  tr("This action cannot be undone. Are you sure you want to proceed?"),
-                  QMessageBox::Yes, QMessageBox::No);
-
+         int res = QMessageBox::Yes;
+         if (ask_when_remove_file) {
+            // Ask the user for confirmation
+            res = QMessageBox::question(this, tr("Confirm deletion"),
+                     tr("You're about to DELETE the file '%1' from your drive.").arg(filename) + "<br>"+
+                     tr("This action cannot be undone. Are you sure you want to proceed?"),
+                     QMessageBox::Yes, QMessageBox::No);
+         }
          if (res == QMessageBox::Yes) {
             // Delete file
             bool success = QFile::remove(filename);
@@ -1489,7 +1493,7 @@ void Playlist::saveSettings() {
    set->setValue( "play_files_from_start", play_files_from_start );
    set->setValue( "automatically_play_next", automatically_play_next );
    set->setValue( "ignore_player_errors", ignore_player_errors );
-
+   set->setValue( "ask_when_remove_file", ask_when_remove_file );
    set->setValue( "row_spacing", row_spacing );
 
 #if !DOCK_PLAYLIST
@@ -1536,7 +1540,7 @@ void Playlist::loadSettings() {
    play_files_from_start = set->value( "play_files_from_start", play_files_from_start ).toBool();
    automatically_play_next = set->value( "automatically_play_next", automatically_play_next ).toBool();
    ignore_player_errors = set->value( "ignore_player_errors", ignore_player_errors ).toBool();
-
+   ask_when_remove_file = set->value( "ask_when_remove_file", ask_when_remove_file ).toBool();
    row_spacing = set->value( "row_spacing", row_spacing ).toInt();
 
 #if !DOCK_PLAYLIST
diff -up src/playlist.h ./playlist.h
--- src/playlist.h   2016-01-05 00:34:33.000000000 +0100
+++ ./playlist.h   2016-05-12 13:34:13.000000000 +0200
@@ -141,6 +141,7 @@ public slots:
    void setSavePlaylistOnExit(bool b) { save_playlist_in_config = b; };
    void setPlayFilesFromStart(bool b) { play_files_from_start = b; };
    void setIgnorePlayerErrors(bool b) { ignore_player_errors = b; };
+   void setAskMeAgainWhenRemovingFile(bool b) { ask_when_remove_file = b; };
 
 public:
    bool directoryRecursion() { return recursive_add_directory; };
@@ -148,6 +149,7 @@ public:
    bool savePlaylistOnExit() { return save_playlist_in_config; };
    bool playFilesFromStart() { return play_files_from_start; };
    bool ignorePlayerErrors() { return ignore_player_errors; };
+  bool askMeAgainWhenRemovingFile() { return ask_when_remove_file; };
 
    QList<PlaylistItem> playlist(){return pl;};
 
@@ -258,6 +260,7 @@ private:
 
    bool automatically_play_next;
    bool ignore_player_errors;
+   bool ask_when_remove_file;
 };
 
 
diff -up src/prefplaylist.cpp ./prefplaylist.cpp
--- src/prefplaylist.cpp   2016-01-05 00:34:33.000000000 +0100
+++ ./prefplaylist.cpp   2016-05-12 13:21:51.000000000 +0200
@@ -124,6 +124,14 @@ bool PrefPlaylist::ignorePlayerErrors()
    return ignore_errors_check->isChecked();
 }
 
+void PrefPlaylist::setAskMeAgainWhenRemovingFile(bool b){
+   ask_when_remove_file_check->setChecked(b);
+}
+
+bool PrefPlaylist::askMeAgainWhenRemovingFile(){
+   return ask_when_remove_file_check->isChecked();
+}
+
 void PrefPlaylist::createHelp() {
    clearHelp();
 
@@ -166,6 +174,9 @@ void PrefPlaylist::createHelp() {
    setWhatsThis(ignore_errors_check, tr("Play next file even if the previous file failed"),
       tr("If this option is enabled, the playlist will ignore playback errors from a previous file "
            "and will play the next file in the list.") );
+   
+   setWhatsThis(ask_when_remove_file_check, tr("Aks, whenever deleting file from disk."),
+      tr("Uncheck this to not see the prompt messagebox when removing file from disk.") );
 }
 
 #include "moc_prefplaylist.cpp"
diff -up src/prefplaylist.h ./prefplaylist.h
--- src/prefplaylist.h   2016-01-05 00:34:33.000000000 +0100
+++ ./prefplaylist.h   2016-05-12 12:09:48.000000000 +0200
@@ -56,6 +56,9 @@ public:
 
    void setIgnorePlayerErrors(bool b);
    bool ignorePlayerErrors();
+   
+   void setAskMeAgainWhenRemovingFile(bool b);
+   bool askMeAgainWhenRemovingFile();
 
 protected:
    virtual void createHelp();
diff -up src/prefplaylist.ui ./prefplaylist.ui
--- src/prefplaylist.ui   2015-02-07 01:59:06.000000000 +0100
+++ ./prefplaylist.ui   2016-05-12 13:02:05.000000000 +0200
@@ -133,6 +133,13 @@
         </widget>
        </item>
        <item>
+        <widget class="QCheckBox" name="ask_when_remove_file_check">
+         <property name="text">
+          <string>As&amp;k me when removing file from disk</string>
+         </property>
+        </widget>
+       </item>
+       <item>
         <spacer>
          <property name="orientation">
           <enum>Qt::Vertical</enum>
capt.d.
 
Posts: 9
Joined: Sun Dec 08, 2013 7:02 pm

Return to Development

Who is online

Users browsing this forum: No registered users and 1 guest