Example #1
0
QVariant RequestManager::requestFileTransfer(QTcpSocket *& caller, QVariant params)
{
    // VIDEO TRANSFER COMING SOON
    // get the video name
    QJsonObject jobject = params.toJsonObject();
    QJsonValue file_name_value = jobject["FileName"];
    QString file_name;
    if(file_name_value.isString())
        file_name = file_name_value.toString("");
    else
    {
        qDebug() << "VideoTransfer function passed invalid paramter VideoName: " << file_name_value;
        return QVariant();
    }
    QFile file_in(file_name,this);
    qint64 file_size = file_in.size();
    qDebug() << "Preparing to send file: " << file_name << " of size " << file_size;
    //get pointer to main ui object
    QWidget * mainwindow = qobject_cast<QWidget *>(parent()->parent());
    // spwan off stream transfer video
    QAbstractSocket * caller_socket = qobject_cast< QAbstractSocket *>(caller);
    StreamTransferThread * file_transfer = new StreamTransferThread(qobject_cast<QObject *>(this),mainwindow,
            file_name,caller_socket,file_size);
    connect(file_transfer, &StreamTransferThread::finishedTransferingStream,
            this,       &RequestManager::videoTransferThreadFinished);
    file_transfer->start();
    return QVariant();

}
Example #2
0
QVariant RequestManager::requestVideoList(QTcpSocket *caller, QVariant params)
{
    QStringList videos;
    int max_return = -1;
    if(!params.isNull())
    {
        // Get the packed max_return value
        QJsonObject max_return_obj(params.toJsonObject());
        QJsonValue max_ret_val( max_return_obj["max_return"]);
        QVariant max_ret_var(max_ret_val.toVariant());
        if(max_ret_var.type() == QVariant::Int)
            max_return = max_ret_var.toInt();
    }
    videos = VideoLocator::findVideos(mVideoDirectory);
    if(max_return != -1)
    {
        int amount_to_remove = videos.length()-max_return;
        //only return the amount passed in
        for(int i = 0; i < amount_to_remove; ++i)
        {
            videos.pop_back();
        }
    }

    QJsonObject ret_object;
    ret_object["VideoList"] = QJsonValue::fromVariant(QVariant::fromValue(videos));
    QVariant ret_var(QVariant::fromValue(ret_object));
    //qDebug() << "Sending back" << ret_var;
    return ret_var;

}
Example #3
0
void KNMusicStorePageAlbum::setPageLabel(int labelIndex, const QVariant &value)
{
    //Check the lable index.
    switch(labelIndex)
    {
    case AlbumMetadata:
    {
        //This contains the basic data of the album. It is a pack of JSON type
        //object.
        QJsonObject metadata=value.toJsonObject();
        // Album name, it should be a string type value.
        m_albumTitle->setText(metadata.value("name").toString());
        // Album artist, it should be a string type value.
        m_albumArtistLabel->setText(metadata.value("artist").toString());
        // Release date, it should be a long long type. UNIX timestamp.
        quint64 releaseTime=(quint64)metadata.value("release").toDouble();
        m_releaseTime=QDateTime::fromMSecsSinceEpoch(releaseTime).date();
        // Publish by, it should be a string type value.
        m_publishByLabel->setText(m_publishByText.arg(
                                      metadata.value("publish").toString()));
        // Song list, it is a JSON array.
        //Get the album model
        KNMusicStoreAlbumModel *albumModel=knMusicStoreGlobal->albumModel();
        //Clear current data.
        albumModel->clear();
        //Get the song list.
        QJsonArray songList=metadata.value("songs").toArray();
        //Reset the size.
        albumModel->reserve(songList.size());
        //Get over the list, construct the item.
        for(int i=0; i<songList.size(); ++i)
        {
            //Get the object.
            QJsonObject songItem=songList.at(i).toObject();
            //Parse the item.
            KNMusicStoreSongInfo songInfo;
            songInfo.index=songItem.value("index").toString();
            songInfo.name=songItem.value("name").toString();
            songInfo.artist=songItem.value("artist").toString();
            songInfo.artistId=songItem.value("artistId").toString();
            songInfo.duration=songItem.value("duration").toString();
            songInfo.customData=songItem.value("custom").toString();
            //Set the song info to model.
            albumModel->replace(i, songInfo);
        }
        //Update the metadata.
        updateMetadata();
        //Ask for show the page.
        emit requireShowPage();
        emit requireSetNavigatorItem(PageAlbum, m_albumTitle->text());
        //When this part is down.
        break;
    }
    case AlbumArt:
        //Parse the value as pixmap.
        m_albumArt->setPixmap(value.value<QPixmap>());
        break;
    }
}
Example #4
0
QVariant RequestManager::requestVideoInfo(QTcpSocket *caller, QVariant params)
{
    // Unpack the QVariant
    // Layers - QJsonObject { [ QJSonValue FuncName = "VideoInfo", QJSonValue  VideoName = "video_passed"] }
    QJsonObject jobject = params.toJsonObject();
    QJsonValue videoname_value = jobject["VideoName"];
    QString videoname;
    if(videoname_value.isString())
        videoname = videoname_value.toString();
    else
    {
        qDebug() << "VideoInfo function passed invalid paramter VideoName: " << videoname_value;
        return QVariant();
    }
    // fetched videoname now check if the info file exists

    //TODO Replace hard coded path with application settings manager variable
    VideoInfoReader   * inforeader = new VideoInfoReader(this,"mediainfo", "//home/odroid/.config/MissionControl/media_info_format.txt");


    // work some lambda magic Connect inforeader to the RequestManager,
    // when the media is fetched... call an inline "Slot" and pass name and info
    connect(inforeader, &VideoInfoReader::fetchedMediaInfo , [=](QString videoname, QString videoinfo)
    {   // ... execute this inline lamdba function

        // disconnect the slot (don't need it anymore clean up)
        disconnect(inforeader, 0, this, 0);


        QJsonObject return_obj;
        return_obj["VideoName"] = videoname.remove("/home/odroid/Videos//");
        return_obj["VideoInfo"] = videoinfo;
        // create a JsonDocument Wrapper = "{}"
        QJsonDocument doc;
        doc.setObject(return_obj);
        QByteArray message(doc.toJson()); // out to JSON
        // Prepend the Start Byte and Append the End Byte
        message.push_front("\001");
        message.push_back("\004");
        inforeader->deleteLater();
        emit returnMessageReady(caller, message);
    });

    inforeader->fetchMediaInfo(mVideoDirectory + "//" + videoname);
    return QVariant();
}
    void onSnippetRequestSuccess(QVariant response)
    {
        qDebug() << "Got snippet info for video:" << _downloadData->videoId();

        QVariantMap top = response.toJsonObject().toVariantMap();
        Q_ASSERT(!top.isEmpty() && top.contains("items"));

        QList<QVariant> lst = top["items"].toList();
        Q_ASSERT(!lst.empty() && lst.size() == 1);

        QVariantMap map = lst.at(0).toMap();
        Q_ASSERT(!map.isEmpty() && map.contains("snippet") &&
                 map.contains("contentDetails"));

        QVariantMap snippet = map["snippet"].toMap();
        Q_ASSERT(!snippet.isEmpty() && snippet.contains("thumbnails") &&
                 snippet.contains("title"));

        QVariantMap thumbnails = snippet["thumbnails"].toMap();
        Q_ASSERT(!thumbnails.isEmpty() && thumbnails.contains("default"));

        QVariantMap contentDetails = map["contentDetails"].toMap();
        Q_ASSERT(!contentDetails.isEmpty() && contentDetails.contains("duration"));

        QVariantMap quality;
        if (thumbnails.contains("high"))
            quality = thumbnails["high"].toMap();
        else if (thumbnails.contains("medium"))
            quality = thumbnails["medium"].toMap();
        else
            quality = thumbnails["default"].toMap();

        QString url = quality["url"].toString();

        setThumbnailUrl(QUrl(url));
        _downloadData->setTitle(snippet["title"].toString());
        _downloadData->setDuration(contentDetails["duration"].toString());

        _snippetRequest->deleteLater();
        _snippetRequest = NULL;
        beginDataDownloadsIfPossible();
    }
