Commit 6a73b1d4 authored by Scott Wheeler's avatar Scott Wheeler

Lots of code cleaned up. Fixed a memory leak. Moved to using references

as opposed to pointers where appropriate.

svn path=/trunk/kdemultimedia/juk/; revision=157369
parent 9a5869cb
......@@ -36,14 +36,14 @@ FileList::FileList(QWidget *parent, const char *name) : KListView(parent, name)
setup();
}
FileList::FileList(QString item, QWidget *parent, const char *name) : KListView(parent, name)
FileList::FileList(QString &item, QWidget *parent, const char *name) : KListView(parent, name)
{
processed = 0;
setup();
append(item);
}
FileList::FileList(QStringList *items, QWidget *parent, const char *name) : KListView(parent, name)
FileList::FileList(QStringList &items, QWidget *parent, const char *name) : KListView(parent, name)
{
setup();
append(items);
......@@ -61,10 +61,10 @@ void FileList::append(QString item)
emit(dataChanged());
}
void FileList::append(QStringList *items)
void FileList::append(QStringList &items)
{
QApplication::setOverrideCursor(Qt::waitCursor);
for(QStringList::Iterator it = items->begin(); it != items->end(); ++it)
for(QStringList::Iterator it = items.begin(); it != items.end(); ++it)
appendImpl(*it);
QApplication::restoreOverrideCursor();
emit(dataChanged());
......@@ -79,9 +79,9 @@ void FileList::append(FileListItem *item)
emit(dataChanged());
}
void FileList::append(QPtrList<QListViewItem> *items)
void FileList::append(QPtrList<QListViewItem> &items)
{
QPtrListIterator<QListViewItem> it(*items);
QPtrListIterator<QListViewItem> it(items);
while(it.current()) {
append(dynamic_cast<FileListItem *>(it.current()));
++it;
......@@ -89,9 +89,9 @@ void FileList::append(QPtrList<QListViewItem> *items)
// the emit(dataChanged()) is handled in the above function
}
void FileList::remove(QPtrList<QListViewItem> *items)
void FileList::remove(QPtrList<QListViewItem> &items)
{
QPtrListIterator<QListViewItem> it(*items);
QPtrListIterator<QListViewItem> it(items);
while(it.current()) {
members.remove(static_cast<FileListItem *>(it.current())->absFilePath());
delete(it.current());
......
......@@ -29,16 +29,16 @@ class FileList : public KListView
Q_OBJECT
public:
FileList(QWidget *parent = 0, const char *name = 0);
FileList(QString item, QWidget *parent = 0, const char *name = 0);
FileList(QStringList *items, QWidget *parent = 0, const char *name = 0);
FileList(QString &item, QWidget *parent = 0, const char *name = 0);
FileList(QStringList &items, QWidget *parent = 0, const char *name = 0);
~FileList();
void append(QString item);
void append(QStringList *items);
void append(QStringList &items);
void append(FileListItem *item);
void append(QPtrList<QListViewItem> *items);
void append(QPtrList<QListViewItem> &items);
void remove(QPtrList<QListViewItem> *items);
void remove(QPtrList<QListViewItem> &items);
FileListItem *getSelectedItem();
......
......@@ -157,7 +157,7 @@ void JuK::saveConfig()
void JuK::openFile()
{
QStringList files = KFileDialog::getOpenFileNames(QString::null, "*.mp3|MPEG Audio (*.mp3)");
tagger->add(&files);
tagger->add(files);
}
void JuK::openDirectory()
......@@ -212,12 +212,14 @@ void JuK::showPlaylist()
void JuK::addToPlaylist()
{
playlist->add(tagger->getSelectedItems());
QPtrList<QListViewItem> items(tagger->getSelectedItems());
playlist->add(items);
}
void JuK::removeFromPlaylist()
{
playlist->remove(playlist->getSelectedItems());
QPtrList<QListViewItem> items(tagger->getSelectedItems());
playlist->remove(items);
}
void JuK::playFile()
......@@ -232,8 +234,9 @@ void JuK::playFile()
}
}
else if(playlist) {
if(playlist->getSelectedItems()->count() > 0)
playItem(dynamic_cast<FileListItem *>(playlist->getSelectedItems()->at(0)));
QPtrList<QListViewItem> items(tagger->getSelectedItems());
if(items.count() > 0)
playItem(dynamic_cast<FileListItem *>(items.at(0)));
else
playItem(playlist->firstItem());
}
......
......@@ -38,7 +38,7 @@ class JuK : public KMainWindow
{
Q_OBJECT
public:
JuK(QWidget* parent=0, const char *name=0);
JuK(QWidget* parent = 0, const char *name = 0);
~JuK();
private:
......@@ -55,9 +55,15 @@ private:
// actions
SliderAction *sliderAction;
KAction *playAction, *pauseAction, *stopAction;
KAction *showTaggerAction, *showPlaylistAction;
KAction *addToPlaylistAction, *removeFromPlaylistAction;
KAction *playAction;
KAction *pauseAction;
KAction *stopAction;
KAction *showTaggerAction;
KAction *showPlaylistAction;
KAction *addToPlaylistAction;
KAction *removeFromPlaylistAction;
QTimer *playTimer;
Player player;
......
......@@ -43,7 +43,7 @@ void PlaylistWidget::add(QString item)
playlistList->append(item);
}
void PlaylistWidget::add(QStringList *items)
void PlaylistWidget::add(QStringList &items)
{
playlistList->append(items);
}
......@@ -53,26 +53,24 @@ void PlaylistWidget::add(FileListItem *item)
playlistList->append(item);
}
void PlaylistWidget::add(QPtrList<QListViewItem> *items)
void PlaylistWidget::add(QPtrList<QListViewItem> &items)
{
playlistList->append(items);
}
void PlaylistWidget::remove(QPtrList<QListViewItem> *items)
void PlaylistWidget::remove(QPtrList<QListViewItem> &items)
{
playlistList->remove(items);
}
FileList *PlaylistWidget::getPlaylistList()
{
return(playlistList);
}
QPtrList<QListViewItem> *PlaylistWidget::getSelectedItems()
QPtrList<QListViewItem> PlaylistWidget::getSelectedItems()
{
return(new QPtrList<QListViewItem>(playlistList->selectedItems()));
return(playlistList->selectedItems());
}
FileListItem *PlaylistWidget::firstItem()
......
......@@ -32,14 +32,14 @@ public:
~PlaylistWidget();
void add(QString item);
void add(QStringList *items);
void add(QStringList &items);
void add(FileListItem *item);
void add(QPtrList<QListViewItem> *items);
void add(QPtrList<QListViewItem> &items);
void remove(QPtrList<QListViewItem> *items);
void remove(QPtrList<QListViewItem> &items);
FileList *getPlaylistList();
QPtrList<QListViewItem> *getSelectedItems();
QPtrList<QListViewItem> getSelectedItems();
FileListItem *firstItem();
private:
void setupLayout();
......
......@@ -41,14 +41,17 @@ TaggerWidget::TaggerWidget(QWidget *parent) : QWidget(parent)
readConfig();
}
TaggerWidget::~TaggerWidget() {}
TaggerWidget::~TaggerWidget()
{
}
void TaggerWidget::add(QString item)
{
taggerList->append(item);
}
void TaggerWidget::add(QStringList *items)
void TaggerWidget::add(QStringList &items)
{
taggerList->append(items);
}
......@@ -58,9 +61,9 @@ FileList *TaggerWidget::getTaggerList()
return(taggerList);
}
QPtrList<QListViewItem> *TaggerWidget::getSelectedItems()
QPtrList<QListViewItem> TaggerWidget::getSelectedItems()
{
return(new QPtrList<QListViewItem>(taggerList->selectedItems()));
return(taggerList->selectedItems());
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -33,17 +33,18 @@
class TaggerWidget : public QWidget
{
Q_OBJECT
public:
TaggerWidget(QWidget *parent);
~TaggerWidget();
void add(QString item);
void add(QStringList *items);
void add(QStringList &items);
FileList *getTaggerList();
// FileListItem *getSelectedItem();
QPtrList<QListViewItem> *getSelectedItems();
QPtrList<QListViewItem> getSelectedItems();
public slots:
void save();
......
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