Ejemplo n.º 1
0
void RigTests::initTestCase() {
//#define FROM_FILE "/Users/howardstearns/howardHiFi/Zack.fbx"
#ifdef FROM_FILE
    QFile file(FROM_FILE);
    QCOMPARE(file.open(QIODevice::ReadOnly), true);
    FBXGeometry geometry = readFBX(file.readAll(), QVariantHash());
#else
    QUrl fbxUrl("https://s3.amazonaws.com/hifi-public/models/skeletons/Zack/Zack.fbx");
    QNetworkReply* reply = OBJReader().request(fbxUrl, false);  // Just a convenience hack for synchronoud http request
    auto fbxHttpCode = !reply->isFinished() ? -1 : reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
    QCOMPARE(fbxHttpCode, 200);
    FBXGeometry geometry = readFBX(reply->readAll(), QVariantHash());
#endif
 
    QVector<JointState> jointStates;
    for (int i = 0; i < geometry.joints.size(); ++i) {
        JointState state(geometry.joints[i]);
        jointStates.append(state);
    }

    _rig = std::make_shared<AvatarRig>();
    _rig->initJointStates(jointStates, glm::mat4(), 0, 41, 40, 39, 17, 16, 15); // FIXME? get by name? do we really want to exclude the shoulder blades?
    std::cout << "Rig is ready " << geometry.joints.count() << " joints " << std::endl;
    reportAll(_rig);
   }
