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.2 2006-10-15 13:07:45 dockes Exp $ (C) 2005 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: spell_w.cpp,v 1.3 2006-10-30 12:59:44 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
...
...
28
#include <qtextedit.h>
28
#include <qtextedit.h>
29
#include <qlabel.h>
29
#include <qlabel.h>
30
#include <qlineedit.h>
30
#include <qlineedit.h>
31
#include <qlayout.h>
31
#include <qlayout.h>
32
#include <qtooltip.h>
32
#include <qtooltip.h>
33
#include <qcombobox.h>
33
34
34
#include "debuglog.h"
35
#include "debuglog.h"
35
#include "recoll.h"
36
#include "recoll.h"
36
#include "spell_w.h"
37
#include "spell_w.h"
38
#include "guiutils.h"
37
39
38
#ifdef RCL_USE_ASPELL
40
#ifdef RCL_USE_ASPELL
39
#include "rclaspell.h"
41
#include "rclaspell.h"
40
#endif
42
#endif
41
43
42
void SpellW::init()
44
void SpellW::init()
43
{
45
{
46
    expTypeCMB->insertItem(tr("Wildcards"));
47
    expTypeCMB->insertItem(tr("Regexp"));
48
    int maxtyp = 1;
49
#ifdef RCL_USE_ASPELL
50
    expTypeCMB->insertItem(tr("Spelling/Phonetic"));
51
    maxtyp = 2;
52
#endif
53
    int typ = prefs.termMatchType;
54
    if (typ < 0 || typ > maxtyp)
55
  typ = 0;
56
    expTypeCMB->setCurrentItem(typ);
57
44
    // signals and slots connections
58
    // signals and slots connections
45
    connect(baseWordLE, SIGNAL(textChanged(const QString&)), 
59
    connect(baseWordLE, SIGNAL(textChanged(const QString&)), 
46
        this, SLOT(wordChanged(const QString&)));
60
        this, SLOT(wordChanged(const QString&)));
47
    connect(baseWordLE, SIGNAL(returnPressed()), this, SLOT(doExpand()));
61
    connect(baseWordLE, SIGNAL(returnPressed()), this, SLOT(doExpand()));
48
    connect(expandPB, SIGNAL(clicked()), this, SLOT(doExpand()));
62
    connect(expandPB, SIGNAL(clicked()), this, SLOT(doExpand()));
49
    connect(clearPB, SIGNAL(clicked()), baseWordLE, SLOT(clear()));
50
    connect(dismissPB, SIGNAL(clicked()), this, SLOT(close()));
63
    connect(dismissPB, SIGNAL(clicked()), this, SLOT(close()));
51
    connect(suggsTE, SIGNAL(doubleClicked(int, int)), 
64
    connect(suggsTE, SIGNAL(doubleClicked(int, int)), 
52
        this, SLOT(textDoubleClicked(int, int)));
65
        this, SLOT(textDoubleClicked(int, int)));
53
}
66
}
54
67
68
/* Expand term according to current mode */
55
void SpellW::doExpand()
69
void SpellW::doExpand()
56
{
70
{
57
#ifdef RCL_USE_ASPELL
71
    if (baseWordLE->text().isEmpty()) 
72
  return;
73
58
    string reason;
74
    string reason;
59
    if (!aspell || !maybeOpenDb(reason)) {
75
    if (!maybeOpenDb(reason)) {
60
  LOGDEB(("SpellW::doExpand: error aspell %p db: %s\n", aspell,
76
  LOGDEB(("SpellW::doExpand: db error: %s\n", reason.c_str()));
61
      reason.c_str()));
62
    return;
77
    return;
63
    }
78
    }
64
    if (!baseWordLE->text().isEmpty()) {
79
65
  list<string> suggs;
66
  string word = string((const char *)baseWordLE->text().utf8());
80
    string expr = string((const char *)baseWordLE->text().utf8());
81
    list<string> suggs;
82
    prefs.termMatchType = expTypeCMB->currentItem();
83
    Rcl::Db::MatchType mt = Rcl::Db::ET_WILD;
84
    switch (expTypeCMB->currentItem()) {
85
    case 1: mt = Rcl::Db::ET_REGEXP;
86
  /* FALLTHROUGH */
87
    case 0: 
88
  if (!rcldb->termMatch(mt, expr, suggs, prefs.queryStemLang.ascii(),
89
                200)) {
90
      LOGERR(("SpellW::doExpand:rcldb::termMatch failed\n"));
91
      return;
92
  }
93
  break;
94
#ifdef RCL_USE_ASPELL
95
    case 2: {
96
  if (!aspell) {
97
      LOGDEB(("SpellW::doExpand: aspell init error\n"));
98
      return;
99
  }
67
    if (!aspell->suggest(*rcldb, word, suggs, reason)) {
100
    if (!aspell->suggest(*rcldb, expr, suggs, reason)) {
68
        LOGERR(("SpellW::doExpand:suggest failed: %s\n", reason.c_str()));
101
        LOGERR(("SpellW::doExpand:suggest failed: %s\n", reason.c_str()));
69
        return;
102
        return;
70
    }
103
    }
71
  suggsTE->clear();
104
  return;
72
  if (suggs.empty()) {
73
      suggsTE->append(tr("No spelling expansion found"));
74
  } else {
75
      for (list<string>::iterator it = suggs.begin(); 
76
       it != suggs.end(); it++) {
77
      suggsTE->append(QString::fromUtf8(it->c_str()));
78
      }
79
      suggsTE->setCursorPosition(0,0);
80
      suggsTE->ensureCursorVisible();
81
  }
82
    }
105
    }
83
#endif
106
#endif
107
    }
108
109
    suggsTE->clear();
110
    if (suggs.empty()) {
111
  suggsTE->append(tr("No spelling expansion found"));
112
    } else {
113
  for (list<string>::iterator it = suggs.begin(); 
114
       it != suggs.end(); it++) {
115
      suggsTE->append(QString::fromUtf8(it->c_str()));
116
  }
117
  suggsTE->setCursorPosition(0,0);
118
  suggsTE->ensureCursorVisible();
119
    }
84
}
120
}
85
121
86
void SpellW::wordChanged(const QString &text)
122
void SpellW::wordChanged(const QString &text)
87
{
123
{
88
    if (text.isEmpty()) {
124
    if (text.isEmpty()) {
89
    expandPB->setEnabled(false);
125
    expandPB->setEnabled(false);
90
  clearPB->setEnabled(false);
91
    suggsTE->clear();
126
    suggsTE->clear();
92
    } else {
127
    } else {
93
    expandPB->setEnabled(true);
128
    expandPB->setEnabled(true);
94
  clearPB->setEnabled(true);
95
    }
129
    }
96
}
130
}
97
131
98
void SpellW::textDoubleClicked(int, int)
132
void SpellW::textDoubleClicked(int para, int)
99
{
133
{
134
    suggsTE->setSelection(para, 0, para+1, 0);
100
    if (suggsTE->hasSelectedText())
135
    if (suggsTE->hasSelectedText())
101
    emit(wordSelect(suggsTE->selectedText()));
136
    emit(wordSelect(suggsTE->selectedText()));
102
}
137
}