Changeset View
Changeset View
Standalone View
Standalone View
menuinfo.cpp
Show All 13 Lines | |||||
14 | * You should have received a copy of the GNU General Public License | 14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
17 | * | 17 | * | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "menuinfo.h" | 20 | #include "menuinfo.h" | ||
21 | 21 | | |||
22 | #include <QRegExp> | 22 | #include <QRegularExpressionMatch> | ||
23 | 23 | | |||
24 | #include <KDesktopFile> | 24 | #include <KDesktopFile> | ||
25 | 25 | | |||
26 | #include <KConfigGroup> | 26 | #include <KConfigGroup> | ||
27 | #include <QStandardPaths> | 27 | #include <QStandardPaths> | ||
28 | 28 | | |||
29 | #include "globalaccel.h" | 29 | #include "globalaccel.h" | ||
30 | #include "menufile.h" | 30 | #include "menufile.h" | ||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | |||||
101 | } | 101 | } | ||
102 | 102 | | |||
103 | // Remove entry | 103 | // Remove entry | ||
104 | void MenuFolderInfo::take(MenuEntryInfo *entry) | 104 | void MenuFolderInfo::take(MenuEntryInfo *entry) | ||
105 | { | 105 | { | ||
106 | entries.removeAll(entry); | 106 | entries.removeAll(entry); | ||
107 | } | 107 | } | ||
108 | 108 | | |||
109 | QString uniqueCaption(const QString &caption) | ||||
110 | { | ||||
111 | static const QRegularExpression re(QStringLiteral("(.*)(?=-\\d+)")); | ||||
112 | const QRegularExpressionMatch match = re.match(caption); | ||||
113 | return match.hasMatch() ? match.captured(1) : caption; | ||||
114 | } | ||||
115 | | ||||
109 | // Return a unique sub-menu caption inspired by @p caption | 116 | // Return a unique sub-menu caption inspired by @p caption | ||
110 | QString MenuFolderInfo::uniqueMenuCaption(const QString &caption) | 117 | QString MenuFolderInfo::uniqueMenuCaption(const QString &caption) | ||
111 | { | 118 | { | ||
112 | QRegExp r(QStringLiteral("(.*)(?=-\\d+)")); | 119 | QString cap = uniqueCaption(caption); | ||
113 | QString cap = (r.indexIn(caption) > -1) ? r.cap(1) : caption; | | |||
114 | 120 | | |||
115 | QString result = caption; | 121 | QString result = caption; | ||
116 | 122 | | |||
117 | for (int n = 1; ++n;) { | 123 | for (int n = 1; ++n;) { | ||
118 | bool ok = true; | 124 | bool ok = true; | ||
119 | foreach (MenuFolderInfo *subFolderInfo, subFolders) { | 125 | foreach (MenuFolderInfo *subFolderInfo, subFolders) { | ||
120 | if (subFolderInfo->caption == result) { | 126 | if (subFolderInfo->caption == result) { | ||
121 | ok = false; | 127 | ok = false; | ||
122 | break; | 128 | break; | ||
123 | } | 129 | } | ||
124 | } | 130 | } | ||
125 | if (ok) { | 131 | if (ok) { | ||
126 | return result; | 132 | return result; | ||
127 | } | 133 | } | ||
128 | 134 | | |||
129 | result = cap + QStringLiteral("-%1").arg(n); | 135 | result = cap + QStringLiteral("-%1").arg(n); | ||
130 | } | 136 | } | ||
131 | return QString(); // Never reached | 137 | return QString(); // Never reached | ||
132 | } | 138 | } | ||
133 | 139 | | |||
134 | // Return a unique item caption inspired by @p caption | 140 | // Return a unique item caption inspired by @p caption | ||
135 | QString MenuFolderInfo::uniqueItemCaption(const QString &caption, const QString &exclude) | 141 | QString MenuFolderInfo::uniqueItemCaption(const QString &caption, const QString &exclude) | ||
136 | { | 142 | { | ||
137 | QRegExp r(QStringLiteral("(.*)(?=-\\d+)")); | 143 | QString cap = uniqueCaption(caption); | ||
138 | QString cap = (r.indexIn(caption) > -1) ? r.cap(1) : caption; | | |||
139 | 144 | | |||
140 | QString result = caption; | 145 | QString result = caption; | ||
141 | 146 | | |||
142 | for (int n = 1; ++n;) { | 147 | for (int n = 1; ++n;) { | ||
143 | bool ok = true; | 148 | bool ok = true; | ||
144 | if (result == exclude) { | 149 | if (result == exclude) { | ||
145 | ok = false; | 150 | ok = false; | ||
146 | } | 151 | } | ||
▲ Show 20 Lines • Show All 319 Lines • Show Last 20 Lines |