// This program is free software; you can redistribute it and/or modify it under // the terms of the GNU General Public License as published by the Free Software // Foundation; either version 3 of the License, or (at your option) any later // version. // // This program 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 General Public License for more // details. // // You should have received a copy of the GNU General Public License along with // this program; if not, see or write to the Free // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // USA using System; using System.Diagnostics; using Do.Universe; namespace Bugzilla { public class BugzillaItem : IURLItem { protected string name, url; public BugzillaItem (string name, string url) { this.name = name; this.url = url; } public string Name { get { return name; } } public string Description { get { return name; } } public string Icon { get { return "www"; } } public string URL { get { return url; } } } public class BugzillaAction : AbstractAction { /* The list of BugzillaItem modifiers */ private IItem[] bugzillas; public BugzillaAction () { bugzillas = new IItem[] { new BugzillaItem("GNOME", "http://bugzilla.gnome.org/{0}"), new BugzillaItem("OpenedHand", "http://bugzilla.openedhand.com/show_bug.cgi?id={0}"), new BugzillaItem("WebKit", "https://bugs.webkit.org/show_bug.cgi?id={0}") }; } public override string Name { get { return "Open bug"; } } public override string Description { get { return "Open bug"; } } public override string Icon { get { return "system-search"; } } public override Type[] SupportedItemTypes { get { return new Type[] { typeof (ITextItem) }; } } public override Type[] SupportedModifierItemTypes { get { return new Type[] { typeof(BugzillaItem) }; } } public override IItem[] DynamicModifierItemsForItem (IItem item) { return bugzillas; } private uint GetBugID(string text) { if (text[0] != '#') return 0; try { return Convert.ToUInt32(text.Substring(1)); } catch (FormatException) { return 0; } } public override bool SupportsItem (IItem item) { string text = (item as ITextItem).Text; if (text.Length == 1 && text[0] == '#') return true; return GetBugID(text) != 0; } public override IItem[] Perform (IItem[] items, IItem[] modifierItems) { BugzillaItem bugzilla = modifierItems[0] as BugzillaItem; uint bugid = GetBugID((items[0] as ITextItem).Text); string url = String.Format(bugzilla.URL, bugid); Process.Start("gnome-open", url); return null; } } }