-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.qml
More file actions
664 lines (585 loc) · 31.3 KB
/
main.qml
File metadata and controls
664 lines (585 loc) · 31.3 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Theme
import org.qfield
import org.qgis
import QtCore
Item {
id: rootItem
property var mainWindow: iface.mainWindow()
// =========================================================================
// 0. INTERNATIONALISATION (I18N)
// =========================================================================
property string currentLang: "en"
function detectLanguage() {
var loc = Qt.locale().name.substring(0, 2);
if (loc === "fr") rootItem.currentLang = "fr";
else rootItem.currentLang = "en";
}
property var translations: {
"title": { "en": "PLUGIN UPDATER", "fr": "MISE À JOUR DES PLUGINS" },
"select_placeholder": { "en": "Select a plugin", "fr": "Sélectionner un plugin" },
"or_custom": { "en": "OR custom URL:", "fr": "OU une URL personnalisée :" },
"destination": { "en": "Target destination:", "fr": "Dossier de destination :" },
"installed_ver": { "en": "Installed version: ", "fr": "Version installée : " },
"btn_wait": { "en": "WAIT...", "fr": "ATTENTE..." },
"btn_install": { "en": "INSTALL NOW", "fr": "INSTALLER" },
"btn_update": { "en": "UPDATE", "fr": "METTRE À JOUR" },
"status_checking": { "en": "Checking for updates...", "fr": "Recherche de mises à jour..." },
"status_scanning": { "en": "🔍 Scanning installed plugins...", "fr": "🔍 Scan des plugins..." },
"status_uptodate": { "en": "✔ All plugins are up to date.", "fr": "✔ Tout est à jour." },
"status_updates_found": { "en": "🚀 Updates found:\n", "fr": "🚀 Mises à jour trouvées :\n" },
"search_step": { "en": "Searching", "fr": "Recherche" },
"source_direct": { "en": "Source: Direct Link", "fr": "Source : Lien direct" },
"wait_search": { "en": "Please wait for search to finish...", "fr": "Attendez la fin de la recherche..." },
"select_warn": { "en": "⚠️ Please select a plugin.", "fr": "⚠️ Sélectionnez un plugin." },
"check_release": { "en": "Checking releases...", "fr": "Vérification des versions..." },
"json_error": { "en": "JSON Error.", "fr": "Erreur JSON." },
"api_error": { "en": "API Error", "fr": "Erreur API" },
"ratelimit_error": { "en": "⚠️ GitHub Rate Limit Reached (403). Try again later.", "fr": "⚠️ Limite GitHub atteinte (403). Réessayez plus tard." },
"no_repo": { "en": "❌ No relevant repository found.", "fr": "❌ Aucun dépôt trouvé." },
"available": { "en": "Available: ", "fr": "Disponible : " },
"found": { "en": "Found: ", "fr": "Trouvé : " },
"no_zip": { "en": "No zip found. Using Main.", "fr": "Aucun zip trouvé. Utilisation de Main." },
"downloading": { "en": "Downloading", "fr": "Téléchargement" },
"extracting": { "en": "Extracting files...", "fr": "Extraction des fichiers..." },
"error": { "en": "❌ Error: ", "fr": "❌ Erreur : " },
"installed": { "en": "✔ Installed", "fr": "✔ Installé" },
"restart": { "en": "\nRestart recommended.", "fr": "\nRedémarrage recommandé." }
}
function tr(key) {
if (translations[key]) {
return translations[key][rootItem.currentLang] || translations[key]["en"];
}
return key;
}
// =========================================================================
// 1. ETAT ET VARIABLES
// =========================================================================
property string finalDownloadUrl: ""
property string preparedUrl: ""
property string targetUuid: ""
property string targetName: ""
property string targetAuthor: ""
property string detectedVersion: ""
property string installedVersion: ""
property string displayUrl: ""
property string targetFolderDisplay: "..."
property bool isWorking: false
property bool isFinished: false
property bool isSelfUpdate: false
property bool updatesChecked: false
property var pluginsQueue: []
property string updatesResultText: tr("status_checking")
property bool isCheckingUpdates: false
// AJOUT : Dictionnaire des dépôts connus pour éviter la recherche
property var knownRepositories: {
"qfield-filter-plugin": "woupss/qfield-filter-plugin",
"qfield-update-qgz-project": "woupss/qfield-update-qgz-project",
"qfield-plugin-update": "woupss/qfield-plugin-update",
"qfield-theme-position-color": "woupss/qfield-theme-position-color",
"qfield-pluginsbox": "woupss/qfield-pluginsbox",
"qfield-plugin-reloader": "gacarrillor/qfield-plugin-reloader",
"qfield-layer-loader": "mbernasocchi/qfield-layer-loader",
"DeleteViaDropdown": "TyHol/DeleteViaDropdown",
"qfield-osrm": "opengisch/qfield-osrm",
"qfield-nominatim-locator": "opengisch/qfield-nominatim-locator",
"FeelGood-UITweaker": "FeelGood-GeoSolutions/FeelGood-UITweaker",
"vocalpoint-qfield-plugin": "SeqLaz/vocalpoint-qfield-plugin",
"TrackedFeatureMarker": "danielseisenbacher/TrackedFeatureMarker",
"qfield-boxbox": "paul-carteron/qfield-boxbox",
"FeelGood-OneTapMeasurement": "FeelGood-GeoSolutions/FeelGood-OneTapMeasurement",
"qfield-snap": "opengisch/qfield-snap",
"qfield-image-based-feature-creation": "danielseisenbacher/qfield-image-based-feature-creation",
"qfield-ask-ai": "mbernasocchi/qfield-ask-ai",
"qfield-geomapfish-locator": "opengisch/qfield-geomapfish-locator",
"Qfield_Convert_Coords": "TyHol/Qfield_Convert_Coords",
"Qfield_search_Irish_UK_Grid": "TyHol/Qfield_search_Irish_UK_Grid",
"qfield-geometryless-addition": "opengisch/qfield-geometryless-addition",
"Qfield-Past-Geometry-Plugin": "qsavoye/Qfield-Past-Geometry-Plugin",
"qfield-weather-forecast": "opengisch/qfield-weather-forecast"
}
// =========================================================================
// 2. LOGIQUE METIER
// =========================================================================
function cleanVersion(v) {
if (!v) return "";
return v.replace(/^[vV]/, "").trim();
}
function isNewerVersion(currentVer, onlineVer) {
var v1 = cleanVersion(currentVer).split('.');
var v2 = cleanVersion(onlineVer).split('.');
var len = Math.max(v1.length, v2.length);
for (var i = 0; i < len; i++) {
var num1 = (i < v1.length) ? parseInt(v1[i]) : 0;
var num2 = (i < v2.length) ? parseInt(v2[i]) : 0;
if (isNaN(num1)) num1 = 0;
if (isNaN(num2)) num2 = 0;
if (num2 > num1) return true;
if (num1 > num2) return false;
}
return false;
}
function startGlobalUpdateCheck() {
if (rootItem.updatesChecked) return;
rootItem.pluginsQueue = [];
rootItem.updatesResultText = tr("status_scanning");
rootItem.isCheckingUpdates = true;
if (typeof pluginManager === "undefined" || !pluginManager.availableAppPlugins) return;
var plugins = pluginManager.availableAppPlugins;
for (var i = 0; i < plugins.length; i++) {
rootItem.pluginsQueue.push({ name: plugins[i].name, version: plugins[i].version, uuid: plugins[i].uuid });
}
updateQueueTimer.start();
}
Timer {
id: updateQueueTimer
interval: 1500; repeat: true
onTriggered: {
if (rootItem.pluginsQueue.length > 0) {
var p = rootItem.pluginsQueue.shift();
checkSinglePluginUpdate(p);
} else {
updateQueueTimer.stop();
rootItem.isCheckingUpdates = false;
rootItem.updatesChecked = true;
if (rootItem.updatesResultText === tr("status_scanning")) {
rootItem.updatesResultText = tr("status_uptodate");
}
}
}
}
// AJOUT: Gestion des erreurs de limite API
function handleRateLimitError() {
updateQueueTimer.stop();
rootItem.isCheckingUpdates = false;
var msg = "\n" + tr("ratelimit_error");
if (rootItem.updatesResultText.indexOf("403") === -1) {
rootItem.updatesResultText += msg;
}
statusText.text = "Error 403: API Limit";
statusText.color = "red";
}
// MODIFICATION: Logique intelligente utilisant knownRepositories
function checkSinglePluginUpdate(pluginObj) {
// 1. Optimisation : Vérifier si le plugin est dans notre liste connue
var repoSlug = knownRepositories[pluginObj.uuid] || knownRepositories[pluginObj.name];
if (repoSlug) {
var directUrl = "https://api.github.com/repos/" + repoSlug;
getLatestTag(directUrl, pluginObj);
return;
}
// 2. Si inconnu, on utilise l'API de recherche (plus coûteuse)
var query = encodeURIComponent(pluginObj.name + " qfield");
var apiUrl = "https://api.github.com/search/repositories?q=" + query + "&sort=stars&order=desc&per_page=1";
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
try {
var response = JSON.parse(xhr.responseText);
if (response.items && response.items.length > 0) getLatestTag(response.items[0].url, pluginObj);
} catch (e) {}
} else if (xhr.status === 403) {
handleRateLimitError();
}
}
}
xhr.open("GET", apiUrl);
xhr.setRequestHeader("User-Agent", "QField-Plugin-Installer");
xhr.send();
}
function getLatestTag(repoUrl, pluginObj) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
try {
var response = JSON.parse(xhr.responseText);
var remoteVer = "";
if (Array.isArray(response) && response.length > 0) remoteVer = response[0].name || response[0].tag_name;
else if (response.tag_name) remoteVer = response.tag_name;
else if (response.name) remoteVer = response.name;
if (remoteVer !== "" && isNewerVersion(pluginObj.version, remoteVer)) {
appendUpdateMessage(pluginObj.name, pluginObj.version, remoteVer);
}
} catch (e) {}
} else if (xhr.status === 403) {
handleRateLimitError();
}
}
}
xhr.open("GET", repoUrl + "/releases/latest");
xhr.setRequestHeader("User-Agent", "QField-Plugin-Installer");
xhr.send();
}
function appendUpdateMessage(name, oldVer, newVer) {
if (rootItem.updatesResultText.indexOf("Scanning") !== -1 || rootItem.updatesResultText.indexOf("Scan") !== -1) {
rootItem.updatesResultText = tr("status_updates_found");
}
rootItem.updatesResultText += "• " + name + ": " + oldVer + " ➡ " + newVer + "\n";
}
function getRepoSlug(url) {
if (!url || url.indexOf("github.com") === -1) return "";
var clean = url.replace("https://github.com/", "").replace("http://github.com/", "");
clean = clean.split("/archive")[0]; clean = clean.split("/releases")[0];
var parts = clean.split("/");
if (parts.length >= 2) return parts[0] + "/" + parts[1];
return "";
}
function startSmartSearch() { searchGitHubBroad(rootItem.targetName + " qfield", 1); }
function searchGitHubBroad(queryTerm, step) {
statusText.text = tr("search_step") + " (" + step + "): '" + queryTerm + "'...";
statusText.color = "gray";
var apiUrl = "https://api.github.com/search/repositories?q=" + encodeURIComponent(queryTerm) + "&sort=stars&order=desc&per_page=5";
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
try {
var response = JSON.parse(xhr.responseText);
var items = response.items || [];
if (items.length > 0) {
var bestRepo = findBestMatch(items);
if (bestRepo) checkGitHubRelease(bestRepo.full_name, bestRepo.html_url, false);
else tryNextSearchStep(step);
} else tryNextSearchStep(step);
} catch (e) { statusText.text = "❌ " + tr("json_error"); }
} else if (xhr.status === 403) {
statusText.text = tr("ratelimit_error");
statusText.color = "red";
} else {
statusText.text = "❌ " + tr("api_error") + " (" + xhr.status + ")";
}
}
}
xhr.open("GET", apiUrl); xhr.setRequestHeader("User-Agent", "QField-Plugin-Installer"); xhr.send();
}
function tryNextSearchStep(currentStep) {
if (currentStep === 1) {
if (rootItem.targetUuid !== "") searchGitHubBroad(rootItem.targetUuid, 2);
else handleSearchFailure();
} else if (currentStep === 2) {
searchGitHubBroad(rootItem.targetName, 3);
} else handleSearchFailure();
}
function handleSearchFailure() { statusText.text = tr("no_repo"); statusText.color = "red"; }
function findBestMatch(items) {
var bestItem = null; var maxScore = 0; var threshold = 15;
var targetUuidClean = rootItem.targetUuid.toLowerCase().replace(/_/g, "-");
var targetAuthorClean = rootItem.targetAuthor.toLowerCase();
var authorParts = targetAuthorClean.split(" ");
var primaryAuthorName = authorParts.length > 0 ? authorParts[0] : targetAuthorClean;
for (var i = 0; i < items.length; i++) {
var item = items[i]; var score = 0;
var repoName = item.name.toLowerCase(); var repoOwner = item.owner.login.toLowerCase();
var desc = (item.description || "").toLowerCase();
if (targetAuthorClean !== "" && (repoOwner.indexOf(primaryAuthorName) !== -1 || targetAuthorClean.indexOf(repoOwner) !== -1)) score += 30;
if (rootItem.targetUuid !== "" && (repoName === targetUuidClean || repoName === rootItem.targetUuid.toLowerCase())) score += 20;
else if (repoName.indexOf(targetUuidClean) !== -1) score += 10;
if (desc.indexOf("qfield") !== -1 || repoName.indexOf("qfield") !== -1) score += 10;
if (item.stargazers_count > 10) score += 5;
if (score > maxScore) { maxScore = score; bestItem = item; }
}
return maxScore >= threshold ? bestItem : null;
}
function checkGitHubRelease(repoSlug, fallbackUrl, autoInstall) {
var apiUrl = "https://api.github.com/repos/" + repoSlug + "/releases/latest?t=" + new Date().getTime();
if (!autoInstall) statusText.text = tr("check_release");
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) processSingleRelease(xhr.responseText, fallbackUrl, autoInstall);
else if (xhr.status === 403) { statusText.text = tr("ratelimit_error"); statusText.color = "red"; }
else checkGitHubAllReleases(repoSlug, fallbackUrl, autoInstall);
}
}
xhr.open("GET", apiUrl); xhr.setRequestHeader("User-Agent", "QField-Plugin-Installer"); xhr.send();
}
function checkGitHubAllReleases(repoSlug, fallbackUrl, autoInstall) {
var apiUrl = "https://api.github.com/repos/" + repoSlug + "/releases?per_page=1&t=" + new Date().getTime();
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) processListResponse(xhr.responseText, fallbackUrl, autoInstall, "Release");
else checkGitHubTags(repoSlug, fallbackUrl, autoInstall);
}
}
xhr.open("GET", apiUrl); xhr.setRequestHeader("User-Agent", "QField-Plugin-Installer"); xhr.send();
}
function checkGitHubTags(repoSlug, fallbackUrl, autoInstall) {
var apiUrl = "https://api.github.com/repos/" + repoSlug + "/tags?per_page=1&t=" + new Date().getTime();
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) processListResponse(xhr.responseText, fallbackUrl, autoInstall, "Tag");
else handleError(fallbackUrl, autoInstall, "API Error " + xhr.status + ". Using Main.");
}
}
xhr.open("GET", apiUrl); xhr.setRequestHeader("User-Agent", "QField-Plugin-Installer"); xhr.send();
}
function processSingleRelease(jsonText, fallbackUrl, autoInstall) {
try { extractAndFinish(JSON.parse(jsonText), fallbackUrl, autoInstall); }
catch (e) { handleError(fallbackUrl, autoInstall, tr("json_error")); }
}
function processListResponse(jsonText, fallbackUrl, autoInstall, typeLabel) {
try {
var response = JSON.parse(jsonText);
if (Array.isArray(response) && response.length > 0) extractAndFinish(response[0], fallbackUrl, autoInstall);
else handleError(fallbackUrl, autoInstall, "No " + typeLabel + " found. Using Main.");
} catch (e) { handleError(fallbackUrl, autoInstall, tr("json_error")); }
}
function extractAndFinish(obj, fallbackUrl, autoInstall) {
var versionTag = obj.tag_name || obj.name || "Unknown"; var foundAsset = "";
if (obj.assets && obj.assets.length > 0) {
for (var i = 0; i < obj.assets.length; i++) {
if (obj.assets[i].name.toLowerCase().endsWith(".zip")) { foundAsset = obj.assets[i].browser_download_url; break; }
}
}
if (foundAsset === "") foundAsset = obj.zipball_url;
if (foundAsset) {
rootItem.detectedVersion = versionTag; rootItem.preparedUrl = foundAsset; rootItem.displayUrl = foundAsset;
if (!autoInstall) { statusText.text = tr("available") + versionTag; statusText.color = "blue"; }
else { statusText.text = tr("found") + versionTag; executeInstallation(foundAsset); }
} else { handleError(fallbackUrl, autoInstall, tr("no_zip")); }
}
function handleError(fallbackUrl, autoInstall, msg) {
rootItem.detectedVersion = "Main (Dev)"; rootItem.preparedUrl = fallbackUrl; rootItem.displayUrl = fallbackUrl;
if (!autoInstall) { statusText.text = msg; statusText.color = "#888"; }
else { statusText.text = msg; executeInstallation(fallbackUrl); }
}
// MODIFICATION: Logique de pré-vérification pour utiliser knownRepositories
function preCheckVersion() {
rootItem.detectedVersion = ""; rootItem.preparedUrl = ""; rootItem.displayUrl = ""; statusText.text = "";
var customUrl = urlField.text.trim();
if (customUrl !== "") {
var slug = getRepoSlug(customUrl);
if (slug !== "") checkGitHubRelease(slug, customUrl, false);
else { statusText.text = tr("source_direct"); rootItem.preparedUrl = customUrl; rootItem.displayUrl = customUrl; }
updateTargetDisplay(); return;
}
if (pluginCombo.currentIndex !== -1) {
// Vérification si le plugin est connu
var knownSlug = knownRepositories[rootItem.targetUuid] || knownRepositories[rootItem.targetName];
if (knownSlug) {
checkGitHubRelease(knownSlug, "", false);
} else {
startSmartSearch();
}
updateTargetDisplay();
}
}
function updateTargetDisplay() {
var customUrl = urlField.text.trim();
if (customUrl !== "") {
var slug = getRepoSlug(customUrl);
if (slug !== "") rootItem.targetFolderDisplay = ".../plugins/" + slug.split("/")[1];
else rootItem.targetFolderDisplay = ".../plugins/CustomPlugin";
} else if (pluginCombo.currentIndex !== -1) {
if (rootItem.targetUuid !== "") rootItem.targetFolderDisplay = ".../plugins/" + rootItem.targetUuid;
else rootItem.targetFolderDisplay = ".../plugins/" + rootItem.targetName.replace(/\s+/g, '');
} else { rootItem.targetFolderDisplay = "..."; }
}
function startProcess() {
var customUrl = urlField.text.trim();
statusText.color = "black"; rootItem.isWorking = true; rootItem.isFinished = false;
progressBar.value = 0; progressBar.indeterminate = true; rootItem.isSelfUpdate = false;
if (rootItem.installedVersion !== "") rootItem.isSelfUpdate = true;
if (customUrl !== "") {
var slug = getRepoSlug(customUrl);
if (slug !== "") checkGitHubRelease(slug, customUrl, true);
else executeInstallation(customUrl);
return;
}
if (pluginCombo.currentIndex !== -1) {
if (rootItem.preparedUrl !== "") executeInstallation(rootItem.preparedUrl);
else { statusText.text = tr("wait_search"); rootItem.isWorking = false; progressBar.indeterminate = false; }
} else { statusText.text = tr("select_warn"); statusText.color = "red"; rootItem.isWorking = false; }
}
function executeInstallation(finalUrl) {
rootItem.finalDownloadUrl = finalUrl;
installTimer.start();
}
Timer { id: installTimer; interval: 500; repeat: false; onTriggered: pluginManager.installFromUrl(rootItem.finalDownloadUrl) }
Connections {
target: pluginManager
function onInstallProgress(progress) {
progressBar.indeterminate = false; progressBar.value = progress; statusText.color = "#333";
var verInfo = rootItem.detectedVersion !== "" ? "(" + rootItem.detectedVersion + ")" : "";
if (progress < 1) statusText.text = tr("downloading") + " " + verInfo + ": " + Math.round(progress*100) + "%";
else statusText.text = tr("extracting");
}
function onInstallEnded(uuid, error) {
rootItem.isWorking = false; progressBar.value = 1.0; progressBar.indeterminate = false;
if (error && error !== "") { statusText.text = tr("error") + error; statusText.color = "red"; }
else {
rootItem.isFinished = true; var successMsg = tr("installed");
if (rootItem.detectedVersion !== "") successMsg += " " + rootItem.detectedVersion;
// Modification : Suppression du message de redémarrage ici (comme demandé par votre code cible)
statusText.text = successMsg;
statusText.color = "green";
if (pluginManager.pluginModel) pluginManager.pluginModel.refresh(false);
}
}
}
Component.onCompleted: {
detectLanguage();
iface.addItemToPluginsToolbar(toolbarButton);
}
QfToolButton {
id: toolbarButton
iconSource: "icon.svg"; iconColor: Theme.mainColor; bgcolor: Theme.darkGray; round: true
onClicked: {
pluginCombo.currentIndex = -1; urlField.text = ""; rootItem.isFinished = false;
rootItem.isWorking = false; progressBar.value = 0; statusText.text = "";
rootItem.detectedVersion = ""; rootItem.installedVersion = "";
rootItem.displayUrl = ""; rootItem.preparedUrl = ""; rootItem.targetFolderDisplay = "...";
rootItem.targetUuid = ""; rootItem.targetName = ""; rootItem.targetAuthor = "";
updateDialog.open(); startGlobalUpdateCheck();
}
}
// =========================================================================
// INTERFACE GRAPHIQUE
// =========================================================================
Dialog {
id: updateDialog
parent: mainWindow.contentItem
modal: true
padding: 0; topPadding: 0; bottomPadding: 0; leftPadding: 0; rightPadding: 0
width: Math.min(Math.max(350, mainLayout.implicitWidth + 40), mainWindow.width * 0.90)
height: mainLayout.implicitHeight + 20
anchors.centerIn: parent
standardButtons: Dialog.NoButton
onClosed: {}
background: Rectangle {
color: "white"; radius: 8; border.width: 2; border.color: Theme.mainColor
MouseArea { anchors.fill: parent; onClicked: { mainLayout.forceActiveFocus() } }
}
ColumnLayout {
id: mainLayout
anchors.fill: parent
// MARGES ET SPACING
anchors.topMargin: 10
anchors.bottomMargin: 10
anchors.leftMargin: 30
anchors.rightMargin: 30
spacing: 4
// TITRE (Traduit)
Label {
text: tr("title")
color: "black"
font.bold: true; font.pointSize: 16
Layout.alignment: Qt.AlignHCenter
Layout.topMargin: 0
Layout.bottomMargin: 10
}
RowLayout {
Layout.fillWidth: true
ComboBox {
id: pluginCombo; Layout.fillWidth: true
Layout.preferredHeight: 34
font.pixelSize: 14
textRole: "name"; model: pluginManager.availableAppPlugins
displayText: currentIndex === -1 ? tr("select_placeholder") : currentText
onActivated: {
urlField.text = "";
var plugins = pluginManager.availableAppPlugins;
if (index >= 0 && index < plugins.length) {
var p = plugins[index];
rootItem.installedVersion = p.version;
rootItem.targetName = p.name;
rootItem.targetUuid = p.uuid;
rootItem.targetAuthor = (p.author !== undefined) ? p.author : "";
} else {
rootItem.installedVersion = ""; rootItem.targetName = ""; rootItem.targetUuid = ""; rootItem.targetAuthor = "";
}
rootItem.displayUrl = ""; rootItem.preparedUrl = "";
preCheckVersion();
}
}
Button {
text: "✖"; visible: pluginCombo.currentIndex !== -1; Layout.preferredWidth: 40;
Layout.preferredHeight: 34
onClicked: {
pluginCombo.currentIndex = -1; statusText.text = ""; rootItem.detectedVersion = "";
rootItem.installedVersion = ""; rootItem.displayUrl = ""; updateTargetDisplay();
}
}
}
TextField {
visible: rootItem.displayUrl !== ""; Layout.fillWidth: true; text: rootItem.displayUrl; readOnly: true; selectByMouse: true
font.pixelSize: 12; color: "#555"; background: Rectangle { color: "#f0f0f0"; radius: 4 }
Layout.preferredHeight: 34
Layout.minimumHeight: 34
Layout.maximumHeight: 34
Layout.preferredWidth: 50
verticalAlignment: TextInput.AlignVCenter
}
Label { text: tr("or_custom"); font.bold: true; font.pixelSize: 14; Layout.topMargin: 2 }
TextField {
id: urlField; Layout.fillWidth: true; placeholderText: "https://github.com/user/repo"
selectByMouse: true;
font.pixelSize: 14
Layout.preferredHeight: 34
verticalAlignment: TextInput.AlignVCenter
onTextChanged: {
pluginCombo.currentIndex = -1; rootItem.installedVersion = ""; rootItem.displayUrl = "";
if(text.length > 10) preCheckVersion(); else updateTargetDisplay();
}
}
Label { text: tr("destination"); font.bold: true; font.pixelSize: 13 ; Layout.topMargin: 2 }
Rectangle {
Layout.fillWidth: true
Layout.preferredHeight: 32
color: "#e0e0e0"; radius: 4; border.color: "#999"
RowLayout {
anchors.fill: parent; anchors.leftMargin: 4; anchors.rightMargin: 4
Text { text: "📂"; font.pixelSize: 16; verticalAlignment: Text.AlignVCenter }
Text { text: rootItem.targetFolderDisplay; font.family: "Courier"; font.pixelSize: 13; color: "#333"; elide: Text.ElideMiddle; Layout.fillWidth: true; verticalAlignment: Text.AlignVCenter }
}
}
ProgressBar {
id: progressBar; Layout.fillWidth: true; Layout.topMargin: 2
from: 0; to: 1.0; value: 0; indeterminate: rootItem.isWorking && value === 0
visible: rootItem.isWorking || rootItem.isFinished
Layout.preferredHeight: 8
}
Text {
visible: rootItem.installedVersion !== ""
Layout.fillWidth: true; horizontalAlignment: Text.AlignHCenter; font.pixelSize: 14; color: "black"
text: tr("installed_ver") + rootItem.installedVersion
}
Text {
id: statusText; Layout.fillWidth: true; horizontalAlignment: Text.AlignHCenter
font.italic: true; color: "#555"; font.weight: rootItem.detectedVersion !== "" ? Font.Bold : Font.Normal
font.pixelSize: 14
wrapMode: Text.Wrap; text: ""
}
TextArea {
Layout.fillWidth: true
Layout.topMargin: 2
Layout.preferredHeight: Math.max(34, contentHeight + 4)
readOnly: true
text: rootItem.updatesResultText
color: "#333"
font.pixelSize: 13
background: Rectangle { color: "#f9f9f9"; radius: 4; border.color: "#ddd" }
leftPadding: 4; rightPadding: 4; topPadding: 4; bottomPadding: 4
}
Button {
Layout.alignment: Qt.AlignHCenter;
Layout.topMargin: 5
leftPadding: 20
rightPadding: 20
enabled: !rootItem.isWorking && (pluginCombo.currentIndex !== -1 || urlField.text !== "")
background: Rectangle { color: parent.enabled ? Theme.mainColor : "#bdc3c7"; radius: 4 }
contentItem: Text {
text: rootItem.isWorking ? tr("btn_wait") : (rootItem.preparedUrl !== "" ? tr("btn_install") : tr("btn_update"))
color: "white"; font.bold: true; font.pixelSize: 14; horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
}
onClicked: startProcess()
}
}
}
}