1 /* 2 * %kadu copyright begin% 3 * Copyright 2012, 2013 Bartosz Brachaczek (b.brachaczek@gmail.com) 4 * Copyright 2011, 2013, 2014 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com) 5 * %kadu copyright end% 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License as 9 * published by the Free Software Foundation; either version 2 of 10 * the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #include "status/status-type-data.h" 22 #include "status/status-type-manager.h" 23 #include "status/status.h" 24 25 #include "autoaway.h" 26 27 #include "autoaway-status-changer.h" 28 AutoawayStatusChanger(QObject * parent)29AutoawayStatusChanger::AutoawayStatusChanger(QObject *parent) : 30 StatusChanger{900, parent} 31 { 32 } 33 ~AutoawayStatusChanger()34AutoawayStatusChanger::~AutoawayStatusChanger() 35 { 36 } 37 setAutoaway(Autoaway * autoaway)38void AutoawayStatusChanger::setAutoaway(Autoaway *autoaway) 39 { 40 m_autoaway = autoaway; 41 } 42 setStatusTypeManager(StatusTypeManager * statusTypeManager)43void AutoawayStatusChanger::setStatusTypeManager(StatusTypeManager *statusTypeManager) 44 { 45 m_statusTypeManager = statusTypeManager; 46 } 47 changeStatus(StatusContainer * container,Status & status)48void AutoawayStatusChanger::changeStatus(StatusContainer *container, Status &status) 49 { 50 Q_UNUSED(container) 51 52 auto changeStatusTo = m_autoaway->changeStatusTo(); 53 auto changeDescriptionTo = m_autoaway->changeDescriptionTo(); 54 auto descriptionAddon = m_autoaway->descriptionAddon(); 55 auto group = m_statusTypeManager->statusTypeData(status.type()).typeGroup(); 56 57 if (changeStatusTo == NoChangeStatus) 58 return; 59 60 if (status.isDisconnected()) 61 return; 62 63 auto description = status.description(); 64 switch (changeDescriptionTo) 65 { 66 case NoChangeDescription: 67 break; 68 69 case ChangeDescriptionPrepend: 70 description = descriptionAddon + description; 71 break; 72 73 case ChangeDescriptionReplace: 74 description = descriptionAddon; 75 break; 76 77 case ChangeDescriptionAppend: 78 description = description + descriptionAddon; 79 break; 80 } 81 82 if (changeStatusTo == ChangeStatusToOffline) 83 { 84 status.setType(StatusType::Offline); 85 status.setDescription(description); 86 return; 87 } 88 89 if (group == StatusTypeGroup::Invisible) 90 return; 91 92 if (changeStatusTo == ChangeStatusToInvisible) 93 { 94 status.setType(StatusType::Invisible); 95 status.setDescription(description); 96 return; 97 } 98 99 if (group == StatusTypeGroup::Away) 100 return; 101 102 if (changeStatusTo == ChangeStatusToAway) 103 { 104 status.setType(StatusType::Away); 105 status.setDescription(description); 106 return; 107 } 108 109 if (changeStatusTo == ChangeStatusToExtendedAway) 110 { 111 status.setType(StatusType::NotAvailable); 112 status.setDescription(description); 113 return; 114 } 115 } 116 update()117void AutoawayStatusChanger::update() 118 { 119 emit statusChanged(0); // for all status containers 120 } 121 122 #include "moc_autoaway-status-changer.cpp" 123