summaryrefslogtreecommitdiffstats
path: root/src/languages/picprogrammer.h
blob: 580cf6b7f74e0f943c51abfb42b8d67581a8822a (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/***************************************************************************
 *   Copyright (C) 2005 by David Saxton                                    *
 *   david@bluehaze.org                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#ifndef PICPROGRAMMER_H
#define PICPROGRAMMER_H

#include "externallanguage.h"


class KConfig;
class KProcess;


class ProgrammerConfig
{
	public:
		ProgrammerConfig();
		
		/**
		 * Clears the type and all commands.
		 */
		void reset();
		
		QString initCommand;
		QString readCommand;
		QString writeCommand;
		QString verifyCommand;
		QString blankCheckCommand;
		QString eraseCommand;
		
		QString description;
		QString executable; // The name of the program executable
};

typedef QMap< QString, ProgrammerConfig > ProgrammerConfigMap;



/**
This class provides access to the PIC Programmer configurations. Several are
predefinied; the rest can be read from and written to, and removed. Names are
case insensitive.

Each programmer configuration is in the form of the ProgrammerConfig struct.

@author David Saxton
*/
class PicProgrammerSettings
{
	public:
		PicProgrammerSettings();
		
		/**
		 * Reads in custom ProgrammerConfigs from config. Any previously loaded
		 * configurations stored in this class will removed first.
		 */
		void load( KConfig * config );
		/**
		 * Saves the custom ProgrammConfigs to config.
		 */
		void save( KConfig * config );
		/**
		 * @return the ProgrammConfig for the programmer with the given name. If
		 * no such ProgrammerConfigs with the given name exist, then one will be
		 * created. The name is case insensitive (although the full case of the
		 * name will be stored if a new ProgrammerConfig is created).
		 */
		ProgrammerConfig config( const QString & name );
		/**
		 * Removes the config (if it is custom) with the give name.
		 */
		void removeConfig( const QString & name );
		/**
		 * Sets the ProgrammerConfig with the given name (or creates one if no
		 * such config exists). The name is case insensitive.
		 */
		void saveConfig( const QString & name, const ProgrammerConfig & config );
		/**
		 * @param makeLowercase whether the names should be converted to
		 * lowercase before returning.
		 * @return a list of names of the custom and predefined configs.
		 */
		QStringList configNames( bool makeLowercase ) const;
		/**
		 * @return whether the given config is predefined.
		 */
		bool isPredefined( const QString & name ) const;
		
	protected:
		/**
		 * Called when a PicProgrammerSettings object is first created. Does
		 * initialization of the predefined configs.
		 */
		void initStaticConfigs();
		
		ProgrammerConfigMap m_customConfigs;
		
		static bool m_bDoneStaticConfigsInit;
		static ProgrammerConfigMap m_staticConfigs;
};


/**
@author David Saxton
*/
class PicProgrammer : public ExternalLanguage
{
	public:
		PicProgrammer( ProcessChain *processChain, KTechlab *parent );
		~PicProgrammer();
	
		virtual void processInput( ProcessOptions options );
		virtual ProcessOptions::ProcessPath::Path outputPath( ProcessOptions::ProcessPath::Path inputPath ) const;

	protected:
		virtual bool isError( const QString &message ) const;
		virtual bool isWarning( const QString &message ) const;
};

#endif