void MainSettingsDialog::openDeleteAutoProfileConfirmDialog() { QMessageBox msgBox; msgBox.setText(tr("Are you sure you want to delete the profile?")); msgBox.setStandardButtons(QMessageBox::Discard | QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Cancel); int ret = msgBox.exec(); if (ret == QMessageBox::Discard) { int selectedRow = ui->autoProfileTableWidget->currentRow(); if (selectedRow >= 0) { QTableWidgetItem *item = ui->autoProfileTableWidget->item(selectedRow, 5); //QTableWidgetItem *itemDefault = ui->autoProfileTableWidget->item(selectedRow, 4); AutoProfileInfo *info = item->data(Qt::UserRole).value<AutoProfileInfo*>(); if (info->isCurrentDefault()) { if (info->getGUID() == "all") { delete allDefaultProfile; allDefaultProfile = 0; } else if (defaultAutoProfiles.contains(info->getGUID())) { defaultAutoProfiles.remove(info->getGUID()); defaultList.removeAll(info); delete info; info = 0; } } else { if (deviceAutoProfiles.contains(info->getGUID())) { QList<AutoProfileInfo*> temp = deviceAutoProfiles.value(info->getGUID()); temp.removeAll(info); deviceAutoProfiles.insert(info->getGUID(), temp); } if (exeAutoProfiles.contains(info->getExe())) { QList<AutoProfileInfo*> temp = exeAutoProfiles.value(info->getExe()); temp.removeAll(info); exeAutoProfiles.insert(info->getExe(), temp); } profileList.removeAll(info); delete info; info = 0; } } ui->autoProfileTableWidget->removeRow(selectedRow); } }
void MainSettingsDialog::addNewAutoProfile() { AddEditAutoProfileDialog *dialog = static_cast<AddEditAutoProfileDialog*>(sender()); AutoProfileInfo *info = dialog->getAutoProfile(); bool found = false; if (info->isCurrentDefault()) { if (defaultAutoProfiles.contains(info->getGUID())) { found = true; } } else { QList<AutoProfileInfo*> templist; if (exeAutoProfiles.contains(info->getExe())) { templist = exeAutoProfiles.value(info->getExe()); } QListIterator<AutoProfileInfo*> iterProfiles(templist); while (iterProfiles.hasNext()) { AutoProfileInfo *oldinfo = iterProfiles.next(); if (info->getExe() == oldinfo->getExe() && info->getGUID() == oldinfo->getGUID()) { found = true; iterProfiles.toBack(); } } } if (!found) { if (info->isCurrentDefault()) { if (!info->getGUID().isEmpty() && !info->getProfileLocation().isEmpty()) { defaultAutoProfiles.insert(info->getGUID(), info); defaultList.append(info); } } else { if (!info->getGUID().isEmpty() && !info->getProfileLocation().isEmpty() && !info->getExe().isEmpty()) { QList<AutoProfileInfo*> templist; templist.append(info); exeAutoProfiles.insert(info->getExe(), templist); profileList.append(info); QList<AutoProfileInfo*> tempDevProfileList; if (deviceAutoProfiles.contains(info->getGUID())) { tempDevProfileList = deviceAutoProfiles.value(info->getGUID()); } tempDevProfileList.append(info); deviceAutoProfiles.insert(info->getGUID(), tempDevProfileList); } } fillGUIDComboBox(); changeDeviceForProfileTable(ui->devicesComboBox->currentIndex()); } }
void MainSettingsDialog::transferEditsToCurrentTableRow() { AddEditAutoProfileDialog *dialog = static_cast<AddEditAutoProfileDialog*>(sender()); AutoProfileInfo *info = dialog->getAutoProfile(); // Delete pointers to object that might be misplaced // due to an association change. QString oldGUID = dialog->getOriginalGUID(); QString originalExe = dialog->getOriginalExe(); if (oldGUID != info->getGUID()) { if (defaultAutoProfiles.value(oldGUID) == info) { defaultAutoProfiles.remove(oldGUID); } if (info->isCurrentDefault()) { defaultAutoProfiles.insert(info->getGUID(), info); } } if (oldGUID != info->getGUID() && deviceAutoProfiles.contains(oldGUID)) { QList<AutoProfileInfo*> temp = deviceAutoProfiles.value(oldGUID); temp.removeAll(info); if (temp.count() > 0) { deviceAutoProfiles.insert(oldGUID, temp); } else { deviceAutoProfiles.remove(oldGUID); } if (deviceAutoProfiles.contains(info->getGUID())) { QList<AutoProfileInfo*> temp2 = deviceAutoProfiles.value(oldGUID); if (!temp2.contains(info)) { temp2.append(info); deviceAutoProfiles.insert(info->getGUID(), temp2); } } else if (info->getGUID().toLower() != "all") { QList<AutoProfileInfo*> temp2; temp2.append(info); deviceAutoProfiles.insert(info->getGUID(), temp2); } } else if (oldGUID != info->getGUID() && info->getGUID().toLower() != "all") { QList<AutoProfileInfo*> temp; temp.append(info); deviceAutoProfiles.insert(info->getGUID(), temp); } if (!info->isCurrentDefault()) { defaultList.removeAll(info); if (!profileList.contains(info)) { profileList.append(info); } } else { profileList.removeAll(info); if (!defaultList.contains(info)) { defaultList.append(info); } } if (originalExe != info->getExe() && exeAutoProfiles.contains(originalExe)) { QList<AutoProfileInfo*> temp = exeAutoProfiles.value(originalExe); temp.removeAll(info); exeAutoProfiles.insert(originalExe, temp); if (exeAutoProfiles.contains(info->getExe())) { QList<AutoProfileInfo*> temp2 = exeAutoProfiles.value(info->getExe()); if (!temp2.contains(info)) { temp2.append(info); exeAutoProfiles.insert(info->getExe(), temp2); } } else { QList<AutoProfileInfo*> temp2; temp2.append(info); exeAutoProfiles.insert(info->getExe(), temp2); } if (deviceAutoProfiles.contains(info->getGUID())) { QList<AutoProfileInfo*> temp2 = deviceAutoProfiles.value(info->getGUID()); if (!temp2.contains(info)) { temp2.append(info); deviceAutoProfiles.insert(info->getGUID(), temp2); } } else { QList<AutoProfileInfo*> temp2; temp2.append(info); deviceAutoProfiles.insert(info->getGUID(), temp2); } } fillGUIDComboBox(); changeDeviceForProfileTable(ui->devicesComboBox->currentIndex()); }