// // OpenVPN Administrator // // Author(s): Everaldo Canuto // // (C) 2005 Everaldo Canuto // // 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, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // using System; using Gtk; using Gdk; using System.Runtime.InteropServices; using Mono.Unix; namespace Gtk { public class AboutDialog : Gtk.Dialog { #region Fields // properties. private string name; private string version; private string comments; private string copyright; private string license; private string translator_credits; private bool wrap_license; private string [] authors; private string [] documenters; // about. private Gtk.Image logo_image; private Gtk.Label name_label; private Gtk.Label comments_label; private Gtk.Label copyright_label; //private Gtk.Button website_button; // credits. private Gtk.Button credits_button; private Gtk.Dialog credits_dialog; // license. private Gtk.Button license_button; private Gtk.Dialog license_dialog; #endregion #region Constructors and destructors public AboutDialog() : base() { // dialogs. credits_dialog = null; license_dialog = null; // initialize fields. this.name = ""; this.version = ""; this.comments = ""; this.copyright = ""; this.license = ""; this.translator_credits = ""; this.wrap_license = false; this.authors = null; this.documenters = null; Gtk.Widget.PushCompositeChild(); Gtk.VBox vbox = new Gtk.VBox(false, 8); VBox.PackStart(vbox, true, true, 0); // logo logo_image = new Gtk.Image(); vbox.PackStart(logo_image, false, false, 0); // name name_label = new Gtk.Label(); name_label.Selectable = true; name_label.Justify = Gtk.Justification.Center; vbox.PackStart(name_label, false, false, 0); // comments comments_label = new Gtk.Label(); comments_label.Selectable = true; comments_label.Justify = Gtk.Justification.Center; comments_label.Wrap = true; vbox.PackStart(comments_label, false, false, 0); // copyright copyright_label = new Gtk.Label(); copyright_label.Selectable = true; copyright_label.Justify = Gtk.Justification.Center; vbox.PackStart(copyright_label, false, false, 0); // TODO: website button //website_button = *** //Gtk.HBox hbox = new Gtk.HBox(true, 0); //hbox.PackStart(website_button, false, false, 0); //vbox.PackStart(hbox, true, false, 0); vbox.Show(); logo_image.Show(); name_label.Show(); //hbox.Show(); // credits button. credits_button = new Gtk.Button(Catalog.GetString("C_redits")); credits_button.Clicked += new EventHandler(DisplayCreditsDialog); ActionArea.PackEnd(credits_button, false, true, 0); #if !MAEMO ActionArea.SetChildSecondary(credits_button, true); #endif // license button. license_button = new Gtk.Button(Catalog.GetString("_License")); license_button.Clicked += new EventHandler(DisplayLicenseDialog); ActionArea.PackEnd(license_button, false, true, 0); #if !MAEMO ActionArea.SetChildSecondary(license_button, true); #endif // close button. AddButton("gtk-close", ResponseType.Close); DefaultResponse = ResponseType.Close; // default properties. Resizable = false; HasSeparator = false; Response += new ResponseHandler(CloseDialog); StyleSet += new StyleSetHandler(SetStyle); Gtk.Widget.PopCompositeChild(); } #endregion #region Plus!! // This function is not present on Gtk+ AboutDialog but is nice to have // it in Gtk#. public static AboutDialog Helper() { AboutDialog dialog = new AboutDialog(); return dialog; } #endregion #region Properties public Gdk.Pixbuf Logo { get { return this.logo_image.Pixbuf; } set { this.logo_image.Pixbuf = value; } } public new string Name { get { return this.name; } set { if (this.name != value) { this.name = value; UpdateNameVersion(); } } } public string Version { get { return this.version; } set { if (this.version != value) { this.version = value; UpdateNameVersion(); } } } public string Comments { get { return this.comments; } set { if (this.comments != value) { this.comments = value; this.comments_label.Text = value; if (this.comments != "") this.comments_label.Show(); else this.comments_label.Hide(); } } } public string Copyright { get { return this.copyright; } set { if (this.copyright != value) { this.copyright = value; this.copyright_label.Text = value; if (this.copyright != "") this.copyright_label.Show(); else this.copyright_label.Hide(); } } } public string License { get { return this.license; } set { if (this.license != value) { this.license = value; if (this.license != "") this.license_button.Show(); else this.license_button.Hide(); } } } public bool WrapLicense { get { return this.wrap_license; } set { this.wrap_license = value; } } public string[] Authors { get { return this.authors; } set { if (this.authors != value) { this.authors = value; if (this.authors.Length > 0) this.credits_button.Show(); else this.credits_button.Hide(); } } } public string[] Documenters { get { return this.documenters; } set { this.documenters = value; } } public string TranslatorCredits { get { return this.translator_credits; } set { this.translator_credits = value; } } #endregion #region Private methods private void DisplayCreditsDialog(object o, EventArgs args) { if (credits_dialog != null) { credits_dialog.Present(); return; } credits_dialog = new Gtk.Dialog(Catalog.GetString("Credits"), this, DialogFlags.DestroyWithParent); credits_dialog.Modal = this.Modal; credits_dialog.HasSeparator = false; credits_dialog.DefaultResponse = ResponseType.Close; credits_dialog.AddButton("gtk-close", ResponseType.Close); credits_dialog.SetDefaultSize(420, 320); credits_dialog.Response += new ResponseHandler(ResponseDialog); credits_dialog.Destroyed += new EventHandler(CreditsDestroyed); credits_dialog.StyleSet += new StyleSetHandler(SetStyle); Gtk.Notebook notebook = new Gtk.Notebook(); credits_dialog.VBox.PackStart(notebook, true, true, 0); if (authors != null) AddCreditsPage(notebook, Catalog.GetString("Written by"), authors); if (documenters != null) AddCreditsPage(notebook, Catalog.GetString("Documented by"), documenters); if ((translator_credits != null) && (translator_credits != "translator-credits")) { string [] translators = new string [] {translator_credits}; AddCreditsPage(notebook, Catalog.GetString("Translated by"), translators); } credits_dialog.ShowAll(); } private void AddCreditsPage(Gtk.Notebook notebook, string title, string[] people) { // scrolled window Gtk.ScrolledWindow sw = new Gtk.ScrolledWindow(); sw.ShadowType = ShadowType.In; sw.SetPolicy(PolicyType.Automatic, PolicyType.Automatic); // text view Gtk.TextView view = new Gtk.TextView(); view.CursorVisible = false; view.Editable = false; view.LeftMargin = 8; view.RightMargin = 8; sw.Add(view); foreach(string entry in people) view.Buffer.Text += entry + "\n"; notebook.AppendPage(sw, new Gtk.Label(title)); } private void DisplayLicenseDialog(object o, EventArgs args) { if (license_dialog != null) { license_dialog.Present(); return; } license_dialog = new Gtk.Dialog(Catalog.GetString("License"), this, DialogFlags.DestroyWithParent); license_dialog.Modal = this.Modal; license_dialog.HasSeparator = false; license_dialog.DefaultResponse = ResponseType.Close; license_dialog.AddButton("gtk-close", ResponseType.Close); license_dialog.SetDefaultSize(520, 340); license_dialog.Response += new ResponseHandler(ResponseDialog); license_dialog.Destroyed += new EventHandler(LicenseDestroyed); license_dialog.StyleSet += new StyleSetHandler(SetStyle); // scrolled window Gtk.ScrolledWindow sw = new Gtk.ScrolledWindow(); sw.ShadowType = ShadowType.In; sw.SetPolicy(PolicyType.Automatic, PolicyType.Automatic); license_dialog.VBox.PackStart(sw, true, true, 0); // text view Gtk.TextView view = new Gtk.TextView(); view.WrapMode = this.wrap_license ? WrapMode.Word : WrapMode.None; view.Buffer.Text = license; view.CursorVisible = false; view.Editable = false; view.LeftMargin = 8; view.RightMargin = 8; sw.Add(view); license_dialog.ShowAll(); } private void CloseDialog(object o, ResponseArgs args) { if (license_dialog != null) { license_dialog.Destroy(); license_dialog = null; } if (credits_dialog != null) { credits_dialog.Destroy(); credits_dialog = null; } Hide(); } private void ResponseDialog(object o, ResponseArgs args) { Gtk.Dialog dialog = ((Gtk.Dialog) o); dialog.Destroy(); } private void CreditsDestroyed(object o, EventArgs args) { credits_dialog = null; } private void LicenseDestroyed(object o, EventArgs args) { license_dialog = null; } private void SetStyle(object o, StyleSetArgs args) { Gtk.Dialog dialog = ((Gtk.Dialog) o); dialog.VBox.BorderWidth = 12; dialog.VBox.Spacing = 12; dialog.ActionArea.BorderWidth = 0; dialog.ActionArea.Spacing = 6; } private void UpdateNameVersion() { Title = String.Format(Catalog.GetString("About {0}"), name); if (version != "") name_label.Markup = String.Format("{0} {1}", name, version); else name_label.Markup = String.Format("{0}", name); } #endregion #region Public methods // TODO: Public methods //public static AboutDialogActivateLinkFunc SetEmailHook(AboutDialogActivateLinkFunc func) //public static AboutDialogActivateLinkFunc SetUrlHook(AboutDialogActivateLinkFunc func) #endregion } }