~l3on/ubuntu/precise/rkward/rebuild1

« back to all changes in this revision

Viewing changes to rkward/khelpdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Friedrichsmeier
  • Date: 2008-04-20 21:30:00 UTC
  • mfrom: (1.2.2 upstream) (3.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080420213000-fs4i8efmfc793bnn
new upstream release
closes: #475175
closes: #463348
closes: #475982

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
                          khelpdlg  -  description
3
 
                             -------------------
4
 
    begin                : Fri Feb 25 2005
5
 
    copyright            : (C) 2005, 2006 by Thomas Friedrichsmeier
6
 
    email                : tfry@users.sourceforge.net
7
 
 ***************************************************************************/
8
 
 
9
 
/***************************************************************************
10
 
 *                                                                         *
11
 
 *   This program is free software; you can redistribute it and/or modify  *
12
 
 *   it under the terms of the GNU General Public License as published by  *
13
 
 *   the Free Software Foundation; either version 2 of the License, or     *
14
 
 *   (at your option) any later version.                                   *
15
 
 *                                                                         *
16
 
 ***************************************************************************/
17
 
 
18
 
#include "khelpdlg.h"
19
 
 
20
 
#include <klocale.h>
21
 
#include <kurl.h>
22
 
#include <kmessagebox.h>
23
 
 
24
 
#include <qcheckbox.h>
25
 
#include <qcombobox.h>
26
 
#include <qlistview.h>
27
 
#include <qlineedit.h>
28
 
#include <qlayout.h>
29
 
#include <qlabel.h>
30
 
 
31
 
#include "rbackend/rinterface.h"
32
 
#include "rbackend/rcommandreceiver.h"
33
 
#include "debug.h"
34
 
#include "rkglobals.h"
35
 
#include "rkward.h"
36
 
#include "misc/rkcommonfunctions.h"
37
 
 
38
 
#define GET_HELP_URL 1
39
 
#define HELP_SEARCH 2
40
 
#define GET_INSTALLED_PACKAGES 3
41
 
 
42
 
KHelpDlg::KHelpDlg (QWidget* parent, const char* name) : QWidget (parent, name) {
43
 
        QVBoxLayout* main_layout = new QVBoxLayout (this, RKGlobals::marginHint (), RKGlobals::spacingHint ());
44
 
        QHBoxLayout* selection_layout = new QHBoxLayout (main_layout, RKGlobals::spacingHint ());
45
 
 
46
 
 
47
 
        QVBoxLayout* labels_layout = new QVBoxLayout (selection_layout, RKGlobals::spacingHint ());
48
 
        QLabel *label = new QLabel (i18n ("Find:"), this);
49
 
        label->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Minimum);
50
 
        labels_layout->addWidget (label);
51
 
        label = new QLabel (i18n ("Fields:"), this);
52
 
        label->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Minimum);
53
 
        labels_layout->addWidget (label);
54
 
 
55
 
 
56
 
        QVBoxLayout* main_settings_layout = new QVBoxLayout (selection_layout, RKGlobals::spacingHint ());
57
 
        field = new QComboBox (true, this);
58
 
        field->setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
59
 
        connect (field->lineEdit () , SIGNAL (returnPressed ()), this, SLOT (slotFindButtonClicked ()));
60
 
        main_settings_layout->addWidget (field);
61
 
 
62
 
        QHBoxLayout* fields_packages_layout = new QHBoxLayout (main_settings_layout, RKGlobals::spacingHint ());
63
 
        fieldsList = new QComboBox (false, this);
64
 
        // HACK the sequence of options is hardcoded, do not modify
65
 
        fieldsList->insertItem (i18n("All"));
66
 
        fieldsList->insertItem (i18n("All but keywords"));
67
 
        fieldsList->insertItem (i18n("Keywords"));
68
 
        fieldsList->insertItem (i18n("Title"));
69
 
        fields_packages_layout->addWidget (fieldsList);
70
 
 
71
 
        label = new QLabel (i18n ("Package:"), this);
72
 
        label->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Minimum);
73
 
        fields_packages_layout->addWidget (label);
74
 
 
75
 
        packagesList = new QComboBox (false, this);
76
 
        packagesList->insertItem (i18n("All"));
77
 
        fields_packages_layout->addWidget (packagesList);
78
 
 
79
 
 
80
 
        QVBoxLayout* checkboxes_layout = new QVBoxLayout (selection_layout, RKGlobals::spacingHint ());
81
 
        caseSensitiveCheckBox = new QCheckBox (i18n ("Case sensitive"), this);
82
 
        checkboxes_layout->addWidget (caseSensitiveCheckBox);
83
 
        fuzzyCheckBox = new QCheckBox (i18n ("Fuzzy matching"), this);
84
 
        fuzzyCheckBox->setChecked (true);
85
 
        checkboxes_layout->addWidget (fuzzyCheckBox);
86
 
 
87
 
        findButton = new QPushButton (i18n ("Find"), this);
88
 
        findButton->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
89
 
        connect (findButton, SIGNAL (clicked ()), this, SLOT (slotFindButtonClicked ()));
90
 
        selection_layout->addWidget (findButton);
91
 
 
92
 
        resultsList = new QListView (this);
93
 
        resultsList->addColumn (i18n ("Topic"));
94
 
        resultsList->addColumn (i18n ("Title"));
95
 
        resultsList->addColumn (i18n ("Package"));
96
 
        connect (resultsList, SIGNAL (doubleClicked (QListViewItem*, const QPoint&, int)), this, SLOT (slotResultsListDblClicked (QListViewItem*, const QPoint&, int)));
