commit dd8798121d7d334b6e3b3a9eb3d7419edc4f8228 Author: maelstrom Date: Wed May 14 21:53:38 2025 +0200 feat: basic run applet diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d5ce34d --- /dev/null +++ b/.gitignore @@ -0,0 +1,54 @@ +# C++ objects and libs +*.slo +*.lo +*.o +*.a +*.la +*.lai +*.so +*.so.* +*.dll +*.dylib + +# Qt-es +object_script.*.Release +object_script.*.Debug +*_plugin_import.cpp +/.qmake.cache +/.qmake.stash +*.pro.user +*.pro.user.* +*.qbs.user +*.qbs.user.* +*.moc +moc_*.cpp +moc_*.h +qrc_*.cpp +ui_*.h +*.qmlc +*.jsc +Makefile* +*build-* +*.qm +*.prl + +# Qt unit tests +target_wrapper.* + +# QtCreator +*.autosave + +# QtCreator Qml +*.qmlproject.user +*.qmlproject.user.* + +# QtCreator CMake +CMakeLists.txt.user* + +# QtCreator 4.8< compilation database +compile_commands.json + +# QtCreator local machine specific files for imported projects +*creator.user* + +*_qmlcache.qrc \ No newline at end of file diff --git a/aero-applets.pro b/aero-applets.pro new file mode 100644 index 0000000..51eecfc --- /dev/null +++ b/aero-applets.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + run-applet diff --git a/run-applet/main.cpp b/run-applet/main.cpp new file mode 100644 index 0000000..92e2f05 --- /dev/null +++ b/run-applet/main.cpp @@ -0,0 +1,23 @@ +#include "runapplet.h" + +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + QTranslator translator; + const QStringList uiLanguages = QLocale::system().uiLanguages(); + for (const QString &locale : uiLanguages) { + const QString baseName = "run-applet_" + QLocale(locale).name(); + if (translator.load(":/i18n/" + baseName)) { + a.installTranslator(&translator); + break; + } + } + RunApplet w; + w.show(); + return a.exec(); +} diff --git a/run-applet/run-applet.pro b/run-applet/run-applet.pro new file mode 100644 index 0000000..86cbf6b --- /dev/null +++ b/run-applet/run-applet.pro @@ -0,0 +1,29 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++17 + +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + runapplet.cpp + +HEADERS += \ + runapplet.h + +FORMS += \ + runapplet.ui + +TRANSLATIONS += \ + run-applet_en_US.ts +CONFIG += lrelease +CONFIG += embed_translations + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/run-applet/run-applet_en_US.ts b/run-applet/run-applet_en_US.ts new file mode 100644 index 0000000..edd0d34 --- /dev/null +++ b/run-applet/run-applet_en_US.ts @@ -0,0 +1,3 @@ + + + diff --git a/run-applet/runapplet.cpp b/run-applet/runapplet.cpp new file mode 100644 index 0000000..02868f3 --- /dev/null +++ b/run-applet/runapplet.cpp @@ -0,0 +1,50 @@ +#include "runapplet.h" +#include "ui_runapplet.h" + +#include +#include +#include + +RunApplet::RunApplet(QWidget *parent) + : QDialog(parent) + , ui(new Ui::RunApplet) +{ + ui->setupUi(this); + + ui->label->setPixmap(QIcon::fromTheme("system-run-symbolic").pixmap(42, 42)); + // https://forum.qt.io/post/291563 + ui->cancelBtn->setIcon(style()->standardIcon(QStyle::SP_DialogCancelButton)); + ui->okBtn->setIcon(style()->standardIcon(QStyle::SP_DialogOkButton)); + ui->browseBtn->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton)); + + connect(ui->cancelBtn, &QPushButton::clicked, this, [&]() { + qApp->quit(); + }); + + connect(ui->okBtn, &QPushButton::clicked, this, &RunApplet::runApp); +} + +void RunApplet::runApp() { + QString command = ui->comboBox->currentText(); + QStringList args = command.split(" "); + QProcess *process = new QProcess; + process->setProgram(args[0]); + args.remove(0); + process->setArguments(args); + bool status = process->startDetached(); + + if (status) { + qApp->quit(); + } + + // QString errorMessage = process->errorString(); + + QMessageBox messageBox; + messageBox.critical(0, process->program(), QString(tr("Windows cannot find '%1'. Make sure you typed the name correctly, and then try again.")).arg(process->program())); + messageBox.setFixedSize(500,200); +} + +RunApplet::~RunApplet() +{ + delete ui; +} diff --git a/run-applet/runapplet.h b/run-applet/runapplet.h new file mode 100644 index 0000000..ed930bd --- /dev/null +++ b/run-applet/runapplet.h @@ -0,0 +1,25 @@ +#ifndef RUNAPPLET_H +#define RUNAPPLET_H + +#include + +QT_BEGIN_NAMESPACE +namespace Ui { +class RunApplet; +} +QT_END_NAMESPACE + +class RunApplet : public QDialog +{ + Q_OBJECT + +public: + RunApplet(QWidget *parent = nullptr); + ~RunApplet(); + +private: + Ui::RunApplet *ui; + + void runApp(); +}; +#endif // RUNAPPLET_H diff --git a/run-applet/runapplet.ui b/run-applet/runapplet.ui new file mode 100644 index 0000000..e8ddb03 --- /dev/null +++ b/run-applet/runapplet.ui @@ -0,0 +1,119 @@ + + + RunApplet + + + + 0 + 0 + 400 + 175 + + + + RunApplet + + + + + 12 + 21 + 38 + 38 + + + + + + + + + + 63 + 21 + 320 + 42 + + + + Type the name of a program, folder, document, or Internet resource, and Windows will open it for you. + + + true + + + + + + 12 + 73 + 49 + 19 + + + + Open: + + + + + + 63 + 70 + 322 + 27 + + + + Qt::FocusPolicy::StrongFocus + + + true + + + + + + 300 + 132 + 88 + 34 + + + + &Browse... + + + + + + 204 + 132 + 88 + 34 + + + + Cancel + + + + + + 109 + 132 + 88 + 34 + + + + OK + + + true + + + + + +