[PATCH] Removing files using playlist

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

[PATCH] Removing files using playlist

Postby capt.d. » Mon Dec 09, 2013 12:41 pm

Aloha everyone

I've made a little patch for 0.8.5. Now you can remove file from your drive when playlist is active. Press F8 key or right click on song/video and Delete. You can also change the key on actions' editor. Action's name is pl_delete.
Maybe it will be useful for someone.

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

Code: Select all
--- playlist.cpp   2013-12-05 22:26:01.000000000 +0100
+++ playlist.cpp.new   2013-12-08 19:26:32.000000000 +0100
@@ -228,6 +228,11 @@
    // Edit
    editAct = new MyAction(this, "pl_edit", false);
    connect( editAct, SIGNAL(triggered()), this, SLOT(editCurrentItem()) );
+
+   // EDIT BY capt.d.
+   deleteAct = new MyAction(Qt::Key_F8, this, "pl_delete");
+   connect( deleteAct, SIGNAL(triggered()), this, SLOT(deleteItem()));
+   // <--
 }
 
 void Playlist::createToolbar() {
@@ -277,6 +282,10 @@
    popup->addAction(removeSelectedAct);
    popup->addAction(editAct);
 
+   // EDIT BY capt.d.
+     popup->addAction(deleteAct);
+     // <--
+
    connect( listView, SIGNAL(customContextMenuRequested(const QPoint &)),
              this, SLOT(showPopup(const QPoint &)) );
 }
@@ -331,6 +340,11 @@
    // Icon
    setWindowIcon( Images::icon("logo", 64) );
    setWindowTitle( tr( "SMPlayer - Playlist" ) );
+
+     //EDIT BY capt.d.
+     deleteAct->change(tr("Delete file"));
+     // <---
+
 }
 
 void Playlist::list() {
@@ -1482,4 +1496,28 @@
    }
 }
 
+//EDIT BY capt.d.
+void Playlist::deleteItem() {
+   int current = listView->currentRow();
+   if (current > -1) {
+        int res = QMessageBox::question( this,
+         tr("Confirm please."),
+                   tr("Deleting %1").arg(pl[current].filename().toUtf8().data()),
+                   QMessageBox::Yes,
+                   QMessageBox::No);
+        switch (res) {
+         case QMessageBox::No : return; // Discard changes
+         case QMessageBox::Yes :   {
+                if (!unlink(pl[current].filename().toUtf8().data())) {
+                        removeSelected();   
+                }
+             }
+            default : return;
+         };
+      };
+}   
+//<--
+
+
+
 #include "moc_playlist.cpp"


Code: Select all
--- playlist.h   2013-12-05 22:26:07.000000000 +0100
+++ playlist.h.new   2013-12-05 22:11:11.000000000 +0100
@@ -115,6 +115,10 @@
    // EDIT BY NEO -->
    virtual void sortBy(int section);
    // <--
+   
+   // EDIT BY capt.d.
+   virtual void deleteItem();
+   // <--
 
    virtual bool maybeSave();
     virtual void load();
@@ -233,6 +237,10 @@
    MyAction * removeSelectedAct;
    MyAction * removeAllAct;
 
+   // EDIT BY capt.d.
+   MyAction * deleteAct;
+   // <--
+
 private:
    bool modified;
    QTimer * save_timer;

Code: Select all
--- default.keys  2013-12-09 12:35:33.000000000 +0100
+++ default.keys.new  2013-12-09 12:35:27.000000000 +0100
@@ -241,3 +241,4 @@
 edit_floating_control
 show_main_toolbar  F5
 show_language_toolbar  F6
+pl_delete  F8
capt.d.
 
Posts: 9
Joined: Sun Dec 08, 2013 7:02 pm

Re: [PATCH] Removing files using playlist

Postby rhill » Fri Apr 11, 2014 5:37 am

I can't tell you how long I've wanted this feature. I've been using this patch for a couple of months now and it works great. Thanks.
Now, if you could make this work without having to open the playlist it'd be perfect. :D

One small bug: src/playlist.cpp calls unlink() so you'll need to #include <unistd.h>. Otherwise it'll fail to build on >= GCC 4.7.
rhill
 
Posts: 5
Joined: Fri Apr 11, 2014 5:17 am

Re: [PATCH] Removing files using playlist

Postby capt.d. » Sun Apr 27, 2014 9:03 am

Aloha
It's nice to hear, that it's useful for you. Below you've got new patches, put them on the fresh sources.

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

