Commit bb1f92c4 authored by Christoph Cullmann's avatar Christoph Cullmann 🐮

download the file itself, to get for the http charset stuff to detect the right charset to use

svn path=/trunk/kdelibs/; revision=259782
parent 7e5a6432
......@@ -48,6 +48,7 @@
#include <ktexteditor/plugin.h>
#include <kio/job.h>
#include <kio/netaccess.h>
#include <kparts/event.h>
......@@ -71,6 +72,7 @@
#include <kdirwatch.h>
#include <kwin.h>
#include <kencodingfiledialog.h>
#include <ktempfile.h>
#include <qtimer.h>
#include <qfile.h>
......@@ -106,7 +108,9 @@ KateDocument::KateDocument ( bool bSingleViewMode, bool bBrowserView,
lastUndoGroupWhenSaved( 0 ),
docWasSavedWhenUndoWasEmpty( true ),
m_modOnHd (false),
m_modOnHdReason (0)
m_modOnHdReason (0),
m_job (0),
m_tempFile (0)
{
// my dcop object
setObjId ("KateDocument#"+documentDCOPSuffix());
......@@ -2249,12 +2253,121 @@ bool KateDocument::print ()
//BEGIN KParts::ReadWrite stuff
bool KateDocument::openURL( const KURL &url )
{
// no valid URL
if ( !url.isValid() )
return false;
// could not close old one
if ( !closeURL() )
return false;
// set my url
m_url = url;
if ( m_url.isLocalFile() )
{
// local mode, just like in kpart
m_file = m_url.path();
emit started( 0 );
if (openFile())
{
emit completed();
emit setWindowCaption( m_url.prettyURL() );
return true;
}
return false;
}
else
{
// remote mode
m_bTemp = true;
m_tempFile = new KTempFile ();
m_file = m_tempFile->name();
m_job = KIO::get ( url, false, isProgressInfoEnabled() );
// we want to have the http header
//m_job->addMetaData ("PropagateHttpHeader", "true");
m_job->setWindow( widget() ? widget()->topLevelWidget() : 0 );
emit started( m_job );
connect( m_job, SIGNAL( data( KIO::Job*, const QByteArray& ) ),
SLOT( slotDataKate( KIO::Job*, const QByteArray& ) ) );
connect( m_job, SIGNAL( result( KIO::Job* ) ),
SLOT( slotFinishedKate( KIO::Job* ) ) );
return true;
}
}
void KateDocument::slotDataKate ( KIO::Job *, const QByteArray &data )
{
kdDebug(13020) << "KateDocument::slotData" << endl;
if (!m_tempFile || !m_tempFile->file())
return;
m_tempFile->file()->writeBlock (data);
}
void KateDocument::slotFinishedKate ( KIO::Job * job )
{
kdDebug(13020) << "KateDocument::slotJobFinished" << endl;
if (!m_tempFile)
return;
delete m_tempFile;
m_tempFile = 0;
m_job = 0;
if (job->error())
emit canceled( job->errorString() );
else
{
if ( openFile(job) )
emit setWindowCaption( m_url.prettyURL() );
emit completed();
}
}
void KateDocument::abortLoadKate()
{
if ( m_job )
{
kdDebug(13020) << "Aborting job " << m_job << endl;
m_job->kill();
m_job = 0;
}
delete m_tempFile;
m_tempFile = 0;
}
bool KateDocument::openFile()
{
return openFile (0);
}
bool KateDocument::openFile(KIO::Job * job)
{
//
// add the file to dirwatch
//
if (!m_file.isEmpty())
if (m_url.isLocalFile() && !m_file.isEmpty())
KateFactory::self()->dirWatch ()->addFile (m_file);
//
......@@ -2266,7 +2379,18 @@ bool KateDocument::openFile()
m_modOnHdReason = 0;
emit modifiedOnDisc (this, m_modOnHd, 0);
}
//
// use metadata
//
if (job)
{
QString metaDataCharset = job->queryMetaData("charset");
if (!metaDataCharset.isEmpty ())
setEncoding (metaDataCharset);
}
//
// service type magic to get encoding right
//
......@@ -2401,7 +2525,7 @@ bool KateDocument::saveFile()
//
// remove the m_file before saving from dirwatch
//
if (!m_file.isEmpty())
if (m_url.isLocalFile() && !m_file.isEmpty())
KateFactory::self()->dirWatch ()->removeFile (m_file);
//
......@@ -2449,7 +2573,7 @@ bool KateDocument::saveFile()
//
// add file again
//
if (!m_file.isEmpty())
if (m_url.isLocalFile() && !m_file.isEmpty())
KateFactory::self()->dirWatch ()->addFile (m_file);
//
......@@ -2478,6 +2602,8 @@ bool KateDocument::saveFile()
bool KateDocument::closeURL()
{
abortLoadKate();
//
// file mod on hd
//
......@@ -2509,7 +2635,7 @@ bool KateDocument::closeURL()
//
// remove file from dirwatch
//
if (!m_file.isEmpty())
if (m_url.isLocalFile() && !m_file.isEmpty())
KateFactory::self()->dirWatch ()->removeFile (m_file);
//
......
......@@ -38,6 +38,8 @@
namespace KTextEditor { class Plugin; }
namespace KIO { class TransferJob; }
class KateUndoGroup;
class KateCmd;
class KateAttribute;
......@@ -55,6 +57,7 @@ class KateDocumentConfig;
class Highlight;
class KSpell;
class KTempFile;
class QTimer;
......@@ -443,17 +446,28 @@ class KateDocument : public Kate::Document,
// KParts::ReadWrite stuff
//
public:
bool openURL( const KURL &url );
/* Anders:
I reimplemented this, since i need to check if backup succeeded
if requested */
bool save();
bool openFile (KIO::Job * job);
bool openFile ();
bool saveFile ();
void setReadWrite ( bool rw = true );
void setModified( bool m );
private slots:
void slotDataKate ( KIO::Job* kio_job, const QByteArray &data );
void slotFinishedKate ( KIO::Job * job );
private:
void abortLoadKate();
//
// Kate::Document stuff
......@@ -804,7 +818,10 @@ class KateDocument : public Kate::Document,
static QRegExp kvLine;
static QRegExp kvVar;
KIO::TransferJob *m_job;
KTempFile *m_tempFile;
k_dcop:
uint documentNumber () const;
......
......@@ -849,7 +849,7 @@ void KateView::flush()
KateView::saveResult KateView::save()
{
if( m_doc->url().fileName().isEmpty() || !doc()->isReadWrite() )
if( !m_doc->url().isValid() || !doc()->isReadWrite() )
return saveAs();
if( m_doc->save() )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment