Fix relative paths for evidence image and mounted base folders (#757)
* Fix adding mounted folders not using relative path if the chosen folder is inside the application folder Fix evidence relative pathing not being aware of mounted base folders, and fix default evidence folder being in base/evidence rather than first found "evidence" folder * more braces Co-authored-by: stonedDiscord <Tukz@gmx.de>
This commit is contained in:
		
							parent
							
								
									06db93bd0d
								
							
						
					
					
						commit
						b8a5deeaae
					
				@ -971,12 +971,18 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app)
 | 
			
		||||
  ui_mount_add->setSizePolicy(stretch_btns);
 | 
			
		||||
  ui_mount_buttons_layout->addWidget(ui_mount_add, 0, 0, 1, 1);
 | 
			
		||||
  connect(ui_mount_add, &QPushButton::clicked, this, [this] {
 | 
			
		||||
    QString dir = QFileDialog::getExistingDirectory(this, tr("Select a base folder"),
 | 
			
		||||
    QString path = QFileDialog::getExistingDirectory(this, tr("Select a base folder"),
 | 
			
		||||
                                                    QApplication::applicationDirPath(),
 | 
			
		||||
                                                    QFileDialog::ShowDirsOnly);
 | 
			
		||||
    if (dir.isEmpty())
 | 
			
		||||
    if (path.isEmpty()) {
 | 
			
		||||
      return;
 | 
			
		||||
    QListWidgetItem *dir_item = new QListWidgetItem(dir);
 | 
			
		||||
    }
 | 
			
		||||
    QDir dir(QApplication::applicationDirPath());
 | 
			
		||||
    QString relative = dir.relativeFilePath(path);
 | 
			
		||||
    if (!relative.contains("../")) {
 | 
			
		||||
      path = relative;
 | 
			
		||||
    }
 | 
			
		||||
    QListWidgetItem *dir_item = new QListWidgetItem(path);
 | 
			
		||||
    ui_mount_list->addItem(dir_item);
 | 
			
		||||
    ui_mount_list->setCurrentItem(dir_item);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -397,7 +397,7 @@ void Courtroom::on_evidence_image_name_edited()
 | 
			
		||||
 | 
			
		||||
void Courtroom::on_evidence_image_button_clicked()
 | 
			
		||||
{
 | 
			
		||||
  QDir dir(ao_app->get_base_path() + "evidence");
 | 
			
		||||
  QDir dir(ao_app->get_real_path(ao_app->get_evidence_path("")));
 | 
			
		||||
  QFileDialog dialog(this);
 | 
			
		||||
  dialog.setFileMode(QFileDialog::ExistingFile);
 | 
			
		||||
  dialog.setNameFilter(tr("Images (*.png)"));
 | 
			
		||||
@ -413,6 +413,15 @@ void Courtroom::on_evidence_image_button_clicked()
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  QString filename = filenames.at(0);
 | 
			
		||||
  QStringList bases = ao_app->get_mount_paths();
 | 
			
		||||
  bases.prepend(ao_app->get_base_path());
 | 
			
		||||
  for (const QString &base : bases) {
 | 
			
		||||
    QDir baseDir(base);
 | 
			
		||||
    if (filename.startsWith(baseDir.absolutePath())) {
 | 
			
		||||
      dir.setPath(baseDir.absolutePath() + "/evidence");
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  filename = dir.relativeFilePath(filename);
 | 
			
		||||
  ui_evidence_image_name->setText(filename);
 | 
			
		||||
  on_evidence_image_name_edited();
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user