int main(int argc, char** argv)
{
	QCoreApplication app(argc, argv);
	
	if (argc < 3)
		qFatal("Usage: %s <extent> <output filename>", argv[0]);
	
	const int extent = QString(argv[1]).toInt();
	const QString outputFilename(argv[2]);
	
	QMultiMap<float, Vec3<TypeName> > map;
	for (TypeName x=-extent ; x<=extent ; ++x)
		for (TypeName y=-extent ; y<=extent ; ++y)
			for (TypeName z=-extent ; z<=extent ; ++z)
				insert(map, x, y, z);
	
	qDebug() << map.count() << "elements";
	
	QFile file(outputFilename);
	file.open(QIODevice::WriteOnly);
	QDataStream stream(&file);
	
	stream << (quint32) map.count();
	foreach (Vec3<TypeName> v, map)
		stream << v;
	
	return 0;
}
void tst_QWebPluginDatabase::enabled()
{
    QMultiMap<QString, QWebPluginInfo> pluginsMap;
    QWebPluginDatabase* database = QWebSettings::pluginDatabase();
    QList<QWebPluginInfo> plugins = database->plugins();

    for (int i = 0; i < plugins.count(); ++i) {
        QWebPluginInfo plugin = plugins.at(i);

        QList<MimeType> mimeTypes = plugin.mimeTypes();
        for (int j = 0; j < mimeTypes.count(); ++j) {
            QString mimeType = mimeTypes.at(j).name;
            pluginsMap.insert(mimeType, plugin);
            QVERIFY(plugin.supportsMimeType(mimeType));
        }
    }

    QMultiMap<QString, QWebPluginInfo>::iterator it = pluginsMap.begin();
    while (it != pluginsMap.end()) {
        QString mimeType = it.key();
        QWebPluginInfo plugin = it.value();
        QWebPluginInfo pluginForMimeType = database->pluginForMimeType(mimeType);

        QVERIFY(pluginsMap.count(mimeType) > 0);

        if (pluginsMap.count(mimeType) == 1) {
            QCOMPARE(plugin, pluginForMimeType);

            QVERIFY(plugin.isEnabled());
            QVERIFY(pluginForMimeType.isEnabled());
            plugin.setEnabled(false);
            QVERIFY(!plugin.isEnabled());
            QVERIFY(!pluginForMimeType.isEnabled());
        } else {
            QVERIFY(plugin.isEnabled());
            QVERIFY(pluginForMimeType.isEnabled());
            plugin.setEnabled(false);
            QVERIFY(!plugin.isEnabled());
        }

        QVERIFY(!plugin.isNull());
        QVERIFY(!pluginForMimeType.isNull());

        QWebPluginInfo pluginForMimeType2 = database->pluginForMimeType(mimeType);
        if (pluginsMap.count(mimeType) == 1) {
            QVERIFY(pluginForMimeType2 != plugin);
            QVERIFY(pluginForMimeType2.isNull());
        } else {
            QVERIFY(pluginForMimeType2 != plugin);
            QVERIFY(!pluginForMimeType2.isNull());
        }

        plugin.setEnabled(true);

        ++it;
    }
}
static QString certToFormattedString(QSslCertificate cert)
{
    QString resultstring = QLatin1String("<p>");
    QStringList tmplist;

    resultstring += cert.subjectInfo(QSslCertificate::CommonName);

    resultstring += QString::fromLatin1("<br/>Issuer: %1")
        .arg(cert.issuerInfo(QSslCertificate::CommonName));

    resultstring += QString::fromLatin1("<br/>Not valid before: %1<br/>Valid Until: %2")
        .arg(cert.effectiveDate().toString(Qt::ISODate))
        .arg(cert.expiryDate().toString(Qt::ISODate));

    QMultiMap<QSsl::AlternateNameEntryType, QString> names = cert.alternateSubjectNames();
    if (names.count() > 0) {
        tmplist = names.values(QSsl::DnsEntry);
        resultstring += QLatin1String("<br/>Alternate Names:<ul><li>")
            + tmplist.join(QLatin1String("</li><li>"))
            + QLatin1String("</li><</ul>");
    }

    resultstring += QLatin1String("</p>");

    return resultstring;
}
void filterNetworkAccessModule::extractObjects()
{
    if(!this->parseQnStack.isEmpty())
    {
        if( this->parseQnStack.front() == this->ObjectLevel)
        {
            while(!this->parseQnStack.isEmpty())
            {
                std::cout << "Processing..." << std::endl;

                QXmlStreamReader::TokenType tempType = this->parseTypeStack.front();
                this->parseTypeStack.pop_front();
                QString tempQn = this->parseQnStack.front();
                this->parseQnStack.pop_front();
                QString tempText = this->parseTextStack.front();
                this->parseTextStack.pop_front();

                std::cout << "QN : " << tempQn.toAscii().data() <<  " : " << tempType << std::endl;

                //create a new object for the stack
                QMultiMap<QString, QString> *temp = new QMultiMap<QString, QString>;
                do
                {
                    //get the next item from the stack
                    tempType = this->parseTypeStack.front();
                    this->parseTypeStack.pop_front();

                    tempQn = this->parseQnStack.front();
                    this->parseQnStack.pop_front();

                    tempText = this->parseTextStack.front();
                    this->parseTextStack.pop_front();

                    //DEBUG
                    std::cout << "Adding: (" << tempQn.toAscii().data() << "," << tempText.toAscii().data() << ")" << std::endl;

                    //create object
                    temp->insert(tempQn, tempText);


                }while(!this->parseQnStack.isEmpty() && this->parseQnStack.front() != this->ObjectLevel);

                //add object to list
                std::cout << "adding record for " << temp->count() << " submaps" << std::endl;
                std::cout << "block: " << temp->value(QString("name")).toAscii().data() << std::endl;
                this->finalObjects->push_back(temp);
            }
//            std::cout << "Number of Objects:" << this->finalObjects->size() << std::endl;

        }
        else
        {
            std::cerr << "Empty Status: " << this->parseQnStack.size() << std::endl;
            std::cerr << "Back Item: " << this->parseQnStack.back().toAscii().data() << std::endl;
            std::cerr << ":EXTRACTION LOOP EXITS WITHOUT EXECUTING:" << std::endl;
        }
    }
}
void tst_QWebPluginDatabase::pluginForMimeType()
{
    QMultiMap<QString, QWebPluginInfo> pluginsMap;
    QWebPluginDatabase* database = QWebSettings::pluginDatabase();
    QList<QWebPluginInfo> plugins = database->plugins();

    for (int i = 0; i < plugins.count(); ++i) {
        QWebPluginInfo plugin = plugins.at(i);

        QList<MimeType> mimeTypes = plugin.mimeTypes();
        for (int j = 0; j < mimeTypes.count(); ++j) {
            QString mimeType = mimeTypes.at(j).name;
            pluginsMap.insert(mimeType, plugin);
            QVERIFY(plugin.supportsMimeType(mimeType));
        }
    }

    for (int i = 0; i < plugins.count(); ++i) {
        QWebPluginInfo plugin = plugins.at(i);

        QList<MimeType> mimeTypes = plugin.mimeTypes();
        for (int j = 0; j < mimeTypes.count(); ++j) {
            QString mimeType = mimeTypes.at(j).name;

            QVERIFY(pluginsMap.count(mimeType) > 0);
            if (pluginsMap.count(mimeType) > 1)
                continue;

            QWebPluginInfo pluginForMimeType = database->pluginForMimeType(mimeType);
            QCOMPARE(pluginForMimeType, plugin);
            database->setSearchPaths(database->searchPaths());
            QCOMPARE(pluginForMimeType, plugin);
            QCOMPARE(pluginForMimeType, database->pluginForMimeType(mimeType.toUpper()));
            QCOMPARE(pluginForMimeType, database->pluginForMimeType(mimeType.toLower()));
            QVERIFY(plugin.supportsMimeType(mimeType));
            QVERIFY(!pluginForMimeType.isNull());
            QVERIFY(!plugin.isNull());
        }
    }
}
/*!
    Cleans the cache so that its size is under the maximum cache size.
    Returns the current size of the cache.

    When the current size of the cache is greater than the maximumCacheSize()
    older cache files are removed until the total size is less then 90% of
    maximumCacheSize() starting with the oldest ones first using the file
    creation date to determine how old a cache file is.

    Subclasses can reimplement this function to change the order that cache
    files are removed taking into account information in the application
    knows about that QNetworkDiskCache does not, for example the number of times
    a cache is accessed.

    Note: cacheSize() calls expire if the current cache size is unknown.

    \sa maximumCacheSize(), fileMetaData()
 */
qint64 QNetworkDiskCache::expire()
{
    Q_D(QNetworkDiskCache);
    if (d->currentCacheSize >= 0 && d->currentCacheSize < maximumCacheSize())
        return d->currentCacheSize;

    if (cacheDirectory().isEmpty()) {
        qWarning() << "QNetworkDiskCache::expire() The cache directory is not set";
        return 0;
    }

    // close file handle to prevent "in use" error when QFile::remove() is called
    d->lastItem.reset();

    QDir::Filters filters = QDir::AllDirs | QDir:: Files | QDir::NoDotAndDotDot;
    QDirIterator it(cacheDirectory(), filters, QDirIterator::Subdirectories);

    QMultiMap<QDateTime, QString> cacheItems;
    qint64 totalSize = 0;
    while (it.hasNext()) {
        QString path = it.next();
        QFileInfo info = it.fileInfo();
        QString fileName = info.fileName();
        if (fileName.endsWith(CACHE_POSTFIX)) {
            cacheItems.insert(info.created(), path);
            totalSize += info.size();
        }
    }

    int removedFiles = 0;
    qint64 goal = (maximumCacheSize() * 9) / 10;
    QMultiMap<QDateTime, QString>::const_iterator i = cacheItems.constBegin();
    while (i != cacheItems.constEnd()) {
        if (totalSize < goal)
            break;
        QString name = i.value();
        QFile file(name);
        qint64 size = file.size();
        file.remove();
        totalSize -= size;
        ++removedFiles;
        ++i;
    }
#if defined(QNETWORKDISKCACHE_DEBUG)
    if (removedFiles > 0) {
        qDebug() << "QNetworkDiskCache::expire()"
                << "Removed:" << removedFiles
                << "Kept:" << cacheItems.count() - removedFiles;
    }
#endif
    return totalSize;
}
void CalculateTaskScore::run()
{

    qDebug() << "CalculateTaskScore: Starting new thread";

    ConfigParser settings;
    QDateTime started = QDateTime::currentDateTime();
    ctemplate::TemplateDictionary dict("user_task_score");
    db = MySQLHandler::getInstance();
    QMultiMap<int, LCCode> users = UserDao::getUserNativeLCCodes(db);
    QList<QSharedPointer<Task> > tasks = this->getTasks();  //Must use custom function to check message for task id

    QMultiMap<int, LCCode> userSecondaryLanguages = UserDao::getUserLCCodes(db);
    QMultiMap<int, int> userTags = UserDao::getUserTagIds(db);
    QMultiMap<int, int> taskTags = TaskDao::getTaskTagIds(db);

    if(users.count() > 0) {
        for(QMultiMap<int, LCCode>::ConstIterator usersIter = users.constBegin(); usersIter != users.constEnd(); ++usersIter) {
            if(tasks.length() > 0) {
                const LCCode userNativeLCCode = users.value(usersIter.key());
                QList<TaskScore> taskScores;
                foreach(QSharedPointer<Task> task, tasks) {
                    int score = 0;

                    Locale taskSourceLocale = task->sourcelocale();

                    if(userNativeLCCode.first == taskSourceLocale.languagecode()) {
                        score += 750;
                        if(userNativeLCCode.second == taskSourceLocale.countrycode()) {
                            score += 75;
                        }
                    }

                    Locale taskTargetLocale = task->targetlocale();

                    if(userNativeLCCode.first == taskTargetLocale.languagecode()) {
                        score += 1000;
                        if(userNativeLCCode.second == taskTargetLocale.countrycode()) {
                            score += 100;
                        }
                    }

                    if(userSecondaryLanguages.contains(usersIter.key())) {
                        const QList<LCCode> lcCodes = userSecondaryLanguages.values(usersIter.key());
                        if(lcCodes.end() != std::find_if(lcCodes.begin(), lcCodes.end(), LidMatch(taskSourceLocale.languagecode()))) {
                            score += 500;
                            if(lcCodes.end() != std::find_if(lcCodes.begin(), lcCodes.end(), CidMatch(taskSourceLocale.countrycode())) ) {
                                score += 50;
                            }
                        }
                        if(lcCodes.end() != std::find_if(lcCodes.begin(), lcCodes.end(), LidMatch(taskTargetLocale.languagecode()))) {
                            score += 500;
                            if(lcCodes.end() != std::find_if(lcCodes.begin(), lcCodes.end(), CidMatch(taskTargetLocale.countrycode())) ) {
                                score += 50;
                            }
                        }
                    }

                    if(userTags.contains(usersIter.key()) && taskTags.contains(task->id())) {
                        int increment_value = 250;
                        QList<int> userTagIds = userTags.values(usersIter.key());
                        QList<int> userTaskTagIds = taskTags.values(task->id());

                        foreach(int userTagId, userTagIds) {
                            if(userTaskTagIds.contains(userTagId)) {
                                    score += increment_value;
                                    increment_value *= 0.75;
                            }
                        }
                    }

                    QDateTime created_time = QDateTime::fromString(
                                            QString::fromStdString(task->createdtime()), Qt::ISODate);
                    //increase score by one per day since created time
                    score += created_time.daysTo(QDateTime::currentDateTime());
                    taskScores.append(TaskScore(task->id(), score));
                }

                    this->saveUserTaskScore(usersIter.key(),taskScores);

            } else {
Exemple #8
0
void
FormMain::folderChanged( QTreeWidgetItem * current, QTreeWidgetItem * )
{
	editInfo->clear();

	if ( ! current )
		return;

	const int folder_id = current->data( 0, Qt::UserRole ).toInt();

	QString text("Folder: ");

	QSqlQuery q;

	// self
	q.prepare("SELECT "
			"name, "
			"path, "
			"size "
		"FROM "
			"folders "
		"WHERE "
			"id = :id ");

	q.bindValue(":id", folder_id );

	if ( q.exec() ) {
		if ( q.first() )
			text += q.value( 0 ).toString() + "<BR>" +
				"Path: " + q.value( 1 ).toString() + "<BR>" +
				"Size: " + prettyPrint( q.value( 2 ).toLongLong() ) + "<BR>";

	} else {
		emit yell( q.lastError().text() );
		return;
	}

	// count of folders
	int folderCount = 0;
	countFolders( folder_id, folderCount );

	// count of types
	int typeCount = 0;
	QHash< QString, int > types;
	countTypes( folder_id, types, typeCount );

	// ordering
	QMultiMap< int, QString > typesMap;
	QHash< QString, int >::const_iterator h = types.constBegin();

	while ( h != types.constEnd() ) {
		typesMap.insert( h.value(), h.key() );
		++h;
	}

	// percent of folders
	text += tr("folders: %1 (%2%)<BR>")
		.arg( folderCount )
		.arg( folderCount / ( qreal )( folderCount + typeCount ) * 100., 0, 'f', 1 );

	// percents of files

	chart->clear();

	if ( typesMap.count() > 0 ) {
		QMultiMap< int, QString >::const_iterator mm = typesMap.constEnd();

		do {
			--mm;

			const qreal percent = mm.key() / ( qreal )( folderCount + typeCount ) * 100;

			text += tr("%1: %2 (%3%)<BR>")
				.arg( mm.value() )
				.arg( mm.key() )
				.arg( percent, 0, 'f', 1 );

			chart->addPiece( percent, mm.value() );

		} while ( mm != typesMap.constBegin() );
	}

	text += QString( 50, '-' ) + "<BR>";		// horizontal line -------

	// folders
	text += "<BR><B>folders:</B><BR>";

	q.prepare("SELECT "
			"name, "
			"size "
		"FROM "
			"folders "
		"WHERE "
			"parent_id = :id "
		"ORDER BY "
			"size DESC");

	q.bindValue(":id", folder_id );

	if ( q.exec() ) {
		while ( q.next() )
			text += q.value( 0 ).toString() +
				" (" + prettyPrint( q.value( 1 ).toLongLong() ) + ")<BR>";

	} else {
		emit yell( q.lastError().text() );
		return;
	}

	// files
	text += "<BR><B>files:</B><BR>";

	q.prepare("SELECT "
			"name, "
			"size "
		"FROM "
			"files "
		"WHERE "
			"folders_id = :id "
		"ORDER BY "
			"size DESC");

	q.bindValue(":id", folder_id );

	if ( q.exec() ) {
		while ( q.next() )
			text += q.value( 0 ).toString() +
				" (" + prettyPrint( q.value( 1 ).toLongLong() ) + ")<BR>";

	} else {
		emit yell( q.lastError().text() );
		return;
	}

	editInfo->setHtml( text );
}
void tst_QWebPluginDatabase::preferredPlugin()
{
    QMultiMap<QString, QWebPluginInfo> pluginsMap;
    QWebPluginDatabase* database = QWebSettings::pluginDatabase();
    QList<QWebPluginInfo> plugins = database->plugins();

    for (int i = 0; i < plugins.count(); ++i) {
        QWebPluginInfo plugin = plugins.at(i);

        QList<MimeType> mimeTypes = plugin.mimeTypes();
        for (int j = 0; j < mimeTypes.count(); ++j) {
            QString mimeType = mimeTypes.at(j).name;
            pluginsMap.insert(mimeType, plugin);
        }
    }

    QMultiMap<QString, QWebPluginInfo>::iterator it = pluginsMap.begin();
    while (it != pluginsMap.end()) {
        QString mimeType = it.key();

        if (pluginsMap.count(mimeType) > 1) {
            QList<QWebPluginInfo> pluginsForMimeType = pluginsMap.values(mimeType);
            QWebPluginInfo plugin = database->pluginForMimeType(mimeType);
            QVERIFY(plugin.supportsMimeType(mimeType));

            pluginsForMimeType.removeAll(plugin);
            for (int i = 0; i < pluginsForMimeType.count(); ++i) {
                QWebPluginInfo anotherPlugin = pluginsForMimeType.at(i);
                QVERIFY(plugin.supportsMimeType(mimeType));
                QVERIFY(plugin != anotherPlugin);

                QCOMPARE(database->pluginForMimeType(mimeType), plugin);
                database->setPreferredPluginForMimeType(mimeType, anotherPlugin);
                QCOMPARE(database->pluginForMimeType(mimeType), anotherPlugin);

                anotherPlugin.setEnabled(false);
                QCOMPARE(database->pluginForMimeType(mimeType), plugin);

                anotherPlugin.setEnabled(true);
                QCOMPARE(database->pluginForMimeType(mimeType), anotherPlugin);
                database->setSearchPaths(database->searchPaths());
                QCOMPARE(database->pluginForMimeType(mimeType), anotherPlugin);

                database->setPreferredPluginForMimeType(mimeType, QWebPluginInfo());
                QCOMPARE(database->pluginForMimeType(mimeType), plugin);
            }
        } else {
            QWebPluginInfo plugin = database->pluginForMimeType(mimeType);
            QCOMPARE(pluginsMap.value(mimeType), plugin);

            database->setPreferredPluginForMimeType(mimeType, plugin);
            QCOMPARE(database->pluginForMimeType(mimeType), plugin);

            plugin.setEnabled(false);
            QCOMPARE(database->pluginForMimeType(mimeType), QWebPluginInfo());
            plugin.setEnabled(true);

            database->setPreferredPluginForMimeType(mimeType, QWebPluginInfo());
            QCOMPARE(database->pluginForMimeType(mimeType), plugin);
        }

        ++it;
    }

    if (pluginsMap.keys().count() >= 2) {
        QStringList mimeTypes = pluginsMap.uniqueKeys();

        QString mimeType1 = mimeTypes.at(0);
        QString mimeType2 = mimeTypes.at(1);
        QWebPluginInfo plugin1 = database->pluginForMimeType(mimeType1);
        QWebPluginInfo plugin2 = database->pluginForMimeType(mimeType2);

        int i = 2;
        while (plugin2.supportsMimeType(mimeType1)
               && !mimeType2.isEmpty()
               && i < mimeTypes.count()) {
            mimeType2 = mimeTypes.at(i);
            plugin2 = database->pluginForMimeType(mimeType2);
            ++i;
        }

        plugin1 = database->pluginForMimeType(mimeType1);
        QVERIFY(plugin1.supportsMimeType(mimeType1));
        QVERIFY(!plugin1.isNull());
        plugin2 = database->pluginForMimeType(mimeType2);
        QVERIFY(plugin2.supportsMimeType(mimeType2));
        QVERIFY(!plugin2.isNull());

        database->setPreferredPluginForMimeType(mimeType2, plugin1);
        QVERIFY(!plugin1.supportsMimeType(mimeType2));
        QCOMPARE(database->pluginForMimeType(mimeType2), plugin2);

        database->setPreferredPluginForMimeType(mimeType1, plugin1);
        QVERIFY(!plugin2.supportsMimeType(mimeType1));
        QCOMPARE(database->pluginForMimeType(mimeType2), plugin2);
    }
}