summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/configure.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/configure.cpp')
-rw-r--r--rbutil/rbutilqt/configure.cpp108
1 files changed, 75 insertions, 33 deletions
diff --git a/rbutil/rbutilqt/configure.cpp b/rbutil/rbutilqt/configure.cpp
index 35654f8711..e48a89f302 100644
--- a/rbutil/rbutilqt/configure.cpp
+++ b/rbutil/rbutilqt/configure.cpp
@@ -23,7 +23,6 @@
23#include "configure.h" 23#include "configure.h"
24#include "autodetection.h" 24#include "autodetection.h"
25#include "ui_configurefrm.h" 25#include "ui_configurefrm.h"
26#include "browsedirtree.h"
27#include "encoders.h" 26#include "encoders.h"
28#include "ttsbase.h" 27#include "ttsbase.h"
29#include "system.h" 28#include "system.h"
@@ -88,7 +87,7 @@ Config::Config(QWidget *parent,int index) : QDialog(parent)
88 connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(abort())); 87 connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(abort()));
89 connect(ui.radioNoProxy, SIGNAL(toggled(bool)), this, SLOT(setNoProxy(bool))); 88 connect(ui.radioNoProxy, SIGNAL(toggled(bool)), this, SLOT(setNoProxy(bool)));
90 connect(ui.radioSystemProxy, SIGNAL(toggled(bool)), this, SLOT(setSystemProxy(bool))); 89 connect(ui.radioSystemProxy, SIGNAL(toggled(bool)), this, SLOT(setSystemProxy(bool)));
91 connect(ui.browseMountPoint, SIGNAL(clicked()), this, SLOT(browseFolder())); 90 connect(ui.refreshMountPoint, SIGNAL(clicked()), this, SLOT(refreshMountpoint()));
92 connect(ui.buttonAutodetect,SIGNAL(clicked()),this,SLOT(autodetect())); 91 connect(ui.buttonAutodetect,SIGNAL(clicked()),this,SLOT(autodetect()));
93 connect(ui.buttonCacheBrowse, SIGNAL(clicked()), this, SLOT(browseCache())); 92 connect(ui.buttonCacheBrowse, SIGNAL(clicked()), this, SLOT(browseCache()));
94 connect(ui.buttonCacheClear, SIGNAL(clicked()), this, SLOT(cacheClear())); 93 connect(ui.buttonCacheClear, SIGNAL(clicked()), this, SLOT(cacheClear()));
@@ -98,6 +97,8 @@ Config::Config(QWidget *parent,int index) : QDialog(parent)
98 connect(ui.treeDevices, SIGNAL(itemSelectionChanged()), this, SLOT(updateEncState())); 97 connect(ui.treeDevices, SIGNAL(itemSelectionChanged()), this, SLOT(updateEncState()));
99 connect(ui.testTTS,SIGNAL(clicked()),this,SLOT(testTts())); 98 connect(ui.testTTS,SIGNAL(clicked()),this,SLOT(testTts()));
100 connect(ui.showDisabled, SIGNAL(toggled(bool)), this, SLOT(showDisabled(bool))); 99 connect(ui.showDisabled, SIGNAL(toggled(bool)), this, SLOT(showDisabled(bool)));
100 connect(ui.mountPoint, SIGNAL(editTextChanged(QString)), this, SLOT(updateMountpoint(QString)));
101 connect(ui.mountPoint, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMountpoint(int)));
101 // delete this dialog after it finished automatically. 102 // delete this dialog after it finished automatically.
102 connect(this, SIGNAL(finished(int)), this, SLOT(deleteLater())); 103 connect(this, SIGNAL(finished(int)), this, SLOT(deleteLater()));
103 104
@@ -149,25 +150,25 @@ void Config::accept()
149 RbSettings::setValue(RbSettings::Language, language); 150 RbSettings::setValue(RbSettings::Language, language);
150 151
151 // mountpoint 152 // mountpoint
152 QString mp = ui.mountPoint->text(); 153 if(mountpoint.isEmpty()) {
153 if(mp.isEmpty()) {
154 errormsg += "<li>" + tr("No mountpoint given") + "</li>"; 154 errormsg += "<li>" + tr("No mountpoint given") + "</li>";
155 error = true; 155 error = true;
156 } 156 }
157 else if(!QFileInfo(mp).exists()) { 157 else if(!QFileInfo(mountpoint).exists()) {
158 errormsg += "<li>" + tr("Mountpoint does not exist") + "</li>"; 158 errormsg += "<li>" + tr("Mountpoint does not exist") + "</li>";
159 error = true; 159 error = true;
160 } 160 }
161 else if(!QFileInfo(mp).isDir()) { 161 else if(!QFileInfo(mountpoint).isDir()) {
162 errormsg += "<li>" + tr("Mountpoint is not a directory.") + "</li>"; 162 errormsg += "<li>" + tr("Mountpoint is not a directory.") + "</li>";
163 error = true; 163 error = true;
164 } 164 }
165 else if(!QFileInfo(mp).isWritable()) { 165 else if(!QFileInfo(mountpoint).isWritable()) {
166 errormsg += "<li>" + tr("Mountpoint is not writeable") + "</li>"; 166 errormsg += "<li>" + tr("Mountpoint is not writeable") + "</li>";
167 error = true; 167 error = true;
168 } 168 }
169 else { 169 else {
170 RbSettings::setValue(RbSettings::Mountpoint, QDir::fromNativeSeparators(mp)); 170 RbSettings::setValue(RbSettings::Mountpoint,
171 QDir::fromNativeSeparators(mountpoint));
171 } 172 }
172 173
173 // platform 174 // platform
@@ -269,7 +270,9 @@ void Config::setUserSettings()
269 connect(ui.listLanguages, SIGNAL(itemSelectionChanged()), this, SLOT(updateLanguage())); 270 connect(ui.listLanguages, SIGNAL(itemSelectionChanged()), this, SLOT(updateLanguage()));
270 271
271 // devices tab 272 // devices tab
272 ui.mountPoint->setText(QDir::toNativeSeparators(RbSettings::value(RbSettings::Mountpoint).toString())); 273 refreshMountpoint();
274 mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
275 setMountpoint(mountpoint);
273 276
274 // cache tab 277 // cache tab
275 if(!QFileInfo(RbSettings::value(RbSettings::CachePath).toString()).isDir()) 278 if(!QFileInfo(RbSettings::value(RbSettings::CachePath).toString()).isDir())
@@ -556,28 +559,6 @@ void Config::updateLanguage()
556} 559}
557 560
558 561
559void Config::browseFolder()
560{
561 browser = new BrowseDirtree(this,tr("Select your device"));
562#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
563 browser->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
564#elif defined(Q_OS_WIN32)
565 browser->setFilter(QDir::Drives);
566#endif
567#if defined(Q_OS_MACX)
568 browser->setRoot("/Volumes");
569#elif defined(Q_OS_LINUX)
570 browser->setDir("/media");
571#endif
572 if( ui.mountPoint->text() != "" )
573 {
574 browser->setDir(ui.mountPoint->text());
575 }
576 browser->show();
577 connect(browser, SIGNAL(itemChanged(QString)), this, SLOT(setMountpoint(QString)));
578}
579
580
581void Config::browseCache() 562void Config::browseCache()
582{ 563{
583 QString old = ui.cachePath->text(); 564 QString old = ui.cachePath->text();
@@ -593,9 +574,70 @@ void Config::browseCache()
593} 574}
594 575
595 576
577void Config::refreshMountpoint()
578{
579 // avoid QComboBox to send signals during rebuild to avoid changing to an
580 // unwanted item.
581 ui.mountPoint->blockSignals(true);
582 ui.mountPoint->clear();
583 QStringList mps = Autodetection::mountpoints();
584 for(int i = 0; i < mps.size(); ++i) {
585 // add mountpoint as user data so we can change the displayed string
586 // later (to include volume label or similar)
587 // Skip unwritable mountpoints, they are not useable for us.
588 if(QFileInfo(mps.at(i)).isWritable()) {
589 QString title = QString("%1 (%2 GiB of %3 GiB free)")
590 .arg(QDir::toNativeSeparators(mps.at(i)))
591 .arg((double)Utils::filesystemFree(mps.at(i))/(1<<30), 0, 'f', 2)
592 .arg((double)Utils::filesystemTotal(mps.at(i))/(1<<30), 0, 'f', 2);
593 ui.mountPoint->addItem(title, mps.at(i));
594 }
595 }
596 if(!mountpoint.isEmpty()) {
597 setMountpoint(mountpoint);
598 }
599 ui.mountPoint->blockSignals(false);
600}
601
602
603void Config::updateMountpoint(QString m)
604{
605 if(!m.isEmpty()) {
606 mountpoint = m;
607 qDebug() << "[Config] Mountpoint set to" << mountpoint;
608 }
609}
610
611
612void Config::updateMountpoint(int idx)
613{
614 if(idx == -1) {
615 return;
616 }
617 QString mp = ui.mountPoint->itemData(idx).toString();
618 if(!mp.isEmpty()) {
619 mountpoint = mp;
620 qDebug() << "[Config] Mountpoint set to" << mountpoint;
621 }
622}
623
624
596void Config::setMountpoint(QString m) 625void Config::setMountpoint(QString m)
597{ 626{
598 ui.mountPoint->setText(m); 627 if(m.isEmpty()) {
628 return;
629 }
630 int index = ui.mountPoint->findData(m);
631 if(index != -1) {
632 ui.mountPoint->setCurrentIndex(index);
633 }
634 else {
635 // keep a mountpoint that is not in the list for convenience (to allow
636 // easier development)
637 ui.mountPoint->addItem(m);
638 ui.mountPoint->setCurrentIndex(ui.mountPoint->findText(m));
639 }
640 qDebug() << "[Config] Mountpoint set to" << mountpoint;
599} 641}
600 642
601 643
@@ -682,7 +724,7 @@ void Config::autodetect()
682 724
683 if(detector.getMountPoint() != "" ) 725 if(detector.getMountPoint() != "" )
684 { 726 {
685 ui.mountPoint->setText(QDir::toNativeSeparators(detector.getMountPoint())); 727 setMountpoint(detector.getMountPoint());
686 } 728 }
687 else 729 else
688 { 730 {