feat: add Kimi Code and web APIs
This commit is contained in:
@@ -104,6 +104,16 @@ bool hasAllFilesAccess();
|
||||
* dialog for it). A desktop, a phone that already has it or one too old to
|
||||
* know about it returns "" and nothing opens. */
|
||||
QString requestAllFilesAccess();
|
||||
/* Take the whole screen. A phone's status bar -- and a tablet's taskbar, which
|
||||
* is a status bar with icons in it -- is drawn *over* the window, and the
|
||||
* window here draws from its own first pixel, so the bars sit on the app's top
|
||||
* row and the controls there cannot be touched. Hiding them is what "full
|
||||
* screen" means on a phone; a desktop has no such bars to ask about and
|
||||
* returns "". Asking is repeatable and cheap: the bars come back with a swipe
|
||||
* from the edge or a switch to another app, so the front end asks again every
|
||||
* time the window comes to the front. Returns "" once they are gone, a reason
|
||||
* otherwise (which the front end logs). */
|
||||
QString requestFullscreen();
|
||||
/* The arguments the Android activity was started with (the
|
||||
* "applicationArguments" intent extra): the way
|
||||
* `cst-agent-app --uitest --workspace DIR` is reachable on a device, since
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <QQuickStyle>
|
||||
#include <QQuickWindow>
|
||||
#include <QStandardPaths>
|
||||
#include <QTemporaryDir>
|
||||
#include <QTextStream>
|
||||
@@ -353,5 +354,25 @@ int main(int argc, char **argv) {
|
||||
/* The phone's back key, one layer at a time (app/src/ui/BackKey.h). */
|
||||
app::installBackKey(engine.rootObjects().value(0),
|
||||
engine.rootObjects().value(0));
|
||||
/* The system bars are drawn over the window (see requestFullscreen): ask for
|
||||
* the whole screen, and ask again whenever the app comes back to the front,
|
||||
* because a swipe from the edge or a switch to another app brings them back.
|
||||
* A refusal is not fatal -- it is logged and the window keeps working with
|
||||
* the bars over its top row. */
|
||||
{
|
||||
const QString why = app::requestFullscreen();
|
||||
if (!why.isEmpty())
|
||||
qWarning("fullscreen: %s", qUtf8Printable(why));
|
||||
QQuickWindow *qwin =
|
||||
qobject_cast<QQuickWindow *>(engine.rootObjects().value(0));
|
||||
if (qwin)
|
||||
QObject::connect(qwin, &QQuickWindow::sceneGraphInitialized, qwin,
|
||||
[] { app::requestFullscreen(); });
|
||||
QObject::connect(&app, &QGuiApplication::applicationStateChanged, &app,
|
||||
[](Qt::ApplicationState state) {
|
||||
if (state == Qt::ApplicationActive)
|
||||
app::requestFullscreen();
|
||||
});
|
||||
}
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
@@ -846,6 +846,65 @@ QString requestAllFilesAccess() {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* The status bar -- and on a tablet in desktop mode the taskbar, which is a
|
||||
* status bar full of icons -- is drawn over the window, and this window draws
|
||||
* from its own first pixel, so the bars land on the app's top row and the
|
||||
* controls there cannot be touched. Which call hides them depends on the API
|
||||
* level: WindowInsetsController from Android 11 (API 30) on, the older
|
||||
* systemUiVisibility flags before it. Measured on the tablet: the app's own
|
||||
* title row was under the taskbar, this puts the window on the whole screen
|
||||
* and the row is touchable again.
|
||||
*
|
||||
* Nothing here is fatal: an invalid context, a missing class or a null insets
|
||||
* controller comes back as a reason (which main.cpp logs) and the window keeps
|
||||
* working with the bars over it. */
|
||||
QString requestFullscreen() {
|
||||
QString err;
|
||||
onGuiThread([&] {
|
||||
QJniObject activity = appContext();
|
||||
if (!activity.isValid()) {
|
||||
err = QStringLiteral("no activity");
|
||||
return;
|
||||
}
|
||||
QJniObject window =
|
||||
activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
|
||||
if (!window.isValid()) {
|
||||
err = QStringLiteral("no window");
|
||||
return;
|
||||
}
|
||||
if (sdkInt() >= 30) {
|
||||
/* Edge to edge plus the bars hidden: the window is told to fill the
|
||||
* screen itself rather than lay out inside the bars. */
|
||||
window.callMethod<void>("setDecorFitsSystemWindows", "(Z)V", false);
|
||||
QJniObject control = window.callObjectMethod(
|
||||
"getInsetsController", "()Landroid/view/WindowInsetsController;");
|
||||
if (!control.isValid()) {
|
||||
err = QStringLiteral("no insets controller");
|
||||
return;
|
||||
}
|
||||
const jint bars = QJniObject::callStaticMethod<jint>(
|
||||
"android/view/WindowInsets$Type", "systemBars", "()I");
|
||||
control.callMethod<void>("hide", "(I)V", bars);
|
||||
/* BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE: a swipe from the edge brings
|
||||
* the bars back for a moment and they leave again by themselves. */
|
||||
control.callMethod<void>("setSystemBarsBehavior", "(I)V", 2);
|
||||
return;
|
||||
}
|
||||
QJniObject decor =
|
||||
window.callObjectMethod("getDecorView", "()Landroid/view/View;");
|
||||
if (!decor.isValid()) {
|
||||
err = QStringLiteral("no decor view");
|
||||
return;
|
||||
}
|
||||
/* SYSTEM_UI_FLAG_HIDE_NAVIGATION | FULLSCREEN | LAYOUT_STABLE |
|
||||
* LAYOUT_HIDE_NAVIGATION | LAYOUT_FULLSCREEN | IMMERSIVE_STICKY */
|
||||
const jint flags = 0x00000002 | 0x00000004 | 0x00000100 | 0x00000200 |
|
||||
0x00000400 | 0x00001000;
|
||||
decor.callMethod<void>("setSystemUiVisibility", "(I)V", flags);
|
||||
});
|
||||
return err;
|
||||
}
|
||||
|
||||
int platformRegisterAndroid(AgentCore *core) {
|
||||
if (!core)
|
||||
return 0;
|
||||
|
||||
@@ -157,6 +157,10 @@ QString materializeAttachment(const QString &pathOrUri, QString *err) {
|
||||
bool hasAllFilesAccess() { return true; }
|
||||
QString requestAllFilesAccess() { return QString(); }
|
||||
|
||||
/* A desktop window is not drawn under anything of the desktop's own: the bars
|
||||
* a panel draws are the panel's, and nothing here can be asked for them. */
|
||||
QString requestFullscreen() { return QString(); }
|
||||
|
||||
int platformRegisterLinux(AgentCore *core) {
|
||||
static const cst_tool_param_t params[CST_TOOL_MAX_PARAMS] = {
|
||||
{"message", "string", 1, "text of the notification"},
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
/* Platform tools on Windows, implemented by the app (not by the engine): they
|
||||
* exist exactly where the desktop service does, and the engine only ever sees
|
||||
* the capability -- platforms + probe decide whether the tool is offered.
|
||||
*
|
||||
* The Linux file next door is the same shape; what differs is the service
|
||||
* behind each call. A notification is the scripting host's popup (Wscript.Shell
|
||||
* through PowerShell) because Windows has no notify-send and a toast needs the
|
||||
* WinRT API; it carries the same two arguments and answers the same way. */
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QClipboard>
|
||||
#include <QDesktopServices>
|
||||
#include <QFileInfo>
|
||||
#include <QGuiApplication>
|
||||
#include <QProcess>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include "core/AgentCore.h"
|
||||
#include "core/ToolProvider.h"
|
||||
|
||||
namespace app {
|
||||
namespace {
|
||||
|
||||
/* whereis-style check without a shell: PATH is split on the Windows separator
|
||||
* and a name may need one of the executable suffixes. */
|
||||
bool haveProgram(const char *name) {
|
||||
const QByteArray path = qgetenv("PATH");
|
||||
const QList<QByteArray> dirs = path.split(';');
|
||||
const QList<QByteArray> exts = {QByteArray(), QByteArray(".exe"),
|
||||
QByteArray(".cmd"), QByteArray(".bat")};
|
||||
for (const QByteArray &d : dirs) {
|
||||
if (d.isEmpty())
|
||||
continue;
|
||||
for (const QByteArray &ext : exts) {
|
||||
const QString cand = QFileInfo(QString::fromLocal8Bit(d + "\\" + name +
|
||||
ext))
|
||||
.absoluteFilePath();
|
||||
if (QFileInfo::exists(cand) && QFileInfo(cand).isExecutable())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* 0 when notifications can be shown; -1 with the reason otherwise. */
|
||||
int notifyProbe(char *why, size_t why_sz) {
|
||||
if (haveProgram("powershell") || haveProgram("pwsh"))
|
||||
return 0;
|
||||
snprintf(why, why_sz, "no powershell on PATH to show a popup with");
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *argOf(const ctl_tool_call_t *call, const char *key) {
|
||||
for (int i = 0; i < call->nargs; i++)
|
||||
if (strcmp(call->args[i].key, key) == 0)
|
||||
return call->args[i].value;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* Runs on the turn's worker thread: no GUI objects here. The popup is started
|
||||
* detached -- it waits for its own timeout, and the turn must not. */
|
||||
int notifyRun(const cst_tool_ctx_t *ctx, const ctl_tool_call_t *call,
|
||||
cst_tool_result_t *r, void *ud) {
|
||||
(void)ctx;
|
||||
(void)ud;
|
||||
const char *title = argOf(call, "title");
|
||||
const char *message = argOf(call, "message");
|
||||
if (!message || !message[0]) {
|
||||
const char *msg = "error: notification_send needs a message";
|
||||
r->out = strdup(msg);
|
||||
r->out_len = r->out ? strlen(msg) : 0;
|
||||
r->exit_code = 1;
|
||||
return 0;
|
||||
}
|
||||
const QString shown =
|
||||
title && title[0] ? QString::fromUtf8(title) : QStringLiteral("CST-agent");
|
||||
/* The popup's own text is single-quoted for PowerShell; a quote inside it is
|
||||
* doubled, which is how PowerShell escapes one. */
|
||||
QString text = QString::fromUtf8(message);
|
||||
text.replace(QLatin1Char('\''), QLatin1String("''"));
|
||||
QString heading = shown;
|
||||
heading.replace(QLatin1Char('\''), QLatin1String("''"));
|
||||
const QString script =
|
||||
QStringLiteral("$w = New-Object -ComObject Wscript.Shell; "
|
||||
"$w.Popup('%1', 8, '%2', 64) | Out-Null")
|
||||
.arg(text, heading);
|
||||
const QString exe = haveProgram("pwsh") ? QStringLiteral("pwsh")
|
||||
: QStringLiteral("powershell");
|
||||
QStringList args;
|
||||
args << QStringLiteral("-NoProfile") << QStringLiteral("-NonInteractive")
|
||||
<< QStringLiteral("-Command") << script;
|
||||
const bool started = QProcess::startDetached(exe, args);
|
||||
const QByteArray out = started
|
||||
? QByteArrayLiteral("notification shown")
|
||||
: QByteArrayLiteral("could not start ") +
|
||||
exe.toLocal8Bit();
|
||||
r->out = strdup(out.constData());
|
||||
r->out_len = r->out ? strlen(r->out) : 0;
|
||||
r->exit_code = started ? 0 : 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Registered once; the engine keeps a copy until the owner is unregistered. */
|
||||
cst_tool_def_t g_notify;
|
||||
|
||||
} // namespace
|
||||
|
||||
/* A file card's "open": ShellExecute through QDesktopServices, so the file's
|
||||
* own application comes up. */
|
||||
QString openLocalFile(const QString &path, const QString &title,
|
||||
QString *status) {
|
||||
const QString name = title.isEmpty() ? QFileInfo(path).fileName() : title;
|
||||
if (qEnvironmentVariableIsSet("CST_APP_NO_OPEN")) {
|
||||
if (status)
|
||||
*status = QStringLiteral("opened %1 (test mode)").arg(name);
|
||||
return QString();
|
||||
}
|
||||
if (!QFileInfo::exists(path))
|
||||
return QStringLiteral("the file is gone: %1").arg(name);
|
||||
if (!QDesktopServices::openUrl(QUrl::fromLocalFile(path)))
|
||||
return QStringLiteral("no application on this machine opens %1").arg(name);
|
||||
if (status)
|
||||
*status = QStringLiteral("opened %1").arg(name);
|
||||
return QString();
|
||||
}
|
||||
|
||||
/* No share sheet here: the path is what another program needs, so it goes to
|
||||
* the clipboard. */
|
||||
QString shareLocalFile(const QString &path, const QString &title,
|
||||
QString *status) {
|
||||
const QString name = title.isEmpty() ? QFileInfo(path).fileName() : title;
|
||||
if (qEnvironmentVariableIsSet("CST_APP_NO_OPEN")) {
|
||||
if (status)
|
||||
*status = QStringLiteral("shared %1 (test mode)").arg(name);
|
||||
return QString();
|
||||
}
|
||||
if (!QFileInfo::exists(path))
|
||||
return QStringLiteral("the file is gone: %1").arg(name);
|
||||
QGuiApplication::clipboard()->setText(path);
|
||||
if (status)
|
||||
*status = QStringLiteral("%1: the path is on the clipboard").arg(name);
|
||||
return QString();
|
||||
}
|
||||
|
||||
/* Windows does not freeze a process whose window is open, and the app's own
|
||||
* window is what keeps it alive: nothing to hold. */
|
||||
QString holdForeground(const QString &text) {
|
||||
(void)text;
|
||||
return QString();
|
||||
}
|
||||
void releaseForeground() {}
|
||||
|
||||
/* A native file dialog hands over a path, so there is nothing to turn into
|
||||
* one: a file:// URL loses its scheme and anything else is taken as a path. */
|
||||
QString materializeAttachment(const QString &pathOrUri, QString *err) {
|
||||
(void)err;
|
||||
QString s = pathOrUri;
|
||||
if (s.startsWith(QLatin1String("file://")))
|
||||
s = s.mid(7);
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Every process on Windows reads the files its user can. */
|
||||
bool hasAllFilesAccess() { return true; }
|
||||
QString requestAllFilesAccess() { return QString(); }
|
||||
|
||||
/* A Windows window has its own frame; there is no system bar drawn over it. */
|
||||
QString requestFullscreen() { return QString(); }
|
||||
|
||||
int platformRegisterWindows(AgentCore *core) {
|
||||
static const cst_tool_param_t params[CST_TOOL_MAX_PARAMS] = {
|
||||
{"message", "string", 1, "text of the notification"},
|
||||
{"title", "string", 0, "title line (default: CST-agent)"},
|
||||
{nullptr, nullptr, 0, nullptr},
|
||||
{nullptr, nullptr, 0, nullptr},
|
||||
{nullptr, nullptr, 0, nullptr},
|
||||
{nullptr, nullptr, 0, nullptr}};
|
||||
memset(&g_notify, 0, sizeof(g_notify));
|
||||
setMeta(&g_notify, "notification_send",
|
||||
"Show a notification outside the window (a popup that goes away by "
|
||||
"itself).",
|
||||
CST_TP_ASK, "notify", kDesktopOnly, notifyProbe);
|
||||
memcpy(g_notify.params, params, sizeof(params));
|
||||
g_notify.run = nullptr;
|
||||
g_notify.run_ex = notifyRun;
|
||||
g_notify.ud = nullptr;
|
||||
g_notify.owner = "app:windows";
|
||||
return core->registerTool(&g_notify) ? 1 : 0;
|
||||
}
|
||||
|
||||
} // namespace app
|
||||
+176
-42
@@ -12,7 +12,9 @@
|
||||
#include <QClipboard>
|
||||
#include <QBuffer>
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QImage>
|
||||
#include <QPalette>
|
||||
#include <QJsonDocument>
|
||||
@@ -128,11 +130,20 @@ int countNamed(QQuickItem *root, const QString &prefix) {
|
||||
/* An item by objectName. The QObject tree is tried first (it holds the named
|
||||
* controls); a view's delegates can be owned by the model instead, so the
|
||||
* visual tree -- what a finger can actually reach -- is walked as well. */
|
||||
bool onScreen(QQuickItem *it); /* defined below: isVisible() is not enough */
|
||||
|
||||
QQuickItem *item(QQuickWindow *win, const QString &name) {
|
||||
QList<QQuickItem *> hits;
|
||||
collectNamed(win->contentItem(), name, &hits);
|
||||
/* What a finger can reach is the one the test means: a delegate on its way
|
||||
* out is still in the tree but invisible. */
|
||||
/* What a finger can reach is the one the test means. Two things say
|
||||
* "visible" without being reachable: a delegate on its way out, and a
|
||||
* second copy of a control that lives in a closed drawer (the sidebar is
|
||||
* drawn from the window and, when narrow, from a drawer off to the left).
|
||||
* Which copy comes first in the tree is not the same on every platform, so
|
||||
* the one whose centre is really on screen wins. */
|
||||
for (QQuickItem *it : hits)
|
||||
if (onScreen(it))
|
||||
return it;
|
||||
for (QQuickItem *it : hits)
|
||||
if (it->isVisible())
|
||||
return it;
|
||||
@@ -168,12 +179,66 @@ bool onScreen(QQuickItem *it) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* An event lands on whatever is at that point, and isVisible() does not know
|
||||
* about a scrolling ancestor's clipping (see onScreen): an item the view has
|
||||
* scrolled past still says it is visible, and the click goes to the row that
|
||||
* happens to be at that pixel -- which is a different row on a window whose
|
||||
* font makes the rows taller (another platform, another Qt). So a click
|
||||
* scrolls its target in first, which is what a person does. The nearest
|
||||
* ancestor that both clips and scrolls (a ListView's own item) is the one to
|
||||
* move; anchored to its middle, so a row at either edge still gets its whole
|
||||
* centre inside the viewport. */
|
||||
void scrollIntoView(QQuickItem *it, bool middle = false) {
|
||||
if (!it || (!middle && onScreen(it)))
|
||||
return;
|
||||
for (QQuickItem *a = it->parentItem(); a; a = a->parentItem()) {
|
||||
const QVariant contentY = a->property("contentY");
|
||||
if (!a->clip() || !contentY.isValid() ||
|
||||
!a->property("contentHeight").isValid())
|
||||
continue;
|
||||
const double y = it->mapToItem(a, QPointF(0, 0)).y() + contentY.toDouble();
|
||||
const double lowest = a->property("contentHeight").toDouble() - a->height();
|
||||
note(QStringLiteral("%1 is out of the viewport (contentY %2, at %3 of %4): "
|
||||
"scrolling to it")
|
||||
.arg(it->objectName())
|
||||
.arg(contentY.toDouble())
|
||||
.arg(y)
|
||||
.arg(a->property("contentHeight").toDouble()));
|
||||
a->setProperty("contentY", qBound(0.0, y - a->height() / 2, lowest));
|
||||
QTest::qWait(150);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* One rendered frame: items are laid out, and a view's delegates are created,
|
||||
* in the render loop's polish step. A platform whose window is never exposed
|
||||
* -- offscreen on Windows, which is how this is run on a machine that has no
|
||||
* Windows -- only runs that step when something asks for a picture, so
|
||||
* without this the window can be a whole pass behind: a row still 0 wide, a
|
||||
* card not created yet. A person looking at the window would see it settled,
|
||||
* which is what the checks below are about. */
|
||||
void frame(QQuickWindow *win) {
|
||||
if (win)
|
||||
win->grabWindow();
|
||||
QTest::qWait(50);
|
||||
}
|
||||
|
||||
void clickItem(QQuickWindow *win, QQuickItem *it); /* defined below */
|
||||
void tapItem(QQuickWindow *win, QPointingDevice *dev, QQuickItem *it);
|
||||
|
||||
void clickMouse(QQuickWindow *win, const QString &name) {
|
||||
QQuickItem *it = item(win, name);
|
||||
if (!it || !it->isVisible()) {
|
||||
check(false, QStringLiteral("mouse click %1: not there").arg(name));
|
||||
return;
|
||||
}
|
||||
clickItem(win, it);
|
||||
}
|
||||
|
||||
/* The same click, on an item the caller already has: a name can match more
|
||||
* than one item (a view keeps a delegate from the session before), and the
|
||||
* one the test means is not always the first in the tree. */
|
||||
void clickItem(QQuickWindow *win, QQuickItem *it) {
|
||||
QTest::mouseClick(win, Qt::LeftButton, Qt::NoModifier, centre(it));
|
||||
}
|
||||
|
||||
@@ -183,6 +248,10 @@ void tapTouch(QQuickWindow *win, QPointingDevice *dev, const QString &name) {
|
||||
check(false, QStringLiteral("touch tap %1: not there").arg(name));
|
||||
return;
|
||||
}
|
||||
tapItem(win, dev, it);
|
||||
}
|
||||
|
||||
void tapItem(QQuickWindow *win, QPointingDevice *dev, QQuickItem *it) {
|
||||
const QPoint p = centre(it);
|
||||
QTest::touchEvent(win, dev).press(0, p, win);
|
||||
QTest::touchEvent(win, dev).release(0, p, win);
|
||||
@@ -417,6 +486,10 @@ int runUiTest(AgentCore &core, const QString &size) {
|
||||
QStringLiteral("a session fixture with a tool call is in the store"));
|
||||
QMetaObject::invokeMethod(win, "reloadSessions");
|
||||
QTest::qWait(150);
|
||||
/* A row is not clickable until the layout pass that gives it its width has
|
||||
* run (see frame()): a click on a row that is still 0 wide goes to whatever
|
||||
* is behind it. */
|
||||
frame(win);
|
||||
int rowsSeen = countNamed(win->contentItem(), QStringLiteral("sessionRow:"));
|
||||
if (qEnvironmentVariableIsSet("CST_APP_DUMP"))
|
||||
std::printf("note: %d session rows in the visual tree\n", rowsSeen);
|
||||
@@ -465,61 +538,89 @@ int runUiTest(AgentCore &core, const QString &size) {
|
||||
/* A click goes to whatever is at that point, and the transcript replays
|
||||
* from its bottom: on a phone-sized window the card can be above the
|
||||
* visible part, where isVisible() still says yes (it does not know about
|
||||
* the view's clipping) and the click lands on the row that happens to be
|
||||
* there. Scroll it in first, which is what a person does -- and stop the
|
||||
* view following its tail (ChatView.stickBottom), or the scroll is undone
|
||||
* by the next content change. */
|
||||
if (list && !onScreen(item(win, QStringLiteral("fileOpen0")))) {
|
||||
QQuickItem *button = item(win, QStringLiteral("fileOpen0"));
|
||||
QQuickItem *chat = item(win, QStringLiteral("chatView"));
|
||||
if (chat)
|
||||
* the view's clipping). scrollIntoView puts it in the middle of the view --
|
||||
* and stop the view following its tail (ChatView.stickBottom) first, or
|
||||
* the scroll is undone by the next content change. */
|
||||
if (list) {
|
||||
/* Stop the view following its tail (ChatView.stickBottom) first: the
|
||||
* scroll to the card below would be undone by the next content
|
||||
* change. */
|
||||
if (QQuickItem *chat = item(win, QStringLiteral("chatView")))
|
||||
chat->setProperty("stickBottom", false);
|
||||
const double contentY = list->property("contentY").toDouble();
|
||||
const double y = button->mapToItem(list, QPointF(0, 0)).y() + contentY;
|
||||
const double lowest =
|
||||
list->property("contentHeight").toDouble() - list->height();
|
||||
note(QStringLiteral("the card is out of the viewport (contentY %1, card "
|
||||
"at %2 of %3): scrolling to it")
|
||||
.arg(contentY)
|
||||
.arg(y)
|
||||
.arg(list->property("contentHeight").toDouble()));
|
||||
list->setProperty("contentY", qBound(0.0, y - list->height() / 2, lowest));
|
||||
QTest::qWait(150);
|
||||
}
|
||||
clickMouse(win, QStringLiteral("fileOpen0"));
|
||||
/* What the card itself hands the engine ("rel" is the name the store keeps
|
||||
* the file under), and whether it is really on screen: a card outside the
|
||||
* viewport takes the events meant for it, and the card's own line is where
|
||||
* the engine puts its refusal. */
|
||||
QStringList rels;
|
||||
QString cardSays;
|
||||
QList<QQuickItem *> strips;
|
||||
collectNamed(win->contentItem(), QStringLiteral("imageStrip"), &strips);
|
||||
/* Which card is the session's own. The tree still holds the delegate of
|
||||
* the session before -- a view keeps a row or two around -- and its card
|
||||
* names a file of *that* session, so the first "fileOpen0" in the tree is
|
||||
* not necessarily the one the check means. A rel this session can open is
|
||||
* one that is really in its attachment directory. */
|
||||
QQuickItem *openButton = nullptr;
|
||||
QQuickItem *shareButton = nullptr;
|
||||
const QString attachDir = core.attachmentDir();
|
||||
for (QQuickItem *s : strips) {
|
||||
const QVariantList files = s->property("files").toList();
|
||||
for (const QVariant &f : files)
|
||||
for (int i = 0; i < files.size(); i++) {
|
||||
const QVariant &f = files.at(i);
|
||||
rels << f.toMap().value(QStringLiteral("rel")).toString();
|
||||
if (openButton) {
|
||||
continue;
|
||||
}
|
||||
const QString rel =
|
||||
f.toMap().value(QStringLiteral("rel")).toString();
|
||||
if (rel.isEmpty() ||
|
||||
!QFileInfo::exists(attachDir + QLatin1Char('/') + rel))
|
||||
continue;
|
||||
QList<QQuickItem *> hits;
|
||||
collectNamed(s, QStringLiteral("fileOpen%1").arg(i), &hits);
|
||||
if (!hits.isEmpty()) {
|
||||
openButton = hits.first();
|
||||
collectNamed(s, QStringLiteral("fileShare%1").arg(i), &hits);
|
||||
shareButton = hits.isEmpty() ? nullptr : hits.first();
|
||||
}
|
||||
}
|
||||
if (cardSays.isEmpty())
|
||||
cardSays = s->property("errorText").toString();
|
||||
}
|
||||
if (!openButton)
|
||||
openButton = item(win, QStringLiteral("fileOpen0"));
|
||||
if (!shareButton)
|
||||
shareButton = item(win, QStringLiteral("fileShare0"));
|
||||
/* What the card itself hands the engine ("rel" is the name the store keeps
|
||||
* the file under), and whether it is really on screen: a card outside the
|
||||
* viewport takes the events meant for it, and the card's own line is where
|
||||
* the engine puts its refusal. */
|
||||
if (openButton) {
|
||||
scrollIntoView(openButton, true);
|
||||
frame(win);
|
||||
clickItem(win, openButton);
|
||||
} else {
|
||||
check(false, QStringLiteral("the delivered file has a card to open"));
|
||||
}
|
||||
const bool byMouse = !win->property("statusText").toString().isEmpty();
|
||||
if (!byMouse)
|
||||
tapTouch(win, touch, QStringLiteral("fileOpen0"));
|
||||
if (!byMouse && openButton)
|
||||
tapItem(win, touch, openButton);
|
||||
const QString opened = win->property("statusText").toString();
|
||||
check(opened.startsWith(QLatin1String("opened ")),
|
||||
QStringLiteral("Open hands the file to the system (%1%2; cards hold '%3', "
|
||||
"%4, card says '%5')")
|
||||
.arg(opened, byMouse ? QString() : QStringLiteral(" after a tap"),
|
||||
rels.join(QLatin1String(", ")),
|
||||
onScreen(item(win, QStringLiteral("fileOpen0")))
|
||||
onScreen(openButton)
|
||||
? QStringLiteral("on screen")
|
||||
: QStringLiteral("out of the viewport"),
|
||||
cardSays));
|
||||
win->setProperty("statusText", QString());
|
||||
clickMouse(win, QStringLiteral("fileShare0"));
|
||||
if (shareButton) {
|
||||
scrollIntoView(shareButton, true);
|
||||
frame(win);
|
||||
clickItem(win, shareButton);
|
||||
}
|
||||
const bool shareByMouse = !win->property("statusText").toString().isEmpty();
|
||||
if (!shareByMouse)
|
||||
tapTouch(win, touch, QStringLiteral("fileShare0"));
|
||||
if (!shareByMouse && shareButton)
|
||||
tapItem(win, touch, shareButton);
|
||||
const QString shared = win->property("statusText").toString();
|
||||
check(shared.contains(QLatin1String("report.md")),
|
||||
QStringLiteral("Share names the file (%1%2; card says '%3')")
|
||||
@@ -709,27 +810,46 @@ int runUiTest(AgentCore &core, const QString &size) {
|
||||
|
||||
/* and back to the fixture, which still has its six rows */
|
||||
QTest::qWait(150);
|
||||
/* The sidebar holds two more sessions by now, so the row may sit below the
|
||||
* fold: brought into view first, or the click goes to the row that happens
|
||||
* to be there (see scrollIntoView). */
|
||||
if (QQuickItem *row = item(win, QStringLiteral("sessionRow:") + fixture)) {
|
||||
scrollIntoView(row);
|
||||
frame(win);
|
||||
}
|
||||
clickMouse(win, QStringLiteral("sessionRow:") + fixture);
|
||||
check(core.sessionId() == fixture && list &&
|
||||
list->property("count").toInt() == 6,
|
||||
QStringLiteral("switching back replays it again"));
|
||||
{
|
||||
bool promptImage = false;
|
||||
int promptImageRow = -1;
|
||||
const QVariantList rows = core.history();
|
||||
for (const QVariant &v : rows) {
|
||||
for (int i = 0; i < rows.size(); i++) {
|
||||
const QVariant &v = rows.at(i);
|
||||
const QVariantMap r = v.toMap();
|
||||
if (r.value(QStringLiteral("role")).toString() == QLatin1String("user") &&
|
||||
r.value(QStringLiteral("images")).toString().contains(
|
||||
QLatin1String("|")))
|
||||
QLatin1String("|"))) {
|
||||
promptImage = true;
|
||||
if (promptImageRow < 0)
|
||||
promptImageRow = i;
|
||||
}
|
||||
}
|
||||
check(promptImage,
|
||||
QStringLiteral("a stored prompt image comes back with its row"));
|
||||
/* The view follows the tail (ChatView.stickBottom) and the picture is in
|
||||
* the first prompt: on a window that fits fewer rows than this one it is
|
||||
* above the visible part, where a delegate is not created at all. Put it
|
||||
* on screen, which is what a person does before looking at it. */
|
||||
if (list && promptImageRow >= 0)
|
||||
QMetaObject::invokeMethod(list, "positionViewAtIndex",
|
||||
Q_ARG(int, promptImageRow), Q_ARG(int, 0));
|
||||
/* The rows are in the model by now; the cards -- and the thumbnails in
|
||||
* them -- are built on the view's next layout pass. A frame forces it,
|
||||
* and that frame is also the picture a person looks at. */
|
||||
maybeShot(win, QStringLiteral("-images"));
|
||||
QTest::qWait(150);
|
||||
frame(win);
|
||||
if (qEnvironmentVariableIsSet("CST_APP_DUMP")) {
|
||||
QVariant v;
|
||||
QMetaObject::invokeMethod(win, "rowJson", Q_RETURN_ARG(QVariant, v),
|
||||
@@ -1057,9 +1177,13 @@ int runUiTest(AgentCore &core, const QString &size) {
|
||||
/* --- the image provider: only the session's own files ----------------- */
|
||||
{
|
||||
const QString dir = core.attachmentDir();
|
||||
/* one directory per session since v0.9.5: <sessions>/<id>/attachments */
|
||||
check(!dir.isEmpty() && dir.endsWith(QLatin1String("/attachments")) &&
|
||||
dir.contains(QLatin1String("/sessions/")),
|
||||
/* one directory per session since v0.9.5: <sessions>/<id>/attachments.
|
||||
* The engine builds the path with the separator of the platform it runs
|
||||
* on, so what arrives here is "…/sessions\<id>\attachments" on Windows:
|
||||
* asked with forward slashes, which is what the check means. */
|
||||
const QString shown = QDir::fromNativeSeparators(dir);
|
||||
check(!shown.isEmpty() && shown.endsWith(QLatin1String("/attachments")) &&
|
||||
shown.contains(QLatin1String("/sessions/")),
|
||||
QStringLiteral("the agent names its image directory (%1)").arg(dir));
|
||||
QImage pic(32, 16, QImage::Format_RGB32);
|
||||
pic.fill(Qt::darkGreen);
|
||||
@@ -1100,6 +1224,14 @@ int runUiTest(AgentCore &core, const QString &size) {
|
||||
const int before = list->property("count").toInt();
|
||||
const int thumbsBefore =
|
||||
countNamed(win->contentItem(), QStringLiteral("imageThumb"));
|
||||
if (qEnvironmentVariableIsSet("CST_APP_DUMP") && list)
|
||||
std::printf("note: tool card: model %d, contentY %.1f of %.1f (view %.1f), "
|
||||
"%d strips, %d thumbs, %d cards\n", before,
|
||||
list->property("contentY").toDouble(),
|
||||
list->property("contentHeight").toDouble(), list->height(),
|
||||
countNamed(win->contentItem(), QStringLiteral("imageStrip")),
|
||||
thumbsBefore,
|
||||
countNamed(win->contentItem(), QStringLiteral("card:")));
|
||||
event4("engineToolEvent", QStringLiteral("open"), QStringLiteral("call-img"),
|
||||
QStringLiteral("view_image"), QStringLiteral("{\"path\":\"shot.png\"}"));
|
||||
const QString imgs =
|
||||
@@ -1108,7 +1240,7 @@ int runUiTest(AgentCore &core, const QString &size) {
|
||||
Q_ARG(QVariant, QStringLiteral("call-img")),
|
||||
Q_ARG(QVariant, imgs)),
|
||||
QStringLiteral("images a tool made reach the view"));
|
||||
QTest::qWait(150);
|
||||
frame(win);
|
||||
const QVariantMap card = rowAt(before);
|
||||
check(card.value(QStringLiteral("images"))
|
||||
.toString()
|
||||
@@ -1118,7 +1250,9 @@ int runUiTest(AgentCore &core, const QString &size) {
|
||||
QStringLiteral("the card of that call carries the image"));
|
||||
check(countNamed(win->contentItem(), QStringLiteral("imageThumb")) >
|
||||
thumbsBefore,
|
||||
QStringLiteral("its thumbnail is in the card"));
|
||||
QStringLiteral("its thumbnail is in the card (%1 -> %2)").arg(thumbsBefore)
|
||||
.arg(countNamed(win->contentItem(),
|
||||
QStringLiteral("imageThumb"))));
|
||||
maybeShot(win, QStringLiteral("-toolimage"));
|
||||
}
|
||||
|
||||
@@ -1144,7 +1278,7 @@ int runUiTest(AgentCore &core, const QString &size) {
|
||||
Q_ARG(QVariant, QStringLiteral("call-file")),
|
||||
Q_ARG(QVariant, files)),
|
||||
QStringLiteral("the files a tool delivered reach the view"));
|
||||
QTest::qWait(150);
|
||||
frame(win);
|
||||
const QVariantMap card = rowAt(before);
|
||||
check(card.value(QStringLiteral("images"))
|
||||
.toString()
|
||||
|
||||
Reference in New Issue
Block a user