cfg.addBooleanParameter2(_PluginActive, _BaseConfigName + "." + _PluginActive, false);
cfg.addIntParameter2(_IntervalSearch, _BaseConfigName + "." + _IntervalSearch, _IntervalSearchDefault);
cfg.addStringParameter2(_ExcludeFilesRegex, _BaseConfigName + "." + _ExcludeFilesRegex, "");
BooleanParameter useLanguageOnSubTitle =
cfg.addBooleanParameter2(_UseLanguageOnSubtitle, _BaseConfigName + "." + _UseLanguageOnSubtitle, false);
String[] subTitleValues = SubTitleLanguage.getValues();
String[] subTitleLabels = SubTitleLanguage.getDescriptions();
StringListParameter languageOnSubtitle =
cfg.addStringListParameter2(_LanguageOnSubtitle, _BaseConfigName + "." + _LanguageOnSubtitle, subTitleValues, subTitleLabels, "");
useLanguageOnSubTitle.addEnabledOnSelection(languageOnSubtitle);
// Configuração dos Handlers
final List<IDownloadHandler> handlersList = SubTitleManager.getExistingHandlers();
for (IDownloadHandler handler : handlersList) {
try {
DownloadHandlerVO handlerVO = (DownloadHandlerVO) handler.getHandlerVOType().newInstance();
Method[] metodos = handlerVO.getClass().getMethods();
int paramCount = 2;
for (Method metodo : metodos)
if (metodo.getName().startsWith("set"))
paramCount++;
String nomeHandle = handler.getClass().getSimpleName();
addLocalisedMessage(localeUtil, nomeHandle, handler.getDescription());
addLocalisedMessage(localeUtil, handler.getSiteUrl(), handler.getSiteUrl());
Parameter[] parametros = new Parameter[paramCount];
parametros[0] = cfg.addHyperlinkParameter2(handler.getSiteUrl(), handler.getSiteUrl());
parametros[1] = cfg.addBooleanParameter2(nomeHandle, _BaseConfigName + ".Active", false);
paramCount = 2;
for (Method metodo : metodos) {
if (metodo.getName().startsWith("set")) {
Class<?> typeParam = metodo.getParameterTypes()[0];
String nomeProp = metodo.getName().substring(3);
String nomePropPlugin = handler.getClass().getSimpleName() + "." + nomeProp;
String resourceMessage = _BaseConfigName + "." + handlerVO.getClass().getSimpleName() + "." + nomeProp;
if ((handler.getLogonType() == IDownloadHandler.LogonType.None) &
((metodo.getName().equals("setUserName")) || (metodo.getName().equals("setPassword"))))
continue;
if (typeParam == SubTitleLanguage.class) {
// Na lista de idiomas coloco só os que o Handler suporta
SubTitleLanguage[] enumValores = handler.getSupportedLanguages();
String[] valores = SubTitleLanguage.getValues(enumValores);
String[] labels = SubTitleLanguage.getDescriptions(enumValores);
parametros[paramCount] = cfg.addStringListParameter2(nomePropPlugin, resourceMessage, valores, labels, "");
} else if (typeParam == FileUtils.SubTitleExtensions.class) {
// Na lista de extensões coloca só as que o Handler suporta
FileUtils.SubTitleExtensions[] enumValores = handler.getSupportedSubTitleExtensions();
if (enumValores.length > 0) {
String[] valores = new String[enumValores.length];
for (int j = 0; j < enumValores.length; j++)
valores[j] = enumValores[j].toString();
parametros[paramCount] = cfg.addStringListParameter2(nomePropPlugin, resourceMessage, valores, "");
}
} else if (typeParam == int.class) {
parametros[paramCount] = cfg.addIntParameter2(nomePropPlugin, resourceMessage, 0);
} else if (typeParam == String.class) {
if (nomeProp.equalsIgnoreCase("Password"))
parametros[paramCount] = cfg.addPasswordParameter2(nomePropPlugin, resourceMessage, PasswordParameter.ET_PLAIN, new byte[0]);
else
parametros[paramCount] = cfg.addStringParameter2(nomePropPlugin, resourceMessage, "");
} else if (typeParam.isEnum()) {
Object[] enumValores = typeParam.getEnumConstants();
String[] valores = new String[enumValores.length];
for (int j = 0; j < enumValores.length; j++)
valores[j] = enumValores[j].toString();
parametros[paramCount] = cfg.addStringListParameter2(nomePropPlugin, resourceMessage, valores, "");
}
((BooleanParameter) parametros[1]).addEnabledOnSelection(parametros[paramCount]);
paramCount++;
}
}
cfg.createGroup(nomeHandle, parametros);
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
// Configuração das Categorias
String[] existingCategories = getExistingCategories(pluginInterface);
Parameter[] parametros = new Parameter[existingCategories.length];
BooleanParameter paramCatAll = cfg.addBooleanParameter2(_CategoryAll, _BaseConfigName + "." + _CategoryAll, true);
int paramCount = 0;
for (String category : existingCategories) {
String nomeCfgCategory = _CategoryList + "." + category;
String nomeResMessage = _BaseConfigName + "." + nomeCfgCategory;
addLocalisedMessage(localeUtil, nomeResMessage, category);
parametros[paramCount] = cfg.addBooleanParameter2(nomeCfgCategory, nomeResMessage, false);
paramCatAll.addDisabledOnSelection(parametros[paramCount]);
paramCount++;
}
cfg.createGroup(_BaseConfigName + "." + _CategoryList, parametros);
}