public JsonResult UserSelectPhoto(int userId, string imageName) { var photo = db.SelectedPhotos.Where(s => s.ImageName.ToLower() == imageName.ToLower() && s.UserId == userId).FirstOrDefault(); if (photo == null) { photo = new SelectedPhoto() { ImageName = imageName.ToLower(), UserId = userId }; db.SelectedPhotos.Add(photo); db.SaveChanges(); } return(Json(photo.Id)); }
private void FireUpFileChooserForDownloading() { if (uploadbutton.Active) return; FileChooserDialog chooser = new FileChooserDialog( "Select a folder", null, FileChooserAction.SelectFolder, Stock.Open, ResponseType.Ok, Stock.Cancel, ResponseType.Cancel); chooser.SetIconFromFile(DeskFlickrUI.ICON_PATH); chooser.SetFilename(PersistentInformation.GetInstance().DownloadFoldername); ResponseType choice = (ResponseType) chooser.Run(); string foldername = ""; if (choice == ResponseType.Ok) { foldername = chooser.Filename; // Set the default path to be opened next time file chooser runs. PersistentInformation.GetInstance().DownloadFoldername = foldername; } chooser.Destroy(); if (foldername.Equals("")) return; // Selected folder for downloading. ArrayList photoids = new ArrayList(); ArrayList selectedphotos = new ArrayList(); bool refreshview = false; if (treeview2.Selection.GetSelectedRows().Length > 0) { foreach (TreePath path in treeview2.Selection.GetSelectedRows()) { Photo p = new Photo(GetPhoto(path)); TreePath childpath = filter.ConvertPathToChildPath(path); SelectedPhoto sel = new SelectedPhoto(p, childpath.ToString()); selectedphotos.Add(sel); photoids.Add(p.Id); } } else if (treeview1.Selection.GetSelectedRows().Length > 0) { // Going through the complex way of figuring out photos for the // different tab modes. Easier way would be to just copy contents // of _photos, as it already takes care of left tree selection. However, // when the view is locked to 'downloads', _photos wouldn't be updated. // Hence the need to figure out photoids. TreePath path = treeview1.Selection.GetSelectedRows()[0]; if (selectedtab == 0) { // albums Album album = new Album((Album) _albums[path.Indices[0]]); photoids = PersistentInformation.GetInstance().GetPhotoIdsForAlbum(album.SetId); //foldername = String.Format("{0}/{1}", foldername, album.Title); } else if (selectedtab == 1) { // tags string tag = (string) _tags[path.Indices[0]]; photoids = PersistentInformation.GetInstance().GetPhotoIdsForTag(tag); //foldername = String.Format("{0}/{1}", foldername, tag); } else if (selectedtab == 2) { PersistentInformation.Entry poolentry = (PersistentInformation.Entry) _pools[path.Indices[0]]; string poolid = poolentry.entry1; //string pooltitle = poolentry.entry2; photoids = PersistentInformation.GetInstance().GetPhotoidsForPool(poolid); //foldername = String.Format("{0}/{1}", foldername, pooltitle); } else if (selectedtab == 3) { PersistentInformation.Entry blog = (PersistentInformation.Entry) _blogs[path.Indices[0]]; foreach (BlogEntry blogentry in PersistentInformation.GetInstance().GetEntriesForBlog(blog.entry1)) { photoids.Add(blogentry.Photoid); } //foldername = String.Format("{0}/{1}", foldername, blog.entry2); } refreshview = true; } Utils.EnsureDirectoryExists(foldername); foreach (string id in photoids) { if (PersistentInformation.GetInstance().IsDownloadEntryExists(id)) { PersistentInformation.GetInstance().DeleteEntryFromDownload(id); } PersistentInformation.GetInstance().InsertEntryToDownload(id, foldername); } UpdateToolBarButtons(); if (downloadbutton.Active) RefreshDownloadPhotos(); else if (refreshview) RefreshLeftTreeView(); else UpdatePhotos(selectedphotos); }
// Don't really care about the selection data sent. Because, we can // rather easily just look at the selected photos. private void OnPhotoDraggedForAddition(object o, DragDataReceivedArgs args) { TreePath path; TreeViewDropPosition pos; // This line determines the destination row. treeview1.GetDestRowAtPos(args.X, args.Y, out path, out pos); if (path == null) return; int destindex = path.Indices[0]; if (selectedtab == 0) { // albums // TODO: Allow addition to sets. if (uploadbutton.Active) return; // Doesn't allow addition to sets yet. string setid = ((Album) _albums[destindex]).SetId; foreach (TreePath photospath in treeview2.Selection.GetSelectedRows()) { string photoid = GetPhoto(photospath).Id; bool exists = PersistentInformation.GetInstance() .HasAlbumPhoto(photoid, setid); if (exists) { TreePath albumselectedpath = treeview1.Selection.GetSelectedRows()[0]; if (!streambutton.Active && !conflictbutton.Active && treeview2.Selection.GetSelectedRows().Length == 1 // If dragged dest album is same as the one selected. && albumselectedpath.Indices[0] == destindex) { // Scenario: The user is viewing the set, and decides to // change the primary photo. He can do so by dragging the photo // from the respective set, to the set itself. However, make // sure that only one photo is selected. // The album selected is the same as the album the photo is // dragged on. PersistentInformation.GetInstance().SetPrimaryPhotoForAlbum(setid, photoid); PersistentInformation.GetInstance().SetAlbumDirtyIfNotNew(setid); PopulateAlbums(); } } else { // The photo isn't present in set. PersistentInformation.GetInstance().AddPhotoToAlbum(photoid, setid); if (PersistentInformation.GetInstance().GetPhotoIdsForAlbum(setid).Count == 1) { PersistentInformation.GetInstance().SetPrimaryPhotoForAlbum(setid, photoid); } PersistentInformation.GetInstance().SetAlbumDirtyIfNotNew(setid); UpdateAlbumAtPath(path, (Album) _albums[destindex]); } } } else if (selectedtab == 1) { // tags ArrayList selectedphotos = new ArrayList(); foreach (TreePath photospath in treeview2.Selection.GetSelectedRows()) { Photo photo = GetPhoto(photospath); string tag = (string) _tags[destindex]; if (uploadbutton.Active) { photo.AddTag(tag); PersistentInformation.GetInstance().UpdateInfoForUploadPhoto(photo); } else { // Check if the original version is stored in db. Allow for revert. if (!PersistentInformation.GetInstance().HasOriginalPhoto(photo.Id) && !PersistentInformation.GetInstance().IsPhotoDirty(photo.Id)) { PersistentInformation.GetInstance().InsertOriginalPhoto(photo); } if (!PersistentInformation.GetInstance().HasTag(photo.Id, tag)) { PersistentInformation.GetInstance().InsertTag(photo.Id, tag); PersistentInformation.GetInstance().SetPhotoDirty(photo.Id, true); } } photo.AddTag(tag); TreePath childpath = filter.ConvertPathToChildPath(photospath); SelectedPhoto selphoto = new SelectedPhoto(photo, childpath.ToString()); selectedphotos.Add(selphoto); } // UpdatePhotos will replace the old photos, with the new ones containing // the tag information. UpdatePhotos(selectedphotos); UpdateTagAtPath(path, (string) _tags[destindex]); } else if (selectedtab == 2) { // pools // TODO: Allow addition to pools. if (uploadbutton.Active) return; // Doesn't allow addition to sets yet. PersistentInformation.Entry entry = (PersistentInformation.Entry) _pools[destindex]; string groupid = entry.entry1; foreach (TreePath photospath in treeview2.Selection.GetSelectedRows()) { Photo photo = GetPhoto(photospath); if (!PersistentInformation.GetInstance().HasPoolPhoto(photo.Id, groupid)) { PersistentInformation.GetInstance().InsertPhotoToPool(photo.Id, groupid); PersistentInformation.GetInstance().MarkPhotoAddedToPool(photo.Id, groupid, true); } else if (PersistentInformation.GetInstance() .IsPhotoDeletedFromPool(photo.Id, groupid)) { PersistentInformation.GetInstance() .MarkPhotoDeletedFromPool(photo.Id, groupid, false); } } UpdatePoolAtPath(path, entry); } else if (selectedtab == 3) { // blogs if (uploadbutton.Active) return; PersistentInformation.Entry entry = (PersistentInformation.Entry) _blogs[destindex]; string blogid = entry.entry1; ArrayList selectedphotos = new ArrayList(); foreach (TreePath photospath in treeview2.Selection.GetSelectedRows()) { Photo photo = GetPhoto(photospath); if (!PersistentInformation.GetInstance().HasBlogPhoto(blogid, photo.Id)) { BlogEntry blogentry = new BlogEntry(blogid, photo.Id, photo.Title, photo.Description); PersistentInformation.GetInstance().InsertEntryToBlog(blogentry); } TreePath childpath = filter.ConvertPathToChildPath(photospath); SelectedPhoto selphoto = new SelectedPhoto(photo, childpath.ToString()); selectedphotos.Add(selphoto); } UpdatePhotos(selectedphotos); UpdateBlogAtPath(path, entry); } }
private void OnEditButtonClicked(object o, EventArgs args) { // Check right tree first. if (treeview2.Selection.GetSelectedRows().Length > 0) { ArrayList selectedphotos = new ArrayList(); foreach (TreePath path in treeview2.Selection.GetSelectedRows()) { Photo p = new Photo(GetPhoto(path)); // Check if the original version is stored in db. Allow for revert. if (!uploadbutton.Active && !PersistentInformation.GetInstance().HasOriginalPhoto(p.Id) && !PersistentInformation.GetInstance().IsPhotoDirty(p.Id)) { PersistentInformation.GetInstance().InsertOriginalPhoto(p); } TreePath childpath = filter.ConvertPathToChildPath(path); if (GetMode() == DeskFlickrUI.ModeSelected.BlogMode) { string blogid = ((PersistentInformation.Entry) _blogs[leftcurselectedindex]).entry1; BlogEntry blogentry = PersistentInformation.GetInstance().GetEntryForBlog(blogid, p.Id); BlogSelectedPhoto bsel = new BlogSelectedPhoto(p, blogentry, childpath.ToString()); selectedphotos.Add(bsel); } else { SelectedPhoto sel = new SelectedPhoto(p, childpath.ToString()); selectedphotos.Add(sel); } } PhotoEditorUI.FireUp(selectedphotos, GetMode()); } // check left tree now. else if (treeview1.Selection.GetSelectedRows().Length > 0) { if (selectedtab == 1) return; // Tags can't be edited. TreePath path = treeview1.Selection.GetSelectedRows()[0]; Album album = new Album((Album) _albums[path.Indices[0]]); AlbumEditorUI.FireUp(album); } }
private void OnDoubleClickPhoto(object o, RowActivatedArgs args) { ArrayList selectedphotos = new ArrayList(); // Make sure that we don't point to the photo object stored here. // Otherwise, even if the editing is not saved, it would be stored // in _photos. So, create a new Photo object. Photo p = new Photo(GetPhoto(args.Path)); if (!uploadbutton.Active && !PersistentInformation.GetInstance().HasOriginalPhoto(p.Id) && !PersistentInformation.GetInstance().IsPhotoDirty(p.Id)) { PersistentInformation.GetInstance().InsertOriginalPhoto(p); } TreePath childpath = filter.ConvertPathToChildPath(args.Path); if (GetMode() == DeskFlickrUI.ModeSelected.BlogMode) { string blogid = ((PersistentInformation.Entry) _blogs[leftcurselectedindex]).entry1; BlogEntry blogentry = PersistentInformation.GetInstance().GetEntryForBlog(blogid, p.Id); BlogSelectedPhoto bsel = new BlogSelectedPhoto(p, blogentry, childpath.ToString()); selectedphotos.Add(bsel); } else { SelectedPhoto sel = new SelectedPhoto(p, childpath.ToString()); selectedphotos.Add(sel); } PhotoEditorUI.FireUp(selectedphotos, GetMode()); }
private void deleteBTN_Click(object sender, EventArgs e) { SelectedPhoto.Delete(); LoadPhotos(); }
/// <summary> /// 写真読み込み家の初期化 /// </summary> private void PhotoInitialize() { #region ファイル読み込み SelectPhotoDirCommand = new ReactiveCommand(); SelectPhotoDirCommand.Subscribe(() => SelectDirectory(path => { Config.Value.PhotoDir = path; Config.ForceNotify(); })); SelectExportDirCommand = new ReactiveCommand(); SelectExportDirCommand.Subscribe(() => SelectDirectory(path => { Config.Value.ExportDir = path; Config.ForceNotify(); })); ReadPhotoCommand = new ReactiveCommand(); ReadPhotoCommand.Subscribe(async() => { IsPhotoUIEnable.Value = false; var photos = await LoadPhotos(new Progress <string>(msg => Log(msg))); //反映 Photos.Clear(); Tags.Clear(); Photos.AddRangeOnScheduler(photos); Tags.AddRangeOnScheduler(Config.Value.Tags); IsPhotoUIEnable.Value = true; Log($"{photos.Length}枚の画像を読み込み。プレビュー画像が古い場合、{Config.Value.PreviewTempPath}を削除してから再度実行してください。"); }); #endregion // フィルタ IsPhotoUIEnable.PropertyChangedAsObservable() .Select(x => Photos.AsEnumerable()) .CombineLatest(TagFilterAll, TagFilterNone, TagFilterTag, TagFilterSelectedTag, (p, isAll, isNone, isTag, tagText) => { // RadioButtonが2回判定が来る, trueがふたつあるときは無視 if ((isAll ? 1 : 0) + (isNone ? 1 : 0) + (isTag ? 1 : 0) > 1) { return(null); } if (isAll) { return(p); } else if (isNone) { return(p.Where(x => x.TagDetails.Length == 0)); } else if (isTag) { return(p.Where(x => x.TagDetails.Any(t => t.ToString().Equals(tagText)))); } else { throw new NotImplementedException(); } }) .Where(photos => photos != null) .Subscribe(photos => { FilteredPhotos.Clear(); FilteredPhotos.AddRangeOnScheduler(photos); }); #region ファイル名変更 SelectedPhoto.Where(x => x != null) .Subscribe(p => { ChangeFileName.Value = p.OriginalName; }); ChangeFileNameCommand = ChangeFileName.Select(x => !string.IsNullOrWhiteSpace(x)) .ToReactiveCommand(); ChangeFileNameCommand.Subscribe(() => { var oldName = SelectedPhoto.Value.OriginalName; var newName = ChangeFileName.Value; var newPath = Path.GetFullPath($"{Config.Value.PhotoDir}/{newName}"); if (File.Exists(newPath)) { Log("すでに存在するファイル名です"); return; } File.Move(SelectedPhoto.Value.OriginalPath, newPath); SelectedPhoto.Value.OriginalName = newName; // サムネが消えるのでリロードする SelectedPhoto.Value.GeneratePreviewImage(); Log($"ファイル名を変更 {oldName} -> {newName}"); }); #endregion #region Tag AddTagCommand = NewTagName.Select(x => !string.IsNullOrWhiteSpace(x)) .ToReactiveCommand(false); AddTagCommand.Subscribe(() => { var tag = Tags.FirstOrDefault(x => x.Name.Equals(NewTagName.Value)); if (tag == null) { Tags.AddOnScheduler(new Tag() { CreateAt = DateTime.Now, Name = NewTagName.Value, Description = NewTagDescription.Value, }); } else { tag.Description = NewTagDescription.Value; } }); ToggleTagCommand = SelectedPhoto.Select(x => x != null) .ToReactiveCommand <Tag>(false); //タグがある場合は削除、なければ追加 ToggleTagCommand.Subscribe(t => { var tagList = SelectedPhoto.Value.TagDetails.ToList(); var target = tagList.FirstOrDefault(x => x.Name.Equals(t.Name)); if (target != null) { tagList.Remove(target); } else { tagList.Add(t); } SelectedPhoto.Value.TagDetails = tagList.ToArray(); SelectedPhoto.ForceNotify(); }); #endregion #region Export ExportCommand = IsPhotoUIEnable.ToReactiveCommand(); ExportCommand.Subscribe(async() => { IsPhotoUIEnable.Value = false; // ファイルの削除 if (Directory.Exists(Config.Value.ExportDir)) { Directory.Delete(Config.Value.ExportDir, true); Log($"{Config.Value.ExportDir}を削除"); } // データのエクスポート await ExportPhotos(new Progress <string>(msg => Log(msg))); // Webから参照するデータをエクスポートする var data = new JObject() as dynamic; data.photos = JArray.FromObject(Photos.ToArray()); data.tags = JArray.FromObject(Tags.ToArray()); data.update = DateTime.Now; var json = JsonConvert.SerializeObject(data, Formatting.Indented); File.WriteAllText($"{Config.Value.ExportDir}/{Config.Value.ExportFileName}", json, Encoding.UTF8); Log($"{Config.Value.ExportFileName}に設定ファイルを出力"); // 情報のエクスポート Config.Value.Photos = Photos.ToArray(); Config.Value.Tags = Tags.ToArray(); SaveConfig(); IsPhotoUIEnable.Value = true; Log("エクスポート完了"); Process.Start(Config.Value.ExportDir); }); #endregion ClosingCommand = new ReactiveCommand(); ClosingCommand.Subscribe(() => { SaveConfig(); }); }