show error when selecting file as package folder in nodejs settings
This commit is contained in:
		
							parent
							
								
									34ff686ca4
								
							
						
					
					
						commit
						7910bde52d
					
				
					 1 changed files with 37 additions and 29 deletions
				
			
		|  | @ -20,32 +20,28 @@ SettingsNodejs::SettingsNodejs(Settings* settings, QWidget* parent) : SettingsPa | |||
|                                   "%1 integrates Node.js to bring some modern features like Adblock.\n\n" | ||||
|                                   "Note that usually all required Node.js tools should be available via your \"PATH\" " | ||||
|                                   "environment variable, so you do not have to specify full paths.\n\n" | ||||
|                                   "Also, relaunch \"Settings\" dialog after you install Node.js.").arg(APP_NAME), | ||||
|                                   "Also, relaunch \"Settings\" dialog after you install Node.js.") | ||||
|                                  .arg(APP_NAME), | ||||
|                                false); | ||||
| 
 | ||||
|   m_ui.m_helpPackages->setHelpText(tr("%1 automatically installs some Node.js packages so that you do not have to. %1 does not " | ||||
|   m_ui.m_helpPackages | ||||
|     ->setHelpText(tr("%1 automatically installs some Node.js packages so that you do not have to. %1 does not " | ||||
|                      "use global package folder because that requires administrator rights, therefore by default " | ||||
|                                       "it uses subfolder placed in your \"user data\" folder.").arg(APP_NAME), | ||||
|                      "it uses subfolder placed in your \"user data\" folder.") | ||||
|                     .arg(APP_NAME), | ||||
|                   false); | ||||
| 
 | ||||
|   connect(m_ui.m_btnDownloadNodejs, &QPushButton::clicked, | ||||
|           this, [this]() { | ||||
|   connect(m_ui.m_btnDownloadNodejs, &QPushButton::clicked, this, [this]() { | ||||
|     qApp->web()->openUrlInExternalBrowser(QSL("https://nodejs.org/en/download/")); | ||||
|   }); | ||||
| 
 | ||||
|   connect(m_ui.m_tbNodeExecutable->lineEdit(), &BaseLineEdit::textChanged, | ||||
|           this, &SettingsNodejs::testNodejs); | ||||
|   connect(m_ui.m_tbNpmExecutable->lineEdit(), &BaseLineEdit::textChanged, | ||||
|           this, &SettingsNodejs::testNpm); | ||||
|   connect(m_ui.m_tbPackageFolder->lineEdit(), &BaseLineEdit::textChanged, | ||||
|           this, &SettingsNodejs::testPackageFolder); | ||||
|   connect(m_ui.m_tbNodeExecutable->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsNodejs::testNodejs); | ||||
|   connect(m_ui.m_tbNpmExecutable->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsNodejs::testNpm); | ||||
|   connect(m_ui.m_tbPackageFolder->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsNodejs::testPackageFolder); | ||||
| 
 | ||||
|   connect(m_ui.m_tbNodeExecutable->lineEdit(), &BaseLineEdit::textChanged, | ||||
|           this, &SettingsNodejs::dirtifySettings); | ||||
|   connect(m_ui.m_tbNpmExecutable->lineEdit(), &BaseLineEdit::textChanged, | ||||
|           this, &SettingsNodejs::dirtifySettings); | ||||
|   connect(m_ui.m_tbPackageFolder->lineEdit(), &BaseLineEdit::textChanged, | ||||
|           this, &SettingsNodejs::dirtifySettings); | ||||
|   connect(m_ui.m_tbNodeExecutable->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsNodejs::dirtifySettings); | ||||
|   connect(m_ui.m_tbNpmExecutable->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsNodejs::dirtifySettings); | ||||
|   connect(m_ui.m_tbPackageFolder->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsNodejs::dirtifySettings); | ||||
| 
 | ||||
|   connect(m_ui.m_btnPackageFolder, &QPushButton::clicked, this, [this]() { | ||||
|     changeFileFolder(m_ui.m_tbPackageFolder, true); | ||||
|  | @ -111,8 +107,7 @@ void SettingsNodejs::testNodejs() { | |||
|                                        tr("Node.js has version %1.").arg(node_version)); | ||||
|   } | ||||
|   catch (const ApplicationException& ex) { | ||||
|     m_ui.m_tbNodeExecutable->setStatus(WidgetWithStatus::StatusType::Error, | ||||
|                                        tr("Node.js: %1.").arg(ex.message())); | ||||
|     m_ui.m_tbNodeExecutable->setStatus(WidgetWithStatus::StatusType::Error, tr("Node.js: %1.").arg(ex.message())); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
|  | @ -120,20 +115,33 @@ void SettingsNodejs::testNpm() { | |||
|   try { | ||||
|     QString npm_version = qApp->nodejs()->npmVersion(m_ui.m_tbNpmExecutable->lineEdit()->text()); | ||||
| 
 | ||||
|     m_ui.m_tbNpmExecutable->setStatus(WidgetWithStatus::StatusType::Ok, | ||||
|                                       tr("NPM has version %1.").arg(npm_version)); | ||||
|     m_ui.m_tbNpmExecutable->setStatus(WidgetWithStatus::StatusType::Ok, tr("NPM has version %1.").arg(npm_version)); | ||||
|   } | ||||
|   catch (const ApplicationException& ex) { | ||||
|     m_ui.m_tbNpmExecutable->setStatus(WidgetWithStatus::StatusType::Error, | ||||
|                                       tr("NPM: %1.").arg(ex.message())); | ||||
|     m_ui.m_tbNpmExecutable->setStatus(WidgetWithStatus::StatusType::Error, tr("NPM: %1.").arg(ex.message())); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void SettingsNodejs::testPackageFolder() { | ||||
|   QString folder = qApp->replaceDataUserDataFolderPlaceholder(m_ui.m_tbPackageFolder->lineEdit()->text()); | ||||
| 
 | ||||
|   m_ui.m_tbPackageFolder->setStatus(WidgetWithStatus::StatusType::Ok, | ||||
|                                     QDir().exists(folder) | ||||
|                                     ? tr("Package folder is OK.") | ||||
|                                     : tr("Package folder will be created!")); | ||||
|   const auto fi = QFileInfo(folder); | ||||
|   const auto is_file = fi.isFile() && fi.exists(); | ||||
|   QString desc; | ||||
|   WidgetWithStatus::StatusType stat; | ||||
| 
 | ||||
|   if (is_file) { | ||||
|     stat = WidgetWithStatus::StatusType::Error; | ||||
|     desc = tr("You cannot choose file, you have to choose FOLDER."); | ||||
|   } | ||||
|   else if (QDir().exists(folder)) { | ||||
|     stat = WidgetWithStatus::StatusType::Ok; | ||||
|     desc = tr("Package folder is OK."); | ||||
|   } | ||||
|   else { | ||||
|     stat = WidgetWithStatus::StatusType::Ok; | ||||
|     desc = tr("Package folder will be created!"); | ||||
|   } | ||||
| 
 | ||||
|   m_ui.m_tbPackageFolder->setStatus(stat, desc); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue