1 /* 2 Bacula(R) - The Network Backup Solution 3 4 Copyright (C) 2000-2020 Kern Sibbald 5 6 The original author of Bacula is Kern Sibbald, with contributions 7 from many others, a complete list can be found in the file AUTHORS. 8 9 You may use this file and others of this release according to the 10 license defined in the LICENSE file, which includes the Affero General 11 Public License, v3.0 ("AGPLv3") and some additional permissions and 12 terms pursuant to its AGPLv3 Section 7. 13 14 This notice must be preserved when any source code is 15 conveyed and/or propagated. 16 17 Bacula(R) is a registered trademark of Kern Sibbald. 18 */ 19 20 #ifndef RESPANELGUICONTROLLER_H 21 #define RESPANELGUICONTROLLER_H 22 23 #include <QObject> 24 #include <QString> 25 #include "tray_conf.h" 26 #include "config-storage.h" 27 #include "resmodel.h" 28 #include <android/log.h> 29 #include "jcr.h" 30 #include "task.h" 31 #include "common.h" 32 #include "jobmodel.h" 33 #include "runjobmodel.h" 34 #include "restorejobmodel.h" 35 36 /* 37 TrayUiController - Controls the screen displayed when a user selects one resource 38 (Director, File Daemon or Storage Daemon). It allows the user to: 39 40 1 - Change the data that's required to connect with the resource (name, password, address and port) 41 2 - Connect to the resource, and therefore see it's terminated jobs and running jobs 42 43 */ 44 class ResPanelUiController : public QObject 45 { 46 Q_OBJECT 47 48 // Data related to the resource that the user selected 49 Q_PROPERTY(ResourceModel *resModel WRITE setResModel) 50 Q_PROPERTY(QString resType WRITE setResType) 51 52 //These can be edited by the user 53 Q_PROPERTY(QString resourceName READ resourceName WRITE setResourceName NOTIFY resourceNameChanged) 54 Q_PROPERTY(QString resourcePassword READ resourcePassword WRITE setResourcePassword NOTIFY resourcePasswordChanged) 55 Q_PROPERTY(QString resourceAddress READ resourceAddress WRITE setResourceAddress NOTIFY resourceAddressChanged) 56 Q_PROPERTY(QString resourcePort READ resourcePort WRITE setResourcePort NOTIFY resourcePortChanged) 57 Q_PROPERTY(bool remoteClient READ isRemoteClient WRITE setIsRemoteClient NOTIFY isRemoteClientChanged) 58 59 //TODO merge both into a variable 'dialogMsg' 60 // Message displayed on the GUI dialogs 61 Q_PROPERTY(QString successMsg READ successMsg WRITE setSuccessMessage NOTIFY successMessageChanged) 62 Q_PROPERTY(QString errorMsg READ errorMsg WRITE setErrorMessage NOTIFY errorMessageChanged) 63 64 private: 65 QString m_resourceName; 66 QString m_resourcePassword; 67 QString m_resourceAddress; 68 QString m_resourcePort; 69 QString m_successMsg; 70 QString m_errorMsg; 71 bool m_remoteClient; 72 ConfigStorage *m_storage = NULL; 73 rescode m_resCode; 74 RESMON *m_res = NULL; 75 76 public: 77 explicit ResPanelUiController(QObject *parent = nullptr); 78 ~ResPanelUiController(); 79 setResCode(rescode code)80 void setResCode(rescode code) { 81 if (m_resCode == code) { 82 return; 83 } 84 85 m_resCode = code; 86 emit resCodeChanged(); 87 } 88 89 // Resource Name resourceName()90 QString resourceName() { 91 return m_resourceName; 92 } 93 setResourceName(const QString & resourceName)94 void setResourceName(const QString &resourceName) { 95 if (resourceName == m_resourceName) 96 return; 97 98 m_resourceName = resourceName; 99 emit resourceNameChanged(); 100 } 101 102 // Resource Password resourcePassword()103 QString resourcePassword() { 104 return m_resourcePassword; 105 } 106 setResourcePassword(const QString & resourcePassword)107 void setResourcePassword(const QString &resourcePassword) { 108 if (resourcePassword == m_resourcePassword) 109 return; 110 111 m_resourcePassword = resourcePassword; 112 emit resourcePasswordChanged(); 113 } 114 115 // Resource Address resourceAddress()116 QString resourceAddress() { 117 return m_resourceAddress; 118 } 119 setResourceAddress(const QString & resourceAddress)120 void setResourceAddress(const QString &resourceAddress) { 121 if (resourceAddress == m_resourceAddress) 122 return; 123 124 m_resourceAddress = resourceAddress; 125 emit resourceAddressChanged(); 126 } 127 128 // Resource Port resourcePort()129 QString resourcePort() { 130 return m_resourcePort; 131 } 132 setResourcePort(const QString & resourcePort)133 void setResourcePort(const QString &resourcePort) { 134 if (resourcePort == m_resourcePort) 135 return; 136 137 m_resourcePort = resourcePort; 138 emit resourcePortChanged(); 139 } 140 141 // Remote Client isRemoteClient()142 bool isRemoteClient() { 143 return m_remoteClient; 144 } 145 setIsRemoteClient(bool remote)146 void setIsRemoteClient(bool remote) { 147 if (m_remoteClient == remote) { 148 return; 149 } 150 151 m_remoteClient = remote; 152 emit isRemoteClientChanged(); 153 } 154 155 // Dialog Success Message successMsg()156 QString successMsg() { 157 return m_successMsg; 158 } 159 setSuccessMessage(const QString & successMsg)160 void setSuccessMessage(const QString &successMsg) { 161 m_successMsg = successMsg; 162 emit successMessageChanged(); 163 } 164 165 // Dialog Error Message errorMsg()166 QString errorMsg() { 167 return m_errorMsg; 168 } 169 setErrorMessage(const QString & errorMsg)170 void setErrorMessage(const QString &errorMsg) { 171 m_errorMsg = errorMsg; 172 emit errorMessageChanged(); 173 } 174 175 // Model (If Edition Mode) setResModel(ResourceModel * resModel)176 void setResModel(ResourceModel *resModel) { 177 m_res = resModel->resource(); 178 setResCode(m_res->code); 179 setResourceName(m_res->hdr.name); 180 setResourcePassword(m_res->password); 181 setResourceAddress(m_res->address); 182 setResourcePort(QString::number(m_res->port)); 183 setIsRemoteClient(m_res->use_remote); 184 } 185 186 // Called if Save Mode setResType(QString resType)187 void setResType(QString resType) { 188 m_res = NULL; 189 setResourceName(""); 190 setResourcePassword(""); 191 setResourceAddress(""); 192 setIsRemoteClient(false); 193 194 if(resType == "1") { 195 setResCode(R_DIRECTOR); 196 setResourcePort("9101"); 197 } else if(resType == "2") { 198 setResCode(R_STORAGE); 199 setResourcePort("9103"); 200 } else { 201 setResCode(R_CLIENT); 202 setResourcePort("9102"); 203 } 204 } 205 206 signals: 207 // Events that are emitted to our GUI code to inform changes in our data 208 void resourceNameChanged(); 209 void resourcePasswordChanged(); 210 void resourceAddressChanged(); 211 void resourcePortChanged(); 212 void successMessageChanged(); 213 void errorMessageChanged(); 214 void isRemoteClientChanged(); 215 void resCodeChanged(); 216 217 public slots: 218 // Save the changes made to this resource on bacula-tray-monitor.conf 219 void saveChanges(); 220 isClient()221 bool isClient() { 222 return m_resCode == R_CLIENT; 223 } 224 225 }; 226 227 #endif // RESPANELGUICONTROLLER_H 228