-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
552 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(search) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(application) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
64
lib/search/plugins/application/applicationsearchplugin.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.