/// <summary> /// sets the data from the dataStruct into the dataList vector, returns false if id is too big /// </summary> /// <param name="dataStruct">Structure containing data to set</param> /// <param name="id">Image id to set data of</param> /// <returns>True/False whether image is valid and data was set</returns> public bool setData(pictureData dataStruct, int id) { if (id >= dataList.Count) { return(false); } else { dataList[id] = dataStruct; return(true); } }
/// <summary> /// Function is called when importing a picture, where path is the picture's path /// Copies the pic to a new photos folder /// Compares pictires if a duplicate name exists /// adds the image to the datalist /// sets a default description to nothing /// Zach & Cavan /// </summary> /// <param name="path">Path to picture to import</param> /// <param name="allImages">List of all current images</param> public void addPhoto(string path, ref List <Utilities.AllImagesInfo> allImages) { int totalImages = allImages.Count; string newPath; bool alreadyExists = false; string dateAdded = Utilities.getTimeStamp(); string imageName = Utilities.getNameFromPath(path); string calculateMD5 = Utilities.CalculateMD5(path); Utilities.AllImagesInfo newImage; pictureData image = new pictureData(); newPath = directory + photoFolder + "\\" + imageName + Path.GetExtension(path); //Checks to see if a pic with the same name exists, checks if it exists then compare the pics try { for (int i = 0; i < totalImages; i++) { if (allImages[i].MD5 == calculateMD5) { alreadyExists = true; newPath = allImages[i].path; break; } } if (!alreadyExists) //if the md5 was not found { if (File.Exists(newPath)) //check to see if a file w/ the same name exists { newPath = Utilities.getAppendName(newPath); //append a number to the end of it } new Thread(() => copyImage(path, newPath)).Start(); //copy that image over to our photos directory in a new thread } newImage.path = newPath; newImage.MD5 = calculateMD5; image.description = ""; image.dateAdded = dateAdded; image.dateModified = dateAdded; image.MD5 = calculateMD5; image.path = newPath; image.name = imageName; image.id = Utilities.getIdFromInt(dataList.Count); allImages.Add(newImage); dataList.Add(image); } catch { } }
/// <summary> /// Loads the album information from a .abm(XML format) file and adds information to a query /// then, the datalist vector will get each pictures information /// Zach /// </summary> /// <param name="albumName">Name of album to open</param> /// <returns>Whether album was successfuly opened</returns> public bool loadAlbum(string albumName) { pictureData PicData = new pictureData(); //if fails to get or read file //return false; XDocument xdoc = new XDocument(); try { xdoc = XDocument.Load(albumName); }catch { return(false); } //Run query, only header item is the album name. children contains all pciture information var Albums = from AlbumInfo in xdoc.Descendants("AlbumInfo") select new { Header = AlbumInfo.Attribute("name").Value, Children = AlbumInfo.Descendants("PictureInfo") }; //Loop through results and add the info to the datalist for each picture foreach (var albumInfo in Albums) { foreach (var PictureInfo in albumInfo.Children) { PicData.id = PictureInfo.Attribute("id").Value; PicData.path = PictureInfo.Attribute("path").Value; PicData.name = PictureInfo.Attribute("name").Value; PicData.description = PictureInfo.Attribute("description").Value; PicData.MD5 = PictureInfo.Attribute("md5").Value; PicData.dateAdded = PictureInfo.Attribute("dateAdded").Value; PicData.dateModified = PictureInfo.Attribute("dateModified").Value; PicData.albumPath = albumName; dataList.Add(PicData); } } //read and load xml data into dataList _filePath = albumName; _currentAlbumName = albumName; return(true); }
/// <summary> /// Function is used to get picture info from and element in the datalist /// The id of the picture is sent and the info for that pic is returned /// </summary> /// <param name="id">ID of picture to retrieve data of</param> /// <returns>Data retrieved</returns> public pictureData getData(int id) { pictureData tempData = new pictureData(); tempData.name = ""; tempData.id = "0"; tempData.path = ""; tempData.description = ""; //if invalid id is received if (id >= dataList.Count) { return(tempData); } else { tempData = dataList[id]; return(tempData); } }
//Sets current photo. Passed pictureData structure public void setData(pictureData data) { photoData = data; }
/// <summary> /// sets the data from the dataStruct into the dataList vector, returns false if id is too big /// </summary> /// <param name="dataStruct">Structure containing data to set</param> /// <param name="id">Image id to set data of</param> /// <returns>True/False whether image is valid and data was set</returns> public bool setData(pictureData dataStruct, int id) { if (id >= dataList.Count) return false; else { dataList[id] = dataStruct; return true; } }
/// <summary> /// Function is called when importing a picture, where path is the picture's path /// Copies the pic to a new photos folder /// Compares pictires if a duplicate name exists /// adds the image to the datalist /// sets a default description to nothing /// Zach & Cavan /// </summary> /// <param name="path">Path to picture to import</param> /// <param name="allImages">List of all current images</param> public void addPhoto(string path, ref List<Utilities.AllImagesInfo> allImages) { int totalImages = allImages.Count; string newPath; bool alreadyExists = false; string dateAdded = Utilities.getTimeStamp(); string imageName = Utilities.getNameFromPath(path); string calculateMD5 = Utilities.CalculateMD5(path); Utilities.AllImagesInfo newImage; pictureData image = new pictureData(); newPath = directory + photoFolder + "\\" + imageName + Path.GetExtension(path); //Checks to see if a pic with the same name exists, checks if it exists then compare the pics try { for (int i = 0; i < totalImages; i++) { if (allImages[i].MD5 == calculateMD5) { alreadyExists = true; newPath = allImages[i].path; break; } } if (!alreadyExists) //if the md5 was not found { if (File.Exists(newPath)) //check to see if a file w/ the same name exists { newPath = Utilities.getAppendName(newPath); //append a number to the end of it } new Thread(() => copyImage(path, newPath)).Start(); //copy that image over to our photos directory in a new thread } newImage.path = newPath; newImage.MD5 = calculateMD5; image.description = ""; image.dateAdded = dateAdded; image.dateModified = dateAdded; image.MD5 = calculateMD5; image.path = newPath; image.name = imageName; image.id = Utilities.getIdFromInt(dataList.Count); allImages.Add(newImage); dataList.Add(image); } catch { } }
/// <summary> /// Function is used to get picture info from and element in the datalist /// The id of the picture is sent and the info for that pic is returned /// </summary> /// <param name="id">ID of picture to retrieve data of</param> /// <returns>Data retrieved</returns> public pictureData getData(int id) { pictureData tempData = new pictureData(); tempData.name = ""; tempData.id = "0"; tempData.path = ""; tempData.description = ""; //if invalid id is received if (id >= dataList.Count) return tempData; else { tempData = dataList[id]; return tempData; } }
/// <summary> /// Loads the album information from a .abm(XML format) file and adds information to a query /// then, the datalist vector will get each pictures information /// Zach /// </summary> /// <param name="albumName">Name of album to open</param> /// <returns>Whether album was successfuly opened</returns> public bool loadAlbum(string albumName) { pictureData PicData = new pictureData(); //if fails to get or read file //return false; XDocument xdoc = new XDocument(); try { xdoc = XDocument.Load(albumName); }catch { return false; } //Run query, only header item is the album name. children contains all pciture information var Albums = from AlbumInfo in xdoc.Descendants("AlbumInfo") select new { Header = AlbumInfo.Attribute("name").Value, Children = AlbumInfo.Descendants("PictureInfo") }; //Loop through results and add the info to the datalist for each picture foreach (var albumInfo in Albums) { foreach (var PictureInfo in albumInfo.Children) { PicData.id = PictureInfo.Attribute("id").Value; PicData.path = PictureInfo.Attribute("path").Value; PicData.name = PictureInfo.Attribute("name").Value; PicData.description = PictureInfo.Attribute("description").Value; PicData.MD5 = PictureInfo.Attribute("md5").Value; PicData.dateAdded = PictureInfo.Attribute("dateAdded").Value; PicData.dateModified = PictureInfo.Attribute("dateModified").Value; PicData.albumPath = albumName; dataList.Add(PicData); } } //read and load xml data into dataList _filePath = albumName; _currentAlbumName = albumName; return true; }
/// <summary> /// Ceate New Panel thumbnail /// Parameters: accepts picturedata struct /// Creates a new panel, sets its picture data, and sets background image to scaled down image from file /// Returns thumbnial panel /// </summary> /// <param name="imageData">Picture data to use for thumbnail</param> /// <param name="id">ID of picture to find</param> /// <returns>New thumbnail panel to be inserted</returns> private Panel getNewThumbnail(ref pictureData imageData, int id) { Panel newPanel = new Panel(); newPanel.Visible = false; newPanel.Name = "panel" + imageData.id; newPanel.Size = frameSize; newPanel.BackgroundImageLayout = ImageLayout.Zoom; //Attempts to load background Image. If fail, loads a default image and updates description try { Image tempImage = Image.FromFile(imageData.path); //imageData.size = tempImage.Size; //_albumData.setData(imageData, id); imageData.size.Height = tempImage.Height; imageData.size.Width = tempImage.Width; newPanel.BackgroundImage = Utilities.ScalImage(tempImage, new Size(frameSize.Width, frameSize.Height)); //imageData.size = newPanel.BackgroundImage.Size; tempImage.Dispose(); } catch { newPanel.BackgroundImage = Resources.Resource1.warning; //imageData.size = new Size(0, 0); if (!imageData.description.Contains("File not found")) { imageData.description = "File not found\n\n" + imageData.description; } //_albumData.setData(imageData, id); } //Panel event handlers newPanel.MouseClick += new System.Windows.Forms.MouseEventHandler(this.panel_MouseClick); newPanel.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.panel_MouseDoubleClick); return newPanel; }
/// <summary> /// Thumbnail click event /// Shows border panel around clicked panel. Sets current photo. enables and populates picture info panel /// Focusses thumbnail panel for delete button catching /// Calls selectNode method /// If right clicked also shows the context menu /// Cavan & Zach /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void panel_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right) { _panel_CurrentPanel.BackColor = color_backColor; Panel p = sender as Panel; string id = p.Name.Substring(p.Name.Length - 3, 3); //get id //currentId = Convert.ToInt32(id); //Set border panel panel_Border.Location = new Point((p.Location.X - (_frameWidth / 20 + 2)), (p.Location.Y - (_frameWidth / 20)) - 3); panel_Border.Show(); p.BringToFront(); _pictureDataStored = _albumData.getData(Convert.ToInt32(id)); //get album data _currentPhoto.setData(_pictureDataStored); //Sets current photo properties //Set picture info panel textBox_Name.Text = _pictureDataStored.name; //picViewPath = pictureDataStored.path; richTextBox_Description.Text = _pictureDataStored.description; label_picSize.Text = _pictureDataStored.size.Width + " x " + _pictureDataStored.size.Height + " pixels"; p.BackColor = panel_Border.BackColor; //reset last thubmnail backcolor _panel_CurrentPanel = p; p.Focus(); //so delete key works panel_PictureData.Enabled = true; removeToolStripMenuItem.Enabled = true; selectTreeNode(Convert.ToInt32(id)); //update list view label_NameError.Visible = false; } //Show context menu if (e.Button == MouseButtons.Right) { //fileNameToolStripMenuItem.Text = currentPhoto.name; fileNameToolStripMenuItem.Visible = false; toolStripSeparator_Picture.Visible = false; contextMenuStrip_Picture.Show(Cursor.Position.X, Cursor.Position.Y); } }
/// <summary> /// Picture list tree node click /// Updates picture data panel with picture info. Sets current panel and find corresponding panel /// Sets border and thubmnails for thumbnail view /// calls select node method /// Cavan & Zach /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void treeView_Pictures_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right) { //Get data int id = e.Node.Index; if (_filterList == null) { _pictureDataStored = _albumData.getData(Convert.ToInt32(id)); } else { _pictureDataStored = _filterList[Convert.ToInt32(id)]; } _currentPhoto.setData(_pictureDataStored); //Set data panel textBox_Name.Text = _pictureDataStored.name; richTextBox_Description.Text = _pictureDataStored.description; label_picSize.Text = _pictureDataStored.size.Width + ", " + _pictureDataStored.size.Height; panel_PictureData.Enabled = true; removeToolStripMenuItem.Enabled = true; label_NameError.Visible = false; _panel_CurrentPanel.BackColor = panel1.BackColor; //Finds panel based on id and sets border and current panel so both views match foreach (Panel value in panel1.Controls) { if (value.Name == ("panel" + Utilities.getIdFromInt(id))) { _panel_CurrentPanel = value; _panel_CurrentPanel.Name = "panel" + Utilities.getIdFromInt(id); panel_Border.Location = new Point((value.Location.X - (_frameWidth / 20 + 2)), (value.Location.Y - (_frameWidth / 20)) - 3); panel_Border.SendToBack(); panel_Border.Show(); _panel_CurrentPanel.BackColor = panel_Border.BackColor; //break; } } selectTreeNode(Convert.ToInt32(id)); } //Show context menu if (e.Button == MouseButtons.Right) { fileNameToolStripMenuItem.Text = _currentPhoto.name; fileNameToolStripMenuItem.Visible = true; toolStripSeparator_Picture.Visible = true; treeView_Pictures.SelectedNode = e.Node; contextMenuStrip_Picture.Show(Cursor.Position.X, Cursor.Position.Y); } }
/// <summary> /// Displays the thumbnails in the current picture list /// Brandon /// </summary> /// <param name="picList">List of thumnails to display</param> private void showThumbnail(List<pictureData> picList) { pictureData picData = new pictureData(); int loopCount = picList.Count; Panel tempPanel; try{ disablePanel(loopCount); for (int i = 0; i < loopCount; i++) { //If panel is already added, skip it (mainly for when inporting pictures) //if (panel1.Controls.Find("panel" + Utilities.getIdFromInt(i), false).Count() > 0) //{ // continue; //} picData = picList[i]; tempPanel = getNewThumbnail(ref picData, i); //Create new panel picList[i] = picData; //reset the picList[i] with the picData changed in the thumbnail - we update the photo dimensions tempPanel.Location = getFrameLocation(i); //Sets panel position from frame variables this.Invoke(new MethodInvoker(delegate() { tempPanel.Show(); //Still shares reference with panel1.Controls element, so this change affects that one panel1.Controls.Add(tempPanel); //Add panel to main panel //label4.Text = "Processing Images " + i.ToString() + "/" + loopCount.ToString(); progressImageProcess.Increment(1); })); } enablePanel(); } catch { handleError("Unable to show thumbnails."); } }
/// <summary> /// Rename Picture method /// Checks for invalid names and updates picture data. Notifyes user of success or failure /// Cavan /// </summary> private void renamePicture() { //Check for invalid characters or blank name. If invalid, show error message if (textBox_Name.Text.Trim() != "" && Utilities.isStringValid(textBox_Name.Text)) { //Valid name, update picture data _currentPhoto.name = textBox_Name.Text; string id = _panel_CurrentPanel.Name.Substring(_panel_CurrentPanel.Name.Length - 3, 3); //get id _pictureDataStored = _albumData.getData(Convert.ToInt32(id)); textBox_Name.Text = textBox_Name.Text.Trim(); //trim spaces _pictureDataStored.name = textBox_Name.Text; _albumData.setData(_pictureDataStored, Convert.ToInt32(id)); //Notify user of success label_NameError.ForeColor = Color.Green; label_NameError.Text = "Update successful"; label_NameError.Visible = true; populateList(); } else { label_NameError.Text = "Invalid Name"; label_NameError.ForeColor = Color.DarkRed; label_NameError.Visible = true; } }
/// <summary> /// If images are modified, make sure they are saved and that main form /// will be updated appropriately /// </summary> private void saveModifiedImage() { bool gifContinue = true; string imageID; string imagePath; string newPath; string newMD5; string newModified; modifiedImageInfo holder; List <Utilities.AllImagesInfo> allImages; try { if (_isModifiedCurrent && MessageBox.Show("Would you like to save the changes you have made?", "Confirm Save", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (System.IO.Path.GetExtension(_pictureList[_currentImage].path) == ".gif" && MessageBox.Show("You appear to be rotating a .GIF image. If there is animation in your GIF file, the animation will not be saved after being rotate. Are you sure you want to continue?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No) { gifContinue = false; } if (gifContinue) { allImages = Utilities.getAllImageInfo(); imagePath = _pictureList[_currentImage].path; imageID = _pictureList[_currentImage].id; if (allImages.FindAll(s => s.path == imagePath).Count > 1) //if photo exists multiple times { newPath = Utilities.getAppendName(imagePath); } else { newPath = imagePath; } _imageViewer.Save(newPath); try { XDocument xdoc = new XDocument(); xdoc = XDocument.Load(_pictureList[_currentImage].albumPath); var Albums = from AlbumInfo in xdoc.Elements("Album").Elements("AlbumInfo").Elements("PictureInfo") select AlbumInfo; foreach (XElement picture in Albums) { if (picture.Attribute("id").Value == imageID) { newMD5 = Utilities.CalculateMD5(newPath); newModified = Utilities.getTimeStamp(); picture.Attribute("path").Value = newPath; picture.Attribute("md5").Value = newMD5; picture.Attribute("dateModified").Value = newModified; pictureData temp = _pictureList[_currentImage]; temp.path = newPath; temp.MD5 = newMD5; temp.dateModified = newModified; _pictureList[_currentImage] = temp; } } xdoc.Save(_pictureList[_currentImage].albumPath); } catch { MessageBox.Show("you gone done sumthin wrong"); } _isModifiedCurrent = false; _isModified = true; _totalFlips = 0; holder.path = newPath; holder.id = "panel" + imageID; _modifiedImages.Add(holder); } else { _isModifiedCurrent = false; } } else { _isModifiedCurrent = false; } } catch (Exception e) { MessageBox.Show("Sorry but an error has occurred while saving your image.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Console.WriteLine("Error: " + e.Message); this.Close(); } }