8c6aac4ae9630e4dc50169ffd46754c31b14f6af
[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                 QWidget *pluginWidget = new QWidget;
113                 QVBoxLayout *vbox = new QVBoxLayout;
114                 QHBoxLayout *hbox = new QHBoxLayout;
115                 comboBox_ = new QComboBox;
116                 searchLine_ = new QLineEdit;
117                 searchButton_ = new QPushButton("Search");
118
119                 hbox->addWidget(searchLine_);
120                 hbox->addWidget(searchButton_);
121                 vbox->addWidget(comboBox_);
122                 vbox->addLayout(hbox);
123                 pluginWidget->setLayout(vbox);
124
125                 connect(searchButton_, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked()));
126                 //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*)));
127
128                 host_->setGui(pluginWidget);
129         }
130 }
131
132 QWidget* SearchPlugin::getGui()
133 {
134         return NULL;
135 }
136
137 void SearchPlugin::on_searchButton_clicked()
138 {
139         QUrl searchUrl(QString("http://www.google.fi/search?q="
140                                + searchLine_->text()));
141         qDebug() << searchUrl;
142         QWebView *result = new QWebView;
143         result->load(searchUrl);
144
145         on_searchResult((QWidget*)result);
146 }
147
148 void SearchPlugin::on_searchResult(QWidget* resultWidget)
149 {
150         qDebug() << "on_searchResult()";
151         if (host_) {
152                 host_->addPluginWidget(resultWidget);
153         }
154 }
155
156 } // namespace qtrapids
157
158 Q_EXPORT_PLUGIN2(searchplugin, qtrapids::SearchPlugin)