]> sigrok.org Git - sigrok-qt.git/blob - decodersform.cpp
.gitignore: Add missing entries.
[sigrok-qt.git] / decodersform.cpp
1 /*
2  * This file is part of the sigrok project.
3  *
4  * Copyright (C) 2011 Uwe Hermann <uwe@hermann-uwe.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 extern "C" {
22 #include <sigrokdecode.h>
23 #include <glib.h>
24 }
25
26 #include <QLabel>
27 #include "decodersform.h"
28 #include "ui_decodersform.h"
29
30 DecodersForm::DecodersForm(QWidget *parent) :
31     QDialog(parent),
32     ui(new Ui::DecodersForm)
33 {
34         int i;
35         GSList *ll, *ll2;
36         struct srd_decoder *dec;
37         QWidget *pages[MAX_NUM_DECODERS];
38         char **ann, *doc;
39         QString *s;
40
41         ui->setupUi(this);
42
43         for (ll = srd_decoder_list(), i = 0; ll; ll = ll->next, ++i) {
44                 dec = (struct srd_decoder *)ll->data;
45
46                 /* Add the decoder to the list. */
47                 new QListWidgetItem(QString(dec->name), ui->listWidget);
48
49                 /* Add a page for the decoder details. */
50                 pages[i] = new QWidget;
51
52                 /* Add some decoder data to that page. */
53                 QVBoxLayout *l = new QVBoxLayout;
54                 l->addWidget(new QLabel("ID: " + QString(dec->id)));
55                 l->addWidget(new QLabel("Name: " + QString(dec->name)));
56                 l->addWidget(new QLabel("Long name: " + QString(dec->longname)));
57                 l->addWidget(new QLabel("Description: " + QString(dec->desc)));
58                 l->addWidget(new QLabel("License: " + QString(dec->license)));
59                 s = new QString("Annotations:\n");
60                 for (ll2 = dec->annotations; ll2; ll2 = ll2->next) {
61                         ann = (char **)ll2->data;
62                         s->append(QString(" - %1: %2\n").arg(ann[0]).arg(ann[1]));
63                 }
64                 l->addWidget(new QLabel(*s));
65                 s = new QString("Protocol documentation:\n");
66                 if (doc = srd_decoder_doc_get(dec)) {
67                         s->append(QString("%1\n")
68                                   .arg(doc[0] == '\n' ? doc + 1 : doc));
69                         g_free(doc);
70                 } /* else: Error. */
71                 l->addWidget(new QLabel(*s));
72
73                 l->insertStretch(-1);
74
75                 pages[i]->setLayout(l);
76
77                 /* Add the decoder's page to the stackedWidget. */
78                 ui->stackedWidget->addWidget(pages[i]);
79         }
80 }
81
82 DecodersForm::~DecodersForm()
83 {
84         delete ui;
85 }
86
87 void DecodersForm::changeEvent(QEvent *e)
88 {
89         QDialog::changeEvent(e);
90         switch (e->type()) {
91         case QEvent::LanguageChange:
92                 ui->retranslateUi(this);
93                 break;
94         default:
95                 break;
96         }
97 }
98
99 void DecodersForm::on_closeButton_clicked()
100 {
101         close();
102 }
103
104 void DecodersForm::on_listWidget_currentItemChanged(QListWidgetItem *current,
105                                                     QListWidgetItem *previous)
106 {
107         if (!current)
108                 current = previous;
109
110         ui->stackedWidget->setCurrentIndex(ui->listWidget->row(current));
111 }