+ m_width = width;
+ m_height = height;
+}
+
+int TitleDocument::base64ToUrl(QGraphicsItem* item, QDomElement& content, bool embed)
+{
+ 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");
+ }
+
+ } else {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+
+//static
+const QString TitleDocument::extractBase64Image(const QString &titlePath, const QString &data)
+{
+ QString filename = titlePath + QString(QCryptographicHash::hash(data.toAscii(), QCryptographicHash::Md5).toHex().append(".titlepart"));
+ KStandardDirs::makeDir(titlePath);
+ QFile f(filename);
+ if (f.open(QIODevice::WriteOnly)) {
+ f.write(QByteArray::fromBase64(data.toAscii())) ;
+ f.close();
+ return filename;
+ }
+ return QString();