#include "setaudio.h" using namespace BlackSound; namespace BlackMisc { namespace Settings { /* * Constructor */ CSettingsAudio::CSettingsAudio() { this->initDefaultValues(); } /* * Flag */ bool CSettingsAudio::getNotificationFlag(CNotificationSounds::Notification notification) const { const int i = static_cast(notification); if (i >= m_notificationFlags.length()) return true; // default QChar f = m_notificationFlags.at(i); return '1' == f; } /* * Convert to string */ QString CSettingsAudio::convertToQString(bool i18n) const { Q_UNUSED(i18n); QString s("Notification flags:"); s.append(" ").append(m_notificationFlags); return s; } /* * metaTypeId */ int CSettingsAudio::getMetaTypeId() const { return qMetaTypeId(); } /* * is a */ bool CSettingsAudio::isA(int metaTypeId) const { if (metaTypeId == qMetaTypeId()) { return true; } return this->CValueObject::isA(metaTypeId); } /* * Compare */ int CSettingsAudio::compareImpl(const CValueObject &otherBase) const { const auto &other = static_cast(otherBase); return compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); } /* * Marshall */ void CSettingsAudio::marshallToDbus(QDBusArgument &argument) const { argument << TupleConverter::toTuple(*this); } /* * Unmarshall */ void CSettingsAudio::unmarshallFromDbus(const QDBusArgument &argument) { argument >> TupleConverter::toTuple(*this); } /* * Equal? */ bool CSettingsAudio::operator ==(const CSettingsAudio &other) const { if (this == &other) return true; return compare(*this, other) == 0; } /* * Unequal? */ bool CSettingsAudio::operator !=(const CSettingsAudio &other) const { return !((*this) == other); } /* * Hash */ uint CSettingsAudio::getValueHash() const { return qHash(TupleConverter::toTuple(*this)); } /* * To JSON */ QJsonObject CSettingsAudio::toJson() const { return BlackMisc::serializeJson(CSettingsAudio::jsonMembers(), TupleConverter::toTuple(*this)); } /* * From JSON */ void CSettingsAudio::fromJson(const QJsonObject &json) { BlackMisc::deserializeJson(json, CSettingsAudio::jsonMembers(), TupleConverter::toTuple(*this)); } /* * Members */ const QStringList &CSettingsAudio::jsonMembers() { return TupleConverter::jsonMembers(); } /* * Default values */ void CSettingsAudio::initDefaultValues() { this->initNotificationFlags(); } void CSettingsAudio::initNotificationFlags() { // if we add flags in the future, we automatically extend ... static const int l = 1 + static_cast(CNotificationSounds::Notification::NotificationsLoadSounds); if (this->m_notificationFlags.length() < l) { int cl = m_notificationFlags.length(); this->m_notificationFlags.append(QString(l - cl, '1')); } } /* * Register metadata */ void CSettingsAudio::registerMetadata() { qRegisterMetaType(); qDBusRegisterMetaType(); } /* * Value */ BlackMisc::CStatusMessageList CSettingsAudio::value(const QString &path, const QString &command, const QVariant &value, bool &changedFlag) { // TODO: This needs to be refactored to a smarter way to delegate commands changedFlag = false; CStatusMessageList msgs; if (path == CSettingsAudio::ValueNotificationFlag()) { if (command == CSettingUtilities::CmdSetTrue() || command == CSettingUtilities::CmdSetFalse()) { CNotificationSounds::Notification index = static_cast(value.toInt()); char value = (command == CSettingUtilities::CmdSetTrue()) ? '1' : '0' ; this->initNotificationFlags(); this->m_notificationFlags.replace(index, 1, value); return msgs; } } return CSettingUtilities::wrongPathMessages(path); } } // namespace } // namespace