Changeset View
Changeset View
Standalone View
Standalone View
src/statusnotifier.cpp
Show All 35 Lines | 35 | StatusNotifier::StatusNotifier(QObject *parent) | |||
---|---|---|---|---|---|
36 | : QObject(parent) | 36 | : QObject(parent) | ||
37 | , m_autoCloseTimer(new QTimer(this)) | 37 | , m_autoCloseTimer(new QTimer(this)) | ||
38 | , m_sni(new KStatusNotifierItem(this)) | 38 | , m_sni(new KStatusNotifierItem(this)) | ||
39 | { | 39 | { | ||
40 | CrashedApplication *crashedApp = DrKonqi::crashedApplication(); | 40 | CrashedApplication *crashedApp = DrKonqi::crashedApplication(); | ||
41 | 41 | | |||
42 | // this is used for both the SNI tooltip as well as the notification | 42 | // this is used for both the SNI tooltip as well as the notification | ||
43 | m_title = i18nc("Placeholder is an application name; it crashed", "%1 Closed Unexpectedly", crashedApp->name()); | 43 | m_title = i18nc("Placeholder is an application name; it crashed", "%1 Closed Unexpectedly", crashedApp->name()); | ||
44 | } | ||||
45 | | ||||
46 | StatusNotifier::~StatusNotifier() = default; | ||||
47 | | ||||
48 | bool StatusNotifier::activationAllowed() const | ||||
49 | { | ||||
50 | return m_activationAllowed; | ||||
51 | } | ||||
52 | | ||||
53 | void StatusNotifier::setActivationAllowed(bool allowed) | ||||
54 | { | ||||
55 | m_activationAllowed = allowed; | ||||
56 | } | ||||
57 | | ||||
58 | void StatusNotifier::show() | ||||
59 | { | ||||
60 | CrashedApplication *crashedApp = DrKonqi::crashedApplication(); | ||||
44 | 61 | | |||
45 | // if nobody bothered to look at the crash after 1 minute, just close | 62 | // if nobody bothered to look at the crash after 1 minute, just close | ||
46 | m_autoCloseTimer->setSingleShot(true); | 63 | m_autoCloseTimer->setSingleShot(true); | ||
47 | m_autoCloseTimer->setInterval(60000); | 64 | m_autoCloseTimer->setInterval(60000); | ||
48 | m_autoCloseTimer->start(); | 65 | m_autoCloseTimer->start(); | ||
49 | connect(m_autoCloseTimer, &QTimer::timeout, this, &StatusNotifier::expired); | 66 | connect(m_autoCloseTimer, &QTimer::timeout, this, &StatusNotifier::expired); | ||
50 | connect(this, &StatusNotifier::activated, this, &StatusNotifier::deleteLater); | 67 | connect(this, &StatusNotifier::activated, this, &StatusNotifier::deleteLater); | ||
51 | 68 | | |||
52 | KService::Ptr service = KService::serviceByStorageId(crashedApp->fakeExecutableBaseName()); | | |||
53 | if (service) { | | |||
54 | m_iconName = service->icon(); | | |||
55 | } | | |||
56 | | ||||
57 | m_sni->setTitle(m_title); | 69 | m_sni->setTitle(m_title); | ||
58 | m_sni->setIconByName(QStringLiteral("tools-report-bug")); | 70 | m_sni->setIconByName(QStringLiteral("tools-report-bug")); | ||
59 | m_sni->setStatus(KStatusNotifierItem::Active); | 71 | m_sni->setStatus(KStatusNotifierItem::Active); | ||
60 | m_sni->setCategory(KStatusNotifierItem::SystemServices); | 72 | m_sni->setCategory(KStatusNotifierItem::SystemServices); | ||
61 | m_sni->setToolTip(!m_iconName.isEmpty() ? m_iconName : m_sni->iconName(), m_sni->title(), i18n("Please report this error to help improve this software.")); | 73 | m_sni->setToolTip(m_sni->iconName(), m_sni->title(), i18n("Please report this error to help improve this software.")); | ||
62 | connect(m_sni, &KStatusNotifierItem::activateRequested, this, &StatusNotifier::activated); | 74 | connect(m_sni, &KStatusNotifierItem::activateRequested, this, &StatusNotifier::activated); | ||
63 | 75 | | |||
64 | // you cannot turn off that "Do you really want to quit?" message, so we'll add our own below | 76 | // you cannot turn off that "Do you really want to quit?" message, so we'll add our own below | ||
65 | m_sni->setStandardActionsEnabled(false); | 77 | m_sni->setStandardActionsEnabled(false); | ||
66 | 78 | | |||
67 | QMenu *sniMenu = new QMenu(); | 79 | QMenu *sniMenu = new QMenu(); | ||
68 | QAction *action = new QAction(QIcon::fromTheme(QStringLiteral("tools-report-bug")), | 80 | QAction *action = new QAction(QIcon::fromTheme(QStringLiteral("tools-report-bug")), | ||
69 | i18n("Report &Bug"), nullptr); | 81 | i18n("Report &Bug"), nullptr); | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
119 | }); | 131 | }); | ||
120 | connect(KIdleTime::instance(), &KIdleTime::resumingFromIdle, this, [this] { | 132 | connect(KIdleTime::instance(), &KIdleTime::resumingFromIdle, this, [this] { | ||
121 | if (!m_autoCloseTimer->isActive()) { | 133 | if (!m_autoCloseTimer->isActive()) { | ||
122 | m_autoCloseTimer->start(); | 134 | m_autoCloseTimer->start(); | ||
123 | } | 135 | } | ||
124 | }); | 136 | }); | ||
125 | } | 137 | } | ||
126 | 138 | | |||
127 | StatusNotifier::~StatusNotifier() = default; | | |||
128 | | ||||
129 | void StatusNotifier::notify() | 139 | void StatusNotifier::notify() | ||
130 | { | 140 | { | ||
131 | CrashedApplication *crashedApp = DrKonqi::crashedApplication(); | 141 | CrashedApplication *crashedApp = DrKonqi::crashedApplication(); | ||
132 | 142 | | |||
143 | const QString title = m_activationAllowed ? m_title : crashedApp->name(); | ||||
144 | const QString message = m_activationAllowed ? i18nc("Notification text", "Please report this error to help improve this software.") | ||||
sitter: Please make at least the new string i18nc informing translators that it's a notification… | |||||
I don't think that is neccessary, broulik: I don't think that is neccessary,
The keep short in the buttons was mostly because back then… | |||||
I care more about the context that this is a notification message than about the brevity recommendation. sitter: I care more about the context that this is a notification message than about the brevity… | |||||
We never do that. Do we have a @context for that or should I just write i18nc("Notification text", "...")? broulik: We never do that. Do we have a `@context` for that or should I just write `i18nc("Notification… | |||||
We do not. I always check my handy cheat sheet http://people.ubuntu.com/~apachelogger/misc/i18nccheatsheet.png ;) i18nc("Notification text", "...") lgtm sitter: We do not. I always check my handy cheat sheet http://people.ubuntu. | |||||
145 | : i18nc("Notification text", "The application closed unexpectedly."); | ||||
146 | | ||||
133 | KNotification *notification = KNotification::event(QStringLiteral("applicationcrash"), | 147 | KNotification *notification = KNotification::event(QStringLiteral("applicationcrash"), | ||
134 | m_title, | 148 | title, | ||
135 | i18n("Please report this error to help improve this software."), | 149 | message, | ||
136 | !m_iconName.isEmpty() ? m_iconName : QStringLiteral("tools-report-bug"), | 150 | QStringLiteral("tools-report-bug"), | ||
137 | nullptr, | 151 | nullptr, | ||
138 | KNotification::DefaultEvent | KNotification::SkipGrouping); | 152 | KNotification::DefaultEvent | KNotification::SkipGrouping); | ||
139 | 153 | | |||
140 | QStringList actions = {i18nc("Notification action button, keep short", "Report Bug")}; | 154 | QStringList actions; | ||
141 | 155 | if (m_activationAllowed) { | |||
156 | actions << i18nc("Notification action button, keep short", "Report Bug"); | ||||
157 | } | ||||
142 | if (canBeRestarted(crashedApp)) { | 158 | if (canBeRestarted(crashedApp)) { | ||
143 | actions << i18nc("Notification action button, keep short", "Restart App"); | 159 | actions << i18nc("Notification action button, keep short", "Restart App"); | ||
144 | } | 160 | } | ||
145 | 161 | | |||
146 | notification->setActions(actions); | 162 | notification->setActions(actions); | ||
147 | 163 | | |||
148 | connect(notification, static_cast<void (KNotification::*)(unsigned int)>(&KNotification::activated), | 164 | connect(notification, static_cast<void (KNotification::*)(unsigned int)>(&KNotification::activated), | ||
149 | this, [this, crashedApp](int actionIndex) { | 165 | this, [this, crashedApp](int actionIndex) { | ||
150 | // 0 = default action (NOTE this is not implemented by Plasma, clicking notification popup just closes it) | 166 | if (actionIndex == 1 && m_activationAllowed) { | ||
151 | // 1 = "Report Bug" button | | |||
152 | // 2 = "Restart App" button | | |||
153 | if (actionIndex == 0 || actionIndex == 1) { | | |||
154 | emit activated(); | 167 | emit activated(); | ||
155 | } else if (actionIndex == 2) { | 168 | } else if (canBeRestarted(crashedApp)) { | ||
156 | crashedApp->restart(); | 169 | crashedApp->restart(); | ||
157 | // keep status notifier there to allow reporting a bug when user chose to restart app | | |||
158 | } | 170 | } | ||
159 | }); | 171 | }); | ||
160 | 172 | | |||
161 | // when the SNI disappears you won't be able to interact with the notification anymore anyway, so close it | 173 | // when the SNI disappears you won't be able to interact with the notification anymore anyway, so close it | ||
174 | if (m_activationAllowed) { | ||||
162 | connect(this, &StatusNotifier::activated, notification, &KNotification::close); | 175 | connect(this, &StatusNotifier::activated, notification, &KNotification::close); | ||
163 | connect(this, &StatusNotifier::expired, notification, &KNotification::close); | 176 | connect(this, &StatusNotifier::expired, notification, &KNotification::close); | ||
177 | } else { | ||||
178 | // No SNI means we should quit when the notification is gone | ||||
179 | connect(notification, &KNotification::closed, this, &StatusNotifier::expired); | ||||
180 | } | ||||
164 | } | 181 | } | ||
165 | 182 | | |||
166 | bool StatusNotifier::notificationServiceRegistered() | 183 | bool StatusNotifier::notificationServiceRegistered() | ||
167 | { | 184 | { | ||
168 | return QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.freedesktop.Notifications")); | 185 | return QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.freedesktop.Notifications")); | ||
169 | } | 186 | } | ||
170 | 187 | | |||
171 | bool StatusNotifier::canBeRestarted(CrashedApplication *app) | 188 | bool StatusNotifier::canBeRestarted(CrashedApplication *app) | ||
172 | { | 189 | { | ||
173 | return !app->hasBeenRestarted() && app->fakeExecutableBaseName() != QLatin1String("drkonqi"); | 190 | return !app->hasBeenRestarted() && app->fakeExecutableBaseName() != QLatin1String("drkonqi"); | ||
174 | } | 191 | } |
Please make at least the new string i18nc informing translators that it's a notification message and should be kept brief.