~ubuntu-branches/ubuntu/raring/kbibtex/raring

« back to all changes in this revision

Viewing changes to src/websearch/websearchgeneral.cpp

  • Committer: Package Import Robot
  • Author(s): Michael Hanke
  • Date: 2011-07-18 09:29:48 UTC
  • mfrom: (1.1.6) (2.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20110718092948-ksxjmg7kdfamolmg
Tags: 0.3-1
* First upstream release for KDE4 (Closes: #634255). A number of search
  engines are still missing, in comparison to the 0.2 series.
* Bumped Standards-Version to 3.9.2, no changes necessary.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
*   Copyright (C) 2004-2011 by Thomas Fischer                             *
 
3
*   fischer@unix-ag.uni-kl.de                                             *
 
4
*                                                                         *
 
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  *
 
7
*   the Free Software Foundation; either version 2 of the License, or     *
 
8
*   (at your option) any later version.                                   *
 
9
*                                                                         *
 
10
*   This program is distributed in the hope that it will be useful,       *
 
11
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
12
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
13
*   GNU General Public License for more details.                          *
 
14
*                                                                         *
 
15
*   You should have received a copy of the GNU General Public License     *
 
16
*   along with this program; if not, write to the                         *
 
17
*   Free Software Foundation, Inc.,                                       *
 
18
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
19
***************************************************************************/
 
20
 
 
21
#include <QGridLayout>
 
22
#include <QLabel>
 
23
#include <QSpinBox>
 
24
 
 
25
#include <KLineEdit>
 
26
#include <KLocale>
 
27
 
 
28
#include "websearchgeneral.h"
 
29
 
 
30
WebSearchQueryFormGeneral::WebSearchQueryFormGeneral(QWidget *parent)
 
31
        : WebSearchQueryFormAbstract(parent)
 
32
{
 
33
    QGridLayout *layout = new QGridLayout(this);
 
34
    layout->setMargin(0);
 
35
 
 
36
    QLabel *label = new QLabel(i18n("Free text:"), this);
 
37
    layout->addWidget(label, 0, 0, 1, 1);
 
38
    KLineEdit *lineEdit = new KLineEdit(this);
 
39
    lineEdit->setClearButtonShown(true);
 
40
    lineEdit->setFocus(Qt::TabFocusReason);
 
41
    layout->addWidget(lineEdit, 0, 1, 1, 1);
 
42
    queryFields.insert(WebSearchAbstract::queryKeyFreeText, lineEdit);
 
43
    label->setBuddy(lineEdit);
 
44
    connect(lineEdit, SIGNAL(returnPressed()), this, SIGNAL(returnPressed()));
 
45
 
 
46
    label = new QLabel(i18n("Title:"), this);
 
47
    layout->addWidget(label, 1, 0, 1, 1);
 
48
    lineEdit = new KLineEdit(this);
 
49
    lineEdit->setClearButtonShown(true);
 
50
    queryFields.insert(WebSearchAbstract::queryKeyTitle, lineEdit);
 
51
    layout->addWidget(lineEdit, 1, 1, 1, 1);
 
52
    label->setBuddy(lineEdit);
 
53
    connect(lineEdit, SIGNAL(returnPressed()), this, SIGNAL(returnPressed()));
 
54
 
 
55
    label = new QLabel(i18n("Author:"), this);
 
56
    layout->addWidget(label, 2, 0, 1, 1);
 
57
    lineEdit = new KLineEdit(this);
 
58
    lineEdit->setClearButtonShown(true);
 
59
    queryFields.insert(WebSearchAbstract::queryKeyAuthor, lineEdit);
 
60
    layout->addWidget(lineEdit, 2, 1, 1, 1);
 
61
    label->setBuddy(lineEdit);
 
62
    connect(lineEdit, SIGNAL(returnPressed()), this, SIGNAL(returnPressed()));
 
63
 
 
64
    label = new QLabel(i18n("Year:"), this);
 
65
    layout->addWidget(label, 3, 0, 1, 1);
 
66
    lineEdit = new KLineEdit(this);
 
67
    lineEdit->setClearButtonShown(true);
 
68
    queryFields.insert(WebSearchAbstract::queryKeyYear, lineEdit);
 
69
    layout->addWidget(lineEdit, 3, 1, 1, 1);
 
70
    label->setBuddy(lineEdit);
 
71
    connect(lineEdit, SIGNAL(returnPressed()), this, SIGNAL(returnPressed()));
 
72
 
 
73
    label = new QLabel(i18n("Number of Results:"), this);
 
74
    layout->addWidget(label, 4, 0, 1, 1);
 
75
    numResultsField = new QSpinBox(this);
 
76
    numResultsField->setMinimum(3);
 
77
    numResultsField->setMaximum(100);
 
78
    numResultsField->setValue(20);
 
79
    layout->addWidget(numResultsField, 4, 1, 1, 1);
 
80
    label->setBuddy(numResultsField);
 
81
 
 
82
    layout->setRowStretch(5, 100);
 
83
}
 
84
 
 
85
bool WebSearchQueryFormGeneral::readyToStart() const
 
86
{
 
87
    for (QMap<QString, KLineEdit*>::ConstIterator it = queryFields.constBegin(); it != queryFields.constEnd(); ++it)
 
88
        if (!it.value()->text().isEmpty())
 
89
            return true;
 
90
 
 
91
    return false;
 
92
}
 
93
 
 
94
QMap<QString, QString> WebSearchQueryFormGeneral::getQueryTerms()
 
95
{
 
96
    QMap<QString, QString> result;
 
97
 
 
98
    for (QMap<QString, KLineEdit*>::ConstIterator it = queryFields.constBegin(); it != queryFields.constEnd(); ++it) {
 
99
        if (!it.value()->text().isEmpty())
 
100
            result.insert(it.key(), it.value()->text());
 
101
    }
 
102
 
 
103
    return result;
 
104
}
 
105
 
 
106
int WebSearchQueryFormGeneral::getNumResults()
 
107
{
 
108
    return numResultsField->value();
 
109
}