1
/***************************************************************************
2
copyright : (C) 2007 by Robby Stephenson
3
email : robby@periapsis.org
4
***************************************************************************/
6
/***************************************************************************
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; *
12
***************************************************************************/
14
#include "griffithimporter.h"
15
#include "../collections/videocollection.h"
16
#include "tellicoimporter.h"
17
#include "../tellico_debug.h"
20
#include <kstandarddirs.h>
26
using Tellico::Import::GriffithImporter;
28
GriffithImporter::~GriffithImporter() {
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;
43
QString python = KStandardDirs::findExe(QString::fromLatin1("python"));
44
if(python.isEmpty()) {
45
myWarning() << "GriffithImporter::collection() - python not found!" << endl;
49
QString griffith = KGlobal::dirs()->findResource("appdata", QString::fromLatin1("griffith2tellico.py"));
50
if(griffith.isEmpty()) {
51
myWarning() << "GriffithImporter::collection() - griffith2tellico.py not found!" << endl;
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;
68
void GriffithImporter::slotData(KProcess*, char* buffer_, int len_) {
69
QDataStream stream(m_data, IO_WriteOnly | IO_Append);
70
stream.writeRawBytes(buffer_, len_);
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);
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;
87
if(m_data.isEmpty()) {
88
myDebug() << "GriffithImporter::slotProcessExited() - no data" << endl;
92
QString text = QString::fromUtf8(m_data, m_data.size());
93
TellicoImporter imp(text);
95
m_coll = imp.collection();
97
myDebug() << "GriffithImporter::slotProcessExited() - no collection pointer" << endl;
99
myLog() << "GriffithImporter::slotProcessExited() - results found: " << m_coll->entryCount() << endl;
103
bool GriffithImporter::canImport(int type) const {
104
return type == Data::Collection::Video;
107
#include "griffithimporter.moc"