Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/knewfilemenu.cpp
Show First 20 Lines • Show All 887 Lines • ▼ Show 20 Line(s) | 886 | struct EntryWithName { | |||
---|---|---|---|---|---|
888 | KNewFileMenuSingleton::Entry entry; | 888 | KNewFileMenuSingleton::Entry entry; | ||
889 | }; | 889 | }; | ||
890 | 890 | | |||
891 | void KNewFileMenuPrivate::_k_slotFillTemplates() | 891 | void KNewFileMenuPrivate::_k_slotFillTemplates() | ||
892 | { | 892 | { | ||
893 | KNewFileMenuSingleton *s = kNewMenuGlobals(); | 893 | KNewFileMenuSingleton *s = kNewMenuGlobals(); | ||
894 | //qDebug(); | 894 | //qDebug(); | ||
895 | 895 | | |||
896 | QStringList dirs = { QStringLiteral(":/kio5/newfile-templates") }; | 896 | const QStringList qrcTemplates = { QStringLiteral(":/kio5/newfile-templates") }; | ||
897 | dirs += QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("templates"), QStandardPaths::LocateDirectory); | 897 | const QStringList installedTemplates = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("templates"), QStandardPaths::LocateDirectory); | ||
898 | const QStringList templates = qrcTemplates + installedTemplates; | ||||
898 | 899 | | |||
899 | // Ensure any changes in the templates dir will call this | 900 | // Ensure any changes in the templates dir will call this | ||
900 | if (! s->dirWatch) { | 901 | if (! s->dirWatch) { | ||
901 | s->dirWatch = new KDirWatch; | 902 | s->dirWatch = new KDirWatch; | ||
902 | for (QStringList::const_iterator it = dirs.constBegin(); it != dirs.constEnd(); ++it) { | 903 | for (const QString &dir : installedTemplates) { | ||
903 | //qDebug() << "Templates resource dir:" << *it; | 904 | s->dirWatch->addDir(dir); | ||
904 | s->dirWatch->addDir(*it); | | |||
905 | } | 905 | } | ||
906 | QObject::connect(s->dirWatch, SIGNAL(dirty(QString)), | 906 | QObject::connect(s->dirWatch, SIGNAL(dirty(QString)), | ||
907 | q, SLOT(_k_slotFillTemplates())); | 907 | q, SLOT(_k_slotFillTemplates())); | ||
908 | QObject::connect(s->dirWatch, SIGNAL(created(QString)), | 908 | QObject::connect(s->dirWatch, SIGNAL(created(QString)), | ||
909 | q, SLOT(_k_slotFillTemplates())); | 909 | q, SLOT(_k_slotFillTemplates())); | ||
910 | QObject::connect(s->dirWatch, SIGNAL(deleted(QString)), | 910 | QObject::connect(s->dirWatch, SIGNAL(deleted(QString)), | ||
911 | q, SLOT(_k_slotFillTemplates())); | 911 | q, SLOT(_k_slotFillTemplates())); | ||
912 | // Ok, this doesn't cope with new dirs in XDG_DATA_DIRS, but that's another story | 912 | // Ok, this doesn't cope with new dirs in XDG_DATA_DIRS, but that's another story | ||
913 | } | 913 | } | ||
914 | ++s->templatesVersion; | 914 | ++s->templatesVersion; | ||
915 | s->filesParsed = false; | 915 | s->filesParsed = false; | ||
916 | 916 | | |||
917 | s->templatesList->clear(); | 917 | s->templatesList->clear(); | ||
918 | 918 | | |||
919 | // Look into "templates" dirs. | 919 | // Look into "templates" dirs. | ||
920 | QStringList files; | 920 | QStringList files; | ||
921 | QDir dir; | 921 | QDir dir; | ||
922 | 922 | | |||
923 | Q_FOREACH (const QString &path, dirs) { | 923 | for (const QString &path : templates) { | ||
924 | dir.setPath(path); | 924 | dir.setPath(path); | ||
925 | const QStringList &entryList(dir.entryList(QStringList() << QStringLiteral("*.desktop"), QDir::Files)); | 925 | const QStringList &entryList(dir.entryList(QStringList() << QStringLiteral("*.desktop"), QDir::Files)); | ||
926 | Q_FOREACH (const QString &entry, entryList) { | 926 | Q_FOREACH (const QString &entry, entryList) { | ||
927 | const QString file = dir.path() + QLatin1Char('/') + entry; | 927 | const QString file = dir.path() + QLatin1Char('/') + entry; | ||
928 | files.append(file); | 928 | files.append(file); | ||
929 | } | 929 | } | ||
930 | } | 930 | } | ||
931 | 931 | | |||
▲ Show 20 Lines • Show All 338 Lines • Show Last 20 Lines |