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

kget

  • sources
  • kde-4.12
  • kdenetwork
  • kget
  • transfer-plugins
  • mirrorsearch
mirrors.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2 
3  Copyright (C) 2006 Manolo Valdes <nolis71cu@gmail.com>
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 */
10 
11 #include "mirrors.h"
12 #include "mirrorsearchsettings.h"
13 
14 #include <KDebug>
15 
16 mirror::mirror()
17 {
18  if( !MirrorSearchSettings::searchEnginesUrlList().isEmpty())
19  m_search_engine = MirrorSearchSettings::searchEnginesUrlList().takeFirst();
20 }
21 
22 void mirror::search(const KUrl &url, QObject *receiver, const char *member)
23 {
24  kDebug(5001);
25 
26  m_url = url;
27  if (m_url.path() != m_url.fileName())
28  {
29  m_Urls << m_url;
30  }
31 
32  search(m_url.fileName(),receiver,member);
33 }
34 
35 void mirror::search(const QString &fileName, QObject *receiver, const char *member)
36 {
37  kDebug(5001);
38 
39  KUrl search(m_search_engine.replace("${filename}",fileName));
40  m_job = KIO::get(search, KIO::NoReload, KIO::HideProgressInfo);
41  connect(m_job,SIGNAL(data(KIO::Job*,QByteArray)),
42  SLOT(slotData(KIO::Job*,QByteArray)));
43  connect(m_job,SIGNAL(result(KJob*)),
44  SLOT(slotResult(KJob*)));
45  connect(this,SIGNAL(urls(QList<KUrl>&)),receiver,member);
46 }
47 
48 void mirror::slotData(KIO::Job *, const QByteArray& data)
49 {
50  kDebug(5001);
51  if (data.size() == 0)
52  return;
53  m_data.append(data);
54 }
55 
56 void mirror::slotResult( KJob *job )
57 {
58  kDebug(5001);
59  m_job = 0;
60  int minUrlsNeeded = static_cast<int>(!m_Urls.isEmpty());
61 
62  if( job->error() )
63  {
64  deleteLater();
65  return;
66  }
67  QString str(m_data);
68 
69  int start = 0, posOfTagA = 0, posOfTagHref = 0, hrefEnd = 0;
70 
71  while ((posOfTagA = str.indexOf("<a " , start, Qt::CaseInsensitive)) != -1 )
72  {
73  posOfTagHref = str.indexOf("href=\"", posOfTagA, Qt::CaseInsensitive);
74  hrefEnd = str.indexOf("\"",posOfTagHref + 6,Qt::CaseInsensitive);
75  QString u = str.mid(posOfTagHref + 6, (hrefEnd - posOfTagHref -6));
76 
77  start = hrefEnd + 1;
78  if ( u.endsWith( '/' + m_url.fileName() ) )
79  {
80  m_Urls << KUrl(u);
81  kDebug(5001) << "url: " << u;
82  }
83  }
84 
85  if (m_Urls.size() > minUrlsNeeded)
86  emit urls(m_Urls);
87  deleteLater();
88 }
89 
90 void MirrorSearch ( const KUrl &url, QObject *receiver, const char *member )
91 {
92  mirror *searcher = new mirror();
93  searcher->search(url, receiver, member);
94 }
95 
96 void MirrorSearch ( const QString &fileName, QObject *receiver, const char *member )
97 {
98  mirror *searcher = new mirror();
99  searcher->search(fileName, receiver, member);
100 }
101 
102 #include "mirrors.moc"
mirrors.h
mirror::search
void search(const KUrl &url, QObject *receiver, const char *member)
Definition: mirrors.cpp:22
QObject
mirror
Definition: mirrors.h:17
mirror::mirror
mirror()
Definition: mirrors.cpp:16
mirror::urls
void urls(QList< KUrl > &)
MirrorSearchSettings::searchEnginesUrlList
static QStringList searchEnginesUrlList()
Get List of the available search engine URLs.
Definition: mirrorsearchsettings.h:68
mirrorsearchsettings.h
MirrorSearch
void MirrorSearch(const KUrl &url, QObject *receiver, const char *member)
Definition: mirrors.cpp:90
KJob
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:17 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kget

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

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

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