Skip to content

Commit

Permalink
Initializes ProfileModel (#1147)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon authored Nov 29, 2024
1 parent d614b4c commit af9cc16
Show file tree
Hide file tree
Showing 35 changed files with 183 additions and 509 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@
"rust-analyzer.imports.granularity.group": "module",
"rust-analyzer.imports.group.enable": false,
"rust-analyzer.imports.prefix": "self",
"slint.libraryPaths": {
"root": "gui/ui"
},
"slint.preview.style": "fluent-dark"
}
1 change: 0 additions & 1 deletion gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ add_executable(obliteration WIN32 MACOSX_BUNDLE
main.cpp
main_window.cpp
path.cpp
profile_models.cpp
progress_dialog.cpp
resources.cpp
resources.qrc
Expand Down
7 changes: 3 additions & 4 deletions gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ path = "src/main.rs"
required-features = ["slint"]

[features]
slint = ["dep:slint", "dep:clap", "dep:open"]
slint = []
qt = []

[dependencies]
bitfield-struct = "0.9.2"
ciborium = "0.2.2"
clap = { version = "4.5.21", features = ["derive"], optional = true }
clap = { version = "4.5.21", features = ["derive"] }
gdbstub = "0.7.3"
gdbstub_arch = "0.3.1"
humansize = "2.1.3"
Expand All @@ -29,7 +29,7 @@ obfw = { git = "https://github.com/obhq/firmware-dumper.git", features = [
"read",
"std",
] }
open = { version = "5.3.1", optional = true }
open = { version = "5.3.1" }
raw-window-handle = "0.6.2"
serde = { version = "1.0.209", features = ["derive"] }
thiserror = "1.0"
Expand All @@ -45,7 +45,6 @@ features = [
"std",
]
default-features = false
optional = true

[target.'cfg(target_arch = "aarch64")'.dependencies]
aarch64 = { path = "../arch/aarch64" }
Expand Down
24 changes: 12 additions & 12 deletions gui/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cbindgen::{Builder, Config, Language, Style};
use slint_build::CompilerConfiguration;
use std::collections::HashMap;
use std::path::PathBuf;

const LINUX_INCLUDE: &str = r#"
Expand All @@ -9,24 +10,23 @@ const LINUX_INCLUDE: &str = r#"
"#;

fn main() {
if std::env::var("CARGO_FEATURE_SLINT").is_ok_and(|var| var == "1") {
build_bin();
}
// Build path for @root.
let mut root = PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap());

root.push("ui");

// Compile Slint.
let config = CompilerConfiguration::new()
.with_style(String::from("fluent-dark"))
.with_library_paths(HashMap::from([("root".into(), root)]));

slint_build::compile_with_config(PathBuf::from_iter(["ui", "main.slint"]), config).unwrap();

if std::env::var("CARGO_FEATURE_QT").is_ok_and(|var| var == "1") {
build_lib();
}
}

fn build_bin() {
// Compile Slint.
slint_build::compile_with_config(
PathBuf::from_iter(["ui", "main.slint"]),
CompilerConfiguration::new().with_style(String::from("fluent-dark")),
)
.unwrap();
}

fn build_lib() {
let root = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
let mut conf = Config::default();
Expand Down
39 changes: 0 additions & 39 deletions gui/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,6 @@
struct Param;
struct Pkg;

/**
* Display resolution to report to the kernel.
*/
enum DisplayResolution {
/**
* 1280 × 720.
*/
DisplayResolution_Hd,
/**
* 1920 × 1080.
*/
DisplayResolution_FullHd,
/**
* 3840 × 2160.
*/
DisplayResolution_UltraHd,
};

/**
* Contains settings to launch the kernel.
*/
struct Profile;

/**
* Error object managed by Rust side.
*/
Expand All @@ -49,22 +26,6 @@ void error_free(struct RustError *e);

const char *error_message(const struct RustError *e);

struct Profile *profile_new(const char *name);

struct Profile *profile_load(const char *path, struct RustError **err);

void profile_free(struct Profile *p);

char *profile_id(const struct Profile *p);

const char *profile_name(const struct Profile *p);

enum DisplayResolution profile_display_resolution(const struct Profile *p);

void profile_set_display_resolution(struct Profile *p, enum DisplayResolution v);

struct RustError *profile_save(const struct Profile *p, const char *path);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
9 changes: 0 additions & 9 deletions gui/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ inline void Rust<char>::free()
m_ptr = nullptr;
}

template<>
inline void Rust<Profile>::free()
{
if (m_ptr) {
profile_free(m_ptr);
m_ptr = nullptr;
}
}

template<>
inline void Rust<RustError>::free()
{
Expand Down
52 changes: 1 addition & 51 deletions gui/display_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,11 @@ DisplaySettings::DisplaySettings(QList<VkPhysicalDevice> &&vkDevices, QWidget *p
#ifndef __APPLE__
m_devices(nullptr),
#endif
m_resolutions(nullptr),
m_profile(nullptr)
m_resolutions(nullptr)
{
auto layout = new QGridLayout();

#ifdef __APPLE__
layout->addWidget(buildResolution(), 0, 0);
#else
layout->addWidget(buildDevice(std::move(vkDevices)), 0, 0);
layout->addWidget(buildResolution(), 0, 1);
#endif
layout->setRowStretch(1, 1);

setLayout(layout);
Expand All @@ -41,25 +35,6 @@ DisplaySettings::~DisplaySettings()
{
}

void DisplaySettings::setProfile(Profile *p)
{
// Set current profile before update the widgets since the update may trigger some signals.
m_profile = p;

// Set resolution.
auto resolution = profile_display_resolution(p);
auto i = m_resolutions->findData(resolution);

if (i < 0) {
QMessageBox::critical(
this,
"Error",
QString("Unknown display resolution %1.").arg(resolution));
} else {
m_resolutions->setCurrentIndex(i);
}
}

#ifndef __APPLE__
DisplayDevice *DisplaySettings::currentDevice() const
{
Expand Down Expand Up @@ -91,31 +66,6 @@ QWidget *DisplaySettings::buildDevice(QList<VkPhysicalDevice> &&vkDevices)
}
#endif

QWidget *DisplaySettings::buildResolution()
{
// Setup group box.
auto group = new QGroupBox("Resolution");
auto layout = new QVBoxLayout();

// Setup resolution list.
m_resolutions = new QComboBox();
m_resolutions->addItem("1280 × 720", DisplayResolution_Hd);
m_resolutions->addItem("1920 × 1080", DisplayResolution_FullHd);
m_resolutions->addItem("3840 × 2160", DisplayResolution_UltraHd);

connect(m_resolutions, &QComboBox::currentIndexChanged, [this](int index) {
auto value = static_cast<DisplayResolution>(m_resolutions->itemData(index).toInt());

profile_set_display_resolution(m_profile, value);
});

layout->addWidget(m_resolutions);

group->setLayout(layout);

return group;
}

#ifndef __APPLE__
DisplayDevice::DisplayDevice(VkPhysicalDevice handle) :
m_handle(handle)
Expand Down
6 changes: 0 additions & 6 deletions gui/display_settings.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include "core.h"

#ifndef __APPLE__
#include <QVulkanInstance>
#endif
Expand All @@ -21,22 +19,18 @@ class DisplaySettings final : public QWidget {
#endif
~DisplaySettings() override;

void setProfile(Profile *p);

#ifndef __APPLE__
DisplayDevice *currentDevice() const;
#endif
private:
#ifndef __APPLE__
QWidget *buildDevice(QList<VkPhysicalDevice> &&vkDevices);
#endif
QWidget *buildResolution();

#ifndef __APPLE__
QComboBox *m_devices;
#endif
QComboBox *m_resolutions;
Profile *m_profile;
};

#ifndef __APPLE__
Expand Down
46 changes: 3 additions & 43 deletions gui/launch_settings.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "launch_settings.hpp"
#include "cpu_settings.hpp"
#include "display_settings.hpp"
#include "profile_models.hpp"
#include "resources.hpp"

#include <QComboBox>
Expand All @@ -19,10 +18,9 @@
#include <utility>

#ifdef __APPLE__
LaunchSettings::LaunchSettings(ProfileList *profiles, QWidget *parent) :
LaunchSettings::LaunchSettings(QWidget *parent) :
#else
LaunchSettings::LaunchSettings(
ProfileList *profiles,
QList<VkPhysicalDevice> &&vkDevices,
QWidget *parent) :
#endif
Expand All @@ -38,7 +36,7 @@ LaunchSettings::LaunchSettings(
#else
layout->addWidget(buildSettings(std::move(vkDevices)));
#endif
layout->addLayout(buildActions(profiles));
layout->addLayout(buildActions());

setLayout(layout);
}
Expand All @@ -47,21 +45,6 @@ LaunchSettings::~LaunchSettings()
{
}

Profile *LaunchSettings::currentProfile() const
{
// Check if profile list is not empty.
auto index = m_profiles->currentIndex();

if (index < 0) {
return nullptr;
}

// Get profile.
auto profiles = reinterpret_cast<ProfileList *>(m_profiles->model());

return profiles->get(index);
}

#ifndef __APPLE__
DisplayDevice *LaunchSettings::currentDisplayDevice() const
{
Expand Down Expand Up @@ -100,15 +83,12 @@ QWidget *LaunchSettings::buildSettings(QList<VkPhysicalDevice> &&vkDevices)
return tab;
}

QLayout *LaunchSettings::buildActions(ProfileList *profiles)
QLayout *LaunchSettings::buildActions()
{
auto layout = new QHBoxLayout();

// Profile list.
m_profiles = new QComboBox();
m_profiles->setModel(profiles);

connect(m_profiles, &QComboBox::currentIndexChanged, this, &LaunchSettings::profileChanged);

layout->addWidget(m_profiles, 1);

Expand All @@ -122,16 +102,6 @@ QLayout *LaunchSettings::buildActions(ProfileList *profiles)

save->setIcon(loadIcon(":/resources/content-save.svg", save->iconSize()));

connect(save, &QAbstractButton::clicked, [this]() {
auto index = m_profiles->currentIndex();

if (index >= 0) {
auto profiles = reinterpret_cast<ProfileList *>(m_profiles->model());

emit saveClicked(profiles->get(index));
}
});

actions->addButton(save, QDialogButtonBox::ApplyRole);

// Start button.
Expand All @@ -145,13 +115,3 @@ QLayout *LaunchSettings::buildActions(ProfileList *profiles)

return layout;
}

void LaunchSettings::profileChanged(int index)
{
assert(index >= 0);

auto profiles = reinterpret_cast<ProfileList *>(m_profiles->model());
auto p = profiles->get(index);

m_display->setProfile(p);
}
Loading

0 comments on commit af9cc16

Please sign in to comment.