This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Use of LocalIO in a javascript plasmoid

Tags: None
(comma "," separated)
dikilroy
Registered Member
Posts
3
Karma
0
OS
Hi,

I want to read a local file. I go crazy on how to use LocalIO::userDataPath(...) and LocalIO::getUrl(...).

My metadata.desktop already contains the extension tag (as described in http://techbase.kde.org/Development/Tutorials/Plasma/JavaScript/API-Extensions):
Code: Select all
"X-Plasma-RequiredExtensions=LocalIO"


In my js file I tried following:
Code: Select all
print("Home: " + userDataPath("home"));

Resulting this error: Reference Error: Can't find variable userDataPath

Code: Select all
print("Home: " + plasmoid.userDataPath("home"));

Resulting this error: Type Error: Result of expression 'plasmoid.userDataPath' [undefined] is not a function.

At KDE-Examples I didn't find a code snippet. Also didn't find any usefull links with google 'plasmoid localio'.

Could somebody explain me the usage of userDataPath and getUrl, please?

Thx!
André
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
I would recommend asking about this on the Plasma development mailing list, plasma-devel@kde.org.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
dikilroy
Registered Member
Posts
3
Karma
0
OS
Thx for reply. I solved it by myself.
The method userDataPath is only available at script version > 4 which I don't have. The getUrl method works!
Here is my example code:

Code: Select all

var fileContent = null;

function onData(job, data){
   if(data.length > 0){
      var content = new String(data.valueOf());
      fileContent += content;
   }
}

function onMimetype(job, mimeType){
   print(mimeType);
}

function onFinished(job) {
   startWorkWithFileContent(fileContent);
}

function startWorkWithFileContent(fileContent){
   print(fileContent);
}

function onConnect(job){
}

var job = plasmoid.getUrl("/some/directory/file.name");
// or var job = plasmoid.getUrl("http://a_nice_url.de/file.name");
job.data.connect( onData );
job.mimetype.connect( onMimetype );
job.finished.connect( onFinished );
job.connected.connect( onConnect );


This is a small example which show the usage of LocalIO and the connections with the signal of IOJob. At getUrl you can link to any file in your local filesystem or to a file at the web. This script writes out the contents of the file at /some/directory/file.name.


Greets
André


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft