Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 52fe7a8d authored by Scott Wheeler's avatar Scott Wheeler

Switched FileListItem to also be based on QFileInfo, rather than having

a QFileInfo member.  Also I began work on allowing FileListItems to be
added to a FileList by the add() and append() members.

svn path=/trunk/kdemultimedia/juk/; revision=143309
parent fa92a475
......@@ -59,12 +59,22 @@ void FileList::append(QString item)
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();
}
void FileList::append(FileListItem *item)
{
}
void FileList::append(QPtrList<QListViewItem> *items)
{
// for(QPtrListIterator it = items->begin(); it != items->end(); ++it)
// append(QString((*it)));
}
FileListItem *FileList::getSelectedItem()
{
return(dynamic_cast<FileListItem *>(currentItem()));
......@@ -92,13 +102,6 @@ void FileList::setup()
setItemMargin(3);
setSorting(1);
// QColor backGround = paletteBackgroundColor();
// int r, g, b;
// backGround.rgb(&r, &g, &b);
// r=r-5; g=g-5; b=b-5;
// const QColor ab(10,10,10);
// setAlternateBackground(ab);
}
void FileList::appendImpl(QString item)
......@@ -115,8 +118,9 @@ void FileList::appendImpl(QString item)
}
}
else {
// QFileInfo::extension() doesn't always work, so I'm getting old-school on this.
QString extension=file->filePath().right(file->filePath().length() - (file->filePath().findRev(".") + 1));
// QFileInfo::extension() doesn't always work, so I'm getting old-school on this. -- fixed in Qt 3
// QString extension = file->filePath().right(file->filePath().length() - (file->filePath().findRev(".") + 1));
QString extension = file->extension(false);
if(extensions.contains(extension) > 0 && members.contains(file->absFilePath()) == 0) {
members.append(file->absFilePath());
(void) new FileListItem(file, this);
......
......@@ -34,6 +34,8 @@ public:
void append(QString item);
void append(QStringList *items);
void append(FileListItem *item);
void append(QPtrList<QListViewItem> *items);
FileListItem *getSelectedItem();
......
......@@ -23,11 +23,11 @@
// public methods
////////////////////////////////////////////////////////////////////////////////
FileListItem::FileListItem(QFileInfo *file, KListView *parent) : KListViewItem(parent)
FileListItem::FileListItem(QFileInfo *file, KListView *parent) : KListViewItem(parent), QFileInfo(*file)
{
header = 0;
fileInfo = file;
tag = new Tag(fileInfo->filePath());
// fileInfo = file;
tag = new Tag(filePath());
refresh();
}
......@@ -41,15 +41,10 @@ FileListItem::~FileListItem()
delete(header);
}
QFileInfo *FileListItem::getFileInfo()
{
return(fileInfo);
}
Tag *FileListItem::getTag()
{
if(!tag) {
tag = new Tag(fileInfo->filePath());
tag = new Tag(filePath());
}
return(tag);
}
......@@ -57,15 +52,14 @@ Tag *FileListItem::getTag()
MPEGHeader *FileListItem::getHeader()
{
if(!header) {
header = new MPEGHeader(fileInfo->filePath());
header = new MPEGHeader(filePath());
}
return(header);
}
void FileListItem::setFile(QString fileName)
{
if(fileInfo)
fileInfo->setFile(fileName);
setFile(fileName);
if(header) {
delete(header);
......@@ -85,7 +79,7 @@ void FileListItem::refresh()
setText(3, tag->getTrackNumberString());
setText(4, tag->getGenre());
setText(5, tag->getYearString());
setText(6, fileInfo->filePath());
setText(6, filePath());
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -24,12 +24,11 @@
#include "tag.h"
#include "MPEGHeader.h"
class FileListItem : public KListViewItem {
class FileListItem : public KListViewItem, public QFileInfo {
public:
FileListItem(QFileInfo *file, KListView *parent);
~FileListItem();
QFileInfo *getFileInfo();
Tag *getTag();
MPEGHeader *getHeader();
......
......@@ -194,7 +194,7 @@ void JuK::playFile()
float volume = float(sliderAction->getVolumeSlider()->value()) / float(sliderAction->getVolumeSlider()->maxValue());
playTimer=new QTimer(this);
player.play(tagger->getSelectedItem()->getFileInfo()->absFilePath(), volume);
player.play(tagger->getSelectedItem()->absFilePath(), volume);
if(player.playing()) {
playAction->setEnabled(false);
pauseAction->setEnabled(true);
......
......@@ -48,6 +48,15 @@ void PlaylistWidget::add(QStringList *items)
playlistList->append(items);
}
void PlaylistWidget::add(FileListItem *item)
{
playlistList->append(item);
}
void PlaylistWidget::add(QPtrList<QListViewItem> *items)
{
playlistList->append(items);
}
////////////////////////////////////////////////////////////////////////////////
// private members
......
......@@ -18,9 +18,10 @@
#ifndef PLAYLISTWIDGET_H
#define PLAYLISTWIDGET_H
// #include <unistd.h>
#include <klistview.h>
#include <klistview.h>
#include "filelist.h"
#include "filelistitem.h"
class PlaylistWidget : public QWidget
{
......@@ -30,6 +31,8 @@ public:
void add(QString item);
void add(QStringList *items);
void add(FileListItem *item);
void add(QPtrList<QListViewItem> *items);
private:
void setupLayout();
......
......@@ -75,21 +75,21 @@ void TaggerWidget::save()
FileListItem *item = dynamic_cast<FileListItem *>(items.first());
if(item && changed) {
QFileInfo newFile(item->getFileInfo()->dirPath() + QDir::separator() + fileNameBox->text());
QFileInfo directory(item->getFileInfo()->dirPath());
QFileInfo newFile(item->dirPath() + QDir::separator() + fileNameBox->text());
QFileInfo directory(item->dirPath());
// if (the new file is writable or the new file doesn't exist and it's directory is writable)
// and the old file is writable...
if((newFile.isWritable() || (!newFile.exists() && directory.isWritable())) && item->getFileInfo()->isWritable()) {
if((newFile.isWritable() || (!newFile.exists() && directory.isWritable())) && item->isWritable()) {
// if the file name in the box doesn't match the current file name
if(item->getFileInfo()->fileName()!=newFile.fileName()) {
if(item->fileName()!=newFile.fileName()) {
// rename the file if it doesn't exist or we say it's ok
if(!newFile.exists() ||
KMessageBox::warningYesNo(this, i18n("This file already exists.\nDo you want to replace it?"),
i18n("File Exists")) == KMessageBox::Yes)
{
QDir currentDir;
currentDir.rename(item->getFileInfo()->filePath(), newFile.filePath());
currentDir.rename(item->filePath(), newFile.filePath());
item->setFile(newFile.filePath());
}
}
......@@ -283,7 +283,7 @@ void TaggerWidget::readConfig()
void TaggerWidget::updateBoxes() // this needs to be updated to properly work with multiple selections
{
// kdDebug() << "updateBoxes(): " << item->getFileInfo()->filePath() << endl;
// kdDebug() << "updateBoxes(): " << item->filePath() << endl;
QPtrList<QListViewItem> items = taggerList->selectedItems();
......@@ -293,7 +293,6 @@ void TaggerWidget::updateBoxes() // this needs to be updated to properly work wi
if(item) {
Tag *tag = item->getTag();
QFileInfo *fileInfo = item->getFileInfo();
MPEGHeader *header = item->getHeader();
artistNameBox->setEditText(tag->getArtist());
......@@ -307,7 +306,7 @@ void TaggerWidget::updateBoxes() // this needs to be updated to properly work wi
genreBox->setEditText(tag->getGenre());
}
fileNameBox->setText(fileInfo->fileName());
fileNameBox->setText(item->fileName());
trackSpin->setValue(tag->getTrackNumber());
yearSpin->setValue(tag->getYear());
......
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