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" |                                   "%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\" " |                                   "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" |                                   "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); |                                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 | ||||||
|                                       "use global package folder because that requires administrator rights, therefore by default " |     ->setHelpText(tr("%1 automatically installs some Node.js packages so that you do not have to. %1 does not " | ||||||
|                                       "it uses subfolder placed in your \"user data\" folder.").arg(APP_NAME), |                      "use global package folder because that requires administrator rights, therefore by default " | ||||||
|                                    false); |                      "it uses subfolder placed in your \"user data\" folder.") | ||||||
|  |                     .arg(APP_NAME), | ||||||
|  |                   false); | ||||||
| 
 | 
 | ||||||
|   connect(m_ui.m_btnDownloadNodejs, &QPushButton::clicked, |   connect(m_ui.m_btnDownloadNodejs, &QPushButton::clicked, this, [this]() { | ||||||
|           this, [this]() { |  | ||||||
|     qApp->web()->openUrlInExternalBrowser(QSL("https://nodejs.org/en/download/")); |     qApp->web()->openUrlInExternalBrowser(QSL("https://nodejs.org/en/download/")); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   connect(m_ui.m_tbNodeExecutable->lineEdit(), &BaseLineEdit::textChanged, |   connect(m_ui.m_tbNodeExecutable->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsNodejs::testNodejs); | ||||||
|           this, &SettingsNodejs::testNodejs); |   connect(m_ui.m_tbNpmExecutable->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsNodejs::testNpm); | ||||||
|   connect(m_ui.m_tbNpmExecutable->lineEdit(), &BaseLineEdit::textChanged, |   connect(m_ui.m_tbPackageFolder->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsNodejs::testPackageFolder); | ||||||
|           this, &SettingsNodejs::testNpm); |  | ||||||
|   connect(m_ui.m_tbPackageFolder->lineEdit(), &BaseLineEdit::textChanged, |  | ||||||
|           this, &SettingsNodejs::testPackageFolder); |  | ||||||
| 
 | 
 | ||||||
|   connect(m_ui.m_tbNodeExecutable->lineEdit(), &BaseLineEdit::textChanged, |   connect(m_ui.m_tbNodeExecutable->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsNodejs::dirtifySettings); | ||||||
|           this, &SettingsNodejs::dirtifySettings); |   connect(m_ui.m_tbNpmExecutable->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsNodejs::dirtifySettings); | ||||||
|   connect(m_ui.m_tbNpmExecutable->lineEdit(), &BaseLineEdit::textChanged, |   connect(m_ui.m_tbPackageFolder->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsNodejs::dirtifySettings); | ||||||
|           this, &SettingsNodejs::dirtifySettings); |  | ||||||
|   connect(m_ui.m_tbPackageFolder->lineEdit(), &BaseLineEdit::textChanged, |  | ||||||
|           this, &SettingsNodejs::dirtifySettings); |  | ||||||
| 
 | 
 | ||||||
|   connect(m_ui.m_btnPackageFolder, &QPushButton::clicked, this, [this]() { |   connect(m_ui.m_btnPackageFolder, &QPushButton::clicked, this, [this]() { | ||||||
|     changeFileFolder(m_ui.m_tbPackageFolder, true); |     changeFileFolder(m_ui.m_tbPackageFolder, true); | ||||||
|  | @ -111,8 +107,7 @@ void SettingsNodejs::testNodejs() { | ||||||
|                                        tr("Node.js has version %1.").arg(node_version)); |                                        tr("Node.js has version %1.").arg(node_version)); | ||||||
|   } |   } | ||||||
|   catch (const ApplicationException& ex) { |   catch (const ApplicationException& ex) { | ||||||
|     m_ui.m_tbNodeExecutable->setStatus(WidgetWithStatus::StatusType::Error, |     m_ui.m_tbNodeExecutable->setStatus(WidgetWithStatus::StatusType::Error, tr("Node.js: %1.").arg(ex.message())); | ||||||
|                                        tr("Node.js: %1.").arg(ex.message())); |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -120,20 +115,33 @@ void SettingsNodejs::testNpm() { | ||||||
|   try { |   try { | ||||||
|     QString npm_version = qApp->nodejs()->npmVersion(m_ui.m_tbNpmExecutable->lineEdit()->text()); |     QString npm_version = qApp->nodejs()->npmVersion(m_ui.m_tbNpmExecutable->lineEdit()->text()); | ||||||
| 
 | 
 | ||||||
|     m_ui.m_tbNpmExecutable->setStatus(WidgetWithStatus::StatusType::Ok, |     m_ui.m_tbNpmExecutable->setStatus(WidgetWithStatus::StatusType::Ok, tr("NPM has version %1.").arg(npm_version)); | ||||||
|                                       tr("NPM has version %1.").arg(npm_version)); |  | ||||||
|   } |   } | ||||||
|   catch (const ApplicationException& ex) { |   catch (const ApplicationException& ex) { | ||||||
|     m_ui.m_tbNpmExecutable->setStatus(WidgetWithStatus::StatusType::Error, |     m_ui.m_tbNpmExecutable->setStatus(WidgetWithStatus::StatusType::Error, tr("NPM: %1.").arg(ex.message())); | ||||||
|                                       tr("NPM: %1.").arg(ex.message())); |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void SettingsNodejs::testPackageFolder() { | void SettingsNodejs::testPackageFolder() { | ||||||
|   QString folder = qApp->replaceDataUserDataFolderPlaceholder(m_ui.m_tbPackageFolder->lineEdit()->text()); |   QString folder = qApp->replaceDataUserDataFolderPlaceholder(m_ui.m_tbPackageFolder->lineEdit()->text()); | ||||||
| 
 | 
 | ||||||
|   m_ui.m_tbPackageFolder->setStatus(WidgetWithStatus::StatusType::Ok, |   const auto fi = QFileInfo(folder); | ||||||
|                                     QDir().exists(folder) |   const auto is_file = fi.isFile() && fi.exists(); | ||||||
|                                     ? tr("Package folder is OK.") |   QString desc; | ||||||
|                                     : tr("Package folder will be created!")); |   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