/// <summary> /// Event handler for connected devices. /// </summary> /// <param name="sender">Sender of the event.</param> /// <param name="args">Event arguments.</param> private void OnDeviceConnected(object sender, CDMEventArgs args) { Device device = args.Device; if (configuration.ShowNotificationPopups) { string message = "'" + device.Name + "' has been connected. " + "You may now synchronize the device " + "with the playlist for this device.\n\nDevices currently connected:"; foreach (Device d in connectedDevices.GetConnectedDevices()) { message += "\n - " + d.Name; } itaTray.ShowBalloonTip(5, "Device connected!", message, ToolTipIcon.Info); } IITPlaylist playlist = PlaylistExists(device); //Delete playlist if it exists. //if (playlist != null) // playlist.Delete(); if (playlist == null) { try { if (configuration.UseListFolder) { CreateMyDevicesFolder(); playlist = folderMyDevices.CreatePlaylist(device.Name); } else { playlist = itunes.CreatePlaylist(device.Name); } } catch (Exception e) { l.Error(e); MessageBox.Show("Failed to create list for device '" + device.Name + "'. You will not be able to synchronize this device with iTunes.", "Playlist error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { //If the option to use "My Devices" folder is set, move the playlist to that folder. if (configuration.UseListFolder && (playlist.Kind == ITPlaylistKind.ITPlaylistKindUser) && (device.Playlist == null || device.Playlist.Length == 0)) { CreateMyDevicesFolder(); object parent = (object)folderMyDevices; ((IITUserPlaylist)playlist).set_Parent(ref parent); } } }
/// <summary> /// Method for dispatching device connected events. /// </summary> /// <param name="drive">The drive where the device is connected.</param> /// <param name="device">Info on the connected device.</param> protected void OnDeviceConnected(DriveInfo drive, Device device) { if (DeviceConnected != null) { CDMEventArgs args = new CDMEventArgs(drive, device); DeviceConnected(this, args); } }
/// <summary> /// Method for sending out device disconnected events. /// </summary> /// <param name="driveName">The name of the drive where the device was located.</param> /// <param name="device">Device object describing the device that was disconnected.</param> protected void OnDeviceDisconnected(string driveName, Device device) { if (DeviceDisconnected != null) { CDMEventArgs args = new CDMEventArgs(null, device); DeviceDisconnected(this, driveName, args); } }
/// <summary> /// Event handler for disconnected devices. /// </summary> /// <param name="sender">Sender of the event.</param> /// <param name="driveName">Name of drive where the device was connected.</param> /// <param name="args">Event arguments.</param> private void OnDeviceDisconnect(object sender, string driveName, CDMEventArgs args) { Device device = args.Device; if (configuration.ShowNotificationPopups) { itaTray.ShowBalloonTip(5, "Device disconnected", "'" + device.Name + "' was disconnected.", ToolTipIcon.Info); } }
/// <summary> /// Overriding OnClosing to remove playlists for devices. /// </summary> /// <param name="e"></param> protected override void OnClosing(CancelEventArgs e) { Hashtable cd = connectedDevices.GetConnectedDevicesWithDrives(); IDictionaryEnumerator cdenum = cd.GetEnumerator(); while (cdenum.MoveNext()) { CDMEventArgs args = new CDMEventArgs(null, (Device)cdenum.Value); OnDeviceDisconnect(this, (string)cdenum.Key, args); } itunes = null; base.OnClosing(e); }
/// <summary> /// Overriding OnClosing to remove playlists for devices. /// </summary> /// <param name="e"></param> protected override void OnClosing(CancelEventArgs e) { Dictionary <String, HashSet <Device> > cd = connectedDevices.GetConnectedDevicesWithDrives(); IDictionaryEnumerator cdenum = cd.GetEnumerator(); while (cdenum.MoveNext()) { HashSet <Device> devices = (HashSet <Device>)cdenum.Value; foreach (Device device in devices) { CDMEventArgs args = new CDMEventArgs(null, device); OnDeviceDisconnect(this, (string)cdenum.Key, args); } } itunes = null; base.OnClosing(e); }