[Kde-bindings] Help with loading an image from a URL

Richard Dale rdale at foton.es
Thu Jun 7 11:35:57 UTC 2007


On Wednesday 06 June 2007, Pau Garcia i Quiles wrote:
> Quoting Chris Gow <sniffy at rogers.com>:
> > On Wednesday 06 June 2007 15:47:42 Pau Garcia i Quiles wrote:
> >> Quoting Chris Gow <sniffy at rogers.com>:
> >> > On Wednesday 06 June 2007 12:30:42 Pau Garcia i Quiles wrote:
> >> >> Quoting Chris Gow <sniffy at rogers.com>:
> >> >> > Ok its working correctly, but is this the correct way to load an
> >> >> > image from a remote resource or is there an easier way?
> >> >>
> >> >> There is an easier way :-)
> >> >
> >> > Cool.
> >> >
> >> >> You can use KIO. It is explained in Larrosa's KDE tutorial which was
> >> >> translated to Ruby and is available at
> >> >> http://developer.kde.org/language-bindings/ruby/kde3tutorial/index.ht
> >> >>ml.
> >> >>
> >> >> lthough chapter 11, which is the one dealing with what you want to
> >> >> do, has not been translated to Ruby yet, it shouldn't be difficult to
> >> >> understand:
> >> >> http://developer.kde.org/~larrosa/visualtutorial/chapter11.html
> >> >
> >> > I originally looked at the KIO::NetAccess class but dismissed it
> >>
> >> as  > it creates
> >>
> >> > a local file. But given the two options, I guess I'll go with it.
> >> > Ideally I'd like KIO::NetAccess (or something similar) to take a
> >> > buffer or something. In any case, I'm having an issue using the
> >> > KIO::NetAccess class. I can't seem to find the download method
> >> > locally:
> >> >
> >> > irb(main):001:0> require 'korundum'
> >> > => true
> >> > irb(main):002:0> tmpFile = ""
> >> > => ""
> >> > irb(main):003:0>
> >> > KIO::NetAccess.download("http://www.google.ca/index.html", tmpFile)
> >> > NoMethodError: undefined method `download' for KIO::NetAccess:Class
> >> >         from (irb):3:in `method_missing'
> >> >         from (irb):3
> >> >
> >> > I'm running Kubuntu Feisty w/KDE 3.5.7. According to adept I am using
> >> > the 3.5.5 bindings.
> >>
> >> Two problems here:
> >> 1) static bool KIO::NetAccess::download(const KURL&, QString&) is
> >> KDE_DEPRECATED, so Korundum probably does not allow it (I can't
> >> verify  because the system I am writing from does not have an
> >> usable Korundum  installation)
> >
> > I don't think it does as I tried using a KURL too.
> >
> >> 2) The first argument must be a KURL. Try this:
> >
> > That's what I saw too, but the p3 tutorial on korundum makes
> > reference to this
> > class and it uses a string and the KDeveloper tutorial you mentioned
> > originally also uses a string (makes reference to the fact that the C++
> > compiler will figure out what you mean) so I thought that using a string
> > would work. Guess not.
>
> Tutorials might not be up-to-date. The only references you may trust
> are api.kde.org and rbkdeapi/rbqtapi. For instance, look what rbkdeapi
> said for the KIO::NetAccess class:
>
> pgquiles at enigma:~$ rbkdeapi KIO::NetAccess
>
>          [...removed...]
>          static bool KIO::NetAccess::download(const KURL&, QString&,
> QWidget*) [...removed...]
>
> Do you notice there is no KIO::NetAccess::download with only two
> arguments? I don't know if the KURL was a problem or not, but trying
> to call the 2-argument KIO::NetAccess::download certainly was. Morale:
> rbkdeapi saves your ass :-)
Yes, the two arg form is deprecated. I've just tried this and it worked fine:

require 'Korundum'

class MyClass < KDE::MainWindow
    def initialize( name )
        super(nil, name) 
        tmpFile = ""
        KIO::NetAccess.download(
            KDE::URL.new("http://www.google.ca/index.html"),
            tmpFile, nil)
        puts tmpFile
    end
end

about = KDE::AboutData.new( "p2", "Test", "0.1" )
KDE::CmdLineArgs.init( ARGV, about )
app = KDE::Application.new( )

window = MyClass.new("Test")

app.mainWidget = window
window.resize(300,200)
window.show

app.exec

-- Richard





More information about the Kde-bindings mailing list