Switch to unified view

a/src/qtgui/spell_w.cpp b/src/qtgui/spell_w.cpp
1
#ifndef lint
1
#ifndef lint
2
static char rcsid[] = "@(#$Id: spell_w.cpp,v 1.5 2006-11-06 17:37:22 dockes Exp $ (C) 2005 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: spell_w.cpp,v 1.6 2006-11-21 08:47:51 dockes Exp $ (C) 2005 J.F.Dockes";
3
#endif
3
#endif
4
/*
4
/*
5
 *   This program is free software; you can redistribute it and/or modify
5
 *   This program is free software; you can redistribute it and/or modify
6
 *   it under the terms of the GNU General Public License as published by
6
 *   it under the terms of the GNU General Public License as published by
7
 *   the Free Software Foundation; either version 2 of the License, or
7
 *   the Free Software Foundation; either version 2 of the License, or
...
...
41
#include "rclaspell.h"
41
#include "rclaspell.h"
42
#endif
42
#endif
43
43
44
void SpellW::init()
44
void SpellW::init()
45
{
45
{
46
    // Don't change the order, or fix the rest of the code...
46
    expTypeCMB->insertItem(tr("Wildcards"));
47
    /*0*/expTypeCMB->insertItem(tr("Wildcards"));
47
    expTypeCMB->insertItem(tr("Regexp"));
48
    /*1*/expTypeCMB->insertItem(tr("Regexp"));
48
    int maxtyp = 1;
49
    /*2*/expTypeCMB->insertItem(tr("Stem expansion"));
49
#ifdef RCL_USE_ASPELL
50
#ifdef RCL_USE_ASPELL
50
    expTypeCMB->insertItem(tr("Spelling/Phonetic"));
51
    /*3*/expTypeCMB->insertItem(tr("Spelling/Phonetic"));
51
    maxtyp = 2;
52
#endif
52
#endif
53
53
    int typ = prefs.termMatchType;
54
    int typ = prefs.termMatchType;
54
    if (typ < 0 || typ > maxtyp)
55
    if (typ < 0 || typ > expTypeCMB->count())
55
    typ = 0;
56
    typ = 0;
56
    expTypeCMB->setCurrentItem(typ);
57
    expTypeCMB->setCurrentItem(typ);
58
59
    // Stemming language combobox
60
    stemLangCMB->clear();
61
    list<string> langs;
62
    if (!getStemLangs(langs)) {
63
  QMessageBox::warning(0, "Recoll", 
64
               tr("error retrieving stemming languages"));
65
    }
66
    for (list<string>::const_iterator it = langs.begin(); 
67
   it != langs.end(); it++) {
68
  stemLangCMB->
69
      insertItem(QString::fromAscii(it->c_str(), it->length()));
70
    }
71
    stemLangCMB->setEnabled(false);
57
72
58
    // signals and slots connections
73
    // signals and slots connections
59
    connect(baseWordLE, SIGNAL(textChanged(const QString&)), 
74
    connect(baseWordLE, SIGNAL(textChanged(const QString&)), 
60
        this, SLOT(wordChanged(const QString&)));
75
        this, SLOT(wordChanged(const QString&)));
61
    connect(baseWordLE, SIGNAL(returnPressed()), this, SLOT(doExpand()));
76
    connect(baseWordLE, SIGNAL(returnPressed()), this, SLOT(doExpand()));
62
    connect(expandPB, SIGNAL(clicked()), this, SLOT(doExpand()));
77
    connect(expandPB, SIGNAL(clicked()), this, SLOT(doExpand()));
63
    connect(dismissPB, SIGNAL(clicked()), this, SLOT(close()));
78
    connect(dismissPB, SIGNAL(clicked()), this, SLOT(close()));
64
    connect(suggsTE, SIGNAL(doubleClicked(int, int)), 
79
    connect(suggsTE, SIGNAL(doubleClicked(int, int)), 
65
        this, SLOT(textDoubleClicked(int, int)));
80
        this, SLOT(textDoubleClicked(int, int)));
