mirror of
https://github.com/Lurkki14/tuxclocker.git
synced 2024-11-28 02:43:49 -06:00
add some readable items to gui
This commit is contained in:
parent
09cff3b591
commit
c56fb42b6d
@ -77,6 +77,9 @@ tc_module_t *tc_module_find(enum tc_module_category category, const char *name)
|
||||
break;
|
||||
case TC_CATEGORY_INTERFACE:
|
||||
mod_abs_path = module_filename("interface", name);
|
||||
break;
|
||||
case TC_CATEGORY_READABLE:
|
||||
mod_abs_path = module_filename("readable", name);
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
@ -120,10 +123,14 @@ tc_module_t **tc_module_find_all_from_category(enum tc_module_category category,
|
||||
case TC_CATEGORY_ASSIGNABLE:
|
||||
snprintf(mod_dir_name, 512, "%s/%s", TC_MODULE_PATH, "assignable");
|
||||
break;
|
||||
case TC_CATEGORY_READABLE:
|
||||
snprintf(mod_dir_name, 512, "%s/%s", TC_MODULE_PATH, "readable");
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// FIXME: file_names members are sometimes corrupted
|
||||
char **file_names = tc_fs_dir_filenames(mod_dir_name, &file_count);
|
||||
if (file_names == NULL) {
|
||||
return NULL;
|
||||
@ -156,7 +163,7 @@ void tc_module_close(tc_module_t* module) {
|
||||
if (module->close_callback() != TC_SUCCESS) {
|
||||
// Add some sort of log message here
|
||||
// It's probably good to abort here
|
||||
abort();
|
||||
//abort();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,8 @@ static void postorder_traverse(tc_readable_node_t *node, void (*func)(tc_readabl
|
||||
}
|
||||
|
||||
tc_readable_node_t *tc_readable_node_new() {
|
||||
return calloc(1, sizeof(tc_readable_node_t));
|
||||
tc_readable_node_t *node = calloc(1, sizeof(tc_readable_node_t));
|
||||
return node;
|
||||
}
|
||||
|
||||
void tc_readable_node_destroy(tc_readable_node_t *node) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "ReadableManager.h"
|
||||
|
||||
ReadableManger::ReadableManger() {
|
||||
ReadableManager::ReadableManager() {
|
||||
uint16_t mod_count = 0;
|
||||
tc_module_t **modules = tc_module_find_all_from_category(TC_CATEGORY_READABLE, &mod_count);
|
||||
|
||||
@ -11,19 +11,21 @@ ReadableManger::ReadableManger() {
|
||||
for (uint16_t i = 0; i < mod_count; i++) {
|
||||
if (modules[i]->init_callback && modules[i]->init_callback() == TC_SUCCESS) {
|
||||
// Module was initialized successfully
|
||||
|
||||
tc_readable_node_t *root_node = static_cast<tc_readable_node_t*>(modules[i]->category_data_callback());
|
||||
if (root_node) {
|
||||
// Add to the list
|
||||
m_rootNodes.append(root_node);
|
||||
m_root = root_node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tc_module_t *nv_mod = tc_module_find(TC_CATEGORY_READABLE, "nvidia");
|
||||
/* tc_module_t *nv_mod = tc_module_find(TC_CATEGORY_READABLE, "nvidia");
|
||||
nv_mod->init_callback();
|
||||
tc_readable_node_t *nv_node = static_cast<tc_readable_node_t*>(nv_mod->category_data_callback());
|
||||
m_rootNodes.append(nv_node);
|
||||
m_rootNodes.append(nv_node);*/
|
||||
}
|
||||
|
||||
ReadableManger::~ReadableManger() {
|
||||
ReadableManager::~ReadableManager() {
|
||||
}
|
||||
|
@ -5,11 +5,13 @@
|
||||
#include <tc_module.h>
|
||||
#include <tc_readable.h>
|
||||
|
||||
class ReadableManger {
|
||||
class ReadableManager {
|
||||
public:
|
||||
ReadableManger();
|
||||
~ReadableManger();
|
||||
ReadableManager();
|
||||
~ReadableManager();
|
||||
QVector <tc_readable_node_t*> rootNodes() {return m_rootNodes;}
|
||||
tc_readable_node_t *root() {return m_root;}
|
||||
private:
|
||||
QVector <tc_readable_node_t*> m_rootNodes;
|
||||
tc_readable_node_t *m_root;
|
||||
};
|
||||
|
@ -1,8 +1,61 @@
|
||||
#include "ReadableBrowser.h"
|
||||
|
||||
ReadableBrowser::ReadableBrowser(QWidget *parent) : QWidget(parent) {
|
||||
#include <QDebug>
|
||||
|
||||
ReadableBrowser::ReadableBrowser(ReadableManager *readableManager, QWidget *parent) : QWidget(parent) {
|
||||
m_mainLayout = new QVBoxLayout;
|
||||
|
||||
m_readableTreeView = new QTreeView;
|
||||
|
||||
m_browserModel = new QStandardItemModel;
|
||||
|
||||
m_readableManager = readableManager;
|
||||
|
||||
genBrowserTree(m_readableTreeView, m_browserModel);
|
||||
|
||||
m_mainLayout->addWidget(m_readableTreeView);
|
||||
|
||||
setLayout(m_mainLayout);
|
||||
|
||||
}
|
||||
|
||||
ReadableBrowser::~ReadableBrowser() {
|
||||
}
|
||||
|
||||
void ReadableBrowser::genBrowserTree(QTreeView *treeView, QStandardItemModel *itemModel) {
|
||||
QStandardItem *parentItem = itemModel->invisibleRootItem();
|
||||
|
||||
std::function<void(tc_readable_node_t*, QStandardItem*)> traverse;
|
||||
traverse = [=, &traverse](tc_readable_node_t *node, QStandardItem *item) {
|
||||
if (node->name) {
|
||||
qDebug() << node->name;
|
||||
}
|
||||
addBrowserItem(node, item);
|
||||
|
||||
for (uint16_t i = 0; i < node->children_count; i++) {
|
||||
traverse(node->children_nodes[i], item);
|
||||
}
|
||||
};
|
||||
//tc_readable_node_t *root = m_readableManager->root();
|
||||
QVector <tc_readable_node_t*> rootNodes = m_readableManager->rootNodes();
|
||||
|
||||
for (tc_readable_node_t *node : m_readableManager->rootNodes()) {
|
||||
traverse(node, parentItem);
|
||||
}
|
||||
|
||||
treeView->setModel(itemModel);
|
||||
}
|
||||
|
||||
void ReadableBrowser::addBrowserItem(tc_readable_node_t* node, QStandardItem *parent) {
|
||||
// Don't add item for constants
|
||||
if (node->constant) {
|
||||
return;
|
||||
}
|
||||
if (!node->name) {
|
||||
return;
|
||||
}
|
||||
QStandardItem *item = new QStandardItem;
|
||||
item->setText(node->name);
|
||||
|
||||
parent->appendRow(item);
|
||||
}
|
||||
|
@ -1,9 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <ReadableManager.h>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QTreeView>
|
||||
#include <QStandardItemModel>
|
||||
|
||||
class ReadableBrowser : public QWidget {
|
||||
public:
|
||||
ReadableBrowser(QWidget *parent = nullptr);
|
||||
ReadableBrowser(ReadableManager *readableManager, QWidget *parent = nullptr);
|
||||
~ReadableBrowser();
|
||||
private:
|
||||
ReadableManager *m_readableManager; // ReadableManager instance that the browser is generated from
|
||||
|
||||
QVBoxLayout *m_mainLayout;
|
||||
QTreeView *m_readableTreeView;
|
||||
QStandardItemModel *m_browserModel;
|
||||
|
||||
void genBrowserTree(QTreeView *treeView, QStandardItemModel *itemModel);
|
||||
void addBrowserItem(tc_readable_node_t* node, QStandardItem *parent); // Create a new item from 'node'
|
||||
};
|
||||
|
@ -8,7 +8,10 @@ ReadableWidget::ReadableWidget(QWidget *parent) : QWidget(parent) {
|
||||
|
||||
m_tabWidget = new QTabWidget;
|
||||
|
||||
m_readableBrowser = new ReadableBrowser;
|
||||
m_readableManager = new ReadableManager;
|
||||
qDebug() << "rd nodes" << m_readableManager->rootNodes();
|
||||
|
||||
m_readableBrowser = new ReadableBrowser(m_readableManager);
|
||||
|
||||
m_tabWidget->addTab(m_readableBrowser, "Browser");
|
||||
|
||||
@ -16,8 +19,6 @@ ReadableWidget::ReadableWidget(QWidget *parent) : QWidget(parent) {
|
||||
|
||||
setLayout(m_mainLayout);
|
||||
|
||||
m_readableManager = new ReadableManger;
|
||||
qDebug() << "rd nodes" << m_readableManager->rootNodes();
|
||||
}
|
||||
|
||||
ReadableWidget::~ReadableWidget() {
|
||||
|
@ -19,5 +19,5 @@ private:
|
||||
|
||||
QVBoxLayout *m_mainLayout;
|
||||
|
||||
ReadableManger *m_readableManager;
|
||||
ReadableManager *m_readableManager;
|
||||
};
|
||||
|
@ -175,10 +175,13 @@ void add_temp_item(tc_readable_node_t *parent, nvmlDevice_t dev) {
|
||||
if (temp_node == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tc_readable_node_add_child(parent, temp_node) != TC_SUCCESS) {
|
||||
tc_readable_node_destroy(temp_node);
|
||||
return;
|
||||
}
|
||||
|
||||
temp_node->name = strdup("Temperature");
|
||||
}
|
||||
|
||||
tc_readable_result_t get_temp(tc_readable_node_t *node) {
|
||||
|
Loading…
Reference in New Issue
Block a user