| 3039 | |
| 3040 | |
| 3041 | void NBrowserWindow::attachFileSelected(QString filename) { |
| 3042 | // Read in the file |
| 3043 | QFile file(filename); |
| 3044 | |
| 3045 | // Save prior path for future use |
| 3046 | QFileInfo fileInfo(file); |
| 3047 | attachFilePath = fileInfo.path(); |
| 3048 | |
| 3049 | file.open(QIODevice::ReadOnly); |
| 3050 | QByteArray ba = file.readAll(); |
| 3051 | file.close(); |
| 3052 | |
| 3053 | QString script_start = "document.execCommand('insertHTML', false, '"; |
| 3054 | QString script_end = "');"; |
| 3055 | |
| 3056 | MimeReference mimeRef; |
| 3057 | QString extension = filename; |
| 3058 | int endPos = filename.lastIndexOf("."); |
| 3059 | if (endPos != -1) |
| 3060 | extension = extension.mid(endPos); |
| 3061 | QString mime = mimeRef.getMimeFromExtension(extension); |
| 3062 | Resource newRes; |
| 3063 | bool attachment = true; |
| 3064 | if (mime == "application/pdf" || mime.startsWith("image/")) |
| 3065 | attachment = false; |
| 3066 | qint32 rlid = createResource(newRes, 0, ba, mime, attachment, QFileInfo(filename).fileName()); |
| 3067 | QByteArray hash; |
| 3068 | if (newRes.data.isSet()) { |
| 3069 | Data d = newRes.data; |
| 3070 | if (d.bodyHash.isSet()) |
| 3071 | hash = d.bodyHash; |
| 3072 | } |
| 3073 | if (rlid <= 0) |
| 3074 | return; |
| 3075 | |
| 3076 | // If we have an image, then insert it. |
| 3077 | if (mime.startsWith("image", Qt::CaseInsensitive)) { |
| 3078 | |
| 3079 | // The resource is done, now we need to add it to the |
| 3080 | // note body |
| 3081 | QString g = QString::number(rlid)+extension; |
| 3082 | QString path = global.fileManager.getDbaDirPath() + g; |
| 3083 | |
| 3084 | // do the actual insert into the note |
| 3085 | QString buffer; |
| 3086 | QByteArray hash = ""; |
| 3087 | if (newRes.data.isSet()) { |
| 3088 | Data d= newRes.data; |
| 3089 | if (d.bodyHash.isSet()) |
| 3090 | hash = d.bodyHash; |
| 3091 | } |
| 3092 | buffer.append("<img src=\"file://"); |
| 3093 | #ifdef _WIN32 |
| 3094 | buffer.append("/"); |
| 3095 | #endif |
| 3096 | buffer.append(path); |
| 3097 | buffer.append("\" type=\""); |
| 3098 | buffer.append(mime); |
nothing calls this directly
no test coverage detected