LeechCraft  0.6.70-3565-g2d86529
Modular cross-platform feature rich live environment.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
LeechCraft::Util Namespace Reference

Namespaces

 AN
 
 CacheStrat
 
 detail
 
 SvcAuth
 
 SysInfo
 
 XDG
 

Classes

class  BackendSelector
 A common dialog to select storage backend. More...
 
class  DBLock
 Provides database transaction lock. More...
 
class  AutoResizeMixin
 Automatically moves a widget to fit a rectangle on resize. More...
 
class  ClearLineEditAddon
 Provides a "clear text" action for line edits. More...
 
class  ColorButton
 A button for choosing a color. More...
 
class  FindNotification
 A horizontal bar with typical widgets for text search. More...
 
class  FindNotificationWk
 A helper class to aid connecting FindNotification with Qt WebKit. More...
 
class  FlowLayout
 A simple flow layout implementation. More...
 
class  LineEditButtonManager
 Manages additional overlay buttons in a QLineEdit. More...
 
class  PageNotification
 A horizontal widget embedding into the parent layout of the passed parent widget. More...
 
class  SelectableBrowser
 A "browser" that shows HTML either via QTextBrowser or a browser plugin. More...
 
class  UnhoverDeleteMixin
 Allows to hide a widget or popup after mouse leave. More...
 
class  IDPool
 A simple pool of identificators of the given type. More...
 
class  DndActionsMixin
 Abstracts away differences between Qt4 and Qt5 in model DnD support. More...
 
class  FlattenFilterModel
 Proxy model flattening a hierarchical model. More...
 
class  FlatToFoldersProxyModel
 
class  MergeModel
 
class  ModelItem
 Provides a proxying API on top of an QAbstractItemModel. More...
 
class  ModelItemBase
 Base class for model items for tree-like models. More...
 
class  ModelIterator
 Provides an iterator-based API to a Qt model. More...
 
class  RoleNamesMixin
 Wraps differences between role names handling in Qt4 and Qt5. More...
 
class  CustomCookieJar
 A customized cookie jar with additional features. More...
 
class  CustomNetworkReply
 A network reply with customizable content and reply headers. More...
 
class  NetworkDiskCache
 A thread-safe garbage-collected network disk cache. More...
 
class  NetworkDiskCacheGC
 Garbage collection for a set of network disk caches. More...
 
class  ColorThemeProxy
 Proxy for QML files to use colors from current color theme. More...
 
class  PlotItem
 
class  QmlErrorWatcher
 Utility class for logging errors from a QML view. More...
 
class  SettableIconProvider
 QML image provider with settable icons for each path. More...
 
class  StandardNAMFactory
 A standard QML QNetworkAccessManager factory. More...
 
class  ThemeImageProvider
 Provides icons from the current theme by their FDO name. More...
 
class  ToolTipItem
 ToolTip for Qml objects. More...
 
class  UnhideListModel
 A model suitable to be used with UnhideListViewBase. More...
 
class  UnhideListViewBase
 
class  WidthIconProvider
 Provides scalable icons to QML. More...
 
class  ShortcutManager
 Aids in providing configurable shortcuts. More...
 
class  AssocCache
 
class  ConcurrentException
 A concurrent exception that plays nicely with Qt. More...
 
class  DelayedExecutor
 Executes a given action after a given timeout. More...
 
class  EitherCont
 A peir of two functions, typically a continuation and an error handler. More...
 
class  LazyInitializer
 Provides lazy initialization on first access to an object. More...
 
class  NewType
 A somewhat "strong" typedef. More...
 
struct  WrapType
 
struct  WrapType< QList< QString > >
 
class  QueueManager
 A simple scheduling manager for a queue of functors. More...
 
struct  RegExpImpl
 
class  RegExp
 
class  SlotClosureBase
 Base class for SlotClosure. More...
 
class  SlotClosure
 Executes a given functor upon a signal (or a list of signals). More...
 
class  BasicDeletePolicy
 
class  DeleteLaterPolicy
 Deletes a SlotClosure object after its signal has fired. More...
 
class  NoDeletePolicy
 Does not delete a SlotClosure object. More...
 
class  ChoiceDeletePolicy
 
class  FuturesTest
 
class  PreludeTest
 
class  DummyObject
 
class  SlotClosureTest
 
class  StlizeTest
 
class  UrlAccessor
 
class  UrlOperator
 Manipulates query part of an QUrl object. More...
 
class  ExtensionsData
 
class  ExtensionsDataImpl
 
class  FDGuard
 
class  FileRemoveGuard
 QFile removing itself from file system on destruction. More...
 
class  MimeDetectorImpl
 
class  MimeDetector
 
class  ResourceLoader
 Utility class for loading a file from a set of locations. More...
 
class  CategorySelector
 The CategorySelector widget provides a way to select amongst a group of items. More...
 
class  TagsCompleter
 Completer suitable for tag completion. More...
 
class  TagsCompletionModel
 A QStringListModel providing additional methods for tags. More...
 
class  TagsFilterModel
 Provides filter model with additional tags filter mode. More...
 
class  TagsLineEdit
 A line edit class suitable for use with TagsCompleter. More...
 
class  XWrapper
 
class  BaseHookInterconnector
 Base class for signal-slot relays in plugin APIs. More...
 
class  DefaultHookProxy
 Standard implementation of IHookProxy. More...
 
class  DownloadHandler
 
class  Introspectable
 
class  NotificationActionHandler
 Aids in adding actions to notifications. More...
 
class  StdDataFilterMenuCreator
 Adds actions to handle some data with relevant IDataFilter plugins to a menu. More...
 
class  AddressesModelManager
 Manages an XML settings model with a list of network interfaces selected by the user from the list of available ones. More...
 
class  FontChooserWidget
 
class  MassFontChangeDialog
 
class  WkFontsWidget
 A settings widget for configuring WebKit fonts. More...
 

Typedefs

typedef std::shared_ptr
< XmlSettingsDialog > 
XmlSettingsDialog_ptr
 
typedef std::shared_ptr
< ModelItem
ModelItem_ptr
 
typedef std::weak_ptr< ModelItemModelItem_wtr
 
typedef QVector< ModelItem_ptrModelItemsList_t
 
typedef std::shared_ptr< const
ModelItem
ModelItem_cptr
 
typedef QList< QPair< QString,
QString > > 
AddrList_t
 
using OneTimeRunner = SlotClosure< DeleteLaterPolicy >
 An utility typedef for SlotClosure deleting immediately after firing. More...
 
template<typename T >
using WrapType_t = typename WrapType< T >::type
 
using DefaultScopeGuard = detail::ScopeGuard< detail::DefaultScopeGuardDeleter >
 
typedef std::shared_ptr
< QIODevice > 
QIODevice_ptr
 
typedef std::shared_ptr
< DefaultHookProxy
DefaultHookProxy_ptr
 
using Introspect_f = std::function< QVariantMap(QVariant)>
 

Enumerations

enum  FitFlag {
  NoFlags,
  NoOverlap = 0x01
}
 
enum  QueuePriority {
  QueuePriority::Normal,
  QueuePriority::High
}
 The priority of the action in the queue. More...
 
enum  SysPath {
  SysPath::QML,
  SysPath::Share
}
 Describes various root paths recognized by GetSysPath(). More...
 
enum  UserDir {
  UserDir::Cache,
  UserDir::LC
}
 Describes various user-specific paths. More...
 
enum  WinStateFlag {
  NoState = 0,
  Modal = 1 << 0,
  Sticky = 1 << 1,
  MaximizedVert = 1 << 2,
  MaximizedHorz = 1 << 3,
  Shaded = 1 << 4,
  SkipTaskbar = 1 << 5,
  SkipPager = 1 << 6,
  Hidden = 1 << 7,
  Fullscreen = 1 << 8,
  OnTop = 1 << 9,
  OnBottom = 1 << 10,
  Attention = 1 << 11
}
 
