• 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
contentfetch.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 "contentfetch.h"
12 #include "core/kget.h"
13 #include "core/transfergroup.h"
14 #include "script.h"
15 
16 #include <kiconloader.h>
17 #include <klocale.h>
18 #include <KDebug>
19 #include <KMessageBox>
20 #include <KUrl>
21 
22 #include <kross/core/manager.h>
23 #include <kross/core/action.h>
24 #include <QDomElement>
25 #include <QFile>
26 #include <QString>
27 
28 ContentFetch::ContentFetch(TransferGroup* parent, TransferFactory* factory,
29  Scheduler* scheduler, const KUrl& source,
30  const KUrl& dest, const QString &scriptFile,
31  const QDomElement* e)
32  : Transfer(parent, factory, scheduler, source, dest, e),
33  m_p_group(parent), m_scriptFile(scriptFile), m_destDir(dest.directory(KUrl::AppendTrailingSlash))
34 {
35  m_p_script = new Script(this, source);
36  connect(m_p_script, SIGNAL(newTransfer(QString,QString)),
37  this, SLOT(slotAddTransfer(QString,QString)));
38  connect(m_p_script, SIGNAL(finished()), this, SLOT(slotFinish()));
39  connect(m_p_script, SIGNAL(aborted(QString)), this, SLOT(slotAbort(QString)));
40  connect(m_p_script, SIGNAL(percentUpdated(int)), this, SLOT(setPercent(int)));
41  connect(m_p_script, SIGNAL(textStatusUpdated(QString)), this, SLOT(slotSetTextStatus(QString)));
42 }
43 
44 void ContentFetch::deinit()
45 {
46  return;
47 }
48 
49 void ContentFetch::start()
50 {
51  kDebug(5001) << "ContentFetch::start";
52  setStatus(Job::Running, i18nc("Transfer state: processing script", "Processing script...."), SmallIcon("media-playback-start"));
53  setTransferChange(Tc_Status, true);
54  m_p_script->setFile(m_scriptFile);
55  m_p_script->start();
56  kDebug(5001) << "ContentFetch::start() finished!";
57 }
58 
59 void ContentFetch::stop()
60 {
61  if(status() == Stopped)
62  {
63  return;
64  }
65  kDebug(5001) << "ContentFetch::stop";
66  // kill -9 the script
67  m_p_script->terminate();
68  // delete m_p_script to avoid crash?
69  setStatus(Job::Stopped, i18nc("transfer state: stopped", "Stopped"), SmallIcon("process-stop"));
70  setTransferChange(Tc_Status, true);
71 }
72 
73 void ContentFetch::slotAddTransfer(const QString &url, const QString &filename)
74 {
75  // even if filename is empty it's still ok
76  kDebug() << "The whole filename is " << m_destDir + filename;
77  KGet::addTransfer(KUrl(url), m_destDir + filename, m_p_group->name(), true);
78 }
79 
80 void ContentFetch::slotFinish()
81 {
82  m_percent = 100;
83  setStatus(Job::Finished, i18nc("Transfer State: Finished", "Finished"), SmallIcon("dialog-ok"));
84  setTransferChange(Tc_Status|Tc_Percent, true);
85  //delete m_p_script;
86 }
87 
88 void ContentFetch::slotAbort(const QString &error)
89 {
90  if (error.isEmpty())
91  {
92  setStatus(Job::Aborted, i18nc("Transfer State: Aborted", "Aborted"), SmallIcon("process-stop"));
93  }
94  else
95  {
96  setStatus(Job::Aborted, error, SmallIcon("process-stop"));
97  }
98  setTransferChange(Tc_Status, true);
99 }
100 
101 void ContentFetch::slotSetTextStatus(const QString& text)
102 {
103  setStatus(Job::Running, text, SmallIcon("media-playback-start"));
104  setTransferChange(Tc_Status, true);
105 }
106 
107 bool ContentFetch::isResumable() const
108 {
109  return false;
110 }
111 
112 void ContentFetch::setPercent(int percent)
113 {
114  m_percent = percent;
115  setTransferChange( Transfer::Tc_Percent, true );
116 }
ContentFetch::ContentFetch
ContentFetch(TransferGroup *parent, TransferFactory *factory, Scheduler *scheduler, const KUrl &src, const KUrl &dest, const QString &scriptFile, const QDomElement *e=0)
Definition: contentfetch.cpp:28
KGet::addTransfer
static TransferHandler * addTransfer(KUrl srcUrl, QString destDir=QString(), QString suggestedFileName=QString(), QString groupName=QString(), bool start=false)
Adds a new transfer to the KGet.
Definition: kget.cpp:179
ContentFetch::start
void start()
Definition: contentfetch.cpp:49
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
contentfetch.h
TransferGroup::name
const QString & name()
Definition: transfergroup.h:163
Transfer::percent
int percent() const
Definition: transfer.h:178
script.h
Transfer::Tc_Status
Definition: transfer.h:53
Script
Definition: script.h:24
Job::Running
Definition: job.h:43
Script::setFile
bool setFile(const QString &filename)
Definition: script.cpp:41
transfergroup.h
Job::Aborted
The job is stopped.
Definition: job.h:45
ContentFetch::setPercent
void setPercent(int percent)
Definition: contentfetch.cpp:112
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
Job::status
Status status() const
Definition: job.h:93
kget.h
ContentFetch::isResumable
bool isResumable() const
Definition: contentfetch.cpp:107
ContentFetch::deinit
void deinit()
Definition: contentfetch.cpp:44
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_Percent
Definition: transfer.h:55
Transfer::m_percent
int m_percent
Definition: transfer.h:363
TransferFactory
TransferFactory.
Definition: transferfactory.h:52
ContentFetch::stop
void stop()
Definition: contentfetch.cpp:59
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