const gchar *apply_profile_changes(void) { char *pf_dir_path, *pf_dir_path2, *pf_filename; GList *fl1, *fl2; profile_def *profile1, *profile2; gboolean found; emem_strbuf_t *message = ep_strbuf_new(NULL); const gchar *err_msg; /* First validate all profile names */ fl1 = edited_profile_list(); while (fl1) { profile1 = (profile_def *) fl1->data; g_strstrip(profile1->name); if ((err_msg = profile_name_is_valid(profile1->name)) != NULL) { ep_strbuf_printf(message, "%s", err_msg); return message->str; } fl1 = g_list_next(fl1); } /* Then do all copy profiles */ fl1 = edited_profile_list(); while (fl1) { profile1 = (profile_def *) fl1->data; g_strstrip(profile1->name); if (profile1->status == PROF_STAT_COPY) { if (create_persconffile_profile(profile1->name, &pf_dir_path) == -1) { ep_strbuf_printf(message, "Can't create directory\n\"%s\":\n%s.", pf_dir_path, g_strerror(errno)); g_free(pf_dir_path); } profile1->status = PROF_STAT_EXISTS; if (profile1->reference) { if (copy_persconffile_profile(profile1->name, profile1->reference, profile1->from_global, &pf_filename, &pf_dir_path, &pf_dir_path2) == -1) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't copy file \"%s\" in directory\n\"%s\" to\n\"%s\":\n%s.", pf_filename, pf_dir_path2, pf_dir_path, g_strerror(errno)); g_free(pf_filename); g_free(pf_dir_path); g_free(pf_dir_path2); } } g_free (profile1->reference); profile1->reference = g_strdup(profile1->name); } fl1 = g_list_next(fl1); } /* Then create new and rename changed */ fl1 = edited_profile_list(); while (fl1) { profile1 = (profile_def *) fl1->data; g_strstrip(profile1->name); if (profile1->status == PROF_STAT_NEW) { /* We do not create a directory for the default profile */ if (strcmp(profile1->name, DEFAULT_PROFILE)!=0) { if (create_persconffile_profile(profile1->name, &pf_dir_path) == -1) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't create directory\n\"%s\":\n%s.", pf_dir_path, g_strerror(errno)); g_free(pf_dir_path); } profile1->status = PROF_STAT_EXISTS; g_free (profile1->reference); profile1->reference = g_strdup(profile1->name); } } else if (profile1->status == PROF_STAT_CHANGED) { if (strcmp(profile1->reference, profile1->name)!=0) { /* Rename old profile directory to new */ if (rename_persconffile_profile(profile1->reference, profile1->name, &pf_dir_path, &pf_dir_path2) == -1) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't rename directory\n\"%s\" to\n\"%s\":\n%s.", pf_dir_path, pf_dir_path2, g_strerror(errno)); g_free(pf_dir_path); g_free(pf_dir_path2); } profile1->status = PROF_STAT_EXISTS; g_free (profile1->reference); profile1->reference = g_strdup(profile1->name); } } fl1 = g_list_next(fl1); } /* Last remove deleted */ fl1 = current_profile_list(); while (fl1) { found = FALSE; profile1 = (profile_def *) fl1->data; fl2 = edited_profile_list(); while (fl2) { profile2 = (profile_def *) fl2->data; if (!profile2->is_global) { if (strcmp(profile1->name, profile2->name)==0) { /* Profile exists in both lists */ found = TRUE; } else if (strcmp(profile1->name, profile2->reference)==0) { /* Profile has been renamed */ found = TRUE; } } fl2 = g_list_next(fl2); } if (!found) { /* Exists in existing list and not in edited, this is a deleted profile */ if (delete_persconffile_profile(profile1->name, &pf_dir_path) == -1) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't delete profile directory\n\"%s\":\n%s.", pf_dir_path, g_strerror(errno)); g_free(pf_dir_path); } } fl1 = g_list_next(fl1); } copy_profile_list(); return NULL; }
void ProfileDialog::updateWidgets() { QTreeWidgetItem *item = pd_ui_->profileTreeWidget->currentItem(); bool enable_new = false; bool enable_del = false; bool enable_copy = false; bool enable_ok = true; profile_def *current_profile = NULL; if (item) { current_profile = (profile_def *) VariantPointer<GList>::asPtr(item->data(0, Qt::UserRole))->data; enable_new = true; enable_copy = true; if (!current_profile->is_global && !(item->font(0).strikeOut())) { enable_del = true; } } if (current_profile) { QString profile_path; QString profile_info; switch (current_profile->status) { case PROF_STAT_DEFAULT: if (item->font(0).strikeOut()) { profile_info = tr("Will be reset to default values"); } else { profile_path = get_persconffile_path("", FALSE); } break; case PROF_STAT_EXISTS: { char* profile_dir = current_profile->is_global ? get_global_profiles_dir() : get_profiles_dir(); profile_path = profile_dir; g_free(profile_dir); profile_path.append(QDir::separator()).append(current_profile->name); } break; case PROF_STAT_COPY: if (current_profile->reference) { profile_info = tr("Created from %1").arg(current_profile->reference); if (current_profile->from_global) { profile_info.append(QString(" %1").arg(tr("(system provided)"))); } break; } /* Fall Through */ case PROF_STAT_NEW: profile_info = tr("Created from default settings"); break; case PROF_STAT_CHANGED: profile_info = tr("Renamed from %1").arg(current_profile->reference); break; } if (!profile_path.isEmpty()) { pd_ui_->infoLabel->setUrl(QUrl::fromLocalFile(profile_path).toString()); pd_ui_->infoLabel->setText(profile_path); pd_ui_->infoLabel->setToolTip(tr("Go to %1").arg(profile_path)); } else { pd_ui_->infoLabel->clear(); pd_ui_->infoLabel->setText(profile_info); } } else { pd_ui_->infoLabel->clear(); } if (pd_ui_->profileTreeWidget->topLevelItemCount() > 0) { profile_def *profile; for (int i = 0; i < pd_ui_->profileTreeWidget->topLevelItemCount(); i++) { item = pd_ui_->profileTreeWidget->topLevelItem(i); profile = (profile_def *) VariantPointer<GList>::asPtr(item->data(0, Qt::UserRole))->data; if (gchar *err_msg = profile_name_is_valid(profile->name)) { item->setToolTip(0, err_msg); item->setBackground(0, ColorUtils::fromColorT(&prefs.gui_text_invalid)); if (profile == current_profile) { pd_ui_->infoLabel->setText(err_msg); } g_free(err_msg); enable_ok = false; continue; } if (profile->is_global) { item->setToolTip(0, tr("This is a system provided profile.")); continue; } if (current_profile && !current_profile->is_global && profile != current_profile && strcmp(profile->name, current_profile->name) == 0) { item->setToolTip(0, tr("A profile already exists with this name.")); item->setBackground(0, ColorUtils::fromColorT(&prefs.gui_text_invalid)); if (current_profile->status != PROF_STAT_DEFAULT && current_profile->status != PROF_STAT_EXISTS) { pd_ui_->infoLabel->setText(tr("A profile already exists with this name")); } enable_ok = false; } else if (item->font(0).strikeOut()) { item->setToolTip(0, tr("The profile will be reset to default values.")); item->setBackground(0, ColorUtils::fromColorT(&prefs.gui_text_deprecated)); } else { item->setBackground(0, QBrush()); } } } pd_ui_->profileTreeWidget->resizeColumnToContents(0); pd_ui_->newToolButton->setEnabled(enable_new); pd_ui_->deleteToolButton->setEnabled(enable_del); pd_ui_->copyToolButton->setEnabled(enable_copy); ok_button_->setEnabled(enable_ok); }