| 1 | /* fre:ac - free audio converter |
| 2 | * Copyright (C) 2001-2021 Robert Kausch <[email protected]> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License as |
| 6 | * published by the Free Software Foundation, either version 2 of |
| 7 | * the License, or (at your option) any later version. |
| 8 | * |
| 9 | * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR |
| 10 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
| 11 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ |
| 12 | |
| 13 | #include <dialogs/error.h> |
| 14 | |
| 15 | #include <config.h> |
| 16 | |
| 17 | #include <boca.h> |
| 18 | |
| 19 | freac::ErrorDialog::ErrorDialog(const Array<String> &errors) |
| 20 | { |
| 21 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 22 | |
| 23 | i18n->SetContext("Dialogs::Errors"); |
| 24 | |
| 25 | Rect workArea = S::System::Screen::GetActiveScreenWorkArea(); |
| 26 | |
| 27 | mainWnd = new Window(i18n->TranslateString("Errors"), workArea.GetPosition() + Point((workArea.GetSize().cx - 480) / 2, (workArea.GetSize().cy - 400) / 2), Size(480, 400)); |
| 28 | mainWnd->SetMinimumSize(Size(330, 220)); |
| 29 | mainWnd->SetRightToLeft(i18n->IsActiveLanguageRightToLeft()); |
| 30 | mainWnd->GetMainLayer()->onChangeSize.Connect(&ErrorDialog::OnChangeSize, this); |
| 31 | |
| 32 | mainWnd_titlebar = new Titlebar(TB_CLOSEBUTTON); |
| 33 | divbar = new Divider(39, OR_HORZ | OR_BOTTOM); |
| 34 | |
| 35 | btn_ok = new Button(i18n->TranslateString("OK"), Point(87, 29), Size()); |
| 36 | btn_ok->onAction.Connect(&ErrorDialog::OK, this); |
| 37 | btn_ok->SetOrientation(OR_LOWERRIGHT); |
| 38 | |
| 39 | text_errors = new Text(i18n->AddColon(i18n->TranslateString("%1 errors while processing job").Replace("%1", String::FromInt(errors.Length()))), Point(7, 5)); |
| 40 | |
| 41 | list_errors = new ListBox(Point(7, 24), Size(378, 157)); |
| 42 | list_errors->onSelectEntry.Connect(&ErrorDialog::OnSelectError, this); |
| 43 | |
| 44 | foreach (const String &error, errors) list_errors->AddEntry(error); |
| 45 | |
| 46 | edit_details = new MultiEdit(Point(7, 127), Size(378, 80)); |
| 47 | edit_details->SetOrientation(OR_LOWERLEFT); |
| 48 | edit_details->Deactivate(); |
| 49 | |
| 50 | text_details = new Text(i18n->TranslateString("select an entry for details"), Point()); |
| 51 | text_details->SetFont(GUI::Font(GUI::Font::Default, 12, GUI::Font::Bold, 0, Setup::InactiveTextColor)); |
| 52 | text_details->SetOrientation(OR_LOWERLEFT); |
| 53 | |
| 54 | Add(mainWnd); |
| 55 | |
| 56 | mainWnd->Add(btn_ok); |
| 57 | |
| 58 | mainWnd->Add(text_errors); |
| 59 | mainWnd->Add(list_errors); |
| 60 | |
| 61 | mainWnd->Add(edit_details); |
| 62 | mainWnd->Add(text_details); |
| 63 | |
| 64 | mainWnd->Add(mainWnd_titlebar); |
| 65 | mainWnd->Add(divbar); |
| 66 | |
| 67 | mainWnd->SetFlags(WF_MODAL); |
| 68 | mainWnd->SetIcon(ImageLoader::Load(String(Config::Get()->resourcesPath).Append("icons/freac.png"))); |
| 69 | } |
| 70 | |
| 71 | freac::ErrorDialog::~ErrorDialog() |
| 72 | { |
| 73 | DeleteObject(mainWnd_titlebar); |
| 74 | DeleteObject(mainWnd); |
| 75 | DeleteObject(divbar); |
| 76 | |
| 77 | DeleteObject(text_errors); |
| 78 | DeleteObject(list_errors); |
| 79 | |
| 80 | DeleteObject(edit_details); |
| 81 | DeleteObject(text_details); |
| 82 | |
| 83 | DeleteObject(btn_ok); |
| 84 | } |
| 85 | |
| 86 | const Error &freac::ErrorDialog::ShowDialog() |
| 87 | { |
| 88 | mainWnd->WaitUntilClosed(); |
| 89 | |
| 90 | return error; |
| 91 | } |
| 92 | |
| 93 | Void freac::ErrorDialog::OnChangeSize(const Size &nSize) |
| 94 | { |
| 95 | Rect clientRect = Rect(mainWnd->GetMainLayer()->GetPosition(), mainWnd->GetMainLayer()->GetSize()); |
| 96 | Size clientSize = Size(clientRect.right - clientRect.left, clientRect.bottom - clientRect.top); |
| 97 | |
| 98 | list_errors->SetSize(clientSize - Size(14, 159)); |
| 99 | |
| 100 | edit_details->SetWidth(clientSize.cx - 14); |
| 101 | text_details->SetPosition(edit_details->GetPosition() + Point((edit_details->GetWidth() - text_details->GetUnscaledTextWidth()) / 2, (-(edit_details->GetHeight() - text_details->GetUnscaledTextHeight())) / 2)); |
| 102 | } |
| 103 | |
| 104 | Void freac::ErrorDialog::OK() |
| 105 | { |
| 106 | mainWnd->Close(); |
| 107 | } |
| 108 | |
| 109 | Void freac::ErrorDialog::OnSelectError(ListEntry *error) |
| 110 | { |
| 111 | text_details->Hide(); |
| 112 | edit_details->SetText(error->GetText()); |
| 113 | } |