Kstars

pwizprint.cpp
1/*
2 SPDX-FileCopyrightText: 2011 Rafał Kułaga <rl.kulaga@gmail.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "pwizprint.h"
8
9#include "finderchart.h"
10#include "kstars.h"
11#include "ksnotification.h"
12#include "Options.h"
13#include "printingwizard.h"
14
15#include <KMessageBox>
16#include <KIO/StoredTransferJob>
17
18#include <QFileDialog>
19#include <QTemporaryFile>
20#include <QPrintPreviewDialog>
21#include <QPrinter>
22#include <QPrintDialog>
23#include <QPointer>
24
25PWizPrintUI::PWizPrintUI(PrintingWizard *wizard, QWidget *parent) : QFrame(parent), m_ParentWizard(wizard)
26{
27 setupUi(this);
28
29 connect(previewButton, SIGNAL(clicked()), this, SLOT(slotPreview()));
30 connect(printButton, SIGNAL(clicked()), this, SLOT(slotPrint()));
31 connect(exportButton, SIGNAL(clicked()), this, SLOT(slotExport()));
32}
33
34void PWizPrintUI::slotPreview()
35{
37 connect(previewDlg, SIGNAL(paintRequested(QPrinter*)), SLOT(slotPrintPreview(QPrinter*)));
38 previewDlg->exec();
39 delete previewDlg;
40}
41
42void PWizPrintUI::slotPrintPreview(QPrinter *printer)
43{
44 printDocument(printer);
45}
46
47void PWizPrintUI::slotPrint()
48{
49 QPointer<QPrintDialog> dialog(new QPrintDialog(m_ParentWizard->getPrinter(), KStars::Instance()));
50 if (dialog->exec() == QDialog::Accepted)
51 {
52 printDocument(m_ParentWizard->getPrinter());
53 }
54 delete dialog;
55}
56
57void PWizPrintUI::printDocument(QPrinter *printer)
58{
59 m_ParentWizard->getFinderChart()->print(printer);
60}
61
62void PWizPrintUI::slotExport()
63{
64 QUrl url =
66 "application/pdf application/postscript application/vnd.oasis.opendocument.text");
67 //User cancelled file selection dialog - abort image export
68 if (url.isEmpty())
69 {
70 return;
71 }
72
73 //Warn user if file exists!
74 if (QFile::exists(url.toLocalFile()))
75 {
77 parentWidget(), i18n("A file named \"%1\" already exists. Overwrite it?", url.fileName()),
78 i18n("Overwrite File?"), KStandardGuiItem::overwrite());
79 if (r == KMessageBox::Cancel)
80 return;
81 }
82
83 QString urlStr = url.url();
84 if (!urlStr.contains(QDir::separator()))
85 {
86 urlStr = QDir::homePath() + '/' + urlStr;
87 }
88
90 tmpfile.open();
92
93 if (url.isValid())
94 {
95 if (url.isLocalFile())
96 {
97 fname = url.toLocalFile();
98 }
99
100 else
101 {
102 fname = tmpfile.fileName();
103 }
104
105 //Determine desired image format from filename extension
106 QString ext = fname.mid(fname.lastIndexOf(".") + 1);
107 if (ext == "pdf" || ext == "ps")
108 {
109 m_ParentWizard->getFinderChart()->writePsPdf(fname);
110 }
111 else if (ext == "odt")
112 {
113 m_ParentWizard->getFinderChart()->writeOdt(fname);
114 }
115 else
116 {
117 return;
118 }
119
120 if (tmpfile.fileName() == fname)
121 {
122 //attempt to upload image to remote location
123 if (KIO::storedHttpPost(&tmpfile, url)->exec() == false)
124 //if(!KIO::NetAccess::upload(tmpfile.fileName(), url, this))
125 {
126 QString message = i18n("Could not upload file to remote location: %1", url.url());
127 KSNotification::sorry(message, i18n("Could not upload file"));
128 }
129 }
130 }
131}
void writePsPdf(const QString &fname)
Write contents of the document to the Postscript/PDF file.
bool writeOdt(const QString &fname)
Write contents of the document to Open Document Text file.
void print(QPrinter *printer)
Print contents of the document.
static KStars * Instance()
Definition kstars.h:123
PWizPrintUI(PrintingWizard *wizard, QWidget *parent=nullptr)
Constructor.
Definition pwizprint.cpp:25
Class representing Printing Wizard for KStars printed documents (currently only finder charts).
FinderChart * getFinderChart()
Get used FinderChart document.
QPrinter * getPrinter()
Get printer used by Printing Wizard.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
KIOCORE_EXPORT StoredTransferJob * storedHttpPost(const QByteArray &arr, const QUrl &url, JobFlags flags=DefaultFlags)
ButtonCode warningContinueCancel(QWidget *parent, const QString &text, const QString &title=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Notify)
KGuiItem overwrite()
QString homePath()
QChar separator()
bool exists() const const
QUrl getSaveFileUrl(QWidget *parent, const QString &caption, const QUrl &dir, const QString &filter, QString *selectedFilter, Options options, const QStringList &supportedSchemes)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString fileName(ComponentFormattingOptions options) const const
bool isEmpty() const const
bool isLocalFile() const const
bool isValid() const const
QString toLocalFile() const const
QString url(FormattingOptions options) const const
QWidget * parentWidget() const const
void setupUi(QWidget *widget)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:48:27 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.