1
0
Fork 0
forked from len0rd/rockbox

Replace mountpoint selection with combo box.

Instead of entering the mountpoint via a tree browser or manually use a combo
box that lists all available drives / mountpoints. This also allows to easily
add more information like the free and total size for each mountpoint. For
development this can still be overriden by editing the dropdown value manually.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30140 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dominik Riebeling 2011-07-15 19:14:26 +00:00
parent 21a38713a6
commit 241f28eefc
3 changed files with 114 additions and 64 deletions

View file

@ -23,7 +23,6 @@
#include "configure.h"
#include "autodetection.h"
#include "ui_configurefrm.h"
#include "browsedirtree.h"
#include "encoders.h"
#include "ttsbase.h"
#include "system.h"
@ -88,7 +87,7 @@ Config::Config(QWidget *parent,int index) : QDialog(parent)
connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(abort()));
connect(ui.radioNoProxy, SIGNAL(toggled(bool)), this, SLOT(setNoProxy(bool)));
connect(ui.radioSystemProxy, SIGNAL(toggled(bool)), this, SLOT(setSystemProxy(bool)));
connect(ui.browseMountPoint, SIGNAL(clicked()), this, SLOT(browseFolder()));
connect(ui.refreshMountPoint, SIGNAL(clicked()), this, SLOT(refreshMountpoint()));
connect(ui.buttonAutodetect,SIGNAL(clicked()),this,SLOT(autodetect()));
connect(ui.buttonCacheBrowse, SIGNAL(clicked()), this, SLOT(browseCache()));
connect(ui.buttonCacheClear, SIGNAL(clicked()), this, SLOT(cacheClear()));
@ -98,6 +97,8 @@ Config::Config(QWidget *parent,int index) : QDialog(parent)
connect(ui.treeDevices, SIGNAL(itemSelectionChanged()), this, SLOT(updateEncState()));
connect(ui.testTTS,SIGNAL(clicked()),this,SLOT(testTts()));
connect(ui.showDisabled, SIGNAL(toggled(bool)), this, SLOT(showDisabled(bool)));
connect(ui.mountPoint, SIGNAL(editTextChanged(QString)), this, SLOT(updateMountpoint(QString)));
connect(ui.mountPoint, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMountpoint(int)));
// delete this dialog after it finished automatically.
connect(this, SIGNAL(finished(int)), this, SLOT(deleteLater()));
@ -149,25 +150,25 @@ void Config::accept()
RbSettings::setValue(RbSettings::Language, language);
// mountpoint
QString mp = ui.mountPoint->text();
if(mp.isEmpty()) {
if(mountpoint.isEmpty()) {
errormsg += "<li>" + tr("No mountpoint given") + "</li>";
error = true;
}
else if(!QFileInfo(mp).exists()) {
else if(!QFileInfo(mountpoint).exists()) {
errormsg += "<li>" + tr("Mountpoint does not exist") + "</li>";
error = true;
}
else if(!QFileInfo(mp).isDir()) {
else if(!QFileInfo(mountpoint).isDir()) {
errormsg += "<li>" + tr("Mountpoint is not a directory.") + "</li>";
error = true;
}
else if(!QFileInfo(mp).isWritable()) {
else if(!QFileInfo(mountpoint).isWritable()) {
errormsg += "<li>" + tr("Mountpoint is not writeable") + "</li>";
error = true;
}
else {
RbSettings::setValue(RbSettings::Mountpoint, QDir::fromNativeSeparators(mp));
RbSettings::setValue(RbSettings::Mountpoint,
QDir::fromNativeSeparators(mountpoint));
}
// platform
@ -269,7 +270,9 @@ void Config::setUserSettings()
connect(ui.listLanguages, SIGNAL(itemSelectionChanged()), this, SLOT(updateLanguage()));
// devices tab
ui.mountPoint->setText(QDir::toNativeSeparators(RbSettings::value(RbSettings::Mountpoint).toString()));
refreshMountpoint();
mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
setMountpoint(mountpoint);
// cache tab
if(!QFileInfo(RbSettings::value(RbSettings::CachePath).toString()).isDir())
@ -556,28 +559,6 @@ void Config::updateLanguage()
}
void Config::browseFolder()
{
browser = new BrowseDirtree(this,tr("Select your device"));
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
browser->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
#elif defined(Q_OS_WIN32)
browser->setFilter(QDir::Drives);
#endif
#if defined(Q_OS_MACX)
browser->setRoot("/Volumes");
#elif defined(Q_OS_LINUX)
browser->setDir("/media");
#endif
if( ui.mountPoint->text() != "" )
{
browser->setDir(ui.mountPoint->text());
}
browser->show();
connect(browser, SIGNAL(itemChanged(QString)), this, SLOT(setMountpoint(QString)));
}
void Config::browseCache()
{
QString old = ui.cachePath->text();
@ -593,9 +574,70 @@ void Config::browseCache()
}
void Config::refreshMountpoint()
{
// avoid QComboBox to send signals during rebuild to avoid changing to an
// unwanted item.
ui.mountPoint->blockSignals(true);
ui.mountPoint->clear();
QStringList mps = Autodetection::mountpoints();
for(int i = 0; i < mps.size(); ++i) {
// add mountpoint as user data so we can change the displayed string
// later (to include volume label or similar)
// Skip unwritable mountpoints, they are not useable for us.
if(QFileInfo(mps.at(i)).isWritable()) {
QString title = QString("%1 (%2 GiB of %3 GiB free)")
.arg(QDir::toNativeSeparators(mps.at(i)))
.arg((double)Utils::filesystemFree(mps.at(i))/(1<<30), 0, 'f', 2)
.arg((double)Utils::filesystemTotal(mps.at(i))/(1<<30), 0, 'f', 2);
ui.mountPoint->addItem(title, mps.at(i));
}
}
if(!mountpoint.isEmpty()) {
setMountpoint(mountpoint);
}
ui.mountPoint->blockSignals(false);
}
void Config::updateMountpoint(QString m)
{
if(!m.isEmpty()) {
mountpoint = m;
qDebug() << "[Config] Mountpoint set to" << mountpoint;
}
}
void Config::updateMountpoint(int idx)
{
if(idx == -1) {
return;
}
QString mp = ui.mountPoint->itemData(idx).toString();
if(!mp.isEmpty()) {
mountpoint = mp;
qDebug() << "[Config] Mountpoint set to" << mountpoint;
}
}
void Config::setMountpoint(QString m)
{
ui.mountPoint->setText(m);
if(m.isEmpty()) {
return;
}
int index = ui.mountPoint->findData(m);
if(index != -1) {
ui.mountPoint->setCurrentIndex(index);
}
else {
// keep a mountpoint that is not in the list for convenience (to allow
// easier development)
ui.mountPoint->addItem(m);
ui.mountPoint->setCurrentIndex(ui.mountPoint->findText(m));
}
qDebug() << "[Config] Mountpoint set to" << mountpoint;
}
@ -682,7 +724,7 @@ void Config::autodetect()
if(detector.getMountPoint() != "" )
{
ui.mountPoint->setText(QDir::toNativeSeparators(detector.getMountPoint()));
setMountpoint(detector.getMountPoint());
}
else
{

View file

@ -23,7 +23,6 @@
#define CONFIGURE_H
#include "ui_configurefrm.h"
#include "browsedirtree.h"
#include <QtGui>
class Config : public QDialog
@ -51,19 +50,19 @@ class Config : public QDialog
QString language;
QString programPath;
QUrl proxy;
QString mountpoint;
void updateCacheInfo(QString);
BrowseDirtree *browser;
BrowseDirtree *cbrowser;
private slots:
void setNoProxy(bool);
void setSystemProxy(bool);
void updateLanguage(void);
void browseFolder(void);
void refreshMountpoint(void);
void browseCache(void);
void autodetect(void);
void setMountpoint(QString);
void updateMountpoint(QString);
void updateMountpoint(int);
void cacheClear(void);
void configTts(void);
void configEnc(void);

View file

@ -13,8 +13,8 @@
<property name="windowTitle">
<string>Configuration</string>
</property>
<layout class="QGridLayout">
<item row="0" column="0" colspan="3">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="labelTitle">
<property name="text">
<string>Configure Rockbox Utility</string>
@ -34,7 +34,7 @@
<attribute name="title">
<string>&amp;Device</string>
</attribute>
<layout class="QGridLayout">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="labelMountPoint">
<property name="text">
@ -46,25 +46,25 @@
</widget>
</item>
<item row="1" column="0" colspan="3">
<layout class="QHBoxLayout">
<item>
<widget class="QLineEdit" name="mountPoint"/>
</item>
<item>
<widget class="QPushButton" name="browseMountPoint">
<property name="text">
<string>&amp;Browse</string>
</property>
<property name="icon">
<iconset resource="rbutilqt.qrc">
<normaloff>:/icons/system-search.png</normaloff>:/icons/system-search.png</iconset>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
<widget class="QComboBox" name="mountPoint">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="refreshMountPoint">
<property name="text">
<string>&amp;Refresh</string>
</property>
<property name="icon">
<iconset resource="rbutilqt.qrc">
<normaloff>:/icons/view-refresh.png</normaloff>:/icons/view-refresh.png</iconset>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelPlayer">
@ -89,17 +89,26 @@
</property>
</spacer>
</item>
<item row="2" column="2">
<item row="2" column="2" colspan="2">
<widget class="QCheckBox" name="showDisabled">
<property name="text">
<string>Show disabled targets</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QTreeWidget" name="treeDevices"/>
<item row="3" column="0" colspan="4">
<widget class="QTreeWidget" name="treeDevices">
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
<item row="4" column="0" colspan="3">
<item row="4" column="0" colspan="4">
<widget class="QPushButton" name="buttonAutodetect">
<property name="text">
<string>&amp;Autodetect</string>