Example #6
0
void KNConfigure::setData(const QString &key, const QVariant &value)
{
    //Check whether the value is null.
    if(value.isNull())
    {
        //Remove the key from the configure data.
        m_dataObject.remove(key);
        //Complete.
        return;
    }
    //Because the QJsonObject can only insert QJsonValue, and the construct
    //function of QJsonValue only have the following types:
    //   bool, QString, array, double, object.
    //So we have to translate some complex type variant to object.
    switch(value.type())
    {
    //For the basic types(double, float, int, bool, QString), we will save them
    //directly.
    case QVariant::LongLong:
        m_dataObject.insert(key, value.toLongLong());
        break;
    case QVariant::Double:
        m_dataObject.insert(key, value.toDouble());
        break;
    case QVariant::String:
        m_dataObject.insert(key, value.toString());
        break;
    case QVariant::Int:
        m_dataObject.insert(key, value.toInt());
        break;
    case QVariant::Bool:
        m_dataObject.insert(key, value.toBool());
        break;
    //For advanced types(like Font), we have to translate them to a object.
    case QVariant::Font:
    {
        //Generate the font object.
        QFont font=value.value<QFont>();
        QJsonObject fontObject;
        fontObject.insert("Type", QString("Font"));
        fontObject.insert("Family", font.family());
        fontObject.insert("Size", font.pixelSize());
        fontObject.insert("Bold", font.bold());
        fontObject.insert("Italic", font.italic());
        fontObject.insert("Underline", font.underline());
        fontObject.insert("Strikeout", font.strikeOut());
        fontObject.insert("Kerning", font.kerning());
        //Insert the font object.
        m_dataObject.insert(key, fontObject);
        break;
    }
    case QVariant::KeySequence:
    {
        //Generate a key sequence object.
        QKeySequence keySequence=value.value<QKeySequence>();
        //A shortcut object.
        QJsonObject shortcutObject;
        shortcutObject.insert("Type", QString("Shortcut"));
        shortcutObject.insert("Key", keySequence.toString(
                                  QKeySequence::PortableText));
        //Insert the key sequence object.
        m_dataObject.insert(key, shortcutObject);
        break;
    }
    //For the JSON object, it is quite wired that QVariant doesn't enumerate the
    //JSON type here, but it will use the meta type json object here.
    case QMetaType::QJsonObject:
    {
        //Check with the value contains the custom type.
        QJsonObject customObject=value.toJsonObject();
        //Check the custom object type is matched.
        if("CustomObject"==customObject.value("Type").toString())
        {
            //Simply insert the json object to the data.
            m_dataObject.insert(key, customObject);
        }
        break;
    }
    //For the JSON array, directly save the original data.
    case QMetaType::QJsonArray:
    {
        //Simply insert the json array to the data.
        m_dataObject.insert(key, value.toJsonArray());
        break;
    }
    default:
        return;
    }
    //Emit the signal.
    emit valueChanged();
}