QString getLocalStorageGroupPath(VideoArtworkType type, QString host)
{
    QString path;

    StorageGroup sg;

    if (type == kArtworkCoverart)
        sg.Init("Coverart", host);
    else if (type == kArtworkFanart)
        sg.Init("Fanart", host);
    else if (type == kArtworkBanner)
        sg.Init("Banners", host);
    else if (type == kArtworkScreenshot)
        sg.Init("Screenshots", host);
    else
        sg.Init("Default", host);

    path = sg.FindNextDirMostFree();

    return path;
}
Exemplo n.º 2
0
/** \fn     ImageUtils::GetStorageDirs()
 *  \brief  Gets the available storage groups
 *  \return List of all available storage groups
 */
QStringList ImageUtils::GetStorageDirs()
{
    QStringList sgDirList;

    // The name that shall be used for the images storage group. It must be
    // specified because its not part of the default storage group names
    QString sgName = gCoreContext->GetSetting("GalleryStorageGroupName");

    if (!sgName.isEmpty())
    {
        QString host = gCoreContext->GetHostName();

        // Search for the specified dirs in the defined storage group.
        // If there is no such storage group then don't use the fallback
        // and don't get the default storage group name of "/mnt/store".
        // The list will be empty. The user has to check the settings.
        StorageGroup sg;
        sg.Init(sgName, host, false);
        sgDirList = sg.GetDirList();
    }

    return sgDirList;
}
Exemplo n.º 3
0
QString FileServerHandler::LocalFilePath(const QUrl &url,
                                           const QString &wantgroup)
{
    QString lpath = url.path();

    if (lpath.section('/', -2, -2) == "channels")
    {
        // This must be an icon request. Check channel.icon to be safe.
        QString querytext;

        QString file = lpath.section('/', -1);
        lpath = "";

        MSqlQuery query(MSqlQuery::InitCon());
        query.prepare("SELECT icon FROM channel WHERE icon LIKE :FILENAME ;");
        query.bindValue(":FILENAME", QString("%/") + file);

        if (query.exec() && query.next())
        {
            lpath = query.value(0).toString();
        }
        else
        {
            MythDB::DBError("Icon path", query);
        }
    }
    else
    {
        lpath = lpath.section('/', -1);

        QString fpath = lpath;
        if (fpath.right(4) == ".png")
            fpath = fpath.left(fpath.length() - 4);

        ProgramInfo pginfo(fpath);
        if (pginfo.GetChanID())
        {
            QString pburl = GetPlaybackURL(&pginfo);
            if (pburl.left(1) == "/")
            {
                lpath = pburl.section('/', 0, -2) + "/" + lpath;
                LOG(VB_FILE, LOG_INFO,
                    QString("Local file path: %1").arg(lpath));
            }
            else
            {
                LOG(VB_GENERAL, LOG_ERR,
                        QString("LocalFilePath unable to find local "
                                "path for '%1', found '%2' instead.")
                                .arg(lpath).arg(pburl));
                lpath = "";
            }
        }
        else if (!lpath.isEmpty())
        {
            // For securities sake, make sure filename is really the pathless.
            QString opath = lpath;
            StorageGroup sgroup;

            if (!wantgroup.isEmpty())
            {
                sgroup.Init(wantgroup);
                lpath = url.toString();
            }
            else
            {
                lpath = QFileInfo(lpath).fileName();
            }

            QString tmpFile = sgroup.FindFile(lpath);
            if (!tmpFile.isEmpty())
            {
                lpath = tmpFile;
                LOG(VB_FILE, LOG_INFO,
                        QString("LocalFilePath(%1 '%2'), found through "
                                "exhaustive search at '%3'")
                            .arg(url.toString()).arg(opath).arg(lpath));
            }
            else
            {
                LOG(VB_GENERAL, LOG_ERR, QString("LocalFilePath unable to "
                                                 "find local path for '%1'.")
                                .arg(opath));
                lpath = "";
            }

        }
        else
        {
            lpath = "";
        }
    }

    return lpath;
}