enum  AllowedActionFlag {
  NoAction = 0,
  Move = 1 << 0,
  Resize = 1 << 1,
  Minimize = 1 << 2,
  Shade = 1 << 3,
  Stick = 1 << 4,
  MaximizeHorz = 1 << 5,
  MaximizeVert = 1 << 6,
  ShowFullscreen = 1 << 7,
  ChangeDesktop = 1 << 8,
  Close = 1 << 9,
  MoveToTop = 1 << 10,
  MoveToBottom = 1 << 11
}
 

Functions

 Rect_ (size)
 
QPoint FitRectScreen (QPoint pos, const QSize &size, FitFlags flags=NoFlags, const QPoint &shiftAdd=QPoint(0, 0))
 Tries to fit a rectangle (like a dialog or popup) into screen. More...
 
QPoint FitRect (QPoint pos, const QSize &size, const QRect &geometry, FitFlags flags=NoFlags, const QPoint &shiftAdd=QPoint(0, 0))
 Tries to fit a rectangle (like a dialog or popup) into geometry. More...
 
QLabel * ShowPixmapLabel (const QPixmap &pixmap, const QPoint &pos=QPoint())
 Shows a pixmap at the given pos. More...
 
 Q_DECLARE_FLAGS (FitFlags, FitFlag)
 
bool operator== (const ModelIterator &left, const ModelIterator &right)
 
bool operator!= (const ModelIterator &left, const ModelIterator &right)
 
AddrList_t GetLocalAddresses (int port=0)
 Returns all local addresses. More...
 
QList< QHostAddress > GetAllAddresses ()
 Returns all addresses likely accessible "from the outside". More...
 
QString GetSocketErrorString (QAbstractSocket::SocketError error)
 Returns an error string for the given socket error. More...
 
void CreateShortcuts (const QList< QKeySequence > &seqs, const std::function< void()> &func, QWidget *parent)
 Makes func invokable with shortcuts in seq. More...
 
void CreateShortcuts (const QList< QKeySequence > &seqs, QObject *object, const char *metamethod, QWidget *parent)
 Makes metamethod invokable with shortcuts in seq. More...
 
void ExecuteLater (const DelayedExecutor::Actor_f &actor, int delay=0)
 
template<typename R , typename T , typename... Args>
std::function< R(Args...)> BindMemFn (R(T::*fn)(Args...), T *c)
 Binds an instance of an object to its member function. More...
 
template<typename Executor , typename ResultHandler , typename... Args>
void ExecuteFuture (Executor f, ResultHandler rh, QObject *parent, Args...args)
 Runs a QFuture-returning function and feeding the future to a handler when it is ready. More...
 
template<typename Executor , typename... Args>
detail::SequenceProxy
< typename detail::Sequencer
< Executor, Args...>
::RetType_t, Executor, Args...> 
Sequence (QObject *parent, Executor f, Args...args)
 Creates a sequencer that allows chaining multiple futures. More...
 
template<typename F , typename... Args>
auto Invoke (F &&f, Args &&...args) -> decltype(std::forward< F >(f)(std::forward< Args >(args)...))
 
template<typename Base , typename Real , typename Res >
auto Invoke (Res Base::*mem, Real &&obj, typename std::enable_if<!std::is_member_function_pointer< decltype(mem)>::value >::type *=nullptr) -> decltype(obj.*mem)
 
template<typename Base , typename Real , typename Res >
auto Invoke (Res Base::*mem, Real &&obj) -> decltype((obj.*mem)())
 
QVariant ParseJson (const QByteArray &bytes, const char *context)
 Parses JSON content in the given bytearray. More...
 
QVariant ParseJson (QIODevice *device, const char *context)
 Utility function parsing JSON from the device. More...
 
template<typename T1 , typename T2 , template< typename U > class Container, typename F >
auto ZipWith (const Container< T1 > &c1, const Container< T2 > &c2, F f) -> Container< typename std::result_of< F(T1, T2)>::type >
 
template<typename T1 , typename T2 , template< typename U > class Container, template< typename U1, typename U2 > class Pair = QPair>
auto Zip (const Container< T1 > &c1, const Container< T2 > &c2) -> Container< Pair< T1, T2 >>
 
template<typename T , template< typename U > class Container, typename F >
auto Map (const Container< T > &c, F f) -> typename std::enable_if<!std::is_same< void, decltype(Invoke(f, std::declval< T >()))>::value, WrapType_t< Container< typename std::decay< decltype(Invoke(f, std::declval< T >()))>::type >>>::type
 
template<template< typename...> class Container, typename F , template< typename > class ResultCont = QList, typename... ContArgs>
auto Map (const Container< ContArgs...> &c, F f) -> typename std::enable_if<!std::is_same< void, decltype(Invoke(f,*c.begin()))>::value, WrapType_t< ResultCont< typename std::decay< decltype(Invoke(f,*c.begin()))>::type >>>::type
 
template<template< typename...> class Container, typename F , typename... ContArgs>
auto Map (Container< ContArgs...> &c, F f) -> typename std::enable_if< std::is_same< void, decltype(Invoke(f,*c.begin()))>::value >::type
 
template<template< typename...> class Container, typename F , typename... ContArgs>
auto Map (const Container< ContArgs...> &c, F f) -> typename std::enable_if< std::is_same< void, decltype(Invoke(f,*c.begin()))>::value >::type
 
template<typename F >
QList< typename std::decay
< typename std::result_of< F(QString)>
::type >::type > 
Map (const QStringList &c, F f)
 
template<typename T , template< typename U > class Container, typename F >
auto Filter (const Container< T > &c, F f) -> Container< T >
 
template<template< typename > class Container, typename T >
Container< T > Concat (const Container< Container< T >> &containers)
 
template<template< typename...> class Container, typename... ContArgs>
auto Concat (const Container< ContArgs...> &containers) -> typename std::decay< decltype(*containers.begin())>::type
 
template<template< typename > class Container, typename T >
Container< Container< T > > SplitInto (size_t numChunks, const Container< T > &container)
 
template<template< typename Pair, typename...Rest > class Cont, template< typename K, typename V > class Pair, typename K , typename V , typename KV , typename... Rest>
boost::optional< V > Lookup (const KV &key, const Cont< Pair< K, V >, Rest...> &cont)
 
template<typename R >
detail::ComparingByClosure< R > ComparingBy (R r)
 
QString Escape (const QString &str)
 
template<template< typename K, typename V > class PairType = std::pair, typename Assoc >
auto Stlize (Assoc &&assoc) -> detail::StlAssocRange< decltype(assoc.begin()), Assoc, PairType >
 Converts an Qt's associative sequence assoc to an STL-like iteratable range. More...
 
QByteArray SerializeJson (const QVariant &var, bool compact=true)
 Serializes the given var to JSON representation. More...
 
template<typename F >
detail::ScopeGuard< F > MakeScopeGuard (const F &f)
 Returns an object performing passed function on scope exit. More...
 
void swap (FDGuard &g1, FDGuard &g2)
 
QByteArray DetectFileMime (const QString &path)
 
QStringList GetPathCandidates (SysPath path, QString subfolder)
 Returns possible full paths for the path and subfolder. More...
 
QString GetSysPath (SysPath path, const QString &subfolder, const QString &filename)
 Returns path to the file in the given root path and subfolder. More...
 
QUrl GetSysPathUrl (SysPath path, const QString &subfolder, const QString &filename)
 Returns path to the file in the given root path and subfolder. More...
 
QStringList GetSystemPaths ()
 Returns the components of the system PATH variable. More...
 
QString FindInSystemPath (const QString &name, const QStringList &paths, const std::function< bool(QFileInfo)> &filter=std::function< bool(QFileInfo)>())
 Searches for a file in system paths according to a filter. More...
 
QDir GetUserDir (UserDir dir, const QString &subpath)
 
QDir CreateIfNotExists (QString path)
 Creates a path if it doesn't exist. More...
 
QString GetTemporaryName (const QString &pattern=QString("lc_temp.XXXXXX"))
 Returns a temporary filename. More...
 
bool HasSupportedImageExtension (const QString &filename)
 Checks if the given filename has a known image extension. More...
 
QString FromStdString (const std::string &str)
 An utility function that creates a QString from UTF8-encoded std::string. More...
 
