using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Net; using System.Xml; namespace Picasa2Piwigo { using Picasa2PiwigoConstants; public partial class Form1 : Form { string[] command_line_args; XmlDocument AlbumList = new XmlDocument(); public struct AlbumListStruct { public string album_name; public string full_album_path; public int album_index; public string album_parent_chain; } AlbumListStruct[] album_list_array = new AlbumListStruct[1024]; int album_count; public Form1(string[] args) { InitializeComponent(); command_line_args = args; } private void Form1_Load(object sender, EventArgs e) { this.SyncButton.Enabled = false; this.Show(); this.Refresh(); //if no arguments then exit if (command_line_args.Length == 0) { return; } AccessComboBox.SelectedIndex = Form1Settings.Default.AccessSetting; this.SyncButton.Enabled = true; //determine album name, if possible AlbumNameTextBox.Text = DetermineAlbumNameFromCommandLine(command_line_args[0]); if (FormSettings.Default.PiwigoUrlSetting.Length == 0 || FormSettings.Default.PicasaContactsLocation.Length == 0) { MessageBox.Show("Set up your Piwigo Server Connection using the Options button.", "Picasa2Piwigo"); return; } //ok to try to login etc LoginBuildAlbumList(); //populate album listbox PopulateAlbumListBox(); } private void SyncButton_Click(object sender, EventArgs e) { DialogResult result; if (NewAlbumRadioButton.Checked) { if (AlbumNameTextBox.Text.Length == 0) { MessageBox.Show("Error: Blank Album Name"); return; } GlobalClass.NewAlbumName = AlbumNameTextBox.Text; if (NewAlbumParentAlbumComboBox.SelectedIndex == -1) { GlobalClass.NewAlbumNameParentID = -1; } else { GlobalClass.NewAlbumNameParentID = album_list_array[NewAlbumParentAlbumComboBox.SelectedIndex].album_index; } if (AlbumAlreadyExists(NewAlbumParentAlbumComboBox.SelectedIndex)) { MessageBox.Show("Album already exists in Piwigo. Please choose a different album name."); return; } Form StatusForm = new StatusForm(constants.COMMAND_NEW_ALBUM, command_line_args); result = StatusForm.ShowDialog(); StatusForm.Close(); if (result == DialogResult.No) { MessageBox.Show(GlobalClass.StatusDialogErrorMessage, "Picasa2Piwigo Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Add to new album complete."); Application.Exit(); } } if (AddTopAlbumCheckbox.Checked) { if (AddToAlbumComboBox.SelectedIndex == -1) { MessageBox.Show("Error: No Album Selected"); return; } GlobalClass.AddAlbumCategoryID = album_list_array[AddToAlbumComboBox.SelectedIndex].album_index; Form StatusForm = new StatusForm(constants.COMMAND_ADD_TO_ALBUM, command_line_args); result = StatusForm.ShowDialog(); StatusForm.Close(); if (result == DialogResult.No) { MessageBox.Show(GlobalClass.StatusDialogErrorMessage, "Picasa2Piwigo Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Add to album complete."); Application.Exit(); } } } private void OptionsButton_Click(object sender, EventArgs e) { DialogResult option_form_result; Form OptionsForm = new OptionsForm(); OptionsButton.Enabled = false; option_form_result = OptionsForm.ShowDialog(); OptionsButton.Enabled = true; if (option_form_result == DialogResult.OK) { if (FormSettings.Default.PiwigoUrlSetting.Length != 0 && FormSettings.Default.PicasaContactsLocation.Length != 0) { this.SyncButton.Enabled = true; //ok to try to login etc LoginBuildAlbumList(); //populate album listbox PopulateAlbumListBox(); } } } private void NewAlbumRadioButton_CheckedChanged(object sender, EventArgs e) { if (NewAlbumRadioButton.Checked) { NewAlbumGroupBox.Enabled = true; AddToAlbumGroupbox.Enabled = false; } } private void AddTopAlbumCheckbox_CheckedChanged(object sender, EventArgs e) { if (AddTopAlbumCheckbox.Checked) { NewAlbumGroupBox.Enabled = false; AddToAlbumGroupbox.Enabled = true; } } public void LoginBuildAlbumList() { DialogResult result; Form StatusForm = new StatusForm(constants.COMMAND_START_UP, command_line_args); result = StatusForm.ShowDialog(); StatusForm.Close(); if (result == DialogResult.No) { MessageBox.Show(GlobalClass.StatusDialogErrorMessage, "Picasa2Piwigo Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } AlbumList = GlobalClass.AlbumList; //build album list BuildAlbumList(AlbumList); } public string DetermineAlbumNameFromCommandLine(string command_line) { int k, l, m; string album_name; k = command_line.LastIndexOf("\\"); album_name = ""; if (k != -1) { l = command_line.LastIndexOf("\\", k - 1); m = command_line.LastIndexOf(":", k - 1); if (l != -1) { album_name = command_line.Substring(l + 1, k - l - 1); } else if (m != -1) { album_name = command_line.Substring(m + 1, k - m - 1); } } return album_name; } public void BuildAlbumList(XmlDocument AlbumList) { album_count = 0; XmlNodeList nodelist = AlbumList.GetElementsByTagName("category"); foreach (XmlNode anode in nodelist) { if (album_count >= album_list_array.Length) { Array.Resize(ref album_list_array, album_list_array.Length + 1024); } if (anode.Attributes.Item(0).Name == "id") { album_list_array[album_count].album_index = Convert.ToInt32(anode.Attributes.Item(0).Value); } album_list_array[album_count].album_name = anode.ChildNodes[0].InnerText; album_count++; } } public void PopulateAlbumListBox() { int i; for (i = 0; i < album_count; i++) { NewAlbumParentAlbumComboBox.Items.Add(album_list_array[i].album_name); AddToAlbumComboBox.Items.Add(album_list_array[i].album_name); } } public bool AlbumAlreadyExists(int selected_index) { int i; string NewAlbumNameFull; if (selected_index == -1) { NewAlbumNameFull = GlobalClass.NewAlbumName; } else { NewAlbumNameFull = album_list_array[selected_index].album_name + " / " + GlobalClass.NewAlbumName; } for (i = 0; i < album_count; i++) { if (album_list_array[i].album_name == NewAlbumNameFull) { return true; } } return false; } private void AccessComboBox_SelectedIndexChanged(object sender, EventArgs e) { Form1Settings.Default.AccessSetting = AccessComboBox.SelectedIndex; Form1Settings.Default.AccessValue = AccessComboBox.Text; Form1Settings.Default.Save(); } } }