summaryrefslogtreecommitdiffstats
path: root/heimdall-frontend/Source/mainwindow.cpp
diff options
context:
space:
mode:
authorBenjamin Dobell <benjamin.dobell@glassechidna.com.au>2011-07-05 18:58:28 +0200
committerBenjamin Dobell <benjamin.dobell@glassechidna.com.au>2011-07-05 18:58:28 +0200
commitb6ffa766b21fe2c985437aa80824a3cd4c384de8 (patch)
treeda9f5c33b33074748bd981175d36d2974ff3fb98 /heimdall-frontend/Source/mainwindow.cpp
parentMerge pull request #15 from alanorth/patch-1 (diff)
downloadHeimdall-b6ffa766b21fe2c985437aa80824a3cd4c384de8.tar
Heimdall-b6ffa766b21fe2c985437aa80824a3cd4c384de8.tar.gz
Heimdall-b6ffa766b21fe2c985437aa80824a3cd4c384de8.tar.bz2
Heimdall-b6ffa766b21fe2c985437aa80824a3cd4c384de8.tar.lz
Heimdall-b6ffa766b21fe2c985437aa80824a3cd4c384de8.tar.xz
Heimdall-b6ffa766b21fe2c985437aa80824a3cd4c384de8.tar.zst
Heimdall-b6ffa766b21fe2c985437aa80824a3cd4c384de8.zip
Diffstat (limited to 'heimdall-frontend/Source/mainwindow.cpp')
-rw-r--r--heimdall-frontend/Source/mainwindow.cpp972
1 files changed, 580 insertions, 392 deletions
diff --git a/heimdall-frontend/Source/mainwindow.cpp b/heimdall-frontend/Source/mainwindow.cpp
index b5287e2..8043599 100644
--- a/heimdall-frontend/Source/mainwindow.cpp
+++ b/heimdall-frontend/Source/mainwindow.cpp
@@ -18,9 +18,6 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/
-// Heimdall Frontend
-#include "mainwindow.h"
-
// Qt
#include <QCoreApplication>
#include <QDesktopServices>
@@ -30,151 +27,214 @@
#include <QRegExp>
#include <QUrl>
+// Heimdall Frontend
+#include "mainwindow.h"
+#include "Packaging.h"
+
using namespace HeimdallFrontend;
-bool MainWindow::IsArchive(QString path)
+void MainWindow::UpdateUnusedPartitionIds(void)
{
- // Not a real check but hopefully it gets the message across, don't flash archives!
- return (path.endsWith(".tar", Qt::CaseInsensitive) || path.endsWith(".gz", Qt::CaseInsensitive) || path.endsWith(".zip", Qt::CaseInsensitive)
- || path.endsWith(".bz2", Qt::CaseInsensitive) || path.endsWith(".7z", Qt::CaseInsensitive) || path.endsWith(".rar", Qt::CaseInsensitive));
+ unusedPartitionIds.clear();
+
+ // Initially populate unusedPartitionIds with all possible partition IDs.
+ for (unsigned int i = 0; i < currentPitData.GetEntryCount(); i++)
+ {
+ const PitEntry *pitEntry = currentPitData.GetEntry(i);
+
+ if (!pitEntry->GetUnused() && strcmp(pitEntry->GetPartitionName(), "PIT") != 0)
+ unusedPartitionIds.append(pitEntry->GetPartitionIdentifier());
+ }
+
+ // Remove any used partition IDs from unusedPartitionIds
+ QList<FileInfo>& fileList = workingPackageData.GetFirmwareInfo().GetFileInfos();
+
+ for (int i = 0; i < fileList.length(); i++)
+ unusedPartitionIds.removeOne(fileList[i].GetPartitionId());
}
-QString MainWindow::PromptFileSelection(void)
+bool MainWindow::ReadPit(QFile *file)
{
- QString path = QFileDialog::getOpenFileName(this, "Select File", lastDirectory);
+ if(!file->open(QIODevice::ReadOnly))
+ return (false);
- if (path != "")
- lastDirectory = path.left(path.lastIndexOf('/') + 1);
+ unsigned char *buffer = new unsigned char[file->size()];
- return (path);
+ file->read(reinterpret_cast<char *>(buffer), file->size());
+ file->close();
+
+ bool success = currentPitData.Unpack(buffer);
+ delete buffer;
+
+ if (!success)
+ currentPitData.Clear();
+
+ return (success);
}
-void MainWindow::UpdateStartButton(void)
+void MainWindow::UpdatePackageUserInterface(void)
{
- if (heimdallRunning)
+ supportedDevicesListWidget->clear();
+ includedFilesListWidget->clear();
+
+ if (loadedPackageData.IsCleared())
{
- startFlashButton->setEnabled(false);
- return;
- }
+ // Package Interface
+ firmwareNameLineEdit->clear();
+ versionLineEdit->clear();
- if (repartitionCheckBox->isChecked())
+ developerNamesLineEdit->clear();
+
+ platformLineEdit->clear();
+
+ developerHomepageButton->setEnabled(false);
+ developerDonateButton->setEnabled(false);
+
+ repartitionRadioButton->setChecked(false);
+
+ loadFirmwareButton->setEnabled(false);
+ }
+ else
{
- if (!IsArchive(pitLineEdit->text()) && factoryfsCheckBox->isChecked() && !IsArchive(factoryfsLineEdit->text()) && kernelCheckBox->isChecked()
- && !IsArchive(kernelLineEdit->text()) && paramCheckBox->isChecked() && !IsArchive(paramLineEdit->text())
- && primaryBootCheckBox->isChecked() && !IsArchive(primaryBootLineEdit->text()) && secondaryBootCheckBox->isChecked()
- && !IsArchive(secondaryBootLineEdit->text()) && modemCheckBox->isChecked() && !IsArchive(modemLineEdit->text()))
+ firmwareNameLineEdit->setText(loadedPackageData.GetFirmwareInfo().GetName());
+ versionLineEdit->setText(loadedPackageData.GetFirmwareInfo().GetVersion());
+
+ QString developerNames;
+
+ if (!loadedPackageData.GetFirmwareInfo().GetDevelopers().isEmpty())
{
- startFlashButton->setEnabled(true);
+ developerNames = loadedPackageData.GetFirmwareInfo().GetDevelopers()[0];
+ for (int i = 1; i < loadedPackageData.GetFirmwareInfo().GetDevelopers().length(); i++)
+ developerNames += ", " + loadedPackageData.GetFirmwareInfo().GetDevelopers()[i];
}
+
+ developerNamesLineEdit->setText(developerNames);
+
+ platformLineEdit->setText(loadedPackageData.GetFirmwareInfo().GetPlatformInfo().GetName() + " ("
+ + loadedPackageData.GetFirmwareInfo().GetPlatformInfo().GetVersion() + ")");
+
+ if (!loadedPackageData.GetFirmwareInfo().GetUrl().isEmpty())
+ developerHomepageButton->setEnabled(true);
else
+ developerHomepageButton->setEnabled(false);
+
+ if (!loadedPackageData.GetFirmwareInfo().GetDonateUrl().isEmpty())
+ developerDonateButton->setEnabled(true);
+ else
+ developerDonateButton->setEnabled(false);
+
+ for (int i = 0; i < loadedPackageData.GetFirmwareInfo().GetDeviceInfos().length(); i++)
{
- startFlashButton->setEnabled(false);
+ const DeviceInfo& deviceInfo = loadedPackageData.GetFirmwareInfo().GetDeviceInfos()[i];
+ supportedDevicesListWidget->addItem(deviceInfo.GetManufacturer() + " " + deviceInfo.GetName() + " (" + deviceInfo.GetProduct() + ")");
}
- }
- else
- {
- bool atLeastOneFile = false;
- if (factoryfsCheckBox->isChecked())
+ for (int i = 0; i < loadedPackageData.GetFirmwareInfo().GetFileInfos().length(); i++)
{
- atLeastOneFile = true;
-
- if (IsArchive(factoryfsLineEdit->text()))
- {
- startFlashButton->setEnabled(false);
- return;
- }
+ const FileInfo& fileInfo = loadedPackageData.GetFirmwareInfo().GetFileInfos()[i];
+ includedFilesListWidget->addItem(fileInfo.GetFilename());
}
- if (kernelCheckBox->isChecked())
- {
- atLeastOneFile = true;
+ repartitionRadioButton->setChecked(loadedPackageData.GetFirmwareInfo().GetRepartition());
- if (IsArchive(kernelLineEdit->text()))
- {
- startFlashButton->setEnabled(false);
- return;
- }
- }
+ loadFirmwareButton->setEnabled(true);
+ }
+}
- if (paramCheckBox->isChecked())
- {
- atLeastOneFile = true;
+bool MainWindow::IsArchive(QString path)
+{
+ // Not a real check but hopefully it gets the message across, don't flash archives!
+ return (path.endsWith(".tar", Qt::CaseInsensitive) || path.endsWith(".gz", Qt::CaseInsensitive) || path.endsWith(".zip", Qt::CaseInsensitive)
+ || path.endsWith(".bz2", Qt::CaseInsensitive) || path.endsWith(".7z", Qt::CaseInsensitive) || path.endsWith(".rar", Qt::CaseInsensitive));
+}
- if (IsArchive(paramLineEdit->text()))
- {
- startFlashButton->setEnabled(false);
- return;
- }
- }
+QString MainWindow::PromptFileSelection(void)
+{
+ QString path = QFileDialog::getOpenFileName(this, "Select File", lastDirectory);
- if (primaryBootCheckBox->isChecked())
- {
- atLeastOneFile = true;
+ if (path != "")
+ lastDirectory = path.left(path.lastIndexOf('/') + 1);
- if (IsArchive(primaryBootLineEdit->text()))
- {
- startFlashButton->setEnabled(false);
- return;
- }
- }
+ return (path);
+}
- if (secondaryBootCheckBox->isChecked())
- {
- atLeastOneFile = true;
+QString MainWindow::PromptFileCreation(void)
+{
+ QString path = QFileDialog::getSaveFileName(this, "Save File", lastDirectory);
- if (IsArchive(secondaryBootLineEdit->text()))
- {
- startFlashButton->setEnabled(false);
- return;
- }
- }
+ if (path != "")
+ lastDirectory = path.left(path.lastIndexOf('/') + 1);
- if (cacheCheckBox->isChecked())
- {
- atLeastOneFile = true;
+ return (path);
+}
- if (IsArchive(cacheLineEdit->text()))
- {
- startFlashButton->setEnabled(false);
- return;
- }
- }
+void MainWindow::UpdatePartitionNamesInterface(void)
+{
+ populatingPartitionNames = true;
- if (databaseCheckBox->isChecked())
- {
- atLeastOneFile = true;
+ partitionNameComboBox->clear();
- if (IsArchive(databaseLineEdit->text()))
- {
- startFlashButton->setEnabled(false);
- return;
- }
- }
+ int partitionsListWidgetRow = partitionsListWidget->currentRow();
- if (modemCheckBox->isChecked())
- {
- atLeastOneFile = true;
+ if (partitionsListWidgetRow >= 0)
+ {
+ const FileInfo& partitionInfo = workingPackageData.GetFirmwareInfo().GetFileInfos()[partitionsListWidget->currentRow()];
- if (IsArchive(modemLineEdit->text()))
- {
- startFlashButton->setEnabled(false);
- return;
- }
- }
+ for (int i = 0; i < unusedPartitionIds.length(); i++)
+ partitionNameComboBox->addItem(currentPitData.FindEntry(unusedPartitionIds[i])->GetPartitionName());
- if (recoveryCheckBox->isChecked())
- {
- atLeastOneFile = true;
+ partitionNameComboBox->addItem(currentPitData.FindEntry(partitionInfo.GetPartitionId())->GetPartitionName());
+ partitionNameComboBox->setCurrentIndex(unusedPartitionIds.length());
- if (IsArchive(recoveryLineEdit->text()))
- {
- startFlashButton->setEnabled(false);
- return;
- }
+ partitionNameComboBox->setEnabled(true);
+ }
+ else
+ {
+ partitionNameComboBox->setEnabled(false);
+ }
+
+ populatingPartitionNames = false;
+}
+
+void MainWindow::UpdateStartButton(void)
+{
+ if (heimdallRunning)
+ {
+ startFlashButton->setEnabled(false);
+ return;
+ }
+
+ bool allPartitionsValid = true;
+
+ QList<FileInfo>& fileList = workingPackageData.GetFirmwareInfo().GetFileInfos();
+
+ for (int i = 0; i < fileList.length(); i++)
+ {
+ if (fileList[i].GetFilename().isEmpty())
+ {
+ allPartitionsValid = false;
+ break;
}
+ }
+
+ bool validSettings = allPartitionsValid && fileList.length() > 0;
- startFlashButton->setEnabled(atLeastOneFile);
+ startFlashButton->setEnabled(validSettings);
+ functionTabWidget->setTabEnabled(functionTabWidget->indexOf(createPackageTab), validSettings);
+}
+
+void MainWindow::UpdateBuildPackageButton(void)
+{
+ const FirmwareInfo& firmwareInfo = workingPackageData.GetFirmwareInfo();
+
+ if (firmwareInfo.GetName().isEmpty() || firmwareInfo.GetVersion().isEmpty() || firmwareInfo.GetPlatformInfo().GetName().isEmpty()
+ || firmwareInfo.GetPlatformInfo().GetVersion().isEmpty() || firmwareInfo.GetDevelopers().isEmpty() || firmwareInfo.GetDeviceInfos().isEmpty())
+ {
+ buildPackageButton->setEnabled(false);
+ }
+ else
+ {
+ buildPackageButton->setEnabled(true);
}
}
@@ -186,33 +246,52 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
lastDirectory = QDir::toNativeSeparators(QApplication::applicationDirPath());
+ populatingPartitionNames = false;
+
+ functionTabWidget->setTabEnabled(functionTabWidget->indexOf(createPackageTab), false);
+
QObject::connect(actionDonate, SIGNAL(triggered()), this, SLOT(OpenDonationWebpage()));
QObject::connect(actionAboutHeimdall, SIGNAL(triggered()), this, SLOT(ShowAbout()));
+ QObject::connect(browseFirmwarePackageButton, SIGNAL(clicked()), this, SLOT(SelectFirmwarePackage()));
+ QObject::connect(developerHomepageButton, SIGNAL(clicked()), this, SLOT(OpenDeveloperHomepage()));
+ QObject::connect(developerDonateButton, SIGNAL(clicked()), this, SLOT(OpenDeveloperDonationWebpage()));
+ QObject::connect(loadFirmwareButton, SIGNAL(clicked()), this, SLOT(LoadFirmwarePackage()));
+
+ QObject::connect(partitionsListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(SelectPartition(int)));
+ QObject::connect(addPartitionButton, SIGNAL(clicked()), this, SLOT(AddPartition()));
+ QObject::connect(removePartitionButton, SIGNAL(clicked()), this, SLOT(RemovePartition()));
+
+ QObject::connect(partitionNameComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(SelectPartitionName(int)));
+ QObject::connect(partitionFileBrowseButton, SIGNAL(clicked()), this, SLOT(SelectPartitionFile()));
+
QObject::connect(pitBrowseButton, SIGNAL(clicked()), this, SLOT(SelectPit()));
- QObject::connect(factoryfsBrowseButton, SIGNAL(clicked()), this, SLOT(SelectFactoryfs()));
- QObject::connect(kernelBrowseButton, SIGNAL(clicked()), this, SLOT(SelectKernel()));
- QObject::connect(paramBrowseButton, SIGNAL(clicked()), this, SLOT(SelectParam()));
- QObject::connect(primaryBootBrowseButton, SIGNAL(clicked()), this, SLOT(SelectPrimaryBootloader()));
- QObject::connect(secondaryBootBrowseButton, SIGNAL(clicked()), this, SLOT(SelectSecondaryBootloader()));
- QObject::connect(cacheBrowseButton, SIGNAL(clicked()), this, SLOT(SelectCache()));
- QObject::connect(databaseBrowseButton, SIGNAL(clicked()), this, SLOT(SelectDatabase()));
- QObject::connect(modemBrowseButton, SIGNAL(clicked()), this, SLOT(SelectModem()));
- QObject::connect(recoveryBrowseButton, SIGNAL(clicked()), this, SLOT(SelectRecovery()));
-
- QObject::connect(repartitionCheckBox, SIGNAL(stateChanged(int)), this, SLOT(SetRepartionEnabled(int)));
- QObject::connect(factoryfsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(SetFactoryfsEnabled(int)));
- QObject::connect(kernelCheckBox, SIGNAL(stateChanged(int)), this, SLOT(SetKernelEnabled(int)));
- QObject::connect(paramCheckBox, SIGNAL(stateChanged(int)), this, SLOT(SetParamEnabled(int)));
- QObject::connect(primaryBootCheckBox, SIGNAL(stateChanged(int)), this, SLOT(SetPrimaryBootloaderEnabled(int)));
- QObject::connect(secondaryBootCheckBox, SIGNAL(stateChanged(int)), this, SLOT(SetSecondaryBootloaderEnabled(int)));
- QObject::connect(cacheCheckBox, SIGNAL(stateChanged(int)), this, SLOT(SetCacheEnabled(int)));
- QObject::connect(databaseCheckBox, SIGNAL(stateChanged(int)), this, SLOT(SetDatabaseEnabled(int)));
- QObject::connect(modemCheckBox, SIGNAL(stateChanged(int)), this, SLOT(SetModemEnabled(int)));
- QObject::connect(recoveryCheckBox, SIGNAL(stateChanged(int)), this, SLOT(SetRecoveryEnabled(int)));
+ QObject::connect(repartitionCheckBox, SIGNAL(stateChanged(int)), this, SLOT(SetRepartition(int)));
QObject::connect(startFlashButton, SIGNAL(clicked()), this, SLOT(StartFlash()));
+ QObject::connect(createFirmwareNameLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(FirmwareNameChanged(const QString&)));
+ QObject::connect(createFirmwareVersionLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(FirmwareVersionChanged(const QString&)));
+ QObject::connect(createPlatformNameLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(PlatformNameChanged(const QString&)));
+ QObject::connect(createPlatformVersionLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(PlatformVersionChanged(const QString&)));
+
+ QObject::connect(createHomepageLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(HomepageUrlChanged(const QString&)));
+ QObject::connect(createDonateLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(DonateUrlChanged(const QString&)));
+
+ QObject::connect(createDevelopersListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(SelectDeveloper(int)));
+ QObject::connect(createDeveloperNameLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(DeveloperNameChanged(const QString&)));
+ QObject::connect(addDeveloperButton, SIGNAL(clicked()), this, SLOT(AddDeveloper()));
+ QObject::connect(removeDeveloperButton, SIGNAL(clicked()), this, SLOT(RemoveDeveloper()));
+
+ QObject::connect(createDevicesListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(SelectDevice(int)));
+ QObject::connect(deviceManufacturerLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(DeviceInfoChanged(const QString&)));
+ QObject::connect(deviceNameLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(DeviceInfoChanged(const QString&)));
+ QObject::connect(deviceProductCodeLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(DeviceInfoChanged(const QString&)));
+ QObject::connect(addDeviceButton, SIGNAL(clicked()), this, SLOT(AddDevice()));
+ QObject::connect(removeDeviceButton, SIGNAL(clicked()), this, SLOT(RemoveDevice()));
+
+ QObject::connect(buildPackageButton, SIGNAL(clicked()), this, SLOT(BuildPackage()));
+
QObject::connect(&process, SIGNAL(readyRead()), this, SLOT(HandleHeimdallStdout()));
QObject::connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(HandleHeimdallReturned(int, QProcess::ExitStatus)));
QObject::connect(&process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(HandleHeimdallError(QProcess::ProcessError)));
@@ -232,284 +311,314 @@ void MainWindow::ShowAbout(void)
aboutForm.show();
}
-void MainWindow::SelectPit(void)
+void MainWindow::SelectFirmwarePackage(void)
{
+ loadedPackageData.Clear();
+ UpdatePackageUserInterface();
+
QString path = PromptFileSelection();
- pitLineEdit->setText(path);
+ firmwarePackageLineEdit->setText(path);
- SetRepartionEnabled(path != "");
+ if (firmwarePackageLineEdit->text() != "")
+ {
+ if (Packaging::ExtractPackage(firmwarePackageLineEdit->text(), &loadedPackageData))
+ {
+ UpdatePackageUserInterface();
+ }
+ else
+ {
+ // TODO: Error?
+ loadedPackageData.Clear();
+ }
+ }
}
-void MainWindow::SelectFactoryfs(void)
+void MainWindow::OpenDeveloperHomepage(void)
{
- QString path = PromptFileSelection();
- factoryfsLineEdit->setText(path);
-
- SetFactoryfsEnabled(path != "");
+ QDesktopServices::openUrl(QUrl(loadedPackageData.GetFirmwareInfo().GetUrl(), QUrl::TolerantMode));
}
-void MainWindow::SelectKernel(void)
+void MainWindow::OpenDeveloperDonationWebpage(void)
{
- QString path = PromptFileSelection();
- kernelLineEdit->setText(path);
-
- SetKernelEnabled(path != "");
+ QDesktopServices::openUrl(QUrl(loadedPackageData.GetFirmwareInfo().GetDonateUrl(), QUrl::TolerantMode));
}
-void MainWindow::SelectParam(void)
+void MainWindow::LoadFirmwarePackage(void)
{
- QString path = PromptFileSelection();
- paramLineEdit->setText(path);
+ workingPackageData.Clear();
+ currentPitData.Clear();
+
+ // Make flashSettings responsible for the temporary files
+ workingPackageData.GetFiles().append(loadedPackageData.GetFiles());
+ loadedPackageData.RemoveAllFiles();
- SetParamEnabled(path != "");
-}
+ const QList<FileInfo> packageFileInfos = loadedPackageData.GetFirmwareInfo().GetFileInfos();
-void MainWindow::SelectPrimaryBootloader(void)
-{
- QString path = PromptFileSelection();
- primaryBootLineEdit->setText(path);
+ for (int i = 0; i < packageFileInfos.length(); i++)
+ {
+ for (int j = 0; j < workingPackageData.GetFiles().length(); j++)
+ {
+ if (workingPackageData.GetFiles()[j]->fileTemplate() == ("XXXXXX-" + packageFileInfos[i].GetFilename()))
+ {
+ FileInfo partitionInfo(packageFileInfos[i].GetPartitionId(), QDir::current().absoluteFilePath(workingPackageData.GetFiles()[j]->fileName()));
+ workingPackageData.GetFirmwareInfo().GetFileInfos().append(partitionInfo);
- SetPrimaryBootloaderEnabled(path != "");
-}
+ break;
+ }
+ }
+ }
-void MainWindow::SelectSecondaryBootloader(void)
-{
- QString path = PromptFileSelection();
- secondaryBootLineEdit->setText(path);
+ // Find the PIT file and read it
+ for (int i = 0; i < workingPackageData.GetFiles().length(); i++)
+ {
+ QTemporaryFile *file = workingPackageData.GetFiles()[i];
- SetSecondaryBootloaderEnabled(path != "");
-}
+ if (file->fileTemplate() == ("XXXXXX-" + loadedPackageData.GetFirmwareInfo().GetPitFilename()))
+ {
+ workingPackageData.GetFirmwareInfo().SetPitFilename(QDir::current().absoluteFilePath(file->fileName()));
-void MainWindow::SelectCache(void)
-{
- QString path = PromptFileSelection();
- cacheLineEdit->setText(path);
+ if (!ReadPit(file))
+ {
+ // TODO: Error
+ loadedPackageData.Clear();
+ UpdatePackageUserInterface();
- SetCacheEnabled(path != "");
-}
+ workingPackageData.Clear();
+ UpdateUnusedPartitionIds();
+ return;
+ }
-void MainWindow::SelectDatabase(void)
-{
- QString path = PromptFileSelection();
- databaseLineEdit->setText(path);
+ break;
+ }
+ }
- SetDatabaseEnabled(path != "");
-}
+ UpdateUnusedPartitionIds();
+ workingPackageData.GetFirmwareInfo().SetRepartition(loadedPackageData.GetFirmwareInfo().GetRepartition());
-void MainWindow::SelectModem(void)
-{
- QString path = PromptFileSelection();
- modemLineEdit->setText(path);
+ loadedPackageData.Clear();
+ UpdatePackageUserInterface();
+ firmwarePackageLineEdit->clear();
- SetModemEnabled(path != "");
-}
+ partitionsListWidget->clear();
-void MainWindow::SelectRecovery(void)
-{
- QString path = PromptFileSelection();
- recoveryLineEdit->setText(path);
+ // Populate partitionsListWidget with partition names (from the PIT file)
+ for (int i = 0; i < workingPackageData.GetFirmwareInfo().GetFileInfos().length(); i++)
+ {
+ const FileInfo& partitionInfo = workingPackageData.GetFirmwareInfo().GetFileInfos()[i];
- SetRecoveryEnabled(path != "");
-}
+ const PitEntry *pitEntry = currentPitData.FindEntry(partitionInfo.GetPartitionId());
-void MainWindow::SetRepartionEnabled(int enabled)
-{
- if (repartitionCheckBox->isChecked() != (enabled != 0))
- repartitionCheckBox->setChecked(enabled);
+ if (pitEntry)
+ {
+ partitionsListWidget->addItem(pitEntry->GetPartitionName());
+ }
+ else
+ {
+ // TODO: "Firmware package includes invalid partition IDs."
+ loadedPackageData.GetFirmwareInfo().Clear();
+ currentPitData.Clear();
+ UpdateUnusedPartitionIds();
- if (enabled)
- {
- repartitionCheckBox->setEnabled(true);
- pitLineEdit->setEnabled(true);
- repartitionCheckBox->setChecked(true);
- }
- else
- {
- repartitionCheckBox->setEnabled(pitLineEdit->text() != "");
- pitLineEdit->setEnabled(false);
+ partitionsListWidget->clear();
+ return;
+ }
}
-
- UpdateStartButton();
-}
-void MainWindow::SetFactoryfsEnabled(int enabled)
-{
- if (factoryfsCheckBox->isChecked() != (enabled != 0))
- factoryfsCheckBox->setChecked(enabled);
+ partitionNameComboBox->clear();
+ partitionIdLineEdit->clear();
+ partitionFileLineEdit->clear();
+ partitionFileBrowseButton->setEnabled(false);
- if (enabled)
- {
- factoryfsCheckBox->setEnabled(true);
- factoryfsLineEdit->setEnabled(true);
- factoryfsCheckBox->setChecked(true);
- }
- else
- {
- factoryfsCheckBox->setEnabled(factoryfsLineEdit->text() != "");
- factoryfsLineEdit->setEnabled(false);
- }
-
- UpdateStartButton();
-}
+ repartitionCheckBox->setEnabled(true);
+ repartitionCheckBox->setChecked(workingPackageData.GetFirmwareInfo().GetRepartition());
+ partitionsListWidget->setEnabled(true);
+ addPartitionButton->setEnabled(true);
+ removePartitionButton->setEnabled(true && partitionsListWidget->currentRow() >= 0);
-void MainWindow::SetKernelEnabled(int enabled)
-{
- if (kernelCheckBox->isChecked() != (enabled != 0))
- kernelCheckBox->setChecked(enabled);
+ pitLineEdit->setText(workingPackageData.GetFirmwareInfo().GetPitFilename());
+
+ functionTabWidget->setCurrentWidget(flashTab);
- if (enabled)
- {
- kernelCheckBox->setEnabled(true);
- kernelLineEdit->setEnabled(true);
- kernelCheckBox->setChecked(true);
- }
- else
- {
- kernelCheckBox->setEnabled(kernelLineEdit->text() != "");
- kernelLineEdit->setEnabled(false);
- }
-
UpdateStartButton();
}
-void MainWindow::SetParamEnabled(int enabled)
+void MainWindow::SelectPartitionName(int index)
{
- if (paramCheckBox->isChecked() != (enabled != 0))
- paramCheckBox->setChecked(enabled);
-
- if (enabled)
- {
- paramCheckBox->setEnabled(true);
- paramLineEdit->setEnabled(true);
- paramCheckBox->setChecked(true);
- }
- else
+ if (!populatingPartitionNames && index != -1 && index != unusedPartitionIds.length())
{
- paramCheckBox->setEnabled(paramLineEdit->text() != "");
- paramLineEdit->setEnabled(false);
+ unsigned int newPartitionIndex = unusedPartitionIds[index];
+ unusedPartitionIds.removeAt(index);
+
+ FileInfo& partitionInfo = workingPackageData.GetFirmwareInfo().GetFileInfos()[partitionsListWidget->currentRow()];
+ unusedPartitionIds.append(partitionInfo.GetPartitionId());
+ partitionInfo.SetPartitionId(newPartitionIndex);
+
+ partitionNameComboBox->clear();
+
+ // Update interface
+ UpdatePartitionNamesInterface();
+ partitionIdLineEdit->setText(QString::number(newPartitionIndex));
+ partitionsListWidget->currentItem()->setText(currentPitData.FindEntry(newPartitionIndex)->GetPartitionName());
}
-
- UpdateStartButton();
}
-void MainWindow::SetPrimaryBootloaderEnabled(int enabled)
+void MainWindow::SelectPartitionFile(void)
{
- if (primaryBootCheckBox->isChecked() != (enabled != 0))
- primaryBootCheckBox->setChecked(enabled);
+ QString path = PromptFileSelection();
- if (enabled)
- {
- primaryBootCheckBox->setEnabled(true);
- primaryBootLineEdit->setEnabled(true);
- primaryBootCheckBox->setChecked(true);
- }
- else
+ if (path != "")
{
- primaryBootCheckBox->setEnabled(primaryBootLineEdit->text() != "");
- primaryBootLineEdit->setEnabled(false);
+ workingPackageData.GetFirmwareInfo().GetFileInfos()[partitionsListWidget->currentRow()].SetFilename(path);
+ partitionFileLineEdit->setText(path);
+
+ pitBrowseButton->setEnabled(true);
+ partitionsListWidget->setEnabled(true);
+ UpdateStartButton();
+
+ if (unusedPartitionIds.length() > 0)
+ addPartitionButton->setEnabled(true);
}
-
- UpdateStartButton();
}
-void MainWindow::SetSecondaryBootloaderEnabled(int enabled)
+void MainWindow::SelectPartition(int row)
{
- if (secondaryBootCheckBox->isChecked() != (enabled != 0))
- secondaryBootCheckBox->setChecked(enabled);
-
- if (enabled)
+ if (row >= 0)
{
- secondaryBootCheckBox->setEnabled(true);
- secondaryBootLineEdit->setEnabled(true);
- secondaryBootCheckBox->setChecked(true);
+ const FileInfo& partitionInfo = workingPackageData.GetFirmwareInfo().GetFileInfos()[row];
+
+ UpdatePartitionNamesInterface();
+
+ partitionIdLineEdit->setText(QString::number(partitionInfo.GetPartitionId()));
+ partitionFileLineEdit->setText(partitionInfo.GetFilename());
+ partitionFileBrowseButton->setEnabled(true);
+
+ removePartitionButton->setEnabled(true);
}
else
{
- secondaryBootCheckBox->setEnabled(secondaryBootLineEdit->text() != "");
- secondaryBootLineEdit->setEnabled(false);
+ UpdatePartitionNamesInterface();
+
+ partitionIdLineEdit->clear();
+ partitionFileLineEdit->clear();
+ partitionFileBrowseButton->setEnabled(false);
+
+ removePartitionButton->setEnabled(false);
}
-
- UpdateStartButton();
}
-void MainWindow::SetCacheEnabled(int enabled)
+void MainWindow::AddPartition(void)
{
- if (cacheCheckBox->isChecked() != (enabled != 0))
- cacheCheckBox->setChecked(enabled);
+ FileInfo partitionInfo(unusedPartitionIds.first(), "");
+ workingPackageData.GetFirmwareInfo().GetFileInfos().append(partitionInfo);
+ UpdateUnusedPartitionIds();
- if (enabled)
- {
- cacheCheckBox->setEnabled(true);
- cacheLineEdit->setEnabled(true);
- cacheCheckBox->setChecked(true);
- }
- else
- {
- cacheCheckBox->setEnabled(cacheLineEdit->text() != "");
- cacheLineEdit->setEnabled(false);
- }
-
+ pitBrowseButton->setEnabled(false);
+ addPartitionButton->setEnabled(false);
+
+ partitionsListWidget->addItem(currentPitData.FindEntry(partitionInfo.GetPartitionId())->GetPartitionName());
+ partitionsListWidget->setCurrentRow(partitionsListWidget->count() - 1);
+ partitionsListWidget->setEnabled(false);
UpdateStartButton();
}
-void MainWindow::SetDatabaseEnabled(int enabled)
+void MainWindow::RemovePartition(void)
{
- if (databaseCheckBox->isChecked() != (enabled != 0))
- databaseCheckBox->setChecked(enabled);
+ workingPackageData.GetFirmwareInfo().GetFileInfos().removeAt(partitionsListWidget->currentRow());
+ UpdateUnusedPartitionIds();
- if (enabled)
- {
- databaseCheckBox->setEnabled(true);
- databaseLineEdit->setEnabled(true);
- databaseCheckBox->setChecked(true);
- }
- else
- {
- databaseCheckBox->setEnabled(databaseLineEdit->text() != "");
- databaseLineEdit->setEnabled(false);
- }
-
+ QListWidgetItem *item = partitionsListWidget->currentItem();
+ partitionsListWidget->setCurrentRow(-1);
+ delete item;
+
+ pitBrowseButton->setEnabled(true);
+ addPartitionButton->setEnabled(true);
+ partitionsListWidget->setEnabled(true);
UpdateStartButton();
}
-void MainWindow::SetModemEnabled(int enabled)
+void MainWindow::SelectPit(void)
{
- if (modemCheckBox->isChecked() != (enabled != 0))
- modemCheckBox->setChecked(enabled);
+ QString path = PromptFileSelection();
+ bool validPit = path != "";
+
+ // In order to map files in the old PIT to file in the new one, we first must use partition names instead of IDs.
+ QList<FileInfo> fileInfos = workingPackageData.GetFirmwareInfo().GetFileInfos();
+
+ int partitionNamesCount = fileInfos.length();
+ QString *partitionNames = new QString[fileInfos.length()];
+ for (int i = 0; i < fileInfos.length(); i++)
+ partitionNames[i] = currentPitData.FindEntry(fileInfos[i].GetPartitionId())->GetPartitionName();
- if (enabled)
+ currentPitData.Clear();
+
+ if (validPit)
{
- modemCheckBox->setEnabled(true);
- modemLineEdit->setEnabled(true);
- modemCheckBox->setChecked(true);
+ QFile pitFile(path);
+
+ if (ReadPit(&pitFile))
+ {
+ workingPackageData.GetFirmwareInfo().SetPitFilename(path);
+
+ partitionsListWidget->clear();
+ int partitionInfoIndex = 0;
+
+ for (int i = 0; i < partitionNamesCount; i++)
+ {
+ const PitEntry *pitEntry = currentPitData.FindEntry(partitionNames[i].toAscii().constData());
+
+ if (pitEntry)
+ {
+ fileInfos[partitionInfoIndex++].SetPartitionId(pitEntry->GetPartitionIdentifier());
+ partitionsListWidget->addItem(pitEntry->GetPartitionName());
+ }
+ else
+ {
+ fileInfos.removeAt(partitionInfoIndex);
+ }
+ }
+ }
+ else
+ {
+ validPit = false;
+ }
}
- else
+
+ // If the selected PIT was invalid, attempt to reload the old one.
+ if (!validPit)
{
- modemCheckBox->setEnabled(databaseLineEdit->text() != "");
- modemLineEdit->setEnabled(false);
+ // TODO: "The file selected was not a valid PIT file."
+ QFile originalPitFile(workingPackageData.GetFirmwareInfo().GetPitFilename());
+
+ if (ReadPit(&originalPitFile))
+ {
+ validPit = true;
+ }
+ else
+ {
+ // TODO: "Failed to reload working PIT data."
+ workingPackageData.Clear();
+ partitionsListWidget->clear();
+ }
}
-
+
+ UpdateUnusedPartitionIds();
+
+ delete [] partitionNames;
+
+ pitLineEdit->setText(workingPackageData.GetFirmwareInfo().GetPitFilename());
+
+ repartitionCheckBox->setEnabled(validPit);
+ partitionsListWidget->setEnabled(validPit);
+
+ addPartitionButton->setEnabled(validPit);
+ removePartitionButton->setEnabled(validPit && partitionsListWidget->currentRow() >= 0);
+
UpdateStartButton();
}
-void MainWindow::SetRecoveryEnabled(int enabled)
+void MainWindow::SetRepartition(int enabled)
{
- if (recoveryCheckBox->isChecked() != (enabled != 0))
- recoveryCheckBox->setChecked(enabled);
-
- if (enabled)
- {
- recoveryCheckBox->setEnabled(true);
- recoveryLineEdit->setEnabled(true);
- recoveryCheckBox->setChecked(true);
- }
- else
- {
- recoveryCheckBox->setEnabled(databaseLineEdit->text() != "");
- recoveryLineEdit->setEnabled(false);
- }
-
- UpdateStartButton();
+ workingPackageData.GetFirmwareInfo().SetRepartition(enabled);
}
void MainWindow::StartFlash(void)
@@ -522,68 +631,13 @@ void MainWindow::StartFlash(void)
if (repartitionCheckBox->isChecked())
{
+ arguments.append("--repartition");
+
arguments.append("--pit");
arguments.append(pitLineEdit->text());
}
- if (factoryfsCheckBox->isChecked())
- {
- arguments.append("--factoryfs");
- arguments.append(factoryfsLineEdit->text());
- }
-
- if (kernelCheckBox->isChecked())
- {
- arguments.append("--kernel");
- arguments.append(kernelLineEdit->text());
- }
-
- if (paramCheckBox->isChecked())
- {
- arguments.append("--param");
- arguments.append(paramLineEdit->text());
- }
-
- if (primaryBootCheckBox->isChecked())
- {
- arguments.append("--primary-boot");
- arguments.append(primaryBootLineEdit->text());
- }
-
- if (secondaryBootCheckBox->isChecked())
- {
- arguments.append("--secondary-boot");
- arguments.append(secondaryBootLineEdit->text());
- }
-
- if (cacheCheckBox->isChecked())
- {
- arguments.append("--cache");
- arguments.append(cacheLineEdit->text());
- }
-
- if (databaseCheckBox->isChecked())
- {
- arguments.append("--dbdata");
- arguments.append(databaseLineEdit->text());
- }
-
- if (modemCheckBox->isChecked())
- {
- arguments.append("--modem");
- arguments.append(modemLineEdit->text());
- }
-
- if (recoveryCheckBox->isChecked())
- {
- arguments.append("--recovery");
- arguments.append(recoveryLineEdit->text());
- }
-
- if (repartitionCheckBox->isChecked())
- {
- arguments.append("--repartition");
- }
+ // TODO: Loop through partitions and append them.
flashProgressBar->setEnabled(true);
UpdateStartButton();
@@ -600,13 +654,13 @@ void MainWindow::StartFlash(void)
QStringList environment = QProcess::systemEnvironment();
QStringList paths;
- // Ensure /usr/local/bin is in PATH
+ // Ensure /usr/bin is in PATH
for (int i = 0; i < environment.length(); i++)
{
if (environment[i].left(5) == "PATH=")
{
paths = environment[i].mid(5).split(':');
- paths.prepend("/usr/local/bin");
+ paths.prepend("/usr/bin");
break;
}
}
@@ -640,6 +694,140 @@ void MainWindow::StartFlash(void)
}
}
+void MainWindow::FirmwareNameChanged(const QString& text)
+{
+ workingPackageData.GetFirmwareInfo().SetName(text);
+ UpdateBuildPackageButton();
+}
+
+void MainWindow::FirmwareVersionChanged(const QString& text)
+{
+ workingPackageData.GetFirmwareInfo().SetVersion(text);
+ UpdateBuildPackageButton();
+}
+
+void MainWindow::PlatformNameChanged(const QString& text)
+{
+ workingPackageData.GetFirmwareInfo().GetPlatformInfo().SetName(text);
+ UpdateBuildPackageButton();
+}
+
+void MainWindow::PlatformVersionChanged(const QString& text)
+{
+ workingPackageData.GetFirmwareInfo().GetPlatformInfo().SetVersion(text);
+ UpdateBuildPackageButton();
+}
+
+void MainWindow::HomepageUrlChanged(const QString& text)
+{
+ workingPackageData.GetFirmwareInfo().SetUrl(text);
+}
+
+void MainWindow::DonateUrlChanged(const QString& text)
+{
+ workingPackageData.GetFirmwareInfo().SetDonateUrl(text);
+}
+
+void MainWindow::DeveloperNameChanged(const QString& text)
+{
+ if (text.isEmpty())
+ addDeveloperButton->setEnabled(false);
+ else
+ addDeveloperButton->setEnabled(true);
+}
+
+void MainWindow::SelectDeveloper(int row)
+{
+ if (row >= 0)
+ removeDeveloperButton->setEnabled(true);
+ else
+ removeDeveloperButton->setEnabled(false);
+}
+
+void MainWindow::AddDeveloper(void)
+{
+ workingPackageData.GetFirmwareInfo().GetDevelopers().append(createDeveloperNameLineEdit->text());
+
+ createDevelopersListWidget->addItem(createDeveloperNameLineEdit->text());
+ createDeveloperNameLineEdit->clear();
+
+ UpdateBuildPackageButton();
+}
+
+void MainWindow::RemoveDeveloper(void)
+{
+ workingPackageData.GetFirmwareInfo().GetDevelopers().removeAt(createDevelopersListWidget->currentRow());
+
+ QListWidgetItem *item = createDevelopersListWidget->currentItem();
+ createDevelopersListWidget->setCurrentRow(-1);
+ delete item;
+
+ removeDeveloperButton->setEnabled(false);
+
+ UpdateBuildPackageButton();
+}
+
+void MainWindow::DeviceInfoChanged(const QString& text)
+{
+ if (deviceManufacturerLineEdit->text().isEmpty() || deviceNameLineEdit->text().isEmpty() || deviceProductCodeLineEdit->text().isEmpty())
+ addDeviceButton->setEnabled(false);
+ else
+ addDeviceButton->setEnabled(true);
+}
+
+void MainWindow::SelectDevice(int row)
+{
+ if (row >= 0)
+ removeDeviceButton->setEnabled(true);
+ else
+ removeDeviceButton->setEnabled(false);
+}
+
+void MainWindow::AddDevice(void)
+{
+ workingPackageData.GetFirmwareInfo().GetDeviceInfos().append(DeviceInfo(deviceManufacturerLineEdit->text(), deviceNameLineEdit->text(),
+ deviceProductCodeLineEdit->text()));
+
+ createDevicesListWidget->addItem(deviceManufacturerLineEdit->text() + " " + deviceNameLineEdit->text() + " (" + deviceProductCodeLineEdit->text() + ")");
+ deviceManufacturerLineEdit->clear();
+ deviceNameLineEdit->clear();
+ deviceProductCodeLineEdit->clear();
+
+ UpdateBuildPackageButton();
+}
+
+void MainWindow::RemoveDevice(void)
+{
+ workingPackageData.GetFirmwareInfo().GetDeviceInfos().removeAt(createDevicesListWidget->currentRow());
+
+ QListWidgetItem *item = createDevicesListWidget->currentItem();
+ createDevicesListWidget->setCurrentRow(-1);
+ delete item;
+
+ removeDeviceButton->setEnabled(false);
+
+ UpdateBuildPackageButton();
+}
+
+void MainWindow::BuildPackage(void)
+{
+ QString packagePath = PromptFileCreation();
+
+ if (!packagePath.endsWith(".tar.gz", Qt::CaseInsensitive))
+ {
+ if (packagePath.endsWith(".tar", Qt::CaseInsensitive))
+ packagePath.append(".gz");
+ else if (packagePath.endsWith(".gz", Qt::CaseInsensitive))
+ packagePath.replace(packagePath.length() - 3, ".tar.gz");
+ else if (packagePath.endsWith(".tgz", Qt::CaseInsensitive))
+ packagePath.replace(packagePath.length() - 4, ".tar.gz");
+ else
+ packagePath.append(".tar.gz");
+ }
+
+ Packaging::BuildPackage(packagePath, workingPackageData);
+}
+
void MainWindow::HandleHeimdallStdout(void)
{
QString output = process.read(1024);