Initial Commit

This commit is contained in:
Digital Artifex
2025-08-03 18:41:56 -04:00
commit f65399ec53
402 changed files with 4704 additions and 0 deletions

5
plugin/.qmlls.ini Normal file
View File

@@ -0,0 +1,5 @@
[General]
buildDir="/home/parametheus/kde/src/komplex/build/bin"
no-cmake-calls=false
docDir=/usr/share/doc/qt6
importPaths="/usr/lib/qt6/qml"

72
plugin/AudioModel.cpp Normal file
View File

@@ -0,0 +1,72 @@
#include "AudioModel.h"
#ifdef AUDIOMODEL_H
AudioModel::AudioModel(QObject *parent)
: QObject(parent), m_deviceString(QString())
{
}
AudioModel::~AudioModel()
{
if (m_recorder)
{
m_recorder->stop();
delete m_recorder;
}
if (m_audioInput)
delete m_audioInput;
if (m_captureSession)
delete m_captureSession;
}
QByteArray AudioModel::frame() const
{
// This function should return the current audio frame.
// For now, we return an empty QByteArray.
return QByteArray();
}
QString AudioModel::device() const
{
return m_deviceString;
}
QStringList AudioModel::availableDevices() const
{
QStringList devices;
// Assuming QAudioDeviceInfo is used to get available audio devices
for (const auto &device : QMediaDevices::audioInputs())
{
devices.append(QString::fromLatin1(device.id()));
}
return devices;
}
void AudioModel::setDeviceName(const QString &device)
{
if (m_deviceString == device)
return;
m_deviceString = device;
// if (m_audioInput)
// {
// m_audioInput->setDevice(QAudioInput(device));
// getAudioFrame();
// }
}
void AudioModel::getAudioFrame()
{
// This function should be implemented to retrieve the audio frame
// from the audio input device and emit the frameChanged signal.
// For now, we will just emit the signal to indicate that the frame is ready.
Q_EMIT frameChanged();
}
#endif

107
plugin/AudioModel.h Normal file
View File

@@ -0,0 +1,107 @@
/*
* Komplex Wallpaper Engine
* Copyright (C) 2025 @DigitalArtifex | github.com/DigitalArtifex
*
* AudioModel.h
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*/
#ifndef AUDIOMODEL_H
#define AUDIOMODEL_H
#include "Komplex_global.h"
#include <QObject>
#include <QString>
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonParseError>
#include <QAudioDevice>
#include <QMediaDevices>
#include <QAudioInput>
#include <QMediaCaptureSession>
#include <QMediaRecorder>
#include <QtQml/qqmlregistration.h>
class KOMPLEX_EXPORT AudioModel : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
explicit AudioModel(QObject *parent = nullptr);
~AudioModel();
/**!
* @brief frame
* This function returns the current audio frame as a QString.
* It is expected to be called periodically to update the audio frame for the shader.
*
* @return QString containing the current audio frame.
*/
QByteArray frame() const;
/**!
* @brief device
* This function returns the currently set audio device name.
*
* @return QString containing the name of the audio device.
*/
QString device() const;
/**!
* @brief availableDevices
* This function returns a list of available audio devices on the system.
*
* @return QStringList containing the names of available audio devices.
*/
QStringList availableDevices() const;
/**!
* @brief setDeviceName
* This function sets the audio device to be used for capturing audio frames.
*
* @param device The name of the audio device to set.
*/
Q_INVOKABLE void setDeviceName(const QString &device);
/**!
* @brief getAudioFrame
* This function retrieves the current audio frame from the specified audio device.
* It is expected to be called periodically to update the audio frame for the shader.
*
* It is an asynchronous fuction and will emit the frameChanged signal when the audio frame is ready.
*/
Q_INVOKABLE void getAudioFrame();
Q_SIGNALS:
void frameChanged();
private:
QString m_deviceString;
QMediaCaptureSession *m_captureSession = nullptr;
QAudioInput *m_audioInput = nullptr;
QMediaRecorder *m_recorder = nullptr;
Q_PROPERTY(QByteArray frame READ frame NOTIFY frameChanged)
Q_PROPERTY(QString device READ device WRITE setDeviceName NOTIFY frameChanged)
};
Q_DECLARE_METATYPE(AudioModel)
#endif

65
plugin/CMakeLists.txt Normal file
View File

@@ -0,0 +1,65 @@
set(QML_IMPORT_PATH ${CMAKE_SOURCE_DIR}/plugin ${CMAKE_BINARY_DIR}/imports CACHE STRING "" FORCE)
set(BUILD_QML ON CACHE BOOL "")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
add_library(
${PROJECT_NAME}
SHARED
plugin.cpp
ShaderPackModel.cpp
AudioModel.cpp
)
qt_add_qml_module(
${PROJECT_NAME}
URI
${QMLPLUGIN_URI}
VERSION
1.0
PLUGIN_TARGET
${PROJECT_NAME}
CLASS_NAME
KomplexPlugin
SOURCES
plugin.cpp
ShaderPackModel.cpp
AudioModel.cpp
NO_GENERATE_PLUGIN_SOURCE
)
target_link_libraries(
${PROJECT_NAME}
PRIVATE
Qt6::Quick
Qt6::Core
Qt6::Gui
Qt6::Quick3D
Qt6::Multimedia
Qt6::Qml
KF6::CoreAddons
KF6::I18n
KF6::Package
)
target_compile_definitions(
${PROJECT_NAME}
PUBLIC
KOMPLEX_PLUGIN
)
ecm_finalize_qml_module(komplex)
install(
TARGETS
${PROJECT_NAME}
DESTINATION
${KDE_INSTALL_QMLDIR}/${QMLPLUGIN_INSTALL_URI}
)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden)
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL")

10
plugin/Komplex_global.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef KOMPLEX_GLOBAL_H
#define KOMPLEX_GLOBAL_H
#ifdef KOMPLEX_PLUGIN
#define KOMPLEX_EXPORT Q_DECL_EXPORT
#else
#define KOMPLEX_EXPORT Q_DECL_IMPORT
#endif
#endif // KOMPLEX_GLOBAL_H

269
plugin/ShaderPackModel.cpp Normal file
View File

@@ -0,0 +1,269 @@
#include "ShaderPackModel.h"
ShaderPackModel::ShaderPackModel(QObject *parent)
: QObject(parent),
m_shaderPackPath(QString("%1/.local/share/komplex/packs/default").arg(QStandardPaths::writableLocation(QStandardPaths::HomeLocation))),
m_shaderPackInstallPath(QString("%1/.local/share/komplex/packs").arg(QStandardPaths::writableLocation(QStandardPaths::HomeLocation))),
m_shadersPath(QString("%1/.local/share/komplex/shaders").arg(QStandardPaths::writableLocation(QStandardPaths::HomeLocation))),
m_imagesPath(QString("%1/.local/share/komplex/images").arg(QStandardPaths::writableLocation(QStandardPaths::HomeLocation))),
m_cubeMapsPath(QString("%1/.local/share/komplex/cubemaps").arg(QStandardPaths::writableLocation(QStandardPaths::HomeLocation))),
m_videosPath(QString("%1/.local/share/komplex/videos").arg(QStandardPaths::writableLocation(QStandardPaths::HomeLocation))),
m_json(QString())
{
}
void ShaderPackModel::loadJson(const QString &filePath)
{
if (filePath.isEmpty())
return;
setState(Loading); // Set the state to Loading
// Open the file and read its contents
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
setState(Idle); // Reset state to Idle
qWarning("Could not open file %s for reading", qPrintable(filePath));
return;
}
QByteArray fileData = file.readAll();
file.close();
// Parse the JSON data to validate it
QJsonParseError error;
QJsonDocument document = QJsonDocument::fromJson(fileData, &error);
if(error.error != QJsonParseError::NoError)
{
setState(Idle); // Reset state to Idle
qWarning("JSON parse error: %s at offset %d", qPrintable(error.errorString()), error.offset);
return;
}
// Minify the JSON document to a QString
QString json = QString::fromLatin1(document.toJson(QJsonDocument::Compact));
// Check if the JSON content has changed
if (json != m_json)
{
m_json = json;
Q_EMIT jsonChanged();
setShaderPackPath(filePath); // Update the shader pack path
}
setState(Idle); // Reset state to Idle
}
QString ShaderPackModel::json() const
{
return m_json;
}
QStringList ShaderPackModel::availableShaderPacks() const
{
return m_availableShaderPacks.keys();
}
void ShaderPackModel::refreshShaderPacks()
{
setState(Loading);
// check for and create the directory if it doesn't exist
QDir dir(m_shaderPackPath);
if (!dir.exists())
{
if (!dir.mkpath(m_shaderPackPath))
{
setState(Idle); // Reset state to Idle
qWarning("Failed to create shader pack directory: %s", qPrintable(m_shaderPackPath));
return;
}
}
// Get a list of directories in the shader pack path
QStringList shaderPacks = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
QMap<QString,QString> verifiedShaderPacks;
// Only keep shader packs that contain a valid pack.json file
for(const QString &pack : std::as_const(shaderPacks))
{
QDir packDir(dir.absoluteFilePath(pack));
bool valid = false;
// Check if the pack directory contains a pack.json file
if(packDir.exists("pack.json"))
{
// Load the pack.json data
QFile packFile(packDir.absoluteFilePath("pack.json"));
if (packFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
QByteArray packData = packFile.readAll();
packFile.close(); // close the file immediately after reading
// Parse the JSON data to validate it
QJsonParseError error;
QJsonDocument doc = QJsonDocument::fromJson(packData, &error);
if (error.error != QJsonParseError::NoError)
{
qWarning("Shader pack %s has invalid JSON: %s at offset %d",
qPrintable(pack), qPrintable(error.errorString()), error.offset);
}
else
valid = true; // JSON is valid
}
}
// If valid, add to the list of verified shader packs
if(valid)
verifiedShaderPacks.insert(pack, packDir.absoluteFilePath("pack.json")); // Store the path to the pack.json file
// Otherwise, log a warning
else
qWarning("Shader pack %s does not contain a valid pack.json file", qPrintable(pack));
}
if(m_availableShaderPacks != verifiedShaderPacks)
{
m_availableShaderPacks = verifiedShaderPacks;
Q_EMIT shaderPacksChanged(); // Emit signal to notify that the list has changed
}
setState(Idle); // Reset state to Idle
}
void ShaderPackModel::loadShaderPack(const QString &name)
{
setState(Loading);
if (name.isEmpty() || !m_availableShaderPacks.contains(name))
{
qWarning("Shader pack '%s' not found", qPrintable(name));
return;
}
QString filePath = m_availableShaderPacks.value(name);
loadJson(filePath); // Load the JSON content of the shader pack
}
// This may be replaced with Quazip and something similar for tarballs in the future
void ShaderPackModel::importShaderPack(const QString &filePath)
{
if (filePath.isEmpty())
{
qWarning("File path is empty");
return;
}
QFileInfo file(filePath);
if (!file.exists())
{
qWarning("File does not exist: %s", qPrintable(filePath));
return;
}
QProcess process;
QString command;
setState(Importing); // Set the state to Importing
// Check if the file is a zip or tarball
if(filePath.endsWith(".zip", Qt::CaseInsensitive))
command = QString("unzip -o %1 -d %2/%3").arg(file.absoluteFilePath(), m_shaderPackInstallPath, file.baseName());
else if(filePath.endsWith(".tar.gz", Qt::CaseInsensitive) || filePath.endsWith(".tar", Qt::CaseInsensitive))
command = QString("tar -xf %1 -C %2/%3").arg(file.absoluteFilePath(), m_shaderPackInstallPath, file.baseName());
else
{
setState(Idle); // Reset state to Idle
qWarning("Unsupported file format for shader pack import: %s", qPrintable(filePath));
return;
}
// Connect to the process finished signal to refresh shader packs and so the event loop can exit
connect(&process, &QProcess::finished, this, [this](int exitCode, QProcess::ExitStatus exitStatus)
{
// Check if the process exited normally and with a success code
if (exitStatus == QProcess::NormalExit && exitCode == 0)
refreshShaderPacks(); // Refresh the list of shader packs
else
{
setState(Idle); // Reset state to Idle
qWarning("Failed to import shader pack: Exit code %d, Status %d", exitCode, exitStatus);
return;
}
});
// Start the process
process.start(command);
// Make sure the process started successfully
if (!process.waitForStarted())
{
setState(Idle); // Reset state to Idle
qWarning("Failed to start process for importing shader pack: %s", qPrintable(process.errorString()));
return;
}
}
ShaderPackModel::State ShaderPackModel::state() const
{
return m_state;
}
void ShaderPackModel::setState(State state)
{
if (m_state != state)
{
m_state = state;
Q_EMIT stateChanged();
}
}
QString ShaderPackModel::shaderPackPath() const
{
return m_shaderPackPath;
}
void ShaderPackModel::setShaderPackPath(const QString &filePath)
{
QFileInfo fileInfo(filePath);
if (m_shaderPackPath != fileInfo.absolutePath())
{
m_shaderPackPath = filePath;
Q_EMIT shaderPackPathChanged();
}
}
QString ShaderPackModel::shaderPackName() const
{
return m_shaderPackName;
}
QString ShaderPackModel::shaderPackInstallPath() const
{
return m_shaderPackInstallPath;
}
QString ShaderPackModel::shadersPath() const
{
return m_shadersPath;
}
QString ShaderPackModel::imagesPath() const
{
return m_imagesPath;
}
QString ShaderPackModel::cubeMapsPath() const
{
return m_cubeMapsPath;
}
QString ShaderPackModel::videosPath() const
{
return m_videosPath;
}