void Ut_NotificationPreviewPresenter::testUpdateNotificationRemovesNotificationFromQueueIfNotShowable()
{
    NotificationPreviewPresenter presenter;

    // Create two notifications
    LipstickNotification *notification1 = createNotification(1);
    LipstickNotification *notification2 = createNotification(2);
    presenter.updateNotification(1);
    presenter.updateNotification(2);

    // Update the notifications to have no summary or body
    QSignalSpy changedSpy(&presenter, SIGNAL(notificationChanged()));
    QSignalSpy presentedSpy(&presenter, SIGNAL(notificationPresented(uint)));
    notification1->setHints(QVariantHash());
    notification2->setHints(QVariantHash());
    presenter.updateNotification(1);
    presenter.updateNotification(2);

    // Check that the current notification is not removed
    QCOMPARE(changedSpy.count(), 0);

    // The notifications should be considered presented
    QCOMPARE(presentedSpy.count(), 2);

    // Check that the other notification is removed from the queue
    presenter.showNextNotification();
    QCOMPARE(changedSpy.count(), 1);
    QCOMPARE(presenter.notification(), (LipstickNotification *)0);
    QCOMPARE(presentedSpy.count(), 2);
}
Ejemplo n.º 3
0
void
Account::loadFromConfig( const QString& accountId )
{
    m_accountId = accountId;
    TomahawkSettings* s = TomahawkSettings::instance();
    s->beginGroup( "accounts/" + m_accountId );
    m_accountFriendlyName = s->value( "accountfriendlyname", QString() ).toString();
    m_enabled = s->value( "enabled", false ).toBool();
    m_credentials = s->value( "credentials", QVariantHash() ).toHash();
    m_configuration = s->value( "configuration", QVariantHash() ).toHash();
    m_acl = s->value( "acl", QVariantMap() ).toMap();
    m_types = s->value( "types", QStringList() ).toStringList();
    s->endGroup();
}
Ejemplo n.º 4
0
TwitterPlugin::TwitterPlugin( const QString& pluginId )
    : SipPlugin( pluginId )
    , m_isAuthed( false )
    , m_checkTimer( this )
    , m_connectTimer( this )
    , m_dmPollTimer( this )
    , m_cachedFriendsSinceId( 0 )
    , m_cachedMentionsSinceId( 0 )
    , m_cachedDirectMessagesSinceId( 0 )
    , m_cachedPeers()
    , m_keyCache()
    , m_state( Disconnected )
{
    qDebug() << Q_FUNC_INFO;

    if ( Database::instance()->dbid() != twitterSavedDbid() )
        setTwitterCachedPeers( QVariantHash() );

    setTwitterSavedDbid( Database::instance()->dbid() );

    m_checkTimer.setInterval( 180000 );
    m_checkTimer.setSingleShot( false );
    connect( &m_checkTimer, SIGNAL( timeout() ), SLOT( checkTimerFired() ) );

    m_dmPollTimer.setInterval( 60000 );
    m_dmPollTimer.setSingleShot( false );
    connect( &m_dmPollTimer, SIGNAL( timeout() ), SLOT( pollDirectMessages() ) );

    m_connectTimer.setInterval( 180000 );
    m_connectTimer.setSingleShot( false );
    connect( &m_connectTimer, SIGNAL( timeout() ), SLOT( connectTimerFired() ) );

    m_configWidget = QWeakPointer< TwitterConfigWidget >( new TwitterConfigWidget( this, 0 ) );
    connect( m_configWidget.data(), SIGNAL( twitterAuthed( bool ) ), SLOT( configDialogAuthedSignalSlot( bool ) ) );
}
Ejemplo n.º 5
0
QVariantHash FileSpecification::asVariantHash() const
{
  Q_D(const FileSpecification);
  if (d->json.isObject())
    return QtJson::toVariant(d->json).toHash();
  return QVariantHash();
}
Ejemplo n.º 6
0
QVariant createSameKeyedObject(const QVariant &in)
{
	if(in.type() == QVariant::Hash)
		return QVariantHash();
	else if(in.type() == QVariant::Map)
		return QVariantMap();
	else
		return QVariant();
}
void Ut_NotificationFeedbackPlayer::testWithoutFeedbackId()
{
    // Create a notification
    LipstickNotification *notification = createNotification(1);
    notification->setHints(QVariantHash());
    player->addNotification(1);

    // Check that NGFAdapter::play() was not called for the feedback
    QCOMPARE(gClientStub->stubCallCount("play"), 0);
}
Ejemplo n.º 8
0
void RigTests::initTestCase() {
//#define FROM_FILE "/Users/howardstearns/howardHiFi/Zack.fbx"
#ifdef FROM_FILE
    QFile file(FROM_FILE);
    QCOMPARE(file.open(QIODevice::ReadOnly), true);
    FBXGeometry* geometry = readFBX(file.readAll(), QVariantHash());
#else
    QUrl fbxUrl("https://s3.amazonaws.com/hifi-public/models/skeletons/Zack/Zack.fbx");
    QNetworkReply* reply = OBJReader().request(fbxUrl, false);  // Just a convenience hack for synchronoud http request
    auto fbxHttpCode = !reply->isFinished() ? -1 : reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
    QCOMPARE(fbxHttpCode, 200);
    FBXGeometry* geometry = readFBX(reply->readAll(), QVariantHash());
#endif
    QVERIFY((bool)geometry);

    _rig = std::make_shared<Rig>();
    _rig->initJointStates(*geometry, glm::mat4());
    std::cout << "Rig is ready " << geometry->joints.count() << " joints " << std::endl;
    reportAll(_rig);
}
Ejemplo n.º 9
0
bool FBXMLHandler::endElement( const QString & /*namespaceURI*/,
                               const QString & /*localName*/,
                               const QString & /*qName*/ )
{
    flushCharacters();

    QVariant c = iStack [iStack.count() - 1] ;
    QString name = topName();

    iStack.removeLast();
    iNameStack.removeLast();

    if (!iStack.count())
    {
        iRootObject = c;
        iRootName = name;
    }
    else
    {
        QVariant tC = iStack[iStack.count() - 1] ;
        if (tC.isNull())
        {
            tC = QVariantHash();
            iStack.replace(iStack.count() - 1, tC);
        }

        if (tC.type() == QVariant::List)
        {
            QVariantList list = tC.toList();
            list.append( c.toHash() );

            iStack.replace( iStack.count() - 1 , list);

        }
        else if (tC.type() == QVariant::Hash)
        {
            QVariantHash hash = tC.toHash();
            if (c.isNull())
            {
                c  = QString("");
            }
            hash.insert( name, c );

            iStack.replace( iStack.count() - 1 , hash);
        }
    }

    return true;
}
Ejemplo n.º 10
0
void RegroupNode::render( OutputStream *stream, Context *c ) const
{
  Q_UNUSED( stream )
  QVariantList objList = m_target.toList( c );
  if ( objList.isEmpty() ) {
    c->insert( m_varName, QVariantHash() );
    return;
  }

  // What's going on?
  //
  // objList is a flat list of objects with a common parameter. For example, Person objects with
  // a name parameter. The list is already sorted.
  // Say the objList contains ["David Beckham", "David Blain", "Keira Nightly"] etc.
  // We want to regroup the list into separate lists of people with the same first name.
  // ie objHash should be: {"David": ["David Beckham", "David Blain"], "Keira": ["Keira Nightly"]}
  //
  // We then insert the objHash into the Context ready for rendering later in a for loop.

  QVariantList contextList;
  const QString keyName = getSafeString( m_expression.resolve( c ) );
  QListIterator<QVariant> i( objList );
  while ( i.hasNext() ) {
    const QVariant var = i.next();
    c->push();
    c->insert( QLatin1String( "var" ), var );
    const QString key = getSafeString( FilterExpression( QLatin1String( "var." ) + keyName, 0 ).resolve( c ) );
    c->pop();
    QVariantHash hash;
    if ( contextList.size() > 0 ) {
      QVariant hashVar = contextList.last();
      hash = hashVar.toHash();
    }
    if ( !hash.contains( QLatin1String( "grouper" ) ) || hash.value( QLatin1String( "grouper" ) ) != key ) {
      QVariantHash newHash;
      hash.insert( QLatin1String( "grouper" ), key );
      hash.insert( QLatin1String( "list" ), QVariantList() );
      contextList.append( newHash );
    }

    QVariantList list = hash.value( QLatin1String( "list" ) ).toList();
    list.append( var );
    hash.insert( QLatin1String( "list" ), list );
    contextList[contextList.size() - 1] = hash;
  }
  c->insert( m_varName, contextList );
}
Ejemplo n.º 11
0
bool ModelPackager::loadModel() {
    // First we check the FST file (if any)
    if (_modelFile.completeSuffix().contains("fst")) {
        QFile fst(_modelFile.filePath());
        if (!fst.open(QFile::ReadOnly | QFile::Text)) {
            OffscreenUi::asyncWarning(NULL,
                                 QString("ModelPackager::loadModel()"),
                                 QString("Could not open FST file %1").arg(_modelFile.filePath()),
                                 QMessageBox::Ok);
            qWarning() << QString("ModelPackager::loadModel(): Could not open FST file %1").arg(_modelFile.filePath());
            return false;
        }
        qCDebug(interfaceapp) << "Reading FST file";
        _mapping = FSTReader::readMapping(fst.readAll());
        fst.close();
        
        _fbxInfo = QFileInfo(_modelFile.path() + "/" + _mapping.value(FILENAME_FIELD).toString());
    } else {
        _fbxInfo = QFileInfo(_modelFile.filePath());
    }
    
    // open the fbx file
    QFile fbx(_fbxInfo.filePath());
    if (!_fbxInfo.exists() || !_fbxInfo.isFile() || !fbx.open(QIODevice::ReadOnly)) {
        OffscreenUi::asyncWarning(NULL,
                             QString("ModelPackager::loadModel()"),
                             QString("Could not open FBX file %1").arg(_fbxInfo.filePath()),
                             QMessageBox::Ok);
        qWarning() << "ModelPackager::loadModel(): Could not open FBX file";
        return false;
    }
    try {
        qCDebug(interfaceapp) << "Reading FBX file : " << _fbxInfo.filePath();
        QByteArray fbxContents = fbx.readAll();

        _hfmModel = FBXSerializer().read(fbxContents, QVariantHash(), _fbxInfo.filePath());

        // make sure we have some basic mappings
        populateBasicMapping(_mapping, _fbxInfo.filePath(), *_hfmModel);
    } catch (const QString& error) {
        qCDebug(interfaceapp) << "Error reading: " << error;
        return false;
    }
    return true;
}
Ejemplo n.º 12
0
void OBJBaker::bakeOBJ() {
    // Read the OBJ file
    QFile objFile(_originalModelFilePath);
    if (!objFile.open(QIODevice::ReadOnly)) {
        handleError("Error opening " + _originalModelFilePath + " for reading");
        return;
    }

    QByteArray objData = objFile.readAll();

    bool combineParts = true; // set true so that OBJReader reads material info from material library
    OBJReader reader;
    auto geometry = reader.readOBJ(objData, QVariantHash(), combineParts, _modelURL);

    // Write OBJ Data as FBX tree nodes
    createFBXNodeTree(_rootNode, *geometry);

    checkIfTexturesFinished();
}
Ejemplo n.º 13
0
QVariantHash GeoIPDatabase::readMetadata() const
{
    const char *ptr = reinterpret_cast<const char *>(m_data);
    quint32 size = m_size;
    if (m_size > MAX_METADATA_SIZE) {
        ptr += m_size - MAX_METADATA_SIZE;
        size = MAX_METADATA_SIZE;
    }

    const QByteArray data = QByteArray::fromRawData(ptr, size);
    int index = data.lastIndexOf(METADATA_BEGIN_MARK);
    if (index >= 0) {
        if (m_size > MAX_METADATA_SIZE)
            index += (m_size - MAX_METADATA_SIZE); // from begin of all data
        quint32 offset = static_cast<quint32>(index + strlen(METADATA_BEGIN_MARK));
        QVariant metadata = readDataField(offset);
        if (metadata.userType() == QMetaType::QVariantHash)
            return metadata.toHash();
    }

    return QVariantHash();
}
Ejemplo n.º 14
0
void AnimationReader::run() {
    DependencyManager::get<StatTracker>()->decrementStat("PendingProcessing");
    CounterStat counter("Processing");

    PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xFF00FF00, 0, { { "url", _url.toString() } });
    auto originalPriority = QThread::currentThread()->priority();
    if (originalPriority == QThread::InheritPriority) {
        originalPriority = QThread::NormalPriority;
    }
    QThread::currentThread()->setPriority(QThread::LowPriority);
    try {
        if (_data.isEmpty()) {
            throw QString("Reply is NULL ?!");
        }
        QString urlname = _url.path().toLower();
        bool urlValid = true;
        urlValid &= !urlname.isEmpty();
        urlValid &= !_url.path().isEmpty();

        if (urlValid) {
            // Parse the FBX directly from the QNetworkReply
            HFMModel::Pointer hfmModel;
            if (_url.path().toLower().endsWith(".fbx")) {
                hfmModel = FBXSerializer().read(_data, QVariantHash(), _url.path());
            } else {
                QString errorStr("usupported format");
                emit onError(299, errorStr);
            }
            emit onSuccess(hfmModel);
        } else {
            throw QString("url is invalid");
        }

    } catch (const QString& error) {
        emit onError(299, error);
    }
    QThread::currentThread()->setPriority(originalPriority);
}
Ejemplo n.º 15
0
void TestMustache::testSections()
{
	QVariantHash map = contactInfo("John Smith", "*****@*****.**");
	QVariantList contacts;
	contacts << contactInfo("James Dee", "*****@*****.**");
	contacts << contactInfo("Jim Jones", "*****@*****.**");
	map["contacts"] = contacts;

	QString _template = "Name: {{name}}, Email: {{email}}\n"
	                    "{{#contacts}}  {{name}} - {{email}}\n{{/contacts}}"
	                    "{{^contacts}}  No contacts{{/contacts}}";

	QString expectedOutput = "Name: John Smith, Email: [email protected]\n"
	                         "  James Dee - [email protected]\n"
	                         "  Jim Jones - [email protected]\n";

	Mustache::Renderer renderer;
	Mustache::QtVariantContext context(map);
	QString output = renderer.render(_template, &context);

	QCOMPARE(output, expectedOutput);

	// test inverted sections
	map.remove("contacts");
	context = Mustache::QtVariantContext(map);
	output = renderer.render(_template, &context);

	expectedOutput = "Name: John Smith, Email: [email protected]\n"
	                 "  No contacts";
	QCOMPARE(output, expectedOutput);

	// test with an empty list instead of an empty key
	map["contacts"] = QVariantHash();
	context = Mustache::QtVariantContext(map);
	output = renderer.render(_template, &context);
	QCOMPARE(output, expectedOutput);
}
Ejemplo n.º 16
0
TwitterSipPlugin::TwitterSipPlugin( Tomahawk::Accounts::Account* account )
    : SipPlugin( account )
    , m_checkTimer( this )
    , m_connectTimer( this )
    , m_dmPollTimer( this )
    , m_cachedFriendsSinceId( 0 )
    , m_cachedMentionsSinceId( 0 )
    , m_cachedDirectMessagesSinceId( 0 )
    , m_cachedPeers()
    , m_keyCache()
    , m_state( Tomahawk::Accounts::Account::Disconnected )
{
    qDebug() << Q_FUNC_INFO;

    connect( account, SIGNAL( nowAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &, const QTweetUser & ) ), SLOT( accountAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &, const QTweetUser & ) ) );

    m_configuration = account->configuration();
    qDebug() << "SIP configuration:" << m_configuration << m_configuration[ "cachedpeers" ];
    if ( Database::instance()->dbid() != m_account->configuration()[ "saveddbid" ].toString() )
    {
        m_configuration[ "cachedpeers" ] = QVariantHash();
        m_configuration[ "saveddbid" ] = Database::instance()->dbid();
        syncConfig();
    }

    m_checkTimer.setInterval( 180000 );
    m_checkTimer.setSingleShot( false );
    connect( &m_checkTimer, SIGNAL( timeout() ), SLOT( checkTimerFired() ) );

    m_dmPollTimer.setInterval( 60000 );
    m_dmPollTimer.setSingleShot( false );
    connect( &m_dmPollTimer, SIGNAL( timeout() ), SLOT( pollDirectMessages() ) );

    m_connectTimer.setInterval( 180000 );
    m_connectTimer.setSingleShot( false );
    connect( &m_connectTimer, SIGNAL( timeout() ), SLOT( connectTimerFired() ) );
}
Ejemplo n.º 17
0
void FBXMLHandler::flushCharacters()
{
    for ( int i = 0; i < iChars.length(); i ++)
    {
        QChar uniChar = iChars.at(i);

        if (!iWhiteSpaceAndNewLineCharSet.contains(uniChar))
        {

            QVariant container;
            if (iStack.count() >= 2)
            {
                container = iStack[iStack.count() - 2];
                if (container.isNull())
                {
                    container = QVariantHash();
                    iStack.replace( iStack.count() - 2 , container);
                }
            }

            if (container.type() == QVariant::List)
            {                
                QVariantHash object;
                object.insert( topName(), iChars );
                iStack.replace (iStack.count() - 1, object);
            } else {
                QVariant object(iChars);
                iStack.replace (iStack.count() - 1, object);
            }
            break;
        }

    }

    iChars.clear();
}
Ejemplo n.º 18
0
QVariantHash Job::hash() const
{
  if (warnIfInvalid())
    return m_jobData->hash();
  return QVariantHash();
}
Ejemplo n.º 19
0
/*!
    \since 4.7
    Returns all incoming options set in this QAuthenticator object by parsing
    the server reply. See \l{QAuthenticator#Options} for more information
    on incoming options.

    \sa option(), QAuthenticator#Options
*/
QVariantHash QAuthenticator::options() const
{
    return d ? d->options : QVariantHash();
}
Ejemplo n.º 20
0
void Ut_NotificationListModel::testNotificationIsNotAddedIfNoSummaryOrBody()
{
    QFETCH(QString, summary);
    QFETCH(QString, body);
    QFETCH(int, addItemCount);

    LipstickNotification notification("appName", 1, "appIcon", summary, body, QStringList() << "action", QVariantHash(), 1);
    gNotificationManagerStub->stubSetReturnValue("notificationIds", QList<uint>() << 1);
    gNotificationManagerStub->stubSetReturnValue("notification", &notification);
    NotificationListModel model;
    QCOMPARE(model.itemCount(), addItemCount);
}
Ejemplo n.º 21
0
void Ut_NotificationListModel::testNotificationIsOnlyAddedIfNotAlreadyAdded()
{
    LipstickNotification notification("appName", 1, "appIcon", "summary", "body", QStringList() << "action", QVariantHash(), 1);
    gNotificationManagerStub->stubSetReturnValue("notificationIds", QList<uint>() << 1);
    gNotificationManagerStub->stubSetReturnValue("notification", &notification);
    NotificationListModel model;
    model.updateNotification(1);
    QCOMPARE(model.itemCount(), 1);
}
Ejemplo n.º 22
0
void Ut_NotificationListModel::testModelPopulatesOnConstruction()
{
    LipstickNotification notification("appName", 1, "appIcon", "summary", "body", QStringList() << "action", QVariantHash(), 1);
    gNotificationManagerStub->stubSetReturnValue("notificationIds", QList<uint>() << 1);
    gNotificationManagerStub->stubSetReturnValue("notification", &notification);
    NotificationListModel model;
    QCOMPARE(model.itemCount(), 1);
    QCOMPARE(model.get(0), &notification);
}
Ejemplo n.º 23
0
void Ut_NotificationListModel::testNotificationRemoval()
{
    LipstickNotification notification("appName", 1, "appIcon", "summary", "body", QStringList() << "action", QVariantHash(), 1);
    gNotificationManagerStub->stubSetReturnValue("notification", &notification);
    NotificationListModel model;
    model.removeNotification(1);
    QCOMPARE(model.itemCount(), 0);
}
Ejemplo n.º 24
0
void Ut_NotificationListModel::testAlreadyAddedNotificationIsRemovedIfNoLongerAddable()
{
    LipstickNotification notification("appName", 1, "appIcon", "", "", QStringList() << "action", QVariantHash(), 1);
    gNotificationManagerStub->stubSetReturnValue("notificationIds", QList<uint>() << 1);
    gNotificationManagerStub->stubSetReturnValue("notification", &notification);
    NotificationListModel model;
    QCOMPARE(model.itemCount(), 0);
}
Ejemplo n.º 25
0
void GeometryResource::setExtra(void* extra) {
    const GeometryExtra* geometryExtra = static_cast<const GeometryExtra*>(extra);
    _mappingPair = geometryExtra ? geometryExtra->mapping : GeometryMappingPair(QUrl(), QVariantHash());
    _textureBaseURL = geometryExtra ? resolveTextureBaseUrl(_url, geometryExtra->textureBaseUrl) : QUrl();
    _combineParts = geometryExtra ? geometryExtra->combineParts : true;
}
Ejemplo n.º 26
0
QVariantHash IImageSource::readMetadata()
{
    return QVariantHash();
}