// Copyright (C) 2011 Red Hat, Inc.
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see .
using GLib;
using Custom;
using SpiceProtocol.Controller;
namespace SpiceCtrl {
public class MenuItem: Object {
public Menu submenu;
public int parent_id;
public int id;
public string text;
public string accel;
public SpiceProtocol.Controller.MenuFlags flags;
public MenuItem (int id, string text, SpiceProtocol.Controller.MenuFlags flags) {
this.id = id;
this.text = text;
this.flags = flags;
}
public MenuItem.from_string (string str) throws SpiceCtrl.Error {
var params = str.split (SpiceProtocol.Controller.MENU_PARAM_DELIMITER);
if (warn_if (params.length != 5))
throw new SpiceCtrl.Error.VALUE(""); /* Vala: why is it mandatory to give a string? */
parent_id = int.parse (params[0]);
id = int.parse (params[1]);
var textaccel = params[2].split ("\t");
text = textaccel[0];
if (textaccel.length > 1)
accel = textaccel[1];
flags = (SpiceProtocol.Controller.MenuFlags)int.parse (params[3]);
submenu = new Menu ();
}
public string to_string () {
var sub = submenu.to_string ();
var str = @"pid: $parent_id, id: $id, text: \"$text\", flags: $flags";
foreach (var l in sub.to_string ().split ("\n")) {
if (l == "")
continue;
str += @"\n $l";
}
return str;
}
}
public class Menu: Object {
public List