Experimenting with plugin and main app communication.

This commit is contained in:
2025-11-23 02:18:24 +00:00
parent b874491d9c
commit 42828b368d
14 changed files with 137 additions and 6 deletions

View File

@@ -332,3 +332,9 @@ void CalculatorPlugin::multiplicativeOperatorClicked()
pendingMultiplicativeOperator = clickedOperator;
waitingForOperand = true;
}
void CalculatorPlugin::connectToHost(QObject* host)
{
Q_UNUSED(host);
// Calculator plugin doesn't need host signals
}

View File

@@ -27,6 +27,8 @@ public:
QString pname() override;
QString pdesc() override;
QWidget *pcontent() override;
void connectToHost(QObject* host) override;
private:
QLineEdit *display;
enum { NumDigitButtons = 10 };

View File

@@ -112,6 +112,7 @@ void FileExplorerPlugin::onDirSelected(const QModelIndex &index) {
// Show contents of selected dir on the right
QModelIndex fileRoot = fileModel->setRootPath(path);
fileList->setRootIndex(fileRoot);
emit fileSelected(path);
}
// ---------- Double-click / activate on file: open editor for text files ----------
@@ -127,8 +128,9 @@ void FileExplorerPlugin::onFileActivated(const QModelIndex &index) {
return;
}
// Try to open text files in simple editor; binary files will fail to load as text
editFile(path);
//editFile(path);
}
// ---------- Context menu: right pane (files + folders) ----------
@@ -391,3 +393,9 @@ void FileExplorerPlugin::editFile(const QString &path) {
fileList->setRootIndex(fileModel->index(cur));
}
}
void FileExplorerPlugin::connectToHost(QObject* host)
{
Q_UNUSED(host);
// Calculator plugin doesn't need host signals
}

View File

@@ -23,6 +23,8 @@ public:
QString pname() override;
QString pdesc() override;
QWidget *pcontent() override;
void connectToHost(QObject* host) override;
private slots:
void onDirSelected(const QModelIndex &index);
@@ -51,6 +53,9 @@ private:
void editFile(const QString &path);
bool removePath(const QString &path);
bool renamePath(const QString &oldPath, const QString &newName);
signals:
void fileSelected(const QString& path);
};
#endif

View File

@@ -267,3 +267,9 @@ void IrcClientPlugin::append(const QString &line)
{
msgs->append(line);
}
void IrcClientPlugin::connectToHost(QObject* host)
{
Q_UNUSED(host);
// Calculator plugin doesn't need host signals
}

View File

@@ -30,6 +30,8 @@ public:
QString pname() override;
QString pdesc() override;
QWidget *pcontent() override;
void connectToHost(QObject* host) override;
private:
void append(const QString& line);

View File

@@ -155,3 +155,9 @@ void ScreenShotPlugin::updateceheck()
hideThisWindowCheckBox->setDisabled(false);
}
}
void ScreenShotPlugin::connectToHost(QObject* host)
{
Q_UNUSED(host);
// Calculator plugin doesn't need host signals
}

View File

@@ -27,6 +27,8 @@ public:
QString pname() override;
QString pdesc() override;
QWidget *pcontent() override ;
void connectToHost(QObject* host) override;
public slots:
void updateceheck();

View File

@@ -20,8 +20,10 @@ QWidget* TerminalPlugin::pcontent()
QWidget *test = new QWidget();
QVBoxLayout *mainLayout = new QVBoxLayout;
chdir(path.toUtf8().constData());
console = new QTermWidget(test);
QFont font = QApplication::font();
font.setFamily("Monospace");
font.setPointSize(12);
@@ -31,6 +33,7 @@ QWidget* TerminalPlugin::pcontent()
console->setColorScheme("WhiteOnBlack");
console->setContextMenuPolicy(Qt::CustomContextMenu);
connect(console, &QWidget::customContextMenuRequested, this, [=](const QPoint &pos) {
QMenu menu;
@@ -57,6 +60,7 @@ QWidget* TerminalPlugin::pcontent()
menu.exec(globalPos);
});
test->setWindowTitle(tr("Terminal Plugin"));
test->resize(600, 400);
mainLayout->addWidget(console);
@@ -64,3 +68,18 @@ QWidget* TerminalPlugin::pcontent()
return test;
}
void TerminalPlugin::connectToHost(QObject* host)
{
connect(host, SIGNAL(currentPathChanged(QString)),
this, SLOT(onHostPathChanged(QString)));
}
void TerminalPlugin::onHostPathChanged(const QString &newpath)
{
path = newpath;
QMessageBox::about(pcontent(), tr("About Terminal"),
tr(newpath.toUtf8().constData()));
}

View File

