<commit_before>/*
 * Copyright 2011 Intel Corporation.
 *
 * This program is licensed under the terms and conditions of the
 * Apache License, version 2.0.  The full text of the Apache License is at 	
 * http://www.apache.org/licenses/LICENSE-2.0
 */

#include "mediaitem.h"
#include <inttypes.h>

MediaItem::MediaItem(int type, QDateTime recenttime, QStringList args, QObject *parent) :
    QObject(parent), m_type(type)
{
    m_favorite = false;
    m_recentlyadded = false;
    m_recentlyviewed = false;
    m_id = QString().sprintf("0x%08lX", (uintptr_t)this);
    m_thumburi_exists = false;
    m_thumburi_ignore = true;
    m_thumbtype = NoThumb;
    artistitem = NULL;
    albumitem = NULL;
    m_tracknum = 0;
    m_length = 0;
    m_isvirtual = false;
    m_playstatus = 0;
    m_sid = 0;
    m_width = 0;
    m_height = 0;
    m_isusercontent = false;
    changeData(recenttime, args);
}

MediaItem::MediaItem(int type, QString uri, QObject *parent) :
        QObject(parent), m_type(type)
{
    m_favorite = false;
    m_recentlyadded = false;
    m_recentlyviewed = false;
    m_id = QString().sprintf("0x%08lX", (uintptr_t)this);
    m_thumburi_exists = false;
    m_thumburi_ignore = true;
    m_thumbtype = NoThumb;
    artistitem = NULL;
    albumitem = NULL;
    m_tracknum = 0;
    m_length = 0;
    m_isvirtual = true;
    m_playstatus = 0;
    m_sid = 0;
    m_width = 0;
    m_height = 0;
    m_isusercontent = false;

    if(isAnyVideoType())
    {
        m_uri = (QUrl::fromEncoded(fileFormatted(uri).toAscii())).toString();
        QStringList temp = m_uri.split("/", QString::SkipEmptyParts);
        m_title = temp.last();
        m_thumbtype = VideoThumb;
        m_thumburi = thumbPhoto(m_uri);
        m_thumburi_ignore = false;
        if(thumbExists())
            m_thumburi_exists = true;
    }
    else if(isSong())
    {
        m_uri = (QUrl::fromEncoded(fileFormatted(uri).toAscii())).toString();
        QStringList temp = m_uri.split("/", QString::SkipEmptyParts);
        m_title = temp.last();
        m_thumburi_exists = false;
        m_thumburi_ignore = true;
    }
    else if(isPhoto())
    {
        m_uri = (QUrl::fromEncoded(fileFormatted(uri).toAscii())).toString();
        QStringList temp = m_uri.split("/", QString::SkipEmptyParts);
        m_title = temp.last();
        m_thumbtype = PhotoThumb;
        m_thumburi = thumbPhoto(m_uri);
        m_thumburi_ignore = false;
        if(thumbExists())
            m_thumburi_exists = true;
    }
}

MediaItem::MediaItem(int type, QObject *parent) :
    QObject(parent), m_type(type)
{
    m_favorite = false;
    m_recentlyadded = false;
    m_recentlyviewed = false;
    m_id = QString().sprintf("0x%08lX", (uintptr_t)this);
    m_thumburi_exists = false;
    m_thumburi_ignore = true;
    m_thumbtype = NoThumb;
    artistitem = NULL;
    albumitem = NULL;
    m_tracknum = 0;
    m_length = 0;
    m_isvirtual = true;
    m_playstatus = 0;
    m_sid = 0;
    m_width = 0;
    m_height = 0;
    m_isusercontent = false;
}

MediaItem::MediaItem(QObject *parent) :
    QObject(parent)
{
    m_type = PhotoItem;
    m_favorite = false;
    m_recentlyadded = false;
    m_recentlyviewed = false;
    m_id = QString().sprintf("0x%08lX", (uintptr_t)this);
    m_thumburi_exists = false;
    m_thumburi_ignore = true;
    m_thumbtype = NoThumb;
    artistitem = NULL;
    albumitem = NULL;
    m_tracknum = 0;
    m_length = 0;
    m_isvirtual = true;
    m_playstatus = 0;
    m_sid = 0;
    m_width = 0;
    m_height = 0;
    m_isusercontent = false;
}