Code: Select all
--- playlist.h   2013-05-02 00:21:53.000000000 +0200
+++ playlist.h.new   2014-04-27 11:31:29.000000000 +0200
@@ -79,6 +79,7 @@
 
    bool isModified() { return modified; };
 
+
 public slots:
    void addItem(QString filename, QString name, double duration);
 
@@ -116,9 +117,13 @@
    virtual void sortBy(int section);
    // <--
 
+   // edit by capt.d.
+   void confirmDelete(void);
+   // <---
+
    virtual bool maybeSave();
-    virtual void load();
-    virtual bool save();
+  virtual void load();
+  virtual bool save();
 
    virtual void load_m3u(QString file);
    virtual bool save_m3u(QString file);
@@ -234,6 +239,10 @@
    MyAction * removeAllAct;
 
 private:
+   // edit by capt.d.
+   MyAction * deleteAct;
+   //<--
+   
    bool modified;
    QTimer * save_timer;
 


Code: Select all
--- playlist.cpp   2013-05-02 00:21:53.000000000 +0200
+++ playlist.cpp.new   2014-04-27 11:28:25.000000000 +0200
@@ -55,6 +55,10 @@
 
 #include <stdlib.h>
 
+// edit by capt.d. -->
+#include <unistd.h>
+//<--
+
 #if USE_INFOPROVIDER
 #include "infoprovider.h"
 #endif
@@ -83,8 +87,8 @@
    modified = false;
 
    core = c;
-    playlist_path = "";
-    latest_dir = "";
+       playlist_path = "";
+   latest_dir = "";
 
    createTable();
    createActions();
@@ -228,6 +232,11 @@
    // Edit
    editAct = new MyAction(this, "pl_edit", false);
    connect( editAct, SIGNAL(triggered()), this, SLOT(editCurrentItem()) );
+
+   // edit by capt.d.
+   deleteAct = new MyAction(Qt::Key_F8, this, "pl_delete");
+   connect( deleteAct, SIGNAL(triggered()), this, SLOT(confirmDelete()));
+   // <--
 }
 
 void Playlist::createToolbar() {
@@ -277,6 +286,10 @@
    popup->addAction(removeSelectedAct);
    popup->addAction(editAct);
 
+   // edit by capt.d.
+    popup->addAction(deleteAct);
+    // <--
+
    connect( listView, SIGNAL(customContextMenuRequested(const QPoint &)),
              this, SLOT(showPopup(const QPoint &)) );
 }
@@ -331,6 +344,10 @@
    // Icon
    setWindowIcon( Images::icon("logo", 64) );
    setWindowTitle( tr( "SMPlayer - Playlist" ) );
+
+    // edit by capt.d.
+    deleteAct->change(tr("Delete file"));
+    // <---
 }
 
 void Playlist::list() {
@@ -1482,4 +1499,44 @@
    }
 }
 
+// edit by capt.d.
+void Playlist::confirmDelete(void)
+{
+   int index = -1;
+   if(sender() == deleteAct) // from playlist
+   {
+      index = listView->currentRow();
+   }
+   else
+   {
+      index = current_item;
+   }
+  if (index > -1 && index <= pl.count()) // this is unnecessary ;)   
+   {
+      int res = QMessageBox::question( this,
+         tr("Confirm please."),
+                   tr("Deleting %1").arg(pl[index].filename().toUtf8().data()),
+                   QMessageBox::Yes,
+                   QMessageBox::No);
+          switch (res)
+         {
+            case QMessageBox::No : return; // Discard changes
+            case QMessageBox::Yes :
+            {
+               if (!unlink(pl[index].filename().toUtf8().data()))
+               {
+                  if (pl[index].played()) // signal from outside 
+                  {
+                     pl[index].setPlayed(false);
+                     core->stop();
+                  }
+                  remove(index);
+               }
+            }
+            default : return;
+         };
+  };
+}   
+//<--
+
 #include "moc_playlist.cpp"


Code: Select all
--- basegui.h   2013-05-06 00:01:06.000000000 +0200
+++ basegui.h.new   2014-04-27 11:21:57.000000000 +0200
@@ -675,7 +675,10 @@
    MyAction * dvdnavPrevAct;
    MyAction * dvdnavMouseAct;
 #endif
-
+   // edit by capt.d.
+   MyAction *deleteAct;
+   //<---
+   
    // MENUS
    QMenu *openMenu;
    QMenu *playMenu;
@@ -792,6 +795,6 @@
 
    bool ignore_show_hide_events;
 };
-   
+
 #endif


