// ============================================ // PROTECTED (Methods) Event Handlers // ============================================ protected void OnDragDataReceived(object sender, DragDataReceivedArgs args) { // Get Drop Paths object[] filesPath = Dnd.GetDragReceivedPaths(args); if (this.userInfo == MyInfo.GetInstance()) { // Copy Selected Files Into Directory foreach (string filePath in filesPath) { FileUtils.CopyAll(filePath, currentDirectory.FullName); } // Refresh Icon View Refresh(); } else { // Send Files foreach (string filePath in filesPath) { PeerSocket peer = (PeerSocket)P2PManager.KnownPeers[userInfo]; bool fisDir = FileUtils.IsDirectory(filePath); Debug.Log("Send To '{0}' URI: '{1}'", userInfo.Name, filePath); if (FileSend != null) { FileSend(peer, filePath, fisDir); } } } Drag.Finish(args.Context, true, false, args.Time); }
/// Check Login, Return null if Login failed public UserInfo CheckLogin() { MyInfo.Initialize(Username, SecureAuthentication); if (SecureAuthentication == false) { return(MyInfo.GetInstance()); } // Login Progress Dialog LoginDialog.ProgressDialog dialog = new LoginDialog.ProgressDialog(Password); ResponseType response = (ResponseType)dialog.Run(); string responseMsg = dialog.ResponseMessage; dialog.Destroy(); // Login OK if (response == ResponseType.Ok) { return(MyInfo.GetInstance()); } string title = "Login Error"; if (responseMsg == null) { responseMsg = "Unknown Error..."; } ShowErrorMessage(title, responseMsg); return(null); }
/// Check Login, Return null if Login failed public UserInfo CheckLogin() { MyInfo.Initialize(Username, SecureAuthentication); if (SecureAuthentication == false) { return(MyInfo.GetInstance()); } // Login Progress Dialog LoginProgressDialog dialog = new LoginProgressDialog(Password); ResponseType response = (ResponseType)dialog.Run(); string responseMsg = dialog.ResponseMessage; dialog.Destroy(); // Login OK if (response == ResponseType.Ok) { return(MyInfo.GetInstance()); } WindowUtils.Shake(this, 2); if (responseMsg != null) { Glue.Dialogs.MessageError("Login Error", responseMsg); } return(null); }
/// Refresh Folder Viewer and Folder Store public void Refresh() { // Directory's Path if (currentDirectory == null || baseDirectory == null) { return; } // Clear The Store store.Clear(); if (this.userInfo == MyInfo.GetInstance()) { // MyFolder this.store.Fill(currentDirectory.FullName); } else { // Peer Folder if (FolderRefresh != null) { FolderRefresh(this, currentDirectory.FullName); } } }
protected void OnItemActivated(object sender, ItemActivatedArgs args) { // Get File Path & IsDirectory Flag bool isDir = store.GetIsDirectory(args.Path); string path = store.GetFilePath(args.Path); if (isDir == true) { // Replace Parent With Path and ReFill The Model currentDirectory = new DirectoryInfo(path); // Refresh FileStore Gtk.Application.Invoke(delegate { Refresh(); }); // Sensitize the up button if (DirChanged != null) { DirChanged(this, true); } } else if (userInfo == MyInfo.GetInstance()) { try { // Try To Open This File System.Diagnostics.Process.Start(path); } catch (Exception e) { Debug.Log("Failed Process.Start() {0}: {1}", path, e.Message); } } }
/// Update Shared Files Num public void UpdateSharedFilesNum() { try { UserInfo userInfo = MyInfo.GetInstance(); string sharedFolder = Paths.UserSharedDirectory(userInfo.Name); int numFiles = CountDirectoryFiles(sharedFolder); this.labelTFiles.Text = numFiles.ToString() + " Shared Files"; } catch {} }
// ============================================ // PRIVATE Methods // ============================================ private void UserConnect(UserInfo userInfo) { try { // Connect & Send Login P2PManager.AddPeer(userInfo, userInfo.Ip, userInfo.Port); PeerSocket peer = (PeerSocket)P2PManager.KnownPeers[userInfo]; CmdManager.Login(peer, MyInfo.GetInstance()); OnPeerLogin(peer, userInfo); } catch (Exception e) { Glue.Dialogs.MessageError("Connenting To " + userInfo.Name + " Failed", e.Message); } }
private void UserConnect(UserInfo userInfo) { try { // Connect & Send Login P2PManager.AddPeer(userInfo, userInfo.Ip, userInfo.Port); PeerSocket peer = (PeerSocket)P2PManager.KnownPeers[userInfo]; Cmd.Login(peer, MyInfo.GetInstance()); OnPeerLogin(peer, userInfo); } catch (Exception e) { string title = "Connection To <b>" + userInfo.Name + "</b> Failed"; Base.Dialogs.MessageError(title, e.Message); } }
private static void OnTalkFrameRemoved(object o, object page) { if (talkFrames.ContainsValue(page) == true) { TalkFrame talkFrame = page as TalkFrame; talkFrame.Message -= new StringEventHandler(OnSendMessage); PeerSocket peer = (PeerSocket)P2PManager.KnownPeers[talkFrame.UserInfo]; SendStatus(peer, MyInfo.GetInstance().Name + " has closed the conversation Window..."); talkFrames.Remove(talkFrame.UserInfo); } }
// ============================================ // 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); }
private void UserConnect(UserInfo userInfo) { if (userInfo.SecureAuthentication == false) { return; } try { // Connect & Send Login userInfo.GetIpAndPort(); Debug.Log("Auto Add Buddy: {0} {1}:{2}", userInfo.Name, userInfo.Ip, userInfo.Port); P2PManager.AddPeer(userInfo, userInfo.Ip, userInfo.Port); PeerSocket peer = (PeerSocket)P2PManager.KnownPeers[userInfo]; Cmd.Login(peer, MyInfo.GetInstance()); } catch (Exception e) { Debug.Log("Connection To {0} Failed: {1}", userInfo.Name, e.Message); } }
// ============================================ // 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 static void OnTalkFrameRemoved(object o, object page) { Gtk.Application.Invoke(delegate { if (talkFrames.ContainsValue(page) == true) { TalkFrame talkFrame = page as TalkFrame; talkFrame.Message -= new StringEventHandler(OnSendMessage); PeerSocket peer = (PeerSocket)P2PManager.KnownPeers[talkFrame.UserInfo]; if (peer != null) { UserInfo userInfo = MyInfo.GetInstance(); SendStatus(peer, userInfo.Name + " has closed the conversation Window..."); } talkFrames.Remove(talkFrame.UserInfo); } }); }
// ============================================ // PRIVATE (Methods) Event Handlers // ============================================ private static void OnSendMessage(object sender, string message) { TalkFrame talkFrame = sender as TalkFrame; PeerSocket peer = (PeerSocket)P2PManager.KnownPeers[talkFrame.UserInfo]; if (peer != null) { SendMessage(peer, message); Gtk.Application.Invoke(delegate { talkFrame.InsertMessage(MyInfo.GetInstance(), message); }); } else { Gtk.Application.Invoke(delegate { talkFrame.InsertError("Couldn't Send Message: " + message); }); } }
// ============================================ // PROTECTED (Methods) Event Handlers // ============================================ protected void OnDragDataReceived(object sender, DragDataReceivedArgs args) { if (this.userInfo == MyInfo.GetInstance()) { return; } // Get Drop Paths object[] filesPath = Dnd.GetDragReceivedPaths(args); foreach (string filePath in filesPath) { PeerSocket peer = (PeerSocket)P2PManager.KnownPeers[userInfo]; bool fisDir = FileUtils.IsDirectory(filePath); Debug.Log("Send To '{0}' URI: '{1}'", userInfo.Name, filePath); if (FileSend != null) { FileSend(peer, filePath, fisDir); } } Drag.Finish(args.Context, true, false, args.Time); }
protected void OnItemClicked(object sender, ButtonPressEventArgs args) { if (iconView.SelectedItems.Length <= 0) { return; } if (args.Event.Device.Source != Gdk.InputSource.Mouse) { return; } if (args.Event.Button == 3) { PopupMenu menu = new PopupMenu(); // Options if (this.userInfo == MyInfo.GetInstance()) { AddSendFileMenu(menu); menu.AddImageItem(Gtk.Stock.Remove, new EventHandler(OnFileRemove)); } else { menu.AddImageItem(Gtk.Stock.Save, new EventHandler(OnFileSave)); } // Start Right Menu Event if (RightMenu != null) { RightMenu(this, menu); } menu.Popup(); menu.ShowAll(); } }
private void OnMyFolderCliecked(object sender, EventArgs args) { Gtk.Application.Invoke(delegate { this.notebookViewer.Append(MyInfo.GetInstance(), "<b>Me</b> (" + MyInfo.Name + ")"); }); }