summaryrefslogtreecommitdiffstats
path: root/kbabel/kbabeldict/kbabeldictview.cpp
blob: 7964c65a224bb57c0121cdbfccd089590b7dc68c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/* ****************************************************************************
  This file is part of KBabel

  Copyright (C) 2000 by Matthias Kiefer
                            <matthias.kiefer@gmx.de>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

  In addition, as a special exception, the copyright holders give
  permission to link the code of this program with any edition of
  the TQt library by Trolltech AS, Norway (or with modified versions
  of TQt that use the same license as TQt), and distribute linked
  combinations including the two.  You must obey the GNU General
  Public License in all respects for all of the code used other than 
  TQt. If you modify this file, you may extend this exception to
  your version of the file, but you are not obligated to do so.  If
  you do not wish to do so, delete this exception statement from
  your version.

**************************************************************************** */


#include "kbabeldictview.h"
#include "kbabeldictbox.h"
#include "searchengine.h"


#include <tqcheckbox.h>
#include <tqgroupbox.h>
#include <tqhbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqptrlist.h>
#include <tqpushbutton.h>
#include <tqstringlist.h>
#include <tqwidgetstack.h>
#include <tqsplitter.h>
#include <tqvbox.h>

#include <kcombobox.h>
#include <tdeconfig.h>
#include <kdialog.h>
#include <tdeglobal.h>
#include <klineedit.h>
#include <tdelocale.h>
#include <kprogress.h>
#include <kseparator.h>
#include <kdebug.h>
#include <kiconloader.h>

/* 
 *  Constructs a KBabelDictView which is a child of 'parent', with the 
 *  name 'name' and widget flags set to 'f' 
 */
KBabelDictView::KBabelDictView( TQWidget* parent,  const char* name, WFlags fl )
    : TQWidget( parent, name, fl )
{
    TQVBoxLayout    *mainLayout = new TQVBoxLayout(this);
    mainLayout->setSpacing(KDialog::spacingHint());
    mainLayout->setMargin(KDialog::marginHint());

    splitter = new TQSplitter(this);
    mainLayout->addWidget(splitter);

    TQWidget *w = new TQWidget(splitter);
    TQVBoxLayout *wLayout= new TQVBoxLayout(w);
    wLayout->setSpacing(KDialog::spacingHint());
    wLayout->setMargin(KDialog::marginHint());
    
    TQHBoxLayout *hbox = new TQHBoxLayout(wLayout);
    TQLabel *label = new TQLabel(i18n("Search in module:"), w);
    hbox->addWidget(label);
    moduleCombo = new KComboBox(w);
    hbox->addWidget(moduleCombo);

    TQWidget *temp = new TQWidget(w);
    hbox->addWidget(temp);
    hbox->setStretchFactor(temp,2);
    editButton = new TQPushButton(i18n("&Edit"),w);
    editButton->setEnabled(false);
    hbox->addWidget(editButton);

    // added a button "clear search" here
    hbox = new TQHBoxLayout(wLayout);
    TQPushButton* clearButton = new TQPushButton(w);
    clearButton->setFlat(true);
    clearButton->setPixmap(SmallIcon("locationbar_erase"));
    hbox->addWidget(clearButton);
    textEdit = new KLineEdit(w,"textedit");
    textEdit->setFocus();
    hbox->addWidget(textEdit);

    hbox = new TQHBoxLayout(wLayout);
    startButton = new TQPushButton(i18n("&Start Search"),w);
    hbox->addWidget(startButton);
    inTransButton = new TQCheckBox(i18n("Sea&rch in translations"),w);
    hbox->addWidget(inTransButton);
    hbox->addStretch(1);
    stopButton = new TQPushButton(i18n("S&top"),w);
    stopButton->setEnabled(false);
    hbox->addWidget(stopButton);

    KSeparator *sep = new KSeparator(w);
    wLayout->addWidget(sep);
    dictBox = new KBabelDictBox(w,"kbabeldictbox");
    wLayout->addWidget(dictBox);

    prefWidget = new TQWidget(splitter);
    TQVBoxLayout *tempLayout= new TQVBoxLayout(prefWidget);
    tempLayout->setSpacing(KDialog::spacingHint());
    tempLayout->setMargin(KDialog::marginHint());

    label = new TQLabel(i18n("Settings:"),prefWidget);
    tempLayout->addWidget(label);
    
    prefStack = new TQWidgetStack(prefWidget);
    tempLayout->addWidget(prefStack);
    tempLayout->addStretch(1);

    TDEConfig *config = TDEGlobal::config();
    dictBox->readSettings(config);
    dictBox->setAutoUpdateOptions(true);
           
    TQStringList modules = dictBox->moduleNames();
    moduleCombo->insertStringList(modules);

    TQPtrList<PrefWidget> prefs = dictBox->modPrefWidgets(prefStack);
    prefs.setAutoDelete(false);

    PrefWidget *p;
    int i=0;
    for(p = prefs.first(); p != 0; p=prefs.next())
    {
        prefStack->addWidget(p,i);
        i++;
    }

    int active=dictBox->activeModule();
    prefStack->raiseWidget(active);
    moduleCombo->setCurrentItem(active);


    TQHBox *h = new TQHBox(this);
    h->setSpacing(KDialog::spacingHint());
    mainLayout->addWidget(h);
    progressLabel = new TQLabel(h);
    progressBar = new KProgress(h);

    connect(textEdit,TQT_SIGNAL(returnPressed()),startButton,TQT_SLOT(animateClick()));
    connect(startButton,TQT_SIGNAL(clicked()),this, TQT_SLOT(startSearch()));
    connect(stopButton, TQT_SIGNAL(clicked()), dictBox,TQT_SLOT(slotStopSearch()));
    connect(editButton, TQT_SIGNAL(clicked()), dictBox, TQT_SLOT(edit()));
    connect(dictBox, TQT_SIGNAL(searchStarted()), this, TQT_SLOT(searchStarted()));
    connect(dictBox, TQT_SIGNAL(searchStopped()), this, TQT_SLOT(searchStopped()));
    connect(dictBox, TQT_SIGNAL(progressed(int)), progressBar, TQT_SLOT(setProgress(int)));
    connect(dictBox, TQT_SIGNAL(activeModuleChanged(bool))
            , editButton, TQT_SLOT(setEnabled(bool)));
    
    connect(dictBox, TQT_SIGNAL(progressStarts(const TQString&))
            , this, TQT_SLOT(progressStarted(const TQString&)));
    connect(dictBox, TQT_SIGNAL(progressEnds()), this, TQT_SLOT(progressStopped()));
    
    connect(moduleCombo, TQT_SIGNAL(activated(int)), 
                    dictBox, TQT_SLOT(setActiveModule(int)));
    connect(dictBox, TQT_SIGNAL(activeModuleChanged(int))
                    , this, TQT_SLOT(switchModule(int)));
    connect(clearButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotClearSearch()));
}

