summaryrefslogtreecommitdiffstats
path: root/src/libgui/device_gui.h
blob: a10c58a213787434669d3a2ec7157fe9cf044f31 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/***************************************************************************
 *   Copyright (C) 2005 Nicolas Hadacek <hadacek@kde.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 DEVICE_GUI_H
#define DEVICE_GUI_H

#include <qpushbutton.h>
#include <qlayout.h>
#include <qcombobox.h>
class QListViewItem;
class QCheckBox;
#include <ktextbrowser.h>
class KListView;

#include "common/gui/key_gui.h"
#include "common/gui/dialog.h"
#include "device_editor.h"
#include "devices/pic/base/pic.h"
namespace Programmer { class Group; }
namespace Tool { class Group; }

namespace DeviceChooser
{

enum Type { Choose, ChooseWithAuto };
class View;

BEGIN_DECLARE_ENUM(ListType)
  FamilyTree = 0, Flat
END_DECLARE_ENUM_STD(ListType)

//-----------------------------------------------------------------------------
class Config : public GenericConfig
{
public:
  Config() : GenericConfig("device_chooser") {}
  const Programmer::Group *programmerGroup();
  void writeProgrammerGroup(const Programmer::Group *group);
  const Tool::Group *toolGroup();
  void writeToolGroup(const Tool::Group *group);
};

//-----------------------------------------------------------------------------
template <typename Enum>
class EnumComboBox
{
public:
  EnumComboBox(const QString &key, QWidget *parent) : _key(key) {
    _combo = new QComboBox(parent);
    for (Enum type; type<Enum::Nb_Types; ++type) _combo->insertItem(type.label());
    Config config;
    Enum type = config.readEnumEntry(key, Enum(Enum::Nb_Types));
    if ( type!=Enum::Nb_Types ) _combo->setCurrentItem(type.type());
  }
  EnumComboBox(const QString &emptyLabel, const QString &key, QWidget *parent) : _key(key) {
    _combo = new QComboBox(parent);
    _combo->insertItem(emptyLabel);
    for (Enum type; type<Enum::Nb_Types; ++type) _combo->insertItem(type.label());
    Config config;
    Enum type = config.readEnumEntry(key, Enum(Enum::Nb_Types));
    if ( type!=Enum::Nb_Types ) _combo->setCurrentItem(type.type()+1);
  }
  QComboBox *combo() { return _combo; }
  Enum value() const {
    if ( _combo->count()==Enum::Nb_Types ) return typename Enum::Type(_combo->currentItem());
    if ( _combo->currentItem()==0 ) return Enum::Nb_Types;
    return typename Enum::Type(_combo->currentItem()-1);
  }
  void reset() { _combo->setCurrentItem(0); }
  void writeConfig() {
    Config config;
    config.writeEnumEntry(_key, value());
  }

private:
  QString    _key;
  QComboBox *_combo;
};

//-----------------------------------------------------------------------------
class Dialog : public ::Dialog
{
Q_OBJECT
public:
  Dialog(const QString &device, Type type, QWidget *parent);
  virtual ~Dialog();

  QString device() const;

private slots:
  void listDoubleClicked(QListViewItem *item);
  void currentChanged(QListViewItem *item);
  void deviceChange(const QString &device);
  void updateList();
  void resetFilters();

private:
  bool _withAuto;
  KeyComboBox<QString> *_programmerCombo, *_toolCombo;
  EnumComboBox<ListType>                 *_listTypeCombo;
  EnumComboBox<Device::MemoryTechnology> *_memoryCombo;
  EnumComboBox<Device::Status>           *_statusCombo;
  EnumComboBox<Pic::Feature>             *_featureCombo;
  KListView   *_listView;
  View        *_deviceView;

  void updateList(const QString &device);
  const Programmer::Group *programmerGroup() const;
  const Tool::Group *toolGroup() const;
};

//-----------------------------------------------------------------------------
class ComboBox : public QComboBox
{
Q_OBJECT
public:
  ComboBox(bool withAuto, QWidget *parent);
  void setDevice(const QString &device, const Device::Data *data = 0);
  QString device() const;
  bool withAuto() const { return _withAuto; }

private:
  bool _withAuto;
};

//-----------------------------------------------------------------------------
class Button : public QWidget
{
Q_OBJECT
public:
  Button(bool withAuto, QWidget *parent);
  void setDevice(const QString &device) { _combo->setDevice(device); }
  QString device() const { return _combo->device(); }

signals:
  void changed();

private slots:
  void chooseDevice();

private:
  ComboBox *_combo;
};

//-----------------------------------------------------------------------------
class Browser : public KTextBrowser
{
Q_OBJECT
public:
  Browser(QWidget *parent);

signals:
  void deviceChanged(const QString &device);

public slots:
  virtual void setSource(const QString &name);
};

//-----------------------------------------------------------------------------
class View : public TabWidget
{
Q_OBJECT
public:
  View(QWidget *parent);
  void clear();
  void setText(const QString &text);
  void setDevice(const QString &name, bool cannotChangeDevice);

signals:
  void deviceChanged(const QString &device);

private:
  QMimeSourceFactory _msf;
  Browser *_info, *_memory, *_vfg, *_pins;
};

//-----------------------------------------------------------------------------
class Editor : public DeviceEditor
{
Q_OBJECT
public:
  Editor(const QString &title, const QString &tag, QWidget *parent);
  virtual bool isModified() const { return false; }
  virtual bool isReadOnly() const { return true; }
  virtual void addGui() {}
  virtual void removeGui() {}
  virtual void setFocus() {}

signals:
  void deviceChanged(const QString &device);

private:
  virtual QWidget *createView(const Device::Data *data, QWidget *parent);
  virtual void setModifiedInternal(bool) {}
  virtual void setReadOnlyInternal(bool) {}
};

} // namespace

#endif