Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/email/emailplugin.cpp
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | 37 | public: | |||
---|---|---|---|---|---|
79 | } | 79 | } | ||
80 | 80 | | |||
81 | void launchMailto() | 81 | void launchMailto() | ||
82 | { | 82 | { | ||
83 | const auto urls = data().value(QStringLiteral("urls")).toArray(); | 83 | const auto urls = data().value(QStringLiteral("urls")).toArray(); | ||
84 | 84 | | |||
85 | QUrlQuery query; | 85 | QUrlQuery query; | ||
86 | for (const auto &att : urls) { | 86 | for (const auto &att : urls) { | ||
87 | QUrl url(att.toString()); | ||||
88 | if (url.isLocalFile()) { | ||||
87 | query.addQueryItem(QStringLiteral("attachment"), att.toString()); | 89 | query.addQueryItem(QStringLiteral("attachment"), att.toString()); | ||
90 | } else { | ||||
91 | query.addQueryItem(QStringLiteral("body"), att.toString()); | ||||
92 | query.addQueryItem(QStringLiteral("subject"), data().value(QStringLiteral("title")).toString()); | ||||
93 | } | ||||
88 | } | 94 | } | ||
89 | QUrl url; | 95 | QUrl url; | ||
90 | url.setScheme(QStringLiteral("mailto")); | 96 | url.setScheme(QStringLiteral("mailto")); | ||
91 | url.setQuery(query); | 97 | url.setQuery(query); | ||
92 | if (!QDesktopServices::openUrl(url)) { | 98 | if (!QDesktopServices::openUrl(url)) { | ||
93 | setError(KJob::UserDefinedError); | 99 | setError(KJob::UserDefinedError); | ||
94 | setErrorText(i18n("Failed to launch email client")); | 100 | setErrorText(i18n("Failed to launch email client")); | ||
95 | } | 101 | } | ||
96 | emitResult(); | 102 | emitResult(); | ||
97 | } | 103 | } | ||
98 | 104 | | |||
99 | void launchThunderbird() | 105 | void launchThunderbird() | ||
100 | { | 106 | { | ||
101 | // thunderbird -compose "attachment='file:///att1','file:///att2'" | 107 | // thunderbird -compose "attachment='file:///att1','file:///att2'" | ||
102 | 108 | | |||
103 | const auto tb = QStandardPaths::findExecutable(QStringLiteral("thunderbird")); | 109 | const auto tb = QStandardPaths::findExecutable(QStringLiteral("thunderbird")); | ||
104 | if (tb.isEmpty()) { | 110 | if (tb.isEmpty()) { | ||
105 | launchMailto(); | 111 | launchMailto(); | ||
106 | return; | 112 | return; | ||
107 | } | 113 | } | ||
108 | 114 | | |||
109 | const auto urls = data().value(QStringLiteral("urls")).toArray(); | 115 | const auto urls = data().value(QStringLiteral("urls")).toArray(); | ||
110 | QStringList attachments; | 116 | QStringList attachments; | ||
117 | QStringList args = QStringList{ QStringLiteral("-compose")}; | ||||
118 | QString message; | ||||
111 | for (const auto &att : urls) { | 119 | for (const auto &att : urls) { | ||
120 | QUrl url(att.toString()); | ||||
121 | if (url.isLocalFile()) { | ||||
112 | attachments.push_back(att.toString()); | 122 | attachments.push_back(att.toString()); | ||
123 | } else { | ||||
124 | message += QStringLiteral("body='%1',subject='%2',").arg(url.toString()).arg(data().value(QStringLiteral("title")).toString()); | ||||
113 | } | 125 | } | ||
114 | const auto args = QStringList{ QStringLiteral("-compose"), | 126 | } | ||
115 | QStringLiteral("attachment='%1'").arg(attachments.join(QStringLiteral(","))) }; | 127 | | ||
128 | message +=(QStringLiteral("attachment='%1'").arg(attachments.join(QStringLiteral(",")))); | ||||
129 | args.append(message); | ||||
130 | | ||||
116 | if (!QProcess::startDetached(tb, args)) { | 131 | if (!QProcess::startDetached(tb, args)) { | ||
117 | setError(KJob::UserDefinedError); | 132 | setError(KJob::UserDefinedError); | ||
118 | setErrorText(i18n("Failed to launch email client")); | 133 | setErrorText(i18n("Failed to launch email client")); | ||
119 | } | 134 | } | ||
120 | emitResult(); | 135 | emitResult(); | ||
121 | } | 136 | } | ||
122 | 137 | | |||
123 | }; | 138 | }; | ||
Show All 20 Lines |