Example #1
0
void LocalSong::readList(const QString &fName)
{
    QString fileName = QString("%1.xml").arg(fName);
    QFile file(fileName);
    if (false==file.open(QFile::ReadOnly | QFile::Text)) {
        return;
    }
    QXmlStreamReader reader;
    reader.setDevice(&file);
    songlist.clear();//清空歌曲路径列表
    while (false==reader.atEnd())
    {
        reader.readNext();
        if (reader.isStartElement())
        {
            if (reader.name() == "path")
            {
                QString songPath=reader.readElementText().toUtf8();
                addSongList(songPath);//读取列表
                setInfo(songPath);
            }
        }
    }
    qDebug()<<"本地列表读取完成";
    unsigned long dirLength=songlist.length();
    qDebug()<<"歌曲总数为"<<dirLength;
    emit dirCount(dirLength);
    file.close();
}
Example #2
0
void LocalSong::addDir()
{
    locDir= QFileDialog::getExistingDirectory(this,tr("扫描本地目录"),musicPaths.isEmpty() ? QDir::homePath() : musicPaths.first(),QFileDialog::ShowDirsOnly
                                              | QFileDialog::DontResolveSymlinks);
    QDir dir(locDir);
    if(false==dir.exists())
    {
        return;
    }
    dir.setFilter(QDir::Files | QDir::NoSymLinks);
    QFileInfoList list = dir.entryInfoList();

    int file_count = list.count();
    if(file_count <= 0)
    {
        return;
    }
    for(int i=0; i<file_count;++i)
    {
        QFileInfo file_info = list.at(i);
        QString suffix = file_info.suffix();
        if(QString::compare(suffix, QString("mp3"), Qt::CaseInsensitive) == 0)
        {
            QString absolute_file_path = file_info.absoluteFilePath();
            addSongList(absolute_file_path);
            setInfo(absolute_file_path);
        }
    }
    qDebug()<<"已添加整个目录"<<locDir;
    unsigned long dirLength=songlist.length();
    qDebug()<<"歌曲总数为"<<dirLength;
    emit dirCount(dirLength);
}
Example #3
0
void LocalSong::openFile()
{


    filePath = QFileDialog::getOpenFileName(
                this, tr("添加本地音乐"),
                musicPaths.isEmpty() ? QDir::homePath() : musicPaths.first(),
                tr("Music files (*.mp3 *.m4a);;All files (*.*)"));
    if(filePath.isEmpty())
    {
        return;
    }
    addSongList(filePath);
    setInfo(filePath);
    qDebug()<<"文件路径为"<<filePath;
    unsigned long sinLength=songlist.length();
    qDebug()<<"歌曲总数为"<<sinLength;
    emit dirCount(sinLength);
}
Example #4
0
bool RDirNode::empty() {
    return (visible_count==0 && dirCount()==0) ? true : false;
}
Example #5
0
bool RDirNode::addFile(RFile* f) {

    //doesnt match this path at all
    if(f->path.find(abspath) != 0) {

        if(parent!=0) return false;

        RDirNode* newparent;

        std::string common = commonPathPrefix(f->path);
        if(common.size()==0) common = "/";

        newparent = new RDirNode(0, common);
        newparent->addNode(this);
        return newparent->addFile(f);
    }

    //simply change path of node and add this to it
    if(   parent==0 && abspath == "/"
       && f->path.compare(abspath) != 0 && fileCount()==0 && dirCount()==0) {
        debugLog("modifying root path to %s\n", f->path.c_str());
        changePath(f->path);
    }

    //is this dir - add to this node
    if(f->path.compare(abspath) == 0) {
        //debugLog("addFile %s to %s\n", f->fullpath.c_str(), abspath.c_str());

        files.push_back(f);
        if(!f->isHidden()) visible_count++;
        f->setDir(this);

        fileUpdated(false);

        return true;
    }

    //does this belong to one of the children ?
    for(std::list<RDirNode*>::iterator it = children.begin(); it != children.end(); it++) {
        RDirNode* child =  (*it);

        bool added = child->addFile(f);

        if(added) return true;
    }

    //add new child, add it to that
    //if commonpath is longer than abspath, add intermediate node, else just add at the files path
    RDirNode* node = new RDirNode(this, f->path);

    node->addFile(f);

    addNode(node);

    // do we have dir nodes, with a common path element greater than abspath,
    // if so create another node, and move those nodes there

     std::string commonpath;
     vec2f commonPos;
     for(std::list<RDirNode*>::iterator it = children.begin(); it != children.end(); it++) {
         RDirNode* child =  (*it);

         std::string common = child->commonPathPrefix(f->path);
         if(common.size() > abspath.size() && common != f->path) {
            commonpath = common;
            commonPos = child->getPos();
            break;
         }
     }

    // redistribute to new common node
    if(commonpath.size() > abspath.size()) {
        //debugLog("common path %s\n", commonpath.c_str());

        RDirNode* cnode = new RDirNode(this, commonpath);
        cnode->setPos(commonPos);

        for(std::list<RDirNode*>::iterator it = children.begin(); it != children.end();) {
            RDirNode* child =  (*it);

            if(child->prefixedBy(commonpath)) {
                //debugLog("this path = %s, commonpath = %s, path = %s\n", abspath.c_str(), commonpath.c_str(), child->getPath().c_str());
                it = children.erase(it);
                cnode->addNode(child);
                continue;
            }

            it++;
        }

        addNode(cnode);
    }

    return true;
}