update dict
[QFreeRecite.git] / src / gui / BaseScannerWidget.cpp
blobf0813c01c5a0a84861ab16bfd569fabe7cb011eb
1 #include <QMessageBox>
2 #include <QScrollBar>
3 #include <QChar>
4 #include <QUrl>
7 #include <FCore.h>
8 #include "BaseScannerWidget.h"
9 #include "ModifyDialog.h"
10 #include "ListModel.h"
11 #include "ResultWidget.h"
12 #include "AddDialog.h"
13 #include "Speaker.h"
15 using namespace freeRecite;
17 BaseScannerWidget::BaseScannerWidget(QWidget *parent)
18 :QWidget(parent),scanner(0),resultWidget(0),
19 startTime(0),listModel(0)
21 //Do nothing here!
24 BaseScannerWidget::~BaseScannerWidget() {
25 if(scanner != 0)
26 delete scanner;
27 if(qobject_cast<QObject *>(resultWidget) != 0)
28 resultWidget->deleteLater();
29 D_OUTPUT("~BaseScannerWidget()")
32 void BaseScannerWidget::add() {
33 QString word = AddDialog::getString(this,tr("Getting New Word"));
34 if(!word.isEmpty()){
35 Speaker::play("ok");
36 scanner->add(word.toStdString());
37 }else
38 Speaker::play("fail");
39 setInfo();
42 void BaseScannerWidget::remove(){
43 Speaker::play("remove");
44 scanner->remove(scanner->getWord());
45 showNext();
46 setInfo();
49 void BaseScannerWidget::modify(){
50 QString word;
51 if(dictionary.lookUp(scanner->getWord())) {
52 word = ModifyDialog::getDicItmeString(dictionary.word(),
53 dictionary.rawPhonetics(),
54 dictionary.translation(),
55 dictionary.example(),
56 this);
57 } else { //Can't find the word in dictionary.
58 word = ModifyDialog::getDicItmeString(scanner->getWord(),
59 "",
60 "",
61 "",
62 this);
64 if(dictionary.modify(word.toUtf8().constData())) {
65 Speaker::play("ok");
66 showNext();
67 QMessageBox::information(this,tr("Modify Information"),
68 tr("The dictionary has been modified!"));
69 } else {
70 Speaker::play("fail");
71 QMessageBox::warning(this,tr("Modify Information"),
72 tr("The dictionary Can Not be modified!"));