24 #include <kiconloader.h> 26 #include <kmimetype.h> 27 #include <klibloader.h> 28 #include <kstaticdeleter.h> 29 #include <tdeparts/componentfactory.h> 33 #include "tdelficon.h" 34 #endif // HAVE_ELFICON 36 #include "kurifilter.h" 38 template class TQPtrList<KURIFilterPlugin>;
41 :TQObject( parent, name )
43 m_strName = TQString::fromLatin1( name );
49 if ( data.
uri() != uri )
52 data.m_bChanged =
true;
56 class KURIFilterDataPrivate
59 KURIFilterDataPrivate() {};
67 m_iType = data.m_iType;
69 m_strErrMsg = data.m_strErrMsg;
70 m_strIconName = data.m_strIconName;
71 m_bChanged = data.m_bChanged;
72 m_bCheckForExecutables = data.m_bCheckForExecutables;
73 d =
new KURIFilterDataPrivate;
87 m_iType = KURIFilterData::UNKNOWN;
89 m_strErrMsg = TQString::null;
90 m_strIconName = TQString::null;
91 m_bCheckForExecutables =
true;
93 d =
new KURIFilterDataPrivate;
94 d->typedString = url.url();
99 m_iType = KURIFilterData::UNKNOWN;
101 m_strErrMsg = TQString::null;
102 m_strIconName = TQString::null;
103 m_bCheckForExecutables =
true;
105 d =
new KURIFilterDataPrivate;
106 d->typedString = url;
109 void KURIFilterData::reinit(
const KURL &url)
115 void KURIFilterData::reinit(
const TQString &url)
123 return d->typedString;
128 m_bCheckForExecutables = check;
133 return !d->args.isEmpty();
138 return !d->abs_path.isEmpty();
145 if( (!m_pURI.isValid() || m_pURI.isLocalFile()) )
147 d->abs_path = absPath;
167 m_customIconPixmap = TQPixmap();
170 case KURIFilterData::LOCAL_FILE:
171 case KURIFilterData::LOCAL_DIR:
172 case KURIFilterData::NET_PROTOCOL:
177 case KURIFilterData::EXECUTABLE:
179 TQString exeName = m_pURI.url();
180 exeName = exeName.mid( exeName.findRev(
'/' ) + 1 );
186 if (service && service->icon() != TQString::fromLatin1(
"unknown" )) {
187 m_strIconName = service->icon();
189 else if ( !TDEGlobal::iconLoader()->loadIcon( exeName, TDEIcon::NoGroup, 16, TDEIcon::DefaultState, 0,
true ).isNull() ) {
190 m_strIconName = exeName;
194 m_strIconName = TQString::fromLatin1(
"application-x-executable");
196 #else // HAVE_ELFICON 200 if (service && service->icon() != TQString::fromLatin1(
"unknown" )) {
201 m_strIconName = service->icon();
203 else if ( !TDEGlobal::iconLoader()->loadIcon( exeName, TDEIcon::NoGroup, 16, TDEIcon::DefaultState, 0,
true ).isNull() ) {
204 m_strIconName = exeName;
208 m_strIconName = TQString::fromLatin1(
"application-x-executable");
212 unsigned int icon_size;
213 libr_icon *icon = NULL;
214 libr_file *handle = NULL;
215 libr_access_t access = LIBR_READ;
216 char libr_can_continue = 1;
218 if((handle = libr_open(const_cast<char*>(m_pURI.path().ascii()), access)) == NULL)
220 kdWarning() <<
"failed to open file " << m_pURI.path() << endl;
221 libr_can_continue = 0;
224 if (libr_can_continue == 1) {
226 icon = libr_icon_geticon_bysize(handle, icon_size);
228 if (libr_can_continue == 1) {
231 int iconresnamefound = 0;
232 iconentry *entry = NULL;
234 if(!get_iconlist(handle, &icons))
237 kdDebug() <<
"failed to obtain ELF icon from " << m_pURI.path() <<
": " << libr_errmsg() << endl;
240 TQString sysIconName = elf_get_resource(handle,
".metadata_sysicon");
241 if (!sysIconName.isEmpty()) {
242 if (TDEGlobal::iconLoader()->iconPath(sysIconName.ascii(), 0,
true) !=
"") {
243 m_strIconName = sysIconName;
248 libr_can_continue = 0;
251 while((entry = get_nexticon(&icons, entry)) != NULL)
256 icon = libr_icon_geticon_byname(handle, entry->name);
258 if (TDEGlobal::iconLoader()->iconPath(entry->name, 0,
true) !=
"") {
259 iconresnamefound = 1;
260 m_strIconName = entry->name;
266 if (libr_can_continue == 1) {
267 if ((iconresnamefound == 0) && (icon)) {
269 size_t icon_data_length;
270 char* icondata = libr_icon_malloc(icon, &icon_data_length);
271 m_customIconPixmap.loadFromData(static_cast<uchar*>(static_cast<void*>(icondata)), icon_data_length);
272 if (icon_size != 0) {
273 TQImage ip = m_customIconPixmap.convertToImage();
274 ip = ip.smoothScale(icon_size, icon_size);
275 m_customIconPixmap.convertFromImage(ip);
278 libr_icon_close(icon);
285 #endif // HAVE_ELFICON 288 case KURIFilterData::HELP:
290 m_strIconName = TQString::fromLatin1(
"khelpcenter");
293 case KURIFilterData::SHELL:
295 m_strIconName = TQString::fromLatin1(
"konsole");
298 case KURIFilterData::ERROR:
299 case KURIFilterData::BLOCKED:
301 m_strIconName = TQString::fromLatin1(
"error");
305 m_strIconName = TQString::null;
310 return m_strIconName;
315 return m_customIconPixmap;
326 static KStaticDeleter<KURIFilter> kurifiltersd;
331 s_self = kurifiltersd.setObject(s_self,
new KURIFilter);
337 m_lstPlugins.setAutoDelete(
true);
347 bool filtered =
false;
352 if( filters.isEmpty() )
353 use_plugins = m_lstPlugins;
357 for( TQStringList::ConstIterator lst = filters.begin(); lst != filters.end(); ++lst )
359 TQPtrListIterator<KURIFilterPlugin> it( m_lstPlugins );
360 for( ; it.current() ; ++it )
362 if( (*lst) == it.current()->name() )
365 use_plugins.append( it.current() );
372 TQPtrListIterator<KURIFilterPlugin> it( use_plugins );
375 for (; it.current() && !filtered; ++it)
378 filtered |= it.current()->filterURI( data );
386 bool filtered =
filterURI( data, filters );
387 if( filtered ) uri = data.
uri();
394 bool filtered =
filterURI( data, filters );
395 if( filtered ) uri = data.
uri().url();
411 return data.
uri().url();
416 return TQPtrListIterator<KURIFilterPlugin>(m_lstPlugins);
422 for(TQPtrListIterator<KURIFilterPlugin> i = pluginsIterator(); *i; ++i)
423 list.append((*i)->name());
431 TDETrader::OfferList::ConstIterator it = offers.begin();
432 TDETrader::OfferList::ConstIterator end = offers.end();
434 for (; it != end; ++it )
436 KURIFilterPlugin *plugin = KParts::ComponentFactory::createInstanceFromService<KURIFilterPlugin>( *it, 0, (*it)->desktopEntryName().latin1() );
438 m_lstPlugins.append( plugin );
448 void KURIFilterPlugin::virtual_hook(
int,
void* )
451 #include "kurifilter.moc" TQString typedString() const
static TDETrader * self()
This is a static pointer to a TDETrader instance.
static TQString iconForURL(const KURL &_url, mode_t _mode=0)
The same functionality as pixmapForURL(), but this method returns the name of the icon to load...
void loadPlugins()
Loads all allowed plugins.
void setFilteredURI(KURIFilterData &data, const KURL &uri) const
Sets the the URL in data to uri.
static KURIFilter * self()
Returns an instance of KURIFilter.
virtual bool filterURI(KURIFilterData &data) const =0
Filters a URI.
A list of filter plugins.
bool hasAbsolutePath() const
Checks whether the supplied data had an absolute path.
bool filterURI(KURIFilterData &data, const TQStringList &filters=TQStringList())
Filters the URI given by the object URIFilterData.
bool setAbsolutePath(const TQString &abs_path)
Sets the absolute path to be used whenever the supplied data is a relative local URL.
KURIFilterData()
Default constructor.
KURL filteredURI(const KURL &uri, const TQStringList &filters=TQStringList())
Returns the filtered URI.
void setArguments(KURIFilterData &data, const TQString &args) const
Sets the arguments and options string in data to args if any were found during filterting.
virtual OfferList query(const TQString &servicetype, const TQString &constraint=TQString::null, const TQString &preferences=TQString::null) const
The main function in the TDETrader class.
KURL uri() const
Returns the filtered or the original URL.
TQPixmap customIconPixmap()
Returns the current custom icon The results are valid iff iconName() has returned TQString::null...
TQString iconName()
Returns the name of the icon that matches the current filtered URL.
bool hasArgsAndOptions() const
Checks whether the current data is a local resource with command line options and arguments...
~KURIFilterData()
Destructor.
TQPtrListIterator< KURIFilterPlugin > pluginsIterator() const
Return an iterator to iterate over all loaded plugins.
A basic message object used for exchanging filtering information between the filter plugins and the a...
Manages the filtering of URIs.
TQString argsAndOptions() const
Returns the command line options and arguments for a local resource when present. ...
TQString absolutePath() const
Returns the absolute path if one has already been set.
static Ptr serviceByDesktopName(const TQString &_name)
Find a service by the name of its desktop file, not depending on its actual location (as long as it's...
TQValueList< KService::Ptr > OfferList
A list of services.
void setCheckForExecutables(bool check)
Check whether the provided uri is executable or not.
KURIFilterPlugin(TQObject *parent=0, const char *name=0, double pri=1.0)
Constructs a filter plugin with a given name and priority.
void init(const KURL &url)
Initializes the KURIFilterData on construction.
Base class for URI filter plugins.
KURIFilter()
A protected constructor.
TQStringList pluginNames() const
Return a list of the names of all loaded plugins.