~neon/kompare/master

« back to all changes in this revision

Viewing changes to libdialogpages/filespage.cpp

  • Committer: Friedrich W. H. Kossebau
  • Date: 2020-11-13 21:43:33 UTC
  • Revision ID: git-v1:79fce0df862602a8e2790d7d14f4037744a006f6
Reorganize sources into src/ subfolder

NO_CHANGELOG

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
                                filespage.cpp
3
 
                                -------------
4
 
        begin                   : Sun Apr 18 2004
5
 
        Copyright 2004      Otto Bruggeman <otto.bruggeman@home.nl>
6
 
        Copyright 2007-2011 Kevin Kofler   <kevin.kofler@chello.at>
7
 
****************************************************************************/
8
 
 
9
 
/***************************************************************************
10
 
**
11
 
**   This program is free software; you can redistribute it and/or modify
12
 
**   it under the terms of the GNU General Public License as published by
13
 
**   the Free Software Foundation; either version 2 of the License, or
14
 
**   (at your option) any later version.
15
 
**
16
 
***************************************************************************/
17
 
 
18
 
#include "filespage.h"
19
 
 
20
 
#include <QLayout>
21
 
#include <QGroupBox>
22
 
#include <QVBoxLayout>
23
 
#include <QHBoxLayout>
24
 
 
25
 
#include <KCharsets>
26
 
#include <KConfig>
27
 
#include <KLocalizedString>
28
 
#include <KUrlComboBox>
29
 
#include <KUrlRequester>
30
 
 
31
 
#include "filessettings.h"
32
 
 
33
 
FilesPage::FilesPage() : QFrame()
34
 
{
35
 
    QVBoxLayout* layout = new QVBoxLayout(this);
36
 
 
37
 
    m_firstGB = new QGroupBox(QStringLiteral("You have to set this moron :)"), this);  // whut?
38
 
    layout->addWidget(m_firstGB);
39
 
    QHBoxLayout* gb1Layout = new QHBoxLayout(m_firstGB);
40
 
    m_firstURLComboBox = new KUrlComboBox(KUrlComboBox::Both, true, m_firstGB);
41
 
    m_firstURLComboBox->setMaxItems(10);
42
 
    m_firstURLComboBox->setObjectName(QStringLiteral("SourceURLComboBox"));
43
 
    m_firstURLRequester = new KUrlRequester(m_firstURLComboBox, nullptr);
44
 
    gb1Layout->addWidget(m_firstURLComboBox);
45
 
    m_firstURLComboBox->setFocus();
46
 
 
47
 
    QPushButton* button = new QPushButton(this);
48
 
    button->setIcon(QIcon::fromTheme(QStringLiteral("document-open")));
49
 
    button->setToolTip(i18nc("@info:tooltip", "Select file"));
50
 
    button->setProperty("combobox", QStringLiteral("SourceURLComboBox"));
51
 
    button->setProperty("folder", false);
52
 
    connect(button, &QPushButton::clicked, this, &FilesPage::open);
53
 
    gb1Layout->addWidget(button);
54
 
 
55
 
    button = new QPushButton(this);
56
 
    button->setIcon(QIcon::fromTheme(QStringLiteral("folder-open")));
57
 
    QSizePolicy sp = button->sizePolicy();
58
 
    sp.setRetainSizeWhenHidden(true);
59
 
    button->setSizePolicy(sp);
60
 
    button->setObjectName(QStringLiteral("firstURLOpenFolder"));
61
 
    button->setToolTip(i18nc("@info:tooltip", "Select folder"));
62
 
    button->setProperty("combobox", QStringLiteral("SourceURLComboBox"));
63
 
    button->setProperty("folder", true);
64
 
    connect(button, &QPushButton::clicked, this, &FilesPage::open);
65
 
    gb1Layout->addWidget(button);
66
 
 
67
 
    m_secondGB = new QGroupBox(QStringLiteral("This too moron !"), this);  // whut again?
68
 
    layout->addWidget(m_secondGB);
69
 
    QHBoxLayout* gb2Layout = new QHBoxLayout(m_secondGB);
70
 
    m_secondURLComboBox = new KUrlComboBox(KUrlComboBox::Both, true, m_secondGB);
71
 
    m_secondURLComboBox->setMaxItems(10);
72
 
    m_secondURLComboBox->setObjectName(QStringLiteral("DestURLComboBox"));
73
 
    m_secondURLRequester = new KUrlRequester(m_secondURLComboBox, nullptr);
74
 
    gb2Layout->addWidget(m_secondURLComboBox);
75
 
 
76
 
    button = new QPushButton(this);
77
 
    button->setIcon(QIcon::fromTheme(QStringLiteral("document-open")));
78
 
    button->setToolTip(i18nc("@info:tooltip", "Select file"));
79
 
    button->setProperty("combobox", QStringLiteral("DestURLComboBox"));
80
 
    button->setProperty("folder", false);
81
 
    connect(button, &QPushButton::clicked, this, &FilesPage::open);
82
 
    gb2Layout->addWidget(button);
83
 
 
84
 
    button = new QPushButton(this);
85
 
    button->setIcon(QIcon::fromTheme(QStringLiteral("folder-open")));
86
 
    button->setObjectName(QStringLiteral("secondURLOpenFolder"));
87
 
    sp = button->sizePolicy();
88
 
    sp.setRetainSizeWhenHidden(true);
89
 
    button->setSizePolicy(sp);
90
 
    button->setToolTip(i18nc("@info:tooltip", "Select folder"));
91
 
    button->setProperty("combobox", QStringLiteral("DestURLComboBox"));
92
 
    button->setProperty("folder", true);
93
 
    connect(button, &QPushButton::clicked, this, &FilesPage::open);
94
 
    gb2Layout->addWidget(button);
95
 
 
96
 
 
97
 
    m_thirdGB = new QGroupBox(i18nc("@title:group", "Encoding"), this);
98
 
    layout->addWidget(m_thirdGB);
99
 
    QHBoxLayout* gb3Layout = new QHBoxLayout(m_thirdGB);
100
 
    m_encodingComboBox = new KComboBox(false, m_thirdGB);
101
 
    m_encodingComboBox->setObjectName(QStringLiteral("encoding_combobox"));
102
 
    m_encodingComboBox->insertItem(0, i18nc("@item:inlistbox encoding", "Default"));
103
 
    m_encodingComboBox->insertItems(1, KCharsets::charsets()->availableEncodingNames());
104
 
    gb3Layout->addWidget(m_encodingComboBox);
105
 
 
106
 
    layout->addWidget(m_firstGB);
107
 
    layout->addWidget(m_secondGB);
108
 
    layout->addWidget(m_thirdGB);
109
 
 
110
 
    layout->addStretch(1);
111
 
}
112
 
 
113
 
FilesPage::~FilesPage()
114
 
{
115
 
    delete m_firstURLRequester;
116
 
    m_firstURLRequester = nullptr;
117
 
    delete m_secondURLRequester;
118
 
    m_secondURLRequester = nullptr;
119
 
    m_settings = nullptr;
120
 
}
121
 
 
122
 
void FilesPage::open()
123
 
{
124
 
    QPushButton* button = (QPushButton*) sender();
125
 
    bool selectFolders = button->property("folder").toBool();
126
 
    KUrlComboBox* urlComboBox = findChild<KUrlComboBox*>(button->property("combobox").toString());
127
 
 
128
 
    doOpen(urlComboBox, selectFolders);
129
 
}
130
 
 
131
 
void FilesPage::doOpen(KUrlComboBox* urlComboBox, bool selectFolders)
132
 
{
133
 
    QUrl currentUrl = QUrl::fromUserInput(urlComboBox->currentText());
134
 
 
135
 
    QUrl newUrl = selectFolders ? QFileDialog::getExistingDirectoryUrl(this,
136
 
                                                                       i18nc("@title:window", "Select Folder"),
137
 
                                                                       currentUrl,
138
 
                                                                       QFileDialog::ReadOnly)
139
 
                                : QFileDialog::getOpenFileUrl(this,
140
 
                                                              i18nc("@title:window", "Select File"),
141
 
                                                              currentUrl);
142
 
    if (!newUrl.isEmpty())
143
 
    {
144
 
        // remove newUrl if already exists and add it as the first item
145
 
        urlComboBox->setUrl(newUrl);
146
 
        Q_EMIT urlChanged();
147
 
    }
148
 
 
149
 
}
150
 
 
151
 
KUrlRequester* FilesPage::firstURLRequester() const
152
 
{
153
 
    return m_firstURLRequester;
154
 
}
155
 
 
156
 
KUrlRequester* FilesPage::secondURLRequester() const
157
 
