-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpudevicelist.cpp
134 lines (119 loc) · 4.36 KB
/
gpudevicelist.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/****************************************************************************}
{ gpudevicelist.cpp - GPU device list }
{ }
{ Copyright (c) 2018 Alexey Parfenov <zxed@alkatrazstudio.net> }
{ }
{ This file is part of GPU Fan Meister. }
{ }
{ GPU Fan Meister 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. }
{ }
{ GPU Fan Meister 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: https://gnu.org/licenses/gpl.html }
{****************************************************************************/
#include "gpudevicelist.h"
#include "errormanager.h"
#include "appsettings.h"
#include <QDebug>
static const char* GPU_DEVICE_LIST_CONF_GROUP = "GpuDeviceList";
static const int TIMER_UPDATE_INTERVAL = 1000;
GpuDeviceList::GpuDeviceList(QObject* parent) :
QObject(parent)
{
}
GpuDeviceList::GpuDeviceList(const QStringList &plugins, QObject* parent) :
QObject(parent)
{
loadSettings();
for(const QString& name : plugins)
{
try{
GpuDevicePlugin::Ptr plugin(new GpuDevicePlugin(name));
size_t nDevices = plugin->deviceCount();
for(size_t deviceIndex=0; deviceIndex<nDevices; deviceIndex++)
{
try{
GpuDevice* dev = new GpuDevice(plugin, deviceIndex, this);
QObject::connect(dev, &GpuDevice::onShowAppClick, [this, dev]{
emit onShowAppClick(dev);
});
QObject::connect(dev, &GpuDevice::onShowDevOptionsClick, [this, dev]{
emit onShowDevOptionsClick(dev);
});
QObject::connect(dev, &GpuDevice::onShowManualClick, [this, dev](const QString& uri){
emit onShowManualClick(uri, dev);
});
QObject::connect(dev, &GpuDevice::onQuitClick, this, &GpuDeviceList::onQuitClick);
devices_.append(dev);
}catch(const ErrorManager::Exception& e){
Q_UNUSED(e);
}
}
}catch(GpuDevicePlugin::Error& e){
qDebug() << name << ":" << e.what();
}
}
if(devices_.empty())
return;
timerId_ = startTimer(TIMER_UPDATE_INTERVAL);
CHECKE(timerId_, Err::timer);
}
GpuDeviceList::~GpuDeviceList()
{
if(timerId_)
killTimer(timerId_);
}
void GpuDeviceList::saveDeviceModeSettings() const
{
for(GpuDevice* dev : qAsConst(devices_))
dev->saveModeSettings();
}
void GpuDeviceList::loadDeviceModeSettings()
{
for(GpuDevice* dev : qAsConst(devices_))
dev->loadModeSettings();
}
void GpuDeviceList::loadSettings()
{
AppSettings conf;
conf.beginGroup(GPU_DEVICE_LIST_CONF_GROUP);
set_trayUpdateSecs(conf.getUInt("trayUpdateSecs", 10));
conf.endGroup();
}
void GpuDeviceList::saveSettings()
{
AppSettings conf;
conf.beginGroup(GPU_DEVICE_LIST_CONF_GROUP);
conf.setValue("trayUpdateSecs", trayUpdateSecs_);
conf.endGroup();
}
void GpuDeviceList::timerEvent(QTimerEvent *event)
{
if(event->timerId() != timerId_)
return;
bool listUpdated = false;
for(GpuDevice* dev : qAsConst(devices_))
{
try{
dev->update();
}catch(ErrorManager::Exception&){
devices_.removeOne(dev);
dev->deleteLater();
listUpdated = true;
}
}
if(listUpdated)
emit onListChanged();
}
QString GpuDeviceList::errorCodeToString(Err errorCode)
{
switch(errorCode)
{
case Err::timer: return "Cannot init timer";
}
return QString();
}