~paulbrianstewart/ubuntu/oneiric/tellico/852247-Formatting-Fix

« back to all changes in this revision

Viewing changes to src/translators/griffithimporter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-31 19:33:05 UTC
  • mfrom: (0.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080131193305-9l01m5gfhykl6pkl
Tags: 1.3-1ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: build-dep on kdepim-dev
  - debian/control: drop versioned python from tellico-data suggests
  - debian/rules: call dh_icons

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    copyright            : (C) 2007 by Robby Stephenson
 
3
    email                : robby@periapsis.org
 
4
 ***************************************************************************/
 
5
 
 
6
/***************************************************************************
 
7
 *                                                                         *
 
8
 *   This program is free software; you can redistribute it and/or modify  *
 
9
 *   it under the terms of version 2 of the GNU General Public License as  *
 
10
 *   published by the Free Software Foundation;                            *
 
11
 *                                                                         *
 
12
 ***************************************************************************/
 
13
 
 
14
#include "griffithimporter.h"
 
15
#include "../collections/videocollection.h"
 
16
#include "tellicoimporter.h"
 
17
#include "../tellico_debug.h"
 
18
 
 
19
#include <kglobal.h>
 
20
#include <kstandarddirs.h>
 
21
#include <kprocess.h>
 
22
 
 
23
#include <qdir.h>
 
24
#include <qfile.h>
 
25
 
 
26
using Tellico::Import::GriffithImporter;
 
27
 
 
28
GriffithImporter::~GriffithImporter() {
 
29
  if(m_process) {
 
30
    m_process->kill();
 
31
    delete m_process;
 
32
    m_process = 0;
 
33
  }
 
34
}
 
35
 
 
36
Tellico::Data::CollPtr GriffithImporter::collection() {
 
37
  QString filename = QDir::homeDirPath() + QString::fromLatin1("/.griffith/griffith.db");
 
38
  if(!QFile::exists(filename)) {
 
39
    myWarning() << "GriffithImporter::collection() - database not found: " << filename << endl;
 
40
    return 0;
 
41
  }
 
42
 
 
43
  QString python = KStandardDirs::findExe(QString::fromLatin1("python"));
 
44
  if(python.isEmpty()) {
 
45
    myWarning() << "GriffithImporter::collection() - python not found!" << endl;
 
46
    return 0;
 
47
  }
 
48
 
 
49
  QString griffith = KGlobal::dirs()->findResource("appdata", QString::fromLatin1("griffith2tellico.py"));
 
50
  if(griffith.isEmpty()) {
 
51
    myWarning() << "GriffithImporter::collection() - griffith2tellico.py not found!" << endl;
 
52
    return 0;
 
53
  }
 
54
 
 
55
  m_process = new KProcess();
 
56
  connect(m_process, SIGNAL(receivedStdout(KProcess*, char*, int)), SLOT(slotData(KProcess*, char*, int)));
 
57
  connect(m_process, SIGNAL(receivedStderr(KProcess*, char*, int)), SLOT(slotError(KProcess*, char*, int)));
 
58
  connect(m_process, SIGNAL(processExited(KProcess*)), SLOT(slotProcessExited(KProcess*)));
 
59
  *m_process << python << griffith;
 
60
  if(!m_process->start(KProcess::Block, KProcess::AllOutput)) {
 
61
    myDebug() << "ExecExternalFetcher::startSearch() - process failed to start" << endl;
 
62
    return 0;
 
63
  }
 
64
 
 
65
  return m_coll;
 
66
}
 
67
 
 
68
void GriffithImporter::slotData(KProcess*, char* buffer_, int len_) {
 
69
  QDataStream stream(m_data, IO_WriteOnly | IO_Append);
 
70
  stream.writeRawBytes(buffer_, len_);
 
71
}
 
72
 
 
73
void GriffithImporter::slotError(KProcess*, char* buffer_, int len_) {
 
74
  QString msg = QString::fromLocal8Bit(buffer_, len_);
 
75
  myDebug() << "GriffithImporter::slotError() - " << msg << endl;
 
76
  setStatusMessage(msg);
 
77
}
 
78
 
 
79
 
 
80
void GriffithImporter::slotProcessExited(KProcess*) {
 
81
//  myDebug() << "GriffithImporter::slotProcessExited()" << endl;
 
82
  if(!m_process->normalExit() || m_process->exitStatus()) {
 
83
    myDebug() << "GriffithImporter::slotProcessExited() - process did not exit successfully" << endl;
 
84
    return;
 
85
  }
 
86
 
 
87
  if(m_data.isEmpty()) {
 
88
    myDebug() << "GriffithImporter::slotProcessExited() - no data" << endl;
 
89
    return;
 
90
  }
 
91
 
 
92
  QString text = QString::fromUtf8(m_data, m_data.size());
 
93
  TellicoImporter imp(text);
 
94
 
 
95
  m_coll = imp.collection();
 
96
  if(!m_coll) {
 
97
    myDebug() << "GriffithImporter::slotProcessExited() - no collection pointer" << endl;
 
98
  } else {
 
99
    myLog() << "GriffithImporter::slotProcessExited() - results found: " << m_coll->entryCount() << endl;
 
100
  }
 
101
}
 
102
 
 
103
bool GriffithImporter::canImport(int type) const {
 
104
  return type == Data::Collection::Video;
 
105
}
 
106
 
 
107
#include "griffithimporter.moc"