Merge branch 'master' of https://github.com/fluxer/kdelibs into devinfo

This commit is contained in:
Ivailo Monev 2021-07-05 15:26:56 +00:00
commit e870ca49d9
8 changed files with 22 additions and 69 deletions

View file

@ -388,7 +388,6 @@ KLockFile::LockResult KLockFile::lock(LockFlags options)
KLockFile::LockResult result; KLockFile::LockResult result;
int hardErrors = 5; int hardErrors = 5;
int n = 5;
while(true) { while(true) {
KDE_struct_stat st_buf; KDE_struct_stat st_buf;
// Try to create the lock file // Try to create the lock file

View file

@ -76,9 +76,6 @@ class KLocalizedStringPrivate
QString postFormat (const QString &text, QString postFormat (const QString &text,
const QString &lang, const QString &lang,
const QString &ctxt) const; const QString &ctxt) const;
static void notifyCatalogsUpdated (const QStringList &languages,
const QList<KCatalogName> &catalogs);
}; };
class KLocalizedStringPrivateStatics class KLocalizedStringPrivateStatics
@ -92,6 +89,7 @@ public:
} }
}; };
K_GLOBAL_STATIC(KLocalizedStringPrivateStatics, staticsKLSP) K_GLOBAL_STATIC(KLocalizedStringPrivateStatics, staticsKLSP)
Q_GLOBAL_STATIC(QMutex, staticsKLSPLock)
KLocalizedString::KLocalizedString () KLocalizedString::KLocalizedString ()
: d(new KLocalizedStringPrivate) : d(new KLocalizedStringPrivate)
@ -161,8 +159,6 @@ QString KLocalizedString::toString (const KLocale *locale,
QString KLocalizedStringPrivate::toString (const KLocale *locale, QString KLocalizedStringPrivate::toString (const KLocale *locale,
const QString *catalogName) const const QString *catalogName) const
{ {
const KLocalizedStringPrivateStatics *s = staticsKLSP;
QMutexLocker lock(kLocaleMutex()); QMutexLocker lock(kLocaleMutex());
// Assure the message has been supplied. // Assure the message has been supplied.
@ -211,9 +207,7 @@ QString KLocalizedStringPrivate::toString (const KLocale *locale,
// Substitute placeholders in ordinary translation. // Substitute placeholders in ordinary translation.
QString finalstr = substituteSimple(rawtrans); QString finalstr = substituteSimple(rawtrans);
// Post-format ordinary translation. // Post-format ordinary translation.
finalstr = postFormat(finalstr, lang, QString::fromLatin1(ctxt)); return postFormat(finalstr, lang, QString::fromLatin1(ctxt));
return finalstr;
} }
QString KLocalizedStringPrivate::selectForEnglish () const QString KLocalizedStringPrivate::selectForEnglish () const
@ -363,17 +357,13 @@ QString KLocalizedStringPrivate::postFormat (const QString &text,
const QString &lang, const QString &lang,
const QString &ctxt) const const QString &ctxt) const
{ {
QMutexLocker lock(staticsKLSPLock());
const KLocalizedStringPrivateStatics *s = staticsKLSP; const KLocalizedStringPrivateStatics *s = staticsKLSP;
QMutexLocker lock(kLocaleMutex());
QString finalstr = text;
// Transform any semantic markup into visual formatting. // Transform any semantic markup into visual formatting.
if (s->formatters.contains(lang)) { if (s->formatters.contains(lang)) {
finalstr = s->formatters[lang]->format(finalstr, ctxt); return s->formatters[lang]->format(text, ctxt);
} }
return text;
return finalstr;
} }
static QString wrapNum (const QString &tag, const QString &numstr, static QString wrapNum (const QString &tag, const QString &numstr,
@ -547,19 +537,11 @@ KLocalizedString ki18ncp (const char* ctxt,
void KLocalizedString::notifyCatalogsUpdated (const QStringList &languages, void KLocalizedString::notifyCatalogsUpdated (const QStringList &languages,
const QList<KCatalogName> &catalogs) const QList<KCatalogName> &catalogs)
{ {
KLocalizedStringPrivate::notifyCatalogsUpdated(languages, catalogs); QMutexLocker lock(staticsKLSPLock());
}
void KLocalizedStringPrivate::notifyCatalogsUpdated (const QStringList &languages,
const QList<KCatalogName> &catalogs)
{
if (staticsKLSP.isDestroyed()) { if (staticsKLSP.isDestroyed()) {
return; return;
} }
KLocalizedStringPrivateStatics *s = staticsKLSP; KLocalizedStringPrivateStatics *s = staticsKLSP;
// Very important: do not the mutex here.
//QMutexLocker lock(kLocaleMutex());
// Create visual formatters for each new language. // Create visual formatters for each new language.
foreach (const QString &lang, languages) { foreach (const QString &lang, languages) {
if (!s->formatters.contains(lang)) { if (!s->formatters.contains(lang)) {

View file

@ -708,7 +708,7 @@ QString KMimeType::mainExtension() const
{ {
Q_D(const KMimeType); Q_D(const KMimeType);
Q_FOREACH(const QString& pattern, patterns()) { Q_FOREACH(const QString& pattern, d->patterns()) {
// Skip if if looks like: README or *. or *.* // Skip if if looks like: README or *. or *.*
// or *.JP*G or *.JP? // or *.JP*G or *.JP?
if (pattern.startsWith(QLatin1String("*.")) && if (pattern.startsWith(QLatin1String("*.")) &&

View file

@ -52,8 +52,6 @@ public:
HostInfoAgentPrivate(); HostInfoAgentPrivate();
QHostInfo lookupHost(const QString &hostName, const unsigned long timeout); QHostInfo lookupHost(const QString &hostName, const unsigned long timeout);
QHostInfo lookupCachedHostInfoFor(const QString &hostName);
void cacheLookup(const QHostInfo &hostName);
protected: protected:
// reimplementation // reimplementation
@ -76,16 +74,6 @@ QHostInfo HostInfo::lookupHost(const QString &hostName, unsigned long timeout)
return hostInfoAgentPrivate->lookupHost(hostName, timeout); return hostInfoAgentPrivate->lookupHost(hostName, timeout);
} }
QHostInfo HostInfo::lookupCachedHostInfoFor(const QString& hostName)
{
return hostInfoAgentPrivate->lookupCachedHostInfoFor(hostName);
}
void HostInfo::cacheLookup(const QHostInfo &info)
{
hostInfoAgentPrivate->cacheLookup(info);
}
HostInfoAgentPrivate::HostInfoAgentPrivate() HostInfoAgentPrivate::HostInfoAgentPrivate()
: m_dnsCache(HOSTINFO_CACHE_SIZE) : m_dnsCache(HOSTINFO_CACHE_SIZE)
{ {
@ -106,7 +94,10 @@ QHostInfo HostInfoAgentPrivate::lookupHost(const QString &hostName, unsigned lon
} }
// Look up the name in the DNS cache... // Look up the name in the DNS cache...
hostInfo = HostInfo::lookupCachedHostInfoFor(hostName); const HostInfoPair* pair = m_dnsCache.object(hostName);
if (pair) {
hostInfo = pair->first;
}
if (!hostInfo.hostName().isEmpty() && hostInfo.error() == QHostInfo::NoError) { if (!hostInfo.hostName().isEmpty() && hostInfo.error() == QHostInfo::NoError) {
return hostInfo; return hostInfo;
} }
@ -136,29 +127,15 @@ QHostInfo HostInfoAgentPrivate::lookupHost(const QString &hostName, unsigned lon
return m_dnsCache.object(hostName)->first; return m_dnsCache.object(hostName)->first;
} }
void HostInfoAgentPrivate::cacheLookup(const QHostInfo &info) void HostInfoAgentPrivate::lookupFinished(const QHostInfo &hostInfo)
{ {
if (info.hostName().isEmpty() || info.error() != QHostInfo::NoError) { m_lookups.removeAll(hostInfo.lookupId());
if (hostInfo.hostName().isEmpty() || hostInfo.error() != QHostInfo::NoError) {
return; return;
} }
QTime expiration = QTime::currentTime(); QTime expiration = QTime::currentTime();
expiration.addSecs(HOSTINFO_EXPIRE_AFTER); expiration.addSecs(HOSTINFO_EXPIRE_AFTER);
m_dnsCache.insert(info.hostName(), new HostInfoPair(info, expiration)); m_dnsCache.insert(hostInfo.hostName(), new HostInfoPair(hostInfo, expiration));
}
QHostInfo HostInfoAgentPrivate::lookupCachedHostInfoFor(const QString& hostName)
{
const HostInfoPair* pair = m_dnsCache.object(hostName);
if (pair) {
return pair->first;
}
return QHostInfo();
}
void HostInfoAgentPrivate::lookupFinished(const QHostInfo &hostInfo)
{
m_lookups.removeAll(hostInfo.lookupId());
cacheLookup(hostInfo);
} }
void HostInfoAgentPrivate::timerEvent(QTimerEvent *event) void HostInfoAgentPrivate::timerEvent(QTimerEvent *event)

View file

@ -29,8 +29,6 @@ namespace KIO
namespace HostInfo namespace HostInfo
{ {
KIO_EXPORT QHostInfo lookupHost(const QString& hostName, unsigned long timeout); KIO_EXPORT QHostInfo lookupHost(const QString& hostName, unsigned long timeout);
KIO_EXPORT QHostInfo lookupCachedHostInfoFor(const QString& hostName);
KIO_EXPORT void cacheLookup(const QHostInfo& info);
} }
} }

View file

@ -722,9 +722,9 @@ protected:
/** /**
* Performs a DNS lookup for @p hostname and returns the result. * Performs a DNS lookup for @p hostname and returns the result.
* *
* This function uses the KIO/KHTML DNS cache to speed up the * This function uses the KIO DNS cache to speed up the lookup.
* lookup. It also avoids doing a reverse lookup if the given * It also avoids doing a reverse lookup if the givem host name
* host name is already an ip address. * is already an IP address.
* *
* \note All uri filter plugins that need to perform a hostname * \note All uri filter plugins that need to perform a hostname
* lookup should use this function. * lookup should use this function.
@ -735,7 +735,7 @@ protected:
* *
* @since 4.7 * @since 4.7
*/ */
QHostInfo resolveName (const QString& hostname, unsigned long timeout) const; QHostInfo resolveName(const QString& hostname, unsigned long timeout) const;
private: private:
class KUriFilterPluginPrivate * const d; class KUriFilterPluginPrivate * const d;

View file

@ -34,7 +34,6 @@
#include <kurl.h> #include <kurl.h>
#include <klocalizedstring.h> #include <klocalizedstring.h>
#include <kio/hostinfo_p.h>
namespace namespace
{ {
@ -168,11 +167,7 @@ namespace
// needless reverse lookup // needless reverse lookup
QHostAddress address ( host ); QHostAddress address ( host );
if ( address.isNull() ) { if ( address.isNull() ) {
QHostInfo hostInfo = KIO::HostInfo::lookupCachedHostInfoFor(host); QHostInfo hostInfo = QHostInfo::fromName(host);
if (hostInfo.hostName().isEmpty() || hostInfo.error() != QHostInfo::NoError) {
hostInfo = QHostInfo::fromName(host);
KIO::HostInfo::cacheLookup(hostInfo);
}
m_addressList = hostInfo.addresses(); m_addressList = hostInfo.addresses();
} else { } else {
m_addressList.clear(); m_addressList.clear();

View file

@ -221,6 +221,8 @@ QString UDevDevice::icon() const
case Solid::OpticalDisc::DiscType::BluRayRecordable: case Solid::OpticalDisc::DiscType::BluRayRecordable:
case Solid::OpticalDisc::DiscType::BluRayRewritable: case Solid::OpticalDisc::DiscType::BluRayRewritable:
return QLatin1String("media-optical-blu-ray"); return QLatin1String("media-optical-blu-ray");
default:
break;
} }
// fallback for every other optical disc // fallback for every other optical disc