⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qmplaylistbrowser.cpp

📁 可以播放MP3,wma等文件格式的播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* qmplaylistbrowser.cpp * * $Id: qmplaylistbrowser.cpp,v 1.30 2002/03/31 23:52:42 kyllingstad Exp $ * * Apollo sound player: http://www.apolloplayer.org * Copyright(C) 2000-2002 Apollo Team.  See CREDITS file. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * * The GNU General Public License is also available online at: * * http://www.gnu.org/copyleft/gpl.html */#include "qmplaylistbrowser.h"#include "message.h"#include "qmbrowseritem.h"#include "qmconfig.h"#include "qmdefaultmenuitem.h"#include "qmdiritem.h"#include "qmfiledialog.h"#include "qmmainwindow.h"#include "qmplaylist.h"#include "qmplaylistbrowseritem.h"#include "qmplaylistpropertypage.h"#include "qmrecoverymanager.h"#include "qmrenameedit.h"#include <iostream>#include <qdom.h>#include <qfile.h>#include <qfont.h>#include <qheader.h>#include <qnamespace.h>#include <qpopupmenu.h>#include <qstring.h>/* Disables false warning in Visual Studio about dynamic_cast */#ifdef _WS_WIN_#pragma warning(disable: 4541)#endif/*! * \file qmplaylistbrowser.cpp * \brief The playlist tree widget, for browsing playlists *//*!  \class QmPlayListBrowser qmplaylistbrowser.h  \brief Represents the playlist tree  Provides functionality for organizing playlist in trees.  The playlists  (apollo xml/m3u files) can be used to populate the playlist widget,  either file by file or by adding entire tree/subtrees of playlists to the  playlist widget.*//*!  Creates a new playlist browser.*/QmPlayListBrowser::QmPlayListBrowser(	QWidget *parent,	const char * /*name*/ )	: QmListView(parent, "playlisttree"),	  m_pPlayListSelected(0),	  m_pPropertyPage(0),	  m_pRenameEdit(0),	  m_pRenameItem(0),	  m_pFileDialog(0),      m_PlayListTree(){	enableSelfSave(QmConfig::instance()->configPath() + "playlisttree");	addColumn(tr("List"));	header()->hide();	setRootIsDecorated(true);    setSelectionMode(Extended);	reorganizable(true);	connect(this, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint &, int)),			this, SLOT(mouseClick(int, QListViewItem*, const QPoint &, int)));	connect(this, SIGNAL(doubleClicked( QListViewItem* )),			this, SLOT(mouseDoubleClick( QListViewItem* )));	if(QmConfig::instance()->loadingEnabled(QmConfig::PlayListTree))		loadPlayListTree();	m_pRenameEdit = new QmRenameEdit(this);	m_pRenameEdit->hide();	connect(m_pRenameEdit, SIGNAL(newName(const QString &)), this, SLOT(renameItem(const QString &)));	// -----------		m_pMenu = new QPopupMenu(this);	m_PrependPlayListId = m_pMenu->insertItem(tr("Add to top"),											  this,											  SLOT(prependPlayList()));	QFont f = m_pMenu->font();    m_AppendPlayListId = m_pMenu->insertItem(new QmDefaultMenuItem(tr("Add to end"), f));    m_pMenu->connectItem(m_AppendPlayListId, this, SLOT(appendPlayList()));	m_ReplacePlayListId = m_pMenu->insertItem(tr("Replace (middle click)"),											  this,											  SLOT(replacePlayList()));	m_pMenu->insertSeparator();	m_AddPlayListFolderId = m_pMenu->insertItem(tr("Add folder"),												this,												SLOT(addPlayListFolder()));	m_RenamePlayListId = m_pMenu->insertItem(tr("Rename"),											 this,											 SLOT(renamePlayList()));	m_PropertyPlayListId = m_pMenu->insertItem(tr("Properties..."),											   this,											   SLOT(propertyPlayList()));	m_pMenu->insertSeparator();	m_RemovePlayListId = m_pMenu->insertItem(tr("Remove"),											 this,											 SLOT(removeSelectedItems()));	m_pMenu->insertItem(        tr("Clear"),        this,        SLOT(clear()));		m_pMenu->insertSeparator();	m_SavePlayListId1 = m_pMenu->insertItem(tr("Add playlist file..."),											this,											SLOT(addOldPlayList()));	m_SavePlayListId2 = m_pMenu->insertItem(tr("Put current playlist in tree..."),											this,											SLOT(addNewPlayList()));    m_LoadFileId = m_pMenu->insertItem(tr("Load new playlist tree..."), this, SLOT(loadFile()));    m_SaveFileId = m_pMenu->insertItem(tr("Save playlist tree"), this, SLOT(saveFile(int)));	m_pMenu->setItemParameter(m_SaveFileId, 0);    m_SaveFileAsId = m_pMenu->insertItem(tr("Save playlist tree As..."), this, SLOT(saveFile(int)));	m_pMenu->setItemParameter(m_SaveFileId, 1);}/*!  Saves the playlist tree.*/QmPlayListBrowser::~QmPlayListBrowser(){	if( ! fileName().isEmpty())		save();}/*!  Identical to QListView::currentItem() except it casts the item into  a QmPlayListBrowserItem pointer.  Provided for convenience.    \return The currently selected playlist or 0 if none selected.*/QmPlayListBrowserItem *QmPlayListBrowser::currentPlayList(){	return static_cast<QmPlayListBrowserItem *>(currentItem());}/*!  Called when an item is expanded.  Takes care of collapsing the previously  expanded item, if any, so that only one item is expanded at a time.  Currently commented out because it doesn't work (?)  \bug Fails if there are subitems (which is not supported yet) */voidQmPlayListBrowser::expanded(	QListViewItem * /* item */){	/*	if(m_pLastExpanded != 0 && m_pLastExpanded != item)		m_pLastExpanded->setOpen(false);	m_pLastExpanded = item;	*/}/*!  Called when either of the mouse buttons are clicked.  \sa showPopup(QListViewItem*, const QPoint&, int) */voidQmPlayListBrowser::mouseClick(    int button,    QListViewItem * item,    const QPoint & pos,    int c ){    if (QmMainWindow::mainwin->state() == QmMainWindow::Ready) {        QmMainWindow::mainwin->setState(QmMainWindow::Busy);        if ( button & Qt::MidButton )            replacePlayList();        else if ( button & Qt::RightButton )            showPopup(item, pos, c);        else if ( button & Qt::LeftButton )        {            if(item == 0 && m_pRenameEdit->isVisible())                m_pRenameEdit->hide();        }                QmMainWindow::mainwin->setState(QmMainWindow::Ready);    }}/*!  Called when the left mouse button has been double clicked. */voidQmPlayListBrowser::mouseDoubleClick(    QListViewItem * /* item */ ){    appendPlayList();}/*!  Called by mouseClick() when the user clicks the right mouse button.  Enables/disables the various menu items according to what item is  currently highlighted (or no item is highlighted).  \sa mouseClick(int, QListViewItem*, const QPoint&, int) */voidQmPlayListBrowser::showPopup(	QListViewItem *current,	const QPoint &pos,	int){	m_pPlayListSelected = dynamic_cast<QmPlayListBrowserItem*>(current);		m_pMenu->setItemEnabled(m_SavePlayListId2, !QmMainWindow::mainwin->playListIsEmpty());    	if(m_pPlayListSelected == 0)		m_pMenu->setItemEnabled(m_AddPlayListFolderId, true);	else		m_pMenu->setItemEnabled(m_AddPlayListFolderId, m_pPlayListSelected->isFolder());	bool enable = m_pPlayListSelected != 0;    	m_pMenu->setItemEnabled(m_RenamePlayListId, enable);	m_pMenu->setItemEnabled(m_PropertyPlayListId, enable);	m_pMenu->setItemEnabled(m_RemovePlayListId, enable);	m_pMenu->setItemEnabled(m_PrependPlayListId, enable);	m_pMenu->setItemEnabled(m_AppendPlayListId, enable);	m_pMenu->setItemEnabled(m_ReplacePlayListId, enable);			m_pMenu->popup(pos);}/*!  Appends the playlist with the selected playlist, if any.  \sa prependPlayList(), replacePlayList() */voidQmPlayListBrowser::appendPlayList(){	QList<QListViewItem> *items = selectedItems();	for (QmPlayListBrowserItem *i=reinterpret_cast<QmPlayListBrowserItem*>(items->first());		 i;		 i = reinterpret_cast<QmPlayListBrowserItem*>(items->next()))    {		if (i->isFolder())			addFolder(i); 		else			QmMainWindow::mainwin->playListAppendList(i->fileName());    }	delete items;}/*!  Prepends the playlist with the selected playlist, if any.  \sa replacePlayList(), appendPlayList() */voidQmPlayListBrowser::prependPlayList(){	QList<QListViewItem> *items = selectedItems();    	for (QmPlayListBrowserItem *i=reinterpret_cast<QmPlayListBrowserItem*>(items->last());		 i;		 i = reinterpret_cast<QmPlayListBrowserItem*>(items->prev()))    {		if (i->isFolder())			addFolder(i, false); 		else			QmMainWindow::mainwin->playListPrependList(i->fileName());    }    	delete items;}/*!  Replaces the playlist with the selected playlist, if any.  \sa prependPlayList(), appendPlayList() */voidQmPlayListBrowser::replacePlayList(){	QmMainWindow::mainwin->clearPlayList();	appendPlayList();}/*!  Appends all the playlists in a folder to the playlist.*/voidQmPlayListBrowser::addFolder(QmPlayListBrowserItem *folder, bool append){    for (QmPlayListBrowserItem *i = static_cast<QmPlayListBrowserItem *>(folder->firstChild());         i;         i = static_cast<QmPlayListBrowserItem *>(i->nextSibling()))    {        if (i->isFolder())            addFolder(i, append);        else			if (append)				QmMainWindow::mainwin->playListAppendList(i->fileName());			else				QmMainWindow::mainwin->playListPrependList(i->fileName());    }}/*!  Adds the current playlist to the tree, pops up a dialog asking for a name  if it doesn't already have one. */voidQmPlayListBrowser::addNewPlayList(){	QString filename = QmMainWindow::mainwin->playListFile();	if (filename.isEmpty())	{		if(m_pFileDialog == 0)			m_pFileDialog = new QmFileDialog();		m_pFileDialog->setDir(QmConfig::instance()->getString("path", "playlist"));		m_pFileDialog->setMode(QFileDialog::AnyFile);		m_pFileDialog->setFilter("Playlists (*.m3u *.xml)");		connect( m_pFileDialog, SIGNAL( dialogDone( QFileDialog *, int ) ),				 this, SLOT( doAddNewPlayList( QFileDialog *, int ) ) );		m_pFileDialog->setCaption(tr("Apollo - Give the new playlist a name"));		m_pFileDialog->show();	}	else		reallyAddNewPlayList(filename);}/*!  Called when the playlist file dialog is done.*/voidQmPlayListBrowser::doAddNewPlayList(	QFileDialog *dlg,	int val){    if ( val == QDialog::Accepted )    {		QmConfig::instance()->set("path", "playlist", dlg->dirPath());		reallyAddNewPlayList(dlg->selectedFile());	}	    disconnect( m_pFileDialog, SIGNAL( dialogDone( QFileDialog *, int ) ),                this, SLOT( doAddNewPlayList( QFileDialog *, int ) ) );}/*!  Actually adds \a playlist to the tree.  Called from addNewPlayList() if  the playlist already had a name, and from doAddNewPlayList() if it didn't.  (All as a result of the "Put current playlist in tree..." context menu)*/voidQmPlayListBrowser::reallyAddNewPlayList(const QString &playlist){	QFileInfo fi(playlist);	if(m_pPlayListSelected == 0)		(void) new QmPlayListBrowserItem(this, 0, fi.baseName(), playlist);	else if(m_pPlayListSelected->isFolder())	{		m_pPlayListSelected->setExpandable(true);		m_pPlayListSelected->setOpen(true);		clearSelection();				(void) new QmPlayListBrowserItem(m_pPlayListSelected, 0, fi.baseName(), playlist);	}	else		(void) new QmPlayListBrowserItem(this, 0, fi.baseName(), playlist);}/*!  Pops up a dialog asking for the name (connecting doSaveFile() on close)  if it doesn't have a name or \a forceAskp, otherwize saves the tree.*/voidQmPlayListBrowser::saveFile(int forceAskp){	if (fileName().isEmpty() || forceAskp)	{		if(m_pFileDialog == 0)			m_pFileDialog = new QmFileDialog();				m_pFileDialog->setDir(QmConfig::instance()->getString("path", "playlisttree"));		m_pFileDialog->setMode(QFileDialog::AnyFile);		m_pFileDialog->setFilter("Playlist tree (*.xml)");				connect( m_pFileDialog, SIGNAL( dialogDone( QFileDialog *, int ) ),             this, SLOT( doSaveFile( QFileDialog *, int ) ) );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -