summaryrefslogtreecommitdiffstats
path: root/src/libgui/hex_editor.h
blob: 86b7f2c2b35ceb50ff48fbec38559addb3e2bfc5 (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
/***************************************************************************
 *   Copyright (C) 2005-2007 Nicolas Hadacek <hadacek@kde.org>             *
 *   Copyright (C) 2003 Alain Gibaud <alain.gibaud@free.fr>                *
 *                                                                         *
 *   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 HEX_EDITOR_H
#define HEX_EDITOR_H

#include <kparts/part.h>

#include "device_editor.h"
#include "devices/base/hex_buffer.h"
#include "devices/base/generic_memory.h"

//-----------------------------------------------------------------------------
class HexEditor;

class HexEditorPart : public KParts::ReadWritePart
{
Q_OBJECT
public:
  HexEditorPart(HexEditor *editor);
  virtual void setReadWrite(bool readWrite);

private:
  virtual bool openFile() { return true; }
  virtual bool saveFile() { return true; }
};

//-----------------------------------------------------------------------------
class HexEditor : public DeviceEditor
{
Q_OBJECT
public:
  HexEditor(const QString &name, QWidget *parent);
  HexEditor(QWidget *parent);
  virtual bool isModified() const { return _modified; }
  virtual bool isReadOnly() const { return !_part->isReadWrite(); }
  virtual ~HexEditor() { clear(); }
  virtual PURL::FileType fileType() const { return PURL::Hex; }
  virtual PURL::Url url() const { return _url; }
  virtual bool save(const PURL::Url &url);
  virtual bool open(const PURL::Url &url);
  Device::Memory *memory() { return _memory; }
  const Device::Memory *memory() const { return _memory; }
  const Device::Memory *originalMemory() const { return _originalMemory; }
  void memoryRead();
  virtual void addGui();
  virtual void removeGui();
  virtual void setFocus() {}
  virtual QValueList<uint> bookmarkLines() const { return QValueList<uint>(); }
  virtual void setBookmarkLines(const QValueList<uint> &) {}

public slots:
  virtual void statusChanged();

private slots:
  void slotModified();
  bool simpleLoad();

private:
  Device::Memory *_originalMemory, *_memory;
  HexBuffer       _hexBuffer;
  bool            _modified, _dirty;
  HexEditorPart  *_part;
  PURL::Url       _url;

  virtual void dropEvent(QDropEvent *e) { emit dropEventPass(e); }
  bool save(const PURL::Url &url, const QString &fileErrorString);
  bool verifyDeviceType();
  virtual QWidget *createView(const Device::Data *data, QWidget *parent);
  virtual void setModifiedInternal(bool modified) { _modified = modified; }
  virtual void setReadOnlyInternal(bool readOnly);
  void display();
  void init();
  void clear();
};

#endif