From 08f2b5848ddd09e0da7e2d42a8743f0b40f1c717 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Tue, 27 Jan 2015 18:44:50 +0900 Subject: Moved TDEFileReplace to tdeutils. This resolves bug 767. Signed-off-by: Michele Calgaro --- tdefilereplace/report.cpp | 282 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 282 insertions(+) create mode 100644 tdefilereplace/report.cpp (limited to 'tdefilereplace/report.cpp') diff --git a/tdefilereplace/report.cpp b/tdefilereplace/report.cpp new file mode 100644 index 0000000..3be703e --- /dev/null +++ b/tdefilereplace/report.cpp @@ -0,0 +1,282 @@ +/*************************************************************************** + report.cpp - Report document class + ------------------- + begin : fri aug 13 15:29:46 CEST 2004 + + copyright : (C) 2004 Emiliano Gulmini + email : emi_barbarossa@yahoo.it + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ +// QT +#include +#include + +// KDE +#include +#include +#include + +// local +#include "report.h" +#include "configurationclasses.h" + +void Report::createReportFile() +{ + TQString xmlFileName = m_docPath + ".xml", + cssFileName = m_docPath + ".css"; + + // Generates a report file + // a) Open the file + TQFile report(xmlFileName); + if (!report.open( IO_WriteOnly )) + { + KMessageBox::error(0, i18n("Cannot open the file %1.").arg(xmlFileName)); + return ; + } + + // b) Write the header of the XML file + + TQDateTime datetime = TQDateTime::currentDateTime(Qt::LocalTime); + TQString dateString = datetime.toString(Qt::LocalDate); + KUser user; + TQString columnTextFour, + columnReplaceWith; + if(!m_isSearchFlag) + { + columnTextFour = i18n("Replaced Strings"); + columnReplaceWith = i18n("Replace with"); + } + else + { + columnTextFour = i18n("Total number occurrences"); + columnReplaceWith = i18n("-"); + } + + TQString css = cssFileName.mid(cssFileName.findRev("/")+1,cssFileName.length()-(cssFileName.findRev("/")+1)); + TQTextStream oTStream( &report ); + oTStream << "\n" + "" + "\n" + " "+i18n("TDEFileReplace Report")+" \n" + " "+user.fullName()+"("+user.loginName()+")"+"\n" + " "+dateString+"\n" + "
\n" + " \n" + " "+i18n("Searching/Replacing Strings Table")+" \n" + "
\n" + " \n" + " "+i18n("Search for")+"\n"; + + if(!m_isSearchFlag) + oTStream<< " "+columnReplaceWith+"\n"; + + oTStream<< " \n" + "
\n"; + // c) Write the strings list + TQListViewItem *lviCurItem, + *lviFirst; + + lviCurItem = lviFirst = m_stringsView->firstChild(); + + if(lviCurItem == 0) + return ; + + TQString rowType="a1"; + + do + { TQString rowTag = "\n" + " text(0)+"]]>\n" + " text(1)+"]]>\n" + "\n"; + + oTStream << rowTag; + + rowType = ((rowType == "a1") ? "a2" : "a1"); + + lviCurItem = lviCurItem->nextSibling(); + } while(lviCurItem && lviCurItem != lviFirst); + + oTStream<< "
\n"; + + oTStream<< "\n" + " \n" + " "+i18n("Results Table")+ " " + "
\n" + " \n" + " "+i18n("Name")+"\n" + " "+i18n("Folder")+"\n"; + if(m_isSearchFlag) + { + oTStream<< " "+i18n("Size")+"\n"; + } + else + { + oTStream<< " "+i18n("Old Size")+"\n" + " "+i18n("New Size")+"\n"; + } + oTStream<< " "+columnTextFour+"\n" + " "+i18n("Owner User")+"\n" + " "+i18n("Owner Group")+"\n" + " \n" + "
\n"; + + // d) Write the result list + + lviCurItem = lviFirst = m_resultsView->firstChild(); + + if(lviCurItem == 0) + return ; + + unsigned int totalOccurrences = 0; + + rowType="a1"; + + do + { TQString rowTag = " \n" + " text(0)+"]]>\n" + " text(1)+"]]>\n"; + if(m_isSearchFlag) + { + rowTag += " text(2)+"]]>\n" + " text(3)+"]]>\n" + " text(4)+"]]>\n" + " text(5)+"]]>\n" + " \n"; + } + else + { + rowTag += " text(2)+"]]>\n" + " text(3)+"]]>\n" + " text(4)+"]]>\n" + " text(5)+"]]>\n" + " text(6)+"]]>\n" + " \n"; + } + + oTStream << rowTag; + + rowType = ((rowType == "a1") ? "a2" : "a1"); + + if(m_isSearchFlag) + totalOccurrences += lviCurItem->text(3).toInt(); + else + totalOccurrences += lviCurItem->text(4).toInt(); + + lviCurItem = lviCurItem->nextSibling(); + } while(lviCurItem && lviCurItem != lviFirst); + + + // e) Write the end of the file + + oTStream<< "
\n" + "" + << totalOccurrences + << "\n" + "
\n"; + + report.close(); +} + +void Report::createStyleSheet() +{ + TQString cssFileName = m_docPath +".css"; + TQFile styleSheet(cssFileName); + if (!styleSheet.open( IO_WriteOnly )) + { + KMessageBox::error(0, i18n("Cannot open the file %1.").arg(cssFileName)); + return ; + } + + TQTextStream oTStream( &styleSheet ); + + TQString css = "title { display:block;font:40px bold sans-serif; }\n\n" + "createdby:before { content :\""+i18n("Created by")+": \"; }\n" + "createdby { display:inline; }\n\n" + "date:before { content :\"-"+i18n("date")+": \"; }\n" + "date { display:inline; }\n\n" + "totaloccurrences:before { content :\""+i18n("Total occurrences")+": \"; }\n" + "totaloccurrences { display:block;text-align:right; font-weight:bold;margin-top:5px;margin-right:5px;}\n" + "tablecaption {display:table-caption;font:20px bold sans-serif;}\n\n" + "hr {display:block;background:black;height:1px;margin:5px 0px 5px;}\n" + "whiteline {display:block;height:16px;}\n\n" + "searchfor {\n" + " display:table-cell;\n" + " border:1px solid black;\n" + " padding:0 7px 0; }\n\n"; + + if(!m_isSearchFlag) + { + css += "replacewith {\n" + " display:table-cell;\n" + " border:1px solid black;\n" + " padding:0 7px 0; }\n\n"; + } + + css += "folder {\n" + " display:table-cell;\n" + " border:1px solid black;\n" + " padding:0 7px 0; }\n\n" + "header { display: table-header-group; }\n\n" + "name {\n" + " display:table-cell;\n" + " border:1px solid black;\n" + " padding:0 7px 0; }\n\n" + "newsize {\n" + " display:table-cell;\n" + " border:1px solid black;\n" + " padding:0 7px 0;\n" + " text-align:right; }\n\n" + "oldsize {\n" + " display:table-cell;\n" + " border:1px solid black;\n" + " padding:0 7px 0;\n" + " text-align:right; }\n\n" + "ownergroup {\n" + " display:table-cell;\n" + " border:1px solid black;\n" + " padding:0 7px 0; }\n\n" + "owneruser {\n" + " display:table-cell;\n" + " border:1px solid black;\n" + " padding:0 7px 0; }\n\n" + "replacedstrings {\n" + " text-align:right;\n" + " display:table-cell;\n" + " border:1px solid black;\n" + " padding:0 7px 0; }\n\n" + "*[class~=header] {\n" + " background : lightgray;\n" + " text-align : center; }\n\n" + "row { display : table-row; }\n\n" + "table {\n" + " display:table;\n" + " border-collapse: collapse; }\n\n" + "*[class~=a1] {\n" + " background-color:aliceblue;\n" + " font-weight : bold;font-size:15px; }\n\n" + "*[class~=a2] {\n" + " background-color:khaki;\n" + " font-weight : bold;\n" + " font-size:15px; }\n\n"; + + oTStream << css; + + styleSheet.close(); +} + +void Report::createDocument(const TQString& docPath) +{ + m_docPath = docPath; + + createStyleSheet(); + createReportFile(); +} + -- cgit v1.2.3