2022-01-20 15:04:17 +08:00
|
|
|
#include "ukui-search-gui.h"
|
|
|
|
#include <QScreen>
|
|
|
|
#include <QTranslator>
|
|
|
|
#include <QLocale>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QCommandLineParser>
|
|
|
|
#include "plugin-manager.h"
|
|
|
|
#include "search-plugin-manager.h"
|
|
|
|
#include "document.h"
|
|
|
|
|
|
|
|
using namespace UkuiSearch;
|
|
|
|
UkuiSearchGui::UkuiSearchGui(int &argc, char *argv[], const QString &applicationName): QtSingleApplication (applicationName, argc, argv)
|
|
|
|
{
|
|
|
|
qDebug()<<"ukui search gui constructor start" << applicationName;
|
|
|
|
setApplicationVersion(QString("v%1").arg(VERSION));
|
|
|
|
if (!this->isRunning()) {
|
|
|
|
connect(this, &QtSingleApplication::messageReceived, [=](QString msg) {
|
|
|
|
this->parseCmd(msg, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
setQuitOnLastWindowClosed(false);
|
|
|
|
|
|
|
|
// qRegisterMetaType<QPair<QString, QStringList>>("QPair<QString,QStringList>");
|
|
|
|
// qRegisterMetaType<UkuiSearch::Document>("Document");
|
|
|
|
|
|
|
|
|
|
|
|
//load translations.
|
2022-05-23 15:48:16 +08:00
|
|
|
QTranslator *translator = new QTranslator(this);
|
2022-01-20 15:04:17 +08:00
|
|
|
try {
|
2022-05-23 15:48:16 +08:00
|
|
|
if(! translator->load("/usr/share/ukui-search/translations/" + QLocale::system().name())) throw - 1;
|
|
|
|
this->installTranslator(translator);
|
2022-01-20 15:04:17 +08:00
|
|
|
} catch(...) {
|
|
|
|
qDebug() << "Load translations file" << QLocale() << "failed!";
|
|
|
|
}
|
|
|
|
|
2022-05-23 15:48:16 +08:00
|
|
|
QTranslator *qt_translator = new QTranslator(this);
|
2022-01-20 15:04:17 +08:00
|
|
|
try {
|
2022-07-18 16:34:26 +08:00
|
|
|
if(! qt_translator->load("/usr/share/qt5/translations/qt_" + QLocale::system().name())) throw - 1;
|
2022-05-23 15:48:16 +08:00
|
|
|
this->installTranslator(qt_translator);
|
2022-01-20 15:04:17 +08:00
|
|
|
} catch(...) {
|
|
|
|
qDebug() << "Load translations file" << QLocale() << "failed!";
|
|
|
|
}
|
|
|
|
|
2022-05-23 15:48:16 +08:00
|
|
|
QTranslator *lib_translator = new QTranslator(this);
|
2022-01-20 15:04:17 +08:00
|
|
|
try {
|
2022-05-23 15:48:16 +08:00
|
|
|
if(! lib_translator->load("/usr/share/ukui-search/translations/libukui-search_" + QLocale::system().name())) throw - 1;
|
|
|
|
this->installTranslator(lib_translator);
|
2022-01-20 15:04:17 +08:00
|
|
|
} catch(...) {
|
|
|
|
qDebug() << "Load translations file" << QLocale() << "failed!";
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "Loading plugins and resources...";
|
|
|
|
SearchPluginManager::getInstance();
|
|
|
|
PluginManager::getInstance();
|
|
|
|
|
|
|
|
m_mainWindow = new UkuiSearch::MainWindow();
|
|
|
|
m_dbusService = new UkuiSearch::UkuiSearchDbusServices(m_mainWindow);
|
|
|
|
qApp->setWindowIcon(QIcon::fromTheme("kylin-search"));
|
|
|
|
this->setActivationWindow(m_mainWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
//parse cmd
|
|
|
|
qDebug()<<"parse cmd";
|
|
|
|
auto message = this->arguments().join(' ').toUtf8();
|
|
|
|
parseCmd(message, !isRunning());
|
|
|
|
|
|
|
|
qDebug()<<"ukui search gui constructor end";
|
|
|
|
}
|
|
|
|
|
|
|
|
UkuiSearchGui::~UkuiSearchGui()
|
|
|
|
{
|
|
|
|
if(m_mainWindow) {
|
|
|
|
delete m_mainWindow;
|
|
|
|
m_mainWindow = nullptr;
|
|
|
|
}
|
|
|
|
if(m_dbusService) {
|
|
|
|
delete m_dbusService;
|
|
|
|
m_dbusService = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchGui::parseCmd(QString msg, bool isPrimary)
|
|
|
|
{
|
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.addHelpOption();
|
|
|
|
parser.addVersionOption();
|
|
|
|
|
2022-11-22 10:17:36 +08:00
|
|
|
QCommandLineOption quitOption(QStringList{"q","quit"}, tr("Quit ukui-search application"));
|
2022-01-20 15:04:17 +08:00
|
|
|
parser.addOption(quitOption);
|
|
|
|
|
2022-11-22 10:17:36 +08:00
|
|
|
QCommandLineOption showOption(QStringList{"s","show"}, tr("Show main window"));
|
2022-01-20 15:04:17 +08:00
|
|
|
parser.addOption(showOption);
|
|
|
|
|
2022-11-22 10:17:36 +08:00
|
|
|
QCommandLineOption unregisterOption("unregister", tr("unregister a plugin with <pluginName>"), "pluginName");
|
|
|
|
parser.addOption(unregisterOption);
|
|
|
|
|
|
|
|
QCommandLineOption registerOption("register", tr("register a plugin with <pluginName>"), "pluginName");
|
|
|
|
parser.addOption(registerOption);
|
|
|
|
|
|
|
|
QCommandLineOption moveOption(QStringList{"m", "move"}, tr("move <pluginName> to the target pos"), "pluginName");
|
|
|
|
parser.addOption(moveOption);
|
|
|
|
|
|
|
|
QCommandLineOption indexOption(QStringList{"i", "index"}, tr("move plugin to <index>"), "index");
|
|
|
|
parser.addOption(indexOption);
|
|
|
|
|
2022-01-20 15:04:17 +08:00
|
|
|
if (isPrimary) {
|
|
|
|
const QStringList args = QString(msg).split(' ');
|
|
|
|
parser.process(args);
|
|
|
|
if(parser.isSet(showOption)) {
|
|
|
|
m_mainWindow->bootOptionsFilter("-s");
|
|
|
|
}
|
|
|
|
if (parser.isSet(quitOption)) {
|
|
|
|
this->quit();
|
|
|
|
}
|
2022-11-22 10:17:36 +08:00
|
|
|
if (parser.isSet(unregisterOption)) {
|
|
|
|
QString pluginName = parser.value(unregisterOption);
|
|
|
|
qDebug() << "unregister plugin:" << pluginName << SearchPluginManager::getInstance()->unregisterPlugin(pluginName);
|
|
|
|
}
|
|
|
|
if (parser.isSet(registerOption)) {
|
|
|
|
qDebug() << parser.values("register");
|
|
|
|
QString pluginName = parser.value(registerOption);
|
|
|
|
|
|
|
|
qDebug() << "register plugin:" << pluginName << SearchPluginManager::getInstance()->reRegisterPlugin(pluginName);
|
|
|
|
}
|
|
|
|
if (parser.isSet(moveOption) and parser.isSet(indexOption)) {
|
|
|
|
QString pluginName = parser.value(moveOption);
|
|
|
|
int pos = parser.value(indexOption).toInt();
|
|
|
|
qDebug() << QString("move plugin:%1 to %2").arg(pluginName).arg(pos) << SearchPluginManager::getInstance()->changePluginPos(pluginName, pos);
|
|
|
|
}
|
2022-01-20 15:04:17 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (arguments().count() < 2) {
|
|
|
|
parser.showHelp();
|
|
|
|
}
|
|
|
|
parser.process(arguments());
|
|
|
|
sendMessage(msg);
|
|
|
|
}
|
|
|
|
}
|