2 Commits 060f96423c ... 903b7e1bb8

Author SHA1 Message Date
  mio 903b7e1bb8 Initial support for removing items from playlist 4 months ago
  mio 0a52aea80d Add 'Escape' and 'f' shortcuts 4 months ago
8 changed files with 119 additions and 41 deletions
  1. 6 0
      .dir-locals.el
  2. 1 0
      .gitignore
  3. 17 1
      source/aster.cpp
  4. 1 1
      source/aster.h
  5. 15 0
      source/playlist.cpp
  6. 50 38
      source/playlist.h
  7. 25 1
      source/playlist_window.cpp
  8. 4 0
      source/playlist_window.h

+ 6 - 0
.dir-locals.el

@@ -0,0 +1,6 @@
+((nil . ((indent-tabs-mode . nil)))
+ (c++-mode . ((c-file-style . "k&r")
+	      (tab-width . 4)
+	      (c-basic-offset . 4)
+	      (c-file-offsets
+	       (access-label . -)))))

+ 1 - 0
.gitignore

@@ -1,4 +1,5 @@
 build/
+builddir/
 .cache/
 .kdev4/
 Aster.kdev4

+ 17 - 1
source/aster.cpp

@@ -105,6 +105,17 @@ void Aster::enqueFile(const KURL &path)
     m_playlist->append(path);
 }
 