154
plugin/ShaderPackModel.h Normal file
View File

@@ -0,0 +1,154 @@
#ifndef SHADERPACKMODEL_H
#define SHADERPACKMODEL_H
#include "Komplex_global.h"
#include <QObject>
#include <QString>
#include <QFile>
#include <QFileInfo>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonParseError>
#include <QStandardPaths>
#include <QDir>
#include <QMap>
#include <QProcess>
#include <QEventLoop>
#include <QtQml/qqmlregistration.h>
class KOMPLEX_EXPORT ShaderPackModel : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
explicit ShaderPackModel(QObject *parent = nullptr);
~ShaderPackModel() override = default;
// State enum to represent the current state of the model
// for the UI and configuration
enum State
{
Idle,
Loading,
Importing
};
Q_ENUM(State)
/**!
* @brief json
* This function returns the current JSON content as a QString.
* It is expected to be called to retrieve the shader pack's JSON data,
* after loadJson() has been called to load the shader pack.
*
* @return QString containing the JSON data.
*/
QString json() const;
/**!
* @brief loadJson
* This function loads a JSON file from the specified path and updates
* the model. It emits jsonChanged() signal if the JSON content changes.
*
* @param filePath The path to the JSON file to load.
*/
Q_INVOKABLE void loadJson(const QString &filePath);
/**!
* @brief availableShaderPacks
* This function returns a list of available shader packs.
* It is expected to be called to retrieve the list of shader packs.
*
* @return QStringList containing the names of available shader packs.
*/
QStringList availableShaderPacks() const;
/**!
* @brief refreshShaderPacks
* This function refreshes the list of available shader packs by checking
* the shader pack directory for valid packs. It emits the shaderPacksChanged()
* signal if the list of available shader packs changes.
*/
Q_INVOKABLE void refreshShaderPacks();
/**!
* @brief loadShaderPack
* This function loads a shader pack from the specified file path.
* It is expected to be called to load a specific shader pack.
*
* @param name The name of the shader pack file to load.
*/
Q_INVOKABLE void loadShaderPack(const QString &name);
/**!
* @brief importShaderPack
* This function imports a shader pack from the specified file path.
* It is expected to be called to be either a zip or tarball structured
* as described in the wiki.
*
* @param filePath The path to the shader pack file to import.
*/
Q_INVOKABLE void importShaderPack(const QString &filePath);
/**!
* @brief state
* This function returns the current state of the model.
* It is expected to be called to retrieve the current state.
*
* @return State representing the current state of the model.
*/
State state() const;
QString shaderPackPath() const;
QString shaderPackName() const;
QString shaderPackInstallPath() const;
QString shadersPath() const;
QString imagesPath() const;
QString cubeMapsPath() const;
QString videosPath() const;
protected:
void setState(State state);
void setShaderPackPath(const QString &filePath);
Q_SIGNALS:
void shaderPackPathChanged();
void shaderPackNameChanged();
void shaderPackInstallPathChanged();
void jsonChanged();
void shaderPacksChanged();
void stateChanged();
void error(const QString &errorString);
private:
QString m_shaderPackPath;
QString m_shaderPackName;
const QString m_shaderPackInstallPath;
const QString m_shadersPath;
const QString m_imagesPath;
const QString m_cubeMapsPath;
const QString m_videosPath;
QString m_json;
QMap<QString, QString> m_availableShaderPacks; // Maps shader pack names to their file paths
State m_state = Idle;
Q_PROPERTY(QString json READ json WRITE loadJson NOTIFY jsonChanged)
Q_PROPERTY(QStringList availableShaderPacks READ availableShaderPacks NOTIFY shaderPacksChanged)
Q_PROPERTY(State state READ state NOTIFY stateChanged)
Q_PROPERTY(QString shaderPackPath READ shaderPackPath NOTIFY shaderPackPathChanged)
Q_PROPERTY(QString shaderPackName READ shaderPackName NOTIFY shaderPackNameChanged)
Q_PROPERTY(QString shaderPackInstallPath READ shaderPackInstallPath NOTIFY shaderPackInstallPathChanged)
Q_PROPERTY(QString shadersPath READ shadersPath CONSTANT)
Q_PROPERTY(QString imagesPath READ imagesPath CONSTANT)
Q_PROPERTY(QString cubeMapsPath READ cubeMapsPath CONSTANT)
Q_PROPERTY(QString videosPath READ videosPath CONSTANT)
};
Q_DECLARE_METATYPE(ShaderPackModel)
#endif // SHADERPACKMODEL_H

