57 #include "FilePicker.hh"
59 #include <QHBoxLayout>
60 #include <QMessageBox>
62 FilePicker::FilePicker(QWidget *parent) :
64 textBox_(new QComboBox),
65 browseButton_(new QPushButton(trUtf8(
"Browse..."))),
66 recent_files_ini_key_(
"GenericFilePickerRecents"),
67 dialog_type_(DT_OPEN_FILE),
68 overwrite_confirmed_by_user_(false) {
73 FilePicker::FilePicker(QString recent_files_ini_key,
74 DialogType dialog_type,
77 textBox_(new QComboBox),
78 browseButton_(new QPushButton(trUtf8(
"Browse..."))),
79 recent_files_ini_key_(recent_files_ini_key),
80 dialog_type_(dialog_type),
81 overwrite_confirmed_by_user_(false) {
86 void FilePicker::init() {
90 textBox_->setSizePolicy(QSizePolicy::MinimumExpanding,
91 textBox_->sizePolicy().verticalPolicy());
92 textBox_->setEditable(
true);
93 textBox_->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
95 QHBoxLayout *layout =
new QHBoxLayout(
this);
96 layout->setContentsMargins(0, 0, 0, 0);
97 layout->addWidget(textBox_);
98 layout->addWidget(browseButton_);
103 textBox_->insertItems(
105 OpenFlipper::Options::getRecentItems(recent_files_ini_key()));
106 connect(browseButton_, SIGNAL( clicked() ),
this, SLOT( slot_browse() ));
108 connect(textBox_, SIGNAL( editTextChanged(
const QString &) ),
109 this, SLOT( path_changed() ));
112 void FilePicker::set_recent_files_ini_key(QString value) {
113 recent_files_ini_key_ = value;
115 textBox_->insertItems(
117 OpenFlipper::Options::getRecentItems(recent_files_ini_key_));
120 void FilePicker::path_changed() {
121 overwrite_confirmed_by_user_ =
false;
124 bool FilePicker::confirm_overwrite_if_necessary() {
125 if (overwrite_confirmed_by_user())
return true;
126 if (dialog_type() != DT_SAVE_FILE)
return true;
127 if (!QFile::exists(currentFileName()))
return true;
129 const QString file_name = QFileInfo(currentFileName()).fileName();
130 const QMessageBox::StandardButton result =
131 QMessageBox::question(
132 this, trUtf8(
"Overwrite File?"),
133 trUtf8(
"The file \"%1\" exists. "
134 "Do you want to overwrite?")
136 QMessageBox::Yes | QMessageBox::No,
139 if (result == QMessageBox::Yes) {
140 overwrite_confirmed_by_user_ =
true;
147 void FilePicker::slot_browse() {
148 OpenFlipper::Options::obtainPathName(
150 dialog_title().toUtf8().constData(),
151 file_filter().toUtf8().constData(),
152 recent_files_ini_key().toUtf8().constData(),
153 static_cast<OpenFlipper::Options::DialogType>(dialog_type()));
155 std::cout <<
"overwrite confirmed." << std::endl;
156 overwrite_confirmed_by_user_ =
true;
159 FilePicker::~FilePicker() {