27417f11370723bdf30e90bb275c19e7e7228b82
[qtrapids] / src / plugins / searchplugin / SearchPlugin.cpp
1 /***************************************************************************
2  *   Copyright (C) 2009 by Lassi Väätämöinen   *
3  *   lassi.vaatamoinen@ixonos.com   *
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 <QDebug>
22 #include <QtCore/qplugin.h>
23 #include <QVBoxLayout>
24 #include <QHBoxLayout>
25 #include <QComboBox>
26 #include <QLineEdit>
27 #include <QPushButton>
28 #include <QUrl>
29 #include <QWebView>
30
31
32 #include "SearchPlugin.h"
33
34 namespace qtrapids
35 {
36         SearchPlugin::SearchPlugin() : 
37                 comboBox_(NULL), searchLine_(NULL), searchButton_(NULL), host_(NULL)
38         {
39                 // TODO: Parse engine descriptions.
40                 // -Add engines to model
41                 // -Show model in comboBox
42         
43         }
44         
45         void SearchPlugin::initialize(PluginHostInterface* host)
46         {
47                 host_ = host;
48                 
49                 if (host_ != NULL) {
50                         
51                         QWidget *pluginWidget = new QWidget;
52                         QVBoxLayout *vbox = new QVBoxLayout;
53                         QHBoxLayout *hbox = new QHBoxLayout;
54                         comboBox_ = new QComboBox;
55                         searchLine_ = new QLineEdit;
56                         searchButton_ = new QPushButton("Search");
57                         
58                         hbox->addWidget(searchLine_);
59                         hbox->addWidget(searchButton_);
60                         vbox->addWidget(comboBox_);
61                         vbox->addLayout(hbox);
62                         pluginWidget->setLayout(vbox);
63         
64                         connect(searchButton_, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked()));
65                         //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*)));
66                         
67                         host_->setGui(pluginWidget, qtrapids::PluginHostInterface::BASE_WIDGET);
68                 }
69         }
70         
71         QWidget* SearchPlugin::getGui()
72         {
73                 return NULL;
74         }
75         
76         void SearchPlugin::on_searchButton_clicked()
77         {
78                 QUrl searchUrl(QString("http://www.google.fi/search?q="
79                         + searchLine_->text()));
80                 qDebug() << searchUrl;
81                 QWebView *result = new QWebView;
82                 result->load(searchUrl);
83                 
84                 on_searchResult((QWidget*)result);
85         }
86         
87         void SearchPlugin::on_searchResult(QWidget* resultWidget)
88         {
89                 qDebug() << "on_searchResult()";
90                 if (host_) {
91                         host_->addPluginWidget(resultWidget, qtrapids::PluginHostInterface::TAB_PAGE);
92                 }
93         }
94
95 } // namespace qtrapids
96
97 Q_EXPORT_PLUGIN2(searchplugin, qtrapids::SearchPlugin)