1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using System.Linq; |
---|
4 | using System.Text; |
---|
5 | |
---|
6 | using System.IO; |
---|
7 | using Com.Piwigo.Uploader.DTO; |
---|
8 | |
---|
9 | namespace Com.Piwigo.Uploader.Helper |
---|
10 | { |
---|
11 | internal static class MainAppHelper |
---|
12 | { |
---|
13 | internal static void showdErrorMessageBox(ApplicationException aEx) |
---|
14 | { |
---|
15 | System.Windows.Forms.MessageBox.Show(aEx.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); |
---|
16 | } |
---|
17 | |
---|
18 | internal static System.Windows.Forms.TreeNode buildAlbumToNode(LocalAlbum aAlbum) |
---|
19 | { |
---|
20 | System.Windows.Forms.TreeNode aNode = new System.Windows.Forms.TreeNode(aAlbum.Name,1,1); |
---|
21 | aNode.ToolTipText = aAlbum.LocalDir; |
---|
22 | aNode.Tag = aAlbum; |
---|
23 | |
---|
24 | foreach (LocalImage Img in aAlbum.LocalImages) |
---|
25 | { |
---|
26 | System.Windows.Forms.TreeNode imgNode = new System.Windows.Forms.TreeNode(Img.Name, 2, 2); |
---|
27 | imgNode.ToolTipText = Img.LocalFile; |
---|
28 | imgNode.Tag = Img; |
---|
29 | aNode.Nodes.Add(imgNode); |
---|
30 | } |
---|
31 | |
---|
32 | foreach (LocalAlbum Alb in aAlbum.SubAlbums) |
---|
33 | { |
---|
34 | aNode.Nodes.Add(buildAlbumToNode(Alb)); |
---|
35 | } |
---|
36 | |
---|
37 | return aNode; |
---|
38 | } |
---|
39 | |
---|
40 | internal static void BuildAlbumTree(System.Windows.Forms.TreeView aTree, LocalAlbumList lstAlbum) |
---|
41 | { |
---|
42 | if (aTree.Nodes.Count > 0) |
---|
43 | { |
---|
44 | aTree.Nodes.Clear(); |
---|
45 | } |
---|
46 | |
---|
47 | System.Windows.Forms.TreeNode root = new System.Windows.Forms.TreeNode("Albums", 0, 0); |
---|
48 | aTree.Nodes.Add(root); |
---|
49 | |
---|
50 | foreach (LocalAlbum Alb in lstAlbum) |
---|
51 | { |
---|
52 | root.Nodes.Add(buildAlbumToNode(Alb)); |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | #region thumb |
---|
57 | internal static string MakeThumb(FileInfo fi, String ext, int size) |
---|
58 | { |
---|
59 | // create an image object, using the filename we just retrieved |
---|
60 | System.Drawing.Image image = System.Drawing.Image.FromFile(fi.FullName); |
---|
61 | |
---|
62 | // create the actual thumbnail image |
---|
63 | System.Drawing.Image thumbnailImage = image.GetThumbnailImage(size, size, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); |
---|
64 | |
---|
65 | // make a memory stream to work with the image bytes |
---|
66 | FileStream imageStream = new FileStream(ext, FileMode.OpenOrCreate); |
---|
67 | |
---|
68 | // put the image into the memory stream |
---|
69 | thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg); |
---|
70 | |
---|
71 | imageStream.Close(); |
---|
72 | return ext; |
---|
73 | } |
---|
74 | |
---|
75 | /// <summary> |
---|
76 | /// Required, but not used |
---|
77 | /// </summary> |
---|
78 | /// <returns>true</returns> |
---|
79 | internal static bool ThumbnailCallback() |
---|
80 | { |
---|
81 | return true; |
---|
82 | } |
---|
83 | |
---|
84 | #endregion thumb |
---|
85 | } |
---|
86 | } |
---|