quill/koboxappsdialog.cpp

185 lines
6.3 KiB
C++
Raw Permalink Normal View History

#include "koboxappsdialog.h"
#include "ui_koboxappsdialog.h"
#include "functions.h"
#include <QStringListModel>
#include <QScreen>
#include <QFontDatabase>
#include <QMessageBox>
#include <QDir>
#include <QDebug>
koboxAppsDialog::koboxAppsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::koboxAppsDialog)
{
ui->setupUi(this);
ui->appsList->setFont(QFont("u001"));
// Preventing outside interaction
this->setModal(true);
// Stylesheet, style & misc.
2022-04-03 20:26:15 -07:00
QFile stylesheetFile("/mnt/onboard/.adds/inkbox/eink.qss");
stylesheetFile.open(QFile::ReadOnly);
this->setStyleSheet(stylesheetFile.readAll());
stylesheetFile.close();
if(global::deviceID == "n705\n") {
// If we don't do this, the text will clip out of the display.
ui->definitionLabel->setText("Please select an application.\nClick on 'Launch' to start it.");
}
ui->launchBtn->setProperty("type", "borderless");
ui->cancelBtn->setProperty("type", "borderless");
ui->launchBtn->setStyleSheet("font-size: 9pt; padding: 10px; font-weight: bold; background: lightGrey");
ui->cancelBtn->setStyleSheet("font-size: 9pt; padding: 10px; font-weight: bold; background: lightGrey");
ui->appsList->setStyleSheet("font-size: 9pt");
ui->headerLabel->setStyleSheet("font-weight: bold");
// UI fonts
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Regular.ttf");
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
QFont crimson(family);
ui->definitionLabel->setFont(QFont(crimson));
this->adjustSize();
// Centering dialog
QRect screenGeometry = QGuiApplication::screens()[0]->geometry();
int x = (screenGeometry.width() - this->width()) / 2;
int y = (screenGeometry.height() - this->height()) / 2;
this->move(x, y);
checkApps();
2022-07-17 23:40:32 -07:00
QStringListModel * model = new QStringListModel(this);
QStringList list = apps.split("\n", QString::SkipEmptyParts);
2021-04-30 19:26:59 -07:00
// Apps that aren't extensions
list.prepend("Geany");
2021-04-30 19:26:59 -07:00
if(checkconfig("/external_root/opt/root/rooted") == true) {
list.prepend("KTerm");
2021-04-30 19:26:59 -07:00
}
model->setStringList(list);
ui->appsList->setModel(model);
ui->appsList->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
void koboxAppsDialog::checkApps() {
QFile apps_list("/external_root/opt/X11/extensions_list");
apps_list.open(QIODevice::ReadWrite);
QTextStream in (&apps_list);
apps = in.readAll();
apps_list.close();
}
koboxAppsDialog::~koboxAppsDialog()
{
delete ui;
}
void koboxAppsDialog::on_cancelBtn_clicked()
{
koboxAppsDialog::close();
}
void koboxAppsDialog::on_launchBtn_clicked()
{
index = ui->appsList->currentIndex();
itemText = index.data(Qt::DisplayRole).toString();
if(itemText.isEmpty()) {
emit showToast("Please select an application");
}
else {
// DPI setting
string_checkconfig(".config/00-kobox/dpiSetting");
2021-04-30 19:26:59 -07:00
if(checkconfig_str_val == "") {
2022-05-22 12:38:02 -07:00
if(global::deviceID == "n705\n" or global::deviceID == "n905\n" or global::deviceID == "kt\n") {
2021-06-26 16:29:51 -07:00
dpiSetting = "125";
}
else if(global::deviceID == "n613\n" or global::deviceID == "n236\n" or global::deviceID == "n306\n") {
2021-06-26 16:29:51 -07:00
dpiSetting = "175";
}
else if(global::deviceID == "n437\n") {
2022-02-06 19:49:06 -08:00
dpiSetting = "225";
}
else if(global::deviceID == "n873\n") {
dpiSetting = "250";
}
2021-06-26 16:29:51 -07:00
else {
dpiSetting = "125";
}
2021-04-30 19:26:59 -07:00
}
else {
dpiSetting = checkconfig_str_val.toStdString();
}
// Fullscreen or windowed (i3)
// Mostly windowed except for apps like KTerm which ship their own OSK
dpModeSetting = "windowed";
if(itemText == "Netsurf") {
2022-04-15 17:27:58 -07:00
log("Launching KoBox app: NetSurf", className);
// Bypass standard shell script launch shenanigans
string_writeconfig("/external_root/tmp/X_program", "!netsurf");
}
else if(itemText == "KTerm") {
2022-04-15 17:27:58 -07:00
log("Launching KoBox app: KTerm", className);
string_writeconfig("/external_root/tmp/X_program", "/usr/local/bin/kterm -l /usr/local/share/kterm/layouts/keyboard-kt.xml -k 1");
2021-04-30 19:26:59 -07:00
dpModeSetting = "fullscreen";
2022-05-22 12:38:02 -07:00
if(global::deviceID == "n705\n" or global::deviceID == "n905\n" or global::deviceID == "kt\n") {
2021-06-26 16:29:51 -07:00
dpiSetting = "175";
}
else if(global::deviceID == "n613\n" or global::deviceID == "n236\n" or global::deviceID == "n306\n") {
2021-06-26 16:29:51 -07:00
dpiSetting = "225";
2022-01-27 12:16:48 -08:00
}
else if(global::deviceID == "n437\n") {
2022-02-06 19:49:06 -08:00
dpiSetting = "275";
}
else if(global::deviceID == "n873\n") {
2021-07-11 20:48:11 -07:00
dpiSetting = "300";
}
2021-06-26 16:29:51 -07:00
else {
dpiSetting = "175";
}
}
else if(itemText == "Geany") {
2022-04-15 17:27:58 -07:00
log("Launching KoBox app: Geany", className);
string_writeconfig("/external_root/tmp/X_program", "geany");
}
else {
2022-04-15 17:27:58 -07:00
log("Launching KoBox app: " + itemText, className);
QString itemTextLower = itemText.toLower();
std::string app = itemTextLower.toStdString();
string_writeconfig("/external_root/tmp/X_program", app);
}
string_writeconfig("/external_root/tmp/X_dpmode", dpModeSetting);
string_writeconfig("/external_root/tmp/X_dpi", dpiSetting);
/* Wheeee! */
global::kobox::showKoboxSplash = true;
// Re-use USBMS splash window for KoBox splash, since it's pretty much the same layout
2022-06-07 14:03:28 -07:00
log("Showing KoBox splash", className);
usbmsSplashWindow = new usbms_splash();
usbmsSplashWindow->setAttribute(Qt::WA_DeleteOnClose);
usbmsSplashWindow->setGeometry(QRect(QPoint(0,0), screen()->geometry().size()));
usbmsSplashWindow->show();
QApplication::processEvents();
// Stop EncFS/Encrypted storage
if(checkconfig("/external_root/run/encfs_mounted") == true) {
string_writeconfig("/external_root/run/encfs_stop_cleanup", "true");
string_writeconfig("/opt/ibxd", "encfs_stop\n");
}
// Write to FIFO to start X11
2021-04-30 19:26:59 -07:00
string_writeconfig("/opt/ibxd", "x_start_gui\n");
}
}