summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/confedit/listviewitemconffile.cpp7
-rw-r--r--noncore/apps/confedit/listviewitemconfigentry.cpp21
-rw-r--r--noncore/apps/confedit/listviewitemconfigentry.h3
-rw-r--r--noncore/apps/confedit/mainwindow.cpp4
4 files changed, 33 insertions, 2 deletions
diff --git a/noncore/apps/confedit/listviewitemconffile.cpp b/noncore/apps/confedit/listviewitemconffile.cpp
index a8fd770..858726d 100644
--- a/noncore/apps/confedit/listviewitemconffile.cpp
+++ b/noncore/apps/confedit/listviewitemconffile.cpp
@@ -49,51 +49,58 @@ void ListViewItemConfFile::parseFile()
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);
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();
setExpandable( _valid );
}
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
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();
qDebug("no saveing yet...");
unchanged();
}
diff --git a/noncore/apps/confedit/listviewitemconfigentry.cpp b/noncore/apps/confedit/listviewitemconfigentry.cpp
index 16be46e..77ce17d 100644
--- a/noncore/apps/confedit/listviewitemconfigentry.cpp
+++ b/noncore/apps/confedit/listviewitemconfigentry.cpp
@@ -1,107 +1,128 @@
/***************************************************************************
* *
* 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
// (c) 2002 Patrick S. Vogtp <tille@handhelds.org>
#include "listviewitemconfigentry.h"
#include "listviewitemconffile.h"
+#include <qtextstream.h>
ListViewItemConfigEntry::ListViewItemConfigEntry(ListViewItemConfFile *parent, QString group, QString key)
: ListViewItemConf(parent)
{
_fileItem = parent;
_file = parent->fileName();
_group = group;
setKey(key);
_fileItem->unchanged();
}
ListViewItemConfigEntry::~ListViewItemConfigEntry()
{
}
bool ListViewItemConfigEntry::isGroup()
{
return _key.isEmpty();
}
bool ListViewItemConfigEntry::isKey()
{
return !_key.isEmpty();
}
QString ListViewItemConfigEntry::getFile()
{
return _file;
}
void ListViewItemConfigEntry::setGroup(QString g)
{
if (g==_group) return;
_group = g;
changed();
}
QString ListViewItemConfigEntry::getGroup()
{
return _group;
}
void ListViewItemConfigEntry::setKey(QString key)
{
int pos = key.find("=");
_key = key.left(pos).stripWhiteSpace();
_value = key.right(key.length() - pos - 1).stripWhiteSpace();
displayText();
}
QString ListViewItemConfigEntry::getKey()
{
return _key;
}
QString ListViewItemConfigEntry::getValue()
{
return _value;
}
void ListViewItemConfigEntry::keyChanged(QString k)
{
if (k==_key) return;
_key = k;
changed();
}
void ListViewItemConfigEntry::valueChanged(QString v)
{
if (v==_value) return;
_value = v;
changed();
}
void ListViewItemConfigEntry::displayText()
{
QString s;
if (_changed) s="*";
if (isGroup())
{
s += "["+_group+"]";
_type = Group;
}else{
s += _key+" = "+_value;
_type = Key;
}
setText(0,s);
}
void ListViewItemConfigEntry::changed()
{
_changed=true;
displayText();
_fileItem->changed();
} \ No newline at end of file
+
+void ListViewItemConfigEntry::save(QTextStream *t)
+{
+ QString s;
+ if (isGroup())
+ {
+ s += "["+_group+"]";
+ _type = Group;
+ }else{
+ s += _key+" = "+_value;
+ _type = Key;
+ }
+ s += "\n";
+ (*t) << s;
+ _changed = false;
+ for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling())
+ {
+ ((ListViewItemConfigEntry*)it)->save(t);
+ }
+} \ No newline at end of file
diff --git a/noncore/apps/confedit/listviewitemconfigentry.h b/noncore/apps/confedit/listviewitemconfigentry.h
index d2b331f..1ff0491 100644
--- a/noncore/apps/confedit/listviewitemconfigentry.h
+++ b/noncore/apps/confedit/listviewitemconfigentry.h
@@ -1,43 +1,46 @@
/***************************************************************************
* *
* 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
// (c) 2002 Patrick S. Vogtp <tille@handhelds.org>
#ifndef LISTVIEWITEMCONFIGENTRY_H
#define LISTVIEWITEMCONFIGENTRY_H
#include <qwidget.h>
#include <qlistview.h>
#include "listviewitemconffile.h"
#include "listviewitemconf.h"
+class QTextStream;
+
class ListViewItemConfigEntry : public ListViewItemConf {
public:
ListViewItemConfigEntry(ListViewItemConfFile *parent, QString group, QString key="");
~ListViewItemConfigEntry();
bool isGroup();
bool isKey();
QString getFile();
void setGroup(QString);
QString getGroup();
void setKey(QString);
QString getKey();
QString getValue();
void keyChanged(QString);
void valueChanged(QString);
virtual void displayText();
virtual void changed();
+ void save(QTextStream*);
private:
QString _file;
QString _group;
QString _key;
QString _value;
ListViewItemConfFile *_fileItem;
};
#endif
diff --git a/noncore/apps/confedit/mainwindow.cpp b/noncore/apps/confedit/mainwindow.cpp
index 30dfdf7..47d9518 100644
--- a/noncore/apps/confedit/mainwindow.cpp
+++ b/noncore/apps/confedit/mainwindow.cpp
@@ -10,102 +10,102 @@
// (c) 2002 Patrick S. Vogt <tille@handhelds.org>
#include "mainwindow.h"
#include <qpe/qpemenubar.h>
#include <qpe/qpemessagebox.h>
#include <qpe/resource.h>
#include <qpe/config.h>
#include <qpe/qpetoolbar.h>
#include <qaction.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <qtoolbutton.h>
#include <qstring.h>
#include <qlabel.h>
#include <qfile.h>
#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 ) :
QMainWindow( parent, name, f ), _currentItem(0), _fileItem(0)
{
setCaption( tr("Conf File Editor") );
popupTimer = new QTimer(this);
popupMenu = new QPopupMenu(this);
QWidget *mainWidget = new QWidget(this);
setCentralWidget( mainWidget);
QGridLayout *mainLayout = new QGridLayout( mainWidget );
mainLayout->setSpacing( 3 );
mainLayout->setMargin( 3 );
settingList = new ListViewConfDir( "/root/Settings/", this, "settingslist");
mainLayout->addWidget( settingList, 0, 0 );
editor = new EditWidget(this);
mainLayout->addWidget( editor, 1, 0 );
- connect (settingList, SIGNAL( currentChanged(QListViewItem*) ),
+ connect(settingList, SIGNAL( pressed(QListViewItem*) ),
this, SLOT(setCurrent(QListViewItem*)));
connect( popupTimer, SIGNAL(timeout()),
this, SLOT(showPopup()) );
- connect( this, SIGNAL( clicked( 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&) ) );
makeMenu();
}
void MainWindow::makeMenu()
{
}
MainWindow::~MainWindow()
{
}
void MainWindow::setCurrent(QListViewItem *item)
{
if (!item) return;
ListViewItemConf *i = (ListViewItemConf*) item;
if (!i) return;
if (i->getType() == ListViewItemConf::File)
{
qDebug("start timer");
popupTimer->start( 750, true );
editor->hide();
updateGeometry();
_currentItem=0;
_fileItem = (ListViewItemConfFile*)item;
return;
}else editor->show();
_fileItem = 0;
_currentItem = (ListViewItemConfigEntry*)item;
if (!_currentItem) return;
QString file = _currentItem->getFile();
QString group = _currentItem->getGroup();
QString key = _currentItem->getKey();
QString val = _currentItem->getValue();
editor->TextFileName->setText(file);
editor->LineEditGroup->setText(group);
if (!key.isEmpty())