~ubuntu-branches/ubuntu/wily/scribus/wily-proposed

« back to all changes in this revision

Viewing changes to scribus/plugins/tools/spellcheck/aspellpluginimpl.cpp

  • Committer: Package Import Robot
  • Author(s): Oleksandr Moskalenko
  • Date: 2012-02-09 21:50:56 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120209215056-2wrx1ara0jbm7fi5
Tags: 1.4.0.dfsg+r17287-1
* New upstream stable release upload into Debian (Closes: #654703).
* Applied the Ubuntu armel patch.
* Removed non-free color swatches from resources.
* debian/control:
  - Moved icc-profiles from Recommends to Suggests (Closes: #655885).
  - Updated Standards-Version to 3.9.2.
  - Updated extended description per lintian warning.
* debian/rules:
  - Update mailcap (Closes: #630751). A request for mime.types update has
    been sent to the mime-support maintainer.
  - Added build-arch and build-indep targets per lintian warning.
* debian/patches:
  - top_cmakelists.patch - don't copy extra docs and changelogs.
  - scribus_cmakelists.patch - don't copy extra docs and changelogs.
  - scribus_cmakelists.patch - don't install the non-free "doc" dir.
  - profiles_cmakelists.patch - don't install non-free sRGB profile.
* debian/copyright: 
  - Converted to the DEP5 machine readable foramt.
  - Added licenses for free color swatches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
#include "pageitem_textframe.h"
9
9
#include "text/specialchars.h"
10
10
#include "util.h"
 
11
#include <QDebug>
11
12
#include <QMessageBox>
12
13
 
13
14
const char* AspellPluginImpl::kDEF_CONTEXT = "AspellPlugin";
20
21
// Initialize members here, if any
21
22
AspellPluginImpl::AspellPluginImpl(ScribusDoc* doc, QWidget* parent) :
22
23
        QDialog( parent ),
 
24
        fsuggest(0),
23
25
        fdoc( doc ),
24
26
        m_docIsChanged(false),
25
27
        fpos(0),
36
38
        getPreferences();
37
39
        QString text = tr( "Loaded " ) + (fentry == kDEF_ASPELL_ENTRY ? tr( "default " ) : "") + fentry + tr( " aspell dictionary." );
38
40
        doc->scMW()->setStatusBarInfoText( text );
 
41
        bool dictCount=0;
39
42
        try
40
43
        {
41
44
                // Deactivate GUI elements in spell-checking tab until an
50
53
                // Get list of available aspell dictionaries
51
54
                std::vector<std::string> entries;
52
55
                fsuggest->listDicts( entries );
53
 
                for( std::vector<std::string>::const_iterator i = entries.begin(); i != entries.end(); ++i )
 
56
                dictCount=entries.size();
 
57
                if (!entries.empty())
54
58
                {
55
 
                        // FIXME: Handle encodings other than UTF-8.
56
 
                        flistDicts->addItem(i->c_str());
57
 
//                      qDebug() << i->c_str();
 
59
                        //qDebug()<<"Listing dictionaries";
 
60
                        for( std::vector<std::string>::const_iterator i = entries.begin(); i != entries.end(); ++i )
 
61
                        {
 
62
                                // FIXME: Handle encodings other than UTF-8.
 
63
                                flistDicts->addItem(i->c_str());
 
64
                                //qDebug() << i->c_str();
 
65
                        }
58
66
                }
59
67
                // check the availability of any dict. If == 0 then the plugin
60
68
                // is disabled in all GUI.
61
 
                if (flistDicts->count() == 0)
 
69
                if (entries.empty() || flistDicts->count() == 0)
 
70
                {
 
71
                        //qDebug() << "Dictionaries found:"<<flistDicts->count();
62
72
                        m_errorMessage = tr("No available Aspell dictionaries found. Install some, please.");
63
 
                // use dict for system local if there are no preferences set before
64
 
                QString locale(QLocale::system().name().left(2));
65
 
                if (fentry.isEmpty())
 
73
                        qWarning()<<m_errorMessage.toUtf8().data();
 
74
                }
 
75
                else
66
76
                {
67
 
                        int ix = flistDicts->findText(locale, Qt::MatchStartsWith);
68
 
                        if (ix != -1)
69
 
                                flistDicts->setCurrentIndex(ix);
 
77
                        // use dict for system local if there are no preferences set before
 
78
                        QString locale(QLocale::system().name().left(2));
 
79
                        if (fentry.isEmpty())
 
80
                        {
 
81
                                int ix = flistDicts->findText(locale, Qt::MatchStartsWith);
 
82
                                if (ix != -1)
 
83
                                        flistDicts->setCurrentIndex(ix);
 
84
                                else
 
85
                                {
 
86
                                        fentry = kDEF_ASPELL_ENTRY;
 
87
                                        setCurrentComboItem(flistDicts, fentry);
 
88
                                }
 
89
                        }
70
90
                        else
71
 
                        {
72
 
                                fentry = kDEF_ASPELL_ENTRY;
73
91
                                setCurrentComboItem(flistDicts, fentry);
74
 
                        }
 
92
                        handleSpellConfig(flistDicts->currentText());
75
93
                }
76
 
                else
77
 
                        setCurrentComboItem(flistDicts, fentry);
78
 
                handleSpellConfig(flistDicts->currentText());
79
94
        }
80
95
        catch( const std::invalid_argument& err )
81
96
        {
82
 
                QString warn = tr( "aspellplugin (AspellPluginImpl::"
83
 
                                   "AspellPluginImpl): Error in aspell "
84
 
                                   "speller configuration." );
85
 
                qWarning( "%s", warn.toUtf8().data() );
 
97
                QString warn = tr( "Spell Checker Plugin Failed to Initialise.\nConfiguration invalid" );
 
98
                qWarning()<<warn.toUtf8().data();
 
99
                if (m_errorMessage.isEmpty())
 
100
                        m_errorMessage=warn;
86
101
        }
87
102
        catch( const std::runtime_error& err )
88
103
        {
89
 
                QString warn = tr( "aspellplugin (AspellPluginImpl::"
90
 
                                   "AspellPluginImpl): Error in creating "
91
 
                                   "aspell speller." );
92
 
                qWarning( "%s", warn.toUtf8().data() );
93
 
        }
94
 
        activateSpellGUI(true);
95
 
        parseSelection();
 
104
                QString warn = tr( "Spell Checker Plugin Failed to Initialise.");
 
105
                if (dictCount==0)
 
106
                        warn+="\n"+tr( "No Aspell dictionaries could be found." );
 
107
                qWarning()<<warn.toUtf8().data();
 
108
                if (m_errorMessage.isEmpty())
 
109
                        m_errorMessage=warn;
 
110
        }
 
111
        if (m_errorMessage.isEmpty())
 
112
        {
 
113
                activateSpellGUI(true);
 
114
                parseSelection();
 
115
        }
96
116
}
97
117
//__________________________________________________________________________
98
118
AspellPluginImpl::~AspellPluginImpl()
99
119
{
100
 
        // Destructor
101
 
        try
102
 
        {
103
 
                fsuggest->saveLists();
104
 
        }
105
 
        catch( const std::runtime_error& err )
106
 
        {
107
 
                qWarning( "aspellplugin (AspellPluginImpl::~AspellPlugin"
108
 
                          "Impl): Error in saving aspell word lists." );
109
 
        }
110
 
 
111
 
        delete fsuggest;
 
120
        if (m_errorMessage.isEmpty())
 
121
        {
 
122
                // Destructor
 
123
                try
 
124
                {
 
125
                        fsuggest->saveLists();
 
126
                }
 
127
                catch( const std::runtime_error& err )
 
128
                {
 
129
                        qWarning( "aspellplugin (AspellPluginImpl::~AspellPlugin"
 
130
                                  "Impl): Error in saving aspell word lists." );
 
131
                }
 
132
        }
 
133
        if (fsuggest)
 
134
                delete fsuggest;
112
135
}
113
136
//__________________________________________________________________________
114
137
void AspellPluginImpl::activateSpellGUI(bool active)
254
277
{
255
278
        // Called when the "Close" button is clicked. Makes any pending
256
279
        // replacements and closes the spell-checking window.
257
 
        spellCheckDone();  // Also closes spell-checking window.
 
280
        if (m_errorMessage.isEmpty())
 
281
                spellCheckDone();  // Also closes spell-checking window.
258
282
}
259
283
//__________________________________________________________________________
260
284
void AspellPluginImpl::on_fchangeBtn_clicked()