1
/***************************************************************************
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
****************************************************************************/
9
/***************************************************************************
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.
16
***************************************************************************/
18
#include "filespage.h"
22
#include <QVBoxLayout>
23
#include <QHBoxLayout>
27
#include <KLocalizedString>
28
#include <KUrlComboBox>
29
#include <KUrlRequester>
31
#include "filessettings.h"
33
FilesPage::FilesPage() : QFrame()
35
QVBoxLayout* layout = new QVBoxLayout(this);
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();
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);
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);
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);
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);
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);
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);
106
layout->addWidget(m_firstGB);
107
layout->addWidget(m_secondGB);
108
layout->addWidget(m_thirdGB);
110
layout->addStretch(1);
113
FilesPage::~FilesPage()
115
delete m_firstURLRequester;
116
m_firstURLRequester = nullptr;
117
delete m_secondURLRequester;
118
m_secondURLRequester = nullptr;
119
m_settings = nullptr;
122
void FilesPage::open()
124
QPushButton* button = (QPushButton*) sender();
125
bool selectFolders = button->property("folder").toBool();
126
KUrlComboBox* urlComboBox = findChild<KUrlComboBox*>(button->property("combobox").toString());
128
doOpen(urlComboBox, selectFolders);
131
void FilesPage::doOpen(KUrlComboBox* urlComboBox, bool selectFolders)
133
QUrl currentUrl = QUrl::fromUserInput(urlComboBox->currentText());
135
QUrl newUrl = selectFolders ? QFileDialog::getExistingDirectoryUrl(this,
136
i18nc("@title:window", "Select Folder"),
138
QFileDialog::ReadOnly)
139
: QFileDialog::getOpenFileUrl(this,
140
i18nc("@title:window", "Select File"),
142
if (!newUrl.isEmpty())
144
// remove newUrl if already exists and add it as the first item
145
urlComboBox->setUrl(newUrl);
151
KUrlRequester* FilesPage::firstURLRequester() const
153
return m_firstURLRequester;
156
KUrlRequester* FilesPage::secondURLRequester() const
158
return m_secondURLRequester;
161
QString FilesPage::encoding() const
163
return m_encodingComboBox->currentText();
166
void FilesPage::setFirstGroupBoxTitle(const QString& title)
168
m_firstGB->setTitle(title);
171
void FilesPage::setSecondGroupBoxTitle(const QString& title)
173
m_secondGB->setTitle(title);
176
void FilesPage::setURLsInComboBoxes()
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));
185
void FilesPage::setFirstURLRequesterMode(unsigned int mode)
187
m_firstURLRequester->setMode((KFile::Mode) mode);
188
if ((mode & KFile::Directory) == 0)
190
QPushButton* button = findChild<QPushButton*>(QStringLiteral("firstURLOpenFolder"));
191
button->setVisible(false);
195
void FilesPage::setSecondURLRequesterMode(unsigned int mode)
197
m_secondURLRequester->setMode((KFile::Mode) mode);
198
if ((mode & KFile::Directory) == 0)
200
QPushButton* button = findChild<QPushButton*>(QStringLiteral("secondURLOpenFolder"));
201
button->setVisible(false);
205
void FilesPage::setSettings(FilesSettings* settings)
207
m_settings = settings;
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));
216
void FilesPage::restore()
218
// this shouldn't do a thing...
221
void FilesPage::apply()
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()));
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();
234
void FilesPage::setDefaults()
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"