Changeset View
Changeset View
Standalone View
Standalone View
src/EditProfileDialog.cpp
Show First 20 Lines • Show All 77 Lines • ▼ Show 20 Line(s) | 68 | { | |||
---|---|---|---|---|---|
78 | connect(mButtonBox, &QDialogButtonBox::accepted, this, &Konsole::EditProfileDialog::accept); | 78 | connect(mButtonBox, &QDialogButtonBox::accepted, this, &Konsole::EditProfileDialog::accept); | ||
79 | connect(mButtonBox, &QDialogButtonBox::rejected, this, &Konsole::EditProfileDialog::reject); | 79 | connect(mButtonBox, &QDialogButtonBox::rejected, this, &Konsole::EditProfileDialog::reject); | ||
80 | 80 | | |||
81 | // disable the apply button , since no modification has been made | 81 | // disable the apply button , since no modification has been made | ||
82 | mButtonBox->button(QDialogButtonBox::Apply)->setEnabled(false); | 82 | mButtonBox->button(QDialogButtonBox::Apply)->setEnabled(false); | ||
83 | 83 | | |||
84 | connect(mButtonBox->button(QDialogButtonBox::Apply), | 84 | connect(mButtonBox->button(QDialogButtonBox::Apply), | ||
85 | &QPushButton::clicked, this, | 85 | &QPushButton::clicked, this, | ||
86 | &Konsole::EditProfileDialog::save); | 86 | &Konsole::EditProfileDialog::apply); | ||
87 | 87 | | |||
88 | connect(_delayedPreviewTimer, &QTimer::timeout, this, | 88 | connect(_delayedPreviewTimer, &QTimer::timeout, this, | ||
89 | &Konsole::EditProfileDialog::delayedPreviewActivate); | 89 | &Konsole::EditProfileDialog::delayedPreviewActivate); | ||
90 | 90 | | |||
91 | _ui = new Ui::EditProfileDialog(); | 91 | _ui = new Ui::EditProfileDialog(); | ||
92 | _ui->setupUi(mainWidget); | 92 | _ui->setupUi(mainWidget); | ||
93 | mainLayout->addWidget(mButtonBox); | 93 | mainLayout->addWidget(mButtonBox); | ||
94 | 94 | | |||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
138 | void EditProfileDialog::reject() | 138 | void EditProfileDialog::reject() | ||
139 | { | 139 | { | ||
140 | unpreviewAll(); | 140 | unpreviewAll(); | ||
141 | QDialog::reject(); | 141 | QDialog::reject(); | ||
142 | } | 142 | } | ||
143 | 143 | | |||
144 | void EditProfileDialog::accept() | 144 | void EditProfileDialog::accept() | ||
145 | { | 145 | { | ||
146 | if (!isValidProfileName()) { | ||||
147 | return; | ||||
148 | } | ||||
149 | save(); | ||||
150 | unpreviewAll(); | ||||
151 | QDialog::accept(); | ||||
152 | } | ||||
153 | | ||||
154 | void EditProfileDialog::apply() | ||||
155 | { | ||||
156 | if (!isValidProfileName()) { | ||||
157 | return; | ||||
158 | } | ||||
159 | save(); | ||||
160 | } | ||||
161 | | ||||
162 | bool EditProfileDialog::isValidProfileName() | ||||
163 | { | ||||
146 | Q_ASSERT(_profile); | 164 | Q_ASSERT(_profile); | ||
147 | Q_ASSERT(_tempProfile); | 165 | Q_ASSERT(_tempProfile); | ||
148 | 166 | | |||
167 | const QList<Profile::Ptr> existingProfiles = ProfileManager::instance()->allProfiles(); | ||||
168 | QStringList otherExistingProfileNames; | ||||
169 | | ||||
170 | foreach(auto existingProfile, existingProfiles) { | ||||
171 | if (existingProfile->name() != _profile->name()) { | ||||
172 | otherExistingProfileNames.append(existingProfile->name()); | ||||
173 | } | ||||
174 | } | ||||
175 | | ||||
149 | if ((_tempProfile->isPropertySet(Profile::Name) | 176 | if ((_tempProfile->isPropertySet(Profile::Name) | ||
150 | && _tempProfile->name().isEmpty()) | 177 | && _tempProfile->name().isEmpty()) | ||
151 | || (_profile->name().isEmpty() && _tempProfile->name().isEmpty())) { | 178 | || (_profile->name().isEmpty() && _tempProfile->name().isEmpty())) { | ||
152 | KMessageBox::sorry(this, | 179 | KMessageBox::sorry(this, | ||
153 | i18n("<p>Each profile must have a name before it can be saved " | 180 | i18n("<p>Each profile must have a name before it can be saved " | ||
154 | "into disk.</p>")); | 181 | "into disk.</p>")); | ||
155 | return; | 182 | // revert the name in the dialog | ||
183 | _ui->profileNameEdit->setText(_profile->name()); | ||||
184 | selectProfileName(); | ||||
185 | return false; | ||||
186 | } else if (!_tempProfile->name().isEmpty() && otherExistingProfileNames.contains(_tempProfile->name())) { | ||||
187 | KMessageBox::sorry(this, | ||||
188 | i18n("<p>A profile with this name already exists.</p>")); | ||||
189 | // revert the name in the dialog | ||||
190 | _ui->profileNameEdit->setText(_profile->name()); | ||||
191 | selectProfileName(); | ||||
192 | return false; | ||||
193 | } else { | ||||
194 | return true; | ||||
156 | } | 195 | } | ||
157 | save(); | | |||
158 | unpreviewAll(); | | |||
159 | QDialog::accept(); | | |||
160 | } | 196 | } | ||
161 | 197 | | |||
162 | QString EditProfileDialog::groupProfileNames(const ProfileGroup::Ptr group, int maxLength) | 198 | QString EditProfileDialog::groupProfileNames(const ProfileGroup::Ptr group, int maxLength) | ||
163 | { | 199 | { | ||
164 | QString caption; | 200 | QString caption; | ||
165 | int count = group->profiles().count(); | 201 | int count = group->profiles().count(); | ||
166 | for (int i = 0; i < count; i++) { | 202 | for (int i = 0; i < count; i++) { | ||
167 | caption += group->profiles()[i]->name(); | 203 | caption += group->profiles()[i]->name(); | ||
▲ Show 20 Lines • Show All 1376 Lines • Show Last 20 Lines |