summaryrefslogtreecommitdiffstats
path: root/src/translators/dataimporter.h
blob: 1d1eaf35fc8d1c323d1abfe995c75bc8ce5e70ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/***************************************************************************
    copyright            : (C) 2003-2006 by Robby Stephenson
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of version 2 of the GNU General Public License as  *
 *   published by the Free Software Foundation;                            *
 *                                                                         *
 ***************************************************************************/

#ifndef DATAIMPORTER_H
#define DATAIMPORTER_H

#include "importer.h"
#include "../filehandler.h"

namespace Tellico {
  namespace Import {

/**
 * @author Robby Stephenson
 */
class DataImporter : public Importer {
TQ_OBJECT
  

public:
  enum Source { URL, Text };

  /**
   * @param url The URL of the file to import
   */
//  DataImporter(const KURL& url) : Importer(url), m_data(FileHandler::readDataFile(url)), m_source(URL) {}
  DataImporter(const KURL& url) : Importer(url), m_source(URL) { m_fileRef = FileHandler::fileRef(url); }
  /**
   * Since the conversion to a TQCString appends a \0 character at the end, remove it.
   *
   * @param text The text. It MUST be in UTF-8.
   */
  DataImporter(const TQString& text) : Importer(text), m_data(text.utf8()), m_source(Text), m_fileRef(0)
    { m_data.truncate(m_data.size()-1); }
  /**
   */
  virtual ~DataImporter() { delete m_fileRef; m_fileRef = 0; }

  Source source() const { return m_source; }

  virtual void setText(const TQString& text) {
    Importer::setText(text); m_data = text.utf8(); m_data.truncate(m_data.size()-1); m_source = Text;
  }

protected:
  /**
   * Return the data in the imported file
   *
   * @return the file data
   */
  const TQByteArray& data() const { return m_data; }
  FileHandler::FileRef& fileRef() const { return *m_fileRef; }

private:
  TQByteArray m_data;
  Source m_source;
  FileHandler::FileRef* m_fileRef;
};

  } // end namespace
} // end namespace
#endif