Diffstat (limited to 'noncore/apps/confedit/listviewitemconffile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/noncore/apps/confedit/listviewitemconffile.cpp b/noncore/apps/confedit/listviewitemconffile.cpp index 858726d..b075063 100644 --- a/noncore/apps/confedit/listviewitemconffile.cpp +++ b/noncore/apps/confedit/listviewitemconffile.cpp @@ -64,27 +64,50 @@ void ListViewItemConfFile::parseFile() group = s.mid(1,s.length()-2); groupItem = new ListViewItemConfigEntry(this, group ); insertItem( groupItem ); } else if ( int pos = s.find('=') ) { // qDebug("got key"+s); item = new ListViewItemConfigEntry(this, group, s ); groupItem->insertItem( item ); } } confFile.close(); + unchanged(); setExpandable( _valid ); } + +void ListViewItemConfFile::revert() +{ + if (_changed) + { + parseFile(); + }else{ + QString backup = confFileInfo->absFilePath()+"~"; + QFile conf(confFileInfo->absFilePath()); + QFile back(backup); + + if (!back.open(IO_ReadOnly)) return; + if (!conf.open(IO_WriteOnly)) return; + + #define SIZE 124 + char buf[SIZE]; + while (int c = back.readBlock(buf, SIZE) ) conf.writeBlock(buf,c); + conf.close(); + back.close(); + } +} + void ListViewItemConfFile::save() { if (!_changed) return; QString backup = confFileInfo->absFilePath()+"~"; qDebug("make backup to "+backup); QFile conf(confFileInfo->absFilePath()); QFile back(backup); if (!conf.open(IO_ReadOnly)) return; if (!back.open(IO_WriteOnly)) return; #define SIZE 124 @@ -92,15 +115,20 @@ void ListViewItemConfFile::save() while (int c = conf.readBlock(buf, SIZE) ) back.writeBlock(buf,c); conf.close(); back.close(); if (!conf.open(IO_WriteOnly)) return; QTextStream *t = new QTextStream( &conf ); for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling()) { ((ListViewItemConfigEntry*)it)->save(t); } conf.close(); - qDebug("no saveing yet..."); unchanged(); } + + +bool ListViewItemConfFile::revertable() +{ + return _changed || QFile(confFileInfo->absFilePath()+"~").exists(); +}
\ No newline at end of file |