• 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
  • mmsthreads
mmstransfer.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the KDE project
3  Copyright (C) 2011 Ernesto Rodriguez Ortiz <eortiz@uci.cu>
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 3 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, see <http://www.gnu.org/licenses/>.
17 
18 */
19 
20 #include "mmstransfer.h"
21 
22 MmsTransfer::MmsTransfer(TransferGroup * parent, TransferFactory * factory,
23  Scheduler * scheduler, const KUrl & source, const
24  KUrl &dest, const QDomElement * e)
25  : Transfer(parent, factory, scheduler, source, dest, e),
26  m_mmsdownload(NULL),
27  m_amountThreads(MmsSettings::threads()),
28  m_retryDownload(false)
29 {
30  m_fileTemp = KStandardDirs::locateLocal("appdata", m_dest.fileName());
31  kDebug(5001) << "Mms transfer initialized: " + m_source.prettyUrl();
32 }
33 
34 MmsTransfer::~MmsTransfer()
35 {
37  if (m_mmsdownload) {
38  m_mmsdownload->quit();
39  m_mmsdownload->deleteLater();
40  }
41 }
42 
43 void MmsTransfer::start()
44 {
46  if (m_mmsdownload || status() == Finished) {
47  return;
48  }
49 
50  setStatus(Job::Running, i18nc("transfer state: running", "Running...."),
51  SmallIcon("media-playback-start"));
52  m_mmsdownload = new MmsDownload(m_source.prettyUrl(), m_dest.pathOrUrl(),
53  m_fileTemp, m_amountThreads);
54  connect(m_mmsdownload, SIGNAL(finished()), this, SLOT(slotResult()));
55  connect(m_mmsdownload, SIGNAL(signBrokenUrl()), this, SLOT(slotBrokenUrl()));
56  connect(m_mmsdownload, SIGNAL(signNotAllowMultiDownload()), this,
57  SLOT(slotNotAllowMultiDownload()));
58  connect(m_mmsdownload, SIGNAL(signTotalSize(qulonglong)), this,
59  SLOT(slotTotalSize(qulonglong)));
60  connect(m_mmsdownload, SIGNAL(signDownloaded(qulonglong)), this,
61  SLOT(slotProcessedSizeAndPercent(qulonglong)));
62  connect(m_mmsdownload, SIGNAL(signSpeed(ulong)), this,
63  SLOT(slotSpeed(ulong)));
64  connect(m_mmsdownload, SIGNAL(signRestartDownload(int)), this,
65  SLOT(slotConnectionsErrors(int)));
66  m_mmsdownload->start();
67  setTransferChange(Tc_Status, true);
68 }
69 
70 void MmsTransfer::stop()
71 {
75  if ((status() == Stopped) || (status() == Finished)) {
76  return;
77  }
78 
79  if (m_mmsdownload) {
80  if (m_mmsdownload->threadsAlive() > 0) {
81  m_mmsdownload->stopTransfer();
82  }
83  }
84 
85  setStatus(Job::Stopped, i18nc("transfer state: stopped", "Stopped"),
86  SmallIcon("process-stop"));
87  m_downloadSpeed = 0;
88  setTransferChange(Tc_Status | Tc_DownloadSpeed, true);
89 }
90 
91 void MmsTransfer::deinit(Transfer::DeleteOptions options)
92 {
94  if (options & Transfer::DeleteFiles) {
95  KIO::Job *del = KIO::del(m_fileTemp, KIO::HideProgressInfo);
96  KIO::NetAccess::synchronousRun(del, 0);
97  del = KIO::del(m_dest.path(), KIO::HideProgressInfo);
98  KIO::NetAccess::synchronousRun(del, 0);
99  }
100 }
101 
102 void MmsTransfer::slotResult()
103 {
106  m_mmsdownload->deleteLater();
107  m_mmsdownload = NULL;
108 
112  if (m_downloadedSize == m_totalSize && m_totalSize != 0) {
113  setStatus(Job::Finished, i18nc("Transfer State:Finished","Finished"),
114  SmallIcon("dialog-ok"));
115  m_percent = 100;
116  m_downloadSpeed = 0;
117  setTransferChange(Tc_Status | Tc_Percent | Tc_DownloadSpeed, true);
118  KIO::Job *del = KIO::del(m_fileTemp, KIO::HideProgressInfo);
119  KIO::NetAccess::synchronousRun(del, 0);
120  }
121 
127  if (m_retryDownload) {
128  m_retryDownload = false;
129  KIO::Job *del = KIO::del(m_fileTemp, KIO::HideProgressInfo);
130  KIO::NetAccess::synchronousRun(del, 0);
131  start();
132  }
133 }
134 
135 void MmsTransfer::slotTotalSize(qulonglong size)
136 {
137  m_totalSize = size;
138  setTransferChange(Tc_TotalSize, true);
139 }
140 
141 void MmsTransfer::slotSpeed(ulong speed)
142 {
143  m_downloadSpeed = (status() == Running) ? speed : 0;
144  setTransferChange(Tc_DownloadSpeed, true);
145 }
146 
147 void MmsTransfer::slotProcessedSizeAndPercent(qulonglong size)
148 {
149  m_downloadedSize = size;
150  m_percent = (m_downloadedSize * 100) / m_totalSize;
151  setTransferChange(Tc_DownloadedSize | Tc_Percent, true);
152 }
153 
154 void MmsTransfer::slotBrokenUrl()
155 {
156  setError(i18n("Download failed, could not access this URL."), SmallIcon("dialog-cancel"),
157  Job::NotSolveable);
158  setTransferChange(Tc_Status, true);
159 }
160 
161 void MmsTransfer::slotNotAllowMultiDownload()
162 {
166  KGet::showNotification(0, "notification", i18n("This URL does not allow multiple connections,\n"
167  "the download will take longer."));
168 }
169 
170 void MmsTransfer::slotConnectionsErrors(int connections)
171 {
177  stop();
178  m_retryDownload = true;
179  if (connections) {
180  m_amountThreads = connections;
181  } else {
182  m_amountThreads--;
183  }
184 }
185 
186 #include "mmstransfer.moc"
MmsTransfer::stop
void stop()
Definition: mmstransfer.cpp:70
MmsTransfer::start
void start()
Definition: mmstransfer.cpp:43
Transfer::m_dest
KUrl m_dest
Definition: transfer.h:357
TransferGroup
class TransferGroup:
Definition: transfergroup.h:46
Scheduler
Scheduler class: what handle all the jobs in kget.
Definition: scheduler.h:32
Job::Finished
The job is stopped, but this also indicates that it stopped because an error occurred.
Definition: job.h:47
Transfer::m_downloadedSize
KIO::filesize_t m_downloadedSize
Definition: transfer.h:361
MmsTransfer::~MmsTransfer
~MmsTransfer()
Definition: mmstransfer.cpp:34
Job::NotSolveable
Definition: job.h:71
MmsTransfer::MmsTransfer
MmsTransfer(TransferGroup *parent, TransferFactory *factory, Scheduler *scheduler, const KUrl &src, const KUrl &dest, const QDomElement *e=0)
Definition: mmstransfer.cpp:22
Transfer::m_totalSize
KIO::filesize_t m_totalSize
Definition: transfer.h:360
Transfer::Tc_Status
Definition: transfer.h:53
Transfer::m_downloadSpeed
int m_downloadSpeed
Definition: transfer.h:364
Job::Running
Definition: job.h:43
MmsDownload::threadsAlive
int threadsAlive()
Definition: mmsdownload.cpp:153
Transfer::Tc_DownloadSpeed
Definition: transfer.h:56
Transfer::setTransferChange
virtual void setTransferChange(ChangesFlags change, bool postEvent=false)
Makes the TransferHandler associated with this transfer know that a change in this transfer has occur...
Definition: transfer.cpp:338
Job::Stopped
The job is being executed.
Definition: job.h:44
MmsDownload
Definition: mmsdownload.h:34
MmsTransfer::deinit
void deinit(Transfer::DeleteOptions options)
Definition: mmstransfer.cpp:91
Job::status
Status status() const
Definition: job.h:93
MmsSettings
Definition: mmssettings.h:9
MmsDownload::stopTransfer
void stopTransfer()
Definition: mmsdownload.cpp:141
KGet::showNotification
static KNotification * showNotification(QWidget *parent, const QString &eventType, const QString &text, const QString &icon=QString("dialog-error"), const QString &title=i18n("KGet"), const KNotification::NotificationFlags &flags=KNotification::CloseOnTimeout)
Shows a knotification.
Definition: kget.cpp:1281
Transfer::setStatus
void setStatus(Job::Status jobStatus, const QString &text=QString(), const QPixmap &pix=QPixmap())
Sets the Job status to jobStatus, the status text to text and the status pixmap to pix...
Definition: transfer.cpp:292
Transfer::Tc_TotalSize
Definition: transfer.h:54
mmstransfer.h
Transfer::Tc_Percent
Definition: transfer.h:55
Transfer::Tc_DownloadedSize
Definition: transfer.h:63
Transfer::m_percent
int m_percent
Definition: transfer.h:363
Transfer::DeleteFiles
Definition: transfer.h:97
TransferFactory
TransferFactory.
Definition: transferfactory.h:52
Transfer::m_source
KUrl m_source
Definition: transfer.h:356
Job::setError
void setError(const QString &text, const QPixmap &pixmap, ErrorType type=AutomaticRetry, int errorId=-1)
Definition: job.cpp:65
Transfer
Definition: transfer.h:36
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