File indexing completed on 2024-12-29 04:47:03
0001 /* 0002 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "grantleeprintstyle.h" 0008 #include "importexport/contactfields.h" 0009 #include "printingwizard.h" 0010 #include "printprogress.h" 0011 #include <Akonadi/GrantleePrint> 0012 0013 #include <KContacts/Addressee> 0014 0015 #include <KLocalizedString> 0016 0017 #include <QFile> 0018 #include <QPrinter> 0019 #include <QTextDocument> 0020 0021 using namespace KABPrinting; 0022 0023 GrantleePrintStyle::GrantleePrintStyle(const QString &themePath, PrintingWizard *parent) 0024 : PrintStyle(parent) 0025 , m_themePath(themePath) 0026 { 0027 QFile previewFile(QString(themePath + QStringLiteral("/preview.png"))); 0028 if (previewFile.exists()) { 0029 setPreview(previewFile.fileName()); 0030 } 0031 setPreferredSortOptions(KAddressBookImportExport::ContactFields::FormattedName, Qt::AscendingOrder); 0032 } 0033 0034 GrantleePrintStyle::~GrantleePrintStyle() = default; 0035 0036 void GrantleePrintStyle::print(const KContacts::Addressee::List &contacts, PrintProgress *progress) 0037 { 0038 QPrinter *printer = wizard()->printer(); 0039 printer->setPageMargins(QMarginsF(20, 20, 20, 20), QPageLayout::Point); 0040 0041 progress->addMessage(i18n("Setting up document")); 0042 0043 KAddressBookGrantlee::GrantleePrint grantleePrint(m_themePath); 0044 grantleePrint.setApplicationDomain("kaddressbook"); 0045 const QString html = grantleePrint.contactsToHtml(contacts); 0046 0047 QTextDocument document; 0048 document.setHtml(html); 0049 0050 progress->addMessage(i18n("Printing")); 0051 0052 document.print(printer); 0053 0054 progress->addMessage(i18nc("Finished printing", "Done")); 0055 } 0056 0057 GrantleeStyleFactory::GrantleeStyleFactory(const QString &name, const QString &themePath, PrintingWizard *parent) 0058 : PrintStyleFactory(parent) 0059 , mThemePath(themePath) 0060 , mName(name) 0061 { 0062 } 0063 0064 PrintStyle *GrantleeStyleFactory::create() const 0065 { 0066 return new GrantleePrintStyle(mThemePath, mParent); 0067 } 0068 0069 QString GrantleeStyleFactory::description() const 0070 { 0071 return mName; 0072 } 0073 0074 #include "moc_grantleeprintstyle.cpp"