Changeset 84436 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- May 21, 2020 3:50:17 PM (5 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r84375 r84436 970 970 src/hostnetwork/UIHostNetworkManager.cpp \ 971 971 src/manager/UIWelcomePane.cpp \ 972 src/manager/chooser/UIChooserAbstractModel.cpp \ 972 973 src/monitor/resource/UIResourceMonitor.cpp \ 973 974 src/snapshots/UISnapshotDetailsWidget.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.cpp
r84434 r84436 15 15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 16 16 */ 17 18 /* Qt includes: */ 19 #include <QThread> 17 20 18 21 /* GUI includes: */ … … 40 43 /* Type defs: */ 41 44 typedef QSet<QString> UIStringSet; 45 46 47 /** QThread subclass allowing to save group settings asynchronously. */ 48 class UIThreadGroupSettingsSave : public QThread 49 { 50 Q_OBJECT; 51 52 signals: 53 54 /** Notifies about machine with certain @a uMachineId to be reloaded. */ 55 void sigReload(const QUuid &uMachineId); 56 57 /** Notifies about task is complete. */ 58 void sigComplete(); 59 60 public: 61 62 /** Returns group settings saving thread instance. */ 63 static UIThreadGroupSettingsSave *instance(); 64 /** Prepares group settings saving thread instance. */ 65 static void prepare(); 66 /** Cleanups group settings saving thread instance. */ 67 static void cleanup(); 68 69 /** Configures @a group settings saving thread with corresponding @a pListener. 70 * @param oldLists Brings the old settings list to be compared. 71 * @param newLists Brings the new settings list to be saved. */ 72 void configure(QObject *pParent, 73 const QMap<QString, QStringList> &oldLists, 74 const QMap<QString, QStringList> &newLists); 75 76 protected: 77 78 /** Constructs group settings saving thread. */ 79 UIThreadGroupSettingsSave(); 80 /** Destructs group settings saving thread. */ 81 virtual ~UIThreadGroupSettingsSave() /* override */; 82 83 /** Contains a thread task to be executed. */ 84 void run(); 85 86 /** Holds the singleton instance. */ 87 static UIThreadGroupSettingsSave *s_pInstance; 88 89 /** Holds the map of group settings to be compared. */ 90 QMap<QString, QStringList> m_oldLists; 91 /** Holds the map of group settings to be saved. */ 92 QMap<QString, QStringList> m_newLists; 93 }; 94 95 96 /** QThread subclass allowing to save group definitions asynchronously. */ 97 class UIThreadGroupDefinitionsSave : public QThread 98 { 99 Q_OBJECT; 100 101 signals: 102 103 /** Notifies about task is complete. */ 104 void sigComplete(); 105 106 public: 107 108 /** Returns group definitions saving thread instance. */ 109 static UIThreadGroupDefinitionsSave *instance(); 110 /** Prepares group definitions saving thread instance. */ 111 static void prepare(); 112 /** Cleanups group definitions saving thread instance. */ 113 static void cleanup(); 114 115 /** Configures group definitions saving thread with corresponding @a pListener. 116 * @param lists Brings definitions lists to be saved. */ 117 void configure(QObject *pListener, 118 const QMap<QString, QStringList> &lists); 119 120 protected: 121 122 /** Constructs group definitions saving thread. */ 123 UIThreadGroupDefinitionsSave(); 124 /** Destructs group definitions saving thread. */ 125 virtual ~UIThreadGroupDefinitionsSave() /* override */; 126 127 /** Contains a thread task to be executed. */ 128 virtual void run() /* override */; 129 130 /** Holds the singleton instance. */ 131 static UIThreadGroupDefinitionsSave *s_pInstance; 132 133 /** Holds the map of group definitions to be saved. */ 134 QMap<QString, QStringList> m_lists; 135 }; 136 137 138 /********************************************************************************************************************************* 139 * Class UIThreadGroupSettingsSave implementation. * 140 *********************************************************************************************************************************/ 141 142 /* static */ 143 UIThreadGroupSettingsSave *UIThreadGroupSettingsSave::s_pInstance = 0; 144 145 /* static */ 146 UIThreadGroupSettingsSave *UIThreadGroupSettingsSave::instance() 147 { 148 return s_pInstance; 149 } 150 151 /* static */ 152 void UIThreadGroupSettingsSave::prepare() 153 { 154 /* Make sure instance is not prepared: */ 155 if (s_pInstance) 156 return; 157 158 /* Crate instance: */ 159 new UIThreadGroupSettingsSave; 160 } 161 162 /* static */ 163 void UIThreadGroupSettingsSave::cleanup() 164 { 165 /* Make sure instance is prepared: */ 166 if (!s_pInstance) 167 return; 168 169 /* Delete instance: */ 170 delete s_pInstance; 171 } 172 173 void UIThreadGroupSettingsSave::configure(QObject *pParent, 174 const QMap<QString, QStringList> &oldLists, 175 const QMap<QString, QStringList> &newLists) 176 { 177 m_oldLists = oldLists; 178 m_newLists = newLists; 179 UIChooserAbstractModel *pChooserAbstractModel = qobject_cast<UIChooserAbstractModel*>(pParent); 180 AssertPtrReturnVoid(pChooserAbstractModel); 181 { 182 connect(this, &UIThreadGroupSettingsSave::sigComplete, 183 pChooserAbstractModel, &UIChooserAbstractModel::sltGroupSettingsSaveComplete); 184 } 185 } 186 187 UIThreadGroupSettingsSave::UIThreadGroupSettingsSave() 188 { 189 /* Assign instance: */ 190 s_pInstance = this; 191 } 192 193 UIThreadGroupSettingsSave::~UIThreadGroupSettingsSave() 194 { 195 /* Make sure thread work is complete: */ 196 wait(); 197 198 /* Erase instance: */ 199 s_pInstance = 0; 200 } 201 202 void UIThreadGroupSettingsSave::run() 203 { 204 /* COM prepare: */ 205 COMBase::InitializeCOM(false); 206 207 /* For every particular machine ID: */ 208 foreach (const QString &strId, m_newLists.keys()) 209 { 210 /* Get new group list/set: */ 211 const QStringList &newGroupList = m_newLists.value(strId); 212 const UIStringSet &newGroupSet = UIStringSet::fromList(newGroupList); 213 /* Get old group list/set: */ 214 const QStringList &oldGroupList = m_oldLists.value(strId); 215 const UIStringSet &oldGroupSet = UIStringSet::fromList(oldGroupList); 216 /* Make sure group set changed: */ 217 if (newGroupSet == oldGroupSet) 218 continue; 219 220 /* The next steps are subsequent. 221 * Every of them is mandatory in order to continue 222 * with common cleanup in case of failure. 223 * We have to simulate a try-catch block. */ 224 CSession comSession; 225 CMachine comMachine; 226 do 227 { 228 /* 1. Open session: */ 229 comSession = uiCommon().openSession(QUuid(strId)); 230 if (comSession.isNull()) 231 break; 232 233 /* 2. Get session machine: */ 234 comMachine = comSession.GetMachine(); 235 if (comMachine.isNull()) 236 break; 237 238 /* 3. Set new groups: */ 239 comMachine.SetGroups(newGroupList.toVector()); 240 if (!comMachine.isOk()) 241 { 242 msgCenter().cannotSetGroups(comMachine); 243 break; 244 } 245 246 /* 4. Save settings: */ 247 comMachine.SaveSettings(); 248 if (!comMachine.isOk()) 249 { 250 msgCenter().cannotSaveMachineSettings(comMachine); 251 break; 252 } 253 } while (0); 254 255 /* Cleanup if necessary: */ 256 if (comMachine.isNull() || !comMachine.isOk()) 257 emit sigReload(QUuid(strId)); 258 if (!comSession.isNull()) 259 comSession.UnlockMachine(); 260 } 261 262 /* Notify listeners about completeness: */ 263 emit sigComplete(); 264 265 /* COM cleanup: */ 266 COMBase::CleanupCOM(); 267 } 268 269 270 /********************************************************************************************************************************* 271 * Class UIThreadGroupDefinitionsSave implementation. * 272 *********************************************************************************************************************************/ 273 274 /* static */ 275 UIThreadGroupDefinitionsSave *UIThreadGroupDefinitionsSave::s_pInstance = 0; 276 277 /* static */ 278 UIThreadGroupDefinitionsSave *UIThreadGroupDefinitionsSave::instance() 279 { 280 return s_pInstance; 281 } 282 283 /* static */ 284 void UIThreadGroupDefinitionsSave::prepare() 285 { 286 /* Make sure instance is not prepared: */ 287 if (s_pInstance) 288 return; 289 290 /* Crate instance: */ 291 new UIThreadGroupDefinitionsSave; 292 } 293 294 /* static */ 295 void UIThreadGroupDefinitionsSave::cleanup() 296 { 297 /* Make sure instance is prepared: */ 298 if (!s_pInstance) 299 return; 300 301 /* Delete instance: */ 302 delete s_pInstance; 303 } 304 305 void UIThreadGroupDefinitionsSave::configure(QObject *pParent, 306 const QMap<QString, QStringList> &groups) 307 { 308 m_lists = groups; 309 UIChooserAbstractModel *pChooserAbstractModel = qobject_cast<UIChooserAbstractModel*>(pParent); 310 AssertPtrReturnVoid(pChooserAbstractModel); 311 { 312 connect(this, &UIThreadGroupDefinitionsSave::sigComplete, 313 pChooserAbstractModel, &UIChooserAbstractModel::sltGroupDefinitionsSaveComplete); 314 } 315 } 316 317 UIThreadGroupDefinitionsSave::UIThreadGroupDefinitionsSave() 318 { 319 /* Assign instance: */ 320 s_pInstance = this; 321 } 322 323 UIThreadGroupDefinitionsSave::~UIThreadGroupDefinitionsSave() 324 { 325 /* Make sure thread work is complete: */ 326 wait(); 327 328 /* Erase instance: */ 329 s_pInstance = 0; 330 } 331 332 void UIThreadGroupDefinitionsSave::run() 333 { 334 /* COM prepare: */ 335 COMBase::InitializeCOM(false); 336 337 /* Clear all the extra-data records related to group definitions: */ 338 gEDataManager->clearSelectorWindowGroupsDefinitions(); 339 /* For every particular group definition: */ 340 foreach (const QString &strId, m_lists.keys()) 341 gEDataManager->setSelectorWindowGroupsDefinitions(strId, m_lists[strId]); 342 343 /* Notify listeners about completeness: */ 344 emit sigComplete(); 345 346 /* COM cleanup: */ 347 COMBase::CleanupCOM(); 348 } 42 349 43 350 … … 1100 1407 1101 1408 1102 /********************************************************************************************************************************* 1103 * Class UIThreadGroupSettingsSave implementation. * 1104 *********************************************************************************************************************************/ 1105 1106 /* static */ 1107 UIThreadGroupSettingsSave *UIThreadGroupSettingsSave::s_pInstance = 0; 1108 1109 /* static */ 1110 UIThreadGroupSettingsSave *UIThreadGroupSettingsSave::instance() 1111 { 1112 return s_pInstance; 1113 } 1114 1115 /* static */ 1116 void UIThreadGroupSettingsSave::prepare() 1117 { 1118 /* Make sure instance is not prepared: */ 1119 if (s_pInstance) 1120 return; 1121 1122 /* Crate instance: */ 1123 new UIThreadGroupSettingsSave; 1124 } 1125 1126 /* static */ 1127 void UIThreadGroupSettingsSave::cleanup() 1128 { 1129 /* Make sure instance is prepared: */ 1130 if (!s_pInstance) 1131 return; 1132 1133 /* Delete instance: */ 1134 delete s_pInstance; 1135 } 1136 1137 void UIThreadGroupSettingsSave::configure(QObject *pParent, 1138 const QMap<QString, QStringList> &oldLists, 1139 const QMap<QString, QStringList> &newLists) 1140 { 1141 m_oldLists = oldLists; 1142 m_newLists = newLists; 1143 UIChooserAbstractModel *pChooserAbstractModel = qobject_cast<UIChooserAbstractModel*>(pParent); 1144 AssertPtrReturnVoid(pChooserAbstractModel); 1145 { 1146 connect(this, &UIThreadGroupSettingsSave::sigComplete, 1147 pChooserAbstractModel, &UIChooserAbstractModel::sltGroupSettingsSaveComplete); 1148 } 1149 } 1150 1151 UIThreadGroupSettingsSave::UIThreadGroupSettingsSave() 1152 { 1153 /* Assign instance: */ 1154 s_pInstance = this; 1155 } 1156 1157 UIThreadGroupSettingsSave::~UIThreadGroupSettingsSave() 1158 { 1159 /* Make sure thread work is complete: */ 1160 wait(); 1161 1162 /* Erase instance: */ 1163 s_pInstance = 0; 1164 } 1165 1166 void UIThreadGroupSettingsSave::run() 1167 { 1168 /* COM prepare: */ 1169 COMBase::InitializeCOM(false); 1170 1171 /* For every particular machine ID: */ 1172 foreach (const QString &strId, m_newLists.keys()) 1173 { 1174 /* Get new group list/set: */ 1175 const QStringList &newGroupList = m_newLists.value(strId); 1176 const UIStringSet &newGroupSet = UIStringSet::fromList(newGroupList); 1177 /* Get old group list/set: */ 1178 const QStringList &oldGroupList = m_oldLists.value(strId); 1179 const UIStringSet &oldGroupSet = UIStringSet::fromList(oldGroupList); 1180 /* Make sure group set changed: */ 1181 if (newGroupSet == oldGroupSet) 1182 continue; 1183 1184 /* The next steps are subsequent. 1185 * Every of them is mandatory in order to continue 1186 * with common cleanup in case of failure. 1187 * We have to simulate a try-catch block. */ 1188 CSession comSession; 1189 CMachine comMachine; 1190 do 1191 { 1192 /* 1. Open session: */ 1193 comSession = uiCommon().openSession(QUuid(strId)); 1194 if (comSession.isNull()) 1195 break; 1196 1197 /* 2. Get session machine: */ 1198 comMachine = comSession.GetMachine(); 1199 if (comMachine.isNull()) 1200 break; 1201 1202 /* 3. Set new groups: */ 1203 comMachine.SetGroups(newGroupList.toVector()); 1204 if (!comMachine.isOk()) 1205 { 1206 msgCenter().cannotSetGroups(comMachine); 1207 break; 1208 } 1209 1210 /* 4. Save settings: */ 1211 comMachine.SaveSettings(); 1212 if (!comMachine.isOk()) 1213 { 1214 msgCenter().cannotSaveMachineSettings(comMachine); 1215 break; 1216 } 1217 } while (0); 1218 1219 /* Cleanup if necessary: */ 1220 if (comMachine.isNull() || !comMachine.isOk()) 1221 emit sigReload(QUuid(strId)); 1222 if (!comSession.isNull()) 1223 comSession.UnlockMachine(); 1224 } 1225 1226 /* Notify listeners about completeness: */ 1227 emit sigComplete(); 1228 1229 /* COM cleanup: */ 1230 COMBase::CleanupCOM(); 1231 } 1232 1233 1234 /********************************************************************************************************************************* 1235 * Class UIThreadGroupDefinitionsSave implementation. * 1236 *********************************************************************************************************************************/ 1237 1238 /* static */ 1239 UIThreadGroupDefinitionsSave *UIThreadGroupDefinitionsSave::s_pInstance = 0; 1240 1241 /* static */ 1242 UIThreadGroupDefinitionsSave *UIThreadGroupDefinitionsSave::instance() 1243 { 1244 return s_pInstance; 1245 } 1246 1247 /* static */ 1248 void UIThreadGroupDefinitionsSave::prepare() 1249 { 1250 /* Make sure instance is not prepared: */ 1251 if (s_pInstance) 1252 return; 1253 1254 /* Crate instance: */ 1255 new UIThreadGroupDefinitionsSave; 1256 } 1257 1258 /* static */ 1259 void UIThreadGroupDefinitionsSave::cleanup() 1260 { 1261 /* Make sure instance is prepared: */ 1262 if (!s_pInstance) 1263 return; 1264 1265 /* Delete instance: */ 1266 delete s_pInstance; 1267 } 1268 1269 void UIThreadGroupDefinitionsSave::configure(QObject *pParent, 1270 const QMap<QString, QStringList> &groups) 1271 { 1272 m_lists = groups; 1273 UIChooserAbstractModel *pChooserAbstractModel = qobject_cast<UIChooserAbstractModel*>(pParent); 1274 AssertPtrReturnVoid(pChooserAbstractModel); 1275 { 1276 connect(this, &UIThreadGroupDefinitionsSave::sigComplete, 1277 pChooserAbstractModel, &UIChooserAbstractModel::sltGroupDefinitionsSaveComplete); 1278 } 1279 } 1280 1281 UIThreadGroupDefinitionsSave::UIThreadGroupDefinitionsSave() 1282 { 1283 /* Assign instance: */ 1284 s_pInstance = this; 1285 } 1286 1287 UIThreadGroupDefinitionsSave::~UIThreadGroupDefinitionsSave() 1288 { 1289 /* Make sure thread work is complete: */ 1290 wait(); 1291 1292 /* Erase instance: */ 1293 s_pInstance = 0; 1294 } 1295 1296 void UIThreadGroupDefinitionsSave::run() 1297 { 1298 /* COM prepare: */ 1299 COMBase::InitializeCOM(false); 1300 1301 /* Clear all the extra-data records related to group definitions: */ 1302 gEDataManager->clearSelectorWindowGroupsDefinitions(); 1303 /* For every particular group definition: */ 1304 foreach (const QString &strId, m_lists.keys()) 1305 gEDataManager->setSelectorWindowGroupsDefinitions(strId, m_lists[strId]); 1306 1307 /* Notify listeners about completeness: */ 1308 emit sigComplete(); 1309 1310 /* COM cleanup: */ 1311 COMBase::CleanupCOM(); 1312 } 1409 #include "UIChooserAbstractModel.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.h
r84434 r84436 22 22 #endif 23 23 24 /* Qt includes: */25 #include <QThread>26 27 24 /* GUI includes: */ 28 25 #include "UIChooserDefs.h" … … 38 35 class CCloudMachine; 39 36 class CMachine; 40 41 37 42 38 /** QObject extension used as VM Chooser-pane abstract model. … … 269 265 }; 270 266 271 272 /** QThread subclass allowing to save group settings asynchronously. */273 class UIThreadGroupSettingsSave : public QThread274 {275 Q_OBJECT;276 277 signals:278 279 /** Notifies about machine with certain @a uMachineId to be reloaded. */280 void sigReload(const QUuid &uMachineId);281 282 /** Notifies about task is complete. */283 void sigComplete();284 285 public:286 287 /** Returns group settings saving thread instance. */288 static UIThreadGroupSettingsSave *instance();289 /** Prepares group settings saving thread instance. */290 static void prepare();291 /** Cleanups group settings saving thread instance. */292 static void cleanup();293 294 /** Configures @a group settings saving thread with corresponding @a pListener.295 * @param oldLists Brings the old settings list to be compared.296 * @param newLists Brings the new settings list to be saved. */297 void configure(QObject *pParent,298 const QMap<QString, QStringList> &oldLists,299 const QMap<QString, QStringList> &newLists);300 301 protected:302 303 /** Constructs group settings saving thread. */304 UIThreadGroupSettingsSave();305 /** Destructs group settings saving thread. */306 virtual ~UIThreadGroupSettingsSave() /* override */;307 308 /** Contains a thread task to be executed. */309 void run();310 311 /** Holds the singleton instance. */312 static UIThreadGroupSettingsSave *s_pInstance;313 314 /** Holds the map of group settings to be compared. */315 QMap<QString, QStringList> m_oldLists;316 /** Holds the map of group settings to be saved. */317 QMap<QString, QStringList> m_newLists;318 };319 320 321 /** QThread subclass allowing to save group definitions asynchronously. */322 class UIThreadGroupDefinitionsSave : public QThread323 {324 Q_OBJECT;325 326 signals:327 328 /** Notifies about task is complete. */329 void sigComplete();330 331 public:332 333 /** Returns group definitions saving thread instance. */334 static UIThreadGroupDefinitionsSave *instance();335 /** Prepares group definitions saving thread instance. */336 static void prepare();337 /** Cleanups group definitions saving thread instance. */338 static void cleanup();339 340 /** Configures group definitions saving thread with corresponding @a pListener.341 * @param lists Brings definitions lists to be saved. */342 void configure(QObject *pListener,343 const QMap<QString, QStringList> &lists);344 345 protected:346 347 /** Constructs group definitions saving thread. */348 UIThreadGroupDefinitionsSave();349 /** Destructs group definitions saving thread. */350 virtual ~UIThreadGroupDefinitionsSave() /* override */;351 352 /** Contains a thread task to be executed. */353 virtual void run() /* override */;354 355 /** Holds the singleton instance. */356 static UIThreadGroupDefinitionsSave *s_pInstance;357 358 /** Holds the map of group definitions to be saved. */359 QMap<QString, QStringList> m_lists;360 };361 362 363 267 #endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserAbstractModel_h */
Note:
See TracChangeset
for help on using the changeset viewer.