Commit f7c1b49d authored by Michael Pyne's avatar Michael Pyne

Simplify Playlist constructors and cleanup header.

parent 70960177
......@@ -114,90 +114,55 @@ int Playlist::m_leftColumn = 0;
// public members
////////////////////////////////////////////////////////////////////////////////
Playlist::Playlist(PlaylistCollection *collection, const QString &name,
const QString &iconName) :
QTreeWidget(collection->playlistStack()),
m_collection(collection),
m_fetcher(new WebImageFetcher(this)),
m_allowDuplicates(true),
m_applySharedSettings(true),
m_columnWidthModeChanged(false),
m_disableColumnWidthUpdates(true),
m_time(0),
m_widthsDirty(true),
m_searchEnabled(true),
m_playlistName(name),
m_rmbMenu(0),
m_blockDataChanged(false)
Playlist::Playlist(
bool delaySetup, const QString &name,
PlaylistCollection *collection, const QString &iconName,
int extraCols)
: QTreeWidget(collection->playlistStack())
, m_collection(collection)
, m_playlistName(name)
, m_fetcher(new WebImageFetcher(this))
{
// Any added columns must precede normal ones, which are normally added
// in setup()
for(int i = 0; i < extraCols; ++i) {
addColumn(i18n("JuK")); // Placeholder text
}
setup();
collection->setupPlaylist(this, iconName);
// Some subclasses need to do even more handling but will remember to
// call setupPlaylist
if(!delaySetup) {
collection->setupPlaylist(this, iconName);
}
}
Playlist::Playlist(PlaylistCollection *collection, const QString &name,
const QString &iconName)
: Playlist(false, name, collection, iconName, 0)
{
}
Playlist::Playlist(PlaylistCollection *collection, const PlaylistItemList &items,
const QString &name, const QString &iconName) :
QTreeWidget(collection->playlistStack()),
m_collection(collection),
m_fetcher(new WebImageFetcher(this)),
m_allowDuplicates(true),
m_applySharedSettings(true),
m_columnWidthModeChanged(false),
m_disableColumnWidthUpdates(true),
m_time(0),
m_widthsDirty(true),
m_searchEnabled(true),
m_playlistName(name),
m_rmbMenu(0),
m_blockDataChanged(false)
const QString &name, const QString &iconName)
: Playlist(false, name, collection, iconName, 0)
{
setup();
collection->setupPlaylist(this, iconName);
createItems(items);
}
Playlist::Playlist(PlaylistCollection *collection, const QFileInfo &playlistFile,
const QString &iconName) :
QTreeWidget(collection->playlistStack()),
m_collection(collection),
m_fetcher(new WebImageFetcher(this)),
m_allowDuplicates(true),
m_applySharedSettings(true),
m_columnWidthModeChanged(false),
m_disableColumnWidthUpdates(true),
m_time(0),
m_widthsDirty(true),
m_searchEnabled(true),
m_fileName(playlistFile.canonicalFilePath()),
m_rmbMenu(0),
m_blockDataChanged(false)
const QString &iconName)
: Playlist(true, QString(), collection, iconName, 0)
{
setup();
m_fileName = playlistFile.canonicalFilePath();
loadFile(m_fileName, playlistFile);
collection->setupPlaylist(this, iconName);
}
Playlist::Playlist(PlaylistCollection *collection, bool delaySetup, int extraColumns) :
QTreeWidget(collection->playlistStack()),
m_collection(collection),
m_fetcher(new WebImageFetcher(this)),
m_allowDuplicates(true),
m_applySharedSettings(true),
m_columnWidthModeChanged(false),
m_disableColumnWidthUpdates(true),
m_time(0),
m_widthsDirty(true),
m_searchEnabled(true),
m_rmbMenu(0),
m_blockDataChanged(false)
Playlist::Playlist(PlaylistCollection *collection, bool delaySetup, int extraColumns)
: Playlist(delaySetup, QString(), collection, QStringLiteral("audio-midi"), extraColumns)
{
for(int i = 0; i < extraColumns; ++i) {
addColumn(i18n("JuK")); // Placeholder text!
}
setup();
if(!delaySetup)
collection->setupPlaylist(this, "audio-midi");
}
Playlist::~Playlist()
......@@ -230,31 +195,6 @@ FileHandle Playlist::currentFile() const
return playingItem() ? playingItem()->file() : FileHandle();
}
int Playlist::time() const
{
// Since this method gets a lot of traffic, let's optimize for such.
if(!m_addTime.isEmpty()) {
foreach(const PlaylistItem *item, m_addTime) {
if(item)
m_time += item->file().tag()->seconds();
}
m_addTime.clear();
}
if(!m_subtractTime.isEmpty()) {
foreach(const PlaylistItem *item, m_subtractTime) {
if(item)
m_time -= item->file().tag()->seconds();
}
m_subtractTime.clear();
}
return m_time;
}
void Playlist::playFirst()
{
TrackSequenceManager::instance()->setNextItem(static_cast<PlaylistItem *>(
......@@ -366,8 +306,6 @@ void Playlist::updateDeletedItem(PlaylistItem *item)
m_search.clearItem(item);
m_history.removeAll(item);
m_addTime.removeAll(item);
m_subtractTime.removeAll(item);
}
void Playlist::clearItem(PlaylistItem *item)
......@@ -1063,20 +1001,11 @@ void Playlist::drawRow(QPainter *p, const QStyleOptionViewItem &option, const QM
void Playlist::insertItem(QTreeWidgetItem *item)
{
// Because we're called from the PlaylistItem ctor, item may not be a
// PlaylistItem yet (it would be QListViewItem when being inserted. But,
// it will be a PlaylistItem by the time it matters, but be careful if
// you need to use the PlaylistItem from here.
m_addTime.append(static_cast<PlaylistItem *>(item));
QTreeWidget::insertTopLevelItem(0, item);
}
void Playlist::takeItem(QTreeWidgetItem *item)
{
// See the warning in Playlist::insertItem.
m_subtractTime.append(static_cast<PlaylistItem *>(item));
int index = indexOfTopLevelItem(item);
QTreeWidget::takeTopLevelItem(index);
}
......@@ -1425,6 +1354,15 @@ void Playlist::setup()
// Should this be itemActivated? It is quite annoying when I try it...
connect(this, &QTreeWidget::itemDoubleClicked, this, &Playlist::slotPlayCurrent);
// Use a timer to soak up the multiple dataChanged signals we're going to get
auto updateRequestor = new QTimer(this);
updateRequestor->setSingleShot(true);
updateRequestor->setInterval(10);
connect(model(), &QAbstractItemModel::dataChanged,
updateRequestor, static_cast<void (QTimer::*)()>(&QTimer::start));
connect(updateRequestor, &QTimer::timeout, this, &Playlist::slotUpdateTime);
// This apparently must be created very early in initialization for other
// Playlist code requiring m_headerMenu.
m_columnVisibleAction = new KActionMenu(i18n("&Show Columns"), this);
......@@ -1453,7 +1391,6 @@ void Playlist::loadFile(const QString &fileName, const QFileInfo &fileInfo)
setSortingEnabled(false);
PlaylistItem *after = nullptr;
m_disableColumnWidthUpdates = true;
m_blockDataChanged = true;
......@@ -1468,7 +1405,7 @@ void Playlist::loadFile(const QString &fileName, const QFileInfo &fileInfo)
if(item.exists() && item.isFile() && item.isReadable() &&
MediaFiles::isMediaFile(item.fileName()))
{
after = createItem(FileHandle(item), after);
(void) createItem(FileHandle(item));
}
}
......@@ -2066,6 +2003,20 @@ void Playlist::slotPlayCurrent()
action("forward")->trigger();
}
void Playlist::slotUpdateTime()
{
int newTime = 0;
QTreeWidgetItemIterator it(this);
while(*it) {
const auto item = static_cast<const PlaylistItem*>(*it);
++it;
newTime += item->file().tag()->seconds();
}
m_time = newTime;
}
////////////////////////////////////////////////////////////////////////////////
// helper functions
////////////////////////////////////////////////////////////////////////////////
......
......@@ -79,7 +79,7 @@ public:
virtual QString name() const;
virtual FileHandle currentFile() const;
virtual int count() const { return model()->rowCount(); }
virtual int time() const;
virtual int time() const { return m_time; }
virtual void playNext();
virtual void playPrevious();
virtual void stop();
......@@ -494,6 +494,12 @@ signals:
void signalMoveFocusAway();
private:
// Common constructor routines, inherited by other constructors
Playlist(
bool delaySetup, const QString &name,
PlaylistCollection *collection, const QString &iconName,
int extraCols);
void setup();
/**
......@@ -643,68 +649,52 @@ private slots:
void slotInlineCompletionModeChanged(KCompletion::CompletionMode mode);
void slotPlayCurrent();
void slotUpdateTime();
private:
friend class PlaylistItem;
PlaylistCollection *m_collection;
PlaylistCollection *m_collection = nullptr;
StringHash m_members;
WebImageFetcher *m_fetcher;
QAction *m_rmbEdit;
bool m_allowDuplicates;
bool m_applySharedSettings;
bool m_columnWidthModeChanged;
QVector<int> m_weightDirty;
bool m_disableColumnWidthUpdates;
// This is only defined if the playlist name is something other than the
// file name.
QString m_playlistName;
QString m_fileName;
mutable int m_time;
mutable PlaylistItemList m_addTime;
mutable PlaylistItemList m_subtractTime;
int m_time = 0;
bool m_allowDuplicates = true;
/**
* The average minimum widths of columns to be used in balancing calculations.
*/
QStringList m_columns;
QVector<int> m_columnWeights;
QVector<int> m_columnFixedWidths;
bool m_widthsDirty;
QVector<int> m_weightDirty;
KActionMenu *m_columnVisibleAction = nullptr;
bool m_columnWidthModeChanged = false;
bool m_disableColumnWidthUpdates = true;
bool m_widthsDirty = true;
bool m_applySharedSettings = true;
static PlaylistItemList m_history;
PlaylistSearch m_search;
bool m_searchEnabled;
/**
* Used to store the text for inline editing before it is changed so that
* we can know if something actually changed and as such if we need to save
* the tag.
*/
QString m_editText;
/**
* This is only defined if the playlist name is something other than the
* file name.
*/
QString m_playlistName;
QString m_fileName;
QStringList m_columns;
QMenu *m_rmbMenu;
QMenu *m_headerMenu;
KActionMenu *m_columnVisibleAction;
bool m_searchEnabled = true;
int m_itemsLoading = 0; /// Count of pending file loads outstanding
bool m_blockDataChanged;
bool m_blockDataChanged = false;
QAction *m_rmbEdit = nullptr;
QMenu *m_rmbMenu = nullptr;
QMenu *m_headerMenu = nullptr;
WebImageFetcher *m_fetcher = nullptr;
/**
* This is used to indicate if the list of visible items has changed (via a
* call to setVisibleItems()) while random play is playing.
*/
static bool m_visibleChanged;
static PlaylistItemList m_history;
static bool m_shuttingDown;
static int m_leftColumn;
static QVector<PlaylistItem *> m_backMenuItems;
......
......@@ -30,7 +30,6 @@
#include <QVBoxLayout>
#include <QLatin1String>
#include <QList>
#include <QTime>
#include <QStackedWidget>
#include <QSizePolicy>
#include <QKeySequence>
......
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