summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2013-04-06 21:15:05 +0200
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2013-04-09 22:39:13 +0200
commite30b3d84e8d744098df13617fceed562bcdb8462 (patch)
tree707d86f86098b287de15e586dc4fb6d11f27127a
parente6c0bd035046e6b97f408fcff14879a2fba6c9e6 (diff)
downloadrockbox-e30b3d84e8d744098df13617fceed562bcdb8462.tar.gz
rockbox-e30b3d84e8d744098df13617fceed562bcdb8462.zip
Change autodetection result to a list.
Both autodetection functionality and the configuration dialog assumed detection to only return one found device. This isn't necessarily true, especially since some players can be detected but detecting their mountpoint might be ambiguous (only if no previous Rockbox installation is present). Instead of returning individual results (found "ok" player, found "error" player etc.) return a list containing an entry for each player. Current autodetection code will never return more than one entry since it doesn't handle multiple devices yet, and the configuration dialog will show an error if multiple devices are found. Thus there is no user visible change yet. Both autodetection and configuration dialog can now get extended to handle multiple devices. Change-Id: I79b763dbd6e7111783194bcc22ab7cc06a4061c1
-rw-r--r--rbutil/rbutilqt/base/autodetection.cpp39
-rw-r--r--rbutil/rbutilqt/base/autodetection.h21
-rw-r--r--rbutil/rbutilqt/configure.cpp181
-rw-r--r--rbutil/rbutilqt/configure.h1
4 files changed, 154 insertions, 88 deletions
diff --git a/rbutil/rbutilqt/base/autodetection.cpp b/rbutil/rbutilqt/base/autodetection.cpp
index fa2fe63cb8..de3765ffb1 100644
--- a/rbutil/rbutilqt/base/autodetection.cpp
+++ b/rbutil/rbutilqt/base/autodetection.cpp
@@ -38,6 +38,7 @@ bool Autodetection::detect()
38 m_device = ""; 38 m_device = "";
39 m_mountpoint = ""; 39 m_mountpoint = "";
40 m_errdev = ""; 40 m_errdev = "";
41 m_usberr = "";
41 42
42 detectUsb(); 43 detectUsb();
43 44
@@ -146,7 +147,8 @@ bool Autodetection::detect()
146 // if the found ipod is a macpod also notice it as device with problem. 147 // if the found ipod is a macpod also notice it as device with problem.
147 if(ipod.macpod) 148 if(ipod.macpod)
148 m_errdev = ipod.targetname; 149 m_errdev = ipod.targetname;
149 m_device = ipod.targetname; 150 else
151 m_device = ipod.targetname;
150 // since resolveMountPoint is doing exact matches we need to select 152 // since resolveMountPoint is doing exact matches we need to select
151 // the correct partition. 153 // the correct partition.
152 QString mp(ipod.diskname); 154 QString mp(ipod.diskname);
@@ -218,8 +220,8 @@ bool Autodetection::detectUsb()
218 return true; 220 return true;
219 } 221 }
220 if(usberror.contains(attached.at(i))) { 222 if(usberror.contains(attached.at(i))) {
221 m_errdev = usberror.value(attached.at(i)).at(0); 223 m_usberr = usberror.value(attached.at(i)).at(0);
222 qDebug() << "[USB] detected problem with player" << m_errdev; 224 qDebug() << "[USB] detected problem with player" << m_usberr;
223 return true; 225 return true;
224 } 226 }
225 QString idstring = QString("%1").arg(attached.at(i), 8, 16, QChar('0')); 227 QString idstring = QString("%1").arg(attached.at(i), 8, 16, QChar('0'));
@@ -233,6 +235,37 @@ bool Autodetection::detectUsb()
233} 235}
234 236
235 237
238QList<struct Autodetection::Detected> Autodetection::detected(void)
239{
240 struct Detected d;
241
242 m_detected.clear();
243 if(!m_device.isEmpty()) {
244 d.device = m_device;
245 d.mountpoint = m_mountpoint;
246 d.status = PlayerOk;
247 m_detected.append(d);
248 }
249 else if(!m_errdev.isEmpty()) {
250 d.device = m_errdev;
251 d.status = PlayerWrongFilesystem;
252 m_detected.append(d);
253 }
254 else if(!m_usberr.isEmpty()) {
255 d.device = m_usberr;
256 d.status = PlayerMtpMode;
257 m_detected.append(d);
258 }
259 else if(!m_incompat.isEmpty()) {
260 d.device = m_incompat;
261 d.status = PlayerIncompatible;
262 m_detected.append(d);
263 }
264
265 return m_detected;
266}
267
268
236bool Autodetection::detectAjbrec(QString root) 269bool Autodetection::detectAjbrec(QString root)
237{ 270{
238 QFile f(root + "/ajbrec.ajz"); 271 QFile f(root + "/ajbrec.ajz");
diff --git a/rbutil/rbutilqt/base/autodetection.h b/rbutil/rbutilqt/base/autodetection.h
index 1543aef766..65a24abb8f 100644
--- a/rbutil/rbutilqt/base/autodetection.h
+++ b/rbutil/rbutilqt/base/autodetection.h
@@ -33,21 +33,34 @@ class Autodetection :public QObject
33public: 33public:
34 Autodetection(QObject* parent=0); 34 Autodetection(QObject* parent=0);
35 35
36 enum PlayerStatus {
37 PlayerOk,
38 PlayerIncompatible,
39 PlayerMtpMode,
40 PlayerWrongFilesystem,
41 PlayerError,
42 };
43
44 struct Detected {
45 QString device;
46 QString mountpoint;
47 enum PlayerStatus status;
48 };
49
36 bool detect(); 50 bool detect();
37 51
38 QString getDevice() {return m_device;} 52 QList<struct Detected> detected(void);
39 QString getMountPoint() {return m_mountpoint;}
40 QString errdev(void) { return m_errdev; }
41 QString incompatdev(void) { return m_incompat; }
42 53
43private: 54private:
44 QString resolveMountPoint(QString); 55 QString resolveMountPoint(QString);
45 bool detectUsb(void); 56 bool detectUsb(void);
46 bool detectAjbrec(QString); 57 bool detectAjbrec(QString);
47 58
59 QList<struct Detected> m_detected;
48 QString m_device; 60 QString m_device;
49 QString m_mountpoint; 61 QString m_mountpoint;
50 QString m_errdev; 62 QString m_errdev;
63 QString m_usberr;
51 QString m_incompat; 64 QString m_incompat;
52 QList<int> m_usbconid; 65 QList<int> m_usbconid;
53}; 66};
diff --git a/rbutil/rbutilqt/configure.cpp b/rbutil/rbutilqt/configure.cpp
index ccf3eea465..922dc19b7c 100644
--- a/rbutil/rbutilqt/configure.cpp
+++ b/rbutil/rbutilqt/configure.cpp
@@ -725,98 +725,117 @@ void Config::autodetect()
725 this->setCursor(Qt::WaitCursor); 725 this->setCursor(Qt::WaitCursor);
726 QCoreApplication::processEvents(); 726 QCoreApplication::processEvents();
727 727
728 if(detector.detect()) //let it detect 728 detector.detect();
729 QList<struct Autodetection::Detected> detected;
730 detected = detector.detected();
731 this->unsetCursor();
732 if(detected.size() > 1) {
733 // FIXME: handle multiple found players.
734 QMessageBox::information(this, tr("Device Detection"),
735 tr("Multiple devices have been detected. Please disconnect "
736 "all players but one and try again."));
737 ui.treeDevices->setEnabled(true);
738 }
739 else if(detected.size() == 0) {
740 QMessageBox::warning(this, tr("Device Detection"),
741 tr("Could not detect a device.\n"
742 "Select your device and Mountpoint manually."),
743 QMessageBox::Ok ,QMessageBox::Ok);
744 ui.treeDevices->setEnabled(true);
745 }
746 else if(detected.at(0).status != Autodetection::PlayerOk) {
747 QString msg;
748 switch(detected.at(0).status) {
749 case Autodetection::PlayerIncompatible:
750 msg += tr("Detected an unsupported player:\n%1\n"
751 "Sorry, Rockbox doesn't run on your player.")
752 .arg(SystemInfo::platformValue(detected.at(0).device,
753 SystemInfo::CurName).toString());
754 break;
755 case Autodetection::PlayerMtpMode:
756 msg = tr("%1 in MTP mode found!\n"
757 "You need to change your player to MSC mode for installation. ")
758 .arg(SystemInfo::platformValue(detected.at(0).device,
759 SystemInfo::CurName).toString());
760 break;
761 case Autodetection::PlayerWrongFilesystem:
762 if(SystemInfo::platformValue(detected.at(0).device,
763 SystemInfo::CurBootloaderMethod) == "ipod") {
764 msg = tr("%1 \"MacPod\" found!\n"
765 "Rockbox needs a FAT formatted Ipod (so-called \"WinPod\") "
766 "to run. ").arg(SystemInfo::platformValue(
767 detected.at(0).device, SystemInfo::CurName).toString());
768 }
769 else {
770 msg = tr("The player contains an incompatible filesystem.\n"
771 "Make sure you selected the correct mountpoint and "
772 "the player is set up to use a filesystem compatible "
773 "with Rockbox.");
774 }
775 break;
776 case Autodetection::PlayerError:
777 msg += tr("An unknown error occured during player detection.");
778 break;
779 default:
780 break;
781 }
782 QMessageBox::information(this, tr("Device Detection"), msg);
783 ui.treeDevices->setEnabled(true);
784 }
785 else {
786 selectDevice(detected.at(0).device, detected.at(0).mountpoint);
787 }
788
789}
790
791void Config::selectDevice(QString device, QString mountpoint)
792{
793 // collapse all items
794 for(int a = 0; a < ui.treeDevices->topLevelItemCount(); a++)
795 ui.treeDevices->topLevelItem(a)->setExpanded(false);
796 // deselect the selected item(s)
797 for(int a = 0; a < ui.treeDevices->selectedItems().size(); a++)
798 ui.treeDevices->selectedItems().at(a)->setSelected(false);
799
800 // find the new item
801 // enumerate all platform items
802 QList<QTreeWidgetItem*> itmList
803 = ui.treeDevices->findItems("*",Qt::MatchWildcard);
804 for(int i=0; i< itmList.size();i++)
729 { 805 {
730 QString devicename = detector.getDevice(); 806 //enumerate device items
731 // deexpand all items 807 for(int j=0;j < itmList.at(i)->childCount();j++)
732 for(int a = 0; a < ui.treeDevices->topLevelItemCount(); a++)
733 ui.treeDevices->topLevelItem(a)->setExpanded(false);
734 //deselect the selected item(s)
735 for(int a = 0; a < ui.treeDevices->selectedItems().size(); a++)
736 ui.treeDevices->selectedItems().at(a)->setSelected(false);
737
738 // find the new item
739 // enumerate all platform items
740 QList<QTreeWidgetItem*> itmList
741 = ui.treeDevices->findItems("*",Qt::MatchWildcard);
742 for(int i=0; i< itmList.size();i++)
743 { 808 {
744 //enumerate device items 809 QString data = itmList.at(i)->child(j)->data(0, Qt::UserRole).toString();
745 for(int j=0;j < itmList.at(i)->childCount();j++) 810 // unset bold flag
811 QFont f = itmList.at(i)->child(j)->font(0);
812 f.setBold(false);
813 itmList.at(i)->child(j)->setFont(0, f);
814
815 if(device == data) // item found
746 { 816 {
747 QString data = itmList.at(i)->child(j)->data(0, Qt::UserRole).toString(); 817 f.setBold(true);
748 // unset bold flag
749 QFont f = itmList.at(i)->child(j)->font(0);
750 f.setBold(false);
751 itmList.at(i)->child(j)->setFont(0, f); 818 itmList.at(i)->child(j)->setFont(0, f);
752 819 itmList.at(i)->child(j)->setSelected(true); //select the item
753 if(devicename == data) // item found 820 itmList.at(i)->setExpanded(true); //expand the platform item
754 { 821 //ui.treeDevices->indexOfTopLevelItem(itmList.at(i)->child(j));
755 f.setBold(true); 822 ui.treeDevices->scrollToItem(itmList.at(i)->child(j));
756 itmList.at(i)->child(j)->setFont(0, f); 823 break;
757 itmList.at(i)->child(j)->setSelected(true); //select the item
758 itmList.at(i)->setExpanded(true); //expand the platform item
759 //ui.treeDevices->indexOfTopLevelItem(itmList.at(i)->child(j));
760 ui.treeDevices->scrollToItem(itmList.at(i)->child(j));
761 break;
762 }
763 }
764 }
765 this->unsetCursor();
766
767 if(!detector.errdev().isEmpty()) {
768 QString text;
769 if(SystemInfo::platformValue(detector.errdev(),
770 SystemInfo::CurBootloaderMethod) == "ipod") {
771 text = tr("%1 \"MacPod\" found!\n"
772 "Rockbox needs a FAT formatted Ipod (so-called \"WinPod\") "
773 "to run. ").arg(SystemInfo::platformValue(
774 detector.errdev(), SystemInfo::CurName).toString());
775 } 824 }
776 // treat all other errors as MTP device for now.
777 else {
778 text = tr("%1 in MTP mode found!\n"
779 "You need to change your player to MSC mode for installation. ")
780 .arg(SystemInfo::platformValue(detector.errdev(),
781 SystemInfo::CurName).toString());
782 }
783 text += tr("Until you change this installation will fail!");
784
785 QMessageBox::critical(this, tr("Fatal error"), text, QMessageBox::Ok);
786 return;
787 } 825 }
788 if(!detector.incompatdev().isEmpty()) { 826 }
789 QString text; 827 this->unsetCursor();
790 text = tr("Detected an unsupported player:\n%1\n"
791 "Sorry, Rockbox doesn't run on your player.")
792 .arg(SystemInfo::platformValue(detector.incompatdev(),
793 SystemInfo::CurName).toString());
794
795 QMessageBox::critical(this, tr("Fatal: player incompatible"),
796 text, QMessageBox::Ok);
797 return;
798 }
799 828
800 if(detector.getMountPoint() != "" ) 829 if(!mountpoint.isEmpty())
801 { 830 {
802 setMountpoint(detector.getMountPoint()); 831 setMountpoint(mountpoint);
803 }
804 else
805 {
806 QMessageBox::warning(this, tr("Autodetection"),
807 tr("Could not detect a Mountpoint.\n"
808 "Select your Mountpoint manually."),
809 QMessageBox::Ok ,QMessageBox::Ok);
810 }
811 } 832 }
812 else 833 else
813 { 834 {
814 this->unsetCursor();
815 QMessageBox::warning(this, tr("Autodetection"), 835 QMessageBox::warning(this, tr("Autodetection"),
816 tr("Could not detect a device.\n" 836 tr("Could not detect a Mountpoint.\n"
817 "Select your device and Mountpoint manually."), 837 "Select your Mountpoint manually."),
818 QMessageBox::Ok ,QMessageBox::Ok); 838 QMessageBox::Ok, QMessageBox::Ok);
819
820 } 839 }
821 ui.treeDevices->setEnabled(true); 840 ui.treeDevices->setEnabled(true);
822} 841}
diff --git a/rbutil/rbutilqt/configure.h b/rbutil/rbutilqt/configure.h
index dd80f65b31..4e69996d1f 100644
--- a/rbutil/rbutilqt/configure.h
+++ b/rbutil/rbutilqt/configure.h
@@ -54,6 +54,7 @@ class Config : public QDialog
54 QString mountpoint; 54 QString mountpoint;
55 void updateCacheInfo(QString); 55 void updateCacheInfo(QString);
56 void changeEvent(QEvent *event); 56 void changeEvent(QEvent *event);
57 void selectDevice(QString device, QString mountpoint);
57 58
58 private slots: 59 private slots:
59 void showProxyPassword(bool show); 60 void showProxyPassword(bool show);