Namespace sh::base

namespace sh::base

Core logic.

Includes common data structures and some basic infrastructure. Some other namespaces in sh contain parts of the infrastructure as well.

Enums

enum LogSeverity

The severity of a log message.

Values:

enumerator DEBUG = 0
enumerator INFO = 100
enumerator _DEFAULT = INFO
enumerator WARNING = 200
enumerator ERROR = 300
enumerator E_RROR = ERROR
class IconManager : public QObject, public sh::base::Singleton
#include <iconmanager.h>

Fetches icons according to theme availability and settings.

Public Functions

QIcon getIcon(QString mainname, QString emblemname = QString(), QString miniemblemname = QString(), QStringList tags = QStringList())

Creates a QIcon from the icon name(s). Uses a cache.

QIcon getIconByFullname(QString fullname)

Creates a QIcon from the icon fullname. Uses a cache.

QIcon getIcon(QIcon mainicon, QString emblemname, QString miniemblemname, QStringList tags)

Creates a QIcon based on an existing one. Uncached.

QPixmap getPixmap(QString name, int size = 22)

Creates a QPixmap for an icon name. Uncached.

~IconManager()
void doInitialize()

Executes singleton initialization.

void doShutdown()

Executes singleton shutdown.

void shutdown()

Shutdown down this singleton.

bool isAlive()

Returns if this singleton is alive (true until its shutdown begins).

Private Functions

IconManager()
QIcon _getIcon(QString name)
QImage _colourImage(QImage img, QColor color)

Private Members

QMutex cachemutex
QHash<QString, QIcon> cache
QList<GetIconStrategy*> getIconStrategies
std::shared_ptr<sh::configuration::ConfigurationValue> cfgvalPreferredStrategy
class GetIconStrategy

Subclassed by sh::base::IconManager::IncludedGetIconStrategy, sh::base::IconManager::QIconFromThemeGetIconStrategy

Public Functions

QIcon getIcon(QString name) = 0
~GetIconStrategy()
class IncludedGetIconStrategy : public sh::base::IconManager::GetIconStrategy

Public Functions

IncludedGetIconStrategy()
QIcon getIcon(QString name)

Private Members

QColor brandingcolor1
QColor brandingcolor2
class QIconFromThemeGetIconStrategy : public sh::base::IconManager::GetIconStrategy

Public Functions

QIconFromThemeGetIconStrategy()
QIcon getIcon(QString name)

Private Members

QHash<QString, QString> _aliases
class Logger : public QObject, public sh::base::Singleton
#include <logger.h>

The logging manager.

Use it for writing messages to the Shallot log and for reading from it.

Note: Logging is easiest by the LOG_* macros like SH_LOG_INFO (and it provides more meta data!).

Public Functions

void logException(sh::exceptions::Exception &ex, LogSeverity severity = LogSeverity::ERROR, QString source = QString())

Logs an exception.

void log(QString message, LogSeverity severity, QString source = QString())

Logs a message.

QString getLogAsText(LogSeverity minseverity = LogSeverity::DEBUG)

Returns all logged messages as one text.

QList<LogMessage*> logMessages()

Returns the list of logged messages.

QString logPrefix()

Returns the log prefix, i.e. an optional string all log output begins with.

~Logger()
void doInitialize()

Executes singleton initialization.

void doShutdown()

Executes singleton shutdown.

void shutdown()

Shutdown down this singleton.

bool isAlive()

Returns if this singleton is alive (true until its shutdown begins).

Signals

void newLogMessageArrived()

Emitted when a new log message was written.

Private Functions

Logger()

Private Members

QMutex mutex
QList<LogMessage*> _logMessages
QString _logPrefix
struct LogMessage
#include <logger.h>

A single log message.

Public Members

QString message
LogSeverity severity
QString source
QDateTime time
class MainThread
#include <mainthread.h>

The main thread.

