本文整理汇总了C++中QContactAvatar::setImageUrl方法的典型用法代码示例。如果您正苦于以下问题:C++ QContactAvatar::setImageUrl方法的具体用法?C++ QContactAvatar::setImageUrl怎么用?C++ QContactAvatar::setImageUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QContactAvatar
的用法示例。
在下文中一共展示了QContactAvatar::setImageUrl方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setAvatarPath
void SeasidePerson::setAvatarPath(QUrl avatarPath)
{
QContactAvatar avatarDetail = mContact.detail<QContactAvatar>();
avatarDetail.setImageUrl(QUrl(avatarPath));
mContact.saveDetail(&avatarDetail);
emit avatarPathChanged();
}
示例2: saveAvatar
void BusinessCardHandling::saveAvatar(const QString filename, QPixmap p, QContact& contact)
{
// Path to store avatar picture
QString path;
#ifdef Q_OS_SYMBIAN
path.append("c:/System/");
#endif
path.append(filename);
// Remove same file if exists
QFile file;
if (file.exists(path))
file.remove(path);
// Save pixmap into file
bool saveRet = p.save(path);
if (saveRet) {
// Create avatar
QContactAvatar contactAvatar;
contactAvatar.setImageUrl(QUrl(path));
bool saveAvatar = contact.saveDetail(&contactAvatar);
// Save contact
if (saveAvatar)
m_contactManager->saveContact(&contact);
// NOTE: Do not remove picture, system needs it for showing avatar
// Remove picture file
//bool removeRet = file.remove(path);
}
}
示例3: QContactAvatar
QContactDetail *CntTransformAvatar::transformItemField(const CContactItemField& field, const QContact &contact)
{
Q_UNUSED(contact);
QContactAvatar *avatar = new QContactAvatar();
if (field.ContentType().ContainsFieldType(KUidContactFieldCodImage)) {
CContactTextField* storage = field.TextStorage();
QString avatarString = QString::fromUtf16(storage->Text().Ptr(), storage->Text().Length());
avatar->setImageUrl(QUrl(avatarString));
}
return avatar;
}
示例4: main
//.........这里部分代码省略.........
syncTimer.start();
manager.saveContacts(&contactsToAggregate);
aggregationElapsed = syncTimer.elapsed();
totalAggregatesInDatabase = manager.contactIds().count();
qDebug() << "Average time for aggregation of" << contactsToAggregate.size() << "contacts (with" << totalAggregatesInDatabase << "existing in database):" << aggregationElapsed
<< "milliseconds (" << ((1.0 * aggregationElapsed) / (1.0 * contactsToAggregate.size())) << " msec per aggregated contact )";
elapsedTimeTotal += aggregationElapsed;
// The next test is about updating existing contacts, amongst a large set.
// We're especially interested in presence updates, as these are common.
qDebug() << "\n\nPerforming presence update tests:";
// in the first presence update test, we update a small number of contacts.
QStringList presenceAvatars = generateAvatarsList();
QList<QContact> contactsToUpdate;
for (int i = 0; i < 10; ++i) {
contactsToUpdate.append(prefillData.at(prefillData.size() - 1 - i));
}
// modify the presence, nickname and avatar of the test data
for (int j = 0; j < contactsToUpdate.size(); ++j) {
QString genstr = QString::number(j);
QContact curr = contactsToUpdate[j];
QContactPresence cp = curr.detail<QContactPresence>();
QContactNickname nn = curr.detail<QContactNickname>();
QContactAvatar av = curr.detail<QContactAvatar>();
cp.setNickname(genstr);
cp.setCustomMessage(genstr);
cp.setTimestamp(QDateTime::currentDateTime());
cp.setPresenceState(static_cast<QContactPresence::PresenceState>(qrand() % 4));
nn.setNickname(nn.nickname() + genstr);
av.setImageUrl(genstr + presenceAvatars.at(qrand() % presenceAvatars.size()));
curr.saveDetail(&cp);
curr.saveDetail(&nn);
curr.saveDetail(&av);
contactsToUpdate.replace(j, curr);
}
// perform a batch save.
syncTimer.start();
manager.saveContacts(&contactsToUpdate);
qint64 presenceElapsed = syncTimer.elapsed();
totalAggregatesInDatabase = manager.contactIds().count();
qDebug() << " update ( batch of" << contactsToUpdate.size() << ") presence+nick+avatar (with" << totalAggregatesInDatabase << "existing in database, all overlap):" << presenceElapsed
<< "milliseconds (" << ((1.0 * presenceElapsed) / (1.0 * contactsToUpdate.size())) << " msec per updated contact )";
elapsedTimeTotal += presenceElapsed;
// in the second presence update test, we update ALL of the contacts
// This simulates having a large number of contacts from a single source (eg, a social network)
// where (due to changed connectivity status) presence updates for the entire set become available.
contactsToUpdate.clear();
QDateTime timestamp = QDateTime::currentDateTime();
for (int j = 0; j < prefillData.size(); ++j) {
QContact curr = prefillData.at(j);
QString genstr = QString::number(j) + "2";
QContactPresence cp = curr.detail<QContactPresence>();
QContactNickname nn = curr.detail<QContactNickname>();
QContactAvatar av = curr.detail<QContactAvatar>();
cp.setNickname(genstr);
cp.setCustomMessage(genstr);
cp.setTimestamp(timestamp);
cp.setPresenceState(static_cast<QContactPresence::PresenceState>((qrand() % 4) + 1));
nn.setNickname(nn.nickname() + genstr);
av.setImageUrl(genstr + presenceAvatars.at(qrand() % presenceAvatars.size()));
示例5: generateContact
QContact generateContact(const QString &syncTarget = QString(QLatin1String("local")), bool possiblyAggregate = false)
{
static const QStringList firstNames(generateFirstNamesList());
static const QStringList middleNames(generateMiddleNamesList());
static const QStringList lastNames(generateLastNamesList());
static const QStringList nonOverlappingFirstNames(generateNonOverlappingFirstNamesList());
static const QStringList nonOverlappingLastNames(generateNonOverlappingLastNamesList());
static const QStringList phoneNumbers(generatePhoneNumbersList());
static const QStringList emailProviders(generateEmailProvidersList());
static const QStringList avatars(generateAvatarsList());
static const QStringList hobbies(generateHobbiesList());
// we randomly determine whether to generate various details
// to ensure that we have heterogeneous contacts in the db.
QContact retn;
int random = qrand();
bool preventAggregate = (syncTarget != QLatin1String("local") && !possiblyAggregate);
// We always have a sync target.
QContactSyncTarget synctarget;
synctarget.setSyncTarget(syncTarget);
retn.saveDetail(&synctarget);
// We always have a name. Select an overlapping name if the sync target
// is something other than "local" and possiblyAggregate is true.
QContactName name;
name.setFirstName(preventAggregate ?
nonOverlappingFirstNames.at(random % nonOverlappingFirstNames.size()) :
firstNames.at(random % firstNames.size()));
name.setLastName(preventAggregate ?
nonOverlappingLastNames.at(random % nonOverlappingLastNames.size()) :
lastNames.at(random % lastNames.size()));
if ((random % 6) == 0) name.setMiddleName(middleNames.at(random % middleNames.size()));
if ((random % 17) == 0) name.setPrefix(QLatin1String("Dr."));
retn.saveDetail(&name);
// Favorite
if ((random % 31) == 0) {
QContactFavorite fav;
fav.setFavorite(true);
retn.saveDetail(&fav);
}
// Phone number
if ((random % 3) == 0) {
QContactPhoneNumber phn;
QString randomPhn = phoneNumbers.at(random % phoneNumbers.size());
phn.setNumber(preventAggregate ? QString(QString::number(random % 500000) + randomPhn) : randomPhn);
if ((random % 9) == 0) phn.setContexts(QContactDetail::ContextWork);
retn.saveDetail(&phn);
}
// Email
if ((random % 2) == 0) {
QContactEmailAddress em;
em.setEmailAddress(QString(QLatin1String("%1%2%3%4"))
.arg(preventAggregate ? QString(QString::number(random % 500000) + syncTarget) : QString())
.arg(name.firstName()).arg(name.lastName())
.arg(emailProviders.at(random % emailProviders.size())));
if (random % 9) em.setContexts(QContactDetail::ContextWork);
retn.saveDetail(&em);
}
// Avatar
if ((random % 5) == 0) {
QContactAvatar av;
av.setImageUrl(name.firstName() + avatars.at(random % avatars.size()));
retn.saveDetail(&av);
}
// Hobby
if ((random % 21) == 0) {
QContactHobby h1;
h1.setHobby(hobbies.at(random % hobbies.size()));
retn.saveDetail(&h1);
int newRandom = qrand();
if ((newRandom % 2) == 0) {
QContactHobby h2;
h2.setHobby(hobbies.at(newRandom % hobbies.size()));
retn.saveDetail(&h2);
}
}
return retn;
}
示例6: reset
void SeasideCache::reset()
{
for (int i = 0; i < FilterTypesCount; ++i) {
m_contacts[i].clear();
m_populated[i] = false;
m_models[i] = 0;
}
m_cache.clear();
m_cacheIndices.clear();
for (uint i = 0; i < sizeof(contactsData) / sizeof(Contact); ++i) {
QContact contact;
// This is specific to the qtcontacts-sqlite backend:
const QString idStr(QString::fromLatin1("qtcontacts:org.nemomobile.contacts.sqlite::sql-%1"));
contact.setId(QContactId::fromString(idStr.arg(i + 1)));
QContactName name;
name.setFirstName(QString::fromLatin1(contactsData[i].firstName));
name.setMiddleName(QString::fromUtf8(contactsData[i].middleName));
name.setLastName(QString::fromLatin1(contactsData[i].lastName));
contact.saveDetail(&name);
if (contactsData[i].avatar) {
QContactAvatar avatar;
avatar.setImageUrl(QUrl(QLatin1String(contactsData[i].avatar)));
contact.saveDetail(&avatar);
}
QContactStatusFlags statusFlags;
if (contactsData[i].email) {
QContactEmailAddress email;
email.setEmailAddress(QLatin1String(contactsData[i].email));
contact.saveDetail(&email);
statusFlags.setFlag(QContactStatusFlags::HasEmailAddress, true);
}
if (contactsData[i].phoneNumber) {
QContactPhoneNumber phoneNumber;
phoneNumber.setNumber(QLatin1String(contactsData[i].phoneNumber));
contact.saveDetail(&phoneNumber);
statusFlags.setFlag(QContactStatusFlags::HasPhoneNumber, true);
}
contact.saveDetail(&statusFlags);
m_cacheIndices.insert(internalId(contact), m_cache.count());
m_cache.append(CacheItem(contact));
QString fullName = name.firstName() + QChar::fromLatin1(' ') + name.lastName();
CacheItem &cacheItem = m_cache.last();
cacheItem.nameGroup = determineNameGroup(&cacheItem);
cacheItem.displayLabel = fullName;
}
insert(FilterAll, 0, getContactsForFilterType(FilterAll));
insert(FilterFavorites, 0, getContactsForFilterType(FilterFavorites));
insert(FilterOnline, 0, getContactsForFilterType(FilterOnline));
}
示例7: propertyProcessed
void SeasidePhotoHandler::propertyProcessed(const QVersitDocument &, const QVersitProperty &property, const QContact &, bool *alreadyProcessed, QList<QContactDetail> * updatedDetails)
{
// if the property is a PHOTO property, store the data to disk
// and then create an avatar detail which points to it.
if (property.name().toLower() != QLatin1String("photo"))
return;
#ifndef QT_VERSION_5
// The Qt4 / QtMobility version has QContactThumbnail support.
// We need to remove any such thumbnail detail from the output,
// as some backends (such as qtcontacts-sqlite) do not support
// that detail type.
for (int i = 0; i < updatedDetails->size(); ++i) {
if (updatedDetails->at(i).definitionName() == QContactThumbnail::DefinitionName) {
updatedDetails->removeAt(i);
--i;
}
}
#endif
// The data might be either a URL, a file path, or encoded image data
// It's hard to tell what the content is, because versit removes the encoding
// information in the process of decoding the data...
// Try to interpret the data as a URL
QString path(property.variantValue().toString());
QUrl url(path);
if (url.isValid()) {
// Treat remote URL as a true URL, and reference it in the avatar
if (!url.scheme().isEmpty() && !url.isLocalFile()) {
QContactAvatar newAvatar;
newAvatar.setImageUrl(url);
updatedDetails->append(newAvatar);
// we have successfully processed this PHOTO property.
*alreadyProcessed = true;
return;
}
}
if (!url.isValid()) {
// See if we can resolve the data as a local file path
url = QUrl::fromLocalFile(path);
}
QByteArray photoData;
if (url.isValid()) {
// Try to read the data from the referenced file
const QString filePath(url.path());
if (QFile::exists(filePath)) {
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly)) {
qWarning() << "Unable to process photo data as file:" << path;
return;
} else {
photoData = file.readAll();
}
}
}
if (photoData.isEmpty()) {
// Try to interpret the encoded property data as the image
photoData = property.variantValue().toByteArray();
if (photoData.isEmpty()) {
qWarning() << "Failed to extract avatar data from vCard PHOTO property";
return;
}
}
QImage img;
bool loaded = img.loadFromData(photoData);
if (!loaded) {
qWarning() << "Failed to load avatar image from vCard PHOTO data";
return;
}
// We will save the avatar image to disk in the system's data location
// Since we're importing user data, it should not require privileged access
const QString subdirectory(QString::fromLatin1(".local/share/system/Contacts/avatars"));
const QString photoDirPath(QDir::home().filePath(subdirectory));
// create the photo file dir if it doesn't exist.
QDir photoDir;
if (!photoDir.mkpath(photoDirPath)) {
qWarning() << "Failed to create avatar image directory when loading avatar image from vCard PHOTO data";
return;
}
// construct the filename of the new avatar image.
QString photoFilePath = QString::fromLatin1(QCryptographicHash::hash(photoData, QCryptographicHash::Md5).toHex());
photoFilePath = photoDirPath + QDir::separator() + photoFilePath + QString::fromLatin1(".jpg");
// save the file to disk
bool saved = img.save(photoFilePath);
if (!saved) {
qWarning() << "Failed to save avatar image from vCard PHOTO data to" << photoFilePath;
return;
}
//.........这里部分代码省略.........
示例8: responseAvailable
//.........这里部分代码省略.........
// Contact Name
QContactName contactname;
QString username = map2["username"].toString();
qDebug()<<"Username = "<<username;
contactname.setFirstName(username);
contactname.setLastName(username);
QVariant nameVar = QVariant::fromValue(contactname);
contact.setValue("Name",nameVar);
// Contact's Flickr Specific ID to QContactGuid
QContactGuid guid;
guid.setGuid(map2["nsid"].toString());
QVariant guidVar = QVariant::fromValue(guid);
contact.setValue("Guid",guidVar);
// Contact's profile image url
QUrl url;
if((0 == map2["iconfarm"].toInt()) && (0 == map2["iconserver"].toInt()))
url = QString("http://www.flickr.com/images/buddyicon.jpg");
else
{
QString str("http://farm");
str.append(map2["iconfarm"].toString());
str.append(".static.flickr.com/");
str.append(map2["iconserver"].toString());
str.append("/buddyicons/");
str.append(map2["nsid"].toString());
str.append(".jpg");
url = str;
}
QContactAvatar avatar;
qDebug()<<"Profile image URL = "<<url.toString();
avatar.setImageUrl(url);
QVariant avatarVar = QVariant::fromValue(avatar);
contact.setValue("Avatar",avatarVar);
list.append(contact);
}
#endif
qDebug()<<"list count = "<<list.count();
aResult->setValue(list);
aRetType = SmfRequestComplete;
error = SmfPluginErrNone;
}
else if(aOperation==SmfContactGetGroups)
{
response.remove(0, 14);
response.chop(1);
bool ok;
qDebug()<<"Before Parser--";
SmfPluginUtil util;
QVariant result = util.parse(response, &ok);
if (!ok)
{
qDebug()<<"An error occurred during json parsing";
aRetType = SmfRequestError;
return SmfPluginErrParsingFailed;
//return 0;
}
QVariantMap map1 = result.toMap();