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

kio/kio

  • kio
  • kio
kurifilter.cpp
1 /* This file is part of the KDE libraries
2  * Copyright (C) 2000 Yves Arrouye <yves@realnames.com>
3  * Copyright (C) 2000 Dawit Alemayehu <adawit at kde.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  **/
20 
21 #include <config.h>
22 
23 #include <kdebug.h>
24 #include <kiconloader.h>
25 #include <ktrader.h>
26 #include <kmimetype.h>
27 #include <klibloader.h>
28 #include <kstaticdeleter.h>
29 #include <kparts/componentfactory.h>
30 
31 #include "kurifilter.h"
32 
33 template class TQPtrList<KURIFilterPlugin>;
34 
35 KURIFilterPlugin::KURIFilterPlugin( TQObject *parent, const char *name, double pri )
36  :TQObject( parent, name )
37 {
38  m_strName = TQString::fromLatin1( name );
39  m_dblPriority = pri;
40 }
41 
42 void KURIFilterPlugin::setFilteredURI( KURIFilterData& data, const KURL& uri ) const
43 {
44  if ( data.uri() != uri )
45  {
46  data.m_pURI = uri;
47  data.m_bChanged = true;
48  }
49 }
50 
51 class KURIFilterDataPrivate
52 {
53 public:
54  KURIFilterDataPrivate() {};
55  TQString abs_path;
56  TQString args;
57  TQString typedString;
58 };
59 
60 KURIFilterData::KURIFilterData( const KURIFilterData& data )
61 {
62  m_iType = data.m_iType;
63  m_pURI = data.m_pURI;
64  m_strErrMsg = data.m_strErrMsg;
65  m_strIconName = data.m_strIconName;
66  m_bChanged = data.m_bChanged;
67  m_bCheckForExecutables = data.m_bCheckForExecutables;
68  d = new KURIFilterDataPrivate;
69  d->abs_path = data.absolutePath();
70  d->typedString = data.typedString();
71  d->args = data.argsAndOptions();
72 }
73 
74 KURIFilterData::~KURIFilterData()
75 {
76  delete d;
77  d = 0;
78 }
79 
80 void KURIFilterData::init( const KURL& url )
81 {
82  m_iType = KURIFilterData::UNKNOWN;
83  m_pURI = url;
84  m_strErrMsg = TQString::null;
85  m_strIconName = TQString::null;
86  m_bCheckForExecutables = true;
87  m_bChanged = true;
88  d = new KURIFilterDataPrivate;
89  d->typedString = url.url();
90 }
91 
92 void KURIFilterData::init( const TQString& url )
93 {
94  m_iType = KURIFilterData::UNKNOWN;
95  m_pURI = url;
96  m_strErrMsg = TQString::null;
97  m_strIconName = TQString::null;
98  m_bCheckForExecutables = true;
99  m_bChanged = true;
100  d = new KURIFilterDataPrivate;
101  d->typedString = url;
102 }
103 
104 void KURIFilterData::reinit(const KURL &url)
105 {
106  delete d;
107  init(url);
108 }
109 
110 void KURIFilterData::reinit(const TQString &url)
111 {
112  delete d;
113  init(url);
114 }
115 
116 TQString KURIFilterData::typedString() const
117 {
118  return d->typedString;
119 }
120 
121 void KURIFilterData::setCheckForExecutables( bool check )
122 {
123  m_bCheckForExecutables = check;
124 }
125 
126 bool KURIFilterData::hasArgsAndOptions() const
127 {
128  return !d->args.isEmpty();
129 }
130 
131 bool KURIFilterData::hasAbsolutePath() const
132 {
133  return !d->abs_path.isEmpty();
134 }
135 
136 bool KURIFilterData::setAbsolutePath( const TQString& absPath )
137 {
138  // Since a malformed URL could possibly be a relative
139  // URL we tag it as a possible local resource...
140  if( (!m_pURI.isValid() || m_pURI.isLocalFile()) )
141  {
142  d->abs_path = absPath;
143  return true;
144  }
145  return false;
146 }
147 
148 TQString KURIFilterData::absolutePath() const
149 {
150  return d->abs_path;
151 }
152 
153 TQString KURIFilterData::argsAndOptions() const
154 {
155  return d->args;
156 }
157 
158 TQString KURIFilterData::iconName()
159 {
160  if( m_bChanged )
161  {
162  switch ( m_iType )
163  {
164  case KURIFilterData::LOCAL_FILE:
165  case KURIFilterData::LOCAL_DIR:
166  case KURIFilterData::NET_PROTOCOL:
167  {
168  m_strIconName = KMimeType::iconForURL( m_pURI );
169  break;
170  }
171  case KURIFilterData::EXECUTABLE:
172  {
173  TQString exeName = m_pURI.url();
174  exeName = exeName.mid( exeName.findRev( '/' ) + 1 ); // strip path if given
175  KService::Ptr service = KService::serviceByDesktopName( exeName );
176  if (service && service->icon() != TQString::fromLatin1( "unknown" ))
177  m_strIconName = service->icon();
178  // Try to find an icon with the same name as the binary (useful for non-kde apps)
179  else if ( !KGlobal::iconLoader()->loadIcon( exeName, KIcon::NoGroup, 16, KIcon::DefaultState, 0, true ).isNull() )
180  m_strIconName = exeName;
181  else
182  // not found, use default
183  m_strIconName = TQString::fromLatin1("exec");
184  break;
185  }
186  case KURIFilterData::HELP:
187  {
188  m_strIconName = TQString::fromLatin1("khelpcenter");
189  break;
190  }
191  case KURIFilterData::SHELL:
192  {
193  m_strIconName = TQString::fromLatin1("konsole");
194  break;
195  }
196  case KURIFilterData::ERROR:
197  case KURIFilterData::BLOCKED:
198  {
199  m_strIconName = TQString::fromLatin1("error");
200  break;
201  }
202  default:
203  m_strIconName = TQString::null;
204  break;
205  }
206  m_bChanged = false;
207  }
208  return m_strIconName;
209 }
210 
211 //******************************************** KURIFilterPlugin **********************************************
212 void KURIFilterPlugin::setArguments( KURIFilterData& data, const TQString& args ) const
213 {
214  data.d->args = args;
215 }
216 
217 //******************************************** KURIFilter **********************************************
218 KURIFilter *KURIFilter::s_self;
219 static KStaticDeleter<KURIFilter> kurifiltersd;
220 
221 KURIFilter *KURIFilter::self()
222 {
223  if (!s_self)
224  s_self = kurifiltersd.setObject(s_self, new KURIFilter);
225  return s_self;
226 }
227 
228 KURIFilter::KURIFilter()
229 {
230  m_lstPlugins.setAutoDelete(true);
231  loadPlugins();
232 }
233 
234 KURIFilter::~KURIFilter()
235 {
236 }
237 
238 bool KURIFilter::filterURI( KURIFilterData& data, const TQStringList& filters )
239 {
240  bool filtered = false;
241  KURIFilterPluginList use_plugins;
242 
243  // If we have a filter list, only include the once
244  // explicitly specified by it. Otherwise, use all available filters...
245  if( filters.isEmpty() )
246  use_plugins = m_lstPlugins; // Use everything that is loaded...
247  else
248  {
249  //kdDebug() << "Named plugins requested..." << endl;
250  for( TQStringList::ConstIterator lst = filters.begin(); lst != filters.end(); ++lst )
251  {
252  TQPtrListIterator<KURIFilterPlugin> it( m_lstPlugins );
253  for( ; it.current() ; ++it )
254  {
255  if( (*lst) == it.current()->name() )
256  {
257  //kdDebug() << "Will use filter plugin named: " << it.current()->name() << endl;
258  use_plugins.append( it.current() );
259  break; // We already found it ; so lets test the next named filter...
260  }
261  }
262  }
263  }
264 
265  TQPtrListIterator<KURIFilterPlugin> it( use_plugins );
266  //kdDebug() << "Using " << use_plugins.count() << " out of the "
267  // << m_lstPlugins.count() << " available plugins" << endl;
268  for (; it.current() && !filtered; ++it)
269  {
270  //kdDebug() << "Using a filter plugin named: " << it.current()->name() << endl;
271  filtered |= it.current()->filterURI( data );
272  }
273  return filtered;
274 }
275 
276 bool KURIFilter::filterURI( KURL& uri, const TQStringList& filters )
277 {
278  KURIFilterData data = uri;
279  bool filtered = filterURI( data, filters );
280  if( filtered ) uri = data.uri();
281  return filtered;
282 }
283 
284 bool KURIFilter::filterURI( TQString& uri, const TQStringList& filters )
285 {
286  KURIFilterData data = uri;
287  bool filtered = filterURI( data, filters );
288  if( filtered ) uri = data.uri().url();
289  return filtered;
290 
291 }
292 
293 KURL KURIFilter::filteredURI( const KURL &uri, const TQStringList& filters )
294 {
295  KURIFilterData data = uri;
296  filterURI( data, filters );
297  return data.uri();
298 }
299 
300 TQString KURIFilter::filteredURI( const TQString &uri, const TQStringList& filters )
301 {
302  KURIFilterData data = uri;
303  filterURI( data, filters );
304  return data.uri().url();
305 }
306 
307 TQPtrListIterator<KURIFilterPlugin> KURIFilter::pluginsIterator() const
308 {
309  return TQPtrListIterator<KURIFilterPlugin>(m_lstPlugins);
310 }
311 
312 TQStringList KURIFilter::pluginNames() const
313 {
314  TQStringList list;
315  for(TQPtrListIterator<KURIFilterPlugin> i = pluginsIterator(); *i; ++i)
316  list.append((*i)->name());
317  return list;
318 }
319 
320 void KURIFilter::loadPlugins()
321 {
322  KTrader::OfferList offers = KTrader::self()->query( "KURIFilter/Plugin" );
323 
324  KTrader::OfferList::ConstIterator it = offers.begin();
325  KTrader::OfferList::ConstIterator end = offers.end();
326 
327  for (; it != end; ++it )
328  {
329  KURIFilterPlugin *plugin = KParts::ComponentFactory::createInstanceFromService<KURIFilterPlugin>( *it, 0, (*it)->desktopEntryName().latin1() );
330  if ( plugin )
331  m_lstPlugins.append( plugin );
332  }
333 
334  // NOTE: Plugin priority is now determined by
335  // the entry in the .desktop files...
336  // TODO: Config dialog to differentiate "system"
337  // plugins from "user-defined" ones...
338  // m_lstPlugins.sort();
339 }
340 
341 void KURIFilterPlugin::virtual_hook( int, void* )
342 { /*BASE::virtual_hook( id, data );*/ }
343 
344 #include "kurifilter.moc"

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.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |