From 7468a16d6326d34f53d5ce1458c25276bafd793c Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Wed, 8 Apr 2026 16:39:23 +0200 Subject: [PATCH] icon --- command.h | 1 + main.cpp | 7 +++++++ rkt_protocol.h | 1 + rktwebview.cpp | 7 +++++++ rktwebview.h | 1 + rktwebview_qt.cpp | 25 +++++++++++++++++++++++++ rktwebview_qt.h | 1 + 7 files changed, 43 insertions(+) diff --git a/command.h b/command.h index e29fa64..a777679 100644 --- a/command.h +++ b/command.h @@ -28,6 +28,7 @@ #define COMMAND_SET_OU_TOKEN 22 #define COMMAND_NEW_CONTEXT 23 #define COMMAND_MESSAGE 24 +#define COMMAND_SET_ICON 25 class Command { diff --git a/main.cpp b/main.cpp index fa81e6a..6e55848 100644 --- a/main.cpp +++ b/main.cpp @@ -271,6 +271,13 @@ void Handler::run() result_queue->enqueue(r); } break; + case CMD_SET_ICON: { + int wv = data_obj["wv"].toInt(); + QString icon_file = data_obj["icon"].toString(); + result_t r = webview_handler->rktWindowSetIcon(wv, icon_file.toUtf8().constData()); + result_queue->enqueue(r); + } + break; case CMD_CHOOSE_DIR: { int wv = data_obj["wv"].toInt(); QString title = data_obj["title"].toString(); diff --git a/rkt_protocol.h b/rkt_protocol.h index b1c3082..d9f40b0 100644 --- a/rkt_protocol.h +++ b/rkt_protocol.h @@ -28,6 +28,7 @@ #define CMD_MSG_BOX 25 // arguments: wv: int, title:string, message: string, submessage: string, type:int -> result_t: int #define CMD_SET_LOGLEVEL 26 // arguments: ll: int #define CMD_INFO 27 // arguments: none +#define CMD_SET_ICON 28 // arguments: wv: int, icon:string (absolute filename to icon in png/jpg/svg) #define RESULT_QUIT 36379 diff --git a/rktwebview.cpp b/rktwebview.cpp index 983593e..c9a680a 100644 --- a/rktwebview.cpp +++ b/rktwebview.cpp @@ -474,6 +474,11 @@ result_t rkt_webview_set_title(rktwebview_t wv, const char *title) CMDRES(CMD_SET_TITLE, wv, "title", title) } +result_t rkt_webview_set_icon(rktwebview_t wv, const char *icon_file) +{ + CMDRES(CMD_SET_ICON, wv, "icon", icon_file) +} + result_t rkt_webview_choose_dir(rktwebview_t w, const char *title, const char *base_dir) { CMDRES2(CMD_CHOOSE_DIR, w, "title", title, "base_dir", base_dir) @@ -591,3 +596,5 @@ rkt_data_t *rkt_webview_info() return d; } + + diff --git a/rktwebview.h b/rktwebview.h index 0fd9da7..c2e2ce8 100644 --- a/rktwebview.h +++ b/rktwebview.h @@ -28,6 +28,7 @@ RKTWEBVIEW_EXPORT int rkt_webview_create(rkt_wv_context_t context, rktwebview_t RKTWEBVIEW_EXPORT void rkt_webview_close(rktwebview_t wv); RKTWEBVIEW_EXPORT bool rkt_webview_valid(rktwebview_t wv); RKTWEBVIEW_EXPORT result_t rkt_webview_set_title(rktwebview_t wv, const char *title); +RKTWEBVIEW_EXPORT result_t rkt_webview_set_icon(rktwebview_t wv, const char *icon_file); RKTWEBVIEW_EXPORT void rkt_webview_set_ou_token(rktwebview_t wv, const char *token); RKTWEBVIEW_EXPORT result_t rkt_webview_set_url(rktwebview_t wv, const char *url); diff --git a/rktwebview_qt.cpp b/rktwebview_qt.cpp index 211cafc..f19d605 100644 --- a/rktwebview_qt.cpp +++ b/rktwebview_qt.cpp @@ -229,6 +229,20 @@ void Rktwebview_qt::processCommand(Command *cmd) cmd->done = true; } break; + case COMMAND_SET_ICON: { + int wv = cmd->args[0].toInt(); + QString icon_file = cmd->args[1].toString(); + if (_views.contains(wv)) { + WebviewWindow *w = _views[wv]; + QIcon icn(icon_file); + w->setWindowIcon(icn); + cmd->result = true; + } else { + cmd->result = false; + } + cmd->done = true; + } + break; case COMMAND_RUN_JS: { int wv = cmd->args[0].toInt(); QString js = cmd->args[1].toString(); @@ -777,6 +791,17 @@ result_t Rktwebview_qt::rktWindowSetTitle(rktwebview_t wv, const char *title) return r ? result_t::oke : result_t::failed; } +result_t Rktwebview_qt::rktWindowSetIcon(rktwebview_t wv, const char *icon_file) +{ + Command c(COMMAND_SET_ICON); + c.args.push_back(wv); + c.args.push_back(icon_file); + postCommand(&c); + while(!c.done) { doEvents(); } + bool r = c.result.toBool(); + return r ? result_t::oke : result_t::failed; +} + void Rktwebview_qt::msgBox(rktwebview_t w, const QString &title, const QString &message, const QString &submessage, rkt_messagetype_t type) { diff --git a/rktwebview_qt.h b/rktwebview_qt.h index 16e5599..11f6eb0 100644 --- a/rktwebview_qt.h +++ b/rktwebview_qt.h @@ -106,6 +106,7 @@ public: result_t rktFileSave(rktwebview_t w, const char *title, const char *base_dir, const char *permitted_exts); result_t rktWindowSetTitle(rktwebview_t wv, const char *title); + result_t rktWindowSetIcon(rktwebview_t wv, const char *icon_file); result_t rktMessageBox(rktwebview_t w, const char *title, const char *message, const char *submessage, rkt_messagetype_t type); bool rktValid(rktwebview_t wv);