/*  
 *  Destroys the object and frees any allocated resources
 */
KBabelDictView::~KBabelDictView()
{
    // no need to delete child widgets, TQt does it all for us
    TDEConfig *config = TDEGlobal::config();
    dictBox->saveSettings(config);
}

/* 
 * public slot
 */
void KBabelDictView::startSearch()
{
    TQString text = textEdit->text();
    
    if(!text.isEmpty())
    {
        if(inTransButton->isChecked())
        {
            dictBox->startTranslationSearch(text);
        }
        else
        {
            dictBox->startSearch(text);
        }
    }


}

void KBabelDictView::progressStopped()
{
    progressBar->setProgress(0);
    progressLabel->setText("");
    startButton->setEnabled(true);
    stopButton->setEnabled(false);
}

void KBabelDictView::progressStarted(const TQString& msg)
{
    progressLabel->setText(msg);
    startButton->setEnabled(false);
    stopButton->setEnabled(true);
}

void KBabelDictView::searchStopped()
{
    progressLabel->setText("");
    progressBar->setProgress(0);
    startButton->setEnabled(true);
    stopButton->setEnabled(false);
}

void KBabelDictView::searchStarted()
{
    progressLabel->setText(i18n("Searching"));
    startButton->setEnabled(false);
    stopButton->setEnabled(true);
}

void KBabelDictView::switchModule(int m)
{
    moduleCombo->blockSignals(true);
    moduleCombo->setCurrentItem(m);
    moduleCombo->blockSignals(false);

    prefStack->raiseWidget(m);
}


void KBabelDictView::about()
{
    dictBox->about();
}


void KBabelDictView::aboutModule()
{
    dictBox->aboutActiveModule();
}

int KBabelDictView::togglePref()
{
    int prefWidth=0;
    if(prefWidget->isVisibleTo(this))
    {
        prefWidget->hide();
        prefWidth=prefWidget->width();
    }
    else
    {
        prefWidget->show();
        prefWidth=prefWidget->width();
    }

    return prefWidth;
}

bool KBabelDictView::prefVisible() 
{
    return prefWidget->isVisibleTo(this);
}

void KBabelDictView::slotClearSearch()
{
  textEdit->clear();
  textEdit->setFocus();
}

#include "kbabeldictview.moc"