0

I'm trying to write KDE4 plasmoid in JavaScript, but have not success. So, I need to get some data via HTTP and display it in Label. That's working well, but I need regular refresh (once in 10 seconds), it's not working.

My code:

inLabel = new Label();
var timer= new QTimer();
var job=0;
var fileContent="";

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

function onFinished(job) {
  inLabel.text=fileContent;
}

plasmoid.sizeChanged=function()
{
    plasmoid.update();
}

timer.timeout.connect(getData);
timer.singleShot=false;
getData();
timer.start(10000);

function getData()
{
    fileContent="";
    job = plasmoid.getUrl("http://192.168.0.10/script.cgi");
    job.data.connect(onData);
    job.finished.connect(onFinished);
    plasmoid.update();
}

It gets script once and does not refresh it after 10 seconds. Where is my mistake?

Shura
  • 108
  • 1
  • 8

1 Answers1

1

It is working just fine in here at least (running a recent build from git master), getData() is being called as expected. Can you see any errors in the console?

EDIT: The problem was that getUrl() explicitly sets NoReload for KIO::get() which causes it load data from cache instead of forcing a reload from the server. Solution was to add a query parameter to the URL in order to make it force reload it.

teprrr
  • 404
  • 2
  • 9
  • No any errors in console. I have ran sniffer and look at traffic and don't see periodical requests, only one at plasmoid start. – Shura May 30 '12 at 12:11
  • Which KDE version are you running? Launching with plasmoidviewer or just adding it to Plasma? I just tested the script (with plasmoidviewer) also on KDE 4.6.5 and it seems to be working there too. You can also try to add print() or debug() calls to your callbacks to see if they're called. – teprrr May 31 '12 at 04:46
  • KDE 4.8.3 from Kubuntu. I have added `print("getData")` to getData() function and now gets in console: $ plasmoidviewer plasma_test getData getData getData getData getData getData getData But in sniffer I don't see requests. – Shura May 31 '12 at 13:21
  • 1
    Ahh, I see it now. The thing is that it uses KIO::get() in the background with a NoReload, which basically causes it to use the cache instead of reloading the page. Try to append a query parameter to the url in order to see if that helps. [Here's a link to the source](http://lxr.kde.org/source/kde/kde-runtime/plasma/scriptengines/javascript/common/extension_io.cpp#62). – teprrr May 31 '12 at 14:00
  • Forgot to add that you probably also want to take a look at [QML plasmoids](http://techbase.kde.org/Development/Tutorials/Plasma#QML) as they are the preferred method for creating scripted applets since 4.7. Doesn't help with this problem though, but worth noticing anyway. – teprrr May 31 '12 at 14:10
  • thank you, I have added to the end of url "?t="+t and adds 1 to t every time. Now it works. – Shura Jun 04 '12 at 06:42