1
/***************************************************************************
4
begin : Fri Feb 25 2005
5
copyright : (C) 2005, 2006 by Thomas Friedrichsmeier
6
email : tfry@users.sourceforge.net
7
***************************************************************************/
9
/***************************************************************************
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. *
16
***************************************************************************/
22
#include <kmessagebox.h>
24
#include <qcheckbox.h>
25
#include <qcombobox.h>
26
#include <qlistview.h>
27
#include <qlineedit.h>
31
#include "rbackend/rinterface.h"
32
#include "rbackend/rcommandreceiver.h"
34
#include "rkglobals.h"
36
#include "misc/rkcommonfunctions.h"
38
#define GET_HELP_URL 1
40
#define GET_INSTALLED_PACKAGES 3
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 ());
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);
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);
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);
71
label = new QLabel (i18n ("Package:"), this);
72
label->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Minimum);
73
fields_packages_layout->addWidget (label);
75
packagesList = new QComboBox (false, this);
76
packagesList->insertItem (i18n("All"));
77
fields_packages_layout->addWidget (packagesList);
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);
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);
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);
100
RKGlobals::rInterface ()->issueCommand (".rk.get.installed.packages ()[[1]]", RCommand::App | RCommand::Sync | RCommand::GetStringVector, QString::null, this, GET_INSTALLED_PACKAGES, 0);
102
setCaption (i18n ("Help search"));
105
KHelpDlg::~KHelpDlg () {
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;
112
getFunctionHelp (result);
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);
119
void KHelpDlg::slotFindButtonClicked () {
121
if (field->currentText ().isEmpty ()) {
125
QString agrep = "FALSE";
126
if (fuzzyCheckBox->isChecked ()) {
130
QString ignoreCase = "TRUE";
131
if(caseSensitiveCheckBox->isChecked ()) {
135
QString package = "NULL";
136
if (packagesList->currentItem ()!=0) {
138
package.append (packagesList->currentText ());
139
package.append ("\"");
142
// HACK the sequence of options is hardcoded, do not modify
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\")";
152
QString s = ".rk.get.search.results (\"" + field->currentText () + "\",agrep=" + agrep + ", ignore.case=" + ignoreCase + ", package=" + package + ", fields=" + fields +")";
154
RKGlobals::rInterface ()->issueCommand (s, RCommand::App | RCommand::Sync | RCommand::GetStringVector, QString::null, this, HELP_SEARCH, 0);
156
field->insertItem (field->currentText ());
159
void KHelpDlg::slotResultsListDblClicked (QListViewItem * item, const QPoint &, int) {
163
if (item->text(0).isEmpty ()) {
168
s.append (item->text (0));
169
s.append ("\", htmlhelp=TRUE, package= \"");
170
s.append (item->text (2));
173
RKGlobals::rInterface ()->issueCommand (s, RCommand::App | RCommand::Sync | RCommand::GetStringVector, QString::null, this, GET_HELP_URL, 0);
176
void KHelpDlg::rCommandDone (RCommand *command) {
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]);
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);
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"));
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]);
206
#include "khelpdlg.moc"