void Job::onUserQuery(Query *query) { if (archiveInterface()->waitForFinishedSignal()) { qCWarning(ARK) << "Plugins run from the main thread should call directly query->execute()"; } emit userQuery(query); }
void CPlayerList::userDetected(QString userId) { QSqlQuery userQuery("SELECT * FROM hr_user WHERE id="+userId); QString name = ""; QString firstName = ""; QString time = QTime::currentTime().toString(Qt::ISODate); QString date = QDate::currentDate().toString("d.M.yyyy"); QString day = QDate::currentDate().toString("dddd"); if(userQuery.next()) { QString name = userQuery.value(1).toString(); QString firstName = userQuery.value(2).toString(); QSqlQuery messageQuery("SELECT * FROM hr_horux_media_message WHERE type='ALL' OR id_user="******" ORDER BY ID"); QString message = ""; while(messageQuery.next()) { if(messageQuery.value(2).toString().toLatin1() != "") { message += messageQuery.value(2).toString().toLatin1(); message.replace(QString("{day}"), day); message.replace(QString("{date}"), date); message.replace(QString("{time}"), time); message.replace(QString("{name}"), name); message.replace(QString("{firstName}"), firstName); message += "\n\n"; } } if(message != "") splash->setText(message); } else { QSqlQuery messageQuery("SELECT * FROM hr_horux_media_message WHERE type='UNKNOWN'"); if(messageQuery.next()) { QString message = messageQuery.value(2).toString().toLatin1(); message.replace(QString("{day}"), day); message.replace(QString("{time}"), time); message.replace(QString("{date}"), date); splash->setText(message); } } }
void RecipeWidget::on_searchButton_clicked() { //tokenize and flattern search query QString userQuery(this->ui->searchLine->text()); if(userQuery.isEmpty()){ return; } QStringList rawTokens = userQuery.split(" "); QStringList tokens; for(int j=0;j<rawTokens.size();j++){ tokens << rawTokens.at(j).toLower(); } //get all recipes QSqlQuery query; if(!query.exec("SELECT id,name FROM Recipe")){ qDebug()<<"Failed to retrieve recipes"; return; } int j=0; bool found=false; ui->listWidget->clear(); while(query.next()){ QString name = query.value(1).toString(); name = name.toLower(); qDebug()<<name; for(int i=0;i<tokens.size();i++){ if(name.contains(tokens.at(i))) found=true; } if(found){ found=false; QListWidgetItem* item = new QListWidgetItem(query.value(1).toString()); item->setData(Qt::UserRole,query.value(0).toInt()); ui->listWidget->insertItem(j++,item); } } if(j==0){ QMessageBox message(this); message.setWindowTitle("No se encontraron recetas"); message.setText("No se encontraron recetas que coincidan con su busqueda, intenta usar palabras mas generales y revisar la ortografia de las palabras"); message.setStandardButtons(QMessageBox::Ok); message.exec(); } }
QString LibSingleFileInterface::overwriteFileName(QString& filename) { QString newFileName(filename); while (QFile::exists(newFileName)) { Kerfuffle::OverwriteQuery query(newFileName); query.setMultiMode(false); emit userQuery(&query); query.waitForResponse(); if ((query.responseCancelled()) || (query.responseSkip())) { return QString(); } else if (query.responseOverwrite()) { break; } else if (query.responseRename()) { newFileName = query.newFilename(); } } return newFileName; }
void CGantnerTime::reloadAllData() { //Reload all user QSqlQuery userQuery("SELECT id, CONCAT(name, ' ', firstname) AS fullname, language FROM hr_user"); while(userQuery.next()) { QSqlQuery groupAttributionQuery; groupAttributionQuery.prepare("SELECT pg.id, pg.name, pg.comment FROM hr_user_group AS pg LEFT JOIN hr_user_group_attribution AS ga ON ga.id_group=pg.id LEFT JOIN hr_user AS pe ON pe.id=ga.id_user WHERE pe.id=:id"); groupAttributionQuery.bindValue(":id", userQuery.value(0)); groupAttributionQuery.exec(); while( groupAttributionQuery.next()) { QString groupId = groupAttributionQuery.value(0).toString(); QSqlQuery deviceQuery; deviceQuery.prepare("SELECT uga.id_device FROM hr_user_group_access AS uga LEFT JOIN hr_device AS d ON d.id = uga.id_device WHERE id_group=:id AND d.type='gantner_TimeTerminal'"); deviceQuery.bindValue(":id", groupId); deviceQuery.exec(); while( deviceQuery.next()) { QString deviceId = deviceQuery.value(0).toString(); QSqlQuery insertQuery; insertQuery.prepare("INSERT INTO hr_gantner_standalone_action (`type`, `func`, `userId`,`keyId`, `deviceId`, `param`, `param2`, `param3`) VALUES (:type,:func,:userId,:keyId,:deviceId, :param, :param2, :param3)"); insertQuery.bindValue(":func", "add"); insertQuery.bindValue(":type", "user"); insertQuery.bindValue(":userId", userQuery.value(0) ); insertQuery.bindValue(":keyId", 0 ); insertQuery.bindValue(":deviceId", deviceId ); insertQuery.bindValue(":param", userQuery.value(1) ); insertQuery.bindValue(":param2",userQuery.value(2) ); //check the last booking to know if the user is present or absent QSqlQuery checkLastBooking; checkLastBooking.prepare("SELECT * FROM hr_tracking AS t LEFT JOIN hr_timux_booking AS tb ON t.id=tb.tracking_id WHERE t.id_user=:userId ORDER BY t.date DESC, t.time DESC, tb.action DESC LIMIT 0,1"); checkLastBooking.bindValue(":userId", userQuery.value(0) ); checkLastBooking.exec(); if(checkLastBooking.next()) { if(checkLastBooking.value(11).toInt() == 255 || checkLastBooking.value(11).toInt() == 155 || checkLastBooking.value(12).toString().right(3) == "_IN" ) { insertQuery.bindValue(":param3",1 ); } else { insertQuery.bindValue(":param3",2 ); } } else { //no booking, the user is absent insertQuery.bindValue(":param3",2 ); } insertQuery.exec(); QSqlQuery keyQuery; keyQuery.prepare("SELECT k.id, serialNumber FROM hr_keys_attribution AS ka LEFT JOIN hr_keys AS k ON k.id=ka.id_key WHERE id_user=:id AND k.isBlocked=0"); keyQuery.bindValue(":id", userQuery.value(0) ); keyQuery.exec(); while(keyQuery.next()) { QSqlQuery insertQuery; insertQuery.prepare("INSERT INTO hr_gantner_standalone_action (`type`, `func`, `userId`,`keyId`, `deviceId`, `param`, `param2`) VALUES (:type,:func,:userId,:keyId,:deviceId, :param, :param2)"); insertQuery.bindValue(":func", "add"); insertQuery.bindValue(":type", "key"); insertQuery.bindValue(":userId", userQuery.value(0) ); insertQuery.bindValue(":keyId", keyQuery.value(0) ); insertQuery.bindValue(":deviceId", deviceId ); insertQuery.bindValue(":param", keyQuery.value(1) ); insertQuery.bindValue(":param2", "" ); insertQuery.exec(); } } } } // Reload all absent reason QSqlQuery deviceQuery("SELECT id_device FROM hr_gantner_TimeTerminal"); while( deviceQuery.next()) { QSqlQuery timeCodeInQuery("SELECT * FROM hr_timux_timecode WHERE signtype='both' OR signtype='in'"); while( timeCodeInQuery.next()) { QSqlQuery insertQuery; insertQuery.prepare("INSERT INTO hr_gantner_standalone_action (`type`, `func`, `userId`,`keyId`, `deviceId`, `param`, `param2`,`reasonId`) VALUES (:type,:func,:userId,:keyId,:deviceId, :param, :param2,:reasonId)"); insertQuery.bindValue(":func", "add"); insertQuery.bindValue(":type", "reason"); insertQuery.bindValue(":userId", 0 ); insertQuery.bindValue(":keyId", 0 ); insertQuery.bindValue(":deviceId", deviceQuery.value(0) ); insertQuery.bindValue(":param", timeCodeInQuery.value(13).toString() ); insertQuery.bindValue(":param2", "1" ); insertQuery.bindValue(":reasonId", timeCodeInQuery.value(0).toString() + "_IN" ); insertQuery.exec(); } QSqlQuery timeCodeOutQuery("SELECT * FROM hr_timux_timecode WHERE signtype='both' OR signtype='out'"); while( timeCodeOutQuery.next()) { QSqlQuery insertQuery; insertQuery.prepare("INSERT INTO hr_gantner_standalone_action (`type`, `func`, `userId`,`keyId`, `deviceId`, `param`, `param2`,`reasonId`) VALUES (:type,:func,:userId,:keyId,:deviceId, :param, :param2,:reasonId)"); insertQuery.bindValue(":func", "add"); insertQuery.bindValue(":type", "reason"); insertQuery.bindValue(":userId", 0 ); insertQuery.bindValue(":keyId", 0 ); insertQuery.bindValue(":deviceId", deviceQuery.value(0) ); insertQuery.bindValue(":param", timeCodeOutQuery.value(13).toString() ); insertQuery.bindValue(":param2", "2" ); insertQuery.bindValue(":reasonId", timeCodeOutQuery.value(0).toString() + "_OUT" ); insertQuery.exec(); } //Reload balances text QSqlQuery balancesTextQuery("SELECT * FROM hr_timux_timecode WHERE (type='overtime' OR type='leave') AND (defaultHoliday=1 OR defaultOvertime=1) ORDER BY type"); int fieldNo = 0; while( balancesTextQuery.next()) { QSqlQuery insertQuery; insertQuery.prepare("INSERT INTO hr_gantner_standalone_action (`type`, `func`, `userId`,`keyId`, `deviceId`, `param`, `param2`) VALUES (:type,:func,:userId,:keyId,:deviceId, :param, :param2)"); insertQuery.bindValue(":func", "add"); insertQuery.bindValue(":type", "balancesText"); insertQuery.bindValue(":userId", 0 ); insertQuery.bindValue(":keyId", 0 ); insertQuery.bindValue(":deviceId", deviceQuery.value(0) ); insertQuery.bindValue(":param",fieldNo ); insertQuery.bindValue(":param2",balancesTextQuery.value(13).toString() ); insertQuery.exec(); fieldNo++; } for(int i=fieldNo; i<10; i++) { QSqlQuery insertQuery; insertQuery.prepare("INSERT INTO hr_gantner_standalone_action (`type`, `func`, `userId`,`keyId`, `deviceId`, `param`, `param2`) VALUES (:type,:func,:userId,:keyId,:deviceId, :param, :param2)"); insertQuery.bindValue(":func", "add"); insertQuery.bindValue(":type", "balancesText"); insertQuery.bindValue(":userId", 0 ); insertQuery.bindValue(":keyId", 0 ); insertQuery.bindValue(":deviceId", deviceQuery.value(0) ); insertQuery.bindValue(":param",i ); insertQuery.bindValue(":param2",""); insertQuery.exec(); } //Reload user balances checkBalances(); // Remove all the load time code for(int i=1; i<=20; i++ ) { QSqlQuery insertQuery; insertQuery.prepare("INSERT INTO hr_gantner_standalone_action (`type`, `func`, `userId`,`keyId`, `deviceId`, `param`) VALUES (:type,:func,:userId,:keyId,:deviceId, :param)"); insertQuery.bindValue(":func", "sub"); insertQuery.bindValue(":type", "load"); insertQuery.bindValue(":userId", 0 ); insertQuery.bindValue(":keyId", 0 ); insertQuery.bindValue(":deviceId", deviceQuery.value(0) ); insertQuery.bindValue(":param",i ); insertQuery.exec(); } //Reload the load time code QSqlQuery loadQuery("SELECT * FROM hr_timux_timecode WHERE type='load' ORDER BY name"); while( loadQuery.next()) { QSqlQuery insertQuery; insertQuery.prepare("INSERT INTO hr_gantner_standalone_action (`type`, `func`, `userId`,`keyId`, `deviceId`, `param`, `param2`, `param3`) VALUES (:type,:func,:userId,:keyId,:deviceId, :param, :param2, :param3)"); insertQuery.bindValue(":type", "load"); insertQuery.bindValue(":func", "add"); insertQuery.bindValue(":userId", 0 ); insertQuery.bindValue(":keyId", 0 ); insertQuery.bindValue(":deviceId", deviceQuery.value(0) ); insertQuery.bindValue(":param",loadQuery.value(15).toString() ); insertQuery.bindValue(":param2",loadQuery.value(2).toString()); insertQuery.bindValue(":param3",loadQuery.value(13).toString()); insertQuery.exec(); } } }
bool LibArchiveInterface::copyFiles(const QVariantList& files, const QString& destinationDirectory, ExtractionOptions options) { kDebug() << "Changing current directory to " << destinationDirectory; QDir::setCurrent(destinationDirectory); const bool extractAll = files.isEmpty(); const bool preservePaths = options.value(QLatin1String( "PreservePaths" )).toBool(); QString rootNode = options.value(QLatin1String("RootNode"), QVariant()).toString(); if ((!rootNode.isEmpty()) && (!rootNode.endsWith(QLatin1Char('/')))) { rootNode.append(QLatin1Char('/')); } ArchiveRead arch(archive_read_new()); if (!(arch.data())) { return false; } if (archive_read_support_compression_all(arch.data()) != ARCHIVE_OK) { return false; } if (archive_read_support_format_all(arch.data()) != ARCHIVE_OK) { return false; } if (archive_read_open_filename(arch.data(), QFile::encodeName(filename()), 10240) != ARCHIVE_OK) { emit error(i18nc("@info", "Could not open the archive <filename>%1</filename>, libarchive cannot handle it.", filename())); return false; } ArchiveWrite writer(archive_write_disk_new()); if (!(writer.data())) { return false; } archive_write_disk_set_options(writer.data(), extractionFlags()); int entryNr = 0; int totalCount = 0; if (extractAll) { if (!m_cachedArchiveEntryCount) { emit progress(0); //TODO: once information progress has been implemented, send //feedback here that the archive is being read kDebug() << "For getting progress information, the archive will be listed once"; m_emitNoEntries = true; list(); m_emitNoEntries = false; } totalCount = m_cachedArchiveEntryCount; } else { totalCount = files.size(); } m_currentExtractedFilesSize = 0; bool overwriteAll = false; // Whether to overwrite all files bool skipAll = false; // Whether to skip all files struct archive_entry *entry; QString fileBeingRenamed; while (archive_read_next_header(arch.data(), &entry) == ARCHIVE_OK) { fileBeingRenamed.clear(); // retry with renamed entry, fire an overwrite query again // if the new entry also exists retry: const bool entryIsDir = S_ISDIR(archive_entry_mode(entry)); //we skip directories if not preserving paths if (!preservePaths && entryIsDir) { archive_read_data_skip(arch.data()); continue; } //entryName is the name inside the archive, full path QString entryName = QDir::fromNativeSeparators(QFile::decodeName(archive_entry_pathname(entry))); if (entryName.startsWith(QLatin1Char( '/' ))) { //for now we just can't handle absolute filenames in a tar archive. //TODO: find out what to do here!! emit error(i18n("This archive contains archive entries with absolute paths, which are not yet supported by ark.")); return false; } if (files.contains(entryName) || entryName == fileBeingRenamed || extractAll) { // entryFI is the fileinfo pointing to where the file will be // written from the archive QFileInfo entryFI(entryName); //kDebug() << "setting path to " << archive_entry_pathname( entry ); const QString fileWithoutPath(entryFI.fileName()); //if we DON'T preserve paths, we cut the path and set the entryFI //fileinfo to the one without the path if (!preservePaths) { //empty filenames (ie dirs) should have been skipped already, //so asserting Q_ASSERT(!fileWithoutPath.isEmpty()); archive_entry_copy_pathname(entry, QFile::encodeName(fileWithoutPath).constData()); entryFI = QFileInfo(fileWithoutPath); //OR, if the commonBase has been set, then we remove this //common base from the filename } else if (!rootNode.isEmpty()) { kDebug() << "Removing" << rootNode << "from" << entryName; const QString truncatedFilename(entryName.remove(0, rootNode.size())); archive_entry_copy_pathname(entry, QFile::encodeName(truncatedFilename).constData()); entryFI = QFileInfo(truncatedFilename); } //now check if the file about to be written already exists if (!entryIsDir && entryFI.exists()) { if (skipAll) { archive_read_data_skip(arch.data()); archive_entry_clear(entry); continue; } else if (!overwriteAll && !skipAll) { Kerfuffle::OverwriteQuery query(entryName); emit userQuery(&query); query.waitForResponse(); if (query.responseCancelled()) { archive_read_data_skip(arch.data()); archive_entry_clear(entry); break; } else if (query.responseSkip()) { archive_read_data_skip(arch.data()); archive_entry_clear(entry); continue; } else if (query.responseAutoSkip()) { archive_read_data_skip(arch.data()); archive_entry_clear(entry); skipAll = true; continue; } else if (query.responseRename()) { const QString newName(query.newFilename()); fileBeingRenamed = newName; archive_entry_copy_pathname(entry, QFile::encodeName(newName).constData()); goto retry; } else if (query.responseOverwriteAll()) { overwriteAll = true; } } } //if there is an already existing directory: if (entryIsDir && entryFI.exists()) { if (entryFI.isWritable()) { kDebug(1601) << "Warning, existing, but writable dir"; } else { kDebug(1601) << "Warning, existing, but non-writable dir. skipping"; archive_entry_clear(entry); archive_read_data_skip(arch.data()); continue; } } int header_response; kDebug() << "Writing " << fileWithoutPath << " to " << archive_entry_pathname(entry); if ((header_response = archive_write_header(writer.data(), entry)) == ARCHIVE_OK) { //if the whole archive is extracted and the total filesize is //available, we use partial progress copyData(arch.data(), writer.data(), (extractAll && m_extractedFilesSize)); } else if (header_response == ARCHIVE_WARN) { kDebug() << "Warning while writing " << entryName; } else { kDebug() << "Writing header failed with error code " << header_response << "While attempting to write " << entryName; } //if we only partially extract the archive and the number of //archive entries is available we use a simple progress based on //number of items extracted if (!extractAll && m_cachedArchiveEntryCount) { ++entryNr; emit progress(float(entryNr) / totalCount); } archive_entry_clear(entry); } else { archive_read_data_skip(arch.data()); } } return archive_read_close(arch.data()) == ARCHIVE_OK; }