diff --git a/CMakeLists.txt b/CMakeLists.txt index 823e4d1..6008b11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,63 +1,60 @@ cmake_minimum_required(VERSION 2.8.12) project(Mangonel) find_package (ECM REQUIRED NO_MODULE) set (CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) include (KDEInstallDirs) include (KDECMakeSettings) include (KDECompilerSettings) include (ECMInstallIcons) include (FeatureSummary) find_package (Qt5 CONFIG REQUIRED Core Widgets Quick) include_directories( ${CMAKE_CURRENT_BINARY_DIR} ) find_package (KF5 REQUIRED COMPONENTS I18n GlobalAccel - KIO NotifyConfig Notifications DBusAddons - WindowSystem UnitConversion + Service ) set(Mangonel_SRCS Mangonel.cpp Config.cpp main.cpp Provider.cpp IconProvider.cpp providers/Applications.cpp providers/Paths.cpp providers/Shell.cpp providers/Calculator.cpp providers/Units.cpp ) qt5_add_resources(Mangonel_SRCS resources.qrc) add_executable(mangonel ${Mangonel_SRCS}) target_link_libraries(mangonel Qt5::Core Qt5::Widgets Qt5::Quick KF5::GlobalAccel - KF5::KIOCore - KF5::KIOWidgets KF5::I18n KF5::DBusAddons KF5::NotifyConfig KF5::Notifications - KF5::WindowSystem KF5::UnitConversion + KF5::Service ) install(TARGETS mangonel ${INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES mangonel.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR}) install(PROGRAMS mangonel.desktop DESTINATION ${AUTOSTART_INSTALL_DIR}) diff --git a/Mangonel.cpp b/Mangonel.cpp index c98e383..ef75eeb 100644 --- a/Mangonel.cpp +++ b/Mangonel.cpp @@ -1,185 +1,184 @@ /* * Copyright 2010-2012 Bart Kroon * Copyright 2012, 2013 Martin Sandsmark * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "Mangonel.h" #include #include #include #include #include #include #include #include #include #include -#include #include #include #include #include #include "Config.h" //Include the providers. #include "providers/Applications.h" #include "providers/Paths.h" #include "providers/Shell.h" #include "providers/Calculator.h" #include "providers/Units.h" #include #include #define WINDOW_WIDTH 440 #define WINDOW_HEIGHT 400 #define ICON_SIZE (WINDOW_WIDTH / 1.5) Mangonel::Mangonel() { // Setup our global shortcut. m_actionShow = new QAction(i18n("Show Mangonel"), this); m_actionShow->setObjectName(QString("show")); QList shortcuts({QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Space)}); KGlobalAccel::self()->setShortcut(m_actionShow, shortcuts); shortcuts = KGlobalAccel::self()->shortcut(m_actionShow); connect(m_actionShow, SIGNAL(triggered()), this, SIGNAL(triggered())); QString shortcutString; if (!shortcuts.isEmpty()) { shortcutString = shortcuts.first().toString(); } QString message = i18nc("@info", "Press %1 to show Mangonel.", shortcutString); KNotification::event(QLatin1String("startup"), message); const KConfigGroup config(KSharedConfig::openConfig(), "mangonel_main"); m_history = config.readEntry("history", QStringList()); // Instantiate the providers. m_providers["applications"] = new Applications(this); m_providers["paths"] = new Paths(this); m_providers["shell"] = new Shell(this); m_providers["Calculator"] = new Calculator(this); m_providers["Units"] = new Units(this); } Mangonel::~Mangonel() // Store history of session. { KConfigGroup config(KSharedConfig::openConfig(), "mangonel_main"); config.writeEntry("history", m_history); config.config()->sync(); } Mangonel *Mangonel::instance() { static Mangonel s_instance; return &s_instance; } QList Mangonel::apps() { QList ret; for (QPointer app : m_apps) { ret.append(app.data()); } return ret; } void Mangonel::getApp(QString query) { for (QPointer app : m_apps) { if (!app) { continue; } app->deleteLater(); } m_apps.clear(); if (query.length() > 0) { m_current = -1; for (Provider* provider : m_providers) { QList list = provider->getResults(query); for (Application *app : list) { app->setParent(this); m_apps.append(app); } } std::sort(m_apps.begin(), m_apps.end(), [](Application *a, Application *b) { if (a->priority != b->priority) { return a->priority < b->priority; } else { return a->name > b->name; } }); } emit appsChanged(); } void Mangonel::showConfig() { QList shortcuts(KGlobalAccel::self()->globalShortcut(qApp->applicationName(), "show")); ConfigDialog* dialog = new ConfigDialog; if (!shortcuts.isEmpty()) { dialog->setHotkey(shortcuts.first()); } connect(dialog, SIGNAL(hotkeyChanged(QKeySequence)), this, SLOT(setHotkey(QKeySequence))); installEventFilter(this); dialog->exec(); removeEventFilter(this); } void Mangonel::setHotkey(const QKeySequence& hotkey) { KGlobalAccel::self()->setShortcut(m_actionShow, QList() << hotkey, KGlobalAccel::NoAutoloading); } void Mangonel::configureNotifications() { KNotifyConfigWidget::configure(); } QString Mangonel::selectionClipboardContent() { return QGuiApplication::clipboard()->text(QClipboard::Selection); } void Mangonel::addToHistory(const QString &text) { m_history.prepend(text); emit historyChanged(); } // kate: indent-mode cstyle; space-indent on; indent-width 4;