Lots of data structure may only accessed from the main thread. The UI and the sh::filesystem::FilesystemModel also live in this thread (although some functions there may allow multi-threading in some ways).

Public Static Functions

sh::base::ThreadDispatcher *dispatcher()

The sh::base::ThreadDispatcher, which allows to execute code in the main thread.

class ShallotProcess : public sh::base::Singleton
#include <shallotprocess.h>

Provides parameters given from the user by command line and some more simple infos.

Public Functions

QString uiMode()

The ui mode (e.g. “qt”, “web”) specified on command line.

QMap<QString, QString> configurationValueAssignments()

The configuration value assignments set on command line.

QList<QString> configurationValueFiles()

The configuration value files set on command line.

QString parameterValue(QString key, QString deflt = QString())

Returns the command line parameter value for a key as string.

QStringList parameterValueList(QString key)

Returns the command line parameter value for a key as list of strings (for multiple parameter usage).

qint64 parameterValueInt(QString key, qint64 deflt = 0)

Returns the command line parameter value for a key as integer.

QStringList parameters()

Returns the list of keys of all specified command line parameter names.

QString initialWorkDirectory()

Returns the initial directory specified on command line.

QString logPrefix()

Returns the log prefix (i.e. an optional string all log output begins with) specified on command line.

QStringList lang()

Returns the ui language specified on command line.

QColor brandingColor()

Returns the Shallot branding color (typically a dark red).

int minport()

Return the minimal allowed port specified on command line (for web ui).

int maxport()

Return the maximal allowed port specified on command line (for web ui).

int workerminport()

Return the minimal allowed port specified on command line for spawing web workers with (for web ui).

int workermaxport()

Return the maximal allowed port specified on command line for spawing web workers with (for web ui).

int maxnumberworkers(int deflt)

Maximum number of workers specified on command line.

int maxnumberworkersperhost(int deflt)

Maximum number of workers per host specified on command line.

int maxmemorypercent(int deflt)

Maximum memory in percent specified on command line.

int maxmemorypercentglobal(int deflt)

Maximum memory in percent globally specified on command line.

int maxbrowserawayseconds(int deflt)

Maximum browser away time in seconds specified on command line.

int maxidlenessseconds(int deflt)

Maximum user idleness time in seconds specified on command line.

void doInitialize()

Executes singleton initialization.

void doShutdown()

Executes singleton shutdown.

void shutdown()

Shutdown down this singleton.

bool isAlive()

Returns if this singleton is alive (true until its shutdown begins).

Public Static Functions

QString userDataDir()

Returns the path to a storage for per-user data. It resides somewhere within the user home directory.

QString shallotDataDir()

Returns the directory of the Shallot program data. It contains the static files which are part of the Shallot program.

QString revisionString()

Returns the Shallot revision string, i.e. the exact version number. Note: This is only updated by a special build tool (anise) and not by directly compiling via qmake.

QString homepage()

Returns the url to the Shallot homepage.

QDateTime buildtime()

Returns the time when this Shallot build was created. Note: This is only updated by a special build tool (anise) and not by directly compiling via qmake.

Private Functions

ShallotProcess()

Private Members

QMutex _brandingcolormutex
QMap<QString, QStringList> _cmdlineargs
QString _workdir
QString _ui
QMap<QString, QString> _cfgvalassignments
QList<QString> _cfgvalfiles
QColor _brandingcolor
std::shared_ptr<sh::configuration::ConfigurationValue> cfgvalBrandingColor
int _minport = 0
int _maxport = 0
int _workerminport = 0
int _workermaxport = 0
class Singleton
#include <singletoninitializer.h>

A singleton with initialization on Shallot startup and shutdown in the end.

See SingletonInitializer.

