private bool AddGamesIdleHandler() { IList games = viewer.ChessGameWidget.Games; if (games == null) { dbDlg.Dispose (); dbDlg = null; return false; } viewer.StartProgress (); double totalgames = games.Count; int ngames = 0; GameCollection collection = null; string[]tags = dbDlg.Tags; if (dbDlg.AddCollection && dbDlg.CollectionTitle != null) { collection = new GameCollection (dbDlg. CollectionTitle, dbDlg. Description, new ArrayList ()); } // Dont use 'foreach' since the list is going to change for (int i = 0; i < games.Count; i++) { ChessGame game = (ChessGame) games[i]; PGNGameDetails updated; if (!(game is PGNGameDetails)) { GameDb.Instance. FindOrCreateGame (game, out updated); } else updated = game as PGNGameDetails; foreach (string tag in tags) { updated.AddTag (tag); } if (collection != null) collection. AddGame (updated); GameDb.Instance.DB.Set (updated); viewer.ChessGameWidget. UpdateGame (game, updated); ngames++; viewer.UpdateProgress (ngames / totalgames); } if (collection != null) GameDb.Instance.DB.Set (collection); if (ngames > 0) GameDb.Instance.Commit (); viewer.StopProgress (); dbDlg.Dispose (); dbDlg = null; return false; }
private void on_add_to_db_activate(object o, EventArgs args) { dbDlg = new AddToDbDialog (null); if (dbDlg.Run () != (int) ResponseType.Ok) { dbDlg.Hide (); dbDlg.Dispose (); return; } dbDlg.Hide (); GLib.Idle.Add (AddGamesIdleHandler); }