File indexing completed on 2024-11-24 04:16:55

0001 /*
0002   SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006   Based on translateLocally code
0007 */
0008 
0009 #pragma once
0010 #include "libbergamot_export.h"
0011 #include <QMetaType>
0012 #include <QString>
0013 #include <QVector>
0014 #include <memory>
0015 
0016 namespace slimt
0017 {
0018 class Response;
0019 }
0020 
0021 /**
0022  * Wrapper around a translation response from the bergamot service. Hides that
0023  * interface from the rest of the Qt code, and provides utility functions to
0024  * access alignment information with character offsets instead of byte offsets.
0025  */
0026 class LIBBERGAMOT_EXPORT Translation
0027 {
0028 public:
0029     Translation();
0030     Translation(slimt::Response &&response);
0031 
0032     /**
0033      * Bool operator to check whether this is an initialised translation or just
0034      * an empty object.
0035      */
0036     inline operator bool() const
0037     {
0038         return !!mResponse;
0039     }
0040 
0041     /**
0042      * Translation result
0043      */
0044     [[nodiscard]] QString translation() const;
0045 
0046 private:
0047     // Note: I would have liked unique_ptr, but that does not go well with
0048     // passing Translation objects through Qt signals/slots.
0049     std::shared_ptr<slimt::Response> mResponse;
0050 };
0051 
0052 Q_DECLARE_METATYPE(Translation)