Skip to content

Commit

Permalink
Move search to plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
neochapay committed Jul 17, 2024
1 parent 3c548e4 commit 8e4edd7
Show file tree
Hide file tree
Showing 21 changed files with 552 additions and 185 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ find_package(KF6BluezQt REQUIRED)
add_definitions(-DBLUEZQT_VERSION_MAJOR=${KF6BluezQt_VERSION_MAJOR})
add_definitions(-DBLUEZQT_VERSION_MINOR=${KF6BluezQt_VERSION_MINOR})

add_subdirectory(lib)
add_subdirectory(src)
add_subdirectory(settings-plugins)

Expand Down
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(search)
26 changes: 26 additions & 0 deletions lib/search/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
set(PROJECT glacierhomesearch)

set(SRC
searchpluginmanager.h
searchpluginmanager.cpp)

set(PUBLIC_HEADERS
glaciersearchplugin.h)

include_directories(${CMAKE_SOURCE_DIR}/src)

add_library(${PROJECT} SHARED ${SRC} ${HEADERS} ${PUBLIC_HEADERS})
add_library(GlacierHome::Search ALIAS ${PROJECT})

target_link_libraries(${PROJECT}
Qt6::Core)

set_target_properties(${PROJECT} PROPERTIES VERSION 0.1 SOVERSION 0)
add_definitions( -DINSTALL_LIBDIR="${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
add_subdirectory(plugins)

install(TARGETS ${PROJECT}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/)

install(FILES ${PUBLIC_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/glacier-home)
45 changes: 45 additions & 0 deletions lib/search/glaciersearchplugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2024 Chupligin Sergey <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#ifndef GLACIERSEARCHPLUGIN_H
#define GLACIERSEARCHPLUGIN_H

#include <QMap>
#include <QObject>
#include <QVariant>
#include <glacier_global.h>

class GLACIER_EXPORT GlacierSearchPlugin : public QObject {
Q_OBJECT
public:
struct SearchResult {
QString iconTitle;
QString iconSource;
QString category;
QString extraCaption;
QMap<QString, QVariant> action;
};

virtual void search(QString searchString) = 0;
signals:
void searchResultReady(QList<SearchResult> results);
};
Q_DECLARE_INTERFACE(GlacierSearchPlugin, "GlacierHome.SearchPlugin")

#endif // GLACIERSEARCHPLUGIN_H
1 change: 1 addition & 0 deletions lib/search/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(application)
19 changes: 19 additions & 0 deletions lib/search/plugins/application/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SET(PLUGINNAME application)

set(SRC ${PLUGINNAME}searchplugin.cpp)
SET(HEADERS ${PLUGINNAME}searchplugin.h)

include_directories(${CMAKE_SOURCE_DIR}/lib)
set(CMAKE_AUTOMOC ON)
add_definitions(-DQT_PLUGIN)

add_library(${PLUGINNAME} MODULE ${SRC} ${HEADERS})

target_link_libraries(${PLUGINNAME} PUBLIC
Qt6::Core
Qt6::DBus
GlacierHome::Search
PkgConfig::LIPSTICK)

install(TARGETS ${PLUGINNAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/glacier-home/plugins/search)
64 changes: 64 additions & 0 deletions lib/search/plugins/application/applicationsearchplugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2024 Chupligin Sergey <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#include "applicationsearchplugin.h"

ApplicationSearchPlugin::ApplicationSearchPlugin(QObject* parent)
: m_launchModel(new LauncherModel)
{
}

void ApplicationSearchPlugin::search(QString searchString)
{
m_searchResults.clear();

for (int i = 0; i < m_launchModel.itemCount(); i++) {
QObject* item = m_launchModel.get(i);
if (item->property("title").toString().toLower().indexOf(searchString) != -1
&& !item->property("isBlacklisted").toBool()) {
SearchResult result;
result.iconTitle = item->property("title").toString();

QString iconSource = item->property("iconId").toString();
if (iconSource.isEmpty()) {
iconSource = "/usr/share/glacier-home/qml/theme/default-icon.png";
} else {
if (iconSource.startsWith("/")) {
iconSource = "file://" + iconSource;
} else if (!iconSource.startsWith("file:///")) {
iconSource = "image://theme/" + iconSource;
}
}
result.iconSource = iconSource;

result.category = tr("Application");
result.extraCaption = tr("installed on your device");
QMap<QString, QVariant> action;
action.insert("type", "exec");
action.insert("app_id", i);
result.action = action;

m_searchResults.push_back(result);
}
}

if (!m_searchResults.isEmpty()) {
emit searchResultReady(m_searchResults);
}
}
39 changes: 39 additions & 0 deletions lib/search/plugins/application/applicationsearchplugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2024 Chupligin Sergey <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#ifndef APPLICATIONSEARCHPLUGIN_H
#define APPLICATIONSEARCHPLUGIN_H

#include <lipstick-qt6/launchermodel.h>
#include <search/glaciersearchplugin.h>

class ApplicationSearchPlugin : public GlacierSearchPlugin {
Q_OBJECT
Q_INTERFACES(GlacierSearchPlugin)
Q_PLUGIN_METADATA(IID "GlacierHome.SearchPlugin")
public:
explicit ApplicationSearchPlugin(QObject* parent = nullptr);
void search(QString searchString);

private:
LauncherModel m_launchModel;
QList<SearchResult> m_searchResults;
};

#endif // APPLICATIONSEARCHPLUGIN_H
79 changes: 79 additions & 0 deletions lib/search/searchpluginmanager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (C) 2024 Chupligin Sergey <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#include "searchpluginmanager.h"
#include <QDir>
#include <QPluginLoader>
#include <QTimer>

#ifndef INSTALL_LIBDIR
#error INTALLINSTALL_LIBDIR is not set!
#endif

SearchPluginManager::SearchPluginManager(QObject* parent)
: QObject { parent }
{
QTimer::singleShot(0, this, SLOT(loadSearchPlugins()));
}

SearchPluginManager::~SearchPluginManager()
{
foreach (const GlacierSearchPlugin* plugin, m_pluginList) {
disconnect(plugin, &GlacierSearchPlugin::searchResultReady, this, &SearchPluginManager::searchResultPluginHandler);
delete plugin;
}
}

void SearchPluginManager::search(QString searchString)
{
m_searchResults.clear();

foreach (GlacierSearchPlugin* plugin, m_pluginList) {
plugin->search(searchString);
}
}

void SearchPluginManager::loadSearchPlugins()
{
QDir pluginsDir(QString::fromUtf8(INSTALL_LIBDIR) + "/glacier-home/plugins/search");
QList<QString> pluginsLibList = pluginsDir.entryList(QDir::Files);

for (const QString& file : qAsConst(pluginsLibList)) {
QPluginLoader pluginLoader(pluginsDir.path() + "/" + file);

QObject* plugin = pluginLoader.instance();
if (plugin) {
GlacierSearchPlugin* searchPlugin = qobject_cast<GlacierSearchPlugin*>(plugin);
if (searchPlugin != nullptr) {
m_pluginList.push_back(searchPlugin);
connect(searchPlugin, &GlacierSearchPlugin::searchResultReady, this, &SearchPluginManager::searchResultReady);
} else {
qWarning() << "CANT CAST PLIUGIN FROM" << pluginsDir.path() + "/" + file;
}
} else {
delete plugin;
}
}
}

void SearchPluginManager::searchResultPluginHandler(QList<GlacierSearchPlugin::SearchResult> results)
{
m_searchResults.append(results);
emit searchResultReady(m_searchResults);
}
48 changes: 48 additions & 0 deletions lib/search/searchpluginmanager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2024 Chupligin Sergey <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#ifndef SEARCHPLUGINMANAGER_H
#define SEARCHPLUGINMANAGER_H

#include "glaciersearchplugin.h"
#include <QMap>
#include <QObject>
#include <QVariant>

class SearchPluginManager : public QObject {
Q_OBJECT
public:
explicit SearchPluginManager(QObject* parent = nullptr);
virtual ~SearchPluginManager();

void search(QString searchString);

signals:
void searchResultReady(QList<GlacierSearchPlugin::SearchResult> results);

private slots:
void loadSearchPlugins();
void searchResultPluginHandler(QList<GlacierSearchPlugin::SearchResult> results);

private:
QList<GlacierSearchPlugin*> m_pluginList;
QList<GlacierSearchPlugin::SearchResult> m_searchResults;
};

#endif // SEARCHPLUGINMANAGER_H
19 changes: 12 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ file(GLOB_RECURSE QML_JS_FILES *.qml *.js)

set(SRC
main.cpp
controlcenterbuttonsmodel.cpp
controlcenterbuttonsmodel.h
fileutils.cpp
fileutils.h
glacierwindowmodel.cpp
glacierwindowmodel.h
mceconnect.cpp
mceconnect.h
logging.h
logging.cpp
${QML_JS_FILES}
)
glacier_global.h
models/glacierwindowmodel.cpp
models/glacierwindowmodel.h
models/controlcenterbuttonsmodel.cpp
models/controlcenterbuttonsmodel.h
models/searchmodel.h
models/searchmodel.cpp
${QML_JS_FILES})

#add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/geoagent.h ${CMAKE_CURRENT_SOURCE_DIR}/geoagent.cpp
# DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.GeoClue2.Agent.xml
Expand All @@ -35,13 +37,16 @@ if(USE_GEOCLUE2)
geoagent.h)
endif()

add_executable(lipstick ${SRC} ${GEOCLUE_SRC})
add_executable(lipstick ${SRC} ${GEOCLUE_SRC} ${PUBLIC_HEADERS})

include_directories(${CMAKE_SOURCE_DIR}/lib)

target_link_libraries(lipstick PUBLIC
Qt6::Gui
Qt6::Qml
Qt6::Quick
Qt6::DBus
GlacierHome::Search
PkgConfig::LIPSTICK
PkgConfig::MLITE6
PkgConfig::NEMODEVICELOCK
Expand Down
Loading

0 comments on commit 8e4edd7

Please sign in to comment.