UTIL_API QString GetAsBase64Src (const QImage &image)
 Returns the given image in a Base64-encoded form. More...
 
UTIL_API QString GetUserText (const Entity &entity)
 Return the user-readable representation of the entity. More...
 
UTIL_API QString MakePrettySize (qint64 sourceSize)
 Makes a formatted size from number. More...
 
UTIL_API QString MakeTimeFromLong (ulong time)
 Makes a formatted time from number. More...
 
UTIL_API QTranslator * LoadTranslator (const QString &base, const QString &locale, const QString &prefix="leechcraft", const QString &appname="leechcraft")
 
UTIL_API QTranslator * InstallTranslator (const QString &base, const QString &prefix="leechcraft", const QString &appname="leechcraft")
 Loads and installs a translator. More...
 
UTIL_API QString GetLocaleName ()
 Returns the current locale name, like en_US. More...
 
UTIL_API QString GetInternetLocaleName (const QLocale &)
 
UTIL_API QString GetLanguage ()
 Returns the current language name. More...
 
UTIL_API QModelIndexList GetSummarySelectedRows (QObject *sender)
 
UTIL_API QAction * CreateSeparator (QObject *parent)
 Returns the action that is set to act as a separator. More...
 
UTIL_API QPixmap DrawOverlayText (QPixmap px, const QString &text, QFont font, const QPen &pen, const QBrush &brush)
 
UTIL_API uintptr_t Handle2Num (Qt::HANDLE handle)
 Converts the handle to an integer. More...
 
template<typename TagGetter , typename TagSetter >
QDomElement GetElementForTags (const QStringList &tags, QDomNode &node, QDomDocument &document, const QString &elementName, TagGetter tagGetter, TagSetter tagSetter)
 Returns an element for a given tags list. More...
 
template<typename K , typename V >
QMap< K, V > MakeMap (std::initializer_list< std::pair< K, V >> l)
 
QString GetPassword (const QString &keyName, const QString &dialogText, const ICoreProxy_ptr &proxy, bool useStore=true)
 Returns password for the key, possibly asking the user. More...
 
void SavePassword (const QString &password, const QString &keyName, const ICoreProxy_ptr &proxy)
 Saves the password to be retrieved later via GetPassword(). More...
 
QList< ANFieldDataGetStdANFields (const QString &category)
 Returns the list of the standard AN fields for the given category. More...
 
Entity MakeAN (const QString &header, const QString &text, Priority priority, const QString &senderID, const QString &cat, const QString &type, const QString &id, const QStringList &visualPath, int delta=1, int count=0, const QString &fullText=QString(), const QString &extendedText=QString())
 Creates an Advanced Notifications-enabled notify entity. More...
 
Entity MakeANRule (const QString &title, const QString &senderID, const QString &category, const QStringList &types, AN::NotifyFlags flags=AN::NotifyNone, bool openConfiguration=false, const QList< QPair< QString, ANFieldValue >> &fields={})
 Creates an Entity defining an Advanced Notifications rule. More...
 
QList< QObject * > GetDataFilters (const QVariant &data, IEntityManager *manager)
 Returns the data filter plugins that can handle data. More...
 
Entity MakeEntity (const QVariant &entity, const QString &location, TaskParameters tp, const QString &mime)
 
Entity MakeNotification (const QString &header, const QString &text, Priority priority)
 An utility function to make a Entity with notification. More...
 
Entity MakeANCancel (const Entity &event)
 Makes an event for canceling another Advanced Notifications event. More...
 
Entity MakeANCancel (const QString &senderId, const QString &eventId)
 Makes an event for canceling another Advanced Notifications event. More...
 
QVariant GetPersistentData (const QByteArray &key, const ICoreProxy_ptr &proxy)
 Returns persistent data stored under given key. More...
 
void SetJobHolderProgress (const QList< QStandardItem * > &row, qint64 done, qint64 total, const QString &text)
 Sets the progress values on the given row. More...
 
void SetJobHolderProgress (QStandardItem *item, qint64 done, qint64 total)
 Sets the done and total progress values on the given item. More...
 
void InitJobHolderRow (const QList< QStandardItem * > &row)
 
UTIL_XPC_API Entity MakeEntity (const QVariant &entity, const QString &location, LeechCraft::TaskParameters tp, const QString &mime=QString())
 An utility function to make a Entity. More...
 
XmlSettingsDialog * OpenXSD (const QString &title, const QString &filename, Util::BaseSettingsManager *bsm)
 Opens XML settings dialog for the given XML filename. More...
 

Variables

struct {
Apply
 
const int SourcePager = 2
 
const int StateRemove = 0
 
const int StateAdd = 1
 
 iem
 
 parent
 
