diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8cf0d27..cdcf5e3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,13 +8,21 @@ set(SRC mceconnect.h logging.h logging.cpp + glacier_global.h models/glacierwindowmodel.cpp models/glacierwindowmodel.h models/controlcenterbuttonsmodel.cpp models/controlcenterbuttonsmodel.h + models/searchmodel.h + models/searchmodel.cpp + search/searchpluginmanager.h + search/searchpluginmanager.cpp ${QML_JS_FILES} ) +set(PUBLIC_HEADERS + search/glaciersearchplugin.h) + #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 # COMMENT "Generate adaptors files for Dbus service" @@ -35,7 +43,7 @@ if(USE_GEOCLUE2) geoagent.h) endif() -add_executable(lipstick ${SRC} ${GEOCLUE_SRC}) +add_executable(lipstick ${SRC} ${GEOCLUE_SRC} ${PUBLIC_HEADERS}) target_link_libraries(lipstick PUBLIC Qt6::Gui @@ -54,3 +62,5 @@ install(TARGETS lipstick RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(DIRECTORY qml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/lipstick-glacier-home-qt6) +install(FILES ${PUBLIC_HEADERS} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/glacier-home) diff --git a/src/glacier_global.h b/src/glacier_global.h new file mode 100644 index 0000000..bfc51d0 --- /dev/null +++ b/src/glacier_global.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2024 Chupligin Sergey + * + * 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 GLACIER_GLOBAL_H +#define GLACIER_GLOBAL_H + +#if defined(GLACIER_LIBRARY) +#define GLACIER_EXPORT Q_DECL_EXPORT +#else +#define GLACIER_EXPORT Q_DECL_IMPORT +#endif + +#endif // GLACIER_GLOBAL_H diff --git a/src/main.cpp b/src/main.cpp index 429a8f0..25b10b8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,6 +36,7 @@ #include "models/controlcenterbuttonsmodel.h" #include "models/glacierwindowmodel.h" +#include "models/searchmodel.h" #ifdef USE_GEOCLUE2 #include "geoclueagent.h" @@ -99,6 +100,7 @@ int main(int argc, char** argv) qmlRegisterType("org.nemomobile.glacier", 1, 0, "GlacierWindowModel"); qmlRegisterType("org.nemomobile.glacier", 1, 0, "GlacierMceConnect"); qmlRegisterType("org.nemomobile.glacier", 1, 0, "ControlCenterButtonsModel"); + qmlRegisterType("org.nemomobile.glacier", 1, 0, "GlacierSearchModel"); #ifdef USE_GEOCLUE2 app.engine()->rootContext()->setContextProperty("usegeoclue2", true); qmlRegisterType("org.nemomobile.glacier", 1, 0, "GlacierGeoAgent"); diff --git a/src/models/searchmodel.cpp b/src/models/searchmodel.cpp new file mode 100644 index 0000000..57328fa --- /dev/null +++ b/src/models/searchmodel.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2024 Chupligin Sergey + * + * 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 "searchmodel.h" + +SearchModel::SearchModel(QObject *parent) + : QAbstractListModel{parent} + , m_manager(new SearchPluginManager(this)) +{ + m_hash.insert(Qt::UserRole, QByteArray("iconTitle")); + m_hash.insert(Qt::UserRole + 1, QByteArray("iconSource")); + m_hash.insert(Qt::UserRole + 2, QByteArray("category")); + m_hash.insert(Qt::UserRole + 3, QByteArray("extraCaption")); + m_hash.insert(Qt::UserRole + 4, QByteArray("action")); +} + +int SearchModel::rowCount(const QModelIndex &parent) const +{ + return -1; +} + +QVariant SearchModel::data(const QModelIndex &index, int role) const +{ + return QVariant(); +} + +void SearchModel::search(QString searchString) +{ + qDebug() << Q_FUNC_INFO << searchString; +} diff --git a/src/models/searchmodel.h b/src/models/searchmodel.h new file mode 100644 index 0000000..9dd1f95 --- /dev/null +++ b/src/models/searchmodel.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2024 Chupligin Sergey + * + * 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 SEARCHMODEL_H +#define SEARCHMODEL_H + +#include +#include + +#include "search/searchpluginmanager.h" + +class SearchModel : public QAbstractListModel +{ + Q_OBJECT +public: + explicit SearchModel(QObject *parent = nullptr); + + int rowCount(const QModelIndex& parent = QModelIndex()) const; + QVariant data(const QModelIndex& index, int role) const; + QHash roleNames() const { return m_hash; } + + Q_INVOKABLE void search(QString searchString); + +private: + QHash m_hash; + SearchPluginManager* m_manager; +}; + +#endif // SEARCHMODEL_H diff --git a/src/qml/applauncher/SearchListView.qml b/src/qml/applauncher/SearchListView.qml index 8608812..7ce7691 100644 --- a/src/qml/applauncher/SearchListView.qml +++ b/src/qml/applauncher/SearchListView.qml @@ -33,6 +33,7 @@ import QtQuick import Nemo.Controls import org.nemomobile.lipstick +import org.nemomobile.glacier Item { id:searchList @@ -41,6 +42,10 @@ Item { property alias searchField: searchField property int oldHeight + GlacierSearchModel{ + id: searchModel + } + function cleanup(){ searchField.focus = false appLauncher.searchString = "" @@ -117,14 +122,10 @@ Item { width:parent.width - searchIcon.width - Theme.itemSpacingMedium placeholderText: qsTr("Search") - Binding { - target: appLauncher - property: "searchString" - value: searchField.text.toLowerCase().trim() - } onTextChanged: { - if(text.lenght>0) { + if(searchField.text.length > 0) { searchField.forceActiveFocus() + searchModel.search(searchField.text) } } diff --git a/src/search/glaciersearchplugin.h b/src/search/glaciersearchplugin.h new file mode 100644 index 0000000..0ac8570 --- /dev/null +++ b/src/search/glaciersearchplugin.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2024 Chupligin Sergey + * + * 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 "../glacier_global.h" +#include + +class GLACIER_EXPORT GlacierSearchPlugin : public QObject { + Q_OBJECT +public: + virtual void search(QString searchString) = 0; +signals: + void searchResultReady(QMap results); +}; +Q_DECLARE_INTERFACE(GlacierSearchPlugin, "GlacierHome.SearchPlugin") + +#endif // GLACIERSEARCHPLUGIN_H diff --git a/src/search/searchpluginmanager.cpp b/src/search/searchpluginmanager.cpp new file mode 100644 index 0000000..671a5c2 --- /dev/null +++ b/src/search/searchpluginmanager.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2024 Chupligin Sergey + * + * 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 +#include +#include + +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::searchResultReady); + delete plugin; + } +} + +void SearchPluginManager::loadSearchPlugins() +{ + QDir pluginsDir("/usr/lib/glacier-home/plugins/search"); + QList pluginsLibList = pluginsDir.entryList(QDir::Files); + + for (const QString& file : qAsConst(pluginsLibList)) { + QPluginLoader pluginLoader(pluginsDir.path() + file); + + QObject* plugin = pluginLoader.instance(); + if (plugin) { + GlacierSearchPlugin* sourcePlugin = qobject_cast(plugin); + if (sourcePlugin != nullptr) { + m_pluginList.push_back(sourcePlugin); + connect(sourcePlugin, &GlacierSearchPlugin::searchResultReady, this, &SearchPluginManager::searchResultReady); + } + } + } +} diff --git a/src/search/searchpluginmanager.h b/src/search/searchpluginmanager.h new file mode 100644 index 0000000..c272ae0 --- /dev/null +++ b/src/search/searchpluginmanager.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2024 Chupligin Sergey + * + * 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 +#include +#include +#include "glaciersearchplugin.h" + +class SearchPluginManager : public QObject +{ + Q_OBJECT +public: + explicit SearchPluginManager(QObject *parent = nullptr); + virtual ~SearchPluginManager(); + +signals: + void searchResultReady(QMap results); + +private slots: + void loadSearchPlugins(); + +private: + QList m_pluginList; +}; + +#endif // SEARCHPLUGINMANAGER_H