Debian Codegraph @

components/extension/langnotify/langnotify.cpp

raw symbols SCIP
1 /* fre:ac - free audio converter
2 * Copyright (C) 2001-2017 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
15 #include "langnotify.h"
16 #include "dialog.h"
17
18 const String &BoCA::LanguageNotifier::GetComponentSpecs()
19 {
20 static String componentSpecs = " \
21 \
22 <?xml version=\"1.0\" encoding=\"UTF-8\"?> \
23 <component> \
24 <name>LanguageNotifier</name> \
25 <version>1.0</version> \
26 <id>langnotify-ext</id> \
27 <type>extension</type> \
28 </component> \
29 \
30 ";
31
32 return componentSpecs;
33 }
34
35 BoCA::LanguageNotifier::LanguageNotifier()
36 {
37 static Bool checkedLanguage = False;
38
39 dialog = NIL;
40
41 if (checkedLanguage) return;
42
43 checkedLanguage = True;
44
45 /* Check if user default language is supported.
46 */
47 I18n *i18n = I18n::Get();
48 String code = i18n->GetUserDefaultLanguageCode();
49
50 if (code == NIL || code == "en" || code.StartsWith("en_") || code.StartsWith("en@")) return;
51
52 Bool supported = False;
53 Bool incomplete = False;
54
55 for (Int i = 0; i < i18n->GetNOfLanguages(); i++)
56 {
57 if (( i18n->GetNthLanguageID(i) == String("freac_").Append(code ).Append(".xml")) ||
58 ( code.Contains("@") && i18n->GetNthLanguageID(i) == String("freac_").Append( code.Head( code.Find("@"))).Append(".xml")) ||
59 (code.Contains("_") && code.Contains("@") && i18n->GetNthLanguageID(i) == String("freac_").Append(code.Head(code.Find("_"))).Append(code.Tail(code.Length() - code.Find("@"))).Append(".xml")) ||
60 (code.Contains("_") && i18n->GetNthLanguageID(i) == String("freac_").Append(code.Head(code.Find("_")) ).Append(".xml")))
61 {
62 supported = True;
63
64 if (i18n->IsNthLanguageIncomplete(i)) incomplete = True;
65
66 break;
67 }
68 }
69
70 if (supported && !incomplete) return;
71
72 /* Display notification dialog at every fourth start.
73 */
74 Config *config = Config::Get();
75
76 Int startCount = config->GetIntValue("LanguageNotifier", "StartCount", 0) + 1;
77
78 if ((startCount - 5) % 10 == 0 && config->GetIntValue("LanguageNotifier", "ShowAgain", True))
79 {
80 dialog = new LanguageNotifierDialog(incomplete);
81
82 dialog->ShowDialog();
83 }
84
85 config->SetIntValue("LanguageNotifier", "StartCount", startCount);
86 }
87
88 BoCA::LanguageNotifier::~LanguageNotifier()
89 {
90 if (dialog != NIL) Object::DeleteObject(dialog);
91 }