Registered Member
|
I'm trying to write a script for 2.2.2 and I've never done this before, so please, bear with me.
1)In order to write to a file in Javascript the local environment has to support some kind of I/O object. What does KDE (or Amarok) have to offer me that I can use to write files? |
Manager
|
Running Kubuntu 22.10 with Plasma 5.26.3, Frameworks 5.100.0, Qt 5.15.6, kernel 5.19.0-23 on Ryzen 5 4600H, AMD Renoir, X11
FWIW: it's always useful to state the exact Plasma version (+ distribution) when asking questions, makes it easier to help ... |
Registered Member
|
Yes, that's where I started from, unless I'm missing something I don't see a way to write files there.
|
KDE Developer
|
Well, you can access most of Qt too (not all of its modules are accessible, but many). Have a look here:
http://doc.trolltech.com/4.5/qfile.html
--
Mark Kretschmann - Amarok Developer |
KDE Developer
|
something like:
file = new QFile( "path" ); if( file.open( QIODevice.ReadWrite ) ) { Do stuff! } should work |
Registered Member
|
Thanks, but it's not working.
When I tried doing this in the Script Console it didn't work. My code:
The error:
What am I doing wrong? |
KDE Developer
|
One problem at least would be that you are using c++ syntax and not js syntax.
QTextStream out (&file); should likely be out = new QTextStream( file ); Also, I am not sure if the << operators work at all in js |
Registered Member
|
Yeah, I thought it was looking a little funky.
I fixed the syntax (I hope) so that it's JS, but now I'm getting an "undefined" error.
|
Registered Member
|
Boy do I feel foolish.
"undefined" was the output from the console, but it did create file! I was just looking for it in the wrong place. For some reason it wrote the file to my Documents folder, not the parent folder of my music collection which is Music. Is there any way to specify that I want the file to be written to the folder that holds the music collection without giving it a specific path? |
KDE Developer
|
Running it step by step in the script console works if I get rid of the "var" prefixes to the variables.
have you remembered to import qt.core ( Importer.loadQtBinding("qt.core"); ) in the script? |
KDE Developer
|
use Amarok.Collection.collectionLocation();
Note however that this might return several paths if the collection is spread out between several top level directories. |
Registered Member
|
That worked, thanks!
I didn't import the qtcore when I was testing my code in the console and it worked fine, but when I write the actual main.js I'll need to, right? |
KDE Developer
|
Yup!
As well as any other special modules that you might need (qt.network, qt.gui, ...) |
Registered users: Bing [Bot], gfielding, Google [Bot], markhm, Sogou [Bot], Yahoo [Bot]