hydrogen 1.2.3
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-2024 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 ),
37 m_sLicenseString( pOther->m_sLicenseString ),
38 m_sCopyrightHolder( pOther->m_sCopyrightHolder ) {
39}
40
43
45 m_license = license;
47}
48
49void License::parse( const QString& sLicenseString ) {
50
51 m_sLicenseString = sLicenseString;
52
53 QString sUp = sLicenseString.toUpper();
54
55 if ( sLicenseString.isEmpty() ||
56 sLicenseString == "undefined license" ) {
57 m_sLicenseString = "undefined license";
59 }
60 else if ( ( sUp.contains( "CC" ) ||
61 ( sUp.contains( "CREATIVE" ) &&
62 sUp.contains( "COMMONS" ) ) ) &&
63 ( sUp.contains( "BY" ) ||
64 sUp.contains( "ATTRIBUTION" ) ) ) {
65 if ( sUp.contains( "SA" ) ||
66 ( sUp.contains( "SHARE" ) &&
67 sUp.contains( "ALIKE" ) ) ) {
68 if ( sUp.contains( "NC" ) ||
69 ( sUp.contains( "NON" ) &&
70 sUp.contains( "COMMERCIAL" ) ) ) {
72 }
73 else {
75 }
76 }
77 else if ( sUp.contains( "ND" ) ||
78 ( sUp.contains( "NO" ) &&
79 sUp.contains( "DERIVATIVES" ) ) ) {
80 if ( sUp.contains( "NC" ) ||
81 ( sUp.contains( "NON" ) &&
82 sUp.contains( "COMMERCIAL" ) ) ) {
84 }
85 else {
87 }
88 }
89 else {
90 if ( sUp.contains( "NC" ) ||
91 ( sUp.contains( "NON" ) &&
92 sUp.contains( "COMMERCIAL" ) ) ) {
94 }
95 else {
97 }
98 }
99 }
100 else if ( ( ( sUp.contains( "CC" ) ||
101 ( sUp.contains( "CREATIVE" ) &&
102 sUp.contains( "COMMONS" ) ) ) &&
103 ( sUp.contains( "0" ) ||
104 sUp.contains( "ZERO" ) ) ) ||
105 ( sUp.contains( "PUBLIC" ) &&
106 sUp.contains( "DOMAIN" ) ) &&
107 ( sUp.contains( "NO" ) &&
108 sUp.contains( "KNOWN" ) &&
109 sUp.contains( "COPYRIGHT" ) ) ) {
111 }
112 else if ( sUp.contains( "GPL" ) ||
113 ( sUp.contains( "GENERAL" ) &&
114 sUp.contains( "PUBLIC" ) &&
115 sUp.contains( "LICENSE" ) ) ) {
117 }
118 else if ( sUp.contains( "ALL" ) &&
119 sUp.contains( "RIGHTS" ) &&
120 sUp.contains( "RESERVED" ) ) {
122 }
123 else {
125 }
126}
127
129 if ( m_license == License::GPL ||
132 return true;
133 }
134
135 return false;
136}
137
139 if ( m_license == License::CC_BY ||
145 return true;
146 }
147
148 return false;
149}
150
151QString License::toQString( const QString& sPrefix, bool bShort ) const {
152 QString s = Base::sPrintIndention;
153 QString sOutput;
154 if ( ! bShort ) {
155 sOutput = QString( "%1[License]\n" ).arg( sPrefix )
156 .append( QString( "%1%2m_license: %3\n" ).arg( sPrefix ).arg( s )
158 .append( QString( "%1%2m_sLicenseString: %3\n" ).arg( sPrefix ).arg( s )
159 .arg( m_sLicenseString ) )
160 .append( QString( "%1%2m_sCopyrightHolder: %3\n" ).arg( sPrefix ).arg( s )
161 .arg( m_sCopyrightHolder ) );
162 }
163 else {
164 sOutput = QString( "[License]" )
165 .append( QString( " m_license: %1" )
167 .append( QString( ", m_sLicenseString: %1" )
168 .arg( m_sLicenseString ) )
169 .append( QString( ", m_sCopyrightHolder: %1" )
170 .arg( m_sCopyrightHolder ) )
171 .append( "\n" );
172 }
173
174 return sOutput;
175}
176};
177
178/* vim: set softtabstop=4 noexpandtab: */
static QString sPrintIndention
String used to format the debugging string output of some core classes.
Definition Object.h:127
Wrapper class to help Hydrogen deal with the license information specified in a drumkit.
Definition License.h:48
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:138
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:128
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:151
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