Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / apps / konqueror / settings / kio / useragentinfo.cpp
blobea6e731b2caf0672dd5edf4eac82d5bac1b6d21f
1 /*
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.
19 // Own
20 #include "useragentinfo.h"
22 // std
23 #include <time.h>
24 #include <sys/utsname.h>
26 // KDE
27 #include <kdebug.h>
28 #include <klocale.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()
37 m_bIsDirty = true;
40 UserAgentInfo::StatusCode UserAgentInfo::createNewUAProvider( const QString& uaStr )
42 QStringList split;
43 int pos = (uaStr).indexOf("::");
45 if ( pos == -1 )
47 pos = (uaStr).indexOf(':');
48 if ( pos != -1 )
50 split.append(uaStr.left(pos));
51 split.append(uaStr.mid(pos+1));
54 else
56 split = uaStr.split( "::");
59 if ( m_lstIdentity.contains(split[1]) )
60 return DUPLICATE_ENTRY;
61 else
63 int count = split.count();
64 m_lstIdentity.append( split[1] );
65 if ( count > 2 )
66 m_lstAlias.append(split[2]);
67 else
68 m_lstAlias.append( split[1]);
71 return SUCCEEDED;
74 void UserAgentInfo::loadFromDesktopFiles()
76 m_providers.clear();
77 m_providers = KServiceTypeTrader::self()->query("UserAgentStrings");
80 void UserAgentInfo::parseDescription()
82 QString tmp;
84 KService::List::ConstIterator it = m_providers.begin();
85 KService::List::ConstIterator lastItem = m_providers.end();
87 for ( ; it != lastItem; ++it )
89 tmp = UA_PTOS("X-KDE-UA-FULL");
91 if ( (*it)->property("X-KDE-UA-DYNAMIC-ENTRY").toBool() )
93 struct utsname utsn;
94 uname( &utsn );
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") );
104 if( ind >= 0 )
106 if( languageList.contains( QLatin1String("en") ) )
107 languageList.removeAt( ind );
108 else
109 languageList.value(ind) = QLatin1String("en");
113 tmp.replace( QFL("appLanguage"), QString("%1").arg(languageList.join(", ")) );
114 tmp.replace( QFL("appPlatform"), QFL("X11") );
117 // Ignore dups...
118 if ( m_lstIdentity.contains(tmp) )
119 continue;
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"));
127 else
128 tmp = QString("%1 %2 on %3").arg(UA_PTOS("X-KDE-UA-"
129 "NAME")).arg(UA_PTOS("X-KDE-UA-VERSION")).arg(tmp);
131 m_lstAlias << tmp;
134 m_bIsDirty = false;
137 QString UserAgentInfo::aliasStr( const QString& name )
139 int id = userAgentStringList().indexOf(name);
140 if ( id == -1 )
141 return QString();
142 else
143 return m_lstAlias[id];
146 QString UserAgentInfo::agentStr( const QString& name )
148 int id = userAgentAliasList().indexOf(name);
149 if ( id == -1 )
150 return QString();
151 else
152 return m_lstIdentity[id];
156 QStringList UserAgentInfo::userAgentStringList()
158 if ( m_bIsDirty )
160 loadFromDesktopFiles();
161 if ( !m_providers.count() )
162 return QStringList();
163 parseDescription();
165 return m_lstIdentity;
168 QStringList UserAgentInfo::userAgentAliasList ()
170 if ( m_bIsDirty )
172 loadFromDesktopFiles();
173 if ( !m_providers.count() )
174 return QStringList();
175 parseDescription();
177 return m_lstAlias;