diff --git a/.gitignore b/.gitignore index a496b2d..bfc5efd 100644 --- a/.gitignore +++ b/.gitignore @@ -216,3 +216,4 @@ FakesAssemblies/ **/*.Server/ModelManifest.xml _Pvt_Extensions /contacts +/vCardEditor/assests/icons8-save-32.png diff --git a/vCardEditor/Presenter/MainPresenter.cs b/vCardEditor/Presenter/MainPresenter.cs index 78e33d4..4af73cb 100644 --- a/vCardEditor/Presenter/MainPresenter.cs +++ b/vCardEditor/Presenter/MainPresenter.cs @@ -5,7 +5,8 @@ using vCardEditor.View; using VCFEditor.Repository; using vCardEditor.Repository; using vCardEditor.Model; - +using System.Linq; +using System.IO; namespace VCFEditor.Presenter { @@ -30,9 +31,28 @@ namespace VCFEditor.Presenter _view.BeforeLeavingContact += BeforeLeavingContact; _view.CloseForm += CloseForm; _view.ModifyImage += ModifyImage; + _view.ExportImage += ExportImage; } + private void ExportImage(object sender, EventArgs e) + { + string imageFile = _view.DisplaySaveDialog(_repository.fileName); + if (_view.SelectedContactIndex > 0) + { + //TODO: image can be url, or file location. + var card = _repository.Contacts[_view.SelectedContactIndex].card; + var image = card.Photos.FirstOrDefault(); + + if (image != null) + _repository.SaveImageToDisk(imageFile, image); + + } + + } + + + private void ModifyImage(object sender, EventArg e) { if (!string.IsNullOrEmpty(e.Data) ) @@ -106,7 +126,7 @@ namespace VCFEditor.Presenter if (!string.IsNullOrEmpty(path)) { - string ext = System.IO.Path.GetExtension(path); + string ext = _repository.GetExtension(path); if (ext != ".vcf") { _view.DisplayMessage("Only vcf extension accepted!", "Error"); diff --git a/vCardEditor/Repository/ContactRepository.cs b/vCardEditor/Repository/ContactRepository.cs index 2d5b7dc..6b4a67f 100644 --- a/vCardEditor/Repository/ContactRepository.cs +++ b/vCardEditor/Repository/ContactRepository.cs @@ -355,6 +355,19 @@ namespace VCFEditor.Repository } } + public string GetExtension(string path) + { + return _fileHandler.GetExtension(path); + } + + public void SaveImageToDisk(string imageFile, vCardPhoto image) + { + using (var ms = new MemoryStream(image.GetBytes())) + { + using (var fs = new FileStream(imageFile, FileMode.Create)) + ms.WriteTo(fs); + } + } /// diff --git a/vCardEditor/Repository/FileHandler.cs b/vCardEditor/Repository/FileHandler.cs index 5c84314..97196fc 100644 --- a/vCardEditor/Repository/FileHandler.cs +++ b/vCardEditor/Repository/FileHandler.cs @@ -1,8 +1,7 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; + namespace vCardEditor.Repository { @@ -13,6 +12,11 @@ namespace vCardEditor.Repository return File.Exists(filename); } + public string GetExtension(string path) + { + return Path.GetExtension(path); + } + public void MoveFile(string newFilename, string oldFilename) { File.Move(newFilename, oldFilename); diff --git a/vCardEditor/Repository/IContactRepository.cs b/vCardEditor/Repository/IContactRepository.cs index feef252..9fc5e84 100644 --- a/vCardEditor/Repository/IContactRepository.cs +++ b/vCardEditor/Repository/IContactRepository.cs @@ -21,5 +21,7 @@ namespace VCFEditor.Repository void SaveDirtyVCard(int index, vCard card); void AddEmptyContact(); void ModifyImage(int index, vCardPhoto photo); + string GetExtension(string path); + void SaveImageToDisk(string imageFile, vCardPhoto image); } } diff --git a/vCardEditor/Repository/IFileHandler.cs b/vCardEditor/Repository/IFileHandler.cs index 413eed2..0d048d3 100644 --- a/vCardEditor/Repository/IFileHandler.cs +++ b/vCardEditor/Repository/IFileHandler.cs @@ -11,5 +11,6 @@ namespace vCardEditor.Repository bool FileExist(string filename); string[] ReadAllLines(string filename); void WriteAllText(string fileName, string contents); + string GetExtension(string path); } } diff --git a/vCardEditor/View/IMainView.cs b/vCardEditor/View/IMainView.cs index 6324801..2a1606d 100644 --- a/vCardEditor/View/IMainView.cs +++ b/vCardEditor/View/IMainView.cs @@ -10,7 +10,7 @@ namespace VCFEditor.View { public interface IMainView { - #region All events + event EventHandler AddContact; event EventHandler DeleteContact; event EventHandler BeforeOpeningNewFile; @@ -22,8 +22,7 @@ namespace VCFEditor.View event EventHandler TextBoxValueChanged; event EventHandler> CloseForm; event EventHandler> ModifyImage; - #endregion - + event EventHandler ExportImage; int SelectedContactIndex { get; } void DisplayContacts(BindingList contacts); void DisplayContactDetail(vCard card, string FileName); @@ -31,6 +30,7 @@ namespace VCFEditor.View bool AskMessage(string msg, string caption); void DisplayMessage(string msg, string caption); string DisplayOpenDialog(string filter); + string DisplaySaveDialog(string filename); void UpdateMRUMenu(FixedList MRUList); } } diff --git a/vCardEditor/View/MainForm.Designer.cs b/vCardEditor/View/MainForm.Designer.cs index 8f458af..06c5564 100644 --- a/vCardEditor/View/MainForm.Designer.cs +++ b/vCardEditor/View/MainForm.Designer.cs @@ -30,7 +30,7 @@ { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.miSave = new System.Windows.Forms.ToolStripMenuItem(); @@ -55,6 +55,7 @@ this.CellularPhoneLabel = new System.Windows.Forms.Label(); this.WorkPhoneLabel = new System.Windows.Forms.Label(); this.gbContactDetail = new System.Windows.Forms.GroupBox(); + this.btnExportImage = new System.Windows.Forms.Button(); this.btnRemoveImage = new System.Windows.Forms.Button(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.tbcAddress = new System.Windows.Forms.TabControl(); @@ -352,6 +353,7 @@ this.gbContactDetail.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.gbContactDetail.Controls.Add(this.btnExportImage); this.gbContactDetail.Controls.Add(this.btnRemoveImage); this.gbContactDetail.Controls.Add(this.groupBox4); this.gbContactDetail.Controls.Add(this.groupBox3); @@ -368,6 +370,17 @@ this.gbContactDetail.TabStop = false; this.gbContactDetail.Text = "Contact Detail :"; // + // btnExportImage + // + this.btnExportImage.BackColor = System.Drawing.SystemColors.Window; + this.btnExportImage.Image = ((System.Drawing.Image)(resources.GetObject("btnExportImage.Image"))); + this.btnExportImage.Location = new System.Drawing.Point(744, 170); + this.btnExportImage.Name = "btnExportImage"; + this.btnExportImage.Size = new System.Drawing.Size(21, 23); + this.btnExportImage.TabIndex = 54; + this.btnExportImage.UseVisualStyleBackColor = true; + this.btnExportImage.Click += new System.EventHandler(this.btnExportImage_Click); + // // btnRemoveImage // this.btnRemoveImage.BackColor = System.Drawing.SystemColors.Window; @@ -1199,8 +1212,8 @@ this.dgContacts.AllowUserToAddRows = false; this.dgContacts.AllowUserToDeleteRows = false; this.dgContacts.AllowUserToResizeRows = false; - dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); - this.dgContacts.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle2; + dataGridViewCellStyle3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); + this.dgContacts.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle3; this.dgContacts.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.dgContacts.AutoGenerateColumns = false; @@ -1384,5 +1397,6 @@ private System.Windows.Forms.ToolStripButton tbsNew; private System.Windows.Forms.ToolStripSeparator toolStripSeparator; private System.Windows.Forms.Button btnRemoveImage; + private System.Windows.Forms.Button btnExportImage; } } \ No newline at end of file diff --git a/vCardEditor/View/MainForm.cs b/vCardEditor/View/MainForm.cs index d005bc4..fa2470e 100644 --- a/vCardEditor/View/MainForm.cs +++ b/vCardEditor/View/MainForm.cs @@ -13,7 +13,6 @@ namespace vCardEditor.View { public partial class MainForm : Form, IMainView { - #region event list public event EventHandler AddContact; public event EventHandler SaveContactsSelected; public event EventHandler BeforeOpeningNewFile; @@ -25,7 +24,8 @@ namespace vCardEditor.View public event EventHandler TextBoxValueChanged; public event EventHandler> CloseForm; public event EventHandler> ModifyImage; - #endregion + public event EventHandler ExportImage; + ComponentResourceManager resources; public int SelectedContactIndex @@ -183,8 +183,7 @@ namespace vCardEditor.View var photo = photos[0]; try { - // Get the bytes of the photo if it has - // not already been loaded. + // Get the bytes of the photo if it has not already been loaded. if (!photo.IsLoaded) photo.Fetch(); @@ -436,6 +435,19 @@ namespace vCardEditor.View return filename; } + + public string DisplaySaveDialog(string filename) + { + + var saveFileDialog = new SaveFileDialog(); + saveFileDialog.FileName = filename; + + DialogResult result = saveFileDialog.ShowDialog(); + if (result == DialogResult.OK) + filename = saveFileDialog.FileName; + + return filename; + } private void PhotoBox_Click(object sender, EventArgs e) { if (ModifyImage != null) @@ -466,5 +478,12 @@ namespace vCardEditor.View //Remove image from vcf ModifyImage(sender, new EventArg("")); } + + private void btnExportImage_Click(object sender, EventArgs e) + { + ExportImage?.Invoke(sender, e); + } + + } } diff --git a/vCardEditor/View/MainForm.resx b/vCardEditor/View/MainForm.resx index 4a62eb8..400f1af 100644 --- a/vCardEditor/View/MainForm.resx +++ b/vCardEditor/View/MainForm.resx @@ -252,6 +252,19 @@ 353, 17 + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL + EwAACxMBAJqcGAAAAZFJREFUOE/NkMtKAlEAhn2Ctq26qmPavTdp3b4Iih6gnqMyoqCw0hIru5hJmFlI + FBE0pNXo2IzO1YNZGK3+xtOIC81t/fBvDnzf+c+x/J+MREi690BHx5qA4ts7bYEUIas6VmMsEiyHpctn + OHeVqO1IbzGxWoZPCVzBH4GmE6hGK7CYV9A654c7cofFiyf07KpgAnLUxGoZChM49zUqyEkKrZCTwb/m + qGAhfIv5WBKOgALGr8DEahk8KcBVEayLuHwUkM6K4DICnjiewmc3D5gNPVKY2ZHrBQOhAvqPdDrR4c+D + 8YmwV+oVYNsSYDXK+IxzA7ZvNxD0H+voOzR6oKE3qNE1zj31R2jOrsI2n1QvqMJj8SJmrouYThBMXRUw + GVcxca5gPCpjNCRR2OptJDBv/vj8QrlcRqlUAiEEmqZBkiSIooiXDE/h7q18vaA6+zeY53lwHEfhro0G + guqbm8GpVIrCnZ5cvaDy28xmtinMsizaVjJoX+YaCDx81u5J4174HQ7fsBRucyezJvbnsVi+AVtEwzA2 + nUJSAAAAAElFTkSuQmCC + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL diff --git a/vCardEditor/assests/icons8-save-16.png b/vCardEditor/assests/icons8-save-16.png new file mode 100644 index 0000000..39661f5 Binary files /dev/null and b/vCardEditor/assests/icons8-save-16.png differ diff --git a/vCardEditor_Test/Entries.cs b/vCardEditor_Test/Entries.cs index b532f15..f2030ef 100644 --- a/vCardEditor_Test/Entries.cs +++ b/vCardEditor_Test/Entries.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace vCardEditor_Test +namespace vCardEditor_Test { public class Entries {