mirror of
https://github.com/abdelkader/vCardEditor
synced 2025-12-12 08:27:19 +07:00
draft of export image
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -216,3 +216,4 @@ FakesAssemblies/
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
/contacts
|
||||
/vCardEditor/assests/icons8-save-32.png
|
||||
|
||||
@@ -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<string> 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");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<EventArg<bool>> CloseForm;
|
||||
event EventHandler<EventArg<string>> ModifyImage;
|
||||
#endregion
|
||||
|
||||
event EventHandler ExportImage;
|
||||
int SelectedContactIndex { get; }
|
||||
void DisplayContacts(BindingList<Contact> 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);
|
||||
}
|
||||
}
|
||||
|
||||
20
vCardEditor/View/MainForm.Designer.cs
generated
20
vCardEditor/View/MainForm.Designer.cs
generated
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<EventArg<bool>> CloseForm;
|
||||
public event EventHandler<EventArg<string>> 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<string>(""));
|
||||
}
|
||||
|
||||
private void btnExportImage_Click(object sender, EventArgs e)
|
||||
{
|
||||
ExportImage?.Invoke(sender, e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,6 +252,19 @@
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>353, 17</value>
|
||||
</metadata>
|
||||
<data name="btnExportImage.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
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
|
||||
</value>
|
||||
</data>
|
||||
<data name="btnRemoveImage.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL
|
||||
|
||||
BIN
vCardEditor/assests/icons8-save-16.png
Normal file
BIN
vCardEditor/assests/icons8-save-16.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 475 B |
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user