• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

lokalize

  • sources
  • kde-4.14
  • kdesdk
  • lokalize
  • src
  • webquery
webquerycontroller.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  This file is part of KAider
3 
4  Copyright (C) 2007 by Nick Shaforostoff <shafff@ukr.net>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  In addition, as a special exception, the copyright holders give
21  permission to link the code of this program with any edition of
22  the Qt library by Trolltech AS, Norway (or with modified versions
23  of Qt that use the same license as Qt), and distribute linked
24  combinations including the two. You must obey the GNU General
25  Public License in all respects for all of the code used other than
26  Qt. If you modify this file, you may extend this exception to
27  your version of the file, but you are not obligated to do so. If
28  you do not wish to do so, delete this exception statement from
29  your version.
30 
31 **************************************************************************** */
32 
33 #include "webquerycontroller.h"
34 #include <QTextCodec>
35 #include "catalog.h"
36 #include "webqueryview.h"
37 
38 #include <QUrl>
39 // #include <kio/netaccess.h>
40 #include <kio/jobclasses.h>
41 #include <kio/job.h>
42 #include <kdebug.h>
43 
44 
45 WebQueryController::WebQueryController(const QString& name, QObject* parent)
46 // : QThread(parent)
47  : QObject(parent)
48  , m_running(false)
49  , m_name(name)
50 {
51 }
52 
53 void WebQueryController::query(const CatalogData& data)
54 {
55  m_queue.enqueue(data);
56  if(!m_running)
57  {
58  m_running=true;
59  emit doQuery();
60  }
61 }
62 
63 
64 
65 QString WebQueryController::msg()
66 {
67  return m_queue.head().msg;
68 }
69 
70 QString WebQueryController::filePath()
71 {
72  return QString();
73 }
74 void WebQueryController::setTwinLangFilePath(QString)
75 {
76 
77 }
78 
79 QString WebQueryController::twinLangMsg()
80 {
81  return QString();
82 }
83 
84 
85 void WebQueryController::doDownloadAndFilter(QString urlStr, QString _codec, QString rx/*, int rep*/)
86 {
87  QString result;
88  QUrl url;
89  url.setUrl(urlStr);
90 
91  kWarning()<<"_real url: "<<url.toString();
92  KIO::StoredTransferJob* readJob = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo);
93  connect(readJob,SIGNAL(result(KJob*)),this,SLOT(slotDownloadResult(KJob*)));
94  readJob->setAutoDelete(false);//HACK HACK HACK
95 
96  codec=QTextCodec::codecForName(_codec.toUtf8());
97  filter=QRegExp(rx);
98 }
99 
100 void WebQueryController::slotDownloadResult(KJob* job)
101 {
102  m_running=false;
103  if ( job->error() )
104  {
105  m_queue.dequeue();
106  delete job;
107  return;
108  }
109 
110  QTextStream stream(static_cast<KIO::StoredTransferJob*>(job)->data());
111  stream.setCodec(codec);
112  if (filter.indexIn(stream.readAll())!=-1)
113  {
114  emit postProcess(filter.cap(1));
115  //kWarning()<<result;
116  }
117  else
118  m_queue.dequeue();
119 
120  delete job;
121 }
122 
123 
124 void WebQueryController::setResult(QString result)
125 {
126  //webQueryView may be deleted before we get result...
127  WebQueryView* a=m_queue.dequeue().webQueryView;
128  connect (this,SIGNAL(addWebQueryResult(const QString&,const QString&)),
129  a,SLOT(addWebQueryResult(const QString&,const QString&)));
130  emit addWebQueryResult(m_name,result);
131  disconnect (this,SIGNAL(addWebQueryResult(const QString&,const QString&)),
132  a,SLOT(addWebQueryResult(const QString&,const QString&)));
133 
134  if(!m_queue.isEmpty())
135  {
136  m_running=true;
137  emit doQuery();
138  }
139 
140 }
141 
142 
143 #include "webquerycontroller.moc"
144 
QTextStream::setCodec
void setCodec(QTextCodec *codec)
QRegExp::cap
QString cap(int nth) const
WebQueryController::setResult
void setResult(QString)
Definition: webquerycontroller.cpp:124
WebQueryController::msg
QString msg()
Definition: webquerycontroller.cpp:65
QQueue::enqueue
void enqueue(const T &t)
WebQueryView
unlike other views, we keep data like catalog pointer in our child view: ui_queryControl contains our...
Definition: webqueryview.h:58
QQueue::dequeue
T dequeue()
QQueue::head
T & head()
webqueryview.h
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QUrl::toString
QString toString(QFlags< QUrl::FormattingOption > options) const
WebQueryController::WebQueryController
WebQueryController(const QString &name, QObject *parent)
Definition: webquerycontroller.cpp:45
WebQueryController::filePath
QString filePath()
Definition: webquerycontroller.cpp:70
WebQueryController::setTwinLangFilePath
void setTwinLangFilePath(QString)
Definition: webquerycontroller.cpp:74
QTextStream
QRegExp::indexIn
int indexIn(const QString &str, int offset, CaretMode caretMode) const
QRegExp
WebQueryController::postProcess
void postProcess(QString)
QUrl::setUrl
void setUrl(const QString &url)
QObject
catalog.h
WebQueryController::doQuery
void doQuery()
QString
CatalogData
Definition: webquerycontroller.h:46
QUrl
WebQueryController::query
void query(const CatalogData &data)
Definition: webquerycontroller.cpp:53
QTextCodec::codecForName
QTextCodec * codecForName(const QByteArray &name)
webquerycontroller.h
WebQueryController::slotDownloadResult
void slotDownloadResult(KJob *)
Definition: webquerycontroller.cpp:100
WebQueryController::addWebQueryResult
void addWebQueryResult(const QString &, const QString &)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
WebQueryController::twinLangMsg
QString twinLangMsg()
Definition: webquerycontroller.cpp:79
QTextStream::readAll
QString readAll()
KJob
WebQueryController::doDownloadAndFilter
void doDownloadAndFilter(QString url, QString codec, QString rx)
Also may be used to get name of another html file (e.g.
Definition: webquerycontroller.cpp:85
QString::toUtf8
QByteArray toUtf8() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:40:07 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

lokalize

Skip menu "lokalize"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal