/* kpalmdoc_dlg.cpp ** ** Copyright (C) 2003 by Reinhold Kainhofer ** ** This is the main dialog of the KDE PalmDOC converter. */ /* ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program in a file called COPYING; if not, write to ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, ** MA 02110-1301, USA. */ /* ** Bug reports and questions can be sent to kde-pim@kde.org */ #include "options.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kpalmdoc_dlg.h" #include "kpalmdoc_dlgbase.h" #include "DOC-converter.h" #include "kpalmdocSettings.h" ConverterDlg::ConverterDlg( TQWidget *parent, const TQString& caption) : KDialogBase( parent, "converterdialog", false, caption, KDialogBase::Close|KDialogBase::Help|KDialogBase::User1, KDialogBase::Close, true, i18n("&About")) { TQWidget *page = makeHBoxMainWidget(); dlg=new ConverterDlgBase(page); TQStringList l = TDEGlobal::charsets()->descriptiveEncodingNames(); for ( TQStringList::Iterator it = l.begin(); it != l.end(); ++it) { dlg->fEncoding->insertItem(*it); } setHelp("conduit-palmdoc", "kpilot/config-conduits.html"); readSettings(); connect(dlg->fDirectories, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotDirectories(bool))); connect(dlg->fTextToPDB, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotToPDB())); connect(dlg->fPDBToText, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotToText())); resize(minimumSize()); } ConverterDlg::~ConverterDlg() { // no need to delete child widgets, TQt does it all for us } void ConverterDlg::writeSettings() { // General page KPalmDocSettings::setTXTFolder( dlg->fTXTDir->url() ); KPalmDocSettings::setPDBFolder( dlg->fPDBDir->url() ); KPalmDocSettings::setSyncFolders( dlg->fDirectories->isChecked() ); KPalmDocSettings::setAskOverwrite( dlg->fAskOverwrite->isChecked() ); KPalmDocSettings::setVerboseMessages( dlg->fVerbose->isChecked() ); KPalmDocSettings::setEncoding( dlg->fEncoding->currentText() ); // PC->Handheld page KPalmDocSettings::setCompress( dlg->fCompress->isChecked() ); KPalmDocSettings::setConvertBookmarks( dlg->fConvertBookmarks->isChecked() ); KPalmDocSettings::setBookmarksInline( dlg->fBookmarksInline->isChecked() ); KPalmDocSettings::setBookmarksEndtags( dlg->fBookmarksEndtags->isChecked() ); KPalmDocSettings::setBookmarksBmk( dlg->fBookmarksBmk->isChecked() ); // Handheld->PC page KPalmDocSettings::setBookmarksToPC( dlg->fPCBookmarks->id(dlg->fPCBookmarks->selected()) ); KPalmDocSettings::self()->writeConfig(); } void ConverterDlg::readSettings() { FUNCTIONSETUP; KPalmDocSettings::self()->readConfig(); // General Page: dlg->fTXTDir->setURL(KPalmDocSettings::tXTFolder()); dlg->fPDBDir->setURL(KPalmDocSettings::pDBFolder()); bool dir=KPalmDocSettings::syncFolders(); dlg->fDirectories->setChecked(dir); slotDirectories(dir); dlg->fAskOverwrite->setChecked( KPalmDocSettings::askOverwrite() ); dlg->fVerbose->setChecked( KPalmDocSettings::verboseMessages() ); TQString encoding = KPalmDocSettings::encoding(); #ifdef DEBUG DEBUGKPILOT << fname << ": Encoding=" << encoding << endl; #endif dlg->fEncoding->setCurrentText( KPalmDocSettings::encoding() ); // PC->Handheld page dlg->fCompress->setChecked(KPalmDocSettings::compress() ); dlg->fConvertBookmarks->setChecked(KPalmDocSettings::convertBookmarks()); dlg->fBookmarksInline->setChecked(KPalmDocSettings::bookmarksInline()); dlg->fBookmarksEndtags->setChecked(KPalmDocSettings::bookmarksEndtags()); dlg->fBookmarksBmk->setChecked(KPalmDocSettings::bookmarksBmk()); // Handheld->PC page dlg->fPCBookmarks->setButton(KPalmDocSettings::bookmarksToPC() ); } void ConverterDlg::slotClose() { writeSettings(); kapp->quit(); delete this; } void ConverterDlg::slotToText() { FUNCTIONSETUP; // First, get the settings from the controls and initialize // the converter object int bmks=dlg->fPCBookmarks->id(dlg->fPCBookmarks->selected()); DOCConverter conv; switch(bmks) { case 0: conv.setBookmarkTypes(DOCConverter::eBmkNone); break; case 1: conv.setBookmarkTypes(DOCConverter::eBmkInline); break; case 2: conv.setBookmarkTypes(DOCConverter::eBmkEndtags); break; case 3: conv.setBookmarkTypes(DOCConverter::eBmkDefaultBmkFile); break; default: break; } askOverwrite=dlg->fAskOverwrite->isChecked(); verbose=dlg->fVerbose->isChecked(); bool dir=dlg->fDirectories->isChecked(); TQString txturl=dlg->fTXTDir->url(); TQString pdburl=dlg->fPDBDir->url(); TQFileInfo txtinfo(txturl); TQFileInfo pdbinfo(pdburl); if (dir) { if (pdbinfo.isFile()) { int res=KMessageBox::questionYesNo(this, i18n("You selected to sync folders, " "but gave a filename instead (%1)." "
Use folder %2 instead?
").arg(pdburl) .arg(pdbinfo.dirPath(true)), TQString(), i18n("Use Folder"), KStdGuiItem::cancel()); if (res==KMessageBox::Yes) { pdburl=pdbinfo.dirPath(true); pdbinfo.setFile(pdburl); } else return; } if (!pdbinfo.isDir()) { // no directory, so error message and return KMessageBox::sorry(this, i18n("The folder %1 for " "the handheld database files is not a valid " "folder.").arg(pdburl)); return; } if (!pdbinfo.exists()) { KMessageBox::sorry(this, i18n("The folder %1 for " "the handheld database files is not a " "valid directory.").arg(pdburl)); return; } // Now check the to directory: if (txtinfo.isFile()) { int res=KMessageBox::questionYesNo(this, i18n("You selected to sync folders, " "but gave a filename instead (%1)." "
Use folder %2 instead?
").arg(txturl) .arg(txtinfo.dirPath(true)), TQString(), i18n("Use Folder"), KStdGuiItem::cancel()); if (res==KMessageBox::Yes) { txturl=txtinfo.dirPath(true); txtinfo.setFile(txturl); } else return; } // Now that we have a directory path, try to create it: if (!txtinfo.isDir()) { txtinfo.dir().mkdir(txturl, true); } if (!txtinfo.isDir()) { KMessageBox::sorry(this, i18n("The folder %1 for " "the text files could not be created.").arg(txturl)); return; } // Now that we have both directories, create the converter object DEBUGKPILOT<<"Pdbinfo.dir="<The file %1 does not " "exist.").arg(pdburl)); return; } // Now check the to file /* // I can't check if a given filename is a valid filename if (!txtinfo.isFile()) { KMessageBox::sorry(this, i18n("The filename %1 for the " "text is not a valid filename.").arg(txturl)); return; }*/ if (convertPDBtoTXT(pdbinfo.dirPath(true), pdbinfo.fileName(), txtinfo.dirPath(true), txtinfo.fileName(), &conv) ) { KMessageBox::information(this, i18n("Conversion of file %1 successful.").arg(pdburl)); } } } void ConverterDlg::slotToPDB() { FUNCTIONSETUP; // First, get the settings from the controls and initialize // the converter object bool compress=dlg->fCompress->isChecked(); int bmks=0; if (dlg->fConvertBookmarks->isChecked()) { if (dlg->fBookmarksInline->isChecked()) bmks|=DOCConverter::eBmkInline; if (dlg->fBookmarksEndtags->isChecked()) bmks|=DOCConverter::eBmkEndtags; if(dlg->fBookmarksBmk->isChecked()) bmks|=DOCConverter::eBmkDefaultBmkFile; } DOCConverter conv; conv.setBookmarkTypes(bmks); conv.setCompress(compress); conv.setSort(DOCConverter::eSortName); askOverwrite=dlg->fAskOverwrite->isChecked(); verbose=dlg->fVerbose->isChecked(); bool dir=dlg->fDirectories->isChecked(); TQString txturl=dlg->fTXTDir->url(); TQString pdburl=dlg->fPDBDir->url(); TQFileInfo txtinfo(txturl); TQFileInfo pdbinfo(pdburl); if (dir) { if (txtinfo.isFile()) { int res=KMessageBox::questionYesNo(this, i18n("You selected to sync folders, " "but gave a filename instead (%1)." "
Use folder %2 instead?
").arg(txturl) .arg(txtinfo.dirPath(true)), TQString(), i18n("Use Folder"), KStdGuiItem::cancel()); if (res==KMessageBox::Yes) { txturl=txtinfo.dirPath(true); txtinfo.setFile(txturl); } else return; } if (!txtinfo.isDir() || !txtinfo.exists()) { KMessageBox::sorry(this, i18n("The folder %1 for " "the text files is not a valid folder.").arg(txturl)); return; } // Now check the to directory: if (pdbinfo.isFile()) { int res=KMessageBox::questionYesNo(this, i18n("You selected to sync folders, " "but gave a filename instead (%1)." "
Use folder %2 instead?
") .arg(pdburl) .arg(pdbinfo.dirPath(true)), TQString(), i18n("Use Folder"), KStdGuiItem::cancel()); if (res==KMessageBox::Yes) { pdburl=pdbinfo.dirPath(true); pdbinfo.setFile(pdburl); } else return; } // Now that we have a directory path, try to create it: if (!pdbinfo.isDir()) { pdbinfo.dir().mkdir(pdburl, true); } if (!pdbinfo.isDir()) { KMessageBox::sorry(this, i18n("The folder %1 for " "the PalmDOC files could not be created.").arg(pdburl)); return; } // Now that we have both directories, create the converter object DEBUGKPILOT<<"Pdbinfo.dir="<The file %1 does not " "exist.").arg(txturl)); return; } if (convertTXTtoPDB(txtinfo.dirPath(true), txtinfo.fileName(), pdbinfo.dirPath(true), pdbinfo.fileName(), &conv) ) { KMessageBox::information(this, i18n("Conversion of file %1 successful.").arg(txturl)); } } } void ConverterDlg::slotUser1() { TDEAboutApplication ab(TDEGlobal::instance()->aboutData(), this); ab.show(); ab.exec(); return; } void ConverterDlg::slotDirectories(bool dir) { FUNCTIONSETUP; DEBUGKPILOT<<"Slot Directories: "<fTextLabel->setText(i18n("&Text folder:")); dlg->fPdbLabel->setText(i18n("&PalmDOC folder:")); dlg->fTXTDir->setMode(KFile::LocalOnly | KFile::Directory); dlg->fPDBDir->setMode(KFile::LocalOnly | KFile::Directory); } else { dlg->fTextLabel->setText(i18n("&Text file:")); dlg->fPdbLabel->setText(i18n("&DOC file:")); dlg->fTXTDir->setMode(KFile::LocalOnly | KFile::File); dlg->fPDBDir->setMode(KFile::LocalOnly | KFile::File); } } bool ConverterDlg::convertTXTtoPDB(TQString txtdir, TQString txtfile, TQString pdbdir, TQString pdbfile, DOCConverter*conv) { FUNCTIONSETUP; bool res=false; TQFileInfo dbfileinfo(pdbdir, pdbfile); DEBUGKPILOT<<"Working on file "<The database file %1 already exists. Overwrite it?") .arg(dbfileinfo.filePath()), TQString(), i18n("Overwrite"), KStdGuiItem::cancel() ) )) { PilotLocalDatabase*pdbdb=new PilotLocalDatabase(pdbdir, TQFileInfo(pdbfile).baseName(), false); if (pdbdb) { if (!pdbdb->isOpen()) { #ifdef DEBUG DEBUGKPILOT<createDatabase(get_long("REAd"), get_long("TEXt")) ) { } } if (pdbdb->isOpen()) { conv->setPDB(pdbdb); conv->setTXTpath(txtdir, txtfile); DEBUGKPILOT<<"Converting "<convertTXTtoPDB()) res=true; } delete pdbdb; } if ( !res && verbose ) { KMessageBox::sorry(this, i18n("Error while converting the text %1.").arg(txtfile)); } } else { DEBUGKPILOT<<"Ignoring the file "<The text file %1 already exists. Overwrite it?") .arg(txtfileinfo.filePath()), TQString(), i18n("Overwrite"), KStdGuiItem::cancel() ) )) { PilotLocalDatabase*pdbdb=new PilotLocalDatabase(pdbdir, TQFileInfo(pdbfile).baseName(), false); if (pdbdb) { if (pdbdb->isOpen()) { conv->setPDB(pdbdb); conv->setTXTpath(txtdir, txtfile); DEBUGKPILOT<<"Converting "<convertPDBtoTXT()) res=true; } delete pdbdb; } if ( !res && verbose ) { KMessageBox::sorry(this, i18n("Error while converting the text %1.").arg(pdbfile)); } } else { DEBUGKPILOT<<"Ignoring the file "<