void Thumbnailer_Thread() { Console.WriteLine("T: Hello from the Thumbnailer thread"); while (true) { try { thumbnail_sema.Down(); } catch { // ignore } ThumbnailerInfo tinfo; while (thumb_stack.Count > 0) { lock (thumb_stack) { tinfo = (ThumbnailerInfo)thumb_stack.Pop(); } MakeThumbnail(tinfo); lock (thumbs_done) { thumbs_done.Enqueue(tinfo); } main_notify.WakeupMain(); } } }
private void SimiasEventNotifyHandler(SimiasEventArgs args) { try { NotifyEventArgs notifyEventArgs = args as NotifyEventArgs; lock (NotifyEventQueue) { NotifyEventQueue.Enqueue(notifyEventArgs); GenericEventFired.WakeupMain(); } } catch (Exception e) { if (printErrors) { Debug.PrintLine("Exception in SimiasEventNotifyHandler(): " + e.Message); Debug.PrintLine(e.StackTrace); } } }
private void SimiasEventSyncFileHandler(SimiasEventArgs args) { try { FileSyncEventArgs fileSyncArgs = args as FileSyncEventArgs; lock (FileEventQueue) { FileEventQueue.Enqueue(fileSyncArgs); FileEventFired.WakeupMain(); } } catch (Exception e) { if (printErrors) { Debug.PrintLine("Exception in SimiasEventSyncFileHandler(): " + e.Message); Debug.PrintLine(e.StackTrace); } } }
private void OpenPack(string filename) { if (Packer.Create(System.IO.Path.GetExtension(filename), out fileSystem)) { waitWindow = new WaitWindow(this, "Opening", filename); waitWindow.Show(); ThreadNotify done = new ThreadNotify(new ReadyEvent(() => { waitWindow.Destroy(); waitWindow = null; })); ThreadNotify error = new ThreadNotify(new ReadyEvent(() => { waitWindow.Destroy(); waitWindow = null; CustomMessageDialog msg = new CustomMessageDialog(this, MessageType.Error, fileSystem.LastError); msg.Run(); msg.Destroy(); })); new Thread(new ThreadStart(() => { if (fileSystem.Open(filename)) { RebuildPackTree(fileSystem.ListFiles()); ChangePackActionSensitive(true); done.WakeupMain(); } else error.WakeupMain(); })).Start(); } }
private void HandleSaveAction() { if (fileSystem == null) return; CustomFileChooserDialog dlg = new CustomFileChooserDialog(this, "Save pack", FileChooserAction.Save); dlg.FileChooser.SelectMultiple = false; using (Gtk.FileFilter filter = new Gtk.FileFilter()) { filter.Name = fileSystem.Extension.ToUpper(); filter.AddPattern("*." + fileSystem.Extension.ToLower()); dlg.FileChooser.AddFilter(filter); } using (Gtk.FileFilter filter = new Gtk.FileFilter()) { filter.Name = "All"; filter.AddPattern("*.*"); dlg.FileChooser.AddFilter(filter); } dlg.Ok += (sender, e) => { string filename = dlg.FileChooser.Filename; waitWindow = new WaitWindow(this, "Saving", filename); waitWindow.Show(); ThreadNotify done = new ThreadNotify(new ReadyEvent(() => { waitWindow.Destroy(); waitWindow = null; })); ThreadNotify error = new ThreadNotify(new ReadyEvent(() => { waitWindow.Destroy(); waitWindow = null; CustomMessageDialog msg = new CustomMessageDialog(this, MessageType.Error, fileSystem.LastError); msg.Run(); msg.Destroy(); })); new Thread(new ThreadStart(() => { if (fileSystem.Save(filename)) done.WakeupMain(); else error.WakeupMain(); })).Start(); dlg.Destroy(); }; dlg.Cancel += (sender, e) => dlg.Destroy(); dlg.Show(); }
private void HandleAddFolderAction() { if (fileSystem == null) return; CustomFileChooserDialog dlg = new CustomFileChooserDialog(this, "Add folder to pack", FileChooserAction.SelectFolder); dlg.Ok += (sender, e) => { packTreeView.Selection.UnselectAll(); waitWindow = new WaitWindow(this, "Adding", ""); waitWindow.Show(); ThreadNotify done = new ThreadNotify(new ReadyEvent(() => { waitWindow.Destroy(); waitWindow = null; })); new Thread(new ThreadStart(() => { string path = dlg.FileChooser.Filename; dlg.Destroy(); Packer.Item folderItem = NewItem(currentFolder, path); TreeIter folderIter = AppendItem(currentFolder, folderItem); if (!TreeIter.Zero.Equals(folderIter)) AppendFolders(folderIter, folderItem.HDDPath); done.WakeupMain(); })).Start(); }; dlg.Cancel += (sender, e) => dlg.Destroy(); dlg.Show(); }
private void HandleAddFilesAction() { if (fileSystem == null) return; CustomFileChooserDialog dlg = new CustomFileChooserDialog(this, "Add files to pack", FileChooserAction.Open); dlg.FileChooser.SelectMultiple = true; using (Gtk.FileFilter filter = new Gtk.FileFilter()) { filter.Name = "All"; filter.AddPattern("*.*"); dlg.FileChooser.AddFilter(filter); } dlg.Ok += (sender, e) => { packTreeView.Selection.UnselectAll(); waitWindow = new WaitWindow(this, "Adding", ""); waitWindow.Show(); ThreadNotify done = new ThreadNotify(new ReadyEvent(() => { dlg.Destroy(); waitWindow.Destroy(); waitWindow = null; })); new Thread(new ThreadStart(() => { dlg.FileChooser.Filenames.ToList().ForEach( file => AppendFile(currentFolder, file)); done.WakeupMain(); })).Start(); }; dlg.Cancel += (sender, e) => dlg.Destroy(); dlg.Show(); }
private void ExtractFile(TreeIter iter, string filename) { waitWindow = new WaitWindow(this, "Extracting", filename); waitWindow.Show(); ThreadNotify done = new ThreadNotify(new ReadyEvent(() => { waitWindow.Destroy(); waitWindow = null; })); ThreadNotify error = new ThreadNotify(new ReadyEvent(() => { waitWindow.Destroy(); waitWindow = null; CustomMessageDialog msg = new CustomMessageDialog(this, MessageType.Error, fileSystem.LastError); msg.Run(); msg.Destroy(); })); Packer.Item item = packStore.GetValue(iter, 0) as Packer.Item; new Thread(new ThreadStart(() => { if (fileSystem.Extract(item, filename)) done.WakeupMain(); else error.WakeupMain(); })).Start(); }
private void SimiasEventSyncCollectionHandler(SimiasEventArgs args) { try { if (args == null) { Debug.PrintLine("SimiasEventSyncCollectionHandler received a null SimiasEventArgs"); return; } CollectionSyncEventArgs syncEventArgs = args as CollectionSyncEventArgs; if (syncEventArgs == null || syncEventArgs.Name == null || syncEventArgs.ID == null) { Debug.PrintLine("SimiasEventSyncCollectionHandler() Name, ID, Action, or Connected is null"); return; // Prevent a null object } if (ifdata.IsiFolder(syncEventArgs.ID)) { iFolderHolder ifHolder = ifdata.GetiFolder(syncEventArgs.ID); if (ifHolder != null) { switch (syncEventArgs.Action) { case Simias.Client.Event.Action.StartLocalSync: ifHolder.State = iFolderState.SynchronizingLocal; break; case Simias.Client.Event.Action.StartSync: ifHolder.State = iFolderState.Synchronizing; break; case Simias.Client.Event.Action.StopSync: try { SyncSize syncSize = ifws.CalculateSyncSize(syncEventArgs.ID); ifHolder.ObjectsToSync = syncSize.SyncNodeCount; } catch {} if (ifHolder.ObjectsToSync > 0) { ifHolder.State = iFolderState.Normal; } else { if (syncEventArgs.Connected || ifHolder.iFolder.Role == "Master") { ifHolder.State = iFolderState.Normal; } else { ifHolder.State = iFolderState.Disconnected; } } break; } if ((ifHolder.iFolder.UnManagedPath == null) || (ifHolder.iFolder.UnManagedPath.Length == 0)) { // Because the iFolder has no path // re-read the iFolder and fire a changed event ifHolder = ifdata.ReadiFolder(syncEventArgs.ID); if (ifHolder != null) { lock (NodeEventQueue) { NodeEventQueue.Enqueue(new SimiasEvent( ifHolder.iFolder.ID, null, null, SimiasEventType.ChangediFolder)); SimiasEventFired.WakeupMain(); } } } } } // pass the sync event on to the client lock (SyncEventQueue) { SyncEventQueue.Enqueue(syncEventArgs); SyncEventFired.WakeupMain(); } } catch (Exception e) { if (printErrors) { Debug.PrintLine("Exception in SimiasEventSyncCollectionHandler(): " + e.Message); Debug.PrintLine(e.StackTrace); } } }
/** * When a buddy changes, and we need to display it, this method * handles it */ public void BuddyChangeHandler(object buddy, System.EventArgs args) { Buddy b = (Buddy)buddy; /* * We use an anonymous delegate here to handle the threading. */ Gtk.ThreadNotify notify = new ThreadNotify( delegate { TreeIter it; if( _store.GetIterFirst(out it) ) { //Let's find the info for this buddy: do { string buddy_alias = (string)_store.GetValue(it,0); if( b.Alias.Equals( buddy_alias ) ) { _store.SetValue(it,2, b.Status); //Now we are done } } while( _store.IterNext(ref it) ); } }); notify.WakeupMain(); }
/** * The buddy list sends an event when there is an incoming chat */ public void IncomingChatHandler(object buddy, System.EventArgs args) { Buddy b = (Buddy)buddy; ChatEventArgs cea = (ChatEventArgs)args; Brunet.Chat.Message mes = cea.Message; /* * We use an anonymous delegate here to handle the threading. */ Gtk.ThreadNotify notify = new ThreadNotify( delegate { //These are GTK operations which need to be synchronized BrunetChatIM imwin = OpenChatSession(b); imwin.DeliverMessage(mes.Body); }); notify.WakeupMain(); //Threads.Leave(); /* * Send a terminal bell when we get a message. * Otherwise, we tend not to notice our Buddies */ char bell_char = (char)7; System.Console.Write(bell_char); }