~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to kcontrol/kio/fakeuaprovider.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-27 12:09:48 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080527120948-dottsyd5rcwhzd36
Tags: 4:4.0.80-1ubuntu1
* Merge with Debian
 - remove 97_fix_target_link_libraries.diff
 - Add replaces/conflicts on -kde4 packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (c) 2001 Dawit Alemayehu <adawit@kde.org>
3
 
 *
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.
8
 
 *
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.
13
 
 *
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.
17
 
 */
18
 
 
19
 
#include <time.h>
20
 
#include <sys/utsname.h>
21
 
 
22
 
 
23
 
#include <kdebug.h>
24
 
#include <klocale.h>
25
 
#include <kstandarddirs.h>
26
 
 
27
 
#include "fakeuaprovider.h"
28
 
 
29
 
#define UA_PTOS(x) (*it)->property(x).toString()
30
 
#define QFL(x) QString::fromLatin1(x)
31
 
 
32
 
FakeUASProvider::FakeUASProvider()
33
 
{
34
 
   m_bIsDirty = true;
35
 
}
36
 
 
37
 
FakeUASProvider::StatusCode FakeUASProvider::createNewUAProvider( const QString& uaStr )
38
 
{
39
 
  QStringList split;
40
 
  int pos = (uaStr).find("::");
41
 
 
42
 
  if ( pos == -1 )
43
 
  {
44
 
    pos = (uaStr).find(':');
45
 
    if ( pos != -1 )
46
 
    {
47
 
      split.append(uaStr.left(pos));
48
 
      split.append(uaStr.mid(pos+1));
49
 
    }
50
 
  }
51
 
  else
52
 
  {
53
 
    split = QStringList::split("::", uaStr);
54
 
  }
55
 
 
56
 
  if ( m_lstIdentity.contains(split[1]) )
57
 
    return DUPLICATE_ENTRY;
58
 
  else
59
 
  {
60
 
    int count = split.count();
61
 
    m_lstIdentity.append( split[1] );
62
 
    if ( count > 2 )
63
 
      m_lstAlias.append(split[2]);
64
 
    else
65
 
      m_lstAlias.append( split[1]);
66
 
  }
67
 
 
68
 
  return SUCCEEDED;
69
 
}
70
 
 
71
 
void FakeUASProvider::loadFromDesktopFiles()
72
 
{
73
 
  m_providers.clear();
74
 
  m_providers = KTrader::self()->query("UserAgentStrings");
75
 
}
76
 
 
77
 
void FakeUASProvider::parseDescription()
78
 
{
79
 
  QString tmp;
80
 
 
81
 
  KTrader::OfferList::ConstIterator it = m_providers.begin();
82
 
  KTrader::OfferList::ConstIterator lastItem = m_providers.end();
83
 
 
84
 
  for ( ; it != lastItem; ++it )
85
 
  {
86
 
    tmp = UA_PTOS("X-KDE-UA-FULL");
87
 
 
88
 
    if ( (*it)->property("X-KDE-UA-DYNAMIC-ENTRY").toBool() )
89
 
    {
90
 
      struct utsname utsn;
91
 
      uname( &utsn );
92
 
 
93
 
      tmp.replace( QFL("appSysName"), QString(utsn.sysname) );
94
 
      tmp.replace( QFL("appSysRelease"), QString(utsn.release) );
95
 
      tmp.replace( QFL("appMachineType"), QString(utsn.machine) );
96
 
 
97
 
      QStringList languageList = KGlobal::locale()->languageList();
98
 
      if ( languageList.count() )
99
 
      {
100
 
        QStringList::Iterator it = languageList.find( QString::fromLatin1("C") );
101
 
        if( it != languageList.end() )
102
 
        {
103
 
          if( languageList.contains( QString::fromLatin1("en") ) > 0 )
104
 
            languageList.remove( it );
105
 
          else
106
 
            (*it) = QString::fromLatin1("en");
107
 
        }
108
 
      }
109
 
 
110
 
      tmp.replace( QFL("appLanguage"), QString("%1").arg(languageList.join(", ")) );
111
 
      tmp.replace( QFL("appPlatform"), QFL("X11") );
112
 
    }
113
 
 
114
 
    // Ignore dups...
115
 
    if ( m_lstIdentity.contains(tmp) )
116
 
      continue;
117
 
 
118
 
    m_lstIdentity << tmp;
119
 
 
120
 
    tmp = QString("%1 %2").arg(UA_PTOS("X-KDE-UA-SYSNAME")).arg(UA_PTOS("X-KDE-UA-SYSRELEASE"));
121
 
    if ( tmp.stripWhiteSpace().isEmpty() )
122
 
      tmp = QString("%1 %2").arg(UA_PTOS("X-KDE-UA-"
123
 
                    "NAME")).arg(UA_PTOS("X-KDE-UA-VERSION"));
124
 
    else
125
 
      tmp = QString("%1 %2 on %3").arg(UA_PTOS("X-KDE-UA-"
126
 
                    "NAME")).arg(UA_PTOS("X-KDE-UA-VERSION")).arg(tmp);
127
 
 
128
 
    m_lstAlias << tmp;
129
 
  }
130
 
 
131
 
  m_bIsDirty = false;
132
 
}
133
 
 
134
 
QString FakeUASProvider::aliasStr( const QString& name )
135
 
{
136
 
  int id = userAgentStringList().findIndex(name);
137
 
  if ( id == -1 )
138
 
    return QString::null;
139
 
  else
140
 
    return m_lstAlias[id];
141
 
}
142
 
 
143
 
QString FakeUASProvider::agentStr( const QString& name )
144
 
{
145
 
  int id = userAgentAliasList().findIndex(name);
146
 
  if ( id == -1 )
147
 
    return QString::null;
148
 
  else
149
 
    return m_lstIdentity[id];
150
 
}
151
 
 
152
 
 
153
 
QStringList FakeUASProvider::userAgentStringList()
154
 
{
155
 
  if ( m_bIsDirty )
156
 
  {
157
 
    loadFromDesktopFiles();
158
 
    if ( !m_providers.count() )
159
 
      return QStringList();
160
 
    parseDescription();
161
 
  }
162
 
  return m_lstIdentity;
163
 
}
164
 
 
165
 
QStringList FakeUASProvider::userAgentAliasList ()
166
 
{
167
 
  if ( m_bIsDirty )
168
 
  {
169
 
    loadFromDesktopFiles();
170
 
    if ( !m_providers.count() )
171
 
      return QStringList();
172
 
    parseDescription();
173
 
  }
174
 
  return m_lstAlias;
175
 
}
176