1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 #include "csvdia.h"
8 
9 #include "scribusapi.h"
10 
11 #include <QVBoxLayout>
12 #include <QHBoxLayout>
13 #include <QBoxLayout>
14 #include <QComboBox>
15 #include <QCheckBox>
16 #include <QPushButton>
17 #include <QLabel>
18 #include <QPixmap>
19 #include <QString>
20 #include <QStringList>
21 
22 #include "iconmanager.h"
23 
CsvDialog()24 CsvDialog::CsvDialog() : QDialog(nullptr)
25 {
26 	setModal(true);
27 	setWindowTitle( tr("CSV Importer Options"));
28 	setWindowIcon(QIcon(IconManager::instance().loadIcon("AppIcon.png")));
29 
30 	QBoxLayout* layout = new QVBoxLayout(this);
31 	layout->setContentsMargins(9, 9, 9, 9);
32 	layout->setSpacing(6);
33 
34 	QBoxLayout* flayout = new QHBoxLayout;
35 	flayout->setContentsMargins(0, 0, 0, 0);
36 	flayout->setSpacing(6);
37 	QLabel* fdlabel = new QLabel( tr("Field delimiter:"), this);
38 	fdlabel->setMinimumWidth(120);
39 	flayout->addWidget(fdlabel,1);
40 	fdelimCombo = new QComboBox(this);
41 	fdelimCombo->setEditable(false);
42 	QStringList fdList(",");
43 	fdList << ";";
44 	fdList << tr("(TAB)");
45 	fdelimCombo->addItems(fdList);
46 	fdelimCombo->setMinimumWidth(120);
47 	flayout->addWidget(fdelimCombo,5);
48 	layout->addLayout(flayout);
49 
50 	QBoxLayout* vlayout = new QHBoxLayout;
51 	vlayout->setContentsMargins(0, 0, 0, 0);
52 	vlayout->setSpacing(6);
53 	QLabel* vdlabel = new QLabel( tr("Value delimiter:"), this);
54 	vdlabel->setMinimumWidth(120);
55 	vlayout->addWidget(vdlabel,1);
56 	vdelimCombo = new QComboBox(this);
57 	vdelimCombo->setEditable(false);
58 	QStringList vdList("\"");
59 	vdList << "'" << tr("None", "delimiter");
60 	vdelimCombo->addItems(vdList);
61 	vdelimCombo->setMinimumWidth(120);
62 	vlayout->addWidget(vdelimCombo,5);
63 	layout->addLayout(vlayout);
64 
65 	QBoxLayout* hlayout = new QHBoxLayout;
66 	hlayout->setContentsMargins(0, 0, 0, 0);
67 	hlayout->setSpacing(6);
68 	headerCheck = new QCheckBox( tr("First row is a header"), this);
69 	hlayout->addWidget(headerCheck);
70 	layout->addLayout(hlayout);
71 
72 	QBoxLayout* blayout = new QHBoxLayout;
73 	blayout->setContentsMargins(0, 0, 0, 0);
74 	blayout->setSpacing(6);
75 	blayout->addStretch(10);
76 	okButton = new QPushButton( tr("OK"), this);
77 	blayout->addWidget(okButton);
78 
79 	cancelButton = new QPushButton( tr("Cancel"), this);
80 	blayout->addWidget(cancelButton);
81 	layout->addLayout(blayout);
82 
83 	connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
84 	connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
85 }
86 
getFDelim()87 QString CsvDialog::getFDelim()
88 {
89 	if (fdelimCombo->currentText() == tr("(TAB)"))
90 		return "\t";
91 	return fdelimCombo->currentText();
92 }
93 
getVDelim()94 QString CsvDialog::getVDelim()
95 {
96 	return vdelimCombo->currentText();
97 }
98 
hasHeader()99 bool CsvDialog::hasHeader()
100 {
101 	return headerCheck->isChecked();
102 }
103 
useVDelim()104 bool CsvDialog::useVDelim()
105 {
106 	return vdelimCombo->currentIndex() != 2;
107 }
108 
~CsvDialog()109 CsvDialog::~CsvDialog()
110 {
111 
112 }
113