| 1 | /* fre:ac - free audio converter |
| 2 | * Copyright (C) 2001-2019 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 "dialog.h" |
| 14 | |
| 15 | Array<PaymentMethod *(*)()> *BoCA::DonateDialog::factories = NIL; |
| 16 | |
| 17 | BoCA::DonateDialog::DonateDialog() |
| 18 | { |
| 19 | Config *config = Config::Get(); |
| 20 | I18n *i18n = I18n::Get(); |
| 21 | |
| 22 | i18n->SetContext("Extensions::Donate"); |
| 23 | |
| 24 | mainWnd = new GUI::Window(i18n->TranslateString("Support this project"), Point(100, 100), Size(380, 350)); |
| 25 | mainWnd->SetRightToLeft(i18n->IsActiveLanguageRightToLeft()); |
| 26 | |
| 27 | mainWnd_titlebar = new Titlebar(TB_NONE); |
| 28 | divider = new Divider(39, OR_HORZ | OR_BOTTOM); |
| 29 | |
| 30 | mainWnd->Add(mainWnd_titlebar); |
| 31 | mainWnd->Add(divider); |
| 32 | |
| 33 | button_close = new Button(i18n->TranslateString("Close"), Point(87, 29), Size()); |
| 34 | button_close->onAction.Connect(&DonateDialog::Close, this); |
| 35 | button_close->SetOrientation(OR_LOWERRIGHT); |
| 36 | |
| 37 | mainWnd->Add(button_close); |
| 38 | |
| 39 | Size tabSize; |
| 40 | |
| 41 | tab_methods = new TabWidget(Point(7, 7), Size(100, 24)); |
| 42 | |
| 43 | foreach (PaymentMethod *(*factory)(), *factories) |
| 44 | { |
| 45 | PaymentMethod *method = factory(); |
| 46 | |
| 47 | methods.Add(method, method->GetID().ComputeCRC32()); |
| 48 | } |
| 49 | |
| 50 | const Array<String> &order = i18n->TranslateString("paypal,donorbox,bitcoin,ethereum").Explode(","); |
| 51 | |
| 52 | foreach (const String &id, order) |
| 53 | { |
| 54 | PaymentMethod *method = methods.Get(id.ComputeCRC32()); |
| 55 | |
| 56 | if (method == NIL) continue; |
| 57 | |
| 58 | Layer *layer = method->GetLayer(); |
| 59 | |
| 60 | tabSize.cx = Math::Max(tabSize.cx, layer->GetWidth()); |
| 61 | tabSize.cy = Math::Max(tabSize.cy, layer->GetHeight()); |
| 62 | |
| 63 | tab_methods->Add(layer, method->GetLogo()); |
| 64 | } |
| 65 | |
| 66 | text_intro = new Text(i18n->TranslateString("Please support this project!"), Point(7, 12)); |
| 67 | text_intro->SetFont(Font(Font::Default, 12, Font::Bold, 0, text_intro->GetFont().GetColor())); |
| 68 | |
| 69 | text_donate = new Text(i18n->TranslateString("Please help keep this software free by supporting the %1 project with a\ndonation.").Replace("%1", "fre:ac"), Point(7, text_intro->GetUnscaledTextHeight() + 25)); |
| 70 | text_donate_other = new Text(i18n->TranslateString("Please write to %1 if you would like to mail a check or send\nmoney by mail.").Replace("%1", "[email protected]"), Point(7, text_donate->GetY() + text_donate->GetUnscaledTextHeight() + tabSize.cy + 40)); |
| 71 | |
| 72 | text_thanks = new Text(i18n->TranslateString("Thank you very much!"), Point(7, text_donate_other->GetY() + text_donate_other->GetUnscaledTextHeight() + 13)); |
| 73 | text_thanks->SetFont(Font(Font::Default, 12, Font::Bold, 0, text_thanks->GetFont().GetColor())); |
| 74 | |
| 75 | Int maxElementSize = Math::Max(tabSize.cx + 2, Math::Max(Math::Max(text_intro->GetUnscaledTextWidth(), text_thanks->GetUnscaledTextWidth()), Math::Max(text_donate->GetUnscaledTextWidth(), text_donate_other->GetUnscaledTextWidth()))); |
| 76 | |
| 77 | tabSize.cx = maxElementSize - 2; |
| 78 | |
| 79 | tab_methods->SetMetrics(Point(7, text_donate->GetY() + text_donate->GetUnscaledTextHeight() + 9), tabSize + Size(2, 24)); |
| 80 | |
| 81 | text_intro->SetX((maxElementSize + 12 - text_intro->GetUnscaledTextWidth()) / 2); |
| 82 | text_thanks->SetX((maxElementSize + 12 - text_thanks->GetUnscaledTextWidth()) / 2); |
| 83 | |
| 84 | mainWnd->Add(tab_methods); |
| 85 | |
| 86 | mainWnd->Add(text_intro); |
| 87 | mainWnd->Add(text_donate); |
| 88 | mainWnd->Add(text_donate_other); |
| 89 | mainWnd->Add(text_thanks); |
| 90 | |
| 91 | remind = config->GetIntValue("Donate", "ShowAgain", True); |
| 92 | |
| 93 | check_remind = new CheckBox(i18n->TranslateString("Remind me later"), Point(7, 27), Size(), &remind); |
| 94 | check_remind->SetOrientation(OR_LOWERLEFT); |
| 95 | check_remind->SetWidth(check_remind->GetUnscaledTextWidth() + 23); |
| 96 | |
| 97 | mainWnd->Add(check_remind); |
| 98 | |
| 99 | Add(mainWnd); |
| 100 | |
| 101 | mainWnd->SetFlags(mainWnd->GetFlags() | WF_TOPMOST | WF_NOTASKBUTTON); |
| 102 | mainWnd->SetIcon(ImageLoader::Load("icons/freac.png")); |
| 103 | |
| 104 | #ifndef __WIN32__ |
| 105 | if (Directory(S::System::System::GetResourcesDirectory().Append("freac")).Exists()) mainWnd->SetIcon(ImageLoader::Load(S::System::System::GetResourcesDirectory().Append("freac/icons/freac.png"))); |
| 106 | #endif |
| 107 | |
| 108 | Rect workArea = Screen::GetActiveScreenWorkArea(); |
| 109 | Float scaleFactor = Surface().GetSurfaceDPI() / 96.0; |
| 110 | |
| 111 | Size wndSize = Size(maxElementSize + 22, text_thanks->GetY() + text_thanks->GetUnscaledTextHeight() + 87); |
| 112 | Point wndPos = workArea.GetPosition() + Point((workArea.GetWidth() - Math::Round(wndSize.cx * scaleFactor)) / 2, |
| 113 | (workArea.GetHeight() - Math::Round(wndSize.cy * scaleFactor)) / 2); |
| 114 | |
| 115 | mainWnd->SetMetrics(wndPos, wndSize); |
| 116 | } |
| 117 | |
| 118 | BoCA::DonateDialog::~DonateDialog() |
| 119 | { |
| 120 | DeleteObject(mainWnd); |
| 121 | DeleteObject(mainWnd_titlebar); |
| 122 | |
| 123 | DeleteObject(divider); |
| 124 | |
| 125 | DeleteObject(button_close); |
| 126 | |
| 127 | DeleteObject(tab_methods); |
| 128 | |
| 129 | foreach (PaymentMethod *method, methods) delete method; |
| 130 | |
| 131 | DeleteObject(text_intro); |
| 132 | DeleteObject(text_donate); |
| 133 | DeleteObject(text_donate_other); |
| 134 | DeleteObject(text_thanks); |
| 135 | |
| 136 | DeleteObject(check_remind); |
| 137 | } |
| 138 | |
| 139 | const Error &BoCA::DonateDialog::ShowDialog() |
| 140 | { |
| 141 | return ShowDialog(False); |
| 142 | } |
| 143 | |
| 144 | const Error &BoCA::DonateDialog::ShowDialog(Bool blocking) |
| 145 | { |
| 146 | if (!blocking) mainWnd->Show(); |
| 147 | else mainWnd->WaitUntilClosed(); |
| 148 | |
| 149 | return error; |
| 150 | } |
| 151 | |
| 152 | Void BoCA::DonateDialog::Close() |
| 153 | { |
| 154 | Config *config = Config::Get(); |
| 155 | |
| 156 | mainWnd->Close(); |
| 157 | |
| 158 | config->SetIntValue("Donate", "ShowAgain", remind); |
| 159 | } |
| 160 | |
| 161 | Bool BoCA::DonateDialog::RegisterPaymentMethod(PaymentMethod *(*factory)()) |
| 162 | { |
| 163 | if (factories == NIL) factories = new Array<PaymentMethod *(*)()>; |
| 164 | |
| 165 | factories->Add(factory); |
| 166 | |
| 167 | return True; |
| 168 | } |
| 169 | |
| 170 | const Array<PaymentMethod *(*)()> &BoCA::DonateDialog::GetPaymentMethodFactories() |
| 171 | { |
| 172 | if (factories == NIL) factories = new Array<PaymentMethod *(*)()>; |
| 173 | |
| 174 | return *factories; |
| 175 | } |
| 176 | |
| 177 | Bool BoCA::DonateDialog::FreePaymentMethodFactories() |
| 178 | { |
| 179 | if (factories == NIL) return True; |
| 180 | |
| 181 | delete factories; |
| 182 | |
| 183 | factories = NIL; |
| 184 | |
| 185 | return True; |
| 186 | } |