Check file using CutterCore::tryFile() instead of QFileInfo

This commit is contained in:
Florian Märkl 2018-01-07 11:58:37 +01:00
parent ec7cef1394
commit 266402095f
3 changed files with 16 additions and 22 deletions

View File

@ -414,7 +414,6 @@ bool CutterCore::tryFile(QString path, bool rw)
cf = r_core_file_open(this->core_, path.toUtf8().constData(), flags, 0LL); cf = r_core_file_open(this->core_, path.toUtf8().constData(), flags, 0LL);
if (!cf) if (!cf)
{ {
eprintf("QRCore::tryFile: Cannot open file?\n");
return false; return false;
} }

View File

@ -305,32 +305,29 @@ bool NewFileDialog::fillProjectsList()
void NewFileDialog::loadFile(const QString &filename) void NewFileDialog::loadFile(const QString &filename)
{ {
// Check that there is a file selected if(!Core()->tryFile(filename, false))
QFileInfo checkfile(filename);
if (!checkfile.exists() || !checkfile.isFile())
{ {
QMessageBox msgBox(this); QMessageBox msgBox(this);
msgBox.setText(tr("Select a new program or a previous one\nbefore continuing")); msgBox.setText(tr("Select a new program or a previous one before continuing."));
msgBox.exec(); msgBox.exec();
return;
} }
else
{
// Add file to recent file list
QSettings settings;
QStringList files = settings.value("recentFileList").toStringList();
files.removeAll(filename);
files.prepend(filename);
while (files.size() > MaxRecentFiles)
files.removeLast();
settings.setValue("recentFileList", files); // Add file to recent file list
QSettings settings;
QStringList files = settings.value("recentFileList").toStringList();
files.removeAll(filename);
files.prepend(filename);
while (files.size() > MaxRecentFiles)
files.removeLast();
// Close dialog and open MainWindow/OptionsDialog settings.setValue("recentFileList", files);
MainWindow *main = new MainWindow();
main->openNewFile(filename);
close(); // Close dialog and open MainWindow/OptionsDialog
} MainWindow *main = new MainWindow();
main->openNewFile(filename);
close();
} }
void NewFileDialog::loadProject(const QString &project) void NewFileDialog::loadProject(const QString &project)

View File

@ -67,8 +67,6 @@ OptionsDialog::OptionsDialog(MainWindow *main):
connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(reject())); connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
ui->programLineEdit->setText(main->getFilename()); ui->programLineEdit->setText(main->getFilename());
QFileInfo fi(this->main->getFilename());
this->core->tryFile(fi.filePath(), fi.isWritable());
} }
OptionsDialog::~OptionsDialog() {} OptionsDialog::~OptionsDialog() {}