~ubuntu-branches/ubuntu/wily/kbibtex/wily

« back to all changes in this revision

Viewing changes to src/documentsourceview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2009-06-15 12:41:19 UTC
  • mfrom: (1.1.3 upstream) (2.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090615124119-eoojhlvkmw3o9tkm
Tags: 0.2.2-1
* New upstream version (Closes: #487301, #507837, #518959, #520392).
* Bumped Standards-Version to 3.8.1. No changes necessary.
* Added 'DM-Upload-Allowed: yes'.
* Added missing '${misc:Depends}'.
* Support for per-file encoding settings (Closes: #514356)
* Upgrade debhelper compatibility to version 5.
* Update debian/copyright for 2009 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
*   Copyright (C) 2004-2008 by Thomas Fischer                             *
 
2
*   Copyright (C) 2004-2009 by Thomas Fischer                             *
3
3
*   fischer@unix-ag.uni-kl.de                                             *
4
4
*                                                                         *
5
5
*   This program is free software; you can redistribute it and/or modify  *
32
32
#include <ktrader.h>
33
33
#include <kmimetype.h>
34
34
#include <kservice.h>
 
35
#include <kprogress.h>
35
36
#include <kparts/componentfactory.h>
36
37
#include <ktexteditor/configinterface.h>
37
38
#include <ktexteditor/editorchooser.h>
46
47
{
47
48
 
48
49
    DocumentSourceView::DocumentSourceView( KBibTeX::DocumentWidget *docWidget, bool isReadOnly, QWidget *parent, const char *name )
49
 
            : QWidget( parent, name ), m_isReadOnly( isReadOnly ), m_docWidget( docWidget ), m_bibtexFile( NULL ), m_document( NULL ), m_view( NULL )
 
50
            : QWidget( parent, name ), m_isReadOnly( isReadOnly ), m_docWidget( docWidget ), m_bibtexFile( NULL ), m_document( NULL ), m_view( NULL ), m_progDlg( NULL )
50
51
    {
51
52
        setupGUI();
52
53
 
210
211
        Settings * settings = Settings::self();
211
212
 
212
213
        bool result = FALSE;
 
214
        m_progDlg = new KProgressDialog( this, NULL, i18n( "Source View" ), i18n( "Converting BibTeX document to plain text ..." ), true );
 
215
        m_progDlg->setAllowCancel( false );
 
216
        kapp->processEvents();
213
217
 
214
218
        QBuffer buffer;
215
219
        buffer.open( IO_WriteOnly );
216
220
        BibTeX::FileExporterBibTeX * exporter = new BibTeX::FileExporterBibTeX();
 
221
        connect( exporter, SIGNAL( progress( int, int ) ), this, SLOT( updateProgress( int, int ) ) );
217
222
        exporter->setStringDelimiter( settings->fileIO_BibtexStringOpenDelimiter, settings->fileIO_BibtexStringCloseDelimiter );
218
223
        exporter->setKeywordCasing( settings->fileIO_KeywordCasing );
219
 
        exporter->setEncoding(( BibTeX::File::Encoding ) settings->fileIO_Encoding );
 
224
        exporter->setEncoding( "latex" );
220
225
        exporter->setEnclosingCurlyBrackets( settings->fileIO_EnclosingCurlyBrackets );
221
226
        result = exporter->save( &buffer, bibtexFile );
222
227
        delete exporter;
224
229
 
225
230
        if ( result )
226
231
        {
 
232
            kapp->processEvents();
227
233
            buffer.open( IO_ReadOnly );
228
234
            QTextStream in( &buffer );
229
235
            in.setEncoding( QTextStream::UnicodeUTF8 );
232
238
 
233
239
            if ( m_editInterface )
234
240
            {
 
241
                kapp->processEvents();
235
242
                // very strange: to set the text, you have to set
236
243
                // readwrite to TRUE...
237
244
                m_document->setReadWrite( TRUE );
242
249
            m_bibtexFile = bibtexFile;
243
250
        }
244
251
 
 
252
        kapp->processEvents();
 
253
        delete m_progDlg;
 
254
 
245
255
        return result;
246
256
    }
247
257
 
358
368
        }
359
369
        while ( KMessageBox::questionYesNo( this, QString( i18n( "Could not find text '%1' in the document.\nStart from the beginning?" ) ).arg( m_lastSearchTerm ), i18n( "Find text in source view" ), KGuiItem( i18n( "Restart search" ) ) ) == KMessageBox::Yes );
360
370
    }
 
371
 
 
372
    void DocumentSourceView::updateProgress( int current, int total )
 
373
    {
 
374
        m_progDlg->progressBar()->setTotalSteps( total );
 
375
        m_progDlg->progressBar()->setValue( current );
 
376
        kapp->processEvents();
 
377
    }
 
378
 
361
379
}
362
380
#include "documentsourceview.moc"