summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/confedit/listviewitemconffile.cpp15
-rw-r--r--noncore/apps/confedit/mainwindow.cpp1
2 files changed, 13 insertions, 3 deletions
diff --git a/noncore/apps/confedit/listviewitemconffile.cpp b/noncore/apps/confedit/listviewitemconffile.cpp
index 1f85095..ce6504c 100644
--- a/noncore/apps/confedit/listviewitemconffile.cpp
+++ b/noncore/apps/confedit/listviewitemconffile.cpp
@@ -45,107 +45,116 @@ void ListViewItemConfFile::parseFile()
QFile confFile(confFileInfo->absFilePath());
if(! confFile.open(IO_ReadOnly))
QMessageBox::critical(0,tr("Could not open"),tr("The file ")+confFileInfo->fileName()+tr(" could not be opened."),1,0);
QTextStream t( &confFile );
QString s;
QString group;
ListViewItemConfigEntry *groupItem;
ListViewItemConfigEntry *item;
while ( !t.atEnd() )
{
s = t.readLine().stripWhiteSpace();
//qDebug( "line: >%s<\n", s.latin1() );
if (s.contains("<?xml"))
{
_valid = false;
break;
}else
if ( s[0] == '[' && s[s.length()-1] == ']' )
{
// qDebug("got group"+s);
group = s.mid(1,s.length()-2);
if (!groupItem) groupItem = new ListViewItemConfigEntry(this, tr("no group") );
groupItem = new ListViewItemConfigEntry(this, group );
insertItem( groupItem );
} else
if ( int pos = s.find('=') )
{
// qDebug("got key"+s);
if (!groupItem) qDebug("PANIK NO GROUP! >%s<",group.latin1());
item = new ListViewItemConfigEntry(this, group, s );
groupItem->insertItem( item );
}
}
confFile.close();
setExpandable( _valid );
// qDebug("ListViewItemConfFile::parseFile END");
}
void ListViewItemConfFile::remove()
{
QFile::remove(confFileInfo->absFilePath());
QFile::remove(backupFileName());
delete this;
}
void ListViewItemConfFile::revert()
{
- if (_changed)
+ if (!_changed)
{
- parseFile();
- }else{
+ // read the backup file
QFile conf(confFileInfo->absFilePath());
QFile back(backupFileName());
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();
}
+ parseFile();
+ expand();
}
void ListViewItemConfFile::save()
{
if (!_changed) return;
QFile conf(confFileInfo->absFilePath());
QFile back(backupFileName());
if (!conf.open(IO_ReadOnly)) return;
if (!back.open(IO_WriteOnly)) return;
char buf[SIZE];
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();
unchanged();
}
bool ListViewItemConfFile::revertable()
{
return _changed || QFile(backupFileName()).exists();
}
QString ListViewItemConfFile::backupFileName()
{
return confFileInfo->absFilePath()+"~";
}
void ListViewItemConfFile::expand()
{
+ QListViewItem *subItem = firstChild();
+ QListViewItem *toDel;
+ while(subItem)
+ {
+ toDel = subItem;
+ subItem = subItem->nextSibling();
+ delete toDel;
+ }
parseFile();
}
diff --git a/noncore/apps/confedit/mainwindow.cpp b/noncore/apps/confedit/mainwindow.cpp
index 6de8741..c91c846 100644
--- a/noncore/apps/confedit/mainwindow.cpp
+++ b/noncore/apps/confedit/mainwindow.cpp
@@ -28,96 +28,97 @@
#include <qpushbutton.h>
#include <qlayout.h>
#include <qlineedit.h>
#include "listviewconfdir.h"
#include "listviewitemconf.h"
#include "listviewitemconfigentry.h"
MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) :
QDialog( parent, name, f ), _currentItem(0), _fileItem(0)
{
setCaption( tr("Conf File Editor") );
// setBaseSize( qApp->globalStrut() );
setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));//, sizePolicy().hasHeightForWidth() ) );
mainLayout = new QVBoxLayout( this );
mainLayout->setSpacing( 0 );
mainLayout->setMargin( 0 );
qDebug("creating settingList");
settingList = new ListViewConfDir( "/root/Settings/", this, "settingslist");
settingList->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));//, sizePolicy().hasHeightForWidth() ) );
mainLayout->addWidget( settingList, 0);
qDebug("creating editor");
editor = new EditWidget(this);
editor->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Maximum));//, sizePolicy().hasHeightForWidth() ) );
mainLayout->addWidget( editor, 1 );
editor->layoutType( ListViewItemConf::File );
makeMenu();
connect(settingList, SIGNAL( pressed(QListViewItem*) ),
this, SLOT(setCurrent(QListViewItem*)));
connect( settingList, SIGNAL( clicked( QListViewItem* ) ),
this, SLOT( stopTimer( QListViewItem* ) ) );
connect( editor->LineEditGroup, SIGNAL( textChanged(const QString&) ),
SLOT( groupChanged(const QString&) ) );
connect( editor->LineEditKey, SIGNAL( textChanged(const QString&) ),
SLOT( keyChanged(const QString&) ) );
connect( editor->LineEditValue, SIGNAL( textChanged(const QString&) ),
SLOT( valueChanged(const QString&) ) );
setCurrent(0);
+ editor->layoutType(EditWidget::File);
}
void MainWindow::makeMenu()
{
popupTimer = new QTimer(this);
popupMenuFile = new QPopupMenu(this);
popupMenuEntry = new QPopupMenu(this);
popupActionSave = new QAction( tr("Save"),QString::null, 0, this, 0 );
popupActionSave->addTo( popupMenuFile );
// popupActionSave->addTo( popupMenuEntry );
connect( popupActionSave, SIGNAL( activated() ),
this , SLOT( saveConfFile() ) );
popupActionRevert = new QAction( tr("Revert"),QString::null, 0, this, 0 );
popupActionRevert->addTo( popupMenuFile );
popupActionRevert->addTo( popupMenuEntry );
connect( popupActionRevert, SIGNAL( activated() ),
this , SLOT( revertConfFile() ) );
popupActionDelete = new QAction( tr("Delete"),QString::null, 0, this, 0 );
popupActionDelete->addTo( popupMenuFile );
popupActionDelete->addTo( popupMenuEntry );
connect( popupActionDelete, SIGNAL( activated() ),
this , SLOT( removeConfFile() ) );
connect( popupTimer, SIGNAL(timeout()),
this, SLOT(showPopup()) );
}
MainWindow::~MainWindow()
{
}
void MainWindow::setCurrent(QListViewItem *item)
{
// qDebug("MainWindow::setCurrent");
if (!item) return;
_item = (ListViewItemConf*) item;
if (!_item) return;
popupTimer->start( 750, true );
if (_item->getType() == ListViewItemConf::File)
{
editor->layoutType(EditWidget::File);
_currentItem=0;
_fileItem = (ListViewItemConfFile*)item;