1 /* 2 * %kadu copyright begin% 3 * Copyright 2011, 2014 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com) 4 * %kadu copyright end% 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #pragma once 21 22 #include "configuration/configuration-aware-object.h" 23 #include "status/status-container-aware-object.h" 24 #include "exports.h" 25 26 #include <QtCore/QObject> 27 #include <QtCore/QPointer> 28 #include <injeqt/injeqt.h> 29 30 class Configuration; 31 class StatusChangerManager; 32 class StatusContainerManager; 33 class StatusTypeManager; 34 class Status; 35 36 /** 37 * @addtogroup Status 38 * @{ 39 */ 40 41 /** 42 * @class StatusSetter 43 * @author Rafał 'Vogel' Malinowski 44 * @short Class responsible for setting modified status to StatusContainers. 45 * @see StatusChangerManager 46 * 47 * This singleton class is used to set status on status containers. Current implementation uses StatusChangerManager 48 * to modify all statuses before sending them to status containers. 49 * 50 * StatusSetter also allows receiving originally statused (not modified) by manuallySetStatus method. 51 */ 52 class KADUAPI StatusSetter : public QObject, private StatusContainerAwareObject, private ConfigurationAwareObject 53 { 54 Q_OBJECT 55 56 public: 57 Q_INVOKABLE explicit StatusSetter(QObject *parent = nullptr); 58 virtual ~StatusSetter(); 59 60 /** 61 * @author Rafał 'Vogel' Malinowski 62 * @short Sets status on given status container with modifications. 63 * @param statusContainer StatusContainer to set status on. 64 * @param status status to be modified and then set on statusContainer 65 * 66 * This methods stores given status as manually set status (to receive by manuallySetStatus) and then modifies 67 * it using StatusChangersManager singleton. After all changes are done, new status is set on statusContainer 68 * using StatusContainer::setStatus method. 69 */ 70 void setStatusManually(StatusContainer *statusContainer, Status status); 71 72 /** 73 * @author Rafał 'Vogel' Malinowski 74 * @short Returns manually (unchanged) status from given StatusContainer. 75 * @param statusContainer StatusContainer to get status from. 76 * 77 * This methods returns manually set status from given StatusContainer. This is the last status that was 78 * set using StatusSetter::setStatus method. 79 */ 80 Status manuallySetStatus(StatusContainer *statusContainer); 81 82 protected: 83 void configurationUpdated(); 84 85 /** 86 * @author Rafał 'Vogel' Malinowski 87 * @short Called on registration of new container, sets default status. 88 * @param statusContainer new status container 89 * 90 * If core is initialized this method calls setDefaultStatus to set initial status on given status container. 91 * If core is not initialized, this method does nothing. On core initialization this method will be called 92 * for each status container. 93 */ 94 void statusContainerRegistered(StatusContainer *statusContainer); 95 void statusContainerUnregistered(StatusContainer *statusContainer); 96 97 private: 98 friend class Core; 99 100 QPointer<Configuration> m_configuration; 101 QPointer<StatusChangerManager> m_statusChangerManager; 102 QPointer<StatusContainerManager> m_statusContainerManager; 103 QPointer<StatusTypeManager> m_statusTypeManager; 104 105 QString StartupStatus; 106 QString StartupDescription; 107 bool StartupLastDescription; 108 bool OfflineToInvisible; 109 110 /** 111 * @author Rafał 'Vogel' Malinowski 112 * @short Private method called by Core. 113 * 114 * This method is called by Core when all internals have been initialized. It allows StatusSetter 115 * to set initial status on all registered status containers. 116 */ 117 void coreInitialized(); 118 119 /** 120 * @author Rafał 'Vogel' Malinowski 121 * @short Sets default status on given container. 122 * @param statusContainer container to set default status on 123 * 124 * This method is internally called after new status container is registered. Stored status 125 * is retreived from this container, then configuration is applied on this status (like: 126 * default description), then this status is send to StatusChangerManager to get final version 127 * to set on container. 128 */ 129 void setDefaultStatus(StatusContainer *statusContainer); 130 131 private slots: 132 INJEQT_SET void setConfiguration(Configuration *configuration); 133 INJEQT_SET void setStatusChangerManager(StatusChangerManager *statusChangerManager); 134 INJEQT_SET void setStatusContainerManager(StatusContainerManager *statusContainerManager); 135 INJEQT_SET void setStatusTypeManager(StatusTypeManager *statusTypeManager); 136 INJEQT_INIT void init(); 137 138 }; 139 140 /** 141 * @addtogroup Status 142 * @} 143 */ 144