1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Fixed GCS export file selection problem - in windows.

This commit is contained in:
Pip 2011-06-13 16:12:04 +01:00
parent a13c8470d3
commit 7b3241cca9
3 changed files with 123 additions and 171 deletions

View File

@ -37,6 +37,7 @@
#include <QSettings> #include <QSettings>
#include <QMessageBox> #include <QMessageBox>
#include <QFileInfo> #include <QFileInfo>
#include <QFileDialog>
#include <QDesktopServices> #include <QDesktopServices>
#include <QUrl> #include <QUrl>
#include <QDir> #include <QDir>
@ -47,10 +48,8 @@ ImportExportGadgetWidget::ImportExportGadgetWidget(QWidget *parent) :
{ {
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
ui->setupUi(this); ui->setupUi(this);
ui->configFile->setExpectedKind(Utils::PathChooser::File);
ui->configFile->setPromptDialogFilter(tr("XML file (*.xml)"));
ui->configFile->setPromptDialogTitle(tr("Choose configuration file"));
filename = "";
} }
ImportExportGadgetWidget::~ImportExportGadgetWidget() ImportExportGadgetWidget::~ImportExportGadgetWidget()
@ -72,35 +71,21 @@ void ImportExportGadgetWidget::changeEvent(QEvent *e)
void ImportExportGadgetWidget::on_exportButton_clicked() void ImportExportGadgetWidget::on_exportButton_clicked()
{ {
QString file = ui->configFile->path(); QString file = filename;
if (file.isEmpty()) { QString filter = tr("GCS Settings file (*.xml)");
QMessageBox msgBox; file = QFileDialog::getSaveFileName(this, tr("Save GCS Settings too file .."), QFileInfo(file).absoluteFilePath(), filter).trimmed();
msgBox.setText(tr("Empty File name.")); if (file.isEmpty()) {
msgBox.setInformativeText(tr("Please choose an export file name.")); return;
msgBox.setStandardButtons(QMessageBox::Ok); }
msgBox.exec();
return; // Add a "XML" extension to the file in case it does not exist:
} if (!file.toLower().endsWith(".xml"))
// Add a "XML" extension to the file in case it does not exist:
if (!file.endsWith(".xml"))
file.append(".xml"); file.append(".xml");
filename = file;
qDebug() << "Export pressed! Write to file " << QFileInfo(file).absoluteFilePath(); qDebug() << "Export pressed! Write to file " << QFileInfo(file).absoluteFilePath();
if ( QFileInfo(file).exists() ){
QMessageBox msgBox;
msgBox.setText(tr("File already exists."));
msgBox.setInformativeText(tr("Do you want to overwrite the existing file?"));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
if ( msgBox.exec() == QMessageBox::Ok ){
QFileInfo(file).absoluteDir().remove(QFileInfo(file).fileName());
}
else{
qDebug() << "Export canceled!";
return;
}
}
QMessageBox msgBox; QMessageBox msgBox;
QDir dir = QFileInfo(file).absoluteDir(); QDir dir = QFileInfo(file).absoluteDir();
if (! dir.exists()) { if (! dir.exists()) {
@ -163,8 +148,17 @@ void ImportExportGadgetWidget::writeError(const QString& msg) const
void ImportExportGadgetWidget::on_importButton_clicked() void ImportExportGadgetWidget::on_importButton_clicked()
{ {
QString file = ui->configFile->path(); QString file = filename;
QString filter = tr("GCS Settings file (*.xml)");
file = QFileDialog::getOpenFileName(this, tr("Load GCS Settings from file .."), QFileInfo(file).absoluteFilePath(), filter).trimmed();
if (file.isEmpty()) {
return;
}
filename = file;
qDebug() << "Import pressed! Read from file " << QFileInfo(file).absoluteFilePath(); qDebug() << "Import pressed! Read from file " << QFileInfo(file).absoluteFilePath();
QMessageBox msgBox; QMessageBox msgBox;
if (! QFileInfo(file).isReadable()) { if (! QFileInfo(file).isReadable()) {
msgBox.setText(tr("Can't read file ") + QFileInfo(file).absoluteFilePath()); msgBox.setText(tr("Can't read file ") + QFileInfo(file).absoluteFilePath());

View File

@ -41,8 +41,10 @@ private:
void importConfiguration(const QString& fileName); void importConfiguration(const QString& fileName);
QList<Core::IConfigurablePlugin*> getConfigurables(); QList<Core::IConfigurablePlugin*> getConfigurables();
QString filename;
private slots: private slots:
void on_resetButton_clicked(); void on_resetButton_clicked();
void on_helpButton_clicked(); void on_helpButton_clicked();
void on_importButton_clicked(); void on_importButton_clicked();
void on_exportButton_clicked(); void on_exportButton_clicked();

View File

@ -7,162 +7,118 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>483</width> <width>483</width>
<height>271</height> <height>154</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item row="0" column="0" colspan="2"> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QLabel" name="label"> <widget class="QGroupBox" name="groupBoxItems">
<property name="sizePolicy"> <property name="title">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred"> <string>Items</string>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Config File</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="checkBoxGeneral">
<property name="text">
<string>General (Workspace, Key-Bindings)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxAllGadgets">
<property name="text">
<string>All Gadgets</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxPlugins">
<property name="text">
<string>Plugins</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="Utils::PathChooser" name="configFile" native="true"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizePolicy"> <item>
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> <widget class="QPushButton" name="helpButton">
<horstretch>0</horstretch> <property name="maximumSize">
<verstretch>0</verstretch> <size>
</sizepolicy> <width>32</width>
</property> <height>32</height>
</widget> </size>
</item> </property>
</layout> <property name="text">
</item> <string/>
<item row="1" column="0"> </property>
<widget class="QGroupBox" name="groupBoxItems"> <property name="icon">
<property name="title"> <iconset resource="../coreplugin/core.qrc">
<string>Items</string> <normaloff>:/core/images/helpicon.svg</normaloff>:/core/images/helpicon.svg</iconset>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <property name="iconSize">
<item> <size>
<widget class="QCheckBox" name="checkBoxGeneral"> <width>32</width>
<property name="text"> <height>32</height>
<string>General (Workspace, Key-Bindings)</string> </size>
</property> </property>
<property name="checked"> <property name="flat">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="checkBoxAllGadgets"> <widget class="QPushButton" name="exportButton">
<property name="text"> <property name="toolTip">
<string>All Gadgets</string> <string>Export the GCS settings selected in the checkboxes above.</string>
</property> </property>
<property name="checked"> <property name="text">
<bool>true</bool> <string>Export</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="checkBoxPlugins"> <widget class="QPushButton" name="importButton">
<property name="text"> <property name="toolTip">
<string>Plugins</string> <string>Import settings from the config file, only for the items checked above.</string>
</property> </property>
<property name="checked"> <property name="text">
<bool>true</bool> <string>Import</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> <item>
</widget> <widget class="QPushButton" name="resetButton">
</item> <property name="toolTip">
<item row="2" column="0" colspan="2"> <string>Resets your GCS configuration to its default configuration.</string>
<layout class="QHBoxLayout" name="horizontalLayout"> </property>
<item> <property name="text">
<spacer name="horizontalSpacer"> <string>Reset Config</string>
<property name="orientation"> </property>
<enum>Qt::Horizontal</enum> </widget>
</property> </item>
<property name="sizeHint" stdset="0"> </layout>
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="helpButton">
<property name="maximumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../coreplugin/core.qrc">
<normaloff>:/core/images/helpicon.svg</normaloff>:/core/images/helpicon.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="exportButton">
<property name="toolTip">
<string>Export the GCS settings selected in the checkboxes above.</string>
</property>
<property name="text">
<string>Export</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="importButton">
<property name="toolTip">
<string>Import settings from the config file, only for the items checked above.</string>
</property>
<property name="text">
<string>Import</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="resetButton">
<property name="toolTip">
<string>Resets your GCS configuration to its default configuration.</string>
</property>
<property name="text">
<string>Reset Config</string>
</property>
</widget>
</item> </item>
</layout> </layout>
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header>utils/pathchooser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources> <resources>
<include location="../coreplugin/core.qrc"/> <include location="../coreplugin/core.qrc"/>
</resources> </resources>