applied clang format

This commit is contained in:
deeaitch committed 2026-10-01 12:21:40 -04:00
1 parent 39ab7acc08
commit 73d82e9562
6 files changed
+22 -48

No files matched your search

+1 -3
View File
@@ -29,9 +29,7 @@ public:
return false; return false;
auto *clipboard = QGuiApplication::clipboard(); auto *clipboard = QGuiApplication::clipboard();
clipboard->setText(m_text, QClipboard::Clipboard); clipboard->setText(m_text, QClipboard::Clipboard);
const bool copied = clipboard->text (QClipboard::Clipboard) == m_text const bool copied = clipboard->text(QClipboard::Clipboard) == m_text && (!QGuiApplication::platformName().startsWith(QStringLiteral("wayland")) || clipboard->ownsClipboard());
&& (!QGuiApplication::platformName().startsWith (QStringLiteral ("wayland"))
|| clipboard->ownsClipboard());
m_status->setText(copied ? QStringLiteral("Short URL copied to clipboard.") m_status->setText(copied ? QStringLiteral("Short URL copied to clipboard.")
: QStringLiteral("Could not copy the short URL. Click OK to retry.")); : QStringLiteral("Could not copy the short URL. Click OK to retry."));
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
+1 -2
View File
@@ -19,8 +19,7 @@ inline QUrl parseText (const QString &text) {
if (urlText.size() >= 2) { if (urlText.size() >= 2) {
const QChar first = urlText.front(); const QChar first = urlText.front();
const QChar last = urlText.back(); const QChar last = urlText.back();
if ((first == '\'' && last == '\'') || (first == '"' && last == '"') if ((first == '\'' && last == '\'') || (first == '"' && last == '"') || (first == '<' && last == '>'))
|| (first == '<' && last == '>'))
urlText = urlText.mid(1, urlText.size() - 2).trimmed(); urlText = urlText.mid(1, urlText.size() - 2).trimmed();
} }
+6 -19
View File
@@ -1,6 +1,6 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "clipboardurl.h"
#include "clipboardresultdialog.h" #include "clipboardresultdialog.h"
#include "clipboardurl.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "yourlsclient.h" #include "yourlsclient.h"
@@ -58,16 +58,7 @@ namespace {
* @param parent Parent widget. * @param parent Parent widget.
*/ */
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow (parent) : QMainWindow(parent), ui(new Ui::MainWindow), m_trayIcon(nullptr), m_trayMenu(nullptr), m_cutUrlAction(nullptr), m_settingsAction(nullptr), m_helpAction(nullptr), m_aboutAction(nullptr), m_exitAction(nullptr), m_yourlsClient(new YourlsClient(this)) {
, ui (new Ui::MainWindow)
, m_trayIcon (nullptr)
, m_trayMenu (nullptr)
, m_cutUrlAction (nullptr)
, m_settingsAction (nullptr)
, m_helpAction (nullptr)
, m_aboutAction (nullptr)
, m_exitAction (nullptr)
, m_yourlsClient (new YourlsClient (this)) {
ui->setupUi(this); ui->setupUi(this);
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
qDebug() << "[yourls-ui] debug build, executable:" << QCoreApplication::applicationFilePath() qDebug() << "[yourls-ui] debug build, executable:" << QCoreApplication::applicationFilePath()
@@ -189,8 +180,7 @@ void MainWindow::showSettingsWindow() {
* @brief Hides the settings window to tray when possible. * @brief Hides the settings window to tray when possible.
*/ */
void MainWindow::hideToTray() { void MainWindow::hideToTray() {
if (!hasValidSettings() || m_trayIcon == nullptr if (!hasValidSettings() || m_trayIcon == nullptr || !QSystemTrayIcon::isSystemTrayAvailable() || !m_trayIcon->isVisible()) {
|| !QSystemTrayIcon::isSystemTrayAvailable() || !m_trayIcon->isVisible()) {
showSettingsWindow(); showSettingsWindow();
return; return;
} }
@@ -233,8 +223,7 @@ void MainWindow::cutUrlFromClipboard() {
} }
QUrl longUrl; QUrl longUrl;
if (QGuiApplication::platformName().startsWith (QStringLiteral ("wayland")) if (QGuiApplication::platformName().startsWith(QStringLiteral("wayland")) && !isActiveWindow()) {
&& !isActiveWindow()) {
// Wayland delivers clipboard offers to clients with keyboard focus. // Wayland delivers clipboard offers to clients with keyboard focus.
// A tray menu belongs to the shell and does not focus our application. // A tray menu belongs to the shell and does not focus our application.
QDialog clipboardDialog(this); QDialog clipboardDialog(this);
@@ -260,8 +249,7 @@ void MainWindow::cutUrlFromClipboard() {
if (!clipboardDialog.isActiveWindow()) if (!clipboardDialog.isActiveWindow())
return; return;
const auto *mimeData = QGuiApplication::clipboard()->mimeData(); const auto *mimeData = QGuiApplication::clipboard()->mimeData();
if ((mimeData != nullptr && !mimeData->formats().isEmpty()) if ((mimeData != nullptr && !mimeData->formats().isEmpty()) || ++activePolls >= 20)
|| ++activePolls >= 20)
readClipboard(); readClipboard();
}); });
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
@@ -377,8 +365,7 @@ void MainWindow::loadSettings() {
* @return True when the application can work from the tray. * @return True when the application can work from the tray.
*/ */
bool MainWindow::hasValidSettings() const { bool MainWindow::hasValidSettings() const {
return !ui->urlLineEdit->text().trimmed().isEmpty() return !ui->urlLineEdit->text().trimmed().isEmpty() && !ui->apiKeyLineEdit->text().trimmed().isEmpty();
&& !ui->apiKeyLineEdit->text().trimmed().isEmpty();
} }
/** /**
+2 -4
View File
@@ -25,11 +25,9 @@ int main (int argc, char **argv) {
check(ClipboardUrl::parseText(QString::fromUtf8(text)) == expected, text); check(ClipboardUrl::parseText(QString::fromUtf8(text)) == expected, text);
} }
check(ClipboardUrl::parseText(QStringLiteral( check(ClipboardUrl::parseText(QStringLiteral(
"[Other label](https://git.himro.ca/explore/repos?filter=a%26b#section)")) "[Other label](https://git.himro.ca/explore/repos?filter=a%26b#section)")) == QUrl(QStringLiteral("https://git.himro.ca/explore/repos?filter=a%26b#section")),
== QUrl (QStringLiteral ("https://git.himro.ca/explore/repos?filter=a%26b#section")),
"Markdown must use the destination and preserve query and fragment"); "Markdown must use the destination and preserve query and fragment");
check (ClipboardUrl::parseText (QStringLiteral ("[Link](https://example.com/a_(b))")) check(ClipboardUrl::parseText(QStringLiteral("[Link](https://example.com/a_(b))")) == QUrl(QStringLiteral("https://example.com/a_(b)")),
== QUrl (QStringLiteral ("https://example.com/a_(b)")),
"Parentheses in URL paths must be preserved"); "Parentheses in URL paths must be preserved");
for (const auto &text: {"", "not a URL", "https://", "[Link](https://)"}) for (const auto &text: {"", "not a URL", "https://", "[Link](https://)"})
check(!ClipboardUrl::parseText(QString::fromUtf8(text)).isValid(), text); check(!ClipboardUrl::parseText(QString::fromUtf8(text)).isValid(), text);
+8 -7
View File
@@ -40,18 +40,18 @@ private slots:
QVERIFY(server.listen(QHostAddress::LocalHost)); QVERIFY(server.listen(QHostAddress::LocalHost));
QByteArray requestData; QByteArray requestData;
const QByteArray body = QJsonDocument(QJsonObject{ const QByteArray body = QJsonDocument(QJsonObject{
{"status", status}, {"code", code}, {"shorturl", shortUrl}, {"status", status},
{"url", QJsonObject {{"url", originalUrl}}} {"code", code},
}).toJson (QJsonDocument::Compact); {"shorturl", shortUrl},
{"url", QJsonObject{{"url", originalUrl}}}})
.toJson(QJsonDocument::Compact);
connect(&server, &QTcpServer::newConnection, this, [&]() { connect(&server, &QTcpServer::newConnection, this, [&]() {
auto *socket = server.nextPendingConnection(); auto *socket = server.nextPendingConnection();
connect(socket, &QTcpSocket::readyRead, &server, [&, socket]() { connect(socket, &QTcpSocket::readyRead, &server, [&, socket]() {
requestData += socket->readAll(); requestData += socket->readAll();
if (!requestData.contains("\r\n\r\n")) if (!requestData.contains("\r\n\r\n"))
return; return;
socket->write ("HTTP/1.1 " + QByteArray::number (httpStatus) socket->write("HTTP/1.1 " + QByteArray::number(httpStatus) + " Result\r\nContent-Type: application/json\r\nContent-Length: " + QByteArray::number(body.size()) + "\r\nConnection: close\r\n\r\n" + body);
+ " Result\r\nContent-Type: application/json\r\nContent-Length: "
+ QByteArray::number (body.size()) + "\r\nConnection: close\r\n\r\n" + body);
socket->disconnectFromHost(); socket->disconnectFromHost();
}); });
}); });
@@ -60,7 +60,8 @@ private slots:
QSignalSpy failed(&client, &YourlsClient::shortenFailed); QSignalSpy failed(&client, &YourlsClient::shortenFailed);
const QUrl source(QStringLiteral("https://git.himro.ca/explore/repos?q=a%26b&next=x+y#section")); const QUrl source(QStringLiteral("https://git.himro.ca/explore/repos?q=a%26b&next=x+y#section"));
client.shortenUrl({QStringLiteral("http://127.0.0.1:%1/api").arg(server.serverPort()), client.shortenUrl({QStringLiteral("http://127.0.0.1:%1/api").arg(server.serverPort()),
QStringLiteral ("test-signature")}, source); QStringLiteral("test-signature")},
source);
QTRY_COMPARE(succeeded.count() + failed.count(), 1); QTRY_COMPARE(succeeded.count() + failed.count(), 1);
QCOMPARE(succeeded.count(), success ? 1 : 0); QCOMPARE(succeeded.count(), success ? 1 : 0);
if (success) if (success)
+4 -13
View File
@@ -15,8 +15,7 @@
* @param parent QObject parent. * @param parent QObject parent.
*/ */
YourlsClient::YourlsClient(QObject *parent) YourlsClient::YourlsClient(QObject *parent)
: QObject (parent) : QObject(parent), m_networkAccessManager(new QNetworkAccessManager(this)) {
, m_networkAccessManager (new QNetworkAccessManager (this)) {
} }
/** /**
@@ -82,16 +81,9 @@ void YourlsClient::shortenUrl (const YourlsSettings &settings, const QUrl &longU
const QJsonDocument jsonDocument = QJsonDocument::fromJson(body, &parseError); const QJsonDocument jsonDocument = QJsonDocument::fromJson(body, &parseError);
const QJsonObject object = jsonDocument.object(); const QJsonObject object = jsonDocument.object();
const QUrl existingShortUrl(object.value(QStringLiteral("shorturl")).toString()); const QUrl existingShortUrl(object.value(QStringLiteral("shorturl")).toString());
const QUrl existingLongUrl (object.value (QStringLiteral ("url")).toObject() const QUrl existingLongUrl(object.value(QStringLiteral("url")).toObject().value(QStringLiteral("url")).toString());
.value (QStringLiteral ("url")).toString());
// YOURLS reports duplicate URLs as HTTP 400, but returns the existing link. // YOURLS reports duplicate URLs as HTTP 400, but returns the existing link.
if (reply->attribute (QNetworkRequest::HttpStatusCodeAttribute).toInt() == 400 if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 400 && object.value(QStringLiteral("status")).toString() == QStringLiteral("fail") && object.value(QStringLiteral("code")).toString() == QStringLiteral("error:url") && existingLongUrl == longUrl && existingShortUrl.isValid() && (existingShortUrl.scheme() == QStringLiteral("https") || existingShortUrl.scheme() == QStringLiteral("http")) && !existingShortUrl.host().isEmpty()) {
&& object.value (QStringLiteral ("status")).toString() == QStringLiteral ("fail")
&& object.value (QStringLiteral ("code")).toString() == QStringLiteral ("error:url")
&& existingLongUrl == longUrl && existingShortUrl.isValid()
&& (existingShortUrl.scheme() == QStringLiteral ("https")
|| existingShortUrl.scheme() == QStringLiteral ("http"))
&& !existingShortUrl.host().isEmpty()) {
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
qDebug() << "[yourls] reusing existing short URL:" << existingShortUrl; qDebug() << "[yourls] reusing existing short URL:" << existingShortUrl;
#endif #endif
@@ -144,8 +136,7 @@ void YourlsClient::shortenUrl (const YourlsSettings &settings, const QUrl &longU
} }
const QUrl shortUrl(shortUrlText); const QUrl shortUrl(shortUrlText);
if (!shortUrl.isValid() || shortUrl.host().isEmpty() if (!shortUrl.isValid() || shortUrl.host().isEmpty() || (shortUrl.scheme() != QStringLiteral("https") && shortUrl.scheme() != QStringLiteral("http"))) {
|| (shortUrl.scheme() != QStringLiteral ("https") && shortUrl.scheme() != QStringLiteral ("http"))) {
reply->deleteLater(); reply->deleteLater();
emit shortenFailed(QStringLiteral("YOURLS returned an invalid short URL: %1").arg(shortUrlText)); emit shortenFailed(QStringLiteral("YOURLS returned an invalid short URL: %1").arg(shortUrlText));
return; return;