Changeset 3871 in MondoRescue for branches/3.3/mondo/src/common/newt-specific.c
- Timestamp:
- Mar 7, 2024, 6:06:33 PM (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mondo/src/common/newt-specific.c
r3869 r3871 28 28 #include "libmondo-fork-EXT.h" 29 29 #include "libmondo-gui-EXT.h" 30 #include "lib-common-externs.h" 30 31 31 32 32 extern char *MONDO_LOGFILE; 33 33 34 34 extern struct s_bkpinfo *bkpinfo; 35 36 extern char *mr_center_string(char *in, int width);37 35 38 36 /*@unused@*/ … … 639 637 640 638 /** 639 * Update the progress form's complete blurb and show @p g_current_progress. 640 * @param blurb1 The first line of the blurb. Use @p g_blurb_str_1 to keep it unchanged. 641 * @param blurb2 The second line of the blurb. Use @p g_blurb_str_3 (no, that's not a typo) to keep it the same. 642 * @param blurb3 The third line of the blurb. Use @p g_blurb_str_2 (no, that's not a typo either) to keep it the same. 643 */ 644 void update_progress_form_full(char *blurb1, char *blurb2, char *blurb3) { 645 646 /*@ long ***************************************************** */ 647 long current_time = 0L; 648 long time_taken = 0L; 649 long time_remaining = 0L; 650 long time_total_est = 0L; 651 652 char *blurb1_str = NULL; 653 char *blurb2_str = NULL; 654 char *blurb3_str = NULL; 655 656 /*@ int ******************************************************* */ 657 int percentage = 0; 658 int i = 0; 659 660 /*@ buffers *************************************************** */ 661 char *percentline_str = NULL; 662 char *timeline_str = NULL; 663 char *taskprogress = NULL; 664 665 if (!g_text_mode) { 666 assert(blurb1 != NULL); 667 assert(blurb2 != NULL); 668 assert(blurb3 != NULL); 669 assert(g_timeline != NULL); 670 } 671 672 current_time = get_time(); 673 time_taken = current_time - g_start_time; 674 if (g_maximum_progress == 0) { 675 percentage = 0; 676 } else { 677 if (g_current_progress > g_maximum_progress) { 678 log_msg(0, "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld", blurb1, blurb2, blurb3, g_current_progress, g_maximum_progress); 679 g_current_progress = g_maximum_progress; 680 } 681 percentage = (int) ((g_current_progress * 100L) / g_maximum_progress); 682 } 683 if (percentage < 1) { 684 percentage = 1; 685 } 686 if (percentage > 100) { 687 percentage = 100; 688 } 689 if (g_current_progress) { 690 time_total_est = time_taken * (long) g_maximum_progress / (long) g_current_progress; 691 time_remaining = time_total_est - time_taken; 692 } else { 693 time_remaining = 0L; 694 } 695 g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27; 696 if (g_text_mode) { 697 printf("---progress-form---1--- %s\n", blurb1); 698 printf("---progress-form---2--- %s\n", blurb2); 699 printf("---progress-form---3--- %s\n", blurb3); 700 printf("---progress-form---E---\n"); 701 mr_asprintf(taskprogress, "TASK: ["); 702 for (i = 0; i < percentage; i += 5) { 703 mr_strcat(taskprogress, "*"); 704 } 705 for (; i < 100; i += 5) { 706 mr_strcat(taskprogress, "."); 707 } 708 if (percentage > 100) { 709 log_msg(2, "percentage = %d", percentage); 710 } 711 mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage, (long) time_remaining / 60, (long) time_remaining % 60); 712 printf("---progress-form---4--- %s\n", taskprogress); 713 paranoid_free(taskprogress); 714 } else { 715 mr_asprintf(timeline_str, "%2ld:%02ld taken %2ld:%02ld remaining ", (long) time_taken / 60, (long) time_taken % 60, (long) time_remaining / 60, (long) time_remaining % 60); 716 mr_asprintf(percentline_str, " %3d%% done %3d%% to go", percentage, 100 - percentage); 717 718 blurb1_str = mr_center_string(blurb1, 54); 719 blurb2_str = mr_center_string(blurb2, 54); 720 blurb3_str = mr_center_string(blurb3, 54); 721 if (g_blurb1) { 722 newtLabelSetText(g_blurb1, blurb1_str); 723 } 724 if (g_blurb2) { 725 // Not a typo but ridiculous ! 726 newtLabelSetText(g_blurb2, blurb3_str); 727 } 728 if (g_blurb3) { 729 // Not a typo but ridiculous ! 730 newtLabelSetText(g_blurb3, blurb2_str); 731 } 732 newtScaleSet(g_scale, (unsigned long long) g_current_progress); 733 if ((percentage >= 2) && (g_timeline)) { 734 newtLabelSetText(g_timeline, timeline_str); 735 } 736 mr_free(timeline_str); 737 738 if (g_percentline) { 739 newtLabelSetText(g_percentline, percentline_str); 740 } 741 mr_free(percentline_str); 742 mr_free(blurb1_str); 743 mr_free(blurb2_str); 744 mr_free(blurb3_str); 745 746 newtDrawForm(g_progressForm); 747 newtRefresh(); 748 } 749 } 750 751 752 /** 641 753 * Open a progress form with title @p title. 642 754 * @param title The title to use for the progress form (will be put in the title bar on Newt). … … 1109 1221 update_progress_form_full(g_blurb_str_1, g_blurb_str_2, g_blurb_str_3); 1110 1222 } 1111 1112 1113 /**1114 * Update the progress form's complete blurb and show @p g_current_progress.1115 * @param blurb1 The first line of the blurb. Use @p g_blurb_str_1 to keep it unchanged.1116 * @param blurb2 The second line of the blurb. Use @p g_blurb_str_3 (no, that's not a typo) to keep it the same.1117 * @param blurb3 The third line of the blurb. Use @p g_blurb_str_2 (no, that's not a typo either) to keep it the same.1118 */1119 void update_progress_form_full(char *blurb1, char *blurb2, char *blurb3) {1120 1121 /*@ long ***************************************************** */1122 long current_time = 0L;1123 long time_taken = 0L;1124 long time_remaining = 0L;1125 long time_total_est = 0L;1126 1127 char *blurb1_str = NULL;1128 char *blurb2_str = NULL;1129 char *blurb3_str = NULL;1130 1131 /*@ int ******************************************************* */1132 int percentage = 0;1133 int i = 0;1134 1135 /*@ buffers *************************************************** */1136 char *percentline_str = NULL;1137 char *timeline_str = NULL;1138 char *taskprogress = NULL;1139 1140 if (!g_text_mode) {1141 assert(blurb1 != NULL);1142 assert(blurb2 != NULL);1143 assert(blurb3 != NULL);1144 assert(g_timeline != NULL);1145 }1146 1147 current_time = get_time();1148 time_taken = current_time - g_start_time;1149 if (g_maximum_progress == 0) {1150 percentage = 0;1151 } else {1152 if (g_current_progress > g_maximum_progress) {1153 log_msg(0, "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld", blurb1, blurb2, blurb3, g_current_progress, g_maximum_progress);1154 g_current_progress = g_maximum_progress;1155 }1156 percentage = (int) ((g_current_progress * 100L) / g_maximum_progress);1157 }1158 if (percentage < 1) {1159 percentage = 1;1160 }1161 if (percentage > 100) {1162 percentage = 100;1163 }1164 if (g_current_progress) {1165 time_total_est = time_taken * (long) g_maximum_progress / (long) g_current_progress;1166 time_remaining = time_total_est - time_taken;1167 } else {1168 time_remaining = 0L;1169 }1170 g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27;1171 if (g_text_mode) {1172 printf("---progress-form---1--- %s\n", blurb1);1173 printf("---progress-form---2--- %s\n", blurb2);1174 printf("---progress-form---3--- %s\n", blurb3);1175 printf("---progress-form---E---\n");1176 mr_asprintf(taskprogress, "TASK: [");1177 for (i = 0; i < percentage; i += 5) {1178 mr_strcat(taskprogress, "*");1179 }1180 for (; i < 100; i += 5) {1181 mr_strcat(taskprogress, ".");1182 }1183 if (percentage > 100) {1184 log_msg(2, "percentage = %d", percentage);1185 }1186 mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage, (long) time_remaining / 60, (long) time_remaining % 60);1187 printf("---progress-form---4--- %s\n", taskprogress);1188 paranoid_free(taskprogress);1189 } else {1190 mr_asprintf(timeline_str, "%2ld:%02ld taken %2ld:%02ld remaining ", (long) time_taken / 60, (long) time_taken % 60, (long) time_remaining / 60, (long) time_remaining % 60);1191 mr_asprintf(percentline_str, " %3d%% done %3d%% to go", percentage, 100 - percentage);1192 1193 blurb1_str = mr_center_string(blurb1, 54);1194 blurb2_str = mr_center_string(blurb2, 54);1195 blurb3_str = mr_center_string(blurb3, 54);1196 if (g_blurb1) {1197 newtLabelSetText(g_blurb1, blurb1_str);1198 }1199 if (g_blurb2) {1200 // Not a typo but ridiculous !1201 newtLabelSetText(g_blurb2, blurb3_str);1202 }1203 if (g_blurb3) {1204 // Not a typo but ridiculous !1205 newtLabelSetText(g_blurb3, blurb2_str);1206 }1207 newtScaleSet(g_scale, (unsigned long long) g_current_progress);1208 if ((percentage >= 2) && (g_timeline)) {1209 newtLabelSetText(g_timeline, timeline_str);1210 }1211 mr_free(timeline_str);1212 1213 if (g_percentline) {1214 newtLabelSetText(g_percentline, percentline_str);1215 }1216 mr_free(percentline_str);1217 mr_free(blurb1_str);1218 mr_free(blurb2_str);1219 mr_free(blurb3_str);1220 1221 newtDrawForm(g_progressForm);1222 newtRefresh();1223 }1224 }1225 1223 1226 1224
Note:
See TracChangeset
for help on using the changeset viewer.