- Plugin interface added to MainWindow
[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 <<<<<<< .mine
37         SearchPlugin::SearchPlugin() : 
38                 comboBox_(NULL), searchLine_(NULL), searchButton_(NULL), host_(NULL)
39         {
40                 // TODO: Parse engine descriptions.
41                 // -Add engines to model
42                 // -Show model in comboBox
43         
44         }
45         
46         void SearchPlugin::initialize(PluginHostInterface* host)
47         {
48                 host_ = host;
49                 
50                 if (host_ != NULL) {
51                         
52                         QWidget *pluginWidget = new QWidget;
53                         QVBoxLayout *vbox = new QVBoxLayout;
54                         QHBoxLayout *hbox = new QHBoxLayout;
55                         comboBox_ = new QComboBox;
56                         searchLine_ = new QLineEdit;
57                         searchButton_ = new QPushButton("Search");
58                         
59                         hbox->addWidget(searchLine_);
60                         hbox->addWidget(searchButton_);
61                         vbox->addWidget(comboBox_);
62                         vbox->addLayout(hbox);
63                         pluginWidget->setLayout(vbox);
64         
65                         connect(searchButton_, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked()));
66                         //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*)));
67                         
68                         host_->setGui(this, pluginWidget);
69                 }
70         }
71         
72         QWidget* SearchPlugin::getGui()
73         {
74                 return NULL;
75         }
76         
77         void SearchPlugin::on_searchButton_clicked()
78         {
79                 QUrl searchUrl(QString("http://www.google.fi/search?q="
80                         + searchLine_->text()));
81                 qDebug() << searchUrl;
82                 QWebView *result = new QWebView;
83                 result->load(searchUrl);
84                 
85                 on_searchResult((QWidget*)result);
86         }
87         
88         void SearchPlugin::on_searchResult(QWidget* resultWidget)
89         {
90                 qDebug() << "on_searchResult()";
91                 if (host_) {
92                         host_->addPluginWidget(this, resultWidget);
93                 }
94         }
95 =======
96 SearchPlugin::SearchPlugin() :
97         comboBox_(NULL), searchLine_(NULL), searchButton_(NULL), host_(NULL)
98 {
99     // TODO: Parse engine descriptions.
100     // -Add engines to model
101     // -Show model in comboBox
102 >>>>>>> .r31
103
104 }
105
106 void SearchPlugin::initialize(PluginHostInterface* host)
107 {
108     host_ = host;
109
110     if (host_ != NULL)
111     {
112
113         QWidget *pluginWidget = new QWidget;
114         QVBoxLayout *vbox = new QVBoxLayout;
115         QHBoxLayout *hbox = new QHBoxLayout;
116         comboBox_ = new QComboBox;
117         searchLine_ = new QLineEdit;
118         searchButton_ = new QPushButton("Search");
119
120         hbox->addWidget(searchLine_);
121         hbox->addWidget(searchButton_);
122         vbox->addWidget(comboBox_);
123         vbox->addLayout(hbox);
124         pluginWidget->setLayout(vbox);
125
126         connect(searchButton_, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked()));
127         //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*)));
128
129         host_->setGui(pluginWidget);
130     }
131 }
132
133 QWidget* SearchPlugin::getGui()
134 {
135     return NULL;
136 }
137
138 void SearchPlugin::on_searchButton_clicked()
139 {
140     QUrl searchUrl(QString("http://www.google.fi/search?q="
141                            + searchLine_->text()));
142     qDebug() << searchUrl;
143     QWebView *result = new QWebView;
144     result->load(searchUrl);
145
146     on_searchResult((QWidget*)result);
147 }
148
149 void SearchPlugin::on_searchResult(QWidget* resultWidget)
150 {
151     qDebug() << "on_searchResult()";
152     if (host_)
153     {
154         host_->addPluginWidget(resultWidget);
155     }
156 }
157
158 } // namespace qtrapids
159
160 Q_EXPORT_PLUGIN2(searchplugin, qtrapids::SearchPlugin)