File indexing completed on 2023-10-01 08:41:43

0001 /*
0002     Copyright (C) 2012 George Kiagiadakis <kiagiadakis.george@gmail.com>
0003 
0004     This library is free software; you can redistribute it and/or modify
0005     it under the terms of the GNU Lesser General Public License as published
0006     by the Free Software Foundation; either version 2.1 of the License, or
0007     (at your option) any later version.
0008 
0009     This program 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
0012     GNU General Public License for more details.
0013 
0014     You should have received a copy of the GNU Lesser General Public License
0015     along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016 */
0017 
0018 #include "capabilities-hack-private.h"
0019 
0020 /*
0021  * This is a hack to workaround a gabble bug.
0022  * https://bugs.freedesktop.org/show_bug.cgi?id=51978
0023  */
0024 
0025 namespace CapabilitiesHackPrivate {
0026 
0027 static Tp::RequestableChannelClassSpec gabbleAudioCallRCC()
0028 {
0029     static Tp::RequestableChannelClassSpec spec;
0030 
0031     if (!spec.isValid()) {
0032         Tp::RequestableChannelClass rcc;
0033         rcc.fixedProperties.insert(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType"),
0034                 TP_QT_IFACE_CHANNEL_TYPE_CALL);
0035         rcc.fixedProperties.insert(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType"),
0036                 (uint) Tp::HandleTypeContact);
0037         rcc.allowedProperties.append(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String(".InitialAudio"));
0038         rcc.allowedProperties.append(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String(".InitialAudioName"));
0039         spec = Tp::RequestableChannelClassSpec(rcc);
0040     }
0041 
0042     return spec;
0043 }
0044 
0045 static Tp::RequestableChannelClassSpec gabbleVideoCallRCC()
0046 {
0047     static Tp::RequestableChannelClassSpec spec;
0048 
0049     if (!spec.isValid()) {
0050         Tp::RequestableChannelClass rcc;
0051         rcc.fixedProperties.insert(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType"),
0052                 TP_QT_IFACE_CHANNEL_TYPE_CALL);
0053         rcc.fixedProperties.insert(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType"),
0054                 (uint) Tp::HandleTypeContact);
0055         rcc.allowedProperties.append(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String(".InitialVideo"));
0056         rcc.allowedProperties.append(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String(".InitialVideoName"));
0057         spec = Tp::RequestableChannelClassSpec(rcc);
0058     }
0059 
0060     return spec;
0061 }
0062 
0063 bool audioCalls(const Tp::CapabilitiesBase &caps, const QString &cmName)
0064 {
0065     bool gabbleResult = false;
0066     if (cmName == QLatin1String("gabble")) {
0067         Q_FOREACH (const Tp::RequestableChannelClassSpec &rccSpec, caps.allClassSpecs()) {
0068             if (rccSpec.supports(gabbleAudioCallRCC())) {
0069                 gabbleResult = true;
0070                 break;
0071             }
0072         }
0073     }
0074 
0075     return gabbleResult || caps.audioCalls();
0076 }
0077 
0078 bool videoCalls(const Tp::CapabilitiesBase &caps, const QString &cmName)
0079 {
0080     bool gabbleResult = false;
0081     if (cmName == QLatin1String("gabble")) {
0082         Q_FOREACH (const Tp::RequestableChannelClassSpec &rccSpec, caps.allClassSpecs()) {
0083             if (rccSpec.supports(gabbleVideoCallRCC())) {
0084                 gabbleResult = true;
0085                 break;
0086             }
0087         }
0088     }
0089 
0090     return gabbleResult || caps.videoCalls();
0091 }
0092 
0093 }