delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / kurifilter-plugins / fixhost / fixhosturifilter.cpp
blob34783168464d0eb1a6a5df742d7945d26854a036
1 /*
2 fixhostfilter.cpp
4 This file is part of the KDE project
5 Copyright (C) 2007 Lubos Lunak <llunak@suse.cz>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <config-runtime.h>
23 #include "fixhosturifilter.h"
25 #include <kdebug.h>
26 #include <kurl.h>
27 #include <k3resolver.h>
29 using namespace KNetwork;
31 /**
32 * IMPORTANT: If you change anything here, please run the regression test
33 * ../tests/kurifiltertest
36 FixHostUriFilter::FixHostUriFilter( QObject *parent, const QVariantList & /*args*/ )
37 : KUriFilterPlugin( "fixhosturifilter", parent )
41 bool FixHostUriFilter::filterUri( KUriFilterData& data ) const
43 KUrl url = data.uri();
44 QString cmd = url.url();
46 kDebug() << "FixHostUriFilter::filterUri: " << url;
48 KUrl url2 = url;
49 url2.setHost( "www." + url.host());
51 if(( url.protocol() == "http" || url.protocol() == "https" )
52 && !url.host().startsWith( "www." ) && !exists( url ) && exists( url2 ))
54 setFilteredUri( data, url2 );
55 setUriType( data, KUriFilterData::NetProtocol );
57 kDebug() << "FilteredUri: " << data.uri();
58 return true;
61 return false;
64 bool FixHostUriFilter::exists( const KUrl& url )
66 KResolver resolver( url.host());
67 resolver.setFamily( KResolver::InetFamily );
68 return( resolver.start() && resolver.wait( 5000 ) && resolver.error() == KResolver::NoError );
71 K_PLUGIN_FACTORY(FixHostUriFilterFactory, registerPlugin<FixHostUriFilter>();)
72 K_EXPORT_PLUGIN(FixHostUriFilterFactory("kcmkurifilt"))
74 #include "fixhosturifilter.moc"