Skip to content

Commit 20c4fb3

Browse files
committed
clients_icons.txt added to resources with a way to override
Introduced a new option options.iconsets.clients-capsfile to set custom clients_icons.txt
1 parent 9678a72 commit 20c4fb3

File tree

3 files changed

+45
-33
lines changed

3 files changed

+45
-33
lines changed

options/default.xml

+1
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ QLineEdit#le_status_text {
695695
<activities type="QString">default</activities>
696696
<affiliations type="QString">default</affiliations>
697697
<clients type="QString">default</clients>
698+
<clients-capsfile type="QString" comment="Override file for internal client_icons.txt"/>
698699
</iconsets>
699700
<messages>
700701
<default-outgoing-message-type type="QString">chat</default-outgoing-message-type>

psi.qrc

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
<file>options/macosx.xml</file>
77
<file>options/newprofile.xml</file>
88
<file>README.html</file>
9+
<file>client_icons.txt</file>
910
</qresource>
1011
</RCC>

src/psiiconset.cpp

+43-33
Original file line numberDiff line numberDiff line change
@@ -490,48 +490,58 @@ bool PsiIconset::loadClients()
490490
iconsId.insert(it.next()->name().section('/', 1, 1));
491491
}
492492

493-
QStringList dirs = ApplicationInfo::dataDirs();
494493
ClientIconMap cm; // start part, spec[spec2[spec3]]
495-
foreach (const QString &dataDir, dirs) {
496-
QFile capsConv(dataDir + QLatin1String("/client_icons.txt"));
494+
495+
auto readClientsDesc = [&](const QString &filePath) {
496+
QFile capsConv(filePath);
497497
/* file format: <icon res name> <left_part_of_cap1#inside1#inside2>,<left_part_of_cap2>
498498
next line the same.
499499
*/
500-
if (capsConv.open(QIODevice::ReadOnly)) {
501-
QTextStream stream(&capsConv);
502-
503-
QString line;
504-
while (!(line = stream.readLine()).isNull()) {
505-
line = line.trimmed();
506-
QString iconName = line.section(QLatin1Char(' '), 0, 0);
507-
if (!iconName.length() || !iconsId.contains(iconName)) {
508-
continue;
509-
}
510-
ClientIconCheck ic = { iconName, QStringList() };
511-
QString caps = line.mid(iconName.length());
512-
foreach (const QString &c, caps.split(QLatin1Char(','), QString::SkipEmptyParts)) {
513-
QString ct = c.trimmed();
514-
if (ct.length()) {
515-
QStringList spec = ct.split('#');
516-
if (spec.size() > 1) {
517-
ic.inside = spec.mid(1);
518-
} else {
519-
ic.inside.clear();
520-
}
521-
ClientIconMap::Iterator it = cm.find(spec[0]);
522-
if (it == cm.end()) {
523-
cm.insert(spec[0], QList<ClientIconCheck>() << ic);
524-
} else {
525-
it.value().append(ic);
526-
}
500+
if (!capsConv.open(QIODevice::ReadOnly))
501+
return false;
502+
503+
QTextStream stream(&capsConv);
504+
505+
QString line;
506+
while (!(line = stream.readLine()).isNull()) {
507+
line = line.trimmed();
508+
QString iconName = line.section(QLatin1Char(' '), 0, 0);
509+
if (!iconName.length() || !iconsId.contains(iconName)) {
510+
continue;
511+
}
512+
ClientIconCheck ic = { iconName, QStringList() };
513+
QString caps = line.mid(iconName.length());
514+
for (const QString &c : caps.split(QLatin1Char(','), QString::SkipEmptyParts)) {
515+
QString ct = c.trimmed();
516+
if (ct.length()) {
517+
QStringList spec = ct.split('#');
518+
if (spec.size() > 1) {
519+
ic.inside = spec.mid(1);
520+
} else {
521+
ic.inside.clear();
522+
}
523+
ClientIconMap::Iterator it = cm.find(spec[0]);
524+
if (it == cm.end()) {
525+
cm.insert(spec[0], QList<ClientIconCheck>() << ic);
526+
} else {
527+
it.value().append(ic);
527528
}
528529
}
529530
}
530-
/* insert end boundry element to make search implementation simple */
531-
cm.insert(QLatin1String("~"), QList<ClientIconCheck>());
532-
break;
533531
}
532+
/* insert end boundry element to make search implementation simple */
533+
cm.insert(QLatin1String("~"), QList<ClientIconCheck>());
534+
return true;
535+
};
536+
537+
auto customPath = PsiOptions::instance()->getOption("options.iconsets.clients-capsfile").toString();
538+
if (customPath.isEmpty() || !readClientsDesc(customPath)) {
539+
QStringList dirs = ApplicationInfo::dataDirs();
540+
for (const auto &dataDir : dirs)
541+
if (readClientsDesc(dataDir + QLatin1String("/client_icons.txt")))
542+
break;
534543
}
544+
535545
if (cm.isEmpty()) {
536546
qWarning("Failed to read client_icons.txt. Clients detection won't work");
537547
}

0 commit comments

Comments
 (0)