From f00bf62144a97669bd25dd8967474d9136b16921 Mon Sep 17 00:00:00 2001 From: uncor3 Date: Sun, 1 Feb 2026 01:13:23 +0000 Subject: [PATCH] add utils, enhance ui, remove debug stuff --- src/cableinfowidget.cpp | 3 +- src/devicedatabase.cpp | 2 +- src/gallerywidget.cpp | 12 ++-- src/iDescriptor-utils.h | 120 ++++++++++++++++++++++++++++++++++++++++ src/iDescriptor.h | 50 +---------------- src/servicemanager.cpp | 1 - 6 files changed, 131 insertions(+), 57 deletions(-) create mode 100644 src/iDescriptor-utils.h diff --git a/src/cableinfowidget.cpp b/src/cableinfowidget.cpp index 3d62c8a..b85b9b2 100644 --- a/src/cableinfowidget.cpp +++ b/src/cableinfowidget.cpp @@ -229,7 +229,8 @@ void CableInfoWidget::updateUI() if (!m_cableInfo.isConnected) { m_errorLabel->setText( - "Device does not seem to be connected to any cable."); + QString("%1 does not seem to be connected to any cable.") + .arg(m_device->deviceInfo.productType)); m_loadingWidget->showError(); return; } diff --git a/src/devicedatabase.cpp b/src/devicedatabase.cpp index 77dff79..5b5767f 100644 --- a/src/devicedatabase.cpp +++ b/src/devicedatabase.cpp @@ -570,5 +570,5 @@ std::string DeviceDatabase::parseRegionInfo(const std::string &code) if (code == "C/A") return "Canada (English, French)"; - return "Unknown Region (" + code + ")"; + return code; } \ No newline at end of file diff --git a/src/gallerywidget.cpp b/src/gallerywidget.cpp index 3c5b1d8..7a8929b 100644 --- a/src/gallerywidget.cpp +++ b/src/gallerywidget.cpp @@ -153,7 +153,9 @@ void GalleryWidget::setupControlsLayout() m_exportAllButton = new QPushButton("Export All"); // Back button - m_backButton = new QPushButton("← Back to Albums"); + m_backButton = new QPushButton("←"); + m_backButton->setToolTip("Back to Albums"); + m_backButton->setMaximumWidth(30); m_backButton->hide(); // Hidden initially // Connect signals @@ -491,8 +493,8 @@ void GalleryWidget::onAlbumSelected(const QString &albumPath) }); } - connect(m_model, &PhotoModel::thumbnailNeedsToBeLoaded, m_model, - &PhotoModel::requestThumbnail, Qt::QueuedConnection); + // connect(m_model, &PhotoModel::thumbnailNeedsToBeLoaded, m_model, + // &PhotoModel::requestThumbnail, Qt::QueuedConnection); // Set album path and load photos m_model->setAlbumPath(albumPath); @@ -506,8 +508,8 @@ void GalleryWidget::onAlbumSelected(const QString &albumPath) void GalleryWidget::onBackToAlbums() { if (m_model) { - disconnect(m_model, &PhotoModel::thumbnailNeedsToBeLoaded, m_model, - &PhotoModel::requestThumbnail); + // disconnect(m_model, &PhotoModel::thumbnailNeedsToBeLoaded, m_model, + // &PhotoModel::requestThumbnail); } // Switch back to album selection view diff --git a/src/iDescriptor-utils.h b/src/iDescriptor-utils.h new file mode 100644 index 0000000..b949c62 --- /dev/null +++ b/src/iDescriptor-utils.h @@ -0,0 +1,120 @@ +#include +#include +#include + +struct ProductTypeVersion { + int major; + int minor; + + ProductTypeVersion(int maj = 0, int min = 0) : major(maj), minor(min) {} + + // Compare two product type versions + // Returns: -1 if this < other, 0 if equal, 1 if this > other + int compareTo(const ProductTypeVersion &other) const + { + if (major != other.major) { + return major < other.major ? -1 : 1; + } + if (minor != other.minor) { + return minor < other.minor ? -1 : 1; + } + return 0; // Equal + } + + bool operator<(const ProductTypeVersion &other) const + { + return compareTo(other) < 0; + } + + bool operator==(const ProductTypeVersion &other) const + { + return compareTo(other) == 0; + } + + bool operator>(const ProductTypeVersion &other) const + { + return compareTo(other) > 0; + } +}; + +namespace iDescriptor +{ +class Utils +{ +private: + // Extract version numbers from iPhone product type string + // Example: "iPhone8,1" -> ProductTypeVersion{8, 1} + static ProductTypeVersion + extractProductTypeVersion(const std::string &productType) + { + // Regex to match iPhone followed by major,minor numbers + std::regex pattern(R"(iPhone(\d+),(\d+))"); + std::smatch matches; + + if (std::regex_search(productType, matches, pattern)) { + if (matches.size() >= 3) { + try { + int major = std::stoi(matches[1].str()); + int minor = std::stoi(matches[2].str()); + return ProductTypeVersion(major, minor); + } catch (const std::invalid_argument &e) { + throw std::invalid_argument( + "Invalid numeric values in product type: " + + productType); + } + } + } + + throw std::invalid_argument("Invalid iPhone product type format: " + + productType); + } + + static bool compare_product_type(const std::string &productType, + const std::string &otherProductType) + { + try { + ProductTypeVersion version1 = + extractProductTypeVersion(productType); + ProductTypeVersion version2 = + extractProductTypeVersion(otherProductType); + + // Return true if productType is newer/higher than otherProductType + return version1 > version2; + } catch (const std::exception &e) { + // Handle invalid product types - you might want to log this + return false; + } + } + +public: + static bool isProductTypeNewer(const std::string &productType, + const std::string &otherProductType) + { + return compare_product_type(productType, otherProductType); + } + + static QString formatSize(uint64_t bytes) + { + const char *units[] = {"B", "KB", "MB", "GB", "TB"}; + int unitIndex = 0; + double size = bytes; + + while (size >= 1024 && unitIndex < 4) { + size /= 1024; + unitIndex++; + } + + return QString("%1 %2") + .arg(QString::number(size, 'f', 1)) + .arg(units[unitIndex]); + }; + + static bool isVideoFile(const QString &fileName) + { + /* known iPhone video file extensions */ + return fileName.endsWith(".MOV", Qt::CaseInsensitive) || + fileName.endsWith(".MP4", Qt::CaseInsensitive) || + fileName.endsWith(".M4V", Qt::CaseInsensitive); + } +}; +} // namespace iDescriptor \ No newline at end of file diff --git a/src/iDescriptor.h b/src/iDescriptor.h index 1768d78..f7ed588 100644 --- a/src/iDescriptor.h +++ b/src/iDescriptor.h @@ -66,6 +66,7 @@ #define IDEVICE_DEVICE_VERSION(maj, min, patch) \ ((((maj) & 0xFF) << 16) | (((min) & 0xFF) << 8) | ((patch) & 0xFF)) #include "devicemonitor.h" +#include "iDescriptor-utils.h" #define DeviceLockedMountErrorCode -21 #define NotFoundErrorCode -14 @@ -475,53 +476,6 @@ struct ImageInfo { bool isMounted = false; }; -// /** -// * @brief Compare two iPhone product types to determine which is newer -// * @param productType First iPhone product type (e.g., "iPhone8,1") -// * @param otherProductType Second iPhone product type (e.g., "iPhone7,2") -// * @return true if productType is newer than otherProductType, false -// otherwise -// * -// * Examples: -// * - compare_product_type("iPhone8,1", "iPhone7,2") returns true -// * - compare_product_type("iPhone6,1", "iPhone8,1") returns false -// * - compare_product_type("iPhone8,2", "iPhone8,1") returns true -// */ -// bool compare_product_type(std::string productType, -// std::string otherProductType); - -// /** -// * @brief Check if two iPhone product types are exactly equal -// * @param productType First iPhone product type -// * @param otherProductType Second iPhone product type -// * @return true if both product types are identical -// */ -// bool are_product_types_equal(const std::string &productType, -// const std::string &otherProductType); - -// /** -// * @brief Check if first product type is newer than second -// * @param productType First iPhone product type -// * @param otherProductType Second iPhone product type -// * @return true if productType is newer than otherProductType -// */ -bool is_product_type_newer(const std::string &productType, - const std::string &otherProductType); - -// /** -// * @brief Check if first product type is older than second -// * @param productType First iPhone product type -// * @param otherProductType Second iPhone product type -// * @return true if productType is older than otherProductType -// */ -// bool is_product_type_older(const std::string &productType, -// const std::string &otherProductType); - -// bool query_mobile_gestalt(iDescriptorDevice *id_device, const QStringList -// &keys, -// uint32_t &xml_size, char *&xml_data); -// ; - // std::string safeGetXML(const char *key, pugi::xml_node dict); void get_battery_info(DiagnosticsRelay *diagRelay, plist_t &diagnostics); @@ -533,8 +487,6 @@ void fetchAppIconFromApple(QNetworkAccessManager *manager, const QString &bundleId, std::function callback); -// afc_error_t afc2_client_new(idevice_t device, afc_client_t *afc); - void _get_cable_info(const iDescriptorDevice *device, plist_t &response); struct NetworkDevice { diff --git a/src/servicemanager.cpp b/src/servicemanager.cpp index 4c07e13..dc4a3d7 100644 --- a/src/servicemanager.cpp +++ b/src/servicemanager.cpp @@ -274,7 +274,6 @@ IdeviceFfiError *ServiceManager::exportFileToPath( IdeviceFfiError *read_err = nullptr; // Read file in chunks while (true) { - std::this_thread::sleep_for(std::chrono::seconds(2)); // Check for cancellation if (cancelRequested && cancelRequested->load()) { fclose(out);