2 * Copyright 2010 Thomas McGuire <mcguire@kde.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 #include "inserttextfilejob.h"
29 using namespace Message
;
31 InsertTextFileJob::InsertTextFileJob( QTextEdit
*editor
, const KUrl
&url
)
32 : KJob( editor
), mEditor( editor
), mUrl( url
)
36 InsertTextFileJob::~InsertTextFileJob()
40 void InsertTextFileJob::slotFileData ( KIO::Job
* job
, const QByteArray
& data
)
46 void InsertTextFileJob::slotGetJobFinished( KJob
* job
)
49 kWarning() << job
->errorString();
50 setError( job
->error() );
51 setErrorText( job
->errorText() );
57 const QTextCodec
*fileCodec
= 0;
58 if ( !mEncoding
.isEmpty() ) {
59 fileCodec
= KGlobal::charsets()->codecForName( mEncoding
);
61 mEditor
->textCursor().insertText( fileCodec
->toUnicode( mFileData
.data() ) );
63 mEditor
->textCursor().insertText( QString::fromLocal8Bit( mFileData
.data() ) );
71 void InsertTextFileJob::setEncoding( const QString
&encoding
)
76 void InsertTextFileJob::start()
78 KIO::TransferJob
*job
= KIO::get( mUrl
);
79 connect( job
, SIGNAL( result( KJob
* ) ),
80 this, SLOT( slotGetJobFinished( KJob
* ) ) );
81 connect( job
, SIGNAL( data( KIO::Job
*, const QByteArray
& ) ),
82 this, SLOT( slotFileData( KIO::Job
*, const QByteArray
& ) ) );