2021-04-29 20:36:25 -07:00
|
|
|
#include "koboxappsdialog.h"
|
|
|
|
#include "ui_koboxappsdialog.h"
|
|
|
|
|
|
|
|
#include "functions.h"
|
|
|
|
|
|
|
|
#include <QStringListModel>
|
|
|
|
#include <QScreen>
|
2021-04-30 09:49:33 -07:00
|
|
|
#include <QFontDatabase>
|
|
|
|
#include <QMessageBox>
|
2021-04-30 20:19:54 -07:00
|
|
|
#include <QDir>
|
|
|
|
#include <QDebug>
|
2021-04-29 20:36:25 -07:00
|
|
|
|
|
|
|
koboxAppsDialog::koboxAppsDialog(QWidget *parent) :
|
2021-04-30 09:49:33 -07:00
|
|
|
QDialog(parent),
|
2021-04-29 20:36:25 -07:00
|
|
|
ui(new Ui::koboxAppsDialog)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2022-03-02 21:40:11 -08:00
|
|
|
ui->appsList->setFont(QFont("u001"));
|
2021-04-29 20:36:25 -07:00
|
|
|
|
|
|
|
// Preventing outside interaction
|
2021-04-30 09:49:33 -07:00
|
|
|
this->setModal(true);
|
2021-04-29 20:36:25 -07:00
|
|
|
|
|
|
|
// Stylesheet, style & misc.
|
|
|
|
QFile stylesheetFile(":/resources/eink.qss");
|
|
|
|
stylesheetFile.open(QFile::ReadOnly);
|
|
|
|
this->setStyleSheet(stylesheetFile.readAll());
|
|
|
|
stylesheetFile.close();
|
|
|
|
|
2022-04-02 13:49:18 -07:00
|
|
|
if(global::deviceID == "n705\n") {
|
2021-05-09 15:06:14 -07:00
|
|
|
// 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.");
|
|
|
|
}
|
|
|
|
|
2021-04-29 20:36:25 -07:00
|
|
|
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");
|
2021-04-30 09:49:33 -07:00
|
|
|
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));
|
2021-04-29 20:36:25 -07:00
|
|
|
|
|
|
|
this->adjustSize();
|
2021-05-09 15:06:14 -07:00
|
|
|
|
2021-04-29 20:36:25 -07:00
|
|
|
// 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();
|
|
|
|
QStringListModel* model = new QStringListModel(this);
|
|
|
|
QStringList list = apps.split("\n", QString::SkipEmptyParts);
|
2021-04-30 19:26:59 -07:00
|
|
|
|
2021-05-09 11:07:05 -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) {
|
2021-04-30 20:19:54 -07:00
|
|
|
list.prepend("KTerm");
|
2021-04-30 19:26:59 -07:00
|
|
|
}
|
|
|
|
|
2021-04-29 20:36:25 -07:00
|
|
|
model->setStringList(list);
|
|
|
|
ui->appsList->setModel(model);
|
|
|
|
ui->appsList->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
}
|
|
|
|
|
|
|
|
void koboxAppsDialog::checkApps() {
|
2021-04-30 09:49:33 -07:00
|
|
|
QFile apps_list("/external_root/opt/X11/extensions_list");
|
2021-04-29 20:36:25 -07:00
|
|
|
apps_list.open(QIODevice::ReadWrite);
|
|
|
|
QTextStream in (&apps_list);
|
|
|
|
apps = in.readAll();
|
|
|
|
apps_list.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
koboxAppsDialog::~koboxAppsDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2021-04-30 09:49:33 -07:00
|
|
|
|
|
|
|
void koboxAppsDialog::on_cancelBtn_clicked()
|
|
|
|
{
|
|
|
|
koboxAppsDialog::close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void koboxAppsDialog::on_launchBtn_clicked()
|
|
|
|
{
|
|
|
|
index = ui->appsList->currentIndex();
|
|
|
|
itemText = index.data(Qt::DisplayRole).toString();
|
|
|
|
if(itemText == "") {
|
|
|
|
QMessageBox::critical(this, tr("Invalid argument"), tr("Please select an application."));
|
|
|
|
}
|
|
|
|
else {
|
2021-04-30 15:19:48 -07:00
|
|
|
// DPI setting
|
|
|
|
string_checkconfig(".config/00-kobox/dpiSetting");
|
2021-04-30 19:26:59 -07:00
|
|
|
if(checkconfig_str_val == "") {
|
2022-04-02 13:49:18 -07:00
|
|
|
if(global::deviceID == "n705\n" or global::deviceID == "n905\n") {
|
2021-06-26 16:29:51 -07:00
|
|
|
dpiSetting = "125";
|
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
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";
|
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
else if(global::deviceID == "n437\n") {
|
2022-02-06 19:49:06 -08:00
|
|
|
dpiSetting = "225";
|
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
else if(global::deviceID == "n873\n") {
|
2021-07-10 22:08:38 -07:00
|
|
|
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();
|
|
|
|
}
|
2021-04-30 15:19:48 -07:00
|
|
|
|
|
|
|
// Fullscreen or windowed (i3)
|
2021-05-13 17:42:50 -07:00
|
|
|
// Mostly windowed except for apps like KTerm which ship their own OSK
|
2021-04-30 15:19:48 -07:00
|
|
|
dpModeSetting = "windowed";
|
|
|
|
|
|
|
|
if(itemText == "Netsurf") {
|
|
|
|
// Bypass standard shell script launch shenanigans
|
|
|
|
string_writeconfig("/external_root/tmp/X_program", "!netsurf");
|
|
|
|
}
|
2021-04-30 20:19:54 -07:00
|
|
|
else if(itemText == "KTerm") {
|
2021-05-13 17:42:50 -07:00
|
|
|
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-04-02 13:49:18 -07:00
|
|
|
if(global::deviceID == "n705\n" or global::deviceID == "n905\n") {
|
2021-06-26 16:29:51 -07:00
|
|
|
dpiSetting = "175";
|
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
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
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
else if(global::deviceID == "n437\n") {
|
2022-02-06 19:49:06 -08:00
|
|
|
dpiSetting = "275";
|
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
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";
|
|
|
|
}
|
2021-04-30 15:19:48 -07:00
|
|
|
}
|
2021-05-09 11:07:05 -07:00
|
|
|
else if(itemText == "Geany") {
|
|
|
|
string_writeconfig("/external_root/tmp/X_program", "geany");
|
|
|
|
}
|
2021-04-30 15:19:48 -07:00
|
|
|
else {
|
|
|
|
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);
|
|
|
|
|
2021-05-13 17:42:50 -07:00
|
|
|
/* Wheeee! */
|
2021-04-30 20:55:38 -07:00
|
|
|
global::kobox::showKoboxSplash = true;
|
|
|
|
|
|
|
|
// Re-use USBMS splash window for KoBox splash, since it's pretty much the same layout
|
|
|
|
usbmsSplashWindow = new usbms_splash();
|
|
|
|
usbmsSplashWindow->setAttribute(Qt::WA_DeleteOnClose);
|
2022-02-20 12:11:00 -08:00
|
|
|
usbmsSplashWindow->setGeometry(QRect(QPoint(0,0), screen()->geometry().size()));
|
2021-04-30 20:55:38 -07:00
|
|
|
usbmsSplashWindow->show();
|
|
|
|
QApplication::processEvents();
|
|
|
|
|
2022-02-20 12:11:00 -08:00
|
|
|
// 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");
|
|
|
|
}
|
|
|
|
|
2021-05-13 17:42:50 -07:00
|
|
|
// Write to FIFO to start X11
|
2021-04-30 19:26:59 -07:00
|
|
|
string_writeconfig("/opt/ibxd", "x_start_gui\n");
|
2021-04-30 09:49:33 -07:00
|
|
|
}
|
|
|
|
}
|