7#include "shareserviceurlmanager.h"
9#include "pimcommon_debug.h"
11#include <KLocalizedString>
12#include <QDesktopServices>
18class PimCommon::ShareServiceUrlManagerPrivate
26 [[nodiscard]]
QIcon typeToIcon(ShareServiceUrlManager::ServiceType type)
const;
27 [[nodiscard]]
QString typeToI18n(ShareServiceUrlManager::ServiceType type)
const;
28 void initializeMenu();
33void ShareServiceUrlManagerPrivate::initializeMenu()
36 for (
int i = 0; i < ShareServiceUrlManager::ServiceEndType; ++i) {
37 const auto type =
static_cast<ShareServiceUrlManager::ServiceType
>(i);
38 auto action =
new QAction(
i18nc(
"@action:inmenu Share On...",
"%1", typeToI18n(type)), q);
40 const QIcon icon = typeToIcon(type);
42 action->setIcon(icon);
49QIcon ShareServiceUrlManagerPrivate::typeToIcon(ShareServiceUrlManager::ServiceType type)
const
53 case ShareServiceUrlManager::Fbook:
56 case ShareServiceUrlManager::Twitter:
59 case ShareServiceUrlManager::MailTo:
62 case ShareServiceUrlManager::LinkedIn:
64 case ShareServiceUrlManager::Evernote:
66 case ShareServiceUrlManager::Pocket:
68 case ShareServiceUrlManager::LiveJournal:
70 case ShareServiceUrlManager::ServiceEndType:
71 qCWarning(PIMCOMMON_LOG) <<
"icon for unknown type requested. It's a bug.";
78QString ShareServiceUrlManagerPrivate::typeToI18n(ShareServiceUrlManager::ServiceType type)
const
82 case ShareServiceUrlManager::Fbook:
83 str =
i18n(
"Facebook");
85 case ShareServiceUrlManager::Twitter:
86 str =
i18n(
"Twitter");
88 case ShareServiceUrlManager::MailTo:
91 case ShareServiceUrlManager::LinkedIn:
92 str =
i18n(
"LinkedIn");
94 case ShareServiceUrlManager::Evernote:
95 str =
i18n(
"Evernote");
97 case ShareServiceUrlManager::Pocket:
100 case ShareServiceUrlManager::LiveJournal:
101 str =
i18n(
"LiveJournal");
103 case ShareServiceUrlManager::ServiceEndType:
104 qCWarning(PIMCOMMON_LOG) <<
"text for unknown type requested. It's a bug.";
110ShareServiceUrlManager::ShareServiceUrlManager(
QObject *parent)
112 , d(new
PimCommon::ShareServiceUrlManagerPrivate(this))
117ShareServiceUrlManager::~ShareServiceUrlManager() =
default;
124void ShareServiceUrlManager::slotSelectServiceUrl(
QAction *act)
127 const auto type = act->
data().
value<PimCommon::ShareServiceUrlManager::ServiceType>();
128 Q_EMIT serviceUrlSelected(type);
132QUrl ShareServiceUrlManager::generateServiceUrl(
const QString &link,
const QString &title, ServiceType type)
135 if (
link.isEmpty()) {
140 url.
setUrl(QStringLiteral(
"https://www.facebook.com/sharer.php"));
148 url.
setUrl(QStringLiteral(
"https://twitter.com/share"));
156 url.
setUrl(QStringLiteral(
"mailto:"));
158 urlQuery.
addQueryItem(QStringLiteral(
"subject"), title);
164 url.
setUrl(QStringLiteral(
"http://www.linkedin.com/shareArticle"));
166 urlQuery.
addQueryItem(QStringLiteral(
"mini"), QStringLiteral(
"true"));
173 url.
setUrl(QStringLiteral(
"https://www.evernote.com/clip.action"));
181 url.
setUrl(QStringLiteral(
"https://getpocket.com/save"));
189 url.
setUrl(QStringLiteral(
"http://www.livejournal.com/update.bml"));
192 urlQuery.
addQueryItem(QStringLiteral(
"subject"), title);
202void ShareServiceUrlManager::openUrl(
const QUrl &url)
207 qCDebug(PIMCOMMON_LOG) <<
"url is invalid.";
211#include "moc_shareserviceurlmanager.cpp"
The ShareServiceUrlManager class.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
Type type(const QSqlDatabase &db)
KIOCORE_EXPORT CopyJob * link(const QList< QUrl > &src, const QUrl &destDir, JobFlags flags=DefaultFlags)
QVariant data() const const
bool openUrl(const QUrl &url)
QIcon fromTheme(const QString &name)
bool isNull() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool isValid() const const
void setQuery(const QString &query, ParsingMode mode)
void setUrl(const QString &url, ParsingMode parsingMode)
void addQueryItem(const QString &key, const QString &value)
QVariant fromValue(T &&value)