| 1 | /* fre:ac - free audio converter |
| 2 | * Copyright (C) 2001-2019 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 <gui/main_threads.h> |
| 14 | #include <jobs/job.h> |
| 15 | |
| 16 | #include <boca.h> |
| 17 | |
| 18 | using namespace smooth::GUI::Dialogs; |
| 19 | |
| 20 | using namespace BoCA; |
| 21 | using namespace BoCA::AS; |
| 22 | |
| 23 | freac::LayerThreads::LayerThreads() : Layer("Jobs") |
| 24 | { |
| 25 | text_progress = new Text(NIL, Point(7, 11)); |
| 26 | |
| 27 | list_threads = new ListBox(Point(7, 35), Size(500, 360)); |
| 28 | list_threads->onSelectEntry.Connect(&LayerThreads::OnSelectJob, this); |
| 29 | list_threads->SetFlags(LF_ALLOWRESELECT); |
| 30 | list_threads->EnableLocking(); |
| 31 | |
| 32 | text_errors = new Text(NIL, Point(7, 25)); |
| 33 | text_errors->SetOrientation(OR_LOWERLEFT); |
| 34 | |
| 35 | edit_errors = new EditBox(Point(text_errors->GetUnscaledTextWidth() + 14, 28), Size(25, 0)); |
| 36 | edit_errors->SetOrientation(OR_LOWERLEFT); |
| 37 | edit_errors->Deactivate(); |
| 38 | |
| 39 | combo_errors = new ComboBox(Point(text_errors->GetUnscaledTextWidth() + 47, 28), Size(250, 0)); |
| 40 | combo_errors->SetOrientation(OR_LOWERLEFT); |
| 41 | |
| 42 | button_details = new Button(String(), Point(87, 29), Size(80, 0)); |
| 43 | button_details->onAction.Connect(&LayerThreads::ShowDetails, this); |
| 44 | button_details->SetOrientation(OR_LOWERRIGHT); |
| 45 | |
| 46 | Add(text_progress); |
| 47 | Add(list_threads); |
| 48 | |
| 49 | Add(text_errors); |
| 50 | Add(edit_errors); |
| 51 | Add(combo_errors); |
| 52 | Add(button_details); |
| 53 | |
| 54 | OnChangeJobs(); |
| 55 | |
| 56 | /* Connect slots. |
| 57 | */ |
| 58 | BoCA::Settings::Get()->onChangeLanguageSettings.Connect(&LayerThreads::OnChangeLanguageSettings, this); |
| 59 | |
| 60 | onChangeSize.Connect(&LayerThreads::OnChangeSize, this); |
| 61 | |
| 62 | Job::onChange.Connect(&LayerThreads::OnChangeJobs, this); |
| 63 | } |
| 64 | |
| 65 | freac::LayerThreads::~LayerThreads() |
| 66 | { |
| 67 | /* Disconnect slots. |
| 68 | */ |
| 69 | Job::onChange.Disconnect(&LayerThreads::OnChangeJobs, this); |
| 70 | |
| 71 | BoCA::Settings::Get()->onChangeLanguageSettings.Disconnect(&LayerThreads::OnChangeLanguageSettings, this); |
| 72 | |
| 73 | /* Delete widgets. |
| 74 | */ |
| 75 | DeleteObject(text_progress); |
| 76 | DeleteObject(list_threads); |
| 77 | |
| 78 | DeleteObject(text_errors); |
| 79 | DeleteObject(edit_errors); |
| 80 | DeleteObject(combo_errors); |
| 81 | DeleteObject(button_details); |
| 82 | } |
| 83 | |
| 84 | Void freac::LayerThreads::OnChangeSize(const Size &nSize) |
| 85 | { |
| 86 | Rect clientRect = Rect(GetPosition(), GetSize()); |
| 87 | Size clientSize = Size(clientRect.right - clientRect.left, clientRect.bottom - clientRect.top); |
| 88 | |
| 89 | list_threads->SetSize(clientSize - Size(15, 72)); |
| 90 | |
| 91 | combo_errors->SetWidth(clientSize.cx - text_errors->GetUnscaledTextWidth() - 142); |
| 92 | } |
| 93 | |
| 94 | Void freac::LayerThreads::OnChangeLanguageSettings() |
| 95 | { |
| 96 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 97 | |
| 98 | i18n->SetContext("Jobs"); |
| 99 | |
| 100 | SetText(i18n->TranslateString("Jobs")); |
| 101 | |
| 102 | /* Hide all affected widgets prior to changing |
| 103 | * labels to avoid flickering. |
| 104 | */ |
| 105 | Bool prevVisible = IsVisible(); |
| 106 | |
| 107 | if (prevVisible) Hide(); |
| 108 | |
| 109 | text_progress->SetText(i18n->AddColon(i18n->TranslateString("Progress"))); |
| 110 | text_errors->SetText(i18n->AddColon(i18n->TranslateString("Errors / Warnings"))); |
| 111 | |
| 112 | edit_errors->SetX(text_errors->GetUnscaledTextWidth() + 14); |
| 113 | combo_errors->SetX(text_errors->GetUnscaledTextWidth() + 47); |
| 114 | |
| 115 | button_details->SetText(i18n->TranslateString("Details")); |
| 116 | |
| 117 | /* OnChangeSize will correct sizes of any other widgets. |
| 118 | */ |
| 119 | OnChangeSize(GetSize()); |
| 120 | |
| 121 | /* Show all widgets again. |
| 122 | */ |
| 123 | if (prevVisible) Show(); |
| 124 | } |
| 125 | |
| 126 | Void freac::LayerThreads::OnChangeJobs() |
| 127 | { |
| 128 | Surface *surface = (IsVisible() ? GetDrawSurface() : NIL); |
| 129 | |
| 130 | if (surface) surface->StartPaint(GetVisibleArea()); |
| 131 | |
| 132 | list_threads->RemoveAllEntries(); |
| 133 | |
| 134 | text_errors->Deactivate(); |
| 135 | edit_errors->SetText("0/0"); |
| 136 | |
| 137 | combo_errors->RemoveAllEntries(); |
| 138 | combo_errors->Deactivate(); |
| 139 | |
| 140 | button_details->Deactivate(); |
| 141 | |
| 142 | const Array<Job *> &jobs = Job::GetAllJobs(); |
| 143 | |
| 144 | foreach (Job *job, jobs) |
| 145 | { |
| 146 | list_threads->Add(job); |
| 147 | |
| 148 | if (job->IsSelected()) OnSelectJob(job); |
| 149 | } |
| 150 | |
| 151 | if (surface) surface->EndPaint(); |
| 152 | } |
| 153 | |
| 154 | Void freac::LayerThreads::OnSelectJob(ListEntry *entry) |
| 155 | { |
| 156 | Job *job = (Job *) entry; |
| 157 | |
| 158 | const Array<String> errors = job->GetErrors(); |
| 159 | const Array<String> warnings = job->GetWarnings(); |
| 160 | |
| 161 | text_errors->Activate(); |
| 162 | edit_errors->SetText(String::FromInt(errors.Length()).Append("/").Append(String::FromInt(warnings.Length()))); |
| 163 | |
| 164 | combo_errors->RemoveAllEntries(); |
| 165 | |
| 166 | if (errors.Length() > 0 || warnings.Length() > 0) |
| 167 | { |
| 168 | combo_errors->Activate(); |
| 169 | button_details->Activate(); |
| 170 | |
| 171 | foreach (const String &error, errors) combo_errors->AddEntry(error); |
| 172 | foreach (const String &warning, warnings) combo_errors->AddEntry(warning); |
| 173 | |
| 174 | combo_errors->Paint(SP_PAINT); |
| 175 | } |
| 176 | else |
| 177 | { |
| 178 | combo_errors->Deactivate(); |
| 179 | button_details->Deactivate(); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | Void freac::LayerThreads::ShowDetails() |
| 184 | { |
| 185 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 186 | |
| 187 | i18n->SetContext("Jobs"); |
| 188 | |
| 189 | QuickMessage(combo_errors->GetSelectedEntry()->GetText(), i18n->TranslateString("Error details"), Message::Buttons::Ok, Message::Icon::Information); |
| 190 | } |