| 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/cddb/extsettings.h> |
| 14 | |
| 15 | #include <config.h> |
| 16 | |
| 17 | #include <boca.h> |
| 18 | |
| 19 | freac::cddbExtendedSettingsDlg::cddbExtendedSettingsDlg(Int tab) |
| 20 | { |
| 21 | BoCA::Config *config = BoCA::Config::Get(); |
| 22 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 23 | |
| 24 | i18n->SetContext("Configuration::CDDB::Extended"); |
| 25 | |
| 26 | mainWnd = new Window(i18n->TranslateString("Extended CDDB settings"), Point(config->GetIntValue(Config::CategorySettingsID, Config::SettingsWindowPosXID, Config::SettingsWindowPosXDefault), config->GetIntValue(Config::CategorySettingsID, Config::SettingsWindowPosYID, Config::SettingsWindowPosYDefault)) + Point(80, 80), Size(352, 221)); |
| 27 | mainWnd->SetRightToLeft(i18n->IsActiveLanguageRightToLeft()); |
| 28 | |
| 29 | mainWnd_titlebar = new Titlebar(TB_CLOSEBUTTON); |
| 30 | divbar = new Divider(39, OR_HORZ | OR_BOTTOM); |
| 31 | |
| 32 | register_layer_http = new Layer(i18n->TranslateString("HTTP settings")); |
| 33 | register_layer_proxy = new Layer(i18n->TranslateString("Proxy settings")); |
| 34 | |
| 35 | btn_cancel = new Button(i18n->TranslateString("Cancel"), Point(175, 29), Size()); |
| 36 | btn_cancel->onAction.Connect(&cddbExtendedSettingsDlg::Cancel, this); |
| 37 | btn_cancel->SetOrientation(OR_LOWERRIGHT); |
| 38 | |
| 39 | btn_ok = new Button(i18n->TranslateString("OK"), Point(87, 29), Size()); |
| 40 | btn_ok->onAction.Connect(&cddbExtendedSettingsDlg::OK, this); |
| 41 | btn_ok->SetOrientation(OR_LOWERRIGHT); |
| 42 | |
| 43 | reg_register = new TabWidget(Point(7, 7), Size(329, 134)); |
| 44 | |
| 45 | http_group_scripts = new GroupBox(i18n->TranslateString("CGI scripts"), Point(7, 11), Size(312, 66)); |
| 46 | |
| 47 | http_text_query = new Text(i18n->AddColon(i18n->TranslateString("CDDB query script")), Point(16, 24)); |
| 48 | http_edit_query = new EditBox(config->GetStringValue(Config::CategoryFreedbID, Config::FreedbQueryPathID, Config::FreedbQueryPathDefault), Point(117, 21), Size(192, 0), 0); |
| 49 | |
| 50 | http_list_query = new List(); |
| 51 | http_list_query->AddEntry(Config::FreedbQueryPathDefault); |
| 52 | |
| 53 | http_edit_query->SetDropDownList(http_list_query); |
| 54 | |
| 55 | http_text_submit = new Text(i18n->AddColon(i18n->TranslateString("CDDB submit script")), Point(16, 51)); |
| 56 | http_edit_submit = new EditBox(config->GetStringValue(Config::CategoryFreedbID, Config::FreedbSubmitPathID, Config::FreedbSubmitPathDefault), Point(117, 48), Size(192, 0), 0); |
| 57 | |
| 58 | http_list_submit = new List(); |
| 59 | http_list_submit->AddEntry(Config::FreedbSubmitPathDefault); |
| 60 | |
| 61 | http_edit_submit->SetDropDownList(http_list_submit); |
| 62 | |
| 63 | Int maxTextSize = Math::Max(http_text_query->GetUnscaledTextWidth(), http_text_submit->GetUnscaledTextWidth()); |
| 64 | |
| 65 | http_edit_query->SetMetrics(Point(maxTextSize + 24, http_edit_query->GetY()), Size(285 - maxTextSize, http_edit_query->GetHeight())); |
| 66 | http_edit_submit->SetMetrics(Point(maxTextSize + 24, http_edit_submit->GetY()), Size(285 - maxTextSize, http_edit_submit->GetHeight())); |
| 67 | |
| 68 | proxy_group_proxy = new GroupBox(i18n->TranslateString("Proxy settings"), Point(7, 11), Size(312, 93)); |
| 69 | |
| 70 | proxy_text_mode = new Text(i18n->AddColon(i18n->TranslateString("Proxy type")), Point(16, 24)); |
| 71 | |
| 72 | proxy_combo_mode = new ComboBox(Point(116, 21), Size(185, 0)); |
| 73 | proxy_combo_mode->onSelectEntry.Connect(&cddbExtendedSettingsDlg::SetProxyMode, this); |
| 74 | proxy_combo_mode->AddEntry(i18n->TranslateString("no proxy")); |
| 75 | proxy_combo_mode->AddEntry("HTTP Forward"); |
| 76 | proxy_combo_mode->AddEntry("HTTPS Tunnel"); |
| 77 | proxy_combo_mode->AddEntry("SOCKS v4/v4a"); |
| 78 | proxy_combo_mode->AddEntry("SOCKS v5"); |
| 79 | |
| 80 | proxy_text_server = new Text(i18n->AddColon(i18n->TranslateString("Proxy server")), Point(16, 51)); |
| 81 | proxy_edit_server = new EditBox(config->GetStringValue(Config::CategoryFreedbID, Config::FreedbProxyID, Config::FreedbProxyDefault), Point(116, 48), Size(100, 0), 0); |
| 82 | |
| 83 | proxy_text_port = new Text(i18n->AddColon(i18n->TranslateString("Port")), Point(226, 51)); |
| 84 | proxy_text_port->SetPosition(Point(264 - proxy_text_port->GetUnscaledTextWidth(), proxy_text_port->GetY())); |
| 85 | |
| 86 | proxy_edit_port = new EditBox(String::FromInt(config->GetIntValue(Config::CategoryFreedbID, Config::FreedbProxyPortID, Config::FreedbProxyPortDefault)), Point(272, 48), Size(37, 0), 5); |
| 87 | proxy_edit_port->SetFlags(EDB_NUMERIC); |
| 88 | |
| 89 | proxy_text_user = new Text(i18n->AddColon(i18n->TranslateString("User name")), Point(16, 78)); |
| 90 | proxy_edit_user = new EditBox(config->GetStringValue(Config::CategoryFreedbID, Config::FreedbProxyUserID, Config::FreedbProxyUserDefault), Point(116, 75), Size(100, 0), 0); |
| 91 | |
| 92 | proxy_text_password = new Text(i18n->AddColon(i18n->TranslateString("Password")), Point(226, 78)); |
| 93 | proxy_text_password->SetPosition(Point(234 - proxy_text_password->GetUnscaledTextWidth(), proxy_text_password->GetY())); |
| 94 | |
| 95 | proxy_edit_password = new EditBox(config->GetStringValue(Config::CategoryFreedbID, Config::FreedbProxyPasswordID, Config::FreedbProxyPasswordDefault), Point(242, 75), Size(67, 0), 0); |
| 96 | proxy_edit_password->SetFlags(EDB_ASTERISK); |
| 97 | |
| 98 | maxTextSize = Math::Max(Math::Max(proxy_text_mode->GetUnscaledTextWidth(), proxy_text_server->GetUnscaledTextWidth()), proxy_text_user->GetUnscaledTextWidth()); |
| 99 | |
| 100 | proxy_combo_mode->SetMetrics(Point(maxTextSize + 24, proxy_combo_mode->GetY()), Size(285 - maxTextSize, proxy_combo_mode->GetHeight())); |
| 101 | proxy_edit_server->SetMetrics(Point(maxTextSize + 24, proxy_edit_server->GetY()), Size(233 - maxTextSize - proxy_text_port->GetUnscaledTextWidth(), proxy_edit_server->GetHeight())); |
| 102 | proxy_edit_user->SetMetrics(Point(maxTextSize + 24, proxy_edit_user->GetY()), Size(203 - maxTextSize - proxy_text_password->GetUnscaledTextWidth(), proxy_edit_user->GetHeight())); |
| 103 | |
| 104 | proxy_combo_mode->SelectNthEntry(config->GetIntValue(Config::CategoryFreedbID, Config::FreedbProxyModeID, Config::FreedbProxyModeDefault)); |
| 105 | |
| 106 | SetProxyMode(); |
| 107 | |
| 108 | Add(mainWnd); |
| 109 | |
| 110 | mainWnd->Add(mainWnd_titlebar); |
| 111 | mainWnd->Add(divbar); |
| 112 | mainWnd->Add(btn_ok); |
| 113 | mainWnd->Add(btn_cancel); |
| 114 | mainWnd->Add(reg_register); |
| 115 | |
| 116 | reg_register->Add(register_layer_http); |
| 117 | reg_register->Add(register_layer_proxy); |
| 118 | |
| 119 | register_layer_http->Add(http_group_scripts); |
| 120 | register_layer_http->Add(http_text_query); |
| 121 | register_layer_http->Add(http_edit_query); |
| 122 | register_layer_http->Add(http_text_submit); |
| 123 | register_layer_http->Add(http_edit_submit); |
| 124 | |
| 125 | register_layer_proxy->Add(proxy_group_proxy); |
| 126 | register_layer_proxy->Add(proxy_text_mode); |
| 127 | register_layer_proxy->Add(proxy_combo_mode); |
| 128 | register_layer_proxy->Add(proxy_text_server); |
| 129 | register_layer_proxy->Add(proxy_edit_server); |
| 130 | register_layer_proxy->Add(proxy_text_port); |
| 131 | register_layer_proxy->Add(proxy_edit_port); |
| 132 | register_layer_proxy->Add(proxy_text_user); |
| 133 | register_layer_proxy->Add(proxy_edit_user); |
| 134 | register_layer_proxy->Add(proxy_text_password); |
| 135 | register_layer_proxy->Add(proxy_edit_password); |
| 136 | |
| 137 | switch (tab) |
| 138 | { |
| 139 | case 0: |
| 140 | reg_register->SelectTab(register_layer_http); |
| 141 | break; |
| 142 | case 1: |
| 143 | reg_register->SelectTab(register_layer_proxy); |
| 144 | break; |
| 145 | } |
| 146 | |
| 147 | mainWnd->SetFlags(mainWnd->GetFlags() | WF_NOTASKBUTTON | WF_MODAL); |
| 148 | mainWnd->SetIcon(ImageLoader::Load(String(Config::Get()->resourcesPath).Append("icons/freac.png"))); |
| 149 | } |
| 150 | |
| 151 | freac::cddbExtendedSettingsDlg::~cddbExtendedSettingsDlg() |
| 152 | { |
| 153 | DeleteObject(mainWnd_titlebar); |
| 154 | DeleteObject(mainWnd); |
| 155 | DeleteObject(divbar); |
| 156 | DeleteObject(reg_register); |
| 157 | DeleteObject(register_layer_http); |
| 158 | DeleteObject(register_layer_proxy); |
| 159 | DeleteObject(http_group_scripts); |
| 160 | DeleteObject(http_text_query); |
| 161 | DeleteObject(http_edit_query); |
| 162 | DeleteObject(http_list_query); |
| 163 | DeleteObject(http_text_submit); |
| 164 | DeleteObject(http_edit_submit); |
| 165 | DeleteObject(http_list_submit); |
| 166 | DeleteObject(proxy_group_proxy); |
| 167 | DeleteObject(proxy_text_mode); |
| 168 | DeleteObject(proxy_combo_mode); |
| 169 | DeleteObject(proxy_text_server); |
| 170 | DeleteObject(proxy_edit_server); |
| 171 | DeleteObject(proxy_text_port); |
| 172 | DeleteObject(proxy_edit_port); |
| 173 | DeleteObject(proxy_text_user); |
| 174 | DeleteObject(proxy_edit_user); |
| 175 | DeleteObject(proxy_text_password); |
| 176 | DeleteObject(proxy_edit_password); |
| 177 | DeleteObject(btn_ok); |
| 178 | DeleteObject(btn_cancel); |
| 179 | } |
| 180 | |
| 181 | const Error &freac::cddbExtendedSettingsDlg::ShowDialog() |
| 182 | { |
| 183 | mainWnd->WaitUntilClosed(); |
| 184 | |
| 185 | return error; |
| 186 | } |
| 187 | |
| 188 | Void freac::cddbExtendedSettingsDlg::OK() |
| 189 | { |
| 190 | BoCA::Config *config = BoCA::Config::Get(); |
| 191 | |
| 192 | config->SetStringValue(Config::CategoryFreedbID, Config::FreedbQueryPathID, http_edit_query->GetText()); |
| 193 | config->SetStringValue(Config::CategoryFreedbID, Config::FreedbSubmitPathID, http_edit_submit->GetText()); |
| 194 | |
| 195 | config->SetIntValue(Config::CategoryFreedbID, Config::FreedbProxyModeID, proxy_combo_mode->GetSelectedEntryNumber()); |
| 196 | config->SetStringValue(Config::CategoryFreedbID, Config::FreedbProxyID, proxy_edit_server->GetText()); |
| 197 | config->SetIntValue(Config::CategoryFreedbID, Config::FreedbProxyPortID, proxy_edit_port->GetText().ToInt()); |
| 198 | config->SetStringValue(Config::CategoryFreedbID, Config::FreedbProxyUserID, proxy_edit_user->GetText()); |
| 199 | config->SetStringValue(Config::CategoryFreedbID, Config::FreedbProxyPasswordID, proxy_edit_password->GetText()); |
| 200 | |
| 201 | mainWnd->Close(); |
| 202 | } |
| 203 | |
| 204 | Void freac::cddbExtendedSettingsDlg::Cancel() |
| 205 | { |
| 206 | mainWnd->Close(); |
| 207 | } |
| 208 | |
| 209 | Void freac::cddbExtendedSettingsDlg::SetProxyMode() |
| 210 | { |
| 211 | if (proxy_combo_mode->GetSelectedEntryNumber() == 0) |
| 212 | { |
| 213 | proxy_text_server->Deactivate(); |
| 214 | proxy_edit_server->Deactivate(); |
| 215 | proxy_text_port->Deactivate(); |
| 216 | proxy_edit_port->Deactivate(); |
| 217 | } |
| 218 | else |
| 219 | { |
| 220 | proxy_text_server->Activate(); |
| 221 | proxy_edit_server->Activate(); |
| 222 | proxy_text_port->Activate(); |
| 223 | proxy_edit_port->Activate(); |
| 224 | } |
| 225 | |
| 226 | if (proxy_combo_mode->GetSelectedEntryNumber() == 0 || proxy_combo_mode->GetSelectedEntryNumber() == 3) |
| 227 | { |
| 228 | proxy_text_user->Deactivate(); |
| 229 | proxy_edit_user->Deactivate(); |
| 230 | proxy_text_password->Deactivate(); |
| 231 | proxy_edit_password->Deactivate(); |
| 232 | } |
| 233 | else |
| 234 | { |
| 235 | proxy_text_user->Activate(); |
| 236 | proxy_edit_user->Activate(); |
| 237 | proxy_text_password->Activate(); |
| 238 | proxy_edit_password->Activate(); |
| 239 | } |
| 240 | |
| 241 | if ((proxy_combo_mode->GetSelectedEntryNumber() == 1 || proxy_combo_mode->GetSelectedEntryNumber() == 2) && proxy_edit_port->GetText().ToInt() == 1080) |
| 242 | { |
| 243 | proxy_edit_port->SetText("80"); |
| 244 | } |
| 245 | |
| 246 | if ((proxy_combo_mode->GetSelectedEntryNumber() == 3 || proxy_combo_mode->GetSelectedEntryNumber() == 4) && proxy_edit_port->GetText().ToInt() == 80) |
| 247 | { |
| 248 | proxy_edit_port->SetText("1080"); |
| 249 | } |
| 250 | } |