File indexing completed on 2024-05-26 05:43:54
0001 #include "Notifier.hpp" 0002 0003 namespace cutehmi { 0004 0005 Notifier::Notifier(QObject * parent): 0006 QObject(parent), 0007 m(new Members) 0008 { 0009 } 0010 0011 NotificationListModel * Notifier::model() const 0012 { 0013 return m->model.get(); 0014 } 0015 0016 Notifier * Notifier::create(QQmlEngine * qmlEngine, QJSEngine * jsEngine) 0017 { 0018 Q_UNUSED(jsEngine) 0019 0020 Notifier * instance = & Instance(); 0021 qmlEngine->setObjectOwnership(instance, QQmlEngine::CppOwnership); 0022 0023 return instance; 0024 } 0025 0026 int Notifier::maxNotifications() const 0027 { 0028 return m->maxNotifications; 0029 } 0030 0031 void Notifier::setMaxNotifications(int maxNotifications) 0032 { 0033 if (m->maxNotifications != maxNotifications) { 0034 m->maxNotifications = maxNotifications; 0035 if (m->model->rowCount() > maxNotifications) 0036 m->model->removeFirst(m->model->rowCount() - maxNotifications); 0037 emit maxNotificationsChanged(); 0038 } 0039 } 0040 0041 void Notifier::add(Notification * notification_l) 0042 { 0043 QMutexLocker locker(& m->modelMutex); 0044 0045 switch (notification_l->type()) { 0046 case Notification::INFO: 0047 CUTEHMI_INFO("[NOTIFICATION] " << notification_l->text()); 0048 break; 0049 case Notification::WARNING: 0050 CUTEHMI_WARNING("[NOTIFICATION] " << notification_l->text()); 0051 break; 0052 case Notification::CRITICAL: 0053 CUTEHMI_CRITICAL("[NOTIFICATION] " << notification_l->text()); 0054 break; 0055 default: 0056 CUTEHMI_CRITICAL("Unrecognized code ('" << notification_l->type() << "') of 'Notification::type()'. Assuming 'Notification::CRITICAL'."); 0057 CUTEHMI_CRITICAL("[NOTIFICATION] " << notification_l->text()); 0058 } 0059 0060 m->model->append(notification_l->clone()); 0061 0062 if (m->model->rowCount() > maxNotifications()) 0063 m->model->removeFirst(); 0064 0065 emit notificationAdded(); 0066 } 0067 0068 void Notifier::clear() 0069 { 0070 m->model->clear(); 0071 } 0072 0073 } 0074 0075 //(c)C: Copyright © 2019-2023, Michał Policht <michal@policht.pl>. All rights reserved. 0076 //(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT 0077 //(c)C: This file is a part of CuteHMI. 0078 //(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 0079 //(c)C: CuteHMI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 0080 //(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI. If not, see <https://www.gnu.org/licenses/>. 0081 //(c)C: Additionally, this file is licensed under terms of MIT license as expressed below. 0082 //(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 0083 //(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 0084 //(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.