| 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/overwrite.h> |
| 14 | |
| 15 | #include <config.h> |
| 16 | |
| 17 | freac::DialogConfirmOverwrite::DialogConfirmOverwrite(const Array<BoCA::Track> &tracks) |
| 18 | { |
| 19 | userAction = ConfirmOverwrite::Action::None; |
| 20 | |
| 21 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 22 | |
| 23 | i18n->SetContext("Dialogs::Overwrite"); |
| 24 | |
| 25 | Rect workArea = S::System::Screen::GetActiveScreenWorkArea(); |
| 26 | |
| 27 | mainWnd = new Window(i18n->TranslateString("Confirm overwrite"), workArea.GetPosition() + Point((workArea.GetSize().cx - 565) / 2, (workArea.GetSize().cy - 375) / 2), Size(565, 375)); |
| 28 | mainWnd->SetMinimumSize(Size(400, 220)); |
| 29 | mainWnd->SetRightToLeft(i18n->IsActiveLanguageRightToLeft()); |
| 30 | mainWnd->GetMainLayer()->onChangeSize.Connect(&DialogConfirmOverwrite::OnChangeSize, this); |
| 31 | |
| 32 | mainWnd_titlebar = new Titlebar(TB_CLOSEBUTTON); |
| 33 | divbar = new Divider(39, OR_HORZ | OR_BOTTOM); |
| 34 | |
| 35 | button_overwrite = new Button(i18n->TranslateString("Confirm"), Point(87, 29), Size()); |
| 36 | button_overwrite->onAction.Connect(&DialogConfirmOverwrite::OnOverwrite, this); |
| 37 | button_overwrite->SetOrientation(OR_LOWERRIGHT); |
| 38 | button_overwrite->SetWidth(Math::Max(80, button_overwrite->GetUnscaledTextWidth() + 14)); |
| 39 | button_overwrite->SetX(7 + button_overwrite->GetWidth()); |
| 40 | |
| 41 | button_skip = new Button(i18n->TranslateString("Skip all"), Point(175, 29), Size()); |
| 42 | button_skip->onAction.Connect(&DialogConfirmOverwrite::OnSkip, this); |
| 43 | button_skip->SetOrientation(OR_LOWERRIGHT); |
| 44 | button_skip->SetWidth(Math::Max(80, button_skip->GetUnscaledTextWidth() + 14)); |
| 45 | button_skip->SetX(15 + button_overwrite->GetWidth() + button_skip->GetWidth()); |
| 46 | |
| 47 | button_cancel = new Button(i18n->TranslateString("Cancel"), Point(183 + button_skip->GetWidth(), 29), Size()); |
| 48 | button_cancel->onAction.Connect(&DialogConfirmOverwrite::OnCancel, this); |
| 49 | button_cancel->SetOrientation(OR_LOWERRIGHT); |
| 50 | button_cancel->SetX(103 + button_skip->GetWidth() + button_overwrite->GetWidth()); |
| 51 | |
| 52 | text_files = new Text(i18n->AddColon(i18n->TranslateString("The following %1 files already exist or have duplicate file names").Replace("%1", String::FromInt(tracks.Length()))), Point(7, 5)); |
| 53 | |
| 54 | Config *freacConfig = Config::Get(); |
| 55 | |
| 56 | i18n->SetContext("Joblist"); |
| 57 | |
| 58 | button_select_all = new Button(ImageLoader::Load(String(freacConfig->resourcesPath).Append("icons/select/select-all.png")), Point(-2, 20), Size(21, 21)); |
| 59 | button_select_all->onAction.Connect(&DialogConfirmOverwrite::SelectAll, this); |
| 60 | button_select_all->SetFlags(BF_NOFRAME); |
| 61 | button_select_all->SetTooltipText(i18n->TranslateString("Select all")); |
| 62 | |
| 63 | button_select_none = new Button(ImageLoader::Load(String(freacConfig->resourcesPath).Append("icons/select/select-none.png")), Point(-2, 34), Size(21, 21)); |
| 64 | button_select_none->onAction.Connect(&DialogConfirmOverwrite::SelectNone, this); |
| 65 | button_select_none->SetFlags(BF_NOFRAME); |
| 66 | button_select_none->SetTooltipText(i18n->TranslateString("Select none")); |
| 67 | |
| 68 | button_select_toggle = new Button(ImageLoader::Load(String(freacConfig->resourcesPath).Append("icons/select/select-toggle.png")), Point(-2, 48), Size(21, 21)); |
| 69 | button_select_toggle->onAction.Connect(&DialogConfirmOverwrite::ToggleSelection, this); |
| 70 | button_select_toggle->SetFlags(BF_NOFRAME); |
| 71 | button_select_toggle->SetTooltipText(i18n->TranslateString("Toggle selection")); |
| 72 | |
| 73 | i18n->SetContext("Dialogs::Overwrite"); |
| 74 | |
| 75 | list_files = new ListBox(Point(17, 24), Size(378, 90)); |
| 76 | list_files->SetFlags(LF_MULTICHECKBOX); |
| 77 | list_files->onMarkEntry.Connect(&DialogConfirmOverwrite::OnMarkEntry, this); |
| 78 | list_files->AddTab(i18n->TranslateString("File name")); |
| 79 | list_files->AddTab(i18n->TranslateString("Action"), Math::Max(75, Math::Max(list_files->GetFont().GetUnscaledTextSizeX(i18n->TranslateString("Overwrite")), list_files->GetFont().GetUnscaledTextSizeX(i18n->TranslateString("Skip"))) + 25)); |
| 80 | |
| 81 | foreach (const BoCA::Track &track, tracks) |
| 82 | { |
| 83 | ListEntry *entry = list_files->AddEntry(String(track.outputFile).Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Overwrite")), True); |
| 84 | |
| 85 | entry->SetTooltipText(track.outputFile); |
| 86 | } |
| 87 | |
| 88 | Add(mainWnd); |
| 89 | |
| 90 | mainWnd->Add(button_skip); |
| 91 | mainWnd->Add(button_overwrite); |
| 92 | mainWnd->Add(button_cancel); |
| 93 | |
| 94 | mainWnd->Add(text_files); |
| 95 | |
| 96 | mainWnd->Add(button_select_all); |
| 97 | mainWnd->Add(button_select_none); |
| 98 | mainWnd->Add(button_select_toggle); |
| 99 | |
| 100 | mainWnd->Add(list_files); |
| 101 | |
| 102 | mainWnd->Add(mainWnd_titlebar); |
| 103 | mainWnd->Add(divbar); |
| 104 | |
| 105 | mainWnd->SetFlags(WF_MODAL); |
| 106 | mainWnd->SetIcon(ImageLoader::Load(String(Config::Get()->resourcesPath).Append("icons/freac.png"))); |
| 107 | } |
| 108 | |
| 109 | freac::DialogConfirmOverwrite::~DialogConfirmOverwrite() |
| 110 | { |
| 111 | DeleteObject(mainWnd_titlebar); |
| 112 | DeleteObject(mainWnd); |
| 113 | DeleteObject(divbar); |
| 114 | |
| 115 | DeleteObject(text_files); |
| 116 | |
| 117 | DeleteObject(button_select_all); |
| 118 | DeleteObject(button_select_none); |
| 119 | DeleteObject(button_select_toggle); |
| 120 | |
| 121 | DeleteObject(list_files); |
| 122 | |
| 123 | DeleteObject(button_skip); |
| 124 | DeleteObject(button_overwrite); |
| 125 | DeleteObject(button_cancel); |
| 126 | } |
| 127 | |
| 128 | const Error &freac::DialogConfirmOverwrite::ShowDialog() |
| 129 | { |
| 130 | mainWnd->WaitUntilClosed(); |
| 131 | |
| 132 | return error; |
| 133 | } |
| 134 | |
| 135 | Int freac::DialogConfirmOverwrite::GetUserAction() const |
| 136 | { |
| 137 | return userAction; |
| 138 | } |
| 139 | |
| 140 | const Array<Int> &freac::DialogConfirmOverwrite::GetUserActions() const |
| 141 | { |
| 142 | static Array<Int> userActions; |
| 143 | |
| 144 | userActions.RemoveAll(); |
| 145 | |
| 146 | for (Int i = 0; i < list_files->Length(); i++) |
| 147 | { |
| 148 | if (GetUserAction() == ConfirmOverwrite::Action::Confirm) userActions.Add(list_files->GetNthEntry(i)->IsMarked() ? ConfirmOverwrite::Action::Overwrite : ConfirmOverwrite::Action::Skip); |
| 149 | else if (GetUserAction() == ConfirmOverwrite::Action::SkipAll) userActions.Add(ConfirmOverwrite::Action::Skip); |
| 150 | else userActions.Add(ConfirmOverwrite::Action::None); |
| 151 | } |
| 152 | |
| 153 | return userActions; |
| 154 | } |
| 155 | |
| 156 | Void freac::DialogConfirmOverwrite::OnChangeSize(const Size &nSize) |
| 157 | { |
| 158 | Rect clientRect = Rect(mainWnd->GetMainLayer()->GetPosition(), mainWnd->GetMainLayer()->GetSize()); |
| 159 | Size clientSize = Size(clientRect.right - clientRect.left, clientRect.bottom - clientRect.top); |
| 160 | |
| 161 | list_files->SetSize(clientSize - Size(24, 71)); |
| 162 | } |
| 163 | |
| 164 | Void freac::DialogConfirmOverwrite::SelectAll() |
| 165 | { |
| 166 | for (Int i = 0; i < list_files->Length(); i++) |
| 167 | { |
| 168 | if (!list_files->GetNthEntry(i)->IsMarked()) list_files->GetNthEntry(i)->SetMark(True); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | Void freac::DialogConfirmOverwrite::SelectNone() |
| 173 | { |
| 174 | for (Int i = 0; i < list_files->Length(); i++) |
| 175 | { |
| 176 | if (list_files->GetNthEntry(i)->IsMarked()) list_files->GetNthEntry(i)->SetMark(False); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | Void freac::DialogConfirmOverwrite::ToggleSelection() |
| 181 | { |
| 182 | for (Int i = 0; i < list_files->Length(); i++) |
| 183 | { |
| 184 | if (list_files->GetNthEntry(i)->IsMarked()) list_files->GetNthEntry(i)->SetMark(False); |
| 185 | else list_files->GetNthEntry(i)->SetMark(True); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | Void freac::DialogConfirmOverwrite::OnMarkEntry(ListEntry *entry) |
| 190 | { |
| 191 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 192 | |
| 193 | i18n->SetContext("Dialogs::Overwrite"); |
| 194 | |
| 195 | String file = entry->GetText().Head(entry->GetText().FindLast(ListEntry::tabDelimiter)); |
| 196 | String action = i18n->TranslateString("Overwrite"); |
| 197 | |
| 198 | if (!entry->IsMarked()) action = i18n->TranslateString("Skip"); |
| 199 | |
| 200 | entry->SetText(String(file).Append(ListEntry::tabDelimiter).Append(action)); |
| 201 | } |
| 202 | |
| 203 | Void freac::DialogConfirmOverwrite::OnSkip() |
| 204 | { |
| 205 | userAction = ConfirmOverwrite::Action::SkipAll; |
| 206 | |
| 207 | mainWnd->Close(); |
| 208 | } |
| 209 | |
| 210 | Void freac::DialogConfirmOverwrite::OnOverwrite() |
| 211 | { |
| 212 | userAction = ConfirmOverwrite::Action::Confirm; |
| 213 | |
| 214 | mainWnd->Close(); |
| 215 | } |
| 216 | |
| 217 | Void freac::DialogConfirmOverwrite::OnCancel() |
| 218 | { |
| 219 | userAction = ConfirmOverwrite::Action::Cancel; |
| 220 | |
| 221 | mainWnd->Close(); |
| 222 | } |