hydrogen 1.2.6
License.cpp
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2025 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY, without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
23#include <QRegularExpression>
24#include "core/License.h"
25
26namespace H2Core {
27
28 License::License( const QString& sLicenseString, const QString& sCopyrightHolder ) :
29 m_sLicenseString( sLicenseString ),
30 m_sCopyrightHolder( sCopyrightHolder )
31{
32 parse( sLicenseString );
33}
34
35License::License( const License* pOther ) :
36 m_license( pOther->m_license ),
39}
40
43
45 m_license = license;
47}
48
49void License::parse( const QString& sLicenseString ) {
50
51 m_sLicenseString = sLicenseString;
52
53 const QString sUp = sLicenseString.toUpper();
54
55 if ( sUp.isEmpty() ||
56 sUp == "UNDEFINED LICENSE" ||
57 sUp == "UNKNOWN LICENSE" ) {
58 m_sLicenseString = "undefined license";
60 }
61 else if ( ( sUp.contains( "CC" ) ||
62 ( sUp.contains( "CREATIVE" ) &&
63 sUp.contains( "COMMONS" ) ) ) &&
64 ( sUp.contains( "BY" ) ||
65 sUp.contains( "ATTRIBUTION" ) ) ) {
66 if ( sUp.contains( "SA" ) ||
67 ( sUp.contains( "SHARE" ) &&
68 sUp.contains( "ALIKE" ) ) ) {
69 if ( sUp.contains( "NC" ) ||
70 ( sUp.contains( "NON" ) &&
71 sUp.contains( "COMMERCIAL" ) ) ) {
73 }
74 else {
76 }
77 }
78 else if ( sUp.contains( "ND" ) ||
79 ( sUp.contains( "NO" ) &&
80 sUp.contains( "DERIVATIVES" ) ) ) {
81 if ( sUp.contains( "NC" ) ||
82 ( sUp.contains( "NON" ) &&
83 sUp.contains( "COMMERCIAL" ) ) ) {
85 }
86 else {
88 }
89 }
90 else {
91 if ( sUp.contains( "NC" ) ||
92 ( sUp.contains( "NON" ) &&
93 sUp.contains( "COMMERCIAL" ) ) ) {
95 }
96 else {
98 }
99 }
100 }
101 else if ( ( ( sUp.contains( "CC" ) ||
102 ( sUp.contains( "CREATIVE" ) &&
103 sUp.contains( "COMMONS" ) ) ) &&
104 ( sUp.contains( "0" ) ||
105 sUp.contains( "ZERO" ) ) ) ||
106 ( sUp.contains( "PUBLIC" ) &&
107 sUp.contains( "DOMAIN" ) ) &&
108 ( sUp.contains( "NO" ) &&
109 sUp.contains( "KNOWN" ) &&
110 sUp.contains( "COPYRIGHT" ) ) ) {
112 }
113 else if ( sUp.contains( "GPL" ) ||
114 ( sUp.contains( "GENERAL" ) &&
115 sUp.contains( "PUBLIC" ) &&
116 sUp.contains( "LICENSE" ) ) ) {
118 }
119 else if ( sUp.contains( "ALL" ) &&
120 sUp.contains( "RIGHTS" ) &&
121 sUp.contains( "RESERVED" ) ) {
123 }
124 else {
126 }
127}
128
130 if ( m_license == License::GPL ||
133 return true;
134 }
135
136 return false;
137}
138
140 if ( m_license == License::CC_BY ||
146 return true;
147 }
148
149 return false;
150}
151
152QString License::toQString( const QString& sPrefix, bool bShort ) const {
153 QString s = Base::sPrintIndention;
154 QString sOutput;
155 if ( ! bShort ) {
156 sOutput = QString( "%1[License]\n" ).arg( sPrefix )
157 .append( QString( "%1%2m_license: %3\n" ).arg( sPrefix ).arg( s )
159 .append( QString( "%1%2m_sLicenseString: %3\n" ).arg( sPrefix ).arg( s )
160 .arg( m_sLicenseString ) )
161 .append( QString( "%1%2m_sCopyrightHolder: %3\n" ).arg( sPrefix ).arg( s )
162 .arg( m_sCopyrightHolder ) );
163 }
164 else {
165 sOutput = QString( "[License]" )
166 .append( QString( " m_license: %1" )
168 .append( QString( ", m_sLicenseString: %1" )
169 .arg( m_sLicenseString ) )
170 .append( QString( ", m_sCopyrightHolder: %1" )
171 .arg( m_sCopyrightHolder ) )
172 .append( "\n" );
173 }
174
175 return sOutput;
176}
177};
178
179/* vim: set softtabstop=4 noexpandtab: */
static QString sPrintIndention
String used to format the debugging string output of some core classes.
Definition Object.h:127
LicenseType
A couple of recognized licenses.
Definition License.h:58
@ GPL
Not a desirable license for audio data but introduced here specifically since it is already used by a...
Definition License.h:68
@ Unspecified
No license set yet.
Definition License.h:74
@ AllRightsReserved
User decides with withhold all rights.
Definition License.h:70
@ Other
All other licenses not specified above.
Definition License.h:72
bool hasAttribution() const
Definition License.cpp:139
QString m_sCopyrightHolder
This variable will not be written to disk.
Definition License.h:140
QString m_sLicenseString
Definition License.h:134
void setType(LicenseType license)
Definition License.cpp:44
bool isCopyleft() const
Definition License.cpp:129
static QString LicenseTypeToQString(LicenseType license)
Definition License.h:155
QString toQString(const QString &sPrefix="", bool bShort=true) const override
Formatted string version for debugging purposes.
Definition License.cpp:152
LicenseType m_license
Definition License.h:133
License(const QString &sLicenseString="", const QString &sCopyrightHolder="")
Definition License.cpp:28
void parse(const QString &sLicenseString)
Definition License.cpp:49