/// Run Add Peer Dialog public static UserInfo AddPeer() { GUI.Dialogs.AddPeer dialog = new GUI.Dialogs.AddPeer(); ResponseType response; string username; do { response = dialog.Run(); username = dialog.Username; } while (response == ResponseType.Ok && username == null); bool secureAuth = dialog.SecureAuthentication; string ip = dialog.Ip; int port = dialog.Port; dialog.Destroy(); if (response == ResponseType.Ok && username != null) { UserInfo userInfo = new UserInfo(username, secureAuth); userInfo.SetIpAndPort(ip, port); try { // Get User Ip & Port from Server if (userInfo.SecureAuthentication == true) { userInfo.GetIpAndPort(); } return(userInfo); } catch (Exception e) { string title = "Fetch <b>" + userInfo.Name + "</b> Information"; GUI.Base.Dialogs.MessageError(title, e.Message); return(null); } } return(null); }
// ============================================ // PUBLIC Methods // ============================================ /// Add New Peer public void Add(UserInfo userInfo) { // Setup Pixbuf Gdk.Pixbuf pixbuf; if (userInfo.SecureAuthentication == true) { pixbuf = StockIcons.GetPixbuf("Network", 74); } else { pixbuf = StockIcons.GetPixbuf("NetworkInsecure", 74); } this.AppendValues(userInfo, userInfo.Name, pixbuf); }
// ============================================ // PUBLIC Events // ============================================ // ============================================ // PUBLIC Methods // ============================================ /// Send Login public static void Login(PeerSocket peer, UserInfo userInfo) { XmlRequest xmlRequest = new XmlRequest(); xmlRequest.FirstTag = "login"; xmlRequest.Attributes.Add("name", userInfo.Name); xmlRequest.Attributes.Add("secure", userInfo.SecureAuthentication.ToString()); string magic = Protocol.Login.GenerateMagic(peer); xmlRequest.Attributes.Add("magic", magic); peer.Send(xmlRequest.GenerateXml()); }
// ============================================ // PUBLIC Constructors // ============================================ public UserPanel() : base(false, 2) { // Get My Info this.myInfo = MyInfo.GetInstance(); // Initialize Folder Image this.imageFolder = new Gtk.Image(); this.PackStart(this.imageFolder, false, false, 2); SetOnlineStatusIcon(false); // Initialize Label Folder Button this.labelFolderButton = new Gtk.Label(GetNameLabel()); this.labelFolderButton.Justify = Justification.Center; this.labelFolderButton.UseMarkup = true; // Initialize Folder Button this.folderButton = new Gtk.Button(this.labelFolderButton); this.folderButton.Relief = Gtk.ReliefStyle.None; this.PackStart(this.folderButton, false, false, 2); // Vertical Separator this.PackStart(new HSeparator(), false, false, 2); // Initialize Num Download Label this.labelDownload = new Gtk.Label("0 Download"); this.PackStart(this.labelDownload, false, false, 2); // Initialize Num Upload Label this.labelUpload = new Gtk.Label("0 Upload"); this.PackStart(this.labelUpload, false, false, 2); // Initialize Num Files Label this.labelTFiles = new Gtk.Label("0 Shared Files"); this.UpdateSharedFilesNum(); this.PackStart(this.labelTFiles, false, false, 2); // Update Labels Timeout timeoutUpdateRet = true; timeoutUpdate = GLib.Timeout.Add(10000, UpdateInfoLabels); // Update Download Label DownloadManager.Added += new BlankEventHandler(UpdateDownloadNum); DownloadManager.Finished += new BlankEventHandler(UpdateDownloadNum); DownloadManager.Aborted += new BlankEventHandler(UpdateDownloadNum); // Update Upload Label UploadManager.Added += new BlankEventHandler(UpdateUploadNum); UploadManager.Finished += new BlankEventHandler(UpdateUploadNum); UploadManager.Aborted += new BlankEventHandler(UpdateUploadNum); }
// ============================================ // PUBLIC Constructors // ============================================ public TalkFrame(UserInfo userInfo) { // Initialize User Info this.userInfo = userInfo; // VPaned Position this.Position = 120; Gtk.Frame frame; // Output Text View this.talkView = new TalkView(); // Output Scrolled Window this.scrolledWindowOut = new Gtk.ScrolledWindow(null, null); this.scrolledWindowOut.ShadowType = Gtk.ShadowType.None; this.scrolledWindowOut.HscrollbarPolicy = Gtk.PolicyType.Automatic; this.scrolledWindowOut.VscrollbarPolicy = Gtk.PolicyType.Automatic; this.scrolledWindowOut.Add(this.talkView); // Output Frame frame = new Gtk.Frame(); frame.Shadow = ShadowType.EtchedOut; frame.ShadowType = ShadowType.EtchedOut; frame.Add(this.scrolledWindowOut); this.Add1(frame); // Input Text View this.inputView = new Gtk.TextView(); this.inputView.HeightRequest = 25; this.inputView.KeyReleaseEvent += new KeyReleaseEventHandler(OnKeyReleaseEvent); // Input Scrolled Window this.scrolledWindowIn = new Gtk.ScrolledWindow(null, null); this.scrolledWindowIn.ShadowType = Gtk.ShadowType.None; this.scrolledWindowIn.HscrollbarPolicy = Gtk.PolicyType.Automatic; this.scrolledWindowIn.VscrollbarPolicy = Gtk.PolicyType.Automatic; this.scrolledWindowIn.Add(this.inputView); // Input Frame frame = new Gtk.Frame(); frame.Shadow = ShadowType.EtchedOut; frame.ShadowType = ShadowType.EtchedOut; frame.Add(this.scrolledWindowIn); this.Add2(frame); // Show All this.ShowAll(); }
private static Hashtable talkFrames = null; // [UserInfo] = TalkFrame #endregion Fields #region Methods public static TalkFrame AddTalkFrame(UserInfo userInfo) { TalkFrame talkFrame = LookupTalkFrame(userInfo); if (talkFrame != null) return(talkFrame); // Initialize Talk Frame talkFrame = new TalkFrame(userInfo); talkFrame.Message += new StringEventHandler(OnSendMessage); talkFrames.Add(userInfo, talkFrame); notebookViewer.AppendCustom(talkFrame, userInfo.Name, new Gtk.Image("TalkBubble", IconSize.Menu)); return(talkFrame); }
/// Check User Authentication public static bool Authentication(UserInfo userInfo) { // Set Options Hashtable options = new Hashtable(); options.Add("magic", userInfo.Informations["magic"]); // Make Url & Request string url = MakeUrl(userInfo, "UserAuth.php", options); XmlRequest xml = MakeRequest(url); // Parse Xml Response if (xml.FirstTag == "authentication") return(true); // Request Error return(false); }
/// Create New Login Checker public Login(PeerSocket peer, XmlRequest xml) { // Get UserName string userName = (string) xml.Attributes["name"]; if (userName == null) return; // Get SecureAuth bool secureAuth = false; string _secureAuth = (string) xml.Attributes["secure"]; if (_secureAuth != null && _secureAuth == "True") secureAuth = true; // Get Magic string magic = (string) xml.Attributes["magic"]; if (secureAuth == true && magic == null) return; // Initialize UserInfo this.userInfo = new UserInfo(userName, secureAuth, magic); }
// ============================================ // PRIVATE Members // ============================================ // ============================================ // PUBLIC Constructors // ============================================ /// Create New Folder Viewer public FolderViewer(UserInfo userInfo) { // Initialize Scrolled Window BorderWidth = 0; ShadowType = ShadowType.EtchedIn; SetPolicy(PolicyType.Automatic, PolicyType.Automatic); // Initialize UserInfo this.userInfo = userInfo; if (this.userInfo == MyInfo.GetInstance()) { baseDirectory = Paths.UserSharedDirectory(MyInfo.Name); } else { baseDirectory = "/"; } currentDirectory = new DirectoryInfo(baseDirectory); // Initialize Folder Store this.store = new FolderStore(); this.store.DirectoryAdded += new ObjectEventHandler(OnStoreDirAdded); this.store.FileAdded += new ObjectEventHandler(OnStoreFileAdded); // Initialize Icon View iconView = new IconView(store); iconView.TextColumn = FolderStore.COL_NAME; iconView.PixbufColumn = FolderStore.COL_PIXBUF; iconView.SelectionMode = SelectionMode.Multiple; // Initialize Icon View Events iconView.ItemActivated += new ItemActivatedHandler(OnItemActivated); iconView.ButtonPressEvent += new ButtonPressEventHandler(OnItemClicked); // Initialize Icon View Drag & Drop iconView.EnableModelDragDest(Dnd.TargetTable, Gdk.DragAction.Copy); iconView.DragDataReceived += new DragDataReceivedHandler(OnDragDataReceived); // Add IconView to ScrolledWindow Add(iconView); // Refresh Icon View Refresh(); }
private void DoLogin(GUI.Dialogs.Login dialog) { if (dialog.ValidateInput() == false) return; if ((myInfo = dialog.CheckLogin()) != null) { dialog.Destroy(); } }
// ================================================= // PROTECTED (Methods) Network Viewer Event Handlers // ================================================= private void OnSendFile(object obj, UserInfo userInfo, string path) { Gtk.Application.Invoke(delegate { PeerSocket peer = P2PManager.KnownPeers[userInfo] as PeerSocket; UploadManager.Add(peer, path); }); }
// ================================================= // PROTECTED (Methods) Folder Viewers Event Handlers // ================================================= private void OnSaveFile(object obj, UserInfo userInfo, string path) { Gtk.Application.Invoke(delegate { PeerSocket peer = P2PManager.KnownPeers[userInfo] as PeerSocket; string saveAs = FileAlreadyInUse(path.Substring(1)); if (saveAs != null) { DownloadManager.Accept(peer, 0, path, saveAs); Cmd.RequestFile(peer, path); } }); }
// ============================================ // PUBLIC Constructors // ============================================ /// Create New Login Checker public Login(UserInfo userInfo) { this.userInfo = userInfo; }
public void RequestImage(UserInfo userInfo, string filePath) { // Get Peer From UserInfo PeerSocket peer = P2PManager.KnownPeers[userInfo] as PeerSocket; if (peer != null) { // Generate Xml Request XmlRequest xmlRequest = new XmlRequest(); xmlRequest.FirstTag = "get"; xmlRequest.BodyText = filePath; xmlRequest.Attributes.Add("what", "imgthumb"); peer.Send(xmlRequest.GenerateXml()); } else { LoadImage(userInfo, filePath); } }
// ============================================ // PRIVATE Methods // ============================================ private static string MakeUrl(UserInfo userInfo, string pg, Hashtable opts) { StringBuilder url = new StringBuilder(); url.Append("http://"); url.Append(userInfo.GetDomain()); url.Append("/NyFolder/"); url.Append(pg); url.Append("?"); url.Append("user="); url.Append(userInfo.GetName()); if (opts != null) { foreach (string name in opts.Keys) { url.Append('&'); url.Append(name); url.Append('='); url.Append((string) opts[name]); } } return(url.ToString()); }
/// Get User Port public static int Port(UserInfo userInfo) { // Make Url & Request string url = MakeUrl(userInfo, "GetPort.php", null); XmlRequest xml = MakeRequest(url); // Parse Xml Response if (xml.FirstTag == "port") return(Int32.Parse(xml.BodyText)); // Request Error throw(new Exception(xml.FirstTag + ": " + xml.BodyText)); }
// ============================================ // PRIVATE Methods // ============================================ private static string MakeUrl(UserInfo userInfo, string pg, Hashtable opts) { StringBuilder url = new StringBuilder(); url.Append("http://"); url.Append(userInfo.GetDomain()); url.Append("/NyFolder/"); url.Append(pg); url.Append("?"); url.Append("user="); url.Append(userInfo.GetName()); AddUrlOpts(ref url, opts); return(url.ToString()); }
// ============================================ // PRIVATE Methods // ============================================ private static TalkFrame LookupTalkFrame(UserInfo userInfo) { return((TalkFrame) talkFrames[userInfo]); }
private void LoadImage(UserInfo userInfo, string path, Gdk.Pixbuf pixbuf) { // Lookup File Iter FolderViewer folderViewer = notebookViewer.LookupPage(userInfo); if (folderViewer == null) return; // Get File Tree Iter Gtk.TreeIter iter = folderViewer.Store.GetIter(path); if (iter.Equals(Gtk.TreeIter.Zero)) return; // Build & Set Thumb Image Gtk.Application.Invoke(delegate { folderViewer.Store.SetPixbuf(iter, pixbuf); folderViewer.ShowAll(); }); }
private void LoadImage(UserInfo userInfo, string path) { try { Gdk.Pixbuf pixbuf = ImageUtils.GetPixbuf(path, ThumbWidth, ThumbHeight); LoadImage(userInfo, path, pixbuf); } catch (Exception e) { Debug.Log("Load {0} Image {1}: {2}", userInfo.Name, path, e.Message); } }
private void ReceiveImageThumb(UserInfo userInfo, string path, string b64image) { byte[] imgData = Convert.FromBase64String(b64image); Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(imgData); LoadImage(userInfo, path, pixbuf); }
public void SendImageThumb(UserInfo userInfo, string filePath) { PeerSocket peer = P2PManager.KnownPeers[userInfo] as PeerSocket; if (peer != null) SendImageThumb(peer, filePath); }
/// Do Login and return IpWeb & Magic public static bool Login(UserInfo userInfo, string password) { // Set Options Hashtable options = new Hashtable(); options.Add("passwd", password); // Make Url & Request string url = MakeUrl(userInfo, "Login.php", options); XmlRequest xml = MakeRequest(url); // Parse Xml Response if (xml.FirstTag == "login") { userInfo.Informations.Add("ipweb", xml.Attributes["ip"]); userInfo.Informations.Add("magic", xml.BodyText); return(true); } // Request Error throw(new Exception(xml.FirstTag + ": " + xml.BodyText)); }
public static void InsertError(UserInfo userInfo, string error) { TalkFrame talkFrame = LookupTalkFrame(userInfo); if (talkFrame != null) talkFrame.InsertError(error); }
/// Update My Server Status public static void Update(UserInfo userInfo) { // Set Options Hashtable options = new Hashtable(); options.Add("magic", userInfo.Informations["magic"]); // Make Url & Request string url = MakeUrl(userInfo, "Update.php", options); XmlRequest xml = MakeRequest(url); // Parse Xml Response if (xml.FirstTag != "update") { // Request Error throw(new Exception(xml.FirstTag + ": " + xml.BodyText)); } }
/// Connect on Server public static void Connect(UserInfo userInfo, int port) { // Set Options Hashtable options = new Hashtable(); options.Add("magic", userInfo.Informations["magic"]); options.Add("port", port.ToString()); // Make Url & Request string url = MakeUrl(userInfo, "Connect.php", options); XmlRequest xml = MakeRequest(url); // Parse Xml Response if (xml.FirstTag != "connect") { // Request Error throw(new Exception(xml.FirstTag + ": " + xml.BodyText)); } }
private void OnSaveFile(object sender, UserInfo userInfo, string path) { Gtk.Application.Invoke(delegate { PeerSocket peer = P2PManager.KnownPeers[userInfo] as PeerSocket; // Save File Dialog string savePath = Glue.Dialogs.SaveFile(Paths.UserSharedDirectory(MyInfo.Name), path.Substring(1)); if (savePath == null) return; try { DownloadManager.AddToAcceptList(peer, path, savePath); CmdManager.AcceptFile(peer, path); } catch (Exception e) { Glue.Dialogs.MessageError("Save File", e.Message); } }); }
private void OnLoginChecked(UserInfo info, bool status, string message) { Gtk.Application.Invoke(delegate { if (timerRet == true) { this.message = message; Respond((status == true) ? ResponseType.Ok : ResponseType.No); } }); }
public static void InsertMessage(UserInfo userInfo, string message) { TalkFrame talkFrame = AddTalkFrame(userInfo); talkFrame.InsertMessage(userInfo, message); }
public static void InsertStatus(UserInfo userInfo, string status) { TalkFrame talkFrame = LookupTalkFrame(userInfo); if (talkFrame != null) talkFrame.InsertStatus(status); }