File indexing completed on 2024-12-22 05:01:05
0001 /* 0002 SPDX-FileCopyrightText: 2022 Sandro Knauß <sknauss@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 #include "encryptionstate.h" 0007 0008 EncryptionState::EncryptionState() 0009 { 0010 connect(this, &EncryptionState::acceptedSolutionChanged, this, &EncryptionState::updateEncrypt); 0011 connect(this, &EncryptionState::overrideChanged, this, &EncryptionState::updateEncrypt); 0012 connect(this, &EncryptionState::possibleEncryptChanged, this, &EncryptionState::updateEncrypt); 0013 connect(this, &EncryptionState::autoEncryptChanged, this, &EncryptionState::updateEncrypt); 0014 } 0015 0016 bool EncryptionState::override() const 0017 { 0018 return m_override; 0019 } 0020 0021 void EncryptionState::setOverride(bool setByUser) 0022 { 0023 if (!m_hasOverride) { 0024 m_hasOverride = true; 0025 Q_EMIT hasOverrideChanged(true); 0026 // Before the override setting was undefined, we should trigger a signal with correct state 0027 m_override = setByUser; 0028 Q_EMIT overrideChanged(setByUser); 0029 return; 0030 } 0031 0032 if (m_override == setByUser) { 0033 return; 0034 } 0035 0036 m_override = setByUser; 0037 Q_EMIT overrideChanged(m_override); 0038 } 0039 0040 void EncryptionState::toggleOverride() 0041 { 0042 setOverride(!encrypt()); 0043 } 0044 0045 void EncryptionState::unsetOverride() 0046 { 0047 if (!m_hasOverride) { 0048 return; 0049 } 0050 m_hasOverride = false; 0051 Q_EMIT hasOverrideChanged(false); 0052 Q_EMIT overrideChanged(false); 0053 } 0054 0055 bool EncryptionState::hasOverride() const 0056 { 0057 return m_hasOverride; 0058 } 0059 0060 bool EncryptionState::acceptedSolution() const 0061 { 0062 return m_acceptedSolution; 0063 } 0064 0065 void EncryptionState::setAcceptedSolution(bool acceptedSolution) 0066 { 0067 if (m_acceptedSolution == acceptedSolution) { 0068 return; 0069 } 0070 0071 m_acceptedSolution = acceptedSolution; 0072 Q_EMIT acceptedSolutionChanged(m_acceptedSolution); 0073 } 0074 0075 bool EncryptionState::possibleEncrypt() const 0076 { 0077 return m_possibleEncrypt; 0078 } 0079 0080 void EncryptionState::setPossibleEncrypt(bool possibleEncrypt) 0081 { 0082 if (m_possibleEncrypt == possibleEncrypt) { 0083 return; 0084 } 0085 0086 m_possibleEncrypt = possibleEncrypt; 0087 Q_EMIT possibleEncryptChanged(m_possibleEncrypt); 0088 } 0089 0090 bool EncryptionState::autoEncrypt() const 0091 { 0092 return m_autoEncrypt; 0093 } 0094 0095 void EncryptionState::setAutoEncrypt(bool autoEncrypt) 0096 { 0097 if (m_autoEncrypt == autoEncrypt) { 0098 return; 0099 } 0100 0101 m_autoEncrypt = autoEncrypt; 0102 Q_EMIT autoEncryptChanged(m_autoEncrypt); 0103 } 0104 0105 void EncryptionState::setEncrypt(bool encrypt) 0106 { 0107 if (m_encrypt == encrypt) { 0108 return; 0109 } 0110 0111 m_encrypt = encrypt; 0112 Q_EMIT encryptChanged(m_encrypt); 0113 } 0114 0115 void EncryptionState::updateEncrypt() 0116 { 0117 if (m_hasOverride) { 0118 setEncrypt(m_override); 0119 return; 0120 } 0121 if (!m_possibleEncrypt) { 0122 setEncrypt(false); 0123 return; 0124 } 0125 0126 if (!m_autoEncrypt) { 0127 setEncrypt(false); 0128 return; 0129 } 0130 0131 setEncrypt(m_acceptedSolution); 0132 } 0133 0134 bool EncryptionState::encrypt() const 0135 { 0136 return m_encrypt; 0137 } 0138 0139 #include "moc_encryptionstate.cpp"