Subclassed by sh::actions::ActionsManager, sh::actions::mainmenu::ActionMain, sh::base::IconManager, sh::base::Logger, sh::base::ShallotProcess, sh::configuration::ConfigurationManager, sh::detailcolumns::DetailColumnCustomAttributes, sh::detailcolumns::DetailColumnDirectSymlinkTarget, sh::detailcolumns::DetailColumnExtendedAttributes, sh::detailcolumns::DetailColumnFilesize, sh::detailcolumns::DetailColumnMimetype, sh::detailcolumns::DetailColumnMtime, sh::detailcolumns::DetailColumnResolvedSymlink, sh::exceptions::ExceptionHandlerSettingsManager, sh::filesystem::FilesystemHandlerRegister, sh::filesystem::FilesystemModel, sh::filesystem::FilesystemModelDirectoryTreeProxy, sh::filesystem::FilesystemModelDirectoryTreeProxyVisibilityEnforcements, sh::filesystemhandlers::GnomeIODevicesFilesystemHandler, sh::filesystemhandlers::GnomeIONetworkFilesystemHandler, sh::filesystemhandlers::GnomeIOSmbFilesystemHandler, sh::filesystemhandlers::LocalFilesystemHandler, sh::filesystemhandlers::SharcFilesystemHandler, sh::paneldetails::PanelDetailManager, sh::scripting::api::ApiGlobalObject, sh::scripting::PythonScriptInterpreter, sh::scripting::ScriptingEngine, sh::search::SearchFilesystemHandler, sh::search::SearchManager, sh::settings::SettingsManager, sh::tools::accounts::AccountsManager, sh::tools::Benchmarking, sh::tools::BookmarkManager, sh::tools::DataExchange, sh::tools::filetypes::FileTypeManager, sh::tools::filetypes::UserDefinedOpenMethodDeterminationStrategy, sh::tools::LocalFilesystemWatcher, sh::tools::LocalFilesystemWatcherConnector, sh::tools::OperationsCache, sh::tools::ThumbnailManager, sh::tools::VisibleViews

Public Functions

void doInitialize()

Executes singleton initialization.

void doShutdown()

Executes singleton shutdown.

void shutdown()

Shutdown down this singleton.

bool isAlive()

Returns if this singleton is alive (true until its shutdown begins).

~Singleton()
Singleton(const Singleton&) = delete
Singleton(Singleton&&) = delete

Private Members

QMutex _mutex_shutdown
bool _shutdown = false
class SingletonInitializer
#include <singletoninitializer.h>

Takes care of initialization and shutdown of infrastructure singletons.

It is a very early part of shallot core infrastructure. Singletons typically participate by using those macros:

DECLARE_SINGLETON(STYPE): Used inside the singleton class definition. STYPE is the singleton’s class. It must be a subclass of sh::base::Singleton. It will get a static std::shared_ptr<STYPE> instance() method by that.

REGISTER_SINGLETON(NS, STYPE, GROUPNAME): Used inside the source file. NS is the namespace of the singleton. STYPE is the singleton’s class. GROUPNAME is the singleton group name (used for dependency handling, see later).

For singleton groups, there is REGISTER_SINGLETON_GROUP(GROUPNAME, ...): GROUPNAME is the group name used for grouping singletons together. Additional arguments are other group names; those groups are considered as dependencies, which must be fulfilled before this group can.

For just initializing stuff via static methods (without a singleton instance), use REGISTER_STATICINIT(NS, STYPE, GROUPNAME): NS is the namespace of the class to initialize. STYPE is the class to initialize. It must provide public static void doInitialize() and static void doShutdown(). GROUPNAME is the group name.

Public Functions

void callInitializers()

Executes all create-callbacks at first, then all init-callbacks. In both runs, the callbacks with lower index come first. Afterwards, the singletons are considered as up and running.

SingletonInitializer()

Constructed only by the infrastructure and made available otherwise.

~SingletonInitializer()
void shutdown()

Executes all shutdown-callbacks at first, then all remove-callbacks. The callback order is the reversed one of callInitializers. Afterwards, the singletons are considered as shut down and removed.

Public Static Functions

char registerGroup(QString groupname, QStringList groupdeps)

