• 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
  • contentfetch
script.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2 
3  Copyright (C) 2008 Ningyu Shi <shiningyu@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 "script.h"
12 #include "scriptdownloadengine.h"
13 #include "scriptconfigadaptor.h"
14 #include <QVariant>
15 #include <KDebug>
16 
17 Script::Script(QObject* parent, const KUrl &source)
18  :QThread(parent), m_p_kgetcore(0), m_source(source)
19 {
20  kDebug(5002) << "One Script Newed.";
21  /*
22  Use 0 as parent here because of threading issue, comply to qt manual.
23  Adapted below:
24  " The child of a QObject must always be created in the thread where the
25  parent was created. This implies, among other things, that you should
26  never pass the QThread object (this) as the parent of an object created
27  in the thread (since the QThread object itself was created in another thread)."
28 
29  See http://doc.trolltech.com/4.4/threads.html#qobject-reentrancy
30  */
31  m_p_kgetcore = new ScriptDownloadEngine(0, m_source);
32 }
33 
34 Script::~Script()
35 {
36  delete m_p_kgetcore;
37  delete m_p_action;
38  kDebug(5002) << "m_p_kgetcore & m_p_action is deleted!";
39 }
40 
41 bool Script::setFile(const QString &filename)
42 {
43  m_fileName = filename;
44  return true;
45 }
46 
47 void Script::run()
48 {
49  setPriority(QThread::LowPriority);
50  // use 0 as parent, see Constructor.
51  m_p_action = new Kross::Action(0, m_fileName); //"ContentFetchScript");
52  // quit the exec() loop after get finish/abort signal from script
53  connect(m_p_kgetcore, SIGNAL(finished()), this, SLOT(quit()));
54  connect(m_p_kgetcore, SIGNAL(aborted(QString)), this, SLOT(quit()));
55  // add transfer
56  connect(m_p_kgetcore, SIGNAL(newTransfer(QString,QString)),
57  this, SIGNAL(newTransfer(QString,QString)));
58  // update status signal/slot
59  connect(m_p_kgetcore, SIGNAL(percentUpdated(int)),
60  this, SIGNAL(percentUpdated(int)));
61  connect(m_p_kgetcore, SIGNAL(textStatusUpdated(QString)),
62  this, SIGNAL(textStatusUpdated(QString)));
63  connect(m_p_kgetcore, SIGNAL(finished()), this, SIGNAL(finished()));
64  connect(m_p_kgetcore, SIGNAL(aborted(QString)), this, SIGNAL(aborted(QString)));
65  // main entry point
66  connect(this, SIGNAL(startDownload(QObject*)),
67  m_p_kgetcore, SIGNAL(startDownload(QObject*)));
68  m_p_action->setFile(m_fileName);
69  // TODO add check
70  kDebug(5002) << "KGetCore Added to script at ThreadId " << QThread::currentThreadId();
71  m_p_action->addObject(m_p_kgetcore, "kgetcore",
72  Kross::ChildrenInterface::AutoConnectSignals);
73  m_p_action->trigger();
74  ScriptConfigAdaptor config;
75  emit startDownload(&config);
76 
77  //m_p_action->callFunction("startDownload", QVariantList());
78  kDebug(5002) << "Script Finished!" << QThread::currentThreadId();
79  //delete m_p_kgetcore;
80  //delete m_p_action;
81  if (m_p_action->hadError())
82  {
83  kDebug(5002) << "Error:" << m_p_action->errorMessage() << m_p_action->errorTrace();
84  }
85  else
86  {
87  exec();
88  }
89 }
Script::percentUpdated
void percentUpdated(int percent)
QObject
script.h
Script::Script
Script(QObject *parent, const KUrl &source)
Definition: script.cpp:17
ScriptDownloadEngine
Definition: scriptdownloadengine.h:21
scriptdownloadengine.h
Script::textStatusUpdated
void textStatusUpdated(const QString &text)
Script::startDownload
void startDownload(QObject *configadaptor)
Script::setFile
bool setFile(const QString &filename)
Definition: script.cpp:41
Script::newTransfer
void newTransfer(const QString &url, const QString &filename)
Script::finished
void finished()
Script::run
void run()
Definition: script.cpp:47
scriptconfigadaptor.h
Script::~Script
~Script()
Definition: script.cpp:34
ScriptConfigAdaptor
Definition: scriptconfigadaptor.h:20
Script::aborted
void aborted(const QString &error)
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