2 * Copyright (c) 2001 Dawit Alemayehu <adawit@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
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
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "useragentinfo.h"
24 #include <sys/utsname.h>
29 #include <kservicetypetrader.h>
30 #include <kstandarddirs.h>
32 #define UA_PTOS(x) (*it)->property(x).toString()
33 #define QFL(x) QLatin1String(x)
35 UserAgentInfo::UserAgentInfo()
40 UserAgentInfo::StatusCode
UserAgentInfo::createNewUAProvider( const QString
& uaStr
)
43 int pos
= (uaStr
).indexOf("::");
47 pos
= (uaStr
).indexOf(':');
50 split
.append(uaStr
.left(pos
));
51 split
.append(uaStr
.mid(pos
+1));
56 split
= uaStr
.split( "::");
59 if ( m_lstIdentity
.contains(split
[1]) )
60 return DUPLICATE_ENTRY
;
63 int count
= split
.count();
64 m_lstIdentity
.append( split
[1] );
66 m_lstAlias
.append(split
[2]);
68 m_lstAlias
.append( split
[1]);
74 void UserAgentInfo::loadFromDesktopFiles()
77 m_providers
= KServiceTypeTrader::self()->query("UserAgentStrings");
80 void UserAgentInfo::parseDescription()
84 KService::List::ConstIterator it
= m_providers
.constBegin();
85 KService::List::ConstIterator lastItem
= m_providers
.constEnd();
87 for ( ; it
!= lastItem
; ++it
)
89 tmp
= UA_PTOS("X-KDE-UA-FULL");
91 if ( (*it
)->property("X-KDE-UA-DYNAMIC-ENTRY").toBool() )
96 tmp
.replace( QFL("appSysName"), QString(utsn
.sysname
) );
97 tmp
.replace( QFL("appSysRelease"), QString(utsn
.release
) );
98 tmp
.replace( QFL("appMachineType"), QString(utsn
.machine
) );
100 QStringList languageList
= KGlobal::locale()->languageList();
101 if ( languageList
.count() )
103 int ind
= languageList
.indexOf( QLatin1String("C") );
106 if( languageList
.contains( QLatin1String("en") ) )
107 languageList
.removeAt( ind
);
109 languageList
.value(ind
) = QLatin1String("en");
113 tmp
.replace( QFL("appLanguage"), QString("%1").arg(languageList
.join(", ")) );
114 tmp
.replace( QFL("appPlatform"), QFL("X11") );
118 if ( m_lstIdentity
.contains(tmp
) )
121 m_lstIdentity
<< tmp
;
123 tmp
= QString("%1 %2").arg(UA_PTOS("X-KDE-UA-SYSNAME")).arg(UA_PTOS("X-KDE-UA-SYSRELEASE"));
124 if ( tmp
.trimmed().isEmpty() )
125 tmp
= QString("%1 %2").arg(UA_PTOS("X-KDE-UA-"
126 "NAME")).arg(UA_PTOS("X-KDE-UA-VERSION"));
128 tmp
= QString("%1 %2 on %3").arg(UA_PTOS("X-KDE-UA-"
129 "NAME")).arg(UA_PTOS("X-KDE-UA-VERSION")).arg(tmp
);
137 QString
UserAgentInfo::aliasStr( const QString
& name
)
139 int id
= userAgentStringList().indexOf(name
);
143 return m_lstAlias
[id
];
146 QString
UserAgentInfo::agentStr( const QString
& name
)
148 int id
= userAgentAliasList().indexOf(name
);
152 return m_lstIdentity
[id
];
156 QStringList
UserAgentInfo::userAgentStringList()
160 loadFromDesktopFiles();
161 if ( !m_providers
.count() )
162 return QStringList();
165 return m_lstIdentity
;
168 QStringList
UserAgentInfo::userAgentAliasList ()
172 loadFromDesktopFiles();
173 if ( !m_providers
.count() )
174 return QStringList();