theshell/main.cpp

230 lines
7.2 KiB
C++
Raw Normal View History

2016-02-17 17:24:00 +11:00
#include "mainwindow.h"
2016-03-17 19:46:40 +11:00
#include "background.h"
2016-03-29 17:42:24 +11:00
#include "loginsplash.h"
2016-05-29 17:03:52 +10:00
#include "segfaultdialog.h"
#include "globalfilter.h"
2016-06-16 20:53:49 +10:00
#include "dbusevents.h"
2016-08-20 16:26:35 +10:00
//#include "dbusmenuregistrar.h"
2016-06-11 17:07:36 +10:00
#include <nativeeventfilter.h>
2016-02-17 17:24:00 +11:00
#include <QApplication>
2016-03-17 19:46:40 +11:00
#include <QDesktopWidget>
#include <QProcess>
#include <QThread>
2016-03-29 17:42:24 +11:00
#include <QUrl>
#include <QMediaPlayer>
#include <QDebug>
#include <QSettings>
#include <QInputDialog>
2016-05-29 17:03:52 +10:00
#include <signal.h>
#include <unistd.h>
MainWindow* MainWin = NULL;
2016-06-11 17:07:36 +10:00
NativeEventFilter* NativeFilter = NULL;
2016-06-16 20:53:49 +10:00
DbusEvents* DBusEvents = NULL;
2016-05-29 17:03:52 +10:00
void catch_signal(int signal) {
SegfaultDialog* dialog;
if (signal == SIGSEGV) {
qDebug() << "SEGFAULT! Quitting now!";
dialog = new SegfaultDialog("SIGSEGV");
2016-07-01 14:01:19 +10:00
} else if (signal == SIGBUS) {
qDebug() << "SIGBUS! Quitting now!";
dialog = new SegfaultDialog("SIGBUS");
2016-07-01 14:01:19 +10:00
} else if (signal == SIGABRT) {
qDebug() << "SIGABRT! Quitting now!";
dialog = new SegfaultDialog("SIGABRT");
} else if (signal == SIGILL) {
qDebug() << "SIGILL! Quitting now!";
dialog = new SegfaultDialog("SIGILL");
}
2016-05-29 17:03:52 +10:00
if (MainWin != NULL) {
MainWin->close();
delete MainWin;
}
dialog->exec();
2016-07-01 14:01:19 +10:00
std::terminate();
2016-05-29 17:03:52 +10:00
}
2016-02-17 17:24:00 +11:00
int main(int argc, char *argv[])
{
2016-07-22 22:47:38 +10:00
signal(SIGSEGV, *catch_signal); //Catch SIGSEGV
signal(SIGBUS, *catch_signal); //Catch SIGBUS
signal(SIGABRT, *catch_signal); //Catch SIGABRT
signal(SIGILL, *catch_signal); //Catch SIGILL
2016-05-29 17:03:52 +10:00
2016-02-17 17:24:00 +11:00
QApplication a(argc, argv);
2016-03-17 19:46:40 +11:00
2016-03-29 17:42:24 +11:00
bool showSplash = true;
bool autoStart = true;
2016-07-22 22:47:38 +10:00
bool startKscreen = true;
2016-03-29 17:42:24 +11:00
QStringList args = a.arguments();
args.removeFirst();
for (QString arg : a.arguments()) {
if (arg == "--help" || arg == "-h") {
qDebug() << "theShell";
qDebug() << "Usage: theshell [OPTIONS]";
qDebug() << " -s, --no-splash-screen Don't show the splash screen";
qDebug() << " -a, --no-autostart Don't autostart executables";
2016-07-22 22:47:38 +10:00
qDebug() << " -k, --no-kscreen Don't autostart KScreen";
2016-03-29 17:42:24 +11:00
qDebug() << " -h, --help Show this help output";
return 0;
} else if (arg == "-s" || arg == "--no-splash-screen") {
showSplash = false;
} else if (arg == "-a" || arg == "--no-autostart") {
autoStart = false;
2016-07-22 22:47:38 +10:00
} else if (arg == "-k" || arg == "--no-kscreen") {
startKscreen = false;
2016-03-29 17:42:24 +11:00
}
}
a.setOrganizationName("theSuite");
a.setOrganizationDomain("");
a.setApplicationName("theShell");
QFile lockfile(QDir::home().absolutePath() + "/.theshell.lck");
if (lockfile.exists()) {
if (QMessageBox::warning(0, "theShell already running", "theShell seems to already be running. "
"Do you wish to start theShell anyway?",
QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
return 0;
}
}
lockfile.open(QFile::WriteOnly);
lockfile.write(QByteArray());
lockfile.close();
2016-07-22 22:47:38 +10:00
if (startKscreen) {
QDBusMessage kscreen = QDBusMessage::createMethodCall("org.kde.kded5", "/kded", "org.kde.kded5", "loadModule");
QVariantList args;
args.append("kscreen");
kscreen.setArguments(args);
QDBusConnection::sessionBus().call(kscreen);
}
2016-08-20 16:26:35 +10:00
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.registerService("org.thesuite.theshell");
QProcess polkitProcess;
polkitProcess.start("/usr/lib/ts-polkitagent");
2016-08-20 16:26:35 +10:00
QProcess btProcess;
btProcess.start("ts-bt");
btProcess.waitForStarted();
2016-06-11 17:07:36 +10:00
NativeFilter = new NativeEventFilter();
a.installNativeEventFilter(NativeFilter);
2016-08-20 16:26:35 +10:00
MainWin = new MainWindow();
new GlobalFilter(&a);
2016-06-16 20:53:49 +10:00
DBusEvents = new DbusEvents();
//new DBusMenuRegistrar();
2016-06-28 16:48:19 +10:00
qDBusRegisterMetaType<QList<QVariantMap>>();
2016-06-24 15:53:02 +10:00
qDBusRegisterMetaType<QMap<QString, QVariantMap>>();
2016-03-29 17:42:24 +11:00
QSettings settings;
2016-07-01 14:01:19 +10:00
QString windowManager = settings.value("startup/WindowManagerCommand", "kwin_x11").toString();
2016-03-29 17:42:24 +11:00
if (autoStart) {
QStringList autostartApps = settings.value("startup/autostart", "").toString().split(",");
for (QString app : autostartApps) {
QProcess::startDetached(app);
}
}
while (!QProcess::startDetached(windowManager)) {
windowManager = QInputDialog::getText(0, "Window Manager couldn't start",
"The window manager \"" + windowManager + "\" could not start. \n\n"
"Enter the name or path of a window manager to attempt to start a different window"
"manager, or hit 'Cancel' to start theShell without a window manager.");
if (windowManager == "") {
break;
}
}
2016-03-29 17:42:24 +11:00
if (showSplash) {
LoginSplash* splash = new LoginSplash();
splash->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
splash->showFullScreen();
}
//QProcess* ksuperkey = new QProcess();
//ksuperkey->start("ksuperkey -d -e \"Super_L=Alt_L|F5;Alt_R|F5\"");
2016-03-17 19:46:40 +11:00
QRect screenGeometry = QApplication::desktop()->screenGeometry();
2016-03-17 19:46:40 +11:00
2016-05-29 17:03:52 +10:00
MainWin->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
MainWin->setGeometry(screenGeometry.x() - 1, screenGeometry.y(), screenGeometry.width() + 1, MainWin->height());
MainWin->show();
2016-02-17 17:24:00 +11:00
2016-03-17 19:46:40 +11:00
QThread::sleep(1);
2016-02-17 17:24:00 +11:00
return a.exec();
}
2016-03-29 17:42:24 +11:00
void playSound(QUrl location, bool uncompressed = false) {
if (uncompressed) {
QSoundEffect* sound = new QSoundEffect();
sound->setSource(location);
sound->play();
} else {
QMediaPlayer* sound = new QMediaPlayer();
sound->setMedia(location);
sound->play();
}
}
2016-05-29 17:03:52 +10:00
QIcon getIconFromTheme(QString name, QColor textColor) {
int averageCol = (textColor.red() + textColor.green() + textColor.blue()) / 3;
if (averageCol <= 127) {
return QIcon(":/icons/dark/images/dark/" + name);
} else {
return QIcon(":/icons/light/images/light/" + name);
}
}
void EndSession(EndSessionWait::shutdownType type) {
switch (type) {
case EndSessionWait::powerOff:
case EndSessionWait::reboot:
case EndSessionWait::logout:
case EndSessionWait::dummy:
{
EndSessionWait* w = new EndSessionWait(type);
w->showFullScreen();
QApplication::setOverrideCursor(Qt::BlankCursor);
}
break;
case EndSessionWait::suspend:
{
QList<QVariant> arguments;
arguments.append(true);
QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "Suspend");
message.setArguments(arguments);
QDBusConnection::systemBus().send(message);
}
break;
case EndSessionWait::hibernate:
{
QList<QVariant> arguments;
arguments.append(true);
QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "Hibernate");
message.setArguments(arguments);
QDBusConnection::systemBus().send(message);
}
break;
}
2016-05-29 17:03:52 +10:00
}