• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.14
  • kdepim
  • kmail
  • job
saveasfilejob.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2015 Montel Laurent <montel@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 
19 */
20 
21 #include "saveasfilejob.h"
22 #include <KFileDialog>
23 #include <qpointer.h>
24 #include <qtextdocumentwriter.h>
25 #include <QDebug>
26 #include <KUrl>
27 #include <messagecomposer/composer/kmeditor.h>
28 
29 SaveAsFileJob::SaveAsFileJob(QObject *parent)
30  : QObject(parent),
31  mHtmlMode(false),
32  mEditor(0),
33  mParentWidget(0)
34 {
35 
36 }
37 
38 SaveAsFileJob::~SaveAsFileJob()
39 {
40 
41 }
42 
43 void SaveAsFileJob::start()
44 {
45  QPointer<KFileDialog> dlg = new KFileDialog(KUrl(),QString(),mParentWidget);
46  dlg->setOperationMode(KFileDialog::Saving);
47  dlg->setConfirmOverwrite(true);
48  if( mHtmlMode ) {
49  dlg->setFilter( QString::fromLatin1("text/html text/plain application/vnd.oasis.opendocument.text") );
50  } else {
51  dlg->setFilter( QString::fromLatin1("text/plain") );
52  }
53 
54  if(dlg->exec()) {
55  QTextDocumentWriter writer;
56  const QString filename = dlg->selectedUrl().path();
57  writer.setFileName(dlg->selectedUrl().path());
58  if (dlg->currentFilter() == QString::fromLatin1("text/plain") || filename.endsWith(QLatin1String(".txt"))) {
59  writer.setFormat("plaintext");
60  } else if (dlg->currentFilter() == QString::fromLatin1("text/html")|| filename.endsWith(QLatin1String(".html"))) {
61  writer.setFormat("HTML");
62  } else if (dlg->currentFilter() == QString::fromLatin1("application/vnd.oasis.opendocument.text") || filename.endsWith(QLatin1String(".odf"))) {
63  writer.setFormat("ODF");
64  } else {
65  writer.setFormat("plaintext");
66  }
67  if (!writer.write(mEditor->document())) {
68  qDebug()<<" Error during writing";
69  }
70  }
71  delete dlg;
72  deleteLater();
73 }
74 
75 void SaveAsFileJob::setHtmlMode(bool htmlMode)
76 {
77  mHtmlMode = htmlMode;
78 }
79 
80 void SaveAsFileJob::setEditor(MessageComposer::KMeditor *editor)
81 {
82  mEditor = editor;
83 }
84 
85 void SaveAsFileJob::setParentWidget(QWidget *parentWidget)
86 {
87  mParentWidget = parentWidget;
88 }
89 
90 
91 
92 
QWidget
SaveAsFileJob::SaveAsFileJob
SaveAsFileJob(QObject *parent=0)
Definition: saveasfilejob.cpp:29
SaveAsFileJob::setEditor
void setEditor(MessageComposer::KMeditor *editor)
Definition: saveasfilejob.cpp:80
SaveAsFileJob::start
void start()
Definition: saveasfilejob.cpp:43
QPointer
SaveAsFileJob::setParentWidget
void setParentWidget(QWidget *parentWidget)
Definition: saveasfilejob.cpp:85
QTextDocumentWriter
QObject
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
QObject::deleteLater
void deleteLater()
QString
saveasfilejob.h
SaveAsFileJob::~SaveAsFileJob
~SaveAsFileJob()
Definition: saveasfilejob.cpp:38
QLatin1String
SaveAsFileJob::setHtmlMode
void setHtmlMode(bool htmlMode)
Definition: saveasfilejob.cpp:75
QTextDocumentWriter::write
bool write(const QTextDocument *document)
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QTextDocumentWriter::setFormat
void setFormat(const QByteArray &format)
QTextDocumentWriter::setFileName
void setFileName(const QString &fileName)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal