Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved user flag handling #37

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ extern QDir lastMapDir;
extern QDir vymInstallDir;
#endif
extern QString zipToolPath;
extern QString flagsPath;

extern QColor vymBlue;

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion tex/vym.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down