 E_ { e }
 

Typedef Documentation

typedef QList<QPair<QString, QString> > LeechCraft::Util::AddrList_t

Definition at line 44 of file addresses.h.

Definition at line 126 of file defaulthookproxy.h.

using LeechCraft::Util::Introspect_f = typedef std::function<QVariantMap (QVariant)>

Definition at line 43 of file introspectable.h.

typedef std::shared_ptr<const ModelItem> LeechCraft::Util::ModelItem_cptr

Definition at line 45 of file modelitem.h.

typedef std::shared_ptr<ModelItem> LeechCraft::Util::ModelItem_ptr

Definition at line 40 of file modelitem.h.

Definition at line 43 of file modelitem.h.

Definition at line 44 of file modelitem.h.

An utility typedef for SlotClosure deleting immediately after firing.

See Also
SlotClosure

Definition at line 43 of file onetimerunner.h.

typedef std::shared_ptr<QIODevice> LeechCraft::Util::QIODevice_ptr

Definition at line 50 of file resourceloader.h.

template<typename T >
using LeechCraft::Util::WrapType_t = typedef typename WrapType<T>::type

Definition at line 75 of file prelude.h.

typedef std::shared_ptr<XmlSettingsDialog> LeechCraft::Util::XmlSettingsDialog_ptr

Definition at line 39 of file ihavesettings.h.

Enumeration Type Documentation

Enumerator
NoAction 
Move 
Resize 
Minimize 
Shade 
Stick 
MaximizeHorz 
MaximizeVert 
ShowFullscreen 
ChangeDesktop 
Close 
MoveToTop 
MoveToBottom 

Definition at line 57 of file winflags.h.

The priority of the action in the queue.

Enumerator
Normal 

Standard priority.

High 

Higher priority.

Definition at line 48 of file queuemanager.h.

Describes various root paths recognized by GetSysPath().

See Also
GetPathCandidates(), GetSysPath()
Enumerator
QML 

Root path for QML files.

Plugins are expected to install their files into a subdirectory of this directory.

Share 

Directory with shared data files.

Corresponds to /usr/[local/]share/leechcraft on Linux, for example.

Definition at line 48 of file paths.h.

Describes various user-specific paths.

Enumerator
Cache 

Cache for volatile data.

LC 

Root LeechCraft directory (something like ~/.leechcraft).

Definition at line 170 of file paths.h.

Enumerator
NoState 
Modal 
Sticky 
MaximizedVert 
MaximizedHorz 
Shaded 
SkipTaskbar 
SkipPager 
Hidden 
Fullscreen 
OnTop 
OnBottom 
Attention 

Definition at line 38 of file winflags.h.

Function Documentation

template<typename R , typename T , typename... Args>
std::function<R (Args...)> LeechCraft::Util::BindMemFn ( R(T::*)(Args...)  fn,
T *  c 
)

Binds an instance of an object to its member function.

Parameters
[in]fnThe member function of class T.
[in]cThe instance of class T to bind to the member function fn.
Returns
A functor callable with all arguments of fn but the object itself.
Template Parameters
RThe return type of the function.
TThe type of the object.
ArgsThe arguments to the function, besides the object itself.

Definition at line 60 of file functional.h.

template<typename R >
detail::ComparingByClosure<R> LeechCraft::Util::ComparingBy ( r)

Definition at line 251 of file prelude.h.

template<template< typename > class Container, typename T >
Container<T> LeechCraft::Util::Concat ( const Container< Container< T >> &  containers)

Definition at line 177 of file prelude.h.

template<template< typename...> class Container, typename... ContArgs>
auto LeechCraft::Util::Concat ( const Container< ContArgs...> &  containers) -> typename std::decay<decltype (*containers.begin ())>::type

Definition at line 186 of file prelude.h.

UTIL_SYS_API QDir LeechCraft::Util::CreateIfNotExists ( QString  path)

Creates a path if it doesn't exist.

Creates a relative path ~/.leechcraft/path and throws an exception if this could not be done or if such path already exists and it is not readable.

Parameters
[in]pathThe path to create.
Returns
The newly created dir.
Exceptions
std::runtime_errorThrows if the path could not be created.

Definition at line 169 of file paths.cpp.

QAction * LeechCraft::Util::CreateSeparator ( QObject *  parent)

Returns the action that is set to act as a separator.

That is the action with setSeparator(true);

Parameters
[in]parentThe parent of the action.
Returns
The separator action.

Definition at line 255 of file util.cpp.

UTIL_SHORTCUTS_API void LeechCraft::Util::CreateShortcuts ( const QList< QKeySequence > &  seqs,
const std::function< void()> &  func,
QWidget *  parent 
)

Makes func invokable with shortcuts in seq.

This function creates one QShortcut object per each key sequence in seqs and calls func when one of the shortcuts is activated.

If seqs is empty, this function does nothing.

Parameters
[in]seqsThe list of key sequences to handle.
[in]funcThe function to invoke when one of key sequences in seqs is activated.
[in]parentThe parent object for the shortcuts.

Definition at line 38 of file util.cpp.

UTIL_SHORTCUTS_API void LeechCraft::Util::CreateShortcuts ( const QList< QKeySequence > &  seqs,
QObject *  object,
const char *  metamethod,
QWidget *  parent 
)

Makes metamethod invokable with shortcuts in seq.

This function creates one QShortcut object per each key sequence in seqs and calls metamethod of the given object when one of the shortcuts is activated.

If seqs is empty, this function does nothing.

Parameters
[in]seqsThe list of key sequences to handle.
[in]objectThe object whose metamethod should be invoked.
[in]metamethodThe metamethod to invoke when one of key sequences in seqs is activated.
[in]parentThe parent object for the shortcuts.

Definition at line 54 of file util.cpp.

UTIL_SYS_API QByteArray LeechCraft::Util::DetectFileMime ( const QString &  path)

Definition at line 88 of file mimedetector.cpp.

QPixmap LeechCraft::Util::DrawOverlayText ( QPixmap  px,
const QString &  text,
QFont  font,
const QPen &  pen,
const QBrush &  brush 
)

Definition at line 262 of file util.cpp.

UTIL_SLL_API QString LeechCraft::Util::Escape ( const QString &  str)

Definition at line 42 of file qtutil.cpp.

Referenced by Stlize().

+ Here is the caller graph for this function:

template<typename Executor , typename ResultHandler , typename... Args>
void LeechCraft::Util::ExecuteFuture ( Executor  f,
ResultHandler  rh,
QObject *  parent,
Args...  args 
)

Runs a QFuture-returning function and feeding the future to a handler when it is ready.

This function creates a QFutureWatcher of a type compatible with the QFuture type returned from the f, makes sure that rh handler is invoked when the future finishes, and then invokes the f with the given list of args (that may be empty).

rh should accept a single argument of the same type T that is wrapped in a QFuture returned by the f (that is, f should return QFuture<T>).

Parameters
[in]fA callable that should be executed, taking the arguments args and returning a QFuture<T> for some T.
[in]rhA callable that will be invoked when the future finishes, that should be callable with a single argument of type T.
[in]parentThe parent object for all QObject-derived classes created in this function, may be a nullptr.
[in]argsThe arguments to be passed to the callable f.

Definition at line 112 of file futures.h.

Referenced by LeechCraft::Util::NetworkDiskCache::expire(), and LeechCraft::Util::XDG::ItemsFinder::update().

+ Here is the caller graph for this function:

void LeechCraft::Util::ExecuteLater ( const DelayedExecutor::Actor_f &  actor,
int  delay = 0 
)
inline

Definition at line 93 of file delayedexecutor.h.

template<typename T , template< typename U > class Container, typename F >
auto LeechCraft::Util::Filter ( const Container< T > &  c,
f 
) -> Container<T>

Definition at line 169 of file prelude.h.

UTIL_SYS_API QString LeechCraft::Util::FindInSystemPath ( const QString &  name,
const QStringList &  paths,
const std::function< bool(QFileInfo)> &  filter = std::function< bool(QFileInfo)>() 
)

Searches for a file in system paths according to a filter.

This function searches for a file named name in system paths passed in paths and returns the full path for the first file that matches filter, or an empty string if nothing is found.

paths are most possibly obtained via GetSystemPaths(), but an arbitrary set of paths is fine too.

Parameters
[in]nameThe name of the file to search for.
[in]pathsThe paths to search in.
[in]filterThe filter function for the candidates.
Returns
The full path to the first found file or an empty string.

Definition at line 114 of file paths.cpp.

QString LeechCraft::Util::FromStdString ( const std::string &  str)
inline

An utility function that creates a QString from UTF8-encoded std::string.

Parameters
[in]strThe UTF-8 encoded std::string.
Returns
The QString containing the same string.

Definition at line 54 of file util.h.

QString LeechCraft::Util::GetAsBase64Src ( const QImage &  image)

Returns the given image in a Base64-encoded form.

The return result is suitable for inserting into <img>'s src attribute as is.

Parameters
[in]imageThe image to represent as Base64-encoded form.
Returns
The source string.

Definition at line 54 of file util.cpp.

UTIL_XPC_API QList< QObject * > LeechCraft::Util::GetDataFilters ( const QVariant &  data,
IEntityManager manager 
)

Returns the data filter plugins that can handle data.

This function queries all available data filters plugins if they can handle data and returns the list of object instances that can handle it. The object instances are guaranteed to implement the IDataFilter interface as well as IEntityHandler interface.

The manager is used to obtain the list of plugins. It can be obtained from the ICoreProxy_ptr object that is passed to your plugin's Init() function.

Parameters
[in]dataThe data to query.
[in]managerThe manager used to get the plugins.
Returns
The list of data filters that can handle data.

Definition at line 94 of file util.cpp.

References IEntityManager::GetPossibleHandlers(), and MakeEntity().

+ Here is the call graph for this function:

template<typename TagGetter , typename TagSetter >
QDomElement LeechCraft::Util::GetElementForTags ( const QStringList &  tags,
QDomNode &  node,
QDomDocument &  document,
const QString &  elementName,
TagGetter  tagGetter,
TagSetter  tagSetter 
)

Returns an element for a given tags list.

This function tries to implement projection from tags to a hierarchical structure in form of XML. It traverses the tags list and creates child nodes from the document, appending the hierarchical structure's tree root to the node. It returns the parent element to which the item should be appended.

For empty tags list it just returns node converted to the QDomElement.

tagSetter is a function or functor that should be able to take two parameters, a QDomElement and a QString, and set tags for it.

tagGetter is a function or functor that should be able to take one parameter, a QDomElement, and return a QString for it with tags previously set with tagSetter.

Parameters
[in]tagsList of tags.
[in]nodeThe parent-most node to which all other nodes are appended.
[in]documentThe document containing all these nodes.
[in]elementNameThe name of the XML element that carries info about the tags.
[in]tagSetterSetter function for the tags for the given element.
[in]tagGetterGetter function for the tags for the given element.
Returns
Parent element of the item with tags.

Definition at line 219 of file util.h.

QString LeechCraft::Util::GetInternetLocaleName ( const QLocale &  locale)

Definition at line 222 of file util.cpp.

QString LeechCraft::Util::GetLanguage ( )

Returns the current language name.

This function works as GetLocaleName() except it doesn't return (and doesn't query for) country name.

Returns
Current language name.
See Also
GetLocaleName()

Definition at line 232 of file util.cpp.

References GetLocaleName().

+ Here is the call graph for this function:

QString LeechCraft::Util::GetLocaleName ( )

Returns the current locale name, like en_US.