void MediaItem::changeData(QDateTime recenttime, QStringList args)
{
    m_urn = args.at(IDX_URN);
    if(!args.at(IDX_SUBJECTID).isEmpty())
        m_sid = args.at(IDX_SUBJECTID).toInt();
    m_addedtime = QDateTime::fromString(args.at(IDX_ADDTIME), Qt::ISODate);
    m_lastplayedtime = args.at(IDX_VIEWED);
    m_favorite = (args.at(IDX_FAVORITE) == "favorite");

    if(isSong() && (args.count() == SNG_ARGS))
    {
        m_title = args.at(IDX_SNG_TITLE);
        m_uri = (QUrl::fromEncoded(args.at(IDX_SNG_URI).toAscii())).toString();
        m_creationtime = args.at(IDX_SNG_CTIME);
        if(!args.at(IDX_SNG_TRACK).isEmpty())
            m_tracknum = args.at(IDX_SNG_TRACK).toInt();
        if(!args.at(IDX_SNG_DURATION).isEmpty())<commit_msg>Workaround for MusicPicker returning uri for playlists and albums This way everyone has unique "uri" even if not real<commit_after>/*
 * Copyright 2011 Intel Corporation.
 *
 * This program is licensed under the terms and conditions of the
 * Apache License, version 2.0.  The full text of the Apache License is at 	
 * http://www.apache.org/licenses/LICENSE-2.0
 */

#include "mediaitem.h"
#include <inttypes.h>

MediaItem::MediaItem(int type, QDateTime recenttime, QStringList args, QObject *parent) :
    QObject(parent), m_type(type)
{
    m_favorite = false;
    m_recentlyadded = false;
    m_recentlyviewed = false;
    m_id = QString().sprintf("0x%08lX", (uintptr_t)this);
    m_thumburi_exists = false;
    m_thumburi_ignore = true;
    m_thumbtype = NoThumb;
    artistitem = NULL;
    albumitem = NULL;
    m_tracknum = 0;
    m_length = 0;
    m_isvirtual = false;
    m_playstatus = 0;
    m_sid = 0;
    m_width = 0;
    m_height = 0;
    m_isusercontent = false;
    changeData(recenttime, args);
}

MediaItem::MediaItem(int type, QString uri, QObject *parent) :
        QObject(parent), m_type(type)
{
    m_favorite = false;
    m_recentlyadded = false;
    m_recentlyviewed = false;
    m_id = QString().sprintf("0x%08lX", (uintptr_t)this);
    m_thumburi_exists = false;
    m_thumburi_ignore = true;
    m_thumbtype = NoThumb;
    artistitem = NULL;
    albumitem = NULL;
    m_tracknum = 0;
    m_length = 0;
    m_isvirtual = true;
    m_playstatus = 0;
    m_sid = 0;
    m_width = 0;
    m_height = 0;
    m_isusercontent = false;

    if(isAnyVideoType())
    {
        m_uri = (QUrl::fromEncoded(fileFormatted(uri).toAscii())).toString();
        QStringList temp = m_uri.split("/", QString::SkipEmptyParts);
        m_title = temp.last();
        m_thumbtype = VideoThumb;
        m_thumburi = thumbPhoto(m_uri);
        m_thumburi_ignore = false;
        if(thumbExists())
            m_thumburi_exists = true;
    }
    else if(isSong())
    {
        m_uri = (QUrl::fromEncoded(fileFormatted(uri).toAscii())).toString();
        QStringList temp = m_uri.split("/", QString::SkipEmptyParts);
        m_title = temp.last();
        m_thumburi_exists = false;
        m_thumburi_ignore = true;
    }
    else if(isPhoto())
    {
        m_uri = (QUrl::fromEncoded(fileFormatted(uri).toAscii())).toString();
        QStringList temp = m_uri.split("/", QString::SkipEmptyParts);
        m_title = temp.last();
        m_thumbtype = PhotoThumb;
        m_thumburi = thumbPhoto(m_uri);
        m_thumburi_ignore = false;
        if(thumbExists())
            m_thumburi_exists = true;
    }
}

MediaItem::MediaItem(int type, QObject *parent) :
    QObject(parent), m_type(type)
{
    m_favorite = false;
    m_recentlyadded = false;
    m_recentlyviewed = false;
    m_id = QString().sprintf("0x%08lX", (uintptr_t)this);
    m_thumburi_exists = false;
    m_thumburi_ignore = true;
    m_thumbtype = NoThumb;
    artistitem = NULL;
    albumitem = NULL;
    m_tracknum = 0;
    m_length = 0;
    m_isvirtual = true;
    m_playstatus = 0;
    m_sid = 0;
    m_width = 0;
    m_height = 0;
    m_isusercontent = false;
}

MediaItem::MediaItem(QObject *parent) :
    QObject(parent)
{
    m_type = PhotoItem;
    m_favorite = false;
    m_recentlyadded = false;
    m_recentlyviewed = false;
    m_id = QString().sprintf("0x%08lX", (uintptr_t)this);
    m_thumburi_exists = false;
    m_thumburi_ignore = true;
    m_thumbtype = NoThumb;
    artistitem = NULL;
    albumitem = NULL;
    m_tracknum = 0;
    m_length = 0;
    m_isvirtual = true;
    m_playstatus = 0;
    m_sid = 0;
    m_width = 0;
    m_height = 0;
    m_isusercontent = false;
}

void MediaItem::changeData(QDateTime recenttime, QStringList args)
{
    m_urn = args.at(IDX_URN);

    //Workaround for MusicPicker returning uri for playlists and albums
    // This way everyone has unique "uri" even if not real
    m_uri = m_urn;

    if(!args.at(IDX_SUBJECTID).isEmpty())
        m_sid = args.at(IDX_SUBJECTID).toInt();
    m_addedtime = QDateTime::fromString(args.at(IDX_ADDTIME), Qt::ISODate);
    m_lastplayedtime = args.at(IDX_VIEWED);
    m_favorite = (args.at(IDX_FAVORITE) == "favorite");

    if(isSong() && (args.count() == SNG_ARGS))
    {
        m_title = args.at(IDX_SNG_TITLE);
        m_uri = (QUrl::fromEncoded(args.at(IDX_SNG_URI).toAscii())).toString();
        m_creationtime = args.at(IDX_SNG_CTIME);
        if(!args.at(IDX_SNG_TRACK).isEmpty())
            m_tracknum = args.at(IDX_SNG_TRACK).toInt();
        if(!args.at(IDX_SNG_DURATION).isEmpty())
{'fraction_non_alphanumeric': 0.12359043752819125, 'fraction_numerical': 0.009923319801533603, 'mean_word_length': 2.9842767295597485, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1021690', 'n_tokens_mistral': 3320, 'n_tokens_neox': 3233, 'n_words': 612}