{
158
 
    return m_secondURLRequester;
159
 
}
160
 
 
161
 
QString FilesPage::encoding() const
162
 
{
163
 
    return m_encodingComboBox->currentText();
164
 
}
165
 
 
166
 
void FilesPage::setFirstGroupBoxTitle(const QString& title)
167
 
{
168
 
    m_firstGB->setTitle(title);
169
 
}
170
 
 
171
 
void FilesPage::setSecondGroupBoxTitle(const QString& title)
172
 
{
173
 
    m_secondGB->setTitle(title);
174
 
}
175
 
 
176
 
void FilesPage::setURLsInComboBoxes()
177
 
{
178
 
//     qDebug() << "first : " << m_firstURLComboBox->currentText() ;
179
 
//     qDebug() << "second: " << m_secondURLComboBox->currentText() ;
180
 
    m_firstURLComboBox->setUrl(QUrl::fromUserInput(m_firstURLComboBox->currentText(), QDir::currentPath(), QUrl::AssumeLocalFile));
181
 
    m_secondURLComboBox->setUrl(QUrl::fromUserInput(m_secondURLComboBox->currentText(), QDir::currentPath(), QUrl::AssumeLocalFile));
182
 
}
183
 
 
184
 
 
185
 
void FilesPage::setFirstURLRequesterMode(unsigned int mode)
186
 
{
187
 
    m_firstURLRequester->setMode((KFile::Mode) mode);
188
 
    if ((mode & KFile::Directory) == 0)
189
 
    {
190
 
        QPushButton* button = findChild<QPushButton*>(QStringLiteral("firstURLOpenFolder"));
191
 
        button->setVisible(false);
192
 
    }
193
 
}
194
 
 
195
 
void FilesPage::setSecondURLRequesterMode(unsigned int mode)
196
 
{
197
 
    m_secondURLRequester->setMode((KFile::Mode) mode);
198
 
    if ((mode & KFile::Directory) == 0)
199
 
    {
200
 
        QPushButton* button = findChild<QPushButton*>(QStringLiteral("secondURLOpenFolder"));
201
 
        button->setVisible(false);
202
 
    }
203
 
}
204
 
 
205
 
void FilesPage::setSettings(FilesSettings* settings)
206
 
{
207
 
    m_settings = settings;
208
 
 
209
 
    m_firstURLComboBox->setUrls(m_settings->m_recentSources);
210
 
    m_firstURLComboBox->setUrl(QUrl::fromUserInput(m_settings->m_lastChosenSourceURL, QDir::currentPath(), QUrl::AssumeLocalFile));
211
 
    m_secondURLComboBox->setUrls(m_settings->m_recentDestinations);
212
 
    m_secondURLComboBox->setUrl(QUrl::fromUserInput(m_settings->m_lastChosenDestinationURL, QDir::currentPath(), QUrl::AssumeLocalFile));
213
 
    m_encodingComboBox->setCurrentIndex(m_encodingComboBox->findText(m_settings->m_encoding, Qt::MatchFixedString));
214
 
}
215
 
 
216
 
void FilesPage::restore()
217
 
{
218
 
    // this shouldn't do a thing...
219
 
}
220
 
 
221
 
void FilesPage::apply()
222
 
{
223
 
    // set the current items as the first ones
224
 
    m_firstURLComboBox->insertUrl(0, QUrl(m_firstURLComboBox->currentText()));
225
 
    m_secondURLComboBox->insertUrl(0, QUrl(m_secondURLComboBox->currentText()));
226
 
 
227
 
    m_settings->m_recentSources            = m_firstURLComboBox->urls();
228
 
    m_settings->m_lastChosenSourceURL      = m_firstURLComboBox->currentText();
229
 
    m_settings->m_recentDestinations       = m_secondURLComboBox->urls();
230
 
    m_settings->m_lastChosenDestinationURL = m_secondURLComboBox->currentText();
231
 
    m_settings->m_encoding                 = m_encodingComboBox->currentText();
232
 
}
233
 
 
234
 
void FilesPage::setDefaults()
235
 
{
236
 
    m_firstURLComboBox->setUrls(QStringList());
237
 
    m_firstURLComboBox->setUrl(QUrl());
238
 
    m_secondURLComboBox->setUrls(QStringList());
239
 
    m_secondURLComboBox->setUrl(QUrl());
240
 
    m_encodingComboBox->setCurrentIndex(0);   // "Default"
241
 
}