• 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
mmsthread.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 "mmsthread.h"
21 
22 MmsThread::MmsThread(const QString& url, const QString& name, int begin, int end)
23 : QThread(),
24  m_sourceUrl(url),
25  m_fileName(name),
26  m_begin(begin),
27  m_end(end),
28  m_download(true)
29 {}
30 
31 void MmsThread::run()
32 {
34  int readed;
35  mmsx_t* mms;
36  QFile file(m_fileName);
38  file.open(QIODevice::ReadWrite);
39  file.seek(m_begin);
40 
42  mms = mmsx_connect(NULL, NULL, qstrdup(m_sourceUrl.toAscii()) , 1e6);
43  if (mms) {
44  m_locker.lock();
45  emit signIsConnected(true);
46  m_locker.unlock();
48  mmsx_seek(0, mms, m_begin, 0);
49  while ((m_begin < m_end) && m_download) {
50  if ((m_begin + 1024) > m_end) {
51  const int var = m_end - m_begin;
52  char data[var];
53  readed = mmsx_read(0, mms, data, var);
54  m_locker.lock();
55  emit signReading(var, m_end, m_begin = m_end);
57  if (readed) {
58  file.write(data, readed);
59  }
60  m_locker.unlock();
61  } else {
62  char data[1024];
63  readed = mmsx_read(0, mms, data, 1024);
64  m_locker.lock();
65  emit signReading(1024, m_end, m_begin += 1024);
67  if (readed) {
68  file.write(data, readed);
69  }
70  m_locker.unlock();
71  }
72  }
73  file.close();
74  mmsx_close(mms);
75  quit(); // NOTE: Keep "quit()" here, if not then the thread never emit the signal finish.
76  } else {
78  m_locker.lock();
79  emit signIsConnected(false);
80  m_locker.unlock();
81  quit(); // NOTE: Keep "quit()" here, if not then the thread never emit the signal finish.
82  }
83  exec();
84 }
85 
86 void MmsThread::stop()
87 {
88  m_download = false;
89 }
MmsThread::run
void run()
Definition: mmsthread.cpp:31
MmsThread::signReading
void signReading(int data, int m_end, int m_begin)
MmsThread::stop
void stop()
Definition: mmsthread.cpp:86
MmsThread::signIsConnected
void signIsConnected(bool connected)
mmsthread.h
MmsThread::MmsThread
MmsThread(const QString &url, const QString &name, int begin, int end)
Definition: mmsthread.cpp:22
QThread
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