Ejemplo n.º 1
0
//we add the case to test dump function by creating medatedata object with file name from other team.
void ut_metadata::testSetOrientationTag()
{
    QVERIFY(QuillMetadata::canRead("/usr/share/libquillmetadata-tests/images/exif.jpg"));
    metadata->setEntry(QuillMetadata::Tag_Orientation, QVariant(short(7)));
    QByteArray result = metadata->dump(QuillMetadata::ExifFormat);
    QVERIFY(!result.isNull());
}
Ejemplo n.º 2
0
QByteArray QWget::exec(QUrl url, QByteArray postData)
{
    QNetworkAccessManager * manager = network_manager();
    manager->setProxy(_proxy);
    connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(onFinished(QNetworkReply*)));
    QNetworkRequest * nr = new QNetworkRequest(url);
    //nr->setRawHeader("User-Agent","Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1");
    nr->setRawHeader("User-Agent","Opera/9.0");
    qDebug() << url;

    finished = false;
    if(postData.isNull())
        manager->get(*nr);
    else
        manager->post(*nr,postData);
    while(!finished)
    {
        QCoreApplication::instance()->processEvents();
        #ifdef WIN32
        Sleep(50);
        #else
            usleep(50000);
        #endif
    }
    delete nr;
    QCoreApplication::instance()->processEvents();
    //qDebug() << "Ans: " << ans;
    // delete nr;
    return ans;
    return QByteArray();
}
Ejemplo n.º 3
0
void Serializer::serialize( const QVariant& v, QIODevice* io, bool* ok )
{
  Q_ASSERT( io );
  if (!io->isOpen()) {
    if (!io->open(QIODevice::WriteOnly)) {
      if ( ok != 0 )
        *ok = false;
      qCritical ("Error opening device");
      return;
    }
  }

  if (!io->isWritable()) {
    if (ok != 0)
      *ok = false;
    qCritical ("Device is not readable");
    io->close();
    return;
  }

  const QByteArray str = serialize( v );
  if ( !str.isNull() ) {
    QDataStream stream( io );
    stream << str;
  } else {
    if ( ok )
      *ok = false;
  }
}
Ejemplo n.º 4
0
void  EditorWindow::loadSettings()
{

    QSettings settings;

    /* Main Window location */
    settings.beginGroup("EditorWindow");
    QSize size = settings.value("size").toSize();
    QPoint pos = settings.value("position").toPoint();
    QByteArray state = settings.value("state").toByteArray();

    /* Recent docs/projects */
    recentDocs = settings.value("recentDocs", QStringList()).toStringList();
    recentProjects = settings.value("recentProjects",
                                    QStringList()).toStringList();

    settings.endGroup();

    if(!(size.isNull() || pos.isNull() || state.isNull()))
    {
        resize(size);
        move(pos);
        restoreState(state);
    }

}
Ejemplo n.º 5
0
void EditTOC::ReadSettings()
{
    SettingsStore settings;
    settings.beginGroup(SETTINGS_GROUP);
    // The size of the window and it's full screen status
    QByteArray geometry = settings.value("geometry").toByteArray();

    if (!geometry.isNull()) {
        restoreGeometry(geometry);
    }

    // Column widths
    int size = settings.beginReadArray("column_data");

    for (int column = 0; column < size && column < ui.TOCTree->header()->count(); column++) {
        settings.setArrayIndex(column);
        int column_width = settings.value("width").toInt();

        if (column_width) {
            ui.TOCTree->setColumnWidth(column, column_width);
        }
    }
    settings.endArray();

    settings.endGroup();
}
Ejemplo n.º 6
0
void
PhotosEngine::resultFlickr( const KUrl &url, QByteArray data, NetworkAccessManagerProxy::Error e )
{
    if( !m_flickrUrls.contains( url ) )
        return;

    DEBUG_BLOCK
    m_flickrUrls.remove( url );
    if( e.code != QNetworkReply::NoError )
    {
        setData( "photos", "message", i18n( "Unable to retrieve from Flickr.com: %1", e.description ) );
        debug() << "Unable to retrieve Flickr information:" << e.description;
        return;
    }

    if( data.isNull() )
    {
        debug() << "Got bad xml!";
        return;
    }

    removeAllData( "photos" );
    QXmlStreamReader xml( data );
    PhotosInfo::List photosInfo = photosListFromXml( xml );
    debug() << "got" << photosInfo.size() << "photo info";
    setData( "photos", "artist", m_artist );
    setData( "photos", "data", qVariantFromValue( photosInfo ) );
}
Ejemplo n.º 7
0
QByteArray
StarDictDictionaryManager::poNextWord(QByteArray searchWord, int* iCurrent)
{
    // the input can be:
    // (word,iCurrent),read word,write iNext to iCurrent,and return next word. used by TopWin::NextCallback();
    // (NULL,iCurrent),read iCurrent,write iNext to iCurrent,and return next word. used by AppCore::ListWords();
    QByteArray currentWord = NULL;
    QVector<Dictionary *>::size_type iCurrentLib = 0;
    const char *word;

    for (QVector<Dictionary *>::size_type iLib = 0; iLib < d->dictionaryList.size(); ++iLib)
    {
        if (!searchWord.isEmpty())
            iCurrent[iLib] = d->dictionaryList.at(iLib)->lookup(searchWord);

        if (iCurrent[iLib] == invalidIndex)
            continue;

        if (iCurrent[iLib] >= articleCount(iLib) || iCurrent[iLib] < 0)
            continue;

        if (currentWord.isNull())
        {
            currentWord = key(iCurrent[iLib], iLib);
            iCurrentLib = iLib;
        }
        else
        {
            word = key(iCurrent[iLib], iLib);

            if (stardictStringCompare(currentWord, word) > 0 )
            {
                currentWord = word;
                iCurrentLib = iLib;
            }
        }
    }

    if (!currentWord.isEmpty())
    {
        iCurrent[iCurrentLib]++;
        for (QVector<Dictionary *>::size_type iLib = 0; iLib < d->dictionaryList.size(); ++iLib)
        {
            if (iLib == iCurrentLib)
                continue;

            if (iCurrent[iLib] == invalidIndex)
                continue;

            if ( iCurrent[iLib] >= articleCount(iLib) || iCurrent[iLib] < 0)
                continue;

            if (strcmp(currentWord, key(iCurrent[iLib], iLib)) == 0 )
                iCurrent[iLib]++;
        }

        currentWord = poCurrentWord(iCurrent);
    }
    return currentWord;
}
Ejemplo n.º 8
0
qlonglong ddMainWindow::getSizeWithDU(const QString &folder)
{
    qlonglong folderSize = 0;
    // -------------использем утилиту du для получения размера--------------------
    QProcess* adb = new QProcess(this);
    QString cmd = "adb";
    QStringList argAdb;
    argAdb << "shell" << "du" <<"-Lcs" << folder;
    adb->start(cmd, argAdb);
    if (!adb->waitForFinished())
        return 0;

    QByteArray res = adb->readLine();
    while (!res.isNull())
    {
        QString strLine = res;
        if (strLine.contains("total"))
        {
            QStringList list = strLine.split("\t");
            folderSize = list.at(0).toLongLong();
            break;
        }

        res = adb->readLine();
    }

    return folderSize;


}
Ejemplo n.º 9
0
void tst_QProcessEnvironment::systemEnvironment()
{
    static const char envname[] = "THIS_ENVIRONMENT_VARIABLE_HOPEFULLY_DOESNT_EXIST";
    QByteArray path = qgetenv("PATH");
    QByteArray nonexistant = qgetenv(envname);
    QProcessEnvironment system = QProcessEnvironment::systemEnvironment();

    QVERIFY(nonexistant.isNull());

#ifdef Q_WS_WINCE
    // Windows CE has no environment
    QVERIFY(path.isEmpty());
    QVERIFY(!system.contains("PATH"));
    QVERIFY(system.isEmpty());
#else
    // all other system have environments
    if (path.isEmpty())
        QFAIL("Could not find the PATH environment variable -- please correct the test environment");

    QVERIFY(system.contains("PATH"));
    QCOMPARE(system.value("PATH"), QString::fromLocal8Bit(path));

    QVERIFY(!system.contains(envname));

# ifdef Q_OS_WIN
    // check case-insensitive too
    QVERIFY(system.contains("path"));
    QCOMPARE(system.value("path"), QString::fromLocal8Bit(path));

    QVERIFY(!system.contains(QString(envname).toLower()));
# endif
#endif
}
Ejemplo n.º 10
0
/* calculate request-digest/response-digest as per HTTP Digest spec */
static QByteArray digestMd5Response(
    const QByteArray &alg,
    const QByteArray &userName,
    const QByteArray &realm,
    const QByteArray &password,
    const QByteArray &nonce,       /* nonce from server */
    const QByteArray &nonceCount,  /* 8 hex digits */
    const QByteArray &cNonce,      /* client nonce */
    const QByteArray &qop,         /* qop-value: "", "auth", "auth-int" */
    const QByteArray &method,      /* method from the request */
    const QByteArray &digestUri,   /* requested URL */
    const QByteArray &hEntity       /* H(entity body) if qop="auth-int" */
    )
{
    QCryptographicHash hash(QCryptographicHash::Md5);
    hash.addData(userName);
    hash.addData(":", 1);
    hash.addData(realm);
    hash.addData(":", 1);
    hash.addData(password);
    QByteArray ha1 = hash.result();
    if (alg.toLower() == "md5-sess") {
        hash.reset();
        hash.addData(ha1);
        hash.addData(":", 1);
        hash.addData(nonce);
        hash.addData(":", 1);
        hash.addData(cNonce);
        ha1 = hash.result();
    };
    ha1 = ha1.toHex();
      
    // calculate H(A2)
    hash.reset();
    hash.addData(method);
    hash.addData(":", 1);
    hash.addData(digestUri);
    if (qop.toLower() == "auth-int") {
        hash.addData(":", 1);
        hash.addData(hEntity);
    }
    QByteArray ha2hex = hash.result().toHex();

    // calculate response
    hash.reset();
    hash.addData(ha1);
    hash.addData(":", 1);
    hash.addData(nonce);
    hash.addData(":", 1);
    if (!qop.isNull()) {
        hash.addData(nonceCount);
        hash.addData(":", 1);
        hash.addData(cNonce);
        hash.addData(":", 1);
        hash.addData(qop);
        hash.addData(":", 1);
    }
    hash.addData(ha2hex);
    return hash.result().toHex();
}
Ejemplo n.º 11
0
/*!
    Creates a QByteArray of the \a environment.
*/
static QByteArray qt_create_environment(const QStringList &environment)
{
    QByteArray envlist;
    if (environment.isEmpty())
        return envlist;

    int pos = 0;
    // add PATH if necessary (for DLL loading)
    QByteArray path = qgetenv("PATH");
    if (environment.filter(QRegExp("^PATH=",Qt::CaseInsensitive)).isEmpty() && !path.isNull()) {
            QString tmp = QString(QLatin1String("PATH=%1")).arg(QString::fromLocal8Bit(path));
            uint tmpSize = sizeof(wchar_t) * (tmp.length() + 1);
            envlist.resize(envlist.size() + tmpSize);
            memcpy(envlist.data() + pos, tmp.utf16(), tmpSize);
            pos += tmpSize;
    }
    // add the user environment
    for (QStringList::ConstIterator it = environment.begin(); it != environment.end(); it++ ) {
            QString tmp = *it;
            uint tmpSize = sizeof(wchar_t) * (tmp.length() + 1);
            envlist.resize(envlist.size() + tmpSize);
            memcpy(envlist.data() + pos, tmp.utf16(), tmpSize);
            pos += tmpSize;
    }
    // add the 2 terminating 0 (actually 4, just to be on the safe side)
    envlist.resize(envlist.size() + 4);
    envlist[pos++] = 0;
    envlist[pos++] = 0;
    envlist[pos++] = 0;
    envlist[pos++] = 0;

    return envlist;
}
/*!
  Sets the raw header \a key to be of value \a value.
  If \a key was previously set, it is added multiply.
*/
void TInternetMessageHeader::addRawHeader(const QByteArray &key, const QByteArray &value)
{
    if (key.isEmpty() || value.isNull())
        return;

    headerPairList << RawHeaderPair(key, value);
}
Ejemplo n.º 13
0
bool ZeroCopyInputStreamQIODevice::Skip(int count)
{
   if (this->pos != this->buffer + this->nbLastRead) // There is still some data into the buffer. See 'BackUp(..)'.
   {
      if (this->pos + count > this->buffer + this->nbLastRead)
      {
         count -= (this->buffer + this->nbLastRead) - this->pos;
         this->pos = this->buffer + this->nbLastRead;
      }
      else
      {
         this->pos += count;
         count = 0;
      }
   }

   if (this->device->bytesAvailable() == 0)
      return false;

   if (count == 0)
      return true;

   QByteArray data = this->device->read(count);
   if (data.isNull())
      return false;
   this->bytesRead += data.size();
   return this->device->bytesAvailable() > 0;
}
Ejemplo n.º 14
0
ByteArrayReply::ByteArrayReply(const QNetworkRequest &request,
							   const QByteArray &ba, const QString& mimeType,
							   QObject *parent) :
	QNetworkReply(parent),
	origLen(ba.size()),
	data(ba)
{
	setRequest(request);
	setOpenMode(QIODevice::ReadOnly);

	if (ba.isNull()) {
		setError(QNetworkReply::ContentNotFoundError, "Not found");
		QTimer::singleShot(0, this, SIGNAL(metaDataChanged()));
		QTimer::singleShot(0, this, SLOT(signalError()));
		QTimer::singleShot(0, this, SIGNAL(finished()));
	} else {
		if (mimeType.isEmpty()) {
			setHeader(QNetworkRequest::ContentTypeHeader, "application/octet-stream");
		} else {
			setHeader(QNetworkRequest::ContentTypeHeader, mimeType);
		}
		setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(origLen));
		QTimer::singleShot(0, this, SIGNAL(metaDataChanged()));
		QTimer::singleShot(0, this, SIGNAL(readyRead()));
	}
}
Ejemplo n.º 15
0
QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
{
    QList<QByteArray>   devices;

    UInt32  propSize = 0;

    if (AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &propSize, 0) == noErr) {

        const int dc = propSize / sizeof(AudioDeviceID);

        if (dc > 0) {
            AudioDeviceID*  audioDevices = new AudioDeviceID[dc];

            if (AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &propSize, audioDevices) == noErr) {
                for (int i = 0; i < dc; ++i) {
                    QByteArray info = get_device_info(audioDevices[i], mode);
                    if (!info.isNull())
                        devices << info;
                }
            }

            delete audioDevices;
        }
    }

    return devices;
}
Ejemplo n.º 16
0
void QCustomNetworkReply::setHttpStatusCode( int code, const QByteArray &statusText )
{
    setAttribute( QNetworkRequest::HttpStatusCodeAttribute, code );
    if ( statusText.isNull() )
        return;

    setAttribute( QNetworkRequest::HttpReasonPhraseAttribute, statusText );
}
Ejemplo n.º 17
0
QByteArray contentChecksumType()
{
    static QByteArray type = qgetenv("OWNCLOUD_CONTENT_CHECKSUM_TYPE");
    if (!type.isNull()) { // can set to "" to disable checksumming
        return type;
    }
    return "SHA1";
}
Ejemplo n.º 18
0
template <> optional<std::string> Query::get(int offset) {
    assert(stmt.impl && stmt.impl->query.isValid());
    QByteArray value = stmt.impl->query.value(offset).toByteArray();
    checkQueryError(stmt.impl->query);
    if (value.isNull())
        return {};
    return { std::string(value.constData(), value.size()) };
}
Ejemplo n.º 19
0
QByteArray Kleo::hexencode(const QByteArray &in)
{
    if (in.isNull()) {
        return QByteArray();
    }
    const std::string result = hexencode(std::string(in.constData()));
    return QByteArray(result.data(), result.size());
}
Ejemplo n.º 20
0
void tst_QByteArrayList::joinEmptiness() const
{
    QByteArrayList list;
    QByteArray string = list.join(QByteArray());

    QVERIFY(string.isEmpty());
    QVERIFY(string.isNull());
}
Ejemplo n.º 21
0
void KConfigGroup::writeEntry( const char* key, const QByteArray& value,
                               WriteConfigFlags flags )
{
    Q_ASSERT_X(isValid(), "KConfigGroup::writeEntry", "accessing an invalid group");
    Q_ASSERT_X(!d->bConst, "KConfigGroup::writeEntry", "writing to a read-only group");

    config()->d_func()->putData(d->fullName(), key, value.isNull()? QByteArray(""): value, flags);
}
Ejemplo n.º 22
0
QByteArray
StarDictDictionaryManager::poPreviousWord(long *iCurrent)
{
    // used by TopWin::PreviousCallback(); the iCurrent is cached by AppCore::TopWinWordChange();
    QByteArray poCurrentWord = NULL;
    QVector<Dictionary *>::size_type iCurrentLib = 0;
    const char *word;

    for (QVector<Dictionary *>::size_type iLib = 0; iLib < d->dictionaryList.size(); ++iLib)
    {
        if (iCurrent[iLib] == invalidIndex)
            iCurrent[iLib] = articleCount(iLib);
        else
        {
            if ( iCurrent[iLib] > articleCount(iLib) || iCurrent[iLib] <= 0)
                continue;
        }

        if ( poCurrentWord.isNull() )
        {
            poCurrentWord = key(iCurrent[iLib] - 1, iLib);
            iCurrentLib = iLib;
        }
        else
        {
            word = key(iCurrent[iLib] - 1, iLib);
            if (stardictStringCompare(poCurrentWord, word) < 0 )
            {
                poCurrentWord = word;
                iCurrentLib = iLib;
            }
        }
    }

    if (!poCurrentWord.isEmpty())
    {
        iCurrent[iCurrentLib]--;
        for (QVector<Dictionary *>::size_type iLib = 0; iLib < d->dictionaryList.size(); ++iLib)
        {
            if (iLib == iCurrentLib)
                continue;

            if (iCurrent[iLib] > articleCount(iLib) || iCurrent[iLib] <= 0)
                continue;

            if (poCurrentWord == key(iCurrent[iLib] - 1, iLib))
            {
                iCurrent[iLib]--;
            }
            else
            {
                if (iCurrent[iLib] == articleCount(iLib))
                    iCurrent[iLib] = invalidIndex;
            }
        }
    }
    return poCurrentWord;
}
Ejemplo n.º 23
0
void InitializationThread::selfTest(void)
{
	const unsigned int cpu[4] = {CPU_TYPE_X86_GEN, CPU_TYPE_X86_SSE, CPU_TYPE_X64_GEN, CPU_TYPE_X64_SSE};

	LockedFile::selfTest();

	for(size_t k = 0; k < 4; k++)
	{
		qDebug("[TEST]");
		switch(cpu[k])
		{
			PRINT_CPU_TYPE(CPU_TYPE_X86_GEN); break;
			PRINT_CPU_TYPE(CPU_TYPE_X86_SSE); break;
			PRINT_CPU_TYPE(CPU_TYPE_X64_GEN); break;
			PRINT_CPU_TYPE(CPU_TYPE_X64_SSE); break;
			default: MUTILS_THROW("CPU support undefined!");
		}
		unsigned int n = 0;
		for(int i = 0; true; i++)
		{
			if(!(g_lamexp_tools[i].pcName || g_lamexp_tools[i].pcHash  || g_lamexp_tools[i].uiVersion))
			{
				break;
			}
			else if(g_lamexp_tools[i].pcName && g_lamexp_tools[i].pcHash && g_lamexp_tools[i].uiVersion)
			{
				const QString toolName = QString::fromLatin1(g_lamexp_tools[i].pcName);
				const QByteArray expectedHash = QByteArray(g_lamexp_tools[i].pcHash);
				if(g_lamexp_tools[i].uiCpuType & cpu[k])
				{
					qDebug("%02i -> %s", ++n, MUTILS_UTF8(toolName));
					QFile resource(QString(":/tools/%1").arg(toolName));
					if(!resource.open(QIODevice::ReadOnly))
					{
						qFatal("The resource for \"%s\" could not be opened!", MUTILS_UTF8(toolName));
						break;
					}
					QByteArray hash = LockedFile::fileHash(resource);
					if(hash.isNull() || _stricmp(hash.constData(), expectedHash.constData()))
					{
						qFatal("Hash check for tool \"%s\" has failed!", MUTILS_UTF8(toolName));
						break;
					}
					resource.close();
				}
			}
			else
			{
				qFatal("Inconsistent checksum data detected. Take care!");
			}
		}
		if(n != EXPECTED_TOOL_COUNT)
		{
			qFatal("Tool count mismatch for CPU type %u !!!", cpu[k]);
		}
		qDebug("Done.\n");
	}
}
Ejemplo n.º 24
0
void MjpegPlayer::readImg()
{
    if (m_reply->bytesAvailable()) {
        QByteArray array = m_multiPartReader->read( m_reply->readAll() );
        if ( !array.isNull() && m_currentPixmap->loadFromData(array)) {
            emit( frameReady(m_currentPixmap) );
        }
    }
}
Ejemplo n.º 25
0
void ComputeChecksum::slotCalculationDone()
{
    QByteArray checksum = _watcher.future().result();
    if (!checksum.isNull()) {
        emit done(_checksumType, checksum);
    } else {
        emit done(QByteArray(), QByteArray());
    }
}
Ejemplo n.º 26
0
QList<Course> IversityClient::courses(const QString &query)
{
    QList<Course> list;

    QByteArray data;
    net::Uri::Path path;
    net::Uri::QueryParameters params;

    qCDebug(Iversity) << "Download started...";
    if (data.isNull())
        get( path, params, data);
    qCDebug(Iversity) << "Data received:" << data.length() << "bytes";
    QJsonDocument root = QJsonDocument::fromJson(data);

    QVariantMap variant = root.toVariant().toMap();
    QList<QVariant> courses = variant["courses"].toList();
    qCDebug(Iversity) << "Element count:" << courses.length();

    SearchEngine se(query);

    for (const QVariant &i : courses)
    {
        QVariantMap map = i.toMap();

        Course course;
        course.id = map["id"].toString();
        course.slug = map["url"].toString();
        course.title = map["title"].toString();
        course.description = map["description"].toString();
        course.headline = map["subtitle"].toString();
        course.art = map["cover"].toString();
        course.link = map["url"].toString();
        course.extra = grabExtra(map);
        course.video = map["trailer_video"].toString();

        QList<QVariant> instructors = map["instructors"].toList();
        for (const QVariant& j : instructors)
        {
            QVariantMap imap = j.toMap();
            Instructor instr;
            instr.image = imap["image"].toString();
            instr.bio = imap["biography"].toString();
            instr.name = imap["name"].toString();

            course.instructors.append(instr);
        }

        course.departments.append(map["discipline"].toString());

        //qCDebug(Iversity) << "Category count: " << course.departments;
        //qCDebug(Iversity) << "Instr count: " << course.instructors.size();
        if (query.isEmpty() || se.isMatch(course))
            list.append(course);
    }

    return list;
}
Ejemplo n.º 27
0
bool PluginTV::Init()
{
	QByteArray ceSoir = TTSManager::CreateNewSound("Programme télé de ce soir", "claire");
	if(ceSoir.isNull())
		return false;
	
	ceSoirMessage = "MU " + ceSoir + "\nPL 3\nMW\n";
	return true;
}
Ejemplo n.º 28
0
void TlenAvatarService::avatarReady(ContactAccountData *contactAccountData, const QByteArray &avatar)
{
	InProgress.removeAll(contactAccountData);

	if (avatar.isNull())
		return;

	emit avatarFetched(contactAccountData, avatar);
	qDebug() << "Tlen Have Avatar" << contactAccountData->id();
}
Ejemplo n.º 29
0
 QString SessionPrivate::readString(const QByteArray& data) const
 {
     QByteArray enc = encoding;
     if (enc.isNull())
         enc = detectEncoding(data);
     QTextCodec *codec = QTextCodec::codecForName(enc);
     if (!codec)
         codec = QTextCodec::codecForLocale();
     return codec->toUnicode(data);
 }
qint64 TcpServerClient::send(QByteArray data)
{
    if(!data.isNull())
    {
        serverClientMessage(this, 7, data);
        return socket->write(data);
    }

    return 0;
}