Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
Executable
+200
@@ -0,0 +1,200 @@
|
||||
#include "configurator.h"
|
||||
|
||||
#include "guez2018/guez2018.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QScreen>
|
||||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
#include <QStyle>
|
||||
#include <QDesktopWidget>
|
||||
#include <QFile>
|
||||
#include <QCheckBox>
|
||||
#include <QProcess>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
Configurator::Configurator(const QString &filename)
|
||||
: QWidget(nullptr)
|
||||
, m_uiIfc(nullptr)
|
||||
, m_currentScreen(nullptr)
|
||||
, m_mainScreen(nullptr)
|
||||
, m_filename(filename)
|
||||
, m_cbMainScreen(nullptr)
|
||||
{
|
||||
int index = projectNames().indexOf(m_filename);
|
||||
switch (index)
|
||||
{
|
||||
case 0: // guez2018
|
||||
{
|
||||
m_uiIfc = new Guez2018(this);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
QMessageBox::critical(this, QString(), QStringLiteral("Ui implementation missing for this project - aborting."));
|
||||
QCoreApplication::quit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_cbMainScreen = findChild<QCheckBox *>(QStringLiteral("cbMainScreen"));
|
||||
|
||||
if (m_cbMainScreen == nullptr)
|
||||
{
|
||||
qWarning() << "Developer: there is no ui element 'cbMainScreen' !";
|
||||
QCoreApplication::quit();
|
||||
return;
|
||||
}
|
||||
|
||||
m_screensToTest = QGuiApplication::screens();
|
||||
|
||||
QList<QPushButton *> screenButtons = findChildren<QPushButton *>();
|
||||
|
||||
for (auto i = screenButtons.constBegin(); i != screenButtons.constEnd(); ++i)
|
||||
{
|
||||
QPushButton *btn = *i;
|
||||
|
||||
btn->setStyleSheet(QStringLiteral("QPushButton:hover { padding: 4px; border: 1px solid; border-color: #009933; border-radius: 2px; background-color: #99ff99; outline: none; } "
|
||||
"QPushButton { padding: 4px; border: 1px solid; border-color: #66ff66; border-radius: 2px; background-color: #ccffcc; outline: none; } "
|
||||
"QPushButton:disabled { padding: 4px; border: 1px solid; border-color: #000000; border-radius: 2px; background-color: #b3b3b3; outline: none; }"));
|
||||
|
||||
connect(btn, &QPushButton::clicked,
|
||||
this, &Configurator::slotScreenClicked);
|
||||
}
|
||||
|
||||
|
||||
slotGo();
|
||||
}
|
||||
|
||||
|
||||
Configurator::~Configurator()
|
||||
{
|
||||
delete m_uiIfc;
|
||||
}
|
||||
|
||||
|
||||
void Configurator::slotScreenClicked()
|
||||
{
|
||||
//QMap<QString, QPoint> m_config;
|
||||
|
||||
QPushButton *screenButton = qobject_cast<QPushButton *>(sender());
|
||||
screenButton->setEnabled(false); // already selected now
|
||||
|
||||
if (m_cbMainScreen->isChecked())
|
||||
{
|
||||
m_mainScreen = m_currentScreen;
|
||||
m_cbMainScreen->setEnabled(false); // cannot set more than one main screen :)
|
||||
m_cbMainScreen->setChecked(false); // there is already the main screen
|
||||
}
|
||||
|
||||
m_config.insert(m_currentScreen->name(),
|
||||
QPoint(screenButton->property("screenX").toInt(),
|
||||
screenButton->property("screenY").toInt()));
|
||||
|
||||
slotGo(); // next !
|
||||
}
|
||||
|
||||
|
||||
void Configurator::slotGo()
|
||||
{
|
||||
if (m_screensToTest.isEmpty())
|
||||
{
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
m_currentScreen = m_screensToTest.takeFirst();
|
||||
setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, size(), m_currentScreen->availableGeometry()));
|
||||
}
|
||||
|
||||
|
||||
void Configurator::done()
|
||||
{
|
||||
hide();
|
||||
slotSave();
|
||||
}
|
||||
|
||||
|
||||
void Configurator::slotSave()
|
||||
{
|
||||
if (m_mainScreen == nullptr)
|
||||
{
|
||||
QMessageBox::critical(this, QString(), QStringLiteral("You did not specify the main screen - aborting."));
|
||||
QCoreApplication::quit();
|
||||
return;
|
||||
}
|
||||
|
||||
QFile f(QStringLiteral(":/%1.conf").arg(m_filename));
|
||||
|
||||
if (!f.open(QFile::ReadOnly))
|
||||
{
|
||||
QMessageBox::critical(this, QString(), QStringLiteral("Cannot open project template file from resources - aborting."));
|
||||
QCoreApplication::quit();
|
||||
return;
|
||||
}
|
||||
|
||||
QString config = QString::fromUtf8(f.readAll());
|
||||
|
||||
int index = projectNames().indexOf(m_filename);
|
||||
switch (index)
|
||||
{
|
||||
case 0: // guez2018
|
||||
{
|
||||
QStringList metamodes;
|
||||
|
||||
for (auto i = m_config.constBegin(); i != m_config.constEnd(); ++i)
|
||||
{
|
||||
const QString &interfaceName = i.key();
|
||||
const QPoint &screenPos = i.value();
|
||||
|
||||
metamodes.append(QStringLiteral("%1: nvidia-auto-select +%2+%3").arg(interfaceName).arg(screenPos.x()).arg(screenPos.y()));
|
||||
}
|
||||
|
||||
|
||||
config = config.arg(m_mainScreen->name(), metamodes.join(QStringLiteral(", ")));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
QMessageBox::critical(this, QString(), QStringLiteral("Save implementation missing for this project - aborting."));
|
||||
QCoreApplication::quit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString configFileName(QStringLiteral("/etc/X11/xorg.conf.d/50-nvidia.conf"));
|
||||
|
||||
if (QFile::remove(QStringLiteral("/etc/X11/xorg.conf")))
|
||||
qWarning() << "xorg.conf deleted as this file is non-sense..";
|
||||
|
||||
QFile configFile(configFileName);
|
||||
|
||||
if (!configFile.open(QFile::WriteOnly))
|
||||
{
|
||||
QMessageBox::critical(this, QString(), QStringLiteral("Cannot write to config file '%1'.\n%2.\nAborting.").arg(configFileName, configFile.errorString()));
|
||||
QCoreApplication::quit();
|
||||
return;
|
||||
}
|
||||
|
||||
configFile.write(config.toUtf8());
|
||||
|
||||
if (QMessageBox::question(this, QString(),
|
||||
QStringLiteral("Config file '%1' was successfully written.\nDo you want to restart the X server now?").arg(configFileName),
|
||||
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No) == QMessageBox::StandardButton::Yes)
|
||||
{
|
||||
QProcess::startDetached(QStringLiteral("systemctl restart display-manager"));
|
||||
}
|
||||
|
||||
QCoreApplication::quit(); // done!
|
||||
}
|
||||
|
||||
|
||||
void Configurator::closeEvent(QCloseEvent */*event*/)
|
||||
{
|
||||
QCoreApplication::quit();
|
||||
}
|
||||
Reference in new issue
Block a user