369 const QVariantHash
m = QJsonDocument::fromJson(
params()[
"json"].toUtf8()).toVariant().toHash();
371 QVariantHash::ConstIterator it;
372 const auto hasKey = [&it, &
m](
const char *key) ->
bool
374 it =
m.find(QLatin1String(key));
375 return (it !=
m.constEnd());
380 if (hasKey(
"torrent_content_layout"))
381 session->setTorrentContentLayout(
Utils::String::toEnum(it.value().toString(), BitTorrent::TorrentContentLayout::Original));
382 if (hasKey(
"start_paused_enabled"))
383 session->setAddTorrentPaused(it.value().toBool());
384 if (hasKey(
"auto_delete_mode"))
387 if (hasKey(
"preallocate_all"))
388 session->setPreallocationEnabled(it.value().toBool());
389 if (hasKey(
"incomplete_files_ext"))
390 session->setAppendExtensionEnabled(it.value().toBool());
393 if (hasKey(
"auto_tmm_enabled"))
394 session->setAutoTMMDisabledByDefault(!it.value().toBool());
395 if (hasKey(
"torrent_changed_tmm_enabled"))
396 session->setDisableAutoTMMWhenCategoryChanged(!it.value().toBool());
397 if (hasKey(
"save_path_changed_tmm_enabled"))
398 session->setDisableAutoTMMWhenDefaultSavePathChanged(!it.value().toBool());
399 if (hasKey(
"category_changed_tmm_enabled"))
400 session->setDisableAutoTMMWhenCategorySavePathChanged(!it.value().toBool());
401 if (hasKey(
"save_path"))
402 session->setSavePath(it.value().toString());
403 if (hasKey(
"temp_path_enabled"))
404 session->setDownloadPathEnabled(it.value().toBool());
405 if (hasKey(
"temp_path"))
406 session->setDownloadPath(it.value().toString());
407 if (hasKey(
"export_dir"))
408 session->setTorrentExportDirectory(it.value().toString());
409 if (hasKey(
"export_dir_fin"))
410 session->setFinishedTorrentExportDirectory(it.value().toString());
414 if (hasKey(
"scan_dirs"))
416 QStringList scanDirs;
418 const QStringList oldScanDirs = fsWatcher->
folders().keys();
419 const QVariantHash nativeDirs = it.value().toHash();
420 for (
auto i = nativeDirs.cbegin(); i != nativeDirs.cend(); ++i)
429 const int intVal = i.value().toInt(&isInt);
434 params.savePath = watchedFolder;
435 params.useAutoTMM =
false;
440 const QString customSavePath = i.value().toString();
441 params.savePath = customSavePath;
442 params.useAutoTMM =
false;
446 scanDirs.append(watchedFolder);
454 for (
const QString &path : oldScanDirs)
456 if (!scanDirs.contains(path))
463 if (hasKey(
"mail_notification_enabled"))
464 pref->setMailNotificationEnabled(it.value().toBool());
465 if (hasKey(
"mail_notification_sender"))
466 pref->setMailNotificationSender(it.value().toString());
467 if (hasKey(
"mail_notification_email"))
468 pref->setMailNotificationEmail(it.value().toString());
469 if (hasKey(
"mail_notification_smtp"))
470 pref->setMailNotificationSMTP(it.value().toString());
471 if (hasKey(
"mail_notification_ssl_enabled"))
472 pref->setMailNotificationSMTPSSL(it.value().toBool());
473 if (hasKey(
"mail_notification_auth_enabled"))
474 pref->setMailNotificationSMTPAuth(it.value().toBool());
475 if (hasKey(
"mail_notification_username"))
476 pref->setMailNotificationSMTPUsername(it.value().toString());
477 if (hasKey(
"mail_notification_password"))
478 pref->setMailNotificationSMTPPassword(it.value().toString());
480 if (hasKey(
"autorun_enabled"))
481 pref->setAutoRunEnabled(it.value().toBool());
482 if (hasKey(
"autorun_program"))
483 pref->setAutoRunProgram(it.value().toString());
487 if (hasKey(
"random_port") && it.value().toBool())
491 else if (hasKey(
"listen_port"))
493 session->setPort(it.value().toInt());
498 if (hasKey(
"max_connec"))
499 session->setMaxConnections(it.value().toInt());
500 if (hasKey(
"max_connec_per_torrent"))
501 session->setMaxConnectionsPerTorrent(it.value().toInt());
502 if (hasKey(
"max_uploads"))
503 session->setMaxUploads(it.value().toInt());
504 if (hasKey(
"max_uploads_per_torrent"))
505 session->setMaxUploadsPerTorrent(it.value().toInt());
510 if (hasKey(
"proxy_type"))
512 if (hasKey(
"proxy_ip"))
513 proxyConf.
ip = it.value().toString();
514 if (hasKey(
"proxy_port"))
515 proxyConf.
port = it.value().toUInt();
516 if (hasKey(
"proxy_username"))
517 proxyConf.
username = it.value().toString();
518 if (hasKey(
"proxy_password"))
519 proxyConf.
password = it.value().toString();
520 proxyManager->setProxyConfiguration(proxyConf);
522 if (hasKey(
"proxy_peer_connections"))
523 session->setProxyPeerConnectionsEnabled(it.value().toBool());
524 if (hasKey(
"proxy_torrents_only"))
525 proxyManager->setProxyOnlyForTorrents(it.value().toBool());
528 if (hasKey(
"ip_filter_enabled"))
529 session->setIPFilteringEnabled(it.value().toBool());
530 if (hasKey(
"ip_filter_path"))
531 session->setIPFilterFile(it.value().toString());
532 if (hasKey(
"ip_filter_trackers"))
533 session->setTrackerFilteringEnabled(it.value().toBool());
534 if (hasKey(
"banned_IPs"))
535 session->setBannedIPs(it.value().toString().split(
'\n', Qt::SkipEmptyParts));
539 if (hasKey(
"dl_limit"))
540 session->setGlobalDownloadSpeedLimit(it.value().toInt());
541 if (hasKey(
"up_limit"))
542 session->setGlobalUploadSpeedLimit(it.value().toInt());
543 if (hasKey(
"alt_dl_limit"))
544 session->setAltGlobalDownloadSpeedLimit(it.value().toInt());
545 if (hasKey(
"alt_up_limit"))
546 session->setAltGlobalUploadSpeedLimit(it.value().toInt());
547 if (hasKey(
"bittorrent_protocol"))
549 if (hasKey(
"limit_utp_rate"))
550 session->setUTPRateLimited(it.value().toBool());
551 if (hasKey(
"limit_tcp_overhead"))
552 session->setIncludeOverheadInLimits(it.value().toBool());
553 if (hasKey(
"limit_lan_peers"))
554 session->setIgnoreLimitsOnLAN(!it.value().toBool());
556 if (hasKey(
"scheduler_enabled"))
557 session->setBandwidthSchedulerEnabled(it.value().toBool());
558 if (
m.contains(
"schedule_from_hour") &&
m.contains(
"schedule_from_min"))
559 pref->setSchedulerStartTime(QTime(
m[
"schedule_from_hour"].toInt(),
m[
"schedule_from_min"].toInt()));
560 if (
m.contains(
"schedule_to_hour") &&
m.contains(
"schedule_to_min"))
561 pref->setSchedulerEndTime(QTime(
m[
"schedule_to_hour"].toInt(),
m[
"schedule_to_min"].toInt()));
562 if (hasKey(
"scheduler_days"))
563 pref->setSchedulerDays(
static_cast<Scheduler::Days>(it.value().toInt()));
568 session->setDHTEnabled(it.value().toBool());
570 session->setPeXEnabled(it.value().toBool());
572 session->setLSDEnabled(it.value().toBool());
573 if (hasKey(
"encryption"))
574 session->setEncryption(it.value().toInt());
575 if (hasKey(
"anonymous_mode"))
576 session->setAnonymousModeEnabled(it.value().toBool());
578 if (hasKey(
"queueing_enabled"))
579 session->setQueueingSystemEnabled(it.value().toBool());
580 if (hasKey(
"max_active_downloads"))
581 session->setMaxActiveDownloads(it.value().toInt());
582 if (hasKey(
"max_active_torrents"))
583 session->setMaxActiveTorrents(it.value().toInt());
584 if (hasKey(
"max_active_uploads"))
585 session->setMaxActiveUploads(it.value().toInt());
586 if (hasKey(
"dont_count_slow_torrents"))
587 session->setIgnoreSlowTorrentsForQueueing(it.value().toBool());
588 if (hasKey(
"slow_torrent_dl_rate_threshold"))
589 session->setDownloadRateForSlowTorrents(it.value().toInt());
590 if (hasKey(
"slow_torrent_ul_rate_threshold"))
591 session->setUploadRateForSlowTorrents(it.value().toInt());
592 if (hasKey(
"slow_torrent_inactive_timer"))
593 session->setSlowTorrentsInactivityTimer(it.value().toInt());
595 if (hasKey(
"max_ratio_enabled"))
597 if (it.value().toBool())
598 session->setGlobalMaxRatio(
m[
"max_ratio"].toReal());
600 session->setGlobalMaxRatio(-1);
602 if (hasKey(
"max_seeding_time_enabled"))
604 if (it.value().toBool())
605 session->setGlobalMaxSeedingMinutes(
m[
"max_seeding_time"].toInt());
607 session->setGlobalMaxSeedingMinutes(-1);
609 if (hasKey(
"max_ratio_act"))
610 session->setMaxRatioAction(
static_cast<MaxRatioAction>(it.value().toInt()));
612 if (hasKey(
"add_trackers_enabled"))
613 session->setAddTrackersEnabled(it.value().toBool());
614 if (hasKey(
"add_trackers"))
615 session->setAdditionalTrackers(it.value().toString());
619 if (hasKey(
"locale"))
621 QString locale = it.value().toString();
622 if (pref->getLocale() != locale)
624 auto *translator =
new QTranslator;
625 if (translator->load(QLatin1String(
":/lang/qbittorrent_") + locale))
627 qDebug(
"%s locale recognized, using translation.", qUtf8Printable(locale));
631 qDebug(
"%s locale unrecognized, using default (en).", qUtf8Printable(locale));
633 qApp->installTranslator(translator);
635 pref->setLocale(locale);
639 if (hasKey(
"web_ui_domain_list"))
640 pref->setServerDomains(it.value().toString());
641 if (hasKey(
"web_ui_address"))
642 pref->setWebUiAddress(it.value().toString());
643 if (hasKey(
"web_ui_port"))
644 pref->setWebUiPort(it.value().toUInt());
645 if (hasKey(
"web_ui_upnp"))
646 pref->setUPnPForWebUIPort(it.value().toBool());
647 if (hasKey(
"use_https"))
648 pref->setWebUiHttpsEnabled(it.value().toBool());
649 if (hasKey(
"web_ui_https_cert_path"))
650 pref->setWebUIHttpsCertificatePath(it.value().toString());
651 if (hasKey(
"web_ui_https_key_path"))
652 pref->setWebUIHttpsKeyPath(it.value().toString());
654 if (hasKey(
"web_ui_username"))
655 pref->setWebUiUsername(it.value().toString());
656 if (hasKey(
"web_ui_password"))
658 if (hasKey(
"bypass_local_auth"))
659 pref->setWebUiLocalAuthEnabled(!it.value().toBool());
660 if (hasKey(
"bypass_auth_subnet_whitelist_enabled"))
661 pref->setWebUiAuthSubnetWhitelistEnabled(it.value().toBool());
662 if (hasKey(
"bypass_auth_subnet_whitelist"))
665 pref->setWebUiAuthSubnetWhitelist(it.value().toString().split(QRegularExpression(
"\n|,"), Qt::SkipEmptyParts));
667 if (hasKey(
"web_ui_max_auth_fail_count"))
668 pref->setWebUIMaxAuthFailCount(it.value().toInt());
669 if (hasKey(
"web_ui_ban_duration"))
670 pref->setWebUIBanDuration(std::chrono::seconds {it.value().toInt()});
671 if (hasKey(
"web_ui_session_timeout"))
672 pref->setWebUISessionTimeout(it.value().toInt());
674 if (hasKey(
"alternative_webui_enabled"))
675 pref->setAltWebUiEnabled(it.value().toBool());
676 if (hasKey(
"alternative_webui_path"))
677 pref->setWebUiRootFolder(it.value().toString());
679 if (hasKey(
"web_ui_clickjacking_protection_enabled"))
680 pref->setWebUiClickjackingProtectionEnabled(it.value().toBool());
681 if (hasKey(
"web_ui_csrf_protection_enabled"))
682 pref->setWebUiCSRFProtectionEnabled(it.value().toBool());
683 if (hasKey(
"web_ui_secure_cookie_enabled"))
684 pref->setWebUiSecureCookieEnabled(it.value().toBool());
685 if (hasKey(
"web_ui_host_header_validation_enabled"))
686 pref->setWebUIHostHeaderValidationEnabled(it.value().toBool());
688 if (hasKey(
"web_ui_use_custom_http_headers_enabled"))
689 pref->setWebUICustomHTTPHeadersEnabled(it.value().toBool());
690 if (hasKey(
"web_ui_custom_http_headers"))
691 pref->setWebUICustomHTTPHeaders(it.value().toString());
693 if (hasKey(
"web_ui_reverse_proxy_enabled"))
694 pref->setWebUIReverseProxySupportEnabled(it.value().toBool());
695 if (hasKey(
"web_ui_reverse_proxies_list"))
696 pref->setWebUITrustedReverseProxiesList(it.value().toString());
698 if (hasKey(
"dyndns_enabled"))
699 pref->setDynDNSEnabled(it.value().toBool());
700 if (hasKey(
"dyndns_service"))
701 pref->setDynDNSService(
static_cast<DNS::Service>(it.value().toInt()));
702 if (hasKey(
"dyndns_username"))
703 pref->setDynDNSUsername(it.value().toString());
704 if (hasKey(
"dyndns_password"))
705 pref->setDynDNSPassword(it.value().toString());
706 if (hasKey(
"dyndns_domain"))
707 pref->setDynDomainName(it.value().toString());
709 if (hasKey(
"rss_refresh_interval"))
711 if (hasKey(
"rss_max_articles_per_feed"))
713 if (hasKey(
"rss_processing_enabled"))
715 if (hasKey(
"rss_auto_downloading_enabled"))
717 if (hasKey(
"rss_download_repack_proper_episodes"))
719 if (hasKey(
"rss_smart_episode_filters"))
725 if (hasKey(
"current_network_interface"))
727 const QString ifaceValue {it.value().toString()};
729 const QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
730 const auto ifacesIter = std::find_if(ifaces.cbegin(), ifaces.cend(), [&ifaceValue](
const QNetworkInterface &iface)
732 return (!iface.addressEntries().isEmpty()) && (iface.name() == ifaceValue);
734 const QString ifaceName = (ifacesIter != ifaces.cend()) ? ifacesIter->humanReadableName() : QString {};
736 session->setNetworkInterface(ifaceValue);
737 session->setNetworkInterfaceName(ifaceName);
740 if (hasKey(
"current_interface_address"))
742 const QHostAddress ifaceAddress {it.value().toString().trimmed()};
743 session->setNetworkInterfaceAddress(ifaceAddress.isNull() ? QString {} : ifaceAddress.toString());
746 if (hasKey(
"save_resume_data_interval"))
747 session->setSaveResumeDataInterval(it.value().toInt());
749 if (hasKey(
"recheck_completed_torrents"))
750 pref->recheckTorrentsOnCompletion(it.value().toBool());
752 if (hasKey(
"resolve_peer_countries"))
753 pref->resolvePeerCountries(it.value().toBool());
755 if (hasKey(
"reannounce_when_address_changed"))
756 session->setReannounceWhenAddressChangedEnabled(it.value().toBool());
760 if (hasKey(
"async_io_threads"))
761 session->setAsyncIOThreads(it.value().toInt());
763 if (hasKey(
"hashing_threads"))
764 session->setHashingThreads(it.value().toInt());
766 if (hasKey(
"file_pool_size"))
767 session->setFilePoolSize(it.value().toInt());
769 if (hasKey(
"checking_memory_use"))
770 session->setCheckingMemUsage(it.value().toInt());
772 if (hasKey(
"disk_cache"))
773 session->setDiskCacheSize(it.value().toInt());
774 if (hasKey(
"disk_cache_ttl"))
775 session->setDiskCacheTTL(it.value().toInt());
777 if (hasKey(
"enable_os_cache"))
778 session->setUseOSCache(it.value().toBool());
780 if (hasKey(
"enable_coalesce_read_write"))
781 session->setCoalesceReadWriteEnabled(it.value().toBool());
783 if (hasKey(
"enable_piece_extent_affinity"))
784 session->setPieceExtentAffinity(it.value().toBool());
786 if (hasKey(
"enable_upload_suggestions"))
787 session->setSuggestMode(it.value().toBool());
789 if (hasKey(
"send_buffer_watermark"))
790 session->setSendBufferWatermark(it.value().toInt());
791 if (hasKey(
"send_buffer_low_watermark"))
792 session->setSendBufferLowWatermark(it.value().toInt());
793 if (hasKey(
"send_buffer_watermark_factor"))
794 session->setSendBufferWatermarkFactor(it.value().toInt());
796 if (hasKey(
"connection_speed"))
797 session->setConnectionSpeed(it.value().toInt());
799 if (hasKey(
"socket_backlog_size"))
800 session->setSocketBacklogSize(it.value().toInt());
802 if (hasKey(
"outgoing_ports_min"))
803 session->setOutgoingPortsMin(it.value().toInt());
804 if (hasKey(
"outgoing_ports_max"))
805 session->setOutgoingPortsMax(it.value().toInt());
807 if (hasKey(
"upnp_lease_duration"))
808 session->setUPnPLeaseDuration(it.value().toInt());
810 if (hasKey(
"peer_tos"))
811 session->setPeerToS(it.value().toInt());
813 if (hasKey(
"utp_tcp_mixed_mode"))
816 if (hasKey(
"idn_support_enabled"))
817 session->setIDNSupportEnabled(it.value().toBool());
819 if (hasKey(
"enable_multi_connections_from_same_ip"))
820 session->setMultiConnectionsPerIpEnabled(it.value().toBool());
822 if (hasKey(
"validate_https_tracker_certificate"))
823 session->setValidateHTTPSTrackerCertificate(it.value().toBool());
825 if (hasKey(
"ssrf_mitigation"))
826 session->setSSRFMitigationEnabled(it.value().toBool());
828 if (hasKey(
"block_peers_on_privileged_ports"))
829 session->setBlockPeersOnPrivilegedPorts(it.value().toBool());
831 if (hasKey(
"embedded_tracker_port"))
832 pref->setTrackerPort(it.value().toInt());
833 if (hasKey(
"enable_embedded_tracker"))
834 session->setTrackerEnabled(it.value().toBool());
836 if (hasKey(
"upload_slots_behavior"))
839 if (hasKey(
"upload_choking_algorithm"))
842 if (hasKey(
"announce_to_all_trackers"))
843 session->setAnnounceToAllTrackers(it.value().toBool());
844 if (hasKey(
"announce_to_all_tiers"))
845 session->setAnnounceToAllTiers(it.value().toBool());
846 if (hasKey(
"announce_ip"))
848 const QHostAddress announceAddr {it.value().toString().trimmed()};
849 session->setAnnounceIP(announceAddr.isNull() ? QString {} : announceAddr.toString());
851 if (hasKey(
"max_concurrent_http_announces"))
852 session->setMaxConcurrentHTTPAnnounces(it.value().toInt());
853 if (hasKey(
"stop_tracker_timeout"))
854 session->setStopTrackerTimeout(it.value().toInt());
856 if (hasKey(
"peer_turnover"))
857 session->setPeerTurnover(it.value().toInt());
858 if (hasKey(
"peer_turnover_cutoff"))
859 session->setPeerTurnoverCutoff(it.value().toInt());
860 if (hasKey(
"peer_turnover_interval"))
861 session->setPeerTurnoverInterval(it.value().toInt());
virtual void setEnabled(bool enabled)=0
void setDownloadRepacks(bool enabled)
void setSmartEpisodeFilters(const QStringList &filters)
void setProcessingEnabled(bool enabled)
void setRefreshInterval(int refreshInterval)
void setMaxArticlesPerFeed(int n)
void setProcessingEnabled(bool enabled)
static void setAutoDeleteMode(AutoDeleteMode mode)
void removeWatchedFolder(const QString &path)
static QString makeCleanPath(const QString &path)
void setWatchedFolder(const QString &path, const WatchedFolderOptions &options)
QByteArray generate(const QString &password)
T toEnum(const QString &serializedValue, const T &defaultValue)
BitTorrent::AddTorrentParams addTorrentParams