Move available translations getter to translator class
This commit is contained in:
		
							parent
							
								
									10f5e5e387
								
							
						
					
					
						commit
						295353332f
					
				@ -3,6 +3,7 @@
 | 
				
			|||||||
#include "manager.h"
 | 
					#include "manager.h"
 | 
				
			||||||
#include "runatsystemstart.h"
 | 
					#include "runatsystemstart.h"
 | 
				
			||||||
#include "tesseract.h"
 | 
					#include "tesseract.h"
 | 
				
			||||||
 | 
					#include "translator.h"
 | 
				
			||||||
#include "ui_settingseditor.h"
 | 
					#include "ui_settingseditor.h"
 | 
				
			||||||
#include "updates.h"
 | 
					#include "updates.h"
 | 
				
			||||||
#include "widgetstate.h"
 | 
					#include "widgetstate.h"
 | 
				
			||||||
@ -224,17 +225,12 @@ void SettingsEditor::updateTranslators()
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  ui->translatorList->clear();
 | 
					  ui->translatorList->clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const auto path = ui->translatorsPath->text();
 | 
					  auto names = Translator::availableTranslators(ui->translatorsPath->text());
 | 
				
			||||||
  if (path.isEmpty())
 | 
					  if (names.isEmpty())
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  QDir dir(path);
 | 
					  std::sort(names.begin(), names.end());
 | 
				
			||||||
  if (!dir.exists())
 | 
					  ui->translatorList->addItems(names);
 | 
				
			||||||
    return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  auto files = dir.entryList({"*.js"}, QDir::Files);
 | 
					 | 
				
			||||||
  std::sort(files.begin(), files.end());
 | 
					 | 
				
			||||||
  ui->translatorList->addItems(files);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  for (auto i = 0, end = ui->translatorList->count(); i < end; ++i) {
 | 
					  for (auto i = 0, end = ui->translatorList->count(); i < end; ++i) {
 | 
				
			||||||
    auto item = ui->translatorList->item(i);
 | 
					    auto item = ui->translatorList->item(i);
 | 
				
			||||||
@ -246,15 +242,12 @@ void SettingsEditor::updateTranslators()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void SettingsEditor::updateTranslationLanguages()
 | 
					void SettingsEditor::updateTranslationLanguages()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  LanguageIds names;
 | 
					 | 
				
			||||||
  LanguageCodes languages;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  for (const auto &bundle : languages.all()) {
 | 
					 | 
				
			||||||
    if (!bundle.second.iso639_1.isEmpty())
 | 
					 | 
				
			||||||
      names.append(QObject::tr(bundle.second.name));
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  ui->translateLangCombo->clear();
 | 
					  ui->translateLangCombo->clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  auto names = Translator::availableLanguageNames();
 | 
				
			||||||
 | 
					  if (names.isEmpty())
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  std::sort(names.begin(), names.end());
 | 
					  std::sort(names.begin(), names.end());
 | 
				
			||||||
  ui->translateLangCombo->addItems(names);
 | 
					  ui->translateLangCombo->addItems(names);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,6 @@
 | 
				
			|||||||
#include "translator.h"
 | 
					#include "translator.h"
 | 
				
			||||||
#include "debug.h"
 | 
					#include "debug.h"
 | 
				
			||||||
 | 
					#include "languagecodes.h"
 | 
				
			||||||
#include "manager.h"
 | 
					#include "manager.h"
 | 
				
			||||||
#include "settings.h"
 | 
					#include "settings.h"
 | 
				
			||||||
#include "task.h"
 | 
					#include "task.h"
 | 
				
			||||||
@ -8,6 +9,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <QBoxLayout>
 | 
					#include <QBoxLayout>
 | 
				
			||||||
#include <QCloseEvent>
 | 
					#include <QCloseEvent>
 | 
				
			||||||
 | 
					#include <QDir>
 | 
				
			||||||
#include <QLabel>
 | 
					#include <QLabel>
 | 
				
			||||||
#include <QLineEdit>
 | 
					#include <QLineEdit>
 | 
				
			||||||
#include <QSplitter>
 | 
					#include <QSplitter>
 | 
				
			||||||
@ -274,6 +276,32 @@ void Translator::finish(const TaskPtr &task)
 | 
				
			|||||||
  processQueue();
 | 
					  processQueue();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QStringList Translator::availableTranslators(const QString &path)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if (path.isEmpty())
 | 
				
			||||||
 | 
					    return {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  QDir dir(path);
 | 
				
			||||||
 | 
					  if (!dir.exists())
 | 
				
			||||||
 | 
					    return {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const auto names = dir.entryList({"*.js"}, QDir::Files);
 | 
				
			||||||
 | 
					  return names;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QStringList Translator::availableLanguageNames()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  QStringList names;
 | 
				
			||||||
 | 
					  LanguageCodes languages;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  for (const auto &bundle : languages.all()) {
 | 
				
			||||||
 | 
					    if (!bundle.second.iso639_1.isEmpty())
 | 
				
			||||||
 | 
					      names.append(QObject::tr(bundle.second.name));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return names;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Translator::timerEvent(QTimerEvent * /*event*/)
 | 
					void Translator::timerEvent(QTimerEvent * /*event*/)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  processQueue();
 | 
					  processQueue();
 | 
				
			||||||
 | 
				
			|||||||
@ -21,6 +21,9 @@ public:
 | 
				
			|||||||
  void updateSettings();
 | 
					  void updateSettings();
 | 
				
			||||||
  void finish(const TaskPtr &task);
 | 
					  void finish(const TaskPtr &task);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  static QStringList availableTranslators(const QString &path);
 | 
				
			||||||
 | 
					  static QStringList availableLanguageNames();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
  void timerEvent(QTimerEvent *event) override;
 | 
					  void timerEvent(QTimerEvent *event) override;
 | 
				
			||||||
  void closeEvent(QCloseEvent *event) override;
 | 
					  void closeEvent(QCloseEvent *event) override;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user