Registers a singleton group.

You should typically use REGISTER_SINGLETON_GROUP. See SingletonInitializer.

char registerSingleton(QString name, std::function<std::shared_ptr<Singleton>()> instancefctQString groupname, )

Registers a singleton.

You should typically use DECLARE_SINGLETON and REGISTER_SINGLETON. See SingletonInitializer.

QThread *initializerThread()
bool isShutdown()

If the singletons are completely shut down and removed.

Private Types

std::tuple< QString, QString, std::function< std::shared_ptr< Singleton >)> > SingletonTuple
typedef std::tuple<QString, QStringList> SingletonGroupTuple

Private Static Functions

bool dependsOn(QString group, QString depgroup)

Private Static Attributes

QList<SingletonTuple> *_singletons
QHash<QString, SingletonGroupTuple> *_groups
bool _isshutdown = false
QMutex shutdownmutex
class ThreadDispatcher : public QObject
#include <threaddispatcher.h>

Dispatcher for sync/async invocation of functions into the associated thread.

Public Functions

ThreadDispatcher(QObject *parent, QThread *thread)

Constructed only by the infrastructure and made available otherwise.

void invokeSync(std::function<void()>)

Synchronously executes a function in the dispatcher’s thread.

If it already runs in the current thread, it just executes the function. It returns when the function is completely executed.

void invokeAsync(std::function<void()>)

Asynchronously executes a function in the dispatcher’s thread.

It directly returns. The actual execution will take place in a later message loop iteration of that thread.

void invokeAsync(std::function<void()>std::shared_ptr<void> obj1, std::shared_ptr<void> obj2 = 0, std::shared_ptr<void> obj3 = 0, )

Like the other variant, but it can also conserve some shared pointers until after execution.

bool inThread()

Returns if the current thread is already equal to the dispatcher’s thread (so dispatching isn’t required).

Signals

void _invoked()

Private Functions

void _invokeAsync(std::function<void()>)

Private Members

QMutex callsmutex
QThread *_thread
QQueue<std::function<void()>> _queue

Private Slots

void slot_invoked()
class ThreadPool : public QObject
#include <threadpool.h>

A pool of worker threads doing some short jobs from a queue.

Public Static Functions

void enqueueForce(std::function<void()> fct)

Enqueues code to the threadpool.

void enqueueForce(std::function<void()> fctstd::shared_ptr<void> obj1, std::shared_ptr<void> obj2 = 0, std::shared_ptr<void> obj3 = 0, )

Enqueues code to the threadpool.

It can also conserve some shared pointers until after execution.

void enqueueForceBeyondAsyncCallBarrier(std::function<void()> fctstd::shared_ptr<void> obj1 = 0, std::shared_ptr<void> obj2 = 0, std::shared_ptr<void> obj3 = 0, )

Enqueues code to the threadpool and forbids async calls within it. This is useful for ensuring that no code might access a certain object after its deletion.

It can also conserve some shared pointers until after execution.

void enqueueIfIn(std::function<void()> fctQThread *thread, )

Enqueues code to the threadpool if currently in thread. Otherwise executes directly.

void enqueueIfInMain(std::function<void()> fct)

Enqueues code to the threadpool if currently in main thread. Otherwise executes directly.

void doShutdown()

Only called by the Shallot infrastructure for shutdown.

bool isShuttingDown()
bool isShutdown()
int getThreadCount()
void respectThreadAbort()
void doInitialize()

Private Static Functions

void _enqueueForce(std::function<void()> fct)

Private Static Attributes

const int THREAD_COUNT = 10
QMutex poolmutex
QWaitCondition pooladdedcondition
QList<std::function<void()>> tasks
bool _shutsdown = false
QList<ThreadPoolThread*> _threads
int _threadsalive = 0

Friends

friend class ThreadPoolThread
class ThreadPoolThread : public QThread
#include <threadpool.h>

A thread in the thread pool.

Friends

friend class ThreadPool