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

tdeio/tdeio

  • tdeio
  • tdeio
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<TDETrader>;
31 
32 using namespace TDEIO;
33 
34 class TDETraderSorter
35 {
36 public:
37  TDETraderSorter() { m_pService = 0; };
38  TDETraderSorter( const TDETraderSorter& s ) : m_userPreference( s.m_userPreference ),
39  m_bAllowAsDefault( s.m_bAllowAsDefault ),
40  m_traderPreference( s.m_traderPreference ), m_pService( s.m_pService ) { }
41  TDETraderSorter( 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 TDETraderSorter& ) 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 TDETraderSorter::operator< ( const TDETraderSorter& _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 TDETrader* TDETrader::s_self = 0;
88 static KStaticDeleter<TDETrader> ktradersd;
89 
90 TDETrader* TDETrader::self()
91 {
92  if ( !s_self )
93  ktradersd.setObject( s_self, new TDETrader );
94 
95  return s_self;
96 }
97 
98 TDETrader::TDETrader()
99 {
100 }
101 
102 TDETrader::~TDETrader()
103 {
104 }
105 
106 TDETrader::OfferList TDETrader::query( const TQString& _servicetype, const TQString& _constraint,
107  const TQString& _preferences ) const
108 {
109  return query( _servicetype, TQString::null, _constraint, _preferences );
110 }
111 
112 TDETrader::OfferList TDETrader::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 = TDEIO::parseConstraints( _constraint );
122 
123  if ( !_preferences.isEmpty() )
124  prefs = TDEIO::parsePreferences( _preferences );
125 
126  KServiceTypeProfile::OfferList lst;
127  TDETrader::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<TDETraderSorter> 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( TDETraderSorter( (*it).service(), p.f, (*it).preference(), (*it).allowAsDefault() ) );
157  }
158  qBubbleSort( sorter );
159 
160  TQValueList<TDETraderSorter>::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 TDETrader::virtual_hook( int, void* )
184 { /*BASE::virtual_hook( id, data );*/ }
185 
186 #include "ktrader.moc"
TDETrader
A Trader interface, similar to the CORBA Trader.
Definition: ktrader.h:85
TDETrader::self
static TDETrader * self()
This is a static pointer to a TDETrader instance.
Definition: ktrader.cpp:90
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
TDEIO
A namespace for TDEIO globals.
Definition: authinfo.h:29
TDETrader::query
virtual OfferList query(const TQString &servicetype, const TQString &constraint=TQString::null, const TQString &preferences=TQString::null) const
The main function in the TDETrader class.
Definition: ktrader.cpp:106
TDETrader::~TDETrader
virtual ~TDETrader()
Standard destructor.
Definition: ktrader.cpp:102
TDETrader::OfferList
TQValueList< KService::Ptr > OfferList
A list of services.
Definition: ktrader.h:92

tdeio/tdeio

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

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.8.8
This website is maintained by Timothy Pearson.