private void OkDialogButton_Click(object sender, EventArgs e) { JsonObject request = Requests.CreateBasicObject(ProtocolConstants.METHOD_TORRENTSET); JsonObject arguments = Requests.GetArgObject(request); arguments.Put(ProtocolConstants.KEY_IDS, Toolbox.ListViewSelectionToIdArray(selections)); arguments.Put(ProtocolConstants.FIELD_SPEEDLIMITUPENABLED, uploadLimitEnableField.Checked ? 1 : 0); arguments.Put(ProtocolConstants.FIELD_UPLOADLIMITED, uploadLimitEnableField.Checked ? 1 : 0); arguments.Put(ProtocolConstants.FIELD_UPLOADLIMIT, uploadLimitField.Value); arguments.Put(ProtocolConstants.FIELD_SPEEDLIMITUP, uploadLimitField.Value); arguments.Put(ProtocolConstants.FIELD_SPEEDLIMITDOWNENABLED, downloadLimitEnableField.Checked ? 1 : 0); arguments.Put(ProtocolConstants.FIELD_DOWNLOADLIMITED, downloadLimitEnableField.Checked ? 1 : 0); arguments.Put(ProtocolConstants.FIELD_DOWNLOADLIMIT, downloadLimitField.Value); arguments.Put(ProtocolConstants.FIELD_SPEEDLIMITDOWN, downloadLimitField.Value); arguments.Put(ProtocolConstants.FIELD_PEERLIMIT, peerLimitValue.Value); if (seedRatioLimitValue.Enabled) { arguments.Put(ProtocolConstants.FIELD_SEEDRATIOLIMIT, seedRatioLimitValue.Value); } if (seedIdleLimitValue.Enabled) { arguments.Put(ProtocolConstants.FIELD_SEEDIDLELIMIT, seedIdleLimitValue.Value); } if (honorsSessionLimits.Enabled) { arguments.Put(ProtocolConstants.FIELD_HONORSSESSIONLIMITS, honorsSessionLimits.Checked); } if (seedRatioLimitedCheckBox.Enabled) { arguments.Put(ProtocolConstants.FIELD_SEEDRATIOMODE, (int)(2 - seedRatioLimitedCheckBox.CheckState)); } if (seedIdleLimitedCheckBox.Enabled) { arguments.Put(ProtocolConstants.FIELD_SEEDIDLEMODE, (int)(2 - seedIdleLimitedCheckBox.CheckState)); } if (bandwidthComboBox.Enabled) { int bandwidthPriority = 0; if (bandwidthComboBox.SelectedIndex == 0) { bandwidthPriority = -1; } else if (bandwidthComboBox.SelectedIndex == 2) { bandwidthPriority = 1; } arguments.Put(ProtocolConstants.FIELD_BANDWIDTHPRIORITY, bandwidthPriority); } Torrent firstTorrent = (Torrent)selections[0]; JsonArray trackerRemove = new JsonArray(); foreach (JsonObject tracker in firstTorrent.Trackers) { int id = Toolbox.ToInt(tracker[ProtocolConstants.FIELD_ID]); if (!trackersList.Items.Contains(id)) { trackerRemove.Add(id); } } JsonArray trackerReplace = new JsonArray(); foreach (TrackerListItem t in trackersList.Items) { if (!t.Changed) { continue; } trackerReplace.Add(t.Id); trackerReplace.Add(t.Announce); } JsonArray trackerAdd = new JsonArray(); foreach (TrackerListItem t in trackersList.Items) { if (t.Id == -1) { trackerAdd.Add(t.Announce); } } if (trackerRemove.Count > 0) { arguments.Put(ProtocolConstants.FIELD_TRACKER_REMOVE, trackerRemove); } if (trackerReplace.Count > 0) { arguments.Put(ProtocolConstants.FIELD_TRACKER_REPLACE, trackerReplace); } if (trackerAdd.Count > 0) { arguments.Put(ProtocolConstants.FIELD_TRACKER_ADD, trackerAdd); } Program.Form.SetupAction(CommandFactory.RequestAsync(request)); Close(); }
private void SaveButton_Click(object sender, EventArgs e) { JsonObject request = Requests.CreateBasicObject(ProtocolConstants.METHOD_SESSIONSET); JsonObject arguments = Requests.GetArgObject(request); arguments.Put((string)incomingPortValue.Tag, incomingPortValue.Value); arguments.Put(ProtocolConstants.FIELD_PORTFORWARDINGENABLED, portForwardCheckBox.Checked); arguments.Put((string)pexEnabledCheckBox.Tag, pexEnabledCheckBox.Checked); arguments.Put((string)peerLimitValue.Tag, peerLimitValue.Value); arguments.Put(ProtocolConstants.FIELD_PEERLIMITPERTORRENT, peerLimitTorrentValue.Value); if (cacheSizeValue.Enabled) { arguments.Put(ProtocolConstants.FIELD_CACHESIZE, cacheSizeValue.Value); } if (blocklistUrlField.Enabled) { arguments.Put(ProtocolConstants.FIELD_BLOCKLISTURL, blocklistUrlField.Text); } switch (encryptionCombobox.SelectedIndex) { case 1: arguments.Put(ProtocolConstants.FIELD_ENCRYPTION, ProtocolConstants.VALUE_PREFERRED); break; case 2: arguments.Put(ProtocolConstants.FIELD_ENCRYPTION, ProtocolConstants.VALUE_REQUIRED); break; default: arguments.Put(ProtocolConstants.FIELD_ENCRYPTION, ProtocolConstants.VALUE_TOLERATED); break; } arguments.Put(ProtocolConstants.FIELD_SPEEDLIMITUPENABLED, limitUploadCheckBox.Checked); arguments.Put(ProtocolConstants.FIELD_SPEEDLIMITUP, limitUploadValue.Value); arguments.Put(ProtocolConstants.FIELD_SPEEDLIMITDOWNENABLED, limitDownloadCheckBox.Checked); arguments.Put(ProtocolConstants.FIELD_SPEEDLIMITDOWN, limitDownloadValue.Value); if (altSpeedLimitEnable.Enabled) { arguments.Put(ProtocolConstants.FIELD_ALTSPEEDENABLED, altSpeedLimitEnable.Checked); arguments.Put(ProtocolConstants.FIELD_ALTSPEEDDOWN, altDownloadLimitField.Value); arguments.Put(ProtocolConstants.FIELD_ALTSPEEDUP, altUploadLimitField.Value); } if (altTimeConstraintEnabled.Enabled) { arguments.Put(ProtocolConstants.FIELD_ALTSPEEDTIMEENABLED, altTimeConstraintEnabled.Checked); arguments.Put(ProtocolConstants.FIELD_ALTSPEEDTIMEBEGIN, timeConstraintBeginHours.Value * 60 + timeConstraintBeginMinutes.Value); arguments.Put(ProtocolConstants.FIELD_ALTSPEEDTIMEEND, timeConstraintEndHours.Value * 60 + timeConstraintEndMinutes.Value); } if (blocklistEnabledCheckBox.Enabled) { arguments.Put(ProtocolConstants.FIELD_BLOCKLISTENABLED, blocklistEnabledCheckBox.Checked); } if (seedRatioEnabledCheckBox.Enabled) { arguments.Put(ProtocolConstants.FIELD_SEEDRATIOLIMITED, seedRatioEnabledCheckBox.Checked); arguments.Put(ProtocolConstants.FIELD_SEEDRATIOLIMIT, seedLimitUpDown.Value); } if (seedIdleEnabledCheckBox.Enabled) { arguments.Put(ProtocolConstants.FIELD_IDLESEEDLIMITENABLED, seedIdleEnabledCheckBox.Checked); arguments.Put(ProtocolConstants.FIELD_IDLESEEDLIMIT, seedIdleLimitUpDown.Value); } if (incompleteToCheckBox.Enabled) { arguments.Put(ProtocolConstants.FIELD_INCOMPLETE_DIR_ENABLED, incompleteToCheckBox.Checked); arguments.Put(ProtocolConstants.FIELD_INCOMPLETE_DIR, incompleteToField.Text); } if (watchdirCheckBox.Enabled) { arguments.Put(ProtocolConstants.FIELD_WATCH_DIR_ENABLED, watchdirCheckBox.Checked); arguments.Put(ProtocolConstants.FIELD_WATCH_DIR, watchdirField.Text); } if (dhtEnabledCheckBox.Enabled) { arguments.Put(ProtocolConstants.FIELD_DHTENABLED, dhtEnabledCheckBox.Checked); } if (lpdEnabledCheckBox.Enabled) { arguments.Put(ProtocolConstants.FIELD_LPDENABLED, lpdEnabledCheckBox.Checked); } if (utpEnabledCheckBox.Enabled) { arguments.Put(ProtocolConstants.FIELD_UTPENABLED, utpEnabledCheckBox.Checked); } if (renamePartialFilesCheckBox.Enabled) { arguments.Put(ProtocolConstants.FIELD_RENAME_PARTIAL_FILES, renamePartialFilesCheckBox.Checked); } arguments.Put(ProtocolConstants.DOWNLOAD_DIR, downloadToField.Text); CommandFactory.RequestAsync(request).Completed += RemoteSettingsDialog_Completed; CloseAndDispose(); }