Catalog/WPFCatalog/MainWindowViewModel.cs

813 lines
23 KiB
C#
Raw Normal View History

2016-07-04 16:45:45 +02:00
using System;
using System.Collections.Generic;
2016-11-07 16:20:31 +01:00
using System.Diagnostics;
using System.IO;
2016-07-04 16:45:45 +02:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CatalogLib;
2016-11-07 16:20:31 +01:00
using GalaSoft.MvvmLight.Command;
2017-09-20 15:01:22 +02:00
using MaddoLibrary.Base.Log;
2016-11-07 16:20:31 +01:00
using MaddoLibrary.Helpers;
2017-03-17 16:23:29 +01:00
using WPFCatalog.Messages;
2016-07-04 16:45:45 +02:00
namespace WPFCatalog
{
public class MainWindowViewModel : ViewModelBase
{
2016-11-07 16:20:31 +01:00
public PicSettings PicSettings
{
get { return PicSettings.Instance; }
}
2016-07-04 16:45:45 +02:00
public MainWindowViewModel()
{
2016-11-07 16:20:31 +01:00
//PicSettings = new PicSettings();
RegisterCommands();
}
// todo: comandi e serializzazione
#region commands
public RelayCommand ExportSettingsCommand { get; private set; }
2016-11-07 20:58:16 +01:00
public RelayCommand ImportSettingsCommand { get; private set; }
2016-11-07 16:20:31 +01:00
public RelayCommand SelectSourceFolderCommand { get; private set; }
public RelayCommand SelectDestinationFolderCommand { get; private set; }
public RelayCommand OpenSourceFolderCommand { get; private set; }
public RelayCommand OpenDestinationFolderCommand { get; private set; }
2016-11-07 20:58:16 +01:00
public RelayCommand StartCommand { get; private set; }
2017-03-17 16:23:29 +01:00
public RelayCommand PickFontCommand { get; private set; }
2016-11-07 20:58:16 +01:00
2016-11-07 16:20:31 +01:00
private void RegisterCommands()
{
ExportSettingsCommand = new RelayCommand(ExportSettings);
2016-11-07 20:58:16 +01:00
ImportSettingsCommand = new RelayCommand(ImportSettings);
2016-11-07 16:20:31 +01:00
SelectSourceFolderCommand = new RelayCommand(SelectSourceFolder);
OpenSourceFolderCommand = new RelayCommand(OpenSourceFolder);
SelectDestinationFolderCommand = new RelayCommand(SelectDestinationFolder);
OpenDestinationFolderCommand = new RelayCommand(OpenDestinationFolder);
2016-11-07 20:58:16 +01:00
StartCommand = new RelayCommand(Start);
2017-03-17 16:23:29 +01:00
PickFontCommand = new RelayCommand(PickFont);
}
private void PickFont()
{
//FontData d = null;
MessengerInstance.Send<OpenFontWindowMessage>(new OpenFontWindowMessage((ayy) =>
{
this.FontName = ayy.Name;
this.FontSize = ayy.Size;
//d = ayy;
}));
//if (d != null)
//{
// FontName = d.Name;
//}
//string s = d.Name;
2016-11-07 20:58:16 +01:00
}
2016-11-07 16:20:31 +01:00
2017-09-20 15:01:22 +02:00
private struct ImageTask
2016-11-07 20:58:16 +01:00
{
2017-09-20 15:01:22 +02:00
public Task TaskImage;
public string ImageName;
public bool Completed;
}
2017-03-17 16:23:29 +01:00
2017-09-20 15:01:22 +02:00
//private List<ImageTask> _tasks;
private async void Start()
{
Task outerTask = new Task(() =>
2016-11-07 20:58:16 +01:00
{
2017-09-20 15:01:22 +02:00
var tasks = new List<Task>();
// todo folder mode
MaddoLogger.Log("Starting elaboration");
foreach (var file in Directory.EnumerateFiles(PicSettings.DirectorySorgente))
{
//Task t = new Task(() =>
//{
// //CompleteFile(file);
//});
tasks.Add(FileTask(file));
//_tasks.Add(new ImageTask() { ImageName = file, TaskImage = t, Completed = false });
//t.Start();
}
Task.WhenAll(tasks).Start();
//tt.RunSynchronously();
MaddoLogger.Log("Finished");
DialogHelper.PopUpAlert("Finished", "message");
});
outerTask.Start();
}
private Task FileTask(string file)
{
MaddoLogger.Log("Starting task for image {0}", file);
IImageProcessor i = new ImgSharpCreator();
//ImageCreator2 i = new ImageCreator2();
i.Start(new FileInfo(file));
return null;
}
private void CompleteFile(string file)
{
2017-03-17 16:23:29 +01:00
2016-11-07 16:20:31 +01:00
}
private void OpenSourceFolder()
{
if (Directory.Exists(DirSorgente))
{
Process.Start("explorer.exe", DirSorgente);
}
}
2016-07-04 16:45:45 +02:00
2016-11-07 16:20:31 +01:00
private void OpenDestinationFolder()
{
if (Directory.Exists(DirDestinazione))
{
Process.Start("explorer.exe", DirDestinazione);
}
2016-07-04 16:45:45 +02:00
}
2016-11-07 16:20:31 +01:00
private void SelectSourceFolder()
{
var a = FileHelper.GetOpenFolderPath();
if (!string.IsNullOrWhiteSpace(a))
{
this.DirSorgente = a;
2016-11-07 20:58:16 +01:00
2016-11-07 16:20:31 +01:00
}
}
private void SelectDestinationFolder()
{
var a = FileHelper.GetOpenFolderPath();
if (!string.IsNullOrWhiteSpace(a))
{
this.DirDestinazione = a;
}
}
private void ExportSettings()
{
string s = PicSettings.SerializeSettings();
DialogHelper.PopUpAlert(s, "data");
2016-11-07 20:58:16 +01:00
var savePath = FileHelper.GetSavePath("", "settings.json", string.Empty);
if (string.IsNullOrWhiteSpace(savePath)) return;
if (Directory.Exists(Path.GetDirectoryName(savePath)))
{
Debug.WriteLine(savePath);
FileHelper.WriteToFile(savePath, s, false);
2016-11-07 20:58:16 +01:00
Debug.WriteLine(s);
}
}
private void ImportSettings()
{
var loadPath = FileHelper.GetOpenPath();
if (string.IsNullOrWhiteSpace(loadPath)) return;
if (File.Exists(loadPath))
{
var f = FileHelper.ReadTextFile(loadPath);
PicSettings.DeserializeSettings(f);
RaisePropertyChanged(string.Empty);
}
2016-11-07 16:20:31 +01:00
}
#endregion
2016-07-04 16:45:45 +02:00
#region Proprietà
public PicSettings SettingsString
{
get { return PicSettings; }
}
public string DirSorgente
{
2016-11-07 16:20:31 +01:00
get { return PicSettings.GetString("DirSorgente"); }
set { PicSettings.Set("DirSorgente", value); RaisePropertyChanged("DirSorgente"); }
2016-07-04 16:45:45 +02:00
}
public string DirDestinazione
{
2016-11-07 16:20:31 +01:00
get { return PicSettings.DirectoryDestinazione; }
2016-07-04 16:45:45 +02:00
set
{
2016-11-07 16:20:31 +01:00
PicSettings.Set("DirDestinazione", value);
2016-07-04 16:45:45 +02:00
RaisePropertyChanged("DirDestinazione");
}
}
2016-11-07 16:20:31 +01:00
public bool DirAggiornaSottoDirectory
2016-07-04 16:45:45 +02:00
{
2016-11-07 16:20:31 +01:00
get { return PicSettings.DirAggiornaSottoDirectory; }
2016-07-04 16:45:45 +02:00
set
{
2016-11-07 16:20:31 +01:00
PicSettings.DirAggiornaSottoDirectory = value;
RaisePropertyChanged("DirAggiornaSottoDirectory");
2016-07-04 16:45:45 +02:00
}
}
public bool SubdirCreaSottoCartelle
{
2016-11-07 20:58:16 +01:00
get { return PicSettings.SubdirCreaSottoCartelle; }
set { PicSettings.SubdirCreaSottoCartelle = value; RaisePropertyChanged("SubdirCreaSottoCartelle"); }
}
public int SubdirIntervalloFile
{
get { return PicSettings.SubdirIntervalloFile; }
set { PicSettings.SubdirIntervalloFile = value; RaisePropertyChanged("SubdirIntervalloFile"); }
}
public string SubdirSuffisso
{
get { return PicSettings.SubdirSuffisso; }
set { PicSettings.SubdirSuffisso = value; RaisePropertyChanged("SubdirSuffisso"); }
}
public int SubdirCifreContatore
{
get { return PicSettings.SubdirCifreContatore; }
set { PicSettings.SubdirCifreContatore = value; RaisePropertyChanged("SubdirCifreContatore"); }
}
public bool SubdirNumerazioneProgressiva
{
get { return PicSettings.SubdirNumerazioneProgressiva; }
set { PicSettings.SubdirNumerazioneProgressiva = value; RaisePropertyChanged("SubdirNumerazioneProgressiva"); }
}
public bool SubdirNumerazioneFiles
{
get { return PicSettings.SubdirNumerazioneFiles; }
set { PicSettings.SubdirNumerazioneFiles = value; RaisePropertyChanged("SubdirNumerazioneFiles"); }
2016-07-04 16:45:45 +02:00
}
public string DirDividiNumFile { get { return PicSettings.GetString("dirDividiNumFile"); } set { PicSettings.Set("dirDividiNumFile", value); } }
public string DirDividiSuffisso { get { return PicSettings.GetString("dirDividiSuffisso"); } set { PicSettings.Set("dirDividiSuffisso", value); } }
2016-11-07 16:20:31 +01:00
public string DirDividiNumCifre { get { return PicSettings.GetString("dirDividiNumCifre"); } set { PicSettings.Set("dirDividiNumCifre", value); RaisePropertyChanged("DirDividiNumCifre"); } }
2016-07-04 16:45:45 +02:00
public bool DirDividiDestinazione { get { return PicSettings.GetBool("dirDividiDestinazione"); } set { PicSettings.Set("dirDividiDestinazione", value); } }
public bool DirDividiTipoNumerazioneProg { get { return PicSettings.GetString("DirDividiTipoNumerazione").ToUpper() == "PROGRESSIVA"; } set { if (value == true) PicSettings.Set("DirDividiTipoNumerazione", "PROGRESSIVA"); } }
public bool DirDividiTipoNumerazioneFile { get { return PicSettings.GetString("DirDividiTipoNumerazione").ToUpper() == "FILES"; } set { if (value == false) PicSettings.Set("DirDividiTipoNumerazione", "FILES"); } }
2016-11-07 16:20:31 +01:00
public bool MiniatureCrea { get { return PicSettings.GetBool("miniatureCrea"); } set { PicSettings.Set("miniatureCrea", value); RaisePropertyChanged("MiniatureCrea"); } }
2016-11-07 20:58:16 +01:00
2016-07-04 16:45:45 +02:00
public string MiniatureSuffisso
{
get { return PicSettings.GetString("miniatureSuffisso"); }
set
{
PicSettings.Set("miniatureSuffisso", value);
RaisePropertyChanged("MiniatureSuffisso");
}
}
public string MiniatureAltezza
{
get { return PicSettings.GetString("miniatureAltezza"); }
set
{
PicSettings.Set("miniatureAltezza", value);
RaisePropertyChanged("MiniatureAltezza");
}
}
public string MiniatureLarghezza
{
get { return PicSettings.GetString("miniatureLarghezza"); }
set
{
PicSettings.Set("miniatureLarghezza", value);
RaisePropertyChanged("MiniatureLarghezza");
}
}
public bool MiniatureAddScritta
{
get { return PicSettings.GetBool("miniatureAddScritta"); }
set
{
PicSettings.Set("miniatureAddScritta", value);
RaisePropertyChanged("MiniatureAddScritta");
}
}
public bool MiniatureAddOrario
{
get { return PicSettings.GetBool("miniatureAddOrario"); }
set
{
PicSettings.Set("miniatureAddOrario", value);
RaisePropertyChanged("MiniatureAddOrario");
}
}
2016-11-07 20:58:16 +01:00
public int FotoAltezza
2016-07-04 16:45:45 +02:00
{
2016-11-07 20:58:16 +01:00
get
{
return PicSettings.FotoAltezza;
}
2016-07-04 16:45:45 +02:00
set
{
2016-11-07 20:58:16 +01:00
PicSettings.FotoAltezza = value;
2016-07-04 16:45:45 +02:00
RaisePropertyChanged("FotoAltezza");
}
}
2016-11-07 20:58:16 +01:00
public int FotoLarghezza
2016-07-04 16:45:45 +02:00
{
2016-11-07 20:58:16 +01:00
get { return PicSettings.FotoLarghezza; }
2016-07-04 16:45:45 +02:00
set
{
2016-11-07 20:58:16 +01:00
PicSettings.FotoLarghezza = value;
2016-07-04 16:45:45 +02:00
RaisePropertyChanged("FotoLarghezza");
}
}
public string FontDimensione
{
get { return PicSettings.GetString("fontDimensione"); }
set
{
PicSettings.Set("fontDimensione", value);
RaisePropertyChanged("FontDimensione");
}
}
public string FontDimensioneMiniatura
{
get { return PicSettings.GetString("fontDimensioneMiniatura"); }
set
{
PicSettings.Set("fontDimensioneMiniatura", value);
RaisePropertyChanged("FontDimensioneMiniatura");
}
}
public bool FontBold
{
get { return PicSettings.GetBool("fontBold"); }
set
{
PicSettings.Set("fontBold", value);
RaisePropertyChanged("FontBold");
}
}
public bool FontNome
{
get { return PicSettings.GetBool("fontNome"); }
set
{
PicSettings.Set("$parName", value);
RaisePropertyChanged("FontNome");
}
}
public string TestoTesto
{
get { return PicSettings.GetString("testoTesto"); }
set
{
PicSettings.Set("testoTesto", value);
RaisePropertyChanged("TestoTesto");
}
}
public string TestoTrasparente
{
get { return PicSettings.GetString("testoTrasparente"); }
set
{
PicSettings.Set("testoTrasparente", value);
RaisePropertyChanged("TestoTrasparente");
}
}
public string TestoMargine
{
get { return PicSettings.GetString("testoMargine"); }
set
{
PicSettings.Set("testoMargine", value);
RaisePropertyChanged("TestoMargine");
}
}
public string TestoPosizione
{
get { return PicSettings.GetString("testoPosizione"); }
set
{
PicSettings.Set("testoPosizione", value);
RaisePropertyChanged("TestoPosizione");
}
}
public string TestoAllineamento
{
get { return PicSettings.GetString("testoAllineamento"); }
set
{
PicSettings.Set("testoAllineamento", value);
RaisePropertyChanged("TestoAllineamento");
}
}
public string MarchioFile
{
get { return PicSettings.GetString("marchioFile"); }
set
{
PicSettings.Set("marchioFile", value);
RaisePropertyChanged("MarchioFile");
}
}
public string MarchioAltezza
{
get { return PicSettings.GetString("marchioAltezza"); }
set
{
PicSettings.Set("marchioAltezza", value);
RaisePropertyChanged("MarchioAltezza");
}
}
public string MarchioLarghezza
{
get { return PicSettings.GetString("marchioLarghezza"); }
set
{
PicSettings.Set("marchioLarghezza", value);
RaisePropertyChanged("MarchioLarghezza");
}
}
public string MarchioMargine
{
get { return PicSettings.GetString("marchioMargine"); }
set
{
PicSettings.Set("marchioMargine", value);
RaisePropertyChanged("MarchioMargine");
}
}
public string MarchioAllOrizzontale
{
get { return PicSettings.GetString("marchioAllOrizzontale"); }
set
{
PicSettings.Set("marchioAllOrizzontale", value);
RaisePropertyChanged("MarchioAllOrizzontale");
}
}
public string MarchioAllVerticale
{
get { return PicSettings.GetString("marchioAllVerticale"); }
set
{
PicSettings.Set("marchioAllVerticale", value);
RaisePropertyChanged("MarchioAllVerticale");
}
}
public string MarchioTrasparenza
{
get { return PicSettings.GetString("marchioTrasparenza"); }
set
{
PicSettings.Set("marchioTrasparenza", value);
RaisePropertyChanged("MarchioTrasparenza");
}
}
public bool MarchioAggiungi
{
get { return PicSettings.GetBool("marchioAggiungi"); }
set
{
PicSettings.Set("marchioAggiungi", value);
RaisePropertyChanged("MarchioAggiungi");
}
}
public bool TempoGara
{
get { return PicSettings.GetBool("tempoGara"); }
set
{
PicSettings.Set("tempoGara", value);
RaisePropertyChanged("TempoGara");
}
}
public bool Orario
{
get { return PicSettings.GetBool("orario"); }
set
{
PicSettings.Set("orario", value);
RaisePropertyChanged("Orario");
}
}
public string EtichettaOrario
{
get { return PicSettings.GetString("etichettaOrario"); }
set
{
PicSettings.Set("etichettaOrario", value);
RaisePropertyChanged("EtichettaOrario");
}
}
2016-11-07 16:20:31 +01:00
public bool GeneraleForzaJPG
2016-07-04 16:45:45 +02:00
{
2016-11-07 16:20:31 +01:00
get { return PicSettings.GeneraleForzaJPG; }
2016-07-04 16:45:45 +02:00
set
{
2016-11-07 16:20:31 +01:00
PicSettings.GeneraleForzaJPG = value;
RaisePropertyChanged("GeneraleForzaJPG");
2016-07-04 16:45:45 +02:00
}
}
public bool GeneraleRotazioneAutomatica
{
2016-11-07 16:20:31 +01:00
get { return PicSettings.GeneraleRotazioneAutomatica; }
2016-07-04 16:45:45 +02:00
set
{
2016-11-07 16:20:31 +01:00
PicSettings.GeneraleRotazioneAutomatica = value;
2016-07-04 16:45:45 +02:00
RaisePropertyChanged("GeneraleRotazioneAutomatica");
}
}
public bool GeneraleSovrascriviFile
{
2016-11-07 16:20:31 +01:00
get { return PicSettings.GeneraleSovrascriviFile; }
2016-07-04 16:45:45 +02:00
set
{
2016-11-07 16:20:31 +01:00
PicSettings.GeneraleSovrascriviFile = value;
2016-07-04 16:45:45 +02:00
RaisePropertyChanged("GeneraleSovrascriviFile");
}
}
public string GrandezzaVerticale
{
get { return PicSettings.GetString("grandezzaVerticale"); }
set
{
PicSettings.Set("grandezzaVerticale", value);
RaisePropertyChanged("GrandezzaVerticale");
}
}
public string MargineVerticale
{
get { return PicSettings.GetString("margineVerticale"); }
set
{
PicSettings.Set("margineVerticale", value);
RaisePropertyChanged("MargineVerticale");
}
}
public bool DimensioniOriginali
{
get { return PicSettings.GetBool("dimensioniOriginali"); }
set
{
PicSettings.Set("dimensioniOriginali", value);
RaisePropertyChanged("DimensioniOriginali");
}
}
public string TestoVerticale
{
get { return PicSettings.GetString("testoVerticale"); }
set
{
PicSettings.Set("testoVerticale", value);
RaisePropertyChanged("TestoVerticale");
}
}
public bool NomeMiniatura
{
get { return PicSettings.GetBool("nomeMiniatura"); }
set
{
PicSettings.Set("nomeMiniatura", value);
RaisePropertyChanged("NomeMiniatura");
}
}
public bool DataFoto
{
get { return PicSettings.GetBool("dataFoto"); }
set
{
PicSettings.Set("dataFoto", value);
RaisePropertyChanged("DataFoto");
}
}
public bool NumeroFoto
{
get { return PicSettings.GetBool("numeroFoto"); }
set
{
PicSettings.Set("numeroFoto", value);
RaisePropertyChanged("NumeroFoto");
}
}
public bool TempoSmall
{
get { return PicSettings.GetBool("tempoSmall"); }
set
{
PicSettings.Set("tempoSmall", value);
RaisePropertyChanged("TempoSmall");
}
}
public bool NumTempoSmall
{
get { return PicSettings.GetBool("numTempoSmall"); }
set
{
PicSettings.Set("numTempoSmall", value);
RaisePropertyChanged("NumTempoSmall");
}
}
2016-11-07 20:58:16 +01:00
public int CompressioneJpeg
2016-07-04 16:45:45 +02:00
{
2016-11-07 20:58:16 +01:00
get { return PicSettings.CompressioneJpeg; }
2016-07-04 16:45:45 +02:00
set
{
2016-11-07 20:58:16 +01:00
PicSettings.CompressioneJpeg = value;
2016-07-04 16:45:45 +02:00
RaisePropertyChanged("CompressioneJpeg");
}
}
2016-11-07 20:58:16 +01:00
public bool FotoMantieniDimensioni
{
get { return PicSettings.FotoMantieniDimensioni; }
set
{
PicSettings.FotoMantieniDimensioni = value;
RaisePropertyChanged("FotoMantieniDimensioni");
}
}
public string FotoSuffisso
{
get { return PicSettings.FotoSuffisso; }
set { PicSettings.FotoSuffisso = value; RaisePropertyChanged("FotoSuffisso"); }
}
2016-07-04 16:45:45 +02:00
public string CompressioneJpegMiniatura
{
get { return PicSettings.GetString("compressioneJpegMiniatura"); }
set
{
PicSettings.Set("compressioneJpegMiniatura", value);
RaisePropertyChanged("CompressioneJpegMiniatura");
}
}
2017-03-17 16:23:29 +01:00
#endregion
#region Testo
public bool EnableText
{
get { return PicSettings.EnableText; }
set { PicSettings.EnableText = value; RaisePropertyChanged("EnableText"); }
}
2016-07-04 16:45:45 +02:00
public string ColoreTestoRGB
2017-09-20 15:01:22 +02:00
{
2017-04-17 13:06:09 +02:00
get { return PicSettings.ColoreTestoRGB; }
2016-07-04 16:45:45 +02:00
set
{
2017-04-17 13:06:09 +02:00
PicSettings.ColoreTestoRGB = value;
2016-07-04 16:45:45 +02:00
RaisePropertyChanged("ColoreTestoRGB");
}
}
2017-03-17 16:23:29 +01:00
public string FontName
2016-11-07 20:58:16 +01:00
{
2017-03-17 16:23:29 +01:00
get { return PicSettings.NomeFont; }
set
{
PicSettings.NomeFont = value;
RaisePropertyChanged("FontName");
}
2016-11-07 20:58:16 +01:00
}
2017-03-17 16:23:29 +01:00
public double FontSize
2016-11-07 20:58:16 +01:00
{
2017-03-17 16:23:29 +01:00
get
{
{
return PicSettings.DimensioneFont;
}
}
set
{
PicSettings.DimensioneFont = value;
RaisePropertyChanged("FontSize");
}
2016-11-07 20:58:16 +01:00
}
2017-03-23 14:36:06 +01:00
public string TestoApplicareOrizzontale
{
get
{
return PicSettings.TestoApplicareOrizzontale;
}
set
{
PicSettings.TestoApplicareOrizzontale = value;
RaisePropertyChanged("TestoApplicareOrizzontale");
}
}
2017-03-17 16:23:29 +01:00
//todo: bold
2017-03-23 14:36:06 +01:00
//todo: italic
2017-03-17 16:23:29 +01:00
#endregion
#region Logo
2016-11-07 20:58:16 +01:00
public bool EnableLogo
{
get { return PicSettings.EnableLogo; }
set { PicSettings.EnableLogo = value; RaisePropertyChanged("EnableLogo"); }
}
#endregion
2017-03-17 16:23:29 +01:00
#region Thumbnail
public bool EnableThumbnails
{
get { return PicSettings.EnableThumbnails; }
set { PicSettings.EnableThumbnails = value; RaisePropertyChanged("EnableThumbnails"); }
}
#endregion
2016-07-04 16:45:45 +02:00
}
}