[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    Re: KDE/kdebase/runtime/kurifilter-plugins/fixhost
From:       Dawit A <adawit () kde ! org>
Date:       2010-05-15 17:12:13
Message-ID: 201005151312.13913.adawit () kde ! org
[Download RAW message or body]

Great. One thing I can scratch off my TODO list. The only thing left now is to 
combine this plugin and the localdomain one...

Thanks.

On Saturday, May 15, 2010 13:03:28 Kevin Ottens wrote:
> SVN commit 1127170 by ervin:
> 
> Use the async API to avoid blocking the UI for too long. Just like the
> previous version now exists() blocks again for ~1s max.
> 
> CCMAIL: adawit@kde.org
> CCMAIL: thiago@kde.org
> 
> 
>  M  +24 -4     fixhosturifilter.cpp
>  M  +9 -1      fixhosturifilter.h
> 
> 
> ---
> trunk/KDE/kdebase/runtime/kurifilter-plugins/fixhost/fixhosturifilter.cpp
> #1127169:1127170 @@ -22,7 +22,7 @@
> 
>  #include "fixhosturifilter.h"
> 
> -#include <QtNetwork/QHostInfo>
> +#include <QtCore/QTimer>
> 
>  #include <kdebug.h>
>  #include <kurl.h>
> @@ -33,7 +33,7 @@
>   */
> 
>  FixHostUriFilter::FixHostUriFilter( QObject *parent, const QVariantList &
> /*args*/ ) -    : KUriFilterPlugin( "fixhosturifilter", parent )
> +    : KUriFilterPlugin( "fixhosturifilter", parent ), m_hostExists( false
> ) {
>  }
> 
> @@ -60,11 +60,31 @@
>      return false;
>  }
> 
> -bool FixHostUriFilter::exists( const KUrl& url )
> +void FixHostUriFilter::lookedUp( const QHostInfo &hostInfo )
>  {
> -    return QHostInfo::fromName( url.host() ).error() ==
> QHostInfo::NoError; +    m_hostExists = ( hostInfo.error() ==
> QHostInfo::NoError );
> +    m_eventLoop.exit();
>  }
> 
> +bool FixHostUriFilter::exists( const KUrl& url ) const
> +{
> +    FixHostUriFilter *self = const_cast<FixHostUriFilter*>( this );
> +    int lookupId = QHostInfo::lookupHost( url.host(), self,
> SLOT(lookedUp(QHostInfo)) ); +
> +    QTimer t;
> +    connect( &t, SIGNAL(timeout()), &m_eventLoop, SLOT(exit()) );
> +    t.start(1000);
> +
> +    m_hostExists = false;
> +    m_eventLoop.exec();
> +
> +    t.stop();
> +
> +    QHostInfo::abortHostLookup( lookupId );
> +
> +    return m_hostExists;
> +}
> +
>  K_PLUGIN_FACTORY(FixHostUriFilterFactory,
> registerPlugin<FixHostUriFilter>();)
> K_EXPORT_PLUGIN(FixHostUriFilterFactory("kcmkurifilt"))
> 
> --- trunk/KDE/kdebase/runtime/kurifilter-plugins/fixhost/fixhosturifilter.h
> #1127169:1127170 @@ -26,6 +26,9 @@
>  #include <kgenericfactory.h>
>  #include <kurifilter.h>
> 
> +#include<QtCore/QEventLoop>
> +#include<QtNetwork/QHostInfo>
> +
>  /*
>   This filter tries to automatically prepend www. to http URLs that
>   need it.
> @@ -38,8 +41,13 @@
>      public:
>          FixHostUriFilter( QObject* parent, const QVariantList& args );
>          virtual bool filterUri( KUriFilterData &data ) const;
> +    private slots:
> +        void lookedUp( const QHostInfo &hostInfo );
>      private:
> -        static bool exists( const KUrl& url );
> +        bool exists( const KUrl& url ) const;
> +
> +        mutable QEventLoop m_eventLoop;
> +        mutable bool m_hostExists;
>  };
> 
>  #endif
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic