• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kio/kio
 

kio/kio

  • kio
  • kio
ktrader.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2000 Torben Weis <weis@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "ktrader.h"
20 #include "ktraderparsetree.h"
21 
22 #include <tqtl.h>
23 #include <tqbuffer.h>
24 
25 #include <kuserprofile.h>
26 #include <kstandarddirs.h>
27 #include <kstaticdeleter.h>
28 #include <kdebug.h>
29 
30 template class KStaticDeleter<KTrader>;
31 
32 using namespace KIO;
33 
34 class KTraderSorter
35 {
36 public:
37  KTraderSorter() { m_pService = 0; };
38  KTraderSorter( const KTraderSorter& s ) : m_userPreference( s.m_userPreference ),
39  m_bAllowAsDefault( s.m_bAllowAsDefault ),
40  m_traderPreference( s.m_traderPreference ), m_pService( s.m_pService ) { }
41  KTraderSorter( const KService::Ptr &_service, double _pref1, int _pref2, bool _default )
42  { m_pService = _service;
43  m_userPreference = _pref2;
44  m_traderPreference = _pref1;
45  m_bAllowAsDefault = _default;
46  }
47 
48  KService::Ptr service() const { return m_pService; }
49 
50  bool operator< ( const KTraderSorter& ) const;
51 
52 private:
57  int m_userPreference;
61  bool m_bAllowAsDefault;
62 
67  double m_traderPreference;
68 
69  KService::Ptr m_pService;
70 };
71 
72 bool KTraderSorter::operator< ( const KTraderSorter& _o ) const
73 {
74  if ( _o.m_bAllowAsDefault && !m_bAllowAsDefault )
75  return true;
76  if ( _o.m_userPreference > m_userPreference )
77  return true;
78  if ( _o.m_userPreference < m_userPreference )
79  return false;
80  if ( _o.m_traderPreference > m_traderPreference )
81  return true;
82  return false;
83 }
84 
85 // --------------------------------------------------
86 
87 KTrader* KTrader::s_self = 0;
88 static KStaticDeleter<KTrader> ktradersd;
89 
90 KTrader* KTrader::self()
91 {
92  if ( !s_self )
93  ktradersd.setObject( s_self, new KTrader );
94 
95  return s_self;
96 }
97 
98 KTrader::KTrader()
99 {
100 }
101 
102 KTrader::~KTrader()
103 {
104 }
105 
106 KTrader::OfferList KTrader::query( const TQString& _servicetype, const TQString& _constraint,
107  const TQString& _preferences ) const
108 {
109  return query( _servicetype, TQString::null, _constraint, _preferences );
110 }
111 
112 KTrader::OfferList KTrader::query( const TQString& _servicetype, const TQString& _genericServiceType,
113  const TQString& _constraint,
114  const TQString& _preferences ) const
115 {
116  // TODO: catch errors here
117  ParseTreeBase::Ptr constr;
118  ParseTreeBase::Ptr prefs;
119 
120  if ( !_constraint.isEmpty() )
121  constr = KIO::parseConstraints( _constraint );
122 
123  if ( !_preferences.isEmpty() )
124  prefs = KIO::parsePreferences( _preferences );
125 
126  KServiceTypeProfile::OfferList lst;
127  KTrader::OfferList ret;
128 
129  // Get all services of this service type.
130  lst = KServiceTypeProfile::offers( _servicetype, _genericServiceType );
131  if ( lst.count() == 0 )
132  return ret;
133 
134  if ( !!constr )
135  {
136  // Find all services matching the constraint
137  // and remove the other ones
138  KServiceTypeProfile::OfferList::Iterator it = lst.begin();
139  while( it != lst.end() )
140  {
141  if ( matchConstraint( constr, (*it).service(), lst ) != 1 )
142  it = lst.remove( it );
143  else
144  ++it;
145  }
146  }
147 
148  if ( !!prefs )
149  {
150  TQValueList<KTraderSorter> sorter;
151  KServiceTypeProfile::OfferList::Iterator it = lst.begin();
152  for( ; it != lst.end(); ++it )
153  {
154  PreferencesReturn p = matchPreferences( prefs, (*it).service(), lst );
155  if ( p.type == PreferencesReturn::PRT_DOUBLE )
156  sorter.append( KTraderSorter( (*it).service(), p.f, (*it).preference(), (*it).allowAsDefault() ) );
157  }
158  qBubbleSort( sorter );
159 
160  TQValueList<KTraderSorter>::Iterator it2 = sorter.begin();
161  for( ; it2 != sorter.end(); ++it2 )
162  ret.prepend( (*it2).service() );
163  }
164  else
165  {
166  KServiceTypeProfile::OfferList::Iterator it = lst.begin();
167  for( ; it != lst.end(); ++it )
168  ret.append( (*it).service() );
169  }
170 
171 #ifndef NDEBUG
172  TQString query = _servicetype;
173  if ( !_genericServiceType.isEmpty() ) {
174  query += ", ";
175  query += _genericServiceType;
176  }
177  kdDebug(7014) << "query for " << query
178  << " : returning " << ret.count() << " offers" << endl;
179 #endif
180  return ret;
181 }
182 
183 void KTrader::virtual_hook( int, void* )
184 { /*BASE::virtual_hook( id, data );*/ }
185 
186 #include "ktrader.moc"
KServiceTypeProfile::offers
OfferList offers() const
Returns the list of all service offers for the service types that are represented by this profile...
Definition: kuserprofile.cpp:260
KIO
A namespace for KIO globals.
Definition: authinfo.h:29
KTrader
A Trader interface, similar to the CORBA Trader.
Definition: ktrader.h:85
KTrader::query
virtual OfferList query(const TQString &servicetype, const TQString &constraint=TQString::null, const TQString &preferences=TQString::null) const
The main function in the KTrader class.
Definition: ktrader.cpp:106
KTrader::~KTrader
virtual ~KTrader()
Standard destructor.
Definition: ktrader.cpp:102
KTrader::OfferList
TQValueList< KService::Ptr > OfferList
A list of services.
Definition: ktrader.h:92
KTrader::self
static KTrader * self()
This is a static pointer to a KTrader instance.
Definition: ktrader.cpp:90

kio/kio

Skip menu "kio/kio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kio/kio

Skip menu "kio/kio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/kio by doxygen 1.8.8
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |