| 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 <dialogs/config/config_interface.h> |
| 14 | |
| 15 | #include <config.h> |
| 16 | |
| 17 | freac::ConfigureInterface::ConfigureInterface() |
| 18 | { |
| 19 | BoCA::Config *config = BoCA::Config::Get(); |
| 20 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 21 | |
| 22 | i18n->SetContext("Configuration::Joblist"); |
| 23 | |
| 24 | showJobs = config->GetIntValue(Config::CategorySettingsID, Config::SettingsShowJobsTabID, Config::SettingsShowJobsTabDefault); |
| 25 | |
| 26 | group_joblist = new GroupBox(i18n->TranslateString("Joblist"), Point(7, 11), Size(552, 184)); |
| 27 | |
| 28 | text_fields = new Text(i18n->AddColon(i18n->TranslateString("Columns")), Point(9, 12)); |
| 29 | |
| 30 | list_fields = new ListBox(Point(16 + text_fields->GetUnscaledTextWidth(), 10), group_joblist->GetSize() - Size(114 + text_fields->GetUnscaledTextWidth(), 20)); |
| 31 | list_fields->SetFlags(LF_ALLOWREORDER | LF_MULTICHECKBOX); |
| 32 | list_fields->AddTab(i18n->TranslateString("Name"), 100); |
| 33 | list_fields->AddTab(i18n->TranslateString("Description")); |
| 34 | list_fields->onSelectEntry.Connect(&ConfigureInterface::OnSelectJoblistField, this); |
| 35 | |
| 36 | /* Connect OnSelectJoblistField to check buttons state. |
| 37 | */ |
| 38 | list_fields->onChangeEntryOrder.Connect(&ConfigureInterface::OnSelectJoblistField, this); |
| 39 | |
| 40 | button_up = new Button(i18n->TranslateString("Up"), Point(90, 10), Size()); |
| 41 | button_up->SetOrientation(OR_UPPERRIGHT); |
| 42 | button_up->Deactivate(); |
| 43 | button_up->onAction.Connect(&ConfigureInterface::JoblistFieldMoveUp, this); |
| 44 | |
| 45 | button_down = new Button(i18n->TranslateString("Down"), Point(90, 40), Size()); |
| 46 | button_down->SetOrientation(OR_UPPERRIGHT); |
| 47 | button_down->Deactivate(); |
| 48 | button_down->onAction.Connect(&ConfigureInterface::JoblistFieldMoveDown, this); |
| 49 | |
| 50 | group_joblist->Add(text_fields); |
| 51 | group_joblist->Add(list_fields); |
| 52 | group_joblist->Add(button_up); |
| 53 | group_joblist->Add(button_down); |
| 54 | |
| 55 | group_jobs = new GroupBox(i18n->TranslateString("Jobs"), Point(7, 207), Size(552, 40)); |
| 56 | |
| 57 | check_show_jobs = new CheckBox(i18n->TranslateString("Show Jobs tab"), Point(10, 13), Size(group_jobs->GetWidth() - 20, 0), &showJobs); |
| 58 | |
| 59 | group_jobs->Add(check_show_jobs); |
| 60 | |
| 61 | FillJoblistFieldsList(); |
| 62 | |
| 63 | Add(group_joblist); |
| 64 | Add(group_jobs); |
| 65 | |
| 66 | SetSize(Size(566, 254)); |
| 67 | } |
| 68 | |
| 69 | freac::ConfigureInterface::~ConfigureInterface() |
| 70 | { |
| 71 | DeleteObject(group_joblist); |
| 72 | DeleteObject(text_fields); |
| 73 | DeleteObject(list_fields); |
| 74 | DeleteObject(button_up); |
| 75 | DeleteObject(button_down); |
| 76 | |
| 77 | DeleteObject(group_jobs); |
| 78 | DeleteObject(check_show_jobs); |
| 79 | } |
| 80 | |
| 81 | Void freac::ConfigureInterface::FillJoblistFieldsList() |
| 82 | { |
| 83 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 84 | |
| 85 | i18n->SetContext("Configuration::Joblist::Columns"); |
| 86 | |
| 87 | Array<String> entryTexts; |
| 88 | Array<Bool> entryPresent; |
| 89 | |
| 90 | entryTexts.Add(String("<artist>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Track artist"))); entryPresent.Add(False); |
| 91 | entryTexts.Add(String("<title>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Track title"))); entryPresent.Add(False); |
| 92 | entryTexts.Add(String("<genre>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Track genre"))); entryPresent.Add(False); |
| 93 | entryTexts.Add(String("<album>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Album title"))); entryPresent.Add(False); |
| 94 | entryTexts.Add(String("<albumartist>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Album artist"))); entryPresent.Add(False); |
| 95 | entryTexts.Add(String("<composer>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Composer"))); entryPresent.Add(False); |
| 96 | entryTexts.Add(String("<conductor>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Conductor"))); entryPresent.Add(False); |
| 97 | entryTexts.Add(String("<year>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Year"))); entryPresent.Add(False); |
| 98 | entryTexts.Add(String("<disc>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Disc number"))); entryPresent.Add(False); |
| 99 | entryTexts.Add(String("<track>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Track number"))); entryPresent.Add(False); |
| 100 | entryTexts.Add(String("<rating>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Track rating"))); entryPresent.Add(False); |
| 101 | entryTexts.Add(String("<time>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Track length"))); entryPresent.Add(False); |
| 102 | entryTexts.Add(String("<bytes>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Track size"))); entryPresent.Add(False); |
| 103 | entryTexts.Add(String("<bitrate>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Bitrate"))); entryPresent.Add(False); |
| 104 | entryTexts.Add(String("<samplerate>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Sampling rate"))); entryPresent.Add(False); |
| 105 | entryTexts.Add(String("<channels>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Channels"))); entryPresent.Add(False); |
| 106 | entryTexts.Add(String("<resolution>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Sample resolution"))); entryPresent.Add(False); |
| 107 | entryTexts.Add(String("<drive>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("CD drive"))); entryPresent.Add(False); |
| 108 | entryTexts.Add(String("<discid>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Disc ID"))); entryPresent.Add(False); |
| 109 | entryTexts.Add(String("<isrc>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("ISRC"))); entryPresent.Add(False); |
| 110 | entryTexts.Add(String("<tempo>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Tempo"))); entryPresent.Add(False); |
| 111 | entryTexts.Add(String("<initialkey>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Musical key"))); entryPresent.Add(False); |
| 112 | entryTexts.Add(String("<file>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("File name"))); entryPresent.Add(False); |
| 113 | entryTexts.Add(String("<filetype>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("File type"))); entryPresent.Add(False); |
| 114 | entryTexts.Add(String("<outputfile>").Append(ListEntry::tabDelimiter).Append(i18n->TranslateString("Output file name"))); entryPresent.Add(False); |
| 115 | |
| 116 | const Array<String> &fields = BoCA::Config::Get()->GetStringValue(Config::CategoryJoblistID, Config::JoblistFieldsID, Config::JoblistFieldsDefault).Explode(","); |
| 117 | |
| 118 | foreach (const String &field, fields) |
| 119 | { |
| 120 | for (Int i = 0; i < entryTexts.Length(); i++) |
| 121 | { |
| 122 | const String &entryText = entryTexts.GetNth(i); |
| 123 | |
| 124 | if (entryText.StartsWith(field)) { list_fields->AddEntry(entryText, True); entryPresent.SetNth(i, True); } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | for (Int i = 0; i < entryTexts.Length(); i++) |
| 129 | { |
| 130 | const String &entryText = entryTexts.GetNth(i); |
| 131 | |
| 132 | if (!entryPresent.GetNth(i)) list_fields->AddEntry(entryText, False); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | Void freac::ConfigureInterface::OnSelectJoblistField() |
| 137 | { |
| 138 | if (list_fields->GetSelectedEntryNumber() == 0) button_up->Deactivate(); |
| 139 | else button_up->Activate(); |
| 140 | |
| 141 | if (list_fields->GetSelectedEntryNumber() == list_fields->Length() - 1) button_down->Deactivate(); |
| 142 | else button_down->Activate(); |
| 143 | } |
| 144 | |
| 145 | Void freac::ConfigureInterface::JoblistFieldMoveUp() |
| 146 | { |
| 147 | list_fields->MoveEntry(list_fields->GetSelectedEntryNumber(), list_fields->GetSelectedEntryNumber() - 1); |
| 148 | |
| 149 | list_fields->Paint(SP_UPDATE); |
| 150 | } |
| 151 | |
| 152 | Void freac::ConfigureInterface::JoblistFieldMoveDown() |
| 153 | { |
| 154 | list_fields->MoveEntry(list_fields->GetSelectedEntryNumber(), list_fields->GetSelectedEntryNumber() + 1); |
| 155 | |
| 156 | list_fields->Paint(SP_UPDATE); |
| 157 | } |
| 158 | |
| 159 | Int freac::ConfigureInterface::SaveSettings() |
| 160 | { |
| 161 | String fields; |
| 162 | |
| 163 | for (Int i = 0; i < list_fields->Length(); i++) |
| 164 | { |
| 165 | ListEntry *entry = list_fields->GetNthEntry(i); |
| 166 | const String &entryText = entry->GetText(); |
| 167 | |
| 168 | if (entry->IsMarked()) fields = fields.Append(fields != NIL ? "," : NIL).Append(entryText.Head(entryText.Find(ListEntry::tabDelimiter))); |
| 169 | } |
| 170 | |
| 171 | BoCA::Config *config = BoCA::Config::Get(); |
| 172 | |
| 173 | config->SetStringValue(Config::CategoryJoblistID, Config::JoblistFieldsID, fields); |
| 174 | config->SetIntValue(Config::CategorySettingsID, Config::SettingsShowJobsTabID, showJobs); |
| 175 | |
| 176 | return Success(); |
| 177 | } |