97
 
        main_layout->addWidget (resultsList);
98
 
 
99
 
 
100
 
        RKGlobals::rInterface ()->issueCommand (".rk.get.installed.packages ()[[1]]", RCommand::App | RCommand::Sync | RCommand::GetStringVector, QString::null, this, GET_INSTALLED_PACKAGES, 0);
101
 
 
102
 
        setCaption (i18n ("Help search"));
103
 
}
104
 
 
105
 
KHelpDlg::~KHelpDlg () {
106
 
}
107
 
 
108
 
void KHelpDlg::getContextHelp (const QString &context_line, int cursor_pos) {
109
 
        QString result = RKCommonFunctions::getCurrentSymbol (context_line, cursor_pos);
110
 
        if (result.isEmpty ()) return;
111
 
 
112
 
        getFunctionHelp (result);
113
 
}
114
 
 
115
 
void KHelpDlg::getFunctionHelp (const QString &function_name) {
116
 
        RKGlobals::rInterface ()->issueCommand ("help(\"" + function_name + "\", htmlhelp=TRUE)[1]", RCommand::App | RCommand::GetStringVector, QString::null, this, GET_HELP_URL, 0);
117
 
}
118
 
 
119
 
void KHelpDlg::slotFindButtonClicked () {
120
 
 
121
 
        if (field->currentText ().isEmpty ()) {
122
 
                return;
123
 
        }
124
 
        
125
 
        QString agrep = "FALSE";
126
 
        if (fuzzyCheckBox->isChecked ()) {
127
 
                agrep="NULL";
128
 
        }
129
 
        
130
 
        QString ignoreCase = "TRUE";
131
 
        if(caseSensitiveCheckBox->isChecked ()) {
132
 
                ignoreCase="FALSE";
133
 
        }
134
 
        
135
 
        QString package = "NULL";
136
 
        if (packagesList->currentItem ()!=0) {
137
 
                package="\"";
138
 
                package.append (packagesList->currentText ());
139
 
                package.append ("\"");
140
 
        }
141
 
 
142
 
        // HACK the sequence of options is hardcoded, do not modify
143
 
        QString fields;
144
 
        
145
 
        switch (fieldsList->currentItem ()) {
146
 
                case 1: fields = "c(\"alias\", \"concept\", \"title\")";break;
147
 
                case 2: fields = "c(\"keyword\")";break;
148
 
                case 3: fields = "c(\"title\")";break;
149
 
                default: fields = "c(\"alias\", \"concept\", \"title\",\"keyword\")";
150
 
        }
151
 
 
152
 
        QString s = ".rk.get.search.results (\"" + field->currentText () + "\",agrep=" + agrep + ", ignore.case=" + ignoreCase + ", package=" + package + ", fields=" + fields +")";
153
 
        
154
 
        RKGlobals::rInterface ()->issueCommand (s, RCommand::App | RCommand::Sync | RCommand::GetStringVector, QString::null, this, HELP_SEARCH, 0);
155
 
        setEnabled (false);
156
 
        field->insertItem (field->currentText ());
157
 
}
158
 
 
159
 
void KHelpDlg::slotResultsListDblClicked (QListViewItem * item, const QPoint &, int) {
160
 
        if (item == NULL) {
161
 
                return;
162
 
        }
163
 
        if (item->text(0).isEmpty ()) {
164
 
                return;
165
 
        }
166
 
        
167
 
        QString s="help(\"";
168
 
        s.append (item->text (0));
169
 
        s.append ("\", htmlhelp=TRUE, package= \"");
170
 
        s.append (item->text (2));
171
 
        s.append ("\")");
172
 
        
173
 
        RKGlobals::rInterface ()->issueCommand (s, RCommand::App | RCommand::Sync | RCommand::GetStringVector, QString::null, this, GET_HELP_URL, 0);
174
 
}
175
 
 
176
 
void KHelpDlg::rCommandDone (RCommand *command) {
177
 
        KURL url;
178
 
        if (command->getFlags () == HELP_SEARCH) {
179
 
                resultsList->clear ();
180
 
                RK_ASSERT ((command->getDataLength () % 3) == 0);
181
 
                int count = (command->getDataLength () / 3);
182
 
                for (int i=0; i < count; ++i) {
183
 
                        new QListViewItem (resultsList, command->getStringVector ()[i], command->getStringVector ()[count + i], command->getStringVector ()[2*count + i]);
184
 
                }
185
 
                setEnabled(true);
186
 
        } else if (command->getFlags () == GET_HELP_URL) {
187
 
                RK_ASSERT (command->getDataLength ());
188
 
                url.setPath(command->getStringVector ()[0]);
189
 
                if (QFile::exists (url.path ())) {
190
 
                        RKwardApp::getApp ()->openHTML (url);
191
 
                        return;
192
 
                } else {
193
 
                        KMessageBox::sorry (this, i18n ("No help found on '%1'. Maybe the corresponding package is not installed/loaded, or maybe you mistyped the command. Try using Help->Search R Help for more options.").arg (command->command ().section ("\"", 1, 1)), i18n ("No help found"));
194
 
                }
195
 
        } else if (command->getFlags () == GET_INSTALLED_PACKAGES) {
196
 
                RK_ASSERT (command->getDataType () == RData::StringVector);
197
 
                unsigned int count = command->getDataLength ();
198
 
                for (unsigned int i=0; i < count; ++i) {
199
 
                        packagesList->insertItem (command->getStringVector ()[i]);
200
 
                }
201
 
        } else {
202
 
                RK_ASSERT (false);
203
 
        }
204
 
}
205
 
 
206
 
#include "khelpdlg.moc"