First, this function checks the locale value stored in "Language" key of settings object with organizationName() and applicationName(). If it's equal to "system", this function queries the LANG environment variable, and if it is empty or in invalid format (not like en_US), it takes the value of QLocale::system().name().

Then, if the resulting name the name of the language only, GetLocaleName() tries to find any countries for that language. If any countries are found, the code of the first found country is appended, else "_00" is appended.

Returns
Current locale name.
See Also
GetLanguage()

Definition at line 191 of file util.cpp.

Referenced by GetLanguage(), and InstallTranslator().

+ Here is the caller graph for this function:

UTIL_XPC_API QString LeechCraft::Util::GetPassword ( const QString &  keyName,
const QString &  dialogText,
const ICoreProxy_ptr proxy,
bool  useStore = true 
)

Returns password for the key, possibly asking the user.

This function returns password for the given keyName and using the given emitter object. The password is typically stored in a storage plugin like SecMan.

If the password isn't found in any password stores (or there are no password stores) or useStore is set to false, this function asks the user for the password instead using the dialogText for the dialog and returns the user input instead. If user has canceled the dialog it returns an null string. Otherwise, if the user has entered some text this function automatically stores the password under the keyName.

The emitter object is used to send the corresponding internal Entity objects around, so it should have its gotEntity() and delegateEntity() signals both relayed to the corresponding plugin instance object.

Note
Despite the name this function can be used to retrieve arbitrary string data saved via SavePassword().
Parameters
[in]keyNameThe name of the key uniquely identifying the password.
[in]dialogTextThe text of the dialog to present to the user if the password isn't found or useStore is false.
[in]emitterThe object used to emit the gotEntity() and delegateEntity() signals.
[in]useStoreWhether stored password should be used at all. Calling code may explicitly set this to false if the saved password is known to be invalid, for instance.
Returns
The password or a null string.
See Also
SavePassword()

Definition at line 77 of file passutils.cpp.

References SavePassword().

+ Here is the call graph for this function:

UTIL_SYS_API QStringList LeechCraft::Util::GetPathCandidates ( SysPath  path,
QString  subfolder 
)

Returns possible full paths for the path and subfolder.

This function returns a list of paths formed as the given root path identified by path plus the subfolder in it. The paths in the returned list aren't checked for existence.

For example, on Linux

const auto& paths = GetPathCandidates (SysPath::Share, "flags");

will return { "/usr/share/leechcraft/flags", "/usr/local/share/leechcraft/flags" }.

The subfolder can actually be a relative path, like flags/countries, not just a single subfolder name.

This function hardly needs to be called from user code, consider using GetSysPath() instead.

Parameters
[in]pathThe root path.
[in]subfolderThe subfolder inside the root path.
Returns
The list of possible paths to the subfolder in the root path identified by path.
See Also
GetSysPath()

Definition at line 53 of file paths.cpp.

References QML, and Share.

Referenced by GetSysPath(), and LeechCraft::Util::UnhideListViewBase::UnhideListViewBase().

+ Here is the caller graph for this function:

UTIL_XPC_API QVariant LeechCraft::Util::GetPersistentData ( const QByteArray &  key,
const ICoreProxy_ptr proxy 
)

Returns persistent data stored under given key.

The persistent data itself is stored in plugins implementing the IPersistentStoragePlugin interface. This function uses the passed proxy to get the list of those.

If no data is found under the given key, a null QVariant is returned.

Parameters
[in]keyThe key to look for.
[in]proxyThe ICoreProxy object for getting the list of persistent storage plugins.
Returns
The data stored under the given key as a QVariant, or a null QVariant of no data is found (and, particularly, if no storage plugins are available).
See Also
IPersistentStoragePlugin

Definition at line 148 of file util.cpp.

UTIL_XPC_API QList< ANFieldData > LeechCraft::Util::GetStdANFields ( const QString &  category)
QModelIndexList LeechCraft::Util::GetSummarySelectedRows ( QObject *  sender)

Definition at line 237 of file util.cpp.

UTIL_SYS_API QString LeechCraft::Util::GetSysPath ( SysPath  path,
const QString &  subfolder,
const QString &  filename 
)

Returns path to the file in the given root path and subfolder.

This function returns path to a file named filename and located in the path specified by path + subfolder. It actually checks whether the file exists and if it doesn't, returns a null string instead.

If LeechCraft is running on a system where multiple paths correspond to a single path, they are checked from more user-accessible to less user-accessible. For example, SysPath::Share corresponds to /usr/local/share/leechcraft and then /usr/share/leechcraft.

The subfolder can actually be a relative path, like flags/countries, not just a single subfolder name.

Refer to GetPathCandidates() for more information.

Parameters
[in]pathThe identifier of the root path.
[in]subfolderThe subfolder inside the path.
[in]filenameThe filename inside the path + subfolder.
Returns
Path to the filename located in path + subfolder, or an empty string if there is no such file.
See Also
GetPathCandidates()
GetSysPathUrl()

Definition at line 91 of file paths.cpp.

References GetPathCandidates().

Referenced by GetSysPathUrl(), and LeechCraft::Util::UnhideListViewBase::UnhideListViewBase().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

UTIL_SYS_API QUrl LeechCraft::Util::GetSysPathUrl ( SysPath  path,
const QString &  subfolder,
const QString &  filename 
)

Returns path to the file in the given root path and subfolder.

This function behaves exactly like GetSysPath(), but it returns the path as QUrl via the QUrl::fromLocalFile, so it is suitable, for example, for QML views.

Parameters
[in]pathThe identifier of the root path.
[in]subfolderThe subfolder inside the path.
[in]filenameThe filename inside the path + subfolder.
Returns
Path to the filename located in path + subfolder, or an empty URL if there is no such file.
See Also
GetSysPath()

Definition at line 104 of file paths.cpp.

References GetSysPath().

+ Here is the call graph for this function:

UTIL_SYS_API QStringList LeechCraft::Util::GetSystemPaths ( )

Returns the components of the system PATH variable.

This function gets the PATH variable from the environment, parses it and returns the list of the components to the caller.

Returns
System PATH components.
See Also
FindInSystemPath()

Definition at line 109 of file paths.cpp.

UTIL_SYS_API QString LeechCraft::Util::GetTemporaryName ( const QString &  pattern = QString("lc_temp.XXXXXX"))

Returns a temporary filename.

This function returns a name of a temporary file that could be created, not creating the file itself.

Parameters
[in]patternPattern of the filename.
Returns
The filename.

Definition at line 186 of file paths.cpp.

Referenced by LeechCraft::Util::DownloadHandler::DownloadHandler().

+ Here is the caller graph for this function:

UTIL_SYS_API QDir LeechCraft::Util::GetUserDir ( UserDir  dir,
const QString &  subpath 
)

Definition at line 132 of file paths.cpp.

References Cache, and LC.

QString LeechCraft::Util::GetUserText ( const Entity &  entity)

Return the user-readable representation of the entity.

Parameters
[in]entityThe Entity from which to make the user-readable representation.
Returns
The user-readable string describing the entity.

Definition at line 63 of file util.cpp.

References LeechCraft::Entity::Additional_, LeechCraft::Entity::Entity_, and LeechCraft::Entity::Mime_.

uintptr_t LeechCraft::Util::Handle2Num ( Qt::HANDLE  handle)

Converts the handle to an integer.

Different handles are mapped to different integers. This way a handle can be used, for example, as a part of a DB connection ID string.

Parameters
[in]handleThe handle to convert.
Returns
The integer representation of the handle.

Definition at line 318 of file util.cpp.

UTIL_SYS_API bool LeechCraft::Util::HasSupportedImageExtension ( const QString &  filename)

Checks if the given filename has a known image extension.

This function checks if the filename has an extension matching any image format known to QImageWriter.

Parameters
[in]filenameThe name of the file, either relative or absolute.
Returns
Whether the filename has a known image suffix.

Definition at line 38 of file util.cpp.

UTIL_XPC_API void LeechCraft::Util::InitJobHolderRow ( const QList< QStandardItem * > &  row)
QTranslator * LeechCraft::Util::InstallTranslator ( const QString &  base,
const QString &  prefix = "leechcraft",
const QString &  appname = "leechcraft" 
)

