~ubuntu-branches/ubuntu/trusty/scribus-ng/trusty

« back to all changes in this revision

Viewing changes to scribus/gtfiledialog.cpp

  • Committer: Package Import Robot
  • Author(s): Oleksandr Moskalenko
  • Date: 2012-02-15 15:57:12 UTC
  • mfrom: (4.2.10 sid)
  • Revision ID: package-import@ubuntu.com-20120215155712-biimoc8o875jht80
Tags: 1.4.0.dfsg+r17300-1
* Prepare a dummy transitional package to converge on the 1.4.0 release.
* debian/NEWS: update the news.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 <QToolTip>
8
 
#include <QTextCodec>
9
 
#include "gtfiledialog.h"
10
 
 
11
 
#include "prefsmanager.h"
12
 
#include "prefscontext.h"
13
 
#include "prefsfile.h"
14
 
 
15
 
gtFileDialog::gtFileDialog(const QString& filters, const QStringList& importers, const QString& wdir)
16
 
        : QDialog()
17
 
{
18
 
        setupUi(this);
19
 
 
20
 
        fileWidget->setDirectory(wdir);
21
 
        fileWidget->setFileMode(QFileDialog::ExistingFile);
22
 
        fileWidget->setFilter(filters);
23
 
 
24
 
        importerCombo->setToolTip( tr("Choose the importer to use"));
25
 
        importerCombo->addItem( tr("Automatic"));
26
 
        importerCombo->addItems(importers);
27
 
 
28
 
        textOnlyCheckBox->setToolTip( tr("Import text without any formatting"));
29
 
 
30
 
        QString tmp_txc[] = {"ISO 8859-1", "ISO 8859-2", "ISO 8859-3", "ISO 8859-4", "ISO 8859-5", "ISO 8859-6",
31
 
                                           "ISO 8859-7", "ISO 8859-8", "ISO 8859-9", "ISO 8859-10", "ISO 8859-13", "ISO 8859-14",
32
 
                                           "ISO 8859-15", "UTF-8", "UTF-16", "KOI8-R", "KOI8-U", "CP1250", "CP1251", "CP1252", "CP1253",
33
 
                                           "CP1254", "CP1255", "CP1256", "CP1257", "Apple Roman"};
34
 
        size_t array = sizeof(tmp_txc) / sizeof(*tmp_txc);
35
 
        for (uint a = 0; a < array; ++a)
36
 
                encodingCombo->addItem(tmp_txc[a]);
37
 
        QString localEn = QTextCodec::codecForLocale()->name();
38
 
        if (localEn == "ISO-10646-UCS-2")
39
 
                localEn = "UTF-16";
40
 
        bool hasIt = false;
41
 
        for (int cc = 0; cc < encodingCombo->count(); ++cc)
42
 
        {
43
 
                if (encodingCombo->itemText(cc) == localEn)
44
 
                {
45
 
                        encodingCombo->setCurrentIndex(cc);
46
 
                        hasIt = true;
47
 
                        break;
48
 
                }
49
 
        }
50
 
        if (!hasIt)
51
 
        {
52
 
                encodingCombo->addItem(localEn);
53
 
                encodingCombo->setCurrentIndex(encodingCombo->count()-1);
54
 
        }
55
 
 
56
 
        loadSettings();
57
 
 
58
 
        connect(fileWidget, SIGNAL(accepted()), this, SLOT(accept()));
59
 
        connect(fileWidget, SIGNAL(rejected()), this, SLOT(reject()));
60
 
}
61
 
 
62
 
QString gtFileDialog::selectedFile()
63
 
{
64
 
        return fileWidget->selectedFile();
65
 
}
66
 
 
67
 
void gtFileDialog::accept()
68
 
{
69
 
        saveSettings();
70
 
        QDialog::accept();
71
 
}
72
 
 
73
 
void gtFileDialog::loadSettings(void)
74
 
{
75
 
        PrefsContext* context = PrefsManager::instance()->prefsFile->getContext("textimport_dialog");
76
 
        if (context->contains("filter"))
77
 
        {
78
 
                QString filter = context->get("filter");
79
 
                QStringList filters = fileWidget->filters();
80
 
                if (!filter.isEmpty() && filters.contains(filter))
81
 
                        fileWidget->selectNameFilter(filter);
82
 
        }
83
 
        if (context->contains("importer"))
84
 
        {
85
 
                QString importer = context->get("importer");
86
 
                int index = importerCombo->findText(importer);
87
 
                if (index >= 0)
88
 
                        importerCombo->setCurrentIndex(index);
89
 
        }
90
 
        if (context->contains("encoding"))
91
 
        {
92
 
                QString encoding = context->get("encoding");
93
 
                int index = encodingCombo->findText(encoding);
94
 
                if (index >= 0)
95
 
                        encodingCombo->setCurrentIndex(index);
96
 
        }
97
 
        if (context->contains("textonly"))
98
 
        {
99
 
                bool textOnly = context->getBool("textonly");
100
 
                textOnlyCheckBox->setChecked(textOnly);
101
 
        }
102
 
}
103
 
 
104
 
void gtFileDialog::saveSettings(void)
105
 
{
106
 
        PrefsContext* context = PrefsManager::instance()->prefsFile->getContext("textimport_dialog");
107
 
        context->set("filter"  , fileWidget->selectedFilter());
108
 
        context->set("importer", importerCombo->currentText());
109
 
        context->set("encoding", encodingCombo->currentText());
110
 
        context->set("textonly", textOnlyCheckBox->isChecked());
111
 
}
112
 
 
113
 
gtFileDialog::~gtFileDialog()
114
 
{
115
 
}