@@ -0,0 +1,37 | |||
|
1 | #include "filelist.h" | |
|
2 | #include <QMimeData> | |
|
3 | ||
|
4 | FileList::FileList(QWidget *parent) : | |
|
5 | QTableWidget(parent) | |
|
6 | { | |
|
7 | setHorizontalHeaderLabels(QStringList()<<"File"<<"Type"); | |
|
8 | this->setAcceptDrops(true); | |
|
9 | } | |
|
10 | ||
|
11 | void FileList::dragEnterEvent(QDragEnterEvent *event) | |
|
12 | { | |
|
13 | event->acceptProposedAction(); | |
|
14 | } | |
|
15 | ||
|
16 | void FileList::dragMoveEvent(QDragMoveEvent *event) | |
|
17 | { | |
|
18 | event->acceptProposedAction(); | |
|
19 | } | |
|
20 | ||
|
21 | void FileList::dropEvent(QDropEvent *event) | |
|
22 | { | |
|
23 | const QMimeData* mimeData = event->mimeData(); | |
|
24 | ||
|
25 | if (mimeData->hasUrls()) | |
|
26 | { | |
|
27 | QStringList pathList; | |
|
28 | QList<QUrl> urlList = mimeData->urls(); | |
|
29 | ||
|
30 | for (int i = 0; i < urlList.size() && i < 32; ++i) | |
|
31 | { | |
|
32 | pathList.append(urlList.at(i).toLocalFile()); | |
|
33 | } | |
|
34 | emit openFiles(pathList); | |
|
35 | event->acceptProposedAction(); | |
|
36 | } | |
|
37 | } |
@@ -0,0 +1,26 | |||
|
1 | #ifndef FILELIST_H | |
|
2 | #define FILELIST_H | |
|
3 | ||
|
4 | #include <QTableWidget> | |
|
5 | #include <QDropEvent> | |
|
6 | #include <QDragEnterEvent> | |
|
7 | #include <QDragMoveEvent> | |
|
8 | #include <QString> | |
|
9 | #include <QStringList> | |
|
10 | ||
|
11 | class FileList : public QTableWidget | |
|
12 | { | |
|
13 | Q_OBJECT | |
|
14 | public: | |
|
15 | explicit FileList(QWidget *parent = 0); | |
|
16 | void dragEnterEvent(QDragEnterEvent *event); | |
|
17 | void dragMoveEvent(QDragMoveEvent *event); | |
|
18 | void dropEvent(QDropEvent *event); | |
|
19 | ||
|
20 | signals: | |
|
21 | void openFiles(const QStringList& files); | |
|
22 | public slots: | |
|
23 | ||
|
24 | }; | |
|
25 | ||
|
26 | #endif // FILELIST_H |
@@ -1,185 +1,190 | |||
|
1 | 1 | #include "genericbinaryfilewidget.h" |
|
2 | 2 | #include "ui_genericbinaryfilewidget.h" |
|
3 | 3 | #include <QFileDialog> |
|
4 | 4 | #include <QFile> |
|
5 | 5 | #include "srec/srecfile.h" |
|
6 | 6 | #include "srec/srecfilewidget.h" |
|
7 | 7 | #include "BinFile/binaryfile.h" |
|
8 | 8 | #include "BinFile/binaryfilewidget.h" |
|
9 | 9 | #include "elf/elffile.h" |
|
10 | 10 | #include "elf/elffilewidget.h" |
|
11 | 11 | |
|
12 | 12 | |
|
13 | 13 | genericBinaryFileWidget::genericBinaryFileWidget(QWidget *parent) : |
|
14 | 14 | QWidget(parent), |
|
15 | 15 | ui(new Ui::genericBinaryFileWidget) |
|
16 | 16 | { |
|
17 | 17 | ui->setupUi(this); |
|
18 | 18 | connect(this->ui->openFileQpb,SIGNAL(clicked()),this,SLOT(openFile())); |
|
19 | 19 | connect(this->ui->removeFileQpb,SIGNAL(clicked()),this,SLOT(removeFiles())); |
|
20 | 20 | connect(this->ui->fileList,SIGNAL(cellActivated(int,int)),this,SLOT(fileCellActivated(int,int))); |
|
21 | connect(this->ui->fileList,SIGNAL(openFiles(QStringList)),this,SLOT(openFile(QStringList))); | |
|
21 | 22 | } |
|
22 | 23 | |
|
23 | 24 | genericBinaryFileWidget::~genericBinaryFileWidget() |
|
24 | 25 | { |
|
25 | 26 | delete ui; |
|
26 | 27 | } |
|
27 | 28 | |
|
28 | 29 | void genericBinaryFileWidget::openFile() |
|
29 | 30 | { |
|
30 | 31 | QStringList filesNames = QFileDialog::getOpenFileNames( |
|
31 | 32 | this, |
|
32 | 33 | "Select one or more files to open", |
|
33 | 34 | NULL, |
|
34 | 35 | "Binary Files (*.bin);;SREC Files (*.srec);;Elf Files (*)"); |
|
35 | 36 | |
|
36 | for(int i=0;i<filesNames.count();i++) | |
|
37 | openFile(filesNames); | |
|
38 | } | |
|
39 | ||
|
40 | void genericBinaryFileWidget::openFile(const QStringList &FileList) | |
|
41 | { | |
|
42 | for(int i=0;i<FileList.count();i++) | |
|
37 | 43 | { |
|
38 | 44 | bool fileOpened = false; |
|
39 | 45 | for(int l=0;l<files.count();l++) |
|
40 | 46 | { |
|
41 |
if( |
|
|
47 | if(FileList.at(i)==files.at(l)->fileName) | |
|
42 | 48 | { |
|
43 | 49 | fileOpened = true; |
|
44 | 50 | } |
|
45 | 51 | } |
|
46 |
QFile file( |
|
|
52 | QFile file(FileList.at(i)); | |
|
47 | 53 | if(!fileOpened && file.open(QIODevice::ReadOnly)) |
|
48 | 54 | { |
|
49 | 55 | char magic[4]; |
|
50 | 56 | file.read(magic,4); |
|
51 | 57 | QString line; |
|
52 | 58 | switch((int)magic[0]) |
|
53 | 59 | { |
|
54 | 60 | case 0x7F: |
|
55 | 61 | if((magic[1]=='E') && (magic[2]=='L') && (magic[3]=='F')) |
|
56 | 62 | { |
|
57 |
files.append(new FileListElement( |
|
|
63 | files.append(new FileListElement(FileList.at(i),false,Type_Elf,NULL,NULL)); | |
|
58 | 64 | } |
|
59 | 65 | break; |
|
60 | 66 | case 'S': |
|
61 | 67 | file.seek(0); |
|
62 | 68 | line = file.readLine(); |
|
63 | 69 | if(srecFile::checkSum(line)) |
|
64 | 70 | { |
|
65 |
files.append(new FileListElement( |
|
|
71 | files.append(new FileListElement(FileList.at(i),false,Type_SREC,NULL,NULL)); | |
|
66 | 72 | } |
|
67 | 73 | break; |
|
68 | 74 | default: |
|
69 |
files.append(new FileListElement( |
|
|
75 | files.append(new FileListElement(FileList.at(i),false,Type_Bin,NULL,NULL)); | |
|
70 | 76 | break; |
|
71 | 77 | } |
|
72 | 78 | } |
|
73 | 79 | } |
|
74 | 80 | updateFileList(); |
|
75 | ||
|
76 | 81 | } |
|
77 | 82 | |
|
78 | 83 | void genericBinaryFileWidget::updateFileList() |
|
79 | 84 | { |
|
80 | 85 | this->ui->fileList->clear(); |
|
81 | 86 | this->ui->fileList->setRowCount(files.count()); |
|
82 | 87 | this->ui->fileList->setHorizontalHeaderLabels(QStringList()<<"File"<<"Type"); |
|
83 | 88 | for(int i=0;i<files.count();i++) |
|
84 | 89 | { |
|
85 | 90 | QTableWidgetItem *newItem = new QTableWidgetItem(files.at(i)->fileName); |
|
86 | 91 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); |
|
87 | 92 | this->ui->fileList->setItem(i, 0, newItem); |
|
88 | 93 | |
|
89 | 94 | newItem = new QTableWidgetItem(files.at(i)->type()); |
|
90 | 95 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); |
|
91 | 96 | this->ui->fileList->setItem(i, 1, newItem); |
|
92 | 97 | } |
|
93 | 98 | this->ui->fileList->resizeColumnsToContents(); |
|
94 | 99 | } |
|
95 | 100 | |
|
96 | 101 | void genericBinaryFileWidget::removeFiles() |
|
97 | 102 | { |
|
98 | 103 | QList<QTableWidgetItem*> items = this->ui->fileList->selectedItems(); |
|
99 | 104 | for(int i=0;i<items.count();i++) |
|
100 | 105 | { |
|
101 | 106 | QString filename = this->ui->fileList->item(items.at(i)->row(),0)->text(); |
|
102 | 107 | for(int l=0;l<files.count();l++) |
|
103 | 108 | { |
|
104 | 109 | if(files.at(l)->fileName==filename) |
|
105 | 110 | { |
|
106 | 111 | if(files.at(l)->isOpened) |
|
107 | 112 | { |
|
108 | 113 | for(int m=0;m<this->ui->fileViewerTab->count();m++) |
|
109 | 114 | { |
|
110 | 115 | if(this->ui->fileViewerTab->widget(m)==this->files.at(l)->viewer) |
|
111 | 116 | { |
|
112 | 117 | this->ui->fileViewerTab->removeTab(m); |
|
113 | 118 | } |
|
114 | 119 | } |
|
115 | 120 | delete this->files.at(l)->viewer; |
|
116 | 121 | delete this->files.at(l)->parser; |
|
117 | 122 | } |
|
118 | 123 | delete files.at(l); |
|
119 | 124 | files.removeAt(l); |
|
120 | 125 | } |
|
121 | 126 | } |
|
122 | 127 | } |
|
123 | 128 | updateFileList(); |
|
124 | 129 | } |
|
125 | 130 | |
|
126 | 131 | void genericBinaryFileWidget::fileCellActivated(int row, int column) |
|
127 | 132 | { |
|
128 | 133 | Q_UNUSED(column) |
|
129 | 134 | QString fileName = this->ui->fileList->item(row,0)->text(); |
|
130 | 135 | if(fileName!="") |
|
131 | 136 | { |
|
132 | 137 | for(int l=0;l<files.count();l++) |
|
133 | 138 | { |
|
134 | 139 | FileListElement* file = files.at(l); |
|
135 | 140 | if(file->fileName==fileName) |
|
136 | 141 | { |
|
137 | 142 | if(!file->isOpened) |
|
138 | 143 | { |
|
139 | 144 | if(file->parser==NULL) |
|
140 | 145 | { |
|
141 | 146 | switch (file->FileType) |
|
142 | 147 | { |
|
143 | 148 | case Type_Bin: |
|
144 | 149 | file->parser = new binaryFile(file->fileName); |
|
145 | 150 | if(file->viewer==NULL) |
|
146 | 151 | { |
|
147 | 152 | file->viewer = new binaryFileWidget(); |
|
148 | 153 | file->viewer->setFile(file->parser); |
|
149 | 154 | this->ui->fileViewerTab->addTab(file->viewer,file->fileName); |
|
150 | 155 | } |
|
151 | 156 | file->isOpened = true; |
|
152 | 157 | break; |
|
153 | 158 | case Type_Elf: |
|
154 | 159 | file->parser = new ElfFile(file->fileName); |
|
155 | 160 | if(file->viewer==NULL) |
|
156 | 161 | { |
|
157 | 162 | file->viewer = new elfFileWidget(); |
|
158 | 163 | file->viewer->setFile(file->parser); |
|
159 | 164 | this->ui->fileViewerTab->addTab(file->viewer,file->fileName); |
|
160 | 165 | } |
|
161 | 166 | file->isOpened = true; |
|
162 | 167 | break; |
|
163 | 168 | case Type_SREC: |
|
164 | 169 | file->parser = new srecFile(file->fileName); |
|
165 | 170 | if(file->viewer==NULL) |
|
166 | 171 | { |
|
167 | 172 | file->viewer = new srecFileWidget(); |
|
168 | 173 | file->viewer->setFile(file->parser); |
|
169 | 174 | this->ui->fileViewerTab->addTab(file->viewer,file->fileName); |
|
170 | 175 | } |
|
171 | 176 | file->isOpened = true; |
|
172 | 177 | break; |
|
173 | 178 | default: |
|
174 | 179 | break; |
|
175 | 180 | } |
|
176 | 181 | } |
|
177 | 182 | } |
|
178 | 183 | } |
|
179 | 184 | } |
|
180 | 185 | } |
|
181 | 186 | } |
|
182 | 187 | |
|
183 | 188 | |
|
184 | 189 | |
|
185 | 190 |
@@ -1,63 +1,64 | |||
|
1 | 1 | #ifndef GENERICBINARYFILEWIDGET_H |
|
2 | 2 | #define GENERICBINARYFILEWIDGET_H |
|
3 | 3 | |
|
4 | 4 | #include <QWidget> |
|
5 | 5 | #include <QString> |
|
6 | 6 | #include <QStringList> |
|
7 | 7 | #include <abstractbinfile.h> |
|
8 | 8 | |
|
9 | 9 | namespace Ui { |
|
10 | 10 | class genericBinaryFileWidget; |
|
11 | 11 | } |
|
12 | 12 | |
|
13 | 13 | typedef enum {Type_SREC,Type_Bin,Type_Elf}FileTypeEnum; |
|
14 | 14 | class FileListElement |
|
15 | 15 | { |
|
16 | 16 | public: |
|
17 | 17 | FileListElement() {} |
|
18 | 18 | FileListElement(QString fileName,bool isOpened,FileTypeEnum FileType,abstractBinFileWidget* viewer=0,abstractBinFile* parser=0) |
|
19 | 19 | :fileName(fileName),isOpened(isOpened),FileType(FileType),viewer(viewer),parser(parser){} |
|
20 | 20 | QString type() |
|
21 | 21 | { |
|
22 | 22 | switch (this->FileType) { |
|
23 | 23 | case Type_SREC: |
|
24 | 24 | return "Srec"; |
|
25 | 25 | break; |
|
26 | 26 | case Type_Bin: |
|
27 | 27 | return "Binary"; |
|
28 | 28 | break; |
|
29 | 29 | case Type_Elf: |
|
30 | 30 | return "Elf"; |
|
31 | 31 | break; |
|
32 | 32 | default: |
|
33 | 33 | return "Unknow"; |
|
34 | 34 | break; |
|
35 | 35 | } |
|
36 | 36 | } |
|
37 | 37 | QString fileName; |
|
38 | 38 | bool isOpened; |
|
39 | 39 | FileTypeEnum FileType; |
|
40 | 40 | abstractBinFileWidget* viewer; |
|
41 | 41 | abstractBinFile* parser; |
|
42 | 42 | }; |
|
43 | 43 | |
|
44 | 44 | class genericBinaryFileWidget : public QWidget |
|
45 | 45 | { |
|
46 | 46 | Q_OBJECT |
|
47 | 47 | |
|
48 | 48 | public: |
|
49 | 49 | explicit genericBinaryFileWidget(QWidget *parent = 0); |
|
50 | 50 | ~genericBinaryFileWidget(); |
|
51 | 51 | |
|
52 | 52 | public slots: |
|
53 | 53 | void openFile(); |
|
54 | void openFile(const QStringList& FileList); | |
|
54 | 55 | void updateFileList(); |
|
55 | 56 | void removeFiles(); |
|
56 | 57 | void fileCellActivated(int row, int column); |
|
57 | 58 | |
|
58 | 59 | private: |
|
59 | 60 | Ui::genericBinaryFileWidget *ui; |
|
60 | 61 | QList<FileListElement*> files; |
|
61 | 62 | }; |
|
62 | 63 | |
|
63 | 64 | #endif // GENERICBINARYFILEWIDGET_H |
@@ -1,103 +1,119 | |||
|
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
|
2 | 2 | <ui version="4.0"> |
|
3 | 3 | <class>genericBinaryFileWidget</class> |
|
4 | 4 | <widget class="QWidget" name="genericBinaryFileWidget"> |
|
5 | 5 | <property name="geometry"> |
|
6 | 6 | <rect> |
|
7 | 7 | <x>0</x> |
|
8 | 8 | <y>0</y> |
|
9 | 9 | <width>878</width> |
|
10 | 10 | <height>360</height> |
|
11 | 11 | </rect> |
|
12 | 12 | </property> |
|
13 | 13 | <property name="acceptDrops"> |
|
14 | 14 | <bool>false</bool> |
|
15 | 15 | </property> |
|
16 | 16 | <property name="windowTitle"> |
|
17 | 17 | <string>Form</string> |
|
18 | 18 | </property> |
|
19 | 19 | <layout class="QGridLayout" name="gridLayout_2"> |
|
20 | 20 | <item row="0" column="0"> |
|
21 | 21 | <widget class="QSplitter" name="splitter"> |
|
22 | 22 | <property name="orientation"> |
|
23 | 23 | <enum>Qt::Horizontal</enum> |
|
24 | 24 | </property> |
|
25 | 25 | <widget class="QWidget" name="widget" native="true"> |
|
26 | 26 | <layout class="QGridLayout" name="gridLayout"> |
|
27 | 27 | <item row="1" column="0"> |
|
28 | 28 | <widget class="QPushButton" name="openFileQpb"> |
|
29 | 29 | <property name="text"> |
|
30 | 30 | <string/> |
|
31 | 31 | </property> |
|
32 | 32 | <property name="icon"> |
|
33 | 33 | <iconset resource="genericBinaryFiles.qrc"> |
|
34 | 34 | <normaloff>:/img/ressources/Gnome-list-add.svg</normaloff>:/img/ressources/Gnome-list-add.svg</iconset> |
|
35 | 35 | </property> |
|
36 | 36 | <property name="iconSize"> |
|
37 | 37 | <size> |
|
38 |
<width> |
|
|
39 |
<height> |
|
|
38 | <width>24</width> | |
|
39 | <height>24</height> | |
|
40 | 40 | </size> |
|
41 | 41 | </property> |
|
42 | 42 | </widget> |
|
43 | 43 | </item> |
|
44 | 44 | <item row="1" column="1"> |
|
45 | 45 | <widget class="QPushButton" name="removeFileQpb"> |
|
46 | 46 | <property name="text"> |
|
47 | 47 | <string/> |
|
48 | 48 | </property> |
|
49 | 49 | <property name="icon"> |
|
50 | 50 | <iconset resource="genericBinaryFiles.qrc"> |
|
51 | 51 | <normaloff>:/img/ressources/Gnome-user-trash.svg</normaloff>:/img/ressources/Gnome-user-trash.svg</iconset> |
|
52 | 52 | </property> |
|
53 | 53 | <property name="iconSize"> |
|
54 | 54 | <size> |
|
55 |
<width> |
|
|
56 |
<height> |
|
|
55 | <width>24</width> | |
|
56 | <height>24</height> | |
|
57 | 57 | </size> |
|
58 | 58 | </property> |
|
59 | 59 | </widget> |
|
60 | 60 | </item> |
|
61 | 61 | <item row="1" column="2"> |
|
62 | 62 | <spacer name="horizontalSpacer"> |
|
63 | 63 | <property name="orientation"> |
|
64 | 64 | <enum>Qt::Horizontal</enum> |
|
65 | 65 | </property> |
|
66 | 66 | <property name="sizeHint" stdset="0"> |
|
67 | 67 | <size> |
|
68 | 68 | <width>40</width> |
|
69 | 69 | <height>20</height> |
|
70 | 70 | </size> |
|
71 | 71 | </property> |
|
72 | 72 | </spacer> |
|
73 | 73 | </item> |
|
74 | 74 | <item row="0" column="0" colspan="3"> |
|
75 |
<widget class=" |
|
|
75 | <widget class="FileList" name="fileList"> | |
|
76 | <property name="dragEnabled"> | |
|
77 | <bool>false</bool> | |
|
78 | </property> | |
|
76 | 79 | <column> |
|
77 | 80 | <property name="text"> |
|
78 | 81 | <string>File</string> |
|
79 | 82 | </property> |
|
80 | 83 | </column> |
|
81 | 84 | <column> |
|
82 | 85 | <property name="text"> |
|
83 | 86 | <string>Type</string> |
|
84 | 87 | </property> |
|
85 | 88 | </column> |
|
86 | 89 | </widget> |
|
87 | 90 | </item> |
|
88 | 91 | </layout> |
|
89 | 92 | </widget> |
|
90 | 93 | <widget class="QTabWidget" name="fileViewerTab"> |
|
94 | <property name="minimumSize"> | |
|
95 | <size> | |
|
96 | <width>300</width> | |
|
97 | <height>0</height> | |
|
98 | </size> | |
|
99 | </property> | |
|
91 | 100 | <property name="currentIndex"> |
|
92 | 101 | <number>-1</number> |
|
93 | 102 | </property> |
|
94 | 103 | </widget> |
|
95 | 104 | </widget> |
|
96 | 105 | </item> |
|
97 | 106 | </layout> |
|
98 | 107 | </widget> |
|
108 | <customwidgets> | |
|
109 | <customwidget> | |
|
110 | <class>FileList</class> | |
|
111 | <extends>QTableWidget</extends> | |
|
112 | <header>filelist.h</header> | |
|
113 | </customwidget> | |
|
114 | </customwidgets> | |
|
99 | 115 | <resources> |
|
100 | 116 | <include location="genericBinaryFiles.qrc"/> |
|
101 | 117 | </resources> |
|
102 | 118 | <connections/> |
|
103 | 119 | </ui> |
General Comments 0
You need to be logged in to leave comments.
Login now