Logo Search packages:      
Sourcecode: tellico version File versions

void MainWindow::slotFileImport ( int  format  )  [slot]

Imports data.

Parameters:
format The import format

Definition at line 1764 of file mainwindow.cpp.

References Tellico::ImportDialog::action(), Tellico::LineEditAction::clear(), Tellico::ImportDialog::collection(), Tellico::EntryEditDialog::queryModified(), slotEnableModifiedActions(), slotEnableOpenedActions(), slotStatusMsg(), slotUpdateFractionDone(), Tellico::ImportDialog::statusMessage(), and Tellico::Data::Collection::type().

Referenced by initActions().

                                           {
  slotStatusMsg(i18n("Importing data..."));
  m_quickFilter->clear();

  Import::Format format = static_cast<Import::Format>(format_);
  bool checkURL = true;
  KURL url;
  switch(ImportDialog::importTarget(format)) {
    case Import::File:
      url = KFileDialog::getOpenURL(QString::fromLatin1(":import"), ImportDialog::fileFilter(format),
                                    this, i18n("Import File..."));
      break;

    case Import::Dir:
      // TODO: allow remote audiofile importing
      url.setPath(KFileDialog::getExistingDirectory(QString::fromLatin1(":import"),
                                                    this, i18n("Import File...")));
      break;

    case Import::None:
    default:
      checkURL = false;
      break;
  }

  if(checkURL) {
    bool ok = !url.isEmpty() && url.isValid();
#if KDE_IS_VERSION(3,1,90)
    ok &= KIO::NetAccess::exists(url, true, this);
#else
    ok &= KIO::NetAccess::exists(url, true);
#endif
    if(!ok) {
      slotStatusMsg(i18n(ready));
      return;
    }
  }

  ImportDialog dlg(format, url, this, "importdlg");
  if(dlg.exec() != QDialog::Accepted) {
    slotStatusMsg(i18n(ready));
    return;
  }

  bool failed = false;
//  if edit dialog is saved ok and if replacing, then the doc is saved ok
  if(m_editDialog->queryModified() &&
     (dlg.action() != Import::Replace || Kernel::self()->doc()->saveModified())) {
    kapp->setOverrideCursor(Qt::waitCursor);
    Data::Collection* coll = dlg.collection();
    if(!coll) {
      kapp->restoreOverrideCursor();
      if(!dlg.statusMessage().isEmpty()) {
        KMessageBox::sorry(this, dlg.statusMessage());
      }
      slotStatusMsg(i18n(ready));
      return;
    }

    switch(dlg.action()) {
      case Import::Append:
        // only append if match, but special case importing books into bibliographies
        if(Kernel::self()->collection()->type() == coll->type()
           || (Kernel::self()->collection()->type() == Data::Collection::Bibtex && coll->type() == Data::Collection::Book)) {
          Kernel::self()->doc()->appendCollection(coll);
          slotEnableModifiedActions(true);
        } else {
          KMessageBox::sorry(this, i18n("Only collections with the same type of entries as the current "
                                        "one can be appended. No changes are being made to the current "
                                        "collection"));
          failed = true;
        }
        delete coll;
        break;

      case Import::Merge:
        // only merge if match, but special case importing books into bibliographies
        if(Kernel::self()->collection()->type() == coll->type()
           || (Kernel::self()->collection()->type() == Data::Collection::Bibtex && coll->type() == Data::Collection::Book)) {
          Kernel::self()->doc()->mergeCollection(coll);
          slotEnableModifiedActions(true);
        } else {
          KMessageBox::sorry(this, i18n("Only collections with the same type of entries as the current "
                                        "one can be merged. No changes are being made to the current "
                                        "collection"));
          failed = true;
        }
        delete coll;
        break;

      default: // replace
        Kernel::self()->doc()->replaceCollection(coll);
        m_fileOpenRecent->setCurrentItem(-1);
        m_newDocument = true;
        slotEnableOpenedActions();
        slotEnableModifiedActions(false);
    }
    kapp->restoreOverrideCursor();
  }

  if(failed) {
    // The progress bar is hidden by the Controller when a new collection is added
    // that doesn't happen here, so need to clear it
    m_currentStep = m_maxSteps;
    slotUpdateFractionDone(1.0);
    m_currentStep = 1;
  }
  slotStatusMsg(i18n(ready));
}


Generated by  Doxygen 1.6.0   Back to index