void run() { QString setting = Settings.playlistThumbnails(); if (setting == "hidden") return; QImage image = DB.getThumbnail(cacheKey(m_in)); if (image.isNull()) { image = makeThumbnail(m_in); m_producer.set(kThumbnailInProperty, new QImage(image), 0, (mlt_destructor) deleteQImage, NULL); DB.putThumbnail(cacheKey(m_in), image); } else { m_producer.set(kThumbnailInProperty, new QImage(image), 0, (mlt_destructor) deleteQImage, NULL); } m_model->showThumbnail(m_row); if (setting == "tall" || setting == "wide") { image = DB.getThumbnail(cacheKey(m_out)); if (image.isNull()) { image = makeThumbnail(m_out); m_producer.set(kThumbnailOutProperty, new QImage(image), 0, (mlt_destructor) deleteQImage, NULL); DB.putThumbnail(cacheKey(m_out), image); } else { m_producer.set(kThumbnailOutProperty, new QImage(image), 0, (mlt_destructor) deleteQImage, NULL); } m_model->showThumbnail(m_row); } }
QImage NemoThumbnailProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) { setupCache(); // needed for stupid things like gallery model, which pass us a url if (id.startsWith("file://")) { // qWarning() << Q_FUNC_INFO << "Removing file:// prefix, before: " << id; QString &nid = const_cast<QString &>(id); nid = nid.remove(0, 7); } TDEBUG() << Q_FUNC_INFO << "Requested image: " << id << " with size " << requestedSize; // sourceSize should indicate what size thumbnail you want. i.e. if you want a 120x120px thumbnail, // set sourceSize: Qt.size(120, 120). if (!requestedSize.isValid()) qFatal("You must request a sourceSize whenever you use nemoThumbnail"); if (size) *size = requestedSize; QByteArray hashData = cacheKey(id, requestedSize); QImage img = attemptCachedServe(id, hashData); if (!img.isNull()) { TDEBUG() << Q_FUNC_INFO << "Read " << id << " from cache"; return img; } return generateThumbnail(id, hashData, requestedSize); }
QImage ThumbnailProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) { QImage result; // id is mlt_service/resource#frameNumber int index = id.lastIndexOf('#'); if (index != -1) { QString service = id.section('/', 0, 0); QString resource = id.section('/', 1); int frameNumber = id.mid(index + 1).toInt(); if (service == "avformat-novalidate") service = "avformat"; else if (service.startsWith("xml")) service = "xml-nogl"; resource = resource.left(resource.lastIndexOf('#')); Mlt::Producer producer(MLT.profile(), service.toUtf8().constData(), resource.toUtf8().constData()); if (producer.is_valid()) { QString key = cacheKey(producer, frameNumber); result = DB.getThumbnail(key); if (result.isNull()) { result = makeThumbnail(producer, frameNumber, requestedSize); DB.putThumbnail(key, result); } if (size) *size = result.size(); } } return result; }
void ImageRegistry::putInCache( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode, float opacity, const QPixmap& pixmap, QColor tint ) { tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Adding to image cache:" << image << size << mode; QHash< qint64, QPixmap > subsubcache; QHash< int, QHash< qint64, QPixmap > > subcache; if ( s_cache.contains( image ) ) { subcache = s_cache.value( image ); if ( subcache.contains( mode ) ) { subsubcache = subcache.value( mode ); /* if ( subsubcache.contains( size.width() * size.height() ) ) { Q_ASSERT( false ); }*/ } } subsubcache.insert( cacheKey( size, opacity, tint ), pixmap ); subcache.insert( mode, subsubcache ); s_cache.insert( image, subcache ); }
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QtQuick2ApplicationViewer viewer; viewer.setMainQmlFile(QStringLiteral("qml/testCacheName/main.qml")); viewer.showExpanded(); QSize requestSize; requestSize.setHeight(200); requestSize.setWidth(200); qDebug() << "++++aaaaaaaa" << cacheKey("/home/mengcong/Pictures/1.jpg", requestSize); qDebug() << "++++bbbbbbbb" << cacheKey("/home/mengcong/Pictures/1.jpg", requestSize); return app.exec(); }
bool DBClientWithCommands::ensureIndex( const string &ns , BSONObj keys , bool unique, const string & name ) { BSONObjBuilder toSave; toSave.append( "ns" , ns ); toSave.append( "key" , keys ); string cacheKey(ns); cacheKey += "--"; if ( name != "" ) { toSave.append( "name" , name ); cacheKey += name; } else { string nn = genIndexName( keys ); toSave.append( "name" , nn ); cacheKey += nn; } if ( unique ) toSave.appendBool( "unique", unique ); if ( _seenIndexes.count( cacheKey ) ) return 0; _seenIndexes.insert( cacheKey ); insert( Namespace( ns.c_str() ).getSisterNS( "system.indexes" ).c_str() , toSave.obj() ); return 1; }
QString Option::fixString(QString string, uchar flags) { //const QString orig_string = string; static QHash<FixStringCacheKey, QString> *cache = 0; if(!cache) { cache = new QHash<FixStringCacheKey, QString>; qmakeAddCacheClear(qmakeDeleteCacheClear<QHash<FixStringCacheKey, QString> >, (void**)&cache); } FixStringCacheKey cacheKey(string, flags); QHash<FixStringCacheKey, QString>::const_iterator it = cache->constFind(cacheKey); if (it != cache->constEnd()) { //qDebug() << "Fix (cached) " << orig_string << "->" << it.value(); return it.value(); } //fix the environment variables if(flags & Option::FixEnvVars) { int rep; static QRegExp reg_var("\\$\\(.*\\)"); reg_var.setMinimal(true); while((rep = reg_var.indexIn(string)) != -1) string.replace(rep, reg_var.matchedLength(), QString::fromLocal8Bit(qgetenv(string.mid(rep + 2, reg_var.matchedLength() - 3).toLatin1().constData()).constData())); } //canonicalize it (and treat as a path) if(flags & Option::FixPathCanonicalize) { #if 0 string = QFileInfo(string).canonicalFilePath(); #endif string = QDir::cleanPath(string); } if(string.length() > 2 && string[0].isLetter() && string[1] == QLatin1Char(':')) string[0] = string[0].toLower(); //fix separators Q_ASSERT(!((flags & Option::FixPathToLocalSeparators) && (flags & Option::FixPathToTargetSeparators))); if(flags & Option::FixPathToLocalSeparators) { #if defined(Q_OS_WIN32) string = string.replace('/', '\\'); #else string = string.replace('\\', '/'); #endif } else if(flags & Option::FixPathToTargetSeparators) { string = string.replace('/', Option::dir_sep).replace('\\', Option::dir_sep); } if ((string.startsWith("\"") && string.endsWith("\"")) || (string.startsWith("\'") && string.endsWith("\'"))) string = string.mid(1, string.length()-2); //cache //qDebug() << "Fix" << orig_string << "->" << string; cache->insert(cacheKey, string); return string; }
Datum ComponentRegistry::getValue(std::string expression, GenericDataType type) { std::pair<std::string, GenericDataType> cacheKey(expression, type); shared_ptr<Datum> test = data_cache[cacheKey]; if(test != NULL){ return *test; } double doubleValue; long longValue; bool boolValue; Datum value; try { switch(type){ case M_FLOAT: case M_INTEGER: case M_BOOLEAN: doubleValue = boost::lexical_cast<double>(expression); if (M_FLOAT == type) { value = Datum(doubleValue); } else if (M_INTEGER == type) { longValue = (long)doubleValue; if ((double)longValue != doubleValue) { throw NonFatalParserException("invalid integer literal", expression.c_str()); } value = Datum(longValue); } else { boolValue = (bool)doubleValue; if ((double)boolValue != doubleValue) { throw NonFatalParserException("invalid boolean literal", expression.c_str()); } value = Datum(boolValue); } break; case M_STRING: value = Datum(string(expression)); break; default: // No lexical_cast for other types break; } if (!value.isUndefined()) { data_cache[cacheKey] = shared_ptr<Datum>(new Datum(value)); return value; } } catch (NonFatalParserException& e){ // Until we work out how to effectively flag these issues, treat them as fatal errors throw FatalParserException(e.what()); } catch (boost::bad_lexical_cast& e){ // no biggie, we can do this the hard(er) way } return Datum(ParsedExpressionVariable::evaluateExpression(expression)); }
void OrganizerCalendarDatabaseAccess::getIdList(CCalendar* cal, int compType, int& calError, std::vector<std::string> &result) { OrganizerCalIdTypeIdCacheKey cacheKey(cal->getCalendarId(), compType); if (m_dbCache->containsIds(cacheKey)) { m_dbCache->takeIdsVector(cacheKey, result); } else { result = cal->getIdList(compType, calError); m_dbCache->insertIds(cacheKey, result); } }
CTodo* OrganizerCalendarDatabaseAccess::getTodo(CCalendar* cal, const std::string& id, int& calError) { OrganizerIdCacheKey cacheKey(cal->getCalendarId(), QString::fromStdString(id)); if (m_dbCache->containsTodo(cacheKey)) { return m_dbCache->takeTodo(cacheKey); } else { CTodo* todo = cal->getTodo(id, calError); m_dbCache->insertTodo(cacheKey, todo); return todo; } }
CJournal* OrganizerCalendarDatabaseAccess::getJournal(CCalendar* cal, const std::string& id, int& calError) { OrganizerIdCacheKey cacheKey(cal->getCalendarId(), QString::fromStdString(id)); if (m_dbCache->containsJournal(cacheKey)) { return m_dbCache->takeJournal(cacheKey); } else { CJournal* journal = cal->getJournal(id, calError); m_dbCache->insertJournal(cacheKey, journal); return journal; } }
CEvent* OrganizerCalendarDatabaseAccess::getEvent(CCalendar* cal, const std::string& id, int& calError) { OrganizerIdCacheKey cacheKey(cal->getCalendarId(), QString::fromStdString(id)); if (m_dbCache->containsEvent(cacheKey)) { return m_dbCache->takeEvent(cacheKey); } else { CEvent* event = cal->getEvent(id, calError); m_dbCache->insertEvent(cacheKey, event); return event; } }
bool DBClientBase::ensureIndex( const string &ns , BSONObj keys , bool unique, const string & name ) { BSONObjBuilder toSave; toSave.append( "ns" , ns ); toSave.append( "key" , keys ); string cacheKey(ns); cacheKey += "--"; if ( name != "" ) { toSave.append( "name" , name ); cacheKey += name; } else { stringstream ss; bool first = 1; for ( BSONObjIterator i(keys); i.more(); ) { BSONElement f = i.next(); if ( first ) first = 0; else ss << "_"; ss << f.fieldName() << "_"; if ( f.type() == NumberInt ) ss << (int)(f.number() ); else if ( f.type() == NumberDouble ) ss << f.number(); } toSave.append( "name" , ss.str() ); cacheKey += ss.str(); } if ( unique ) toSave.appendBool( "unique", unique ); if ( _seenIndexes.count( cacheKey ) ) return 0; _seenIndexes.insert( cacheKey ); insert( Namespace( ns.c_str() ).getSisterNS( "system.indexes" ).c_str() , toSave.obj() ); return 1; }
QPixmap AvatarPainter::getOrCreateCacheItem() { QString key = cacheKey(); QPixmap cached; if (QPixmapCache::find(key, &cached)) return cached; QPixmap item = QPixmap(AvatarRect.size()); item.fill(QColor(0, 0, 0, 0)); QPainter cachePainter; cachePainter.begin(&item); doPaint(&cachePainter, item.size()); cachePainter.end(); QPixmapCache::insert(key, item); return item; }
PassRefPtr<ShareableElementData> DocumentSharedObjectPool::cachedShareableElementDataWithAttributes(const Vector<Attribute>& attributes) { ASSERT(!attributes.isEmpty()); ShareableElementDataCacheKey cacheKey(attributes.data(), attributes.size()); unsigned cacheHash = cacheKey.hash(); ShareableElementDataCache::iterator cacheIterator = m_shareableElementDataCache.add(cacheHash, nullptr).iterator; if (cacheIterator->value && cacheIterator->value->key != cacheKey) cacheHash = 0; RefPtr<ShareableElementData> elementData; if (cacheHash && cacheIterator->value) elementData = cacheIterator->value->value; else elementData = ShareableElementData::createWithAttributes(attributes); if (!cacheHash || cacheIterator->value) return elementData.release(); cacheIterator->value = adoptPtr(new ShareableElementDataCacheEntry(ShareableElementDataCacheKey(elementData->immutableAttributeArray(), elementData->length()), elementData)); return elementData.release(); }
/*! adds \a offset using key \a key. \a itemType is the type of the structure, where offset points to. Only acceptable separator for key is '/'. doesn't check, if the item is already in the cache. */ bool HbSharedCache::add(ItemType itemType, const QString &key, int offset) { bool added = false; if (offset >= 0) { QString cacheKey(key); if (cacheKey.at(0) == ':') { //use only filename as a key. int index = cacheKey.lastIndexOf('/'); if (index >= 0) { cacheKey = cacheKey.right((cacheKey.size() - 1) - index); } } try { CacheItem cacheItem(cacheKey, offset); HbVector<CacheItem> &vector = itemCache(itemType); HbCacheLocker locker(*Semaphore); vector.append(cacheItem); added = true; } catch (std::exception &) { } } return added; }
std::vector<CEvent *> OrganizerCalendarDatabaseAccess::getEvents(int calId, std::string guid, int &pErrorCode) { std::vector<CEvent*> listEvent; OrganizerGuidCacheKey cacheKey(calId, E_EVENT, QString::fromStdString(guid)); if (m_dbCache->containsEventVector(cacheKey)) { // found in cache m_dbCache->takeEventVector(cacheKey, listEvent); return listEvent; } const int columnNumber = 49; CEvent *event = 0; CAlarm *pAlarm = 0; CRecurrence *pRec = 0; int iI_EventCount = 0; int iJ_EventCount = 0; pErrorCode = CALENDAR_OPERATION_SUCCESSFUL; std::vector<long> vCookie; std::vector<std::string> vERule; std::vector<std::string> vEdate; std::vector<std::string> vRdate; std::vector<std::string> vRRule; QSqlQuery pQuery; if (!pQuery.prepare(selectInnerJoinBatchGuid)) { pErrorCode = CALENDAR_DATABASE_ERROR; return listEvent; } pQuery.bindValue(":calId", QString::number(calId)); pQuery.bindValue(":compType", QString::number(E_EVENT)); pQuery.bindValue(":compUid", QString::fromStdString(guid)); bool ok = pQuery.exec(); sqliteErrorMapper(pQuery.lastError(), pErrorCode); if (!ok) return listEvent; while (pQuery.next()) { event = new CEvent(); pAlarm = new CAlarm(); pRec = new CRecurrence(); for (iJ_EventCount = 0; iJ_EventCount < columnNumber; ++iJ_EventCount) { switch(iJ_EventCount) { case 0: // ID1 event->setId(pQuery.value(iJ_EventCount).toString().toStdString()); break; case 1: break; case 2: // ID3 event->setType(pQuery.value(iJ_EventCount).toInt()); break; case 3: // ID4 event->setFlags(pQuery.value(iJ_EventCount).toInt()); break; case 4: // ID5 event->setDateStart(pQuery.value(iJ_EventCount).toInt()); break; case 5: // ID6 event->setDateEnd(pQuery.value(iJ_EventCount).toInt()); break; case 6: // ID7 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) event->setSummary(pQuery.value(iJ_EventCount).toString().toStdString()); break; case 7: // ID8 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) event->setLocation(pQuery.value(iJ_EventCount).toString().toStdString()); break; case 8: // ID9 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) event->setDescription(pQuery.value(iJ_EventCount).toString().toStdString()); break; case 9: // ID10 event->setStatus(pQuery.value(iJ_EventCount).toInt()); break; case 10: // ID11 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) event->setGUid(pQuery.value(iJ_EventCount).toString().toStdString()); break; case 11: // ID12 event->setUntil(pQuery.value(iJ_EventCount).toInt()); break; case 12: // ID13 event->setAllDay(pQuery.value(iJ_EventCount).toInt()); break; case 13: // ID14 event->setCreatedTime(pQuery.value(iJ_EventCount).toInt()); break; case 14: // ID15 event->setLastModified(pQuery.value(iJ_EventCount).toInt()); break; case 15: // ID16 event->setTzid(pQuery.value(iJ_EventCount).toString().toStdString()); break; case 16: // ID17 case 17: // ID18 case 18: // ID19 break; case 19: // ID20 if (pQuery.value(iJ_EventCount).toInt()) event->setClas(pQuery.value(iJ_EventCount).toString().toStdString()); break; case 20: // ID21 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) event->setGeo(pQuery.value(iJ_EventCount).toString().toStdString()); break; case 21: // ID22 event->setPriority(pQuery.value(iJ_EventCount).toInt()); break; case 22: // ID23 event->setDateStamp(pQuery.value(iJ_EventCount).toInt()); break; case 23: // ID24 event->setSequence(pQuery.value(iJ_EventCount).toInt()); break; case 24: // ID25 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) event->setTransparency(pQuery.value(iJ_EventCount).toString().toStdString()); break; case 25: // ID26 event->setUid(pQuery.value(iJ_EventCount).toInt()); break; case 26: // ID27 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) event->setUrl(pQuery.value(iJ_EventCount).toString().toStdString()); break; case 27: // ID28 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) { std::vector<std::string> vAtt; vAtt.push_back(pQuery.value(iJ_EventCount).toString().toStdString()); event->setAttachments(vAtt); } break; case 28: // ID29 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) event->setCategories(pQuery.value(iJ_EventCount).toString().toStdString()); break; case 29: // ID30 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) event->setComments(pQuery.value(iJ_EventCount).toString().toStdString()); break; case 30: // ID31 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) event->setContact(pQuery.value(iJ_EventCount).toString().toStdString()); break; case 31: // ID32 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) event->setRelated(pQuery.value(iJ_EventCount).toString().toStdString()); break; case 32: // ID33 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) event->setResources(pQuery.value(iJ_EventCount).toString().toStdString()); break; case 33: // ID34 case 34: // ID35 case 35: // ID36 break; case 36: // ID37 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) pAlarm->setTrigger(pQuery.value(iJ_EventCount).toInt()); break; case 37: // ID38 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) pAlarm->setRepeat(pQuery.value(iJ_EventCount).toInt()); break; case 38: // ID39 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) pAlarm->setDuration(pQuery.value(iJ_EventCount).toInt()); break; case 39: // ID40 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) pAlarm->setAction(pQuery.value(iJ_EventCount).toInt()); break; case 40: // ID41 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) { vCookie.push_back(pQuery.value(iJ_EventCount).toInt()); pAlarm->setCookie(vCookie); } break; case 41: // ID42 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) pAlarm->setAttach(pQuery.value(iJ_EventCount).toString().toStdString()); break; case 42: // ID43 break; case 43: // ID44 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) { vRRule = event->extractSubStrings(pQuery.value(iJ_EventCount).toString().toStdString(), EXCLAMATION); pRec->setRrule(vRRule); } break; case 44: // ID45 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) { vRdate = event->extractSubStrings(pQuery.value(iJ_EventCount).toString().toStdString(), SEMI_COLON); pRec->setRDays(vRdate); } break; case 45: // ID46 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) { vEdate = event->extractSubStrings(pQuery.value(iJ_EventCount).toString().toStdString(), SEMI_COLON); pRec->setEDays(vEdate); } break; case 46: // ID47 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) { vERule = event->extractSubStrings(pQuery.value(iJ_EventCount).toString().toStdString(), EXCLAMATION); pRec->setErule(vERule); } break; case 47: // ID48 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) pRec->setRecurId(pQuery.value(iJ_EventCount).toInt()); break; case 48: // ID49 if (!pQuery.value(iJ_EventCount).toString().isEmpty()) pRec->setRtype(pQuery.value(iJ_EventCount).toInt()); break; } } if ((event->getFlags() == HAS_RECURRENCE) || (event->getFlags() == HAS_RECURRENCE_ALARM)) { event->setRecurrence(pRec); } delete pRec; pRec = 0; if ((event->getFlags() == HAS_ALARM) || (event->getFlags() == HAS_RECURRENCE_ALARM)) { event->setAlarm(pAlarm); } delete pAlarm; pAlarm = 0; std::vector<CAttendee *> listAttendee; listAttendee = event->retrieveAttendeeDetails(); COrganizer *pOrg = 0; pOrg = event->retrieveOrganizerDetails(); if (listAttendee.size()) event->setAttendees(listAttendee); std::vector<CAttendee *>::iterator listAttendeeIterator; for (listAttendeeIterator = listAttendee.begin(); listAttendeeIterator != listAttendee.end(); ++listAttendeeIterator) delete *listAttendeeIterator; if (pOrg) { event->setOrganizer(pOrg); delete pOrg; pOrg = 0; } /*retrieve xprop */ std::vector<CProperties *> vPropList; vPropList = event->retrieveXPropertyDetails(); event->setXProperties(vPropList); std::vector<CProperties *>::iterator vPropListIterator; for (vPropListIterator = vPropList.begin(); vPropListIterator != vPropList.end(); ++vPropListIterator) delete *vPropListIterator; /*retrieve params */ std::map<std::string, std::vector<CParameters *> > paramMap; paramMap = event->retrieveParameterDetails(); event->setHashMap(paramMap); paramMap.clear(); /* push the event in to the list */ listEvent.push_back(event); ++iI_EventCount; } // put to cache m_dbCache->insertEventVector(cacheKey, listEvent); return listEvent; }
QImage FileThumbnailImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) { setupCache(); // needed for stupid things like gallery model, which pass us a url if (id.startsWith("file://")) { qWarning() << Q_FUNC_INFO << "Removing file:// prefix, before: " << id; QString &nid = const_cast<QString &>(id); nid = nid.remove(0, 7); } qDebug() << Q_FUNC_INFO << "Requested image: " << id << " with size " << requestedSize; // sourceSize should indicate what size thumbnail you want. i.e. if you want a 120x120px thumbnail, // set sourceSize: Qt.size(120, 120). if (!requestedSize.isValid()) qFatal("You must request a sourceSize whenever you use nemoThumbnail"); if (size) *size = requestedSize; QByteArray hashData = cacheKey(id, requestedSize); QImage img = attemptCachedServe(hashData); if (!img.isNull()) { qDebug() << Q_FUNC_INFO << "Read " << id << " from cache"; return img; } // cache couldn't satisfy us. // step 1: read source image in QImageReader ir(id); img = ir.read(); // don't pollute the cache with false positives if (img.isNull()) return QImage(); if (img.size() == requestedSize) return img; // step 2: scale to target size if (img.height() == img.width()) { // in the case of a squared image, there's no need to crop img = img.scaled(requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); } else if (img.height() >= requestedSize.height() && img.width() >= requestedSize.width()) { // if the image is larger than the desired size (on both dimensions) // then crop, and scale down if (img.width() < img.height()) { int cropPosition = (img.height() - img.width()) / 2; img = img.copy(0, cropPosition, img.width(), img.width()); img = img.scaledToWidth(requestedSize.width(), Qt::SmoothTransformation); } else { int cropPosition = (img.width() - img.height()) / 2; img = img.copy(cropPosition, 0, img.height(), img.height()); img = img.scaledToHeight(requestedSize.height(), Qt::SmoothTransformation); } } else if ((img.width() <= requestedSize.width() && img.height() >= requestedSize.height()) || (img.width() >= requestedSize.width() && img.height() <= requestedSize.height())) { // if the image is smaller than the desired size on one dimension, scale it up, // then crop down to thumbnail size. if (img.width() <= requestedSize.width() && img.height() >= requestedSize.height()) { img = img.scaledToWidth(requestedSize.width(), Qt::SmoothTransformation); int cropPosition = (img.height() - img.width()) / 2; img = img.copy(0, cropPosition, img.width(), img.width()); } else { img = img.scaledToHeight(requestedSize.height(), Qt::SmoothTransformation); int cropPosition = (img.width() - img.height()) / 2; img = img.copy(cropPosition, 0, img.height(), img.height()); } } else { // if the image is smaller on both dimensions, scale it up, and use the requested // size to do the cropping if (img.width() < img.height()) { img = img.scaledToWidth(requestedSize.width(), Qt::SmoothTransformation); int cropPosition = (img.height() - requestedSize.height()) / 2; img = img.copy(0, cropPosition, img.width(), img.width()); } else { img = img.scaledToHeight(requestedSize.height(), Qt::SmoothTransformation); int cropPosition = (img.width() - requestedSize.width()) / 2; img = img.copy(cropPosition, 0, img.height(), img.height()); } } // step 3: write to cache for next time writeCacheFile(hashData, img); qDebug() << Q_FUNC_INFO << "Wrote " << id << " to cache"; return img; }
QPixmap ImageRegistry::pixmap( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode, float opacity, QColor tint ) { if ( size.width() < 0 || size.height() < 0 ) { Q_ASSERT( false ); return QPixmap(); } QHash< qint64, QPixmap > subsubcache; QHash< int, QHash< qint64, QPixmap > > subcache; if ( s_cache.contains( image ) ) { subcache = s_cache.value( image ); if ( subcache.contains( mode ) ) { subsubcache = subcache.value( mode ); const qint64 ck = cacheKey( size, opacity, tint ); if ( subsubcache.contains( ck ) ) { return subsubcache.value( ck ); } } } // Image not found in cache. Let's load it. QPixmap pixmap; if ( image.toLower().endsWith( ".svg" ) ) { QSvgRenderer svgRenderer( image ); QPixmap p( size.isNull() || size.height() == 0 || size.width() == 0 ? svgRenderer.defaultSize() : size ); p.fill( Qt::transparent ); QPainter pixPainter( &p ); pixPainter.setOpacity( opacity ); svgRenderer.render( &pixPainter ); pixPainter.end(); if ( tint.alpha() > 0 ) p = TomahawkUtils::tinted( p, tint ); pixmap = p; } else pixmap = QPixmap( image ); if ( !pixmap.isNull() ) { switch ( mode ) { case TomahawkUtils::RoundedCorners: pixmap = TomahawkUtils::createRoundedImage( pixmap, size ); break; default: break; } if ( !size.isNull() && pixmap.size() != size ) { if ( size.width() == 0 ) { pixmap = pixmap.scaledToHeight( size.height(), Qt::SmoothTransformation ); } else if ( size.height() == 0 ) { pixmap = pixmap.scaledToWidth( size.width(), Qt::SmoothTransformation ); } else pixmap = pixmap.scaled( size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); } putInCache( image, size, mode, opacity, pixmap, tint ); } return pixmap; }
void NntpProcessor::SendSegment() { detail("[%i] Sending segment %s (%i=%lli:%i)", m_id, *m_filename, m_part, (long long)m_offset, m_size); if (m_speed > 0) { m_start = Util::GetCurrentTicks(); } BString<1024> fullFilename("%s/%s", m_dataDir, *m_filename); BString<1024> cacheFileDir("%s/%s", m_cacheDir, *m_filename); BString<1024> cacheFileName("%i=%lli-%i", m_part, (long long)m_offset, m_size); BString<1024> cacheFullFilename("%s/%s", *cacheFileDir, *cacheFileName); BString<1024> cacheKey("%s/%s", *m_filename, *cacheFileName); const char* cachedData = nullptr; int cachedSize; if (m_cache) { m_cache->Find(cacheKey, cachedData, cachedSize); } DiskFile cacheFile; bool readCache = !cachedData && m_cacheDir && cacheFile.Open(cacheFullFilename, DiskFile::omRead); bool writeCache = !cachedData && m_cacheDir && !readCache; StringBuilder cacheMem; if (m_cache && !cachedData) { cacheMem.Reserve((int)(m_size * 1.1)); } CString errmsg; if (writeCache && !FileSystem::ForceDirectories(cacheFileDir, errmsg)) { error("Could not create directory %s: %s", *cacheFileDir, *errmsg); } if (writeCache && !cacheFile.Open(cacheFullFilename, DiskFile::omWrite)) { error("Could not create file %s: %s", *cacheFullFilename, *FileSystem::GetLastErrorMessage()); } if (!cachedData && !readCache && !FileSystem::FileExists(fullFilename)) { m_connection->WriteLine(CString::FormatStr("430 Article not found\r\n")); return; } YEncoder encoder(fullFilename, m_part, m_offset, m_size, [proc = this, writeCache, &cacheFile, &cacheMem](const char* buf, int size) { if (proc->m_cache) { cacheMem.Append(buf); } if (writeCache) { cacheFile.Write(buf, size); } proc->SendData(buf, size); }); if (!cachedData && !readCache && !encoder.OpenFile(errmsg)) { m_connection->WriteLine(CString::FormatStr("403 %s\r\n", *errmsg)); return; } m_connection->WriteLine(CString::FormatStr("%i, 0 %s\r\n", m_sendHeaders ? 222 : 220, m_messageid)); if (m_sendHeaders) { m_connection->WriteLine(CString::FormatStr("Message-ID: %s\r\n", m_messageid)); m_connection->WriteLine(CString::FormatStr("Subject: \"%s\"\r\n", FileSystem::BaseFileName(m_filename))); m_connection->WriteLine("\r\n"); } if (cachedData) { SendData(cachedData, cachedSize); } else if (readCache) { cacheFile.Seek(0, DiskFile::soEnd); int size = (int)cacheFile.Position(); CharBuffer buf(size); cacheFile.Seek(0); if (cacheFile.Read((char*)buf, size) != size) { error("Could not read file %s: %s", *cacheFullFilename, *FileSystem::GetLastErrorMessage()); } if (m_cache) { cacheMem.Append(buf, size); } SendData(buf, size); } else { encoder.WriteSegment(); } if (!cachedData && cacheMem.Length() > 0) { m_cache->Append(cacheKey, cacheMem, cacheMem.Length()); } m_connection->WriteLine(".\r\n"); }
Maptarget Dispatcher::mapCompNext(const HttpRequest& request, Dispatcher::urlmap_type::size_type& pos) const { std::string vhost = request.getHost(); std::string compUrl = request.getUrl(); if (pos < _urlmap.size()) { // check cache cxxtools::ReadLock lock(_urlMapCacheMutex, false); urlMapCacheType::key_type cacheKey(request, pos); log_debug("host=\"" << cacheKey.getHost() << "\" url=\"" << cacheKey.getUrl() << "\" method=\"" << cacheKey.getMethod() << "\" ssl=" << cacheKey.getSsl() << " pos=" << cacheKey.getPos()); if (TntConfig::it().maxUrlMapCache > 0) { lock.lock(); urlMapCacheType::const_iterator um = _urlMapCache.find(cacheKey); if (um != _urlMapCache.end()) { pos = um->second.pos; log_debug("match <" << _urlmap[pos] << "> => " << um->second.ci << " (cached)"); return um->second.ci; } log_debug("entry not found in cache"); } else log_debug("cache disabled"); // no cache hit regmatch_formatter formatter; for (; pos < _urlmap.size(); ++pos) { if (_urlmap[pos].match(request, formatter.what)) { const Maptarget& src = _urlmap[pos].getTarget(); Maptarget ci; ci.libname = formatter(src.libname); ci.compname = formatter(src.compname); if (src.hasPathInfo()) ci.setPathInfo(formatter(src.getPathInfo())); for (Maptarget::args_type::const_iterator it = src.getArgs().begin(); it != src.getArgs().end(); ++it) ci._args[it->first] = formatter(it->second); if (TntConfig::it().maxUrlMapCache > 0) { lock.unlock(); cxxtools::WriteLock wlock(_urlMapCacheMutex); // clear cache after maxUrlMapCache distinct requests if (_urlMapCache.size() > TntConfig::it().maxUrlMapCache) { log_warn("clear url-map-cache"); _urlMapCache.clear(); } _urlMapCache.insert(urlMapCacheType::value_type(cacheKey, UrlMapCacheValue(ci, pos))); } log_debug("match <" << _urlmap[pos] << "> => " << ci); return ci; } else { log_debug("no match <" << _urlmap[pos] << '>'); } } } throw NotFoundException(compUrl, vhost); }
/*************************************************************** * Function: AnalysisManager::requestInfo() * Purpose : Request information from an analysis * Initial : Maxime Chevalier-Boisvert on May 4, 2009 **************************************************************** Revisions and bug fixes: shorter output in verbose mode by Daniele Cono D'Elia, August 2015. */ const AnalysisInfo* AnalysisManager::requestInfo( AnalysisFunc pAnalysis, const ProgFunction* pFunction, const StmtSequence* pFuncBody, const TypeSetString& inArgTypes ) { // If we are in very verbose mode if (ConfigManager::s_veryVerboseVar) { std::cout << "Entering AnalysisManager::requestInfo()" << std::endl; // Log the function name std::cout << "Analyzing function: \"" << pFunction->getFuncName() << "\"" << std::endl; } // Create a cache key object from the input parameters CacheKey cacheKey(pAnalysis, pFunction, pFuncBody, inArgTypes); // Attempt to find a corresponding entry in the cache CacheMap::iterator cacheItr = s_cacheMap.find(cacheKey); // If there is no corresponding cache entry if (cacheItr == s_cacheMap.end()) { // Create a cached info entry and get a reference to it CachedInfo& cachedInfo = s_cacheMap[cacheKey]; // Set the analysis running flag to true cachedInfo.running = true; // Run the analysis and store the information in the cache cachedInfo.pInfo = pAnalysis(pFunction, pFuncBody, inArgTypes, false); // Set the analysis running flag to false cachedInfo.running = false; // If we are in very verbose mode, log that we are returning a computed result if (ConfigManager::s_veryVerboseVar) { std::cout << "Returning computed result" << std::endl; } // Return the analysis information return cachedInfo.pInfo; } // Get a reference to the cached info entry CachedInfo& cachedInfo = cacheItr->second; // If the analysis is already running if (cachedInfo.running) { // If we are in very verbose mode, log that we are returning bottom if (ConfigManager::s_veryVerboseVar) { std::cout << "Returning bottom" << std::endl; } // Return the bottom element for this analysis return pAnalysis(pFunction, pFuncBody, inArgTypes, true); } // If we are in very verbose mode, log that we are returning a cached result if (ConfigManager::s_veryVerboseVar) { std::cout << "Returning cached result" << std::endl; } // Return the cached analysis information return cachedInfo.pInfo; }
void TextBoxContent::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { DEBUG_TSTART(); // paint parent AbstractContent::paint(painter, option, widget); painter->save(); //TODO should we clip to the rect or FORCE resize the rect? probably clip... //painter->setClipRect(contentsRect()); //if(option) // painter->setClipRect(option->exposedRect); painter->translate(contentsRect().topLeft()); // + QPoint(p.width(),p.width())); if(sceneContextHint() == MyGraphicsScene::StaticPreview || !modelItem()->shadowEnabled()) { // If we're drawing in a Preview scene, then we render directly with the painter // (rather than caching the results in a pixmap) because this allows the painter // to scale the text glyphs directly (vector scaling), rather than scaling bits // in a pixmap (bitmap scaling), producing more legible results at lower scalings // qDebug() << modelItem()->itemName()<<"TextBoxContent::paint: Rendering either preview or no shadow"; QAbstractTextDocumentLayout::PaintContext pCtx; // What was this for - improving performance? // I've removed it because it seems to be causing the issue reported in Issue #51 on the google code issues tracker. // I'll keep an eye on performance to see if it suffers at all. For now, closing issue #51. //pCtx.clip = option->exposedRect; bool needRestore = false; if(m_zoomEnabled && sceneContextHint() == MyGraphicsScene::Live) { needRestore = true; painter->save(); double xf = (1/m_zoomDestPoint.x()); double yf = (1/m_zoomDestPoint.y()); double sx = m_zoomCurSize.x() / m_zoomStartSize.x(); double sy = m_zoomCurSize.y() / m_zoomStartSize.y(); QRect cRect = contentsRect(); painter->translate(cRect.width()/xf - m_zoomCurSize.x()/xf,cRect.height()/yf - m_zoomCurSize.y()/yf); painter->scale(sx,sy); // qDebug() << modelItem()->itemName()<<"TextBoxContent::paint: Enabling tranlate & scale. Scale:"<<sx<<","<<sy<<". xf/yf:"<<xf<<","<<yf; } if(modelItem()->shadowEnabled()) { // qDebug() << modelItem()->itemName()<<"TextBoxContent::paint: Drawing m_shadowText"; painter->save(); painter->translate(modelItem()->shadowOffsetX(),modelItem()->shadowOffsetY()); m_shadowText->documentLayout()->draw(painter, pCtx); painter->restore(); } m_text->documentLayout()->draw(painter, pCtx); if(needRestore) painter->restore(); } else { QPixmap cache; // qDebug() << modelItem()->itemName()<<"TextBoxContent::paint: Rendering either live or with shadow"; // The primary and only reason we cache the text rendering is inorder // to paint the text and shadow as a single unit (e.g. composite the // shadow+text BEFORE applying opacity rather than setting the opacity // before rendering the shaodw.) If we didnt cache the text as a pixmap // (e.g. render text directly) then when crossfading, the shadow // "apperas" to fade out last, after the text. // Update 20091015: Implemented very aggressive caching across TextBoxContent instances // that share the same modelItem() (see ::cacheKey()) inorder to avoid re-rendering // potentially expensive drop shadows, below. QString key = cacheKey(); if(m_text->toPlainText().trimmed().isEmpty()) { // "<< m_text->toHtml()<<" //qDebug() << modelItem()->itemName()<<": Not rendering cache because:"<< QPixmapCache::find(key,cache)<< " or ...";//plain "<<m_text->toPlainText()<<" is empty"; cache = QPixmap(contentsRect().size()); cache.fill(Qt::transparent); } else { if(!QPixmapCache::find(key,cache)) { if(QFile(key).exists()) { cache.load(key); QPixmapCache::insert(key,cache); //qDebug()<<"TextBoxContent::paint(): modelItem:"<<modelItem()->itemName()<<": Cache load from"<<key; } else { qDebug()<<"TextBoxContent::paint(): modelItem:"<<modelItem()->itemName()<<": Cache redraw"; QSizeF shadowSize = modelItem()->shadowEnabled() ? QSizeF(modelItem()->shadowOffsetX(),modelItem()->shadowOffsetY()) : QSizeF(0,0); cache = QPixmap((contentsRect().size()+shadowSize).toSize()); cache.fill(Qt::transparent); QPainter textPainter(&cache); QAbstractTextDocumentLayout::PaintContext pCtx; #if QT46_SHADOW_ENAB == 0 if(modelItem()->shadowEnabled()) renderShadow(&textPainter,&pCtx); #endif // If we're zooming, we want to render the text straight to the painter // so it can transform the raw vectors instead of scaling the bitmap. // But if we're not zooming, we cache the text with the shadow since it // looks better that way when we're crossfading. if(!m_zoomEnabled) m_text->documentLayout()->draw(&textPainter, pCtx); cache.save(key,"PNG"); QPixmapCache::insert(key, cache); } } } // Draw a rectangular outline in the editor inorder to visually locate empty text blocks if(sceneContextHint() == MyGraphicsScene::Editor && m_text->toPlainText().trimmed() == "") { QPen p = modelItem() ? modelItem()->outlinePen() : QPen(Qt::black,1.5); painter->setPen(p); painter->setBrush(Qt::NoBrush); painter->drawRect(QRect(QPoint(0,0),contentsRect().size())); } else { if(m_zoomEnabled) { double xf = (1/m_zoomDestPoint.x()); double yf = (1/m_zoomDestPoint.y()); double sx = m_zoomCurSize.x() / m_zoomStartSize.x(); double sy = m_zoomCurSize.y() / m_zoomStartSize.y(); painter->save(); QRect cRect = contentsRect(); painter->translate(cRect.width()/xf - m_zoomCurSize.x()/xf,cRect.height()/yf - m_zoomCurSize.y()/yf); painter->scale(sx,sy); painter->drawPixmap(0,0,cache); QAbstractTextDocumentLayout::PaintContext pCtx; m_text->documentLayout()->draw(painter, pCtx); painter->restore(); } else { painter->drawPixmap(0,0,cache); if(sceneContextHint() != MyGraphicsScene::Live && modelItem()->zoomEffectEnabled()) { // cache may not contain the actual text, just shadow, since its not live, // so render the text QAbstractTextDocumentLayout::PaintContext pCtx; m_text->documentLayout()->draw(painter, pCtx); } } } } painter->restore(); //qDebug() << "TextBoxContent::paint(): \t \t Elapsed:"<<(((double)total.elapsed())/1000.0)<<" sec"; }
std::vector<CTodo *> OrganizerCalendarDatabaseAccess::getTodos(int calId, std::string guid, int &pErrorCode) { std::vector<CTodo*> listTodo; OrganizerGuidCacheKey cacheKey(calId, E_TODO, QString::fromStdString(guid)); if (m_dbCache->containsTodoVector(cacheKey)) { // found in cache m_dbCache->takeTodoVector(cacheKey, listTodo); return listTodo; } const int columnNumber = 49; CTodo *todo = 0; CAlarm *pAlarm = 0; int iI_TodoCount = 0; int iJ_TodoCount = 0; pErrorCode = CALENDAR_OPERATION_SUCCESSFUL; std::vector<long> vCookie; QSqlQuery pQuery; if (!pQuery.prepare(selectInnerJoinBatchGuid)) { pErrorCode = CALENDAR_DATABASE_ERROR; return listTodo; } pQuery.bindValue(":calId", QString::number(calId)); pQuery.bindValue(":compType", QString::number(E_TODO)); pQuery.bindValue(":compUid", QString::fromStdString(guid)); bool ok = pQuery.exec(); sqliteErrorMapper(pQuery.lastError(), pErrorCode); if (!ok) return listTodo; while (pQuery.next()) { todo = new CTodo(); pAlarm = new CAlarm(); for (iJ_TodoCount = 0; iJ_TodoCount < columnNumber; ++iJ_TodoCount) { switch(iJ_TodoCount) { case 0: // ID1 todo->setId(pQuery.value(iJ_TodoCount).toString().toStdString()); break; case 1: break; case 2: // ID3 todo->setType(pQuery.value(iJ_TodoCount).toInt()); break; case 3: // ID4 todo->setFlags(pQuery.value(iJ_TodoCount).toInt()); break; case 4: // ID5 todo->setDateStart(pQuery.value(iJ_TodoCount).toInt()); break; case 5: // ID6 todo->setDateEnd(pQuery.value(iJ_TodoCount).toInt()); break; case 6: // ID7 if (!pQuery.value(iJ_TodoCount).toString().isEmpty()) todo->setSummary(pQuery.value(iJ_TodoCount).toString().toStdString()); break; case 7: // ID8 if (!pQuery.value(iJ_TodoCount).toString().isEmpty()) todo->setLocation(pQuery.value(iJ_TodoCount).toString().toStdString()); break; case 8: // ID9 if (!pQuery.value(iJ_TodoCount).toString().isEmpty()) todo->setDescription(pQuery.value(iJ_TodoCount).toString().toStdString()); break; case 9: // ID10 todo->setStatus(pQuery.value(iJ_TodoCount).toInt()); break; case 10: // ID11 if (!pQuery.value(iJ_TodoCount).toString().isEmpty()) todo->setGUid(pQuery.value(iJ_TodoCount).toString().toStdString()); break; case 11: // ID12 todo->setUntil(pQuery.value(iJ_TodoCount).toInt()); break; case 12: // ID13 todo->setAllDay(pQuery.value(iJ_TodoCount).toInt()); break; case 13: // ID14 todo->setCreatedTime(pQuery.value(iJ_TodoCount).toInt()); break; case 14: // ID15 todo->setLastModified(pQuery.value(iJ_TodoCount).toInt()); break; case 15: // ID16 todo->setTzid(pQuery.value(iJ_TodoCount).toString().toStdString()); break; case 16: // ID17 case 17: // ID18 case 18: // ID19 break; case 19: // ID20 if (pQuery.value(iJ_TodoCount).toInt()) todo->setClas(pQuery.value(iJ_TodoCount).toString().toStdString()); break; case 20: // ID21 if (!pQuery.value(iJ_TodoCount).toString().isEmpty()) todo->setGeo(pQuery.value(iJ_TodoCount).toString().toStdString()); break; case 21: // ID22 todo->setPriority(pQuery.value(iJ_TodoCount).toInt()); break; case 22: // ID23 todo->setDateStamp(pQuery.value(iJ_TodoCount).toInt()); break; case 23: // ID24 todo->setSequence(pQuery.value(iJ_TodoCount).toInt()); break; case 24: // ID25 break; case 25: // ID26 todo->setUid(pQuery.value(iJ_TodoCount).toInt()); break; case 26: // ID27 if (!pQuery.value(iJ_TodoCount).toString().isEmpty()) todo->setUrl(pQuery.value(iJ_TodoCount).toString().toStdString()); break; case 27: // ID28 break; case 28: // ID29 if (!pQuery.value(iJ_TodoCount).toString().isEmpty()) todo->setCategories(pQuery.value(iJ_TodoCount).toString().toStdString()); break; case 29: // ID30 if (!pQuery.value(iJ_TodoCount).toString().isEmpty()) todo->setComments(pQuery.value(iJ_TodoCount).toString().toStdString()); break; case 30: // ID31 if (!pQuery.value(iJ_TodoCount).toString().isEmpty()) todo->setContact(pQuery.value(iJ_TodoCount).toString().toStdString()); break; case 31: // ID32 if (!pQuery.value(iJ_TodoCount).toString().isEmpty()) todo->setRelated(pQuery.value(iJ_TodoCount).toString().toStdString()); break; case 32: // ID33 if (!pQuery.value(iJ_TodoCount).toString().isEmpty()) todo->setResources(pQuery.value(iJ_TodoCount).toString().toStdString()); break; case 33: // ID34 todo->setPercentComplete(pQuery.value(iJ_TodoCount).toInt()); break; case 34: // ID35 todo->setCompleted(pQuery.value(iJ_TodoCount).toInt()); break; case 35: // ID36 break; case 36: // ID37 if (!pQuery.value(iJ_TodoCount).toString().isEmpty()) pAlarm->setTrigger(pQuery.value(iJ_TodoCount).toInt()); break; case 37: // ID38 if (!pQuery.value(iJ_TodoCount).toString().isEmpty()) pAlarm->setRepeat(pQuery.value(iJ_TodoCount).toInt()); break; case 38: // ID39 if (!pQuery.value(iJ_TodoCount).toString().isEmpty()) pAlarm->setDuration(pQuery.value(iJ_TodoCount).toInt()); break; case 39: // ID40 if (!pQuery.value(iJ_TodoCount).toString().isEmpty()) pAlarm->setAction(pQuery.value(iJ_TodoCount).toInt()); break; case 40: // ID41 if (!pQuery.value(iJ_TodoCount).toString().isEmpty()) { vCookie.push_back(pQuery.value(iJ_TodoCount).toInt()); pAlarm->setCookie(vCookie); } break; case 41: // ID42 if (!pQuery.value(iJ_TodoCount).toString().isEmpty()) pAlarm->setAttach(pQuery.value(iJ_TodoCount).toString().toStdString()); break; default: break; } } if (todo->getFlags() == HAS_ALARM) todo->setAlarm(pAlarm); delete pAlarm; pAlarm = 0; /*retrieve xprop */ std::vector<CProperties *> vPropList; vPropList = todo->retrieveXPropertyDetails(); todo->setXProperties(vPropList); std::vector<CProperties *>::iterator vPropListIterator; for (vPropListIterator = vPropList.begin(); vPropListIterator != vPropList.end(); ++vPropListIterator) delete *vPropListIterator; /*retrieve params */ std::map<std::string, std::vector<CParameters *> > paramMap; paramMap = todo->retrieveParameterDetails(); todo->setHashMap(paramMap); paramMap.clear(); /* push the todo in to the list */ listTodo.push_back(todo); ++iI_TodoCount; } // put to cache m_dbCache->insertTodoVector(cacheKey, listTodo); return listTodo; }
std::vector<CJournal *> OrganizerCalendarDatabaseAccess::getJournals(int calId, std::string guid, int &pErrorCode) { std::vector<CJournal*> listJournal; OrganizerGuidCacheKey cacheKey(calId, E_JOURNAL, QString::fromStdString(guid)); if (m_dbCache->containsJournalVector(cacheKey)) { // found in cache m_dbCache->takeJournalVector(cacheKey, listJournal); return listJournal; } const int columnNumber = 49; CJournal *journal = 0; int iI_JourCount = 0; int iJ_JourCount = 0; pErrorCode = CALENDAR_OPERATION_SUCCESSFUL; QSqlQuery pQuery; if (!pQuery.prepare(selectInnerJoinBatchGuid)) { pErrorCode = CALENDAR_DATABASE_ERROR; return listJournal; } pQuery.bindValue(":calId", QString::number(calId)); pQuery.bindValue(":compType", QString::number(E_JOURNAL)); pQuery.bindValue(":compUid", QString::fromStdString(guid)); bool ok = pQuery.exec(); sqliteErrorMapper(pQuery.lastError(), pErrorCode); if (!ok) return listJournal; while (pQuery.next()) { journal = new CJournal(); for (iJ_JourCount = 0; iJ_JourCount < columnNumber; ++iJ_JourCount) { switch(iJ_JourCount) { case 0: // ID1 journal->setId(pQuery.value(iJ_JourCount).toString().toStdString()); break; case 1: break; case 2: // ID3 journal->setType(pQuery.value(iJ_JourCount).toInt()); break; case 3: // ID4 journal->setFlags(pQuery.value(iJ_JourCount).toInt()); break; case 4: // ID5 journal->setDateStart(pQuery.value(iJ_JourCount).toInt()); break; case 5: // ID6 journal->setDateEnd(pQuery.value(iJ_JourCount).toInt()); break; case 6: // ID7 if (!pQuery.value(iJ_JourCount).toString().isEmpty()) journal->setSummary(pQuery.value(iJ_JourCount).toString().toStdString()); break; case 7: // ID8 if (!pQuery.value(iJ_JourCount).toString().isEmpty()) journal->setLocation(pQuery.value(iJ_JourCount).toString().toStdString()); break; case 8: // ID9 if (!pQuery.value(iJ_JourCount).toString().isEmpty()) journal->setDescription(pQuery.value(iJ_JourCount).toString().toStdString()); break; case 9: // ID10 journal->setStatus(pQuery.value(iJ_JourCount).toInt()); break; case 10: // ID11 if (!pQuery.value(iJ_JourCount).toString().isEmpty()) journal->setGUid(pQuery.value(iJ_JourCount).toString().toStdString()); break; case 11: // ID12 journal->setUntil(pQuery.value(iJ_JourCount).toInt()); break; case 12: // ID13 journal->setAllDay(pQuery.value(iJ_JourCount).toInt()); break; case 13: // ID14 journal->setCreatedTime(pQuery.value(iJ_JourCount).toInt()); break; case 14: // ID15 journal->setLastModified(pQuery.value(iJ_JourCount).toInt()); break; case 15: // ID16 journal->setTzid(pQuery.value(iJ_JourCount).toString().toStdString()); break; case 16: // ID17 case 17: // ID18 case 18: // ID19 break; case 19: // ID20 if (pQuery.value(iJ_JourCount).toInt()) journal->setClas(pQuery.value(iJ_JourCount).toString().toStdString()); break; case 20: // ID21 case 21: // ID22 break; case 22: // ID23 journal->setDateStamp(pQuery.value(iJ_JourCount).toInt()); break; case 23: // ID24 journal->setSequence(pQuery.value(iJ_JourCount).toInt()); break; case 24: // ID25 break; case 25: // ID26 journal->setUid(pQuery.value(iJ_JourCount).toInt()); break; case 26: // ID27 if (!pQuery.value(iJ_JourCount).toString().isEmpty()) journal->setUrl(pQuery.value(iJ_JourCount).toString().toStdString()); break; case 27: // ID28 break; case 28: // ID29 if (!pQuery.value(iJ_JourCount).toString().isEmpty()) journal->setCategories(pQuery.value(iJ_JourCount).toString().toStdString()); break; case 29: // ID30 if (!pQuery.value(iJ_JourCount).toString().isEmpty()) journal->setComments(pQuery.value(iJ_JourCount).toString().toStdString()); break; case 30: // ID31 if (!pQuery.value(iJ_JourCount).toString().isEmpty()) journal->setContact(pQuery.value(iJ_JourCount).toString().toStdString()); break; case 31: // ID32 if (!pQuery.value(iJ_JourCount).toString().isEmpty()) journal->setRelated(pQuery.value(iJ_JourCount).toString().toStdString()); break; case 32: // ID33 if (!pQuery.value(iJ_JourCount).toString().isEmpty()) journal->setResources(pQuery.value(iJ_JourCount).toString().toStdString()); break; default: break; } } /*retrieve xprop */ std::vector<CProperties *> vPropList; vPropList = journal->retrieveXPropertyDetails(); journal->setXProperties(vPropList); std::vector<CProperties *>::iterator vPropListIterator; for (vPropListIterator = vPropList.begin(); vPropListIterator != vPropList.end(); ++vPropListIterator) delete *vPropListIterator; /*retrieve params */ std::map<std::string, std::vector<CParameters *> > paramMap; paramMap = journal->retrieveParameterDetails(); journal->setHashMap(paramMap); paramMap.clear(); /* push the journal in to the list */ listJournal.push_back(journal); ++iI_JourCount; } // put to cache m_dbCache->insertJournalVector(cacheKey, listJournal); return listJournal; }
void MongoClient::ensureIndex(const EnsureIndexInfo &oldInfo,const EnsureIndexInfo &newInfo) const { std::string ns = newInfo._collection.ns().toString(); mongo::BSONObj keys = mongo::Robomongo::fromjson(newInfo._request); mongo::BSONObjBuilder toSave; bool cache=true; int version =-1; toSave.append( "ns" , ns ); toSave.append( "key" , keys ); std::string cacheKey(ns); cacheKey += "--"; if ( newInfo._name != "" ) { toSave.append( "name" , newInfo._name ); cacheKey += newInfo._name; } else { std::string nn = _dbclient->genIndexName(keys); toSave.append( "name" , nn ); cacheKey += nn; } if (version >= 0) toSave.append("v", version); if (oldInfo._unique != newInfo._unique) toSave.appendBool("unique", newInfo._unique); if (oldInfo._backGround != newInfo._backGround) toSave.appendBool("background", newInfo._backGround); if (oldInfo._dropDups != newInfo._dropDups) toSave.appendBool("dropDups", newInfo._dropDups); if (oldInfo._sparse != newInfo._sparse) toSave.appendBool("sparse", newInfo._sparse); if (oldInfo._defaultLanguage != newInfo._defaultLanguage) toSave.append("default_language", newInfo._defaultLanguage); if (oldInfo._languageOverride != newInfo._languageOverride) toSave.append("language_override", newInfo._languageOverride); if (oldInfo._textWeights != newInfo._textWeights) toSave.append("weights", newInfo._textWeights); /* if ( _seenIndexes.count( cacheKey ) ) return 0; if ( cache ) _seenIndexes.insert( cacheKey );*/ if (oldInfo._ttl != newInfo._ttl) toSave.append("expireAfterSeconds", newInfo._ttl); MongoNamespace namesp(newInfo._collection.ns().databaseName(), "system.indexes"); mongo::BSONObj obj = toSave.obj(); if (!oldInfo._name.empty()) _dbclient->dropIndex(ns, oldInfo._name); _dbclient->insert(namesp.toString().c_str(), obj); }
void TextBoxContent::syncFromModelItem(AbstractVisualItem *model) { DEBUG_TSTART(); m_dontSyncToModel = true; if(!modelItem()) { setModelItem(model); // Start out the last remembered model rev at the rev of the model // so we dont force a redraw of the cache just because we're a fresh // object. if(QPixmapCache::find(cacheKey())) m_lastModelRev = modelItem()->revision(); } static int x = 0; x++; //qDebug() << x<<": TextBoxContent::syncFromModelItem() mark"; QFont font; TextItem * textModel = dynamic_cast<TextItem*>(model); font.setFamily(textModel->fontFamily()); font.setPointSize((int)textModel->fontSize()); m_text->setDefaultFont(font); if (!Qt::mightBeRichText(textModel->text())) { qDebug() << "TextBoxContent:: converting plain text from model item to html"; m_text->setPlainText(textModel->text()); textModel->setText(m_text->toHtml()); } //qDebug() << "TextBoxContent:: Original HTML:"<<textModel->text(); setHtml(textModel->text()); //qDebug() << "TextBoxContent:: New HTML:"<<m_text->toHtml(); AbstractContent::syncFromModelItem(model); if(modelItem()->revision() != m_lastModelRev) { //qDebug()<<"modelItem():"<<modelItem()->itemName()<<": last revision:"<<m_lastModelRev<<", this revision:"<<m_lastModelRev<<", cache dirty!"; m_lastModelRev = modelItem()->revision(); // DONT dirty cache here since we changed the cacheKey algorithm - cache key is now based on visual description, not on item identity //dirtyCache(); } if( model->zoomEffectEnabled() && model->zoomSpeed() > 0 && sceneContextHint() == MyGraphicsScene::Live) { m_zoomEnabled = true; m_zoomAnimationTimer->start(1000 / 20); // / model->zoomSpeed()); QSize size = contentsRect().size(); double width = size.width(); double height = size.height(); double aspectRatio = height == 0 ? 1 : width/height; // if(!m_zoomInit) // { //qDebug() << "aspectRatio: "<<aspectRatio; QPointF delta; m_zoomStartSize.setX(width); m_zoomStartSize.setY(height); m_zoomEndSize.setX(width * model->zoomFactor()); m_zoomEndSize.setY(height * model->zoomFactor()); bool zoomIn = true; if(model->zoomDirection() == AbstractVisualItem::ZoomIn) zoomIn = true; else if(model->zoomDirection() == AbstractVisualItem::ZoomOut) zoomIn = false; else if(model->zoomDirection() == AbstractVisualItem::ZoomRandom) zoomIn = qrand() < RAND_MAX/2; m_zoomCurSize = zoomIn ? m_zoomStartSize : m_zoomEndSize; m_zoomDir = zoomIn ? 1 : -1; delta.setX(m_zoomEndSize.x() - m_zoomCurSize.x()); delta.setY(m_zoomEndSize.y() - m_zoomCurSize.y()); //step.setX(delta.x()/ZOOM_STEPS); //step.setY(delta.y()/ZOOM_STEPS); // m_zoomInit = true; // } // allow it to go below 1.0 for step size by using 75.0 when the max of the zoomSpeed slider in config is 100 m_zoomStep.setX(8.0 / (100.01 - ((double)model->zoomSpeed())) * aspectRatio); m_zoomStep.setY(8.0 / (100.01 - ((double)model->zoomSpeed()))); if(model->zoomAnchorPoint() == AbstractVisualItem::ZoomAnchorRandom) { // pick a third intersection double x = qrand() < RAND_MAX/2 ? .33 : .66; double y = qrand() < RAND_MAX/2 ? .33 : .66; // apply a fudge factor // x += 0.15 - ((double)qrand()) / ((double)RAND_MAX) * 0.075; // y += 0.15 - ((double)qrand()) / ((double)RAND_MAX) * 0.075; m_zoomDestPoint = QPointF(x,y); //qDebug() << "ZoomRandom: "<<x<<","<<y; //qDebug() << model->itemName() << "Random zoom anchor: "<<m_zoomDestPoint; } else { double x = .0, y = .0; switch(model->zoomAnchorPoint()) { case AbstractVisualItem::ZoomTopLeft: x = .33; y = .33; break; case AbstractVisualItem::ZoomTopMid: x = .50; y = .25; break; case AbstractVisualItem::ZoomTopRight: x = .66; y = .33; break; case AbstractVisualItem::ZoomRightMid: x = .75; y = .50; break; case AbstractVisualItem::ZoomBottomRight: x = .66; y = .66; break; case AbstractVisualItem::ZoomBottomMid: x = .50; y = .75; break; case AbstractVisualItem::ZoomBottomLeft: x = .33; y = .66; break; case AbstractVisualItem::ZoomLeftMid: x = .25; y = .50; break; case AbstractVisualItem::ZoomCenter: default: x = .50; y = .50; break; }; m_zoomDestPoint = QPointF(x,y); } } else { m_zoomEnabled = false; if(m_zoomAnimationTimer->isActive()) m_zoomAnimationTimer->stop(); } m_dontSyncToModel = false; }