quill/usbms_splash.cpp

224 lines
8 KiB
C++
Raw Permalink Normal View History

2021-03-25 05:00:19 -07:00
#include "usbms_splash.h"
#include "ui_usbms_splash.h"
#include <QPixmap>
#include <QScreen>
#include <QTimer>
2021-03-25 05:00:19 -07:00
#include "functions.h"
2021-03-25 05:00:19 -07:00
usbms_splash::usbms_splash(QWidget *parent) :
QWidget(parent),
ui(new Ui::usbms_splash)
{
ui->setupUi(this);
usbms_splash::setFont(QFont("u001"));
ui->label->setFont(QFont("Inter"));
2021-03-25 05:00:19 -07:00
// Getting the screen's size
sW = QGuiApplication::screens()[0]->size().width();
sH = QGuiApplication::screens()[0]->size().height();
2021-03-29 05:14:15 -07:00
// Defining what the default icon size will be
if(global::kobox::showKoboxSplash == true) {
float stdIconWidth = sW / 1.30;
float stdIconHeight = sH / 1.30;
// Stylesheet
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();
ui->label->setFont(QFont("Inter"));
ui->label->setText("Launching KoBox subsystem");
ui->label->setStyleSheet("font-size: 14pt; font-weight: bold");
ui->label_3->setText("Please wait, this could take a while.");
2022-05-22 12:38:02 -07:00
if(global::deviceID == "n905\n" or global::deviceID == "kt\n") {
2021-05-14 20:44:59 -07:00
ui->label_3->setStyleSheet("font-size: 11pt");
}
else {
ui->label_3->setStyleSheet("font-size: 10pt");
}
QPixmap pixmap(":/resources/kobox-icon.png");
QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
ui->label_2->setPixmap(scaledPixmap);
}
else {
float stdIconWidth = sW / 1.15;
float stdIconHeight = sH / 1.15;
this->setStyleSheet("background-color:black;");
ui->label->setStyleSheet("QLabel { background-color : black; color : white; font-size: 15pt; font-weight: bold }");
ui->label_3->setStyleSheet("QLabel { background-color : black; color : white; font-size: 10pt }");
2021-03-25 05:00:19 -07:00
QPixmap pixmap(":/resources/usbms.png");
QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
ui->label_2->setPixmap(scaledPixmap);
}
if(global::usbms::launchUsbms == true) {
global::usbms::launchUsbms = false;
usbms_launch();
}
}
void usbms_splash::usbms_launch()
{
log("Entering USBMS session", className);
string_writeconfig("/tmp/in_usbms", "true");
2021-06-29 12:28:54 -07:00
QTimer::singleShot(1500, this, SLOT(brightnessDown()));
2021-05-13 18:40:05 -07:00
if(global::usbms::koboxExportExtensions == true) {
2021-09-26 13:46:25 -07:00
string_writeconfig("/opt/ibxd", "kobox_extensions_storage_unmount\n");
2021-05-13 18:40:05 -07:00
}
if(checkconfig("/external_root/run/encfs_mounted") == true) {
string_writeconfig("/external_root/run/encfs_stop_cleanup", "true");
string_writeconfig("/opt/ibxd", "encfs_stop\n");
QThread::msleep(1500);
2021-05-13 18:40:05 -07:00
}
string_writeconfig("/opt/ibxd", "onboard_unmount\n");
2021-09-26 13:46:25 -07:00
QThread::msleep(500);
string_writeconfig("/opt/ibxd", "usbnet_stop\n");
2021-09-26 19:05:45 -07:00
QThread::msleep(1000);
2022-06-18 06:26:52 -07:00
string_writeconfig("/opt/ibxd", "gui_apps_stop\n");
QThread::msleep(1000);
if(global::deviceID == "n306\n" or global::deviceID == "n873\n") {
2022-05-23 12:24:21 -07:00
QProcess::execute("insmod", QStringList() << "/external_root/lib/modules/fs/configfs/configfs.ko");
QProcess::execute("insmod", QStringList() << "/external_root/lib/modules/drivers/usb/gadget/libcomposite.ko");
QProcess::execute("insmod", QStringList() << "/external_root/lib/modules/drivers/usb/gadget/function/usb_f_mass_storage.ko");
}
else if(global::deviceID == "kt\n") {
QProcess::execute("insmod", QStringList() << "/external_root/lib/modules/2.6.35-inkbox/kernel/drivers/usb/gadget/arcotg_udc.ko");
2022-03-06 10:37:01 -08:00
}
QString prog_1 ("insmod");
QStringList args_1;
2021-05-13 18:40:05 -07:00
2022-05-23 12:24:21 -07:00
if(global::deviceID == "kt\n") {
massStorageModule = "/external_root/lib/modules/2.6.35-inkbox/kernel/drivers/usb/gadget/g_file_storage.ko";
}
else {
massStorageModule = "/external_root/lib/modules/g_mass_storage.ko";
}
2021-05-13 18:40:05 -07:00
if(global::usbms::koboxExportExtensions == true) {
2022-05-23 12:24:21 -07:00
args_1 << massStorageModule << "file=/external_root/opt/storage/X11/extensions-user.img" << "removable=y" << "stall=0";
2021-05-13 18:40:05 -07:00
}
else {
2022-05-23 12:24:21 -07:00
args_1 << massStorageModule << "file=/external_root/opt/storage/onboard" << "removable=y" << "stall=0";
2021-05-13 18:40:05 -07:00
}
QProcess *proc_1 = new QProcess();
proc_1->start(prog_1, args_1);
proc_1->waitForFinished();
2021-08-29 12:05:07 -07:00
proc_1->deleteLater();
bool exitUsbMsDone = false;
QTimer *usbms_t = new QTimer(this);
usbms_t->setInterval(1000);
connect(usbms_t, &QTimer::timeout, [&]() {
if(exitUsbMsDone == false) {
2022-05-23 12:24:21 -07:00
if(isUsbPluggedIn() == 0) {
if(global::usbms::koboxExportExtensions == true) {
reboot(false);
qApp->quit();
}
else {
log("Exiting USBMS session", className);
// '<font/>' bit: because nothing else works ...
ui->label->setText("<font face='Inter'>Processing content</font>");
ui->label->setFont(QFont("Inter"));
ui->label_3->setText("Please wait");
ui->label_3->setFont(QFont("u001"));
ui->label->setStyleSheet("QLabel { background-color : black; color : white; font-size: 15pt; font-weight: bold }");
ui->label_3->setStyleSheet("QLabel { background-color : black; color : white; font-size: 11pt }");
ui->label->setFont(QFont("u001"));
2022-02-13 14:23:54 -08:00
float stdIconWidth = sW / 2;
float stdIconHeight = sH / 2;
QPixmap pixmap(":/resources/clock-inverted.png");
QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
ui->label_2->setPixmap(scaledPixmap);
this->repaint();
QString prog("rmmod");
QStringList args;
2022-05-23 12:24:21 -07:00
args << massStorageModule;
QProcess * proc = new QProcess();
proc->start(prog, args);
proc->waitForFinished();
proc->deleteLater();
QTimer::singleShot(500, this, SLOT(restartServices()));
}
exitUsbMsDone = true;
2021-09-26 13:46:25 -07:00
}
else {
;
2021-09-26 13:46:25 -07:00
}
}
} );
usbms_t->start();
2021-03-25 05:00:19 -07:00
}
usbms_splash::~usbms_splash()
{
delete ui;
}
2021-06-29 12:28:54 -07:00
void usbms_splash::brightnessDown() {
cinematicBrightness(0, 1);
}
2021-09-26 13:46:25 -07:00
void usbms_splash::quit_restart() {
// If existing, cleaning bookconfig_mount mountpoint
string_writeconfig("/opt/ibxd", "bookconfig_unmount\n");
// Restarting InkBox
QProcess process;
process.startDetached("inkbox", QStringList());
qApp->quit();
}
void usbms_splash::restartServices() {
// Restarting USBNet
// NOTE: USBNet is only started if required conditions are met (see https://github.com/Kobo-InkBox/rootfs/blob/master/etc/init.d/usbnet)
string_writeconfig("/opt/ibxd", "usbnet_start\n");
QThread::msleep(1000);
// Mounting onboard storage
string_writeconfig("/opt/ibxd", "onboard_mount\n");
QThread::msleep(1000);
// Checking for updates
string_writeconfig("/opt/ibxd", "update_inkbox_restart\n");
QThread::msleep(2500);
string_writeconfig("/tmp/in_usbms", "false");
2022-06-18 06:26:52 -07:00
// GUI apps: update main JSON file
string_writeconfig("/opt/ibxd", "gui_apps_start\n");
while(true) {
if(QFile::exists("/tmp/gui_apps_started")) {
if(checkconfig("/tmp/gui_apps_started") == true) {
QFile::remove("/tmp/gui_apps_started");
updateUserAppsMainJsonFile();
break;
}
else {
log("GUI apps service failed to start", className);
QFile::remove("/tmp/gui_apps_started");
break;
}
}
}
2022-06-27 15:14:20 -07:00
// Re-generate local library on next launch
QFile::remove(global::localLibrary::databasePath);
quit_restart();
}