diff --git a/CMakeLists.txt b/CMakeLists.txt index cda3d1f..b29c80a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,61 +1,62 @@ 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) include_directories( ${CMAKE_CURRENT_BINARY_DIR} ) find_package (KF5 REQUIRED COMPONENTS I18n GlobalAccel KIO NotifyConfig Notifications DBusAddons WindowSystem XmlGui UnitConversion ) set(Mangonel_SRCS Mangonel.cpp Label.cpp Config.cpp main.cpp + Provider.cpp providers/Applications.cpp providers/Paths.cpp providers/Shell.cpp providers/Calculator.cpp providers/Units.cpp ) add_executable(mangonel ${Mangonel_SRCS}) target_link_libraries(mangonel Qt5::Core Qt5::Widgets KF5::GlobalAccel KF5::KIOCore KF5::KIOWidgets KF5::I18n KF5::DBusAddons KF5::NotifyConfig KF5::Notifications KF5::WindowSystem KF5::XmlGui KF5::UnitConversion ) 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.h b/Mangonel.h index d96e709..247dc39 100644 --- a/Mangonel.h +++ b/Mangonel.h @@ -1,120 +1,120 @@ /* * 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. */ #ifndef Mangonel_H #define Mangonel_H #include "Label.h" #include "Provider.h" #include #include #include #include #include class ProgramView : public QGraphicsItemGroup { public: - ProgramView(Application application); + ProgramView(Application *application); virtual ~ProgramView(); void show(); void shearLeft(); void shearRight(); void center(); void centerItems(); - Application application; + Application *application; private: QGraphicsPixmapItem* m_icon; QGraphicsTextItem* m_label; QGraphicsTextItem* m_descriptionLabel; QGraphicsRectItem* m_block; }; class IconView : public QGraphicsView { Q_OBJECT public: enum direction {left, right}; IconView(QWidget* parent = 0); ~IconView(); - void addProgram(Application application); + void addProgram(Application *application); Application* selectedApp(); void moveItems(IconView::direction direction); void clear(); void setFirst(); Label* label; private: QList m_items; QGraphicsScene* m_scene; int m_current; }; -class AppList : public QList +class AppList : public QList { public: AppList(); ~AppList(); - void insertSorted(const Application &value); + void insertSorted(Application *value); }; class Mangonel : public QWidget { Q_OBJECT public: Mangonel(); ~Mangonel(); public slots: void show(); void hide(); private slots: void launch(); void getApp(QString query); void showHide(); void showConfig(); void configureNotifications(); void setHotkey(const QKeySequence& hotkey); private: bool event(QEvent* event); void inputMethodEvent(QInputMethodEvent* event); void keyPressEvent(QKeyEvent* event); void focusInEvent(QFocusEvent* event); void focusOutEvent(QFocusEvent* event); bool eventFilter(QObject *object, QEvent *event); QAction* m_actionShow; bool m_processingKey; Label* m_label; IconView* m_iconView; int m_historyIndex; QStringList m_history; QHash m_providers; - AppList* m_apps; + QList m_apps; int m_current; }; #endif // Mangonel_H // kate: indent-mode cstyle; space-indent on; indent-width 4; diff --git a/providers/Paths.h b/Provider.cpp similarity index 77% copy from providers/Paths.h copy to Provider.cpp index 3590729..34aa731 100644 --- a/providers/Paths.h +++ b/Provider.cpp @@ -1,44 +1,29 @@ /* - * Copyright 2010-2012 Bart Kroon - * + * Copyright 2016 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. */ -#ifndef Paths_H -#define Paths_H - #include "Provider.h" - -class Paths : public Provider -{ - Q_OBJECT -public: - Paths(); - ~Paths(); -public slots: - QList getResults(QString query); - int launch(QVariant selected); -}; - -#endif //Paths_H -// kate: indent-mode cstyle; space-indent on; indent-width 4; +Application::Application() +{} diff --git a/Provider.h b/Provider.h index 4df3c66..0f45c6f 100644 --- a/Provider.h +++ b/Provider.h @@ -1,66 +1,79 @@ /* * Copyright 2010-2012 Bart Kroon * * 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. */ #ifndef Provider_H #define Provider_H #include #include struct popularity { int lastUse; int count; }; struct Application; // Abstract base class of providers. class Provider : public QObject { + Q_OBJECT + public: - virtual ~Provider() {}; + virtual ~Provider() {} public slots: - virtual QList getResults(QString query) = 0; + virtual QList getResults(QString query) = 0; virtual int launch(QVariant selected) = 0; }; // Struct stored in AppList. -struct Application +struct Application : public QObject { - Application() : priority(2147483647) - {}; + Q_OBJECT + + Q_PROPERTY(QString name MEMBER name CONSTANT) + Q_PROPERTY(QString completion MEMBER completion CONSTANT) + Q_PROPERTY(QString icon MEMBER icon CONSTANT) + Q_PROPERTY(QString type MEMBER type CONSTANT) + Q_PROPERTY(int priority MEMBER priority CONSTANT) + +public: + Application(); QString name; QString completion; QString icon; - int priority; + long priority = 0;//INT_MAX; QVariant program; Provider* object; //Pointer to the search provider that provided this result. QString type; + +public slots: + void launch() { object->launch(program); } }; #endif // Provider_H // kate: indent-mode cstyle; space-indent on; indent-width 4; diff --git a/providers/Applications.cpp b/providers/Applications.cpp index 13c7a8a..9711f78 100644 --- a/providers/Applications.cpp +++ b/providers/Applications.cpp @@ -1,140 +1,142 @@ /* * 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 "Applications.h" #include #include #include #include #include #include Applications::Applications() { const KConfigGroup config(KSharedConfig::openConfig(), "mangonel_applications"); foreach(const QString &key, config.keyList()) { QList values = config.readEntry >(key, QList()); popularity pop; pop.count = values[0].toInt(); pop.lastUse = values[1].toInt(); m_popularities.insert(key, pop); } } Applications::~Applications() { storePopularities(); } -Application Applications::createApp(const KService::Ptr &service) +Application *Applications::createApp(const KService::Ptr &service) { - Application app; - app.name = service->name(); - app.completion = app.name; - app.icon = service->icon(); - app.object = this; - app.program = service->exec(); + Application *app = new Application; + app->name = service->name(); + app->completion = app->name; + app->icon = service->icon(); + app->object = this; + app->program = service->exec(); if (service->isApplication()) - app.type = i18n("Run application"); + app->type = i18n("Run application"); else - app.type = i18n("Open control module"); + app->type = i18n("Open control module"); return app; } -QList< Application > Applications::getResults(QString term) +QList Applications::getResults(QString term) { - QList list; + QList list; QString query = "exist Exec and ( (exist Keywords and '%1' ~subin Keywords) or (exist GenericName and '%1' ~~ GenericName) or (exist Name and '%1' ~~ Name) or ('%1' ~~ Exec) )"; query = query.arg(term); KService::List services = KServiceTypeTrader::self()->query("Application", query); services.append(KServiceTypeTrader::self()->query("KCModule", query)); int priority = 0; foreach(const KService::Ptr &service, services) { if (service->noDisplay()) continue; - Application app = createApp(service); + Application *app = createApp(service); if (m_popularities.contains(service->exec())) { - app.priority = time(NULL) - m_popularities[service->exec()].lastUse; - app.priority -= 3600 * m_popularities[service->exec()].count; + app->priority = time(NULL) - m_popularities[service->exec()].lastUse; + app->priority -= 3600 * m_popularities[service->exec()].count; } else { - app.priority = ++priority; - - if (service->isApplication()) - app.priority *= 0.9; + if (service->isApplication()) app->priority -= 10; + if (app->name.startsWith(term)) app->priority -= 10; + if (app->name.startsWith(term, Qt::CaseInsensitive)) app->priority -= 10; + if (app->name.contains(term)) app->priority -= 10; + if (app->name.contains(term, Qt::CaseInsensitive)) app->priority -= 10; + app->priority += app->name.length(); } list.append(app); } return list; } int Applications::launch(QVariant selected) { QString exec = selected.toString(); popularity pop; if (m_popularities.contains(exec)) { pop = m_popularities[exec]; pop.lastUse = time(NULL); pop.count++; } else { pop.lastUse = time(NULL); pop.count = 0; } m_popularities[exec] = pop; storePopularities(); if (KRun::run(exec, QList(), 0)) return 0; else return 1; } void Applications::storePopularities() { KConfigGroup config(KSharedConfig::openConfig(), "mangonel_controlmodules"); foreach(const QString &key, m_popularities.keys()) { QList values; values.append(m_popularities[key].count); values.append(m_popularities[key].lastUse); config.writeEntry(key, values); } config.sync(); } #include "Applications.moc" // kate: indent-mode cstyle; space-indent on; indent-width 4; diff --git a/providers/Applications.h b/providers/Applications.h index e9c59a6..04e941e 100644 --- a/providers/Applications.h +++ b/providers/Applications.h @@ -1,52 +1,52 @@ /* * 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. */ #ifndef APPLICATIONS_H #define APPLICATIONS_H #include "Provider.h" #include class Applications : public Provider { Q_OBJECT public: Applications(); ~Applications(); public slots: - QList getResults(QString query); - int launch(QVariant selected); + QList getResults(QString query) override; + int launch(QVariant selected) override; private: - Application createApp(const KService::Ptr &service); + Application *createApp(const KService::Ptr &service); void storePopularities(); QHash m_popularities; }; #endif // kate: indent-mode cstyle; space-indent on; indent-width 4; diff --git a/providers/Calculator.cpp b/providers/Calculator.cpp index c329811..43a3a52 100644 --- a/providers/Calculator.cpp +++ b/providers/Calculator.cpp @@ -1,177 +1,194 @@ /* * Copyright 2010-2012 Bart Kroon * * 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 "Calculator.h" #include #include #include #include #include #include const QList operators = (QList() << '+' << '-' << '/' << '*' << '^' << '%'); bool succes = false; Calculator::Calculator() { functions['+'] = [](float val1, float val2) { return val1 + val2; }; functions['-'] = [](float val1, float val2) { return val1 - val2; }; functions['/'] = [](float val1, float val2) { return val1 / val2; }; functions['*'] = [](float val1, float val2) { return val1 * val2; }; functions['^'] = [](float val1, float val2) { return pow(val1, val2); }; functions['%'] = [](float val1, float val2) { return fmod(val1, val2); }; testCalc(); } Calculator::~Calculator() {} -QList Calculator::getResults(QString query) +QList Calculator::getResults(QString query) { succes = false; - QList list = QList(); - float awnser = calculate(query); + QList list; + QString result; + + QRegExp convertPattern("(.+)(?:to|in)\\s+((bin|oct|hex)\\w*)$"); + if (query.contains(convertPattern)) { + QString target = convertPattern.cap(2); + long calculated = calculate(convertPattern.cap(1)); + + if (target.startsWith("bin")) { + result = "0b" + QString::number(calculated, 2); + } else if (target.startsWith("oct")) { + result = "0" + QString::number(calculated, 8); + } else if (target.startsWith("hex")) { + result = "0x" + QString::number(calculated, 16); + } + } else { + result = QString::number(calculate(query), 'g', 12); + } + if (succes) { - Application result = Application(); - result.icon = "accessories-calculator"; - result.name = QString::number(awnser, 'g', 12); - result.program = result.name; - result.object = this; - result.type = i18n("Calculation"); - list.append(result); + Application *app = new Application; + app->icon = "accessories-calculator"; + app->name = result; + app->program = app->name; + app->object = this; + app->type = i18n("Calculation"); + list.append(app); } return list; } float Calculator::calculate(QString query) { query.remove(' '); if (query.length() <= 0) return 0; int pos = 0; QChar ch = query.at(pos); int count = 0; QString inner = ""; while (pos < query.length()) { ch = query.at(pos); if (ch == ')') { count -= 1; if (count <= 0) { QString result = QString::number(this->calculate(inner), 'f', 12); pos -= inner.length() + 2; pos += result.length(); query.replace("("+inner+")", result); } } if (count > 0) inner += ch; if (ch == '(') { count += 1; } pos += 1; } char oper = ' '; QStringList values; foreach(char item, operators) { int index = query.indexOf(item); if (index == 0) index = query.indexOf(item, 1); if (index > 0) { if (not operators.contains(query.at(index-1).toLatin1())) { oper = item; values = query.split(item); break; } } } if (values.isEmpty()) return query.toFloat(&succes); if (functions.contains(oper)) { if (values[0] == "") { values.removeFirst(); values[0] = oper + values[0]; } float value1 = calculate(values.takeFirst()); float value2 = calculate(values.join(QString(oper))); return functions[oper](value1, value2); } else succes = true; return 0; } int Calculator::launch(QVariant selected) { QClipboard* clipboard = QApplication::clipboard(); clipboard->setText(selected.toString(), QClipboard::Selection); return 0; } void Calculator::testCalc() { assert(calculate("") == 0); // Test for default output. assert(calculate(" ") == 0); // Test for default output. assert(calculate("23+23") == 46); // Test addition of integers. assert(calculate("23+-23") == 0); // Test addition of integers. assert(calculate("34.442+23.558") == 58); // Test addition of floats. assert(fabs(calculate("-34.442+23.442") - -11) <= 0.00001); // Test addition of floats. assert(calculate("36-7") == 36-7); // Test substraction of integers. assert(calculate("23.534-12.034") == 11.5); // Test substraction of floats. assert(fabs(calculate("23.534--12.034") - 35.568) <= 0.000001); // Test substraction of floats. assert(calculate("23/2") == 11.5); // Test division of integers. assert(calculate("23/-2") == -11.5); // Test division of integers. assert(calculate("12.5/2") == 6.25); // Test division of a float. assert(calculate("25*25") == 25*25); // Test multiplication of integers. assert(calculate("-25*25") == -25*25); // Test multiplication of integers. assert(fabs(calculate("-25.3*25.4") - -642.62) <= 0.00001); assert(calculate("2.5*3.5") == 8.75); // Test multiplication of floats. assert(calculate("2.5*-3.5") == -8.75); // Test multiplication of floats. assert(calculate("2^5") == 32); // Test raising to power of integers. assert(fabs(calculate("3.5^2.1") - 13.88490) <= 0.00001); // Test raising to power of floats. assert(calculate("12/0") == 1/0.0); // Test infinity. assert(calculate("0/0.0") != calculate("0/0.0")); // Test NaN. assert(calculate("443*(43+3)") == 20378); // Test for nesting without testing operator precedence. assert(calculate("(443+43)*3") == 1458); // Test for nesting with conflicting operator precedence. assert(calculate("443+43*3") == 572); // Test operator precedence. assert(calculate("23*((23-3)*34+43)") == 16629); assert(calculate("23*(84+(-23-3)*34+-43)") == -19389); } // kate: indent-mode cstyle; space-indent on; indent-width 4; diff --git a/providers/Calculator.h b/providers/Calculator.h index 8a5c9fb..df07b49 100644 --- a/providers/Calculator.h +++ b/providers/Calculator.h @@ -1,51 +1,51 @@ /* * Copyright 2010-2012 Bart Kroon * * 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. */ #ifndef Calculator_H #define Calculator_H #include "Provider.h" typedef float (*calcFunct)(float val1, float val2); class Calculator : public Provider { Q_OBJECT public: Calculator(); ~Calculator(); public slots: - QList getResults(QString query); + QList getResults(QString query); int launch(QVariant selected); private: QHash functions; float calculate(QString query); void testCalc(); }; #endif // Calculator_H // kate: indent-mode cstyle; space-indent on; indent-width 4; diff --git a/providers/Paths.cpp b/providers/Paths.cpp index ba236b3..7ff20b7 100644 --- a/providers/Paths.cpp +++ b/providers/Paths.cpp @@ -1,116 +1,116 @@ /* * Copyright 2010-2012 Bart Kroon * * 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 "Paths.h" #include #include #include #include #include static QString subUser(QString path) { QString homePath = QDir::homePath(); if (path.startsWith(homePath)) path = "~" + path.mid(homePath.length(), -1); return path; } Paths::Paths() {} Paths::~Paths() {} -QList Paths::getResults(QString query) +QList Paths::getResults(QString query) { - QList list = QList(); + QList list; QString original = query; QDir dir; if (query.startsWith("/")) { dir = QDir::root(); query.remove(0, 1); } else dir = QDir::home(); QStringList walk = query.split("/", QString::SkipEmptyParts); if (walk.isEmpty()) walk.append(""); QString part = walk.takeFirst(); while (walk.length() > 0) { dir.cd(part); part = walk.takeFirst(); } query = part + "*"; QFileInfoList paths = dir.entryInfoList(QStringList(query), QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files); foreach(QFileInfo path, paths) { - Application result = Application(); - result.name = subUser(path.absoluteFilePath()); - result.completion = result.name.left(result.name.lastIndexOf("/")) + "/" + path.fileName(); - KFileItem info = KFileItem(KFileItem::Unknown, KFileItem::Unknown, path.absoluteFilePath()); + Application *result = new Application(); + result->name = subUser(path.absoluteFilePath()); + result->completion = result->name.left(result->name.lastIndexOf("/")) + "/" + path.fileName(); + KFileItem info = KFileItem(path.absoluteFilePath()); if (path.isDir()) { - result.completion += "/"; - result.icon = "system-file-manager"; - result.priority = time(NULL) - info.time(KFileItem::ModificationTime).toTime_t(); + result->completion += "/"; + result->icon = "system-file-manager"; + result->priority = time(NULL) - info.time(KFileItem::ModificationTime).toTime_t(); } else { - result.icon = info.iconName(); - result.priority = time(NULL) - info.time(KFileItem::ModificationTime).toTime_t(); + result->icon = info.iconName(); + result->priority = time(NULL) - info.time(KFileItem::ModificationTime).toTime_t(); } - result.object = this; - result.program = path.absoluteFilePath(); - result.type = i18n("Open path"); + result->object = this; + result->program = path.absoluteFilePath(); + result->type = i18n("Open path"); list.append(result); } return list; } int Paths::launch(QVariant selected) { KFileItem info = KFileItem(KFileItem::Unknown, KFileItem::Unknown, selected.toString()); KRun run(info.targetUrl(), 0); return 0; } namespace { QString subUser(QString path) { QString homePath = QDir::homePath(); if (path.startsWith(homePath)) path = "~" + path.mid(homePath.length(), -1); return path; } }; // kate: indent-mode cstyle; space-indent on; indent-width 4; diff --git a/providers/Paths.h b/providers/Paths.h index 3590729..2beca71 100644 --- a/providers/Paths.h +++ b/providers/Paths.h @@ -1,44 +1,44 @@ /* * Copyright 2010-2012 Bart Kroon * * 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. */ #ifndef Paths_H #define Paths_H #include "Provider.h" class Paths : public Provider { Q_OBJECT public: Paths(); ~Paths(); public slots: - QList getResults(QString query); - int launch(QVariant selected); + QList getResults(QString query) override; + int launch(QVariant selected) override; }; #endif //Paths_H // kate: indent-mode cstyle; space-indent on; indent-width 4; diff --git a/providers/Shell.h b/providers/Shell.h index 753cbaf..31cd381 100644 --- a/providers/Shell.h +++ b/providers/Shell.h @@ -1,54 +1,54 @@ /* * Copyright 2010-2012 Bart Kroon * * 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. */ #ifndef Shell_H #define Shell_H #include "Provider.h" #include class Shell : public Provider { Q_OBJECT public: Shell(); ~Shell(); public slots: - QList getResults(QString query); - int launch(QVariant selected); + QList getResults(QString query) override; + int launch(QVariant selected) override; private: QHash index; }; namespace { QHash walkDir(QString path); QStringList getPathEnv(); }; #endif //Shell_H // kate: indent-mode cstyle; space-indent on; indent-width 4; diff --git a/providers/Units.cpp b/providers/Units.cpp index 1b76324..bc02b80 100644 --- a/providers/Units.cpp +++ b/providers/Units.cpp @@ -1,71 +1,71 @@ /* * Copyright 2010-2012 Bart Kroon * * 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 "Units.h" #include #include #include #include #include #include Units::Units() {} Units::~Units() {} -QList< Application > Units::getResults(QString query) +QList Units::getResults(QString query) { - QList list = QList(); + QList list; QRegExp pattern = QRegExp("(\\d+)\\s*(\\w+)\\s+(?:\\=|to|is|in)\\s+(\\w+)$", Qt::CaseInsensitive); if (query.contains(pattern) && pattern.captureCount() == 3) { KUnitConversion::Converter converter; KUnitConversion::Value value(pattern.cap(1).toDouble(), pattern.cap(2)); value = converter.convert(value, pattern.cap(3)); if (value.isValid()) { - Application result; - result.icon = "accessories-calculator"; - result.object = this; - result.name = value.toString(); - result.program = result.name; - result.type = i18n("Unit conversion"); + Application *result = new Application; + result->icon = "accessories-calculator"; + result->object = this; + result->name = value.toString(); + result->program = result->name; + result->type = i18n("Unit conversion"); list.append(result); } } return list; } int Units::launch(QVariant selected) { QClipboard* clipboard = QApplication::clipboard(); clipboard->setText(selected.toString(), QClipboard::Selection); return 0; } // kate: indent-mode cstyle; space-indent on; indent-width 4; diff --git a/providers/Units.h b/providers/Units.h index 18e7825..af79feb 100644 --- a/providers/Units.h +++ b/providers/Units.h @@ -1,46 +1,46 @@ /* * Copyright 2010-2012 Bart Kroon * * 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. */ #ifndef Units_H #define Units_H #include "Provider.h" class Units : public Provider { Q_OBJECT public: Units(); ~Units(); public slots: - QList getResults(QString query); - int launch(QVariant selected); + QList getResults(QString query) override; + int launch(QVariant selected) override; }; #endif // Units_H // kate: indent-mode cstyle; space-indent on; indent-width 4; \ No newline at end of file