Skip to content

Commit

Permalink
[Search] implement search plugins core stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
neochapay committed Jul 16, 2024
1 parent 2ba56eb commit 19ab4ec
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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)
29 changes: 29 additions & 0 deletions src/glacier_global.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 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
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include "models/controlcenterbuttonsmodel.h"
#include "models/glacierwindowmodel.h"
#include "models/searchmodel.h"

#ifdef USE_GEOCLUE2
#include "geoclueagent.h"
Expand Down Expand Up @@ -99,6 +100,7 @@ int main(int argc, char** argv)
qmlRegisterType<GlacierWindowModel>("org.nemomobile.glacier", 1, 0, "GlacierWindowModel");
qmlRegisterType<MceConnect>("org.nemomobile.glacier", 1, 0, "GlacierMceConnect");
qmlRegisterType<ControlCenterButtonsModel>("org.nemomobile.glacier", 1, 0, "ControlCenterButtonsModel");
qmlRegisterType<SearchModel>("org.nemomobile.glacier", 1, 0, "GlacierSearchModel");
#ifdef USE_GEOCLUE2
app.engine()->rootContext()->setContextProperty("usegeoclue2", true);
qmlRegisterType<GeoclueAgent>("org.nemomobile.glacier", 1, 0, "GlacierGeoAgent");
Expand Down
46 changes: 46 additions & 0 deletions src/models/searchmodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 "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;
}
45 changes: 45 additions & 0 deletions src/models/searchmodel.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 SEARCHMODEL_H
#define SEARCHMODEL_H

#include <QAbstractListModel>
#include <QObject>

#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<int, QByteArray> roleNames() const { return m_hash; }

Q_INVOKABLE void search(QString searchString);

private:
QHash<int, QByteArray> m_hash;
SearchPluginManager* m_manager;
};

#endif // SEARCHMODEL_H
13 changes: 7 additions & 6 deletions src/qml/applauncher/SearchListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import QtQuick
import Nemo.Controls

import org.nemomobile.lipstick
import org.nemomobile.glacier

Item {
id:searchList
Expand All @@ -41,6 +42,10 @@ Item {
property alias searchField: searchField
property int oldHeight

GlacierSearchModel{
id: searchModel
}

function cleanup(){
searchField.focus = false
appLauncher.searchString = ""
Expand Down Expand Up @@ -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)
}
}

Expand Down
35 changes: 35 additions & 0 deletions src/search/glaciersearchplugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 "../glacier_global.h"
#include <QObject>

class GLACIER_EXPORT GlacierSearchPlugin : public QObject {
Q_OBJECT
public:
virtual void search(QString searchString) = 0;
signals:
void searchResultReady(QMap<QString, QVariant> results);
};
Q_DECLARE_INTERFACE(GlacierSearchPlugin, "GlacierHome.SearchPlugin")

#endif // GLACIERSEARCHPLUGIN_H
56 changes: 56 additions & 0 deletions src/search/searchpluginmanager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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>

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<QString> 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<GlacierSearchPlugin*>(plugin);
if (sourcePlugin != nullptr) {
m_pluginList.push_back(sourcePlugin);
connect(sourcePlugin, &GlacierSearchPlugin::searchResultReady, this, &SearchPluginManager::searchResultReady);
}
}
}
}
45 changes: 45 additions & 0 deletions src/search/searchpluginmanager.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 SEARCHPLUGINMANAGER_H
#define SEARCHPLUGINMANAGER_H

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

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

signals:
void searchResultReady(QMap<QString, QVariant> results);

private slots:
void loadSearchPlugins();

private:
QList<GlacierSearchPlugin*> m_pluginList;
};

#endif // SEARCHPLUGINMANAGER_H

0 comments on commit 19ab4ec

Please sign in to comment.