diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-05-17 08:20:48 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-05-17 08:20:48 +0000 |
commit | aa0726b20f398264f0a2abc60215be044b106f9c (patch) | |
tree | 070fdbc19a1106cfdd7f651a8ce76bb1b89a513d /src/formatimporter.cpp | |
parent | d3cf5b3e75aadc3b02d0b56f030d4c3f8c2c749d (diff) | |
download | basket-aa0726b20f398264f0a2abc60215be044b106f9c.tar.gz basket-aa0726b20f398264f0a2abc60215be044b106f9c.zip |
TQt4 port basket
This enables compilation under both Qt3 and Qt4
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/basket@1232416 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/formatimporter.cpp')
-rw-r--r-- | src/formatimporter.cpp | 154 |
1 files changed, 77 insertions, 77 deletions
diff --git a/src/formatimporter.cpp b/src/formatimporter.cpp index c98ad38..1d203ca 100644 --- a/src/formatimporter.cpp +++ b/src/formatimporter.cpp @@ -18,11 +18,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#include <qstring.h> -#include <qstringlist.h> -#include <qdir.h> -#include <qfileinfo.h> -#include <qdom.h> +#include <tqstring.h> +#include <tqstringlist.h> +#include <tqdir.h> +#include <tqfileinfo.h> +#include <tqdom.h> #include <kglobalsettings.h> #include <kmessagebox.h> #include <klocale.h> @@ -46,29 +46,29 @@ bool FormatImporter::shouldImportBaskets() return false; // ... And there is at least one folder in the save folder, with a ".basket" file inside that folder. - QDir dir(Global::savesFolder(), QString::null, QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoSymLinks); - QStringList list = dir.entryList(); - for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) + TQDir dir(Global::savesFolder(), TQString(), TQDir::Name | TQDir::IgnoreCase, TQDir::Dirs | TQDir::NoSymLinks); + TQStringList list = dir.entryList(); + for (TQStringList::Iterator it = list.begin(); it != list.end(); ++it) if (*it != "." && *it != ".." && dir.exists(Global::savesFolder() + *it + "/.basket")) return true; return false; } -void FormatImporter::copyFolder(const QString &folder, const QString &newFolder) +void FormatImporter::copyFolder(const TQString &folder, const TQString &newFolder) { copyFinished = false; KIO::CopyJob *copyJob = KIO::copyAs(KURL(folder), KURL(newFolder), /*showProgressInfo=*/false); - connect( copyJob, SIGNAL(result(KIO::Job*)), this, SLOT(slotCopyingDone(KIO::Job*)) ); + connect( copyJob, TQT_SIGNAL(result(KIO::Job*)), this, TQT_SLOT(slotCopyingDone(KIO::Job*)) ); while (!copyFinished) kapp->processEvents(); } -void FormatImporter::moveFolder(const QString &folder, const QString &newFolder) +void FormatImporter::moveFolder(const TQString &folder, const TQString &newFolder) { copyFinished = false; KIO::CopyJob *copyJob = KIO::moveAs(KURL(folder), KURL(newFolder), /*showProgressInfo=*/false); - connect( copyJob, SIGNAL(result(KIO::Job*)), this, SLOT(slotCopyingDone(KIO::Job*)) ); + connect( copyJob, TQT_SIGNAL(result(KIO::Job*)), this, TQT_SLOT(slotCopyingDone(KIO::Job*)) ); while (!copyFinished) kapp->processEvents(); } @@ -84,24 +84,24 @@ void FormatImporter::importBaskets() std::cout << "Import Baskets: Preparing..." << std::endl; // Some preliminary preparations (create the destination folders and the basket tree file): - QDir dirPrep; + TQDir dirPrep; dirPrep.mkdir(Global::savesFolder()); dirPrep.mkdir(Global::basketsFolder()); - QDomDocument document("basketTree"); - QDomElement root = document.createElement("basketTree"); + TQDomDocument document("basketTree"); + TQDomElement root = document.createElement("basketTree"); document.appendChild(root); // First up, establish a list of every baskets, ensure the old order (if any), and count them. - QStringList baskets; + TQStringList baskets; // Read the 0.5.0 baskets order: - QDomDocument *doc = XMLWork::openFile("container", Global::savesFolder() + "container.baskets"); + TQDomDocument *doc = XMLWork::openFile("container", Global::savesFolder() + "container.baskets"); if (doc != 0) { - QDomElement docElem = doc->documentElement(); - QDomElement basketsElem = XMLWork::getElement(docElem, "baskets"); - QDomNode n = basketsElem.firstChild(); + TQDomElement docElem = doc->documentElement(); + TQDomElement basketsElem = XMLWork::getElement(docElem, "baskets"); + TQDomNode n = basketsElem.firstChild(); while (!n.isNull()) { - QDomElement e = n.toElement(); + TQDomElement e = n.toElement(); if ((!e.isNull()) && e.tagName() == "basket") baskets.append(e.text()); n = n.nextSibling(); @@ -109,35 +109,35 @@ void FormatImporter::importBaskets() } // Then load the baskets that weren't loaded (import < 0.5.0 ones): - QDir dir(Global::savesFolder(), QString::null, QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoSymLinks); - QStringList list = dir.entryList(); + TQDir dir(Global::savesFolder(), TQString(), TQDir::Name | TQDir::IgnoreCase, TQDir::Dirs | TQDir::NoSymLinks); + TQStringList list = dir.entryList(); if (list.count() > 2) // Pass "." and ".." - for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) // For each folder + for (TQStringList::Iterator it = list.begin(); it != list.end(); ++it) // For each folder if (*it != "." && *it != ".." && dir.exists(Global::savesFolder() + *it + "/.basket")) // If it can be a basket folder - if ( baskets.find((*it) + "/") == baskets.end() && - baskets.find(*it) == baskets.end() ) // And if it is not already in the imported baskets list + if ( baskets.tqfind((*it) + "/") == baskets.end() && + baskets.tqfind(*it) == baskets.end() ) // And if it is not already in the imported baskets list baskets.append(*it); std::cout << "Import Baskets: Found " << baskets.count() << " baskets to import." << std::endl; // Import every baskets: int i = 0; - for (QStringList::iterator it = baskets.begin(); it != baskets.end(); ++it) { + for (TQStringList::iterator it = baskets.begin(); it != baskets.end(); ++it) { ++i; std::cout << "Import Baskets: Importing basket " << i << " of " << baskets.count() << "..." << std::endl; // Move the folder to the new repository (normal basket) or copy the folder (mirorred folder): - QString folderName = *it; + TQString folderName = *it; if (folderName.startsWith("/")) { // It was a folder mirror: KMessageBox::information(0, i18n("<p>Folder mirroring is not possible anymore (see <a href='http://basket.kde.org/'>basket.kde.org</a> for more information).</p>" "<p>The folder <b>%1</b> has been copied for the basket needs. You can either delete this folder or delete the basket, or use both. But remember that " - "modifying one will not modify the other anymore as they are now separate entities.</p>").arg(folderName), i18n("Folder Mirror Import"), + "modifying one will not modify the other anymore as they are now separate entities.</p>").tqarg(folderName), i18n("Folder Mirror Import"), "", KMessageBox::AllowLink); // Also modify folderName to be only the folder name and not the full path anymore: - QString newFolderName = folderName; + TQString newFolderName = folderName; if (newFolderName.endsWith("/")) newFolderName = newFolderName.left(newFolderName.length() - 1); - newFolderName = newFolderName.mid(newFolderName.findRev('/') + 1); + newFolderName = newFolderName.mid(newFolderName.tqfindRev('/') + 1); newFolderName = Tools::fileNameForNewFile(newFolderName, Global::basketsFolder()); FormatImporter f; f.copyFolder(folderName, Global::basketsFolder() + newFolderName); @@ -146,10 +146,10 @@ void FormatImporter::importBaskets() dir.rename(Global::savesFolder() + folderName, Global::basketsFolder() + folderName); // Move the folder // Import the basket structure file and get the properties (to add them in the tree basket-properties cache): - QDomElement properties = importBasket(folderName); + TQDomElement properties = importBasket(folderName); // Add it to the XML document: - QDomElement basketElement = document.createElement("basket"); + TQDomElement basketElement = document.createElement("basket"); root.appendChild(basketElement); basketElement.setAttribute("folderName", folderName); basketElement.appendChild(properties); @@ -158,11 +158,11 @@ void FormatImporter::importBaskets() // Finalize (write to disk and delete now useless files): std::cout << "Import Baskets: Finalizing..." << std::endl; - QFile file(Global::basketsFolder() + "baskets.xml"); + TQFile file(Global::basketsFolder() + "baskets.xml"); if (file.open(IO_WriteOnly)) { - QTextStream stream(&file); - stream.setEncoding(QTextStream::UnicodeUTF8); - QString xml = document.toString(); + TQTextStream stream(&file); + stream.setEncoding(TQTextStream::UnicodeUTF8); + TQString xml = document.toString(); stream << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; stream << xml; file.close(); @@ -174,68 +174,68 @@ void FormatImporter::importBaskets() std::cout << "Import Baskets: Finished." << std::endl; } -QDomElement FormatImporter::importBasket(const QString &folderName) +TQDomElement FormatImporter::importBasket(const TQString &folderName) { // Load the XML file: - QDomDocument *document = XMLWork::openFile("basket", Global::basketsFolder() + folderName + "/.basket"); + TQDomDocument *document = XMLWork::openFile("basket", Global::basketsFolder() + folderName + "/.basket"); if (!document) { std::cout << "Import Baskets: Failed to read the basket file!" << std::endl; - return QDomElement(); + return TQDomElement(); } - QDomElement docElem = document->documentElement(); + TQDomElement docElem = document->documentElement(); // Import properties (change <background color=""> to <appearance backgroundColor="">, and figure out if is a checklist or not): - QDomElement properties = XMLWork::getElement(docElem, "properties"); - QDomElement background = XMLWork::getElement(properties, "background"); - QColor backgroundColor = QColor(background.attribute("color")); + TQDomElement properties = XMLWork::getElement(docElem, "properties"); + TQDomElement background = XMLWork::getElement(properties, "background"); + TQColor backgroundColor = TQColor(background.attribute("color")); if (backgroundColor.isValid() && (backgroundColor != KGlobalSettings::baseColor())) { // Use the default color if it was already that color: - QDomElement appearance = document->createElement("appearance"); + TQDomElement appearance = document->createElement("appearance"); appearance.setAttribute("backgroundColor", backgroundColor.name()); properties.appendChild(appearance); } - QDomElement disposition = document->createElement("disposition"); + TQDomElement disposition = document->createElement("disposition"); disposition.setAttribute("mindMap", "false"); disposition.setAttribute("columnCount", "1"); disposition.setAttribute("free", "false"); bool isCheckList = XMLWork::trueOrFalse( XMLWork::getElementText(properties, "showCheckBoxes", false) ); // Insert all notes in a group (column): 1/ rename "items" to "group", 2/ add "notes" to root, 3/ move "group" into "notes" - QDomElement column = XMLWork::getElement(docElem, "items"); + TQDomElement column = XMLWork::getElement(docElem, "items"); column.setTagName("group"); - QDomElement notes = document->createElement("notes"); + TQDomElement notes = document->createElement("notes"); notes.appendChild(column); docElem.appendChild(notes); // Import notes from older representations: - QDomNode n = column.firstChild(); + TQDomNode n = column.firstChild(); while ( ! n.isNull() ) { - QDomElement e = n.toElement(); + TQDomElement e = n.toElement(); if (!e.isNull()) { e.setTagName("note"); - QDomElement content = XMLWork::getElement(e, "content"); + TQDomElement content = XMLWork::getElement(e, "content"); // Add Check tag: if (isCheckList) { bool isChecked = XMLWork::trueOrFalse(e.attribute("checked", "false")); XMLWork::addElement(*document, e, "tags", (isChecked ? "todo_done" : "todo_unchecked")); } // Import annotations as folded groups: - QDomElement parentE = column; - QString annotations = XMLWork::getElementText(e, "annotations", ""); + TQDomElement tqparentE = column; + TQString annotations = XMLWork::getElementText(e, "annotations", ""); if (!annotations.isEmpty()) { - QDomElement annotGroup = document->createElement("group"); + TQDomElement annotGroup = document->createElement("group"); column.insertBefore(annotGroup, e); annotGroup.setAttribute("folded", "true"); annotGroup.appendChild(e); - parentE = annotGroup; + tqparentE = annotGroup; // Create the text note and add it to the DOM tree: - QDomElement annotNote = document->createElement("note"); + TQDomElement annotNote = document->createElement("note"); annotNote.setAttribute("type", "text"); annotGroup.appendChild(annotNote); - QString annotFileName = Tools::fileNameForNewFile("annotations1.txt", Basket::fullPathForFolderName(folderName)); - QString annotFullPath = Basket::fullPathForFolderName(folderName) + "/" + annotFileName; - QFile file(annotFullPath); + TQString annotFileName = Tools::fileNameForNewFile("annotations1.txt", Basket::fullPathForFolderName(folderName)); + TQString annotFullPath = Basket::fullPathForFolderName(folderName) + "/" + annotFileName; + TQFile file(annotFullPath); if (file.open(IO_WriteOnly)) { - QTextStream stream(&file); + TQTextStream stream(&file); stream << annotations; file.close(); } @@ -243,35 +243,35 @@ QDomElement FormatImporter::importBasket(const QString &folderName) n = annotGroup; } // Import Launchers from 0.3.x, 0.4.0 and 0.5.0-alphas: - QString runCommand = e.attribute("runcommand"); // Keep compatibility with 0.4.0 and 0.5.0-alphas versions + TQString runCommand = e.attribute("runcommand"); // Keep compatibility with 0.4.0 and 0.5.0-alphas versions runCommand = XMLWork::getElementText(e, "action", runCommand); // Keep compatibility with 0.3.x versions if ( ! runCommand.isEmpty() ) { // An import should be done // Prepare the launcher note: - QString title = content.attribute("title", ""); - QString icon = content.attribute("icon", ""); + TQString title = content.attribute("title", ""); + TQString icon = content.attribute("icon", ""); if (title.isEmpty()) title = runCommand; if (icon.isEmpty()) icon = NoteFactory::iconForCommand(runCommand); // Import the launcher note: - // Adapted version of "QString launcherName = NoteFactory::createNoteLauncherFile(runCommand, title, icon, this)": - QString launcherContent = QString( + // Adapted version of "TQString launcherName = NoteFactory::createNoteLauncherFile(runCommand, title, icon, this)": + TQString launcherContent = TQString( "[Desktop Entry]\n" "Exec=%1\n" "Name=%2\n" "Icon=%3\n" "Encoding=UTF-8\n" - "Type=Application\n").arg(runCommand, title, icon.isEmpty() ? QString("exec") : icon); - QString launcherFileName = Tools::fileNameForNewFile("launcher.desktop", Global::basketsFolder() + folderName /*+ "/"*/); - QString launcherFullPath = Global::basketsFolder() + folderName /*+ "/"*/ + launcherFileName; - QFile file(launcherFullPath); + "Type=Application\n").tqarg(runCommand, title, icon.isEmpty() ? TQString("exec") : icon); + TQString launcherFileName = Tools::fileNameForNewFile("launcher.desktop", Global::basketsFolder() + folderName /*+ "/"*/); + TQString launcherFullPath = Global::basketsFolder() + folderName /*+ "/"*/ + launcherFileName; + TQFile file(launcherFullPath); if (file.open(IO_WriteOnly)) { - QTextStream stream(&file); - stream.setEncoding(QTextStream::UnicodeUTF8); + TQTextStream stream(&file); + stream.setEncoding(TQTextStream::UnicodeUTF8); stream << launcherContent; file.close(); } // Add the element to the DOM: - QDomElement launcherElem = document->createElement("note"); - parentE.insertBefore(launcherElem, e); + TQDomElement launcherElem = document->createElement("note"); + tqparentE.insertBefore(launcherElem, e); launcherElem.setAttribute("type", "launcher"); XMLWork::addElement(*document, launcherElem, "content", launcherFileName); } @@ -288,11 +288,11 @@ QDomElement FormatImporter::importBasket(const QString &folderName) } // Save the resulting XML file: - QFile file(Global::basketsFolder() + folderName + "/.basket"); + TQFile file(Global::basketsFolder() + folderName + "/.basket"); if (file.open(IO_WriteOnly)) { - QTextStream stream(&file); - stream.setEncoding(QTextStream::UnicodeUTF8); -// QString xml = document->toString(); + TQTextStream stream(&file); + stream.setEncoding(TQTextStream::UnicodeUTF8); +// TQString xml = document->toString(); // stream << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; // stream << xml; stream << document->toString(); // Document is ALREADY using UTF-8 |