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

📄 qmdiritem.cpp

📁 可以播放MP3,wma等文件格式的播放器
💻 CPP
字号:
/* qmdiritem.cpp * * $Id: qmdiritem.cpp,v 1.39.2.1 2002/09/23 19:26:50 kyllingstad Exp $ * * QtVu is a user-friendly image viewer and browser for X11. * See http://www.qtvu.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 "qmdiritem.h"#include "qmlistview.h"#include "qmpixmapsupplier.h"#include "qmsongitem.h"#include "qmconfig.h"#include "message.h"#include <iostream>#include <qapplication.h>#include <qdir.h>#include <qfile.h>#include <qfileinfo.h>#include <qglobal.h>#include <qlistview.h>#include <qlistview.h>#include <qpixmap.h>#include <qstring.h>#include <qtextstream.h>/* Disables false warning in Visual Studio about dynamic_cast */#ifdef _WS_WIN_#pragma warning(disable: 4541)#endif/** * @file qmdiritem.cpp * @brief Directory widget for the playlist *//*!  \class QmDirItem qmdiritem.h  \brief Represents a directory in the playlist.  A QmDirItem item can be created as 'autoload' or not.  If it  is an autoloading item, it will populate its children by itself  when expanded.  All *.mp3 files and folders will be listed as its  children.  If the item is not created as 'autoload', it's up to the  creator of the object to populate the children.  The item acts  as a regular item.  \sa QmSongItem*//* Based on the dirview example by Troll Tech. *//*!  Creates a new directory item.  \a parent is the parent directory item  and \a after specifies which item \e this item is to be placed after.  \a path is the path to be read.  If \a autoload is true, the item  will automatically populate its children when expanded by listing  all *.mp3 files and folders.  If \a autoload is false, the population  is left to the creator of the item.*/QmDirItem::QmDirItem(    QmDirItem *parent,    QListViewItem *after,    const char *path,    int &count,	bool autoload)    : QmPlayListItem(parent, after),	  m_Dir(path),	  m_AutoLoad(autoload),      m_Label(m_Dir.dirName()){	init( m_AutoLoad, count );}/*!  Creates a new directory item.  The root will be listed. */QmDirItem::QmDirItem(    QListView *parent,    QListViewItem *after,	const char *path,    int &count,	bool autoload)    : QmPlayListItem(parent, after),	  m_Dir(path),	  m_AutoLoad(autoload),      m_Label(m_Dir.dirName()){	init( m_AutoLoad, count );}QmDirItem::QmDirItem(    QListView *parent,    QListViewItem *after,	QString &label)    : QmPlayListItem(parent, after),      m_AutoLoad(false),      m_Label(label){}QmDirItem::QmDirItem(    QmDirItem *parent,    QListViewItem *after,	QString &label)    : QmPlayListItem(parent, after),      m_AutoLoad(false),      m_Label(label){}/*!  Initializes the directory item.*/voidQmDirItem::init( bool exp, int &count ){    QListViewItem::setOpen(false);    if ( exp )         expand(count);    QListViewItem::setOpen(true);}/*!  Overridden to always set the item open.*/voidQmDirItem::setOpen(    bool o){    QListViewItem::setOpen(o);}/*!  Reads the sub directories of this directory.  If \a o is true,  the tree will be exanded, otherwise collapsed. */voidQmDirItem::expand(int &count){    qApp->processEvents();    QString s(fullName());    const QFileInfoList *filelist;	QString format = QmConfig::instance()->getString("stuff", "display-format");	QString formatMulti = QmConfig::instance()->getString("stuff", "display-format-multi");	const char *cformat = format.latin1();	const char *cformatMulti = formatMulti.latin1();    QDir dir(s);    dir.setFilter(QDir::Readable);    dir.setSorting(QDir::DirsFirst);    filelist = dir.entryInfoList( QDir::Dirs );    if(filelist)    {        QFileInfoListIterator it(*filelist);        QFileInfo *fi;        QListViewItem *last = lastChild();	            while((fi = it.current()))        {            ++it;            if(fi->fileName() != "." && fi->fileName() != ".." && fi->isReadable())            {                if(fi->isDir())                {                    if ( !hasDirItem( fi ) )                    {                        QmPlayListItem *cur = new QmDirItem( this, last, fi->absFilePath(), count,true  );                        last = cur;                    }                }                else                    qWarning( "\"%s\" is not a directory which was expected by file info",                              fi->absFilePath().ascii() );                qApp->processEvents();            }        }    }    dir = QDir(s);    dir.setFilter(QDir::Readable);    dir.setNameFilter("*.mp3");    dir.setSorting(QDir::DirsFirst);    filelist = dir.entryInfoList( QDir::Files );    if(filelist)    {        QFileInfoListIterator it(*filelist);        QFileInfo *fi;        QmPlayListItem *last = lastChild();        while((fi = it.current()))        {            ++it;            if(fi->fileName() != "." && fi->fileName() != ".." && fi->isReadable())            {                if(!fi->isDir())                {                    if ( !hasSongItem( fi ) )                    {                        QmPlayListItem *cur = new QmSongItem( this, last, fi->absFilePath() );						/*! \todo this is slow and should be configurable */						// rk: hardcoded 25 for now since it will let you add an album						if (count < 25)							static_cast<QmSongItem *>(cur)->readInfo(cformat, cformatMulti);                        last = cur;                        if (++count%100 == 0)                        {                            QmMainWindow::mainwin->statusUpdate(new Message(Message::Update,                                                                            "Loading ... (%d songs and counting)", count));                        }                    }                }                else                    qWarning( "\"%s\" is not a file which was expected by file info",                              fi->absFilePath().ascii() );            }        }    }}/*!  Updates the playlength by calling updateLength on it's children.*/longQmDirItem::updateLength(){    long len = 0;    for(QListViewItem *i = firstChild(); i; i = i->nextSibling())    {        len += static_cast<QmPlayListItem*>(i)->updateLength();    }        setLengthSeconds(len);    m_LengthSeconds = len;    return m_LengthSeconds;}voidQmDirItem::writeXml(QTextStream &out){    out << "<dir>\n"        << "<name>" << "<![CDATA[" << text(0) << "]]></name>\n"        << "<open>" << isOpen() << "</open>\n";}/*!  Returns true if the dir \c fi exists in the listviewitem list.*/boolQmDirItem::hasDirItem(    const QFileInfo *fi) const{    QListViewItem *child = firstChild();    while( child )    {        QmDirItem *dir = dynamic_cast<QmDirItem *>( child );        if ( dir )        {            if ( dir->m_Dir.absPath() == fi->absFilePath() )                return true;        }        child = child->nextSibling();    }    return false;}/*!  Returns true if the song \c fi exists in the listviewitem list.*/boolQmDirItem::hasSongItem(    const QFileInfo *fi) const{    QListViewItem *child = firstChild();    while( child )    {        QmSongItem *song = dynamic_cast<QmSongItem *>( child );        if ( song )        {            if ( song->filePath() == fi->absFilePath() )                return true;        }        child = child->nextSibling();    }    return false;}/*!  Setup according to packed or not-packed mode.*/voidQmDirItem::setup(){	setExpandable(true);    bool packed = false;    QmConfig::instance()->get( "stuff", "packed", packed);    QmPixmapSupplier *sup = QmPixmapSupplier::instance();    setPixmap( 0, sup->pixmap( "icons-folder" ) );        if (packed)        setHeight(listView()->fontMetrics().height());    else        setHeight(sup->pixmap( "icons-folder" ).height() + 5);}/*!  \return The full path of the directory, including trailing slash. */QStringQmDirItem::fullName(){	return m_Dir.absPath();}/*!  Overridden to return the directory name for column 0, length for column 1.*/QStringQmDirItem::text(    int column) const{    if ( column == 0 ) 		return m_Label;	else         return m_Length;}/*!  \return The save string of the item.  This string can be saved to  disk, and loaded at a later time to create an identical instance  of this class.*/QStringQmDirItem::save(    const QString &rel_path) const{    QDir rel_dir( rel_path );    QDir dir = m_Dir;    bool done = false;    QString full_dir_name, dir_name;    while ( !done )    {        if ( rel_dir == dir )            done = true;        else        {            dir_name = dir.dirName();            if ( dir.isRoot() )            {                full_dir_name = QString( "/" ) + full_dir_name;                done = true;            }            else            {                if ( !dir.cdUp() )                    done = true;                else                    full_dir_name = dir_name + "/" + full_dir_name;            }        }    }	return full_dir_name;}/*!  This function is used to determine whether an item is a song  or a folder.  \return False for items of this class.*/boolQmDirItem::isSong() const{	return false;}//  QString//  QmDirItem::key( int , bool  ) const//  {//      if ( depth() == 0 )//      {//          return sortCounterString();//      }//      else//      {//          return QString( "a" ) + sortCounterString();//  //          if ( col == 0 )//  //              return QString( "a" ) + text( 0 );//  //          else//  //              return text( col );//      }//  }

⌨️ 快捷键说明

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