tray
This commit is contained in:
+42
-12
@@ -200,6 +200,7 @@ void Rktwebview_qt::processCommand(Command *cmd)
|
||||
}
|
||||
|
||||
tray->hide();
|
||||
_view_js_callbacks.remove(wv);
|
||||
delete tray;
|
||||
cmd->result = true;
|
||||
} else {
|
||||
@@ -499,26 +500,21 @@ void Rktwebview_qt::processCommand(Command *cmd)
|
||||
QString icon_file = cmd->args[0].toString();
|
||||
QString tooltip = cmd->args[1].toString();
|
||||
|
||||
void *f = cmd->args[2].value<void *>();
|
||||
event_cb_t js_event_cb = reinterpret_cast <event_cb_t>(f);
|
||||
|
||||
int id = nextHandle();
|
||||
|
||||
QSystemTrayIcon *tray = new QSystemTrayIcon(this);
|
||||
tray->setIcon(QIcon(icon_file));
|
||||
tray->setToolTip(tooltip);
|
||||
tray->setProperty("tray-id", id);
|
||||
|
||||
connect(tray, &QSystemTrayIcon::activated,
|
||||
this, [this, id](QSystemTrayIcon::ActivationReason reason) {
|
||||
EventContainer e("tray-activated");
|
||||
e["reason"] = activationReasonToString(reason);
|
||||
this->triggerEvent(id, e);
|
||||
});
|
||||
|
||||
connect(tray, &QSystemTrayIcon::messageClicked,
|
||||
this, [this, id]() {
|
||||
EventContainer e("tray-message-clicked");
|
||||
this->triggerEvent(id, e);
|
||||
});
|
||||
connect(tray, &QSystemTrayIcon::activated, this, &Rktwebview_qt::handleTrayActivation);
|
||||
connect(tray, &QSystemTrayIcon::messageClicked, this, &Rktwebview_qt::handleTrayMessageClick);
|
||||
|
||||
_trays[id] = tray;
|
||||
_view_js_callbacks[id] = js_event_cb;
|
||||
|
||||
tray->show();
|
||||
|
||||
@@ -606,6 +602,36 @@ void Rktwebview_qt::processCommand(Command *cmd)
|
||||
}
|
||||
}
|
||||
|
||||
void Rktwebview_qt::handleTrayActivation(QSystemTrayIcon::ActivationReason reason)
|
||||
{
|
||||
QObject *obj = sender();
|
||||
|
||||
int tray_wv = obj->property("tray-id").toInt();
|
||||
QString evt = "tray-activated";
|
||||
QString reason_str = activationReasonToString(reason);
|
||||
|
||||
//INFO3("triggering event: %s for tray %d with reason %s\n",
|
||||
// evt.toUtf8().constData(), tray_wv, reason_str.toUtf8().constData());
|
||||
|
||||
EventContainer e(evt);
|
||||
e["reason"] = reason_str;
|
||||
|
||||
this->triggerEvent(tray_wv, e);
|
||||
}
|
||||
|
||||
void Rktwebview_qt::handleTrayMessageClick()
|
||||
{
|
||||
QObject *obj = sender();
|
||||
|
||||
//INFO0("triggering message click\n");
|
||||
|
||||
int tray_wv = obj->property("tray-id").toInt();
|
||||
QString evt = "tray-message-clicked";
|
||||
|
||||
EventContainer e(evt);
|
||||
this->triggerEvent(tray_wv, e);
|
||||
}
|
||||
|
||||
void Rktwebview_qt::removeView(int id)
|
||||
{
|
||||
if (_views.contains(id)) {
|
||||
@@ -1066,6 +1092,8 @@ result_t Rktwebview_qt::rktTraySetIcon(rktwebview_t tray, const char *icon_file)
|
||||
|
||||
result_t Rktwebview_qt::rktTraySetTooltip(rktwebview_t tray, const char *tooltip)
|
||||
{
|
||||
//INFO2("rktTraySetTooltip: %d %s\n", tray, tooltip);
|
||||
|
||||
Command c(COMMAND_TRAY_SET_TOOLTIP);
|
||||
c.args.push_back(tray);
|
||||
c.args.push_back(tooltip);
|
||||
@@ -1073,6 +1101,8 @@ result_t Rktwebview_qt::rktTraySetTooltip(rktwebview_t tray, const char *tooltip
|
||||
postCommand(&c);
|
||||
while(!c.done) { doEvents(); }
|
||||
|
||||
//INFO1("rktTraySetTooltip done: %s\n", tooltip);
|
||||
|
||||
return c.result.toBool() ? result_t::oke : result_t::failed;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user