| Directory: | ./ |
|---|---|
| File: | src/Message.cpp |
| Date: | 2025-11-14 14:56:08 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 25 | 34 | 73.5% |
| Branches: | 21 | 40 | 52.5% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * Copyright (C) 2009-2022 Florian Pose <fp@igh.de> | ||
| 4 | * | ||
| 5 | * This file is part of the QtPdCom library. | ||
| 6 | * | ||
| 7 | * The QtPdCom library is free software: you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU Lesser General Public License as published by | ||
| 9 | * the Free Software Foundation, either version 3 of the License, or (at your | ||
| 10 | * option) any later version. | ||
| 11 | * | ||
| 12 | * The QtPdCom library is distributed in the hope that it will be useful, but | ||
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
| 14 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public | ||
| 15 | * License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public License | ||
| 18 | * along with the QtPdCom Library. If not, see <http://www.gnu.org/licenses/>. | ||
| 19 | * | ||
| 20 | ****************************************************************************/ | ||
| 21 | |||
| 22 | #include "Message.h" | ||
| 23 | |||
| 24 | #include "MessageImpl.h" | ||
| 25 | #include "MessageItem.h" | ||
| 26 | |||
| 27 | #include <QDateTime> | ||
| 28 | |||
| 29 | namespace QtPdCom { | ||
| 30 | |||
| 31 | /****************************************************************************/ | ||
| 32 | |||
| 33 | /** Constructor. | ||
| 34 | */ | ||
| 35 | 24 | Message::Message(QObject *parent): | |
| 36 | QObject(parent), | ||
| 37 |
2/4✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 24 times.
✗ Branch 6 not taken.
|
24 | impl(std::unique_ptr<Impl>(new Message::Impl(this))) |
| 38 | { | ||
| 39 | static const auto mt = | ||
| 40 |
4/8✓ Branch 0 taken 1 times.
✓ Branch 1 taken 23 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
24 | qRegisterMetaType<const Message *>("const QtPdCom::Message*"); |
| 41 | Q_UNUSED(mt); | ||
| 42 | 24 | } | |
| 43 | |||
| 44 | /****************************************************************************/ | ||
| 45 | |||
| 46 | /** Destructor. | ||
| 47 | */ | ||
| 48 | 48 | Message::~Message() | |
| 49 | 48 | {} | |
| 50 | |||
| 51 | /****************************************************************************/ | ||
| 52 | |||
| 53 | /** \return True, if the message is currently active. | ||
| 54 | */ | ||
| 55 | ✗ | bool Message::isActive() const | |
| 56 | { | ||
| 57 | ✗ | return impl->currentItem; | |
| 58 | } | ||
| 59 | |||
| 60 | /****************************************************************************/ | ||
| 61 | |||
| 62 | /** \return The message time in seconds. | ||
| 63 | */ | ||
| 64 | ✗ | double Message::getTime() const | |
| 65 | { | ||
| 66 | ✗ | if (impl->currentItem) { | |
| 67 | ✗ | return impl->currentItem->setTime * 1e-9; | |
| 68 | } | ||
| 69 | else { | ||
| 70 | ✗ | return 0.0; | |
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | /****************************************************************************/ | ||
| 75 | |||
| 76 | /** \return The message type. | ||
| 77 | */ | ||
| 78 | 44 | Message::Type Message::getType() const | |
| 79 | { | ||
| 80 | 44 | return impl->type; | |
| 81 | } | ||
| 82 | |||
| 83 | /****************************************************************************/ | ||
| 84 | |||
| 85 | /** \return The message path. | ||
| 86 | */ | ||
| 87 | 19 | const QString &Message::getPath() const | |
| 88 | { | ||
| 89 | 19 | return impl->path; | |
| 90 | } | ||
| 91 | |||
| 92 | /****************************************************************************/ | ||
| 93 | |||
| 94 | /** \return The message index. | ||
| 95 | */ | ||
| 96 | 19 | int Message::getIndex() const | |
| 97 | { | ||
| 98 | 19 | return impl->index; | |
| 99 | } | ||
| 100 | |||
| 101 | /****************************************************************************/ | ||
| 102 | |||
| 103 | /** \return The message text. If the text is not available in the desired | ||
| 104 | * language, the default text (empty language) will be returned. If that is | ||
| 105 | * also not available, display the message path. | ||
| 106 | */ | ||
| 107 | 104 | QString Message::getText(const QString &lang) const | |
| 108 | { | ||
| 109 |
1/2✓ Branch 5 taken 104 times.
✗ Branch 6 not taken.
|
208 | QString langText = impl->text.value(lang); |
| 110 |
2/2✓ Branch 1 taken 85 times.
✓ Branch 2 taken 19 times.
|
104 | if (not langText.isEmpty()) { |
| 111 | 85 | return langText; | |
| 112 | } | ||
| 113 | |||
| 114 |
2/4✓ Branch 6 taken 19 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 19 times.
✗ Branch 10 not taken.
|
38 | QString defaultLangText = impl->text.value(""); |
| 115 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 16 times.
|
19 | if (not defaultLangText.isEmpty()) { |
| 116 | 3 | return defaultLangText; | |
| 117 | } | ||
| 118 | |||
| 119 | 32 | QString path = impl->path; | |
| 120 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 2 taken 11 times.
|
16 | if (impl->index > -1) { |
| 121 |
3/6✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 11 taken 5 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 5 times.
✗ Branch 15 not taken.
|
5 | path += QString("#%1").arg(impl->index); |
| 122 | } | ||
| 123 | 16 | return path; | |
| 124 | } | ||
| 125 | |||
| 126 | /****************************************************************************/ | ||
| 127 | |||
| 128 | /** \return The message description. | ||
| 129 | */ | ||
| 130 | 35 | QString Message::getDescription(const QString &lang) const | |
| 131 | { | ||
| 132 |
3/6✓ Branch 7 taken 35 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 35 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 35 times.
✗ Branch 14 not taken.
|
35 | return impl->description.value(lang, impl->description.value("")); |
| 133 | } | ||
| 134 | |||
| 135 | /****************************************************************************/ | ||
| 136 | |||
| 137 | /** Returns the message time as a string. | ||
| 138 | */ | ||
| 139 | ✗ | QString Message::getTimeString() const | |
| 140 | { | ||
| 141 | ✗ | quint64 t {impl->currentItem ? impl->currentItem->setTime : 0}; | |
| 142 | ✗ | return impl->timeString(t); | |
| 143 | } | ||
| 144 | |||
| 145 | /****************************************************************************/ | ||
| 146 | |||
| 147 | } // namespace QtPdCom | ||
| 148 | |||
| 149 | /****************************************************************************/ | ||
| 150 |