File indexing completed on 2023-09-24 05:08:02

0001 /*
0002     Copyright (C) 2013  David Edmundson <davidedmundson@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Lesser General Public
0006     License as published by the Free Software Foundation; either
0007     version 2.1 of the License, or (at your option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Lesser General Public License for more details.
0013 
0014     You should have received a copy of the GNU Lesser General Public
0015     License along with this library; if not, write to the Free Software
0016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0017 */
0018 
0019 #include "imdetailswidget.h"
0020 
0021 #include <QGridLayout>
0022 #include <QLabel>
0023 #include <QApplication>
0024 #include <QStyle>
0025 #include <QVBoxLayout>
0026 
0027 #include <KLocalizedString>
0028 #include <KPluginFactory>
0029 
0030 #include <KPeople/PersonData>
0031 #include <TelepathyQt/AccountManager>
0032 #include <KTp/core.h>
0033 
0034 K_PLUGIN_FACTORY_WITH_JSON( ImDetailsWidgetFactory, "imdetailswidgetplugin.json", registerPlugin<ImDetailsWidget>(); )
0035 K_EXPORT_PLUGIN( ImDetailsWidgetFactory("imdetailswidgetplugin", "ktp-common-internals"))
0036 
0037 using namespace KPeople;
0038 
0039 ImDetailsWidget::ImDetailsWidget(QObject* parent, const QVariantList& args)
0040 {
0041     Q_UNUSED(parent);
0042     Q_UNUSED(args);
0043 }
0044 
0045 QString ImDetailsWidget::label() const
0046 {
0047     return i18n("IM");
0048 }
0049 
0050 QWidget* ImDetailsWidget::createDetailsWidget(const KPeople::PersonData &person, QWidget *parent) const
0051 {
0052     QWidget *root = new QWidget(parent);
0053     QGridLayout *layout = new QGridLayout(root);
0054     root->setLayout(layout);
0055 
0056     int row = 0;
0057     for(const QString &contactId: person.contactUris()) {
0058         if (!contactId.startsWith(QStringLiteral("ktp://"))) {
0059             continue;
0060         }
0061         PersonData contact(contactId);
0062         const QString tpcontactId = contact.contactCustomProperty(QStringLiteral("telepathy-contactId")).toString();
0063         const QString accountPath = contact.contactCustomProperty(QStringLiteral("telepathy-accountPath")).toString(); //probably unused till we fix everything properly
0064 
0065         Tp::AccountPtr account = KTp::accountManager()->accountForObjectPath(accountPath);
0066         if (!account) {
0067             continue;
0068         }
0069 
0070         QLabel *iconLabel = new QLabel(root);
0071         const int iconSize = root->style()->pixelMetric(QStyle::PM_SmallIconSize);
0072         iconLabel->setPixmap(QIcon::fromTheme(account->iconName()).pixmap(iconSize, iconSize));
0073         layout->addWidget(iconLabel, row, 0);
0074 
0075         QLabel *label = new QLabel(tpcontactId, root);
0076         label->setTextInteractionFlags(Qt::TextSelectableByMouse);
0077         layout->addWidget(label, row, 1);
0078 
0079         row++;
0080         //FUTURE - presence here + blocked + presence subscription
0081     }
0082     if (layout->count()) {
0083         return root;
0084     } else {
0085         return nullptr;
0086     }
0087 }
0088 
0089 #include "imdetailswidget.moc"