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 5272402f authored by Scott Wheeler's avatar Scott Wheeler

Added "reload from disk" in the RMB menu for the PlaylistBox.

svn path=/trunk/kdemultimedia/juk/; revision=218107
parent e3edd77c
......@@ -139,7 +139,7 @@ void JuK::setupActions()
m_stopAction = new KAction(i18n("&Stop"), "player_stop", 0, this, SLOT(stop()), actionCollection(), "stop");
m_backAction = new KAction(i18n("Skip &Back"), "player_start", 0, this, SLOT(back()), actionCollection(), "back");
m_forwardAction = new KAction(i18n("Skip &Forward"), "player_end", 0, this, SLOT(forward()), actionCollection(), "forward");
m_loopPlaylistAction = new KToggleAction(i18n("&Loop Playlist"), "reload", 0, actionCollection(), "loopPlaylist");
m_loopPlaylistAction = new KToggleAction(i18n("&Loop Playlist"), 0, 0, actionCollection(), "loopPlaylist");
// tagger menu
new KAction(i18n("&Save"), "filesave", "CTRL+t", m_splitter, SLOT(slotSaveTag()), actionCollection(), "saveItem");
......
......@@ -198,39 +198,11 @@ Playlist::Playlist(QWidget *parent, const QString &name) : KListView(parent, nam
}
Playlist::Playlist(const QFileInfo &playlistFile, QWidget *parent, const char *name) : KListView(parent, name),
m_playlistFileName(playlistFile.absFilePath()),
m_fileName(playlistFile.absFilePath()),
m_playingItem(0), m_leftColumn(0)
{
setup();
QFile file(m_playlistFileName);
if(!file.open(IO_ReadOnly))
return;
QTextStream stream(&file);
// turn off non-explicit sorting
setSorting(columns() + 1);
PlaylistItem *after = 0;
while(!stream.atEnd()) {
QString itemName = (stream.readLine()).stripWhiteSpace();
QFileInfo item(itemName);
if(item.isRelative())
item.setFile(QDir::cleanDirPath(playlistFile.dirPath(true) + "/" + itemName));
if(item.exists() && item.isFile() && item.isReadable()) {
if(after)
after = createItem(item, after);
else
after = createItem(item);
}
}
file.close();
loadFile(m_fileName, playlistFile);
}
Playlist::~Playlist()
......@@ -240,13 +212,13 @@ Playlist::~Playlist()
void Playlist::save()
{
if(m_playlistFileName.isEmpty())
if(m_fileName.isEmpty())
return saveAs();
QFile file(m_playlistFileName);
QFile file(m_fileName);
if(!file.open(IO_WriteOnly))
return KMessageBox::error(this, i18n("Could not save to file %1.").arg(m_playlistFileName));
return KMessageBox::error(this, i18n("Could not save to file %1.").arg(m_fileName));
QTextStream stream(&file);
......@@ -262,13 +234,13 @@ void Playlist::saveAs()
{
QStringList extensions = PlaylistSplitter::playlistExtensions();
m_playlistFileName = KFileDialog::getSaveFileName(name() + "." + PlaylistSplitter::playlistExtensions().first(),
m_fileName = KFileDialog::getSaveFileName(name() + "." + PlaylistSplitter::playlistExtensions().first(),
PlaylistSplitter::extensionsString(extensions, i18n("Playlists")));
m_playlistFileName = m_playlistFileName.stripWhiteSpace();
m_fileName = m_fileName.stripWhiteSpace();
if(m_playlistFileName != QString::null) {
if(extensions.find(m_playlistFileName.section('.', -1)) == extensions.end())
m_playlistFileName.append('.' + extensions.first());
if(m_fileName != QString::null) {
if(extensions.find(m_fileName.section('.', -1)) == extensions.end())
m_fileName.append('.' + extensions.first());
if(m_playlistName.isEmpty())
emit signalNameChanged(name());
......@@ -383,7 +355,7 @@ PlaylistItem *Playlist::previousItem(PlaylistItem *current, bool random)
QString Playlist::name() const
{
if(m_playlistName.isNull())
return m_playlistFileName.section(QDir::separator(), -1).section('.', 0, -2);
return m_fileName.section(QDir::separator(), -1).section('.', 0, -2);
else
return m_playlistName;
}
......@@ -423,7 +395,11 @@ void Playlist::paste()
void Playlist::clear()
{
clearItems(selectedItems());
PlaylistItemList l = selectedItems();
if(l.isEmpty())
l = items();
clearItems(l);
}
void Playlist::slotGuessTagInfo()
......@@ -435,6 +411,16 @@ void Playlist::slotGuessTagInfo()
KApplication::restoreOverrideCursor();
}
void Playlist::slotReload()
{
QFileInfo fileInfo(m_fileName);
if(!fileInfo.exists() || !fileInfo.isFile() || !fileInfo.isReadable())
return;
clear();
loadFile(m_fileName, fileInfo);
}
////////////////////////////////////////////////////////////////////////////////
// protected members
////////////////////////////////////////////////////////////////////////////////
......@@ -742,6 +728,38 @@ void Playlist::setup()
connect(header(), SIGNAL(indexChange(int, int, int)), this, SLOT(slotColumnOrderChanged(int, int, int)));
}
void Playlist::loadFile(const QString &fileName, const QFileInfo &fileInfo)
{
QFile file(fileName);
if(!file.open(IO_ReadOnly))
return;
QTextStream stream(&file);
// turn off non-explicit sorting
setSorting(columns() + 1);
PlaylistItem *after = 0;
while(!stream.atEnd()) {
QString itemName = (stream.readLine()).stripWhiteSpace();
QFileInfo item(itemName);
if(item.isRelative())
item.setFile(QDir::cleanDirPath(fileInfo.dirPath(true) + "/" + itemName));
if(item.exists() && item.isFile() && item.isReadable()) {
if(after)
after = createItem(item, after);
else
after = createItem(item);
}
}
file.close();
}
void Playlist::setPlaying(PlaylistItem *item, bool playing)
{
if(playing) {
......
......@@ -91,8 +91,8 @@ public:
*/
virtual PlaylistItem *createItem(const QFileInfo &file, QListViewItem *after = 0);
QString fileName() const { return m_playlistFileName; }
void setFileName(const QString &n) { m_playlistFileName = n; }
QString fileName() const { return m_fileName; }
void setFileName(const QString &n) { m_fileName = n; }
void hideColumn(int c);
void showColumn(int c);
......@@ -147,6 +147,10 @@ public slots:
virtual void selectAll() { KListView::selectAll(true); }
void slotGuessTagInfo();
/**
* Reload the playlist contents from the m3u file.
*/
void slotReload();
protected:
/**
......@@ -199,6 +203,7 @@ signals:
private:
void setup();
void loadFile(const QString &fileName, const QFileInfo &fileInfo);
void applyTag(QListViewItem *item, const QString &text, int column);
int leftMostVisibleColumn() const;
......@@ -224,7 +229,7 @@ private:
bool m_allowDuplicates;
QPtrStack<PlaylistItem> m_history;
QString m_playlistFileName;
QString m_fileName;
/**
* This is only defined if the playlist name is something other than the
......
......@@ -45,21 +45,23 @@ PlaylistBox::PlaylistBox(PlaylistSplitter *parent, const char *name) : KListBox(
m_playlistContextMenu = new KPopupMenu();
m_popupIndex["save"] = m_playlistContextMenu->insertItem(
SmallIconSet("filesave"), i18n("Save"), this,
SLOT(slotContextSave()));
m_popupIndex["saveas"] = m_playlistContextMenu->insertItem(
SmallIconSet("filesaveas"), i18n("Save As..."), this,
SLOT(slotContextSaveAs()));
m_popupIndex["rename"] = m_playlistContextMenu->insertItem(
i18n("Rename..."), this,
SLOT(slotContextRename()));
m_popupIndex["save"] = m_playlistContextMenu->insertItem(
SmallIconSet("filesave"), i18n("Save"), this, SLOT(slotContextSave()));
m_popupIndex["saveas"] = m_playlistContextMenu->insertItem(
SmallIconSet("filesaveas"), i18n("Save As..."), this, SLOT(slotContextSaveAs()));
m_popupIndex["rename"] = m_playlistContextMenu->insertItem(
i18n("Rename..."), this, SLOT(slotContextRename()));
m_popupIndex["duplicate"] = m_playlistContextMenu->insertItem(
SmallIconSet("editcopy"), i18n("Duplicate..."), this,
SLOT(slotContextDuplicate()));
m_popupIndex["remove"] = m_playlistContextMenu->insertItem(
SmallIconSet("edittrash"), i18n("Remove"), this,
SLOT(slotContextDeleteItem()));
SmallIconSet("editcopy"), i18n("Duplicate..."), this, SLOT(slotContextDuplicate()));
m_popupIndex["remove"] = m_playlistContextMenu->insertItem(
SmallIconSet("edittrash"), i18n("Remove"), this, SLOT(slotContextDeleteItem()));
m_popupIndex["reload"] = m_playlistContextMenu->insertItem(
SmallIconSet("reload"), i18n("Reload Playlist File"), this, SLOT(slotContextReload()));
setAcceptDrops(true);
setSelectionMode(Extended);
......@@ -261,6 +263,12 @@ void PlaylistBox::deleteItem(Item *item)
delete item;
}
void PlaylistBox::reload(Item *item)
{
if(item && item->playlist())
item->playlist()->slotReload();
}
void PlaylistBox::resizeEvent(QResizeEvent *e)
{
triggerUpdate(true);
......@@ -379,18 +387,16 @@ void PlaylistBox::slotShowContextMenu(QListBoxItem *item, const QPoint &point)
m_contextMenuOn = i;
if(i) {
if(i->playlist() == CollectionList::instance()) {
m_playlistContextMenu->setItemEnabled(m_popupIndex["save"], false);
m_playlistContextMenu->setItemEnabled(m_popupIndex["saveas"], false);
m_playlistContextMenu->setItemEnabled(m_popupIndex["rename"], false);
m_playlistContextMenu->setItemEnabled(m_popupIndex["remove"], false);
}
else {
m_playlistContextMenu->setItemEnabled(m_popupIndex["save"], true);
m_playlistContextMenu->setItemEnabled(m_popupIndex["saveas"], true);
m_playlistContextMenu->setItemEnabled(m_popupIndex["rename"], true);
m_playlistContextMenu->setItemEnabled(m_popupIndex["remove"], true);
}
bool isCollection = i->playlist() == CollectionList::instance();
bool hasFile = !i->playlist()->fileName().isEmpty();
m_playlistContextMenu->setItemEnabled(m_popupIndex["save"], !isCollection);
m_playlistContextMenu->setItemEnabled(m_popupIndex["saveas"], !isCollection);
m_playlistContextMenu->setItemEnabled(m_popupIndex["rename"], !isCollection);
m_playlistContextMenu->setItemEnabled(m_popupIndex["remove"], !isCollection);
m_playlistContextMenu->setItemEnabled(m_popupIndex["reload"], !isCollection);
m_playlistContextMenu->setItemEnabled(m_popupIndex["reload"], hasFile);
m_playlistContextMenu->popup(point);
}
}
......@@ -421,6 +427,12 @@ void PlaylistBox::slotContextDeleteItem()
m_contextMenuOn = 0;
}
void PlaylistBox::slotContextReload()
{
reload(m_contextMenuOn);
m_contextMenuOn = 0;
}
////////////////////////////////////////////////////////////////////////////////
// PlaylistBox::Item public methods
////////////////////////////////////////////////////////////////////////////////
......
......@@ -77,6 +77,7 @@ private:
void rename(Item *item);
void duplicate(Item *item);
void deleteItem(Item *item);
void reload(Item *item);
virtual void resizeEvent(QResizeEvent *e);
virtual void decode(QMimeSource *s, Item *item);
......@@ -106,6 +107,7 @@ private slots:
void slotContextRename();
void slotContextDuplicate();
void slotContextDeleteItem();
void slotContextReload();
private:
PlaylistSplitter *m_splitter;
......
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