File indexing completed on 2023-11-26 04:55:36

0001 /*
0002  * This file is part of telepathy-accounts-kcm
0003  *
0004  * Copyright (C) 2009 Collabora Ltd. <info@collabora.com>
0005  * Copyright (C) 2011 Thomas Richard <thomas.richard@proan.be>
0006  * Copyright (C) 2011 Dominik Schmidt <kde@dominik-schmidt.de>
0007  * Copyright (C) 2011 Daniele E. Domenichelli <daniele.domenichelli@gmail.com>
0008  *
0009  * This library is free software; you can redistribute it and/or
0010  * modify it under the terms of the GNU Lesser General Public
0011  * License as published by the Free Software Foundation; either
0012  * version 2.1 of the License, or (at your option) any later version.
0013  *
0014  * This library is distributed in the hope that it will be useful,
0015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0017  * Lesser General Public License for more details.
0018  *
0019  * You should have received a copy of the GNU Lesser General Public
0020  * License along with this library; if not, write to the Free Software
0021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0022  */
0023 
0024 #include "salut-details-dialog.h"
0025 
0026 #include "KCMTelepathyAccounts/parameter-edit-model.h"
0027 #include "KCMTelepathyAccounts/account-edit-widget.h"
0028 #include "KCMTelepathyAccounts/profile-item.h"
0029 
0030 #include <KLocalizedString>
0031 #include <KDebug>
0032 
0033 #include <TelepathyQt/ConnectionManager>
0034 #include <TelepathyQt/ProfileManager>
0035 #include <TelepathyQt/AccountManager>
0036 #include <TelepathyQt/PendingOperation>
0037 #include <TelepathyQt/PendingReady>
0038 #include <TelepathyQt/PendingAccount>
0039 
0040 class SalutDetailsDialog::Private
0041 {
0042 public:
0043     Private(SalutDetailsDialog* parent)
0044         : q(parent),
0045           widget(0)
0046     {
0047     }
0048 
0049     SalutDetailsDialog *q;
0050     AccountEditWidget *widget;
0051 
0052     Tp::ProfilePtr profile;
0053 };
0054 
0055 SalutDetailsDialog::SalutDetailsDialog(const Tp::ProfileManagerPtr profileManager, const Tp::ConnectionManagerPtr connectionManager, QWidget *parent)
0056     : KDialog(parent),
0057       d(new Private(this))
0058 {
0059     setMinimumWidth(450);
0060 
0061     // Get the protocol's parameters and values.
0062     Tp::ProtocolInfo protocolInfo = connectionManager->protocol(QLatin1String("local-xmpp"));
0063     Tp::ProtocolParameterList parameters = protocolInfo.parameters();
0064 
0065     // Add the parameters to the model.
0066     ParameterEditModel *parameterModel = new ParameterEditModel(this);
0067     d->profile = profileManager->profilesForCM(QLatin1String("salut")).first();
0068 
0069     Q_ASSERT(!d->profile.isNull());
0070     Q_ASSERT(d->profile->isValid());
0071     Q_ASSERT(d->profile->protocolName() == QLatin1String("local-xmpp"));
0072     if (d->profile.isNull() || !d->profile->isValid() || d->profile->protocolName() != QLatin1String("local-xmpp")) {
0073         kWarning() << "Something went wrong with telepathy salut";
0074     }
0075 
0076     parameterModel->addItems(parameters, d->profile->parameters());
0077 
0078     // Set up the interface
0079     d->widget = new AccountEditWidget(d->profile,
0080                                       QString(),
0081                                       parameterModel,
0082                                       doNotConnectOnAdd,
0083                                       this);
0084     connect(this,
0085             SIGNAL(feedbackMessage(QString,QString,KMessageWidget::MessageType)),
0086             d->widget,
0087             SIGNAL(feedbackMessage(QString,QString,KMessageWidget::MessageType)));
0088     setMainWidget(d->widget);
0089 }
0090 
0091 SalutDetailsDialog::~SalutDetailsDialog()
0092 {
0093     delete d;
0094 }
0095 
0096 void SalutDetailsDialog::accept()
0097 {
0098     Q_EMIT dialogAccepted(d->widget->displayName(), d->widget->parametersSet());
0099     KDialog::accept();
0100 }
0101 
0102 #include "salut-details-dialog.moc"