Code: Select all
--- basegui.cpp   2013-05-04 12:52:19.000000000 +0200
+++ basegui.cpp.new   2014-04-27 11:26:00.000000000 +0200
@@ -457,6 +457,11 @@
    connect( gotoAct, SIGNAL(triggered()),
              this, SLOT(showGotoDialog()) );
 
+   // edit by capt.d.
+   deleteAct= new MyAction(Qt::Key_F8, this, "pl_delete");
+   connect (deleteAct, SIGNAL(triggered()), playlist, SLOT(confirmDelete()));
+   //
+
    // Submenu Speed
    normalSpeedAct = new MyAction( Qt::Key_Backspace, this, "normal_speed" );
    connect( normalSpeedAct, SIGNAL(triggered()),
@@ -1174,7 +1179,11 @@
    forward3Act->setEnabled(b);
    //repeatAct->setEnabled(b);
    gotoAct->setEnabled(b);
-
+   
+   // edit by capt.d.
+   deleteAct->setEnabled(b);
+  // <--   
+   
    // Menu Speed
    normalSpeedAct->setEnabled(b);
    halveSpeedAct->setEnabled(b);
@@ -1502,6 +1511,10 @@
    decSpeed1Act->change( tr("Speed -&1%") );
    incSpeed1Act->change( tr("S&peed +1%") );
 
+   // edit by capt.d.
+   deleteAct->change(tr("Delete file"));
+   //<--
+
    // Menu Video
    fullscreenAct->change( Images::icon("fullscreen"), tr("&Fullscreen") );
    compactAct->change( Images::icon("compact"), tr("&Compact mode") );
@@ -2278,6 +2291,12 @@
    playMenu->addSeparator();
    playMenu->addAction(playPrevAct);
    playMenu->addAction(playNextAct);
+
+   // edit by capt.d.
+   playMenu->addSeparator();
+   playMenu->addAction(deleteAct);
+   playMenu->addSeparator();
+   //<---
    
    // VIDEO MENU
    videotrack_menu = new QMenu(this);


Code: Select all
--- default.keys   2013-12-09 12:35:33.000000000 +0100
+++ default.keys.new   2013-12-09 12:35:27.000000000 +0100
@@ -241,3 +241,4 @@
 edit_floating_control   
 show_main_toolbar   F5
 show_language_toolbar   F6
+pl_delete   F8
capt.d.
 
Posts: 9
Joined: Sun Dec 08, 2013 7:02 pm

Re: [PATCH] Removing files using playlist

Postby rhill » Tue May 06, 2014 7:23 am

Thanks, that's great. I tweaked it to play the next file after deleting (the first patch did this but it would skip over one). I'll put it up here so people don't have to cut and paste:

http://dev.gentoo.org/~rhill/pkgs/smpla ... lete.patch
rhill
 
Posts: 5
Joined: Fri Apr 11, 2014 5:17 am

Re: [PATCH] Removing files using playlist

Postby capt.d. » Wed May 07, 2014 6:52 pm

Aloha
You're welcome. Do you think somebody else is using those patches? I don't ;)

---
Live long and prosper.
capt.d.
capt.d.
 
Posts: 9
Joined: Sun Dec 08, 2013 7:02 pm

Re: [PATCH] Removing files using playlist

Postby holly14 » Wed Jan 28, 2015 5:56 pm

Thanks. you could make this work without having to open the playlist it'd be perfect. :D
**SignaturE**
holly14
 
Posts: 1
Joined: Wed Jan 28, 2015 5:48 pm

Re: [PATCH] Removing files using playlist

Postby rhill » Thu Jan 29, 2015 12:26 am

The one I linked to does just that.
rhill
 
Posts: 5
Joined: Fri Apr 11, 2014 5:17 am

PATCH Removing files using playlist

Postby HaroldBaics » Fri Mar 13, 2015 12:16 pm

Its been almost 18 months since I posted this patch, which seems to me essential for encoding software, and you dont have included it.
Why ?
HaroldBaics
 
Posts: 1
Joined: Thu Dec 18, 2014 4:22 am

Re: [PATCH] Removing files using playlist

Postby rvm » Fri Mar 13, 2015 11:54 pm

I've just added the patch with some modifications (svn r6779).
rvm
Site Admin
 
Posts: 2950
Joined: Wed Dec 23, 2009 1:25 am
Location: España

Re: [PATCH] Removing files using playlist

Postby rhill » Sat Mar 14, 2015 8:53 am

Woohoo! Thanks.
rhill
 
Posts: 5
Joined: Fri Apr 11, 2014 5:17 am

Next

Return to Development

Who is online

Users browsing this forum: No registered users and 0 guests