Debian Codegraph @

components/extension/donate/donate.cpp

raw symbols SCIP
1 /* fre:ac - free audio converter
2 * Copyright (C) 2001-2018 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 <smooth.h>
14 #include <smooth/dll.h>
15
16 #include "donate.h"
17 #include "dialog.h"
18
19 const String &BoCA::Donate::GetComponentSpecs()
20 {
21 static String componentSpecs = " \
22 \
23 <?xml version=\"1.0\" encoding=\"UTF-8\"?> \
24 <component> \
25 <name>Donate</name> \
26 <version>1.0</version> \
27 <id>donate-ext</id> \
28 <type>extension</type> \
29 </component> \
30 \
31 ";
32
33 return componentSpecs;
34 }
35
36 Void smooth::AttachDLL(Void *instance)
37 {
38 DonateDialog::GetPaymentMethodFactories();
39 }
40
41 Void smooth::DetachDLL()
42 {
43 DonateDialog::FreePaymentMethodFactories();
44 }
45
46 BoCA::Donate::Donate()
47 {
48 static Bool checkedDonation = False;
49
50 dialog = NIL;
51
52 if (checkedDonation) return;
53
54 /* Show dialog every 10th start.
55 */
56 Config *config = Config::Get();
57
58 Int startCount = config->GetIntValue("Donate", "StartCount", 0) + 1;
59
60 if (startCount % 10 == 0 && config->GetIntValue("Donate", "ShowAgain", True))
61 {
62 dialog = new DonateDialog();
63
64 dialog->ShowDialog();
65 }
66
67 config->SetIntValue("Donate", "StartCount", startCount);
68
69 checkedDonation = True;
70
71 /* Register menubar overlay handler.
72 */
73 BoCA::Menu *menu = BoCA::Menu::Get();
74
75 menu->doMenubarOverlay.Connect(&Donate::DoMenubarOverlay, this);
76 }
77
78 BoCA::Donate::~Donate()
79 {
80 /* Unregister menubar overlay handler.
81 */
82 BoCA::Menu *menu = BoCA::Menu::Get();
83
84 menu->doMenubarOverlay.Disconnect(&Donate::DoMenubarOverlay, this);
85
86 /* Free opened dialog.
87 */
88 if (dialog != NIL) Object::DeleteObject(dialog);
89 }
90
91 Void BoCA::Donate::ShowDialog()
92 {
93 /* Show donation dialog.
94 */
95 DonateDialog dialog;
96
97 dialog.ShowDialog(True);
98
99 /* Reset startup count.
100 */
101 Config *config = Config::Get();
102
103 config->SetIntValue("Donate", "StartCount", config->GetIntValue("Donate", "StartCount", 0) / 10 * 10);
104 }
105
106 Void BoCA::Donate::DoMenubarOverlay(GUI::Menu *menubar)
107 {
108 I18n *i18n = I18n::Get();
109
110 for (Int i = 0; i < menubar->Length(); i++)
111 {
112 MenuEntry *menubarEntry = menubar->GetNthEntry(i);
113
114 if (menubarEntry->GetText() != i18n->TranslateString("Help", "Menu")) continue;
115
116 PopupMenu *popup = menubarEntry->GetPopupMenu();
117 MenuEntry *popupEntry = popup->AddEntry(i18n->AddEllipsis(i18n->TranslateString("Donate to the %1 project", "Extensions::Donate")).Replace("%1", "fre:ac"));
118
119 popupEntry->onAction.Connect(&Donate::ShowDialog, this);
120 popup->AddEntry();
121
122 popup->MoveEntry(popup->Length() - 2, popup->Length() - 4);
123 popup->MoveEntry(popup->Length() - 1, popup->Length() - 4);
124
125 break;
126 }
127 }