summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDavid Cantrell <dcantrel@mortise.boston.redhat.com>2007-08-08 18:14:08 -0400
committerDavid Cantrell <dcantrel@mortise.boston.redhat.com>2007-08-08 18:14:08 -0400
commit3bb8494e1ed5af0a48ad0211c3219e653167854f (patch)
tree712022b759a7f132993d311f569d949196930f6d /include
parent3769f0a1775773bbb9074492b72bc81b1ed33c7e (diff)
downloadparted-3bb8494e1ed5af0a48ad0211c3219e653167854f.tar.gz
History with undo and redo capabilities.
Author: Matt Davis <mattdavis@gmail.com> Here is a working version of the history with undo/redo capabilities. The idea here was based on a talk with Otavio Salvador who mentioned the concepts from Vanni Brutto. The idea being to capture all changes and only apply them all at once. This protects the user from performing an unwanted change. What I did was capture all disk modifications that are committed to disk, and put them in a list. The history manager allows the list to be traversed linearly, so that a change can be undone, viewed in parted (print command), or reapplied again. Nothing actually happens to the physical disk until the 'save' command is issued. Jim Meyering suggested that the functionality might be useful to libparted thus most of the functionality has been moved there. The stdout displays (printf) are placed in parted.c as the library should not do any output printing on its own. Three commands were added: 1) Undo : Undoes a disk modification 2) Redo : Redoes the most recent 'undone' modification 3) Save : Actually commits the list of non-undone modifications to disk I feel a bit more testing needs to be done, but I am happy with the results right now.
Diffstat (limited to 'include')
-rw-r--r--include/parted/Makefile.am1
-rw-r--r--include/parted/disk.h1
-rw-r--r--include/parted/history.h111
-rw-r--r--include/parted/parted.h1
4 files changed, 114 insertions, 0 deletions
diff --git a/include/parted/Makefile.am b/include/parted/Makefile.am
index dd0e1d4..88a426b 100644
--- a/include/parted/Makefile.am
+++ b/include/parted/Makefile.am
@@ -18,6 +18,7 @@ partedinclude_HEADERS = gnu.h \
natmath.h \
timer.h \
unit.h \
+ history.h \
parted.h \
$(S390_HDRS)
diff --git a/include/parted/disk.h b/include/parted/disk.h
index b82ea0f..69542c1 100644
--- a/include/parted/disk.h
+++ b/include/parted/disk.h
@@ -260,6 +260,7 @@ extern PedDisk* ped_disk_new_fresh (PedDevice* dev,
extern PedDisk* ped_disk_duplicate (const PedDisk* old_disk);
extern void ped_disk_destroy (PedDisk* disk);
extern int ped_disk_commit (PedDisk* disk);
+extern void ped_disk_commit_to_history (const PedDisk *disk);
extern int ped_disk_commit_to_dev (PedDisk* disk);
extern int ped_disk_commit_to_os (PedDisk* disk);
extern int ped_disk_check (const PedDisk* disk);
diff --git a/include/parted/history.h b/include/parted/history.h
new file mode 100644
index 0000000..b2b2cf5
--- /dev/null
+++ b/include/parted/history.h
@@ -0,0 +1,111 @@
+/*
+ libparted - a library for manipulating disk partitions
+ Copyright (C) 1999, 2000, 2001, 2007 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef PED_HISTORY_H_INCLUDED
+#define PED_HISTORY_H_INCLUDED
+
+
+/*
+ * Macros
+ */
+
+#define PED_HISTORY_TAG "[History] "
+#define PED_HISTORY_MAX_NAME 64
+#define PED_HISTORY_IS_UNDONE(_o) (_o->ignore && _o->disk)
+
+
+typedef struct _PedHistObj PedHistObj;
+typedef struct _PedHistManager PedHistManager;
+typedef enum _PedHistRet PedHistRet;
+
+#include <parted/disk.h>
+
+/*
+ * Enums
+ */
+
+enum _PedHistRet {
+ PED_HISTORY_RET_SUCCESS,
+ PED_HISTORY_RET_ERROR,
+ PED_HISTORY_RET_NO_UNDO,
+ PED_HISTORY_RET_NO_REDO,
+ PED_HISTORY_RET_NO_SAVE,
+};
+
+
+/*
+ * Structs
+ */
+
+struct _PedHistObj {
+ int id;
+ int ignore; /* Undo/Redo functionality */
+ char *name; /* Command name */
+ PedDisk *disk;
+ PedHistObj *prev;
+ PedHistObj *next;
+};
+
+
+struct _PedHistManager {
+ PedHistObj *begin;
+ PedHistObj *end;
+ int n_objs;
+ int id;
+};
+
+
+/*
+ * Funcs
+ */
+
+/* Add/Clear history */
+extern void ped_history_add (const char *cmd);
+extern void ped_history_clear (void);
+
+/* Iterating */
+extern const PedHistObj *ped_history_begin (void);
+
+/* Duplicate of the most recent disk mod, this can safely be destroyed */
+extern PedDisk *ped_history_disk (void);
+
+/* Before changes are committed */
+extern PedHistRet ped_history_undo (void);
+extern PedHistRet ped_history_redo (void);
+
+/* Write changes to disk
+ * Each change's success/failure value is passed
+ * to the optional callback so that the end application
+ * can display such values appropriately.
+ */
+typedef void (*PedHistPrintCB) (PedHistRet val, PedHistObj *obj);
+extern PedHistRet ped_history_commit_to_disk (PedHistPrintCB cb);
+
+/* Copy the most recent disk change */
+extern void ped_history_add_disk (const PedDisk *disk);
+
+/* Print */
+extern const char *ped_history_print_ret (PedHistRet val);
+extern void ped_history_print_debug (void);
+
+/* Alloc/dealloc */
+extern PedHistObj *ped_history_alloc_obj (void);
+extern void ped_history_dealloc_obj (PedHistObj *obj);
+
+
+#endif /* PED_HISTORY_H_INCLUDED */
diff --git a/include/parted/parted.h b/include/parted/parted.h
index 1302d8f..f82d02f 100644
--- a/include/parted/parted.h
+++ b/include/parted/parted.h
@@ -30,6 +30,7 @@ typedef struct _PedArchitecture PedArchitecture;
#include <parted/disk.h>
#include <parted/exception.h>
#include <parted/filesys.h>
+#include <parted/history.h>
#include <parted/natmath.h>
#include <parted/unit.h>