Trying to make a GUI for Moblock
Hi
I've down load a gui that was built on gnome glade but won't to build one myself. Here's what the one I DL'd looks like:
// File: MoBlockGUI.cs
// Author: brk3
using System;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using Gtk;
using Glade;
public class MoBlockGUI {
public MoBlockGUI(string[] args) {
Application.Init();
Glade.XML gxml = new Glade.XML (null, "MoBlockGUI.glade", "window1", null);
gxml.Autoconnect (this);
btnEnableDisable.Clicked += btnEnableDisableEvent;
btnClear.Clicked += btnClearEvent;
updatelabelIP();
// check if moblock is already running and set up gui accordingly
if(isMoBlockRunning()) {
labelStatus.Markup = "Status: <span color='darkgreen'>Enabled</span>";
btnEnableDisable.Label = "Disable Moblock";
startClock();
} else {
labelStatus.Markup = "Status: <span color='red'>Disabled</span>";
btnEnableDisable.Label = "Enable Moblock";
}
Application.Run();
}
private void startClock() {
// update log view every 2 seconds
updateLogView();
GLib.Timeout.Add (2000, new GLib.TimeoutHandler(updateLogView));
}
private void updatelabelIP() {
string ipsBlocked = "0";
StreamReader sIn = new StreamReader("/var/log/moblock.log");
string line;
while((line = sIn.ReadLine()) != null)
if(Regex.IsMatch(line, "Ranges loaded:"))
ipsBlocked = Regex.Match(line, @"\d+").ToString();
if(!File.Exists("/var/log/moblock.log") || (!isMoBlockRunning()))
ipsBlocked = "0";
labelIP.Text = "IP's blocked: " + ipsBlocked;
}
private bool updateLogView() {
Process tailProcess = new Process();
tailProcess.StartInfo.FileName = "tail";
tailProcess.StartInfo.Arguments = "/var/log/moblock.log";
tailProcess.StartInfo.UseShellExecute = false;
tailProcess.StartInfo.RedirectStandardOutput = true;
tailProcess.Start();
StreamReader sOut = tailProcess.StandardOutput;
tailProcess.WaitForExit();
logView.Buffer.Text = sOut.ReadToEnd();
sOut.Close();
tailProcess.Close();
return true;
}
private bool isMoBlockRunning() {
Process pidof = new Process();
pidof.StartInfo.FileName = "pidof";
pidof.StartInfo.Arguments = "moblock";
pidof.StartInfo.UseShellExecute = false;
pidof.StartInfo.RedirectStandardOutput = true;
pidof.Start();
StreamReader sOut = pidof.StandardOutput;
pidof.WaitForExit();
string pId = sOut.ReadToEnd();
return (pId.Length > 0) ? true : false;
}
public void btnEnableDisableEvent(object o, EventArgs e) {
if(isMoBlockRunning()) {
Process.Start("gksudo --disable-grab /etc/init.d/moblock-nfq stop");
btnEnableDisable.Label = "Enable Moblock";
labelStatus.Markup = "Status: <span color='red'>Disabled</span>";
} else {
Process.Start("gksudo --disable-grab /etc/init.d/moblock-nfq start");
btnEnableDisable.Label = "Disable Moblock";
labelStatus.Markup = "Status: <span color='darkgreen'>Enabled</span>";
startClock();
}
updatelabelIP();
}
public void btnClearEvent(object o, EventArgs e) {
logView.Buffer.Text = "";
Process.Start("gksudo --disable-grab rm /var/log/moblock.log");
Process.Start("gksudo --disable-grab /etc/init.d/moblock-nfq stop");
Process.Start("gksudo --disable-grab /etc/init.d/moblock-nfq start");
}
public static void Main (string[] args) {
new MoBlockGUI(args);
}
[Glade.Widget]
TextView logView;
[Glade.Widget]
Label labelStatus;
[Glade.Widget]
Label labelIP;
[Glade.Widget]
Button btnEnableDisable;
[Glade.Widget]
Button btnClear;
I can see that gnome glade was use to make this GUI but I would like to do one myself. Could someone point to good way to make a GUI and a ".cs" such as this one. I am a complete beginner here, I scarecely recognize anything on this ".cs"
Thanks
|