Commit 7cb5aaec authored by Scott Wheeler's avatar Scott Wheeler

* Cleaned up some includes

* Added some functionality to PlaylistSearch to allow components to be
  saved and restored
* Added a member variable and accessor methods to Playlist to store the
  current search
* Cleaned up some of the code in Playlist to use PlaylistItemList instead
  of a QPtrList.

The next commit will actually make use of the above stuff to save and
restore searches when the user changes playlists.

svn path=/trunk/kdemultimedia/juk/; revision=229404
parent eb3957de
......@@ -34,6 +34,8 @@
#include <time.h>
#include "playlist.h"
#include "playlistitem.h"
#include "playlistsearch.h"
#include "genrelistlist.h"
#include "collectionlist.h"
#include "mediafiles.h"
......@@ -320,20 +322,18 @@ PlaylistItemList Playlist::historyItems(PlaylistItem *current, bool random) cons
{
PlaylistItemList list;
if (random)
{
QPtrListIterator<PlaylistItem> it(m_history);
it.toLast();
for (int j = 0; it.current() && j < 10; --it, ++j)
list.append(it.current());
if (random) {
PlaylistItemList::ConstIterator it = m_history.end();
for(int j = 0; it != m_history.begin() && j < 10; --it, ++j)
list.append(*it);
}
else if (current)
{
else if(current) {
current = static_cast<PlaylistItem *>(current->itemAbove());
for (int j = 0;
current && j < 10;
++j, current = static_cast<PlaylistItem *>(current->itemAbove()))
for(int j = 0; current && j < 10; ++j) {
current = static_cast<PlaylistItem *>(current->itemAbove());
list.append(current);
}
}
return list;
......@@ -376,11 +376,10 @@ PlaylistItem *Playlist::previousItem(PlaylistItem *current, bool random)
if(!current)
return 0;
if(random && !m_history.isEmpty())
{
PlaylistItem * item = m_history.take(m_history.count() - 1);
//should we add it to the random list ?
//m_randomList.append(item);
if(random && !m_history.isEmpty()) {
PlaylistItemList::Iterator last = m_history.fromLast();
PlaylistItem *item = *last;
m_history.remove(last);
return item;
}
......@@ -873,6 +872,11 @@ void Playlist::setPlaying(PlaylistItem *item, bool p)
item->setPlaying(p);
}
bool Playlist::playing() const
{
return m_playingItem && this == static_cast<Playlist *>(m_playingItem->listView());
}
////////////////////////////////////////////////////////////////////////////////
// private slots
////////////////////////////////////////////////////////////////////////////////
......@@ -982,8 +986,7 @@ void Playlist::slotApplyModification(QListViewItem *item, const QString &text, i
return;
QPtrList<QListViewItem> selectedSongs = KListView::selectedItems();
if (selectedSongs.count() > 1)
{
if (selectedSongs.count() > 1) {
if (KMessageBox::warningYesNo(0,
i18n("This will edit multiple files! Are you sure?"),
QString::null,
......@@ -996,7 +999,7 @@ void Playlist::slotApplyModification(QListViewItem *item, const QString &text, i
QPtrListIterator<QListViewItem> it(selectedSongs);
for(; it.current(); ++it)
applyTag((*it), text, column);
applyTag((*it), text, column);
}
else
applyTag(item, text, column);
......
......@@ -24,15 +24,19 @@
#include <qvaluevector.h>
#include <qptrstack.h>
#include "playlistitem.h"
#include "sortedstringlist.h"
class KPopupMenu;
#include "playlistsearch.h"
class KPopupMenu;
class KActionMenu;
class QEvent;
class QFileInfo;
class PlaylistSearch;
class PlaylistItem;
typedef QValueList<PlaylistItem *> PlaylistItemList;
typedef QValueList<Playlist *> PlaylistList;
......@@ -144,7 +148,7 @@ public:
/**
* Returns true if this playlist is currently playing.
*/
bool playing() const { return m_playingItem && this == static_cast<Playlist *>(m_playingItem->listView()); }
bool playing() const;
/**
* This forces an update of the left most visible column, but does not save
......@@ -154,6 +158,9 @@ public:
static void setItemsVisible(const PlaylistItemList &items, bool visible = true);
PlaylistSearch search() const { return m_search; }
void setSearch(const PlaylistSearch &s) { m_search = s; }
public slots:
/**
* Remove the currently selected items from the playlist and disk.
......@@ -268,7 +275,7 @@ private:
* call to setVisibleItems()) while random play is playing.
*/
static bool m_visibleChanged;
QPtrList<PlaylistItem> m_history;
PlaylistItemList m_history;
QString m_fileName;
......@@ -296,6 +303,7 @@ private:
static int m_leftColumn;
PlaylistItemList m_randomList;
PlaylistSearch m_search;
};
QDataStream &operator<<(QDataStream &s, const Playlist &p);
......
......@@ -16,11 +16,19 @@
***************************************************************************/
#include "playlistsearch.h"
#include "playlist.h"
#include "playlistitem.h"
////////////////////////////////////////////////////////////////////////////////
// public methods
////////////////////////////////////////////////////////////////////////////////
PlaylistSearch::PlaylistSearch() :
m_mode(MatchAny)
{
}
PlaylistSearch::PlaylistSearch(const PlaylistSearch &search) :
m_playlists(search.m_playlists),
m_components(search.m_components),
......@@ -130,6 +138,7 @@ PlaylistSearch::Component::Component(const QRegExp &query, const ColumnList& col
m_caseSensitive(false),
m_re(true)
{
}
bool PlaylistSearch::Component::matches(PlaylistItem *item)
......
......@@ -21,9 +21,10 @@
#include <qvaluelist.h>
#include <qregexp.h>
#include "playlist.h"
#include "playlistitem.h"
class Playlist;
typedef QValueList<Playlist *> PlaylistList;
class PlaylistItem;
typedef QValueList<PlaylistItem *> PlaylistItemList;
typedef QValueList<int> ColumnList;
class PlaylistSearch
......@@ -34,11 +35,8 @@ public:
enum SearchMode { MatchAny = 0, MatchAll = 1 };
/**
* Copy constructor.
*/
PlaylistSearch();
PlaylistSearch(const PlaylistSearch &search);
PlaylistSearch(const PlaylistList &playlists,
const ComponentList &components,
SearchMode mode = MatchAny);
......@@ -50,6 +48,10 @@ public:
PlaylistList playlists() const { return m_playlists; }
ComponentList components() const { return m_components; }
bool isNull() const { return m_components.isEmpty(); }
private:
void search();
......@@ -93,11 +95,12 @@ public:
Component(const QRegExp &query, const ColumnList &columns = ColumnList());
QString query() const { return m_query; }
QRegExp pattern() const { return m_queryRe; }
ColumnList columns() const { return m_columns; }
bool matches(PlaylistItem *item);
protected:
bool isPatternSearch() const { return m_re; }
bool isCaseSensitive() const { return m_caseSensitive; }
private:
QString m_query;
......
......@@ -32,7 +32,6 @@
class KActionMenu;
class KDirWatch;
class PlaylistItem;
/**
......
......@@ -26,6 +26,7 @@
#include "searchwidget.h"
#include "playlist.h"
#include "playlistsearch.h"
////////////////////////////////////////////////////////////////////////////////
// public methods
......@@ -60,6 +61,28 @@ bool SearchWidget::regExp() const
return m_caseSensitive->currentItem() == 2;
}
void SearchWidget::setSearch(const PlaylistSearch &search)
{
PlaylistSearch::ComponentList components = search.components();
// This is intentionally written so that when multiple search lines are
// supported that it can be easily updated.
PlaylistSearch::ComponentList::ConstIterator it = components.begin();
if(it == components.end())
return;
if(!(*it).isPatternSearch()) {
m_lineEdit->setText((*it).query());
m_caseSensitive->setCurrentItem((*it).isCaseSensitive() ? CaseSensitive : Default);
}
else {
m_lineEdit->setText((*it).pattern().pattern());
m_caseSensitive->setCurrentItem(Pattern);
}
}
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////
......
......@@ -26,13 +26,15 @@ class KLineEdit;
class KComboBox;
class Playlist;
class PlaylistSearch;
class SearchWidget : public QWidget
{
Q_OBJECT
public:
/**
enum Mode { Default = 0, CaseSensitive = 1, Pattern = 2 };
/**
* Note that playlist here is just a playlist to get the columns from and
* has nothing to do with the results of a search.
*/
......@@ -47,6 +49,7 @@ public:
QString query() const;
bool caseSensitive() const;
bool regExp() const;
void setSearch(const PlaylistSearch &search);
public slots:
void clear();
......@@ -66,6 +69,6 @@ private:
KComboBox *m_caseSensitive;
QStringList m_columnHeaders;
QValueList< QValueList<int> > m_searchedColumns;
} ;
};
#endif
......@@ -32,6 +32,7 @@
#include "tageditor.h"
#include "collectionlist.h"
#include "genrelistlist.h"
#include "playlistitem.h"
////////////////////////////////////////////////////////////////////////////////
// public members
......
......@@ -21,7 +21,6 @@
#include <qwidget.h>
#include <qmap.h>
#include "playlistitem.h"
#include "genrelist.h"
class KComboBox;
......@@ -33,6 +32,9 @@ class KPushButton;
class QCheckBox;
class QBoxLayout;
class PlaylistItem;
typedef QValueList<PlaylistItem *> PlaylistItemList;
class TagEditor : public QWidget
{
Q_OBJECT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment