summaryrefslogtreecommitdiffstats
path: root/src/newstuff/manager.h
blob: 4102be3d93302a625545bac45f657bdccd8234f4 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/***************************************************************************
    copyright            : (C) 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 TELLICO_NEWSTUFF_MANAGER_H
#define TELLICO_NEWSTUFF_MANAGER_H

class KArchiveDirectory;
class KURL;
class KTempFile;

#include <qobject.h>
#include <qptrlist.h>

class QStringList;

namespace KNS {
  class Entry;
}
namespace KIO {
  class Job;
}

namespace Tellico {
  namespace NewStuff {

class NewScript;

enum DataType {
  EntryTemplate,
  DataScript
};

enum InstallStatus {
  NotInstalled,
  OldVersion,
  Current
};

struct DataSourceInfo {
  DataSourceInfo() : isUpdate(false) {}
  QString specFile; // full path of .spec file
  QString sourceName;
  QString sourceExec; // full executable path of script
  bool isUpdate : 1; // whether the info is for an updated source
};

class Manager : public QObject {
Q_OBJECT

public:
  Manager(QObject* parent);
  ~Manager();

  void install(DataType type, KNS::Entry* entry);
  QPtrList<DataSourceInfo> dataSourceInfo() const { return m_infoList; }

  bool installTemplate(const KURL& url, const QString& entryName = QString::null);
  bool removeTemplate(const QString& name);

  bool installScript(const KURL& url);
  bool removeScript(const QString& name);

  static InstallStatus installStatus(KNS::Entry* entry);
  static bool checkCommonFile();

signals:
  void signalInstalled(KNS::Entry* entry);

private slots:
  void slotDownloadJobResult(KIO::Job* job);
  void slotInstallFinished();

private:
  static QStringList archiveFiles(const KArchiveDirectory* dir,
                                  const QString& path = QString::null);

  static QString findXSL(const KArchiveDirectory* dir);
  static QString findEXE(const KArchiveDirectory* dir);

  typedef QPair<KNS::Entry*, DataType> EntryPair;
  QMap<KIO::Job*, EntryPair> m_jobMap;
  QMap<KURL, QString> m_urlNameMap;
  QMap<const NewScript*, KNS::Entry*> m_scriptEntryMap;
  QPtrList<DataSourceInfo> m_infoList;
  KTempFile* m_tempFile;
};

  }
}

#endif