40e5c08
/* 
40e5c08
   01-fedora-plasma-nm.js - Add NM plasmoid to the systray
40e5c08
   Copyright (C) 2010 Kevin Kofler <kevin.kofler@chello.at>
40e5c08
   Copyright (C) 2013 Jan Grulich <jgrulich@redhat.com>
40e5c08
40e5c08
   This program is free software: you can redistribute it and/or modify
40e5c08
   it under the terms of the GNU General Public License as published by
40e5c08
   the Free Software Foundation, either version 2 of the License, or
40e5c08
   (at your option) any later version.
40e5c08
40e5c08
   This program is distributed in the hope that it will be useful,
40e5c08
   but WITHOUT ANY WARRANTY; without even the implied warranty of
40e5c08
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40e5c08
   GNU General Public License for more details.
40e5c08
40e5c08
   You should have received a copy of the GNU General Public License
40e5c08
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
40e5c08
40e5c08
   Portions lifted from 06-delete-networkmanagement.js:
40e5c08
   Copyright Jonathan Riddell, jriddell@ubuntu.com 2013-09-13
40e5c08
   may be copied under the GNU GPL 2 or later
40e5c08
*/
40e5c08
40e5c08
nmAppletFound = false
40e5c08
pids = panelIds;
40e5c08
for (i = 0; i < pids.length; ++i) { //search through the panels
40e5c08
  panel = panelById(pids[i]);
40e5c08
  if (!panel) continue;
40e5c08
  ids = panel.widgetIds;
40e5c08
  for (j = 0; j < ids.length; ++j) { //search through the widgets for systray
40e5c08
    widget = panel.widgetById(ids[j]);
40e5c08
    if (!widget || widget.type != "systemtray") {
40e5c08
      continue;
40e5c08
    }
40e5c08
    //widget var is now the systray
40e5c08
    widget.currentConfigGroup = Array("Applets");
40e5c08
    noOfApplets = widget.configGroups.length;
40e5c08
    var groups = new Array();
40e5c08
    for (k = 0; k < noOfApplets; ++k) {
40e5c08
      groups.push(widget.configGroups[k])
40e5c08
    }
40e5c08
    for (k = 0; k < noOfApplets; ++k) {
40e5c08
      widget.currentConfigGroup = new Array("Applets", groups[k]);
40e5c08
      if (widget.readConfig("plugin") == "org.kde.plasma-nm") {
40e5c08
	nmAppletFound = true;
40e5c08
        widget.writeConfig("plugin","org.kde.networkmanagement"); //found it at last
40e5c08
	break;
40e5c08
      } else if (widget.readConfig("plugin") == "org.kde.networkmanagement") {
40e5c08
        nmAppletFound = true;
40e5c08
	break;
40e5c08
      }
40e5c08
    }
40e5c08
  }
40e5c08
}
40e5c08
40e5c08
if (!nmAppletFound) {
40e5c08
  systrayFound = false;
40e5c08
  for (i = 0; i < pids.length; ++i) { //search through the panels
40e5c08
    panel = panelById(pids[i]);
40e5c08
    if (!panel) continue;
40e5c08
    ids = panel.widgetIds;
40e5c08
    for (j = 0; j < ids.length; ++j) { //search through the widgets for systray
40e5c08
      widget = panel.widgetById(ids[j]);
40e5c08
      if (!widget || widget.type != "systemtray") {
40e5c08
	continue;
40e5c08
      }
40e5c08
      systrayFound = true;
40e5c08
      //widget var is now the systray
40e5c08
      widget.currentConfigGroup = Array("Applets");
40e5c08
      noOfApplets = widget.configGroups.length;
40e5c08
      widget.currentConfigGroup = new Array("Applets", noOfApplets + 1);
40e5c08
      widget.writeConfig("plugin", "org.kde.networkmanagement");
40e5c08
      print("Network management plasmoid added to the systray");
40e5c08
      break;
40e5c08
    }
40e5c08
    if (systrayFound) break;
40e5c08
  }
40e5c08
}