Diffstat (limited to 'noncore/apps/confedit/listviewitemconffile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/noncore/apps/confedit/listviewitemconffile.cpp b/noncore/apps/confedit/listviewitemconffile.cpp index b075063..228421b 100644 --- a/noncore/apps/confedit/listviewitemconffile.cpp +++ b/noncore/apps/confedit/listviewitemconffile.cpp | |||
@@ -78,15 +78,21 @@ void ListViewItemConfFile::parseFile() | |||
78 | } | 78 | } |
79 | 79 | ||
80 | 80 | ||
81 | void ListViewItemConfFile::remove() | ||
82 | { | ||
83 | QFile::remove(confFileInfo->absFilePath()); | ||
84 | QFile::remove(backupFileName()); | ||
85 | delete this; | ||
86 | } | ||
87 | |||
81 | void ListViewItemConfFile::revert() | 88 | void ListViewItemConfFile::revert() |
82 | { | 89 | { |
83 | if (_changed) | 90 | if (_changed) |
84 | { | 91 | { |
85 | parseFile(); | 92 | parseFile(); |
86 | }else{ | 93 | }else{ |
87 | QString backup = confFileInfo->absFilePath()+"~"; | ||
88 | QFile conf(confFileInfo->absFilePath()); | 94 | QFile conf(confFileInfo->absFilePath()); |
89 | QFile back(backup); | 95 | QFile back(backupFileName()); |
90 | 96 | ||
91 | if (!back.open(IO_ReadOnly)) return; | 97 | if (!back.open(IO_ReadOnly)) return; |
92 | if (!conf.open(IO_WriteOnly)) return; | 98 | if (!conf.open(IO_WriteOnly)) return; |
@@ -102,15 +108,12 @@ void ListViewItemConfFile::revert() | |||
102 | void ListViewItemConfFile::save() | 108 | void ListViewItemConfFile::save() |
103 | { | 109 | { |
104 | if (!_changed) return; | 110 | if (!_changed) return; |
105 | QString backup = confFileInfo->absFilePath()+"~"; | ||
106 | qDebug("make backup to "+backup); | ||
107 | QFile conf(confFileInfo->absFilePath()); | 111 | QFile conf(confFileInfo->absFilePath()); |
108 | QFile back(backup); | 112 | QFile back(backupFileName()); |
109 | 113 | ||
110 | if (!conf.open(IO_ReadOnly)) return; | 114 | if (!conf.open(IO_ReadOnly)) return; |
111 | if (!back.open(IO_WriteOnly)) return; | 115 | if (!back.open(IO_WriteOnly)) return; |
112 | 116 | ||
113 | #define SIZE 124 | ||
114 | char buf[SIZE]; | 117 | char buf[SIZE]; |
115 | while (int c = conf.readBlock(buf, SIZE) ) back.writeBlock(buf,c); | 118 | while (int c = conf.readBlock(buf, SIZE) ) back.writeBlock(buf,c); |
116 | conf.close(); | 119 | conf.close(); |
@@ -130,5 +133,10 @@ void ListViewItemConfFile::save() | |||
130 | 133 | ||
131 | bool ListViewItemConfFile::revertable() | 134 | bool ListViewItemConfFile::revertable() |
132 | { | 135 | { |
133 | return _changed || QFile(confFileInfo->absFilePath()+"~").exists(); | 136 | return _changed || QFile(backupFileName()).exists(); |
134 | } \ No newline at end of file | 137 | } |
138 | |||
139 | QString ListViewItemConfFile::backupFileName() | ||
140 | { | ||
141 | return confFileInfo->absFilePath()+"~"; | ||
142 | } | ||