mirror of
https://github.com/iDescriptor/iDescriptor.git
synced 2026-06-22 03:45:51 +08:00
add utils, enhance ui, remove debug stuff
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
#include <regex>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
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
|
||||
+1
-49
@@ -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<void(const QPixmap &)> 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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user