| 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 "config.h" |
| 14 | |
| 15 | using namespace smooth::GUI::Dialogs; |
| 16 | |
| 17 | const String BoCA::ConfigureProtocols::ConfigID = "Logging"; |
| 18 | |
| 19 | BoCA::ConfigureProtocols::ConfigureProtocols() |
| 20 | { |
| 21 | const Config *config = Config::Get(); |
| 22 | I18n *i18n = I18n::Get(); |
| 23 | |
| 24 | i18n->SetContext("Extensions::Logging::Configuration"); |
| 25 | |
| 26 | showLogsTab = config->GetIntValue(ConfigID, "ShowLogsTab", True); |
| 27 | |
| 28 | archiveLogs = config->GetIntValue(ConfigID, "ArchiveLogs", True); |
| 29 | deleteLogs = config->GetIntValue(ConfigID, "DeleteLogs", True); |
| 30 | |
| 31 | logCompletePaths = config->GetIntValue(ConfigID, "LogCompletePaths", False); |
| 32 | saveConversionLogsWithFiles = config->GetIntValue(ConfigID, "SaveConversionLogsWithFiles", False); |
| 33 | saveRippingLogsOnly = config->GetIntValue(ConfigID, "SaveRippingLogsOnly", True); |
| 34 | |
| 35 | /* Create UI group. |
| 36 | */ |
| 37 | group_ui = new GroupBox(i18n->TranslateString("User interface"), Point(7, 11), Size(480, 41)); |
| 38 | |
| 39 | check_ui_showTab = new CheckBox(i18n->TranslateString("Show Logs tab in main window"), Point(10, 14), Size(group_ui->GetWidth() - 20, 0), &showLogsTab); |
| 40 | |
| 41 | group_ui->Add(check_ui_showTab); |
| 42 | |
| 43 | /* Create Logs group. |
| 44 | */ |
| 45 | group_logs = new GroupBox(i18n->TranslateString("Log files"), Point(7, 63), Size(480, 95)); |
| 46 | |
| 47 | check_logs_archive = new CheckBox(i18n->TranslateString("Archive log files"), Point(10, 14), Size(group_logs->GetWidth() - 108, 0), &archiveLogs); |
| 48 | check_logs_archive->onAction.Connect(&ConfigureProtocols::ToggleArchiveLogs, this); |
| 49 | |
| 50 | text_logs_folder = new Text(i18n->AddColon(i18n->TranslateString("Log file folder")), Point(27, 42)); |
| 51 | edit_logs_folder = new EditBox(config->GetStringValue(ConfigID, "LogsFolder", String(config->cacheDir).Append("logs").Append(Directory::GetDirectoryDelimiter())), Point(text_logs_folder->GetUnscaledTextWidth() + 34, 39), Size(group_logs->GetWidth() - text_logs_folder->GetUnscaledTextWidth() - 132, 0)); |
| 52 | |
| 53 | btn_logs_select = new Button(i18n->TranslateString("Select"), Point(90, 38), Size(0, 0)); |
| 54 | btn_logs_select->onAction.Connect(&ConfigureProtocols::SelectFolder, this); |
| 55 | btn_logs_select->SetOrientation(OR_UPPERRIGHT); |
| 56 | |
| 57 | check_logs_delete = new CheckBox(i18n->AddColon(i18n->TranslateString("Delete old log files after")), Point(27, 67), Size(0, 0), &deleteLogs); |
| 58 | check_logs_delete->SetWidth(check_logs_delete->GetUnscaledTextWidth() + 21); |
| 59 | check_logs_delete->onAction.Connect(&ConfigureProtocols::ToggleDeleteLogs, this); |
| 60 | |
| 61 | edit_logs_days = new EditBox(String::FromInt(config->GetIntValue(ConfigID, "DeleteLogsDays", 30)), Point(check_logs_delete->GetWidth() + 34, 66), Size(18, 0), 3); |
| 62 | edit_logs_days->SetFlags(EDB_NUMERIC); |
| 63 | edit_logs_days->SetWidth(edit_logs_days->GetFont().GetUnscaledTextSizeX("000") + 6); |
| 64 | |
| 65 | text_logs_days = new Text(i18n->TranslateString("days"), Point(check_logs_delete->GetWidth() + edit_logs_days->GetWidth() + 41, 69)); |
| 66 | |
| 67 | group_logs->Add(check_logs_archive); |
| 68 | group_logs->Add(text_logs_folder); |
| 69 | group_logs->Add(edit_logs_folder); |
| 70 | group_logs->Add(btn_logs_select); |
| 71 | group_logs->Add(check_logs_delete); |
| 72 | group_logs->Add(edit_logs_days); |
| 73 | group_logs->Add(text_logs_days); |
| 74 | |
| 75 | /* Create Conversion group. |
| 76 | */ |
| 77 | group_conversion = new GroupBox(i18n->TranslateString("Conversion logs"), Point(7, 169), Size(480, 114)); |
| 78 | |
| 79 | check_complete_paths = new CheckBox(i18n->TranslateString("Log complete file paths"), Point(10, 14), Size(group_conversion->GetWidth() - 20, 0), &logCompletePaths); |
| 80 | |
| 81 | check_conversion_logs = new CheckBox(i18n->TranslateString("Save conversion logs with audio files"), Point(10, 37), Size(group_conversion->GetWidth() - 20, 0), &saveConversionLogsWithFiles); |
| 82 | check_conversion_logs->onAction.Connect(&ConfigureProtocols::ToggleSaveConversionLogsWithFiles, this); |
| 83 | |
| 84 | check_conversion_ripping = new CheckBox(i18n->TranslateString("Audio CD ripping logs only"), Point(27, 60), Size(group_conversion->GetWidth() - 37, 0), &saveRippingLogsOnly); |
| 85 | |
| 86 | String defaultName = String("<albumartist> - <album>").Append(Directory::GetDirectoryDelimiter()).Append("<albumartist> - <album>"); |
| 87 | |
| 88 | text_conversion_filename = new Text(i18n->AddColon(i18n->TranslateString("Filename pattern")), Point(27, 88)); |
| 89 | edit_conversion_filename = new EditBox(config->GetStringValue(ConfigID, "ConversionLogPattern", defaultName), Point(text_conversion_filename->GetUnscaledTextWidth() + 34, 85), Size(group_conversion->GetWidth() - text_conversion_filename->GetUnscaledTextWidth() - 44, 0)); |
| 90 | |
| 91 | list_conversion_filename = new List(); |
| 92 | list_conversion_filename->AddEntry(String("<albumartist> - <album>")); |
| 93 | list_conversion_filename->AddEntry(String("<albumartist> - <album>").Append(Directory::GetDirectoryDelimiter()).Append("<albumartist> - <album>")); |
| 94 | |
| 95 | edit_conversion_filename->SetDropDownList(list_conversion_filename); |
| 96 | |
| 97 | group_conversion->Add(check_complete_paths); |
| 98 | group_conversion->Add(check_conversion_logs); |
| 99 | group_conversion->Add(check_conversion_ripping); |
| 100 | group_conversion->Add(text_conversion_filename); |
| 101 | group_conversion->Add(edit_conversion_filename); |
| 102 | |
| 103 | Add(group_ui); |
| 104 | Add(group_logs); |
| 105 | Add(group_conversion); |
| 106 | |
| 107 | ToggleArchiveLogs(); |
| 108 | ToggleSaveConversionLogsWithFiles(); |
| 109 | |
| 110 | SetSize(Size(group_ui->GetWidth() + 14, 290)); |
| 111 | } |
| 112 | |
| 113 | BoCA::ConfigureProtocols::~ConfigureProtocols() |
| 114 | { |
| 115 | DeleteObject(group_ui); |
| 116 | DeleteObject(check_ui_showTab); |
| 117 | |
| 118 | DeleteObject(group_logs); |
| 119 | DeleteObject(check_logs_archive); |
| 120 | DeleteObject(text_logs_folder); |
| 121 | DeleteObject(edit_logs_folder); |
| 122 | DeleteObject(btn_logs_select); |
| 123 | DeleteObject(check_logs_delete); |
| 124 | DeleteObject(edit_logs_days); |
| 125 | DeleteObject(text_logs_days); |
| 126 | |
| 127 | DeleteObject(group_conversion); |
| 128 | DeleteObject(check_complete_paths); |
| 129 | DeleteObject(check_conversion_logs); |
| 130 | DeleteObject(check_conversion_ripping); |
| 131 | DeleteObject(text_conversion_filename); |
| 132 | DeleteObject(edit_conversion_filename); |
| 133 | DeleteObject(list_conversion_filename); |
| 134 | } |
| 135 | |
| 136 | Void BoCA::ConfigureProtocols::ToggleArchiveLogs() |
| 137 | { |
| 138 | if (archiveLogs) |
| 139 | { |
| 140 | text_logs_folder->Activate(); |
| 141 | edit_logs_folder->Activate(); |
| 142 | btn_logs_select->Activate(); |
| 143 | |
| 144 | check_logs_delete->Activate(); |
| 145 | |
| 146 | ToggleDeleteLogs(); |
| 147 | } |
| 148 | else |
| 149 | { |
| 150 | text_logs_folder->Deactivate(); |
| 151 | edit_logs_folder->Deactivate(); |
| 152 | btn_logs_select->Deactivate(); |
| 153 | |
| 154 | check_logs_delete->Deactivate(); |
| 155 | edit_logs_days->Deactivate(); |
| 156 | text_logs_days->Deactivate(); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | Void BoCA::ConfigureProtocols::ToggleDeleteLogs() |
| 161 | { |
| 162 | if (deleteLogs) |
| 163 | { |
| 164 | edit_logs_days->Activate(); |
| 165 | text_logs_days->Activate(); |
| 166 | } |
| 167 | else |
| 168 | { |
| 169 | edit_logs_days->Deactivate(); |
| 170 | text_logs_days->Deactivate(); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | Void BoCA::ConfigureProtocols::ToggleSaveConversionLogsWithFiles() |
| 175 | { |
| 176 | if (saveConversionLogsWithFiles) |
| 177 | { |
| 178 | check_conversion_ripping->Activate(); |
| 179 | text_conversion_filename->Activate(); |
| 180 | edit_conversion_filename->Activate(); |
| 181 | } |
| 182 | else |
| 183 | { |
| 184 | check_conversion_ripping->Deactivate(); |
| 185 | text_conversion_filename->Deactivate(); |
| 186 | edit_conversion_filename->Deactivate(); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | Void BoCA::ConfigureProtocols::SelectFolder() |
| 191 | { |
| 192 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 193 | |
| 194 | i18n->SetContext("Extensions::Logging::Configuration"); |
| 195 | |
| 196 | DirSelection dialog; |
| 197 | |
| 198 | dialog.SetParentWindow(GetContainerWindow()); |
| 199 | dialog.SetCaption(i18n->AddColon(i18n->TranslateString("Select the folder for saving log files"))); |
| 200 | dialog.SetDirName(BoCA::Utilities::GetAbsolutePathName(edit_logs_folder->GetText())); |
| 201 | |
| 202 | if (dialog.ShowDialog() == Success()) |
| 203 | { |
| 204 | edit_logs_folder->SetText(dialog.GetDirName()); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | Int BoCA::ConfigureProtocols::SaveSettings() |
| 209 | { |
| 210 | Config *config = Config::Get(); |
| 211 | |
| 212 | config->SetIntValue(ConfigID, "ShowLogsTab", showLogsTab); |
| 213 | |
| 214 | config->SetIntValue(ConfigID, "ArchiveLogs", archiveLogs); |
| 215 | config->SetStringValue(ConfigID, "LogsFolder", edit_logs_folder->GetText()); |
| 216 | |
| 217 | config->SetIntValue(ConfigID, "DeleteLogs", deleteLogs); |
| 218 | config->SetIntValue(ConfigID, "DeleteLogsDays", edit_logs_days->GetText().ToInt()); |
| 219 | |
| 220 | config->SetIntValue(ConfigID, "LogCompletePaths", logCompletePaths); |
| 221 | config->SetIntValue(ConfigID, "SaveConversionLogsWithFiles", saveConversionLogsWithFiles); |
| 222 | config->SetIntValue(ConfigID, "SaveRippingLogsOnly", saveRippingLogsOnly); |
| 223 | config->SetStringValue(ConfigID, "ConversionLogPattern", edit_conversion_filename->GetText()); |
| 224 | |
| 225 | return Success(); |
| 226 | } |