File indexing completed on 2024-05-12 04:34:48

0001 /* ============================================================
0002 *
0003 * SPDX-FileCopyrightText: 2017 Alexander Trufanov
0004 *
0005 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 *
0007 * ============================================================ */
0008 
0009 #include "DBusInterface.h"
0010 
0011 #include <skanlite_debug.h>
0012 
0013 bool DBusInterface::setupDBusInterface()
0014 {
0015     QDBusConnection session = QDBusConnection::sessionBus();
0016 
0017     if (!session.isConnected()) {
0018         qCDebug(SKANLITE_LOG) << ("ERROR: Cannot connect to the D-Bus session bus. Continuing...");
0019         return false;
0020     }
0021 
0022     if(!session.registerObject(QStringLiteral("/"), this, QDBusConnection::ExportScriptableContents)) {
0023         qCDebug(SKANLITE_LOG) << ("ERROR: Cannot register D-Bus object. Continuing...");
0024         return false;
0025     }
0026 
0027     if(!session.registerService(QStringLiteral("org.kde.skanlite"))) {
0028         qCDebug(SKANLITE_LOG) << ("ERROR: Cannot register D-Bus service. Continuing...");
0029         return false;
0030     }
0031 
0032     return true;
0033 }
0034 
0035 
0036 // QDbusViewer (qttools5-dev-tools) is a very convinient tool to test D-Bus messaging (QTBUG-7341)
0037 // But it can't pass string list parameters. It passes them as one string in following format:
0038 // "{"KSane::InvertColors=false", "blue-gamma-table=0:0:100", "br-x=220", "br-y=300", "button 0=false", "button 1=false", "button 2=false", "button 3=false", "depth=8 битов", "green-gamma-table=0:0:100", "mode=Color", "opt_chipid=4", "opt_chipname=RTS8822L-02A", "opt_dbgimages=false", "opt_emulategray=false", "opt_model=HP4370", "opt_negative=false", "opt_nogamma=false", "opt_nowarmup=true", "opt_nowshading=true", "opt_realdepth=false", "opt_scancount=12381", "red-gamma-table=0:0:100", "resolution=50 DPI", "source=Flatbed", "tl-x=0", "tl-y=0"}"
0039 // We check for this format and convert string back to string list if detected.
0040 const QStringList DBusInterface::ensureStringList(const QStringList &list)
0041 {
0042     if (list.length() == 1) {
0043         QString s = list[0].trimmed();
0044         if (s.left(2) == QLatin1String("{\"") && s.right(2) == QLatin1String("\"}")) {
0045             return s.remove(QLatin1String("{\"")).remove(QLatin1String("\"}")).split(QStringLiteral("\", \""));
0046         }
0047     }
0048 
0049     return list;
0050 }
0051 
0052 #include "moc_DBusInterface.cpp"