Пример #1
0
void Favorites::load()
{
    qDebug("Favorites::load");

    QRegExp m3u_id("^#EXTM3U|^#M3U");
    QRegExp info("^#EXTINF:(.*),(.*),(.*)");

    QFile f( _filename );
    if ( f.open( QIODevice::ReadOnly ) )
    {

        f_list.clear();

        Favorite fav;

        QTextStream stream( &f );
        stream.setCodec("UTF-8");

        QString line;
        while ( !stream.atEnd() )
        {
            line = stream.readLine(); // line of text excluding '\n'
            //qDebug( " * line: '%s'", line.toUtf8().data() );
            if (m3u_id.indexIn(line)!=-1)
            {
                //#EXTM3U
                // Ignore line
            }
            else if (info.indexIn(line) != -1)
            {
                fav.setName( info.cap(2) );
                fav.setIcon( info.cap(3) );
            }
            else if (line.startsWith("#"))
            {
                // Comment
                // Ignore
            }
            else
            {
                fav.setFile( line );
                if (fav.name().isEmpty()) fav.setName(line);
                //qDebug("Favorites::load: adding '%s' '%s'", fav.name().toUtf8().constData(), fav.file().toUtf8().constData());
                f_list.append(fav);

                // Clear data
                fav.setName("");
                fav.setFile("");
                fav.setIcon("");
            }
        }
        f.close();
    }
}
Пример #2
0
FavoriteList FavoriteEditor::data() {
    FavoriteList list;

    for (int n = 0; n < table->rowCount(); n++) {
        Favorite f;
        f.setName( table->item(n, COL_NAME)->text() );
        f.setIcon( table->item(n, COL_ICON)->data(Qt::UserRole).toString() );
        f.setSubentry( table->item(n, COL_FILE)->data(Qt::UserRole).toBool() );
        if (f.isSubentry()) {
            f.setFile( table->item(n, COL_FILE)->data(Qt::UserRole + 1).toString() );
        } else {
            f.setFile( table->item(n, COL_FILE)->text() );
        }

        list.append(f);
    }

    return list;
}