From 78ae1511849bf0b6d792eb42582aeccf3b0b4063 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Sun, 10 Jan 2016 11:18:38 +0100 Subject: start collecting useful bits here --- akonadish/CMakeLists.txt | 3 ++- akonadish/utils.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ akonadish/utils.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 akonadish/utils.cpp create mode 100644 akonadish/utils.h (limited to 'akonadish') diff --git a/akonadish/CMakeLists.txt b/akonadish/CMakeLists.txt index 6761a32..eaedf9a 100644 --- a/akonadish/CMakeLists.txt +++ b/akonadish/CMakeLists.txt @@ -18,7 +18,8 @@ set(akonadi2_cli_SRCS akonadish_utils.cpp repl/repl.cpp repl/replStates.cpp - state.cpp) + state.cpp + utils.cpp) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/akonadish/utils.cpp b/akonadish/utils.cpp new file mode 100644 index 0000000..d2a28ed --- /dev/null +++ b/akonadish/utils.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2016 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "utils.h" + +namespace Utils +{ + +QStringList filteredCompletions(const QStringList &possibleCompletions, const QString &commandFragment, Qt::CaseSensitivity cs) +{ + if (commandFragment.isEmpty()) { + return possibleCompletions; + } + + QStringList filtered; + for (auto item: possibleCompletions) { + if (item.startsWith(commandFragment, cs)) { + filtered << item; + } + } + + return filtered; +} + +} // namespace Utils + diff --git a/akonadish/utils.h b/akonadish/utils.h new file mode 100644 index 0000000..82be8d5 --- /dev/null +++ b/akonadish/utils.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2016 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#pragma once + +#include + +namespace Utils +{ + +QStringList filteredCompletions(const QStringList &possibleCompletions, const QString &commandFragment, Qt::CaseSensitivity cs = Qt::CaseSensitive); + +} // namespace Utils + -- cgit v1.2.3 From b015ede7cbde5f161d83115d5eef04481f885386 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Sun, 10 Jan 2016 11:18:54 +0100 Subject: use the filter helper in utils, where it moved --- akonadish/akonadish_utils.cpp | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'akonadish') diff --git a/akonadish/akonadish_utils.cpp b/akonadish/akonadish_utils.cpp index 070d788..140c741 100644 --- a/akonadish/akonadish_utils.cpp +++ b/akonadish/akonadish_utils.cpp @@ -22,6 +22,8 @@ #include "common/clientapi.h" +#include "utils.h" + namespace AkonadishUtils { @@ -98,40 +100,24 @@ QStringList resourceIds(State &state) return resources; } -QStringList filtered(const QStringList &list, const QString &fragment) -{ - if (fragment.isEmpty()) { - return list; - } - - QStringList filtered; - for (auto item: list) { - if (item.startsWith(fragment)) { - filtered << item; - } - } - - return filtered; -} - QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state) { - return filtered(resourceIds(state), fragment); + return Utils::filteredCompletions(resourceIds(state), fragment); } QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state) { static QStringList types = QStringList() << "resource" << "folder" << "mail" << "event"; if (commands.count() == 1) { - return filtered(s_types, fragment); + return Utils::filteredCompletions(s_types, fragment); } - return filtered(resourceIds(state), fragment); + return Utils::filteredCompletions(resourceIds(state), fragment); } QStringList typeCompleter(const QStringList &commands, const QString &fragment, State &state) { - return filtered(s_types, fragment); + return Utils::filteredCompletions(s_types, fragment); } QMap keyValueMapFromArgs(const QStringList &args) -- cgit v1.2.3 From 2760d5944802f24321ed98083e9f15a484197f7b Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Sun, 10 Jan 2016 11:19:09 +0100 Subject: add logging level management to State --- akonadish/state.cpp | 14 ++++++++++++++ akonadish/state.h | 3 +++ 2 files changed, 17 insertions(+) (limited to 'akonadish') diff --git a/akonadish/state.cpp b/akonadish/state.cpp index f3f5975..dbd5952 100644 --- a/akonadish/state.cpp +++ b/akonadish/state.cpp @@ -24,6 +24,8 @@ #include #include +#include "common/log.h" + static bool s_hasEventLoop = false; class State::Private @@ -122,4 +124,16 @@ bool State::commandTiming() const return d->timing; } +void State::setLoggingLevel(const QString &level) const +{ + Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::debugLevelFromName(level.toLatin1())); +} + +QString State::loggingLevel() const +{ + // do not turn this into a single line return: that core dumps due to allocation of + // the byte array in Akonadi2::Log + QByteArray rv = Akonadi2::Log::debugLevelName(Akonadi2::Log::debugOutputLevel()); + return rv.toLower(); +} diff --git a/akonadish/state.h b/akonadish/state.h index 9c1ab6f..543b063 100644 --- a/akonadish/state.h +++ b/akonadish/state.h @@ -39,6 +39,9 @@ public: int commandStarted() const; void commandFinished(int returnCode = 0) const; + void setLoggingLevel(const QString &level) const; + QString loggingLevel() const; + static void setHasEventLoop(bool evented); private: -- cgit v1.2.3 From b59a7fe545aa2732e98ecc373c4ab5ca741cd920 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Sun, 10 Jan 2016 11:19:49 +0100 Subject: logging level setting --- akonadish/syntax_modules/core_syntax.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'akonadish') diff --git a/akonadish/syntax_modules/core_syntax.cpp b/akonadish/syntax_modules/core_syntax.cpp index b4812df..ccf96c1 100644 --- a/akonadish/syntax_modules/core_syntax.cpp +++ b/akonadish/syntax_modules/core_syntax.cpp @@ -24,6 +24,7 @@ #include "state.h" #include "syntaxtree.h" +#include "utils.h" namespace CoreSyntax { @@ -145,6 +146,24 @@ bool printSyntaxTree(const QStringList &, State &state) return true; } +bool setLoggingLevel(const QStringList &commands, State &state) +{ + if (commands.count() != 1) { + state.printError(QObject::tr("Wrong number of arguments; expected 1 got %1").arg(commands.count())); + return false; + } + + state.setLoggingLevel(commands.at(0)); + return true; +} + +bool printLoggingLevel(const QStringList &commands, State &state) +{ + const QString level = state.loggingLevel(); + state.printLine(level); + return true; +} + Syntax::List syntax() { Syntax::List syntax; @@ -158,15 +177,22 @@ Syntax::List syntax() Syntax set("set", QObject::tr("Sets settings for the session")); set.children << Syntax("debug", QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel); + Syntax setTiming = Syntax("timing", QObject::tr("Whether or not to print the time commands take to complete")); setTiming.children << Syntax("on", QString(), [](const QStringList &, State &state) -> bool { state.setCommandTiming(true); return true; }); setTiming.children << Syntax("off", QString(), [](const QStringList &, State &state) -> bool { state.setCommandTiming(false); return true; }); set.children << setTiming; + + Syntax logging("logging", QObject::tr("Set the logging level to one of Trace, Log, Warning or Error"), &CoreSyntax::setLoggingLevel); + logging.completer = [](const QStringList &, const QString &fragment, State &state) -> QStringList { return Utils::filteredCompletions(QStringList() << "trace" << "log" << "warning" << "error", fragment, Qt::CaseInsensitive); }; + set.children << logging; + syntax << set; Syntax get("get", QObject::tr("Gets settings for the session")); get.children << Syntax("debug", QObject::tr("The current debug level from 0 to 6"), &CoreSyntax::printDebugLevel); get.children << Syntax("timing", QObject::tr("Whether or not to print the time commands take to complete"), &CoreSyntax::printCommandTiming); + get.children << Syntax("logging", QObject::tr("The current logging level"), &CoreSyntax::printLoggingLevel); syntax << get; return syntax; -- cgit v1.2.3