static void AddDialog () { int cols = (int) (Application.Cols * 0.7); Dialog d = new Dialog (cols, 8, "Add"); Entry e; string name = null; d.Add (new Label (1, 0, "Torrent file:")); e = new Entry (1, 1, cols - 6, Environment.CurrentDirectory); d.Add (e); // buttons Button b = new Button ("Ok", true); b.Clicked += delegate { b.Container.Running = false; name = e.Text; }; d.AddButton (b); b = new Button ("Cancel"); b.Clicked += delegate { b.Container.Running = false; }; d.AddButton (b); Application.Run (d); if (name != null){ if (!File.Exists (name)){ Application.Error ("Missing File", "Torrent file:\n" + name + "\ndoes not exist"); return; } torrent_list.Add (name); } }
static void OptionsDialog () { Dialog d = new Dialog (62, 15, "Options"); d.Add (new Label (1, 1, " Download Directory:")); d.Add (new Label (1, 3, " Listen Port:")); d.Add (new Label (1, 5, " Upload Speed Limit:")); d.Add (new Label (35,5, "kB/s")); d.Add (new Label (1, 7, "Download Speed Limit:")); d.Add (new Label (35,7, "kB/s")); Entry download_dir = new Entry (24, 1, 30, config.DownloadDir); d.Add (download_dir); Entry listen_port = new Entry (24, 3, 6, config.ListenPort.ToString ()); d.Add (listen_port); Entry upload_limit = new Entry (24, 5, 10, RenderSpeed (config.UploadSpeed / 1024)); d.Add (upload_limit); Entry download_limit = new Entry (24, 7, 10, RenderSpeed (config.DownloadSpeed / 1024)); d.Add (download_limit); bool ok = false; Button b = new Button ("Ok", true); b.Clicked += delegate { ok = true; b.Container.Running = false; }; d.AddButton (b); b = new Button ("Cancel"); b.Clicked += delegate { b.Container.Running = false; }; d.AddButton (b); Application.Run (d); if (ok){ int v; if (!Int32.TryParse (listen_port.Text, out v)){ Application.Error ("Error", "The value `{0}' is not a valid port number", listen_port.Text); return; } if (!Directory.Exists (download_dir.Text)){ Application.Error ("Error", "The directory\n{0}\ndoes not exist", download_dir.Text); return; } if (!ValidateSpeed (upload_limit, out config.UploadSpeed)) return; if (!ValidateSpeed (download_limit, out config.DownloadSpeed)) return; config.DownloadDir = download_dir.Text; config.ListenPort = v; // The user enters in kB/sec, the engine expects bytes/sec config.UploadSpeed *= 1024; config.DownloadSpeed *= 1024; TorrentCurses.engine.Settings.GlobalMaxUploadSpeed = config.UploadSpeed; TorrentCurses.engine.Settings.GlobalMaxDownloadSpeed = config.DownloadSpeed; } }
public void TorrentControl (int selected) { Dialog d = new Dialog (60, 8, "Torrent Control"); TorrentManager item = items [selected]; d.Add (new TrimLabel (1, 1, 60-6, item.Torrent.Name)); bool stopped = item.State == TorrentState.Stopped; Button bstartstop = new Button (stopped ? "Start" : "Stop"); bstartstop.Clicked += delegate { if (stopped) item.Start(); else item.Stop(); d.Running = false; }; d.AddButton (bstartstop); // Later, when we hook it up, look up the state bool paused = item.State == TorrentState.Paused; Button br = new Button (paused ? "Resume" : "Pause"); br.Clicked += delegate { if (paused) item.Start(); else item.Pause(); d.Running = false; }; d.AddButton (br); Button bd = new Button ("Delete"); bd.Clicked += delegate { Application.Error ("Not Implemented", "I have not implemented delete yet"); d.Running = false; }; d.AddButton (bd); Button bmap = new Button ("Map"); bmap.Clicked += delegate { Application.Error ("Not Implemented", "I have not implemented map yet"); d.Running = false; }; d.AddButton (bmap); Button bcancel = new Button ("Cancel"); bcancel.Clicked += delegate { d.Running = false; }; Application.Run (d); UpdateStatus (); }
/// <summary> /// Displays a message on a modal dialog box. /// </summary> /// <remarks> /// The error boolean indicates whether this is an /// error message box or not. /// </remarks> public static void Msg(bool error, string caption, string t) { var lines = new List<string> (); int last = 0; int max_w = 0; string x; for (int i = 0; i < t.Length; i++){ if (t [i] == '\n'){ x = t.Substring (last, i-last); lines.Add (x); last = i + 1; if (x.Length > max_w) max_w = x.Length; } } x = t.Substring (last); if (x.Length > max_w) max_w = x.Length; lines.Add (x); Dialog d = new Dialog (System.Math.Max (caption.Length + 8, max_w + 8), lines.Count + 7, caption); if (error) d.ErrorColors (); for (int i = 0; i < lines.Count; i++) d.Add (new Label (1, i + 1, (string) lines [i])); Button b = new Button (0, 0, "Ok", true); d.AddButton (b); b.Clicked += delegate { b.Container.Running = false; }; Application.Run (d); }
public static int Query(int width, int height, string title, string message, params string [] buttons) { var d = new Dialog (width, height, title); int clicked = -1, count = 0; foreach (var s in buttons){ int n = count++; var b = new Button (s); b.Clicked += delegate { clicked = n; d.Running = false; }; d.AddButton (b); } if (message != null){ var l = new Label ((width - 4 - message.Length)/2, 0, message); d.Add (l); } Application.Run (d); return clicked; }
public MainWindow() : base(0, 0, Application.Cols, Application.Lines) { //Frame layout = new Frame(0,0, Application.Cols, Application.Lines, "smuxi"); //Add(layout); // menu Button fileButton = new Button(0, 0, "File"); fileButton.Clicked += delegate { Dialog dialog = new Dialog(40, 6, "File Menu"); Button quitButton = new Button(0, 0, "Quit"); quitButton.Clicked += delegate { Frontend.Quit(); }; dialog.AddButton(quitButton); Button closeButton = new Button(0, 0, "Close"); closeButton.Clicked += delegate { dialog.Running = false; dialog.Clear(); }; dialog.AddButton(closeButton); Application.Run(dialog); }; Add(fileButton); Button helpButton = new Button(10, 0, "Help"); helpButton.Clicked += delegate { Dialog dialog = new Dialog(30, 6, "Help Menu"); Button aboutButton = new Button(0, 0, "About"); aboutButton.Clicked += delegate { Dialog aboutDialog = new Dialog(70, 10, "About smuxi"); aboutDialog.Add(new Label(0, 0, "smuxi")); aboutDialog.Add(new Label(0, 1, "Frontend: " + Frontend.UIName + " " + Frontend.Version)); aboutDialog.Add(new Label(0, 2, "Engine: " + Frontend.EngineVersion)); aboutDialog.Add(new Label(0, 4, "Copyright(C) 2005-2007 (C) Mirco Bauer <*****@*****.**>")); Button closeButton = new Button("Close"); closeButton.Clicked += delegate { aboutDialog.Running = false; aboutDialog.Clear(); }; aboutDialog.AddButton(closeButton); Application.Run(aboutDialog); }; dialog.AddButton(aboutButton); Button helpCloseButton = new Button(0, 0, "Close"); helpCloseButton.Clicked += delegate { dialog.Running = false; dialog.Clear(); }; dialog.AddButton(helpCloseButton); Application.Run(dialog); }; Add(helpButton); // output /* TextView textView = new TextView(0, 1, Application.Cols, Application.Lines -2); textView.Add("Hello World!"); textView.Add("Foo bar me!"); Add(textView); */ LogWidget log = new LogWidget(0, 1, Application.Cols, Application.Lines -2); Add(log); _UI = new CursesUI(log); // input Entry entry = new Entry(0, Application.Lines - 1, Application.Cols, String.Empty); Add(entry); _Entry = entry; // status }
public static void Error(string msg) { var d = new Dialog (Math.Min (Application.Cols-8, msg.Length+6), 8, "Error"); d.ErrorColors (); d.Add (new Label (1, 1, msg)); var b = new Button (0, 0, "Ok"); b.Clicked += delegate { d.Running = false; }; d.AddButton (b); Application.Run (d); }