// Loads all mime types as properties into the model. void MimeTypeFilterModel::reload() { mList.append(ContentFilterProperty(tr( "All" ), QContentFilter(), QIcon(":icon/stop"))); addProperty(tr( "Text" ),QMimeType("text/*"), QIcon(":icon/txt")); addProperty(tr( "Audio" ),QMimeType("audio/*"), QIcon(":icon/sound")); addProperty(tr( "Image" ),QMimeType("image/*"), QIcon(":icon/camera")); addProperty(tr( "Video" ),QMimeType("video/*"), QIcon(":icon/multimedia")); }
QMimeType KFileItem::determineMimeType() const { if (!d) { return QMimeType(); } if (!d->m_mimeType.isValid() || !d->m_bMimeTypeKnown) { QMimeDatabase db; if (isDir()) { d->m_mimeType = db.mimeTypeForName(QStringLiteral("inode/directory")); } else { bool isLocalUrl; const QUrl url = mostLocalUrl(&isLocalUrl); d->m_mimeType = db.mimeTypeForUrl(url); // was: d->m_mimeType = KMimeType::findByUrl( url, d->m_fileMode, isLocalUrl ); // => we are no longer using d->m_fileMode for remote URLs. Q_ASSERT(d->m_mimeType.isValid()); //qDebug() << d << "finding final mimetype for" << url << ":" << d->m_mimeType.name(); } d->m_bMimeTypeKnown = true; } if (d->m_delayedMimeTypes) { // if we delayed getting the iconName up till now, this is the right point in time to do so d->m_delayedMimeTypes = false; d->m_useIconNameCache = false; (void)iconName(); } return d->m_mimeType; }
bool ExifContentPlugin::installContent( const QString &filePath, QContent *content ) { bool success = false; QExifImageHeader exif; if( exif.loadFromJpeg( filePath ) ) { QDateTime date = exif.value(QExifImageHeader::DateTime).toDateTime(); if (date.isValid()) { content->setProperty(QLatin1String("CreationDate"), date.toString(Qt::ISODate)); } QString string = exif.value( QExifImageHeader::ImageDescription ).toString(); if( !string.isEmpty() ) content->setProperty( QContent::Description, string ); string = exif.value( QExifImageHeader::Artist ).toString(); if( !string.isEmpty() ) content->setProperty( QContent::Artist, string ); content->setName( QFileInfo( filePath ).baseName() ); content->setType( QMimeType( filePath ).id() ); content->setFile( filePath ); success = true; } return success; }
void CameraMainWindow::moveToContact() { /*if ( cur_thumb >= 0 ) { QtopiaServiceRequest e("Contacts","setContactImage(QString)"); e << picturefile[cur_thumb].fileName(); e.send(); }*/ if ( cur_thumb >= 0 ) { // Find a suitable QDS service QDSServices services( QString( "image/jpeg" ) ); // Select the first service to create the action (assuming there // is only be one address book type application on the device) QDSAction action( services.findFirst( "setContactImage" ) ); if ( !action.isValid() ) { qWarning( "Camera found no service to set the contact image" ); return; } QFile pixFile(picturefile[cur_thumb].fileName()); QDSData pixData(pixFile, QMimeType( "image/jpeg" ) ); if ( action.exec( pixData ) != QDSAction::Complete ) { qWarning( "Camera unable to set contact image" ); return; } } }
/*! Dispatch the SMS datagram \a msg according to its SMS port number or WAP Push MIME type. This is used by telephony services that accept incoming SMS messages to dispatch them according to the installed services. Returns true if the message was dispatched, or false if no service exists that can handle the message. See the documentation for QSMSMessage::destinationPort() for more information on how WAP push messages and SMS datagrams are dispatched. \sa QSMSMessage::destinationPort() */ bool QTelephonyService::dispatchDatagram( const QSMSMessage& msg ) { QString chan, type; QDSServiceInfo info; QByteArray payload; QByteArray raw; // If the message does not have a port number, then it isn't a datagram. int port = msg.destinationPort(); if ( port == -1 ) return dispatchFlashMessage( msg ); // Recognise port numbers that may contain WAP push datagrams. // We want to check the content type to see if we have a // specialised handler for it before dispatching by port number. if ( port == 2948 || port == 49999 ) { type = QWspPush::quickContentType( msg.applicationData() ); qLog(Modem) << "WAP push message of type " << type; QDSServices services( type, QString(), QStringList() << "push" ); if ( !services.isEmpty() ) { info = services.first(); QByteArray a = msg.applicationData(); QBuffer pushpdu(&a); pushpdu.open(QIODevice::ReadOnly); QWspPduDecoder decoder(&pushpdu); QWspPush push = decoder.decodePush(); payload = push.data(); } } // See if we have a registered service for this port number. if ( !info.isValid() ) { qLog(Modem) << "SMS datagram on port " << port; type = "application/x-smsapp-" + QString::number(port); QDSServices services( type, QString(), QStringList() << "push" ); if ( !services.isEmpty() ) { info = services.first(); payload = msg.applicationData(); } else { return dispatchFlashMessage( msg ); } } // Pack the entire SMS message into a raw datastream, to be sent // along with the message as auxillary data. This allows programs // that need the full SMS/WAP headers to access them. { QDataStream stream ( &raw, QIODevice::WriteOnly | QIODevice::Append ); stream << msg; } // Send the datagram to the specified QDS service for processing. QDSAction action( info ); action.invoke( QDSData( payload, QMimeType( type ) ), raw ); // The datagram has been dispatched. return true; }
/*! Sets the Type property to \a type. The property will not be written to the backing store until commit() is called. \sa name() */ void QContent::setType(const QString& type) { Q_ASSERT( d.constData() != NULL ); if( d.constData() == NULL ) return; d->setMimeType( QMimeType( type ) ); }
void KFileItem::refreshMimeType() { if (!d) { return; } d->m_mimeType = QMimeType(); d->m_bMimeTypeKnown = false; d->m_iconName.clear(); }
/*! Constructs an action request for a service with no request data. The service responding to the request is provided in \a serviceInfo and the channel for responding to the client is provided in \a channel. The request is attached to \a parent. */ QDSActionRequest::QDSActionRequest( const QDSServiceInfo& serviceInfo, const QString& channel, QObject* parent ) : QObject( parent ), d( 0 ) { d = new QDSActionRequestPrivate( serviceInfo, QDSData(), QByteArray(), channel ); if ( !d->mServiceInfo.supportsRequestDataType( QMimeType(QString()) ) ) respond( QString( tr( "request didn't contain data" ) ) ); }
void EmailPropertySetter::setAttachment(const QString& s) { QFileInfo fi( s ); QMailMessageContentDisposition disposition(QMailMessageContentDisposition::Attachment); disposition.setFilename( fi.absoluteFilePath().toLatin1() ); QMailMessageContentType type( QMimeType( fi.absoluteFilePath() ).id().toLatin1() ); type.setName(fi.baseName().toLatin1()); QMailMessagePart attachmentPart; attachmentPart.setBody( QMailMessageBody::fromFile(fi.absoluteFilePath(), type, QMailMessageBody::Base64, QMailMessageBody::RequiresEncoding) ); attachmentPart.setContentDisposition(disposition); target.appendPart( attachmentPart ); }
// Check for and dispatch flash sms messages. static bool dispatchFlashMessage( const QSMSMessage& msg ) { if ( msg.messageClass() != 0 ) return false; qLog(Modem) << "SMS flash message"; QString type = "application/x-sms-flash"; QDSServices services( type, QString(), QStringList() << "push" ); if ( !services.isEmpty() ) { QDSAction action( services.first() ); QByteArray payload; { QDataStream stream ( &payload, QIODevice::WriteOnly | QIODevice::Append ); stream << msg; } action.invoke( QDSData( payload, QMimeType( type ) ) ); return true; } else { return false; } }
QStringList ExifContentPlugin::keys() const { return QMimeType( QLatin1String( "image/jpeg" ) ).extensions(); }
QStringList ThreeGPPContentPlugin::keys() const { return QMimeType( QLatin1String( "audio/3gpp" )).extensions(); }
bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString *errorMessage) { QMimeTypePrivate data; int priority = 50; QStack<QMimeMagicRule *> currentRules; // stack for the nesting of rules QList<QMimeMagicRule> rules; // toplevel rules QXmlStreamReader reader(dev); ParseState ps = ParseBeginning; QXmlStreamAttributes atts; while (!reader.atEnd()) { switch (reader.readNext()) { case QXmlStreamReader::StartElement: ps = nextState(ps, reader.name()); atts = reader.attributes(); switch (ps) { case ParseMimeType: { // start parsing a MIME type name const QString name = atts.value(QLatin1String(mimeTypeAttributeC)).toString(); if (name.isEmpty()) { reader.raiseError(QString::fromLatin1("Missing '%1'-attribute").arg(QString::fromLatin1(mimeTypeAttributeC))); } else { data.name = name; } } break; case ParseGenericIcon: data.genericIconName = atts.value(QLatin1String(nameAttributeC)).toString(); break; case ParseIcon: data.iconName = atts.value(QLatin1String(nameAttributeC)).toString(); break; case ParseGlobPattern: { const QString pattern = atts.value(QLatin1String(patternAttributeC)).toString(); unsigned weight = atts.value(QLatin1String(weightAttributeC)).toString().toInt(); const bool caseSensitive = atts.value(QLatin1String(caseSensitiveAttributeC)).toString() == QLatin1String("true"); if (weight == 0) weight = QMimeGlobPattern::DefaultWeight; Q_ASSERT(!data.name.isEmpty()); const QMimeGlobPattern glob(pattern, data.name, weight, caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive); if (!process(glob, errorMessage)) // for actual glob matching return false; data.addGlobPattern(pattern); // just for QMimeType::globPatterns() } break; case ParseSubClass: { const QString inheritsFrom = atts.value(QLatin1String(mimeTypeAttributeC)).toString(); if (!inheritsFrom.isEmpty()) processParent(data.name, inheritsFrom); } break; case ParseComment: { // comments have locale attributes. We want the default, English one QString locale = atts.value(QLatin1String(localeAttributeC)).toString(); const QString comment = reader.readElementText(); if (locale.isEmpty()) locale = QString::fromLatin1("en_US"); data.localeComments.insert(locale, comment); } break; case ParseAlias: { const QString alias = atts.value(QLatin1String(mimeTypeAttributeC)).toString(); if (!alias.isEmpty()) processAlias(alias, data.name); } break; case ParseMagic: { priority = 50; const QString priorityS = atts.value(QLatin1String(priorityAttributeC)).toString(); if (!priorityS.isEmpty()) { if (!parseNumber(priorityS, &priority, errorMessage)) return false; } currentRules.clear(); //qDebug() << "MAGIC start for mimetype" << data.name; } break; case ParseMagicMatchRule: { QMimeMagicRule *rule = 0; if (!createMagicMatchRule(atts, errorMessage, rule)) return false; QList<QMimeMagicRule> *ruleList; if (currentRules.isEmpty()) ruleList = &rules; else // nest this rule into the proper parent ruleList = ¤tRules.top()->m_subMatches; ruleList->append(*rule); //qDebug() << " MATCH added. Stack size was" << currentRules.size(); currentRules.push(&ruleList->last()); delete rule; break; } case ParseError: reader.raiseError(QString::fromLatin1("Unexpected element <%1>"). arg(reader.name().toString())); break; default: break; } break; // continue switch QXmlStreamReader::Token... case QXmlStreamReader::EndElement: // Finished element { const QStringRef elementName = reader.name(); if (elementName == QLatin1String(mimeTypeTagC)) { if (!process(QMimeType(data), errorMessage)) return false; data.clear(); } else if (elementName == QLatin1String(matchTagC)) { // Closing a <match> tag, pop stack currentRules.pop(); //qDebug() << " MATCH closed. Stack size is now" << currentRules.size(); } else if (elementName == QLatin1String(magicTagC)) { //qDebug() << "MAGIC ended, we got" << rules.count() << "rules, with prio" << priority; // Finished a <magic> sequence QMimeMagicRuleMatcher ruleMatcher(data.name, priority); ruleMatcher.addRules(rules); processMagicMatcher(ruleMatcher); rules.clear(); } break; } default: break; } } if (reader.hasError()) { if (errorMessage) *errorMessage = QString::fromLatin1("An error has been encountered at line %1 of %2: %3:").arg(reader.lineNumber()).arg(fileName, reader.errorString()); return false; } return true; }
QMailMessage EmailComposerInterface::message() const { QMailMessage mail; if( isEmpty() ) return mail; QList<AttachmentItem*> attachments = m_composer->addAttDialog()->attachedFiles(); QString messageText( m_composer->toPlainText() ); QMailMessageContentType type("text/plain; charset=UTF-8"); if(attachments.isEmpty()) { mail.setBody( QMailMessageBody::fromData( messageText, type, QMailMessageBody::Base64 ) ); } else { QMailMessagePart textPart; textPart.setBody(QMailMessageBody::fromData(messageText.toUtf8(), type, QMailMessageBody::Base64)); mail.setMultipartType(QMailMessagePartContainer::MultipartMixed); mail.appendPart(textPart); foreach (AttachmentItem* current, attachments) { const QContent& doc( current->document() ); QString fileName( doc.fileName() ); QFileInfo fi( fileName ); QString partName( fi.fileName() ); fileName = fi.absoluteFilePath(); QString content( doc.type() ); if (content.isEmpty()) content = QMimeType( fileName ).id(); QMailMessageContentType type( content.toLatin1() ); type.setName( partName.toLatin1() ); QMailMessageContentDisposition disposition( QMailMessageContentDisposition::Attachment ); disposition.setFilename( partName.toLatin1() ); QMailMessagePart part; if ((current->action() != QMailMessage::LinkToAttachments) || (fileName.startsWith(Qtopia::tempDir()))) { // This file is temporary - extract the data and create a part from that QFile dataFile(fileName); if (dataFile.open(QIODevice::ReadOnly)) { QDataStream in(&dataFile); part = QMailMessagePart::fromStream(in, disposition, type, QMailMessageBody::Base64, QMailMessageBody::RequiresEncoding); } else { qWarning() << "Unable to open temporary file:" << fileName; } } else { part = QMailMessagePart::fromFile(fileName, disposition, type, QMailMessageBody::Base64, QMailMessageBody::RequiresEncoding); } mail.appendPart(part); } } mail.setMessageType( QMailMessage::Email ); return mail; }
void CameraMainWindow::takePhotoNow() { QImage img = camera->videocaptureview->image(); if ( snapRequest != 0 ) { // Rescale the image and pop it into a QDSData object QImage scaledimg = img.scaled( snap_max, Qt::KeepAspectRatio, Qt::SmoothTransformation); QByteArray savedImageData; { QDataStream stream( &savedImageData, QIODevice::WriteOnly ); stream << QPixmap::fromImage( scaledimg ); } QDSData snappedImage( savedImageData, QMimeType( "image/x-qpixmap" ) ); // Send response with the data snapRequest->respond( snappedImage ); // Reset snap mode setSnapMode( false ); delete snapRequest; snapRequest = 0; // Finished serving QDS request so close the application close(); hideWaitScreen(); } else { showWaitScreen(); QContent f; QList<QString> c; f.setType("image/jpeg"); f.setName(tr("Photo, %1","date") .arg(QTimeString::localYMDHMS(QDateTime::currentDateTime(),QTimeString::Short))); f.setMedia( settings->location->documentPath() ); c.append(camcat); f.setCategories(c); QIODevice* contentDevice = f.open(QIODevice::WriteOnly); if (contentDevice != 0) { QImage temp = img.convertToFormat(QImage::Format_RGB32); temp.save(contentDevice, "JPEG", pquality); contentDevice->close(); f.commit(); pushThumb(f, img); hideWaitScreen(); } else { QString errorText = f.errorString(); if (errorText.isEmpty()) errorText = tr("Unknown error"); QMessageBox::warning(0, tr("Error saving photo"), tr("Could not save photo: %1").arg(errorText)); } } preview(); }