- if (embed)
- {
- if (!item->data(Qt::UserRole+1).toString().isEmpty())
- {
- content.setAttribute("base64",item->data(Qt::UserRole+1).toString());
- } else if (!item->data(Qt::UserRole).toString().isEmpty() )
- {
- content.setAttribute("base64",fileToByteArray( item->data(Qt::UserRole).toString() ).toBase64().data());
- }
- content.removeAttribute("url");
- }else{
- // save for project files to disk
- QString base64=item->data(Qt::UserRole+1).toString();
- if (!base64.isEmpty()){
- QString titlePath;
- if (!m_projectPath.isEmpty())
- {
- titlePath=m_projectPath;
- }else{
- titlePath="/tmp/titles";
- }
- QString filename=titlePath+QString( QCryptographicHash::hash(base64.toAscii(), QCryptographicHash::Md5).toHex().append(".titlepart"));
- KStandardDirs::makeDir(titlePath);
- QFile f(filename);
- if (f.open(QIODevice::WriteOnly)){
- f.write(QByteArray::fromBase64(base64.toAscii()) ) ;
- f.close();
- content.setAttribute("url",filename);
- content.removeAttribute("base64");
- }
-
- } else {
- return 1;
- }
+ if (embed) {
+ if (!item->data(Qt::UserRole + 1).toString().isEmpty()) {
+ content.setAttribute("base64", item->data(Qt::UserRole + 1).toString());
+ } else if (!item->data(Qt::UserRole).toString().isEmpty()) {
+ content.setAttribute("base64", fileToByteArray(item->data(Qt::UserRole).toString()).toBase64().data());
+ }
+ content.removeAttribute("url");
+ } else {
+ // save for project files to disk
+ QString base64 = item->data(Qt::UserRole + 1).toString();
+ if (!base64.isEmpty()) {
+ QString titlePath;
+ if (!m_projectPath.isEmpty()) {
+ titlePath = m_projectPath;
+ } else {
+ titlePath = "/tmp/titles";
+ }
+ QString filename = extractBase64Image(titlePath, base64);
+ if (!filename.isEmpty()) {
+ content.setAttribute("url", filename);
+ content.removeAttribute("base64");