42 #include "FilePicker.hh" 44 #include <QHBoxLayout> 45 #include <QMessageBox> 47 FilePicker::FilePicker(QWidget *parent) :
49 textBox_(new QComboBox),
50 browseButton_(new QPushButton(trUtf8(
"Browse..."))),
51 recent_files_ini_key_(
"GenericFilePickerRecents"),
52 dialog_type_(DT_OPEN_FILE),
53 overwrite_confirmed_by_user_(false) {
58 FilePicker::FilePicker(QString recent_files_ini_key,
59 DialogType dialog_type,
62 textBox_(new QComboBox),
63 browseButton_(new QPushButton(trUtf8(
"Browse..."))),
64 recent_files_ini_key_(recent_files_ini_key),
65 dialog_type_(dialog_type),
66 overwrite_confirmed_by_user_(false) {
71 void FilePicker::init() {
75 textBox_->setSizePolicy(QSizePolicy::MinimumExpanding,
76 textBox_->sizePolicy().verticalPolicy());
77 textBox_->setEditable(
true);
78 textBox_->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
80 QHBoxLayout *layout =
new QHBoxLayout(
this);
81 layout->setContentsMargins(0, 0, 0, 0);
82 layout->addWidget(textBox_);
83 layout->addWidget(browseButton_);
88 textBox_->insertItems(
90 OpenFlipper::Options::getRecentItems(recent_files_ini_key()));
91 connect(browseButton_, SIGNAL( clicked() ),
this, SLOT( slot_browse() ));
93 connect(textBox_, SIGNAL( editTextChanged(
const QString &) ),
94 this, SLOT( path_changed() ));
97 void FilePicker::set_recent_files_ini_key(QString value) {
98 recent_files_ini_key_ = value;
100 textBox_->insertItems(
102 OpenFlipper::Options::getRecentItems(recent_files_ini_key_));
105 void FilePicker::path_changed() {
106 overwrite_confirmed_by_user_ =
false;
109 bool FilePicker::confirm_overwrite_if_necessary() {
110 if (overwrite_confirmed_by_user())
return true;
111 if (dialog_type() != DT_SAVE_FILE)
return true;
112 if (!QFile::exists(currentFileName()))
return true;
114 const QString file_name = QFileInfo(currentFileName()).fileName();
115 const QMessageBox::StandardButton result =
116 QMessageBox::question(
117 this, trUtf8(
"Overwrite File?"),
118 trUtf8(
"The file \"%1\" exists. " 119 "Do you want to overwrite?")
121 QMessageBox::Yes | QMessageBox::No,
124 if (result == QMessageBox::Yes) {
125 overwrite_confirmed_by_user_ =
true;
132 void FilePicker::slot_browse() {
133 OpenFlipper::Options::obtainPathName(
135 dialog_title().toUtf8().constData(),
136 file_filter().toUtf8().constData(),
137 recent_files_ini_key().toUtf8().constData(),
138 static_cast<OpenFlipper::Options::DialogType>(dialog_type()));
140 std::cout <<
"overwrite confirmed." << std::endl;
141 overwrite_confirmed_by_user_ =
true;
144 FilePicker::~FilePicker() {