Source Code (Use browser search to find items of interest.)

Class Index

kab'Kab1Importer (./kdeutils/kab/kab_kab1importer.h:36)

class Kab1Importer : public KDialogBase
{
  Q_OBJECT
public:
  Kab1Importer(KabAPI*, QWidget* parent=0);
  int exec();
protected:
  bool importKab1Addressbook();
  QMultiLineEdit *log;
  KabAPI *api;
  signals:
  void setStatus(const QString&);
};

kab'Kab1Importer::Kab1Importer() (./kdeutils/kab/kab_kab1importer.cc:222)

Kab1Importer::Kab1Importer(KabAPI* api_, QWidget* parent)
  : KDialogBase(parent),
    log(new QMultiLineEdit(this)),
    api(api_)
{
  log->setReadOnly(true);
  log->setWordWrap(QMultiLineEdit::WidgetWidth);
  showButtonApply(false);
  showButtonCancel(false);
}


kab'Kab1Importer::exec() (./kdeutils/kab/kab_kab1importer.cc:233)

int Kab1Importer::exec()
{
  if(importKab1Addressbook())
    {
      log->setMinimumSize(2*log->sizeHint().width(), 2*log->sizeHint().height());
      setMainWidget(log);
      resize(minimumSize());
      log->setCursorPosition(log->numLines(), 0);
      emit(setStatus(i18n("Imported kab 1 addressbook.")));
      return KDialogBase::exec();
    } else {
      emit(setStatus(i18n("Rejected.")));
      return 0;
    }
}


kab'Kab1Importer::importKab1Addressbook() (./kdeutils/kab/kab_kab1importer.cc:249)

bool Kab1Importer::importKab1Addressbook()
{
  bool GUARD; GUARD=true;
  const QCString OldEntriesSection="Entries";
  const QString OldLocalKDEDIR="/.kde/";
  const QString OldLocalKabDir="share/apps/kab/";
  const QString OldDatabaseFilename="addressbook.database";
  const QString OldFilename=QDir::homeDirPath()
    +OldLocalKDEDIR+OldLocalKabDir+OldDatabaseFilename;
  log->insertLine("Importing KDE 1 addressbook.\nYou should not do this more "
		  "than once with the same file.");
  log->insertLine(QString("Filename to import is\n  ")+OldFilename+QString("."));
  QConfigDB database;
  Section *entriesSection;
  Section::StringSectionMap::iterator it;
  QString temp;
  KabKey key;
  AddressBook::Entry entry;
  list<AddressBook::Entry> entries;
  list<AddressBook::Entry>::iterator pos;
  list<AddressBook::Entry>::iterator next;
  bool errors=false;
  // ----- find the file, load it into a QConfigDB object:
  if(database.setFileName(OldFilename, true, true))
    {
      log->insertLine("File opened (no errors).\n  Directory exists. "
		     "File exists.");
    } else {
      log->insertLine("Cannot access the database file. "
		     "You probably never used kab 1.");
      KMessageBox::information
	(this, i18n("Could not access the kab 1 database file.\n"
		    "You most probably never used kab 1."),
	 i18n("Error"));
      return false;
    }
  kDebugInfo(GUARD, 0, "TopLevelWidget::importKab1Addressbook: file found.");
  if(database.load())
    {
      log->insertLine("File read (no errors). "
		     "Database syntax seems to be correct.");
    } else {
      log->insertLine("Database could not be read (syntax error). "
		     "You probably modified your database file manually.");
      KMessageBox::information
	(this, i18n("Could not read the kab 1 database file.\n"
		    "You probably modified your database file manually."),
	 i18n("Error"));
      return false;
    }
  kDebugInfo(GUARD, 0, "TopLevelWidget::importKab1Addressbook: file loaded.");
  // ----- get the pointer to the entries section:
  if(database.get(OldEntriesSection, entriesSection))
    {
      log->insertLine("Entries section found (no errors). "
		     "Database structure seems to be correct.");
    } else {
      log->insertLine("Entries section not found (database structure error)."
		     " You probably modified your database file manually.");
      KMessageBox::information
	(this, i18n("Could not find the entries section in your database.\n"
		    "You probably modified your database file manually."),
	 i18n("Error"));
      return false;
    }
  kDebugInfo(GUARD, 0, "TopLevelWidget::importKab1Addressbook: got entries section.");
  // ----- iterate over "entries" section, creating AddressBook::Entry objects:
  for(it=entriesSection->sectionsBegin(); it!=entriesSection->sectionsEnd();
      ++it)
    {
      temp="Parsing entry ";
      temp+=(*it).first;
      log->insertLine(temp);
      if(makeEntryFromKab1Section((*it).second, entry))
	{
	  api->addressbook()->literalName(entry, temp, true, false);
	  entries.push_back(entry);
	  temp="  Done, no errors (Entry "+temp+").";
	  log->insertLine(temp);
	} else {
	  log->insertLine("  Error. Section could not be parsed as an entry.");
	  errors=true;
	}
    }
  kDebugInfo(GUARD, 0, "TopLevelWidget::importKab1Addressbook: parsed entries.");
  // ----- query the user to really add the entries:
  if(errors)
    {
      temp=i18n("Warning: There where errors importing the KDE 1\n"
		"address database.\n\n");
    } else {
      temp="";
    }
  temp+=i18n("Do you really want to add the entries of your KDE 1\n"
	   "address book to this file?\n"
	    "You will not be able to revert this changes.");
  if(entries.size()>0)
    {
      if(KMessageBox::warningYesNo
	 (this, temp, i18n("Continue"))==KMessageBox::Yes)
	{
	  // ----- do it:
	  log->insertLine("Adding entries to the database.");
	  for(pos=entries.begin(); pos!=entries.end(); ++pos)
	    {
	      api->addressbook()->literalName((*pos), temp, true, false);
	      next=pos;
	      ++next;
	      if(api->add(*pos, key, next==entries.end() ? true : false)
		 !=AddressBook::NoError)
		{
		  temp=QString("  Error: could not add entry ")+temp
		    +".";
		} else {
		  temp=QString("  Success: added entry ")+temp
		    +" to the database (key ";
		  temp+=key.getKey()+").";
		}
	      log->insertLine(temp);
	    }
	  kDebugInfo(GUARD, 0, "TopLevelWidget::importKab1Addressbook: "
	     "added entries, database now holds %i entries.",
	     api->addressbook()->noOfEntries());
	  // ----- now save the database:
	  if(api->save(true)==AddressBook::NoError)
	    {
	      log->insertLine("Database saved successfully.");
	    } else {
	      log->insertLine("Error: could not save database. Possibly "
			      "permission denied.");
	    }
	} else {
	  log->insertLine("Aborted. Entries of the kab 1 address database will"
			  "  not be added to this file.");
	}
    } else {
      log->insertLine("There are no entries in the kab 1 database.");
    }
  // ----- report the results:
  log->insertLine("\n\n-----------\n\nDone. Please read the message above.");
  kDebugInfo(GUARD, 0, "TopLevelWidget::importKab1Addressbook: done.");
  return true;
}