Files
photog/desktop/tagcompleter.cpp
T
puttaalu 504b96ed31 Qt desktop: add manage (edit/delete) and tag autocomplete
Brings the Qt uploader to parity with the web /manage page and the Android
app. Adds a stacked Manage page (reached from the post page) that lists
posts via GET /api/photos with thumbnails from GET /api/thumb/<slug>, edits
caption/date/tags in a QDialog via POST /api/edit, and deletes to trash via
POST /api/delete with a QMessageBox confirm. As a non-browser client it sends
no Origin and so passes the server's same-origin CSRF check.

Tag autocomplete now backs every tags field (post cards and the edit dialog)
via a per-token TagCompleter (QCompleter subclass, MatchContains) fed from
the unguarded GET /api/tags.json.

New files: managepostwidget.{h,cpp}, tagcompleter.{h,cpp}; network methods
and a RemotePhoto struct added to uploadclient. Built and linked clean; not
yet runtime-tested on a real display.
2026-11-04 22:04:06 +01:00

43 lines
1.4 KiB
C++

#include "tagcompleter.h"
#include <QLineEdit>
#include <QStringListModel>
TagCompleter::TagCompleter(QObject *parent)
: QCompleter(parent)
, m_model(new QStringListModel(this))
{
setModel(m_model);
setCaseSensitivity(Qt::CaseInsensitive);
setFilterMode(Qt::MatchContains); // match anywhere in the tag, like Android
setCompletionMode(QCompleter::PopupCompletion);
}
void TagCompleter::setSuggestions(const QStringList &tags)
{
m_model->setStringList(tags);
}
// Complete against the token after the last comma, ignoring the tags already
// entered before it.
QStringList TagCompleter::splitPath(const QString &path) const
{
return QStringList(path.section(QLatin1Char(','), -1).trimmed());
}
// Rebuild the full field value: everything up to and including the last comma,
// then the chosen tag and a trailing ", " ready for the next one.
QString TagCompleter::pathFromIndex(const QModelIndex &index) const
{
const QString completion = QCompleter::pathFromIndex(index);
const auto *edit = qobject_cast<const QLineEdit *>(widget());
if (!edit)
return completion;
const QString text = edit->text();
const int lastComma = text.lastIndexOf(QLatin1Char(','));
const QString head =
lastComma >= 0 ? text.left(lastComma + 1) + QLatin1Char(' ') : QString();
return head + completion + QStringLiteral(", ");
}