! * \brief Shows a dialog for opening a FITS file * If the returned file name is not empty (so a FITS file was selected) and it's not opened yet * then the file is parsed, so the treeview for the extensions is built and the table is filled. */
| 169 | * then the file is parsed, so the treeview for the extensions is built and the table is filled. |
| 170 | */ |
| 171 | void FITSHeaderEditWidget::openFile() { |
| 172 | KConfigGroup conf = Settings::group(QStringLiteral("FITSHeaderEditWidget")); |
| 173 | QString dir = conf.readEntry("LastDir", ""); |
| 174 | QString fileName = QFileDialog::getOpenFileName(this, i18nc("@title:window", "Open FITS File"), dir, i18n("FITS files (*.fits *.fit *.fts)")); |
| 175 | if (fileName.isEmpty()) |
| 176 | return; |
| 177 | |
| 178 | int pos = fileName.lastIndexOf(QLatin1String("/")); |
| 179 | if (pos != -1) { |
| 180 | QString newDir = fileName.left(pos); |
| 181 | if (newDir != dir) |
| 182 | conf.writeEntry("LastDir", newDir); |
| 183 | } |
| 184 | |
| 185 | WAIT_CURSOR; |
| 186 | QTreeWidgetItem* root = ui->twExtensions->invisibleRootItem(); |
| 187 | const int childCount = root->childCount(); |
| 188 | bool opened = false; |
| 189 | for (int i = 0; i < childCount; ++i) { |
| 190 | if (root->child(i)->text(0) == fileName) { |
| 191 | opened = true; |
| 192 | break; |
| 193 | } |
| 194 | } |
| 195 | if (!opened) { |
| 196 | for (QTreeWidgetItem* item : ui->twExtensions->selectedItems()) |
| 197 | item->setSelected(false); |
| 198 | m_fitsFilter->parseExtensions(fileName, ui->twExtensions); |
| 199 | ui->twExtensions->resizeColumnToContents(0); |
| 200 | if (ui->twExtensions->selectedItems().size() > 0) |
| 201 | fillTableSlot(ui->twExtensions->selectedItems().at(0), 0); |
| 202 | |
| 203 | ui->bAddKey->setEnabled(true); |
| 204 | ui->bRemoveKey->setEnabled(true); |
| 205 | ui->bAddUnit->setEnabled(true); |
| 206 | ui->bClose->setEnabled(false); |
| 207 | |
| 208 | } else { |
| 209 | KMessageBox::information(this, i18n("Cannot open file, file already opened."), i18n("File already opened")); |
| 210 | } |
| 211 | enableButtonAddUnit(); |
| 212 | RESET_CURSOR; |
| 213 | } |
| 214 | |
| 215 | /*! |
| 216 | * \brief Triggered when clicking the Save button |
nothing calls this directly
no test coverage detected