11#include " detector.h"
2+
23#include " system/commandrunner.h"
34
45#include < QFile>
6+ #include < QtGlobal>
57#include < QRegularExpression>
68#include < QTextStream>
79
@@ -16,6 +18,7 @@ NvidiaDetector::GpuInfo NvidiaDetector::detect() const {
1618 info.driverLoaded = isModuleLoaded (QStringLiteral (" nvidia" ));
1719 info.nouveauActive = isModuleLoaded (QStringLiteral (" nouveau" ));
1820 info.secureBootEnabled = detectSecureBoot ();
21+ info.sessionType = detectSessionType ();
1922
2023 return info;
2124}
@@ -30,43 +33,60 @@ QString NvidiaDetector::installedDriverVersion() const {
3033 return detectDriverVersion ();
3134}
3235
36+ QString NvidiaDetector::activeDriver () const {
37+ if (m_info.driverLoaded )
38+ return QStringLiteral (" Kapali Kaynak (NVIDIA)" );
39+ if (m_info.nouveauActive )
40+ return QStringLiteral (" Acik Kaynak (Nouveau)" );
41+ return QStringLiteral (" Yuklu Degil/Bilinmiyor" );
42+ }
43+
3344QString NvidiaDetector::verificationReport () const {
3445 const QString gpuText = m_info.found ? m_info.name : QStringLiteral (" Yok" );
35- const QString driverText =
36- m_info.driverVersion .isEmpty () ? QStringLiteral (" Yok" ) : m_info.driverVersion ;
37- const QString secureBootText = m_info.secureBootEnabled ? QStringLiteral (" Acik" )
38- : QStringLiteral (" Kapali/Bilinmiyor" );
39-
40- return QStringLiteral (" GPU: %1\n Surucu Versiyonu: %2\n Secure Boot: %3\n NVIDIA Modulu: %4\n Nouveau: %5" )
41- .arg (gpuText, driverText, secureBootText,
42- m_info.driverLoaded ? QStringLiteral (" Yuklu" ) : QStringLiteral (" Yuklu degil" ),
43- m_info.nouveauActive ? QStringLiteral (" Aktif" ) : QStringLiteral (" Aktif degil" ));
46+ const QString versionText = m_info.driverVersion .isEmpty ()
47+ ? QStringLiteral (" Yok" )
48+ : m_info.driverVersion ;
49+
50+ return QStringLiteral (
51+ " GPU: %1\n Surucu Versiyonu: %2\n Secure Boot: %3\n Oturum: %4\n "
52+ " NVIDIA Modulu: %5\n Nouveau: %6" )
53+ .arg (gpuText, versionText,
54+ m_info.secureBootEnabled ? QStringLiteral (" Acik" )
55+ : QStringLiteral (" Kapali/Bilinmiyor" ),
56+ m_info.sessionType .isEmpty () ? QStringLiteral (" Bilinmiyor" )
57+ : m_info.sessionType ,
58+ m_info.driverLoaded ? QStringLiteral (" Yuklu" )
59+ : QStringLiteral (" Yuklu degil" ),
60+ m_info.nouveauActive ? QStringLiteral (" Aktif" )
61+ : QStringLiteral (" Aktif degil" ));
62+ }
63+
64+ void NvidiaDetector::refresh () {
65+ m_info = detect ();
66+ emit infoChanged ();
4467}
4568
4669QString NvidiaDetector::detectGpuName () const {
4770 CommandRunner runner;
4871
49- // lspci ile PCI cihazlarını listele, NVIDIA olanı filtrele
5072 const auto result =
5173 runner.run (QStringLiteral (" lspci" ), {QStringLiteral (" -mm" )});
5274
5375 if (!result.success ())
5476 return {};
5577
56- // lspci -mm çıktısında NVIDIA GPU satırını ara
5778 const QStringList lines = result.stdout .split (QLatin1Char (' \n ' ));
5879 for (const QString &line : lines) {
5980 if (line.contains (QStringLiteral (" NVIDIA" ), Qt::CaseInsensitive) &&
6081 line.contains (QStringLiteral (" VGA" ), Qt::CaseInsensitive)) {
61- // Tırnak işaretleri arasındaki model adını çıkar
6282 static const QRegularExpression re (QStringLiteral (" \" ([^\" ]+)\" " ));
6383 auto it = re.globalMatch (line);
6484 QStringList parts;
6585 while (it.hasNext ())
6686 parts << it.next ().captured (1 );
6787
6888 if (parts.size () >= 3 )
69- return parts[2 ]; // Model adı 3. tırnak grubunda
89+ return parts[2 ];
7090 }
7191 }
7292
@@ -76,15 +96,13 @@ QString NvidiaDetector::detectGpuName() const {
7696QString NvidiaDetector::detectDriverVersion () const {
7797 CommandRunner runner;
7898
79- // nvidia-smi varsa sürücü versiyonunu döner
8099 const auto result = runner.run (QStringLiteral (" nvidia-smi" ),
81100 {QStringLiteral (" --query-gpu=driver_version" ),
82101 QStringLiteral (" --format=csv,noheader" )});
83102
84103 if (result.success ())
85104 return result.stdout .trimmed ();
86105
87- // nvidia-smi yoksa modinfo'dan dene
88106 const auto modinfo =
89107 runner.run (QStringLiteral (" modinfo" ), {QStringLiteral (" nvidia" )});
90108
@@ -100,7 +118,6 @@ QString NvidiaDetector::detectDriverVersion() const {
100118}
101119
102120bool NvidiaDetector::isModuleLoaded (const QString &moduleName) const {
103- // /proc/modules dosyasını oku — yüklü kernel modüllerini listeler
104121 QFile modules (QStringLiteral (" /proc/modules" ));
105122 if (!modules.open (QIODevice::ReadOnly | QIODevice::Text))
106123 return false ;
@@ -121,13 +138,29 @@ bool NvidiaDetector::detectSecureBoot() const {
121138 runner.run (QStringLiteral (" mokutil" ), {QStringLiteral (" --sb-state" )});
122139
123140 if (result.success () || result.exitCode == 1 ) {
124- return result.stdout .contains (QStringLiteral (" enabled" ), Qt::CaseInsensitive);
141+ return result.stdout .contains (QStringLiteral (" enabled" ),
142+ Qt::CaseInsensitive);
125143 }
126144
127145 return false ;
128146}
129147
130- void NvidiaDetector::refresh () {
131- m_info = detect ();
132- emit infoChanged ();
148+ QString NvidiaDetector::detectSessionType () const {
149+ const QString envType = qEnvironmentVariable (" XDG_SESSION_TYPE" ).trimmed ().toLower ();
150+ if (!envType.isEmpty ())
151+ return envType;
152+
153+ CommandRunner runner;
154+ const auto loginctl = runner.run (
155+ QStringLiteral (" loginctl" ),
156+ {QStringLiteral (" show-session" ), qEnvironmentVariable (" XDG_SESSION_ID" ),
157+ QStringLiteral (" -p" ), QStringLiteral (" Type" ), QStringLiteral (" --value" )});
158+
159+ if (loginctl.success ()) {
160+ const QString type = loginctl.stdout .trimmed ().toLower ();
161+ if (!type.isEmpty ())
162+ return type;
163+ }
164+
165+ return QStringLiteral (" unknown" );
133166}
0 commit comments