Repository navigation
Expand file tree
/
Copy pathmultiarchive.cpp
More file actions
75 lines (65 loc) · 2.83 KB
/
Copy pathmultiarchive.cpp
File metadata and controls
75 lines (65 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// ============================================================
// multiarchive.cpp
// إدارة الملفات المتعددة (ZIP و TAR)
// ============================================================
#include "multiarchive.h"
#include "tarextract.h"
#include "tool.h"
#include <QFileDialog>
#include <QFileInfo>
#include <QListWidget>
#include <QStatusBar>
#include <QDebug>
// ============================================================
// دوال عامة (Public Functions)
// ============================================================
/**
* @brief تحميل وقراءة ملفات متعددة وعرضها في QListWidget
* @param listWidget مؤشر إلى QListWidget لعرض الملفات
* @param statusBar مؤشر إلى QStatusBar لعرض الحالة
*/
void MultiArchive::loadMultipleFiles(QListWidget *listWidget, QStatusBar *statusBar)
{
// 1. فتح نافذة اختيار الملفات المتعددة
QStringList filePaths = QFileDialog::getOpenFileNames(
nullptr,
"اختر ملفات متعددة",
"",
"Archives (*.zip *.tar *.tgz *.tar.gz *.tbz *.tar.bz *.tbz2 *.tar.bz2 *.tar.xz)"
);
// 2. إذا لم يختر المستخدم ملفات، أوقف التنفيذ
if (filePaths.isEmpty()) {
qDebug() << "⚠️ لم يتم اختيار أي ملف";
return;
}
// 3. تنظيف القائمة وعرض رسالة الحالة
listWidget->clear();
statusBar->showMessage("✅ تم اختيار " + QString::number(filePaths.size()) + " ملف", 5000);
// 4. معالجة كل ملف تم اختياره
for (const QString &filePath : filePaths) {
// 4a. عرض اسم الملف
listWidget->addItem("━━━━━━━━━━━━━━━━━━━━");
listWidget->addItem("📦 " + QFileInfo(filePath).fileName());
listWidget->addItem("━━━━━━━━━━━━━━━━━━━━");
// 4b. قراءة محتويات الملف حسب نوعه
QString errorMessage;
QStringList entries;
if (QFileInfo(filePath).suffix().compare("zip", Qt::CaseInsensitive) == 0) {
entries = getArchiveContents(filePath, errorMessage);
} else if (isSupportedTarArchive(filePath)) {
entries = getTarArchiveContents(filePath, errorMessage);
} else {
errorMessage = "Unsupported archive format.";
}
// 4c. عرض محتويات الملف في القائمة
if (!errorMessage.isEmpty()) {
listWidget->addItem(" Error: " + errorMessage);
} else {
for (const QString &entry : entries) {
listWidget->addItem(" " + entry);
}
}
// 4e. إضافة سطر فاصل بين الملفات
listWidget->addItem("");
}
}