Albert
Loading...
Searching...
No Matches
albert::util Namespace Reference

Classes

class  BackgroundExecutor
 Provides a lean interface for recurring indexing tasks. More...
 
class  FileDownloader
 
class  IndexItem
 An item utlized by ItemIndex. More...
 
class  IndexQueryHandler
 Index query handler class. More...
 
class  InputHistory
 Input history class. More...
 
class  Match
 Augmented match score. More...
 
class  MatchConfig
 Configuration for string matching. More...
 
class  Matcher
 Configurable string matcher. More...
 
class  Notification
 The notification class. More...
 
class  OAuth2
 Provides OAuth2 authentication with support for the Authorization Code Flow with PKCE and refresh tokens. More...
 
class  OAuthConfigWidget
 
class  StandardItem
 General purpose value type Item implememtation. More...
 

Functions

QPixmap pixmapFromUrl (const QString &url, const QSize &requestedSize)
 URL based icon factory.
 
QPixmap pixmapFromUrls (const QStringList &urls, const QSize &requestedSize)
 URL list based icon factory.
 
QIcon iconFromUrl (const QString &url)
 URL based icon factory.
 
QIcon iconFromUrls (const QStringList &urls)
 URL list based icon factory.
 
QPixmap genericPixmap (int size, const QColor &bgcolor={}, const QColor &fgcolor=Qt::black, const QString &text={}, float scalar=1.)
 Generic pixmap factory.
 
QIcon genericIcon (const QColor &bgcolor={}, const QColor &fgcolor=Qt::black, const QString &text={}, float scalar=1.)
 Generic icon factory.
 
QIcon fileIcon (const QString &path)
 Create an icon for a file using QFileIconProvider.
 
const QRegularExpression default_separator_regex (QStringLiteral("([\\s\\\\/\\-\\[\\](){}#!?<>\"'=+*.:,;_]+)"))
 
QMessageBox::StandardButton question (const QString &text, QMessageBox::StandardButtons buttons=QMessageBox::StandardButtons(QMessageBox::Yes|QMessageBox::No), QMessageBox::StandardButton default_button=QMessageBox::NoButton)
 Shows a question message box containing text with the given buttons and default_button.
 
QMessageBox::StandardButton information (const QString &text, QMessageBox::StandardButtons buttons=QMessageBox::Ok, QMessageBox::StandardButton default_button=QMessageBox::NoButton)
 Shows an information message box containing text with the given buttons and default_button.
 
QMessageBox::StandardButton warning (const QString &text, QMessageBox::StandardButtons buttons=QMessageBox::Ok, QMessageBox::StandardButton default_button=QMessageBox::NoButton)
 Shows a warning message box containing text with the given buttons and default_button.
 
QMessageBox::StandardButton critical (const QString &text, QMessageBox::StandardButtons buttons=QMessageBox::Ok, QMessageBox::StandardButton default_button=QMessageBox::NoButton)
 Shows a critical message box containing text with the given buttons and default_button.
 
QNetworkAccessManager & network ()
 Returns a global, threadlocal QNetworkAccessManager.
 
QNetworkReply * await (QNetworkReply *reply)
 Blocks until reply is finished.
 
QNetworkRequest makeRestRequest (const QString &base_url, const QString &path, const QUrlQuery &query, const QByteArray &authorization_header)
 
void openUrl (const QString &url)
 Opens url with the default handler for the scheme.
 
void open (const QUrl &url)
 Opens url with the default handler for the scheme.
 
void open (const QString &path)
 Opens a file at path with the associated default application.
 
void open (const std::filesystem::path &path)
 Opens a file at path with the associated default application.
 
void setClipboardText (const QString &text)
 Sets the system clipboard to text.
 
bool havePasteSupport ()
 Returns the true if the platform supports pasting, else false.
 
void setClipboardTextAndPaste (const QString &text)
 Sets the system clipboard to text and pastes text to the front-most window.
 
long long runDetachedProcess (const QStringList &commandline)
 Run the commandline as detached process. Returns the process id.
 
long long runDetachedProcess (const QStringList &commandline, const QString &working_dir)
 Run the commandline with working_dir as detached process. Returns the process id.
 
void tryCreateDirectory (const std::filesystem::path &path)
 Tries to create a directory at path.
 

Function Documentation

◆ await()

QNetworkReply * albert::util::await ( QNetworkReply *  reply)

Blocks until reply is finished.

◆ critical()

QMessageBox::StandardButton albert::util::critical ( const QString &  text,
QMessageBox::StandardButtons  buttons = QMessageBox::Ok,
QMessageBox::StandardButton  default_button = QMessageBox::NoButton 
)

Shows a critical message box containing text with the given buttons and default_button.

The message box modal will appear modal to the main window and have the app name as title.

Returns the button pressed by the user.

◆ default_separator_regex()

const QRegularExpression albert::util::default_separator_regex ( QStringLiteral("([\\s\\\\/\\-\\[\\](){}#!?<>\"'=+*.:,;_]+)")  )

◆ fileIcon()

QIcon albert::util::fileIcon ( const QString &  path)

Create an icon for a file using QFileIconProvider.

Parameters
pathThe path to the file.
Returns
The file icon.

◆ genericIcon()

QIcon albert::util::genericIcon ( const QColor &  bgcolor = {},
const QColor &  fgcolor = Qt::black,
const QString &  text = {},
float  scalar = 1. 
)

Generic icon factory.

Supports drawing a background circle with some text on it.

Parameters
bgcolorThe background color. Default: none.
fgcolorThe text color. Default: black.
textThe text to display. Default: empty.
scalarScalar for the default font size which is the pixmap height. Default: 1.
Returns
The generic pixmap.

◆ genericPixmap()

QPixmap albert::util::genericPixmap ( int  size,
const QColor &  bgcolor = {},
const QColor &  fgcolor = Qt::black,
const QString &  text = {},
float  scalar = 1. 
)

Generic pixmap factory.

Supports drawing a background circle with some text on it.

Parameters
bgcolorThe background color. Default: none.
fgcolorThe text color. Default: black.
textThe text to display. Default: empty.
scalarScalar for the default font size which is the pixmap height. Default: 1.
Returns
The generic icon.

◆ havePasteSupport()

bool albert::util::havePasteSupport ( )

Returns the true if the platform supports pasting, else false.

◆ iconFromUrl()

QIcon albert::util::iconFromUrl ( const QString &  url)

URL based icon factory.

Parameters
urlThe icon URL.
Returns
The icon, if available, null icon otherwise.

◆ iconFromUrls()

QIcon albert::util::iconFromUrls ( const QStringList urls)

URL list based icon factory.

See iconFromUrl(const QString &url).

Parameters
urlsThe icon URLs.
Returns
The first icon available in the urls list. Null icon otherwise.

◆ information()

QMessageBox::StandardButton albert::util::information ( const QString &  text,
QMessageBox::StandardButtons  buttons = QMessageBox::Ok,
QMessageBox::StandardButton  default_button = QMessageBox::NoButton 
)

Shows an information message box containing text with the given buttons and default_button.

The message box modal will appear modal to the main window and have the app name as title.

Returns the button pressed by the user.

◆ makeRestRequest()

QNetworkRequest albert::util::makeRestRequest ( const QString &  base_url,
const QString &  path,
const QUrlQuery &  query,
const QByteArray &  authorization_header 
)

◆ network()

QNetworkAccessManager & albert::util::network ( )

Returns a global, threadlocal QNetworkAccessManager.

◆ open() [1/3]

void albert::util::open ( const QString &  path)

Opens a file at path with the associated default application.

◆ open() [2/3]

void albert::util::open ( const QUrl &  url)

Opens url with the default handler for the scheme.

◆ open() [3/3]

void albert::util::open ( const std::filesystem::path &  path)

Opens a file at path with the associated default application.

◆ openUrl()

void albert::util::openUrl ( const QString &  url)

Opens url with the default handler for the scheme.

Does nothing if url is not a valid URL.

◆ pixmapFromUrl()

QPixmap albert::util::pixmapFromUrl ( const QString &  url,
const QSize &  requestedSize 
)

URL based icon factory.

Supported URL schemes:

  • <path> or
  • file:<path> Use the file at path as icon.
  • :<path> or
  • qrc:<path> Use the file at path in the resource collection as icon.
  • qfip:<path> Uses fileIcon(const QString &path)
  • qsp:<pixmap enumerator> Get an icon from QStyle::StandardPixmap enum.
  • xdg:<icon name> Uses xdgIconLookup(const QString &name);
  • gen:<> Uses genericPixmapFactory. See also QColor::fromString.
  • mask:?src=&radius= Masks a given icon url.
  • comp:?src1=<>&src2=<> Composes two given icons.

Examples

/absolute/path/to/a/local/image/file.png
file:/absolute/path/to/a/local/image/file.png
:path-to-a-qresource-file
qrc:path-to-a-qresource-file
qfip:/path/to/any/file/for/example/a.pdf
qsp:SP_TrashIcon
xdg:some-themed-icon-name
gen:?background=blue&foreground=red&text=Hi&fontscalar=0.5
Parameters
urlThe icon URL.
requestedSizeThe size the pixmap should have if possible.
Returns
The pixmap, if available, null pixmap otherwise. The size can be smaller than requestedSize, but is never larger.

◆ pixmapFromUrls()

QPixmap albert::util::pixmapFromUrls ( const QStringList urls,
const QSize &  requestedSize 
)

URL list based icon factory.

See pixmapFromUrl(const QString &url, QSize *size, const QSize &requestedSize).

Parameters
urlsThe icon URLs.
requestedSizeThe size the pixmap should have if possible.
Returns
The first pixmap available in the urls list. Null pixmap otherwise.

◆ question()

QMessageBox::StandardButton albert::util::question ( const QString &  text,
QMessageBox::StandardButtons  buttons = QMessageBox::StandardButtons(QMessageBox::Yes|QMessageBox::No),
QMessageBox::StandardButton  default_button = QMessageBox::NoButton 
)

Shows a question message box containing text with the given buttons and default_button.

The message box modal will appear modal to the main window and have the app name as title.

Returns the button pressed by the user.

◆ runDetachedProcess() [1/2]

long long albert::util::runDetachedProcess ( const QStringList commandline)

Run the commandline as detached process. Returns the process id.

◆ runDetachedProcess() [2/2]

long long albert::util::runDetachedProcess ( const QStringList commandline,
const QString &  working_dir 
)

Run the commandline with working_dir as detached process. Returns the process id.

◆ setClipboardText()

void albert::util::setClipboardText ( const QString &  text)

Sets the system clipboard to text.

◆ setClipboardTextAndPaste()

void albert::util::setClipboardTextAndPaste ( const QString &  text)

Sets the system clipboard to text and pastes text to the front-most window.

Check albert::havePasteSupport before using this function.

◆ tryCreateDirectory()

void albert::util::tryCreateDirectory ( const std::filesystem::path &  path)

Tries to create a directory at path.

Throws std::runtime_error if the directory could not be created. This is a utility function for use with the *Location functions.

◆ warning()

QMessageBox::StandardButton albert::util::warning ( const QString &  text,
QMessageBox::StandardButtons  buttons = QMessageBox::Ok,
QMessageBox::StandardButton  default_button = QMessageBox::NoButton 
)

Shows a warning message box containing text with the given buttons and default_button.

The message box modal will appear modal to the main window and have the app name as title.

Returns the button pressed by the user.