+
+docstring InsetInfoParams::getDate(string const & iname, QDate const date) const
+{
+ QLocale loc;
+ if (lang)
+ loc = QLocale(toqstr(lang->code()));
+ if (iname == "long")
+ return qstring_to_ucs4(loc.toString(date, QLocale::LongFormat));
+ else if (iname == "short")
+ return qstring_to_ucs4(loc.toString(date, QLocale::ShortFormat));
+ else if (iname == "ISO")
+ return qstring_to_ucs4(date.toString(Qt::ISODate));
+ else if (iname == "loclong")
+ return lang ? qstring_to_ucs4(loc.toString(date, toqstr(lang->dateFormat(0))))
+ : _("No long date format (language unknown)!");
+ else if (iname == "locmedium")
+ return lang ? qstring_to_ucs4(loc.toString(date, toqstr(lang->dateFormat(1))))
+ : _("No medium date format (language unknown)!");
+ else if (iname == "locshort")
+ return lang ? qstring_to_ucs4(loc.toString(date, toqstr(lang->dateFormat(2))))
+ : _("No short date format (language unknown)!");
+ else
+ return qstring_to_ucs4(loc.toString(date, toqstr(iname)));
+}
+
+
+docstring InsetInfoParams::getTime(string const & iname, QTime const time) const
+{
+ QLocale loc;
+ if (lang)
+ loc = QLocale(toqstr(lang->code()));
+ if (iname == "long")
+ return qstring_to_ucs4(loc.toString(time, QLocale::LongFormat));
+ else if (iname == "short")
+ return qstring_to_ucs4(loc.toString(time, QLocale::ShortFormat));
+ else if (iname == "ISO")
+ return qstring_to_ucs4(time.toString(Qt::ISODate));
+ else
+ return qstring_to_ucs4(loc.toString(time, toqstr(iname)));
+}
+
+
+vector<pair<string,docstring>> InsetInfoParams::getArguments(Buffer const * buf,
+ string const & itype) const
+{
+ vector<pair<string,docstring>> result;
+
+ switch (nameTranslator().find(itype)) {
+ case UNKNOWN_INFO:
+ result.push_back(make_pair("invalid", _("Please select a valid type!")));
+ break;
+
+ case SHORTCUT_INFO:
+ case SHORTCUTS_INFO:
+ case MENU_INFO:
+ case ICON_INFO: {
+ result.push_back(make_pair("custom", _("Custom")));
+ for (auto const & name_code : lyxaction) {
+ string const lfun = name_code.first;
+ if (!lfun.empty())
+ result.push_back(make_pair(lfun, from_ascii(lfun)));
+ }
+ break;
+ }
+
+ case L7N_INFO:
+ result.push_back(make_pair("custom", _("Custom")));
+ break;
+
+ case LYXRC_INFO: {
+ result.push_back(make_pair("custom", _("Custom")));
+ set<string> rcs = lyxrc.getRCs();
+ for (auto const & rc : rcs)
+ result.push_back(make_pair(rc, from_ascii(rc)));
+ break;
+ }
+
+ case PACKAGE_INFO:
+ case TEXTCLASS_INFO: {
+ result.push_back(make_pair("custom", _("Custom")));
+ string const filename = (itype == "package") ? "styFiles.lst"
+ : "clsFiles.lst";
+ set<string> flist = getTexFileList(filename);
+ for (auto const & f : flist)
+ result.push_back(make_pair(f, from_utf8(f)));
+ break;
+ }
+
+ case BUFFER_INFO:
+ result.push_back(make_pair("name", _("File name (with extension)")));
+ result.push_back(make_pair("name-noext", _("File name (without extension)")));
+ result.push_back(make_pair("path", _("File path")));
+ result.push_back(make_pair("class", _("Used text class")));
+ break;
+
+ case VCS_INFO: {
+ if (!buf->lyxvc().inUse()) {
+ result.push_back(make_pair("invalid", _("No version control!")));
+ break;
+ }
+ result.push_back(make_pair("revision", _("Revision[[Version Control]]")));
+ result.push_back(make_pair("revision-abbrev", _("Abbreviated revision[[Version Control]]")));
+ result.push_back(make_pair("tree-revision", _("Tree revision")));
+ result.push_back(make_pair("author", _("Author")));
+ result.push_back(make_pair("date", _("Date")));
+ result.push_back(make_pair("time", _("Time[[of day]]")));
+ break;
+ }
+
+ case LYX_INFO:
+ result.push_back(make_pair("version", _("LyX version")));
+ result.push_back(make_pair("layoutformat", _("LyX layout format")));
+ break;
+
+ case FIXDATE_INFO:
+ case DATE_INFO:
+ case MODDATE_INFO: {
+ string const dt = split(name, '@');
+ QDate date;
+ if (itype == "moddate")
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
+ date = QDateTime::fromSecsSinceEpoch(buf->fileName().lastModified()).date();
+#else
+ date = QDateTime::fromTime_t(buf->fileName().lastModified()).date();
+#endif
+ else if (itype == "fixdate" && !dt.empty()) {
+ QDate const gdate = QDate::fromString(toqstr(dt), Qt::ISODate);
+ date = (gdate.isValid()) ? gdate : QDate::currentDate();
+ } else
+ date = QDate::currentDate();
+ result.push_back(make_pair("long",getDate("long", date)));
+ result.push_back(make_pair("short", getDate("short", date)));
+ result.push_back(make_pair("loclong", getDate("loclong", date)));
+ result.push_back(make_pair("locmedium", getDate("locmedium", date)));
+ result.push_back(make_pair("locshort", getDate("locshort", date)));
+ result.push_back(make_pair("ISO", getDate("ISO", date)));
+ result.push_back(make_pair("yyyy", getDate("yyyy", date)));
+ result.push_back(make_pair("MMMM", getDate("MMMM", date)));
+ result.push_back(make_pair("MMM", getDate("MMM", date)));
+ result.push_back(make_pair("dddd", getDate("dddd", date)));
+ result.push_back(make_pair("ddd", getDate("ddd", date)));
+ result.push_back(make_pair("custom", _("Custom")));
+ break;
+ }
+ case FIXTIME_INFO:
+ case TIME_INFO:
+ case MODTIME_INFO: {
+ string const tt = split(name, '@');
+ QTime time;
+ if (itype == "modtime")
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
+ time = QDateTime::fromSecsSinceEpoch(buf->fileName().lastModified()).time();
+#else
+ time = QDateTime::fromTime_t(buf->fileName().lastModified()).time();
+#endif
+ else if (itype == "fixtime" && !tt.empty()) {
+ QTime const gtime = QTime::fromString(toqstr(tt), Qt::ISODate);
+ time = (gtime.isValid()) ? gtime : QTime::currentTime();
+ } else
+ time = QTime::currentTime();
+ result.push_back(make_pair("long",getTime("long", time)));
+ result.push_back(make_pair("short", getTime("short", time)));
+ result.push_back(make_pair("ISO", getTime("ISO", time)));
+ result.push_back(make_pair("custom", _("Custom")));
+ break;
+ }
+ }
+
+ return result;
+}
+
+
+bool InsetInfoParams::validateArgument(Buffer const * buf, docstring const & arg,
+ bool const usedefaults) const
+{
+ string type;
+ string name = trim(split(to_utf8(arg), type, ' '));
+ if (name.empty() && usedefaults)
+ name = defaultValueTranslator().find(type);
+
+ switch (nameTranslator().find(type)) {
+ case UNKNOWN_INFO:
+ return false;
+
+ case SHORTCUT_INFO:
+ case SHORTCUTS_INFO:
+ case MENU_INFO: {
+ FuncRequest func = lyxaction.lookupFunc(name);
+ return func.action() != LFUN_UNKNOWN_ACTION;
+ }
+
+ case L7N_INFO:
+ return !name.empty();
+
+ case ICON_INFO: {
+ FuncCode const action = lyxaction.lookupFunc(name).action();
+ if (action == LFUN_UNKNOWN_ACTION) {
+ string dir = "images";
+ return !imageLibFileSearch(dir, name, "svgz,png").empty();
+ }
+ return true;
+ }
+
+ case LYXRC_INFO: {
+ set<string> rcs = lyxrc.getRCs();
+ return rcs.find(name) != rcs.end();
+ }
+
+ case PACKAGE_INFO:
+ case TEXTCLASS_INFO:
+ return true;
+
+ case BUFFER_INFO:
+ return (name == "name" || name == "name-noext"
+ || name == "path" || name == "class");
+
+ case VCS_INFO:
+ if (name == "revision" || name == "revision-abbrev" || name == "tree-revision"
+ || name == "author" || name == "date" || name == "time")
+ return buf->lyxvc().inUse();
+ return false;
+
+ case LYX_INFO:
+ return name == "version" || name == "layoutformat";
+
+ case FIXDATE_INFO: {
+ string date;
+ string piece;
+ date = split(name, piece, '@');
+ if (!date.empty() && !QDate::fromString(toqstr(date), Qt::ISODate).isValid())
+ return false;
+ if (!piece.empty())
+ name = piece;
+ }
+ // fall through
+ case DATE_INFO:
+ case MODDATE_INFO: {
+ if (name == "long" || name == "short" || name == "ISO")
+ return true;
+ else {
+ QDate date = QDate::currentDate();
+ return !date.toString(toqstr(name)).isEmpty();
+ }
+ }
+ case FIXTIME_INFO: {
+ string time;
+ string piece;
+ time = split(name, piece, '@');
+ if (!time.empty() && !QTime::fromString(toqstr(time), Qt::ISODate).isValid())
+ return false;
+ if (!piece.empty())
+ name = piece;
+ }
+ // fall through
+ case TIME_INFO:
+ case MODTIME_INFO: {
+ if (name == "long" || name == "short" || name == "ISO")
+ return true;
+ else {
+ QTime time = QTime::currentTime();
+ return !time.toString(toqstr(name)).isEmpty();
+ }
+ }
+ }
+
+ return false;
+}
+
+
+
+
+string InsetInfoParams::infoType() const
+{
+ return nameTranslator().find(type);
+}
+
+
+