81
    connect(expTypeCMB, SIGNAL(activated(int)), 
82
      this, SLOT(modeSet(int)));
66
}
83
}
67
84
68
/* Expand term according to current mode */
85
/* Expand term according to current mode */
69
void SpellW::doExpand()
86
void SpellW::doExpand()
70
{
87
{
...
...
79
    }
96
    }
80
97
81
    string expr = string((const char *)baseWordLE->text().utf8());
98
    string expr = string((const char *)baseWordLE->text().utf8());
82
    list<string> suggs;
99
    list<string> suggs;
83
    prefs.termMatchType = expTypeCMB->currentItem();
100
    prefs.termMatchType = expTypeCMB->currentItem();
101
84
    Rcl::Db::MatchType mt = Rcl::Db::ET_WILD;
102
    Rcl::Db::MatchType mt = Rcl::Db::ET_WILD;
85
    switch (expTypeCMB->currentItem()) {
103
    switch (expTypeCMB->currentItem()) {
86
    case 1: mt = Rcl::Db::ET_REGEXP;
104
    case 1: mt = Rcl::Db::ET_REGEXP;
87
    /* FALLTHROUGH */
105
    /* FALLTHROUGH */
88
    case 0: 
106
    case 0: 
...
...
90
                  200)) {
108
                  200)) {
91
        LOGERR(("SpellW::doExpand:rcldb::termMatch failed\n"));
109
        LOGERR(("SpellW::doExpand:rcldb::termMatch failed\n"));
92
        return;
110
        return;
93
    }
111
    }
94
    break;
112
    break;
113
114
115
    case 2: 
116
  {
117
      string stemlang = (const char *)stemLangCMB->currentText().utf8();
118
      suggs = rcldb->stemExpand(stemlang,expr);
119
  }
120
  break;
121
95
#ifdef RCL_USE_ASPELL
122
#ifdef RCL_USE_ASPELL
96
    case 2: {
123
    case 3: {
97
    LOGDEB(("SpellW::doExpand: aspelling\n"));
124
    LOGDEB(("SpellW::doExpand: aspelling\n"));
98
    if (!aspell) {
125
    if (!aspell) {
99
        QMessageBox::warning(0, "Recoll",
126
        QMessageBox::warning(0, "Recoll",
100
                 tr("Aspell init failed. "
127
                 tr("Aspell init failed. "
101
                    "Aspell not installed?"));
128
                    "Aspell not installed?"));
...
...
110
    }
137
    }
111
#endif
138
#endif
112
    }
139
    }
113
140
114
    if (suggs.empty()) {
141
    if (suggs.empty()) {
115
    suggsTE->append(tr("No spelling expansion found"));
142
    suggsTE->append(tr("No expansion found"));
116
    } else {
143
    } else {
117
    for (list<string>::iterator it = suggs.begin(); 
144
    for (list<string>::iterator it = suggs.begin(); 
118
         it != suggs.end(); it++) {
145
         it != suggs.end(); it++) {
119
        suggsTE->append(QString::fromUtf8(it->c_str()));
146
        suggsTE->append(QString::fromUtf8(it->c_str()));
120
    }
147
    }
...
...
137
{
164
{
138
    suggsTE->setSelection(para, 0, para, 1000);
165
    suggsTE->setSelection(para, 0, para, 1000);
139
    if (suggsTE->hasSelectedText())
166
    if (suggsTE->hasSelectedText())
140
    emit(wordSelect(suggsTE->selectedText()));
167
    emit(wordSelect(suggsTE->selectedText()));
141
}
168
}
169
170
void SpellW::modeSet(int mode)
171
{
172
    if (mode == 2)
173
  stemLangCMB->setEnabled(true);
174
    else
175
  stemLangCMB->setEnabled(false);
176
}