Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2026 MuseScore Limited
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #include "toastitem.h"
23 :
24 : using namespace muse::toast;
25 :
26 : namespace {
27 : int CURRENT_TOAST_ID = 1;
28 : }
29 :
30 0 : ToastItem::ToastItem(const std::string& title, const std::string& message, muse::ui::IconCode::Code iconCode, bool dismissible,
31 0 : std::chrono::seconds timeout, std::vector<ToastAction> actions)
32 0 : : m_id(CURRENT_TOAST_ID++),
33 0 : m_title(title),
34 0 : m_message(message),
35 0 : m_iconCode(iconCode),
36 0 : m_dismissible(dismissible),
37 0 : m_timeout(timeout),
38 0 : m_actions(std::move(actions)),
39 0 : m_showProgressInfo(false)
40 : {
41 0 : }
42 :
43 0 : ToastItem::ToastItem(const std::string& title, const std::string& message, muse::ui::IconCode::Code iconCode, bool dismissible,
44 0 : std::vector<ToastAction> actions, std::shared_ptr<muse::Progress> progress, bool showProgressInfo)
45 0 : : m_id(CURRENT_TOAST_ID++),
46 0 : m_title(title),
47 0 : m_message(message),
48 0 : m_iconCode(iconCode),
49 0 : m_dismissible(dismissible),
50 0 : m_timeout(std::chrono::seconds(0)),
51 0 : m_actions(std::move(actions)),
52 0 : m_progress(std::move(progress)),
53 0 : m_showProgressInfo(showProgressInfo)
54 : {
55 0 : }
56 :
57 0 : int ToastItem::id() const
58 : {
59 0 : return m_id;
60 : }
61 :
62 0 : std::string ToastItem::title() const
63 : {
64 0 : return m_title;
65 : }
66 :
67 0 : std::string ToastItem::message() const
68 : {
69 0 : return m_message;
70 : }
71 :
72 0 : muse::ui::IconCode::Code ToastItem::iconCode() const
73 : {
74 0 : return m_iconCode;
75 : }
76 :
77 0 : std::chrono::seconds ToastItem::timeout() const
78 : {
79 0 : return m_timeout;
80 : }
81 :
82 0 : bool ToastItem::isDismissible() const
83 : {
84 0 : return m_dismissible;
85 : }
86 :
87 0 : const std::vector<ToastAction>& ToastItem::actions() const
88 : {
89 0 : return m_actions;
90 : }
91 :
92 0 : std::shared_ptr<muse::Progress> ToastItem::progress() const
93 : {
94 0 : return m_progress;
95 : }
96 :
97 0 : double ToastItem::currentProgress() const
98 : {
99 0 : return m_currentProgress;
100 : }
101 :
102 0 : void ToastItem::setCurrentProgress(double progress)
103 : {
104 0 : m_currentProgress = progress;
105 0 : m_progressChanged.notify();
106 0 : }
107 :
108 0 : muse::async::Notification ToastItem::progressChanged() const
109 : {
110 0 : return m_progressChanged;
111 : }
112 :
113 0 : bool ToastItem::showProgressInfo() const
114 : {
115 0 : return m_showProgressInfo;
116 : }
117 :
118 0 : int ToastItem::timeElapsed() const
119 : {
120 0 : auto now = std::chrono::steady_clock::now();
121 0 : auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(now - m_creationTime).count();
122 0 : return static_cast<int>(elapsed);
123 : }
|