public SparkleNoteController() { Program.Controller.ShowNoteWindowEvent += delegate(string project) { CurrentProject = project; ShowWindowEvent(); UpdateTitleEvent(CurrentProject); }; AvatarFilePath = SparkleAvatars.GetAvatar(Program.Controller.CurrentUser.Email, 48, Program.Controller.Config.FullPath); }
private string GetAvatarFilePath(SparkleUser user) { if (!Program.Controller.AvatarsEnabled) { return("<!-- $pixmaps-path -->/user-icon-default.png"); } string fetched_avatar = SparkleAvatars.GetAvatar(user.Email, 48, Program.Controller.Config.FullPath); if (!string.IsNullOrEmpty(fetched_avatar)) { return("file://" + fetched_avatar.Replace("\\", "/")); } else { return("<!-- $pixmaps-path -->/user-icon-default.png"); } }
private void AddRepository(string folder_path) { SparkleRepoBase repo = null; string folder_name = Path.GetFileName(folder_path); string backend = Config.GetBackendForFolder(folder_name); try { repo = (SparkleRepoBase)Activator.CreateInstance( Type.GetType("SparkleLib." + backend + ".SparkleRepo, SparkleLib." + backend), new object [] { folder_path, Config }); } catch (Exception e) { SparkleLogger.LogInfo("Controller", "Failed to load backend '" + backend + "' for '" + folder_name + "': ", e); return; } repo.ChangesDetected += delegate { UpdateState(); }; repo.SyncStatusChanged += delegate(SyncStatus status) { if (status == SyncStatus.Idle) { ProgressPercentage = 0.0; ProgressSpeedUp = 0.0; ProgressSpeedDown = 0.0; } UpdateState(); }; repo.ProgressChanged += delegate { ProgressPercentage = 0.0; ProgressSpeedUp = 0.0; ProgressSpeedDown = 0.0; double percentage = 0.0; int repo_count = 0; foreach (SparkleRepoBase rep in Repositories) { if (rep.ProgressPercentage > 0) { percentage += rep.ProgressPercentage; repo_count++; } if (rep.Status == SyncStatus.SyncUp) { ProgressSpeedUp += rep.ProgressSpeed; } if (rep.Status == SyncStatus.SyncDown) { ProgressSpeedDown += rep.ProgressSpeed; } } if (repo_count > 0) { ProgressPercentage = percentage / repo_count; } UpdateState(); }; repo.NewChangeSet += delegate(SparkleChangeSet change_set) { if (AvatarsEnabled) { change_set.User.AvatarFilePath = SparkleAvatars.GetAvatar(change_set.User.Email, 48, Config.FullPath); } NotificationRaised(change_set); }; repo.ConflictResolved += delegate { AlertNotificationRaised("Resolved a file collision", "Local and server versions were kept."); }; AddRepository(repo); repo.Initialize(); }