Loads and installs a translator.

Attempts to load and install a translator for the current locale. The name is formed like this: 'prefix_' + base + '_' + locale If base is an empty string, the second _ isn't appended.

First resources are searched (:/), then APPDIR/translations on Windows and /usr/[local/]share/appname/translations on Unix.

Parameters
[in]baseBase name of the translation file.
[in]prefixThe optional prefix of the translation (useful if it's not LC's one).
[in]appnameBase name of the application.
Returns
The translator object if loading is successful, NULL otherwise.

Definition at line 171 of file util.cpp.

References GetLocaleName(), and LoadTranslator().

+ Here is the call graph for this function:

template<typename F , typename... Args>
auto LeechCraft::Util::Invoke ( F &&  f,
Args &&...  args 
) -> decltype (std::forward<F> (f) (std::forward<Args> (args)...))

Definition at line 39 of file oldcppkludges.h.

Referenced by Map(), LeechCraft::Util::Introspectable::Register(), and LeechCraft::Util::SlotClosure< FireDestrPolicy >::run().

+ Here is the caller graph for this function:

template<typename Base , typename Real , typename Res >
auto LeechCraft::Util::Invoke ( Res Base::*  mem,
Real &&  obj,
typename std::enable_if<!std::is_member_function_pointer< decltype(mem)>::value >::type *  = nullptr 
) -> decltype (obj.*mem)

Definition at line 45 of file oldcppkludges.h.

template<typename Base , typename Real , typename Res >
auto LeechCraft::Util::Invoke ( Res Base::*  mem,
Real &&  obj 
) -> decltype ((obj.*mem) ())

Definition at line 52 of file oldcppkludges.h.

QTranslator * LeechCraft::Util::LoadTranslator ( const QString &  base,
const QString &  locale,
const QString &  prefix = "leechcraft",
const QString &  appname = "leechcraft" 
)

Definition at line 129 of file util.cpp.

Referenced by InstallTranslator().

+ Here is the caller graph for this function:

template<template< typename Pair, typename...Rest > class Cont, template< typename K, typename V > class Pair, typename K , typename V , typename KV , typename... Rest>
boost::optional<V> LeechCraft::Util::Lookup ( const KV &  key,
const Cont< Pair< K, V >, Rest...> &  cont 
)

Definition at line 217 of file prelude.h.

UTIL_XPC_API Entity LeechCraft::Util::MakeAN ( const QString &  header,
const QString &  text,
Priority  priority,
const QString &  senderID,
const QString &  cat,
const QString &  type,
const QString &  id,
const QStringList &  visualPath,
int  delta = 1,
int  count = 0,
const QString &  fullText = QString(),
const QString &  extendedText = QString() 
)

Creates an Advanced Notifications-enabled notify entity.

Returns an entity with the given header, text and a bunch of other parameters that can be handled by Advanced Notifications.

The returned entity will also be handled by a visual notifications plugin if AN is not present. To avoid this set the MIME type of the result to x-leechcraft/notification+advanced.

Refer to the hand-written documentation for more information about using Advanced Notifications.

Parameters
[in]headerThe header of the notification. This field will also be used if AN is not present.
[in]textThe text of the notification. This field will also be used if AN is not present.
[in]priorityThe priority of this notification.
[in]senderIDThe ID of the plugin sending this notification.
[in]catThe category of this notification (one of Cat constants in interfaces/an/constants.h).
[in]typeThe type of this notification (one of Type constants in interfaces/an/constants.h).
[in]idThe ID of this notification, used to group consecutive notifications about similar events like incoming message from the same IM contact.
[in]visualPathThe list of names for a menu-like structure wishing to show this notification.
[in]deltaThe change of count of events with this id, or 0 to use count.
[in]countThe total count of events with this id, used if delta is 0.
[in]fullTextThe full text of this notification. If null, the text parameter is used.
[in]extendedTextThe extended text of this notification. If null, the text parameter is used.
See Also
MakeANCancel()
MakeANRule()

Definition at line 46 of file util.cpp.

References LeechCraft::AN::EF::Count, LeechCraft::AN::EF::DeltaCount, LeechCraft::AN::EF::EventCategory, LeechCraft::AN::EF::EventID, LeechCraft::AN::EF::EventType, LeechCraft::AN::EF::ExtendedText, LeechCraft::AN::EF::FullText, MakeNotification(), LeechCraft::AN::EF::SenderID, and LeechCraft::AN::EF::VisualPath.

+ Here is the call graph for this function:

UTIL_XPC_API Entity LeechCraft::Util::MakeANCancel ( const Entity &  event)

Makes an event for canceling another Advanced Notifications event.

Creates an Entity that cancels a previously generated Advanced Notifications event. The returned entity can be then emitted to notify plugins that the given event has been canceled.

Parameters
[in]eventThe event to cancel.
Returns
The Entity canceling the given event.

Definition at line 130 of file util.cpp.

References LeechCraft::Entity::Additional_, LeechCraft::AN::CatEventCancel, LeechCraft::Entity::Entity_, LeechCraft::AN::EF::EventCategory, LeechCraft::AN::EF::EventID, MakeNotification(), LeechCraft::PInfo_, and LeechCraft::AN::EF::SenderID.

+ Here is the call graph for this function:

UTIL_XPC_API Entity LeechCraft::Util::MakeANCancel ( const QString &  senderId,
const QString &  eventId 
)

Makes an event for canceling another Advanced Notifications event.

Creates an Entity that cancels a previously generated Advanced Notifications event. The returned entity can be then emitted to notify plugins that the given event has been canceled.

This function doesn't take a previously created entity as the other overload does. Instead, it plainly creates the required entity from the given senderId and eventId. They should match those of the event in question.

Parameters
[in]senderIdThe ID of the sender of the event that is to be canceled.
[in]eventIdThe ID of the event that is to be canceled.
Returns
The Entity canceling the given event.

Definition at line 139 of file util.cpp.

References LeechCraft::Entity::Additional_, LeechCraft::AN::CatEventCancel, LeechCraft::AN::EF::EventCategory, LeechCraft::AN::EF::EventID, MakeNotification(), LeechCraft::PInfo_, and LeechCraft::AN::EF::SenderID.

+ Here is the call graph for this function:

UTIL_XPC_API Entity LeechCraft::Util::MakeANRule ( const QString &  title,
const QString &  senderID,
const QString &  category,
const QStringList &  types,
AN::NotifyFlags  flags = AN::NotifyNone,
bool  openConfiguration = false,
const QList< QPair< QString, ANFieldValue >> &  fields = {} 
)

Creates an Entity defining an Advanced Notifications rule.

Returns an entity describing a notifications rule triggering under various conditions, defined by the parameters of this function.

Parameters
[in]titleThe human-readable title of the rule.
[in]senderIDThe plugin ID of the sender (must not be empty).
[in]categoryThe category of the event (must not be empty).
[in]typesThe types of events in the given category. If this list is empty, every event type matches.
[in]flagsThe flags describing the notification behavior for for this rule
[in]openConfigurationWhether the configuration widget for the just created rule should be opened automatically.
[in]fieldsThe list of pairs of a field ID (as in ANFieldData::ID_) and corresponding field value as ANFieldValue.
Returns
The Entity object describing a notifications rule for the passed parameters.
See Also
MakeAN()

Definition at line 67 of file util.cpp.

References LeechCraft::Entity::Additional_, LeechCraft::AN::EF::EventCategory, LeechCraft::AN::EF::EventID, LeechCraft::AN::EF::EventType, LeechCraft::AN::EF::IsSingleShot, MakeNotification(), LeechCraft::AN::EF::NotifyAudio, LeechCraft::AN::NotifyAudio, LeechCraft::AN::EF::NotifyPersistent, LeechCraft::AN::NotifyPersistent, LeechCraft::AN::NotifySingleShot, LeechCraft::AN::EF::NotifyTransient, LeechCraft::AN::NotifyTransient, LeechCraft::AN::EF::OpenConfiguration, LeechCraft::PLog_, and LeechCraft::AN::EF::SenderID.

+ Here is the call graph for this function:

Entity LeechCraft::Util::MakeEntity ( const QVariant &  entity,
const QString &  location,
TaskParameters  tp,
const QString &  mime 
)
UTIL_XPC_API Entity LeechCraft::Util::MakeEntity ( const QVariant &  entity,
const QString &  location,
LeechCraft::TaskParameters  tp,
const QString &  mime = QString() 
)

An utility function to make a Entity.

Creates a Entity that wraps the given entity from given location with parameterrs identified by tp and given mime type (which is null by default).

This function is provided for convenience and is equivalent to manually filling the Entity.

Parameters
[in]entityThe Entity_ field of the Entity.
[in]locationThe Location_ field of the Entity.
[in]tpThe Params_ field of the Entity.
[in]mimeThe Mime_ field of the Entity.
Returns
The resulting Entity.
See Also
Entity, MakeNotification()
template<typename K , typename V >
QMap<K, V> LeechCraft::Util::MakeMap ( std::initializer_list< std::pair< K, V >>  l)

Definition at line 269 of file util.h.

UTIL_XPC_API Entity LeechCraft::Util::MakeNotification ( const QString &  header,
const QString &  text,
Priority  priority 
)

An utility function to make a Entity with notification.

Creates a Entity that holds information about user-visible notification. These notifications have "x-leechcraft/notification" MIME.

You can further customize the returned Entity to suit your exact needs. See the documentation for Entity about such entities.

Parameters
[in]headerThe header of the notification.
[in]textThe text of the notification.
[in]priorityThe priority level of the notification.
Returns
The Entity containing the corresponding notification.
See Also
Entity, MakeEntity()

Definition at line 118 of file util.cpp.

References LeechCraft::Entity::Additional_, LeechCraft::AutoAccept, MakeEntity(), and LeechCraft::OnlyHandle.

Referenced by MakeAN(), MakeANCancel(), and MakeANRule().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString LeechCraft::Util::MakePrettySize ( qint64  sourceSize)

Makes a formatted size from number.

Converts, for example, 1048576 to 1.0 MB.

Parameters
[in]sourceSizeSize in bytes.
Returns
Formatted string.
See Also
SetStrings
MakeTimeFromLong

Definition at line 99 of file util.cpp.

template<typename F >
detail::ScopeGuard<F> LeechCraft::Util::MakeScopeGuard ( const F &  f)

Returns an object performing passed function on scope exit.

The returned object performs the passed function f upon destruction (and, thus, on scope exit).

The object is not copyable and not movable, and otherwise is implementation-defined.

Typical usage:

QSettings settings { "OrgNameName", "AppName" };
settings.beginGroup ();
const auto guard = Util::MakeScopeGuard ([&settings] { settings.endGroup (); });
// ...
Parameters
[in]fThe function to execute on scope exit. Should be a callable without any arguments.
Returns
An object executing f on destruction.

Definition at line 124 of file util.h.

Referenced by LeechCraft::Util::SvcAuth::VkAuthManager::ManageQueue(), and LeechCraft::Util::NetworkDiskCacheGC::RegisterDirectory().

+ Here is the caller graph for this function:

QString LeechCraft::Util::MakeTimeFromLong ( ulong  time)

Makes a formatted time from number.

Converts, for example 256 to 00:04:16.

Parameters
[in]timeTime interval in seconds.
Returns
DateTime object.
See Also
MakePrettySize

Definition at line 118 of file util.cpp.

template<typename T , template< typename U > class Container, typename F >
auto LeechCraft::Util::Map ( const Container< T > &  c,
f 
) -> typename std::enable_if<!std::is_same<void, decltype (Invoke (f, std::declval<T> ()))>::value, WrapType_t<Container<typename std::decay<decltype (Invoke (f, std::declval<T> ()))>::type>>>::type

Definition at line 117 of file prelude.h.

References LeechCraft::Util::detail::Append(), and Invoke().

Referenced by Map(), LeechCraft::Util::ShortcutManager::RegisterGlobalShortcut(), and LeechCraft::Util::ShortcutManager::SetShortcut().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<template< typename...> class Container, typename F , template< typename > class ResultCont = QList, typename... ContArgs>
auto LeechCraft::Util::Map ( const Container< ContArgs...> &  c,
f 
) -> typename std::enable_if<!std::is_same<void, decltype (Invoke (f, *c.begin ()))>::value, WrapType_t<ResultCont<typename std::decay<decltype (Invoke (f, *c.begin ()))>::type>>>::type

Definition at line 127 of file prelude.h.

References LeechCraft::Util::detail::Append(), and Invoke().

+ Here is the call graph for this function:

template<template< typename...> class Container, typename F , typename... ContArgs>
auto LeechCraft::Util::Map ( Container< ContArgs...> &  c,
f 
) -> typename std::enable_if<std::is_same<void, decltype (Invoke (f, *c.begin ()))>::value>::type

Definition at line 137 of file prelude.h.

References Invoke().

+ Here is the call graph for this function:

template<template< typename...> class Container, typename F , typename... ContArgs>
auto LeechCraft::Util::Map ( const Container< ContArgs...> &  c,
f 
) -> typename std::enable_if<std::is_same<void, decltype (Invoke (f, *c.begin ()))>::value>::type

Definition at line 144 of file prelude.h.

References Map().

+ Here is the call graph for this function:

template<typename F >
QList<typename std::decay<typename std::result_of<F (QString)>::type>::type> LeechCraft::Util::Map ( const QStringList &  c,
f 
)

Definition at line 152 of file prelude.h.

References Invoke().

+ Here is the call graph for this function:

UTIL_XSD_API XmlSettingsDialog * LeechCraft::Util::OpenXSD ( const QString &  title,
const QString &  filename,
Util::BaseSettingsManager *  bsm 
)

Opens XML settings dialog for the given XML filename.

The dialog is opened as non-modal and non-blocking and is automatically shown. The dialog is also set to be automatically deleted as soon as it is closed.

Parameters
[in]titleThe title of the dialog.
[in]filenameThe XML settings file to use to build the dialog.
[in]bsmThe instance of BaseSettingsManager to use for storing the settings.
Returns
The XML settings dialog.

Definition at line 40 of file util.cpp.

bool LeechCraft::Util::operator!= ( const ModelIterator &  left,
const ModelIterator &  right 
)

For iterators to not be equal at least either the model, parent index, row or column should be unequal. Traversal index is not taken into account.

Parameters
[in]leftFirst iterator to check for inequality.
[in]rightSecond iterator to check for inequality.
Returns
Whether left and right are equal.

Definition at line 99 of file modeliterator.cpp.

bool LeechCraft::Util::operator== ( const ModelIterator &  left,
const ModelIterator &  right 
)

For iterators to be equal the model, parent index, row and column should all be equal. Traversal index is not taken into account.

Parameters
[in]leftFirst iterator to check for equality.
[in]rightSecond iterator to check for equality.
Returns
Whether left and right are equal.

Definition at line 91 of file modeliterator.cpp.

QVariant LeechCraft::Util::ParseJson ( const QByteArray &  bytes,
const char *  context 
)
inline

Parses JSON content in the given bytearray.

This functions uses QJson on Qt4 (don't forget to link to it!) and Qt's native JSON parsers on Qt5.

Parameters
[in]bytesThe byte array to parse JSON from.
[in]contextThe context string to be used in logging messages.
Returns
The recursive QVariant with JSON contents.

Definition at line 57 of file parsejson.h.

Referenced by ParseJson().

+ Here is the caller graph for this function:

QVariant LeechCraft::Util::ParseJson ( QIODevice *  device,
const char *  context 
)
inline

Utility function parsing JSON from the device.

This function reads all available data from the device and passes it to the other ParseJson() overload.

Parameters
[in]deviceThe device from which JSON-encoded data should be read.
[in]contextThe context string to be used in logging messages.
Returns
The recursive QVariant with JSON contents.

Definition at line 97 of file parsejson.h.

References ParseJson().

+ Here is the call graph for this function:

LeechCraft::Util::Q_DECLARE_FLAGS ( FitFlags  ,
FitFlag   
)
LeechCraft::Util::Rect_ ( size  )

Definition at line 49 of file autoresizemixin.cpp.

UTIL_XPC_API void LeechCraft::Util::SavePassword ( const QString &  password,
const QString &  keyName,
const ICoreProxy_ptr proxy 
)

Saves the password to be retrieved later via GetPassword().

This function stores the password under the given keyName and using the given emitter object. The password is typically stored in a storage plugin like SecMan.

If there are no storage plugins, this function does nothing.

The emitter object is used to send the corresponding internal Entity objects around, so it should have its gotEntity() and delegateEntity() signals both relayed to the corresponding plugin instance object.

Note
Despite the name this function can be used to save arbitrary string data in secure storages like SecMan.
Parameters
[in]passwordThe password string to save.
[in]keyNameThe name of the key uniquely identifying the password.
[in]emitterThe object used to emit the gotEntity() and delegateEntity() signals.
See Also
GetPassword()

Definition at line 96 of file passutils.cpp.

Referenced by GetPassword().

+ Here is the caller graph for this function:

template<typename Executor , typename... Args>
detail::SequenceProxy<typename detail::Sequencer<Executor, Args...>::RetType_t, Executor, Args...> LeechCraft::Util::Sequence ( QObject *  parent,
Executor  f,
Args...  args 
)

Creates a sequencer that allows chaining multiple futures.

This function creates a sequencer object that calls the given executor f with the given args, which must return a QFuture<T> (or throw an exception) or void. The concrete object will be unwrapped from the QFuture<T> and passed to the chained function, if any, and so on. The functors may also return QFuture<void>, in which case the next action is expected to be invokable without any arguments.

If a functor returns void, no further chaining is possible.

The functions are chained via the detail::SequenceProxy::Then() method.

The sequencer object is reference-counted internally, and it invokes the executor f after the last instance of this sequencer is destroyed.

A parent QObject controls the lifetime of the sequencer: as soon as it is destroyed, the sequencer is destroyed as well, and all pending actions are cancelled (note, the currently executing action will still continue to execute). This parameter is optional and may be nullptr.

A sample usage may look like:

[this, &]
{
return QtConcurrent::run ([this, &]
{
const auto& contents = file->readAll ();
file->close ();
file->remove ();
return DoSomethingWith (contents);
});
})
.Then ([this, url, script] (const QString& contents)
{
const auto& result = Parse (contents);
if (result.isEmpty ())
{
qWarning () << Q_FUNC_INFO
<< "empty result for"
<< url;
return;
}
const auto id = DoSomethingSynchronouslyWith (result);
emit gotResult (id);
});
Parameters
[in]parentThe parent object of the sequencer (may be nullptr.
[in]fThe executor to run when chaining is finished.
[in]argsThe arguments to pass to f.
Returns
The sequencer object.
Template Parameters
ExecutorThe type of the executor object.
ArgsThe types of the arguments for the Executor, if any.
See Also
detail::SequenceProxy

Definition at line 442 of file futures.h.

QByteArray LeechCraft::Util::SerializeJson ( const QVariant &  var,
bool  compact = true 
)
inline

Serializes the given var to JSON representation.

This function abstracts away differences between Qt4 and Qt5. It uses QJson on Qt4 (don't forget to link to it!) and native JSON functions on Qt5.

Parameters
[in]varThe recursive variant to be serialized to JSON.
[in]compactWhether the output should be compacitified (this parameter may have no effect).
Returns
The serialized representation of var.

Definition at line 55 of file serializejson.h.

UTIL_XPC_API void LeechCraft::Util::SetJobHolderProgress ( const QList< QStandardItem * > &  row,
qint64  done,
qint64  total,
const QString &  text 
)

Sets the progress values on the given row.

This function first retrieves the QStandardItem object at the position defined by JobHolderColumn::JobProgress in the passed row and then sets its text to text and updates the ProcessStateInfo structure under the JobHolderRole::ProcessState role to have the given amount of done and total.

Parameters
[in]rowThe row to set data on.
[in]doneThe amount of work done.
[in]totalThe total amount of work.
[in]textThe text that the progress-related item should have in the row.
See Also
ProcessStateInfo

Definition at line 166 of file util.cpp.

References LeechCraft::JobProgress.

UTIL_XPC_API void LeechCraft::Util::SetJobHolderProgress ( QStandardItem *  item,
qint64  done,
qint64  total 
)

Sets the done and total progress values on the given item.

This function updates the ProcessStateInfo structure stored under the JobHolderRole::ProcessState role in the given item.

Parameters
[in]itemThe item to set data on.
[in]doneThe amount of work done.
[in]totalThe total amount of work.
See Also
ProcessStateInfo

Definition at line 177 of file util.cpp.

References LeechCraft::ProcessStateInfo::Done_, and LeechCraft::ProcessState.

template<template< typename > class Container, typename T >
Container<Container<T> > LeechCraft::Util::SplitInto ( size_t  numChunks,
const Container< T > &  container 
)

Definition at line 195 of file prelude.h.

template<template< typename K, typename V > class PairType = std::pair, typename Assoc >
auto LeechCraft::Util::Stlize ( Assoc &&  assoc) -> detail::StlAssocRange<decltype (assoc.begin ()), Assoc, PairType>

Converts an Qt's associative sequence assoc to an STL-like iteratable range.

This function takes an associative container assoc (one of Qt's containers like QHash and QMap) and returns a range with value_type equal to PairType<K, V>.

This way, both the key and the value of each pair in the assoc can be accessed in a range-for loop, for example.

Example usage:

for (const auto& pair : Util::Stlize (someMap))
qDebug () << pair.first // outputs a QString key
<< pair.second; // outputs an integer value corresponding to the key

All kinds of accesses are supported: elements of a non-const container may be modified via the iterators in the returned range.

Parameters
[in]assocThe Qt's associative container to iterate over.
Returns
A range with iterators providing access to both the key and the value via its value_type.
Template Parameters
PairTypeThe type of the pairs that should be used in the resulting range's iterators' value_type.
AssocThe type of the source Qt associative container.

Definition at line 126 of file qtutil.h.

References Escape(), and UTIL_SLL_API.

Referenced by LeechCraft::Util::WkFontsWidget::accept(), LeechCraft::Util::MassFontChangeDialog::GetFamilies(), and LeechCraft::Util::WkFontsWidget::RegisterSettable().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void LeechCraft::Util::swap ( FDGuard &  g1,
FDGuard &  g2 
)

Definition at line 74 of file fdguard.cpp.

template<typename T1 , typename T2 , template< typename U > class Container, template< typename U1, typename U2 > class Pair = QPair>
auto LeechCraft::Util::Zip ( const Container< T1 > &  c1,
const Container< T2 > &  c2 
) -> Container<Pair<T1, T2>>

Definition at line 61 of file prelude.h.

References ZipWith().

+ Here is the call graph for this function:

template<typename T1 , typename T2 , template< typename U > class Container, typename F >
auto LeechCraft::Util::ZipWith ( const Container< T1 > &  c1,
const Container< T2 > &  c2,
f 
) -> Container<typename std::result_of<F (T1, T2)>::type>

Definition at line 44 of file prelude.h.

Referenced by Zip().

+ Here is the caller graph for this function:

Variable Documentation

struct { ... } LeechCraft::Util::Apply
LeechCraft::Util::E_ { e }

Definition at line 96 of file downloadhandler.cpp.

LeechCraft::Util::iem

Definition at line 60 of file downloadhandler.cpp.

LeechCraft::Util::parent
Initial value:
{
}
DownloadHandler::DownloadHandler (const QUrl& url,
const DataHandler_t& cont,
QObject *parent)
: DownloadHandler { url, {}, iem, cont, parent }
{
}
DownloadHandler::DownloadHandler (const Entity& e,
const EntityHandler_t& cont,
QObject *parent)
: QObject { parent }
Proxy to core entity manager.

Definition at line 80 of file downloadhandler.cpp.

Referenced by LeechCraft::Util::ModelItemBase< ModelItem >::GetRow().

const int LeechCraft::Util::StateAdd = 1
const int LeechCraft::Util::StateRemove = 0