// // OpenVPN Administrator // // Author(s): Everaldo Canuto // // (C) 2006 Everaldo Canuto // (C) 2006 The Gang // // 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 System.Reflection; using Mono.Unix; using Gtk; using Glade; namespace OpenVPN.Admin { public class BaseForm { #region Fields private Gtk.Window window; private Glade.XML gxml; #endregion #region Constructors and destructors public BaseForm() { // do nothing. } public void Destroy() { if (window != null) window.Destroy(); } protected virtual void InitializeComponent(string formname) { gxml = new Glade.XML (null, "openvpn-admin.glade", formname, null); gxml.Autoconnect (this); window = (Gtk.Window) gxml.GetWidget(formname); } #endregion #region Public properties public Gtk.Window Window { get { return window; } } #endregion #region Public methods public virtual void Show() { window.ShowAll(); } public void ErrorBox(string message) { MessageDialog dialog = new MessageDialog(window, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok, message); dialog.Run(); dialog.Destroy(); } public string SelectFolderDialog() { FileChooserDialog dialog = new FileChooserDialog(Catalog.GetString("Select Folder"), window, FileChooserAction.SelectFolder); dialog.AddButton (Stock.Cancel, ResponseType.Cancel); dialog.AddButton (Stock.Open, ResponseType.Ok); dialog.Run(); dialog.Hide(); return dialog.Uri; } #endregion #region Default events handles public void on_close_clicked(object o, EventArgs args) { Window.Hide(); } public void on_selectfolder_clicked(object o, EventArgs args) { if (!(o is Gtk.Widget)) return; string name = ((Gtk.Widget) o).Name; Gtk.Widget entry = gxml.GetWidget(name.Replace("button", "entry")); if ((entry != null) && (entry is Gtk.Entry)) { FileChooserDialog dialog = new FileChooserDialog("Select Folder", window, FileChooserAction.SelectFolder); dialog.AddButton (Stock.Cancel, ResponseType.Cancel); dialog.AddButton (Stock.Open, ResponseType.Ok); if (dialog.Run() == (int) ResponseType.Ok) ((Gtk.Entry) entry).Text = dialog.Filename; dialog.Hide(); } } public void on_openfile_clicked(object o, EventArgs args) { if (!(o is Gtk.Widget)) return; string name = ((Gtk.Widget) o).Name; Gtk.Widget entry = gxml.GetWidget(name.Replace("button", "entry")); if ((entry != null) && (entry is Gtk.Entry)) { FileChooserDialog dialog = new FileChooserDialog("Select Folder", window, FileChooserAction.Open); dialog.AddButton (Stock.Cancel, ResponseType.Cancel); dialog.AddButton (Stock.Open, ResponseType.Ok); if (dialog.Run() == (int) ResponseType.Ok) ((Gtk.Entry) entry).Text = dialog.Filename; dialog.Hide(); } } #endregion #region Private methods #endregion } }