-
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.
[Search] implement search plugins core stuff
- Loading branch information
Showing
9 changed files
with
276 additions
and
7 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,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 |
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,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; | ||
} |
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 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 |
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,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 |
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,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); | ||
} | ||
} | ||
} | ||
} |
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 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 |