23
plugin/plugin.cpp Normal file
View File

@@ -0,0 +1,23 @@
#include <QObject>
#include <QQmlEngine>
#include <QQmlExtensionPlugin>
#include "AudioModel.h"
#include "ShaderPackModel.h"
#include "Komplex_global.h"
class KOMPLEX_EXPORT KomplexPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid FILE "plugin.json")
public:
void registerTypes(const char *uri) override
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("com.github.digitalartifex.komplex"));
qmlRegisterType<AudioModel>(uri, 1, 0, "AudioModel");
qmlRegisterType<ShaderPackModel>(uri, 1, 0, "ShaderPackModel");
}
};
#include "plugin.moc"

18
plugin/plugin.json Normal file
View File

@@ -0,0 +1,18 @@
{
"Id" : "komplex",
"Name" : "Komplex Wallpaper Plugin",
"Version" : "1.0.0",
"CompatVersion" : "1.0.0",
"VendorId" : "digitalartifex",
"Vendor" : "Digital Artifex",
"Copyright" : "(C) 2025 Digital Artifex",
"License" : [
"GLPL-3.0-or-later"
],
"Category" : "Wallpaper Plugins",
"Description" : [
"This plugin enables functionality for the Komplex wallpaper, allowing users to set and manage complex shader arrangements as wallpapers in their KDE environment."
],
"Url" : "http://www.github.com/digitalartifex/komplex",
"DocumentationUrl" : "http://www.github.com/digitalartifex/komplex/wiki"
}

4
plugin/qmldir Normal file
View File

@@ -0,0 +1,4 @@
module com.github.digitalartifex.komplex
plugin komplex
classname AudioModel
classname ShaderPackModel