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

kget

  • sources
  • kde-4.14
  • kdenetwork
  • kget
  • core
mostlocalurl.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 * Copyright (C) 2011 Matthias Fuchs <mat69@gmx.net> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18 ***************************************************************************/
19 
20 #include "mostlocalurl.h"
21 #include "kget.h"
22 #include "plugin/transferfactory.h"
23 
24 #include <KDebug>
25 #include <KIO/NetAccess>
26 
27 KUrl mostLocalUrl(const KUrl &url)
28 {
29  kDebug(5001);
30  const QString protocol = url.protocol();
31  foreach (TransferFactory *factory, KGet::factories()) {
32  if (factory->addsProtocols().contains(protocol)) {
33  return url;
34  }
35  }
36 
37  kDebug(5001) << "Starting KIO::NetAccess::mostLocalUrl for:" << url;
38  return KIO::NetAccess::mostLocalUrl(url, 0);
39 }
40 
41 MostLocalUrlJob *mostLocalUrlJob(const KUrl &url)
42 {
43  return new MostLocalUrlJob(url);
44 }
45 
46 MostLocalUrlJob::MostLocalUrlJob(const KUrl& url)
47  : KIO::Job(),
48  m_url(url)
49 {
50 }
51 
52 KUrl MostLocalUrlJob::url()
53 {
54  return m_url;
55 }
56 
57 KUrl MostLocalUrlJob::mostLocalUrl() const
58 {
59  return m_mostLocalUrl;
60 }
61 
62 void MostLocalUrlJob::start()
63 {
64  bool startJob = true;
65  const QString protocol = m_url.protocol();
66  foreach (TransferFactory *factory, KGet::factories()) {
67  if (factory->addsProtocols().contains(protocol)) {
68  startJob = false;
69  break;
70  }
71  }
72 
73  if (startJob) {
74  kDebug(5001) << "Starting KIO::mostLocalUrl for:" << m_url;
75  KIO::Job *job = KIO::mostLocalUrl(m_url, KIO::HideProgressInfo);
76  addSubjob(job);
77  } else {
78  m_mostLocalUrl = m_url;
79  emitResult();
80  }
81 }
82 
83 void MostLocalUrlJob::slotResult(KJob* job)
84 {
85  if (job->error()) {
86  kWarning(5001) << "Error" << job->error() << "happened for:" << m_url;
87  m_mostLocalUrl = m_url;
88  } else {
89  m_mostLocalUrl = static_cast<KIO::StatJob*>(job)->mostLocalUrl();
90  }
91  kDebug(5001) << "Setting mostLocalUrl to" << m_mostLocalUrl;
92  emitResult();
93 }
Job
Definition: job.h:35
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
MostLocalUrlJob::slotResult
virtual void slotResult(KJob *job)
Definition: mostlocalurl.cpp:83
mostlocalurl.h
TransferFactory::addsProtocols
virtual QStringList addsProtocols() const
Returns a list of protocols for which the TransferFactory adds support.
Definition: transferfactory.cpp:78
mostLocalUrl
KUrl mostLocalUrl(const KUrl &url)
Synchronous.
Definition: mostlocalurl.cpp:27
mostLocalUrlJob
MostLocalUrlJob * mostLocalUrlJob(const KUrl &url)
Asynchronous.
Definition: mostlocalurl.cpp:41
MostLocalUrlJob::MostLocalUrlJob
MostLocalUrlJob(const KUrl &url)
Definition: mostlocalurl.cpp:46
MostLocalUrlJob::start
virtual void start()
Definition: mostlocalurl.cpp:62
transferfactory.h
MostLocalUrlJob::mostLocalUrl
KUrl mostLocalUrl() const
Call this in the slot connected to result.
Definition: mostlocalurl.cpp:57
QString
MostLocalUrlJob
Job for asynchronously getting the most local url, do not use directly, but use mostLocalUrlJob inste...
Definition: mostlocalurl.h:54
MostLocalUrlJob::url
KUrl url()
Definition: mostlocalurl.cpp:52
kget.h
TransferFactory
TransferFactory.
Definition: transferfactory.h:52
KGet::factories
static QList< TransferFactory * > factories()
Definition: kget.cpp:621
KJob
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:28:43 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