QVariant FileModel::data(const QModelIndex &index, int role) const { if (!index.isValid() || index.row() > m_files.size()-1) return QVariant(); StatFileInfo info = m_files.at(index.row()); switch (role) { case Qt::DisplayRole: case FilenameRole: return info.fileName(); case FileKindRole: return info.kind(); case FileIconRole: return infoToIconName(info); case PermissionsRole: return permissionsToString(info.permissions()); case SizeRole: if (info.isSymLink() && info.isDirAtEnd()) return tr("dir-link"); if (info.isDir()) return tr("dir"); return filesizeToString(info.size()); case LastModifiedRole: return datetimeToString(info.lastModified()); case CreatedRole: return datetimeToString(info.created()); case IsDirRole: return info.isDirAtEnd(); case IsLinkRole: return info.isSymLink(); case SymLinkTargetRole: return info.symLinkTarget(); case IsSelectedRole: return info.isSelected(); default: return QVariant(); } }
QDateTime Database::replaceCacheRecordByServerRecord(const QSqlDatabase& dbCache, const QString& table, const QSqlQuery& queryMaster) { QDateTime updated; QSqlRecord record = queryMaster.record(); int fieldUpdated = record.indexOf("updated"); if (fieldUpdated == -1) { fieldUpdated = record.indexOf("created"); } Q_ASSERT(fieldUpdated > -1); updated = record.value(fieldUpdated).toDateTime(); int n = record.count(); if (n > 1) { QString sql = QString("REPLACE INTO %1 (").arg(table); bool first = true; for (int i = 0; i < n; i++) { if (first) first = false; else sql += ", "; sql += record.fieldName(i); } sql += ") VALUES ("; first = true; for (int i = 0; i < n; i++) { if (first) first = false; else sql += ", "; sql += "?"; } sql += ")"; QSqlQuery queryCache(dbCache); queryCache.setForwardOnly(true); queryCache.prepare(sql); for (int i = 0; i < n; i++) { QVariant v(record.value(i)); if (v.type() == QVariant::DateTime) queryCache.bindValue(i, datetimeToString(v.toDateTime())); else queryCache.bindValue(i, v); } if (!queryCache.exec()) throw DatabaseException(queryCache); } return updated; }
void QXmppEntityTimeIq::toXmlElementFromChild(QXmlStreamWriter *writer) const { writer->writeStartElement("time"); writer->writeAttribute("xmlns", ns_entity_time); if(m_utc.isValid()) { helperToXmlAddTextElement(writer, "tzo", timezoneOffsetToString(m_tzo)); helperToXmlAddTextElement(writer, "utc", datetimeToString(m_utc)); } writer->writeEndElement(); }
void Database::setUpdateTimestampForTable(const QSqlDatabase& dbCache, const QString& table, const QUuid* userId, const QDateTime& ts) { QSqlQuery query(dbCache); query.setForwardOnly(true); if (userId) { query.prepare("REPLACE INTO update_timestamp (ts, table_name, user_id) VALUES (?, ?, ?)"); query.bindValue(0, datetimeToString(ts)); query.bindValue(1, table); query.bindValue(2, Database::UuidToString(*userId)); } else { query.prepare("REPLACE INTO update_timestamp (ts, table_name, user_id) VALUES (?, ?, NULL)"); query.bindValue(0, datetimeToString(ts)); query.bindValue(1, table); } if (!query.exec()) throw DatabaseException(query); }
WPXString libvisio::VSDNumericField::getString(const std::map<unsigned, WPXString> &) { if (m_format == 0xffff) return WPXString(); switch (m_format) { case VSD_FIELD_FORMAT_DateMDYY: case VSD_FIELD_FORMAT_DateMMDDYY: case VSD_FIELD_FORMAT_DateMmmDYYYY: case VSD_FIELD_FORMAT_DateMmmmDYYYY: case VSD_FIELD_FORMAT_DateDMYY: case VSD_FIELD_FORMAT_DateDDMMYY: case VSD_FIELD_FORMAT_DateDMMMYYYY: case VSD_FIELD_FORMAT_DateDMMMMYYYY: case VSD_FIELD_FORMAT_Dateyyyymd: case VSD_FIELD_FORMAT_Dateyymmdd: case VSD_FIELD_FORMAT_DateTWNfYYYYMMDDD_C: case VSD_FIELD_FORMAT_DateTWNsYYYYMMDDD_C: case VSD_FIELD_FORMAT_DateTWNfyyyymmddww_C: case VSD_FIELD_FORMAT_DateTWNfyyyymmdd_C: case VSD_FIELD_FORMAT_Dategggemdww_J: case VSD_FIELD_FORMAT_Dateyyyymdww_J: case VSD_FIELD_FORMAT_Dategggemd_J: case VSD_FIELD_FORMAT_Dateyyyymd_J: case VSD_FIELD_FORMAT_DateYYYYMMMDDDWWW_C: case VSD_FIELD_FORMAT_DateYYYYMMMDDD_C: case VSD_FIELD_FORMAT_DategeMMMMddddww_K: case VSD_FIELD_FORMAT_Dateyyyymdww_K: case VSD_FIELD_FORMAT_DategeMMMMddd_K: case VSD_FIELD_FORMAT_Dateyyyymd_K: case VSD_FIELD_FORMAT_Dateyyyy_m_d: case VSD_FIELD_FORMAT_Dateyy_mm_dd: case VSD_FIELD_FORMAT_Dateyyyymd_S: case VSD_FIELD_FORMAT_Dateyyyymmdd_S: case VSD_FIELD_FORMAT_Datewwyyyymmdd_S: case VSD_FIELD_FORMAT_Datewwyyyymd_S: case VSD_FIELD_FORMAT_MsoDateShort: case VSD_FIELD_FORMAT_MsoDateLongDay: case VSD_FIELD_FORMAT_MsoDateLong: case VSD_FIELD_FORMAT_MsoDateShortAlt: case VSD_FIELD_FORMAT_MsoDateISO: case VSD_FIELD_FORMAT_MsoDateShortMon: case VSD_FIELD_FORMAT_MsoDateShortSlash: case VSD_FIELD_FORMAT_MsoDateShortAbb: case VSD_FIELD_FORMAT_MsoDateEnglish: case VSD_FIELD_FORMAT_MsoDateMonthYr: case VSD_FIELD_FORMAT_MsoDateMon_Yr: return datetimeToString("%x", m_number); case VSD_FIELD_FORMAT_TimeGen: case VSD_FIELD_FORMAT_TimeHMM: case VSD_FIELD_FORMAT_TimeHHMM: case VSD_FIELD_FORMAT_TimeHMM24: case VSD_FIELD_FORMAT_TimeHHMM24: case VSD_FIELD_FORMAT_TimeHMMAMPM: case VSD_FIELD_FORMAT_TimeHHMMAMPM: case VSD_FIELD_FORMAT_TimeAMPMhmm_J: case VSD_FIELD_FORMAT_TimeAMPMhmm_C: case VSD_FIELD_FORMAT_TimeAMPMhmm_K: case VSD_FIELD_FORMAT_TimeAMPM_hmm_J: case VSD_FIELD_FORMAT_Timehmm_J: case VSD_FIELD_FORMAT_TimeAMPM_hmm_C: case VSD_FIELD_FORMAT_Timehmm_C: case VSD_FIELD_FORMAT_TimeAMPM_hmm_K: case VSD_FIELD_FORMAT_Timehmm_K: case VSD_FIELD_FORMAT_TimeHMMAMPM_E: case VSD_FIELD_FORMAT_TimeHHMMAMPM_E: case VSD_FIELD_FORMAT_TimeAMPMhmm_S: case VSD_FIELD_FORMAT_TimeAMPMhhmm_S: case VSD_FIELD_FORMAT_MsoTimePM: case VSD_FIELD_FORMAT_MsoTimeSecPM: case VSD_FIELD_FORMAT_MsoTime24: case VSD_FIELD_FORMAT_MsoTimeSec24: return datetimeToString("%X", m_number); case VSD_FIELD_FORMAT_MsoTimeDatePM: case VSD_FIELD_FORMAT_MsoTimeDateSecPM: return datetimeToString("%x %X", m_number); default: { WPXString result; WPXProperty *pProp = WPXPropertyFactory::newDoubleProp(m_number); if (pProp) { result = pProp->getStr(); delete pProp; } return result; } } }
QString FileInfo::created() const { return datetimeToString(m_fileInfo.created()); }
QString FileInfo::modified() const { return datetimeToString(m_fileInfo.lastModified()); }
void Database::createOrUpdateCacheTableFromServer(const QSqlDatabase& dbMaster, const QSqlDatabase& dbCache, const QString& field, const QString& table, const QUuid* userId) { try { QDateTime ts = getUpdateTimestampForTable(dbCache, table, userId); QSqlQuery queryMaster(dbMaster); queryMaster.setForwardOnly(true); queryMaster.prepare("SELECT * FROM " + table + " WHERE " + field + " > ? ORDER BY " + field); queryMaster.bindValue(0, datetimeToString(ts)); if (!queryMaster.exec()) throw DatabaseException(queryMaster); while (queryMaster.next()) { QDateTime updated = Database::replaceCacheRecordByServerRecord(dbCache, table, queryMaster); if (ts < updated) ts = updated; if (table == "genresult") { GenResultDAO* genResultDAO = GenResultDAO::getInstance(); Q_ASSERT(genResultDAO); QSqlRecord record = queryMaster.record(); GenResult genResult(record); if (genResult.getParentId().isNull()) { QUuid id(genResult.getId()); PackagesDAO* packagesDAO = PackagesDAO::getInstance(); Q_ASSERT(packagesDAO); QObject parent; FPackage* projectDoc = packagesDAO->getPackage(genResult.getPackageHash(), &parent); SeDocument* document = projectDoc->getDocument(genResult.getResultId()); if (document) { QStandardItem root; genResultDAO->loadItemModel(id, document, &root); GenIndexDAO* genIndexDAO = GenIndexDAO::getInstance(); Q_ASSERT(genIndexDAO); genIndexDAO->saveItemModel(id, &root); } SeDocument* journal = projectDoc->getJournal(genResult.getResultId()); if (journal) { QStandardItem root; genResultDAO->loadItemModel(id, journal, &root); GenIndexDAO* genIndexDAO = GenIndexDAO::getInstance(); Q_ASSERT(genIndexDAO); genIndexDAO->saveItemModel(id, &root); } SeDocument*report = projectDoc->getReport(genResult.getResultId()); if (report) { QStandardItem root; genResultDAO->loadItemModel(id, report, &root); GenIndexDAO* genIndexDAO = GenIndexDAO::getInstance(); Q_ASSERT(genIndexDAO); genIndexDAO->saveItemModel(id, &root); } SeDocument* advsearch = projectDoc->getAdvSearch(genResult.getResultId()); if (advsearch) { QStandardItem root; genResultDAO->loadItemModel(id, advsearch, &root); GenIndexDAO* genIndexDAO = GenIndexDAO::getInstance(); Q_ASSERT(genIndexDAO); genIndexDAO->saveItemModel(id, &root); } } } } setUpdateTimestampForTable(dbCache, table, userId, ts); } catch (DatabaseException dbException) { dbException.displayMessage(); } }