@@ -4,12 +4,14 @@
#include <../../src/interface.h>
#include <qtermwidget6/qtermwidget.h>
#include <unistd.h>
#include <QObject>
#include <QtPlugin>
#include <QString>
#include <QWidget>
#include <QImage>
#include <QMessageBox>
class TerminalPlugin : public QObject, public Interface
{
@@ -21,9 +23,15 @@ public:
QString pname() override;
QString pdesc() override;
QWidget *pcontent() override;
void connectToHost(QObject* host) override;
private:
QTermWidget *console;
QString path;
private slots:
void onHostPathChanged(const QString &newpath);
};
#endif

View File

@@ -76,3 +76,9 @@ void WebBrowserPlugin::forwardpage()
{
view->forward();
}
void WebBrowserPlugin::connectToHost(QObject* host)
{
Q_UNUSED(host);
// Calculator plugin doesn't need host signals
}

View File

@@ -16,6 +16,8 @@ public:
QString pname() override;
QString pdesc() override;
QWidget *pcontent() override;
void connectToHost(QObject* host) override;
private:
QGroupBox *horizontalGroupBox;

View File

@@ -28,7 +28,7 @@ void MainWindow::createActions()
connect(exitAct, &QAction::triggered, this, &QWidget::close);
settingsAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::WeatherSnow),
tr("&Settings"), this);
tr("&Settings"), this);
connect(settingsAct, &QAction::triggered, this, &MainWindow::settings);
aboutAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::HelpAbout),
@@ -36,7 +36,7 @@ void MainWindow::createActions()
connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
aboutQtAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::HelpAbout),
tr("About &Qt"), this);
tr("About &Qt"), this);
connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
}
@@ -63,15 +63,18 @@ void MainWindow::about()
void MainWindow::initSettings()
{
QSettings settings("SOM", "SOM");
QSettings settings("som", "som");
if (!settings.contains("window/geometry")) {
this->resize(QSize(800, 600));
this->move(this->screen()->geometry().center() - this->frameGeometry().center());
settings.setValue("window/geometry", this->saveGeometry());
projdir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/som-projects";
settings.setValue("window/projdir", this->projdir);
settings.sync();
}
this->restoreGeometry(settings.value("window/geometry").toByteArray());
this->projdir = settings.value("window/projdir").toString();
settings.beginGroup("Plugins");
for (const QString &group : settings.childGroups()) {
@@ -111,7 +114,7 @@ void MainWindow::initSettings()
void MainWindow::saveSettings()
{
QSettings settings("SOM", "SOM");
QSettings settings("som", "som");
settings.setValue("window/geometry", this->saveGeometry());
settings.beginGroup("Plugins");
@@ -141,9 +144,41 @@ void MainWindow::settings()
QWidget *settingsWin = new QWidget();
settingsWin->setWindowTitle("Settings");
settingsWin->resize(300, 200);
QVBoxLayout *layout = new QVBoxLayout(settingsWin);
QLabel *dirLabel = new QLabel(projdir, settingsWin);
layout->addWidget(dirLabel);
QPushButton *browseButton = new QPushButton("Browse...", settingsWin);
layout->addWidget(browseButton);
// Connect the button to open the directory dialog
connect(browseButton, &QPushButton::clicked, this,
[this, dirLabel, settingsWin]() {
QString selectedDir = QFileDialog::getExistingDirectory(
this,
tr("Select Directory"),
projdir,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
);
if (!selectedDir.isEmpty()) {
dirLabel->setText(selectedDir);
QSettings settings("som", "som");
settings.setValue("window/projdir", selectedDir);
settingsWin->close(); // Close the settings window
}
});
settingsWin->setLayout(layout);
settingsWin->show();
}
void MainWindow::loadPlugins()
{
#if DEV_BUILD
@@ -160,6 +195,15 @@ void MainWindow::loadPlugins()
QObject *plugin = loader.instance();
if (plugin) {
auto iPlugin = qobject_cast<Interface*>(plugin);
if (iPlugin) {
iPlugin->connectToHost(this);
// *** NEW: connect plugin.signal → MainWindow.slot ***
connect(plugin, SIGNAL(fileSelected(QString)),
this, SLOT(fileSelected(QString)));
}
populateMenu(plugin);
}
}
@@ -195,9 +239,16 @@ void MainWindow::populateMenu(QObject *plugin)
}
void MainWindow::addToMenu(QObject *plugin, const QString &text,
QMenu *menu, Member member)
QMenu *menu, Member member)
{
auto action = new QAction(text, plugin);
connect(action, &QAction::triggered, this, member);
menu->addAction(action);
}
void MainWindow::fileSelected(const QString &path)
{
emit currentPathChanged(path);
QMessageBox::about(this, tr("About SOM"),
tr(path.toUtf8().constData()));
}

View File

@@ -43,14 +43,22 @@ private:
QAction *settingsAct;
QDir pluginsDir;
QMdiArea *mdi;
QString projdir;
private slots:
void about();
void settings();
void changePlugin();
public slots:
void fileSelected(const QString& path);
protected:
void closeEvent(QCloseEvent *event) override;
signals:
void currentPathChanged(const QString& path);
};
#endif // MAINWINDOW_H