From 2ccecf203ba8a352de21ea84bab663c531edcf54 Mon Sep 17 00:00:00 2001 From: -f Date: Mon, 13 Jan 2014 15:32:00 +0100 Subject: [PATCH] removed unused code --- src/adaptors/UBImportVirtualPrinter.cpp | 213 ------------------------ src/adaptors/UBIniFileParser.cpp | 87 ---------- src/adaptors/UBIniFileParser.h | 52 ------ src/adaptors/adaptors.pri | 2 - 4 files changed, 354 deletions(-) delete mode 100644 src/adaptors/UBImportVirtualPrinter.cpp delete mode 100644 src/adaptors/UBIniFileParser.cpp delete mode 100644 src/adaptors/UBIniFileParser.h diff --git a/src/adaptors/UBImportVirtualPrinter.cpp b/src/adaptors/UBImportVirtualPrinter.cpp deleted file mode 100644 index 3ccdc0e3..00000000 --- a/src/adaptors/UBImportVirtualPrinter.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (C) 2013 Open Education Foundation - * - * Copyright (C) 2010-2013 Groupement d'Intérêt Public pour - * l'Education Numérique en Afrique (GIP ENA) - * - * This file is part of OpenBoard. - * - * OpenBoard 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, version 3 of the License, - * with a specific linking exception for the OpenSSL project's - * "OpenSSL" library (or with modified versions of it that use the - * same license as the "OpenSSL" library). - * - * OpenBoard 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 OpenBoard. If not, see . - */ - - - - -#include "UBImportVirtualPrinter.h" - -#include "core/UBApplication.h" -#include "core/UBPersistenceManager.h" -#include "core/UBDocumentManager.h" - -#include "document/UBDocumentProxy.h" - -#include "UBIniFileParser.h" - -#include - -#include "core/memcheck.h" - -QString UBImportVirtualPrinter::sOriginalDefaultPrintername = ""; - -QPointer UBImportVirtualPrinter::pendingDocument; - - -UBImportVirtualPrinter::UBImportVirtualPrinter(QObject* parent) - : UBImportAdaptor(parent) -{ - // NOOP -} - - -UBImportVirtualPrinter::~UBImportVirtualPrinter() -{ - // NOOP -} - - -QStringList UBImportVirtualPrinter::supportedExtentions() -{ - return QStringList("ini"); -} - - -QString UBImportVirtualPrinter::importFileFilter() -{ - // we don't want user import manually ini file. - return ""; -} - - -QString UBImportVirtualPrinter::pdfFileName(const QFile& pFile) -{ - - UBIniFileParser iniParser(pFile.fileName()); - - // check if we have 1 PDF file to import - QString totalPdfString = iniParser.getStringValue("PDF", "Count"); - bool ok; - int totalPdf = totalPdfString.toInt(&ok); - QString pdfFilename; - - if (ok && totalPdf > 0) - { - pdfFilename = iniParser.getStringValue("PDF", "File0"); - if (pdfFilename == "") - { - qWarning() << "Unable to retreive PDF file name from ini file " << pFile.fileName(); - } - } - - return pdfFilename; -} - - -QStringList UBImportVirtualPrinter::emfFileNames(const QFile& pFile) -{ - - UBIniFileParser iniParser(pFile.fileName()); - - // check if we have 1 PDF file to import - QString totalEmfString = iniParser.getStringValue("EMF", "Count"); - bool ok; - int totalEmf = totalEmfString.toInt(&ok); - QStringList emfFilenames; - - if (ok) - { - for(int i = 0; i < totalEmf; i++) - { - emfFilenames << iniParser.getStringValue("EMF", QString("File%1").arg(i)); - } - } - - return emfFilenames; -} - - - -void UBImportVirtualPrinter::cleanUp(const QFile& pFile, const QString& pPdfFileName, QStringList pEmfFilenames) -{ - - //restore default printer if needed - if (UBImportVirtualPrinter::sOriginalDefaultPrintername != "") - { - LPTSTR wDefaultPrinterName = new TCHAR[255]; - int i = UBImportVirtualPrinter::sOriginalDefaultPrintername.toWCharArray(wDefaultPrinterName); - wDefaultPrinterName[i] = 0; - SetDefaultPrinter(wDefaultPrinterName); - UBImportVirtualPrinter::sOriginalDefaultPrintername = ""; - delete[] wDefaultPrinterName; - } - - // delete tmp ini file - if (!QFile::remove(pFile.fileName())) - { - qWarning() << "Unable to remove file " << pFile.fileName(); - } - // delete tmp PDF file - if (pPdfFileName != "" && !QFile::remove(pPdfFileName)) - { - qWarning() << "Unable to remove file " << pPdfFileName; - } - - foreach(QString f, pEmfFilenames) - { - QFile::remove(f); - } -} - - -UBDocumentProxy* UBImportVirtualPrinter::importFile(const QFile& pFile, const QString& pGroup) -{ - UBApplication::showMessage(tr("Importing Sankore printer file ...")); - UBDocumentProxy *document = 0; - - QString pdfFilename = pdfFileName(pFile); - - if (pdfFilename.size() > 0) - { - QFile pdfFile(pdfFilename); - - document = UBDocumentManager::documentManager()->importFile(pdfFile, pGroup); - - UBIniFileParser iniParser(pFile.fileName()); - - QString documentName = iniParser.getStringValue("Document", "Name"); - - // we must update the document name otherwise the imported document will have the name of the tmp PDF file. - if (document) - { - if (documentName != "") - document->setMetaData(UBSettings::documentName, documentName); - - UBPersistenceManager::persistenceManager()->persistDocumentMetadata(document); - } - } - - if (!document) - { - UBApplication::showMessage(tr("Error while importing Sankore printer file.")); - } - - cleanUp(pFile, pdfFilename, emfFileNames(pFile)); - - return document; -} - - -bool UBImportVirtualPrinter::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) -{ - UBApplication::showMessage(tr("Importing Sankore printer file ...")); - bool result = false; - - QString pdfFilename = pdfFileName(pFile); - - if (pdfFilename.size() > 0) - { - QFile pdfFile(pdfFilename); - result = UBDocumentManager::documentManager()->addFileToDocument(pDocument, pdfFile); - } - - if (!result) - { - UBApplication::showMessage(tr("Error while importing Sankore printer file.")); - } - - cleanUp(pFile, pdfFilename, emfFileNames(pFile)); - - return result; -} - diff --git a/src/adaptors/UBIniFileParser.cpp b/src/adaptors/UBIniFileParser.cpp deleted file mode 100644 index b71a72c5..00000000 --- a/src/adaptors/UBIniFileParser.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2013 Open Education Foundation - * - * Copyright (C) 2010-2013 Groupement d'Intérêt Public pour - * l'Education Numérique en Afrique (GIP ENA) - * - * This file is part of OpenBoard. - * - * OpenBoard 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, version 3 of the License, - * with a specific linking exception for the OpenSSL project's - * "OpenSSL" library (or with modified versions of it that use the - * same license as the "OpenSSL" library). - * - * OpenBoard 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 OpenBoard. If not, see . - */ - - - - -#include "UBIniFileParser.h" - -#include "core/memcheck.h" - -UBIniFileParser::UBIniFileParser(const QString& pFileName) -{ - QFile file(pFileName); - if (file.open(QIODevice::ReadOnly)) - { - QTextStream reader(&file); - - QString catName = ""; - while (!reader.atEnd()) - { - QString line = reader.readLine(); - catName = readLine(line, catName); - } - - file.close(); - } - -} - -QString UBIniFileParser::readLine(const QString& pLine, const QString& pCatName) -{ - if (pLine.indexOf(QChar('[')) == 0) - { - QString cat = pLine.mid(1,pLine.indexOf(QChar(']')) -1); - mIniDico[cat] = new QHash; - return cat; - } - else - { - int equalIndex = pLine.indexOf(QChar('=')); - if (equalIndex > 0) - { - QString key = pLine.left(equalIndex); - QString value = pLine.mid(equalIndex+1, pLine.length()-1); - mIniDico[pCatName]->insert(key, value); - } - } - return pCatName; -} - -UBIniFileParser::~UBIniFileParser() -{ - foreach(QString key, mIniDico.keys()) - { - delete mIniDico[key]; - } -} - -QString UBIniFileParser::getStringValue(const QString& pSection, const QString& pKey) -{ - if (mIniDico[pSection]) - { - return mIniDico[pSection]->value(pKey); - } - return ""; -} diff --git a/src/adaptors/UBIniFileParser.h b/src/adaptors/UBIniFileParser.h deleted file mode 100644 index f524f59f..00000000 --- a/src/adaptors/UBIniFileParser.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2013 Open Education Foundation - * - * Copyright (C) 2010-2013 Groupement d'Intérêt Public pour - * l'Education Numérique en Afrique (GIP ENA) - * - * This file is part of OpenBoard. - * - * OpenBoard 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, version 3 of the License, - * with a specific linking exception for the OpenSSL project's - * "OpenSSL" library (or with modified versions of it that use the - * same license as the "OpenSSL" library). - * - * OpenBoard 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 OpenBoard. If not, see . - */ - - - - -#ifndef UBINIFILEPARSER_H_ -#define UBINIFILEPARSER_H_ - -#include - -/** - * This class can parse a ini file format. - */ -class UBIniFileParser -{ - public: - UBIniFileParser(const QString& pFile); - virtual ~UBIniFileParser(); - - /** - * return the value for pKey in pSection. pSection is the group in which the key must be search (section are defined in [] in the ini file) - */ - QString getStringValue(const QString& pSection, const QString& pKey); - - private: - QString readLine(const QString& pLine, const QString& catName); - QHash*> mIniDico; -}; - -#endif /* UBINIFILEPARSER_H_ */ diff --git a/src/adaptors/adaptors.pri b/src/adaptors/adaptors.pri index 33e7ba16..4695fa34 100644 --- a/src/adaptors/adaptors.pri +++ b/src/adaptors/adaptors.pri @@ -10,7 +10,6 @@ HEADERS += src/adaptors/UBExportAdaptor.h\ src/adaptors/UBThumbnailAdaptor.h \ src/adaptors/UBImportPDF.h \ src/adaptors/UBImportImage.h \ - src/adaptors/UBIniFileParser.h \ src/adaptors/UBExportWeb.h \ src/adaptors/UBImportCFF.h \ src/adaptors/UBExportCFF.h \ @@ -32,7 +31,6 @@ SOURCES += src/adaptors/UBExportAdaptor.cpp\ src/adaptors/UBThumbnailAdaptor.cpp \ src/adaptors/UBImportPDF.cpp \ src/adaptors/UBImportImage.cpp \ - src/adaptors/UBIniFileParser.cpp \ src/adaptors/UBExportWeb.cpp \ src/adaptors/UBImportCFF.cpp \ src/adaptors/UBExportCFF.cpp \