bool QHelpCollectionHandler::openCollectionFile() { if (m_dbOpened) return m_dbOpened; m_connectionName = QHelpGlobal::uniquifyConnectionName( QLatin1String("QHelpCollectionHandler"), this); bool openingOk = true; { QSqlDatabase db = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), m_connectionName); db.setDatabaseName(collectionFile()); openingOk = db.open(); if (openingOk) m_query = QSqlQuery(db); } if (!openingOk) { QSqlDatabase::removeDatabase(m_connectionName); emit error(tr("Cannot open collection file: %1").arg(collectionFile())); return false; } m_query.exec(QLatin1String("SELECT COUNT(*) FROM sqlite_master WHERE TYPE=\'table\'" "AND Name=\'NamespaceTable\'")); m_query.next(); if (m_query.value(0).toInt() < 1) { if (!createTables(&m_query)) { emit error(tr("Cannot create tables in file %1!").arg(collectionFile())); return false; } } m_dbOpened = true; return m_dbOpened; }
bool TextureCollection::TextureCollectionCreator::SaveTextureCollection(const char* _collectionName, const char* _collectionFileName) { // Check if we have at last one texture to save if (!m_TextureData.size()) { // We need at last one texture! return false; } // Create the byte array we will use to put all data std::vector<unsigned char> byteArray; // Set the collection header data TextureCollectionHeader headerData = {}; headerData.collectionName.SetString(_collectionName); headerData.width = m_Width; headerData.height = m_Height; headerData.totalTextures = m_TextureData.size(); // Set the texture size uint32_t textureSize = m_Width * m_Height * 4; // Serialize the header data headerData.SerializeAndAppend(byteArray); // For each texture for (int i = 0; i < m_TextureData.size(); i++) { // Serialize the texture data and append m_TextureData[i].SerializeAndAppend(byteArray); // Increment the vector size byteArray.resize(byteArray.size() + textureSize); // Copy the data memcpy(&byteArray.data()[byteArray.size() - textureSize], m_TextureData[i].data, textureSize); } // Create the file std::ofstream collectionFile(_collectionFileName, std::ios::out | std::ios::binary); if (!collectionFile.is_open()) { // Error creating the file return false; } // Write the data collectionFile.write((char*)byteArray.data(), byteArray.size()); // Close the file collectionFile.close(); return true; }
xtHelp::xtHelp(QWidget *parent) : QHelpEngine(QHC_PATH, parent), _nam(new QNetworkAccessManager), _online(false) { connect(_nam, SIGNAL(finished(QNetworkReply *)), this, SLOT(sError(QNetworkReply *))); if(!setupData()) qWarning("Error setting up the help data"); /* TODO: remove the #ifdef and the empty help file & its corresponding qhc from xtuple/share once we fix the remote image loading bug in fileData */ #ifdef XTHELPONLINE _online = fileData(QUrl(QHCHOMEPAGE)) == QByteArray(""); #endif // XTHELPONLINE if (DEBUG) qDebug() << "xtHelp collection file" << collectionFile() << "exists?" << QFile::exists(collectionFile()) << "online?" << _online; }
/*! Sets the file \a fileName as the collection file for the help engine. Calling this function will leave the help engine in an invalid state, meaning setupData() or any getter function has to be called in order to setup the help engine again. */ void QHelpEngineCore::setCollectionFile(const QString &fileName) { if (fileName == collectionFile()) return; if (d->collectionHandler) { delete d->collectionHandler; d->collectionHandler = 0; d->clearMaps(); } d->init(fileName, this); d->needsSetup = true; }
int QHelpEngineCore::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 4) qt_static_metacall(this, _c, _id, _a); _id -= 4; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< bool*>(_v) = autoSaveFilter(); break; case 1: *reinterpret_cast< QString*>(_v) = collectionFile(); break; case 2: *reinterpret_cast< QString*>(_v) = currentFilter(); break; } _id -= 3; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setAutoSaveFilter(*reinterpret_cast< bool*>(_v)); break; case 1: setCollectionFile(*reinterpret_cast< QString*>(_v)); break; case 2: setCurrentFilter(*reinterpret_cast< QString*>(_v)); break; } _id -= 3; } else if (_c == QMetaObject::ResetProperty) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 3; } #endif // QT_NO_PROPERTIES return _id; }
bool QHelpCollectionHandler::copyCollectionFile(const QString &fileName) { if (!m_dbOpened) return false; QFileInfo fi(fileName); if (fi.exists()) { emit error(tr("The collection file '%1' already exists."). arg(fileName)); return false; } if (!fi.absoluteDir().exists() && !QDir().mkpath(fi.absolutePath())) { emit error(tr("Cannot create directory: %1").arg(fi.absolutePath())); return false; } QString colFile = fi.absoluteFilePath(); QString connectionName = QHelpGlobal::uniquifyConnectionName( QLatin1String("QHelpCollectionHandlerCopy"), this); QSqlQuery *copyQuery = 0; bool openingOk = true; { QSqlDatabase db = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), connectionName); db.setDatabaseName(colFile); openingOk = db.open(); if (openingOk) copyQuery = new QSqlQuery(db); } if (!openingOk) { emit error(tr("Cannot open collection file: %1").arg(colFile)); return false; } copyQuery->exec(QLatin1String("PRAGMA synchronous=OFF")); copyQuery->exec(QLatin1String("PRAGMA cache_size=3000")); if (!createTables(copyQuery)) { emit error(tr("Cannot copy collection file: %1").arg(colFile)); return false; } QString oldBaseDir = QFileInfo(collectionFile()).absolutePath(); QString oldFilePath; QFileInfo newColFi(colFile); m_query.exec(QLatin1String("SELECT Name, FilePath FROM NamespaceTable")); while (m_query.next()) { copyQuery->prepare(QLatin1String("INSERT INTO NamespaceTable VALUES(NULL, ?, ?)")); copyQuery->bindValue(0, m_query.value(0).toString()); oldFilePath = m_query.value(1).toString(); if (!QDir::isAbsolutePath(oldFilePath)) oldFilePath = oldBaseDir + QDir::separator() + oldFilePath; copyQuery->bindValue(1, newColFi.absoluteDir().relativeFilePath(oldFilePath)); copyQuery->exec(); } m_query.exec(QLatin1String("SELECT NamespaceId, Name FROM FolderTable")); while (m_query.next()) { copyQuery->prepare(QLatin1String("INSERT INTO FolderTable VALUES(NULL, ?, ?)")); copyQuery->bindValue(0, m_query.value(0).toString()); copyQuery->bindValue(1, m_query.value(1).toString()); copyQuery->exec(); } m_query.exec(QLatin1String("SELECT Name FROM FilterAttributeTable")); while (m_query.next()) { copyQuery->prepare(QLatin1String("INSERT INTO FilterAttributeTable VALUES(NULL, ?)")); copyQuery->bindValue(0, m_query.value(0).toString()); copyQuery->exec(); } m_query.exec(QLatin1String("SELECT Name FROM FilterNameTable")); while (m_query.next()) { copyQuery->prepare(QLatin1String("INSERT INTO FilterNameTable VALUES(NULL, ?)")); copyQuery->bindValue(0, m_query.value(0).toString()); copyQuery->exec(); } m_query.exec(QLatin1String("SELECT NameId, FilterAttributeId FROM FilterTable")); while (m_query.next()) { copyQuery->prepare(QLatin1String("INSERT INTO FilterTable VALUES(?, ?)")); copyQuery->bindValue(0, m_query.value(0).toInt()); copyQuery->bindValue(1, m_query.value(1).toInt()); copyQuery->exec(); } m_query.exec(QLatin1String("SELECT Key, Value FROM SettingsTable")); while (m_query.next()) { if (m_query.value(0).toString() == QLatin1String("CluceneSearchNamespaces")) continue; copyQuery->prepare(QLatin1String("INSERT INTO SettingsTable VALUES(?, ?)")); copyQuery->bindValue(0, m_query.value(0).toString()); copyQuery->bindValue(1, m_query.value(1)); copyQuery->exec(); } copyQuery->clear(); delete copyQuery; QSqlDatabase::removeDatabase(connectionName); return true; }