Initial repo creation.
This commit is contained in:
+124
@@ -0,0 +1,124 @@
|
||||
#include "window.h"
|
||||
#include "interface/interface.h"
|
||||
#include "plugindialog.h"
|
||||
|
||||
Window::Window()
|
||||
{
|
||||
createActions();
|
||||
createTrayIcon();
|
||||
loadPlugins();
|
||||
setIcon();
|
||||
trayIcon->show();
|
||||
}
|
||||
|
||||
void Window::loadPlugins()
|
||||
{
|
||||
QString pluginPath = "";
|
||||
|
||||
#ifdef DEVMODE
|
||||
pluginPath = QCoreApplication::applicationDirPath() + "/plugins";
|
||||
#else
|
||||
pluginPath = "/usr/lib/ttk/plugins";
|
||||
#endif
|
||||
|
||||
pluginsDir = QDir(pluginPath);
|
||||
|
||||
const auto entryList = pluginsDir.entryList(QDir::Files);
|
||||
for (const QString &fileName : entryList) {
|
||||
|
||||
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
|
||||
QObject *plugin = loader.instance();
|
||||
if (plugin) {
|
||||
|
||||
populateMenu(plugin);
|
||||
pluginFileNames += fileName;
|
||||
}
|
||||
}
|
||||
addtrayactions();
|
||||
}
|
||||
|
||||
void Window::changePlugin()
|
||||
{
|
||||
auto action = qobject_cast<QAction *>(sender());
|
||||
if (!action)
|
||||
return;
|
||||
|
||||
auto iPlugin = qobject_cast<Interface *>(action->parent());
|
||||
if (!iPlugin)
|
||||
return;
|
||||
|
||||
QWidget* output = new QWidget();
|
||||
output = iPlugin->pcontent();
|
||||
output->show();
|
||||
}
|
||||
|
||||
void Window::populateMenu(QObject *plugin)
|
||||
{
|
||||
|
||||
auto iPlugin = qobject_cast<Interface *>(plugin);
|
||||
if (iPlugin)
|
||||
|
||||
addToMenu(plugin, iPlugin->pname(), trayIconMenu, &Window::changePlugin);
|
||||
}
|
||||
|
||||
void Window::addToMenu(QObject *plugin, const QString &text,
|
||||
QMenu *menu, Member member)
|
||||
{
|
||||
auto action = new QAction(text, plugin);
|
||||
connect(action, &QAction::triggered, this, member);
|
||||
menu->addAction(action);
|
||||
}
|
||||
|
||||
void Window::setIcon()
|
||||
{
|
||||
QIcon icon = QIcon(":/images/smile.png");
|
||||
setWindowIcon(icon);
|
||||
trayIcon->setIcon(icon);
|
||||
trayIcon->setToolTip("TTK");
|
||||
}
|
||||
|
||||
|
||||
void Window::createActions()
|
||||
{
|
||||
quitAction = new QAction(tr("&Quit"), this);
|
||||
connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
|
||||
|
||||
aboutAct = new QAction(tr("&About"), this);
|
||||
connect(aboutAct, &QAction::triggered, this, &Window::about);
|
||||
|
||||
aboutQtAct = new QAction(tr("About &Qt"), this);
|
||||
connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
|
||||
|
||||
aboutPluginsAct = new QAction(tr("About &Plugins"), this);
|
||||
connect(aboutPluginsAct, &QAction::triggered, this, &Window::aboutPlugins);
|
||||
}
|
||||
|
||||
void Window::about()
|
||||
{
|
||||
QMessageBox::about(this, tr("About TTK"),
|
||||
tr("This is a wierd handy thing."));
|
||||
}
|
||||
|
||||
|
||||
void Window::aboutPlugins()
|
||||
{
|
||||
PluginDialog dialog(pluginsDir.path(), pluginFileNames, this);
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void Window::addtrayactions()
|
||||
{
|
||||
trayIconMenu->addSeparator();
|
||||
trayIconMenu->addAction(aboutAct);
|
||||
trayIconMenu->addAction(aboutQtAct);
|
||||
trayIconMenu->addAction(aboutPluginsAct);
|
||||
trayIconMenu->addSeparator();
|
||||
trayIconMenu->addAction(quitAction);
|
||||
}
|
||||
|
||||
void Window::createTrayIcon()
|
||||
{
|
||||
trayIconMenu = new QMenu(this);
|
||||
trayIcon = new QSystemTrayIcon(this);
|
||||
trayIcon->setContextMenu(trayIconMenu);
|
||||
}
|
||||
Reference in New Issue
Block a user