-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cf3949
commit 8e9ab6f
Showing
5 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// SPDX-FileCopyrightText: 2024 Carl Schwan <[email protected]> | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
#include "branding.h" | ||
#include "appstream.h" | ||
#include "chelpers.h" | ||
|
||
using namespace AppStream; | ||
|
||
class AppStream::BrandingData : public QSharedData | ||
{ | ||
public: | ||
BrandingData() | ||
{ | ||
brandingp = as_branding_new(); | ||
} | ||
|
||
BrandingData(AsBranding *branding) | ||
: brandingp(branding) | ||
{ | ||
g_object_ref(brandingp); | ||
} | ||
|
||
~BrandingData() | ||
{ | ||
g_object_unref(brandingp); | ||
} | ||
|
||
bool operator==(const BrandingData &rd) const | ||
{ | ||
return rd.brandingp == brandingp; | ||
} | ||
|
||
AsBranding *brandingp; | ||
}; | ||
|
||
Branding::Branding() | ||
: d(new BrandingData) | ||
{ | ||
} | ||
|
||
Branding::Branding(_AsBranding *devp) | ||
: d(new BrandingData(devp)) | ||
{ | ||
} | ||
|
||
Branding::Branding(const Branding &devp) = default; | ||
|
||
Branding::~Branding() = default; | ||
|
||
Branding &Branding::operator=(const Branding &devp) = default; | ||
|
||
bool Branding::operator==(const Branding &other) const | ||
{ | ||
if (this->d == other.d) { | ||
return true; | ||
} | ||
if (this->d && other.d) { | ||
return *(this->d) == *other.d; | ||
} | ||
return false; | ||
} | ||
|
||
_AsBranding *Branding::cPtr() const | ||
{ | ||
return d->brandingp; | ||
} | ||
|
||
QString Branding::colorKindToString(Branding::ColorKind colorKind) | ||
{ | ||
return valueWrap(as_color_kind_to_string(static_cast<AsColorKind>(colorKind))); | ||
} | ||
|
||
Branding::ColorKind Branding::colorKindfromString(const QString &string) | ||
{ | ||
return static_cast<Branding::ColorKind>(as_color_kind_from_string(qPrintable(string))); | ||
} | ||
|
||
QString Branding::colorSchemeToString(ColorSchemeKind colorScheme) | ||
{ | ||
return valueWrap(as_color_scheme_kind_to_string(static_cast<AsColorSchemeKind>(colorScheme))); | ||
} | ||
|
||
Branding::ColorSchemeKind Branding::colorSchemefromString(const QString &string) | ||
{ | ||
return static_cast<Branding::ColorSchemeKind>(as_color_scheme_kind_from_string(qPrintable(string))); | ||
} | ||
|
||
void Branding::setColor(Branding::ColorKind kind, Branding::ColorSchemeKind scheme, const QString &color) | ||
{ | ||
as_branding_set_color(d->brandingp, static_cast<AsColorKind>(kind), static_cast<AsColorSchemeKind>(scheme), qPrintable(color)); | ||
} | ||
|
||
void Branding::removeColor(Branding::ColorKind kind, Branding::ColorSchemeKind scheme) | ||
{ | ||
as_branding_remove_color(d->brandingp, static_cast<AsColorKind>(kind), static_cast<AsColorSchemeKind>(scheme)); | ||
} | ||
|
||
QString Branding::color(Branding::ColorKind kind, Branding::ColorSchemeKind scheme) | ||
{ | ||
return valueWrap(as_branding_get_color(d->brandingp, static_cast<AsColorKind>(kind), static_cast<AsColorSchemeKind>(scheme))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// SPDX-FileCopyrightText: 2024 Carl Schwan <[email protected]> | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
#pragma once | ||
|
||
#include <QObject> | ||
#include <QSharedDataPointer> | ||
#include "appstreamqt_export.h" | ||
|
||
class _AsBranding; | ||
|
||
namespace AppStream | ||
{ | ||
|
||
class BrandingData; | ||
|
||
class APPSTREAMQT_EXPORT Branding | ||
{ | ||
Q_GADGET | ||
|
||
public: | ||
enum class ColorSchemeKind { | ||
Unknown, | ||
Light, | ||
Dark, | ||
}; | ||
|
||
enum class ColorKind { | ||
Unknow, | ||
Primary, | ||
}; | ||
|
||
Branding(); | ||
Branding(_AsBranding *); | ||
Branding(const Branding &devp); | ||
~Branding(); | ||
|
||
Branding &operator=(const Branding &devp); | ||
bool operator==(const Branding &r) const; | ||
|
||
/** | ||
* Converts the ColorKind enumerated value to an text representation. | ||
*/ | ||
static QString colorKindToString(ColorKind colorKind); | ||
|
||
/** | ||
* Converts the text representation to an ColorKind enumerated value. | ||
*/ | ||
static ColorKind colorKindfromString(const QString &string); | ||
|
||
/** | ||
* Converts the ColorScheme enumerated value to an text representation. | ||
*/ | ||
static QString colorSchemeToString(ColorSchemeKind colorScheme); | ||
|
||
/** | ||
* Converts the text representation to an ColorScheme enumerated value. | ||
*/ | ||
static ColorSchemeKind colorSchemefromString(const QString &string); | ||
|
||
/** | ||
* Sets a new accent color. If a color of the given kind with the given scheme preference already exists, | ||
* it will be overriden with the new color code. | ||
*/ | ||
void setColor(ColorKind kind, ColorSchemeKind scheme, const QString &color); | ||
|
||
/** | ||
* Deletes a color that matches the given type and scheme preference. | ||
*/ | ||
void removeColor(ColorKind kind, ColorSchemeKind scheme); | ||
|
||
/** | ||
* Retrieve a color of the given @kind that matches @scheme_kind. | ||
* If a color has no scheme preference defined, it will be returned for either scheme type, | ||
* unless a more suitable color was found. | ||
*/ | ||
QString color(ColorKind kind, ColorSchemeKind scheme); | ||
|
||
/** | ||
* \returns the internally stored AsBranding | ||
*/ | ||
_AsBranding *cPtr() const; | ||
|
||
private: | ||
QSharedDataPointer<BrandingData> d; | ||
}; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters