comparison pwfile.c @ 13:cf81eb0c2d5a

Warn before quitting if there are unsaved changes If there are unsaved changes emit a warning when the quit command is used. Only quit if the quit command is used twice with no other command in between. Add a new Quit command which immediatly quits pwm without a warning.
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Mon, 07 Aug 2017 16:59:47 +0200
parents 17fb30016e64
children efef93e54c5f
comparison
equal deleted inserted replaced
12:8768fbd09bc5 13:cf81eb0c2d5a
211 RB_INSERT(record_id_tree, ctx->record_id_tree, entry); 211 RB_INSERT(record_id_tree, ctx->record_id_tree, entry);
212 } 212 }
213 213
214 free(pws3_record_list); 214 free(pws3_record_list);
215 215
216 ctx->unsaved_changes = 0;
217
216 return (0); 218 return (0);
217 } 219 }
218 220
219 static int 221 static int
220 make_backup_copy(const char *filename) 222 make_backup_copy(const char *filename)
445 } 447 }
446 if ((retval != 0) && ((fd != -1) || (fp != NULL))) { 448 if ((retval != 0) && ((fd != -1) || (fp != NULL))) {
447 unlink(tmpfilename); 449 unlink(tmpfilename);
448 } 450 }
449 free(tmpfilename); 451 free(tmpfilename);
452
453 ctx->unsaved_changes = !!retval;
450 454
451 return (retval); 455 return (retval);
452 } 456 }
453 457
454 static int 458 static int
816 entry = xmalloc(sizeof (struct record_id_entry)); 820 entry = xmalloc(sizeof (struct record_id_entry));
817 entry->id = ctx->next_id++; 821 entry->id = ctx->next_id++;
818 memcpy(entry->uuid, uuid, sizeof (entry->uuid)); 822 memcpy(entry->uuid, uuid, sizeof (entry->uuid));
819 RB_INSERT(record_id_tree, ctx->record_id_tree, entry); 823 RB_INSERT(record_id_tree, ctx->record_id_tree, entry);
820 824
825 ctx->unsaved_changes = 1;
826
821 return (0); 827 return (0);
822 } 828 }
823 829
824 int 830 int
825 pwfile_modify_record(struct pwm_ctx *ctx, unsigned int id, 831 pwfile_modify_record(struct pwm_ctx *ctx, unsigned int id,
832 return (-1); 838 return (-1);
833 } 839 }
834 840
835 update_record(pws3_file_get_record(ctx->file, uuid), record); 841 update_record(pws3_file_get_record(ctx->file, uuid), record);
836 842
843 ctx->unsaved_changes = 1;
844
837 return (0); 845 return (0);
838 } 846 }
839 847
840 int 848 int
841 pwfile_remove_record(struct pwm_ctx *ctx, unsigned int id) 849 pwfile_remove_record(struct pwm_ctx *ctx, unsigned int id)
851 pws3_record_destroy(pws3_file_remove_record(ctx->file, uuid)); 859 pws3_record_destroy(pws3_file_remove_record(ctx->file, uuid));
852 860
853 entry = RB_FIND(record_id_tree, ctx->record_id_tree, 861 entry = RB_FIND(record_id_tree, ctx->record_id_tree,
854 &(struct record_id_entry){ .id = id }); 862 &(struct record_id_entry){ .id = id });
855 free(RB_REMOVE(record_id_tree, ctx->record_id_tree, entry)); 863 free(RB_REMOVE(record_id_tree, ctx->record_id_tree, entry));
864
865 ctx->unsaved_changes = 1;
856 866
857 return (0); 867 return (0);
858 } 868 }
859 869
860 int 870 int
884 if (pws3_field_set_text(empty_group_field, group) != 0) { 894 if (pws3_field_set_text(empty_group_field, group) != 0) {
885 err(1, "pws3_field_set_text"); 895 err(1, "pws3_field_set_text");
886 } 896 }
887 pws3_file_insert_empty_group(ctx->file, empty_group_field); 897 pws3_file_insert_empty_group(ctx->file, empty_group_field);
888 898
899 ctx->unsaved_changes = 1;
900
889 return (0); 901 return (0);
890 } 902 }
891 903
892 int 904 int
893 pwfile_remove_group(struct pwm_ctx *ctx, const char *group) 905 pwfile_remove_group(struct pwm_ctx *ctx, const char *group)
897 empty_group_field = pws3_file_remove_empty_group(ctx->file, group); 909 empty_group_field = pws3_file_remove_empty_group(ctx->file, group);
898 if (empty_group_field == NULL) { 910 if (empty_group_field == NULL) {
899 return (-1); 911 return (-1);
900 } 912 }
901 pws3_field_destroy(empty_group_field); 913 pws3_field_destroy(empty_group_field);
914
915 ctx->unsaved_changes = 1;
902 916
903 return (0); 917 return (0);
904 } 918 }
905 919
906 struct record * 920 struct record *