| 1 | /* fre:ac - free audio converter |
| 2 | * Copyright (C) 2001-2022 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 "layer.h" |
| 14 | |
| 15 | #include "chooser/chooser_tracks.h" |
| 16 | #include "chooser/chooser_albums.h" |
| 17 | #include "chooser/chooser_files.h" |
| 18 | |
| 19 | #include "editor/editor_basic.h" |
| 20 | #include "editor/editor_details.h" |
| 21 | #include "editor/editor_lyrics.h" |
| 22 | #include "editor/editor_publisher.h" |
| 23 | #include "editor/editor_rating.h" |
| 24 | |
| 25 | #include "editor/editor_advanced.h" |
| 26 | |
| 27 | BoCA::LayerTags::LayerTags() : Layer("Tags") |
| 28 | { |
| 29 | tab_editor = NIL; |
| 30 | |
| 31 | /* Create choosers. |
| 32 | */ |
| 33 | tab_mode = new TabWidget(Point(7, 7), Size(100, 150)); |
| 34 | tab_mode->onSelectTab.Connect(&LayerTags::OnSelectTab, this); |
| 35 | |
| 36 | choosers.Add(new ChooserTracks()); |
| 37 | choosers.Add(new ChooserAlbums()); |
| 38 | choosers.Add(new ChooserFiles()); |
| 39 | |
| 40 | foreach (Chooser *chooser, choosers) |
| 41 | { |
| 42 | chooser->onSelectTrack.Connect(&onSelectTrack); |
| 43 | chooser->onSelectAlbum.Connect(&onSelectAlbum); |
| 44 | chooser->onSelectNone.Connect(&onSelectNone); |
| 45 | |
| 46 | chooser->allowTrackChangeByArrowKey.Connect(&LayerTags::AllowTrackChangeByArrowKey, this); |
| 47 | chooser->allowTrackRemoveByDeleteKey.Connect(&LayerTags::AllowTrackRemoveByDeleteKey, this); |
| 48 | |
| 49 | tab_mode->Add(chooser); |
| 50 | } |
| 51 | |
| 52 | /* Create editors. |
| 53 | */ |
| 54 | tab_editor = new TabWidget(Point(7, 226), Size(300, 218)); |
| 55 | tab_editor->SetOrientation(OR_LOWERLEFT); |
| 56 | |
| 57 | editors.Add(new LayerTagBasic()); |
| 58 | editors.Add(new LayerTagDetails()); |
| 59 | editors.Add(new LayerTagPublisher()); |
| 60 | editors.Add(new LayerTagLyrics()); |
| 61 | editors.Add(new LayerTagRating()); |
| 62 | |
| 63 | /* ToDo: Add advanced editor once it's ready. |
| 64 | */ |
| 65 | // editors.Add(new LayerTagAdvanced()); |
| 66 | |
| 67 | foreach (Editor *editor, editors) |
| 68 | { |
| 69 | editor->onModifyTrack.Connect(&LayerTags::OnModifyTrack, this); |
| 70 | |
| 71 | onSelectTrack.Connect(&Editor::OnSelectTrack, editor); |
| 72 | onSelectAlbum.Connect(&Editor::OnSelectAlbum, editor); |
| 73 | onSelectNone.Connect(&Editor::OnSelectNone, editor); |
| 74 | |
| 75 | tab_editor->Add(editor); |
| 76 | } |
| 77 | |
| 78 | Add(tab_editor); |
| 79 | Add(tab_mode); |
| 80 | |
| 81 | /* Connect slots. |
| 82 | */ |
| 83 | onChangeSize.Connect(&LayerTags::OnChangeSize, this); |
| 84 | |
| 85 | Settings::Get()->onChangeLanguageSettings.Connect(&LayerTags::OnChangeLanguageSettings, this); |
| 86 | } |
| 87 | |
| 88 | BoCA::LayerTags::~LayerTags() |
| 89 | { |
| 90 | /* Disconnect slots. |
| 91 | */ |
| 92 | Settings::Get()->onChangeLanguageSettings.Disconnect(&LayerTags::OnChangeLanguageSettings, this); |
| 93 | |
| 94 | /* Free choosers and editors. |
| 95 | */ |
| 96 | foreach (Chooser *chooser, choosers) DeleteObject(chooser); |
| 97 | foreach (Editor *editor, editors) DeleteObject(editor); |
| 98 | |
| 99 | DeleteObject(tab_mode); |
| 100 | DeleteObject(tab_editor); |
| 101 | } |
| 102 | |
| 103 | /* Called when component canvas size changes. |
| 104 | * ---- |
| 105 | */ |
| 106 | Void BoCA::LayerTags::OnChangeSize(const Size &nSize) |
| 107 | { |
| 108 | Rect clientRect = Rect(GetPosition(), GetSize()); |
| 109 | Size clientSize = Size(clientRect.right - clientRect.left, clientRect.bottom - clientRect.top); |
| 110 | |
| 111 | tab_mode->SetSize(Size(clientSize.cx - 15, clientSize.cy - 241)); |
| 112 | |
| 113 | tab_editor->SetWidth(clientSize.cx - 15); |
| 114 | } |
| 115 | |
| 116 | /* Called when application language is changed. |
| 117 | * ---- |
| 118 | */ |
| 119 | Void BoCA::LayerTags::OnChangeLanguageSettings() |
| 120 | { |
| 121 | I18n *i18n = I18n::Get(); |
| 122 | |
| 123 | i18n->SetContext("Extensions::Tag Editor"); |
| 124 | |
| 125 | SetText(i18n->TranslateString("Tags")); |
| 126 | } |
| 127 | |
| 128 | /* Called when a different chooser tab is selected. |
| 129 | * ---- |
| 130 | * Finds the correct chooser and reselects the correct entry. |
| 131 | */ |
| 132 | Void BoCA::LayerTags::OnSelectTab(const Widget *widget) |
| 133 | { |
| 134 | if (tab_editor == NIL) return; |
| 135 | |
| 136 | Surface *surface = GetDrawSurface(); |
| 137 | |
| 138 | surface->StartPaint(tab_editor->GetVisibleArea()); |
| 139 | |
| 140 | onSelectNone.Emit(); |
| 141 | |
| 142 | foreach (Chooser *chooser, choosers) |
| 143 | { |
| 144 | if (chooser == widget) chooser->ReselectEntry(); |
| 145 | } |
| 146 | |
| 147 | surface->EndPaint(); |
| 148 | } |
| 149 | |
| 150 | /* Called when a list entry is modified. |
| 151 | * ---- |
| 152 | * Passes the track on to the active chooser. |
| 153 | */ |
| 154 | Void BoCA::LayerTags::OnModifyTrack(const Track &track) |
| 155 | { |
| 156 | JobList::Get()->onComponentModifyTrack.Emit(track); |
| 157 | |
| 158 | ((Chooser *) tab_mode->GetSelectedTab())->OnModifyTrack(track); |
| 159 | } |
| 160 | |
| 161 | /* Called when a chooser wants to change the track by arrow key. |
| 162 | * ---- |
| 163 | * Collects and evaluates responses from editors. |
| 164 | */ |
| 165 | Bool BoCA::LayerTags::AllowTrackChangeByArrowKey() |
| 166 | { |
| 167 | foreach (Editor *editor, editors) |
| 168 | { |
| 169 | if (!editor->allowTrackChangeByArrowKey.Call()) return False; |
| 170 | } |
| 171 | |
| 172 | return True; |
| 173 | } |
| 174 | |
| 175 | /* Called when a chooser wants to delete a track by delete key. |
| 176 | * ---- |
| 177 | * Collects and evaluates responses from editors. |
| 178 | */ |
| 179 | Bool BoCA::LayerTags::AllowTrackRemoveByDeleteKey() |
| 180 | { |
| 181 | foreach (Editor *editor, editors) |
| 182 | { |
| 183 | if (!editor->allowTrackRemoveByDeleteKey.Call()) return False; |
| 184 | } |
| 185 | |
| 186 | return True; |
| 187 | } |