Development/Tutorials/Plasma4/JavaScript/API-LocalIO

Jump to: navigation, search

LocalIO

This Extension provides access to local files using asynchronous IOJob objects.

Functions:

  • IOJob getUrl(Url url): attempts to fetch the file using an IOJob
  • IOJob getUrl(String url): attempts to fetch the file using an IOJob
  • String userDataPath([String type, String path]): (scripting version >= 4) returns the default path for user data. Called with no parameters, it returns the user's home directory. If only one string is passed in, the standard directory for that type of data in the user's home directory will be located; the following values are recognized:
    • documents
    • music
    • video
    • downloads
    • pictures
    • autostart
    • desktop (should be considered deprecated for Plasma workspaces)

If a second string is passed in, it is considered a request for a specific path and the following types are recognized:

    • apps - Applications menu (.desktop files).
    • autostart - Autostart directories (both XDG and kde-specific)
    • cache - Cached information (e.g. favicons, web-pages)
    • cgi - CGIs to run from kdehelp.
    • config - Configuration files.
    • data - Where applications store data.
    • emoticons - Emoticons themes
    • exe - Executables in $prefix/bin. findExe() for a function that takes $PATH into account.
    • html - HTML documentation.
    • icon - Icons, see KIconLoader.
    • kcfg - KConfigXT config files.
    • lib - Libraries.
    • locale - Translation files for KLocale.
    • mime - Mime types defined by KDE-specific .desktop files.
    • module - Module (dynamically loaded library).
    • qtplugins - Qt plugins (dynamically loaded objects for Qt)
    • services - Services.
    • servicetypes - Service types.
    • sound - Application sounds.
    • templates - Templates for the "Create new file" functionality.
    • wallpaper - Wallpapers.
    • tmp - Temporary files (specific for both current host and current user)
    • socket - UNIX Sockets (specific for both current host and current user)
    • xdgconf-menu - Freedesktop.org standard location for menu layout (.menu) files.
    • xdgdata-apps - Freedesktop.org standard location for application desktop files.
    • xdgdata-dirs - Freedesktop.org standard location for menu descriptions (.directory files).
    • xdgdata-mime - Freedesktop.org standard location for MIME type definitions.
    • xdgdata-icon - Freedesktop.org standard location for icons.
    • xdgdata-pixmap - Gnome-compatibility location for pixmaps.

The second parameter should be a specific resource to find the path to. An example might be userDataPath("data", "plasma-desktop").

Example

This example will load a file given its path. filedata is a plasmoid Label or TextArea where to write the information loaded.

  1. function loadFile(filepath){
  2.     var iojb;
  3.     filedata.text = ""; // First, delete the textarea information.
  4.     iojb = plasmoid.getUrl(filepath);
  5.     iojb.data.connect(loadData);
  6. }
  7.  
  8. // Remember data is a ByteArray, so we need to translate
  9. // this bytes numbers into ASCII(or UTF8) characters.
  10. function loadData(iojb, data){
  11.     var str = "";
  12.     var i;
  13.  
  14.     if (data.length > 0){
  15.         for (i = 0; i < data.length; i++){
  16.             str = str + String.fromCharCode(data[i]);
  17.         }
  18.         //print(str);
  19.         filedata.text = filedata.text + str;
  20.     }
  21. }

Remember that signals are connected using the connect(...) method as explained at Plasma using Javascript: Getting Started


This page was last modified on 22 February 2015, at 20:03. This page has been accessed 2,752 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal