LeechCraft 0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
actionresultreporter.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
10#include <QApplication>
11#include <QMessageBox>
13#include <util/sll/visitor.h>
14#include <util/xpc/util.h>
15
16namespace LC::Util
17{
18 using namespace std::chrono_literals;
19
20 namespace
21 {
22 QDeadlineTimer GetDeadlineTimer (ActionResultReporter::BackgroundPolicy policy)
23 {
24 return Visit (policy,
25 [] (const ActionResultReporter::TimeoutBackgroundPolicy& policy) { return QDeadlineTimer { policy.Timeout_ }; },
26 [] (const auto&) { return QDeadlineTimer { QDeadlineTimer::Forever }; });
27 }
28 }
29
31 : IEM_ { iem }
32 , Context_ { config.Context_ }
33 , Priority_ { config.Priority_ }
34 , Parent_ { parent }
35 , TimerBackground_ { GetDeadlineTimer (config.BackgroundPolicy_) }
36 {
38 [] (const TimeoutBackgroundPolicy&) {},
39 [this] (const auto&)
40 {
41 InitialFocus_ = qApp->focusWidget ();
42 });
43 }
44
45 void ActionResultReporter::operator() (const QString& error)
46 {
47 const auto isBackground = FocusChanged () || TimerBackground_.hasExpired () || (!Parent_ && HadParent_);
48
49 if (isBackground)
50 IEM_.HandleEntity (MakeNotification (Context_, error, Priority_));
51 else
52 switch (Priority_)
53 {
54 case Priority::Info:
55 QMessageBox::information (Parent_, Context_, error);
56 break;
58 QMessageBox::warning (Parent_, Context_, error);
59 break;
61 QMessageBox::critical (Parent_, Context_, error);
62 break;
63 }
64 }
65
66 bool ActionResultReporter::FocusChanged () const
67 {
68 if (!InitialFocus_ || !*InitialFocus_)
69 return false;
70
71 const auto curFocus = qApp->focusWidget ();
72 return InitialFocus_ != curFocus;
73 }
74}
Proxy to core entity manager.
ActionResultReporter(IEntityManager &iem, Config config, QWidget *parent=nullptr)
std::variant< DefaultBackgroundPolicy, FocusBackgroundPolicy, std::chrono::milliseconds > BackgroundPolicy
Entity MakeNotification(const QString &header, const QString &text, Priority priority)
An utility function to make a Entity with notification.
Definition util.cpp:95
auto Visit(const Either< Left, Right > &either, Args &&... args)
Definition either.h:180