From e9ae80694875f869892f13f4fcaf1170a00dea41 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdewebdev@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kfilereplace/report.cpp | 282 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 282 insertions(+) create mode 100644 kfilereplace/report.cpp (limited to 'kfilereplace/report.cpp') diff --git a/kfilereplace/report.cpp b/kfilereplace/report.cpp new file mode 100644 index 00000000..cae0dfe4 --- /dev/null +++ b/kfilereplace/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() +{ + QString xmlFileName = m_docPath + ".xml", + cssFileName = m_docPath + ".css"; + + // Generates a report file + // a) Open the file + QFile 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 + + QDateTime datetime = QDateTime::currentDateTime(Qt::LocalTime); + QString dateString = datetime.toString(Qt::LocalDate); + KUser user; + QString columnTextFour, + columnReplaceWith; + if(!m_isSearchFlag) + { + columnTextFour = i18n("Replaced Strings"); + columnReplaceWith = i18n("Replace with"); + } + else + { + columnTextFour = i18n("Total number occurrences"); + columnReplaceWith = i18n("-"); + } + + QString css = cssFileName.mid(cssFileName.findRev("/")+1,cssFileName.length()-(cssFileName.findRev("/")+1)); + QTextStream oTStream( &report ); + oTStream << "\n" + "" + "\n" + " "+i18n("KFileReplace 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 + QListViewItem *lviCurItem, + *lviFirst; + + lviCurItem = lviFirst = m_stringsView->firstChild(); + + if(lviCurItem == 0) + return ; + + QString rowType="a1"; + + do + { QString 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 + { QString 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() +{ + QString cssFileName = m_docPath +".css"; + QFile styleSheet(cssFileName); + if (!styleSheet.open( IO_WriteOnly )) + { + KMessageBox::error(0, i18n("Cannot open the file %1.").arg(cssFileName)); + return ; + } + + QTextStream oTStream( &styleSheet ); + + QString 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 QString& docPath) +{ + m_docPath = docPath; + + createStyleSheet(); + createReportFile(); +} + -- cgit v1.2.1