File indexing completed on 2023-05-30 11:40:08
0001 /* 0002 * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/> 0003 * @author Andre Moreira Magalhaes <andre.magalhaes@collabora.co.uk> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Lesser General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2.1 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Lesser General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Lesser General Public 0016 * License along with this library; if not, write to the Free Software 0017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 0018 */ 0019 0020 #include <KAboutData> 0021 #include <KLocalizedString> 0022 0023 #include <QApplication> 0024 #include <QDebug> 0025 #include <QCommandLineParser> 0026 #include <QIcon> 0027 0028 #include <TelepathyQt/AccountFactory> 0029 #include <TelepathyQt/AccountManager> 0030 #include <TelepathyQt/ConnectionFactory> 0031 #include <TelepathyQt/ChannelClassSpec> 0032 #include <TelepathyQt/ChannelFactory> 0033 #include <TelepathyQt/ClientRegistrar> 0034 #include <TelepathyQt/ContactFactory> 0035 #include <TelepathyQt/Debug> 0036 #include <TelepathyQt/Types> 0037 0038 #include "sasl-handler.h" 0039 #include "tls-handler.h" 0040 #include "conference-auth-observer.h" 0041 #include "version.h" 0042 0043 #include <KTp/telepathy-handler-application.h> 0044 0045 // FIXME: Move this to tp-qt4 itself 0046 #include "types.h" 0047 0048 int main(int argc, char *argv[]) 0049 { 0050 KAboutData aboutData("ktp-auth-handler", 0051 i18n("Telepathy Authentication Handler"), 0052 0053 KTP_AUTH_HANDLER_VERSION); 0054 aboutData.addAuthor(i18n("David Edmundson"), i18n("Developer"), "kde@davidedmundson.co.uk"); 0055 aboutData.addAuthor(i18n("Daniele E. Domenichelli"), i18n("Developer"), "daniele.domenichelli@gmail.com"); 0056 aboutData.setProductName("telepathy/auth-handler"); 0057 0058 KAboutData::setApplicationData(aboutData); 0059 0060 // This is a very very very ugly hack that attempts to solve the following problem: 0061 // D-Bus service activated applications inherit the environment of dbus-daemon. 0062 // Normally, in KDE, startkde sets these environment variables. However, the session's 0063 // dbus-daemon is started before this happens, which means that dbus-daemon does NOT 0064 // have these variables in its environment and therefore all service-activated UIs 0065 // think that they are not running in KDE. This causes Qt not to load the KDE platform 0066 // plugin, which leaves the UI in a sorry state, using a completely wrong theme, 0067 // wrong colors, etc... 0068 // See also: 0069 // - https://bugs.kde.org/show_bug.cgi?id=269861 0070 // - https://bugs.kde.org/show_bug.cgi?id=267770 0071 // - https://git.reviewboard.kde.org/r/102194/ 0072 // Here we are just going to assume that kde-telepathy is always used in KDE and 0073 // not anywhere else. This is probably the best that we can do. 0074 setenv("KDE_FULL_SESSION", "true", 0); 0075 setenv("KDE_SESSION_VERSION", "5", 0); 0076 0077 KTp::TelepathyHandlerApplication app(argc, argv); 0078 QApplication::setWindowIcon(QIcon::fromTheme(QLatin1String("telepathy-kde"))); 0079 0080 // FIXME: Move this to tp-qt4 itself 0081 registerTypes(); 0082 0083 Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create( 0084 QDBusConnection::sessionBus(), Tp::Account::FeatureCore); 0085 Tp::ConnectionFactoryPtr connectionFactory = Tp::ConnectionFactory::create( 0086 QDBusConnection::sessionBus(), Tp::Connection::FeatureCore); 0087 Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create( 0088 QDBusConnection::sessionBus()); 0089 channelFactory->addCommonFeatures(Tp::Channel::FeatureCore); 0090 Tp::ClientRegistrarPtr clientRegistrar = Tp::ClientRegistrar::create( 0091 accountFactory, connectionFactory, channelFactory); 0092 0093 QMap<QString,Tp::AbstractClientPtr> handlers; 0094 handlers.insert(QLatin1String("KTp.SASLHandler"), Tp::SharedPtr<SaslHandler>(new SaslHandler)); 0095 handlers.insert(QLatin1String("KTp.TLSHandler"), Tp::SharedPtr<TlsHandler>(new TlsHandler)); 0096 Tp::ChannelClassSpecList confAuthFilter = Tp::ChannelClassSpecList() << Tp::ChannelClassSpec::textChatroom(); 0097 handlers.insert(QLatin1String("KTp.ConfAuthObserver"), Tp::SharedPtr<ConferenceAuthObserver>(new ConferenceAuthObserver(confAuthFilter))); 0098 0099 int loadedHandlers = handlers.count(); 0100 QMap<QString,Tp::AbstractClientPtr>::ConstIterator iter = handlers.constBegin(); 0101 for (; iter != handlers.constEnd(); ++iter) { 0102 if (!clientRegistrar->registerClient(iter.value(), iter.key())) { 0103 loadedHandlers--; 0104 } 0105 } 0106 0107 if (loadedHandlers == 0) { 0108 qDebug() << "No handlers registered. Exiting"; 0109 return 1; 0110 } 0111 0112 return app.exec(); 0113 }