diff --git a/autotests/impptest.h b/autotests/impptest.h --- a/autotests/impptest.h +++ b/autotests/impptest.h @@ -47,6 +47,8 @@ void shouldExportWithParameters(); void shouldShouldNotExportTwiceServiceType(); + + void testProtocolInformation(); }; #endif // IMPPTEST_H diff --git a/autotests/impptest.cpp b/autotests/impptest.cpp --- a/autotests/impptest.cpp +++ b/autotests/impptest.cpp @@ -328,4 +328,17 @@ QCOMPARE(ba, expected); } +void ImppTest::testProtocolInformation() +{ + const auto types = KContacts::Impp::serviceTypes(); + QVERIFY(types.size() > 10); + QVERIFY(types.contains(QLatin1String("xmpp"))); + + for (const auto &type : types) { + QVERIFY(!KContacts::Impp::serviceLabel(type).isEmpty()); + } + + QCOMPARE(KContacts::Impp::serviceIcon(QStringLiteral("xmpp")), QLatin1String("im-jabber")); +} + QTEST_MAIN(ImppTest) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -112,6 +112,7 @@ add_subdirectory(converter) add_subdirectory(generator) +add_subdirectory(improtocols) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kcontacts_export.h diff --git a/src/impp.h b/src/impp.h --- a/src/impp.h +++ b/src/impp.h @@ -100,6 +100,23 @@ Q_REQUIRED_RESULT static QString typeToString(ImppType type); + /** + * Returns a translated name of the given IM service. + * @since 5.12 + */ + static QString serviceLabel(const QString &serviceType); + /** + * Returns an icon name representing the given IM service. + * @since 5.12 + */ + static QString serviceIcon(const QString &serviceType); + /** + * List all known service types. + * Don't use these strings directly for display, instead use serviceLabel and serviceIcon. + * @since 5.12 + */ + static QVector serviceTypes(); + private: class Private; QSharedDataPointer d; diff --git a/src/impp.cpp b/src/impp.cpp --- a/src/impp.cpp +++ b/src/impp.cpp @@ -19,11 +19,15 @@ */ #include "impp.h" +#include "kcontacts_debug.h" + +#include +#include +#include #include +#include #include -#include -#include "kcontacts_debug.h" using namespace KContacts; @@ -209,3 +213,37 @@ impp.d->type = static_cast(i); return s; } + +QString Impp::serviceLabel(const QString &serviceType) +{ + const auto path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kf5/kcontacts/improtocols/") + serviceType + QStringLiteral(".desktop")); + KDesktopFile df(path); + return df.readName(); +} + +QString Impp::serviceIcon(const QString &serviceType) +{ + const auto path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kf5/kcontacts/improtocols/") + serviceType + QStringLiteral(".desktop")); + KDesktopFile df(path); + return df.readIcon(); +} + +QVector Impp::serviceTypes() +{ + QVector types; + const auto paths = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kf5/kcontacts/improtocols"), QStandardPaths::LocateDirectory); + for (const auto &path : paths) { + QDirIterator it(path, QDir::Files); + while (it.hasNext()) { + it.next(); + const auto fi = it.fileInfo(); + if (fi.suffix() == QLatin1String("desktop")) { + types.push_back(fi.baseName()); + } + } + } + + std::sort(types.begin(), types.end()); + types.erase(std::unique(types.begin(), types.end()), types.end()); + return types; +} diff --git a/src/improtocols/CMakeLists.txt b/src/improtocols/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/src/improtocols/CMakeLists.txt @@ -0,0 +1,19 @@ +install(FILES + aim.desktop + facebook.desktop + gg.desktop + googletalk.desktop + groupwise.desktop + icq.desktop + irc.desktop + meanwhile.desktop + msn.desktop + qq.desktop + sip.desktop + skype.desktop + sms.desktop + twitter.desktop + xmpp.desktop + ymsgr.desktop + DESTINATION ${KDE_INSTALL_DATADIR_KF5}/kcontacts/improtocols +) diff --git a/src/improtocols/NOTE b/src/improtocols/NOTE new file mode 100644 --- /dev/null +++ b/src/improtocols/NOTE @@ -0,0 +1 @@ +File names in here should match the corresponding URI scheme. diff --git a/src/improtocols/aim.desktop b/src/improtocols/aim.desktop new file mode 100644 --- /dev/null +++ b/src/improtocols/aim.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Service +Icon=im-aim +Comment=AIM Protocol +Name=AIM diff --git a/src/improtocols/facebook.desktop b/src/improtocols/facebook.desktop new file mode 100644 --- /dev/null +++ b/src/improtocols/facebook.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Service +Icon=im-facebook +Comment=Facebook Protocol +Name=Facebook diff --git a/src/improtocols/gg.desktop b/src/improtocols/gg.desktop new file mode 100644 --- /dev/null +++ b/src/improtocols/gg.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Service +Icon=im-gadugadu +Comment=Gadu-Gadu Protocol +Name=Gadu-Gadu diff --git a/src/improtocols/googletalk.desktop b/src/improtocols/googletalk.desktop new file mode 100644 --- /dev/null +++ b/src/improtocols/googletalk.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Service +Icon=im-google +Comment=Google Talk +Name=Google Talk diff --git a/src/improtocols/groupwise.desktop b/src/improtocols/groupwise.desktop new file mode 100644 --- /dev/null +++ b/src/improtocols/groupwise.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Service +Icon=im-groupwise +Comment=Novell GroupWise Messenger +Name=GroupWise diff --git a/src/improtocols/icq.desktop b/src/improtocols/icq.desktop new file mode 100644 --- /dev/null +++ b/src/improtocols/icq.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Service +Icon=im-icq +Comment=ICQ Protocol +Name=ICQ diff --git a/src/improtocols/irc.desktop b/src/improtocols/irc.desktop new file mode 100644 --- /dev/null +++ b/src/improtocols/irc.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Service +Icon=im-irc +Comment=Internet Relay Chat +Name=IRC diff --git a/src/improtocols/meanwhile.desktop b/src/improtocols/meanwhile.desktop new file mode 100644 --- /dev/null +++ b/src/improtocols/meanwhile.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Service +Icon=im-meanwhile +Comment=Meanwhile Protocol +Name=Meanwhile diff --git a/src/improtocols/msn.desktop b/src/improtocols/msn.desktop new file mode 100644 --- /dev/null +++ b/src/improtocols/msn.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Service +Icon=im-msn +Comment=MSN Messenger +Name=MSN Messenger diff --git a/src/improtocols/qq.desktop b/src/improtocols/qq.desktop new file mode 100644 --- /dev/null +++ b/src/improtocols/qq.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Service +Icon=im-qq +Comment=Tencent QQ Messaging +Name=QQ diff --git a/src/improtocols/sip.desktop b/src/improtocols/sip.desktop new file mode 100644 --- /dev/null +++ b/src/improtocols/sip.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Service +Icon=internet-telephone +Comment=Session Initiation Protocol +Name=SIP diff --git a/src/improtocols/skype.desktop b/src/improtocols/skype.desktop new file mode 100644 --- /dev/null +++ b/src/improtocols/skype.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Service +Icon=im-skype +Comment=Skype Internet Telephony +Name=Skype diff --git a/src/improtocols/sms.desktop b/src/improtocols/sms.desktop new file mode 100644 --- /dev/null +++ b/src/improtocols/sms.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Service +Icon=im-sms +Comment=SMS Protocol +Name=SMS diff --git a/src/improtocols/twitter.desktop b/src/improtocols/twitter.desktop new file mode 100644 --- /dev/null +++ b/src/improtocols/twitter.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Service +Icon=im-twitter +Comment=Twitter Protocol +Name=Twitter diff --git a/src/improtocols/xmpp.desktop b/src/improtocols/xmpp.desktop new file mode 100644 --- /dev/null +++ b/src/improtocols/xmpp.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Service +Icon=im-jabber +Comment=Jabber Protocol +Name=Jabber diff --git a/src/improtocols/ymsgr.desktop b/src/improtocols/ymsgr.desktop new file mode 100644 --- /dev/null +++ b/src/improtocols/ymsgr.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Service +Icon=im-yahoo +Comment=Yahoo Protocol +Name=Yahoo