| 207 | MythConfirmationDialog2::MythConfirmationDialog2(MythScreenStack *parent, |
| 208 | const QString &message, |
| 209 | bool showCancel) |
| 210 | : MythScreenType(parent, "mythconfirmpopup") |
| 211 | { |
| 212 | m_message = message; |
| 213 | m_showCancel = showCancel; |
| 214 | |
| 215 | m_result = -1; |
| 216 | m_initialized = false; |
| 217 | } |
| 218 | |
| 219 | MythConfirmationDialog2::MythConfirmationDialog2(const QString &message, |
| 220 | bool showCancel) |
| 221 | : MythScreenType(GetMythMainWindow()->GetStack("popup stack"), |
| 222 | "mythconfirmpopup") |
| 223 | { |
| 224 | m_message = message; |
| 225 | m_showCancel = showCancel; |
| 226 | |
| 227 | m_result = -1; |
| 228 | m_initialized = false; |
| 229 | } |
| 230 | |
| 231 | bool MythConfirmationDialog2::Create(void) |
| 232 | { |
| 233 | if (!CopyWindowFromBase("MythConfirmationDialog", this)) |
| 234 | return false; |
| 235 | |
| 236 | MythUIText *messageText = dynamic_cast<MythUIText *> |
| 237 | (GetChild("message")); |
| 238 | MythUIButton *okButton = dynamic_cast<MythUIButton *> |
| 239 | (GetChild("ok")); |
| 240 | MythUIButton *cancelButton = dynamic_cast<MythUIButton *> |
| 241 | (GetChild("cancel")); |
| 242 | |
| 243 | if (!messageText || !okButton || !cancelButton) |
| 244 | return false; |
| 245 | |
| 246 | if (m_showCancel) |
| 247 | { |
| 248 | connect(cancelButton, SIGNAL(buttonPressed()), SLOT(Cancel())); |
| 249 | } |
| 250 | else |
| 251 | cancelButton->SetVisible(false); |
| 252 | |
| 253 | connect(okButton, SIGNAL(buttonPressed()), SLOT(Confirm())); |
| 254 | |
| 255 | okButton->SetText(tr("Ok")); |
| 256 | cancelButton->SetText(tr("Cancel")); |
| 257 | |
| 258 | messageText->SetText(m_message); |
| 259 | |
| 260 | BuildFocusList(); |
| 261 | |
| 262 | return true; |
| 263 | } |
| 264 | |
| 265 | bool MythConfirmationDialog2::Exec(void) |
| 266 | { |
| 267 | if (!m_initialized) |
| 268 | { |
| 269 | if (!Create()) |
| 270 | { |
| 271 | VERBOSE(VB_IMPORTANT, "MythConfirmationDialog: Failed to create dialog"); |
| 272 | return false; |
| 273 | } |
| 274 | |
| 275 | m_initialized = true; |
| 276 | } |
| 277 | |
| 278 | GetScreenStack()->AddScreen(this); |
| 279 | |
| 280 | while (m_result == -1) |
| 281 | { |
| 282 | qApp->processEvents(); |
| 283 | usleep(500); |
| 284 | } |
| 285 | |
| 286 | Close(); |
| 287 | |
| 288 | return (m_result == 1); |
| 289 | } |
| 290 | |
| 291 | void MythConfirmationDialog2::Confirm() |
| 292 | { |
| 293 | m_result = 1; |
| 294 | } |
| 295 | |
| 296 | void MythConfirmationDialog2::Cancel() |
| 297 | { |
| 298 | m_result = 0; |
| 299 | } |
| 300 | |
| 301 | bool MythConfirmationDialog2::keyPressEvent(QKeyEvent *event) |
| 302 | { |
| 303 | if (GetFocusWidget()->keyPressEvent(event)) |
| 304 | return true; |
| 305 | |
| 306 | bool handled = false; |
| 307 | QStringList actions; |
| 308 | if (GetMythMainWindow()->TranslateKeyPress("qt", event, actions)) |
| 309 | { |
| 310 | for (int i = 0; i < actions.size() && !handled; i++) |
| 311 | { |
| 312 | QString action = actions[i]; |
| 313 | handled = true; |
| 314 | |
| 315 | if (action == "ESCAPE" || action == "MENU") |
| 316 | { |
| 317 | m_result = 0; |
| 318 | } |
| 319 | else |
| 320 | handled = false; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | if (!handled) |
| 325 | MythScreenType::keyPressEvent(event); |
| 326 | |
| 327 | // we don't want another screen to get these while the popup is visible |
| 328 | return true; |
| 329 | } |
| 330 | |
| 331 | |
| 332 | ///////////////////////////////////////////////////////////////// |
| 333 | |