+void Aster::keyPressEvent(TQKeyEvent *event)
+{
+    // Not sure about this. Kinda hidden.
+    // Plus it can be overridden in shortcut configuration.
+    if ((event->key() == Key_Escape) && isFullScreen()) {
+        actionCollection()->action("fullscreen")->activate();
+        event->accept();
+    }
+    TQWidget::keyPressEvent(event);
+}
+
 void Aster::mouseMoveEvent(TQMouseEvent *event)
 {
     if (isFullScreen()) {
@@ -134,7 +145,12 @@ void Aster::setupActions()
     KStdAction::quit(tdeApp, TQ_SLOT(quit()), actionCollection())->plug(fileMenu);
 
     auto viewMenu = new TDEPopupMenu(this);
-    KStdAction::fullScreen(this, TQ_SLOT(slotFullScreen()), actionCollection(), this, "fullscreen")->plug(viewMenu);
+    TDEAction* fullscreenAction = KStdAction::fullScreen(this, TQ_SLOT(slotFullScreen()), actionCollection(), this, "fullscreen");
+    TDEShortcut fsShortcut = fullscreenAction->shortcut();
+    fsShortcut.append(KKey(Key_F));
+    fullscreenAction->setShortcut(fsShortcut);
+    fullscreenAction->plug(viewMenu);
+
     viewMenu->insertItem(i18n("Show &Playlist..."), this, TQ_SLOT(slotShowPlaylist()), CTRL | Key_L);
 
     auto audioMenu = new TDEPopupMenu(this);

+ 1 - 1
source/aster.h

@@ -46,7 +46,7 @@ public slots:
     void enqueFile(const KURL &path);
 
 protected:
-
+    void keyPressEvent(TQKeyEvent *) override;
     void mouseMoveEvent(TQMouseEvent *) override;
     void timerEvent(TQTimerEvent *) override;
 

+ 15 - 0
source/playlist.cpp

@@ -48,6 +48,7 @@ Playlist::~Playlist()
 void Playlist::append(const KURL& mrl)
 {
     d->items.append(mrl);
+    emit itemsInserted(d->items.count(), d->items.count());
 }
 
 void Playlist::append(const KURL::List& items)
@@ -93,6 +94,20 @@ KURL Playlist::currentItem() const
     return d->items[d->index];
 }
 
+bool Playlist::remove(int index)
+{
+    if ((index >= d->items.count()) || (index < 0)) {
+        tqDebug("Playlist::remove: not removing index %d (out-of-bounds %d-%d)",
+                index, 0, d->items.count());
+        return false;
+    }
+
+    auto it = d->items.at(index);
+    d->items.remove(it);
+    emit itemsRemoved(index, index);
+    return true;
+}
+
 KURL Playlist::at(int index) const
 {
     return d->items[index];

+ 50 - 38
source/playlist.h

@@ -23,54 +23,66 @@
 
 class Playlist : public TQObject
 {
-	TQ_OBJECT
+    TQ_OBJECT
 
 public:
-	explicit Playlist(TQObject *parent = nullptr);
-	~Playlist();
+    explicit Playlist(TQObject *parent = nullptr);
+    ~Playlist();
 
-	/*! Add a new item */
-	void append(const KURL& mrl);
-	/*! Append multiple items to the playist. */
-	void append(const KURL::List& items);
-	/*! Is the playlist empty */
-	bool isEmpty() const;
-	/*! Returns the number of items in the playlist. */
-	int count() const;
-	/*! Returns the index of the current item in the playlist. */
-	int currentIndex() const;
-	/*! Returns the current item in the playlist. */
-	KURL currentItem() const;
+    /*! Add a new item */
+    void append(const KURL& mrl);
+    /*! Append multiple items to the playist. */
+    void append(const KURL::List& items);
+    /*! Is the playlist empty */
+    bool isEmpty() const;
+    /*! Returns the number of items in the playlist. */
+    int count() const;
+    /*! Returns the index of the current item in the playlist. */
+    int currentIndex() const;
+    /*! Returns the current item in the playlist. */
+    KURL currentItem() const;
+    /*! Remove the item at position \a index from the playlist. */
+    bool remove(int index);
 
-	/*! The MRL for the item at \p index */
-	KURL at(int index) const;
+    /*! The MRL for the item at \p index */
+    KURL at(int index) const;
 
 signals:
-	/*!
-	 * Emitted whenever the playlist index changes.
-	 *
-	 * \see currentIndex()
-	 */
-	void currentIndexChanged(int index);
-	/*!
-	 * Emitted whenever the playlist index changes.
-	 *
-	 * \see currentItem()
-	 */
-	void currentItemChanged(const KURL& item);
-	void itemsInserted(int start, int end);
-	// void itemRemoved(int);
+    /*!
+     * Emitted whenever the playlist index changes.
+     *
+     * \see currentIndex()
+     */
+    void currentIndexChanged(int index);
+    /*!
+     * Emitted whenever the playlist index changes.
+     *
+     * \see currentItem()
+     */
+    void currentItemChanged(const KURL& item);
+    /*!
+     * Emitted whenever items are added/inserted into the playlist.
+     *
+     * \see append()
+     */
+    void itemsInserted(int start, int end);
+    /*!
+     * Emitted whenever items are removed from the playlist.
+     *
+     * \see remove()
+     */
+    void itemsRemoved(int start, int end);
 
 public slots:
-	/*! Advance to the next playlist item. */
-	void next();
-	/*! Return to the previous playlist item. */
-	void previous();
-	/*! Navigate to the playlist item at \a index. */
-	void setCurrentIndex(int index);
+    /*! Advance to the next playlist item. */
+    void next();
+    /*! Return to the previous playlist item. */
+    void previous();
+    /*! Navigate to the playlist item at \a index. */
+    void setCurrentIndex(int index);
 
 private:
-	class PlaylistPrivate* d;
+    class PlaylistPrivate* d;
 };
 
 #endif /* PLAYLIST_H */

+ 25 - 1
source/playlist_window.cpp

@@ -25,6 +25,7 @@
 
 #include <tdefilemetainfo.h>
 #include <tdelocale.h>
+#include <tdemenubar.h>
 
 class PlaylistTable : public TQTable
 {
@@ -70,6 +71,11 @@ PlaylistWindow::PlaylistWindow(Playlist *playlist, TQWidget *parent, const char
 
 	auto layout = new TQVBoxLayout(this);
 
+    m_menuBar = new KMenuBar(this, "playlist_window_menubar");
+    m_menuBar->insertItem("Open File...", 0); // TODO: Should this just emit a signal?
+    m_menuBar->insertItem("Remove Item", this, TQ_SLOT(slotRemoveCurrent()), Key_Delete, 1);
+    m_menuBar->setItemEnabled(1, m_playlist->count() > 1);
+
 	m_table = new PlaylistTable(this, "playlist_window_table");
 	m_table->setFocusStyle(TQTable::FollowStyle);
 	m_table->setLeftMargin(0);
@@ -83,10 +89,12 @@ PlaylistWindow::PlaylistWindow(Playlist *playlist, TQWidget *parent, const char
 
 	connect(m_playlist, TQ_SIGNAL(currentIndexChanged(int)), TQ_SLOT(slotIndexChanged(int)));
 	connect(m_playlist, TQ_SIGNAL(itemsInserted(int, int)),	TQ_SLOT(slotItemsInserted(int, int)));
+    connect(m_playlist, TQ_SIGNAL(itemsRemoved(int, int)), TQ_SLOT(slotItemsRemoved(int, int)));
 
 	connect(m_table, TQ_SIGNAL(doubleClicked(int, int, int, const TQPoint&)),
 		TQ_SLOT(slotTableDoubleClicked(int, int, int, const TQPoint&)));
 
+    layout->add(m_menuBar);
 	layout->add(m_table);
 
 	/* FIXME: No way to iterate playlist */
@@ -110,7 +118,7 @@ PlaylistWindow::PlaylistWindow(Playlist *playlist, TQWidget *parent, const char
 
 	resize(500, 200);
 	move(parent->x() + (parent->width() / 2) - (width() / 2),
-		parent->y() + (parent->height() / 2) - (height() / 2));
+         parent->y() + (parent->height() / 2) - (height() / 2));
 }
 
 void PlaylistWindow::keyReleaseEvent(TQKeyEvent *event)
@@ -155,6 +163,22 @@ void PlaylistWindow::slotItemsInserted(int start, int end)
 			m_table->setText(start + i, 1, TQString::fromLatin1("00:00:00"));
 		}
 	}
+
+    // Ensure the 'remove item' is active.
+    m_menuBar->setItemEnabled(1, true);
+}
+
+void PlaylistWindow::slotItemsRemoved(int start, int end)
+{
+    m_table->removeRow(start);
+    if (m_playlist->count() == 0)
+        m_menuBar->setItemEnabled(1, false);
+    tqWarning("PlaylistWindow::slotItemsRemoved: implementation isn't finished as multiple selections are not supported.");
+}
+
+void PlaylistWindow::slotRemoveCurrent()
+{
+    m_playlist->remove(m_table->currentRow());
 }
 
 void PlaylistWindow::slotTableDoubleClicked(int row, int, int button, const TQPoint&)

+ 4 - 0
source/playlist_window.h

@@ -21,6 +21,7 @@
 
 class Playlist;
 class TQTable;
+class KMenuBar;
 
 class PlaylistWindow : public TQWidget
 {
@@ -32,6 +33,8 @@ public:
 protected slots:
 	void slotIndexChanged(int);
 	void slotItemsInserted(int, int);
+    void slotItemsRemoved(int, int);
+    void slotRemoveCurrent();
 	void slotTableDoubleClicked(int, int, int, const TQPoint&);
 
 protected:
@@ -40,6 +43,7 @@ protected:
 private:
 	Playlist *m_playlist;
 	TQTable *m_table;
+    KMenuBar *m_menuBar;
 };
 
 #endif /* ASTER_PLAYLIST_WINDOW_H */