From 8793531d8fc06baa3663b3a2a596a8d3b00d9e98 Mon Sep 17 00:00:00 2001 From: Daniel Rossberg <33295041+drossberg@users.noreply.github.com> Date: Fri, 15 Sep 2023 16:55:24 +0200 Subject: [PATCH 1/2] Improved user flag handling - User flags get the sha1 checksum of their image bitmap as UUID (if they don't already have one) - This way, they will be recognized, if it isn't their first appearance, and duplicate entries in the user flag toolbar will be avoided - Domain-specific flags can be provided with a custom installation in the flags/user directory --- src/mainwindow.cpp | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5226b96a..ca84ffe8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -136,6 +136,7 @@ extern QDir lastMapDir; extern QDir vymInstallDir; #endif extern QString zipToolPath; +extern QString flagsPath; extern QColor vymBlue; @@ -2720,6 +2721,19 @@ void Main::setupFlagActions() addToolBarBreak(); + // Add user flags + QDir userFlagsDirectory(flagsPath + "user"); + QStringList supportedImageFiles = QString("*.png *.bmp *.xbm *.jpg *.png " + "*.xpm *.gif *.pnm *.svg *.svgz").split(' '); + QFileInfoList userFlagsList = userFlagsDirectory.entryInfoList(supportedImageFiles, + QDir::Files | QDir::NoDotAndDotDot); + + for (int userFlagIndex = 0; userFlagIndex < userFlagsList.size(); ++userFlagIndex) { + QString userFlagPath = userFlagsList[userFlagIndex].absoluteFilePath(); + + setupFlag(userFlagPath, Flag::UserFlag, userFlagPath, ""); + } + // Add entry now, to avoid chicken and egg problem and position toolbar // after all others: setupFlag(":/flag-stopsign.svg", Flag::StandardFlag, "stopsign", @@ -2912,12 +2926,34 @@ Flag *Main::setupFlag(const QString &path, Flag::FlagType type, flag = standardFlagsMaster->createFlag(path); break; - case Flag::UserFlag: - flag = userFlagsMaster->createFlag(path); - - if (flag &&!uid.isNull()) + case Flag::UserFlag: { // User flags read from file already have a Uuid - use it - flag->setUuid(uid); + // If there is no valid Uuid - generate one from image's binary representation + QUuid flagUuid = uid; + + if (flagUuid.isNull()) { + QFile flagFile(path); + + if (flagFile.open(QIODevice::ReadOnly)) { + QByteArray flagContent = flagFile.readAll(); + flagUuid = QUuid::createUuidV5(QUuid(), flagContent); + } + } + + if (!flagUuid.isNull()) { + flag = userFlagsMaster->findFlagByUid(flagUuid); + + // if flag apparently exist, reuse it + if (flag != NULL) + return flag; + } + + flag = userFlagsMaster->createFlag(path); + + if (flag &&!flagUuid.isNull()) + // User flags read from file already have a Uuid - use it + flag->setUuid(flagUuid); + } break; case Flag::SystemFlag: From 386a43f9f8365b9cd54300a0d938856cc0af458b Mon Sep 17 00:00:00 2001 From: Daniel Rossberg <33295041+drossberg@users.noreply.github.com> Date: Mon, 18 Sep 2023 16:44:14 +0200 Subject: [PATCH 2/2] user documentation of new flag handling --- tex/vym.tex | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tex/vym.tex b/tex/vym.tex index 035640da..503d61b9 100644 --- a/tex/vym.tex +++ b/tex/vym.tex @@ -1642,7 +1642,7 @@ \subsection{Configuration file} The file can be edited manually, or on Mac~OS~X with Property List Editor (installed with xtools). On windows you can use {\tt regedit.exe}. -\subsection{Path to ressources} +\subsection{Path to ressources} \label{ressources} \vym will try to find its ressources (images, stylesheets, filters, etc.) in the following places: \begin{enumerate} @@ -1653,6 +1653,15 @@ \subsection{Path to ressources} \item {\tt /usr/local/share/vym} \end{enumerate} +\subsection{User flags} +User, project, organization, etc.\ specific flags can be stored in the {\tt flags/user} +subdirectory of the ressources (see \ref{ressources} above). +This way, they will be available in the user flags toolbar at program start. + +The image files can be any of PNG, BMP, XBM, JPG, PNG, XPM, GIF, PNM, SVG, and SVGZ +format. +The file name, without the extension, will be used as the name of the flag. + \subsection{Command line options} \label{options} \lstinputlisting{help.tex} You can also give several filenames at the commandline to let \vym open