From f60defc695502f54f6369ef99b024d4a0cf0bc99 Mon Sep 17 00:00:00 2001 From: Javier Feliz Date: Thu, 28 Aug 2025 17:47:17 -0400 Subject: [PATCH] Delete unused --- lib/fuzzy.hpp | 1 + src/main.cpp | 4 +- src/plugins/ExamplePlugin.hpp | 54 ------- src/plugins/FileSearch/FileSearchExample.hpp | 73 ---------- .../FileSearchIntegrationExample.cpp | 49 ------- .../{FileSearch => }/FileSearchPlugin.hpp | 132 ++++++++++++++++-- 6 files changed, 121 insertions(+), 192 deletions(-) delete mode 100644 src/plugins/ExamplePlugin.hpp delete mode 100644 src/plugins/FileSearch/FileSearchExample.hpp delete mode 100644 src/plugins/FileSearch/FileSearchIntegrationExample.cpp rename src/plugins/{FileSearch => }/FileSearchPlugin.hpp (64%) diff --git a/lib/fuzzy.hpp b/lib/fuzzy.hpp index e648c10..77ef4bd 100644 --- a/lib/fuzzy.hpp +++ b/lib/fuzzy.hpp @@ -23,6 +23,7 @@ namespace fuzzy class FuzzyFinder { + void addDesktopApps(); // Deprecated - use PluginManager instead public: // Find method for string candidates std::vector find(const std::vector &candidates, diff --git a/src/main.cpp b/src/main.cpp index 84916cb..0d9161e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,7 +14,7 @@ #include "ui/AppListModel.hpp" #include "plugins/PluginManager.hpp" #include "plugins/DesktopAppPlugin.hpp" -#include "plugins/FileSearch/FileSearchPlugin.hpp" +#include "plugins/FileSearchPlugin.hpp" #include #include #include @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) // Initialize plugin system auto &pluginManager = plugins::PluginManager::instance(); - // pluginManager.registerPlugin(std::make_unique()); + pluginManager.registerPlugin(std::make_unique()); pluginManager.registerPlugin(std::make_unique()); // Enable system theme support diff --git a/src/plugins/ExamplePlugin.hpp b/src/plugins/ExamplePlugin.hpp deleted file mode 100644 index 438b062..0000000 --- a/src/plugins/ExamplePlugin.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include "../../lib/plugins/PluginInterface.hpp" -#include "../../lib/ui/GenericListItem.hpp" - -namespace plugins -{ - // Example of how simple it is to create a new plugin - class ExamplePlugin : public SearchPlugin - { - public: - std::vector search(const QString& query) override - { - std::vector results; - - // Example: Create some sample items that match any query - if (query.contains("test", Qt::CaseInsensitive)) { - // Using the convenient factory function - results.push_back(ListItems::createItem( - "Test Item 1", - "This is a test item", - "example", - []() { /* custom action */ } - )); - - // Or create directly with GenericListItem - results.push_back(std::make_shared( - "Test Item 2", - "Another test item", - QUrl(), // no icon - "example", - []() { - // Custom execute action - qDebug() << "Test item executed!"; - } - )); - } - - return results; - } - - std::vector getAllItems() override - { - // Return some default items - return { - ListItems::createItem("Example Item", "Always visible", "example") - }; - } - - QString pluginName() const override { return "Example Plugin"; } - QString pluginDescription() const override { return "Demonstrates easy plugin creation"; } - int priority() const override { return 10; } // Low priority - }; -} \ No newline at end of file diff --git a/src/plugins/FileSearch/FileSearchExample.hpp b/src/plugins/FileSearch/FileSearchExample.hpp deleted file mode 100644 index 1cc1b21..0000000 --- a/src/plugins/FileSearch/FileSearchExample.hpp +++ /dev/null @@ -1,73 +0,0 @@ -#pragma once - -#include "FileSearchPlugin.hpp" -#include - -namespace plugins -{ - // Example configurations for the FileSearchPlugin - - // Configuration 1: Document searcher - inline std::unique_ptr createDocumentSearcher() { - std::vector searchDirs = { - QDir::homePath().toStdString() + "/Documents", - QDir::homePath().toStdString() + "/Desktop" - }; - - std::vector ignoreDirs = { - QDir::homePath().toStdString() + "/.cache", - QDir::homePath().toStdString() + "/.local/share/Trash" - }; - - return std::make_unique( - searchDirs, - ignoreDirs, - 2, // max depth - 500 // max files - ); - } - - // Configuration 2: Code project searcher - inline std::unique_ptr createCodeSearcher() { - std::vector searchDirs = { - QDir::homePath().toStdString() + "/projects", - QDir::homePath().toStdString() + "/dev", - QDir::homePath().toStdString() + "/code" - }; - - std::vector ignoreDirs = { - QDir::homePath().toStdString() + "/projects/node_modules", - QDir::homePath().toStdString() + "/projects/.git", - QDir::homePath().toStdString() + "/projects/build", - QDir::homePath().toStdString() + "/projects/target" - }; - - return std::make_unique( - searchDirs, - ignoreDirs, - 4, // deeper search for code projects - 1000 // more files for code projects - ); - } - - // Configuration 3: Media searcher - inline std::unique_ptr createMediaSearcher() { - std::vector searchDirs = { - QDir::homePath().toStdString() + "/Pictures", - QDir::homePath().toStdString() + "/Music", - QDir::homePath().toStdString() + "/Videos", - QDir::homePath().toStdString() + "/Downloads" - }; - - std::vector ignoreDirs = { - QDir::homePath().toStdString() + "/.thumbnails" - }; - - return std::make_unique( - searchDirs, - ignoreDirs, - 3, // medium depth - 2000 // lots of media files - ); - } -} \ No newline at end of file diff --git a/src/plugins/FileSearch/FileSearchIntegrationExample.cpp b/src/plugins/FileSearch/FileSearchIntegrationExample.cpp deleted file mode 100644 index e35b58d..0000000 --- a/src/plugins/FileSearch/FileSearchIntegrationExample.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// Example showing how to integrate FileSearchPlugin into main.cpp -// This is not compiled - it's just a reference for how to use the plugin - -/* -#include "plugins/FileSearchPlugin.hpp" -#include "plugins/FileSearchExample.hpp" - -int main(int argc, char *argv[]) -{ - QGuiApplication app(argc, argv); - QCoreApplication::setApplicationName("waycast"); - - // Initialize plugin system - auto& pluginManager = plugins::PluginManager::instance(); - - // Register desktop app plugin - pluginManager.registerPlugin(std::make_unique()); - - // Register file search plugins with different configurations - - // Option 1: Use default configuration - pluginManager.registerPlugin(std::make_unique()); - - // Option 2: Use custom configuration - std::vector customSearchDirs = { - "/home/user/Documents", - "/home/user/Projects" - }; - std::vector customIgnoreDirs = { - "/home/user/.cache", - "/home/user/Projects/node_modules" - }; - pluginManager.registerPlugin(std::make_unique( - customSearchDirs, - customIgnoreDirs, - 3, // max depth - 1000 // max files - )); - - // Option 3: Use predefined configurations - pluginManager.registerPlugin(plugins::createDocumentSearcher()); - pluginManager.registerPlugin(plugins::createMediaSearcher()); - - // Continue with rest of Qt application setup... - // ... - - return app.exec(); -} -*/ \ No newline at end of file diff --git a/src/plugins/FileSearch/FileSearchPlugin.hpp b/src/plugins/FileSearchPlugin.hpp similarity index 64% rename from src/plugins/FileSearch/FileSearchPlugin.hpp rename to src/plugins/FileSearchPlugin.hpp index 5949415..7c7e958 100644 --- a/src/plugins/FileSearch/FileSearchPlugin.hpp +++ b/src/plugins/FileSearchPlugin.hpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include #include @@ -250,34 +252,136 @@ namespace plugins QUrl getFileIcon(const std::filesystem::path &filePath) const { QString ext = QString::fromStdString(filePath.extension().string()).toLower(); - - // Return basic icon URLs - you could expand this with a proper icon system - if (ext == ".txt" || ext == ".md" || ext == ".rst") + QString iconName; + + // Use freedesktop.org standard icon names that respect user themes + if (ext == ".txt" || ext == ".md" || ext == ".rst" || ext == ".readme") { - return QUrl("qrc:/icons/text-file.svg"); + iconName = "text-x-generic"; } else if (ext == ".pdf") { - return QUrl("qrc:/icons/pdf-file.svg"); + iconName = "application-pdf"; } - else if (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".gif" || ext == ".bmp") + else if (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".gif" || + ext == ".bmp" || ext == ".svg" || ext == ".webp" || ext == ".tiff") { - return QUrl("qrc:/icons/image-file.svg"); + iconName = "image-x-generic"; } - else if (ext == ".mp3" || ext == ".wav" || ext == ".ogg" || ext == ".flac") + else if (ext == ".mp3" || ext == ".wav" || ext == ".ogg" || ext == ".flac" || + ext == ".m4a" || ext == ".aac" || ext == ".wma") { - return QUrl("qrc:/icons/audio-file.svg"); + iconName = "audio-x-generic"; } - else if (ext == ".mp4" || ext == ".avi" || ext == ".mkv" || ext == ".webm") + else if (ext == ".mp4" || ext == ".avi" || ext == ".mkv" || ext == ".webm" || + ext == ".mov" || ext == ".wmv" || ext == ".flv" || ext == ".m4v") { - return QUrl("qrc:/icons/video-file.svg"); + iconName = "video-x-generic"; } - else if (ext == ".cpp" || ext == ".hpp" || ext == ".c" || ext == ".h" || ext == ".py" || ext == ".js") + else if (ext == ".zip" || ext == ".tar" || ext == ".gz" || ext == ".bz2" || + ext == ".xz" || ext == ".7z" || ext == ".rar") { - return QUrl("qrc:/icons/code-file.svg"); + iconName = "package-x-generic"; } + else if (ext == ".cpp" || ext == ".hpp" || ext == ".c" || ext == ".h") + { + iconName = "text-x-c++src"; + } + else if (ext == ".py") + { + iconName = "text-x-python"; + } + else if (ext == ".js" || ext == ".ts" || ext == ".json") + { + iconName = "text-x-javascript"; + } + else if (ext == ".html" || ext == ".htm" || ext == ".css") + { + iconName = "text-html"; + } + else if (ext == ".xml" || ext == ".xsl" || ext == ".xsd") + { + iconName = "text-xml"; + } + else if (ext == ".sh" || ext == ".bash" || ext == ".zsh") + { + iconName = "text-x-script"; + } + else if (ext == ".doc" || ext == ".docx" || ext == ".odt") + { + iconName = "application-vnd.oasis.opendocument.text"; + } + else if (ext == ".xls" || ext == ".xlsx" || ext == ".ods") + { + iconName = "application-vnd.oasis.opendocument.spreadsheet"; + } + else if (ext == ".ppt" || ext == ".pptx" || ext == ".odp") + { + iconName = "application-vnd.oasis.opendocument.presentation"; + } + else + { + iconName = "text-x-generic"; + } + + // Use Qt's icon theme system to find the actual icon file + return resolveThemeIcon(iconName); + } - return QUrl("qrc:/icons/file.svg"); + QUrl resolveThemeIcon(const QString& iconName) const + { + // First try Qt's theme system + QIcon icon = QIcon::fromTheme(iconName); + if (!icon.isNull()) { + // Try to find the actual file path by searching standard locations + QStringList dataDirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); + + // Icon subdirectories in order of preference + QStringList iconSubDirs = { + "icons/hicolor/scalable/mimetypes", + "icons/hicolor/48x48/mimetypes", + "icons/hicolor/32x32/mimetypes", + "icons/hicolor/24x24/mimetypes", + "icons/hicolor/16x16/mimetypes", + "icons/Adwaita/scalable/mimetypes", + "icons/Adwaita/48x48/mimetypes", + "icons/Adwaita/32x32/mimetypes", + "icons/breeze/mimetypes/22", // KDE Plasma + "icons/breeze-dark/mimetypes/22", + "icons/Papirus/48x48/mimetypes", // Popular icon theme + "icons/elementary/mimetypes/48", // Elementary OS + }; + + QStringList extensions = {".svg", ".png", ".xpm"}; + + for (const QString& dataDir : dataDirs) { + for (const QString& iconSubDir : iconSubDirs) { + QString basePath = dataDir + "/" + iconSubDir + "/"; + for (const QString& ext : extensions) { + QString fullPath = basePath + iconName + ext; + if (QFile::exists(fullPath)) { + return QUrl::fromLocalFile(fullPath); + } + } + } + } + } + + // Fallback to a generic file icon if nothing found + QIcon fallbackIcon = QIcon::fromTheme("text-x-generic"); + if (!fallbackIcon.isNull()) { + // Try to resolve the fallback icon the same way + QStringList dataDirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); + for (const QString& dataDir : dataDirs) { + QString path = dataDir + "/icons/hicolor/48x48/mimetypes/text-x-generic.png"; + if (QFile::exists(path)) { + return QUrl::fromLocalFile(path); + } + } + } + + // Ultimate fallback - return empty URL and let QML handle with default + return QUrl(); } // Member variables